@@ -1352,7 +1352,8 @@ static SpvReflectResult ParseNames(SpvReflectPrvParser* p_parser) {
13521352 return SPV_REFLECT_RESULT_SUCCESS ;
13531353}
13541354
1355- static SpvReflectResult ParseDecorations (SpvReflectPrvParser * p_parser ) {
1355+ static SpvReflectResult ParseDecorations (SpvReflectPrvParser * p_parser , SpvReflectShaderModule * p_module ) {
1356+ uint32_t spec_constant_count = 0 ;
13561357 for (uint32_t i = 0 ; i < p_parser -> node_count ; ++ i ) {
13571358 SpvReflectPrvNode * p_node = & (p_parser -> nodes [i ]);
13581359
@@ -1538,8 +1539,7 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) {
15381539 } break ;
15391540
15401541 case SpvDecorationSpecId : {
1541- uint32_t word_offset = p_node -> word_offset + member_offset + 3 ;
1542- CHECKED_READU32 (p_parser , word_offset , p_target_decorations -> spec_id );
1542+ spec_constant_count ++ ;
15431543 } break ;
15441544
15451545 case SpvDecorationHlslCounterBufferGOOGLE : {
@@ -1563,6 +1563,27 @@ static SpvReflectResult ParseDecorations(SpvReflectPrvParser* p_parser) {
15631563 } break ;
15641564 }
15651565 }
1566+
1567+ if (spec_constant_count > 0 ) {
1568+ p_module -> spec_constants = (SpvReflectSpecializationConstant * )calloc (spec_constant_count , sizeof (* p_module -> spec_constants ));
1569+ if (IsNull (p_module -> spec_constants )) {
1570+ return SPV_REFLECT_RESULT_ERROR_ALLOC_FAILED ;
1571+ }
1572+ }
1573+ for (uint32_t i = 0 ; i < p_parser -> node_count ; ++ i ) {
1574+ SpvReflectPrvNode * p_node = & (p_parser -> nodes [i ]);
1575+ if (p_node -> op == SpvOpDecorate ) {
1576+ uint32_t decoration = (uint32_t )INVALID_VALUE ;
1577+ CHECKED_READU32 (p_parser , p_node -> word_offset + 2 , decoration );
1578+ if (decoration == SpvDecorationSpecId ) {
1579+ const uint32_t count = p_module -> spec_constant_count ;
1580+ CHECKED_READU32 (p_parser , p_node -> word_offset + 1 , p_module -> spec_constants [count ].constant_id );
1581+ CHECKED_READU32 (p_parser , p_node -> word_offset + 3 , p_module -> spec_constants [count ].spirv_id );
1582+ p_module -> spec_constant_count ++ ;
1583+ }
1584+ }
1585+ }
1586+
15661587 return SPV_REFLECT_RESULT_SUCCESS ;
15671588}
15681589
@@ -3861,7 +3882,7 @@ static SpvReflectResult CreateShaderModule(uint32_t flags, size_t size, const vo
38613882 SPV_REFLECT_ASSERT (result == SPV_REFLECT_RESULT_SUCCESS );
38623883 }
38633884 if (result == SPV_REFLECT_RESULT_SUCCESS ) {
3864- result = ParseDecorations (& parser );
3885+ result = ParseDecorations (& parser , p_module );
38653886 SPV_REFLECT_ASSERT (result == SPV_REFLECT_RESULT_SUCCESS );
38663887 }
38673888
@@ -4050,6 +4071,7 @@ void spvReflectDestroyShaderModule(SpvReflectShaderModule* p_module) {
40504071 }
40514072 SafeFree (p_module -> capabilities );
40524073 SafeFree (p_module -> entry_points );
4074+ SafeFree (p_module -> spec_constants );
40534075
40544076 // Push constants
40554077 for (size_t i = 0 ; i < p_module -> push_constant_block_count ; ++ i ) {
@@ -4455,6 +4477,31 @@ SpvReflectResult spvReflectEnumerateEntryPointPushConstantBlocks(const SpvReflec
44554477 return SPV_REFLECT_RESULT_SUCCESS ;
44564478}
44574479
4480+ SpvReflectResult spvReflectEnumerateSpecializationConstants (const SpvReflectShaderModule * p_module , uint32_t * p_count ,
4481+ SpvReflectSpecializationConstant * * pp_constants ) {
4482+ if (IsNull (p_module )) {
4483+ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER ;
4484+ }
4485+ if (IsNull (p_count )) {
4486+ return SPV_REFLECT_RESULT_ERROR_NULL_POINTER ;
4487+ }
4488+
4489+ if (IsNotNull (pp_constants )) {
4490+ if (* p_count != p_module -> spec_constant_count ) {
4491+ return SPV_REFLECT_RESULT_ERROR_COUNT_MISMATCH ;
4492+ }
4493+
4494+ for (uint32_t index = 0 ; index < * p_count ; ++ index ) {
4495+ SpvReflectSpecializationConstant * p_constant = (SpvReflectSpecializationConstant * )& p_module -> spec_constants [index ];
4496+ pp_constants [index ] = p_constant ;
4497+ }
4498+ } else {
4499+ * p_count = p_module -> spec_constant_count ;
4500+ }
4501+
4502+ return SPV_REFLECT_RESULT_SUCCESS ;
4503+ }
4504+
44584505const SpvReflectDescriptorBinding * spvReflectGetDescriptorBinding (const SpvReflectShaderModule * p_module , uint32_t binding_number ,
44594506 uint32_t set_number , SpvReflectResult * p_result ) {
44604507 const SpvReflectDescriptorBinding * p_descriptor = NULL ;
0 commit comments