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