3 # Copyright 2020 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 a specific selection dag code path
22 # The test passes because the shader always writes red.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # #define _int_3 _GLF_uniform_int_values[0]
29 # #define _int_0 _GLF_uniform_int_values[1]
30 # #define _int_1 _GLF_uniform_int_values[2]
31 # #define _float_10_0 _GLF_uniform_float_values[0]
32 # #define _float_1_0 _GLF_uniform_float_values[1]
33 # #define _float_2_0 _GLF_uniform_float_values[2]
34 # #define _float_3_0 _GLF_uniform_float_values[3]
35 # #define _float_4_0 _GLF_uniform_float_values[4]
37 # precision highp int;
38 # precision highp float;
40 # // Contents of _GLF_uniform_float_values: [10.0, 1.0, 2.0, 3.0, 4.0]
41 # layout(set = 0, binding = 0) uniform buf0
43 # float _GLF_uniform_float_values[5];
46 # // Contents of _GLF_uniform_int_values: [3, 0, 1]
47 # layout(set = 0, binding = 1) uniform buf1
49 # int _GLF_uniform_int_values[3];
52 # layout(location = 0) out vec4 _GLF_color;
56 # mat2 M1 = mat2(_float_1_0, _float_2_0, _float_3_0, _float_4_0);
57 # float a = _float_1_0;
59 # for (int c = _int_0; c < _int_3; c++)
61 # // At each iteration, clamp returns 0.
62 # a += M1[_int_1][clamp(~c, 0, 1)];
65 # if (a == _float_10_0)
67 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
71 # _GLF_color = vec4(_int_1);
74 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
77 ; Generator: Khronos Glslang Reference Front End; 10
81 %1 = OpExtInstImport "GLSL.std.450"
82 OpMemoryModel Logical GLSL450
83 OpEntryPoint Fragment %4 "main" %80
84 OpExecutionMode %4 OriginUpperLeft
89 OpMemberName %14 0 "_GLF_uniform_float_values"
94 OpMemberName %45 0 "_GLF_uniform_int_values"
96 OpName %80 "_GLF_color"
97 OpDecorate %13 ArrayStride 16
98 OpMemberDecorate %14 0 Offset 0
100 OpDecorate %16 DescriptorSet 0
101 OpDecorate %16 Binding 0
102 OpDecorate %44 ArrayStride 16
103 OpMemberDecorate %45 0 Offset 0
105 OpDecorate %47 DescriptorSet 0
106 OpDecorate %47 Binding 1
107 OpDecorate %80 Location 0
109 %3 = OpTypeFunction %2
111 %7 = OpTypeVector %6 2
112 %8 = OpTypeMatrix %7 2
113 %9 = OpTypePointer Function %8
115 %12 = OpConstant %11 5
116 %13 = OpTypeArray %6 %12
117 %14 = OpTypeStruct %13
118 %15 = OpTypePointer Uniform %14
119 %16 = OpVariable %15 Uniform
121 %18 = OpConstant %17 0
122 %19 = OpConstant %17 1
123 %20 = OpTypePointer Uniform %6
124 %23 = OpConstant %17 2
125 %26 = OpConstant %17 3
126 %29 = OpConstant %17 4
127 %32 = OpConstant %6 1
128 %33 = OpConstant %6 0
129 %37 = OpTypePointer Function %6
130 %41 = OpTypePointer Function %17
131 %43 = OpConstant %11 3
132 %44 = OpTypeArray %17 %43
133 %45 = OpTypeStruct %44
134 %46 = OpTypePointer Uniform %45
135 %47 = OpVariable %46 Uniform
136 %48 = OpTypePointer Uniform %17
138 %78 = OpTypeVector %6 4
139 %79 = OpTypePointer Output %78
140 %80 = OpVariable %79 Output
141 %4 = OpFunction %2 None %3
143 %10 = OpVariable %9 Function
144 %38 = OpVariable %37 Function
145 %42 = OpVariable %41 Function
146 %21 = OpAccessChain %20 %16 %18 %19
148 %24 = OpAccessChain %20 %16 %18 %23
150 %27 = OpAccessChain %20 %16 %18 %26
152 %30 = OpAccessChain %20 %16 %18 %29
154 %34 = OpCompositeConstruct %7 %22 %25
155 %35 = OpCompositeConstruct %7 %28 %31
156 %36 = OpCompositeConstruct %8 %34 %35
158 %39 = OpAccessChain %20 %16 %18 %19
161 %49 = OpAccessChain %48 %47 %18 %19
166 OpLoopMerge %53 %54 None
170 %57 = OpAccessChain %48 %47 %18 %18
172 %60 = OpSLessThan %59 %56 %58
173 OpBranchConditional %60 %52 %53
175 %61 = OpAccessChain %48 %47 %18 %23
179 %65 = OpExtInst %17 %1 SClamp %64 %18 %19
180 %66 = OpAccessChain %37 %10 %62 %65
183 %69 = OpFAdd %6 %68 %67
188 %71 = OpIAdd %17 %70 %19
193 %73 = OpAccessChain %20 %16 %18 %18
195 %75 = OpFOrdEqual %59 %72 %74
196 OpSelectionMerge %77 None
197 OpBranchConditional %75 %76 %94
199 %81 = OpAccessChain %48 %47 %18 %23
201 %83 = OpConvertSToF %6 %82
202 %84 = OpAccessChain %48 %47 %18 %19
204 %86 = OpConvertSToF %6 %85
205 %87 = OpAccessChain %48 %47 %18 %19
207 %89 = OpConvertSToF %6 %88
208 %90 = OpAccessChain %48 %47 %18 %23
210 %92 = OpConvertSToF %6 %91
211 %93 = OpCompositeConstruct %78 %83 %86 %89 %92
215 %95 = OpAccessChain %48 %47 %18 %23
217 %97 = OpConvertSToF %6 %96
218 %98 = OpCompositeConstruct %78 %97 %97 %97 %97
226 # uniforms for variant
228 # _GLF_uniform_int_values
229 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
232 # _GLF_uniform_float_values
233 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
237 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
239 PIPELINE graphics variant_pipeline
240 ATTACH variant_vertex_shader
241 ATTACH variant_fragment_shader
242 FRAMEBUFFER_SIZE 16 16
243 BIND BUFFER variant_framebuffer AS color LOCATION 0
244 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
245 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
247 CLEAR_COLOR variant_pipeline 0 0 0 255
249 CLEAR variant_pipeline
250 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
252 EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255