• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <base/containers/unique_ptr.h>
21 #include <render/device/gpu_resource_desc.h>
22 #include <render/device/pipeline_state_desc.h>
23 #include <render/namespace.h>
24 
25 #include "device/gpu_program.h"
26 #include "gles/spirv_cross_helper_structs_gles.h"
27 
28 RENDER_BEGIN_NAMESPACE()
29 class Device;
30 class DeviceGLES;
31 class ShaderModuleGLES;
32 struct PushConstantReflection;
33 struct OES_Bind {
34     uint8_t set { 0 }, bind { 0 };
35 };
36 struct Slice {
37     uint16_t index;
38     uint16_t count;
39 };
40 struct Binder {
41     uint16_t set;
42     uint16_t bind;
43     DescriptorType type;
44     // index/count pair into descriptorIndexIds. count equals descriptor set count.
45     Slice descriptors;
46 };
47 struct Resources {
48     // descriptor set bindings used by the shader.
49     BASE_NS::vector<Binder> resourceList;
50     // index/count pairs into ids. separate images/samplers can be bound to multiple units in which case count is
51     // greater than one.
52     BASE_NS::vector<Slice> descriptorIndexIds;
53     BASE_NS::vector<uint8_t> ids;
54 };
55 struct ResourcesView {
56     BASE_NS::array_view<Binder> resourceList;
57     BASE_NS::array_view<Slice> descriptorIndexIds;
58     BASE_NS::array_view<uint8_t> ids;
59 };
60 struct GpuShaderProgramPlatformDataGL final {
61     uint32_t program { 0 };
62     int32_t flipLocation { Gles::INVALID_LOCATION };
63     ResourcesView resourcesView;
64     BASE_NS::array_view<Gles::PushConstantReflection> pushConstants;
65     int32_t inputs[Gles::ResourceLimits::MAX_VERTEXINPUT_ATTRIBUTES] {};
66     const ShaderModuleGLES* vertShaderModule_ { nullptr };
67     const ShaderModuleGLES* fragShaderModule_ { nullptr };
68 };
69 
70 class GpuShaderProgramGLES final : public GpuShaderProgram {
71 public:
72     GpuShaderProgramGLES(Device& device, const GpuShaderProgramCreateData& createData);
73     ~GpuShaderProgramGLES() override;
74 
75     const GpuShaderProgramPlatformDataGL& GetPlatformData() const;
76     const ShaderReflection& GetReflection() const override;
77 
78     BASE_NS::unique_ptr<GpuShaderProgramGLES> Specialize(
79         const ShaderSpecializationConstantDataView& specialization, uint32_t views) const;
80 
81     BASE_NS::unique_ptr<GpuShaderProgramGLES> OesPatch(
82         const BASE_NS::array_view<const OES_Bind>& binds, uint32_t views) const;
83 
84 private:
85     BASE_NS::unique_ptr<GpuShaderProgramGLES> Specialize(const ShaderSpecializationConstantDataView& specData,
86         const BASE_NS::array_view<const OES_Bind>& oesBinds, uint32_t views) const;
87     static void FilterInputs(GpuShaderProgramGLES& ret);
88     explicit GpuShaderProgramGLES(Device& device);
89     DeviceGLES& device_;
90     GpuShaderProgramPlatformDataGL plat_;
91     BASE_NS::vector<ShaderSpecialization::Constant> constants_;
92     ShaderReflection reflection_;
93 
94     Resources resources_;
95 
96     BASE_NS::vector<Gles::PushConstantReflection> pushConstants;
97     // copy of specialization data used..
98     BASE_NS::vector<uint32_t> specializedWith;
99 };
100 
101 struct GpuComputeProgramPlatformDataGL final {
102     uint32_t program { 0 };
103     int32_t flipLocation { Gles::INVALID_LOCATION };
104     ResourcesView resourcesView;
105     BASE_NS::array_view<Gles::PushConstantReflection> pushConstants;
106     const ShaderModuleGLES* module_ { nullptr };
107 };
108 
109 class GpuComputeProgramGLES final : public GpuComputeProgram {
110 public:
111     GpuComputeProgramGLES(Device& device, const GpuComputeProgramCreateData& createData);
112     ~GpuComputeProgramGLES();
113 
114     const GpuComputeProgramPlatformDataGL& GetPlatformData() const;
115     const ComputeShaderReflection& GetReflection() const override;
116 
117     BASE_NS::unique_ptr<GpuComputeProgramGLES> Specialize(
118         const ShaderSpecializationConstantDataView& specialization) const;
119 
120 private:
121     explicit GpuComputeProgramGLES(Device& device);
122     DeviceGLES& device_;
123     GpuComputeProgramPlatformDataGL plat_;
124     BASE_NS::vector<ShaderSpecialization::Constant> constants_;
125     ComputeShaderReflection reflection_;
126     Resources resources_;
127     BASE_NS::vector<Gles::PushConstantReflection> pushConstants;
128 };
129 RENDER_END_NAMESPACE()
130 
131 #endif // GLES_GPU_PROGRAM_GLES_H
132