| 1 | /* | 
| 2 |  * Copyright 2018-2021 Bradley Austin Davis | 
| 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_REFLECT_HPP | 
| 25 | #define SPIRV_CROSS_REFLECT_HPP | 
| 26 |  | 
| 27 | #include "spirv_glsl.hpp" | 
| 28 | #include <utility> | 
| 29 |  | 
| 30 | namespace simple_json | 
| 31 | { | 
| 32 | class Stream; | 
| 33 | } | 
| 34 |  | 
| 35 | namespace SPIRV_CROSS_NAMESPACE | 
| 36 | { | 
| 37 | class CompilerReflection : public CompilerGLSL | 
| 38 | { | 
| 39 | 	using Parent = CompilerGLSL; | 
| 40 |  | 
| 41 | public: | 
| 42 | 	explicit CompilerReflection(std::vector<uint32_t> spirv_) | 
| 43 | 	    : Parent(std::move(spirv_)) | 
| 44 | 	{ | 
| 45 | 		options.vulkan_semantics = true; | 
| 46 | 	} | 
| 47 |  | 
| 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_)) | 
| 62 | 	{ | 
| 63 | 		options.vulkan_semantics = true; | 
| 64 | 	} | 
| 65 |  | 
| 66 | 	void set_format(const std::string &format); | 
| 67 | 	std::string compile() override; | 
| 68 |  | 
| 69 | private: | 
| 70 | 	static std::string execution_model_to_str(spv::ExecutionModel model); | 
| 71 |  | 
| 72 | 	void emit_entry_points(); | 
| 73 | 	void emit_types(); | 
| 74 | 	void emit_resources(); | 
| 75 | 	void emit_specialization_constants(); | 
| 76 |  | 
| 77 | 	void emit_type(uint32_t type_id, bool &emitted_open_tag); | 
| 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); | 
| 81 | 	void emit_resources(const char *tag, const SmallVector<Resource> &resources); | 
| 82 | 	bool type_is_reference(const SPIRType &type) const; | 
| 83 |  | 
| 84 | 	std::string to_member_name(const SPIRType &type, uint32_t index) const; | 
| 85 |  | 
| 86 | 	std::shared_ptr<simple_json::Stream> json_stream; | 
| 87 | }; | 
| 88 |  | 
| 89 | } // namespace SPIRV_CROSS_NAMESPACE | 
| 90 |  | 
| 91 | #endif | 
| 92 |  |