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 nir opt large constants 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_33 _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_1_0 _GLF_uniform_float_values[0]
32 # #define _float_0_0 _GLF_uniform_float_values[1]
34 # precision highp float;
35 # precision highp int;
37 # // Contents of _GLF_uniform_float_values: [1.0, 0.0]
38 # layout(set = 0, binding = 0) uniform buf0
40 # float _GLF_uniform_float_values[2];
43 # // Contents of _GLF_uniform_int_values: [33, 0, 1]
44 # layout(set = 0, binding = 1) uniform buf1
46 # int _GLF_uniform_int_values[3];
49 # layout(location = 0) out vec4 _GLF_color;
53 # vec4 v1 = vec4(_float_1_0);
54 # for (int i = _int_0; i < _int_33; i++)
56 # int a = int(vec4[2](vec4(1.0), vec4(0.0))[clamp(i, _int_0, _int_1)].x);
57 # v1 = vec4[2](vec4(_float_1_0, _float_0_0, _float_0_0, _float_1_0),
58 # vec4(_float_0_0, _float_1_0, _float_1_0, _float_0_0))[a];
62 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
65 ; Generator: Khronos Glslang Reference Front End; 10
69 %1 = OpExtInstImport "GLSL.std.450"
70 OpMemoryModel Logical GLSL450
71 OpEntryPoint Fragment %4 "main" %90
72 OpExecutionMode %4 OriginUpperLeft
77 OpMemberName %13 0 "_GLF_uniform_float_values"
81 OpMemberName %26 0 "_GLF_uniform_int_values"
84 OpName %59 "indexable"
85 OpName %84 "indexable"
86 OpName %90 "_GLF_color"
87 OpDecorate %12 ArrayStride 16
88 OpMemberDecorate %13 0 Offset 0
90 OpDecorate %15 DescriptorSet 0
91 OpDecorate %15 Binding 0
92 OpDecorate %25 ArrayStride 16
93 OpMemberDecorate %26 0 Offset 0
95 OpDecorate %28 DescriptorSet 0
96 OpDecorate %28 Binding 1
97 OpDecorate %90 Location 0
99 %3 = OpTypeFunction %2
101 %7 = OpTypeVector %6 4
102 %8 = OpTypePointer Function %7
104 %11 = OpConstant %10 2
105 %12 = OpTypeArray %6 %11
106 %13 = OpTypeStruct %12
107 %14 = OpTypePointer Uniform %13
108 %15 = OpVariable %14 Uniform
110 %17 = OpConstant %16 0
111 %18 = OpTypePointer Uniform %6
112 %22 = OpTypePointer Function %16
113 %24 = OpConstant %10 3
114 %25 = OpTypeArray %16 %24
115 %26 = OpTypeStruct %25
116 %27 = OpTypePointer Uniform %26
117 %28 = OpVariable %27 Uniform
118 %29 = OpConstant %16 1
119 %30 = OpTypePointer Uniform %16
121 %44 = OpTypeArray %7 %11
122 %45 = OpConstant %6 1
123 %46 = OpConstantComposite %7 %45 %45 %45 %45
124 %47 = OpConstant %6 0
125 %48 = OpConstantComposite %7 %47 %47 %47 %47
126 %49 = OpConstantComposite %44 %46 %48
127 %53 = OpConstant %16 2
128 %57 = OpConstant %10 0
129 %58 = OpTypePointer Function %44
130 %60 = OpTypePointer Function %6
131 %89 = OpTypePointer Output %7
132 %90 = OpVariable %89 Output
133 %4 = OpFunction %2 None %3
135 %9 = OpVariable %8 Function
136 %23 = OpVariable %22 Function
137 %43 = OpVariable %22 Function
138 %59 = OpVariable %58 Function
139 %84 = OpVariable %58 Function
140 %19 = OpAccessChain %18 %15 %17 %17
142 %21 = OpCompositeConstruct %7 %20 %20 %20 %20
144 %31 = OpAccessChain %30 %28 %17 %29
149 OpLoopMerge %35 %36 None
153 %39 = OpAccessChain %30 %28 %17 %17
155 %42 = OpSLessThan %41 %38 %40
156 OpBranchConditional %42 %34 %35
159 %51 = OpAccessChain %30 %28 %17 %29
161 %54 = OpAccessChain %30 %28 %17 %53
163 %56 = OpExtInst %16 %1 SClamp %50 %52 %55
165 %61 = OpAccessChain %60 %59 %56 %57
167 %63 = OpConvertFToS %16 %62
169 %64 = OpAccessChain %18 %15 %17 %17
171 %66 = OpAccessChain %18 %15 %17 %29
173 %68 = OpAccessChain %18 %15 %17 %29
175 %70 = OpAccessChain %18 %15 %17 %17
177 %72 = OpCompositeConstruct %7 %65 %67 %69 %71
178 %73 = OpAccessChain %18 %15 %17 %29
180 %75 = OpAccessChain %18 %15 %17 %17
182 %77 = OpAccessChain %18 %15 %17 %17
184 %79 = OpAccessChain %18 %15 %17 %29
186 %81 = OpCompositeConstruct %7 %74 %76 %78 %80
187 %82 = OpCompositeConstruct %44 %72 %81
190 %85 = OpAccessChain %8 %84 %83
196 %88 = OpIAdd %16 %87 %29
206 # uniforms for variant
208 # _GLF_uniform_int_values
209 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
212 # _GLF_uniform_float_values
213 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
217 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
219 PIPELINE graphics variant_pipeline
220 ATTACH variant_vertex_shader
221 ATTACH variant_fragment_shader
222 FRAMEBUFFER_SIZE 256 256
223 BIND BUFFER variant_framebuffer AS color LOCATION 0
224 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
225 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
227 CLEAR_COLOR variant_pipeline 0 0 0 255
229 CLEAR variant_pipeline
230 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
232 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255