RetroArch
slang_reflection.h
Go to the documentation of this file.
1 /* RetroArch - A frontend for libretro.
2  * Copyright (C) 2010-2017 - Hans-Kristian Arntzen
3  *
4  * RetroArch is free software: you can redistribute it and/or modify it under the terms
5  * of the GNU General Public License as published by the Free Software Found-
6  * ation, either version 3 of the License, or (at your option) any later version.
7  *
8  * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  * PURPOSE. See the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along with RetroArch.
13  * If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #ifndef SLANG_REFLECTION_H_
17 #define SLANG_REFLECTION_H_
18 
19 // Textures with built-in meaning.
21 {
22  // The input texture to the filter chain.
23  // Canonical name: "Original".
25 
26  // The output from pass N - 1 if executing pass N, or ORIGINAL
27  // if pass #0 is executed.
28  // Canonical name: "Source".
30 
31  // The original inputs with a history back in time.
32  // Canonical name: "OriginalHistory#", e.g. "OriginalHistory2" <- Two frames back.
33  // "OriginalHistory0" is an alias for SEMANTIC_ORIGINAL.
34  // Size name: "OriginalHistorySize#".
36 
37  // The output from pass #N, where pass #0 is the first pass.
38  // Canonical name: "PassOutput#", e.g. "PassOutput3".
39  // Size name: "PassOutputSize#".
41 
42  // The output from pass #N, one frame ago where pass #0 is the first pass.
43  // It is not valid to use the pass feedback from a pass which is not offscreen.
44  // Canonical name: "PassFeedback#", e.g. "PassFeedback2".
46 
47  // Inputs from static textures, defined by the user.
48  // There is no canonical name, and the only way to use these semantics are by
49  // remapping.
51 
54 };
55 
57 {
58  // mat4, MVP
60  // vec4, viewport size of current pass
62  // vec4, viewport size of final pass
64  // uint, frame count with modulo
67 
68  // float, user defined parameter, arrayed
70 
73 };
74 
76 {
79 };
80 
82 {
86 };
87 
88 /* Vulkan minimum limit. */
89 #define SLANG_NUM_BINDINGS 16
90 
91 #ifdef __cplusplus
92 
93 #include <string>
94 #include <unordered_map>
95 #include <stdint.h>
96 #include <spirv_cross.hpp>
97 
98 struct slang_texture_semantic_meta
99 {
100  size_t ubo_offset = 0;
101  size_t push_constant_offset = 0;
102  unsigned binding = 0;
103  uint32_t stage_mask = 0;
104 
105  bool texture = false;
106  bool uniform = false;
107  bool push_constant = false;
108 };
109 
110 struct slang_semantic_meta
111 {
112  size_t ubo_offset = 0;
113  size_t push_constant_offset = 0;
114  unsigned num_components = 0;
115  bool uniform = false;
116  bool push_constant = false;
117 };
118 
119 struct slang_texture_semantic_map
120 {
121  slang_texture_semantic semantic;
122  unsigned index;
123 };
124 
125 struct slang_semantic_map
126 {
127  slang_semantic semantic;
128  unsigned index;
129 };
130 
131 struct slang_reflection
132 {
133  slang_reflection();
134 
135  size_t ubo_size = 0;
136  size_t push_constant_size = 0;
137 
138  unsigned ubo_binding = 0;
139  uint32_t ubo_stage_mask = 0;
140  uint32_t push_constant_stage_mask = 0;
141 
142  std::vector<slang_texture_semantic_meta> semantic_textures[SLANG_NUM_TEXTURE_SEMANTICS];
143  slang_semantic_meta semantics[SLANG_NUM_SEMANTICS];
144  std::vector<slang_semantic_meta> semantic_float_parameters;
145 
146  const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_map = nullptr;
147  const std::unordered_map<std::string, slang_texture_semantic_map> *texture_semantic_uniform_map = nullptr;
148  const std::unordered_map<std::string, slang_semantic_map> *semantic_map = nullptr;
149  unsigned pass_number = 0;
150 };
151 
152 bool slang_reflect_spirv(const std::vector<uint32_t> &vertex,
153  const std::vector<uint32_t> &fragment,
154  slang_reflection *reflection);
155 
156 bool slang_reflect(const spirv_cross::Compiler &vertex_compiler, const spirv_cross::Compiler &fragment_compiler,
157  const spirv_cross::ShaderResources &vertex, const spirv_cross::ShaderResources &fragment,
158  slang_reflection *reflection);
159 
160 #endif
161 #endif
162 
Definition: slang_reflection.h:29
Definition: spirv_cross.hpp:55
slang_stage
Definition: slang_reflection.h:75
bool slang_reflect_spirv(const std::vector< uint32_t > &vertex, const std::vector< uint32_t > &fragment, slang_reflection *reflection)
Definition: slang_reflection.cpp:654
Definition: spirv_cross.hpp:117
Definition: slang_reflection.h:59
Definition: slang_reflection.h:71
Definition: slang_reflection.h:61
slang_semantic
Definition: slang_reflection.h:56
Definition: slang_reflection.h:66
Definition: slang_reflection.h:77
Definition: slang_reflection.h:72
Definition: slang_reflection.h:69
Definition: slang_reflection.h:78
slang_texture_semantic
Definition: slang_reflection.h:20
Definition: slang_reflection.h:52
Definition: slang_reflection.h:83
bool slang_reflect(const Compiler &vertex_compiler, const Compiler &fragment_compiler, const ShaderResources &vertex, const ShaderResources &fragment, slang_reflection *reflection)
Definition: slang_reflection.cpp:364
Definition: slang_reflection.h:85
GLuint index
Definition: glext.h:6671
Definition: slang_reflection.h:65
Definition: slang_reflection.h:35
Definition: slang_reflection.h:40
slang_constant_buffer
Definition: slang_reflection.h:81
Definition: slang_reflection.h:84
Definition: metal_common.m:516
Definition: slang_reflection.h:24
Definition: slang_reflection.h:53
Definition: slang_reflection.h:63
Definition: slang_reflection.h:45
unsigned int uint32_t
Definition: stdint.h:126
Definition: slang_reflection.h:50