@@ -882,6 +882,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
882882 const std::string& parent_name,
883883 uint32_t member_count,
884884 const SpvReflectBlockVariable* p_members,
885+ SpvReflectEvaluation* evaluator,
885886 std::vector<TextLine>* p_text_lines) {
886887 const char * t = indent;
887888 for (uint32_t member_index = 0 ; member_index < member_count; ++member_index) {
@@ -927,7 +928,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
927928 flatten_cbuffers ? p_text_lines : &tl.lines ;
928929 ParseBlockMembersToTextLines (t, indent_depth + 1 , flatten_cbuffers,
929930 current_parent_name, member.member_count ,
930- member.members , p_target_text_line);
931+ member.members , evaluator, p_target_text_line);
931932 tl.text_line_flags = TEXT_LINE_TYPE_LINES;
932933 p_text_lines->push_back (tl);
933934
@@ -995,7 +996,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
995996 uint32_t dim = member.array .dims [array_dim_index];
996997 if (dim == 0xFFFFFFFF ) {
997998 const SpvReflectValue* val;
998- SpvReflectResult res = obj. EvaluateResult ( member.array .spec_constant_op_ids [array_dim_index], &val);
999+ SpvReflectResult res = spvReflectEvaluateResult (evaluator, member.array .spec_constant_op_ids [array_dim_index], &val);
9991000 if ((res == SPV_REFLECT_RESULT_SUCCESS) && val->type && (val->type ->type_flags == SPV_REFLECT_TYPE_FLAG_INT) && (val->type ->traits .numeric .scalar .width == 32 )) {
10001001 dim = val->data .numeric .scalar .value .uint32_bool_value ;
10011002 }
@@ -1017,6 +1018,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
10171018
10181019void ParseBlockVariableToTextLines (const char * indent, bool flatten_cbuffers,
10191020 const SpvReflectBlockVariable& block_var,
1021+ SpvReflectEvaluation* evaluator,
10201022 std::vector<TextLine>* p_text_lines) {
10211023 // Begin block
10221024 TextLine tl = {};
@@ -1033,7 +1035,7 @@ void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers,
10331035 tl = {};
10341036 ParseBlockMembersToTextLines (indent, 2 , flatten_cbuffers, " " ,
10351037 block_var.member_count , block_var.members ,
1036- &tl.lines );
1038+ evaluator, &tl.lines );
10371039 tl.text_line_flags = TEXT_LINE_TYPE_LINES;
10381040 p_text_lines->push_back (tl);
10391041
@@ -1248,6 +1250,7 @@ void StreamWriteTextLines(std::ostream& os, const char* indent,
12481250
12491251void StreamWritePushConstantsBlock (std::ostream& os,
12501252 const SpvReflectBlockVariable& obj,
1253+ SpvReflectEvaluation* evaluator,
12511254 bool flatten_cbuffers, const char * indent) {
12521255 const char * t = indent;
12531256 os << t << " spirv id : " << obj.spirv_id << " \n " ;
@@ -1260,7 +1263,8 @@ void StreamWritePushConstantsBlock(std::ostream& os,
12601263 }
12611264
12621265 std::vector<TextLine> text_lines;
1263- ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj, &text_lines);
1266+ ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj, evaluator,
1267+ &text_lines);
12641268 if (!text_lines.empty ()) {
12651269 os << " \n " ;
12661270 StreamWriteTextLines (os, t, flatten_cbuffers, text_lines);
@@ -1270,6 +1274,7 @@ void StreamWritePushConstantsBlock(std::ostream& os,
12701274
12711275void StreamWriteDescriptorBinding (std::ostream& os,
12721276 const SpvReflectDescriptorBinding& obj,
1277+ SpvReflectEvaluation* evaluator,
12731278 bool write_set, bool flatten_cbuffers,
12741279 const char * indent) {
12751280 const char * t = indent;
@@ -1321,7 +1326,7 @@ void StreamWriteDescriptorBinding(std::ostream& os,
13211326 obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) {
13221327 std::vector<TextLine> text_lines;
13231328 ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj.block ,
1324- &text_lines);
1329+ evaluator, &text_lines);
13251330 if (!text_lines.empty ()) {
13261331 os << " \n " ;
13271332 StreamWriteTextLines (os, t, flatten_cbuffers, text_lines);
@@ -1374,6 +1379,68 @@ void StreamWriteInterfaceVariable(std::ostream& os,
13741379 }
13751380}
13761381
1382+ void StreamWriteSpecializationConstant (
1383+ std::ostream& os, const SpvReflectSpecializationConstant& obj,
1384+ const char * indent) {
1385+ const char * t = indent;
1386+ os << t << " spirv id : " << obj.spirv_id << " \n " ;
1387+ os << t << " constant id: " << obj.constant_id << " \n " ;
1388+ os << t << " name : " << (obj.name != NULL ? obj.name : " " ) << ' \n ' ;
1389+ os << t << " type : " ;
1390+ int type = 0 ;
1391+ if (!obj.type || obj.type ->type_flags == SPV_REFLECT_TYPE_FLAG_BOOL) {
1392+ type = 1 ;
1393+ } else if (obj.type ->type_flags == SPV_REFLECT_TYPE_FLAG_INT) {
1394+ type = 2 ;
1395+ } else if (obj.type ->type_flags == SPV_REFLECT_TYPE_FLAG_FLOAT) {
1396+ type = 3 ;
1397+ }
1398+ switch (type) {
1399+ case 1 :
1400+ os << " boolean\n " ;
1401+ os << t << " default : " << obj.default_value .value .uint32_bool_value ;
1402+ break ;
1403+ case 2 :
1404+ if (obj.type ->traits .numeric .scalar .signedness ) {
1405+ os << " signed " ;
1406+ } else {
1407+ os << " unsigned " ;
1408+ }
1409+ os << obj.type ->traits .numeric .scalar .width << " bit integer\n " ;
1410+ os << t << " default : " ;
1411+ // let's assume only 32 bit and 64 bit types (no 8 and 16 bit types here)
1412+ if (obj.type ->traits .numeric .scalar .width == 32 ) {
1413+ if (obj.type ->traits .numeric .scalar .signedness ) {
1414+ os << obj.default_value .value .sint32_value ;
1415+ } else {
1416+ os << obj.default_value .value .uint32_bool_value ;
1417+ }
1418+ } else if (obj.type ->traits .numeric .scalar .width == 64 ) {
1419+ if (obj.type ->traits .numeric .scalar .signedness ) {
1420+ os << obj.default_value .value .sint64_value ;
1421+ } else {
1422+ os << obj.default_value .value .uint64_value ;
1423+ }
1424+ } else {
1425+ os << " default value not native in c/cpp" ;
1426+ }
1427+ break ;
1428+ case 3 :
1429+ os << obj.type ->traits .numeric .scalar .width << " bit floating point\n " ;
1430+ os << t << " default : " ;
1431+ if (obj.type ->traits .numeric .scalar .width == 32 ) {
1432+ os << obj.default_value .value .float32_value ;
1433+ } else if (obj.type ->traits .numeric .scalar .width == 64 ) {
1434+ os << obj.default_value .value .float64_value ;
1435+ } else {
1436+ os << " default value not native in c/cpp" ;
1437+ }
1438+ break ;
1439+ default :
1440+ os << " unknown type" ;
1441+ }
1442+ }
1443+
13771444void StreamWriteEntryPoint (std::ostream& os, const SpvReflectEntryPoint& obj,
13781445 const char * indent) {
13791446 os << indent << " entry point : " << obj.name ;
@@ -1400,7 +1467,7 @@ void StreamWriteShaderModule(std::ostream& os,
14001467 // "\n";
14011468
14021469 for (uint32_t i = 0 ; i < obj.entry_point_count ; ++i) {
1403- StreamWriteEntryPoint (os, eval, obj.entry_points [i], " " );
1470+ StreamWriteEntryPoint (os, obj.entry_points [i], " " );
14041471 if (i < (obj.entry_point_count - 1 )) {
14051472 os << " \n " ;
14061473 }
@@ -1420,7 +1487,7 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
14201487 const char * tt = " " ;
14211488 const char * ttt = " " ;
14221489
1423- StreamWriteShaderModule (os, obj.GetShaderModule (), obj. GetEvaluation (), " " );
1490+ StreamWriteShaderModule (os, obj.GetShaderModule (), " " );
14241491
14251492 uint32_t count = 0 ;
14261493 std::vector<SpvReflectInterfaceVariable*> variables;
@@ -1512,7 +1579,8 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
15121579 auto p_block = push_constant_bocks[i];
15131580 os << tt << i << " :"
15141581 << " \n " ;
1515- StreamWritePushConstantsBlock (os, *p_block, flatten_cbuffers, ttt);
1582+ StreamWritePushConstantsBlock (os, *p_block, obj.GetEvaluationInterface (),
1583+ flatten_cbuffers, ttt);
15161584 }
15171585 }
15181586
@@ -1541,7 +1609,8 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
15411609 os << tt << " Binding"
15421610 << " " << p_binding->set << " ." << p_binding->binding << " "
15431611 << " \n " ;
1544- StreamWriteDescriptorBinding (os, *p_binding, true , flatten_cbuffers, ttt);
1612+ StreamWriteDescriptorBinding (os, *p_binding, obj.GetEvaluationInterface (),
1613+ true , flatten_cbuffers, ttt);
15451614 if (i < (count - 1 )) {
15461615 os << " \n\n " ;
15471616 }
0 commit comments