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 DEVICE_GPU_PROGRAM_H 17 #define DEVICE_GPU_PROGRAM_H 18 19 #include <cstdint> 20 21 #include <base/containers/array_view.h> 22 #include <render/device/pipeline_layout_desc.h> 23 #include <render/namespace.h> 24 25 RENDER_BEGIN_NAMESPACE() 26 class ShaderModule; 27 28 /** Compute shader reflection */ 29 struct ComputeShaderReflection { 30 /** Pipeline layout */ 31 PipelineLayout pipelineLayout; 32 /** Shader specialization constant view */ 33 ShaderSpecializationConstantView shaderSpecializationConstantView; 34 35 /** Thread group size X */ 36 uint32_t threadGroupSizeX { 0 }; 37 /** Thread group size Y */ 38 uint32_t threadGroupSizeY { 0 }; 39 /** Thread group size Z */ 40 uint32_t threadGroupSizeZ { 0 }; 41 }; 42 43 /** Shader reflection */ 44 struct ShaderReflection { 45 /** Pipeline layout */ 46 PipelineLayout pipelineLayout; 47 /** Shader specialization constant view */ 48 ShaderSpecializationConstantView shaderSpecializationConstantView; 49 /** Vertex input declaration view */ 50 VertexInputDeclarationView vertexInputDeclarationView; 51 }; 52 53 struct GpuShaderProgramCreateData { 54 ShaderModule* vertShaderModule { nullptr }; 55 ShaderModule* fragShaderModule { nullptr }; 56 }; 57 58 /** Shader program. 59 * Compiled shader module and shader reflection. 60 */ 61 class GpuShaderProgram { 62 public: 63 GpuShaderProgram() = default; 64 virtual ~GpuShaderProgram() = default; 65 66 GpuShaderProgram(const GpuShaderProgram&) = delete; 67 GpuShaderProgram& operator=(const GpuShaderProgram&) = delete; 68 69 /* Reflection data is a reference and has array_views. Do not hold on to the data. */ 70 virtual const ShaderReflection& GetReflection() const = 0; 71 }; 72 73 struct GpuComputeProgramCreateData { 74 ShaderModule* compShaderModule { nullptr }; 75 }; 76 77 /** Compute shader program. 78 * Compiled shader module and shader reflection. 79 */ 80 class GpuComputeProgram { 81 public: 82 GpuComputeProgram() = default; 83 virtual ~GpuComputeProgram() = default; 84 85 GpuComputeProgram(const GpuComputeProgram&) = delete; 86 GpuComputeProgram& operator=(const GpuComputeProgram&) = delete; 87 88 /* Reflection data is a reference and has array_views. Do not hold on to the data. */ 89 virtual const ComputeShaderReflection& GetReflection() const = 0; 90 }; 91 RENDER_END_NAMESPACE() 92 93 #endif // DEVICE_GPU_PROGRAM_H 94