FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
spirv_reflect.h
Go to the documentation of this file.
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// clang-format off
31#ifndef SPIRV_REFLECT_H
32#define SPIRV_REFLECT_H
33
34#if defined(SPIRV_REFLECT_USE_SYSTEM_SPIRV_H)
35#include <spirv/unified1/spirv.h>
36#else
37#include "./spirv/unified1/spirv.h"
38#endif
39
40
41#include <stdint.h>
42#include <string.h>
43
44#ifdef _MSC_VER
45 #define SPV_REFLECT_DEPRECATED(msg_str) __declspec(deprecated("This symbol is deprecated. Details: " msg_str))
46#elif defined(__clang__)
47 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated(msg_str)))
48#elif defined(__GNUC__)
49 #if GCC_VERSION >= 40500
50 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated(msg_str)))
51 #else
52 #define SPV_REFLECT_DEPRECATED(msg_str) __attribute__((deprecated))
53 #endif
54#else
55 #define SPV_REFLECT_DEPRECATED(msg_str)
56#endif
57
61typedef enum SpvReflectResult {
62 SPV_REFLECT_RESULT_SUCCESS,
63 SPV_REFLECT_RESULT_NOT_READY,
64 SPV_REFLECT_RESULT_ERROR_PARSE_FAILED,
65 SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED,
66 SPV_REFLECT_RESULT_ERROR_RANGE_EXCEEDED,
67 SPV_REFLECT_RESULT_ERROR_NULL_POINTER,
68 SPV_REFLECT_RESULT_ERROR_INTERNAL_ERROR,
69 SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH,
70 SPV_REFLECT_RESULT_ERROR_ELEMENT_NOT_FOUND,
71 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_CODE_SIZE,
72 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_MAGIC_NUMBER,
73 SPV_REFLECT_RESULT_ERROR_SPIRV_UNEXPECTED_EOF,
74 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE,
75 SPV_REFLECT_RESULT_ERROR_SPIRV_SET_NUMBER_OVERFLOW,
76 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_STORAGE_CLASS,
77 SPV_REFLECT_RESULT_ERROR_SPIRV_RECURSION,
78 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_INSTRUCTION,
79 SPV_REFLECT_RESULT_ERROR_SPIRV_UNEXPECTED_BLOCK_DATA,
80 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_BLOCK_MEMBER_REFERENCE,
81 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ENTRY_POINT,
82 SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_EXECUTION_MODE,
83 SPV_REFLECT_RESULT_ERROR_SPIRV_MAX_RECURSIVE_EXCEEDED,
84} SpvReflectResult;
85
99 SPV_REFLECT_MODULE_FLAG_NONE = 0x00000000,
100 SPV_REFLECT_MODULE_FLAG_NO_COPY = 0x00000001,
102
103typedef uint32_t SpvReflectModuleFlags;
104
108typedef enum SpvReflectTypeFlagBits {
109 SPV_REFLECT_TYPE_FLAG_UNDEFINED = 0x00000000,
110 SPV_REFLECT_TYPE_FLAG_VOID = 0x00000001,
111 SPV_REFLECT_TYPE_FLAG_BOOL = 0x00000002,
112 SPV_REFLECT_TYPE_FLAG_INT = 0x00000004,
113 SPV_REFLECT_TYPE_FLAG_FLOAT = 0x00000008,
114 SPV_REFLECT_TYPE_FLAG_VECTOR = 0x00000100,
115 SPV_REFLECT_TYPE_FLAG_MATRIX = 0x00000200,
116 SPV_REFLECT_TYPE_FLAG_EXTERNAL_IMAGE = 0x00010000,
117 SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLER = 0x00020000,
118 SPV_REFLECT_TYPE_FLAG_EXTERNAL_SAMPLED_IMAGE = 0x00040000,
119 SPV_REFLECT_TYPE_FLAG_EXTERNAL_BLOCK = 0x00080000,
120 SPV_REFLECT_TYPE_FLAG_EXTERNAL_ACCELERATION_STRUCTURE = 0x00100000,
121 SPV_REFLECT_TYPE_FLAG_EXTERNAL_MASK = 0x00FF0000,
122 SPV_REFLECT_TYPE_FLAG_STRUCT = 0x10000000,
123 SPV_REFLECT_TYPE_FLAG_ARRAY = 0x20000000,
124 SPV_REFLECT_TYPE_FLAG_REF = 0x40000000,
125} SpvReflectTypeFlagBits;
126
127typedef uint32_t SpvReflectTypeFlags;
128
142typedef enum SpvReflectDecorationFlagBits {
143 SPV_REFLECT_DECORATION_NONE = 0x00000000,
144 SPV_REFLECT_DECORATION_BLOCK = 0x00000001,
145 SPV_REFLECT_DECORATION_BUFFER_BLOCK = 0x00000002,
146 SPV_REFLECT_DECORATION_ROW_MAJOR = 0x00000004,
147 SPV_REFLECT_DECORATION_COLUMN_MAJOR = 0x00000008,
148 SPV_REFLECT_DECORATION_BUILT_IN = 0x00000010,
149 SPV_REFLECT_DECORATION_NOPERSPECTIVE = 0x00000020,
150 SPV_REFLECT_DECORATION_FLAT = 0x00000040,
151 SPV_REFLECT_DECORATION_NON_WRITABLE = 0x00000080,
152 SPV_REFLECT_DECORATION_RELAXED_PRECISION = 0x00000100,
153 SPV_REFLECT_DECORATION_NON_READABLE = 0x00000200,
154 SPV_REFLECT_DECORATION_PATCH = 0x00000400,
155 SPV_REFLECT_DECORATION_PER_VERTEX = 0x00000800,
156 SPV_REFLECT_DECORATION_PER_TASK = 0x00001000,
157 SPV_REFLECT_DECORATION_WEIGHT_TEXTURE = 0x00002000,
158 SPV_REFLECT_DECORATION_BLOCK_MATCH_TEXTURE = 0x00004000,
159} SpvReflectDecorationFlagBits;
160
161typedef uint32_t SpvReflectDecorationFlags;
162
163// Based of SPV_GOOGLE_user_type
164typedef enum SpvReflectUserType {
165 SPV_REFLECT_USER_TYPE_INVALID = 0,
166 SPV_REFLECT_USER_TYPE_CBUFFER,
167 SPV_REFLECT_USER_TYPE_TBUFFER,
168 SPV_REFLECT_USER_TYPE_APPEND_STRUCTURED_BUFFER,
169 SPV_REFLECT_USER_TYPE_BUFFER,
170 SPV_REFLECT_USER_TYPE_BYTE_ADDRESS_BUFFER,
171 SPV_REFLECT_USER_TYPE_CONSTANT_BUFFER,
172 SPV_REFLECT_USER_TYPE_CONSUME_STRUCTURED_BUFFER,
173 SPV_REFLECT_USER_TYPE_INPUT_PATCH,
174 SPV_REFLECT_USER_TYPE_OUTPUT_PATCH,
175 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_BUFFER,
176 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_BYTE_ADDRESS_BUFFER,
177 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_STRUCTURED_BUFFER,
178 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_TEXTURE_1D,
179 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_TEXTURE_1D_ARRAY,
180 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_TEXTURE_2D,
181 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_TEXTURE_2D_ARRAY,
182 SPV_REFLECT_USER_TYPE_RASTERIZER_ORDERED_TEXTURE_3D,
183 SPV_REFLECT_USER_TYPE_RAYTRACING_ACCELERATION_STRUCTURE,
184 SPV_REFLECT_USER_TYPE_RW_BUFFER,
185 SPV_REFLECT_USER_TYPE_RW_BYTE_ADDRESS_BUFFER,
186 SPV_REFLECT_USER_TYPE_RW_STRUCTURED_BUFFER,
187 SPV_REFLECT_USER_TYPE_RW_TEXTURE_1D,
188 SPV_REFLECT_USER_TYPE_RW_TEXTURE_1D_ARRAY,
189 SPV_REFLECT_USER_TYPE_RW_TEXTURE_2D,
190 SPV_REFLECT_USER_TYPE_RW_TEXTURE_2D_ARRAY,
191 SPV_REFLECT_USER_TYPE_RW_TEXTURE_3D,
192 SPV_REFLECT_USER_TYPE_STRUCTURED_BUFFER,
193 SPV_REFLECT_USER_TYPE_SUBPASS_INPUT,
194 SPV_REFLECT_USER_TYPE_SUBPASS_INPUT_MS,
195 SPV_REFLECT_USER_TYPE_TEXTURE_1D,
196 SPV_REFLECT_USER_TYPE_TEXTURE_1D_ARRAY,
197 SPV_REFLECT_USER_TYPE_TEXTURE_2D,
198 SPV_REFLECT_USER_TYPE_TEXTURE_2D_ARRAY,
199 SPV_REFLECT_USER_TYPE_TEXTURE_2DMS,
200 SPV_REFLECT_USER_TYPE_TEXTURE_2DMS_ARRAY,
201 SPV_REFLECT_USER_TYPE_TEXTURE_3D,
202 SPV_REFLECT_USER_TYPE_TEXTURE_BUFFER,
203 SPV_REFLECT_USER_TYPE_TEXTURE_CUBE,
204 SPV_REFLECT_USER_TYPE_TEXTURE_CUBE_ARRAY,
205} SpvReflectUserType;
206
210typedef enum SpvReflectResourceType {
211 SPV_REFLECT_RESOURCE_FLAG_UNDEFINED = 0x00000000,
212 SPV_REFLECT_RESOURCE_FLAG_SAMPLER = 0x00000001,
213 SPV_REFLECT_RESOURCE_FLAG_CBV = 0x00000002,
214 SPV_REFLECT_RESOURCE_FLAG_SRV = 0x00000004,
215 SPV_REFLECT_RESOURCE_FLAG_UAV = 0x00000008,
216} SpvReflectResourceType;
217
221typedef enum SpvReflectFormat {
222 SPV_REFLECT_FORMAT_UNDEFINED = 0, // = VK_FORMAT_UNDEFINED
223 SPV_REFLECT_FORMAT_R16_UINT = 74, // = VK_FORMAT_R16_UINT
224 SPV_REFLECT_FORMAT_R16_SINT = 75, // = VK_FORMAT_R16_SINT
225 SPV_REFLECT_FORMAT_R16_SFLOAT = 76, // = VK_FORMAT_R16_SFLOAT
226 SPV_REFLECT_FORMAT_R16G16_UINT = 81, // = VK_FORMAT_R16G16_UINT
227 SPV_REFLECT_FORMAT_R16G16_SINT = 82, // = VK_FORMAT_R16G16_SINT
228 SPV_REFLECT_FORMAT_R16G16_SFLOAT = 83, // = VK_FORMAT_R16G16_SFLOAT
229 SPV_REFLECT_FORMAT_R16G16B16_UINT = 88, // = VK_FORMAT_R16G16B16_UINT
230 SPV_REFLECT_FORMAT_R16G16B16_SINT = 89, // = VK_FORMAT_R16G16B16_SINT
231 SPV_REFLECT_FORMAT_R16G16B16_SFLOAT = 90, // = VK_FORMAT_R16G16B16_SFLOAT
232 SPV_REFLECT_FORMAT_R16G16B16A16_UINT = 95, // = VK_FORMAT_R16G16B16A16_UINT
233 SPV_REFLECT_FORMAT_R16G16B16A16_SINT = 96, // = VK_FORMAT_R16G16B16A16_SINT
234 SPV_REFLECT_FORMAT_R16G16B16A16_SFLOAT = 97, // = VK_FORMAT_R16G16B16A16_SFLOAT
235 SPV_REFLECT_FORMAT_R32_UINT = 98, // = VK_FORMAT_R32_UINT
236 SPV_REFLECT_FORMAT_R32_SINT = 99, // = VK_FORMAT_R32_SINT
237 SPV_REFLECT_FORMAT_R32_SFLOAT = 100, // = VK_FORMAT_R32_SFLOAT
238 SPV_REFLECT_FORMAT_R32G32_UINT = 101, // = VK_FORMAT_R32G32_UINT
239 SPV_REFLECT_FORMAT_R32G32_SINT = 102, // = VK_FORMAT_R32G32_SINT
240 SPV_REFLECT_FORMAT_R32G32_SFLOAT = 103, // = VK_FORMAT_R32G32_SFLOAT
241 SPV_REFLECT_FORMAT_R32G32B32_UINT = 104, // = VK_FORMAT_R32G32B32_UINT
242 SPV_REFLECT_FORMAT_R32G32B32_SINT = 105, // = VK_FORMAT_R32G32B32_SINT
243 SPV_REFLECT_FORMAT_R32G32B32_SFLOAT = 106, // = VK_FORMAT_R32G32B32_SFLOAT
244 SPV_REFLECT_FORMAT_R32G32B32A32_UINT = 107, // = VK_FORMAT_R32G32B32A32_UINT
245 SPV_REFLECT_FORMAT_R32G32B32A32_SINT = 108, // = VK_FORMAT_R32G32B32A32_SINT
246 SPV_REFLECT_FORMAT_R32G32B32A32_SFLOAT = 109, // = VK_FORMAT_R32G32B32A32_SFLOAT
247 SPV_REFLECT_FORMAT_R64_UINT = 110, // = VK_FORMAT_R64_UINT
248 SPV_REFLECT_FORMAT_R64_SINT = 111, // = VK_FORMAT_R64_SINT
249 SPV_REFLECT_FORMAT_R64_SFLOAT = 112, // = VK_FORMAT_R64_SFLOAT
250 SPV_REFLECT_FORMAT_R64G64_UINT = 113, // = VK_FORMAT_R64G64_UINT
251 SPV_REFLECT_FORMAT_R64G64_SINT = 114, // = VK_FORMAT_R64G64_SINT
252 SPV_REFLECT_FORMAT_R64G64_SFLOAT = 115, // = VK_FORMAT_R64G64_SFLOAT
253 SPV_REFLECT_FORMAT_R64G64B64_UINT = 116, // = VK_FORMAT_R64G64B64_UINT
254 SPV_REFLECT_FORMAT_R64G64B64_SINT = 117, // = VK_FORMAT_R64G64B64_SINT
255 SPV_REFLECT_FORMAT_R64G64B64_SFLOAT = 118, // = VK_FORMAT_R64G64B64_SFLOAT
256 SPV_REFLECT_FORMAT_R64G64B64A64_UINT = 119, // = VK_FORMAT_R64G64B64A64_UINT
257 SPV_REFLECT_FORMAT_R64G64B64A64_SINT = 120, // = VK_FORMAT_R64G64B64A64_SINT
258 SPV_REFLECT_FORMAT_R64G64B64A64_SFLOAT = 121, // = VK_FORMAT_R64G64B64A64_SFLOAT
259} SpvReflectFormat;
260
264enum SpvReflectVariableFlagBits{
265 SPV_REFLECT_VARIABLE_FLAGS_NONE = 0x00000000,
266 SPV_REFLECT_VARIABLE_FLAGS_UNUSED = 0x00000001,
267 // If variable points to a copy of the PhysicalStorageBuffer struct
268 SPV_REFLECT_VARIABLE_FLAGS_PHYSICAL_POINTER_COPY = 0x00000002,
269};
270
271typedef uint32_t SpvReflectVariableFlags;
272
276typedef enum SpvReflectDescriptorType {
277 SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLER = 0, // = VK_DESCRIPTOR_TYPE_SAMPLER
278 SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER = 1, // = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
279 SPV_REFLECT_DESCRIPTOR_TYPE_SAMPLED_IMAGE = 2, // = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
280 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_IMAGE = 3, // = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
281 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER = 4, // = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
282 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER = 5, // = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
283 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER = 6, // = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
284 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER = 7, // = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
285 SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC = 8, // = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC
286 SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC = 9, // = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC
287 SPV_REFLECT_DESCRIPTOR_TYPE_INPUT_ATTACHMENT = 10, // = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
288 SPV_REFLECT_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR = 1000150000 // = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR
289} SpvReflectDescriptorType;
290
294typedef enum SpvReflectShaderStageFlagBits {
295 SPV_REFLECT_SHADER_STAGE_VERTEX_BIT = 0x00000001, // = VK_SHADER_STAGE_VERTEX_BIT
296 SPV_REFLECT_SHADER_STAGE_TESSELLATION_CONTROL_BIT = 0x00000002, // = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT
297 SPV_REFLECT_SHADER_STAGE_TESSELLATION_EVALUATION_BIT = 0x00000004, // = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
298 SPV_REFLECT_SHADER_STAGE_GEOMETRY_BIT = 0x00000008, // = VK_SHADER_STAGE_GEOMETRY_BIT
299 SPV_REFLECT_SHADER_STAGE_FRAGMENT_BIT = 0x00000010, // = VK_SHADER_STAGE_FRAGMENT_BIT
300 SPV_REFLECT_SHADER_STAGE_COMPUTE_BIT = 0x00000020, // = VK_SHADER_STAGE_COMPUTE_BIT
301 SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV = 0x00000040, // = VK_SHADER_STAGE_TASK_BIT_NV
302 SPV_REFLECT_SHADER_STAGE_TASK_BIT_EXT = SPV_REFLECT_SHADER_STAGE_TASK_BIT_NV, // = VK_SHADER_STAGE_CALLABLE_BIT_EXT
303 SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV = 0x00000080, // = VK_SHADER_STAGE_MESH_BIT_NV
304 SPV_REFLECT_SHADER_STAGE_MESH_BIT_EXT = SPV_REFLECT_SHADER_STAGE_MESH_BIT_NV, // = VK_SHADER_STAGE_CALLABLE_BIT_EXT
305 SPV_REFLECT_SHADER_STAGE_RAYGEN_BIT_KHR = 0x00000100, // = VK_SHADER_STAGE_RAYGEN_BIT_KHR
306 SPV_REFLECT_SHADER_STAGE_ANY_HIT_BIT_KHR = 0x00000200, // = VK_SHADER_STAGE_ANY_HIT_BIT_KHR
307 SPV_REFLECT_SHADER_STAGE_CLOSEST_HIT_BIT_KHR = 0x00000400, // = VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
308 SPV_REFLECT_SHADER_STAGE_MISS_BIT_KHR = 0x00000800, // = VK_SHADER_STAGE_MISS_BIT_KHR
309 SPV_REFLECT_SHADER_STAGE_INTERSECTION_BIT_KHR = 0x00001000, // = VK_SHADER_STAGE_INTERSECTION_BIT_KHR
310 SPV_REFLECT_SHADER_STAGE_CALLABLE_BIT_KHR = 0x00002000, // = VK_SHADER_STAGE_CALLABLE_BIT_KHR
311
312} SpvReflectShaderStageFlagBits;
313
317typedef enum SpvReflectGenerator {
318 SPV_REFLECT_GENERATOR_KHRONOS_LLVM_SPIRV_TRANSLATOR = 6,
319 SPV_REFLECT_GENERATOR_KHRONOS_SPIRV_TOOLS_ASSEMBLER = 7,
320 SPV_REFLECT_GENERATOR_KHRONOS_GLSLANG_REFERENCE_FRONT_END = 8,
321 SPV_REFLECT_GENERATOR_GOOGLE_SHADERC_OVER_GLSLANG = 13,
322 SPV_REFLECT_GENERATOR_GOOGLE_SPIREGG = 14,
323 SPV_REFLECT_GENERATOR_GOOGLE_RSPIRV = 15,
324 SPV_REFLECT_GENERATOR_X_LEGEND_MESA_MESAIR_SPIRV_TRANSLATOR = 16,
325 SPV_REFLECT_GENERATOR_KHRONOS_SPIRV_TOOLS_LINKER = 17,
326 SPV_REFLECT_GENERATOR_WINE_VKD3D_SHADER_COMPILER = 18,
327 SPV_REFLECT_GENERATOR_CLAY_CLAY_SHADER_COMPILER = 19,
328} SpvReflectGenerator;
329
330enum {
331 SPV_REFLECT_MAX_ARRAY_DIMS = 32,
332 SPV_REFLECT_MAX_DESCRIPTOR_SETS = 64,
333};
334
335enum {
336 SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE = ~0,
337 SPV_REFLECT_SET_NUMBER_DONT_CHANGE = ~0
338};
339
341 struct Scalar {
342 uint32_t width;
343 uint32_t signedness;
344 } scalar;
345
346 struct Vector {
347 uint32_t component_count;
348 } vector;
349
350 struct Matrix {
351 uint32_t column_count;
352 uint32_t row_count;
353 uint32_t stride; // Measured in bytes
354 } matrix;
356
357typedef struct SpvReflectImageTraits {
358 SpvDim dim;
359 uint32_t depth;
360 uint32_t arrayed;
361 uint32_t ms; // 0: single-sampled; 1: multisampled
362 uint32_t sampled;
363 SpvImageFormat image_format;
365
366typedef enum SpvReflectArrayDimType {
367 SPV_REFLECT_ARRAY_DIM_RUNTIME = 0, // OpTypeRuntimeArray
368} SpvReflectArrayDimType;
369
370typedef struct SpvReflectArrayTraits {
371 uint32_t dims_count;
372 // Each entry is either:
373 // - specialization constant dimension
374 // - OpTypeRuntimeArray
375 // - the array length otherwise
376 uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS];
377 // Stores Ids for dimensions that are specialization constants
378 uint32_t spec_constant_op_ids[SPV_REFLECT_MAX_ARRAY_DIMS];
379 uint32_t stride; // Measured in bytes
381
383 uint32_t dims_count;
384 uint32_t dims[SPV_REFLECT_MAX_ARRAY_DIMS];
386
391 uint32_t id;
392 SpvOp op;
393 const char* type_name;
394 // Non-NULL if type is member of a struct
395 const char* struct_member_name;
396 SpvStorageClass storage_class;
397 SpvReflectTypeFlags type_flags;
398 SpvReflectDecorationFlags decoration_flags;
399
400 struct Traits {
404 } traits;
405
406 // If underlying type is a struct (ex. array of structs)
407 // this gives access to the OpTypeStruct
408 struct SpvReflectTypeDescription* struct_type_description;
409
410 // Some pointers to SpvReflectTypeDescription are really
411 // just copies of another reference to the same OpType
412 uint32_t copied;
413
414 // @deprecated use struct_type_description instead
415 uint32_t member_count;
416 // @deprecated use struct_type_description instead
417 struct SpvReflectTypeDescription* members;
419
420
425 uint32_t spirv_id;
426 const char* name;
427 uint32_t location;
428 uint32_t component;
429 SpvStorageClass storage_class;
430 const char* semantic;
431 SpvReflectDecorationFlags decoration_flags;
432 SpvBuiltIn built_in;
435
436 uint32_t member_count;
437 struct SpvReflectInterfaceVariable* members;
438
439 SpvReflectFormat format;
440
441 // NOTE: SPIR-V shares type references for variables
442 // that have the same underlying type. This means
443 // that the same type name will appear for multiple
444 // variables.
445 SpvReflectTypeDescription* type_description;
446
447 struct {
448 uint32_t location;
449 } word_offset;
451
456 uint32_t spirv_id;
457 const char* name;
458 // For Push Constants, this is the lowest offset of all memebers
459 uint32_t offset; // Measured in bytes
460 uint32_t absolute_offset; // Measured in bytes
461 uint32_t size; // Measured in bytes
462 uint32_t padded_size; // Measured in bytes
463 SpvReflectDecorationFlags decoration_flags;
466 SpvReflectVariableFlags flags;
467
468 uint32_t member_count;
469 struct SpvReflectBlockVariable* members;
470
471 SpvReflectTypeDescription* type_description;
472
473 struct {
474 uint32_t offset;
475 } word_offset;
476
478
483 uint32_t spirv_id;
484 const char* name;
485 uint32_t binding;
486 uint32_t input_attachment_index;
487 uint32_t set;
488 SpvReflectDescriptorType descriptor_type;
489 SpvReflectResourceType resource_type;
493 uint32_t count;
494 uint32_t accessed;
495 uint32_t uav_counter_id;
496 struct SpvReflectDescriptorBinding* uav_counter_binding;
497 uint32_t byte_address_buffer_offset_count;
498 uint32_t* byte_address_buffer_offsets;
499
500 SpvReflectTypeDescription* type_description;
501
502 struct {
503 uint32_t binding;
504 uint32_t set;
505 } word_offset;
506
507 SpvReflectDecorationFlags decoration_flags;
508 // Requires SPV_GOOGLE_user_type
509 SpvReflectUserType user_type;
511
516 uint32_t set;
517 uint32_t binding_count;
520
521typedef enum SpvReflectExecutionModeValue {
522 SPV_REFLECT_EXECUTION_MODE_SPEC_CONSTANT = 0xFFFFFFFF // specialization constant
523} SpvReflectExecutionModeValue;
524
528typedef struct SpvReflectEntryPoint {
529 const char* name;
530 uint32_t id;
531
532 SpvExecutionModel spirv_execution_model;
533 SpvReflectShaderStageFlagBits shader_stage;
534
535 uint32_t input_variable_count;
536 SpvReflectInterfaceVariable** input_variables;
537 uint32_t output_variable_count;
538 SpvReflectInterfaceVariable** output_variables;
539 uint32_t interface_variable_count;
540 SpvReflectInterfaceVariable* interface_variables;
541
542 uint32_t descriptor_set_count;
543 SpvReflectDescriptorSet* descriptor_sets;
544
545 uint32_t used_uniform_count;
546 uint32_t* used_uniforms;
547 uint32_t used_push_constant_count;
548 uint32_t* used_push_constants;
549
550 uint32_t execution_mode_count;
551 SpvExecutionMode* execution_modes;
552
553 struct LocalSize {
554 uint32_t x;
555 uint32_t y;
556 uint32_t z;
557 } local_size;
558 uint32_t invocations; // valid for geometry
559 uint32_t output_vertices; // valid for geometry, tesselation
561
565typedef struct SpvReflectCapability {
566 SpvCapability value;
567 uint32_t word_offset;
569
570
575 uint32_t spirv_id;
576 uint32_t constant_id;
577 const char* name;
579
584 SpvReflectGenerator generator;
585 const char* entry_point_name;
586 uint32_t entry_point_id;
587 uint32_t entry_point_count;
588 SpvReflectEntryPoint* entry_points;
589 SpvSourceLanguage source_language;
590 uint32_t source_language_version;
591 const char* source_file;
592 const char* source_source;
593 uint32_t capability_count;
594 SpvReflectCapability* capabilities;
595 SpvExecutionModel spirv_execution_model; // Uses value(s) from first entry point
596 SpvReflectShaderStageFlagBits shader_stage; // Uses value(s) from first entry point
597 uint32_t descriptor_binding_count; // Uses value(s) from first entry point
598 SpvReflectDescriptorBinding* descriptor_bindings; // Uses value(s) from first entry point
599 uint32_t descriptor_set_count; // Uses value(s) from first entry point
600 SpvReflectDescriptorSet descriptor_sets[SPV_REFLECT_MAX_DESCRIPTOR_SETS]; // Uses value(s) from first entry point
601 uint32_t input_variable_count; // Uses value(s) from first entry point
602 SpvReflectInterfaceVariable** input_variables; // Uses value(s) from first entry point
603 uint32_t output_variable_count; // Uses value(s) from first entry point
604 SpvReflectInterfaceVariable** output_variables; // Uses value(s) from first entry point
605 uint32_t interface_variable_count; // Uses value(s) from first entry point
606 SpvReflectInterfaceVariable* interface_variables; // Uses value(s) from first entry point
607 uint32_t push_constant_block_count; // Uses value(s) from first entry point
608 SpvReflectBlockVariable* push_constant_blocks; // Uses value(s) from first entry point
609 uint32_t spec_constant_count; // Uses value(s) from first entry point
610 SpvReflectSpecializationConstant* spec_constants; // Uses value(s) from first entry point
611
612 struct Internal {
613 SpvReflectModuleFlags module_flags;
614 size_t spirv_size;
615 uint32_t* spirv_code;
616 uint32_t spirv_word_count;
617
618 size_t type_description_count;
619 SpvReflectTypeDescription* type_descriptions;
620 } * _internal;
621
623
624#if defined(__cplusplus)
625extern "C" {
626#endif
627
636SpvReflectResult spvReflectCreateShaderModule(
637 size_t size,
638 const void* p_code,
639 SpvReflectShaderModule* p_module
640);
641
651SpvReflectResult spvReflectCreateShaderModule2(
652 SpvReflectModuleFlags flags,
653 size_t size,
654 const void* p_code,
655 SpvReflectShaderModule* p_module
656);
657
658SPV_REFLECT_DEPRECATED("renamed to spvReflectCreateShaderModule")
659SpvReflectResult spvReflectGetShaderModule(
660 size_t size,
661 const void* p_code,
662 SpvReflectShaderModule* p_module
663);
664
665
671void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module);
672
673
680uint32_t spvReflectGetCodeSize(const SpvReflectShaderModule* p_module);
681
682
689const uint32_t* spvReflectGetCode(const SpvReflectShaderModule* p_module);
690
698const SpvReflectEntryPoint* spvReflectGetEntryPoint(
699 const SpvReflectShaderModule* p_module,
700 const char* entry_point
701);
702
721SpvReflectResult spvReflectEnumerateDescriptorBindings(
722 const SpvReflectShaderModule* p_module,
723 uint32_t* p_count,
724 SpvReflectDescriptorBinding** pp_bindings
725);
726
747SpvReflectResult spvReflectEnumerateEntryPointDescriptorBindings(
748 const SpvReflectShaderModule* p_module,
749 const char* entry_point,
750 uint32_t* p_count,
751 SpvReflectDescriptorBinding** pp_bindings
752);
753
772SpvReflectResult spvReflectEnumerateDescriptorSets(
773 const SpvReflectShaderModule* p_module,
774 uint32_t* p_count,
776);
777
798SpvReflectResult spvReflectEnumerateEntryPointDescriptorSets(
799 const SpvReflectShaderModule* p_module,
800 const char* entry_point,
801 uint32_t* p_count,
803);
804
805
825SpvReflectResult spvReflectEnumerateInterfaceVariables(
826 const SpvReflectShaderModule* p_module,
827 uint32_t* p_count,
828 SpvReflectInterfaceVariable** pp_variables
829);
830
850SpvReflectResult spvReflectEnumerateEntryPointInterfaceVariables(
851 const SpvReflectShaderModule* p_module,
852 const char* entry_point,
853 uint32_t* p_count,
854 SpvReflectInterfaceVariable** pp_variables
855);
856
857
877SpvReflectResult spvReflectEnumerateInputVariables(
878 const SpvReflectShaderModule* p_module,
879 uint32_t* p_count,
880 SpvReflectInterfaceVariable** pp_variables
881);
882
902SpvReflectResult spvReflectEnumerateEntryPointInputVariables(
903 const SpvReflectShaderModule* p_module,
904 const char* entry_point,
905 uint32_t* p_count,
906 SpvReflectInterfaceVariable** pp_variables
907);
908
909
929SpvReflectResult spvReflectEnumerateOutputVariables(
930 const SpvReflectShaderModule* p_module,
931 uint32_t* p_count,
932 SpvReflectInterfaceVariable** pp_variables
933);
934
954SpvReflectResult spvReflectEnumerateEntryPointOutputVariables(
955 const SpvReflectShaderModule* p_module,
956 const char* entry_point,
957 uint32_t* p_count,
958 SpvReflectInterfaceVariable** pp_variables
959);
960
961
982SpvReflectResult spvReflectEnumeratePushConstantBlocks(
983 const SpvReflectShaderModule* p_module,
984 uint32_t* p_count,
985 SpvReflectBlockVariable** pp_blocks
986);
987SPV_REFLECT_DEPRECATED("renamed to spvReflectEnumeratePushConstantBlocks")
988SpvReflectResult spvReflectEnumeratePushConstants(
989 const SpvReflectShaderModule* p_module,
990 uint32_t* p_count,
991 SpvReflectBlockVariable** pp_blocks
992);
993
1014SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks(
1015 const SpvReflectShaderModule* p_module,
1016 const char* entry_point,
1017 uint32_t* p_count,
1018 SpvReflectBlockVariable** pp_blocks
1019);
1020
1021
1035SpvReflectResult spvReflectEnumerateSpecializationConstants(
1036 const SpvReflectShaderModule* p_module,
1037 uint32_t* p_count,
1039);
1040
1063const SpvReflectDescriptorBinding* spvReflectGetDescriptorBinding(
1064 const SpvReflectShaderModule* p_module,
1065 uint32_t binding_number,
1066 uint32_t set_number,
1067 SpvReflectResult* p_result
1068);
1069
1095const SpvReflectDescriptorBinding* spvReflectGetEntryPointDescriptorBinding(
1096 const SpvReflectShaderModule* p_module,
1097 const char* entry_point,
1098 uint32_t binding_number,
1099 uint32_t set_number,
1100 SpvReflectResult* p_result
1101);
1102
1103
1120const SpvReflectDescriptorSet* spvReflectGetDescriptorSet(
1121 const SpvReflectShaderModule* p_module,
1122 uint32_t set_number,
1123 SpvReflectResult* p_result
1124);
1125
1143const SpvReflectDescriptorSet* spvReflectGetEntryPointDescriptorSet(
1144 const SpvReflectShaderModule* p_module,
1145 const char* entry_point,
1146 uint32_t set_number,
1147 SpvReflectResult* p_result
1148);
1149
1150
1151/* @fn spvReflectGetInputVariableByLocation
1152
1153 @param p_module Pointer to an instance of SpvReflectShaderModule.
1154 @param location The "location" value of the requested input variable.
1155 A location of 0xFFFFFFFF will always return NULL
1156 with *p_result == ELEMENT_NOT_FOUND.
1157 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1158 written to *p_result. Otherwise, a error code
1159 indicating the cause of the failure will be stored
1160 here.
1161 @return If the module contains an input interface variable
1162 with the provided location value, a pointer to that
1163 variable is returned. The caller must not free this
1164 pointer.
1165 If no match can be found, or if an unrelated error
1166 occurs, the return value will be NULL. Detailed
1167 error results are written to *pResult.
1168@note
1169
1170*/
1171const SpvReflectInterfaceVariable* spvReflectGetInputVariableByLocation(
1172 const SpvReflectShaderModule* p_module,
1173 uint32_t location,
1174 SpvReflectResult* p_result
1175);
1176SPV_REFLECT_DEPRECATED("renamed to spvReflectGetInputVariableByLocation")
1177const SpvReflectInterfaceVariable* spvReflectGetInputVariable(
1178 const SpvReflectShaderModule* p_module,
1179 uint32_t location,
1180 SpvReflectResult* p_result
1181);
1182
1183/* @fn spvReflectGetEntryPointInputVariableByLocation
1184
1185 @param p_module Pointer to an instance of SpvReflectShaderModule.
1186 @param entry_point The entry point to get the input variable from.
1187 @param location The "location" value of the requested input variable.
1188 A location of 0xFFFFFFFF will always return NULL
1189 with *p_result == ELEMENT_NOT_FOUND.
1190 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1191 written to *p_result. Otherwise, a error code
1192 indicating the cause of the failure will be stored
1193 here.
1194 @return If the entry point contains an input interface variable
1195 with the provided location value, a pointer to that
1196 variable is returned. The caller must not free this
1197 pointer.
1198 If no match can be found, or if an unrelated error
1199 occurs, the return value will be NULL. Detailed
1200 error results are written to *pResult.
1201@note
1202
1203*/
1204const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableByLocation(
1205 const SpvReflectShaderModule* p_module,
1206 const char* entry_point,
1207 uint32_t location,
1208 SpvReflectResult* p_result
1209);
1210
1211/* @fn spvReflectGetInputVariableBySemantic
1212
1213 @param p_module Pointer to an instance of SpvReflectShaderModule.
1214 @param semantic The "semantic" value of the requested input variable.
1215 A semantic of NULL will return NULL.
1216 A semantic of "" will always return NULL with
1217 *p_result == ELEMENT_NOT_FOUND.
1218 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1219 written to *p_result. Otherwise, a error code
1220 indicating the cause of the failure will be stored
1221 here.
1222 @return If the module contains an input interface variable
1223 with the provided semantic, a pointer to that
1224 variable is returned. The caller must not free this
1225 pointer.
1226 If no match can be found, or if an unrelated error
1227 occurs, the return value will be NULL. Detailed
1228 error results are written to *pResult.
1229@note
1230
1231*/
1232const SpvReflectInterfaceVariable* spvReflectGetInputVariableBySemantic(
1233 const SpvReflectShaderModule* p_module,
1234 const char* semantic,
1235 SpvReflectResult* p_result
1236);
1237
1238/* @fn spvReflectGetEntryPointInputVariableBySemantic
1239
1240 @param p_module Pointer to an instance of SpvReflectShaderModule.
1241 @param entry_point The entry point to get the input variable from.
1242 @param semantic The "semantic" value of the requested input variable.
1243 A semantic of NULL will return NULL.
1244 A semantic of "" will always return NULL with
1245 *p_result == ELEMENT_NOT_FOUND.
1246 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1247 written to *p_result. Otherwise, a error code
1248 indicating the cause of the failure will be stored
1249 here.
1250 @return If the entry point contains an input interface variable
1251 with the provided semantic, a pointer to that
1252 variable is returned. The caller must not free this
1253 pointer.
1254 If no match can be found, or if an unrelated error
1255 occurs, the return value will be NULL. Detailed
1256 error results are written to *pResult.
1257@note
1258
1259*/
1260const SpvReflectInterfaceVariable* spvReflectGetEntryPointInputVariableBySemantic(
1261 const SpvReflectShaderModule* p_module,
1262 const char* entry_point,
1263 const char* semantic,
1264 SpvReflectResult* p_result
1265);
1266
1267/* @fn spvReflectGetOutputVariableByLocation
1268
1269 @param p_module Pointer to an instance of SpvReflectShaderModule.
1270 @param location The "location" value of the requested output variable.
1271 A location of 0xFFFFFFFF will always return NULL
1272 with *p_result == ELEMENT_NOT_FOUND.
1273 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1274 written to *p_result. Otherwise, a error code
1275 indicating the cause of the failure will be stored
1276 here.
1277 @return If the module contains an output interface variable
1278 with the provided location value, a pointer to that
1279 variable is returned. The caller must not free this
1280 pointer.
1281 If no match can be found, or if an unrelated error
1282 occurs, the return value will be NULL. Detailed
1283 error results are written to *pResult.
1284@note
1285
1286*/
1287const SpvReflectInterfaceVariable* spvReflectGetOutputVariableByLocation(
1288 const SpvReflectShaderModule* p_module,
1289 uint32_t location,
1290 SpvReflectResult* p_result
1291);
1292SPV_REFLECT_DEPRECATED("renamed to spvReflectGetOutputVariableByLocation")
1293const SpvReflectInterfaceVariable* spvReflectGetOutputVariable(
1294 const SpvReflectShaderModule* p_module,
1295 uint32_t location,
1296 SpvReflectResult* p_result
1297);
1298
1299/* @fn spvReflectGetEntryPointOutputVariableByLocation
1300
1301 @param p_module Pointer to an instance of SpvReflectShaderModule.
1302 @param entry_point The entry point to get the output variable from.
1303 @param location The "location" value of the requested output variable.
1304 A location of 0xFFFFFFFF will always return NULL
1305 with *p_result == ELEMENT_NOT_FOUND.
1306 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1307 written to *p_result. Otherwise, a error code
1308 indicating the cause of the failure will be stored
1309 here.
1310 @return If the entry point contains an output interface variable
1311 with the provided location value, a pointer to that
1312 variable is returned. The caller must not free this
1313 pointer.
1314 If no match can be found, or if an unrelated error
1315 occurs, the return value will be NULL. Detailed
1316 error results are written to *pResult.
1317@note
1318
1319*/
1320const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableByLocation(
1321 const SpvReflectShaderModule* p_module,
1322 const char* entry_point,
1323 uint32_t location,
1324 SpvReflectResult* p_result
1325);
1326
1327/* @fn spvReflectGetOutputVariableBySemantic
1328
1329 @param p_module Pointer to an instance of SpvReflectShaderModule.
1330 @param semantic The "semantic" value of the requested output variable.
1331 A semantic of NULL will return NULL.
1332 A semantic of "" will always return NULL with
1333 *p_result == ELEMENT_NOT_FOUND.
1334 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1335 written to *p_result. Otherwise, a error code
1336 indicating the cause of the failure will be stored
1337 here.
1338 @return If the module contains an output interface variable
1339 with the provided semantic, a pointer to that
1340 variable is returned. The caller must not free this
1341 pointer.
1342 If no match can be found, or if an unrelated error
1343 occurs, the return value will be NULL. Detailed
1344 error results are written to *pResult.
1345@note
1346
1347*/
1348const SpvReflectInterfaceVariable* spvReflectGetOutputVariableBySemantic(
1349 const SpvReflectShaderModule* p_module,
1350 const char* semantic,
1351 SpvReflectResult* p_result
1352);
1353
1354/* @fn spvReflectGetEntryPointOutputVariableBySemantic
1355
1356 @param p_module Pointer to an instance of SpvReflectShaderModule.
1357 @param entry_point The entry point to get the output variable from.
1358 @param semantic The "semantic" value of the requested output variable.
1359 A semantic of NULL will return NULL.
1360 A semantic of "" will always return NULL with
1361 *p_result == ELEMENT_NOT_FOUND.
1362 @param p_result If successful, SPV_REFLECT_RESULT_SUCCESS will be
1363 written to *p_result. Otherwise, a error code
1364 indicating the cause of the failure will be stored
1365 here.
1366 @return If the entry point contains an output interface variable
1367 with the provided semantic, a pointer to that
1368 variable is returned. The caller must not free this
1369 pointer.
1370 If no match can be found, or if an unrelated error
1371 occurs, the return value will be NULL. Detailed
1372 error results are written to *pResult.
1373@note
1374
1375*/
1376const SpvReflectInterfaceVariable* spvReflectGetEntryPointOutputVariableBySemantic(
1377 const SpvReflectShaderModule* p_module,
1378 const char* entry_point,
1379 const char* semantic,
1380 SpvReflectResult* p_result
1381);
1382
1400const SpvReflectBlockVariable* spvReflectGetPushConstantBlock(
1401 const SpvReflectShaderModule* p_module,
1402 uint32_t index,
1403 SpvReflectResult* p_result
1404);
1405SPV_REFLECT_DEPRECATED("renamed to spvReflectGetPushConstantBlock")
1406const SpvReflectBlockVariable* spvReflectGetPushConstant(
1407 const SpvReflectShaderModule* p_module,
1408 uint32_t index,
1409 SpvReflectResult* p_result
1410);
1411
1431const SpvReflectBlockVariable* spvReflectGetEntryPointPushConstantBlock(
1432 const SpvReflectShaderModule* p_module,
1433 const char* entry_point,
1434 SpvReflectResult* p_result
1435);
1436
1437
1461SpvReflectResult spvReflectChangeDescriptorBindingNumbers(
1462 SpvReflectShaderModule* p_module,
1463 const SpvReflectDescriptorBinding* p_binding,
1464 uint32_t new_binding_number,
1465 uint32_t new_set_number
1466);
1467SPV_REFLECT_DEPRECATED("Renamed to spvReflectChangeDescriptorBindingNumbers")
1468SpvReflectResult spvReflectChangeDescriptorBindingNumber(
1469 SpvReflectShaderModule* p_module,
1470 const SpvReflectDescriptorBinding* p_descriptor_binding,
1471 uint32_t new_binding_number,
1472 uint32_t optional_new_set_number
1473);
1474
1497SpvReflectResult spvReflectChangeDescriptorSetNumber(
1498 SpvReflectShaderModule* p_module,
1499 const SpvReflectDescriptorSet* p_set,
1500 uint32_t new_set_number
1501);
1502
1520SpvReflectResult spvReflectChangeInputVariableLocation(
1521 SpvReflectShaderModule* p_module,
1522 const SpvReflectInterfaceVariable* p_input_variable,
1523 uint32_t new_location
1524);
1525
1526
1544SpvReflectResult spvReflectChangeOutputVariableLocation(
1545 SpvReflectShaderModule* p_module,
1546 const SpvReflectInterfaceVariable* p_output_variable,
1547 uint32_t new_location
1548);
1549
1550
1557const char* spvReflectSourceLanguage(SpvSourceLanguage source_lang);
1558
1565const char* spvReflectBlockVariableTypeName(
1566 const SpvReflectBlockVariable* p_var
1567);
1568
1569#if defined(__cplusplus)
1570};
1571#endif
1572
1573#if defined(__cplusplus) && !defined(SPIRV_REFLECT_DISABLE_CPP_BINDINGS)
1574#include <cstdlib>
1575#include <string>
1576#include <vector>
1577
1578namespace spv_reflect {
1579
1583class ShaderModule {
1584public:
1585 ShaderModule();
1586 ShaderModule(size_t size, const void* p_code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1587 ShaderModule(const std::vector<uint8_t>& code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1588 ShaderModule(const std::vector<uint32_t>& code, SpvReflectModuleFlags flags = SPV_REFLECT_MODULE_FLAG_NONE);
1589 ~ShaderModule();
1590
1591 ShaderModule(ShaderModule&& other);
1592 ShaderModule& operator=(ShaderModule&& other);
1593
1594 SpvReflectResult GetResult() const;
1595
1596 const SpvReflectShaderModule& GetShaderModule() const;
1597
1598 uint32_t GetCodeSize() const;
1599 const uint32_t* GetCode() const;
1600
1601 const char* GetEntryPointName() const;
1602
1603 const char* GetSourceFile() const;
1604
1605 uint32_t GetEntryPointCount() const;
1606 const char* GetEntryPointName(uint32_t index) const;
1607 SpvReflectShaderStageFlagBits GetEntryPointShaderStage(uint32_t index) const;
1608
1609 SpvReflectShaderStageFlagBits GetShaderStage() const;
1610 SPV_REFLECT_DEPRECATED("Renamed to GetShaderStage")
1611 SpvReflectShaderStageFlagBits GetVulkanShaderStage() const {
1612 return GetShaderStage();
1613 }
1614
1615 SpvReflectResult EnumerateDescriptorBindings(uint32_t* p_count, SpvReflectDescriptorBinding** pp_bindings) const;
1616 SpvReflectResult EnumerateEntryPointDescriptorBindings(const char* entry_point, uint32_t* p_count, SpvReflectDescriptorBinding** pp_bindings) const;
1617 SpvReflectResult EnumerateDescriptorSets( uint32_t* p_count, SpvReflectDescriptorSet** pp_sets) const ;
1618 SpvReflectResult EnumerateEntryPointDescriptorSets(const char* entry_point, uint32_t* p_count, SpvReflectDescriptorSet** pp_sets) const ;
1619 SpvReflectResult EnumerateInterfaceVariables(uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1620 SpvReflectResult EnumerateEntryPointInterfaceVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1621 SpvReflectResult EnumerateInputVariables(uint32_t* p_count,SpvReflectInterfaceVariable** pp_variables) const;
1622 SpvReflectResult EnumerateEntryPointInputVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1623 SpvReflectResult EnumerateOutputVariables(uint32_t* p_count,SpvReflectInterfaceVariable** pp_variables) const;
1624 SpvReflectResult EnumerateEntryPointOutputVariables(const char* entry_point, uint32_t* p_count, SpvReflectInterfaceVariable** pp_variables) const;
1625 SpvReflectResult EnumeratePushConstantBlocks(uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const;
1626 SpvReflectResult EnumerateEntryPointPushConstantBlocks(const char* entry_point, uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const;
1627 SPV_REFLECT_DEPRECATED("Renamed to EnumeratePushConstantBlocks")
1628 SpvReflectResult EnumeratePushConstants(uint32_t* p_count, SpvReflectBlockVariable** pp_blocks) const {
1629 return EnumeratePushConstantBlocks(p_count, pp_blocks);
1630 }
1631 SpvReflectResult EnumerateSpecializationConstants(uint32_t* p_count, SpvReflectSpecializationConstant** pp_constants) const;
1632
1633 const SpvReflectDescriptorBinding* GetDescriptorBinding(uint32_t binding_number, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1634 const SpvReflectDescriptorBinding* GetEntryPointDescriptorBinding(const char* entry_point, uint32_t binding_number, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1635 const SpvReflectDescriptorSet* GetDescriptorSet(uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1636 const SpvReflectDescriptorSet* GetEntryPointDescriptorSet(const char* entry_point, uint32_t set_number, SpvReflectResult* p_result = nullptr) const;
1637 const SpvReflectInterfaceVariable* GetInputVariableByLocation(uint32_t location, SpvReflectResult* p_result = nullptr) const;
1638 SPV_REFLECT_DEPRECATED("Renamed to GetInputVariableByLocation")
1639 const SpvReflectInterfaceVariable* GetInputVariable(uint32_t location, SpvReflectResult* p_result = nullptr) const {
1640 return GetInputVariableByLocation(location, p_result);
1641 }
1642 const SpvReflectInterfaceVariable* GetEntryPointInputVariableByLocation(const char* entry_point, uint32_t location, SpvReflectResult* p_result = nullptr) const;
1643 const SpvReflectInterfaceVariable* GetInputVariableBySemantic(const char* semantic, SpvReflectResult* p_result = nullptr) const;
1644 const SpvReflectInterfaceVariable* GetEntryPointInputVariableBySemantic(const char* entry_point, const char* semantic, SpvReflectResult* p_result = nullptr) const;
1645 const SpvReflectInterfaceVariable* GetOutputVariableByLocation(uint32_t location, SpvReflectResult* p_result = nullptr) const;
1646 SPV_REFLECT_DEPRECATED("Renamed to GetOutputVariableByLocation")
1647 const SpvReflectInterfaceVariable* GetOutputVariable(uint32_t location, SpvReflectResult* p_result = nullptr) const {
1648 return GetOutputVariableByLocation(location, p_result);
1649 }
1650 const SpvReflectInterfaceVariable* GetEntryPointOutputVariableByLocation(const char* entry_point, uint32_t location, SpvReflectResult* p_result = nullptr) const;
1651 const SpvReflectInterfaceVariable* GetOutputVariableBySemantic(const char* semantic, SpvReflectResult* p_result = nullptr) const;
1652 const SpvReflectInterfaceVariable* GetEntryPointOutputVariableBySemantic(const char* entry_point, const char* semantic, SpvReflectResult* p_result = nullptr) const;
1653 const SpvReflectBlockVariable* GetPushConstantBlock(uint32_t index, SpvReflectResult* p_result = nullptr) const;
1654 SPV_REFLECT_DEPRECATED("Renamed to GetPushConstantBlock")
1655 const SpvReflectBlockVariable* GetPushConstant(uint32_t index, SpvReflectResult* p_result = nullptr) const {
1656 return GetPushConstantBlock(index, p_result);
1657 }
1658 const SpvReflectBlockVariable* GetEntryPointPushConstantBlock(const char* entry_point, SpvReflectResult* p_result = nullptr) const;
1659
1660 SpvReflectResult ChangeDescriptorBindingNumbers(const SpvReflectDescriptorBinding* p_binding,
1661 uint32_t new_binding_number = SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE,
1662 uint32_t optional_new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE);
1663 SPV_REFLECT_DEPRECATED("Renamed to ChangeDescriptorBindingNumbers")
1664 SpvReflectResult ChangeDescriptorBindingNumber(const SpvReflectDescriptorBinding* p_binding, uint32_t new_binding_number = SPV_REFLECT_BINDING_NUMBER_DONT_CHANGE,
1665 uint32_t new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE) {
1666 return ChangeDescriptorBindingNumbers(p_binding, new_binding_number, new_set_number);
1667 }
1668 SpvReflectResult ChangeDescriptorSetNumber(const SpvReflectDescriptorSet* p_set, uint32_t new_set_number = SPV_REFLECT_SET_NUMBER_DONT_CHANGE);
1669 SpvReflectResult ChangeInputVariableLocation(const SpvReflectInterfaceVariable* p_input_variable, uint32_t new_location);
1670 SpvReflectResult ChangeOutputVariableLocation(const SpvReflectInterfaceVariable* p_output_variable, uint32_t new_location);
1671
1672private:
1673 // Make noncopyable
1674 ShaderModule(const ShaderModule&);
1675 ShaderModule& operator=(const ShaderModule&);
1676
1677private:
1678 mutable SpvReflectResult m_result = SPV_REFLECT_RESULT_NOT_READY;
1679 SpvReflectShaderModule m_module = {};
1680};
1681
1682
1683// =================================================================================================
1684// ShaderModule
1685// =================================================================================================
1686
1690inline ShaderModule::ShaderModule() {}
1691
1692
1699inline ShaderModule::ShaderModule(size_t size, const void* p_code, SpvReflectModuleFlags flags) {
1700 m_result = spvReflectCreateShaderModule2(
1701 flags,
1702 size,
1703 p_code,
1704 &m_module);
1705}
1706
1712inline ShaderModule::ShaderModule(const std::vector<uint8_t>& code, SpvReflectModuleFlags flags) {
1713 m_result = spvReflectCreateShaderModule2(
1714 flags,
1715 code.size(),
1716 code.data(),
1717 &m_module);
1718}
1719
1725inline ShaderModule::ShaderModule(const std::vector<uint32_t>& code, SpvReflectModuleFlags flags) {
1726 m_result = spvReflectCreateShaderModule2(
1727 flags,
1728 code.size() * sizeof(uint32_t),
1729 code.data(),
1730 &m_module);
1731}
1732
1736inline ShaderModule::~ShaderModule() {
1737 spvReflectDestroyShaderModule(&m_module);
1738}
1739
1740
1741inline ShaderModule::ShaderModule(ShaderModule&& other)
1742{
1743 *this = std::move(other);
1744}
1745
1746inline ShaderModule& ShaderModule::operator=(ShaderModule&& other)
1747{
1748 m_result = std::move(other.m_result);
1749 m_module = std::move(other.m_module);
1750
1751 other.m_module = {};
1752 return *this;
1753}
1754
1760inline SpvReflectResult ShaderModule::GetResult() const {
1761 return m_result;
1762}
1763
1764
1770inline const SpvReflectShaderModule& ShaderModule::GetShaderModule() const {
1771 return m_module;
1772}
1773
1774
1780inline uint32_t ShaderModule::GetCodeSize() const {
1781 return spvReflectGetCodeSize(&m_module);
1782}
1783
1784
1790inline const uint32_t* ShaderModule::GetCode() const {
1791 return spvReflectGetCode(&m_module);
1792}
1793
1794
1800inline const char* ShaderModule::GetEntryPointName() const {
1801 return this->GetEntryPointName(0);
1802}
1803
1809inline const char* ShaderModule::GetSourceFile() const {
1810 return m_module.source_file;
1811}
1812
1818inline uint32_t ShaderModule::GetEntryPointCount() const {
1819 return m_module.entry_point_count;
1820}
1821
1827inline const char* ShaderModule::GetEntryPointName(uint32_t index) const {
1828 return m_module.entry_points[index].name;
1829}
1830
1836inline SpvReflectShaderStageFlagBits ShaderModule::GetEntryPointShaderStage(uint32_t index) const {
1837 return m_module.entry_points[index].shader_stage;
1838}
1839
1845inline SpvReflectShaderStageFlagBits ShaderModule::GetShaderStage() const {
1846 return m_module.shader_stage;
1847}
1848
1857inline SpvReflectResult ShaderModule::EnumerateDescriptorBindings(
1858 uint32_t* p_count,
1859 SpvReflectDescriptorBinding** pp_bindings
1860) const
1861{
1862 m_result = spvReflectEnumerateDescriptorBindings(
1863 &m_module,
1864 p_count,
1865 pp_bindings);
1866 return m_result;
1867}
1868
1877inline SpvReflectResult ShaderModule::EnumerateEntryPointDescriptorBindings(
1878 const char* entry_point,
1879 uint32_t* p_count,
1880 SpvReflectDescriptorBinding** pp_bindings
1881) const
1882{
1883 m_result = spvReflectEnumerateEntryPointDescriptorBindings(
1884 &m_module,
1885 entry_point,
1886 p_count,
1887 pp_bindings);
1888 return m_result;
1889}
1890
1891
1899inline SpvReflectResult ShaderModule::EnumerateDescriptorSets(
1900 uint32_t* p_count,
1901 SpvReflectDescriptorSet** pp_sets
1902) const
1903{
1904 m_result = spvReflectEnumerateDescriptorSets(
1905 &m_module,
1906 p_count,
1907 pp_sets);
1908 return m_result;
1909}
1910
1919inline SpvReflectResult ShaderModule::EnumerateEntryPointDescriptorSets(
1920 const char* entry_point,
1921 uint32_t* p_count,
1922 SpvReflectDescriptorSet** pp_sets
1923) const
1924{
1925 m_result = spvReflectEnumerateEntryPointDescriptorSets(
1926 &m_module,
1927 entry_point,
1928 p_count,
1929 pp_sets);
1930 return m_result;
1931}
1932
1933
1941inline SpvReflectResult ShaderModule::EnumerateInterfaceVariables(
1942 uint32_t* p_count,
1943 SpvReflectInterfaceVariable** pp_variables
1944) const
1945{
1946 m_result = spvReflectEnumerateInterfaceVariables(
1947 &m_module,
1948 p_count,
1949 pp_variables);
1950 return m_result;
1951}
1952
1961inline SpvReflectResult ShaderModule::EnumerateEntryPointInterfaceVariables(
1962 const char* entry_point,
1963 uint32_t* p_count,
1964 SpvReflectInterfaceVariable** pp_variables
1965) const
1966{
1967 m_result = spvReflectEnumerateEntryPointInterfaceVariables(
1968 &m_module,
1969 entry_point,
1970 p_count,
1971 pp_variables);
1972 return m_result;
1973}
1974
1975
1983inline SpvReflectResult ShaderModule::EnumerateInputVariables(
1984 uint32_t* p_count,
1985 SpvReflectInterfaceVariable** pp_variables
1986) const
1987{
1988 m_result = spvReflectEnumerateInputVariables(
1989 &m_module,
1990 p_count,
1991 pp_variables);
1992 return m_result;
1993}
1994
2003inline SpvReflectResult ShaderModule::EnumerateEntryPointInputVariables(
2004 const char* entry_point,
2005 uint32_t* p_count,
2006 SpvReflectInterfaceVariable** pp_variables
2007) const
2008{
2009 m_result = spvReflectEnumerateEntryPointInputVariables(
2010 &m_module,
2011 entry_point,
2012 p_count,
2013 pp_variables);
2014 return m_result;
2015}
2016
2017
2025inline SpvReflectResult ShaderModule::EnumerateOutputVariables(
2026 uint32_t* p_count,
2027 SpvReflectInterfaceVariable** pp_variables
2028) const
2029{
2030 m_result = spvReflectEnumerateOutputVariables(
2031 &m_module,
2032 p_count,
2033 pp_variables);
2034 return m_result;
2035}
2036
2045inline SpvReflectResult ShaderModule::EnumerateEntryPointOutputVariables(
2046 const char* entry_point,
2047 uint32_t* p_count,
2048 SpvReflectInterfaceVariable** pp_variables
2049) const
2050{
2051 m_result = spvReflectEnumerateEntryPointOutputVariables(
2052 &m_module,
2053 entry_point,
2054 p_count,
2055 pp_variables);
2056 return m_result;
2057}
2058
2059
2067inline SpvReflectResult ShaderModule::EnumeratePushConstantBlocks(
2068 uint32_t* p_count,
2069 SpvReflectBlockVariable** pp_blocks
2070) const
2071{
2072 m_result = spvReflectEnumeratePushConstantBlocks(
2073 &m_module,
2074 p_count,
2075 pp_blocks);
2076 return m_result;
2077}
2078
2084inline SpvReflectResult ShaderModule::EnumerateSpecializationConstants(
2085 uint32_t* p_count,
2087) const
2088{
2089 m_result = spvReflectEnumerateSpecializationConstants(
2090 &m_module,
2091 p_count,
2092 pp_constants
2093 );
2094 return m_result;
2095}
2096
2105inline SpvReflectResult ShaderModule::EnumerateEntryPointPushConstantBlocks(
2106 const char* entry_point,
2107 uint32_t* p_count,
2108 SpvReflectBlockVariable** pp_blocks
2109) const
2110{
2111 m_result = spvReflectEnumerateEntryPointPushConstantBlocks(
2112 &m_module,
2113 entry_point,
2114 p_count,
2115 pp_blocks);
2116 return m_result;
2117}
2118
2119
2128inline const SpvReflectDescriptorBinding* ShaderModule::GetDescriptorBinding(
2129 uint32_t binding_number,
2130 uint32_t set_number,
2131 SpvReflectResult* p_result
2132) const
2133{
2134 return spvReflectGetDescriptorBinding(
2135 &m_module,
2136 binding_number,
2137 set_number,
2138 p_result);
2139}
2140
2150inline const SpvReflectDescriptorBinding* ShaderModule::GetEntryPointDescriptorBinding(
2151 const char* entry_point,
2152 uint32_t binding_number,
2153 uint32_t set_number,
2154 SpvReflectResult* p_result
2155) const
2156{
2157 return spvReflectGetEntryPointDescriptorBinding(
2158 &m_module,
2159 entry_point,
2160 binding_number,
2161 set_number,
2162 p_result);
2163}
2164
2165
2173inline const SpvReflectDescriptorSet* ShaderModule::GetDescriptorSet(
2174 uint32_t set_number,
2175 SpvReflectResult* p_result
2176) const
2177{
2178 return spvReflectGetDescriptorSet(
2179 &m_module,
2180 set_number,
2181 p_result);
2182}
2183
2192inline const SpvReflectDescriptorSet* ShaderModule::GetEntryPointDescriptorSet(
2193 const char* entry_point,
2194 uint32_t set_number,
2195 SpvReflectResult* p_result
2196) const
2197{
2198 return spvReflectGetEntryPointDescriptorSet(
2199 &m_module,
2200 entry_point,
2201 set_number,
2202 p_result);
2203}
2204
2205
2213inline const SpvReflectInterfaceVariable* ShaderModule::GetInputVariableByLocation(
2214 uint32_t location,
2215 SpvReflectResult* p_result
2216) const
2217{
2218 return spvReflectGetInputVariableByLocation(
2219 &m_module,
2220 location,
2221 p_result);
2222}
2223inline const SpvReflectInterfaceVariable* ShaderModule::GetInputVariableBySemantic(
2224 const char* semantic,
2225 SpvReflectResult* p_result
2226) const
2227{
2228 return spvReflectGetInputVariableBySemantic(
2229 &m_module,
2230 semantic,
2231 p_result);
2232}
2233
2242inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointInputVariableByLocation(
2243 const char* entry_point,
2244 uint32_t location,
2245 SpvReflectResult* p_result
2246) const
2247{
2248 return spvReflectGetEntryPointInputVariableByLocation(
2249 &m_module,
2250 entry_point,
2251 location,
2252 p_result);
2253}
2254inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointInputVariableBySemantic(
2255 const char* entry_point,
2256 const char* semantic,
2257 SpvReflectResult* p_result
2258) const
2259{
2260 return spvReflectGetEntryPointInputVariableBySemantic(
2261 &m_module,
2262 entry_point,
2263 semantic,
2264 p_result);
2265}
2266
2267
2275inline const SpvReflectInterfaceVariable* ShaderModule::GetOutputVariableByLocation(
2276 uint32_t location,
2277 SpvReflectResult* p_result
2278) const
2279{
2280 return spvReflectGetOutputVariableByLocation(
2281 &m_module,
2282 location,
2283 p_result);
2284}
2285inline const SpvReflectInterfaceVariable* ShaderModule::GetOutputVariableBySemantic(
2286 const char* semantic,
2287 SpvReflectResult* p_result
2288) const
2289{
2290 return spvReflectGetOutputVariableBySemantic(&m_module,
2291 semantic,
2292 p_result);
2293}
2294
2303inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointOutputVariableByLocation(
2304 const char* entry_point,
2305 uint32_t location,
2306 SpvReflectResult* p_result
2307) const
2308{
2309 return spvReflectGetEntryPointOutputVariableByLocation(
2310 &m_module,
2311 entry_point,
2312 location,
2313 p_result);
2314}
2315inline const SpvReflectInterfaceVariable* ShaderModule::GetEntryPointOutputVariableBySemantic(
2316 const char* entry_point,
2317 const char* semantic,
2318 SpvReflectResult* p_result
2319) const
2320{
2321 return spvReflectGetEntryPointOutputVariableBySemantic(
2322 &m_module,
2323 entry_point,
2324 semantic,
2325 p_result);
2326}
2327
2328
2336inline const SpvReflectBlockVariable* ShaderModule::GetPushConstantBlock(
2337 uint32_t index,
2338 SpvReflectResult* p_result
2339) const
2340{
2341 return spvReflectGetPushConstantBlock(
2342 &m_module,
2343 index,
2344 p_result);
2345}
2346
2355inline const SpvReflectBlockVariable* ShaderModule::GetEntryPointPushConstantBlock(
2356 const char* entry_point,
2357 SpvReflectResult* p_result
2358) const
2359{
2360 return spvReflectGetEntryPointPushConstantBlock(
2361 &m_module,
2362 entry_point,
2363 p_result);
2364}
2365
2366
2375inline SpvReflectResult ShaderModule::ChangeDescriptorBindingNumbers(
2376 const SpvReflectDescriptorBinding* p_binding,
2377 uint32_t new_binding_number,
2378 uint32_t new_set_number
2379)
2380{
2381 return spvReflectChangeDescriptorBindingNumbers(
2382 &m_module,
2383 p_binding,
2384 new_binding_number,
2385 new_set_number);
2386}
2387
2388
2396inline SpvReflectResult ShaderModule::ChangeDescriptorSetNumber(
2397 const SpvReflectDescriptorSet* p_set,
2398 uint32_t new_set_number
2399)
2400{
2401 return spvReflectChangeDescriptorSetNumber(
2402 &m_module,
2403 p_set,
2404 new_set_number);
2405}
2406
2407
2415inline SpvReflectResult ShaderModule::ChangeInputVariableLocation(
2416 const SpvReflectInterfaceVariable* p_input_variable,
2417 uint32_t new_location)
2418{
2419 return spvReflectChangeInputVariableLocation(
2420 &m_module,
2421 p_input_variable,
2422 new_location);
2423}
2424
2425
2433inline SpvReflectResult ShaderModule::ChangeOutputVariableLocation(
2434 const SpvReflectInterfaceVariable* p_output_variable,
2435 uint32_t new_location)
2436{
2437 return spvReflectChangeOutputVariableLocation(
2438 &m_module,
2439 p_output_variable,
2440 new_location);
2441}
2442
2443} // namespace spv_reflect
2444#endif // defined(__cplusplus) && !defined(SPIRV_REFLECT_DISABLE_CPP_WRAPPER)
2445#endif // SPIRV_REFLECT_H
2446
2447// clang-format on
SpvReflectModuleFlagBits
Definition spirv_reflect.h:98
Definition spirv_reflect.h:370
Definition spirv_reflect.h:382
Definition spirv_reflect.h:455
Definition spirv_reflect.h:565
Definition spirv_reflect.h:482
Definition spirv_reflect.h:515
Definition spirv_reflect.h:553
Definition spirv_reflect.h:528
Definition spirv_reflect.h:357
The OpVariable that is either an Input or Output to the module.
Definition spirv_reflect.h:424
Definition spirv_reflect.h:350
Definition spirv_reflect.h:341
Definition spirv_reflect.h:346
Definition spirv_reflect.h:340
Definition spirv_reflect.h:612
Definition spirv_reflect.h:583
Definition spirv_reflect.h:574
Definition spirv_reflect.h:400
Information about an OpType* instruction.
Definition spirv_reflect.h:390