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 shader with a discard nested in a loop in a function
22 # The test passes because the discard is always reached, so we end up with the background color, black.
24 # Optimized using spirv-opt with the following arguments:
25 # '--simplify-instructions'
26 # '--eliminate-dead-inserts'
27 # '--redundancy-elimination'
28 # '--inline-entry-points-exhaustive'
29 # '--eliminate-dead-branches'
31 # '--convert-local-access-chains'
32 # '--convert-local-access-chains'
33 # '--eliminate-dead-code-aggressive'
34 # '--eliminate-local-single-store'
36 # '--simplify-instructions'
37 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
41 SHADER vertex variant_vertex_shader PASSTHROUGH
43 # variant_fragment_shader is derived from the following GLSL:
45 # precision highp float;
47 # layout(location = 0) out vec4 _GLF_color;
49 # layout(set = 0, binding = 0) uniform buf0 {
50 # vec2 injectionSwitch;
56 # if(1.0 > injectionSwitch.y)
58 # if(gl_FragCoord.y < 0.0)
70 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
72 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
75 ; Generator: Khronos Glslang Reference Front End; 7
79 %1 = OpExtInstImport "GLSL.std.450"
80 OpMemoryModel Logical GLSL450
81 OpEntryPoint Fragment %4 "main" %31 %44
82 OpExecutionMode %4 OriginUpperLeft
87 OpMemberName %15 0 "injectionSwitch"
89 OpName %31 "gl_FragCoord"
90 OpName %44 "_GLF_color"
91 OpMemberDecorate %15 0 Offset 0
93 OpDecorate %17 DescriptorSet 0
94 OpDecorate %17 Binding 0
95 OpDecorate %31 BuiltIn FragCoord
96 OpDecorate %44 Location 0
98 %3 = OpTypeFunction %2
100 %13 = OpConstant %12 1
101 %14 = OpTypeVector %12 2
102 %15 = OpTypeStruct %14
103 %16 = OpTypePointer Uniform %15
104 %17 = OpVariable %16 Uniform
106 %19 = OpConstant %18 0
108 %21 = OpConstant %20 1
109 %22 = OpTypePointer Uniform %12
111 %29 = OpTypeVector %12 4
112 %30 = OpTypePointer Input %29
113 %31 = OpVariable %30 Input
114 %32 = OpTypePointer Input %12
115 %35 = OpConstant %12 0
116 %41 = OpConstantFalse %25
117 %43 = OpTypePointer Output %29
118 %44 = OpVariable %43 Output
119 %45 = OpConstantComposite %29 %13 %35 %35 %13
120 %4 = OpFunction %2 None %3
122 %42 = OpFunctionCall %2 %6
126 %6 = OpFunction %2 None %3
130 OpLoopMerge %10 %38 None
133 %23 = OpAccessChain %22 %17 %19 %21
135 %26 = OpFOrdGreaterThan %25 %13 %24
136 OpSelectionMerge %28 None
137 OpBranchConditional %26 %27 %28
139 %33 = OpAccessChain %32 %31 %21
141 %36 = OpFOrdLessThan %25 %34 %35
142 OpSelectionMerge %46 None
143 OpBranchConditional %36 %37 %38
149 OpBranchConditional %41 %8 %10
157 # uniforms for variant
160 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
164 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
166 PIPELINE graphics variant_pipeline
167 ATTACH variant_vertex_shader
168 ATTACH variant_fragment_shader
169 FRAMEBUFFER_SIZE 256 256
170 BIND BUFFER variant_framebuffer AS color LOCATION 0
171 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
173 CLEAR_COLOR variant_pipeline 0 0 0 255
175 CLEAR variant_pipeline
176 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
178 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 0 0 0 255