1#!amber
2
3# Copyright 2021 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 the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific NIR code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28#
29# precision highp int;
30# precision highp float;
31#
32# layout(location = 0) out vec4 _GLF_color;
33#
34# void main()
35# {
36#     mat2 m = mat2(1, 2, 3, 4);
37#
38#     if (transpose(m) * transpose(m) == transpose(m * m))
39#         _GLF_color = vec4(1, 0, 0, 1);
40#     else
41#         _GLF_color = vec4(0);
42# }
43SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
44; SPIR-V
45; Version: 1.0
46; Generator: Khronos Glslang Reference Front End; 10
47; Bound: 47
48; Schema: 0
49               OpCapability Shader
50          %1 = OpExtInstImport "GLSL.std.450"
51               OpMemoryModel Logical GLSL450
52               OpEntryPoint Fragment %4 "main" %42
53               OpExecutionMode %4 OriginUpperLeft
54               OpSource ESSL 320
55               OpName %4 "main"
56               OpName %10 "m"
57               OpName %42 "_GLF_color"
58               OpDecorate %42 Location 0
59          %2 = OpTypeVoid
60          %3 = OpTypeFunction %2
61          %6 = OpTypeFloat 32
62          %7 = OpTypeVector %6 2
63          %8 = OpTypeMatrix %7 2
64          %9 = OpTypePointer Function %8
65         %11 = OpConstant %6 1
66         %12 = OpConstant %6 2
67         %13 = OpConstantComposite %7 %11 %12
68         %14 = OpConstant %6 3
69         %15 = OpConstant %6 4
70         %16 = OpConstantComposite %7 %14 %15
71         %17 = OpConstantComposite %8 %13 %16
72         %27 = OpTypeBool
73         %30 = OpTypeVector %27 2
74         %40 = OpTypeVector %6 4
75         %41 = OpTypePointer Output %40
76         %42 = OpVariable %41 Output
77         %43 = OpConstant %6 0
78         %44 = OpConstantComposite %40 %11 %43 %43 %11
79         %46 = OpConstantComposite %40 %43 %43 %43 %43
80          %4 = OpFunction %2 None %3
81          %5 = OpLabel
82         %10 = OpVariable %9 Function
83               OpStore %10 %17
84         %18 = OpLoad %8 %10
85         %19 = OpTranspose %8 %18
86         %20 = OpLoad %8 %10
87         %21 = OpTranspose %8 %20
88         %22 = OpMatrixTimesMatrix %8 %19 %21
89         %23 = OpLoad %8 %10
90         %24 = OpLoad %8 %10
91         %25 = OpMatrixTimesMatrix %8 %23 %24
92         %26 = OpTranspose %8 %25
93         %28 = OpCompositeExtract %7 %22 0
94         %29 = OpCompositeExtract %7 %26 0
95         %31 = OpFOrdEqual %30 %28 %29
96         %32 = OpAll %27 %31
97         %33 = OpCompositeExtract %7 %22 1
98         %34 = OpCompositeExtract %7 %26 1
99         %35 = OpFOrdEqual %30 %33 %34
100         %36 = OpAll %27 %35
101         %37 = OpLogicalAnd %27 %32 %36
102               OpSelectionMerge %39 None
103               OpBranchConditional %37 %38 %45
104         %38 = OpLabel
105               OpStore %42 %44
106               OpBranch %39
107         %45 = OpLabel
108               OpStore %42 %46
109               OpBranch %39
110         %39 = OpLabel
111               OpReturn
112               OpFunctionEnd
113END
114
115
116BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
117
118PIPELINE graphics variant_pipeline
119  ATTACH variant_vertex_shader
120  ATTACH variant_fragment_shader
121  FRAMEBUFFER_SIZE 256 256
122  BIND BUFFER variant_framebuffer AS color LOCATION 0
123END
124CLEAR_COLOR variant_pipeline 0 0 0 255
125
126CLEAR variant_pipeline
127RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
128
129EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
130