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 coverage-gap found by GraphicsFuzz.
19
20# Short description: A fragment shader that covers a specific const folding rule path.
21
22# The test passes because shader always writes red.
23
24# Optimized using spirv-opt with the following arguments:
25# '-O'
26# spirv-opt commit hash: 9215c1b7df0029f27807e8c8d7ec80532ce90a87
27
28
29
30SHADER vertex variant_vertex_shader PASSTHROUGH
31
32# variant_fragment_shader is derived from the following GLSL:
33# #version 310 es
34# precision highp float;
35#
36# layout(location = 0) out vec4 _GLF_color;
37#
38# void main()
39# {
40#     vec2 v;
41#
42#     for(int i = 2; i < 3; i++)
43#     {
44#         vec4 tmp = vec4(0);
45#         tmp.xy = vec2(1.0, float(i));
46#         v = tmp.xy;
47#     }
48#
49#     // If condition is always false.
50#     if (v.x != 1.0 || v.y != 2.0)
51#         _GLF_color = vec4(0);
52#     else
53#         _GLF_color = vec4(1, 0, 0, 1);
54# }
55SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
56; SPIR-V
57; Version: 1.0
58; Generator: Khronos Glslang Reference Front End; 8
59; Bound: 69
60; Schema: 0
61               OpCapability Shader
62          %1 = OpExtInstImport "GLSL.std.450"
63               OpMemoryModel Logical GLSL450
64               OpEntryPoint Fragment %4 "main" %57
65               OpExecutionMode %4 OriginUpperLeft
66               OpSource ESSL 310
67               OpName %4 "main"
68               OpName %57 "_GLF_color"
69               OpDecorate %38 RelaxedPrecision
70               OpDecorate %57 Location 0
71               OpDecorate %62 RelaxedPrecision
72          %2 = OpTypeVoid
73          %3 = OpTypeFunction %2
74          %6 = OpTypeInt 32 1
75          %9 = OpConstant %6 2
76         %16 = OpConstant %6 3
77         %17 = OpTypeBool
78         %19 = OpTypeFloat 32
79         %20 = OpTypeVector %19 4
80         %23 = OpConstant %19 0
81         %24 = OpConstantComposite %20 %23 %23 %23 %23
82         %25 = OpConstant %19 1
83         %28 = OpTypeVector %19 2
84         %37 = OpConstant %6 1
85         %51 = OpConstant %19 2
86         %56 = OpTypePointer Output %20
87         %57 = OpVariable %56 Output
88         %59 = OpConstantComposite %20 %25 %23 %23 %25
89         %64 = OpUndef %28
90         %68 = OpConstantNull %20
91          %4 = OpFunction %2 None %3
92          %5 = OpLabel
93               OpBranch %10
94         %10 = OpLabel
95         %63 = OpPhi %28 %64 %5 %35 %11
96         %62 = OpPhi %6 %9 %5 %38 %11
97         %18 = OpSLessThan %17 %62 %16
98               OpLoopMerge %12 %11 None
99               OpBranchConditional %18 %11 %12
100         %11 = OpLabel
101         %27 = OpConvertSToF %19 %62
102         %29 = OpCompositeConstruct %28 %25 %27
103         %35 = OpVectorShuffle %28 %29 %68 0 1
104         %38 = OpIAdd %6 %62 %37
105               OpBranch %10
106         %12 = OpLabel
107         %43 = OpCompositeExtract %19 %63 0
108         %44 = OpFOrdNotEqual %17 %43 %25
109         %45 = OpLogicalNot %17 %44
110               OpSelectionMerge %47 None
111               OpBranchConditional %45 %46 %47
112         %46 = OpLabel
113         %50 = OpCompositeExtract %19 %63 1
114         %52 = OpFOrdNotEqual %17 %50 %51
115               OpBranch %47
116         %47 = OpLabel
117         %53 = OpPhi %17 %44 %12 %52 %46
118               OpSelectionMerge %55 None
119               OpBranchConditional %53 %54 %58
120         %54 = OpLabel
121               OpStore %57 %24
122               OpBranch %55
123         %58 = OpLabel
124               OpStore %57 %59
125               OpBranch %55
126         %55 = OpLabel
127               OpReturn
128               OpFunctionEnd
129END
130
131
132BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
133
134PIPELINE graphics variant_pipeline
135  ATTACH variant_vertex_shader
136  ATTACH variant_fragment_shader
137  FRAMEBUFFER_SIZE 256 256
138  BIND BUFFER variant_framebuffer AS color LOCATION 0
139END
140CLEAR_COLOR variant_pipeline 0 0 0 255
141
142CLEAR variant_pipeline
143RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
144
145EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
146