• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# A test for a bug found by GraphicsFuzz.
16# A fragment shader that uses FragCoord and somewhat complex control flow.
17# Derived from the following GLSL fragment shader.
18# We check that the top-left pixel is red. The test passes because _GLF_color is
19# initially set to red, all other writes to _GLF_color write red, and the discard
20# statement only executes for pixels with an x coordinate >= 10000000.
21
22# #version 310 es
23#
24# precision highp float;
25# precision highp int;
26#
27# layout(location=0) out vec4 _GLF_color;
28#
29# void main() {
30#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
31#   for (int i = 0; i < 1; i++) {
32#     if (int(gl_FragCoord.x) < 10000000) {
33#     } else {
34#
35#       if (int(gl_FragCoord.x) < 10000000) {
36#
37#         for (int j = 0; j < 1; j++) {
38#           for (int k = 0; k < 1; k++) {
39#             _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
40#           }
41#         }
42#         vec4 backup;
43#         for (int l = 0; l < 1; l++) {
44#           backup = vec4(1.0, 0.0, 0.0, 1.0);
45#         }
46#         _GLF_color = backup;
47#       } else {
48#         discard;
49#       }
50#     }
51#   }
52# }
53
54[vertex shader passthrough]
55
56[fragment shader spirv]
57; SPIR-V
58; Version: 1.0
59; Generator: Khronos Glslang Reference Front End; 7
60; Bound: 98
61; Schema: 0
62               OpCapability Shader
63          %1 = OpExtInstImport "GLSL.std.450"
64               OpMemoryModel Logical GLSL450
65               OpEntryPoint Fragment %main "main" %_GLF_color %gl_FragCoord
66               OpExecutionMode %main OriginUpperLeft
67               OpSource ESSL 310
68               OpName %main "main"
69               OpName %_GLF_color "_GLF_color"
70               OpName %gl_FragCoord "gl_FragCoord"
71               OpDecorate %_GLF_color Location 0
72               OpDecorate %gl_FragCoord BuiltIn FragCoord
73       %void = OpTypeVoid
74          %3 = OpTypeFunction %void
75      %float = OpTypeFloat 32
76    %v4float = OpTypeVector %float 4
77%_ptr_Output_v4float = OpTypePointer Output %v4float
78 %_GLF_color = OpVariable %_ptr_Output_v4float Output
79    %float_1 = OpConstant %float 1
80    %float_0 = OpConstant %float 0
81         %12 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
82        %int = OpTypeInt 32 1
83      %int_0 = OpConstant %int 0
84      %int_1 = OpConstant %int 1
85       %bool = OpTypeBool
86%_ptr_Input_v4float = OpTypePointer Input %v4float
87%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
88       %uint = OpTypeInt 32 0
89     %uint_0 = OpConstant %uint 0
90%_ptr_Input_float = OpTypePointer Input %float
91%int_10000000 = OpConstant %int 10000000
92         %88 = OpUndef %v4float
93       %main = OpFunction %void None %3
94          %5 = OpLabel
95               OpStore %_GLF_color %12
96               OpBranch %17
97         %17 = OpLabel
98         %87 = OpPhi %v4float %88 %5 %95 %37
99         %82 = OpPhi %int %int_0 %5 %81 %37
100         %25 = OpSLessThan %bool %82 %int_1
101               OpLoopMerge %19 %37 None
102               OpBranchConditional %25 %18 %19
103         %18 = OpLabel
104         %31 = OpAccessChain %_ptr_Input_float %gl_FragCoord %uint_0
105         %32 = OpLoad %float %31
106         %33 = OpConvertFToS %int %32
107         %35 = OpSLessThan %bool %33 %int_10000000
108               OpSelectionMerge %96 None
109               OpBranchConditional %35 %36 %38
110         %36 = OpLabel
111               OpBranch %37
112         %38 = OpLabel
113               OpSelectionMerge %44 None
114               OpBranchConditional %35 %43 %78
115         %43 = OpLabel
116               OpBranch %46
117         %46 = OpLabel
118         %83 = OpPhi %int %int_0 %43 %64 %56
119         %52 = OpSLessThan %bool %83 %int_1
120               OpLoopMerge %48 %56 None
121               OpBranchConditional %52 %47 %48
122         %47 = OpLabel
123               OpBranch %54
124         %54 = OpLabel
125         %89 = OpPhi %int %int_0 %47 %62 %55
126         %60 = OpSLessThan %bool %89 %int_1
127               OpLoopMerge %97 %55 None
128               OpBranchConditional %60 %55 %97
129         %55 = OpLabel
130               OpStore %_GLF_color %12
131         %62 = OpIAdd %int %89 %int_1
132               OpBranch %54
133         %97 = OpLabel
134               OpBranch %56
135         %56 = OpLabel
136         %64 = OpIAdd %int %83 %int_1
137               OpBranch %46
138         %48 = OpLabel
139               OpBranch %66
140         %66 = OpLabel
141         %85 = OpPhi %v4float %87 %48 %12 %67
142         %84 = OpPhi %int %int_0 %48 %76 %67
143         %72 = OpSLessThan %bool %84 %int_1
144               OpLoopMerge %68 %67 None
145               OpBranchConditional %72 %67 %68
146         %67 = OpLabel
147         %76 = OpIAdd %int %84 %int_1
148               OpBranch %66
149         %68 = OpLabel
150               OpStore %_GLF_color %85
151               OpBranch %44
152         %78 = OpLabel
153               OpKill
154         %44 = OpLabel
155               OpBranch %37
156         %96 = OpLabel
157               OpBranch %37
158         %37 = OpLabel
159         %95 = OpPhi %v4float %87 %36 %85 %44 %88 %96
160         %81 = OpIAdd %int %82 %int_1
161               OpBranch %17
162         %19 = OpLabel
163               OpReturn
164               OpFunctionEnd
165
166
167[test]
168draw rect -1 -1 2 2
169probe rgba (0, 0) (1, 0, 0, 1)
170