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 bug found by GraphicsFuzz.
20 # Short description: Nested switches with break and discard
22 # The test passes because the shader always writes red.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # layout(set = 0, binding = 0) uniform buf0
32 # vec2 injectionSwitch;
35 # layout(location = 0) out vec4 _GLF_color;
39 # _GLF_color = vec4(0.0, 0.0, 0.0, 1.0);
41 # switch (int(injectionSwitch.x)) // 0
47 # if (gl_FragCoord.y >= 0.0) // Always true.
49 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Red.
58 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
61 ; Generator: Khronos Glslang Reference Front End; 8
65 %1 = OpExtInstImport "GLSL.std.450"
66 OpMemoryModel Logical GLSL450
67 OpEntryPoint Fragment %4 "main" %9 %32
68 OpExecutionMode %4 OriginUpperLeft
71 OpName %9 "_GLF_color"
73 OpMemberName %14 0 "injectionSwitch"
75 OpName %32 "gl_FragCoord"
76 OpDecorate %9 Location 0
77 OpMemberDecorate %14 0 Offset 0
79 OpDecorate %16 DescriptorSet 0
80 OpDecorate %16 Binding 0
81 OpDecorate %32 BuiltIn FragCoord
83 %3 = OpTypeFunction %2
85 %7 = OpTypeVector %6 4
86 %8 = OpTypePointer Output %7
87 %9 = OpVariable %8 Output
90 %12 = OpConstantComposite %7 %10 %10 %10 %11
91 %13 = OpTypeVector %6 2
92 %14 = OpTypeStruct %13
93 %15 = OpTypePointer Uniform %14
94 %16 = OpVariable %15 Uniform
96 %18 = OpConstant %17 0
98 %20 = OpConstant %19 0
99 %21 = OpTypePointer Uniform %6
100 %28 = OpConstant %17 1
101 %31 = OpTypePointer Input %7
102 %32 = OpVariable %31 Input
103 %33 = OpConstant %19 1
104 %34 = OpTypePointer Input %6
106 %41 = OpConstantComposite %7 %11 %10 %10 %11
107 %4 = OpFunction %2 None %3
110 %22 = OpAccessChain %21 %16 %18 %20
112 %24 = OpConvertFToS %17 %23
113 OpSelectionMerge %27 None
114 OpSwitch %24 %27 0 %25 42 %26
116 OpSelectionMerge %30 None
117 OpSwitch %28 %30 1 %29
119 %35 = OpAccessChain %34 %32 %33
121 %38 = OpFOrdGreaterThanEqual %37 %36 %10
122 OpSelectionMerge %40 None
123 OpBranchConditional %38 %39 %40
138 # uniforms for variant
141 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
145 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
147 PIPELINE graphics variant_pipeline
148 ATTACH variant_vertex_shader
149 ATTACH variant_fragment_shader
150 FRAMEBUFFER_SIZE 256 256
151 BIND BUFFER variant_framebuffer AS color LOCATION 0
152 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
154 CLEAR_COLOR variant_pipeline 0 0 0 255
156 CLEAR variant_pipeline
157 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
159 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255