spirv_reflect.h 81 KB

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