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 # '--eliminate-dead-code-aggressive'
28 # '--convert-local-access-chains'
29 # '--eliminate-dead-branches'
31 # '--eliminate-local-multi-store'
32 # '--reduce-load-size'
33 # '--convert-local-access-chains'
34 # '--eliminate-local-multi-store'
35 # '--combine-access-chains'
37 # '--scalar-replacement=100'
38 # '--eliminate-dead-branches'
40 # '--copy-propagate-arrays'
41 # '--eliminate-dead-branches'
42 # '--scalar-replacement=100'
43 # '--eliminate-dead-branches'
46 # '--convert-local-access-chains'
47 # '--combine-access-chains'
48 # '--redundancy-elimination'
49 # '--inline-entry-points-exhaustive'
50 # '--combine-access-chains'
51 # '--eliminate-dead-branches'
52 # '--eliminate-local-multi-store'
53 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
57 SHADER vertex variant_vertex_shader PASSTHROUGH
59 # variant_fragment_shader is derived from the following GLSL:
61 # #define _int_1 _GLF_uniform_int_values[0]
62 # #define _int_0 _GLF_uniform_int_values[1]
64 # precision highp int;
65 # precision highp float;
67 # // Contents of _GLF_uniform_int_values: [1, 0]
68 # layout(set = 0, binding = 0) uniform buf0
70 # int _GLF_uniform_int_values[2];
73 # layout(location = 0) out vec4 _GLF_color;
83 # ivec2 a = ivec2(_int_1);
84 # // b = 1 & ((~0 | ~0) >> 1) = 1 & (~0 >> 1) = 1 & ~0 = 1
85 # int b = _int_1 & (((a.x != _int_1 ? 0 : ~ 0) | (a.x != _int_1 ? 0 : ~ 0)) >> _int_1);
90 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
94 # _GLF_color = vec4(_int_0);
102 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
105 ; Generator: Khronos Glslang Reference Front End; 10
109 %1 = OpExtInstImport "GLSL.std.450"
110 OpMemoryModel Logical GLSL450
111 OpEntryPoint Fragment %4 "main" %65
112 OpExecutionMode %4 OriginUpperLeft
115 OpName %10 "func(i1;"
118 OpMemberName %16 0 "_GLF_uniform_int_values"
122 OpName %65 "_GLF_color"
124 OpDecorate %15 ArrayStride 16
125 OpMemberDecorate %16 0 Offset 0
127 OpDecorate %18 DescriptorSet 0
128 OpDecorate %18 Binding 0
129 OpDecorate %65 Location 0
131 %3 = OpTypeFunction %2
133 %7 = OpTypePointer Function %6
134 %8 = OpTypeFunction %2 %7
136 %14 = OpConstant %13 2
137 %15 = OpTypeArray %6 %14
138 %16 = OpTypeStruct %15
139 %17 = OpTypePointer Uniform %16
140 %18 = OpVariable %17 Uniform
141 %19 = OpConstant %6 0
142 %20 = OpTypePointer Uniform %6
144 %28 = OpTypeVector %6 2
145 %29 = OpTypePointer Function %28
146 %37 = OpConstant %13 0
147 %43 = OpConstant %6 -1
149 %63 = OpTypeVector %62 4
150 %64 = OpTypePointer Output %63
151 %65 = OpVariable %64 Output
152 %69 = OpConstant %6 1
153 %4 = OpFunction %2 None %3
155 %85 = OpVariable %7 Function
156 %86 = OpAccessChain %20 %18 %19 %19
159 %88 = OpFunctionCall %2 %10 %85
162 %10 = OpFunction %2 None %8
163 %9 = OpFunctionParameter %7
165 %30 = OpVariable %29 Function
166 %34 = OpVariable %7 Function
168 %21 = OpAccessChain %20 %18 %19 %19
170 %24 = OpSGreaterThan %23 %12 %22
171 OpSelectionMerge %26 None
172 OpBranchConditional %24 %25 %26
176 %33 = OpCompositeConstruct %28 %22 %22
178 %38 = OpAccessChain %7 %30 %37
180 %39 = OpCompositeExtract %6 %89 0
181 %42 = OpINotEqual %23 %39 %22
182 %44 = OpSelect %6 %42 %19 %43
184 %46 = OpCompositeExtract %6 %90 0
185 %49 = OpINotEqual %23 %46 %22
186 %50 = OpSelect %6 %49 %19 %43
187 %51 = OpBitwiseOr %6 %44 %50
188 %54 = OpShiftRightArithmetic %6 %51 %22
189 %55 = OpBitwiseAnd %6 %22 %54
191 %59 = OpIEqual %23 %55 %22
192 OpSelectionMerge %61 None
193 OpBranchConditional %59 %60 %80
195 %68 = OpConvertSToF %62 %22
196 %70 = OpAccessChain %20 %18 %19 %69
198 %72 = OpConvertSToF %62 %71
199 %79 = OpCompositeConstruct %63 %68 %72 %72 %68
203 %81 = OpAccessChain %20 %18 %19 %69
205 %83 = OpConvertSToF %62 %82
206 %84 = OpCompositeConstruct %63 %83 %83 %83 %83
214 # uniforms for variant
216 # _GLF_uniform_int_values
217 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
221 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
223 PIPELINE graphics variant_pipeline
224 ATTACH variant_vertex_shader
225 ATTACH variant_fragment_shader
226 FRAMEBUFFER_SIZE 32 32
227 BIND BUFFER variant_framebuffer AS color LOCATION 0
228 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
230 CLEAR_COLOR variant_pipeline 0 0 0 255
232 CLEAR variant_pipeline
233 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
235 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255