blob: a61dc8ec3cf1c5d5a5ad1784aab02e6773c76d40 [file] [log] [blame]
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +01001/*
Bill Hollings1c947152018-01-31 17:08:43 -05002 * Copyright 2015-2018 ARM Limited
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +01003 *
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 Arntzendad4a342016-11-11 18:04:14 +010017#ifndef SPIRV_CROSS_CPP_HPP
18#define SPIRV_CROSS_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 }
Hans-Kristian Arntzen9bad4772017-04-01 16:08:19 +020033
34 CompilerCPP(const uint32_t *ir, size_t word_count)
35 : CompilerGLSL(ir, word_count)
36 {
37 }
38
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020039 std::string compile() override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010040
Hans-Kristian Arntzenc172a352016-05-30 21:45:16 +020041 // Sets a custom symbol name that can override
42 // spirv_cross_get_interface.
43 //
44 // Useful when several shader interfaces are linked
45 // statically into the same binary.
46 void set_interface_name(std::string name)
47 {
48 interface_name = std::move(name);
49 }
50
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020051private:
52 void emit_header() override;
53 void emit_c_linkage();
Hans-Kristian Arntzene8e58842018-03-12 13:09:25 +010054 void emit_function_prototype(SPIRFunction &func, const Bitset &return_flags) override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010055
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020056 void emit_resources();
rob01157dd2017-02-02 15:19:27 +090057 void emit_buffer_block(const SPIRVariable &type) override;
58 void emit_push_constant_block(const SPIRVariable &var) override;
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020059 void emit_interface_block(const SPIRVariable &type);
60 void emit_block_chain(SPIRBlock &block);
rob01157dd2017-02-02 15:19:27 +090061 void emit_uniform(const SPIRVariable &var) override;
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020062 void emit_shared(const SPIRVariable &var);
Hans-Kristian Arntzen2eb60372016-05-23 14:18:00 +020063 void emit_block_struct(SPIRType &type);
Hans-Kristian Arntzen978901f2017-06-17 10:54:59 +020064 std::string variable_decl(const SPIRType &type, const std::string &name, uint32_t id) override;
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010065
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020066 std::string argument_decl(const SPIRFunction::Parameter &arg);
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010067
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020068 std::vector<std::string> resource_registrations;
69 std::string impl_type;
70 std::string resource_type;
71 uint32_t shared_counter = 0;
Hans-Kristian Arntzenc172a352016-05-30 21:45:16 +020072
73 std::string interface_name;
Hans-Kristian Arntzen4b8ed532016-05-05 09:33:18 +020074};
Hans-Kristian Arntzen382101b2018-04-03 14:08:15 +020075} // namespace spirv_cross
Hans-Kristian Arntzen75471fb2016-03-02 18:09:16 +010076
77#endif