| 1 |
/* |
| 2 |
* Copyright 2015-2020 Arm Limited |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef SPIRV_CROSS_CPP_HPP |
| 18 |
#define SPIRV_CROSS_CPP_HPP |
| 19 |
|
| 20 |
#include "spirv_glsl.hpp" |
| 21 |
#include <utility> |
| 22 |
|
| 23 |
namespace SPIRV_CROSS_NAMESPACE |
| 24 |
{ |
| 25 |
class CompilerCPP : public CompilerGLSL |
| 26 |
{ |
| 27 |
public: |
| 28 |
explicit CompilerCPP(std::vector<uint32_t> spirv_) |
| 29 |
: CompilerGLSL(std::move(spirv_)) |
| 30 |
{ |
| 31 |
} |
| 32 |
|
| 33 |
CompilerCPP(const uint32_t *ir_, size_t word_count) |
| 34 |
: CompilerGLSL(ir_, word_count) |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
explicit CompilerCPP(const ParsedIR &ir_) |
| 39 |
: CompilerGLSL(ir_) |
| 40 |
{ |
| 41 |
} |
| 42 |
|
| 43 |
explicit CompilerCPP(ParsedIR &&ir_) |
| 44 |
: CompilerGLSL(std::move(ir_)) |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
std::string compile() override; |
| 49 |
|
| 50 |
// Sets a custom symbol name that can override |
| 51 |
// spirv_cross_get_interface. |
| 52 |
// |
| 53 |
// Useful when several shader interfaces are linked |
| 54 |
// statically into the same binary. |
| 55 |
void set_interface_name(std::string name) |
| 56 |
{ |
| 57 |
interface_name = std::move(name); |
| 58 |
} |
| 59 |
|
| 60 |
private: |
| 61 |
void emit_header() override; |
| 62 |
void emit_c_linkage(); |
| 63 |
void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override; |
| 64 |
|
| 65 |
void emit_resources(); |
| 66 |
void emit_buffer_block(const SPIRVariable &type) override; |
| 67 |
void emit_push_constant_block(const SPIRVariable &var) override; |
| 68 |
void emit_interface_block(const SPIRVariable &type); |
| 69 |
void emit_block_chain(SPIRBlock &block); |
| 70 |
void emit_uniform(const SPIRVariable &var) override; |
| 71 |
void emit_shared(const SPIRVariable &var); |
| 72 |
void emit_block_struct(SPIRType &type); |
| 73 |
std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override; |
| 74 |
|
| 75 |
std::string argument_decl(const SPIRFunction::Parameter &arg); |
| 76 |
|
| 77 |
SmallVector<std::string> resource_registrations; |
| 78 |
std::string impl_type; |
| 79 |
std::string resource_type; |
| 80 |
uint32_t shared_counter = 0; |
| 81 |
|
| 82 |
std::string interface_name; |
| 83 |
}; |
| 84 |
} // namespace SPIRV_CROSS_NAMESPACE |
| 85 |
|
| 86 |
#endif |