1 | /* |
2 | * Copyright 2015-2021 Arm Limited |
3 | * SPDX-License-Identifier: Apache-2.0 OR MIT |
4 | * |
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 |
8 | * |
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | * |
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. |
16 | */ |
17 | |
18 | /* |
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>. |
22 | */ |
23 | |
24 | #ifndef SPIRV_CROSS_CPP_HPP |
25 | #define SPIRV_CROSS_CPP_HPP |
26 | |
27 | #include "spirv_glsl.hpp" |
28 | #include <utility> |
29 | |
30 | namespace SPIRV_CROSS_NAMESPACE |
31 | { |
32 | class CompilerCPP : public CompilerGLSL |
33 | { |
34 | public: |
35 | explicit CompilerCPP(std::vector<uint32_t> spirv_) |
36 | : CompilerGLSL(std::move(spirv_)) |
37 | { |
38 | } |
39 | |
40 | CompilerCPP(const uint32_t *ir_, size_t word_count) |
41 | : CompilerGLSL(ir_, word_count) |
42 | { |
43 | } |
44 | |
45 | explicit CompilerCPP(const ParsedIR &ir_) |
46 | : CompilerGLSL(ir_) |
47 | { |
48 | } |
49 | |
50 | explicit CompilerCPP(ParsedIR &&ir_) |
51 | : CompilerGLSL(std::move(ir_)) |
52 | { |
53 | } |
54 | |
55 | std::string compile() override; |
56 | |
57 | // Sets a custom symbol name that can override |
58 | // spirv_cross_get_interface. |
59 | // |
60 | // Useful when several shader interfaces are linked |
61 | // statically into the same binary. |
62 | void set_interface_name(std::string name) |
63 | { |
64 | interface_name = std::move(name); |
65 | } |
66 | |
67 | private: |
68 | void () override; |
69 | void emit_c_linkage(); |
70 | void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override; |
71 | |
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; |
81 | |
82 | std::string argument_decl(const SPIRFunction::Parameter &arg); |
83 | |
84 | SmallVector<std::string> resource_registrations; |
85 | std::string impl_type; |
86 | std::string resource_type; |
87 | uint32_t shared_counter = 0; |
88 | |
89 | std::string interface_name; |
90 | }; |
91 | } // namespace SPIRV_CROSS_NAMESPACE |
92 | |
93 | #endif |
94 | |