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 specific NIR code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-dead-branches'
26 # '--eliminate-local-multi-store'
27 # '--eliminate-local-single-store'
28 # '--simplify-instructions'
29 # '--eliminate-dead-branches'
30 # '--copy-propagate-arrays'
31 # '--copy-propagate-arrays'
32 # '--eliminate-dead-inserts'
35 # '--inline-entry-points-exhaustive'
36 # '--eliminate-local-single-store'
37 # '--eliminate-local-single-store'
38 # '--simplify-instructions'
39 # '--eliminate-local-single-block'
41 # '--private-to-local'
42 # '--scalar-replacement=100'
43 # '--eliminate-local-single-block'
44 # '--private-to-local'
45 # '--scalar-replacement=100'
46 # '--simplify-instructions'
47 # '--eliminate-dead-branches'
49 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
57 # #define _float_1_0 _GLF_uniform_float_values[0]
58 # #define _float_2_0 _GLF_uniform_float_values[1]
60 # precision highp float;
61 # precision highp int;
63 # // Contents of _GLF_uniform_float_values: [1.0, 2.0]
64 # layout(set = 0, binding = 0) uniform buf0
66 # float _GLF_uniform_float_values[2];
69 # layout(location = 0) out vec4 _GLF_color;
71 # // Contents of zero: 0.0
72 # layout(set = 0, binding = 1) uniform buf1
79 # vec2 v0 = vec2(_float_1_0);
80 # vec4 v1 = vec4(v0.x);
83 # if(zero != _float_1_0)
86 # if(zero == _float_2_0)
90 # v1.yz -= _float_1_0;
99 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
102 ; Generator: Khronos Glslang Reference Front End; 10
106 %1 = OpExtInstImport "GLSL.std.450"
107 OpMemoryModel Logical GLSL450
108 OpEntryPoint Fragment %4 "main" %61
109 OpExecutionMode %4 OriginUpperLeft
114 OpMemberName %13 0 "_GLF_uniform_float_values"
118 OpMemberName %30 0 "zero"
120 OpName %61 "_GLF_color"
121 OpDecorate %12 ArrayStride 16
122 OpMemberDecorate %13 0 Offset 0
124 OpDecorate %15 DescriptorSet 0
125 OpDecorate %15 Binding 0
126 OpMemberDecorate %30 0 Offset 0
128 OpDecorate %32 DescriptorSet 0
129 OpDecorate %32 Binding 1
130 OpDecorate %61 Location 0
132 %3 = OpTypeFunction %2
134 %7 = OpTypeVector %6 2
135 %8 = OpTypePointer Function %7
137 %11 = OpConstant %10 2
138 %12 = OpTypeArray %6 %11
139 %13 = OpTypeStruct %12
140 %14 = OpTypePointer Uniform %13
141 %15 = OpVariable %14 Uniform
143 %17 = OpConstant %16 0
144 %18 = OpTypePointer Uniform %6
145 %22 = OpTypeVector %6 4
146 %23 = OpTypePointer Function %22
147 %25 = OpConstant %10 0
148 %26 = OpTypePointer Function %6
149 %30 = OpTypeStruct %6
150 %31 = OpTypePointer Uniform %30
151 %32 = OpVariable %31 Uniform
153 %43 = OpConstant %16 1
154 %60 = OpTypePointer Output %22
155 %61 = OpVariable %60 Output
156 %4 = OpFunction %2 None %3
158 %9 = OpVariable %8 Function
159 %24 = OpVariable %23 Function
160 %19 = OpAccessChain %18 %15 %17 %17
162 %21 = OpCompositeConstruct %7 %20 %20
164 %27 = OpAccessChain %26 %9 %25
166 %29 = OpCompositeConstruct %22 %28 %28 %28 %28
168 %33 = OpAccessChain %18 %32 %17
170 %35 = OpAccessChain %18 %15 %17 %17
172 %38 = OpFUnordNotEqual %37 %34 %36
173 OpSelectionMerge %40 None
174 OpBranchConditional %38 %39 %58
176 %41 = OpAccessChain %18 %32 %17
178 %44 = OpAccessChain %18 %15 %17 %43
180 %46 = OpFOrdEqual %37 %42 %45
181 OpSelectionMerge %48 None
182 OpBranchConditional %46 %47 %48
186 %50 = OpAccessChain %18 %15 %17 %17
188 %53 = OpVectorShuffle %7 %29 %29 1 2
189 %54 = OpCompositeConstruct %7 %51 %51
190 %55 = OpFSub %7 %53 %54
191 %57 = OpVectorShuffle %22 %29 %55 0 4 5 3
202 # uniforms for variant
205 BUFFER variant_zero DATA_TYPE float STD140 DATA
208 # _GLF_uniform_float_values
209 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
213 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
215 PIPELINE graphics variant_pipeline
216 ATTACH variant_vertex_shader
217 ATTACH variant_fragment_shader
218 FRAMEBUFFER_SIZE 256 256
219 BIND BUFFER variant_framebuffer AS color LOCATION 0
220 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 1
221 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
223 CLEAR_COLOR variant_pipeline 0 0 0 255
225 CLEAR variant_pipeline
226 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
228 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255