• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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_GPU_PROGRAM_GLES_H
17 #define GLES_GPU_PROGRAM_GLES_H
18 
19 #include <base/containers/array_view.h>
20 #include <render/device/gpu_resource_desc.h>
21 #include <render/device/pipeline_state_desc.h>
22 #include <render/namespace.h>
23 
24 #include "device/gpu_program.h"
25 #include "gles/spirv_cross_helper_structs_gles.h"
26 
27 RENDER_BEGIN_NAMESPACE()
28 class Device;
29 class DeviceGLES;
30 class ShaderModuleGLES;
31 struct PushConstantReflection;
32 struct OES_Bind {
33     uint8_t set { 0 }, bind { 0 };
34 };
35 struct Binder {
36     uint32_t set;
37     uint32_t bind;
38     DescriptorType type;
39     // [descriptorarrayindex][glindices] for separate sample/image case, there can be multiple texture units to bind to,
40     // for other resources the second(inner) vector length is always 1.
41     BASE_NS::vector<BASE_NS::vector<uint32_t>> id;
42 };
43 
44 struct GpuShaderProgramPlatformDataGL final {
45     uint32_t program { 0 };
46     int32_t flipLocation { Gles::INVALID_LOCATION };
47     BASE_NS::array_view<Binder> resourceList;
48     BASE_NS::array_view<Gles::PushConstantReflection> pushConstants;
49     int32_t inputs[Gles::ResourceLimits::MAX_VERTEXINPUT_ATTRIBUTES] {};
50     const ShaderModuleGLES* vertShaderModule_ { nullptr };
51     const ShaderModuleGLES* fragShaderModule_ { nullptr };
52 };
53 
54 class GpuShaderProgramGLES final : public GpuShaderProgram {
55 public:
56     GpuShaderProgramGLES(Device& device, const GpuShaderProgramCreateData& createData);
57     ~GpuShaderProgramGLES();
58 
59     const GpuShaderProgramPlatformDataGL& GetPlatformData() const;
60     const ShaderReflection& GetReflection() const override;
61 
62     GpuShaderProgramGLES* Specialize(const ShaderSpecializationConstantDataView& specialization) const;
63 
64     GpuShaderProgramGLES* OesPatch(const BASE_NS::array_view<const OES_Bind>& binds) const;
65 
66 private:
67     GpuShaderProgramGLES* Specialize(const ShaderSpecializationConstantDataView& specData,
68         const BASE_NS::array_view<const OES_Bind>& oesBinds) const;
69     void FilterInputs(GpuShaderProgramGLES& ret) const;
70     GpuShaderProgramGLES(Device& device);
71     DeviceGLES& device_;
72     GpuShaderProgramPlatformDataGL plat_;
73     BASE_NS::vector<ShaderSpecialization::Constant> constants_;
74     ShaderReflection reflection_;
75 
76     BASE_NS::vector<Binder> resourceList;
77     BASE_NS::vector<Gles::PushConstantReflection> pushConstants;
78     // copy of specialization data used..
79     BASE_NS::vector<uint32_t> specializedWith;
80 };
81 
82 struct GpuComputeProgramPlatformDataGL final {
83     uint32_t program { 0 };
84     int32_t flipLocation { Gles::INVALID_LOCATION };
85     BASE_NS::array_view<Binder> resourceList;
86     BASE_NS::array_view<Gles::PushConstantReflection> pushConstants;
87     const ShaderModuleGLES* module_ { nullptr };
88 };
89 
90 class GpuComputeProgramGLES final : public GpuComputeProgram {
91 public:
92     GpuComputeProgramGLES(Device& device, const GpuComputeProgramCreateData& createData);
93     ~GpuComputeProgramGLES();
94 
95     const GpuComputeProgramPlatformDataGL& GetPlatformData() const;
96     const ComputeShaderReflection& GetReflection() const override;
97 
98     GpuComputeProgramGLES* Specialize(const ShaderSpecializationConstantDataView& specialization) const;
99 
100 private:
101     GpuComputeProgramGLES(Device& device);
102     DeviceGLES& device_;
103     GpuComputeProgramPlatformDataGL plat_;
104     BASE_NS::vector<ShaderSpecialization::Constant> constants_;
105     ComputeShaderReflection reflection_;
106     BASE_NS::vector<Binder> resourceList;
107     BASE_NS::vector<Gles::PushConstantReflection> pushConstants;
108 };
109 RENDER_END_NAMESPACE()
110 
111 #endif // GLES_GPU_PROGRAM_GLES_H
112