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 NIR code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
26 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
30 SHADER vertex variant_vertex_shader PASSTHROUGH
32 # variant_fragment_shader is derived from the following GLSL:
34 # #define _int_1 _GLF_uniform_int_values[0]
35 # #define _int_0 _GLF_uniform_int_values[1]
36 # #define _int_6 _GLF_uniform_int_values[2]
37 # #define _int_5 _GLF_uniform_int_values[3]
39 # precision highp float;
40 # precision highp int;
42 # // Contents of _GLF_uniform_int_values: [1, 0, 6, 5]
43 # layout(set = 0, binding = 0) uniform buf0
45 # int _GLF_uniform_int_values[4];
48 # layout(location = 0) out vec4 _GLF_color;
52 # // a becomes 0x8000000 which is the smallest possible negative integer.
53 # int a = min(1, bitfieldReverse(1));
56 # // a - 1 underflowa to the largest positive integer. The loop is executed
57 # // once because of the break inside.
58 # for (int i = 1; i <= a - 1; i++)
72 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
76 # _GLF_color = vec4(_int_0);
79 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
82 ; Generator: Khronos Glslang Reference Front End; 10
86 %1 = OpExtInstImport "GLSL.std.450"
87 OpMemoryModel Logical GLSL450
88 OpEntryPoint Fragment %4 "main" %56
89 OpExecutionMode %4 OriginUpperLeft
93 OpMemberName %16 0 "_GLF_uniform_int_values"
95 OpName %56 "_GLF_color"
96 OpDecorate %15 ArrayStride 16
97 OpMemberDecorate %16 0 Offset 0
99 OpDecorate %18 DescriptorSet 0
100 OpDecorate %18 Binding 0
101 OpDecorate %56 Location 0
103 %3 = OpTypeFunction %2
107 %14 = OpConstant %13 4
108 %15 = OpTypeArray %6 %14
109 %16 = OpTypeStruct %15
110 %17 = OpTypePointer Uniform %16
111 %18 = OpVariable %17 Uniform
112 %19 = OpConstant %6 0
113 %20 = OpConstant %6 3
114 %21 = OpTypePointer Uniform %6
116 %47 = OpConstant %6 2
118 %54 = OpTypeVector %53 4
119 %55 = OpTypePointer Output %54
120 %56 = OpVariable %55 Output
121 %4 = OpFunction %2 None %3
123 %10 = OpBitReverse %6 %9
124 %11 = OpExtInst %6 %1 SMin %9 %10
125 %22 = OpAccessChain %21 %18 %19 %20
129 %76 = OpPhi %6 %23 %5 %37 %28
130 %75 = OpPhi %6 %9 %5 %45 %28
131 %32 = OpISub %6 %11 %9
132 %34 = OpSLessThanEqual %33 %75 %32
133 OpLoopMerge %27 %28 None
134 OpBranchConditional %34 %26 %27
136 %37 = OpIAdd %6 %76 %75
137 %38 = OpAccessChain %21 %18 %19 %19
139 %40 = OpIEqual %33 %39 %9
140 OpSelectionMerge %42 None
141 OpBranchConditional %40 %41 %42
147 %45 = OpIAdd %6 %75 %9
150 %77 = OpPhi %6 %76 %25 %37 %41
151 %48 = OpAccessChain %21 %18 %19 %47
153 %50 = OpIEqual %33 %77 %49
154 OpSelectionMerge %52 None
155 OpBranchConditional %50 %51 %70
157 %57 = OpAccessChain %21 %18 %19 %19
159 %59 = OpConvertSToF %53 %58
160 %60 = OpAccessChain %21 %18 %19 %9
162 %62 = OpConvertSToF %53 %61
163 %69 = OpCompositeConstruct %54 %59 %62 %62 %59
167 %71 = OpAccessChain %21 %18 %19 %9
169 %73 = OpConvertSToF %53 %72
170 %74 = OpCompositeConstruct %54 %73 %73 %73 %73
178 # uniforms for variant
180 # _GLF_uniform_int_values
181 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
185 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
187 PIPELINE graphics variant_pipeline
188 ATTACH variant_vertex_shader
189 ATTACH variant_fragment_shader
190 FRAMEBUFFER_SIZE 256 256
191 BIND BUFFER variant_framebuffer AS color LOCATION 0
192 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
194 CLEAR_COLOR variant_pipeline 0 0 0 255
196 CLEAR variant_pipeline
197 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
199 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255