1#!amber
2
3# Copyright 2019 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
18# A test for a bug found by GraphicsFuzz.
19
20# Short description: A fragment shader with two loops and some matrices
21
22# The test passes because the fragment shader always writes red; the loops do nothing.
23# The second loop condition is always false.
24
25SHADER vertex variant_vertex_shader PASSTHROUGH
26
27# variant_fragment_shader is derived from the following GLSL:
28# #version 310 es
29# precision highp float;
30#
31# layout(location = 0) out vec4 _GLF_color;
32#
33# layout(set = 0, binding = 0) uniform buf0
34# {
35#   mat4 matrix_a_uni;
36# };
37# void main()
38# {
39#   vec4 matrix_b;
40#   vec4 matrix_u;
41#   for (
42#       int x = 4;
43#       x >= 1;
44#       x--)
45#   {
46#     matrix_u[x] = 1.0;
47#   }
48#   for (
49#       int b = 4;
50#       matrix_a_uni[0][0] < -1.0;
51#       b--)
52#   {
53#     matrix_b[b] = (b > 1 ? min(matrix_b, matrix_b) : matrix_u)[1];
54#   }
55#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
56# }
57SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
58; SPIR-V
59; Version: 1.0
60; Generator: Khronos Glslang Reference Front End; 7
61; Bound: 69
62; Schema: 0
63               OpCapability Shader
64          %1 = OpExtInstImport "GLSL.std.450"
65               OpMemoryModel Logical GLSL450
66               OpEntryPoint Fragment %4 "main" %66
67               OpExecutionMode %4 OriginUpperLeft
68               OpSource ESSL 310
69               OpName %4 "main"
70               OpName %8 "x"
71               OpName %22 "matrix_u"
72               OpName %29 "b"
73               OpName %36 "buf0"
74               OpMemberName %36 0 "matrix_a_uni"
75               OpName %38 ""
76               OpName %47 "matrix_b"
77               OpName %66 "_GLF_color"
78               OpDecorate %8 RelaxedPrecision
79               OpDecorate %15 RelaxedPrecision
80               OpDecorate %23 RelaxedPrecision
81               OpDecorate %27 RelaxedPrecision
82               OpDecorate %28 RelaxedPrecision
83               OpDecorate %29 RelaxedPrecision
84               OpMemberDecorate %36 0 ColMajor
85               OpMemberDecorate %36 0 Offset 0
86               OpMemberDecorate %36 0 MatrixStride 16
87               OpDecorate %36 Block
88               OpDecorate %38 DescriptorSet 0
89               OpDecorate %38 Binding 0
90               OpDecorate %48 RelaxedPrecision
91               OpDecorate %49 RelaxedPrecision
92               OpDecorate %63 RelaxedPrecision
93               OpDecorate %64 RelaxedPrecision
94               OpDecorate %66 Location 0
95          %2 = OpTypeVoid
96          %3 = OpTypeFunction %2
97          %6 = OpTypeInt 32 1
98          %7 = OpTypePointer Function %6
99          %9 = OpConstant %6 4
100         %16 = OpConstant %6 1
101         %17 = OpTypeBool
102         %19 = OpTypeFloat 32
103         %20 = OpTypeVector %19 4
104         %21 = OpTypePointer Function %20
105         %24 = OpConstant %19 1
106         %25 = OpTypePointer Function %19
107         %35 = OpTypeMatrix %20 4
108         %36 = OpTypeStruct %35
109         %37 = OpTypePointer Uniform %36
110         %38 = OpVariable %37 Uniform
111         %39 = OpConstant %6 0
112         %40 = OpTypeInt 32 0
113         %41 = OpConstant %40 0
114         %42 = OpTypePointer Uniform %19
115         %45 = OpConstant %19 -1
116         %59 = OpConstant %40 1
117         %65 = OpTypePointer Output %20
118         %66 = OpVariable %65 Output
119         %67 = OpConstant %19 0
120         %68 = OpConstantComposite %20 %24 %67 %67 %24
121          %4 = OpFunction %2 None %3
122          %5 = OpLabel
123          %8 = OpVariable %7 Function
124         %22 = OpVariable %21 Function
125         %29 = OpVariable %7 Function
126         %47 = OpVariable %21 Function
127         %51 = OpVariable %21 Function
128               OpStore %8 %9
129               OpBranch %10
130         %10 = OpLabel
131               OpLoopMerge %12 %13 None
132               OpBranch %14
133         %14 = OpLabel
134         %15 = OpLoad %6 %8
135         %18 = OpSGreaterThanEqual %17 %15 %16
136               OpBranchConditional %18 %11 %12
137         %11 = OpLabel
138         %23 = OpLoad %6 %8
139         %26 = OpAccessChain %25 %22 %23
140               OpStore %26 %24
141               OpBranch %13
142         %13 = OpLabel
143         %27 = OpLoad %6 %8
144         %28 = OpISub %6 %27 %16
145               OpStore %8 %28
146               OpBranch %10
147         %12 = OpLabel
148               OpStore %29 %9
149               OpBranch %30
150         %30 = OpLabel
151               OpLoopMerge %32 %33 None
152               OpBranch %34
153         %34 = OpLabel
154         %43 = OpAccessChain %42 %38 %39 %39 %41
155         %44 = OpLoad %19 %43
156         %46 = OpFOrdLessThan %17 %44 %45
157               OpBranchConditional %46 %31 %32
158         %31 = OpLabel
159         %48 = OpLoad %6 %29
160         %49 = OpLoad %6 %29
161         %50 = OpSGreaterThan %17 %49 %16
162               OpSelectionMerge %53 None
163               OpBranchConditional %50 %52 %57
164         %52 = OpLabel
165         %54 = OpLoad %20 %47
166         %55 = OpLoad %20 %47
167         %56 = OpExtInst %20 %1 FMin %54 %55
168               OpStore %51 %56
169               OpBranch %53
170         %57 = OpLabel
171         %58 = OpLoad %20 %22
172               OpStore %51 %58
173               OpBranch %53
174         %53 = OpLabel
175         %60 = OpAccessChain %25 %51 %59
176         %61 = OpLoad %19 %60
177         %62 = OpAccessChain %25 %47 %48
178               OpStore %62 %61
179               OpBranch %33
180         %33 = OpLabel
181         %63 = OpLoad %6 %29
182         %64 = OpISub %6 %63 %16
183               OpStore %29 %64
184               OpBranch %30
185         %32 = OpLabel
186               OpStore %66 %68
187               OpReturn
188               OpFunctionEnd
189END
190
191# uniforms for variant
192
193# matrix_a_uni
194BUFFER variant_matrix_a_uni DATA_TYPE mat4x4<float> DATA
195 1.0 5.0 3.0 7.0 9.0 6.0 7.0 8.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0
196END
197
198BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
199
200PIPELINE graphics variant_pipeline
201  ATTACH variant_vertex_shader
202  ATTACH variant_fragment_shader
203  FRAMEBUFFER_SIZE 256 256
204  BIND BUFFER variant_framebuffer AS color LOCATION 0
205  BIND BUFFER variant_matrix_a_uni AS uniform DESCRIPTOR_SET 0 BINDING 0
206END
207CLEAR_COLOR variant_pipeline 0 0 0 255
208
209CLEAR variant_pipeline
210RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
211
212EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
213