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 fast idiv code path
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# #define _int_0 _GLF_uniform_int_values[0]
29# #define _int_1000 _GLF_uniform_int_values[1]
30# #define _int_1 _GLF_uniform_int_values[2]
31#
32# precision highp int;
33#
34# precision highp float;
35#
36# // Contents of _GLF_uniform_int_values: [0, 1000, 1]
37# layout(set = 0, binding = 0) uniform buf0
38# {
39#     int _GLF_uniform_int_values[3];
40# };
41#
42# layout(location = 0) out vec4 _GLF_color;
43#
44# void main()
45# {
46#     int a = _int_1000;
47#
48#     // Always true.
49#     if((a / ivec2(_int_1, 63677)).y == _int_0)
50#     {
51#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
52#     }
53#     else
54#     {
55#         _GLF_color = vec4(_int_0);
56#     }
57# }
58SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
59; SPIR-V
60; Version: 1.0
61; Generator: Khronos Glslang Reference Front End; 10
62; Bound: 59
63; Schema: 0
64               OpCapability Shader
65          %1 = OpExtInstImport "GLSL.std.450"
66               OpMemoryModel Logical GLSL450
67               OpEntryPoint Fragment %4 "main" %40
68               OpExecutionMode %4 OriginUpperLeft
69               OpSource ESSL 320
70               OpName %4 "main"
71               OpName %8 "a"
72               OpName %12 "buf0"
73               OpMemberName %12 0 "_GLF_uniform_int_values"
74               OpName %14 ""
75               OpName %40 "_GLF_color"
76               OpDecorate %11 ArrayStride 16
77               OpMemberDecorate %12 0 Offset 0
78               OpDecorate %12 Block
79               OpDecorate %14 DescriptorSet 0
80               OpDecorate %14 Binding 0
81               OpDecorate %40 Location 0
82          %2 = OpTypeVoid
83          %3 = OpTypeFunction %2
84          %6 = OpTypeInt 32 1
85          %7 = OpTypePointer Function %6
86          %9 = OpTypeInt 32 0
87         %10 = OpConstant %9 3
88         %11 = OpTypeArray %6 %10
89         %12 = OpTypeStruct %11
90         %13 = OpTypePointer Uniform %12
91         %14 = OpVariable %13 Uniform
92         %15 = OpConstant %6 0
93         %16 = OpConstant %6 1
94         %17 = OpTypePointer Uniform %6
95         %21 = OpConstant %6 2
96         %24 = OpConstant %6 63677
97         %25 = OpTypeVector %6 2
98         %29 = OpConstant %9 1
99         %33 = OpTypeBool
100         %37 = OpTypeFloat 32
101         %38 = OpTypeVector %37 4
102         %39 = OpTypePointer Output %38
103         %40 = OpVariable %39 Output
104          %4 = OpFunction %2 None %3
105          %5 = OpLabel
106          %8 = OpVariable %7 Function
107         %18 = OpAccessChain %17 %14 %15 %16
108         %19 = OpLoad %6 %18
109               OpStore %8 %19
110         %20 = OpLoad %6 %8
111         %22 = OpAccessChain %17 %14 %15 %21
112         %23 = OpLoad %6 %22
113         %26 = OpCompositeConstruct %25 %23 %24
114         %27 = OpCompositeConstruct %25 %20 %20
115         %28 = OpSDiv %25 %27 %26
116         %30 = OpCompositeExtract %6 %28 1
117         %31 = OpAccessChain %17 %14 %15 %15
118         %32 = OpLoad %6 %31
119         %34 = OpIEqual %33 %30 %32
120               OpSelectionMerge %36 None
121               OpBranchConditional %34 %35 %54
122         %35 = OpLabel
123         %41 = OpAccessChain %17 %14 %15 %21
124         %42 = OpLoad %6 %41
125         %43 = OpConvertSToF %37 %42
126         %44 = OpAccessChain %17 %14 %15 %15
127         %45 = OpLoad %6 %44
128         %46 = OpConvertSToF %37 %45
129         %47 = OpAccessChain %17 %14 %15 %15
130         %48 = OpLoad %6 %47
131         %49 = OpConvertSToF %37 %48
132         %50 = OpAccessChain %17 %14 %15 %21
133         %51 = OpLoad %6 %50
134         %52 = OpConvertSToF %37 %51
135         %53 = OpCompositeConstruct %38 %43 %46 %49 %52
136               OpStore %40 %53
137               OpBranch %36
138         %54 = OpLabel
139         %55 = OpAccessChain %17 %14 %15 %15
140         %56 = OpLoad %6 %55
141         %57 = OpConvertSToF %37 %56
142         %58 = OpCompositeConstruct %38 %57 %57 %57 %57
143               OpStore %40 %58
144               OpBranch %36
145         %36 = OpLabel
146               OpReturn
147               OpFunctionEnd
148END
149
150# uniforms for variant
151
152# _GLF_uniform_int_values
153BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
154 0 1000 1
155END
156
157BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
158
159PIPELINE graphics variant_pipeline
160  ATTACH variant_vertex_shader
161  ATTACH variant_fragment_shader
162  FRAMEBUFFER_SIZE 256 256
163  BIND BUFFER variant_framebuffer AS color LOCATION 0
164  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
165END
166CLEAR_COLOR variant_pipeline 0 0 0 255
167
168CLEAR variant_pipeline
169RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
170
171EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
172