/
control-flow-switch.amber
216 lines (210 loc) · 6.43 KB
/
control-flow-switch.amber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A test for a bug found by GraphicsFuzz.
# A fragment shader with somewhat complex control flow and a switch.
# Derived from the following GLSL fragment shader.
# We check that all pixels are red. The test passes because the final
# statement writes red to _GLF_color and there are no discard statments.
# #version 310 es
#
# precision highp float;
# precision highp int;
#
# layout(set = 0, binding = 0) uniform buf0 {
# vec2 injectionSwitch;
# };
# layout(location=0) out vec4 _GLF_color;
#
# struct S {
# bool ok;
# };
#
# bool g()
# {
# for(
# int i = 0;
# i < 1;
# i++
# )
# {
# switch(int(injectionSwitch.x))
# {
# case 9:
# S a = S(bool(injectionSwitch.x));
# S b = a;
# case 42:
# if(b.ok)
# {
# return true;
# }
# default:
# break;
# }
# }
# return true;
# }
# vec3 f()
# {
# {
# S a = S(bool(injectionSwitch.x));
# if(a.ok)
# {
# return vec3(0.0);
# }
# if(g())
# {
# return vec3(1.0);
# }
# }
# return vec3(1.0);
# }
# void main()
# {
# _GLF_color = vec4(f(), 1.0);
# // always true at runtime
# if (injectionSwitch.x == 0.0) {
# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
# }
# }
[vertex shader passthrough]
[fragment shader spirv]
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 195
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %_GLF_color
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
OpName %buf0 "buf0"
OpMemberName %buf0 0 "injectionSwitch"
OpName %_ ""
OpName %_GLF_color "_GLF_color"
OpMemberDecorate %buf0 0 Offset 0
OpDecorate %buf0 Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
OpDecorate %_GLF_color Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%bool = OpTypeBool
%float = OpTypeFloat 32
%v3float = OpTypeVector %float 3
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%v2float = OpTypeVector %float 2
%buf0 = OpTypeStruct %v2float
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%_ = OpVariable %_ptr_Uniform_buf0 Uniform
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%float_0 = OpConstant %float 0
%true = OpConstantTrue %bool
%73 = OpConstantComposite %v3float %float_0 %float_0 %float_0
%float_1 = OpConstant %float 1
%79 = OpConstantComposite %v3float %float_1 %float_1 %float_1
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_GLF_color = OpVariable %_ptr_Output_v4float Output
%96 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%false = OpConstantFalse %bool
%182 = OpUndef %bool
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %119
%119 = OpLabel
OpLoopMerge %120 %121 None
OpBranch %122
%122 = OpLabel
%123 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %uint_0
%124 = OpLoad %float %123
%125 = OpFOrdNotEqual %bool %124 %float_0
OpSelectionMerge %129 None
OpBranchConditional %125 %130 %129
%130 = OpLabel
OpBranch %120
%129 = OpLabel
OpBranch %141
%141 = OpLabel
OpLoopMerge %142 %143 None
OpBranch %145
%145 = OpLabel
%179 = OpPhi %bool %182 %141 %194 %156
%177 = OpPhi %int %int_0 %141 %169 %156
%150 = OpSLessThan %bool %177 %int_1
OpLoopMerge %146 %156 None
OpBranchConditional %150 %151 %146
%151 = OpLabel
%154 = OpConvertFToS %int %124
OpSelectionMerge %156 None
OpSwitch %154 %156 9 %157 42 %158
%156 = OpLabel
%194 = OpPhi %bool %179 %151 %178 %166
%169 = OpIAdd %int %177 %int_1
OpBranch %145
%157 = OpLabel
OpBranch %158
%158 = OpLabel
%178 = OpPhi %bool %179 %151 %125 %157
OpSelectionMerge %166 None
OpBranchConditional %178 %167 %166
%167 = OpLabel
OpBranch %146
%166 = OpLabel
OpBranch %156
%146 = OpLabel
%187 = OpPhi %bool %182 %145 %true %167
%183 = OpPhi %bool %false %145 %true %167
OpSelectionMerge %171 None
OpBranchConditional %183 %142 %171
%171 = OpLabel
OpBranch %142
%143 = OpLabel
OpBranch %141
%142 = OpLabel
%186 = OpPhi %bool %187 %146 %true %171
OpSelectionMerge %132 None
OpBranchConditional %186 %133 %132
%133 = OpLabel
OpBranch %120
%132 = OpLabel
OpBranch %120
%121 = OpLabel
OpBranch %119
%120 = OpLabel
%193 = OpPhi %v3float %73 %130 %79 %133 %79 %132
%87 = OpCompositeExtract %float %193 0
%88 = OpCompositeExtract %float %193 1
%89 = OpCompositeExtract %float %193 2
%90 = OpCompositeConstruct %v4float %87 %88 %89 %float_1
OpStore %_GLF_color %90
%93 = OpFOrdEqual %bool %124 %float_0
OpSelectionMerge %95 None
OpBranchConditional %93 %94 %95
%94 = OpLabel
OpStore %_GLF_color %96
OpBranch %95
%95 = OpLabel
OpReturn
OpFunctionEnd
[test]
uniform ubo 0:0 vec2 0 0.0 1.0
draw rect -1 -1 2 2
probe all rgba 1 0 0 1