3 # Copyright 2020 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 coverage-gap found by the GraphicsFuzz project.
20 # Short description: A fragment shader that covers specific NIR code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-local-single-block'
26 # '--eliminate-local-single-store'
27 # '--eliminate-local-multi-store'
28 # '--eliminate-dead-branches'
29 # '--scalar-replacement=100'
30 # '--eliminate-local-multi-store'
31 # '--inline-entry-points-exhaustive'
32 # '--copy-propagate-arrays'
33 # '--inline-entry-points-exhaustive'
34 # '--eliminate-dead-code-aggressive'
35 # '--redundancy-elimination'
37 # '--eliminate-dead-branches'
39 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
43 SHADER vertex variant_vertex_shader PASSTHROUGH
45 # variant_fragment_shader is derived from the following GLSL:
47 # #define _int_0 _GLF_uniform_int_values[0]
48 # #define _int_1 _GLF_uniform_int_values[1]
49 # #define _int_12 _GLF_uniform_int_values[2]
50 # #define _int_5 _GLF_uniform_int_values[3]
52 # precision highp int;
53 # precision highp float;
55 # // Contents of _GLF_uniform_int_values: [0, 1, 12, 5]
56 # layout(set = 0, binding = 0) uniform buf0
58 # int _GLF_uniform_int_values[4];
60 # layout(location = 0) out vec4 _GLF_color;
62 # const int _GLF_global_loop_bound = 10;
63 # int _GLF_global_loop_count = 0;
69 # for(int i = _int_0; i < _int_5; i ++)
71 # _GLF_global_loop_count ++;
82 # // _GLF_global_loop_count = 0, 1, 6, 7, 12
83 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
85 # _GLF_global_loop_count++;
89 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
92 # _GLF_global_loop_count ++;
96 # if(_GLF_global_loop_count == _int_12)
98 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
102 # _GLF_color = vec4(_int_0);
105 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
108 ; Generator: Khronos Glslang Reference Front End; 10
112 %1 = OpExtInstImport "GLSL.std.450"
113 OpMemoryModel Logical GLSL450
114 OpEntryPoint Fragment %4 "main" %79
115 OpExecutionMode %4 OriginUpperLeft
119 OpName %10 "_GLF_global_loop_count"
121 OpMemberName %17 0 "_GLF_uniform_int_values"
123 OpName %79 "_GLF_color"
124 OpDecorate %16 ArrayStride 16
125 OpMemberDecorate %17 0 Offset 0
127 OpDecorate %19 DescriptorSet 0
128 OpDecorate %19 Binding 0
129 OpDecorate %79 Location 0
131 %3 = OpTypeFunction %2
133 %9 = OpTypePointer Private %8
134 %10 = OpVariable %9 Private
135 %11 = OpConstant %8 0
137 %15 = OpConstant %14 4
138 %16 = OpTypeArray %8 %15
139 %17 = OpTypeStruct %16
140 %18 = OpTypePointer Uniform %17
141 %19 = OpVariable %18 Uniform
142 %20 = OpConstant %8 1
143 %21 = OpTypePointer Uniform %8
144 %33 = OpConstant %8 3
146 %55 = OpConstant %8 10
147 %70 = OpConstant %8 2
149 %77 = OpTypeVector %76 4
150 %78 = OpTypePointer Output %77
151 %79 = OpVariable %78 Output
152 %4 = OpFunction %2 None %3
158 %56 = OpSLessThan %36 %54 %55
159 OpLoopMerge %51 %50 None
160 OpBranchConditional %56 %50 %51
163 %58 = OpIAdd %8 %57 %20
165 %59 = OpFunctionCall %2 %6
171 %66 = OpSLessThan %36 %65 %55
172 OpLoopMerge %62 %61 None
173 OpBranchConditional %66 %61 %62
176 %68 = OpIAdd %8 %67 %20
181 %71 = OpAccessChain %21 %19 %11 %70
183 %73 = OpIEqual %36 %69 %72
184 OpSelectionMerge %75 None
185 OpBranchConditional %73 %74 %93
187 %80 = OpAccessChain %21 %19 %11 %20
189 %82 = OpConvertSToF %76 %81
190 %83 = OpAccessChain %21 %19 %11 %11
192 %85 = OpConvertSToF %76 %84
193 %92 = OpCompositeConstruct %77 %82 %85 %85 %82
197 %94 = OpAccessChain %21 %19 %11 %11
199 %96 = OpConvertSToF %76 %95
200 %97 = OpCompositeConstruct %77 %96 %96 %96 %96
206 %6 = OpFunction %2 None %3
208 %22 = OpAccessChain %21 %19 %11 %20
210 %25 = OpAccessChain %21 %19 %11 %11
214 %98 = OpPhi %8 %26 %7 %41 %28
215 %34 = OpAccessChain %21 %19 %11 %33
217 %37 = OpSLessThan %36 %98 %35
218 OpLoopMerge %29 %28 None
219 OpBranchConditional %37 %28 %29
222 %39 = OpIAdd %8 %38 %20
224 %41 = OpIAdd %8 %98 %20
227 %45 = OpSLessThan %36 %23 %23
228 OpSelectionMerge %47 None
229 OpBranchConditional %45 %46 %47
237 # uniforms for variant
239 # _GLF_uniform_int_values
240 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
244 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
246 PIPELINE graphics variant_pipeline
247 ATTACH variant_vertex_shader
248 ATTACH variant_fragment_shader
249 FRAMEBUFFER_SIZE 256 256
250 BIND BUFFER variant_framebuffer AS color LOCATION 0
251 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
253 CLEAR_COLOR variant_pipeline 0 0 0 255
255 CLEAR variant_pipeline
256 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
258 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255