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-local-single-store'
26 # '--convert-local-access-chains'
28 # '--eliminate-local-single-block'
29 # '--simplify-instructions'
30 # '--inline-entry-points-exhaustive'
31 # '--private-to-local'
32 # '--convert-local-access-chains'
33 # '--eliminate-dead-branches'
35 # '--combine-access-chains'
36 # '--reduce-load-size'
37 # '--reduce-load-size'
38 # '--combine-access-chains'
40 # '--eliminate-dead-branches'
41 # '--redundancy-elimination'
42 # '--inline-entry-points-exhaustive'
43 # '--eliminate-dead-branches'
45 # '--eliminate-dead-branches'
46 # '--eliminate-local-single-block'
47 # '--inline-entry-points-exhaustive'
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_3 _GLF_uniform_int_values[0]
58 # #define _int_1 _GLF_uniform_int_values[1]
59 # #define _int_0 _GLF_uniform_int_values[2]
61 # precision highp float;
62 # precision highp int;
64 # // Contents of _GLF_uniform_int_values: [3, 1, 0]
65 # layout(set = 0, binding = 0) uniform buf0 {
66 # int _GLF_uniform_int_values[3];
68 # layout(location = 0) out vec4 _GLF_color;
72 # // f = (0, 1) * max((1, 1), (2, 3)) = (0, 1) * (2, 3) = 0 * 2 + 1 * 3 = 3
73 # float f = dot(vec2(0, 1), max(vec2(_int_1, 1), vec2(2, 3)));
76 # if(int(f) == _int_3)
78 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
82 # _GLF_color = vec4(0);
85 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
88 ; Generator: Khronos Glslang Reference Front End; 10
92 %1 = OpExtInstImport "GLSL.std.450"
93 OpMemoryModel Logical GLSL450
94 OpEntryPoint Fragment %4 "main" %42
95 OpExecutionMode %4 OriginUpperLeft
100 OpMemberName %17 0 "_GLF_uniform_int_values"
102 OpName %42 "_GLF_color"
103 OpDecorate %16 ArrayStride 16
104 OpMemberDecorate %17 0 Offset 0
106 OpDecorate %19 DescriptorSet 0
107 OpDecorate %19 Binding 0
108 OpDecorate %42 Location 0
110 %3 = OpTypeFunction %2
112 %7 = OpTypePointer Function %6
113 %9 = OpTypeVector %6 2
114 %10 = OpConstant %6 0
115 %11 = OpConstant %6 1
116 %12 = OpConstantComposite %9 %10 %11
119 %15 = OpConstant %14 3
120 %16 = OpTypeArray %13 %15
121 %17 = OpTypeStruct %16
122 %18 = OpTypePointer Uniform %17
123 %19 = OpVariable %18 Uniform
124 %20 = OpConstant %13 0
125 %21 = OpConstant %13 1
126 %22 = OpTypePointer Uniform %13
127 %27 = OpConstant %6 2
128 %28 = OpConstant %6 3
129 %29 = OpConstantComposite %9 %27 %28
131 %40 = OpTypeVector %6 4
132 %41 = OpTypePointer Output %40
133 %42 = OpVariable %41 Output
134 %46 = OpConstant %13 2
135 %58 = OpConstantComposite %40 %10 %10 %10 %10
137 %4 = OpFunction %2 None %3
139 %8 = OpVariable %7 Function
140 %23 = OpAccessChain %22 %19 %20 %21
142 %26 = OpCompositeConstruct %9 %59 %11
143 %30 = OpExtInst %9 %1 FMax %26 %29
144 %31 = OpCompositeExtract %6 %30 1
146 %33 = OpConvertFToS %13 %31
147 %34 = OpAccessChain %22 %19 %20 %20
149 %37 = OpIEqual %36 %33 %35
150 OpSelectionMerge %39 None
151 OpBranchConditional %37 %38 %57
153 %45 = OpConvertSToF %6 %24
154 %47 = OpAccessChain %22 %19 %20 %46
156 %49 = OpConvertSToF %6 %48
157 %56 = OpCompositeConstruct %40 %45 %49 %49 %45
168 # uniforms for variant
170 # _GLF_uniform_int_values
171 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
175 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
177 PIPELINE graphics variant_pipeline
178 ATTACH variant_vertex_shader
179 ATTACH variant_fragment_shader
180 FRAMEBUFFER_SIZE 32 32
181 BIND BUFFER variant_framebuffer AS color LOCATION 0
182 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
184 CLEAR_COLOR variant_pipeline 0 0 0 255
186 CLEAR variant_pipeline
187 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
189 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255