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
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 310 es
28# precision highp float;
29#
30# layout(location = 0) out vec4 _GLF_color;
31#
32# void main()
33# {
34#     if(dot(vec2(determinant(mat2(1)), 0), vec2(0)) == 0.0)
35#         _GLF_color = vec4(1, 0, 0, 1);
36#     else
37#         _GLF_color = vec4(0);
38# }
39SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
40; SPIR-V
41; Version: 1.0
42; Generator: Khronos Glslang Reference Front End; 8
43; Bound: 28
44; Schema: 0
45               OpCapability Shader
46          %1 = OpExtInstImport "GLSL.std.450"
47               OpMemoryModel Logical GLSL450
48               OpEntryPoint Fragment %4 "main" %24
49               OpExecutionMode %4 OriginUpperLeft
50               OpSource ESSL 310
51               OpName %4 "main"
52               OpName %24 "_GLF_color"
53               OpDecorate %24 Location 0
54          %2 = OpTypeVoid
55          %3 = OpTypeFunction %2
56          %6 = OpTypeFloat 32
57          %7 = OpTypeVector %6 2
58          %8 = OpTypeMatrix %7 2
59          %9 = OpConstant %6 1
60         %10 = OpConstant %6 0
61         %11 = OpConstantComposite %7 %9 %10
62         %12 = OpConstantComposite %7 %10 %9
63         %13 = OpConstantComposite %8 %11 %12
64         %16 = OpConstantComposite %7 %10 %10
65         %18 = OpTypeBool
66         %22 = OpTypeVector %6 4
67         %23 = OpTypePointer Output %22
68         %24 = OpVariable %23 Output
69         %25 = OpConstantComposite %22 %9 %10 %10 %9
70         %27 = OpConstantComposite %22 %10 %10 %10 %10
71          %4 = OpFunction %2 None %3
72          %5 = OpLabel
73         %14 = OpExtInst %6 %1 Determinant %13
74         %15 = OpCompositeConstruct %7 %14 %10
75         %17 = OpDot %6 %15 %16
76         %19 = OpFOrdEqual %18 %17 %10
77               OpSelectionMerge %21 None
78               OpBranchConditional %19 %20 %26
79         %20 = OpLabel
80               OpStore %24 %25
81               OpBranch %21
82         %26 = OpLabel
83               OpStore %24 %27
84               OpBranch %21
85         %21 = OpLabel
86               OpReturn
87               OpFunctionEnd
88END
89
90
91BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
92
93PIPELINE graphics variant_pipeline
94  ATTACH variant_vertex_shader
95  ATTACH variant_fragment_shader
96  FRAMEBUFFER_SIZE 256 256
97  BIND BUFFER variant_framebuffer AS color LOCATION 0
98END
99CLEAR_COLOR variant_pipeline 0 0 0 255
100
101CLEAR variant_pipeline
102RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
103
104EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
105