• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SPIRV_CROSS_HELPERS_H
17 #define GLES_SPIRV_CROSS_HELPERS_H
18 
19 #include <spirv_cross.hpp>
20 #include <spirv_glsl.hpp>
21 #include <spirv_parser.hpp>
22 #include <string>
23 #include <string_view>
24 
25 #include "spirv_cross_helper_structs_gles.h"
26 
27 namespace Gles {
28 // inherit from CompilerGLSL to have better access
29 class CoreCompiler final : public spirv_cross::CompilerGLSL {
30 public:
31     CoreCompiler(const uint32_t* ir, size_t wordCount);
32     ~CoreCompiler() = default;
33     const std::vector<spirv_cross::SPIRConstant> GetConstants() const;
34     const spirv_cross::ParsedIR& GetIr() const;
35 };
36 
37 void ReflectPushConstants(spirv_cross::Compiler& compiler, const spirv_cross::ShaderResources& resources,
38     std::vector<PushConstantReflection>& reflections, ShaderStageFlags stage);
39 
40 // Converts specialization constant to normal constant, (to reduce unnecessary clutter in glsl)
41 void ConvertSpecConstToConstant(spirv_cross::CompilerGLSL& compiler, const char* name);
42 
43 // Converts constant declaration to uniform. (actually only works on spec constants)
44 void ConvertConstantToUniform(const spirv_cross::CompilerGLSL& compiler, std::string& source, const char* name);
45 
46 void SetSpecMacro(spirv_cross::CompilerGLSL& compiler, const char* name, uint32_t value);
47 
48 void ProcessStruct(const spirv_cross::Compiler& compiler, const PushConstantReflection& base, uint32_t structTypeId,
49     std::vector<PushConstantReflection>& reflections);
50 } // namespace Gles
51 
52 #endif // GLES_SPIRV_CROSS_HELPERS_H
53