Add names for composite constants in SPIR-V

Consider the following code:

    layout(constant_id=0) const int Y = 1;
    layout(constant_id=1) const int Z = 2;
    layout(constant_id=3) const int X = Y + Z;

Previously, it would produce SPIR-V decorations like this:

    Decorate 21(Y) SpecId 1
    Decorate 22 SpecId 3
    Decorate 33(Z) SpecId 0

This seems inaccurate, since the spec constant `X` that is dependent on
the two others did not get a name in the SPIR-V decorations. This behavior
may potentially negatively affect shader introspection capabilities.

This change alters the behavior to always add a name, which results in the code
above producing the following decorations:

    Decorate 21(Y) SpecId 1
    Decorate 22(X) SpecId 3
    Decorate 33(Z) SpecId 0
This commit is contained in:
Grigory Dzhavadyan
2018-10-29 22:56:44 -07:00
committed by nicebyte
parent b2b3d81e9b
commit 4c9876b34c
8 changed files with 232 additions and 117 deletions

View File

@@ -1,7 +1,11 @@
spv.int64.frag
error: SPIRV-Tools Validation Errors
error: OpDecorate SpecId decoration target <id> '1' is not a scalar specialization constant.
OpDecorate %su64inc SpecId 105
// Module Version 10000
// Generated by (magic number): 80007
// Id's are bound by 488
// Id's are bound by 489
Capability Shader
Capability Float64
@@ -55,6 +59,21 @@ spv.int64.frag
Name 467 "si"
Name 468 "su"
Name 469 "sb"
Name 470 "su64inc"
Name 471 "i64_to_b"
Name 472 "u64_to_b"
Name 473 "b_to_i64"
Name 474 "b_to_u64"
Name 475 "i64_to_i"
Name 476 "i_to_i64"
Name 477 "u64_to_u"
Name 478 "u_to_u64"
Name 479 "u64_to_i64"
Name 480 "i64_to_u64"
Name 482 "u64_to_i"
Name 484 "i_to_u64"
Name 486 "i64_to_u"
Name 488 "u_to_i64"
MemberDecorate 28(Uniforms) 0 Offset 0
Decorate 28(Uniforms) Block
Decorate 30 DescriptorSet 0
@@ -69,6 +88,7 @@ spv.int64.frag
Decorate 467(si) SpecId 102
Decorate 468(su) SpecId 103
Decorate 469(sb) SpecId 104
Decorate 470(su64inc) SpecId 105
2: TypeVoid
3: TypeFunction 2
14: TypeInt 64 0
@@ -157,24 +177,25 @@ spv.int64.frag
467(si): 31(int) SpecConstant 4294967291
468(su): 21(int) SpecConstant 4
469(sb): 55(bool) SpecConstantTrue
470: 55(bool) SpecConstantOp 171 465(si64) 69
471: 55(bool) SpecConstantOp 171 466(su64) 69
472: 18(int64_t) SpecConstantOp 169 469(sb) 61 60
473: 14(int64_t) SpecConstantOp 169 469(sb) 70 69
474: 31(int) SpecConstantOp 114 465(si64)
475: 18(int64_t) SpecConstantOp 114 467(si)
476: 21(int) SpecConstantOp 113 466(su64)
477: 14(int64_t) SpecConstantOp 113 468(su)
478: 18(int64_t) SpecConstantOp 128 466(su64) 69
479: 14(int64_t) SpecConstantOp 128 465(si64) 69
480: 21(int) SpecConstantOp 113 466(su64)
481: 31(int) SpecConstantOp 128 480 227
482: 18(int64_t) SpecConstantOp 114 467(si)
483: 14(int64_t) SpecConstantOp 128 482 69
484: 31(int) SpecConstantOp 114 465(si64)
485: 21(int) SpecConstantOp 128 484 227
486: 14(int64_t) SpecConstantOp 113 468(su)
487: 18(int64_t) SpecConstantOp 128 486 69
470(su64inc): 14(int64_t) SpecConstantOp 128 466(su64) 70
471(i64_to_b): 55(bool) SpecConstantOp 171 465(si64) 69
472(u64_to_b): 55(bool) SpecConstantOp 171 466(su64) 69
473(b_to_i64): 18(int64_t) SpecConstantOp 169 469(sb) 61 60
474(b_to_u64): 14(int64_t) SpecConstantOp 169 469(sb) 70 69
475(i64_to_i): 31(int) SpecConstantOp 114 465(si64)
476(i_to_i64): 18(int64_t) SpecConstantOp 114 467(si)
477(u64_to_u): 21(int) SpecConstantOp 113 466(su64)
478(u_to_u64): 14(int64_t) SpecConstantOp 113 468(su)
479(u64_to_i64): 18(int64_t) SpecConstantOp 128 466(su64) 69
480(i64_to_u64): 14(int64_t) SpecConstantOp 128 465(si64) 69
481: 21(int) SpecConstantOp 113 466(su64)
482(u64_to_i): 31(int) SpecConstantOp 128 481 227
483: 18(int64_t) SpecConstantOp 114 467(si)
484(i_to_u64): 14(int64_t) SpecConstantOp 128 483 69
485: 31(int) SpecConstantOp 114 465(si64)
486(i64_to_u): 21(int) SpecConstantOp 128 485 227
487: 14(int64_t) SpecConstantOp 113 468(su)
488(u_to_i64): 18(int64_t) SpecConstantOp 128 487 69
4(main): 2 Function None 3
5: Label
Store 16(u64Max) 17