3 # Copyright 2019 Google LLC
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # A test for a bug found by GraphicsFuzz.
20 # Short description: Shader with loop controlled by struct
22 # The test passes because 'sums[0]' ends up being 0, so that the colour that is written is guaranteed to be red
24 # Optimized using spirv-opt with the following arguments:
25 # '--private-to-local'
26 # '--eliminate-dead-branches'
28 # '--reduce-load-size'
29 # '--eliminate-dead-code-aggressive'
31 # '--eliminate-dead-code-aggressive'
33 # '--convert-local-access-chains'
34 # '--eliminate-dead-branches'
36 # '--eliminate-local-single-store'
38 # '--eliminate-dead-branches'
40 # '--eliminate-local-single-store'
41 # '--eliminate-dead-inserts'
42 # '--eliminate-local-multi-store'
43 # '--copy-propagate-arrays'
44 # '--combine-access-chains'
45 # '--redundancy-elimination'
47 # '--eliminate-local-multi-store'
48 # '--eliminate-dead-code-aggressive'
49 # spirv-opt commit hash: f1e5cd73f658abcc23ee96d78f2dc27c4b7028c1
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
57 # precision highp float;
64 # layout(set = 0, binding = 0) uniform buf0 {
65 # vec2 injectionSwitch;
67 # layout(location = 0) out vec4 _GLF_color;
73 # S ll = S(0, bvec3(true));
74 # ll.f0 != int((injectionSwitch.y));
80 # int overall_region = 0;
81 # _GLF_color = vec4(1.0, vec2(sums[overall_region]), 1.0);
83 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
86 ; Generator: Khronos Glslang Reference Front End; 8
90 %1 = OpExtInstImport "GLSL.std.450"
91 OpMemoryModel Logical GLSL450
92 OpEntryPoint Fragment %4 "main" %50
93 OpExecutionMode %4 OriginUpperLeft
97 OpMemberName %9 0 "f0"
98 OpMemberName %9 1 "f1"
101 OpMemberName %26 0 "injectionSwitch"
104 OpName %50 "_GLF_color"
105 OpMemberDecorate %9 0 RelaxedPrecision
106 OpDecorate %23 RelaxedPrecision
107 OpMemberDecorate %26 0 Offset 0
109 OpDecorate %28 DescriptorSet 0
110 OpDecorate %28 Binding 0
111 OpDecorate %44 RelaxedPrecision
112 OpDecorate %46 RelaxedPrecision
113 OpDecorate %50 Location 0
114 OpDecorate %59 RelaxedPrecision
115 OpDecorate %60 RelaxedPrecision
117 %3 = OpTypeFunction %2
120 %8 = OpTypeVector %7 3
121 %9 = OpTypeStruct %6 %8
122 %10 = OpTypePointer Function %9
123 %12 = OpConstant %6 0
124 %13 = OpConstantTrue %7
125 %14 = OpConstantComposite %8 %13 %13 %13
126 %15 = OpConstantComposite %9 %12 %14
128 %25 = OpTypeVector %24 2
129 %26 = OpTypeStruct %25
130 %27 = OpTypePointer Uniform %26
131 %28 = OpVariable %27 Uniform
133 %30 = OpConstant %29 1
134 %31 = OpTypePointer Uniform %24
135 %36 = OpConstant %29 9
136 %37 = OpTypeArray %24 %36
137 %38 = OpTypePointer Function %37
138 %40 = OpConstant %24 0
139 %41 = OpTypePointer Function %24
140 %45 = OpConstant %6 1
141 %48 = OpTypeVector %24 4
142 %49 = OpTypePointer Output %48
143 %50 = OpVariable %49 Output
144 %51 = OpConstant %24 1
145 %4 = OpFunction %2 None %3
147 %11 = OpVariable %10 Function
148 %39 = OpVariable %38 Function
152 OpLoopMerge %18 %19 None
156 %23 = OpCompositeExtract %6 %59 0
157 %32 = OpAccessChain %31 %28 %12 %30
159 %34 = OpConvertFToS %6 %33
160 %35 = OpINotEqual %7 %23 %34
161 OpBranchConditional %35 %17 %18
163 %42 = OpAccessChain %41 %39 %12
168 %44 = OpCompositeExtract %6 %60 0
169 %46 = OpIAdd %6 %44 %45
171 %62 = OpCompositeInsert %9 %46 %61 0
175 %53 = OpAccessChain %41 %39 %12
177 %55 = OpCompositeConstruct %25 %54 %54
178 %56 = OpCompositeExtract %24 %55 0
179 %57 = OpCompositeExtract %24 %55 1
180 %58 = OpCompositeConstruct %48 %51 %56 %57 %51
186 # uniforms for variant
189 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
193 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
195 PIPELINE graphics variant_pipeline
196 ATTACH variant_vertex_shader
197 ATTACH variant_fragment_shader
198 FRAMEBUFFER_SIZE 256 256
199 BIND BUFFER variant_framebuffer AS color LOCATION 0
200 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
202 CLEAR_COLOR variant_pipeline 0 0 0 255
204 CLEAR variant_pipeline
205 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
207 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255