Debian Codegraph @

third_party/spirv-cross/spirv_reflect.hpp

raw
1 /*
2 * Copyright 2018-2020 Bradley Austin Davis
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_REFLECT_HPP
18 #define SPIRV_CROSS_REFLECT_HPP
19
20 #include "spirv_glsl.hpp"
21 #include <utility>
22
23 namespace simple_json
24 {
25 class Stream;
26 }
27
28 namespace SPIRV_CROSS_NAMESPACE
29 {
30 class CompilerReflection : public CompilerGLSL
31 {
32 using Parent = CompilerGLSL;
33
34 public:
35 explicit CompilerReflection(std::vector<uint32_t> spirv_)
36 : Parent(std::move(spirv_))
37 {
38 options.vulkan_semantics = true;
39 }
40
41 CompilerReflection(const uint32_t *ir_, size_t word_count)
42 : Parent(ir_, word_count)
43 {
44 options.vulkan_semantics = true;
45 }
46
47 explicit CompilerReflection(const ParsedIR &ir_)
48 : CompilerGLSL(ir_)
49 {
50 options.vulkan_semantics = true;
51 }
52
53 explicit CompilerReflection(ParsedIR &&ir_)
54 : CompilerGLSL(std::move(ir_))
55 {
56 options.vulkan_semantics = true;
57 }
58
59 void set_format(const std::string &format);
60 std::string compile() override;
61
62 private:
63 static std::string execution_model_to_str(spv::ExecutionModel model);
64
65 void emit_entry_points();
66 void emit_types();
67 void emit_resources();
68 void emit_specialization_constants();
69
70 void emit_type(uint32_t type_id, bool &emitted_open_tag);
71 void emit_type_member(const SPIRType &type, uint32_t index);
72 void emit_type_member_qualifiers(const SPIRType &type, uint32_t index);
73 void emit_type_array(const SPIRType &type);
74 void emit_resources(const char *tag, const SmallVector<Resource> &resources);
75 bool type_is_reference(const SPIRType &type) const;
76
77 std::string to_member_name(const SPIRType &type, uint32_t index) const;
78
79 std::shared_ptr<simple_json::Stream> json_stream;
80 };
81
82 } // namespace SPIRV_CROSS_NAMESPACE
83
84 #endif