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'
26 # '--inline-entry-points-exhaustive'
27 # '--reduce-load-size'
28 # '--eliminate-local-single-block'
30 # '--eliminate-dead-branches'
31 # '--simplify-instructions'
32 # '--inline-entry-points-exhaustive'
34 # '--redundancy-elimination'
35 # '--eliminate-local-single-block'
37 # '--eliminate-dead-branches'
41 # '--combine-access-chains'
42 # '--simplify-instructions'
43 # '--eliminate-dead-code-aggressive'
44 # '--inline-entry-points-exhaustive'
45 # '--eliminate-dead-inserts'
46 # '--eliminate-local-single-store'
48 # '--reduce-load-size'
49 # '--eliminate-dead-branches'
52 # '--combine-access-chains'
53 # '--copy-propagate-arrays'
54 # '--eliminate-dead-branches'
56 # '--inline-entry-points-exhaustive'
57 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
61 SHADER vertex variant_vertex_shader PASSTHROUGH
63 # variant_fragment_shader is derived from the following GLSL:
65 # #define _int_1 _GLF_uniform_int_values[0]
66 # #define _int_0 _GLF_uniform_int_values[1]
67 # #define _float_1_0 _GLF_uniform_float_values[0]
68 # #define _float_0_0 _GLF_uniform_float_values[1]
70 # precision highp float;
71 # precision highp int;
73 # // Contents of _GLF_uniform_float_values: [1.0, 0.0]
74 # layout(set = 0, binding = 0) uniform buf0
76 # float _GLF_uniform_float_values[2];
79 # // Contents of _GLF_uniform_int_values: [1, 0]
80 # layout(set = 0, binding = 1) uniform buf1
82 # int _GLF_uniform_int_values[2];
85 # layout(location = 0) out vec4 _GLF_color;
91 # int b = int(max(ivec2(1, true ? a : _int_1), ivec2(1, true ? a : _int_1)));
92 # // Returns vec3(1, 1, 1).
93 # return vec3(max(_float_1_0, b == _int_1 ? _float_0_0 : _float_1_0));
99 # if(func() == vec3(_int_1))
101 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
105 # _GLF_color = vec4(_int_0);
108 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
111 ; Generator: Khronos Glslang Reference Front End; 10
115 %1 = OpExtInstImport "GLSL.std.450"
116 OpMemoryModel Logical GLSL450
117 OpEntryPoint Fragment %4 "main" %86
118 OpExecutionMode %4 OriginUpperLeft
122 OpMemberName %17 0 "_GLF_uniform_int_values"
125 OpMemberName %50 0 "_GLF_uniform_float_values"
127 OpName %86 "_GLF_color"
128 OpDecorate %16 ArrayStride 16
129 OpMemberDecorate %17 0 Offset 0
131 OpDecorate %19 DescriptorSet 0
132 OpDecorate %19 Binding 1
133 OpDecorate %49 ArrayStride 16
134 OpMemberDecorate %50 0 Offset 0
136 OpDecorate %52 DescriptorSet 0
137 OpDecorate %52 Binding 0
138 OpDecorate %86 Location 0
140 %3 = OpTypeFunction %2
142 %7 = OpTypeVector %6 3
145 %15 = OpConstant %14 2
146 %16 = OpTypeArray %11 %15
147 %17 = OpTypeStruct %16
148 %18 = OpTypePointer Uniform %17
149 %19 = OpVariable %18 Uniform
150 %20 = OpConstant %11 0
151 %21 = OpTypePointer Uniform %11
152 %25 = OpConstant %11 1
154 %36 = OpTypeVector %11 2
155 %49 = OpTypeArray %6 %15
156 %50 = OpTypeStruct %49
157 %51 = OpTypePointer Uniform %50
158 %52 = OpVariable %51 Uniform
159 %53 = OpTypePointer Uniform %6
160 %60 = OpTypePointer Function %6
161 %79 = OpTypeVector %26 3
162 %84 = OpTypeVector %6 4
163 %85 = OpTypePointer Output %84
164 %86 = OpVariable %85 Output
166 %4 = OpFunction %2 None %3
168 %109 = OpVariable %60 Function
169 %113 = OpAccessChain %21 %19 %20 %20
170 %114 = OpLoad %11 %113
171 %119 = OpCompositeConstruct %36 %25 %143
172 %125 = OpExtInst %36 %1 SMax %119 %119
173 %126 = OpCompositeExtract %11 %125 0
174 %127 = OpAccessChain %53 %52 %20 %20
175 %128 = OpLoad %6 %127
176 %132 = OpIEqual %26 %126 %114
177 OpSelectionMerge %139 None
178 OpBranchConditional %132 %136 %133
183 %137 = OpAccessChain %53 %52 %20 %25
184 %138 = OpLoad %6 %137
188 %140 = OpLoad %6 %109
189 %141 = OpExtInst %6 %1 FMax %128 %140
190 %142 = OpCompositeConstruct %7 %141 %141 %141
191 %77 = OpConvertSToF %6 %114
192 %78 = OpCompositeConstruct %7 %77 %77 %77
193 %80 = OpFOrdEqual %79 %142 %78
195 OpSelectionMerge %83 None
196 OpBranchConditional %81 %82 %100
198 %101 = OpAccessChain %21 %19 %20 %25
199 %102 = OpLoad %11 %101
200 %103 = OpConvertSToF %6 %102
201 %104 = OpCompositeConstruct %84 %103 %103 %103 %103
205 %90 = OpAccessChain %21 %19 %20 %25
207 %92 = OpConvertSToF %6 %91
208 %99 = OpCompositeConstruct %84 %77 %92 %92 %77
216 # uniforms for variant
218 # _GLF_uniform_int_values
219 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
222 # _GLF_uniform_float_values
223 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
227 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
229 PIPELINE graphics variant_pipeline
230 ATTACH variant_vertex_shader
231 ATTACH variant_fragment_shader
232 FRAMEBUFFER_SIZE 32 32
233 BIND BUFFER variant_framebuffer AS color LOCATION 0
234 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
235 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
237 CLEAR_COLOR variant_pipeline 0 0 0 255
239 CLEAR variant_pipeline
240 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
242 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255