3 # Copyright 2018 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 # A fragment shader that uses a while loop inside a switch.
20 # Derived from the following GLSL fragment shader.
21 # We check that the top-left pixel is red. The test passes because the
22 # first if statement checks if the x coordinate is less than 10 and if so writes
23 # red to _GLF_color and then returns.
27 # precision highp float;
28 # precision highp int;
30 # layout(location = 0) out vec4 _GLF_color;
32 # layout(set = 0, binding = 0) uniform buf0 {
33 # vec2 injectionSwitch;
38 # if (gl_FragCoord.x < 10.0) {
39 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
42 # switch(int(injectionSwitch.x))
50 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
54 SHADER vertex variant_vertex_shader PASSTHROUGH
56 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
59 ; Generator: Khronos SPIR-V Tools Assembler; 0
63 %1 = OpExtInstImport "GLSL.std.450"
64 OpMemoryModel Logical GLSL450
65 OpEntryPoint Fragment %2 "main" %3 %4
66 OpExecutionMode %2 OriginUpperLeft
69 OpName %3 "gl_FragCoord"
70 OpName %4 "_GLF_color"
72 OpMemberName %5 0 "injectionSwitch"
74 OpDecorate %3 BuiltIn FragCoord
75 OpDecorate %4 Location 0
76 OpMemberDecorate %5 0 Offset 0
78 OpDecorate %6 DescriptorSet 0
79 OpDecorate %6 Binding 0
81 %8 = OpTypeFunction %7
83 %10 = OpTypeVector %9 4
84 %11 = OpTypePointer Input %10
85 %3 = OpVariable %11 Input
87 %13 = OpConstant %12 0
88 %14 = OpTypePointer Input %9
89 %15 = OpConstant %9 10
91 %17 = OpTypePointer Output %10
92 %4 = OpVariable %17 Output
95 %20 = OpConstantComposite %10 %18 %19 %19 %18
96 %21 = OpTypeVector %9 2
98 %22 = OpTypePointer Uniform %5
99 %6 = OpVariable %22 Uniform
101 %24 = OpConstant %23 0
102 %25 = OpTypePointer Uniform %9
103 %2 = OpFunction %7 None %8
107 OpLoopMerge %28 %29 None
110 %31 = OpAccessChain %14 %3 %13
112 %33 = OpFOrdLessThan %16 %32 %15
113 OpSelectionMerge %34 None
114 OpBranchConditional %33 %35 %34
119 %36 = OpAccessChain %25 %6 %24 %13
121 %38 = OpConvertFToS %23 %37
122 OpSelectionMerge %39 None
123 OpSwitch %38 %39 0 %40
127 OpLoopMerge %42 %43 None
145 # uniforms for variant
148 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
152 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
154 PIPELINE graphics variant_pipeline
155 ATTACH variant_vertex_shader
156 ATTACH variant_fragment_shader
157 FRAMEBUFFER_SIZE 256 256
158 BIND BUFFER variant_framebuffer AS color LOCATION 0
159 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
161 CLEAR_COLOR variant_pipeline 0 0 0 255
163 CLEAR variant_pipeline
164 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
166 EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255