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