blob: 89e711e3ef24834ee7a6e048ee7f3370cff4e200 [file] [log] [blame]
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +01001/*
2 * Copyright 2015-2016 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
Hans-Kristian Arntzen147e53a2016-04-04 09:36:04 +020017#ifndef SPIRV_CPP_HPP
18#define SPIRV_CPP_HPP
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010019
Hans-Kristian Arntzen147e53a2016-04-04 09:36:04 +020020#include "spirv_glsl.hpp"
Hans-Kristian Arntzenc172a352016-05-30 21:45:16 +020021#include <utility>
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010022#include <vector>
23
Hans-Kristian Arntzen147e53a2016-04-04 09:36:04 +020024namespace spirv_cross
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010025{
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020026class CompilerCPP : public CompilerGLSL
27{
28public:
29 CompilerCPP(std::vector<uint32_t> spirv_)
30 : CompilerGLSL(move(spirv_))
31 {
32 }
33 std::string compile() override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010034
Hans-Kristian Arntzenc172a352016-05-30 21:45:16 +020035 // Sets a custom symbol name that can override
36 // spirv_cross_get_interface.
37 //
38 // Useful when several shader interfaces are linked
39 // statically into the same binary.
40 void set_interface_name(std::string name)
41 {
42 interface_name = std::move(name);
43 }
44
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020045private:
46 void emit_header() override;
47 void emit_c_linkage();
48 void emit_function_prototype(SPIRFunction &func, uint64_t return_flags) override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010049
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020050 void emit_resources();
51 void emit_buffer_block(const SPIRVariable &type);
52 void emit_push_constant_block(const SPIRVariable &var);
53 void emit_interface_block(const SPIRVariable &type);
54 void emit_block_chain(SPIRBlock &block);
55 void emit_uniform(const SPIRVariable &var);
56 void emit_shared(const SPIRVariable &var);
Hans-Kristian Arntzen2eb60372016-05-23 14:18:00 +020057 void emit_block_struct(SPIRType &type);
Hans-Kristian Arntzen168e46f2016-05-28 13:09:26 +020058 std::string variable_decl(const SPIRType &type, const std::string &name) override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010059
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020060 std::string argument_decl(const SPIRFunction::Parameter &arg);
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010061
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020062 std::vector<std::string> resource_registrations;
63 std::string impl_type;
64 std::string resource_type;
65 uint32_t shared_counter = 0;
Hans-Kristian Arntzenc172a352016-05-30 21:45:16 +020066
67 std::string interface_name;
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020068};
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010069}
70
71#endif