3 # Copyright 2019 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 bug found by GraphicsFuzz.
20 # Short description: A fragment shader with an always false if.
22 # The test passes because the shader always writes color red.
23 # Function brick() writes red in the beginning and returns in the end.
25 # Optimized using spirv-opt with the following arguments:
26 # '--eliminate-dead-branches'
28 # '--inline-entry-points-exhaustive'
29 # '--scalar-replacement=100'
30 # '--eliminate-local-single-block'
31 # '--eliminate-local-single-block'
32 # '--eliminate-dead-branches'
34 # '--eliminate-dead-code-aggressive'
35 # '--eliminate-dead-branches'
36 # '--convert-local-access-chains'
37 # '--scalar-replacement=100'
38 # '--reduce-load-size'
39 # '--scalar-replacement=100'
40 # '--redundancy-elimination'
41 # '--convert-local-access-chains'
42 # '--eliminate-dead-branches'
44 # '--eliminate-dead-branches'
46 # '--eliminate-local-single-block'
47 # '--private-to-local'
48 # '--copy-propagate-arrays'
49 # '--eliminate-dead-branches'
50 # '--redundancy-elimination'
52 # '--scalar-replacement=100'
53 # '--eliminate-local-multi-store'
54 # '--scalar-replacement=100'
55 # '--redundancy-elimination'
56 # '--redundancy-elimination'
57 # '--copy-propagate-arrays'
58 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
62 SHADER vertex variant_vertex_shader PASSTHROUGH
64 # variant_fragment_shader is derived from the following GLSL:
66 # precision highp float;
68 # layout(set = 0, binding = 0) uniform buf0
70 # vec2 injectionSwitch;
73 # layout(location = 0) out vec4 _GLF_color;
77 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red
82 # if (injectionSwitch.y < 0.0) // Always false
97 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
100 ; Generator: Khronos Glslang Reference Front End; 7
104 %1 = OpExtInstImport "GLSL.std.450"
105 OpMemoryModel Logical GLSL450
106 OpEntryPoint Fragment %4 "main" %15
107 OpExecutionMode %4 OriginUpperLeft
110 OpName %11 "brick(vf2;"
112 OpName %15 "_GLF_color"
114 OpMemberName %23 0 "injectionSwitch"
117 OpDecorate %15 Location 0
118 OpMemberDecorate %23 0 Offset 0
120 OpDecorate %25 DescriptorSet 0
121 OpDecorate %25 Binding 0
123 %3 = OpTypeFunction %2
125 %7 = OpTypeVector %6 2
126 %8 = OpTypePointer Function %7
127 %9 = OpTypeFunction %7 %8
128 %13 = OpTypeVector %6 4
129 %14 = OpTypePointer Output %13
130 %15 = OpVariable %14 Output
131 %16 = OpConstant %6 1
132 %17 = OpConstant %6 0
133 %18 = OpConstantComposite %13 %16 %17 %17 %16
134 %23 = OpTypeStruct %7
135 %24 = OpTypePointer Uniform %23
136 %25 = OpVariable %24 Uniform
138 %27 = OpConstant %26 0
140 %29 = OpConstant %28 1
141 %30 = OpTypePointer Uniform %6
143 %37 = OpConstantComposite %7 %16 %16
144 %39 = OpTypePointer Function %6
145 %44 = OpConstantFalse %33
146 %4 = OpFunction %2 None %3
148 %51 = OpVariable %8 Function
150 %52 = OpFunctionCall %7 %11 %51
153 %11 = OpFunction %7 None %9
154 %10 = OpFunctionParameter %8
159 OpLoopMerge %21 %36 None
162 %31 = OpAccessChain %30 %25 %27 %29
164 %34 = OpFOrdLessThan %33 %32 %17
165 OpSelectionMerge %53 None
166 OpBranchConditional %34 %35 %36
172 %40 = OpAccessChain %39 %10 %29
174 %42 = OpFSub %6 %41 %16
176 OpBranchConditional %44 %19 %21
179 %47 = OpFSub %6 %46 %16
185 # uniforms for variant
188 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
192 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
194 PIPELINE graphics variant_pipeline
195 ATTACH variant_vertex_shader
196 ATTACH variant_fragment_shader
197 FRAMEBUFFER_SIZE 256 256
198 BIND BUFFER variant_framebuffer AS color LOCATION 0
199 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
201 CLEAR_COLOR variant_pipeline 0 0 0 255
203 CLEAR variant_pipeline
204 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
206 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255