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_1 _GLF_uniform_int_values[0]
29 # #define _int_0 _GLF_uniform_int_values[1]
30 # #define _float_100_0 _GLF_uniform_float_values[0]
31 # #define _float_1_0 _GLF_uniform_float_values[1]
33 # precision highp int;
34 # precision highp float;
36 # // Contents of _GLF_uniform_int_values: [1, 0]
37 # layout(set = 0, binding = 0) uniform buf0
39 # int _GLF_uniform_int_values[2];
41 # // Contents of _GLF_uniform_float_values: [100.0, 1.0]
42 # layout(set = 0, binding = 1) uniform buf1
44 # float _GLF_uniform_float_values[2];
46 # layout(location = 0) out vec4 _GLF_color;
50 # vec2 v0 = vec2(_float_1_0, -580.015);
51 # vec2 v1 = clamp(ceil(v0), vec2(-_float_100_0), vec2(100.0));
53 # if(v1.y == -_float_100_0)
55 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
59 # _GLF_color = vec4(_int_0);
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" %47
72 OpExecutionMode %4 OriginUpperLeft
77 OpMemberName %13 0 "_GLF_uniform_float_values"
80 OpName %47 "_GLF_color"
82 OpMemberName %49 0 "_GLF_uniform_int_values"
84 OpDecorate %12 ArrayStride 16
85 OpMemberDecorate %13 0 Offset 0
87 OpDecorate %15 DescriptorSet 0
88 OpDecorate %15 Binding 1
89 OpDecorate %47 Location 0
90 OpDecorate %48 ArrayStride 16
91 OpMemberDecorate %49 0 Offset 0
93 OpDecorate %51 DescriptorSet 0
94 OpDecorate %51 Binding 0
96 %3 = OpTypeFunction %2
98 %7 = OpTypeVector %6 2
99 %8 = OpTypePointer Function %7
101 %11 = OpConstant %10 2
102 %12 = OpTypeArray %6 %11
103 %13 = OpTypeStruct %12
104 %14 = OpTypePointer Uniform %13
105 %15 = OpVariable %14 Uniform
107 %17 = OpConstant %16 0
108 %18 = OpConstant %16 1
109 %19 = OpTypePointer Uniform %6
110 %22 = OpConstant %6 -580.015015
111 %31 = OpConstant %6 100
112 %32 = OpConstantComposite %7 %31 %31
113 %34 = OpConstant %10 1
114 %35 = OpTypePointer Function %6
116 %45 = OpTypeVector %6 4
117 %46 = OpTypePointer Output %45
118 %47 = OpVariable %46 Output
119 %48 = OpTypeArray %16 %11
120 %49 = OpTypeStruct %48
121 %50 = OpTypePointer Uniform %49
122 %51 = OpVariable %50 Uniform
123 %52 = OpTypePointer Uniform %16
124 %4 = OpFunction %2 None %3
126 %9 = OpVariable %8 Function
127 %24 = OpVariable %8 Function
128 %20 = OpAccessChain %19 %15 %17 %18
130 %23 = OpCompositeConstruct %7 %21 %22
133 %26 = OpExtInst %7 %1 Ceil %25
134 %27 = OpAccessChain %19 %15 %17 %17
136 %29 = OpFNegate %6 %28
137 %30 = OpCompositeConstruct %7 %29 %29
138 %33 = OpExtInst %7 %1 FClamp %26 %30 %32
140 %36 = OpAccessChain %35 %24 %34
142 %38 = OpAccessChain %19 %15 %17 %17
144 %40 = OpFNegate %6 %39
145 %42 = OpFOrdEqual %41 %37 %40
146 OpSelectionMerge %44 None
147 OpBranchConditional %42 %43 %66
149 %53 = OpAccessChain %52 %51 %17 %17
151 %55 = OpConvertSToF %6 %54
152 %56 = OpAccessChain %52 %51 %17 %18
154 %58 = OpConvertSToF %6 %57
155 %59 = OpAccessChain %52 %51 %17 %18
157 %61 = OpConvertSToF %6 %60
158 %62 = OpAccessChain %52 %51 %17 %17
160 %64 = OpConvertSToF %6 %63
161 %65 = OpCompositeConstruct %45 %55 %58 %61 %64
165 %67 = OpAccessChain %52 %51 %17 %18
167 %69 = OpConvertSToF %6 %68
168 %70 = OpCompositeConstruct %45 %69 %69 %69 %69
176 # uniforms for variant
178 # _GLF_uniform_float_values
179 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
182 # _GLF_uniform_int_values
183 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
187 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
189 PIPELINE graphics variant_pipeline
190 ATTACH variant_vertex_shader
191 ATTACH variant_fragment_shader
192 FRAMEBUFFER_SIZE 256 256
193 BIND BUFFER variant_framebuffer AS color LOCATION 0
194 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
195 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
197 CLEAR_COLOR variant_pipeline 0 0 0 255
199 CLEAR variant_pipeline
200 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
202 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255