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 an array of matrices and distance.
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;
34 # if (gl_FragCoord.x < 10.0) {
35 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
38 # mat4 m[4] = mat4[](mat4(1.0), mat4(1.0), mat4(1.0), mat4(1.0));
39 # for(int i = 0; i < 4; i ++) {
41 # for(int j = 0; j < 4; j ++) {
46 # vec2 v = m[j][i].xy;
47 # if(distance(vec2(1.0), v) < 1.0) {
48 # _GLF_color = vec4(1.0);
55 SHADER vertex variant_vertex_shader PASSTHROUGH
57 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
60 ; Generator: Khronos SPIR-V Tools Assembler; 0
64 %1 = OpExtInstImport "GLSL.std.450"
65 OpMemoryModel Logical GLSL450
66 OpEntryPoint Fragment %2 "main" %3 %4
67 OpExecutionMode %2 OriginUpperLeft
70 OpName %3 "gl_FragCoord"
71 OpName %4 "_GLF_color"
73 OpDecorate %3 BuiltIn FragCoord
74 OpDecorate %4 Location 0
76 %7 = OpTypeFunction %6
78 %9 = OpTypeVector %8 4
79 %10 = OpTypePointer Input %9
80 %3 = OpVariable %10 Input
82 %12 = OpConstant %11 0
83 %13 = OpTypePointer Input %8
84 %14 = OpConstant %8 10
86 %16 = OpTypePointer Output %9
87 %4 = OpVariable %16 Output
90 %19 = OpConstantComposite %9 %17 %18 %18 %17
91 %20 = OpTypeMatrix %9 4
92 %21 = OpConstant %11 4
93 %22 = OpTypeArray %20 %21
94 %23 = OpTypePointer Function %22
95 %24 = OpConstantComposite %9 %17 %18 %18 %18
96 %25 = OpConstantComposite %9 %18 %17 %18 %18
97 %26 = OpConstantComposite %9 %18 %18 %17 %18
98 %27 = OpConstantComposite %9 %18 %18 %18 %17
99 %28 = OpConstantComposite %20 %24 %25 %26 %27
100 %29 = OpConstantComposite %22 %28 %28 %28 %28
102 %31 = OpConstant %30 0
103 %32 = OpConstant %30 4
104 %33 = OpConstant %30 2
105 %34 = OpConstant %30 1
106 %35 = OpTypeVector %8 2
107 %36 = OpTypePointer Function %9
108 %37 = OpConstantComposite %35 %17 %17
109 %38 = OpConstantComposite %9 %17 %17 %17 %17
110 %2 = OpFunction %6 None %7
112 %5 = OpVariable %23 Function
115 OpLoopMerge %41 %42 None
118 %44 = OpAccessChain %13 %3 %12
120 %46 = OpFOrdLessThan %15 %45 %14
121 OpSelectionMerge %47 None
122 OpBranchConditional %46 %48 %47
130 %50 = OpPhi %30 %31 %47 %51 %52
131 %53 = OpSLessThan %15 %50 %32
132 OpLoopMerge %54 %52 None
133 OpBranchConditional %53 %55 %54
137 %57 = OpPhi %30 %31 %55 %58 %59
138 %60 = OpPhi %30 %31 %55 %61 %59
139 %62 = OpSLessThan %15 %60 %32
140 OpLoopMerge %63 %59 None
141 OpBranchConditional %62 %64 %63
143 %65 = OpSGreaterThanEqual %15 %57 %33
144 OpSelectionMerge %66 None
145 OpBranchConditional %65 %67 %66
149 %58 = OpIAdd %30 %57 %34
150 %68 = OpAccessChain %36 %5 %60 %50
152 %70 = OpVectorShuffle %35 %69 %69 0 1
153 %71 = OpExtInst %8 %1 Distance %37 %70
154 %72 = OpFOrdLessThan %15 %71 %17
155 OpSelectionMerge %73 None
156 OpBranchConditional %72 %74 %59
163 %61 = OpIAdd %30 %60 %34
168 %51 = OpIAdd %30 %50 %34
179 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
181 PIPELINE graphics variant_pipeline
182 ATTACH variant_vertex_shader
183 ATTACH variant_fragment_shader
184 FRAMEBUFFER_SIZE 256 256
185 BIND BUFFER variant_framebuffer AS color LOCATION 0
187 CLEAR_COLOR variant_pipeline 0 0 0 255
189 CLEAR variant_pipeline
190 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
192 EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255