Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 1 | /* |
Hans-Kristian Arntzen | 4704482 | 2021-01-14 16:07:49 +0100 | [diff] [blame] | 2 | * Copyright 2018-2021 Bradley Austin Davis |
Jon Leech | f2a6554 | 2021-05-08 01:47:48 -0700 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 OR MIT |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 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 | |
Hans-Kristian Arntzen | cf1e9e0 | 2020-11-25 15:22:08 +0100 | [diff] [blame] | 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>. |
Hans-Kristian Arntzen | cf1e9e0 | 2020-11-25 15:22:08 +0100 | [diff] [blame] | 22 | */ |
| 23 | |
Brad Davis | ee86000 | 2018-06-14 21:53:55 -0700 | [diff] [blame] | 24 | #ifndef SPIRV_CROSS_REFLECT_HPP |
| 25 | #define SPIRV_CROSS_REFLECT_HPP |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 26 | |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 27 | #include "spirv_glsl.hpp" |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 28 | #include <utility> |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 29 | |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 30 | namespace simple_json |
| 31 | { |
| 32 | class Stream; |
| 33 | } |
| 34 | |
Hans-Kristian Arntzen | 9b92e68 | 2019-03-29 10:29:44 +0100 | [diff] [blame] | 35 | namespace SPIRV_CROSS_NAMESPACE |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 36 | { |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 37 | class CompilerReflection : public CompilerGLSL |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 38 | { |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 39 | using Parent = CompilerGLSL; |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 40 | |
| 41 | public: |
Hans-Kristian Arntzen | 3fe57d3 | 2019-04-09 12:46:23 +0200 | [diff] [blame] | 42 | explicit CompilerReflection(std::vector<uint32_t> spirv_) |
Hans-Kristian Arntzen | a489ba7 | 2019-04-02 11:19:03 +0200 | [diff] [blame] | 43 | : Parent(std::move(spirv_)) |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 44 | { |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 45 | options.vulkan_semantics = true; |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 46 | } |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 47 | |
Hans-Kristian Arntzen | 5bcf02f | 2018-10-05 11:30:57 +0200 | [diff] [blame] | 48 | CompilerReflection(const uint32_t *ir_, size_t word_count) |
| 49 | : Parent(ir_, word_count) |
| 50 | { |
| 51 | options.vulkan_semantics = true; |
| 52 | } |
| 53 | |
| 54 | explicit CompilerReflection(const ParsedIR &ir_) |
| 55 | : CompilerGLSL(ir_) |
| 56 | { |
| 57 | options.vulkan_semantics = true; |
| 58 | } |
| 59 | |
| 60 | explicit CompilerReflection(ParsedIR &&ir_) |
| 61 | : CompilerGLSL(std::move(ir_)) |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 62 | { |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 63 | options.vulkan_semantics = true; |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 64 | } |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 65 | |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 66 | void set_format(const std::string &format); |
| 67 | std::string compile() override; |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 68 | |
| 69 | private: |
Brad Davis | 7620400 | 2018-06-20 10:25:38 -0700 | [diff] [blame] | 70 | static std::string execution_model_to_str(spv::ExecutionModel model); |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 71 | |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 72 | void emit_entry_points(); |
| 73 | void emit_types(); |
| 74 | void emit_resources(); |
Brad Davis | 8d84a54 | 2018-06-20 11:47:31 -0700 | [diff] [blame] | 75 | void emit_specialization_constants(); |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 76 | |
Hans-Kristian Arntzen | 58dad82 | 2020-05-25 11:05:42 +0200 | [diff] [blame] | 77 | void emit_type(uint32_t type_id, bool &emitted_open_tag); |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 78 | void emit_type_member(const SPIRType &type, uint32_t index); |
| 79 | void emit_type_member_qualifiers(const SPIRType &type, uint32_t index); |
| 80 | void emit_type_array(const SPIRType &type); |
Hans-Kristian Arntzen | a489ba7 | 2019-04-02 11:19:03 +0200 | [diff] [blame] | 81 | void emit_resources(const char *tag, const SmallVector<Resource> &resources); |
Hans-Kristian Arntzen | 58dad82 | 2020-05-25 11:05:42 +0200 | [diff] [blame] | 82 | bool type_is_reference(const SPIRType &type) const; |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 83 | |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 84 | std::string to_member_name(const SPIRType &type, uint32_t index) const; |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 85 | |
Brad Davis | 6c88b00 | 2018-06-18 09:30:16 -0700 | [diff] [blame] | 86 | std::shared_ptr<simple_json::Stream> json_stream; |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Hans-Kristian Arntzen | a489ba7 | 2019-04-02 11:19:03 +0200 | [diff] [blame] | 89 | } // namespace SPIRV_CROSS_NAMESPACE |
Brad Davis | 709d3c6 | 2018-06-03 11:16:37 -0700 | [diff] [blame] | 90 | |
| 91 | #endif |