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 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # #define _int_0 _GLF_uniform_int_values[0]
29 # #define _int_1 _GLF_uniform_int_values[1]
31 # precision highp float;
32 # precision highp int;
34 # // Contents of _GLF_uniform_int_values: [0, 1]
35 # layout(set = 0, binding = 0) uniform buf0
37 # int _GLF_uniform_int_values[2];
40 # const int _GLF_global_loop_bound = 100;
41 # int _GLF_global_loop_count = 0;
43 # layout(location = 0) out vec4 _GLF_color;
47 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
49 # while (_GLF_global_loop_count < _GLF_global_loop_bound)
51 # _GLF_global_loop_count++;
54 # if (!(true || _int_0 == _int_1))
60 # // This loop will not be iterated since the loop bound
61 # // has already been reached with the previous loop.
62 # while (_GLF_global_loop_count < _GLF_global_loop_bound)
64 # _GLF_global_loop_count++;
65 # _GLF_color = vec4(_int_0);
68 # // The output color still remains red beacuse the loop above
69 # // was not executed.
71 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
74 ; Generator: Khronos Glslang Reference Front End; 10
78 %1 = OpExtInstImport "GLSL.std.450"
79 OpMemoryModel Logical GLSL450
80 OpEntryPoint Fragment %4 "main" %13
81 OpExecutionMode %4 OriginUpperLeft
84 OpName %8 "_GLF_global_loop_count"
85 OpName %13 "_GLF_color"
87 OpMemberName %17 0 "_GLF_uniform_int_values"
89 OpDecorate %13 Location 0
90 OpDecorate %16 ArrayStride 16
91 OpMemberDecorate %17 0 Offset 0
93 OpDecorate %19 DescriptorSet 0
94 OpDecorate %19 Binding 0
96 %3 = OpTypeFunction %2
98 %7 = OpTypePointer Private %6
99 %8 = OpVariable %7 Private
102 %11 = OpTypeVector %10 4
103 %12 = OpTypePointer Output %11
104 %13 = OpVariable %12 Output
106 %15 = OpConstant %14 2
107 %16 = OpTypeArray %6 %15
108 %17 = OpTypeStruct %16
109 %18 = OpTypePointer Uniform %17
110 %19 = OpVariable %18 Uniform
111 %20 = OpConstant %6 1
112 %21 = OpTypePointer Uniform %6
113 %41 = OpConstant %6 100
115 %46 = OpConstantTrue %42
116 %4 = OpFunction %2 None %3
119 %22 = OpAccessChain %21 %19 %9 %20
121 %24 = OpConvertSToF %10 %23
122 %25 = OpAccessChain %21 %19 %9 %9
124 %27 = OpConvertSToF %10 %26
125 %28 = OpAccessChain %21 %19 %9 %9
127 %30 = OpConvertSToF %10 %29
128 %31 = OpAccessChain %21 %19 %9 %20
130 %33 = OpConvertSToF %10 %32
131 %34 = OpCompositeConstruct %11 %24 %27 %30 %33
135 OpLoopMerge %37 %38 None
139 %43 = OpSLessThan %42 %40 %41
140 OpBranchConditional %43 %36 %37
143 %45 = OpIAdd %6 %44 %20
145 %47 = OpLogicalNot %42 %46
146 OpSelectionMerge %49 None
147 OpBranchConditional %47 %48 %49
149 %50 = OpAccessChain %21 %19 %9 %9
151 %52 = OpAccessChain %21 %19 %9 %20
153 %54 = OpIEqual %42 %51 %53
156 %55 = OpPhi %42 %46 %36 %54 %48
157 %56 = OpLogicalNot %42 %55
158 OpSelectionMerge %58 None
159 OpBranchConditional %56 %57 %58
169 OpLoopMerge %62 %63 None
173 %66 = OpSLessThan %42 %65 %41
174 OpBranchConditional %66 %61 %62
177 %68 = OpIAdd %6 %67 %20
179 %69 = OpAccessChain %21 %19 %9 %9
181 %71 = OpConvertSToF %10 %70
182 %72 = OpCompositeConstruct %11 %71 %71 %71 %71
192 # uniforms for variant
194 # _GLF_uniform_int_values
195 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
199 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
201 PIPELINE graphics variant_pipeline
202 ATTACH variant_vertex_shader
203 ATTACH variant_fragment_shader
204 FRAMEBUFFER_SIZE 256 256
205 BIND BUFFER variant_framebuffer AS color LOCATION 0
206 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
208 CLEAR_COLOR variant_pipeline 0 0 0 255
210 CLEAR variant_pipeline
211 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
213 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255