1/*
2 Copyright 2017-2022 Google Inc.
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/*
18
19VERSION HISTORY
20
21 1.0 (2018-03-27) Initial public release
22
23*/
24
25/*!
26
27 @file spirv_reflect.h
28
29*/
30#ifndef SPIRV_REFLECT_H
31#define SPIRV_REFLECT_H
32
33#if defined(SPIRV_REFLECT_USE_SYSTEM_SPIRV_H)
34#include <spirv/unified1/spirv.h>
35#else
36#include "./include/spirv/unified1/spirv.h"
37#endif
38
39
40#include <stdint.h>
41#include <string.h>
42
43#ifdef _MSC_VER
44 #define SPV_REFLECT_DEPRECATED(msg_str) __declspec(deprecated("This symbol is deprecated. Details: " msg_str))
45#elif defined(__clang__)
46 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated(msg_str)))
47#elif defined(__GNUC__)
48 #if GCC_VERSION >= 40500
49 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated(msg_str)))
50 #else
51 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated))
52 #endif
53#else
54 #define SPV_REFLECT_DEPRECATED(msg_str)
55#endif
56
57/*! @enum SpvReflectResult
58
59*/
60typedef enum SpvReflectResult {
61 SPV_REFLECT_RESULT_SUCCESS,
62 SPV_REFLECT_RESULT_NOT_READY,
63 SPV_REFLECT_RESULT_ERROR_PARSE_FAILED,
64 SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED,
65 SPV_REFLECT_RESULT_ERROR_RANGE_EXCEEDED,
66 SPV_REFLECT_RESULT_ERROR_NULL_POINTER,
67 SPV_REFLECT_RESULT_ERROR_INTERNAL_ERROR,
68 SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH,
69 SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND,
70 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_CODE_SIZE,
71 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_MAGIC_NUMBER,
72 SPV_REFLECT_RESULT_ERROR_SPIRV_UNEXPECTED_EOF,
73 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE,
74 SPV_REFLECT_RESULT_ERROR_SPIRV_SET_NUMBER_OVERFLOW,
75 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_STORAGE_CLASS,
76 SPV_REFLECT_RESULT_ERROR_SPIRV_RECURSION,
77 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_INSTRUCTION,
78 SPV_REFLECT_RESULT_ERROR_SPIRV_UNEXPECTED_BLOCK_DATA,
79 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_BLOCK_MEMBER_REFERENCE,
80 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ENTRY_POINT,
81 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_EXECUTION_MODE,
82} SpvReflectResult;
83
84/*! @enum SpvReflectModuleFlagBits
85
86SPV_REFLECT_MODULE_FLAG_NO_COPY - Disables copying of SPIR-V code
87 when a SPIRV-Reflect shader module is created. It is the
88 responsibility of the calling program to ensure that the pointer
89 remains valid and the memory it's pointing to is not freed while
90 SPIRV-Reflect operations are taking place. Freeing the backing
91 memory will cause undefined behavior or most likely a crash.
92 This is flag is intended for cases where the memory overhead of
93 storing the copied SPIR-V is undesirable.
94
95*/
96typedef enum SpvReflectModuleFlagBits {
97 SPV_REFLECT_MODULE_FLAG_NONE = 0x00000000,
98 SPV_REFLECT_MODULE_FLAG_NO_COPY = 0x00000001,
99} SpvReflectModuleFlagBits;
100
101typedef uint32_t SpvReflectModuleFlags;
102
103/*! @enum SpvReflectTypeFlagBits
104
105*/
106typedef enum SpvReflectTypeFlagBits {
107 SPV_REFLECT_TYPE_FLAG_UNDEFINED = 0x00000000,
108 SPV_REFLECT_TYPE_FLAG_VOID = 0x00000001,
109 SPV_REFLECT_TYPE_FLAG_BOOL = 0x00000002,
110 SPV_REFLECT_TYPE_FLAG_INT = 0x00000004,
111 SPV_REFLECT_TYPE_FLAG_FLOAT = 0x00000008,
112 SPV_REFLECT_TYPE_FLAG_VECTOR = 0x00000100,
113 SPV_REFLECT_TYPE_FLAG_MATRIX = 0x00000200,
114 SPV_REFLECT_TYPE_FLAG_EXTERNAL_IMAGE = 0x00010000,
115 SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLER = 0x00020000,
116 SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLED_IMAGE = 0x00040000,
117 SPV_REFLECT_TYPE_FLAG_EXTERNAL_BLOCK = 0x00080000,
118 SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE = 0x00100000,
119 SPV_REFLECT_TYPE_FLAG_EXTERNAL_MASK = 0x00FF0000,
120 SPV_REFLECT_TYPE_FLAG_STRUCT = 0x10000000,
121 SPV_REFLECT_TYPE_FLAG_ARRAY = 0x20000000,
122} SpvReflectTypeFlagBits;
123
124typedef uint32_t SpvReflectTypeFlags;
125
126/*! @enum SpvReflectDecorationBits
127
128NOTE: HLSL row_major and column_major decorations are reversed
129 in SPIR-V. Meaning that matrices declrations with row_major
130 will get reflected as column_major and vice versa. The
131 row and column decorations get appied during the compilation.
132 SPIRV-Reflect reads the data as is and does not make any
133 attempt to correct it to match what's in the source.
134
135*/
136typedef enum SpvReflectDecorationFlagBits {
137 SPV_REFLECT_DECORATION_NONE = 0x00000000,
138 SPV_REFLECT_DECORATION_BLOCK = 0x00000001,
139 SPV_REFLECT_DECORATION_BUFFER_BLOCK = 0x00000002,
140 SPV_REFLECT_DECORATION_ROW_MAJOR = 0x00000004,
141 SPV_REFLECT_DECORATION_COLUMN_MAJOR = 0x00000008,
142 SPV_REFLECT_DECORATION_BUILT_IN = 0x00000010,
143 SPV_REFLECT_DECORATION_NOPERSPECTIVE = 0x00000020,
144 SPV_REFLECT_DECORATION_FLAT = 0x00000040,
145 SPV_REFLECT_DECORATION_NON_WRITABLE = 0x00000080,
146 SPV_REFLECT_DECORATION_RELAXED_PRECISION = 0x00000100,
147 SPV_REFLECT_DECORATION_NON_READABLE = 0x00000200,
148} SpvReflectDecorationFlagBits;
149
150typedef uint32_t SpvReflectDecorationFlags;
151
152/*! @enum SpvReflectResourceType
153
154*/
155typedef enum SpvReflectResourceType {
156 SPV_REFLECT_RESOURCE_FLAG_UNDEFINED = 0x00000000,
157 SPV_REFLECT_RESOURCE_FLAG_SAMPLER = 0x00000001,
158 SPV_REFLECT_RESOURCE_FLAG_CBV = 0x00000002,
159 SPV_REFLECT_RESOURCE_FLAG_SRV = 0x00000004,
160 SPV_REFLECT_RESOURCE_FLAG_UAV = 0x00000008,
161} SpvReflectResourceType;
162
163/*! @enum SpvReflectFormat
164
165*/
166typedef enum SpvReflectFormat {
167 SPV_REFLECT_FORMAT_UNDEFINED = 0, // = VK_FORMAT_UNDEFINED
168 SPV_REFLECT_FORMAT_R32_UINT = 98, // = VK_FORMAT_R32_UINT
169 SPV_REFLECT_FORMAT_R32_SINT = 99, // = VK_FORMAT_R32_SINT
170 SPV_REFLECT_FORMAT_R32_SFLOAT = 100, // = VK_FORMAT_R32_SFLOAT
171 SPV_REFLECT_FORMAT_R32G32_UINT = 101, // = VK_FORMAT_R32G32_UINT
172 SPV_REFLECT_FORMAT_R32G32_SINT = 102, // = VK_FORMAT_R32G32_SINT
173 SPV_REFLECT_FORMAT_R32G32_SFLOAT = 103, // = VK_FORMAT_R32G32_SFLOAT
174 SPV_REFLECT_FORMAT_R32G32B32_UINT = 104, // = VK_FORMAT_R32G32B32_UINT
175 SPV_REFLECT_FORMAT_R32G32B32_SINT = 105, // = VK_FORMAT_R32G32B32_SINT
176 SPV_REFLECT_FORMAT_R32G32B32_SFLOAT = 106, // = VK_FORMAT_R32G32B32_SFLOAT
177 SPV_REFLECT_FORMAT_R32G32B32A32_UINT = 107, // = VK_FORMAT_R32G32B32A32_UINT
178 SPV_REFLECT_FORMAT_R32G32B32A32_SINT = 108, // = VK_FORMAT_R32G32B32A32_SINT
179 SPV_REFLECT_FORMAT_R32G32B32A32_SFLOAT = 109, // = VK_FORMAT_R32G32B32A32_SFLOAT
180 SPV_REFLECT_FORMAT_R64_UINT = 110, // = VK_FORMAT_R64_UINT
181 SPV_REFLECT_FORMAT_R64_SINT = 111, // = VK_FORMAT_R64_SINT
182 SPV_REFLECT_FORMAT_R64_SFLOAT = 112, // = VK_FORMAT_R64_SFLOAT
183 SPV_REFLECT_FORMAT_R64G64_UINT = 113, // = VK_FORMAT_R64G64_UINT
184 SPV_REFLECT_FORMAT_R64G64_SINT = 114, // = VK_FORMAT_R64G64_SINT
185 SPV_REFLECT_FORMAT_R64G64_SFLOAT = 115, // = VK_FORMAT_R64G64_SFLOAT
186 SPV_REFLECT_FORMAT_R64G64B64_UINT = 116, // = VK_FORMAT_R64G64B64_UINT
187 SPV_REFLECT_FORMAT_R64G64B64_SINT = 117, // = VK_FORMAT_R64G64B64_SINT
188 SPV_REFLECT_FORMAT_R64G64B64_SFLOAT = 118, // = VK_FORMAT_R64G64B64_SFLOAT
189 SPV_REFLECT_FORMAT_R64G64B64A64_UINT = 119, // = VK_FORMAT_R64G64B64A64_UINT
190 SPV_REFLECT_FORMAT_R64G64B64A64_SINT = 120, // = VK_FORMAT_R64G64B64A64_SINT
191 SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT = 121, // = VK_FORMAT_R64G64B64A64_SFLOAT
192} SpvReflectFormat;
193
194/*! @enum SpvReflectVariableFlagBits
195
196*/
197enum SpvReflectVariableFlagBits{
198 SPV_REFLECT_VARIABLE_FLAGS_NONE = 0x00000000,
199 SPV_REFLECT_VARIABLE_FLAGS_UNUSED = 0x00000001,
200};
201
202typedef uint32_t SpvReflectVariableFlags;
203
204/*! @enum SpvReflectDescriptorType
205
206*/
207typedef enum SpvReflectDescriptorType {
208 SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER = 0, // = VK_DESCRIPTOR_TYPE_SAMPLER
209 SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER = 1, // = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
210 SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE = 2, // = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
211 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE = 3, // = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
212 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER = 4, // = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
213 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER = 5, // = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
214 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER = 6, // = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
215 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER = 7, // = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
216 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC = 8, // = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
217 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC = 9, // = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
218 SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT = 10, // = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
219 SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR = 1000150000 // = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR
220} SpvReflectDescriptorType;
221
222/*! @enum SpvReflectShaderStageFlagBits
223
224*/
225typedef enum SpvReflectShaderStageFlagBits {
226 SPV_REFLECT_SHADER_STAGE_VERTEX_BIT = 0x00000001, // = VK_SHADER_STAGE_VERTEX_BIT
227 SPV_REFLECT_SHADER_STAGE_TESSELLATION_CONTROL_BIT = 0x00000002, // = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
228 SPV_REFLECT_SHADER_STAGE_TESSELLATION_EVALUATION_BIT = 0x00000004, // = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
229 SPV_REFLECT_SHADER_STAGE_GEOMETRY_BIT = 0x00000008, // = VK_SHADER_STAGE_GEOMETRY_BIT
230 SPV_REFLECT_SHADER_STAGE_FRAGMENT_BIT = 0x00000010, // = VK_SHADER_STAGE_FRAGMENT_BIT
231 SPV_REFLECT_SHADER_STAGE_COMPUTE_BIT = 0x00000020, // = VK_SHADER_STAGE_COMPUTE_BIT
232 SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV = 0x00000040, // = VK_SHADER_STAGE_TASK_BIT_NV
233 SPV_REFLECT_SHADER_STAGE_TASK_BIT_EXT = SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV, // = VK_SHADER_STAGE_CALLABLE_BIT_EXT
234 SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV = 0x00000080, // = VK_SHADER_STAGE_MESH_BIT_NV
235 SPV_REFLECT_SHADER_STAGE_MESH_BIT_EXT = SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV, // = VK_SHADER_STAGE_CALLABLE_BIT_EXT
236 SPV_REFLECT_SHADER_STAGE_RAYGEN_BIT_KHR = 0x00000100, // = VK_SHADER_STAGE_RAYGEN_BIT_KHR
237 SPV_REFLECT_SHADER_STAGE_ANY_HIT_BIT_KHR = 0x00000200, // = VK_SHADER_STAGE_ANY_HIT_BIT_KHR
238 SPV_REFLECT_SHADER_STAGE_CLOSEST_HIT_BIT_KHR = 0x00000400, // = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
239 SPV_REFLECT_SHADER_STAGE_MISS_BIT_KHR = 0x00000800, // = VK_SHADER_STAGE_MISS_BIT_KHR
240 SPV_REFLECT_SHADER_STAGE_INTERSECTION_BIT_KHR = 0x00001000, // = VK_SHADER_STAGE_INTERSECTION_BIT_KHR
241 SPV_REFLECT_SHADER_STAGE_CALLABLE_BIT_KHR = 0x00002000, // = VK_SHADER_STAGE_CALLABLE_BIT_KHR
242
243} SpvReflectShaderStageFlagBits;
244
245/*! @enum SpvReflectGenerator
246
247*/
248typedef enum SpvReflectGenerator {
249 SPV_REFLECT_GENERATOR_KHRONOS_LLVM_SPIRV_TRANSLATOR = 6,
250 SPV_REFLECT_GENERATOR_KHRONOS_SPIRV_TOOLS_ASSEMBLER = 7,
251 SPV_REFLECT_GENERATOR_KHRONOS_GLSLANG_REFERENCE_FRONT_END = 8,
252 SPV_REFLECT_GENERATOR_GOOGLE_SHADERC_OVER_GLSLANG = 13,
253 SPV_REFLECT_GENERATOR_GOOGLE_SPIREGG = 14,
254 SPV_REFLECT_GENERATOR_GOOGLE_RSPIRV = 15,
255 SPV_REFLECT_GENERATOR_X_LEGEND_MESA_MESAIR_SPIRV_TRANSLATOR = 16,
256 SPV_REFLECT_GENERATOR_KHRONOS_SPIRV_TOOLS_LINKER = 17,
257 SPV_REFLECT_GENERATOR_WINE_VKD3D_SHADER_COMPILER = 18,
258 SPV_REFLECT_GENERATOR_CLAY_CLAY_SHADER_COMPILER = 19,
259} SpvReflectGenerator;
260
261enum {
262 SPV_REFLECT_MAX_ARRAY_DIMS = 32,
263 SPV_REFLECT_MAX_DESCRIPTOR_SETS = 64,
264};
265
266enum {
267 SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE = ~0,
268 SPV_REFLECT_SET_NUMBER_DONT_CHANGE = ~0
269};
270
271typedef struct SpvReflectNumericTraits {
272 struct Scalar {
273 uint32_t width;
274 uint32_t signedness;
275 } scalar;
276
277 struct Vector {
278 uint32_t component_count;
279 } vector;
280
281 struct Matrix {
282 uint32_t column_count;
283 uint32_t row_count;
284 uint32_t stride; // Measured in bytes
285 } matrix;
286} SpvReflectNumericTraits;
287
288typedef struct SpvReflectImageTraits {
289 SpvDim dim;
290 uint32_t depth;
291 uint32_t arrayed;
292 uint32_t ms; // 0: single-sampled; 1: multisampled
293 uint32_t sampled;
294 SpvImageFormat image_format;
295} SpvReflectImageTraits;
296
297typedef struct SpvReflectArrayTraits {
298 uint32_t dims_count;
299 // Each entry is: 0xFFFFFFFF for a specialization constant dimension,
300 // 0 for a runtime array dimension, and the array length otherwise.
301 uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS];
302 // Stores Ids for dimensions that are specialization constants
303 uint32_t spec_constant_op_ids[SPV_REFLECT_MAX_ARRAY_DIMS];
304 uint32_t stride; // Measured in bytes
305} SpvReflectArrayTraits;
306
307typedef struct SpvReflectBindingArrayTraits {
308 uint32_t dims_count;
309 uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS];
310} SpvReflectBindingArrayTraits;
311
312/*! @struct SpvReflectTypeDescription
313
314*/
315typedef struct SpvReflectTypeDescription {
316 uint32_t id;
317 SpvOp op;
318 const char* type_name;
319 const char* struct_member_name;
320 SpvStorageClass storage_class;
321 SpvReflectTypeFlags type_flags;
322 SpvReflectDecorationFlags decoration_flags;
323
324 struct Traits {
325 SpvReflectNumericTraits numeric;
326 SpvReflectImageTraits image;
327 SpvReflectArrayTraits array;
328 } traits;
329
330 uint32_t member_count;
331 struct SpvReflectTypeDescription* members;
332} SpvReflectTypeDescription;
333
334// -- GODOT begin --
335/*! @struct SpvReflectSpecializationConstant
336
337*/
338
339typedef enum SpvReflectSpecializationConstantType {
340 SPV_REFLECT_SPECIALIZATION_CONSTANT_BOOL = 0,
341 SPV_REFLECT_SPECIALIZATION_CONSTANT_INT = 1,
342 SPV_REFLECT_SPECIALIZATION_CONSTANT_FLOAT = 2,
343} SpvReflectSpecializationConstantType;
344
345typedef struct SpvReflectSpecializationConstant {
346 const char* name;
347 uint32_t spirv_id;
348 uint32_t constant_id;
349 SpvReflectSpecializationConstantType constant_type;
350 union {
351 float float_value;
352 uint32_t int_bool_value;
353 } default_value;
354} SpvReflectSpecializationConstant;
355// -- GODOT end --
356
357/*! @struct SpvReflectInterfaceVariable
358
359*/
360typedef struct SpvReflectInterfaceVariable {
361 uint32_t spirv_id;
362 const char* name;
363 uint32_t location;
364 SpvStorageClass storage_class;
365 const char* semantic;
366 SpvReflectDecorationFlags decoration_flags;
367 SpvBuiltIn built_in;
368 SpvReflectNumericTraits numeric;
369 SpvReflectArrayTraits array;
370
371 uint32_t member_count;
372 struct SpvReflectInterfaceVariable* members;
373
374 SpvReflectFormat format;
375
376 // NOTE: SPIR-V shares type references for variables
377 // that have the same underlying type. This means
378 // that the same type name will appear for multiple
379 // variables.
380 SpvReflectTypeDescription* type_description;
381
382 struct {
383 uint32_t location;
384 } word_offset;
385} SpvReflectInterfaceVariable;
386
387/*! @struct SpvReflectBlockVariable
388
389*/
390typedef struct SpvReflectBlockVariable {
391 uint32_t spirv_id;
392 const char* name;
393 uint32_t offset; // Measured in bytes
394 uint32_t absolute_offset; // Measured in bytes
395 uint32_t size; // Measured in bytes
396 uint32_t padded_size; // Measured in bytes
397 SpvReflectDecorationFlags decoration_flags;
398 SpvReflectNumericTraits numeric;
399 SpvReflectArrayTraits array;
400 SpvReflectVariableFlags flags;
401
402 uint32_t member_count;
403 struct SpvReflectBlockVariable* members;
404
405 SpvReflectTypeDescription* type_description;
406
407 struct {
408 uint32_t offset;
409 } word_offset;
410
411} SpvReflectBlockVariable;
412
413/*! @struct SpvReflectDescriptorBinding
414
415*/
416typedef struct SpvReflectDescriptorBinding {
417 uint32_t spirv_id;
418 const char* name;
419 uint32_t binding;
420 uint32_t input_attachment_index;
421 uint32_t set;
422 SpvReflectDescriptorType descriptor_type;
423 SpvReflectResourceType resource_type;
424 SpvReflectImageTraits image;
425 SpvReflectBlockVariable block;
426 SpvReflectBindingArrayTraits array;
427 uint32_t count;
428 uint32_t accessed;
429 uint32_t uav_counter_id;
430 struct SpvReflectDescriptorBinding* uav_counter_binding;
431
432 SpvReflectTypeDescription* type_description;
433
434 struct {
435 uint32_t binding;
436 uint32_t set;
437 } word_offset;
438
439 SpvReflectDecorationFlags decoration_flags;
440} SpvReflectDescriptorBinding;
441
442/*! @struct SpvReflectDescriptorSet
443
444*/
445typedef struct SpvReflectDescriptorSet {
446 uint32_t set;
447 uint32_t binding_count;
448 SpvReflectDescriptorBinding** bindings;
449} SpvReflectDescriptorSet;
450
451/*! @struct SpvReflectEntryPoint
452
453 */
454typedef struct SpvReflectEntryPoint {
455 const char* name;
456 uint32_t id;
457
458 SpvExecutionModel spirv_execution_model;
459 SpvReflectShaderStageFlagBits shader_stage;
460
461 uint32_t input_variable_count;
462 SpvReflectInterfaceVariable** input_variables;
463 uint32_t output_variable_count;
464 SpvReflectInterfaceVariable** output_variables;
465 uint32_t interface_variable_count;
466 SpvReflectInterfaceVariable* interface_variables;
467
468 uint32_t descriptor_set_count;
469 SpvReflectDescriptorSet* descriptor_sets;
470
471 uint32_t used_uniform_count;
472 uint32_t* used_uniforms;
473 uint32_t used_push_constant_count;
474 uint32_t* used_push_constants;
475
476 uint32_t execution_mode_count;
477 SpvExecutionMode* execution_modes;
478
479 struct LocalSize {
480 uint32_t x;
481 uint32_t y;
482 uint32_t z;
483 } local_size;
484 uint32_t invocations; // valid for geometry
485 uint32_t output_vertices; // valid for geometry, tesselation
486} SpvReflectEntryPoint;
487
488/*! @struct SpvReflectCapability
489
490*/
491typedef struct SpvReflectCapability {
492 SpvCapability value;
493 uint32_t word_offset;
494} SpvReflectCapability;
495
496/*! @struct SpvReflectShaderModule
497
498*/
499typedef struct SpvReflectShaderModule {
500 SpvReflectGenerator generator;
501 const char* entry_point_name;
502 uint32_t entry_point_id;
503 uint32_t entry_point_count;
504 SpvReflectEntryPoint* entry_points;
505 SpvSourceLanguage source_language;
506 uint32_t source_language_version;
507 const char* source_file;
508 const char* source_source;
509 uint32_t capability_count;
510 SpvReflectCapability* capabilities;
511 SpvExecutionModel spirv_execution_model; // Uses value(s) from first entry point
512 SpvReflectShaderStageFlagBits shader_stage; // Uses value(s) from first entry point
513 uint32_t descriptor_binding_count; // Uses value(s) from first entry point
514 SpvReflectDescriptorBinding* descriptor_bindings; // Uses value(s) from first entry point
515 uint32_t descriptor_set_count; // Uses value(s) from first entry point
516 SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS]; // Uses value(s) from first entry point
517 uint32_t input_variable_count; // Uses value(s) from first entry point
518 SpvReflectInterfaceVariable** input_variables; // Uses value(s) from first entry point
519 uint32_t output_variable_count; // Uses value(s) from first entry point
520 SpvReflectInterfaceVariable** output_variables; // Uses value(s) from first entry point
521 uint32_t interface_variable_count; // Uses value(s) from first entry point
522 SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
523 uint32_t push_constant_block_count; // Uses value(s) from first entry point
524 SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
525 // -- GODOT begin --
526 uint32_t specialization_constant_count;
527 SpvReflectSpecializationConstant* specialization_constants;
528 // -- GODOT end --
529
530 struct Internal {
531 SpvReflectModuleFlags module_flags;
532 size_t spirv_size;
533 uint32_t* spirv_code;
534 uint32_t spirv_word_count;
535
536 size_t type_description_count;
537 SpvReflectTypeDescription* type_descriptions;
538 } * _internal;
539
540} SpvReflectShaderModule;
541
542#if defined(__cplusplus)
543extern "C" {
544#endif
545
546/*! @fn spvReflectCreateShaderModule
547
548 @param size Size in bytes of SPIR-V code.
549 @param p_code Pointer to SPIR-V code.
550 @param p_module Pointer to an instance of SpvReflectShaderModule.
551 @return SPV_REFLECT_RESULT_SUCCESS on success.
552
553*/
554SpvReflectResult spvReflectCreateShaderModule(
555 size_t size,
556 const void* p_code,
557 SpvReflectShaderModule* p_module
558);
559
560/*! @fn spvReflectCreateShaderModule2
561
562 @param flags Flags for module creations.
563 @param size Size in bytes of SPIR-V code.
564 @param p_code Pointer to SPIR-V code.
565 @param p_module Pointer to an instance of SpvReflectShaderModule.
566 @return SPV_REFLECT_RESULT_SUCCESS on success.
567
568*/
569SpvReflectResult spvReflectCreateShaderModule2(
570 SpvReflectModuleFlags flags,
571 size_t size,
572 const void* p_code,
573 SpvReflectShaderModule* p_module
574);
575
576SPV_REFLECT_DEPRECATED("renamed to spvReflectCreateShaderModule")
577SpvReflectResult spvReflectGetShaderModule(
578 size_t size,
579 const void* p_code,
580 SpvReflectShaderModule* p_module
581);
582
583
584/*! @fn spvReflectDestroyShaderModule
585
586 @param p_module Pointer to an instance of SpvReflectShaderModule.
587
588*/
589void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module);
590
591
592/*! @fn spvReflectGetCodeSize
593
594 @param p_module Pointer to an instance of SpvReflectShaderModule.
595 @return Returns the size of the SPIR-V in bytes
596
597*/
598uint32_t spvReflectGetCodeSize(const SpvReflectShaderModule* p_module);
599
600
601/*! @fn spvReflectGetCode
602
603 @param p_module Pointer to an instance of SpvReflectShaderModule.
604 @return Returns a const pointer to the compiled SPIR-V bytecode.
605
606*/
607const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module);
608
609/*! @fn spvReflectGetEntryPoint
610
611 @param p_module Pointer to an instance of SpvReflectShaderModule.
612 @param entry_point Name of the requested entry point.
613 @return Returns a const pointer to the requested entry point,
614 or NULL if it's not found.
615*/
616const SpvReflectEntryPoint* spvReflectGetEntryPoint(
617 const SpvReflectShaderModule* p_module,
618 const char* entry_point
619);
620
621/*! @fn spvReflectEnumerateDescriptorBindings
622
623 @param p_module Pointer to an instance of SpvReflectShaderModule.
624 @param p_count If pp_bindings is NULL, the module's descriptor binding
625 count (across all descriptor sets) will be stored here.
626 If pp_bindings is not NULL, *p_count must contain the
627 module's descriptor binding count.
628 @param pp_bindings If NULL, the module's total descriptor binding count
629 will be written to *p_count.
630 If non-NULL, pp_bindings must point to an array with
631 *p_count entries, where pointers to the module's
632 descriptor bindings will be written. The caller must not
633 free the binding pointers written to this array.
634 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
635 Otherwise, the error code indicates the cause of the
636 failure.
637
638*/
639SpvReflectResult spvReflectEnumerateDescriptorBindings(
640 const SpvReflectShaderModule* p_module,
641 uint32_t* p_count,
642 SpvReflectDescriptorBinding** pp_bindings
643);
644
645/*! @fn spvReflectEnumerateEntryPointDescriptorBindings
646 @brief Creates a listing of all descriptor bindings that are used in the
647 static call tree of the given entry point.
648 @param p_module Pointer to an instance of SpvReflectShaderModule.
649 @param entry_point The name of the entry point to get the descriptor bindings for.
650 @param p_count If pp_bindings is NULL, the entry point's descriptor binding
651 count (across all descriptor sets) will be stored here.
652 If pp_bindings is not NULL, *p_count must contain the
653 entry points's descriptor binding count.
654 @param pp_bindings If NULL, the entry point's total descriptor binding count
655 will be written to *p_count.
656 If non-NULL, pp_bindings must point to an array with
657 *p_count entries, where pointers to the entry point's
658 descriptor bindings will be written. The caller must not
659 free the binding pointers written to this array.
660 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
661 Otherwise, the error code indicates the cause of the
662 failure.
663
664*/
665SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings(
666 const SpvReflectShaderModule* p_module,
667 const char* entry_point,
668 uint32_t* p_count,
669 SpvReflectDescriptorBinding** pp_bindings
670);
671
672/*! @fn spvReflectEnumerateDescriptorSets
673
674 @param p_module Pointer to an instance of SpvReflectShaderModule.
675 @param p_count If pp_sets is NULL, the module's descriptor set
676 count will be stored here.
677 If pp_sets is not NULL, *p_count must contain the
678 module's descriptor set count.
679 @param pp_sets If NULL, the module's total descriptor set count
680 will be written to *p_count.
681 If non-NULL, pp_sets must point to an array with
682 *p_count entries, where pointers to the module's
683 descriptor sets will be written. The caller must not
684 free the descriptor set pointers written to this array.
685 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
686 Otherwise, the error code indicates the cause of the
687 failure.
688
689*/
690SpvReflectResult spvReflectEnumerateDescriptorSets(
691 const SpvReflectShaderModule* p_module,
692 uint32_t* p_count,
693 SpvReflectDescriptorSet** pp_sets
694);
695
696/*! @fn spvReflectEnumerateEntryPointDescriptorSets
697 @brief Creates a listing of all descriptor sets and their bindings that are
698 used in the static call tree of a given entry point.
699 @param p_module Pointer to an instance of SpvReflectShaderModule.
700 @param entry_point The name of the entry point to get the descriptor bindings for.
701 @param p_count If pp_sets is NULL, the module's descriptor set
702 count will be stored here.
703 If pp_sets is not NULL, *p_count must contain the
704 module's descriptor set count.
705 @param pp_sets If NULL, the module's total descriptor set count
706 will be written to *p_count.
707 If non-NULL, pp_sets must point to an array with
708 *p_count entries, where pointers to the module's
709 descriptor sets will be written. The caller must not
710 free the descriptor set pointers written to this array.
711 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
712 Otherwise, the error code indicates the cause of the
713 failure.
714
715*/
716SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets(
717 const SpvReflectShaderModule* p_module,
718 const char* entry_point,
719 uint32_t* p_count,
720 SpvReflectDescriptorSet** pp_sets
721);
722
723
724/*! @fn spvReflectEnumerateInterfaceVariables
725 @brief If the module contains multiple entry points, this will only get
726 the interface variables for the first one.
727 @param p_module Pointer to an instance of SpvReflectShaderModule.
728 @param p_count If pp_variables is NULL, the module's interface variable
729 count will be stored here.
730 If pp_variables is not NULL, *p_count must contain
731 the module's interface variable count.
732 @param pp_variables If NULL, the module's interface variable count will be
733 written to *p_count.
734 If non-NULL, pp_variables must point to an array with
735 *p_count entries, where pointers to the module's
736 interface variables will be written. The caller must not
737 free the interface variables written to this array.
738 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
739 Otherwise, the error code indicates the cause of the
740 failure.
741
742*/
743SpvReflectResult spvReflectEnumerateInterfaceVariables(
744 const SpvReflectShaderModule* p_module,
745 uint32_t* p_count,
746 SpvReflectInterfaceVariable** pp_variables
747);
748
749/*! @fn spvReflectEnumerateEntryPointInterfaceVariables
750 @brief Enumerate the interface variables for a given entry point.
751 @param entry_point The name of the entry point to get the interface variables for.
752 @param p_module Pointer to an instance of SpvReflectShaderModule.
753 @param p_count If pp_variables is NULL, the entry point's interface variable
754 count will be stored here.
755 If pp_variables is not NULL, *p_count must contain
756 the entry point's interface variable count.
757 @param pp_variables If NULL, the entry point's interface variable count will be
758 written to *p_count.
759 If non-NULL, pp_variables must point to an array with
760 *p_count entries, where pointers to the entry point's
761 interface variables will be written. The caller must not
762 free the interface variables written to this array.
763 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
764 Otherwise, the error code indicates the cause of the
765 failure.
766
767*/
768SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables(
769 const SpvReflectShaderModule* p_module,
770 const char* entry_point,
771 uint32_t* p_count,
772 SpvReflectInterfaceVariable** pp_variables
773);
774
775
776/*! @fn spvReflectEnumerateInputVariables
777 @brief If the module contains multiple entry points, this will only get
778 the input variables for the first one.
779 @param p_module Pointer to an instance of SpvReflectShaderModule.
780 @param p_count If pp_variables is NULL, the module's input variable
781 count will be stored here.
782 If pp_variables is not NULL, *p_count must contain
783 the module's input variable count.
784 @param pp_variables If NULL, the module's input variable count will be
785 written to *p_count.
786 If non-NULL, pp_variables must point to an array with
787 *p_count entries, where pointers to the module's
788 input variables will be written. The caller must not
789 free the interface variables written to this array.
790 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
791 Otherwise, the error code indicates the cause of the
792 failure.
793
794*/
795SpvReflectResult spvReflectEnumerateInputVariables(
796 const SpvReflectShaderModule* p_module,
797 uint32_t* p_count,
798 SpvReflectInterfaceVariable** pp_variables
799);
800
801// -- GOODT begin --
802/*! @fn spvReflectEnumerateSpecializationConstants
803 @brief If the module contains multiple entry points, this will only get
804 the specialization constants for the first one.
805 @param p_module Pointer to an instance of SpvReflectShaderModule.
806 @param p_count If pp_constants is NULL, the module's specialization constant
807 count will be stored here.
808 If pp_variables is not NULL, *p_count must contain
809 the module's specialization constant count.
810 @param pp_variables If NULL, the module's specialization constant count will be
811 written to *p_count.
812 If non-NULL, pp_constants must point to an array with
813 *p_count entries, where pointers to the module's
814 specialization constants will be written. The caller must not
815 free the specialization constants written to this array.
816 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
817 Otherwise, the error code indicates the cause of the
818 failure.
819
820*/
821SpvReflectResult spvReflectEnumerateSpecializationConstants(
822 const SpvReflectShaderModule* p_module,
823 uint32_t* p_count,
824 SpvReflectSpecializationConstant** pp_constants
825);
826// -- GODOT end --
827
828/*! @fn spvReflectEnumerateEntryPointInputVariables
829 @brief Enumerate the input variables for a given entry point.
830 @param entry_point The name of the entry point to get the input variables for.
831 @param p_module Pointer to an instance of SpvReflectShaderModule.
832 @param p_count If pp_variables is NULL, the entry point's input variable
833 count will be stored here.
834 If pp_variables is not NULL, *p_count must contain
835 the entry point's input variable count.
836 @param pp_variables If NULL, the entry point's input variable count will be
837 written to *p_count.
838 If non-NULL, pp_variables must point to an array with
839 *p_count entries, where pointers to the entry point's
840 input variables will be written. The caller must not
841 free the interface variables written to this array.
842 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
843 Otherwise, the error code indicates the cause of the
844 failure.
845
846*/
847SpvReflectResult spvReflectEnumerateEntryPointInputVariables(
848 const SpvReflectShaderModule* p_module,
849 const char* entry_point,
850 uint32_t* p_count,
851 SpvReflectInterfaceVariable** pp_variables
852);
853
854
855/*! @fn spvReflectEnumerateOutputVariables
856 @brief Note: If the module contains multiple entry points, this will only get
857 the output variables for the first one.
858 @param p_module Pointer to an instance of SpvReflectShaderModule.
859 @param p_count If pp_variables is NULL, the module's output variable
860 count will be stored here.
861 If pp_variables is not NULL, *p_count must contain
862 the module's output variable count.
863 @param pp_variables If NULL, the module's output variable count will be
864 written to *p_count.
865 If non-NULL, pp_variables must point to an array with
866 *p_count entries, where pointers to the module's
867 output variables will be written. The caller must not
868 free the interface variables written to this array.
869 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
870 Otherwise, the error code indicates the cause of the
871 failure.
872
873*/
874SpvReflectResult spvReflectEnumerateOutputVariables(
875 const SpvReflectShaderModule* p_module,
876 uint32_t* p_count,
877 SpvReflectInterfaceVariable** pp_variables
878);
879
880/*! @fn spvReflectEnumerateEntryPointOutputVariables
881 @brief Enumerate the output variables for a given entry point.
882 @param p_module Pointer to an instance of SpvReflectShaderModule.
883 @param entry_point The name of the entry point to get the output variables for.
884 @param p_count If pp_variables is NULL, the entry point's output variable
885 count will be stored here.
886 If pp_variables is not NULL, *p_count must contain
887 the entry point's output variable count.
888 @param pp_variables If NULL, the entry point's output variable count will be
889 written to *p_count.
890 If non-NULL, pp_variables must point to an array with
891 *p_count entries, where pointers to the entry point's
892 output variables will be written. The caller must not
893 free the interface variables written to this array.
894 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
895 Otherwise, the error code indicates the cause of the
896 failure.
897
898*/
899SpvReflectResult spvReflectEnumerateEntryPointOutputVariables(
900 const SpvReflectShaderModule* p_module,
901 const char* entry_point,
902 uint32_t* p_count,
903 SpvReflectInterfaceVariable** pp_variables
904);
905
906
907/*! @fn spvReflectEnumeratePushConstantBlocks
908 @brief Note: If the module contains multiple entry points, this will only get
909 the push constant blocks for the first one.
910 @param p_module Pointer to an instance of SpvReflectShaderModule.
911 @param p_count If pp_blocks is NULL, the module's push constant
912 block count will be stored here.
913 If pp_blocks is not NULL, *p_count must
914 contain the module's push constant block count.
915 @param pp_blocks If NULL, the module's push constant block count
916 will be written to *p_count.
917 If non-NULL, pp_blocks must point to an
918 array with *p_count entries, where pointers to
919 the module's push constant blocks will be written.
920 The caller must not free the block variables written
921 to this array.
922 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
923 Otherwise, the error code indicates the cause of the
924 failure.
925
926*/
927SpvReflectResult spvReflectEnumeratePushConstantBlocks(
928 const SpvReflectShaderModule* p_module,
929 uint32_t* p_count,
930 SpvReflectBlockVariable** pp_blocks
931);
932SPV_REFLECT_DEPRECATED("renamed to spvReflectEnumeratePushConstantBlocks")
933SpvReflectResult spvReflectEnumeratePushConstants(
934 const SpvReflectShaderModule* p_module,
935 uint32_t* p_count,
936 SpvReflectBlockVariable** pp_blocks
937);
938
939/*! @fn spvReflectEnumerateEntryPointPushConstantBlocks
940 @brief Enumerate the push constant blocks used in the static call tree of a
941 given entry point.
942 @param p_module Pointer to an instance of SpvReflectShaderModule.
943 @param p_count If pp_blocks is NULL, the entry point's push constant
944 block count will be stored here.
945 If pp_blocks is not NULL, *p_count must
946 contain the entry point's push constant block count.
947 @param pp_blocks If NULL, the entry point's push constant block count
948 will be written to *p_count.
949 If non-NULL, pp_blocks must point to an
950 array with *p_count entries, where pointers to
951 the entry point's push constant blocks will be written.
952 The caller must not free the block variables written
953 to this array.
954 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
955 Otherwise, the error code indicates the cause of the
956 failure.
957
958*/
959SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks(
960 const SpvReflectShaderModule* p_module,
961 const char* entry_point,
962 uint32_t* p_count,
963 SpvReflectBlockVariable** pp_blocks
964);
965
966
967/*! @fn spvReflectGetDescriptorBinding
968
969 @param p_module Pointer to an instance of SpvReflectShaderModule.
970 @param binding_number The "binding" value of the requested descriptor
971 binding.
972 @param set_number The "set" value of the requested descriptor binding.
973 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
974 written to *p_result. Otherwise, a error code
975 indicating the cause of the failure will be stored
976 here.
977 @return If the module contains a descriptor binding that
978 matches the provided [binding_number, set_number]
979 values, a pointer to that binding is returned. The
980 caller must not free this pointer.
981 If no match can be found, or if an unrelated error
982 occurs, the return value will be NULL. Detailed
983 error results are written to *pResult.
984@note If the module contains multiple desriptor bindings
985 with the same set and binding numbers, there are
986 no guarantees about which binding will be returned.
987
988*/
989const SpvReflectDescriptorBinding* spvReflectGetDescriptorBinding(
990 const SpvReflectShaderModule* p_module,
991 uint32_t binding_number,
992 uint32_t set_number,
993 SpvReflectResult* p_result
994);
995
996/*! @fn spvReflectGetEntryPointDescriptorBinding
997 @brief Get the descriptor binding with the given binding number and set
998 number that is used in the static call tree of a certain entry
999 point.
1000 @param p_module Pointer to an instance of SpvReflectShaderModule.
1001 @param entry_point The entry point to get the binding from.
1002 @param binding_number The "binding" value of the requested descriptor
1003 binding.
1004 @param set_number The "set" value of the requested descriptor binding.
1005 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1006 written to *p_result. Otherwise, a error code
1007 indicating the cause of the failure will be stored
1008 here.
1009 @return If the entry point contains a descriptor binding that
1010 matches the provided [binding_number, set_number]
1011 values, a pointer to that binding is returned. The
1012 caller must not free this pointer.
1013 If no match can be found, or if an unrelated error
1014 occurs, the return value will be NULL. Detailed
1015 error results are written to *pResult.
1016@note If the entry point contains multiple desriptor bindings
1017 with the same set and binding numbers, there are
1018 no guarantees about which binding will be returned.
1019
1020*/
1021const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding(
1022 const SpvReflectShaderModule* p_module,
1023 const char* entry_point,
1024 uint32_t binding_number,
1025 uint32_t set_number,
1026 SpvReflectResult* p_result
1027);
1028
1029
1030/*! @fn spvReflectGetDescriptorSet
1031
1032 @param p_module Pointer to an instance of SpvReflectShaderModule.
1033 @param set_number The "set" value of the requested descriptor set.
1034 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1035 written to *p_result. Otherwise, a error code
1036 indicating the cause of the failure will be stored
1037 here.
1038 @return If the module contains a descriptor set with the
1039 provided set_number, a pointer to that set is
1040 returned. The caller must not free this pointer.
1041 If no match can be found, or if an unrelated error
1042 occurs, the return value will be NULL. Detailed
1043 error results are written to *pResult.
1044
1045*/
1046const SpvReflectDescriptorSet* spvReflectGetDescriptorSet(
1047 const SpvReflectShaderModule* p_module,
1048 uint32_t set_number,
1049 SpvReflectResult* p_result
1050);
1051
1052/*! @fn spvReflectGetEntryPointDescriptorSet
1053
1054 @param p_module Pointer to an instance of SpvReflectShaderModule.
1055 @param entry_point The entry point to get the descriptor set from.
1056 @param set_number The "set" value of the requested descriptor set.
1057 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1058 written to *p_result. Otherwise, a error code
1059 indicating the cause of the failure will be stored
1060 here.
1061 @return If the entry point contains a descriptor set with the
1062 provided set_number, a pointer to that set is
1063 returned. The caller must not free this pointer.
1064 If no match can be found, or if an unrelated error
1065 occurs, the return value will be NULL. Detailed
1066 error results are written to *pResult.
1067
1068*/
1069const SpvReflectDescriptorSet* spvReflectGetEntryPointDescriptorSet(
1070 const SpvReflectShaderModule* p_module,
1071 const char* entry_point,
1072 uint32_t set_number,
1073 SpvReflectResult* p_result
1074);
1075
1076
1077/* @fn spvReflectGetInputVariableByLocation
1078
1079 @param p_module Pointer to an instance of SpvReflectShaderModule.
1080 @param location The "location" value of the requested input variable.
1081 A location of 0xFFFFFFFF will always return NULL
1082 with *p_result == ELEMENT_NOT_FOUND.
1083 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1084 written to *p_result. Otherwise, a error code
1085 indicating the cause of the failure will be stored
1086 here.
1087 @return If the module contains an input interface variable
1088 with the provided location value, a pointer to that
1089 variable is returned. The caller must not free this
1090 pointer.
1091 If no match can be found, or if an unrelated error
1092 occurs, the return value will be NULL. Detailed
1093 error results are written to *pResult.
1094@note
1095
1096*/
1097const SpvReflectInterfaceVariable* spvReflectGetInputVariableByLocation(
1098 const SpvReflectShaderModule* p_module,
1099 uint32_t location,
1100 SpvReflectResult* p_result
1101);
1102SPV_REFLECT_DEPRECATED("renamed to spvReflectGetInputVariableByLocation")
1103const SpvReflectInterfaceVariable* spvReflectGetInputVariable(
1104 const SpvReflectShaderModule* p_module,
1105 uint32_t location,
1106 SpvReflectResult* p_result
1107);
1108
1109/* @fn spvReflectGetEntryPointInputVariableByLocation
1110
1111 @param p_module Pointer to an instance of SpvReflectShaderModule.
1112 @param entry_point The entry point to get the input variable from.
1113 @param location The "location" value of the requested input variable.
1114 A location of 0xFFFFFFFF will always return NULL
1115 with *p_result == ELEMENT_NOT_FOUND.
1116 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1117 written to *p_result. Otherwise, a error code
1118 indicating the cause of the failure will be stored
1119 here.
1120 @return If the entry point contains an input interface variable
1121 with the provided location value, a pointer to that
1122 variable is returned. The caller must not free this
1123 pointer.
1124 If no match can be found, or if an unrelated error
1125 occurs, the return value will be NULL. Detailed
1126 error results are written to *pResult.
1127@note
1128
1129*/
1130const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocation(
1131 const SpvReflectShaderModule* p_module,
1132 const char* entry_point,
1133 uint32_t location,
1134 SpvReflectResult* p_result
1135);
1136
1137/* @fn spvReflectGetInputVariableBySemantic
1138
1139 @param p_module Pointer to an instance of SpvReflectShaderModule.
1140 @param semantic The "semantic" value of the requested input variable.
1141 A semantic of NULL will return NULL.
1142 A semantic of "" will always return NULL with
1143 *p_result == ELEMENT_NOT_FOUND.
1144 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1145 written to *p_result. Otherwise, a error code
1146 indicating the cause of the failure will be stored
1147 here.
1148 @return If the module contains an input interface variable
1149 with the provided semantic, a pointer to that
1150 variable is returned. The caller must not free this
1151 pointer.
1152 If no match can be found, or if an unrelated error
1153 occurs, the return value will be NULL. Detailed
1154 error results are written to *pResult.
1155@note
1156
1157*/
1158const SpvReflectInterfaceVariable* spvReflectGetInputVariableBySemantic(
1159 const SpvReflectShaderModule* p_module,
1160 const char* semantic,
1161 SpvReflectResult* p_result
1162);
1163
1164/* @fn spvReflectGetEntryPointInputVariableBySemantic
1165
1166 @param p_module Pointer to an instance of SpvReflectShaderModule.
1167 @param entry_point The entry point to get the input variable from.
1168 @param semantic The "semantic" value of the requested input variable.
1169 A semantic of NULL will return NULL.
1170 A semantic of "" will always return NULL with
1171 *p_result == ELEMENT_NOT_FOUND.
1172 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1173 written to *p_result. Otherwise, a error code
1174 indicating the cause of the failure will be stored
1175 here.
1176 @return If the entry point contains an input interface variable
1177 with the provided semantic, a pointer to that
1178 variable is returned. The caller must not free this
1179 pointer.
1180 If no match can be found, or if an unrelated error
1181 occurs, the return value will be NULL. Detailed
1182 error results are written to *pResult.
1183@note
1184
1185*/
1186const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableBySemantic(
1187 const SpvReflectShaderModule* p_module,
1188 const char* entry_point,
1189 const char* semantic,
1190 SpvReflectResult* p_result
1191);
1192
1193/* @fn spvReflectGetOutputVariableByLocation
1194
1195 @param p_module Pointer to an instance of SpvReflectShaderModule.
1196 @param location The "location" value of the requested output variable.
1197 A location of 0xFFFFFFFF will always return NULL
1198 with *p_result == ELEMENT_NOT_FOUND.
1199 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1200 written to *p_result. Otherwise, a error code
1201 indicating the cause of the failure will be stored
1202 here.
1203 @return If the module contains an output interface variable
1204 with the provided location value, a pointer to that
1205 variable is returned. The caller must not free this
1206 pointer.
1207 If no match can be found, or if an unrelated error
1208 occurs, the return value will be NULL. Detailed
1209 error results are written to *pResult.
1210@note
1211
1212*/
1213const SpvReflectInterfaceVariable* spvReflectGetOutputVariableByLocation(
1214 const SpvReflectShaderModule* p_module,
1215 uint32_t location,
1216 SpvReflectResult* p_result
1217);
1218SPV_REFLECT_DEPRECATED("renamed to spvReflectGetOutputVariableByLocation")
1219const SpvReflectInterfaceVariable* spvReflectGetOutputVariable(
1220 const SpvReflectShaderModule* p_module,
1221 uint32_t location,
1222 SpvReflectResult* p_result
1223);
1224
1225/* @fn spvReflectGetEntryPointOutputVariableByLocation
1226
1227 @param p_module Pointer to an instance of SpvReflectShaderModule.
1228 @param entry_point The entry point to get the output variable from.
1229 @param location The "location" value of the requested output variable.
1230 A location of 0xFFFFFFFF will always return NULL
1231 with *p_result == ELEMENT_NOT_FOUND.
1232 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1233 written to *p_result. Otherwise, a error code
1234 indicating the cause of the failure will be stored
1235 here.
1236 @return If the entry point contains an output interface variable
1237 with the provided location value, a pointer to that
1238 variable is returned. The caller must not free this
1239 pointer.
1240 If no match can be found, or if an unrelated error
1241 occurs, the return value will be NULL. Detailed
1242 error results are written to *pResult.
1243@note
1244
1245*/
1246const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableByLocation(
1247 const SpvReflectShaderModule* p_module,
1248 const char* entry_point,
1249 uint32_t location,
1250 SpvReflectResult* p_result
1251);
1252
1253/* @fn spvReflectGetOutputVariableBySemantic
1254
1255 @param p_module Pointer to an instance of SpvReflectShaderModule.
1256 @param semantic The "semantic" value of the requested output variable.
1257 A semantic of NULL will return NULL.
1258 A semantic of "" will always return NULL with
1259 *p_result == ELEMENT_NOT_FOUND.
1260 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1261 written to *p_result. Otherwise, a error code
1262 indicating the cause of the failure will be stored
1263 here.
1264 @return If the module contains an output interface variable
1265 with the provided semantic, a pointer to that
1266 variable is returned. The caller must not free this
1267 pointer.
1268 If no match can be found, or if an unrelated error
1269 occurs, the return value will be NULL. Detailed
1270 error results are written to *pResult.
1271@note
1272
1273*/
1274const SpvReflectInterfaceVariable* spvReflectGetOutputVariableBySemantic(
1275 const SpvReflectShaderModule* p_module,
1276 const char* semantic,
1277 SpvReflectResult* p_result
1278);
1279
1280/* @fn spvReflectGetEntryPointOutputVariableBySemantic
1281
1282 @param p_module Pointer to an instance of SpvReflectShaderModule.
1283 @param entry_point The entry point to get the output variable from.
1284 @param semantic The "semantic" value of the requested output variable.
1285 A semantic of NULL will return NULL.
1286 A semantic of "" will always return NULL with
1287 *p_result == ELEMENT_NOT_FOUND.
1288 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1289 written to *p_result. Otherwise, a error code
1290 indicating the cause of the failure will be stored
1291 here.
1292 @return If the entry point contains an output interface variable
1293 with the provided semantic, a pointer to that
1294 variable is returned. The caller must not free this
1295 pointer.
1296 If no match can be found, or if an unrelated error
1297 occurs, the return value will be NULL. Detailed
1298 error results are written to *pResult.
1299@note
1300
1301*/
1302const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableBySemantic(
1303 const SpvReflectShaderModule* p_module,
1304 const char* entry_point,
1305 const char* semantic,
1306 SpvReflectResult* p_result
1307);
1308
1309/*! @fn spvReflectGetPushConstantBlock
1310
1311 @param p_module Pointer to an instance of SpvReflectShaderModule.
1312 @param index The index of the desired block within the module's
1313 array of push constant blocks.
1314 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1315 written to *p_result. Otherwise, a error code
1316 indicating the cause of the failure will be stored
1317 here.
1318 @return If the provided index is within range, a pointer to
1319 the corresponding push constant block is returned.
1320 The caller must not free this pointer.
1321 If no match can be found, or if an unrelated error
1322 occurs, the return value will be NULL. Detailed
1323 error results are written to *pResult.
1324
1325*/
1326const SpvReflectBlockVariable* spvReflectGetPushConstantBlock(
1327 const SpvReflectShaderModule* p_module,
1328 uint32_t index,
1329 SpvReflectResult* p_result
1330);
1331SPV_REFLECT_DEPRECATED("renamed to spvReflectGetPushConstantBlock")
1332const SpvReflectBlockVariable* spvReflectGetPushConstant(
1333 const SpvReflectShaderModule* p_module,
1334 uint32_t index,
1335 SpvReflectResult* p_result
1336);
1337
1338/*! @fn spvReflectGetEntryPointPushConstantBlock
1339 @brief Get the push constant block corresponding to the given entry point.
1340 As by the Vulkan specification there can be no more than one push
1341 constant block used by a given entry point, so if there is one it will
1342 be returned, otherwise NULL will be returned.
1343 @param p_module Pointer to an instance of SpvReflectShaderModule.
1344 @param entry_point The entry point to get the push constant block from.
1345 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1346 written to *p_result. Otherwise, a error code
1347 indicating the cause of the failure will be stored
1348 here.
1349 @return If the provided index is within range, a pointer to
1350 the corresponding push constant block is returned.
1351 The caller must not free this pointer.
1352 If no match can be found, or if an unrelated error
1353 occurs, the return value will be NULL. Detailed
1354 error results are written to *pResult.
1355
1356*/
1357const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock(
1358 const SpvReflectShaderModule* p_module,
1359 const char* entry_point,
1360 SpvReflectResult* p_result
1361);
1362
1363
1364/*! @fn spvReflectChangeDescriptorBindingNumbers
1365 @brief Assign new set and/or binding numbers to a descriptor binding.
1366 In addition to updating the reflection data, this function modifies
1367 the underlying SPIR-V bytecode. The updated code can be retrieved
1368 with spvReflectGetCode(). If the binding is used in multiple
1369 entry points within the module, it will be changed in all of them.
1370 @param p_module Pointer to an instance of SpvReflectShaderModule.
1371 @param p_binding Pointer to the descriptor binding to modify.
1372 @param new_binding_number The new binding number to assign to the
1373 provided descriptor binding.
1374 To leave the binding number unchanged, pass
1375 SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE.
1376 @param new_set_number The new set number to assign to the
1377 provided descriptor binding. Successfully changing
1378 a descriptor binding's set number invalidates all
1379 existing SpvReflectDescriptorBinding and
1380 SpvReflectDescriptorSet pointers from this module.
1381 To leave the set number unchanged, pass
1382 SPV_REFLECT_SET_NUMBER_DONT_CHANGE.
1383 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
1384 Otherwise, the error code indicates the cause of
1385 the failure.
1386*/
1387SpvReflectResult spvReflectChangeDescriptorBindingNumbers(
1388 SpvReflectShaderModule* p_module,
1389 const SpvReflectDescriptorBinding* p_binding,
1390 uint32_t new_binding_number,
1391 uint32_t new_set_number
1392);
1393SPV_REFLECT_DEPRECATED("Renamed to spvReflectChangeDescriptorBindingNumbers")
1394SpvReflectResult spvReflectChangeDescriptorBindingNumber(
1395 SpvReflectShaderModule* p_module,
1396 const SpvReflectDescriptorBinding* p_descriptor_binding,
1397 uint32_t new_binding_number,
1398 uint32_t optional_new_set_number
1399);
1400
1401/*! @fn spvReflectChangeDescriptorSetNumber
1402 @brief Assign a new set number to an entire descriptor set (including
1403 all descriptor bindings in that set).
1404 In addition to updating the reflection data, this function modifies
1405 the underlying SPIR-V bytecode. The updated code can be retrieved
1406 with spvReflectGetCode(). If the descriptor set is used in
1407 multiple entry points within the module, it will be modified in all
1408 of them.
1409 @param p_module Pointer to an instance of SpvReflectShaderModule.
1410 @param p_set Pointer to the descriptor binding to modify.
1411 @param new_set_number The new set number to assign to the
1412 provided descriptor set, and all its descriptor
1413 bindings. Successfully changing a descriptor
1414 binding's set number invalidates all existing
1415 SpvReflectDescriptorBinding and
1416 SpvReflectDescriptorSet pointers from this module.
1417 To leave the set number unchanged, pass
1418 SPV_REFLECT_SET_NUMBER_DONT_CHANGE.
1419 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
1420 Otherwise, the error code indicates the cause of
1421 the failure.
1422*/
1423SpvReflectResult spvReflectChangeDescriptorSetNumber(
1424 SpvReflectShaderModule* p_module,
1425 const SpvReflectDescriptorSet* p_set,
1426 uint32_t new_set_number
1427);
1428
1429/*! @fn spvReflectChangeInputVariableLocation
1430 @brief Assign a new location to an input interface variable.
1431 In addition to updating the reflection data, this function modifies
1432 the underlying SPIR-V bytecode. The updated code can be retrieved
1433 with spvReflectGetCode().
1434 It is the caller's responsibility to avoid assigning the same
1435 location to multiple input variables. If the input variable is used
1436 by multiple entry points in the module, it will be changed in all of
1437 them.
1438 @param p_module Pointer to an instance of SpvReflectShaderModule.
1439 @param p_input_variable Pointer to the input variable to update.
1440 @param new_location The new location to assign to p_input_variable.
1441 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
1442 Otherwise, the error code indicates the cause of
1443 the failure.
1444
1445*/
1446SpvReflectResult spvReflectChangeInputVariableLocation(
1447 SpvReflectShaderModule* p_module,
1448 const SpvReflectInterfaceVariable* p_input_variable,
1449 uint32_t new_location
1450);
1451
1452
1453/*! @fn spvReflectChangeOutputVariableLocation
1454 @brief Assign a new location to an output interface variable.
1455 In addition to updating the reflection data, this function modifies
1456 the underlying SPIR-V bytecode. The updated code can be retrieved
1457 with spvReflectGetCode().
1458 It is the caller's responsibility to avoid assigning the same
1459 location to multiple output variables. If the output variable is used
1460 by multiple entry points in the module, it will be changed in all of
1461 them.
1462 @param p_module Pointer to an instance of SpvReflectShaderModule.
1463 @param p_output_variable Pointer to the output variable to update.
1464 @param new_location The new location to assign to p_output_variable.
1465 @return If successful, returns SPV_REFLECT_RESULT_SUCCESS.
1466 Otherwise, the error code indicates the cause of
1467 the failure.
1468
1469*/
1470SpvReflectResult spvReflectChangeOutputVariableLocation(
1471 SpvReflectShaderModule* p_module,
1472 const SpvReflectInterfaceVariable* p_output_variable,
1473 uint32_t new_location
1474);
1475
1476
1477/*! @fn spvReflectSourceLanguage
1478
1479 @param source_lang The source language code.
1480 @return Returns string of source language specified in \a source_lang.
1481 The caller must not free the memory associated with this string.
1482*/
1483const char* spvReflectSourceLanguage(SpvSourceLanguage source_lang);
1484
1485/*! @fn spvReflectBlockVariableTypeName
1486
1487 @param p_var Pointer to block variable.
1488 @return Returns string of block variable's type description type name
1489 or NULL if p_var is NULL.
1490*/
1491const char* spvReflectBlockVariableTypeName(
1492 const SpvReflectBlockVariable* p_var
1493);
1494
1495#if defined(__cplusplus)
1496};
1497#endif
1498
1499#if defined(__cplusplus)
1500#include <cstdlib>
1501#include <string>
1502#include <vector>
1503
1504namespace spv_reflect {
1505
1506/*! \class ShaderModule
1507
1508*/
1509class ShaderModule {
1510public:
1511 ShaderModule();
1512 ShaderModule(size_t size, const void* p_code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1513 ShaderModule(const std::vector<uint8_t>& code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1514 ShaderModule(const std::vector<uint32_t>& code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1515 ~ShaderModule();
1516
1517 ShaderModule(ShaderModule&& other);
1518 ShaderModule& operator=(ShaderModule&& other);
1519
1520 SpvReflectResult GetResult() const;
1521
1522 const SpvReflectShaderModule& GetShaderModule() const;
1523
1524 uint32_t GetCodeSize() const;
1525 const uint32_t* GetCode() const;
1526
1527 const char* GetEntryPointName() const;
1528
1529 const char* GetSourceFile() const;
1530
1531 uint32_t GetEntryPointCount() const;
1532 const char* GetEntryPointName(uint32_t index) const;
1533 SpvReflectShaderStageFlagBits GetEntryPointShaderStage(uint32_t index) const;
1534
1535 SpvReflectShaderStageFlagBits GetShaderStage() const;
1536 SPV_REFLECT_DEPRECATED("Renamed to GetShaderStage")
1537 SpvReflectShaderStageFlagBits GetVulkanShaderStage() const {
1538 return GetShaderStage();
1539 }
1540
1541 SpvReflectResult EnumerateDescriptorBindings(uint32_t* p_count, SpvReflectDescriptorBinding** pp_bindings) const;
1542 SpvReflectResult EnumerateEntryPointDescriptorBindings(const char* entry_point, uint32_t* p_count, SpvReflectDescriptorBinding** pp_bindings) const;
1543 SpvReflectResult EnumerateDescriptorSets( uint32_t* p_count, SpvReflectDescriptorSet** pp_sets) const ;
1544 SpvReflectResult EnumerateEntryPointDescriptorSets(const char* entry_point, uint32_t* p_count, SpvReflectDescriptorSet** pp_sets) const ;
1545 SpvReflectResult EnumerateInterfaceVariables(uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1546 SpvReflectResult EnumerateEntryPointInterfaceVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1547 SpvReflectResult EnumerateInputVariables(uint32_t* p_count,SpvReflectInterfaceVariable** pp_variables) const;
1548 SpvReflectResult EnumerateEntryPointInputVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1549 SpvReflectResult EnumerateOutputVariables(uint32_t* p_count,SpvReflectInterfaceVariable** pp_variables) const;
1550 SpvReflectResult EnumerateEntryPointOutputVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1551 SpvReflectResult EnumeratePushConstantBlocks(uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const;
1552 SpvReflectResult EnumerateEntryPointPushConstantBlocks(const char* entry_point, uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const;
1553 SPV_REFLECT_DEPRECATED("Renamed to EnumeratePushConstantBlocks")
1554 SpvReflectResult EnumeratePushConstants(uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const {
1555 return EnumeratePushConstantBlocks(p_count, pp_blocks);
1556 }
1557
1558 const SpvReflectDescriptorBinding* GetDescriptorBinding(uint32_t binding_number, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1559 const SpvReflectDescriptorBinding* GetEntryPointDescriptorBinding(const char* entry_point, uint32_t binding_number, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1560 const SpvReflectDescriptorSet* GetDescriptorSet(uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1561 const SpvReflectDescriptorSet* GetEntryPointDescriptorSet(const char* entry_point, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1562 const SpvReflectInterfaceVariable* GetInputVariableByLocation(uint32_t location, SpvReflectResult* p_result = nullptr) const;
1563 SPV_REFLECT_DEPRECATED("Renamed to GetInputVariableByLocation")
1564 const SpvReflectInterfaceVariable* GetInputVariable(uint32_t location, SpvReflectResult* p_result = nullptr) const {
1565 return GetInputVariableByLocation(location, p_result);
1566 }
1567 const SpvReflectInterfaceVariable* GetEntryPointInputVariableByLocation(const char* entry_point, uint32_t location, SpvReflectResult* p_result = nullptr) const;
1568 const SpvReflectInterfaceVariable* GetInputVariableBySemantic(const char* semantic, SpvReflectResult* p_result = nullptr) const;
1569 const SpvReflectInterfaceVariable* GetEntryPointInputVariableBySemantic(const char* entry_point, const char* semantic, SpvReflectResult* p_result = nullptr) const;
1570 const SpvReflectInterfaceVariable* GetOutputVariableByLocation(uint32_t location, SpvReflectResult* p_result = nullptr) const;
1571 SPV_REFLECT_DEPRECATED("Renamed to GetOutputVariableByLocation")
1572 const SpvReflectInterfaceVariable* GetOutputVariable(uint32_t location, SpvReflectResult* p_result = nullptr) const {
1573 return GetOutputVariableByLocation(location, p_result);
1574 }
1575 const SpvReflectInterfaceVariable* GetEntryPointOutputVariableByLocation(const char* entry_point, uint32_t location, SpvReflectResult* p_result = nullptr) const;
1576 const SpvReflectInterfaceVariable* GetOutputVariableBySemantic(const char* semantic, SpvReflectResult* p_result = nullptr) const;
1577 const SpvReflectInterfaceVariable* GetEntryPointOutputVariableBySemantic(const char* entry_point, const char* semantic, SpvReflectResult* p_result = nullptr) const;
1578 const SpvReflectBlockVariable* GetPushConstantBlock(uint32_t index, SpvReflectResult* p_result = nullptr) const;
1579 SPV_REFLECT_DEPRECATED("Renamed to GetPushConstantBlock")
1580 const SpvReflectBlockVariable* GetPushConstant(uint32_t index, SpvReflectResult* p_result = nullptr) const {
1581 return GetPushConstantBlock(index, p_result);
1582 }
1583 const SpvReflectBlockVariable* GetEntryPointPushConstantBlock(const char* entry_point, SpvReflectResult* p_result = nullptr) const;
1584
1585 SpvReflectResult ChangeDescriptorBindingNumbers(const SpvReflectDescriptorBinding* p_binding,
1586 uint32_t new_binding_number = SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE,
1587 uint32_t optional_new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE);
1588 SPV_REFLECT_DEPRECATED("Renamed to ChangeDescriptorBindingNumbers")
1589 SpvReflectResult ChangeDescriptorBindingNumber(const SpvReflectDescriptorBinding* p_binding, uint32_t new_binding_number = SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE,
1590 uint32_t new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE) {
1591 return ChangeDescriptorBindingNumbers(p_binding, new_binding_number, new_set_number);
1592 }
1593 SpvReflectResult ChangeDescriptorSetNumber(const SpvReflectDescriptorSet* p_set, uint32_t new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE);
1594 SpvReflectResult ChangeInputVariableLocation(const SpvReflectInterfaceVariable* p_input_variable, uint32_t new_location);
1595 SpvReflectResult ChangeOutputVariableLocation(const SpvReflectInterfaceVariable* p_output_variable, uint32_t new_location);
1596
1597private:
1598 // Make noncopyable
1599 ShaderModule(const ShaderModule&);
1600 ShaderModule& operator=(const ShaderModule&);
1601
1602private:
1603 mutable SpvReflectResult m_result = SPV_REFLECT_RESULT_NOT_READY;
1604 SpvReflectShaderModule m_module = {};
1605};
1606
1607
1608// =================================================================================================
1609// ShaderModule
1610// =================================================================================================
1611
1612/*! @fn ShaderModule
1613
1614*/
1615inline ShaderModule::ShaderModule() {}
1616
1617
1618/*! @fn ShaderModule
1619
1620 @param size
1621 @param p_code
1622
1623*/
1624inline ShaderModule::ShaderModule(size_t size, const void* p_code, SpvReflectModuleFlags flags) {
1625 m_result = spvReflectCreateShaderModule2(
1626 flags,
1627 size,
1628 p_code,
1629 &m_module);
1630}
1631
1632/*! @fn ShaderModule
1633
1634 @param code
1635
1636*/
1637inline ShaderModule::ShaderModule(const std::vector<uint8_t>& code, SpvReflectModuleFlags flags) {
1638 m_result = spvReflectCreateShaderModule2(
1639 flags,
1640 code.size(),
1641 code.data(),
1642 &m_module);
1643}
1644
1645/*! @fn ShaderModule
1646
1647 @param code
1648
1649*/
1650inline ShaderModule::ShaderModule(const std::vector<uint32_t>& code, SpvReflectModuleFlags flags) {
1651 m_result = spvReflectCreateShaderModule2(
1652 flags,
1653 code.size() * sizeof(uint32_t),
1654 code.data(),
1655 &m_module);
1656}
1657
1658/*! @fn ~ShaderModule
1659
1660*/
1661inline ShaderModule::~ShaderModule() {
1662 spvReflectDestroyShaderModule(&m_module);
1663}
1664
1665
1666inline ShaderModule::ShaderModule(ShaderModule&& other)
1667{
1668 *this = std::move(other);
1669}
1670
1671inline ShaderModule& ShaderModule::operator=(ShaderModule&& other)
1672{
1673 m_result = std::move(other.m_result);
1674 m_module = std::move(other.m_module);
1675
1676 other.m_module = {};
1677 return *this;
1678}
1679
1680/*! @fn GetResult
1681
1682 @return
1683
1684*/
1685inline SpvReflectResult ShaderModule::GetResult() const {
1686 return m_result;
1687}
1688
1689
1690/*! @fn GetShaderModule
1691
1692 @return
1693
1694*/
1695inline const SpvReflectShaderModule& ShaderModule::GetShaderModule() const {
1696 return m_module;
1697}
1698
1699
1700/*! @fn GetCodeSize
1701
1702 @return
1703
1704 */
1705inline uint32_t ShaderModule::GetCodeSize() const {
1706 return spvReflectGetCodeSize(&m_module);
1707}
1708
1709
1710/*! @fn GetCode
1711
1712 @return
1713
1714*/
1715inline const uint32_t* ShaderModule::GetCode() const {
1716 return spvReflectGetCode(&m_module);
1717}
1718
1719
1720/*! @fn GetEntryPoint
1721
1722 @return Returns entry point
1723
1724*/
1725inline const char* ShaderModule::GetEntryPointName() const {
1726 return this->GetEntryPointName(0);
1727}
1728
1729/*! @fn GetEntryPoint
1730
1731 @return Returns entry point
1732
1733*/
1734inline const char* ShaderModule::GetSourceFile() const {
1735 return m_module.source_file;
1736}
1737
1738/*! @fn GetEntryPointCount
1739
1740 @param
1741 @return
1742*/
1743inline uint32_t ShaderModule::GetEntryPointCount() const {
1744 return m_module.entry_point_count;
1745}
1746
1747/*! @fn GetEntryPointName
1748
1749 @param index
1750 @return
1751*/
1752inline const char* ShaderModule::GetEntryPointName(uint32_t index) const {
1753 return m_module.entry_points[index].name;
1754}
1755
1756/*! @fn GetEntryPointShaderStage
1757
1758 @param index
1759 @return Returns the shader stage for the entry point at \b index
1760*/
1761inline SpvReflectShaderStageFlagBits ShaderModule::GetEntryPointShaderStage(uint32_t index) const {
1762 return m_module.entry_points[index].shader_stage;
1763}
1764
1765/*! @fn GetShaderStage
1766
1767 @return Returns shader stage for the first entry point
1768
1769*/
1770inline SpvReflectShaderStageFlagBits ShaderModule::GetShaderStage() const {
1771 return m_module.shader_stage;
1772}
1773
1774/*! @fn EnumerateDescriptorBindings
1775
1776 @param count
1777 @param p_binding_numbers
1778 @param pp_bindings
1779 @return
1780
1781*/
1782inline SpvReflectResult ShaderModule::EnumerateDescriptorBindings(
1783 uint32_t* p_count,
1784 SpvReflectDescriptorBinding** pp_bindings
1785) const
1786{
1787 m_result = spvReflectEnumerateDescriptorBindings(
1788 &m_module,
1789 p_count,
1790 pp_bindings);
1791 return m_result;
1792}
1793
1794/*! @fn EnumerateEntryPointDescriptorBindings
1795
1796 @param entry_point
1797 @param count
1798 @param pp_bindings
1799 @return
1800
1801*/
1802inline SpvReflectResult ShaderModule::EnumerateEntryPointDescriptorBindings(
1803 const char* entry_point,
1804 uint32_t* p_count,
1805 SpvReflectDescriptorBinding** pp_bindings
1806) const
1807{
1808 m_result = spvReflectEnumerateEntryPointDescriptorBindings(
1809 &m_module,
1810 entry_point,
1811 p_count,
1812 pp_bindings);
1813 return m_result;
1814}
1815
1816
1817/*! @fn EnumerateDescriptorSets
1818
1819 @param count
1820 @param pp_sets
1821 @return
1822
1823*/
1824inline SpvReflectResult ShaderModule::EnumerateDescriptorSets(
1825 uint32_t* p_count,
1826 SpvReflectDescriptorSet** pp_sets
1827) const
1828{
1829 m_result = spvReflectEnumerateDescriptorSets(
1830 &m_module,
1831 p_count,
1832 pp_sets);
1833 return m_result;
1834}
1835
1836/*! @fn EnumerateEntryPointDescriptorSets
1837
1838 @param entry_point
1839 @param count
1840 @param pp_sets
1841 @return
1842
1843*/
1844inline SpvReflectResult ShaderModule::EnumerateEntryPointDescriptorSets(
1845 const char* entry_point,
1846 uint32_t* p_count,
1847 SpvReflectDescriptorSet** pp_sets
1848) const
1849{
1850 m_result = spvReflectEnumerateEntryPointDescriptorSets(
1851 &m_module,
1852 entry_point,
1853 p_count,
1854 pp_sets);
1855 return m_result;
1856}
1857
1858
1859/*! @fn EnumerateInterfaceVariables
1860
1861 @param count
1862 @param pp_variables
1863 @return
1864
1865*/
1866inline SpvReflectResult ShaderModule::EnumerateInterfaceVariables(
1867 uint32_t* p_count,
1868 SpvReflectInterfaceVariable** pp_variables
1869) const
1870{
1871 m_result = spvReflectEnumerateInterfaceVariables(
1872 &m_module,
1873 p_count,
1874 pp_variables);
1875 return m_result;
1876}
1877
1878/*! @fn EnumerateEntryPointInterfaceVariables
1879
1880 @param entry_point
1881 @param count
1882 @param pp_variables
1883 @return
1884
1885*/
1886inline SpvReflectResult ShaderModule::EnumerateEntryPointInterfaceVariables(
1887 const char* entry_point,
1888 uint32_t* p_count,
1889 SpvReflectInterfaceVariable** pp_variables
1890) const
1891{
1892 m_result = spvReflectEnumerateEntryPointInterfaceVariables(
1893 &m_module,
1894 entry_point,
1895 p_count,
1896 pp_variables);
1897 return m_result;
1898}
1899
1900
1901/*! @fn EnumerateInputVariables
1902
1903 @param count
1904 @param pp_variables
1905 @return
1906
1907*/
1908inline SpvReflectResult ShaderModule::EnumerateInputVariables(
1909 uint32_t* p_count,
1910 SpvReflectInterfaceVariable** pp_variables
1911) const
1912{
1913 m_result = spvReflectEnumerateInputVariables(
1914 &m_module,
1915 p_count,
1916 pp_variables);
1917 return m_result;
1918}
1919
1920/*! @fn EnumerateEntryPointInputVariables
1921
1922 @param entry_point
1923 @param count
1924 @param pp_variables
1925 @return
1926
1927*/
1928inline SpvReflectResult ShaderModule::EnumerateEntryPointInputVariables(
1929 const char* entry_point,
1930 uint32_t* p_count,
1931 SpvReflectInterfaceVariable** pp_variables
1932) const
1933{
1934 m_result = spvReflectEnumerateEntryPointInputVariables(
1935 &m_module,
1936 entry_point,
1937 p_count,
1938 pp_variables);
1939 return m_result;
1940}
1941
1942
1943/*! @fn EnumerateOutputVariables
1944
1945 @param count
1946 @param pp_variables
1947 @return
1948
1949*/
1950inline SpvReflectResult ShaderModule::EnumerateOutputVariables(
1951 uint32_t* p_count,
1952 SpvReflectInterfaceVariable** pp_variables
1953) const
1954{
1955 m_result = spvReflectEnumerateOutputVariables(
1956 &m_module,
1957 p_count,
1958 pp_variables);
1959 return m_result;
1960}
1961
1962/*! @fn EnumerateEntryPointOutputVariables
1963
1964 @param entry_point
1965 @param count
1966 @param pp_variables
1967 @return
1968
1969*/
1970inline SpvReflectResult ShaderModule::EnumerateEntryPointOutputVariables(
1971 const char* entry_point,
1972 uint32_t* p_count,
1973 SpvReflectInterfaceVariable** pp_variables
1974) const
1975{
1976 m_result = spvReflectEnumerateEntryPointOutputVariables(
1977 &m_module,
1978 entry_point,
1979 p_count,
1980 pp_variables);
1981 return m_result;
1982}
1983
1984
1985/*! @fn EnumeratePushConstantBlocks
1986
1987 @param count
1988 @param pp_blocks
1989 @return
1990
1991*/
1992inline SpvReflectResult ShaderModule::EnumeratePushConstantBlocks(
1993 uint32_t* p_count,
1994 SpvReflectBlockVariable** pp_blocks
1995) const
1996{
1997 m_result = spvReflectEnumeratePushConstantBlocks(
1998 &m_module,
1999 p_count,
2000 pp_blocks);
2001 return m_result;
2002}
2003
2004/*! @fn EnumerateEntryPointPushConstantBlocks
2005
2006 @param entry_point
2007 @param count
2008 @param pp_blocks
2009 @return
2010
2011*/
2012inline SpvReflectResult ShaderModule::EnumerateEntryPointPushConstantBlocks(
2013 const char* entry_point,
2014 uint32_t* p_count,
2015 SpvReflectBlockVariable** pp_blocks
2016) const
2017{
2018 m_result = spvReflectEnumerateEntryPointPushConstantBlocks(
2019 &m_module,
2020 entry_point,
2021 p_count,
2022 pp_blocks);
2023 return m_result;
2024}
2025
2026
2027/*! @fn GetDescriptorBinding
2028
2029 @param binding_number
2030 @param set_number
2031 @param p_result
2032 @return
2033
2034*/
2035inline const SpvReflectDescriptorBinding* ShaderModule::GetDescriptorBinding(
2036 uint32_t binding_number,
2037 uint32_t set_number,
2038 SpvReflectResult* p_result
2039) const
2040{
2041 return spvReflectGetDescriptorBinding(
2042 &m_module,
2043 binding_number,
2044 set_number,
2045 p_result);
2046}
2047
2048/*! @fn GetEntryPointDescriptorBinding
2049
2050 @param entry_point
2051 @param binding_number
2052 @param set_number
2053 @param p_result
2054 @return
2055
2056*/
2057inline const SpvReflectDescriptorBinding* ShaderModule::GetEntryPointDescriptorBinding(
2058 const char* entry_point,
2059 uint32_t binding_number,
2060 uint32_t set_number,
2061 SpvReflectResult* p_result
2062) const
2063{
2064 return spvReflectGetEntryPointDescriptorBinding(
2065 &m_module,
2066 entry_point,
2067 binding_number,
2068 set_number,
2069 p_result);
2070}
2071
2072
2073/*! @fn GetDescriptorSet
2074
2075 @param set_number
2076 @param p_result
2077 @return
2078
2079*/
2080inline const SpvReflectDescriptorSet* ShaderModule::GetDescriptorSet(
2081 uint32_t set_number,
2082 SpvReflectResult* p_result
2083) const
2084{
2085 return spvReflectGetDescriptorSet(
2086 &m_module,
2087 set_number,
2088 p_result);
2089}
2090
2091/*! @fn GetEntryPointDescriptorSet
2092
2093 @param entry_point
2094 @param set_number
2095 @param p_result
2096 @return
2097
2098*/
2099inline const SpvReflectDescriptorSet* ShaderModule::GetEntryPointDescriptorSet(
2100 const char* entry_point,
2101 uint32_t set_number,
2102 SpvReflectResult* p_result
2103) const
2104{
2105 return spvReflectGetEntryPointDescriptorSet(
2106 &m_module,
2107 entry_point,
2108 set_number,
2109 p_result);
2110}
2111
2112
2113/*! @fn GetInputVariable
2114
2115 @param location
2116 @param p_result
2117 @return
2118
2119*/
2120inline const SpvReflectInterfaceVariable* ShaderModule::GetInputVariableByLocation(
2121 uint32_t location,
2122 SpvReflectResult* p_result
2123) const
2124{
2125 return spvReflectGetInputVariableByLocation(
2126 &m_module,
2127 location,
2128 p_result);
2129}
2130inline const SpvReflectInterfaceVariable* ShaderModule::GetInputVariableBySemantic(
2131 const char* semantic,
2132 SpvReflectResult* p_result
2133) const
2134{
2135 return spvReflectGetInputVariableBySemantic(
2136 &m_module,
2137 semantic,
2138 p_result);
2139}
2140
2141/*! @fn GetEntryPointInputVariable
2142
2143 @param entry_point
2144 @param location
2145 @param p_result
2146 @return
2147
2148*/
2149inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointInputVariableByLocation(
2150 const char* entry_point,
2151 uint32_t location,
2152 SpvReflectResult* p_result
2153) const
2154{
2155 return spvReflectGetEntryPointInputVariableByLocation(
2156 &m_module,
2157 entry_point,
2158 location,
2159 p_result);
2160}
2161inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointInputVariableBySemantic(
2162 const char* entry_point,
2163 const char* semantic,
2164 SpvReflectResult* p_result
2165) const
2166{
2167 return spvReflectGetEntryPointInputVariableBySemantic(
2168 &m_module,
2169 entry_point,
2170 semantic,
2171 p_result);
2172}
2173
2174
2175/*! @fn GetOutputVariable
2176
2177 @param location
2178 @param p_result
2179 @return
2180
2181*/
2182inline const SpvReflectInterfaceVariable* ShaderModule::GetOutputVariableByLocation(
2183 uint32_t location,
2184 SpvReflectResult* p_result
2185) const
2186{
2187 return spvReflectGetOutputVariableByLocation(
2188 &m_module,
2189 location,
2190 p_result);
2191}
2192inline const SpvReflectInterfaceVariable* ShaderModule::GetOutputVariableBySemantic(
2193 const char* semantic,
2194 SpvReflectResult* p_result
2195) const
2196{
2197 return spvReflectGetOutputVariableBySemantic(&m_module,
2198 semantic,
2199 p_result);
2200}
2201
2202/*! @fn GetEntryPointOutputVariable
2203
2204 @param entry_point
2205 @param location
2206 @param p_result
2207 @return
2208
2209*/
2210inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointOutputVariableByLocation(
2211 const char* entry_point,
2212 uint32_t location,
2213 SpvReflectResult* p_result
2214) const
2215{
2216 return spvReflectGetEntryPointOutputVariableByLocation(
2217 &m_module,
2218 entry_point,
2219 location,
2220 p_result);
2221}
2222inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointOutputVariableBySemantic(
2223 const char* entry_point,
2224 const char* semantic,
2225 SpvReflectResult* p_result
2226) const
2227{
2228 return spvReflectGetEntryPointOutputVariableBySemantic(
2229 &m_module,
2230 entry_point,
2231 semantic,
2232 p_result);
2233}
2234
2235
2236/*! @fn GetPushConstant
2237
2238 @param index
2239 @param p_result
2240 @return
2241
2242*/
2243inline const SpvReflectBlockVariable* ShaderModule::GetPushConstantBlock(
2244 uint32_t index,
2245 SpvReflectResult* p_result
2246) const
2247{
2248 return spvReflectGetPushConstantBlock(
2249 &m_module,
2250 index,
2251 p_result);
2252}
2253
2254/*! @fn GetEntryPointPushConstant
2255
2256 @param entry_point
2257 @param index
2258 @param p_result
2259 @return
2260
2261*/
2262inline const SpvReflectBlockVariable* ShaderModule::GetEntryPointPushConstantBlock(
2263 const char* entry_point,
2264 SpvReflectResult* p_result
2265) const
2266{
2267 return spvReflectGetEntryPointPushConstantBlock(
2268 &m_module,
2269 entry_point,
2270 p_result);
2271}
2272
2273
2274/*! @fn ChangeDescriptorBindingNumbers
2275
2276 @param p_binding
2277 @param new_binding_number
2278 @param new_set_number
2279 @return
2280
2281*/
2282inline SpvReflectResult ShaderModule::ChangeDescriptorBindingNumbers(
2283 const SpvReflectDescriptorBinding* p_binding,
2284 uint32_t new_binding_number,
2285 uint32_t new_set_number
2286)
2287{
2288 return spvReflectChangeDescriptorBindingNumbers(
2289 &m_module,
2290 p_binding,
2291 new_binding_number,
2292 new_set_number);
2293}
2294
2295
2296/*! @fn ChangeDescriptorSetNumber
2297
2298 @param p_set
2299 @param new_set_number
2300 @return
2301
2302*/
2303inline SpvReflectResult ShaderModule::ChangeDescriptorSetNumber(
2304 const SpvReflectDescriptorSet* p_set,
2305 uint32_t new_set_number
2306)
2307{
2308 return spvReflectChangeDescriptorSetNumber(
2309 &m_module,
2310 p_set,
2311 new_set_number);
2312}
2313
2314
2315/*! @fn ChangeInputVariableLocation
2316
2317 @param p_input_variable
2318 @param new_location
2319 @return
2320
2321*/
2322inline SpvReflectResult ShaderModule::ChangeInputVariableLocation(
2323 const SpvReflectInterfaceVariable* p_input_variable,
2324 uint32_t new_location)
2325{
2326 return spvReflectChangeInputVariableLocation(
2327 &m_module,
2328 p_input_variable,
2329 new_location);
2330}
2331
2332
2333/*! @fn ChangeOutputVariableLocation
2334
2335 @param p_input_variable
2336 @param new_location
2337 @return
2338
2339*/
2340inline SpvReflectResult ShaderModule::ChangeOutputVariableLocation(
2341 const SpvReflectInterfaceVariable* p_output_variable,
2342 uint32_t new_location)
2343{
2344 return spvReflectChangeOutputVariableLocation(
2345 &m_module,
2346 p_output_variable,
2347 new_location);
2348}
2349
2350} // namespace spv_reflect
2351#endif // defined(__cplusplus)
2352#endif // SPIRV_REFLECT_H
2353