@@ -882,6 +882,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
882
882
const std::string& parent_name,
883
883
uint32_t member_count,
884
884
const SpvReflectBlockVariable* p_members,
885
+ SpvReflectEvaluation* evaluator,
885
886
std::vector<TextLine>* p_text_lines) {
886
887
const char * t = indent;
887
888
for (uint32_t member_index = 0 ; member_index < member_count; ++member_index) {
@@ -927,7 +928,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
927
928
flatten_cbuffers ? p_text_lines : &tl.lines ;
928
929
ParseBlockMembersToTextLines (t, indent_depth + 1 , flatten_cbuffers,
929
930
current_parent_name, member.member_count ,
930
- member.members , p_target_text_line);
931
+ member.members , evaluator, p_target_text_line);
931
932
tl.text_line_flags = TEXT_LINE_TYPE_LINES;
932
933
p_text_lines->push_back (tl);
933
934
@@ -995,7 +996,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
995
996
uint32_t dim = member.array .dims [array_dim_index];
996
997
if (dim == 0xFFFFFFFF ) {
997
998
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);
999
1000
if ((res == SPV_REFLECT_RESULT_SUCCESS) && val->type && (val->type ->type_flags == SPV_REFLECT_TYPE_FLAG_INT) && (val->type ->traits .numeric .scalar .width == 32 )) {
1000
1001
dim = val->data .numeric .scalar .value .uint32_bool_value ;
1001
1002
}
@@ -1017,6 +1018,7 @@ void ParseBlockMembersToTextLines(const char* indent, int indent_depth,
1017
1018
1018
1019
void ParseBlockVariableToTextLines (const char * indent, bool flatten_cbuffers,
1019
1020
const SpvReflectBlockVariable& block_var,
1021
+ SpvReflectEvaluation* evaluator,
1020
1022
std::vector<TextLine>* p_text_lines) {
1021
1023
// Begin block
1022
1024
TextLine tl = {};
@@ -1033,7 +1035,7 @@ void ParseBlockVariableToTextLines(const char* indent, bool flatten_cbuffers,
1033
1035
tl = {};
1034
1036
ParseBlockMembersToTextLines (indent, 2 , flatten_cbuffers, " " ,
1035
1037
block_var.member_count , block_var.members ,
1036
- &tl.lines );
1038
+ evaluator, &tl.lines );
1037
1039
tl.text_line_flags = TEXT_LINE_TYPE_LINES;
1038
1040
p_text_lines->push_back (tl);
1039
1041
@@ -1248,6 +1250,7 @@ void StreamWriteTextLines(std::ostream& os, const char* indent,
1248
1250
1249
1251
void StreamWritePushConstantsBlock (std::ostream& os,
1250
1252
const SpvReflectBlockVariable& obj,
1253
+ SpvReflectEvaluation* evaluator,
1251
1254
bool flatten_cbuffers, const char * indent) {
1252
1255
const char * t = indent;
1253
1256
os << t << " spirv id : " << obj.spirv_id << " \n " ;
@@ -1260,7 +1263,8 @@ void StreamWritePushConstantsBlock(std::ostream& os,
1260
1263
}
1261
1264
1262
1265
std::vector<TextLine> text_lines;
1263
- ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj, &text_lines);
1266
+ ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj, evaluator,
1267
+ &text_lines);
1264
1268
if (!text_lines.empty ()) {
1265
1269
os << " \n " ;
1266
1270
StreamWriteTextLines (os, t, flatten_cbuffers, text_lines);
@@ -1270,6 +1274,7 @@ void StreamWritePushConstantsBlock(std::ostream& os,
1270
1274
1271
1275
void StreamWriteDescriptorBinding (std::ostream& os,
1272
1276
const SpvReflectDescriptorBinding& obj,
1277
+ SpvReflectEvaluation* evaluator,
1273
1278
bool write_set, bool flatten_cbuffers,
1274
1279
const char * indent) {
1275
1280
const char * t = indent;
@@ -1321,7 +1326,7 @@ void StreamWriteDescriptorBinding(std::ostream& os,
1321
1326
obj.descriptor_type == SPV_REFLECT_DESCRIPTOR_TYPE_STORAGE_BUFFER) {
1322
1327
std::vector<TextLine> text_lines;
1323
1328
ParseBlockVariableToTextLines (" " , flatten_cbuffers, obj.block ,
1324
- &text_lines);
1329
+ evaluator, &text_lines);
1325
1330
if (!text_lines.empty ()) {
1326
1331
os << " \n " ;
1327
1332
StreamWriteTextLines (os, t, flatten_cbuffers, text_lines);
@@ -1374,6 +1379,68 @@ void StreamWriteInterfaceVariable(std::ostream& os,
1374
1379
}
1375
1380
}
1376
1381
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
+
1377
1444
void StreamWriteEntryPoint (std::ostream& os, const SpvReflectEntryPoint& obj,
1378
1445
const char * indent) {
1379
1446
os << indent << " entry point : " << obj.name ;
@@ -1400,7 +1467,7 @@ void StreamWriteShaderModule(std::ostream& os,
1400
1467
// "\n";
1401
1468
1402
1469
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], " " );
1404
1471
if (i < (obj.entry_point_count - 1 )) {
1405
1472
os << " \n " ;
1406
1473
}
@@ -1420,7 +1487,7 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
1420
1487
const char * tt = " " ;
1421
1488
const char * ttt = " " ;
1422
1489
1423
- StreamWriteShaderModule (os, obj.GetShaderModule (), obj. GetEvaluation (), " " );
1490
+ StreamWriteShaderModule (os, obj.GetShaderModule (), " " );
1424
1491
1425
1492
uint32_t count = 0 ;
1426
1493
std::vector<SpvReflectInterfaceVariable*> variables;
@@ -1512,7 +1579,8 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
1512
1579
auto p_block = push_constant_bocks[i];
1513
1580
os << tt << i << " :"
1514
1581
<< " \n " ;
1515
- StreamWritePushConstantsBlock (os, *p_block, flatten_cbuffers, ttt);
1582
+ StreamWritePushConstantsBlock (os, *p_block, obj.GetEvaluationInterface (),
1583
+ flatten_cbuffers, ttt);
1516
1584
}
1517
1585
}
1518
1586
@@ -1541,7 +1609,8 @@ void WriteReflection(const spv_reflect::ShaderModule& obj,
1541
1609
os << tt << " Binding"
1542
1610
<< " " << p_binding->set << " ." << p_binding->binding << " "
1543
1611
<< " \n " ;
1544
- StreamWriteDescriptorBinding (os, *p_binding, true , flatten_cbuffers, ttt);
1612
+ StreamWriteDescriptorBinding (os, *p_binding, obj.GetEvaluationInterface (),
1613
+ true , flatten_cbuffers, ttt);
1545
1614
if (i < (count - 1 )) {
1546
1615
os << " \n\n " ;
1547
1616
}
0 commit comments