• 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 an array of matrices and has deep control flow.
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# void main() {
33#  if (gl_FragCoord.x < 10.0) {
34#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
35#   return;
36#  }
37#  if(true) {
38#   if(true) {
39#    if(true) {
40#     mat4 one = mat4(
41#         1.0, 1.0, 1.0, 1.0,
42#         1.0, 1.0, 1.0, 1.0,
43#         1.0, 1.0, 1.0, 1.0,
44#         1.0, 1.0, 1.0, 1.0
45#       );
46#     mat4 m[4] = mat4[](one, one, one, one);
47#     for(int i = 0; i < 4; i ++) {
48#      for(int j = 0; j < 4; j ++) {
49#       vec2 v = vec2(1.0) / m[j < 4 ? 1 : 0][i].w;
50#       if(distance(vec2(1.0), v) < 1.0) {
51#        _GLF_color = vec4(1.0);
52#       }
53#      }
54#     }
55#    }
56#   }
57#  }
58# }
59
60SHADER vertex variant_vertex_shader PASSTHROUGH
61
62SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
63; SPIR-V
64; Version: 1.0
65; Generator: Khronos SPIR-V Tools Assembler; 0
66; Bound: 68
67; Schema: 0
68               OpCapability Shader
69          %1 = OpExtInstImport "GLSL.std.450"
70               OpMemoryModel Logical GLSL450
71               OpEntryPoint Fragment %2 "main" %3 %4
72               OpExecutionMode %2 OriginUpperLeft
73               OpSource ESSL 310
74               OpName %2 "main"
75               OpName %3 "gl_FragCoord"
76               OpName %4 "_GLF_color"
77               OpName %5 "m"
78               OpDecorate %3 BuiltIn FragCoord
79               OpDecorate %4 Location 0
80          %6 = OpTypeVoid
81          %7 = OpTypeFunction %6
82          %8 = OpTypeFloat 32
83          %9 = OpTypeVector %8 4
84         %10 = OpTypePointer Input %9
85          %3 = OpVariable %10 Input
86         %11 = OpTypeInt 32 0
87         %12 = OpConstant %11 0
88         %13 = OpTypePointer Input %8
89         %14 = OpConstant %8 10
90         %15 = OpTypeBool
91         %16 = OpTypePointer Output %9
92          %4 = OpVariable %16 Output
93         %17 = OpConstant %8 1
94         %18 = OpConstant %8 0
95         %19 = OpConstantComposite %9 %17 %18 %18 %17
96         %20 = OpTypeMatrix %9 4
97         %21 = OpConstantComposite %9 %17 %17 %17 %17
98         %22 = OpConstantComposite %20 %21 %21 %21 %21
99         %23 = OpConstant %11 4
100         %24 = OpTypeArray %20 %23
101         %25 = OpTypePointer Function %24
102         %26 = OpTypeInt 32 1
103         %27 = OpConstant %26 0
104         %28 = OpConstant %26 4
105         %29 = OpTypeVector %8 2
106         %30 = OpConstantComposite %29 %17 %17
107         %31 = OpConstant %26 1
108         %32 = OpConstant %11 3
109         %33 = OpTypePointer Function %8
110         %34 = OpConstantComposite %24 %22 %22 %22 %22
111          %2 = OpFunction %6 None %7
112         %35 = OpLabel
113          %5 = OpVariable %25 Function
114               OpBranch %36
115         %36 = OpLabel
116               OpLoopMerge %37 %38 None
117               OpBranch %39
118         %39 = OpLabel
119         %40 = OpAccessChain %13 %3 %12
120         %41 = OpLoad %8 %40
121         %42 = OpFOrdLessThan %15 %41 %14
122               OpSelectionMerge %43 None
123               OpBranchConditional %42 %44 %43
124         %44 = OpLabel
125               OpStore %4 %19
126               OpBranch %37
127         %43 = OpLabel
128               OpStore %5 %34
129               OpBranch %45
130         %45 = OpLabel
131         %46 = OpPhi %26 %27 %43 %47 %48
132         %49 = OpSLessThan %15 %46 %28
133               OpLoopMerge %50 %48 None
134               OpBranchConditional %49 %51 %50
135         %51 = OpLabel
136               OpBranch %52
137         %52 = OpLabel
138         %53 = OpPhi %26 %27 %51 %54 %55
139         %56 = OpSLessThan %15 %53 %28
140               OpLoopMerge %57 %55 None
141               OpBranchConditional %56 %58 %57
142         %58 = OpLabel
143         %59 = OpSelect %26 %56 %31 %27
144         %60 = OpAccessChain %33 %5 %59 %46 %32
145         %61 = OpLoad %8 %60
146         %62 = OpCompositeConstruct %29 %61 %61
147         %63 = OpFDiv %29 %30 %62
148         %64 = OpExtInst %8 %1 Distance %30 %63
149         %65 = OpFOrdLessThan %15 %64 %17
150               OpSelectionMerge %66 None
151               OpBranchConditional %65 %67 %55
152         %67 = OpLabel
153               OpStore %4 %21
154               OpBranch %55
155         %66 = OpLabel
156               OpBranch %55
157         %55 = OpLabel
158         %54 = OpIAdd %26 %53 %31
159               OpBranch %52
160         %57 = OpLabel
161               OpBranch %48
162         %48 = OpLabel
163         %47 = OpIAdd %26 %46 %31
164               OpBranch %45
165         %50 = OpLabel
166               OpBranch %37
167         %38 = OpLabel
168               OpBranch %36
169         %37 = OpLabel
170               OpReturn
171               OpFunctionEnd
172END
173
174
175
176BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
177
178PIPELINE graphics variant_pipeline
179  ATTACH variant_vertex_shader
180  ATTACH variant_fragment_shader
181  FRAMEBUFFER_SIZE 256 256
182  BIND BUFFER variant_framebuffer AS color LOCATION 0
183END
184CLEAR_COLOR variant_pipeline 0 0 0 255
185
186CLEAR variant_pipeline
187RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
188
189EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255
190