1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GLES_PIPELINE_STATE_OBJECT_GLES_H
17 #define GLES_PIPELINE_STATE_OBJECT_GLES_H
18 
19 #include <base/containers/unique_ptr.h>
20 #include <base/containers/unordered_map.h>
21 #include <render/device/pipeline_layout_desc.h>
22 #include <render/namespace.h>
23 
24 #include "device/pipeline_state_object.h"
25 
26 RENDER_BEGIN_NAMESPACE()
27 class Device;
28 class DeviceGLES;
29 class GpuShaderProgram;
30 class GpuComputeProgram;
31 class GpuComputeProgramGLES;
32 class GpuShaderProgramGLES;
33 struct OES_Bind;
34 
35 struct PipelineStateObjectPlatformDataGL final {
36     const GpuComputeProgramGLES* computeShader;
37     const GpuShaderProgramGLES* graphicsShader;
38     GraphicsState graphicsState;
39     PipelineLayout pipelineLayout;
40     VertexInputDeclarationData vertexInputDeclaration;
41     RenderPassDesc renderPassDesc;
42     DynamicStateFlags dynamicStateFlags;
43     uint32_t vao;
44     uint32_t views;
45 };
46 
47 class GraphicsPipelineStateObjectGLES final : public GraphicsPipelineStateObject {
48 public:
49     GraphicsPipelineStateObjectGLES(Device& device, const GpuShaderProgram& gpuShaderProgram,
50         const GraphicsState& graphicsState, const PipelineLayout& pipelineLayout,
51         const VertexInputDeclarationView& vertexInputDeclaration,
52         const ShaderSpecializationConstantDataView& specializationConstants,
53         const BASE_NS::array_view<const DynamicStateEnum> dynamicStates, const RenderPassDesc& renderPassDesc,
54         const BASE_NS::array_view<const RenderPassSubpassDesc>& renderPassSubpassDescs, const uint32_t subpassIndex);
55 
56     ~GraphicsPipelineStateObjectGLES();
57 
58     const PipelineStateObjectPlatformDataGL& GetPlatformData() const;
59 
60     GpuShaderProgramGLES* GetOESProgram(BASE_NS::array_view<const OES_Bind> oesBinds) const;
61 
62 private:
63     void MakeVAO() noexcept;
64     DeviceGLES& device_;
65 
66     BASE_NS::unique_ptr<GpuShaderProgramGLES> specialized_;
67     PipelineStateObjectPlatformDataGL plat_ {};
68 
69     mutable BASE_NS::unordered_map<BASE_NS::string, BASE_NS::unique_ptr<GpuShaderProgramGLES>>
70         oesPrograms_; // generated dynamically.
71 };
72 
73 class ComputePipelineStateObjectGLES final : public ComputePipelineStateObject {
74 public:
75     ComputePipelineStateObjectGLES(Device& device, const GpuComputeProgram& gpuComputeProgram,
76         const PipelineLayout& pipelineLayout, const ShaderSpecializationConstantDataView& specializationConstants);
77     ~ComputePipelineStateObjectGLES();
78 
79     const PipelineStateObjectPlatformDataGL& GetPlatformData() const;
80 
81 private:
82     DeviceGLES& device_;
83 
84     BASE_NS::unique_ptr<GpuComputeProgramGLES> specialized_ { nullptr };
85     PipelineStateObjectPlatformDataGL plat_ {};
86 };
87 RENDER_END_NAMESPACE()
88 
89 #endif // GLES_PIPELINE_STATE_OBJECT_GLES_H
90