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_SHADER_MODULE_GLES_H 17 #define GLES_SHADER_MODULE_GLES_H 18 19 #include <base/containers/string.h> 20 #include <render/device/gpu_resource_desc.h> 21 #include <render/device/pipeline_layout_desc.h> 22 #include <render/namespace.h> 23 24 #include "device/shader_module.h" 25 26 RENDER_BEGIN_NAMESPACE() 27 class Device; 28 class DeviceGLES; 29 struct ShaderModuleCreateInfo; 30 namespace Gles { 31 struct PushConstantReflection; 32 struct SpecConstantInfo; 33 } // namespace Gles 34 struct ShaderModulePlatformDataGLES : ShaderModulePlatformData { 35 BASE_NS::vector<Gles::PushConstantReflection> infos; 36 struct Bind { 37 uint8_t iSet, iBind; // binding set, binding index 38 uint8_t arrayElements; // for array binds. 39 BASE_NS::string name; // name opengl uniform/block 40 }; 41 BASE_NS::vector<Bind> ubSets; // uniform blocks 42 BASE_NS::vector<Bind> sbSets; // shader storage blocks 43 BASE_NS::vector<Bind> siSets; // subpass inputs 44 BASE_NS::vector<Bind> ciSets; // image textures 45 BASE_NS::vector<Bind> cbSets; // combined textures (sampler2D etc) 46 struct DoubleBind { 47 uint8_t sSet, sBind; // sampler binding set, binding index 48 uint8_t iSet, iBind; // image binding set, binding index 49 BASE_NS::string name; // name of combined image/sampler 50 }; 51 BASE_NS::vector<DoubleBind> combSets; // combined image / sampler (generated from separated image/sampler) 52 }; 53 54 class ShaderModuleGLES final : public ShaderModule { 55 public: 56 ShaderModuleGLES(Device&, const ShaderModuleCreateInfo&); 57 ~ShaderModuleGLES(); 58 59 ShaderStageFlags GetShaderStageFlags() const override; 60 61 const ShaderModulePlatformData& GetPlatformData() const override; 62 63 const PipelineLayout& GetPipelineLayout() const override; 64 ShaderSpecializationConstantView GetSpecilization() const override; 65 66 VertexInputDeclarationView GetVertexInputDeclaration() const override; 67 ShaderThreadGroup GetThreadGroupSize() const override; 68 69 BASE_NS::string GetGLSL(const ShaderSpecializationConstantDataView&) const; 70 71 private: 72 Device& device_; 73 ShaderStageFlags shaderStageFlags_ { 0u }; 74 ShaderModulePlatformDataGLES plat_; 75 BASE_NS::vector<VertexInputDeclaration::VertexInputBindingDescription> vertexInputBindingDescriptions_; 76 BASE_NS::vector<VertexInputDeclaration::VertexInputAttributeDescription> vertexInputAttributeDescriptions_; 77 BASE_NS::vector<ShaderSpecialization::Constant> constants_; 78 79 PipelineLayout pipelineLayout_; 80 ShaderSpecializationConstantView sscv_; 81 VertexInputDeclarationView vidv_; 82 ShaderThreadGroup stg_; 83 84 BASE_NS::string source_; 85 BASE_NS::vector<Gles::SpecConstantInfo> specInfo_; 86 template<typename ShaderBase> 87 friend void ProcessShaderModule(ShaderBase&, const ShaderModuleCreateInfo&); 88 template<typename ShaderBase> 89 friend BASE_NS::string SpecializeShaderModule(const ShaderBase&, const ShaderSpecializationConstantDataView&); 90 }; 91 RENDER_END_NAMESPACE() 92 93 #endif // GLES_SHADER_MODULE_GLES_H 94