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.
17 # A test for a bug found by GraphicsFuzz.
19 # Short description: A fragment shader with return in nest of ifs, inside loop
21 # The test passes because the fragment shader assigns red to _GLF_color then
22 # assigns black to _GLF_color in the loop. The other assignment to _GLF_color
23 # (in the if statement) is not dynamically reachable.
25 # Derived from the following GLSL.
27 # Fragment shader GLSL:
30 # precision highp float;
32 # layout(location = 0) out vec4 _GLF_color;
34 # layout(set = 0, binding = 0) uniform buf0 {
35 # vec2 injectionSwitch;
40 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
47 # _GLF_color = vec4(1.0);
48 # if(1.0 > injectionSwitch.y)
50 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
59 SHADER vertex variant_vertex_shader PASSTHROUGH
61 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
64 ; Generator: Khronos Glslang Reference Front End; 7
68 %1 = OpExtInstImport "GLSL.std.450"
69 OpMemoryModel Logical GLSL450
70 OpEntryPoint Fragment %4 "main" %9
71 OpExecutionMode %4 OriginUpperLeft
74 OpName %9 "_GLF_color"
77 OpMemberName %28 0 "injectionSwitch"
79 OpDecorate %9 Location 0
80 OpDecorate %15 RelaxedPrecision
81 OpDecorate %22 RelaxedPrecision
82 OpMemberDecorate %28 0 Offset 0
84 OpDecorate %30 DescriptorSet 0
85 OpDecorate %30 Binding 0
86 OpDecorate %43 RelaxedPrecision
87 OpDecorate %45 RelaxedPrecision
89 %3 = OpTypeFunction %2
91 %7 = OpTypeVector %6 4
92 %8 = OpTypePointer Output %7
93 %9 = OpVariable %8 Output
96 %12 = OpConstantComposite %7 %10 %11 %11 %10
98 %14 = OpTypePointer Function %13
99 %16 = OpConstant %13 0
100 %23 = OpConstant %13 10
102 %26 = OpConstantComposite %7 %10 %10 %10 %10
103 %27 = OpTypeVector %6 2
104 %28 = OpTypeStruct %27
105 %29 = OpTypePointer Uniform %28
106 %30 = OpVariable %29 Uniform
108 %32 = OpConstant %31 1
109 %33 = OpTypePointer Uniform %6
110 %39 = OpConstantTrue %24
111 %44 = OpConstant %13 1
112 %4 = OpFunction %2 None %3
114 %15 = OpVariable %14 Function
119 OpLoopMerge %19 %20 None
123 %25 = OpSLessThan %24 %22 %23
124 OpBranchConditional %25 %18 %19
127 %34 = OpAccessChain %33 %30 %16 %32
129 %36 = OpFOrdGreaterThan %24 %10 %35
130 OpSelectionMerge %38 None
131 OpBranchConditional %36 %37 %38
134 OpSelectionMerge %41 None
135 OpBranchConditional %39 %40 %41
144 %45 = OpIAdd %13 %43 %44
153 # uniforms for variant
156 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
160 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
162 PIPELINE graphics variant_pipeline
163 ATTACH variant_vertex_shader
164 ATTACH variant_fragment_shader
165 FRAMEBUFFER_SIZE 256 256
166 BIND BUFFER variant_framebuffer AS color LOCATION 0
167 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
169 CLEAR_COLOR variant_pipeline 0 0 0 255
171 CLEAR variant_pipeline
172 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
174 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 255 255 255