• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2018 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17# A test for a bug found by GraphicsFuzz.
18
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.
24
25# #version 310 es
26#
27# precision highp float;
28# precision highp int;
29#
30# layout(location = 0) out vec4 _GLF_color;
31#
32# layout(set = 0, binding = 0) uniform buf0 {
33#   vec2 injectionSwitch;
34# };
35#
36# void main()
37# {
38#   if (gl_FragCoord.x < 10.0) {
39#     _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
40#     return;
41#   }
42#   switch(int(injectionSwitch.x))
43#   {
44#     case 0:
45#       while(bool(1.0))
46#       {
47#         discard;
48#       }
49#   }
50#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
51#   return;
52# }
53
54SHADER vertex variant_vertex_shader PASSTHROUGH
55
56SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
57; SPIR-V
58; Version: 1.0
59; Generator: Khronos SPIR-V Tools Assembler; 0
60; Bound: 45
61; Schema: 0
62               OpCapability Shader
63          %1 = OpExtInstImport "GLSL.std.450"
64               OpMemoryModel Logical GLSL450
65               OpEntryPoint Fragment %2 "main" %3 %4
66               OpExecutionMode %2 OriginUpperLeft
67               OpSource ESSL 310
68               OpName %2 "main"
69               OpName %3 "gl_FragCoord"
70               OpName %4 "_GLF_color"
71               OpName %5 "buf0"
72               OpMemberName %5 0 "injectionSwitch"
73               OpName %6 ""
74               OpDecorate %3 BuiltIn FragCoord
75               OpDecorate %4 Location 0
76               OpMemberDecorate %5 0 Offset 0
77               OpDecorate %5 Block
78               OpDecorate %6 DescriptorSet 0
79               OpDecorate %6 Binding 0
80          %7 = OpTypeVoid
81          %8 = OpTypeFunction %7
82          %9 = OpTypeFloat 32
83         %10 = OpTypeVector %9 4
84         %11 = OpTypePointer Input %10
85          %3 = OpVariable %11 Input
86         %12 = OpTypeInt 32 0
87         %13 = OpConstant %12 0
88         %14 = OpTypePointer Input %9
89         %15 = OpConstant %9 10
90         %16 = OpTypeBool
91         %17 = OpTypePointer Output %10
92          %4 = OpVariable %17 Output
93         %18 = OpConstant %9 1
94         %19 = OpConstant %9 0
95         %20 = OpConstantComposite %10 %18 %19 %19 %18
96         %21 = OpTypeVector %9 2
97          %5 = OpTypeStruct %21
98         %22 = OpTypePointer Uniform %5
99          %6 = OpVariable %22 Uniform
100         %23 = OpTypeInt 32 1
101         %24 = OpConstant %23 0
102         %25 = OpTypePointer Uniform %9
103          %2 = OpFunction %7 None %8
104         %26 = OpLabel
105               OpBranch %27
106         %27 = OpLabel
107               OpLoopMerge %28 %29 None
108               OpBranch %30
109         %30 = OpLabel
110         %31 = OpAccessChain %14 %3 %13
111         %32 = OpLoad %9 %31
112         %33 = OpFOrdLessThan %16 %32 %15
113               OpSelectionMerge %34 None
114               OpBranchConditional %33 %35 %34
115         %35 = OpLabel
116               OpStore %4 %20
117               OpBranch %28
118         %34 = OpLabel
119         %36 = OpAccessChain %25 %6 %24 %13
120         %37 = OpLoad %9 %36
121         %38 = OpConvertFToS %23 %37
122               OpSelectionMerge %39 None
123               OpSwitch %38 %39 0 %40
124         %40 = OpLabel
125               OpBranch %41
126         %41 = OpLabel
127               OpLoopMerge %42 %43 None
128               OpBranch %44
129         %44 = OpLabel
130               OpKill
131         %43 = OpLabel
132               OpBranch %41
133         %42 = OpLabel
134               OpUnreachable
135         %39 = OpLabel
136               OpStore %4 %20
137               OpBranch %28
138         %29 = OpLabel
139               OpBranch %27
140         %28 = OpLabel
141               OpReturn
142               OpFunctionEnd
143END
144
145# uniforms for variant
146
147# injectionSwitch
148BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
149 0.0 1.0
150END
151
152BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
153
154PIPELINE 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
160END
161CLEAR_COLOR variant_pipeline 0 0 0 255
162
163CLEAR variant_pipeline
164RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
165
166EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255
167