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_SHADER_REFLECTION_DATA_H 17 #define DEVICE_SHADER_REFLECTION_DATA_H 18 19 #include <base/containers/array_view.h> 20 #include <base/containers/vector.h> 21 #include <base/math/vector.h> 22 #include <render/device/pipeline_layout_desc.h> 23 #include <render/device/pipeline_state_desc.h> 24 #include <render/namespace.h> 25 26 RENDER_BEGIN_NAMESPACE() 27 enum class ImageDimension : uint8_t { 28 DIMENSION_1D = 0, 29 DIMENSION_2D = 1, 30 DIMENSION_3D = 2, 31 DIMENSION_CUBE = 3, 32 // ignored in higher level, rectangle texture 33 DIMENSION_RECT = 4, 34 // image load / store 35 DIMENSION_BUFFER = 5, 36 DIMENSION_SUBPASS = 6, 37 }; 38 39 enum ImageFlags { 40 IMAGE_DEPTH = 0b00000001, 41 IMAGE_ARRAY = 0b00000010, 42 IMAGE_MULTISAMPLE = 0b00000100, 43 IMAGE_SAMPLED = 0b00001000, 44 IMAGE_LOAD_STORE = 0b00010000, 45 }; 46 47 class ShaderReflectionData { 48 public: 49 ShaderReflectionData() = default; 50 explicit ShaderReflectionData(BASE_NS::array_view<const uint8_t> reflectionData); 51 52 bool IsValid() const; 53 ShaderStageFlags GetStageFlags() const; 54 PipelineLayout GetPipelineLayout() const; 55 BASE_NS::vector<ShaderSpecialization::Constant> GetSpecializationConstants() const; 56 BASE_NS::vector<VertexInputDeclaration::VertexInputAttributeDescription> GetInputDescriptions() const; 57 BASE_NS::Math::UVec3 GetLocalSize() const; 58 const uint8_t* GetPushConstants() const; 59 60 private: 61 BASE_NS::array_view<const uint8_t> reflectionData_; 62 uint16_t size_[5U] {}; 63 }; 64 RENDER_END_NAMESPACE() 65 #endif 66