Merge pull request #2431 from scribam/cmake-minimum-required
[KhronosGroup/SPIRV-Cross.git] / spirv_cpp.hpp
blobc76629cdcbed4ec13e8c24fd236306a9122e7c1a
1 /*
2 * Copyright 2015-2021 Arm Limited
3 * SPDX-License-Identifier: Apache-2.0 OR MIT
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * At your option, you may choose to accept this material under either:
20 * 1. The Apache License, Version 2.0, found at <http://www.apache.org/licenses/LICENSE-2.0>, or
21 * 2. The MIT License, found at <http://opensource.org/licenses/MIT>.
24 #ifndef SPIRV_CROSS_CPP_HPP
25 #define SPIRV_CROSS_CPP_HPP
27 #include "spirv_glsl.hpp"
28 #include <utility>
30 namespace SPIRV_CROSS_NAMESPACE
32 class CompilerCPP : public CompilerGLSL
34 public:
35 explicit CompilerCPP(std::vector<uint32_t> spirv_)
36 : CompilerGLSL(std::move(spirv_))
40 CompilerCPP(const uint32_t *ir_, size_t word_count)
41 : CompilerGLSL(ir_, word_count)
45 explicit CompilerCPP(const ParsedIR &ir_)
46 : CompilerGLSL(ir_)
50 explicit CompilerCPP(ParsedIR &&ir_)
51 : CompilerGLSL(std::move(ir_))
55 std::string compile() override;
57 // Sets a custom symbol name that can override
58 // spirv_cross_get_interface.
60 // Useful when several shader interfaces are linked
61 // statically into the same binary.
62 void set_interface_name(std::string name)
64 interface_name = std::move(name);
67 private:
68 void emit_header() override;
69 void emit_c_linkage();
70 void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
72 void emit_resources();
73 void emit_buffer_block(const SPIRVariable &type) override;
74 void emit_push_constant_block(const SPIRVariable &var) override;
75 void emit_interface_block(const SPIRVariable &type);
76 void emit_block_chain(SPIRBlock &block);
77 void emit_uniform(const SPIRVariable &var) override;
78 void emit_shared(const SPIRVariable &var);
79 void emit_block_struct(SPIRType &type);
80 std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override;
82 std::string argument_decl(const SPIRFunction::Parameter &arg);
84 SmallVector<std::string> resource_registrations;
85 std::string impl_type;
86 std::string resource_type;
87 uint32_t shared_counter = 0;
89 std::string interface_name;
91 } // namespace SPIRV_CROSS_NAMESPACE
93 #endif