Improve line info for symbol access and assignment

This commit is contained in:
Qingyuan Zheng 2023-03-14 10:36:24 -07:00 committed by arcady-lunarg
parent fbabd37aca
commit f8a2442a16
4 changed files with 683 additions and 367 deletions

View File

@ -2004,6 +2004,10 @@ void TGlslangToSpvTraverser::dumpSpv(std::vector<unsigned int>& out)
// //
void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol) void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
{ {
// We update the line information even though no code might be generated here
// This is helpful to yield correct lines for control flow instructions
builder.setLine(symbol->getLoc().line, symbol->getLoc().getFilename());
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder); SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (symbol->getType().isStruct()) if (symbol->getType().isStruct())
glslangTypeToIdMap[symbol->getType().getStruct()] = symbol->getId(); glslangTypeToIdMap[symbol->getType().getStruct()] = symbol->getId();
@ -2155,6 +2159,9 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
node->getRight()->traverse(this); node->getRight()->traverse(this);
spv::Id rValue = accessChainLoad(node->getRight()->getType()); spv::Id rValue = accessChainLoad(node->getRight()->getType());
// reset line number for assignment
builder.setLine(node->getLoc().line, node->getLoc().getFilename());
if (node->getOp() != glslang::EOpAssign) { if (node->getOp() != glslang::EOpAssign) {
// the left is also an r-value // the left is also an r-value
builder.setAccessChain(lValue); builder.setAccessChain(lValue);

View File

@ -1,12 +1,12 @@
spv.debugInfo.frag spv.debugInfo.frag
// Module Version 10300 // Module Version 10300
// Generated by (magic number): 8000b // Generated by (magic number): 8000b
// Id's are bound by 124 // Id's are bound by 187
Capability Shader Capability Shader
2: ExtInstImport "GLSL.std.450" 2: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 5 "main" 24 52 EntryPoint Fragment 5 "main" 30 104
ExecutionMode 5 OriginUpperLeft ExecutionMode 5 OriginUpperLeft
1: String "spv.debugInfo.frag" 1: String "spv.debugInfo.frag"
Source GLSL 450 1 "#version 450 Source GLSL 450 1 "#version 450
@ -36,9 +36,40 @@ vec4 foo(S s)
return r; return r;
} }
float testBranch(float x, float y)
{
float result = 0;
bool b = x > 0;
// branch with load
if (b) {
result += 1;
}
else {
result -= 1;
}
// branch with expression
if (x > y) {
result += x - y;
}
// selection with load
result += b ?
1 : -1;
// selection with expression
result += x < y ?
y :
float(b);
return result;
}
void main() void main()
{ {
outv = foo(s); outv = foo(s);
outv += testBranch(inv.x, inv.y);
outv += texture(s2d, vec2(0.5)); outv += texture(s2d, vec2(0.5));
switch (s.a) { switch (s.a) {
@ -66,17 +97,24 @@ void main()
MemberName 8(S) 0 "a" MemberName 8(S) 0 "a"
Name 14 "foo(struct-S-i11;" Name 14 "foo(struct-S-i11;"
Name 13 "s" Name 13 "s"
Name 17 "r" Name 20 "testBranch(f1;f1;"
Name 24 "inv" Name 18 "x"
Name 52 "outv" Name 19 "y"
Name 53 "S" Name 23 "r"
MemberName 53(S) 0 "a" Name 30 "inv"
Name 54 "ubuf" Name 56 "result"
MemberName 54(ubuf) 0 "s" Name 59 "b"
Name 56 "" Name 104 "outv"
Name 57 "param" Name 105 "S"
Name 67 "s2d" MemberName 105(S) 0 "a"
Name 97 "i" Name 106 "ubuf"
MemberName 106(ubuf) 0 "s"
Name 108 ""
Name 109 "param"
Name 116 "param"
Name 120 "param"
Name 131 "s2d"
Name 161 "i"
ModuleProcessed "no-storage-format" ModuleProcessed "no-storage-format"
ModuleProcessed "resource-set-binding 3" ModuleProcessed "resource-set-binding 3"
ModuleProcessed "auto-map-bindings" ModuleProcessed "auto-map-bindings"
@ -88,15 +126,15 @@ void main()
ModuleProcessed "suppress-warnings" ModuleProcessed "suppress-warnings"
ModuleProcessed "hlsl-offsets" ModuleProcessed "hlsl-offsets"
ModuleProcessed "entry-point main" ModuleProcessed "entry-point main"
Decorate 24(inv) Location 0 Decorate 30(inv) Location 0
Decorate 52(outv) Location 0 Decorate 104(outv) Location 0
MemberDecorate 53(S) 0 Offset 0 MemberDecorate 105(S) 0 Offset 0
MemberDecorate 54(ubuf) 0 Offset 0 MemberDecorate 106(ubuf) 0 Offset 0
Decorate 54(ubuf) Block Decorate 106(ubuf) Block
Decorate 56 DescriptorSet 3 Decorate 108 DescriptorSet 3
Decorate 56 Binding 0 Decorate 108 Binding 0
Decorate 67(s2d) DescriptorSet 3 Decorate 131(s2d) DescriptorSet 3
Decorate 67(s2d) Binding 1 Decorate 131(s2d) Binding 1
3: TypeVoid 3: TypeVoid
4: TypeFunction 3 4: TypeFunction 3
7: TypeInt 32 1 7: TypeInt 32 1
@ -105,179 +143,280 @@ void main()
10: TypeFloat 32 10: TypeFloat 32
11: TypeVector 10(float) 4 11: TypeVector 10(float) 4
12: TypeFunction 11(fvec4) 9(ptr) 12: TypeFunction 11(fvec4) 9(ptr)
16: TypePointer Function 11(fvec4) 16: TypePointer Function 10(float)
18: 7(int) Constant 0 17: TypeFunction 10(float) 16(ptr) 16(ptr)
19: TypePointer Function 7(int) 22: TypePointer Function 11(fvec4)
23: TypePointer Input 11(fvec4) 24: 7(int) Constant 0
24(inv): 23(ptr) Variable Input 25: TypePointer Function 7(int)
28: 10(float) Constant 1065353216 29: TypePointer Input 11(fvec4)
31: TypeInt 32 0 30(inv): 29(ptr) Variable Input
32: 31(int) Constant 0 34: 10(float) Constant 1065353216
33: TypePointer Function 10(float) 37: TypeInt 32 0
36: 10(float) Constant 1077936128 38: 37(int) Constant 0
37: TypeBool 41: 10(float) Constant 1077936128
45: 10(float) Constant 1073741824 42: TypeBool
51: TypePointer Output 11(fvec4) 50: 10(float) Constant 1073741824
52(outv): 51(ptr) Variable Output 57: 10(float) Constant 0
53(S): TypeStruct 7(int) 58: TypePointer Function 42(bool)
54(ubuf): TypeStruct 53(S) 81: 7(int) Constant 1
55: TypePointer Uniform 54(ubuf) 82: 7(int) Constant 4294967295
56: 55(ptr) Variable Uniform 103: TypePointer Output 11(fvec4)
58: TypePointer Uniform 53(S) 104(outv): 103(ptr) Variable Output
64: TypeImage 10(float) 2D sampled format:Unknown 105(S): TypeStruct 7(int)
65: TypeSampledImage 64 106(ubuf): TypeStruct 105(S)
66: TypePointer UniformConstant 65 107: TypePointer Uniform 106(ubuf)
67(s2d): 66(ptr) Variable UniformConstant 108: 107(ptr) Variable Uniform
69: TypeVector 10(float) 2 110: TypePointer Uniform 105(S)
70: 10(float) Constant 1056964608 117: TypePointer Input 10(float)
71: 69(fvec2) ConstantComposite 70 70 121: 37(int) Constant 1
75: TypePointer Uniform 7(int) 128: TypeImage 10(float) 2D sampled format:Unknown
104: 7(int) Constant 10 129: TypeSampledImage 128
109: 7(int) Constant 1 130: TypePointer UniformConstant 129
111: TypePointer Output 10(float) 131(s2d): 130(ptr) Variable UniformConstant
114: 10(float) Constant 1092616192 133: TypeVector 10(float) 2
Line 1 28 11 134: 10(float) Constant 1056964608
135: 133(fvec2) ConstantComposite 134 134
139: TypePointer Uniform 7(int)
168: 7(int) Constant 10
174: TypePointer Output 10(float)
177: 10(float) Constant 1092616192
Line 1 58 11
5(main): 3 Function None 4 5(main): 3 Function None 4
6: Label 6: Label
57(param): 9(ptr) Variable Function 109(param): 9(ptr) Variable Function
97(i): 19(ptr) Variable Function 116(param): 16(ptr) Variable Function
116: 16(ptr) Variable Function 120(param): 16(ptr) Variable Function
Line 1 30 0 161(i): 25(ptr) Variable Function
59: 58(ptr) AccessChain 56 18 179: 22(ptr) Variable Function
60: 53(S) Load 59 Line 1 60 0
61: 7(int) CompositeExtract 60 0 111: 110(ptr) AccessChain 108 24
62: 19(ptr) AccessChain 57(param) 18 112: 105(S) Load 111
Store 62 61 113: 7(int) CompositeExtract 112 0
63: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 57(param) 114: 25(ptr) AccessChain 109(param) 24
Store 52(outv) 63 Store 114 113
Line 1 31 0 115: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 109(param)
68: 65 Load 67(s2d) Store 104(outv) 115
72: 11(fvec4) ImageSampleImplicitLod 68 71 Line 1 61 0
73: 11(fvec4) Load 52(outv) 118: 117(ptr) AccessChain 30(inv) 38
74: 11(fvec4) FAdd 73 72 119: 10(float) Load 118
Store 52(outv) 74 Store 116(param) 119
Line 1 33 0 122: 117(ptr) AccessChain 30(inv) 121
76: 75(ptr) AccessChain 56 18 18 123: 10(float) Load 122
77: 7(int) Load 76 Store 120(param) 123
SelectionMerge 81 None 124: 10(float) FunctionCall 20(testBranch(f1;f1;) 116(param) 120(param)
Switch 77 80 125: 11(fvec4) Load 104(outv)
case 10: 78 126: 11(fvec4) CompositeConstruct 124 124 124 124
case 20: 79 127: 11(fvec4) FAdd 125 126
80: Label Store 104(outv) 127
Line 1 42 0 Line 1 62 0
92: 11(fvec4) Load 52(outv) 132: 129 Load 131(s2d)
93: 11(fvec4) CompositeConstruct 28 28 28 28 136: 11(fvec4) ImageSampleImplicitLod 132 135
94: 11(fvec4) FSub 92 93 137: 11(fvec4) Load 104(outv)
Store 52(outv) 94 138: 11(fvec4) FAdd 137 136
Line 1 43 0 Store 104(outv) 138
Branch 81 Line 1 64 0
78: Label 140: 139(ptr) AccessChain 108 24 24
Line 1 35 0 141: 7(int) Load 140
82: 11(fvec4) Load 52(outv) SelectionMerge 145 None
83: 11(fvec4) CompositeConstruct 28 28 28 28 Switch 141 144
84: 11(fvec4) FAdd 82 83 case 10: 142
Store 52(outv) 84 case 20: 143
Line 1 36 0 144: Label
Branch 81 Line 1 73 0
79: Label 156: 11(fvec4) Load 104(outv)
Line 1 38 0 157: 11(fvec4) CompositeConstruct 34 34 34 34
86: 11(fvec4) Load 52(outv) 158: 11(fvec4) FSub 156 157
87: 11(fvec4) VectorTimesScalar 86 45 Store 104(outv) 158
Store 52(outv) 87 Line 1 74 0
Line 1 39 0 Branch 145
88: 11(fvec4) Load 52(outv) 142: Label
89: 11(fvec4) CompositeConstruct 28 28 28 28 Line 1 66 0
90: 11(fvec4) FAdd 88 89 146: 11(fvec4) Load 104(outv)
Store 52(outv) 90 147: 11(fvec4) CompositeConstruct 34 34 34 34
Line 1 40 0 148: 11(fvec4) FAdd 146 147
Branch 81 Store 104(outv) 148
81: Label Line 1 67 0
Line 1 46 0 Branch 145
Store 97(i) 18 143: Label
Branch 98 Line 1 69 0
98: Label 150: 11(fvec4) Load 104(outv)
Line 1 46 0 151: 11(fvec4) VectorTimesScalar 150 50
LoopMerge 100 101 None Store 104(outv) 151
Branch 102 Line 1 70 0
102: Label 152: 11(fvec4) Load 104(outv)
Line 1 46 0 153: 11(fvec4) CompositeConstruct 34 34 34 34
103: 7(int) Load 97(i) 154: 11(fvec4) FAdd 152 153
105: 37(bool) SLessThan 103 104 Store 104(outv) 154
BranchConditional 105 99 100 Line 1 71 0
99: Label Branch 145
Line 1 47 0 145: Label
106: 11(fvec4) Load 52(outv) Line 1 77 0
107: 11(fvec4) VectorTimesScalar 106 36 Store 161(i) 24
Store 52(outv) 107 Branch 162
Branch 101 162: Label
101: Label Line 1 77 0
Line 1 46 0 LoopMerge 164 165 None
108: 7(int) Load 97(i) Branch 166
110: 7(int) IAdd 108 109 166: Label
Store 97(i) 110 Line 1 77 0
Branch 98 167: 7(int) Load 161(i)
100: Label 169: 42(bool) SLessThan 167 168
Line 1 49 0 BranchConditional 169 163 164
112: 111(ptr) AccessChain 52(outv) 32 163: Label
113: 10(float) Load 112 Line 1 78 0
115: 37(bool) FOrdLessThan 113 114 170: 11(fvec4) Load 104(outv)
SelectionMerge 118 None 171: 11(fvec4) VectorTimesScalar 170 41
BranchConditional 115 117 121 Store 104(outv) 171
117: Label Branch 165
Line 1 50 0 165: Label
119: 11(fvec4) Load 52(outv) Line 1 77 0
120: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 119 172: 7(int) Load 161(i)
Store 52(outv) 120 173: 7(int) IAdd 172 81
Store 116 120 Store 161(i) 173
Branch 118 Branch 162
121: Label 164: Label
Line 1 51 0 Line 1 80 0
122: 11(fvec4) Load 52(outv) 175: 174(ptr) AccessChain 104(outv) 38
123: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 122 176: 10(float) Load 175
Store 52(outv) 123 178: 42(bool) FOrdLessThan 176 177
Store 116 123 SelectionMerge 181 None
Branch 118 BranchConditional 178 180 184
118: Label 180: Label
Line 1 81 0
182: 11(fvec4) Load 104(outv)
183: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 182
Store 104(outv) 183
Store 179 183
Branch 181
184: Label
Line 1 82 0
185: 11(fvec4) Load 104(outv)
186: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 185
Store 104(outv) 186
Store 179 186
Branch 181
181: Label
Return Return
FunctionEnd FunctionEnd
Line 1 16 13 Line 1 16 13
14(foo(struct-S-i11;): 11(fvec4) Function None 12 14(foo(struct-S-i11;): 11(fvec4) Function None 12
13(s): 9(ptr) FunctionParameter 13(s): 9(ptr) FunctionParameter
15: Label 15: Label
17(r): 16(ptr) Variable Function 23(r): 22(ptr) Variable Function
Line 1 18 0 Line 1 18 0
20: 19(ptr) AccessChain 13(s) 18 26: 25(ptr) AccessChain 13(s) 24
21: 7(int) Load 20 27: 7(int) Load 26
22: 10(float) ConvertSToF 21 28: 10(float) ConvertSToF 27
25: 11(fvec4) Load 24(inv) 31: 11(fvec4) Load 30(inv)
26: 11(fvec4) VectorTimesScalar 25 22 32: 11(fvec4) VectorTimesScalar 31 28
Store 17(r) 26 Store 23(r) 32
Line 1 19 0 Line 1 19 0
27: 11(fvec4) Load 17(r) 33: 11(fvec4) Load 23(r)
29: 11(fvec4) CompositeConstruct 28 28 28 28 35: 11(fvec4) CompositeConstruct 34 34 34 34
30: 11(fvec4) FAdd 27 29 36: 11(fvec4) FAdd 33 35
Store 17(r) 30 Store 23(r) 36
Line 1 20 0 Line 1 20 0
34: 33(ptr) AccessChain 17(r) 32 39: 16(ptr) AccessChain 23(r) 38
35: 10(float) Load 34 40: 10(float) Load 39
38: 37(bool) FOrdGreaterThan 35 36 43: 42(bool) FOrdGreaterThan 40 41
SelectionMerge 40 None SelectionMerge 45 None
BranchConditional 38 39 44 BranchConditional 43 44 49
39: Label
Line 1 21 0
41: 11(fvec4) Load 17(r)
42: 11(fvec4) CompositeConstruct 28 28 28 28
43: 11(fvec4) FSub 41 42
Store 17(r) 43
Branch 40
44: Label 44: Label
Line 1 21 0
46: 11(fvec4) Load 23(r)
47: 11(fvec4) CompositeConstruct 34 34 34 34
48: 11(fvec4) FSub 46 47
Store 23(r) 48
Branch 45
49: Label
Line 1 23 0 Line 1 23 0
46: 11(fvec4) Load 17(r) 51: 11(fvec4) Load 23(r)
47: 11(fvec4) VectorTimesScalar 46 45 52: 11(fvec4) VectorTimesScalar 51 50
Store 17(r) 47 Store 23(r) 52
Branch 40 Branch 45
40: Label 45: Label
Line 1 25 0 Line 1 25 0
48: 11(fvec4) Load 17(r) 53: 11(fvec4) Load 23(r)
ReturnValue 48 ReturnValue 53
FunctionEnd
Line 1 28 34
20(testBranch(f1;f1;): 10(float) Function None 17
18(x): 16(ptr) FunctionParameter
19(y): 16(ptr) FunctionParameter
21: Label
56(result): 16(ptr) Variable Function
59(b): 58(ptr) Variable Function
90: 16(ptr) Variable Function
Line 1 30 0
Store 56(result) 57
Line 1 31 0
60: 10(float) Load 18(x)
61: 42(bool) FOrdGreaterThan 60 57
Store 59(b) 61
Line 1 34 0
62: 42(bool) Load 59(b)
SelectionMerge 64 None
BranchConditional 62 63 67
63: Label
Line 1 35 0
65: 10(float) Load 56(result)
66: 10(float) FAdd 65 34
Store 56(result) 66
Branch 64
67: Label
Line 1 38 0
68: 10(float) Load 56(result)
69: 10(float) FSub 68 34
Store 56(result) 69
Branch 64
64: Label
Line 1 42 0
70: 10(float) Load 18(x)
71: 10(float) Load 19(y)
72: 42(bool) FOrdGreaterThan 70 71
SelectionMerge 74 None
BranchConditional 72 73 74
73: Label
Line 1 43 0
75: 10(float) Load 18(x)
76: 10(float) Load 19(y)
77: 10(float) FSub 75 76
78: 10(float) Load 56(result)
79: 10(float) FAdd 78 77
Store 56(result) 79
Branch 74
74: Label
Line 1 47 0
80: 42(bool) Load 59(b)
83: 7(int) Select 80 81 82
84: 10(float) ConvertSToF 83
85: 10(float) Load 56(result)
86: 10(float) FAdd 85 84
Store 56(result) 86
Line 1 51 0
87: 10(float) Load 18(x)
88: 10(float) Load 19(y)
89: 42(bool) FOrdLessThan 87 88
SelectionMerge 92 None
BranchConditional 89 91 94
91: Label
Line 1 52 0
93: 10(float) Load 19(y)
Store 90 93
Branch 92
94: Label
Line 1 53 0
95: 42(bool) Load 59(b)
96: 10(float) Select 95 34 57
Store 90 96
Branch 92
92: Label
97: 10(float) Load 90
Line 1 51 0
98: 10(float) Load 56(result)
99: 10(float) FAdd 98 97
Store 56(result) 99
Line 1 55 0
100: 10(float) Load 56(result)
ReturnValue 100
FunctionEnd FunctionEnd

View File

@ -1,12 +1,12 @@
spv.debugInfo.frag spv.debugInfo.frag
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 8000b // Generated by (magic number): 8000b
// Id's are bound by 124 // Id's are bound by 187
Capability Shader Capability Shader
2: ExtInstImport "GLSL.std.450" 2: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 5 "main" 24 52 EntryPoint Fragment 5 "main" 30 104
ExecutionMode 5 OriginLowerLeft ExecutionMode 5 OriginLowerLeft
1: String "spv.debugInfo.frag" 1: String "spv.debugInfo.frag"
Source GLSL 450 1 "// OpModuleProcessed no-storage-format Source GLSL 450 1 "// OpModuleProcessed no-storage-format
@ -47,9 +47,40 @@ vec4 foo(S s)
return r; return r;
} }
float testBranch(float x, float y)
{
float result = 0;
bool b = x > 0;
// branch with load
if (b) {
result += 1;
}
else {
result -= 1;
}
// branch with expression
if (x > y) {
result += x - y;
}
// selection with load
result += b ?
1 : -1;
// selection with expression
result += x < y ?
y :
float(b);
return result;
}
void main() void main()
{ {
outv = foo(s); outv = foo(s);
outv += testBranch(inv.x, inv.y);
outv += texture(s2d, vec2(0.5)); outv += texture(s2d, vec2(0.5));
switch (s.a) { switch (s.a) {
@ -77,27 +108,34 @@ void main()
MemberName 8(S) 0 "a" MemberName 8(S) 0 "a"
Name 14 "foo(struct-S-i11;" Name 14 "foo(struct-S-i11;"
Name 13 "s" Name 13 "s"
Name 17 "r" Name 20 "testBranch(f1;f1;"
Name 24 "inv" Name 18 "x"
Name 52 "outv" Name 19 "y"
Name 53 "S" Name 23 "r"
MemberName 53(S) 0 "a" Name 30 "inv"
Name 54 "ubuf" Name 56 "result"
MemberName 54(ubuf) 0 "s" Name 59 "b"
Name 56 "" Name 104 "outv"
Name 57 "param" Name 105 "S"
Name 67 "s2d" MemberName 105(S) 0 "a"
Name 97 "i" Name 106 "ubuf"
Decorate 24(inv) Location 0 MemberName 106(ubuf) 0 "s"
Decorate 52(outv) Location 0 Name 108 ""
MemberDecorate 53(S) 0 Offset 0 Name 109 "param"
MemberDecorate 54(ubuf) 0 Offset 0 Name 116 "param"
Decorate 54(ubuf) Block Name 120 "param"
Decorate 56 DescriptorSet 3 Name 131 "s2d"
Decorate 56 Binding 0 Name 161 "i"
Decorate 67(s2d) Location 0 Decorate 30(inv) Location 0
Decorate 67(s2d) DescriptorSet 3 Decorate 104(outv) Location 0
Decorate 67(s2d) Binding 1 MemberDecorate 105(S) 0 Offset 0
MemberDecorate 106(ubuf) 0 Offset 0
Decorate 106(ubuf) Block
Decorate 108 DescriptorSet 3
Decorate 108 Binding 0
Decorate 131(s2d) Location 0
Decorate 131(s2d) DescriptorSet 3
Decorate 131(s2d) Binding 1
3: TypeVoid 3: TypeVoid
4: TypeFunction 3 4: TypeFunction 3
7: TypeInt 32 1 7: TypeInt 32 1
@ -106,179 +144,280 @@ void main()
10: TypeFloat 32 10: TypeFloat 32
11: TypeVector 10(float) 4 11: TypeVector 10(float) 4
12: TypeFunction 11(fvec4) 9(ptr) 12: TypeFunction 11(fvec4) 9(ptr)
16: TypePointer Function 11(fvec4) 16: TypePointer Function 10(float)
18: 7(int) Constant 0 17: TypeFunction 10(float) 16(ptr) 16(ptr)
19: TypePointer Function 7(int) 22: TypePointer Function 11(fvec4)
23: TypePointer Input 11(fvec4) 24: 7(int) Constant 0
24(inv): 23(ptr) Variable Input 25: TypePointer Function 7(int)
28: 10(float) Constant 1065353216 29: TypePointer Input 11(fvec4)
31: TypeInt 32 0 30(inv): 29(ptr) Variable Input
32: 31(int) Constant 0 34: 10(float) Constant 1065353216
33: TypePointer Function 10(float) 37: TypeInt 32 0
36: 10(float) Constant 1077936128 38: 37(int) Constant 0
37: TypeBool 41: 10(float) Constant 1077936128
45: 10(float) Constant 1073741824 42: TypeBool
51: TypePointer Output 11(fvec4) 50: 10(float) Constant 1073741824
52(outv): 51(ptr) Variable Output 57: 10(float) Constant 0
53(S): TypeStruct 7(int) 58: TypePointer Function 42(bool)
54(ubuf): TypeStruct 53(S) 81: 7(int) Constant 1
55: TypePointer Uniform 54(ubuf) 82: 7(int) Constant 4294967295
56: 55(ptr) Variable Uniform 103: TypePointer Output 11(fvec4)
58: TypePointer Uniform 53(S) 104(outv): 103(ptr) Variable Output
64: TypeImage 10(float) 2D sampled format:Unknown 105(S): TypeStruct 7(int)
65: TypeSampledImage 64 106(ubuf): TypeStruct 105(S)
66: TypePointer UniformConstant 65 107: TypePointer Uniform 106(ubuf)
67(s2d): 66(ptr) Variable UniformConstant 108: 107(ptr) Variable Uniform
69: TypeVector 10(float) 2 110: TypePointer Uniform 105(S)
70: 10(float) Constant 1056964608 117: TypePointer Input 10(float)
71: 69(fvec2) ConstantComposite 70 70 121: 37(int) Constant 1
75: TypePointer Uniform 7(int) 128: TypeImage 10(float) 2D sampled format:Unknown
104: 7(int) Constant 10 129: TypeSampledImage 128
109: 7(int) Constant 1 130: TypePointer UniformConstant 129
111: TypePointer Output 10(float) 131(s2d): 130(ptr) Variable UniformConstant
114: 10(float) Constant 1092616192 133: TypeVector 10(float) 2
Line 1 28 11 134: 10(float) Constant 1056964608
135: 133(fvec2) ConstantComposite 134 134
139: TypePointer Uniform 7(int)
168: 7(int) Constant 10
174: TypePointer Output 10(float)
177: 10(float) Constant 1092616192
Line 1 58 11
5(main): 3 Function None 4 5(main): 3 Function None 4
6: Label 6: Label
57(param): 9(ptr) Variable Function 109(param): 9(ptr) Variable Function
97(i): 19(ptr) Variable Function 116(param): 16(ptr) Variable Function
116: 16(ptr) Variable Function 120(param): 16(ptr) Variable Function
Line 1 30 0 161(i): 25(ptr) Variable Function
59: 58(ptr) AccessChain 56 18 179: 22(ptr) Variable Function
60: 53(S) Load 59 Line 1 60 0
61: 7(int) CompositeExtract 60 0 111: 110(ptr) AccessChain 108 24
62: 19(ptr) AccessChain 57(param) 18 112: 105(S) Load 111
Store 62 61 113: 7(int) CompositeExtract 112 0
63: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 57(param) 114: 25(ptr) AccessChain 109(param) 24
Store 52(outv) 63 Store 114 113
Line 1 31 0 115: 11(fvec4) FunctionCall 14(foo(struct-S-i11;) 109(param)
68: 65 Load 67(s2d) Store 104(outv) 115
72: 11(fvec4) ImageSampleImplicitLod 68 71 Line 1 61 0
73: 11(fvec4) Load 52(outv) 118: 117(ptr) AccessChain 30(inv) 38
74: 11(fvec4) FAdd 73 72 119: 10(float) Load 118
Store 52(outv) 74 Store 116(param) 119
Line 1 33 0 122: 117(ptr) AccessChain 30(inv) 121
76: 75(ptr) AccessChain 56 18 18 123: 10(float) Load 122
77: 7(int) Load 76 Store 120(param) 123
SelectionMerge 81 None 124: 10(float) FunctionCall 20(testBranch(f1;f1;) 116(param) 120(param)
Switch 77 80 125: 11(fvec4) Load 104(outv)
case 10: 78 126: 11(fvec4) CompositeConstruct 124 124 124 124
case 20: 79 127: 11(fvec4) FAdd 125 126
80: Label Store 104(outv) 127
Line 1 42 0 Line 1 62 0
92: 11(fvec4) Load 52(outv) 132: 129 Load 131(s2d)
93: 11(fvec4) CompositeConstruct 28 28 28 28 136: 11(fvec4) ImageSampleImplicitLod 132 135
94: 11(fvec4) FSub 92 93 137: 11(fvec4) Load 104(outv)
Store 52(outv) 94 138: 11(fvec4) FAdd 137 136
Line 1 43 0 Store 104(outv) 138
Branch 81 Line 1 64 0
78: Label 140: 139(ptr) AccessChain 108 24 24
Line 1 35 0 141: 7(int) Load 140
82: 11(fvec4) Load 52(outv) SelectionMerge 145 None
83: 11(fvec4) CompositeConstruct 28 28 28 28 Switch 141 144
84: 11(fvec4) FAdd 82 83 case 10: 142
Store 52(outv) 84 case 20: 143
Line 1 36 0 144: Label
Branch 81 Line 1 73 0
79: Label 156: 11(fvec4) Load 104(outv)
Line 1 38 0 157: 11(fvec4) CompositeConstruct 34 34 34 34
86: 11(fvec4) Load 52(outv) 158: 11(fvec4) FSub 156 157
87: 11(fvec4) VectorTimesScalar 86 45 Store 104(outv) 158
Store 52(outv) 87 Line 1 74 0
Line 1 39 0 Branch 145
88: 11(fvec4) Load 52(outv) 142: Label
89: 11(fvec4) CompositeConstruct 28 28 28 28 Line 1 66 0
90: 11(fvec4) FAdd 88 89 146: 11(fvec4) Load 104(outv)
Store 52(outv) 90 147: 11(fvec4) CompositeConstruct 34 34 34 34
Line 1 40 0 148: 11(fvec4) FAdd 146 147
Branch 81 Store 104(outv) 148
81: Label Line 1 67 0
Line 1 46 0 Branch 145
Store 97(i) 18 143: Label
Branch 98 Line 1 69 0
98: Label 150: 11(fvec4) Load 104(outv)
Line 1 46 0 151: 11(fvec4) VectorTimesScalar 150 50
LoopMerge 100 101 None Store 104(outv) 151
Branch 102 Line 1 70 0
102: Label 152: 11(fvec4) Load 104(outv)
Line 1 46 0 153: 11(fvec4) CompositeConstruct 34 34 34 34
103: 7(int) Load 97(i) 154: 11(fvec4) FAdd 152 153
105: 37(bool) SLessThan 103 104 Store 104(outv) 154
BranchConditional 105 99 100 Line 1 71 0
99: Label Branch 145
Line 1 47 0 145: Label
106: 11(fvec4) Load 52(outv) Line 1 77 0
107: 11(fvec4) VectorTimesScalar 106 36 Store 161(i) 24
Store 52(outv) 107 Branch 162
Branch 101 162: Label
101: Label Line 1 77 0
Line 1 46 0 LoopMerge 164 165 None
108: 7(int) Load 97(i) Branch 166
110: 7(int) IAdd 108 109 166: Label
Store 97(i) 110 Line 1 77 0
Branch 98 167: 7(int) Load 161(i)
100: Label 169: 42(bool) SLessThan 167 168
Line 1 49 0 BranchConditional 169 163 164
112: 111(ptr) AccessChain 52(outv) 32 163: Label
113: 10(float) Load 112 Line 1 78 0
115: 37(bool) FOrdLessThan 113 114 170: 11(fvec4) Load 104(outv)
SelectionMerge 118 None 171: 11(fvec4) VectorTimesScalar 170 41
BranchConditional 115 117 121 Store 104(outv) 171
117: Label Branch 165
Line 1 50 0 165: Label
119: 11(fvec4) Load 52(outv) Line 1 77 0
120: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 119 172: 7(int) Load 161(i)
Store 52(outv) 120 173: 7(int) IAdd 172 81
Store 116 120 Store 161(i) 173
Branch 118 Branch 162
121: Label 164: Label
Line 1 51 0 Line 1 80 0
122: 11(fvec4) Load 52(outv) 175: 174(ptr) AccessChain 104(outv) 38
123: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 122 176: 10(float) Load 175
Store 52(outv) 123 178: 42(bool) FOrdLessThan 176 177
Store 116 123 SelectionMerge 181 None
Branch 118 BranchConditional 178 180 184
118: Label 180: Label
Line 1 81 0
182: 11(fvec4) Load 104(outv)
183: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 182
Store 104(outv) 183
Store 179 183
Branch 181
184: Label
Line 1 82 0
185: 11(fvec4) Load 104(outv)
186: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 185
Store 104(outv) 186
Store 179 186
Branch 181
181: Label
Return Return
FunctionEnd FunctionEnd
Line 1 16 13 Line 1 16 13
14(foo(struct-S-i11;): 11(fvec4) Function None 12 14(foo(struct-S-i11;): 11(fvec4) Function None 12
13(s): 9(ptr) FunctionParameter 13(s): 9(ptr) FunctionParameter
15: Label 15: Label
17(r): 16(ptr) Variable Function 23(r): 22(ptr) Variable Function
Line 1 18 0 Line 1 18 0
20: 19(ptr) AccessChain 13(s) 18 26: 25(ptr) AccessChain 13(s) 24
21: 7(int) Load 20 27: 7(int) Load 26
22: 10(float) ConvertSToF 21 28: 10(float) ConvertSToF 27
25: 11(fvec4) Load 24(inv) 31: 11(fvec4) Load 30(inv)
26: 11(fvec4) VectorTimesScalar 25 22 32: 11(fvec4) VectorTimesScalar 31 28
Store 17(r) 26 Store 23(r) 32
Line 1 19 0 Line 1 19 0
27: 11(fvec4) Load 17(r) 33: 11(fvec4) Load 23(r)
29: 11(fvec4) CompositeConstruct 28 28 28 28 35: 11(fvec4) CompositeConstruct 34 34 34 34
30: 11(fvec4) FAdd 27 29 36: 11(fvec4) FAdd 33 35
Store 17(r) 30 Store 23(r) 36
Line 1 20 0 Line 1 20 0
34: 33(ptr) AccessChain 17(r) 32 39: 16(ptr) AccessChain 23(r) 38
35: 10(float) Load 34 40: 10(float) Load 39
38: 37(bool) FOrdGreaterThan 35 36 43: 42(bool) FOrdGreaterThan 40 41
SelectionMerge 40 None SelectionMerge 45 None
BranchConditional 38 39 44 BranchConditional 43 44 49
39: Label
Line 1 21 0
41: 11(fvec4) Load 17(r)
42: 11(fvec4) CompositeConstruct 28 28 28 28
43: 11(fvec4) FSub 41 42
Store 17(r) 43
Branch 40
44: Label 44: Label
Line 1 21 0
46: 11(fvec4) Load 23(r)
47: 11(fvec4) CompositeConstruct 34 34 34 34
48: 11(fvec4) FSub 46 47
Store 23(r) 48
Branch 45
49: Label
Line 1 23 0 Line 1 23 0
46: 11(fvec4) Load 17(r) 51: 11(fvec4) Load 23(r)
47: 11(fvec4) VectorTimesScalar 46 45 52: 11(fvec4) VectorTimesScalar 51 50
Store 17(r) 47 Store 23(r) 52
Branch 40 Branch 45
40: Label 45: Label
Line 1 25 0 Line 1 25 0
48: 11(fvec4) Load 17(r) 53: 11(fvec4) Load 23(r)
ReturnValue 48 ReturnValue 53
FunctionEnd
Line 1 28 34
20(testBranch(f1;f1;): 10(float) Function None 17
18(x): 16(ptr) FunctionParameter
19(y): 16(ptr) FunctionParameter
21: Label
56(result): 16(ptr) Variable Function
59(b): 58(ptr) Variable Function
90: 16(ptr) Variable Function
Line 1 30 0
Store 56(result) 57
Line 1 31 0
60: 10(float) Load 18(x)
61: 42(bool) FOrdGreaterThan 60 57
Store 59(b) 61
Line 1 34 0
62: 42(bool) Load 59(b)
SelectionMerge 64 None
BranchConditional 62 63 67
63: Label
Line 1 35 0
65: 10(float) Load 56(result)
66: 10(float) FAdd 65 34
Store 56(result) 66
Branch 64
67: Label
Line 1 38 0
68: 10(float) Load 56(result)
69: 10(float) FSub 68 34
Store 56(result) 69
Branch 64
64: Label
Line 1 42 0
70: 10(float) Load 18(x)
71: 10(float) Load 19(y)
72: 42(bool) FOrdGreaterThan 70 71
SelectionMerge 74 None
BranchConditional 72 73 74
73: Label
Line 1 43 0
75: 10(float) Load 18(x)
76: 10(float) Load 19(y)
77: 10(float) FSub 75 76
78: 10(float) Load 56(result)
79: 10(float) FAdd 78 77
Store 56(result) 79
Branch 74
74: Label
Line 1 47 0
80: 42(bool) Load 59(b)
83: 7(int) Select 80 81 82
84: 10(float) ConvertSToF 83
85: 10(float) Load 56(result)
86: 10(float) FAdd 85 84
Store 56(result) 86
Line 1 51 0
87: 10(float) Load 18(x)
88: 10(float) Load 19(y)
89: 42(bool) FOrdLessThan 87 88
SelectionMerge 92 None
BranchConditional 89 91 94
91: Label
Line 1 52 0
93: 10(float) Load 19(y)
Store 90 93
Branch 92
94: Label
Line 1 53 0
95: 42(bool) Load 59(b)
96: 10(float) Select 95 34 57
Store 90 96
Branch 92
92: Label
97: 10(float) Load 90
Line 1 51 0
98: 10(float) Load 56(result)
99: 10(float) FAdd 98 97
Store 56(result) 99
Line 1 55 0
100: 10(float) Load 56(result)
ReturnValue 100
FunctionEnd FunctionEnd

View File

@ -25,9 +25,40 @@ vec4 foo(S s)
return r; return r;
} }
float testBranch(float x, float y)
{
float result = 0;
bool b = x > 0;
// branch with load
if (b) {
result += 1;
}
else {
result -= 1;
}
// branch with expression
if (x > y) {
result += x - y;
}
// selection with load
result += b ?
1 : -1;
// selection with expression
result += x < y ?
y :
float(b);
return result;
}
void main() void main()
{ {
outv = foo(s); outv = foo(s);
outv += testBranch(inv.x, inv.y);
outv += texture(s2d, vec2(0.5)); outv += texture(s2d, vec2(0.5));
switch (s.a) { switch (s.a) {