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 discard and add in function in loop
22 # The test passes because main always outputs the color red and returns.
23 # red() has an unreachable discard and adds zero to the returned value.
25 # Optimized using spirv-opt with the following arguments:
27 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
31 SHADER vertex variant_vertex_shader PASSTHROUGH
33 # variant_fragment_shader is derived from the following GLSL:
35 # precision highp float;
37 # layout(location = 0) out vec4 _GLF_color;
39 # layout(set = 0, binding = 0) uniform buf0 {
40 # vec2 injectionSwitch;
45 # if(injectionSwitch.x > 0.0) // always false
48 # return vec4(1.0, 0.0, 0.0, 1.0) + injectionSwitch.x; // add zero
55 # while(injectionSwitch.y > 0.0) // always true
62 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
65 ; Generator: Khronos Glslang Reference Front End; 7
69 %1 = OpExtInstImport "GLSL.std.450"
70 OpMemoryModel Logical GLSL450
71 OpEntryPoint Fragment %4 "main" %52
72 OpExecutionMode %4 OriginUpperLeft
76 OpMemberName %12 0 "injectionSwitch"
78 OpName %52 "_GLF_color"
79 OpMemberDecorate %12 0 Offset 0
81 OpDecorate %14 DescriptorSet 0
82 OpDecorate %14 Binding 0
83 OpDecorate %52 Location 0
85 %3 = OpTypeFunction %2
87 %7 = OpTypeVector %6 4
88 %11 = OpTypeVector %6 2
89 %12 = OpTypeStruct %11
90 %13 = OpTypePointer Uniform %12
91 %14 = OpVariable %13 Uniform
93 %16 = OpConstant %15 0
95 %18 = OpConstant %17 0
96 %19 = OpTypePointer Uniform %6
100 %29 = OpConstantComposite %7 %28 %22 %22 %28
101 %41 = OpConstantTrue %23
102 %47 = OpConstant %17 1
103 %51 = OpTypePointer Output %7
104 %52 = OpVariable %51 Output
105 %63 = OpConstantFalse %23
106 %4 = OpFunction %2 None %3
110 OpLoopMerge %59 %62 None
113 %100 = OpPhi %23 %63 %60 %98 %66
114 OpLoopMerge %38 %66 None
117 %48 = OpAccessChain %19 %14 %16 %47
119 %50 = OpFOrdGreaterThan %23 %49 %22
120 OpLoopMerge %44 %45 None
121 OpBranchConditional %50 %43 %44
125 OpLoopMerge %82 %83 None
128 %85 = OpAccessChain %19 %14 %16 %18
130 %87 = OpFOrdGreaterThan %23 %86 %22
131 OpSelectionMerge %88 None
132 OpBranchConditional %87 %89 %88
134 %90 = OpFunctionCall %2 %55
138 %94 = OpCompositeConstruct %7 %86 %86 %86 %86
139 %95 = OpFAdd %7 %29 %94
144 %97 = OpPhi %7 %91 %89 %95 %88
150 %98 = OpPhi %23 %100 %42 %41 %82
151 OpSelectionMerge %101 None
152 OpBranchConditional %98 %38 %66
158 OpSelectionMerge %68 None
159 OpBranchConditional %98 %59 %68
167 %55 = OpFunction %2 None %3
173 # uniforms for variant
176 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
180 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
182 PIPELINE graphics variant_pipeline
183 ATTACH variant_vertex_shader
184 ATTACH variant_fragment_shader
185 FRAMEBUFFER_SIZE 256 256
186 BIND BUFFER variant_framebuffer AS color LOCATION 0
187 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
189 CLEAR_COLOR variant_pipeline 0 0 0 255
191 CLEAR variant_pipeline
192 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
194 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255