3 # Copyright 2021 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-local-multi-store'
26 # '--eliminate-dead-branches'
28 # '--simplify-instructions'
29 # '--eliminate-dead-branches'
30 # '--reduce-load-size'
31 # '--convert-local-access-chains'
32 # '--eliminate-dead-branches'
34 # '--simplify-instructions'
38 # '--eliminate-dead-code-aggressive'
39 # '--redundancy-elimination'
40 # '--eliminate-local-multi-store'
41 # '--eliminate-dead-branches'
42 # '--eliminate-local-single-store'
43 # '--private-to-local'
44 # '--eliminate-dead-branches'
45 # '--eliminate-dead-branches'
47 # '--eliminate-dead-branches'
49 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
57 # #define _int_5 _GLF_uniform_int_values[0]
58 # #define _int_4 _GLF_uniform_int_values[1]
59 # #define _int_1 _GLF_uniform_int_values[2]
60 # #define _int_0 _GLF_uniform_int_values[3]
62 # precision highp float;
63 # precision highp int;
65 # // Contents of _GLF_uniform_int_values: [5, 4, 1, 0]
66 # layout(set = 0, binding = 0) uniform buf0
68 # int _GLF_uniform_int_values[4];
76 # layout(location = 0) out vec4 _GLF_color;
82 # for(S s = S(0); s.i < _int_5; s.i++)
93 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
97 # _GLF_color = vec4(_int_0);
100 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
103 ; Generator: Khronos Glslang Reference Front End; 10
107 %1 = OpExtInstImport "GLSL.std.450"
108 OpMemoryModel Logical GLSL450
109 OpEntryPoint Fragment %4 "main" %56
110 OpExecutionMode %4 OriginUpperLeft
114 OpMemberName %12 0 "_GLF_uniform_int_values"
117 OpMemberName %20 0 "i"
119 OpName %56 "_GLF_color"
120 OpDecorate %11 ArrayStride 16
121 OpMemberDecorate %12 0 Offset 0
123 OpDecorate %14 DescriptorSet 0
124 OpDecorate %14 Binding 0
125 OpDecorate %56 Location 0
127 %3 = OpTypeFunction %2
130 %10 = OpConstant %9 4
131 %11 = OpTypeArray %6 %10
132 %12 = OpTypeStruct %11
133 %13 = OpTypePointer Uniform %12
134 %14 = OpVariable %13 Uniform
135 %15 = OpConstant %6 0
136 %16 = OpConstant %6 2
137 %17 = OpTypePointer Uniform %6
138 %20 = OpTypeStruct %6
139 %21 = OpTypePointer Function %20
140 %23 = OpConstantComposite %20 %15
142 %36 = OpConstant %6 3
143 %42 = OpConstant %6 1
145 %54 = OpTypeVector %53 4
146 %55 = OpTypePointer Output %54
147 %56 = OpVariable %55 Output
148 %4 = OpFunction %2 None %3
150 %22 = OpVariable %21 Function
151 %18 = OpAccessChain %17 %14 %15 %16
156 %81 = OpPhi %20 %23 %5 %80 %27
157 %75 = OpPhi %6 %19 %5 %43 %27
158 %30 = OpCompositeExtract %6 %81 0
159 %31 = OpAccessChain %17 %14 %15 %15
161 %34 = OpSLessThan %33 %30 %32
162 OpLoopMerge %26 %27 None
163 OpBranchConditional %34 %25 %26
165 %37 = OpSGreaterThan %33 %75 %36
166 OpSelectionMerge %39 None
167 OpBranchConditional %37 %38 %39
171 %43 = OpIAdd %6 %75 %42
174 %45 = OpCompositeExtract %6 %81 0
175 %46 = OpIAdd %6 %45 %42
176 %80 = OpCompositeInsert %20 %46 %81 0
180 %48 = OpAccessChain %17 %14 %15 %42
182 %50 = OpIEqual %33 %75 %49
183 OpSelectionMerge %52 None
184 OpBranchConditional %50 %51 %70
186 %59 = OpConvertSToF %53 %19
187 %60 = OpAccessChain %17 %14 %15 %36
189 %62 = OpConvertSToF %53 %61
190 %69 = OpCompositeConstruct %54 %59 %62 %62 %59
194 %71 = OpAccessChain %17 %14 %15 %36
196 %73 = OpConvertSToF %53 %72
197 %74 = OpCompositeConstruct %54 %73 %73 %73 %73
205 # uniforms for variant
207 # _GLF_uniform_int_values
208 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
212 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
214 PIPELINE graphics variant_pipeline
215 ATTACH variant_vertex_shader
216 ATTACH variant_fragment_shader
217 FRAMEBUFFER_SIZE 256 256
218 BIND BUFFER variant_framebuffer AS color LOCATION 0
219 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
221 CLEAR_COLOR variant_pipeline 0 0 0 255
223 CLEAR variant_pipeline
224 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
226 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255