3 # Copyright 2022 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 LLVM code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-dead-branches'
27 # '--redundancy-elimination'
28 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
32 SHADER vertex variant_vertex_shader PASSTHROUGH
34 # variant_fragment_shader is derived from the following GLSL:
36 # #define _int_0 _GLF_uniform_int_values[0]
37 # #define _int_1 _GLF_uniform_int_values[1]
38 # #define _int_2 _GLF_uniform_int_values[2]
40 # precision highp float;
41 # precision highp int;
43 # // Contents of _GLF_uniform_int_values: [0, 1, 2]
44 # layout(set = 0, binding = 0) uniform buf0
46 # int _GLF_uniform_int_values[3];
49 # layout(location = 0) out vec4 _GLF_color;
51 # const int _GLF_global_loop_bound = 10;
52 # int _GLF_global_loop_count = 0;
65 # while(_GLF_global_loop_count < _GLF_global_loop_bound)
67 # _GLF_global_loop_count++;
69 # // Iterates until the global loop count is reached.
70 # while(a != 1 && _GLF_global_loop_count < _GLF_global_loop_bound)
72 # _GLF_global_loop_count++;
75 # a = S(_int_1, 2).data1;
82 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
86 # _GLF_color = vec4(_int_0);
89 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
92 ; Generator: Khronos Glslang Reference Front End; 10
96 %1 = OpExtInstImport "GLSL.std.450"
97 OpMemoryModel Logical GLSL450
98 OpEntryPoint Fragment %4 "main" %60
99 OpExecutionMode %4 OriginUpperLeft
102 OpName %8 "_GLF_global_loop_count"
105 OpMemberName %15 0 "_GLF_uniform_int_values"
108 OpMemberName %48 0 "data0"
109 OpMemberName %48 1 "data1"
110 OpName %60 "_GLF_color"
111 OpDecorate %14 ArrayStride 16
112 OpMemberDecorate %15 0 Offset 0
114 OpDecorate %17 DescriptorSet 0
115 OpDecorate %17 Binding 0
116 OpDecorate %60 Location 0
118 %3 = OpTypeFunction %2
120 %7 = OpTypePointer Private %6
121 %8 = OpVariable %7 Private
123 %10 = OpTypePointer Function %6
125 %13 = OpConstant %12 3
126 %14 = OpTypeArray %6 %13
127 %15 = OpTypeStruct %14
128 %16 = OpTypePointer Uniform %15
129 %17 = OpVariable %16 Uniform
130 %18 = OpTypePointer Uniform %6
131 %27 = OpConstant %6 10
133 %31 = OpConstant %6 1
134 %47 = OpConstant %6 2
135 %48 = OpTypeStruct %6 %6
137 %58 = OpTypeVector %57 4
138 %59 = OpTypePointer Output %58
139 %60 = OpVariable %59 Output
140 %4 = OpFunction %2 None %3
142 %11 = OpVariable %10 Function
144 %19 = OpAccessChain %18 %17 %9 %9
149 OpLoopMerge %23 %24 None
153 %29 = OpSLessThan %28 %26 %27
154 OpBranchConditional %29 %22 %23
157 %32 = OpIAdd %6 %30 %31
161 OpLoopMerge %35 %36 None
165 %39 = OpINotEqual %28 %38 %31
167 %41 = OpSLessThan %28 %40 %27
168 %42 = OpLogicalAnd %28 %39 %41
169 OpBranchConditional %42 %34 %35
172 %44 = OpIAdd %6 %43 %31
174 %45 = OpAccessChain %18 %17 %9 %31
176 %49 = OpCompositeConstruct %48 %46 %47
177 %50 = OpCompositeExtract %6 %49 1
188 %52 = OpAccessChain %18 %17 %9 %47
190 %54 = OpIEqual %28 %51 %53
191 OpSelectionMerge %56 None
192 OpBranchConditional %54 %55 %74
194 %61 = OpAccessChain %18 %17 %9 %31
196 %63 = OpConvertSToF %57 %62
197 %66 = OpConvertSToF %57 %20
198 %73 = OpCompositeConstruct %58 %63 %66 %66 %63
202 %77 = OpConvertSToF %57 %20
203 %78 = OpCompositeConstruct %58 %77 %77 %77 %77
211 # uniforms for variant
213 # _GLF_uniform_int_values
214 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
218 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
220 PIPELINE graphics variant_pipeline
221 ATTACH variant_vertex_shader
222 ATTACH variant_fragment_shader
223 FRAMEBUFFER_SIZE 32 32
224 BIND BUFFER variant_framebuffer AS color LOCATION 0
225 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
227 CLEAR_COLOR variant_pipeline 0 0 0 255
229 CLEAR variant_pipeline
230 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
232 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255