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