SPV return from main: Simplify a legacy design such returns are not jumps to exit block.

Structured control-flow rules allow leaving the middle of a construct through
a return, but not through a jump to a block that does a return.

Addresses issue #58.
This commit is contained in:
John Kessenich
2015-09-14 20:58:02 -06:00
parent 5f5b205ce9
commit e770b3e6cf
74 changed files with 9648 additions and 9816 deletions

View File

@@ -10,7 +10,7 @@ Linked fragment stage:
// Module Version 99
// Generated by (magic number): 51a00bb
// Id's are bound by 261
// Id's are bound by 260
Source ESSL 310
Capability Shader
@@ -19,382 +19,380 @@ Linked fragment stage:
EntryPoint Fragment 4 "main"
ExecutionMode 4 OriginLowerLeft
Name 4 "main"
Name 16 "foo1(vf4;vf4;i1;"
Name 13 "v1"
Name 14 "v2"
Name 15 "i1"
Name 21 "foo2(vf4;vf4;i1;"
Name 18 "v1"
Name 19 "v2"
Name 20 "i1"
Name 59 "local"
Name 61 "c"
Name 72 "f"
Name 74 "x"
Name 128 "d"
Name 154 "i"
Name 172 "j"
Name 222 "color"
Name 228 "v"
Name 229 "param"
Name 231 "param"
Name 233 "param"
Name 239 "param"
Name 241 "param"
Name 243 "param"
Decorate 59(local) RelaxedPrecision
Decorate 61(c) RelaxedPrecision
Decorate 72(f) RelaxedPrecision
Decorate 74(x) RelaxedPrecision
Decorate 74(x) Smooth
Decorate 128(d) RelaxedPrecision
Decorate 154(i) RelaxedPrecision
Decorate 172(j) RelaxedPrecision
Decorate 222(color) RelaxedPrecision
Decorate 228(v) RelaxedPrecision
Name 15 "foo1(vf4;vf4;i1;"
Name 12 "v1"
Name 13 "v2"
Name 14 "i1"
Name 20 "foo2(vf4;vf4;i1;"
Name 17 "v1"
Name 18 "v2"
Name 19 "i1"
Name 58 "local"
Name 60 "c"
Name 71 "f"
Name 73 "x"
Name 127 "d"
Name 153 "i"
Name 171 "j"
Name 221 "color"
Name 227 "v"
Name 228 "param"
Name 230 "param"
Name 232 "param"
Name 238 "param"
Name 240 "param"
Name 242 "param"
Decorate 58(local) RelaxedPrecision
Decorate 60(c) RelaxedPrecision
Decorate 71(f) RelaxedPrecision
Decorate 73(x) RelaxedPrecision
Decorate 73(x) Smooth
Decorate 127(d) RelaxedPrecision
Decorate 153(i) RelaxedPrecision
Decorate 171(j) RelaxedPrecision
Decorate 221(color) RelaxedPrecision
Decorate 227(v) RelaxedPrecision
2: TypeVoid
3: TypeFunction 2
7: TypeFloat 32
8: TypeVector 7(float) 4
9: TypePointer Function 8(fvec4)
10: TypeInt 32 1
11: TypePointer Function 10(int)
12: TypeFunction 8(fvec4) 9(ptr) 9(ptr) 11(ptr)
37: 7(float) Constant 0
38: 8(fvec4) ConstantComposite 37 37 37 37
48: 7(float) Constant 1065353216
49: 8(fvec4) ConstantComposite 48 48 48 48
60: TypePointer UniformConstant 10(int)
61(c): 60(ptr) Variable UniformConstant
64: 10(int) Constant 1
71: TypePointer Function 7(float)
73: TypePointer Input 7(float)
74(x): 73(ptr) Variable Input
128(d): 60(ptr) Variable UniformConstant
155: 10(int) Constant 0
160: 10(int) Constant 10
161: TypeBool
173: 10(int) Constant 20
178: 10(int) Constant 30
183: 7(float) Constant 1120429670
203: 7(float) Constant 1079739679
221: TypePointer Output 7(float)
222(color): 221(ptr) Variable Output
227: TypePointer UniformConstant 8(fvec4)
228(v): 227(ptr) Variable UniformConstant
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Function 7(fvec4)
9: TypeInt 32 1
10: TypePointer Function 9(int)
11: TypeFunction 7(fvec4) 8(ptr) 8(ptr) 10(ptr)
36: 6(float) Constant 0
37: 7(fvec4) ConstantComposite 36 36 36 36
47: 6(float) Constant 1065353216
48: 7(fvec4) ConstantComposite 47 47 47 47
59: TypePointer UniformConstant 9(int)
60(c): 59(ptr) Variable UniformConstant
63: 9(int) Constant 1
70: TypePointer Function 6(float)
72: TypePointer Input 6(float)
73(x): 72(ptr) Variable Input
127(d): 59(ptr) Variable UniformConstant
154: 9(int) Constant 0
159: 9(int) Constant 10
160: TypeBool
172: 9(int) Constant 20
177: 9(int) Constant 30
182: 6(float) Constant 1120429670
202: 6(float) Constant 1079739679
220: TypePointer Output 6(float)
221(color): 220(ptr) Variable Output
226: TypePointer UniformConstant 7(fvec4)
227(v): 226(ptr) Variable UniformConstant
4(main): 2 Function None 3
5: Label
59(local): 11(ptr) Variable Function
72(f): 71(ptr) Variable Function
154(i): 11(ptr) Variable Function
172(j): 11(ptr) Variable Function
229(param): 9(ptr) Variable Function
231(param): 9(ptr) Variable Function
233(param): 11(ptr) Variable Function
239(param): 9(ptr) Variable Function
241(param): 9(ptr) Variable Function
243(param): 11(ptr) Variable Function
62: 10(int) Load 61(c)
Store 59(local) 62
63: 10(int) Load 59(local)
65: 10(int) IAdd 63 64
Store 59(local) 65
66: 10(int) Load 61(c)
SelectionMerge 70 None
Switch 66 69
case 1: 67
case 2: 68
58(local): 10(ptr) Variable Function
71(f): 70(ptr) Variable Function
153(i): 10(ptr) Variable Function
171(j): 10(ptr) Variable Function
228(param): 8(ptr) Variable Function
230(param): 8(ptr) Variable Function
232(param): 10(ptr) Variable Function
238(param): 8(ptr) Variable Function
240(param): 8(ptr) Variable Function
242(param): 10(ptr) Variable Function
61: 9(int) Load 60(c)
Store 58(local) 61
62: 9(int) Load 58(local)
64: 9(int) IAdd 62 63
Store 58(local) 64
65: 9(int) Load 60(c)
SelectionMerge 69 None
Switch 65 68
case 1: 66
case 2: 67
66: Label
74: 6(float) Load 73(x)
75: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 74
Store 71(f) 75
Branch 69
67: Label
75: 7(float) Load 74(x)
76: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 75
Store 72(f) 76
Branch 70
77: 6(float) Load 73(x)
78: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 77
Store 71(f) 78
Branch 69
68: Label
78: 7(float) Load 74(x)
79: 7(float) ExtInst 1(GLSL.std.450) 14(Cos) 78
Store 72(f) 79
Branch 70
69: Label
81: 7(float) Load 74(x)
82: 7(float) ExtInst 1(GLSL.std.450) 15(Tan) 81
Store 72(f) 82
Branch 70
70: Label
84: 10(int) Load 61(c)
SelectionMerge 88 None
Switch 84 87
case 1: 85
case 2: 86
80: 6(float) Load 73(x)
81: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 80
Store 71(f) 81
Branch 69
69: Label
83: 9(int) Load 60(c)
SelectionMerge 87 None
Switch 83 86
case 1: 84
case 2: 85
84: Label
88: 6(float) Load 73(x)
89: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 88
90: 6(float) Load 71(f)
91: 6(float) FAdd 90 89
Store 71(f) 91
Branch 85
85: Label
89: 7(float) Load 74(x)
90: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 89
91: 7(float) Load 72(f)
92: 7(float) FAdd 91 90
Store 72(f) 92
Branch 86
92: 6(float) Load 73(x)
93: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 92
94: 6(float) Load 71(f)
95: 6(float) FAdd 94 93
Store 71(f) 95
Branch 87
86: Label
93: 7(float) Load 74(x)
94: 7(float) ExtInst 1(GLSL.std.450) 14(Cos) 93
95: 7(float) Load 72(f)
96: 7(float) FAdd 95 94
Store 72(f) 96
Branch 88
87: Label
98: 7(float) Load 74(x)
99: 7(float) ExtInst 1(GLSL.std.450) 15(Tan) 98
100: 7(float) Load 72(f)
101: 7(float) FAdd 100 99
Store 72(f) 101
Branch 88
88: Label
103: 10(int) Load 61(c)
SelectionMerge 106 None
Switch 103 106
case 1: 104
case 2: 105
97: 6(float) Load 73(x)
98: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 97
99: 6(float) Load 71(f)
100: 6(float) FAdd 99 98
Store 71(f) 100
Branch 87
87: Label
102: 9(int) Load 60(c)
SelectionMerge 105 None
Switch 102 105
case 1: 103
case 2: 104
103: Label
106: 6(float) Load 73(x)
107: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 106
108: 6(float) Load 71(f)
109: 6(float) FAdd 108 107
Store 71(f) 109
Branch 105
104: Label
107: 7(float) Load 74(x)
108: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 107
109: 7(float) Load 72(f)
110: 7(float) FAdd 109 108
Store 72(f) 110
Branch 106
105: Label
112: 7(float) Load 74(x)
113: 7(float) ExtInst 1(GLSL.std.450) 14(Cos) 112
114: 7(float) Load 72(f)
115: 7(float) FAdd 114 113
Store 72(f) 115
Branch 106
106: Label
118: 10(int) Load 61(c)
SelectionMerge 122 None
Switch 118 121
case 1: 119
case 2: 120
111: 6(float) Load 73(x)
112: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 111
113: 6(float) Load 71(f)
114: 6(float) FAdd 113 112
Store 71(f) 114
Branch 105
105: Label
117: 9(int) Load 60(c)
SelectionMerge 121 None
Switch 117 120
case 1: 118
case 2: 119
118: Label
122: 6(float) Load 73(x)
123: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 122
124: 6(float) Load 71(f)
125: 6(float) FAdd 124 123
Store 71(f) 125
Branch 121
119: Label
123: 7(float) Load 74(x)
124: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 123
125: 7(float) Load 72(f)
126: 7(float) FAdd 125 124
Store 72(f) 126
Branch 122
120: Label
129: 10(int) Load 128(d)
SelectionMerge 132 None
Switch 129 132
case 1: 130
case 2: 131
128: 9(int) Load 127(d)
SelectionMerge 131 None
Switch 128 131
case 1: 129
case 2: 130
129: Label
132: 6(float) Load 73(x)
133: 6(float) Load 73(x)
134: 6(float) FMul 132 133
135: 6(float) Load 73(x)
136: 6(float) FMul 134 135
137: 6(float) Load 71(f)
138: 6(float) FAdd 137 136
Store 71(f) 138
Branch 131
130: Label
133: 7(float) Load 74(x)
134: 7(float) Load 74(x)
135: 7(float) FMul 133 134
136: 7(float) Load 74(x)
137: 7(float) FMul 135 136
138: 7(float) Load 72(f)
139: 7(float) FAdd 138 137
Store 72(f) 139
Branch 132
131: Label
141: 7(float) Load 74(x)
142: 7(float) Load 74(x)
143: 7(float) FMul 141 142
144: 7(float) Load 72(f)
145: 7(float) FAdd 144 143
Store 72(f) 145
Branch 132
132: Label
Branch 122
121: Label
149: 7(float) Load 74(x)
150: 7(float) ExtInst 1(GLSL.std.450) 15(Tan) 149
151: 7(float) Load 72(f)
152: 7(float) FAdd 151 150
Store 72(f) 152
Branch 122
122: Label
Store 154(i) 155
Branch 156
156: Label
159: 10(int) Load 154(i)
162: 161(bool) SLessThan 159 160
LoopMerge 157 None
BranchConditional 162 158 157
158: Label
163: 10(int) Load 61(c)
SelectionMerge 167 None
Switch 163 166
case 1: 164
case 2: 165
164: Label
168: 7(float) Load 74(x)
169: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 168
170: 7(float) Load 72(f)
171: 7(float) FAdd 170 169
Store 72(f) 171
Store 172(j) 173
Branch 174
140: 6(float) Load 73(x)
141: 6(float) Load 73(x)
142: 6(float) FMul 140 141
143: 6(float) Load 71(f)
144: 6(float) FAdd 143 142
Store 71(f) 144
Branch 131
131: Label
Branch 121
120: Label
148: 6(float) Load 73(x)
149: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 148
150: 6(float) Load 71(f)
151: 6(float) FAdd 150 149
Store 71(f) 151
Branch 121
121: Label
Store 153(i) 154
Branch 155
155: Label
158: 9(int) Load 153(i)
161: 160(bool) SLessThan 158 159
LoopMerge 156 None
BranchConditional 161 157 156
157: Label
162: 9(int) Load 60(c)
SelectionMerge 166 None
Switch 162 165
case 1: 163
case 2: 164
163: Label
167: 6(float) Load 73(x)
168: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 167
169: 6(float) Load 71(f)
170: 6(float) FAdd 169 168
Store 71(f) 170
Store 171(j) 172
Branch 173
173: Label
176: 9(int) Load 171(j)
178: 160(bool) SLessThan 176 177
LoopMerge 174 None
BranchConditional 178 175 174
175: Label
179: 6(float) Load 71(f)
180: 6(float) FAdd 179 47
Store 71(f) 180
181: 6(float) Load 71(f)
183: 160(bool) FOrdLessThan 181 182
SelectionMerge 185 None
BranchConditional 183 184 185
184: Label
Branch 174
185: Label
187: 9(int) Load 171(j)
188: 9(int) IAdd 187 63
Store 171(j) 188
Branch 173
174: Label
177: 10(int) Load 172(j)
179: 161(bool) SLessThan 177 178
LoopMerge 175 None
BranchConditional 179 176 175
176: Label
180: 7(float) Load 72(f)
181: 7(float) FAdd 180 48
Store 72(f) 181
182: 7(float) Load 72(f)
184: 161(bool) FOrdLessThan 182 183
SelectionMerge 186 None
BranchConditional 184 185 186
185: Label
Branch 175
186: Label
188: 10(int) Load 172(j)
189: 10(int) IAdd 188 64
Store 172(j) 189
Branch 174
175: Label
Branch 167
Branch 166
164: Label
190: 6(float) Load 73(x)
191: 6(float) ExtInst 1(GLSL.std.450) 14(Cos) 190
192: 6(float) Load 71(f)
193: 6(float) FAdd 192 191
Store 71(f) 193
Branch 166
165: Label
191: 7(float) Load 74(x)
192: 7(float) ExtInst 1(GLSL.std.450) 14(Cos) 191
193: 7(float) Load 72(f)
194: 7(float) FAdd 193 192
Store 72(f) 194
Branch 167
166: Label
197: 7(float) Load 74(x)
198: 7(float) ExtInst 1(GLSL.std.450) 15(Tan) 197
199: 7(float) Load 72(f)
200: 7(float) FAdd 199 198
Store 72(f) 200
Branch 167
167: Label
202: 7(float) Load 72(f)
204: 161(bool) FOrdLessThan 202 203
SelectionMerge 206 None
BranchConditional 204 205 206
205: Label
Branch 157
206: Label
208: 10(int) Load 154(i)
209: 10(int) IAdd 208 64
Store 154(i) 209
Branch 156
157: Label
210: 10(int) Load 61(c)
SelectionMerge 213 None
Switch 210 213
case 1: 211
case 2: 212
196: 6(float) Load 73(x)
197: 6(float) ExtInst 1(GLSL.std.450) 15(Tan) 196
198: 6(float) Load 71(f)
199: 6(float) FAdd 198 197
Store 71(f) 199
Branch 166
166: Label
201: 6(float) Load 71(f)
203: 160(bool) FOrdLessThan 201 202
SelectionMerge 205 None
BranchConditional 203 204 205
204: Label
Branch 156
205: Label
207: 9(int) Load 153(i)
208: 9(int) IAdd 207 63
Store 153(i) 208
Branch 155
156: Label
209: 9(int) Load 60(c)
SelectionMerge 212 None
Switch 209 212
case 1: 210
case 2: 211
210: Label
213: 6(float) Load 73(x)
214: 6(float) ExtInst 1(GLSL.std.450) 13(Sin) 213
215: 6(float) Load 71(f)
216: 6(float) FAdd 215 214
Store 71(f) 216
Branch 212
211: Label
214: 7(float) Load 74(x)
215: 7(float) ExtInst 1(GLSL.std.450) 13(Sin) 214
216: 7(float) Load 72(f)
217: 7(float) FAdd 216 215
Store 72(f) 217
Branch 213
212: Label
Branch 213
213: Label
223: 7(float) Load 72(f)
224: 10(int) Load 59(local)
225: 7(float) ConvertSToF 224
226: 7(float) FAdd 223 225
Store 222(color) 226
230: 8(fvec4) Load 228(v)
Store 229(param) 230
232: 8(fvec4) Load 228(v)
Store 231(param) 232
234: 10(int) Load 61(c)
Store 233(param) 234
235: 8(fvec4) FunctionCall 16(foo1(vf4;vf4;i1;) 229(param) 231(param) 233(param)
236: 7(float) CompositeExtract 235 1
237: 7(float) Load 222(color)
238: 7(float) FAdd 237 236
Store 222(color) 238
240: 8(fvec4) Load 228(v)
Store 239(param) 240
242: 8(fvec4) Load 228(v)
Store 241(param) 242
244: 10(int) Load 61(c)
Store 243(param) 244
245: 8(fvec4) FunctionCall 21(foo2(vf4;vf4;i1;) 239(param) 241(param) 243(param)
246: 7(float) CompositeExtract 245 2
247: 7(float) Load 222(color)
248: 7(float) FAdd 247 246
Store 222(color) 248
249: 10(int) Load 61(c)
SelectionMerge 252 None
Switch 249 251
case 0: 250
Branch 212
212: Label
222: 6(float) Load 71(f)
223: 9(int) Load 58(local)
224: 6(float) ConvertSToF 223
225: 6(float) FAdd 222 224
Store 221(color) 225
229: 7(fvec4) Load 227(v)
Store 228(param) 229
231: 7(fvec4) Load 227(v)
Store 230(param) 231
233: 9(int) Load 60(c)
Store 232(param) 233
234: 7(fvec4) FunctionCall 15(foo1(vf4;vf4;i1;) 228(param) 230(param) 232(param)
235: 6(float) CompositeExtract 234 1
236: 6(float) Load 221(color)
237: 6(float) FAdd 236 235
Store 221(color) 237
239: 7(fvec4) Load 227(v)
Store 238(param) 239
241: 7(fvec4) Load 227(v)
Store 240(param) 241
243: 9(int) Load 60(c)
Store 242(param) 243
244: 7(fvec4) FunctionCall 20(foo2(vf4;vf4;i1;) 238(param) 240(param) 242(param)
245: 6(float) CompositeExtract 244 2
246: 6(float) Load 221(color)
247: 6(float) FAdd 246 245
Store 221(color) 247
248: 9(int) Load 60(c)
SelectionMerge 251 None
Switch 248 250
case 0: 249
249: Label
Branch 251
250: Label
Branch 252
251: Label
Branch 252
252: Label
256: 10(int) Load 61(c)
SelectionMerge 258 None
Switch 256 257
257: Label
Branch 258
258: Label
Branch 6
6: Label
Branch 251
251: Label
255: 9(int) Load 60(c)
SelectionMerge 257 None
Switch 255 256
256: Label
Branch 257
257: Label
Return
FunctionEnd
16(foo1(vf4;vf4;i1;): 8(fvec4) Function None 12
13(v1): 9(ptr) FunctionParameter
14(v2): 9(ptr) FunctionParameter
15(i1): 11(ptr) FunctionParameter
17: Label
23: 10(int) Load 15(i1)
SelectionMerge 27 None
Switch 23 27
case 0: 24
case 2: 25
case 1: 25
case 3: 26
15(foo1(vf4;vf4;i1;): 7(fvec4) Function None 11
12(v1): 8(ptr) FunctionParameter
13(v2): 8(ptr) FunctionParameter
14(i1): 10(ptr) FunctionParameter
16: Label
22: 9(int) Load 14(i1)
SelectionMerge 26 None
Switch 22 26
case 0: 23
case 2: 24
case 1: 24
case 3: 25
23: Label
27: 7(fvec4) Load 12(v1)
ReturnValue 27
24: Label
28: 8(fvec4) Load 13(v1)
ReturnValue 28
29: 7(fvec4) Load 13(v2)
ReturnValue 29
25: Label
30: 8(fvec4) Load 14(v2)
ReturnValue 30
26: Label
32: 8(fvec4) Load 13(v1)
33: 8(fvec4) Load 14(v2)
34: 8(fvec4) FMul 32 33
ReturnValue 34
27: Label
ReturnValue 38
31: 7(fvec4) Load 12(v1)
32: 7(fvec4) Load 13(v2)
33: 7(fvec4) FMul 31 32
ReturnValue 33
26: Label
ReturnValue 37
FunctionEnd
21(foo2(vf4;vf4;i1;): 8(fvec4) Function None 12
18(v1): 9(ptr) FunctionParameter
19(v2): 9(ptr) FunctionParameter
20(i1): 11(ptr) FunctionParameter
22: Label
40: 10(int) Load 20(i1)
SelectionMerge 45 None
Switch 40 45
case 0: 41
case 2: 42
case 1: 43
case 3: 44
20(foo2(vf4;vf4;i1;): 7(fvec4) Function None 11
17(v1): 8(ptr) FunctionParameter
18(v2): 8(ptr) FunctionParameter
19(i1): 10(ptr) FunctionParameter
21: Label
39: 9(int) Load 19(i1)
SelectionMerge 44 None
Switch 39 44
case 0: 40
case 2: 41
case 1: 42
case 3: 43
40: Label
45: 7(fvec4) Load 17(v1)
ReturnValue 45
41: Label
46: 8(fvec4) Load 18(v1)
ReturnValue 46
ReturnValue 48
42: Label
ReturnValue 49
50: 7(fvec4) Load 18(v2)
ReturnValue 50
43: Label
51: 8(fvec4) Load 19(v2)
ReturnValue 51
44: Label
53: 8(fvec4) Load 18(v1)
54: 8(fvec4) Load 19(v2)
55: 8(fvec4) FMul 53 54
ReturnValue 55
45: Label
ReturnValue 38
52: 7(fvec4) Load 17(v1)
53: 7(fvec4) Load 18(v2)
54: 7(fvec4) FMul 52 53
ReturnValue 54
44: Label
ReturnValue 37
FunctionEnd