• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bug found by the GraphicsFuzz project.
19
20# Short description: A fragment shader with struct array and always true if
21
22# The test passes because the shader always writes the color red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28# precision highp float;
29#
30# precision highp int;
31#
32# layout(location = 0) out vec4 _GLF_color;
33# layout(set = 0, binding = 0) uniform buf0
34# {
35#     vec2 injectionSwitch;   // x == 0.0, y == 1.0
36# };
37# struct struct_base
38# {
39#     int data;
40#     int leftIndex;
41#     int rightIndex;
42# };
43#
44# struct_base struct_array[3] = struct_base[3](struct_base(1, 1, 1), struct_base(1, 1, 1), struct_base(1, 1, 1));
45#
46#
47# void main()
48# {
49#     int index = 1;
50#     struct_array[1].rightIndex = 1;
51#     // Always true.
52#     if (struct_array[1].leftIndex == 1)
53#     {
54#         // index == 1
55#         index = struct_array[int(injectionSwitch.x)].rightIndex;
56#     }
57#     else
58#     {
59#         // index == 1
60#         index = struct_array[int(injectionSwitch.y)].leftIndex;
61#     }
62#     // Always true.
63#     if(struct_array[1].leftIndex == 1)
64#     {
65#         _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
66#     }
67#     else
68#     {
69#         _GLF_color = vec4(1.0);
70#     }
71# }
72SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
73; SPIR-V
74; Version: 1.0
75; Generator: Khronos Glslang Reference Front End; 10
76; Bound: 60
77; Schema: 0
78               OpCapability Shader
79          %1 = OpExtInstImport "GLSL.std.450"
80               OpMemoryModel Logical GLSL450
81               OpEntryPoint Fragment %4 "main" %54
82               OpExecutionMode %4 OriginUpperLeft
83               OpSource ESSL 320
84               OpName %4 "main"
85               OpName %7 "struct_base"
86               OpMemberName %7 0 "data"
87               OpMemberName %7 1 "leftIndex"
88               OpMemberName %7 2 "rightIndex"
89               OpName %12 "struct_array"
90               OpName %17 "index"
91               OpName %29 "buf0"
92               OpMemberName %29 0 "injectionSwitch"
93               OpName %31 ""
94               OpName %54 "_GLF_color"
95               OpMemberDecorate %29 0 Offset 0
96               OpDecorate %29 Block
97               OpDecorate %31 DescriptorSet 0
98               OpDecorate %31 Binding 0
99               OpDecorate %54 Location 0
100          %2 = OpTypeVoid
101          %3 = OpTypeFunction %2
102          %6 = OpTypeInt 32 1
103          %7 = OpTypeStruct %6 %6 %6
104          %8 = OpTypeInt 32 0
105          %9 = OpConstant %8 3
106         %10 = OpTypeArray %7 %9
107         %11 = OpTypePointer Private %10
108         %12 = OpVariable %11 Private
109         %13 = OpConstant %6 1
110         %14 = OpConstantComposite %7 %13 %13 %13
111         %15 = OpConstantComposite %10 %14 %14 %14
112         %16 = OpTypePointer Function %6
113         %18 = OpConstant %6 2
114         %19 = OpTypePointer Private %6
115         %23 = OpTypeBool
116         %27 = OpTypeFloat 32
117         %28 = OpTypeVector %27 2
118         %29 = OpTypeStruct %28
119         %30 = OpTypePointer Uniform %29
120         %31 = OpVariable %30 Uniform
121         %32 = OpConstant %6 0
122         %33 = OpConstant %8 0
123         %34 = OpTypePointer Uniform %27
124         %41 = OpConstant %8 1
125         %52 = OpTypeVector %27 4
126         %53 = OpTypePointer Output %52
127         %54 = OpVariable %53 Output
128         %55 = OpConstant %27 1
129         %56 = OpConstant %27 0
130         %57 = OpConstantComposite %52 %55 %56 %56 %55
131         %59 = OpConstantComposite %52 %55 %55 %55 %55
132          %4 = OpFunction %2 None %3
133          %5 = OpLabel
134         %17 = OpVariable %16 Function
135               OpStore %12 %15
136               OpStore %17 %13
137         %20 = OpAccessChain %19 %12 %13 %18
138               OpStore %20 %13
139         %21 = OpAccessChain %19 %12 %13 %13
140         %22 = OpLoad %6 %21
141         %24 = OpIEqual %23 %22 %13
142               OpSelectionMerge %26 None
143               OpBranchConditional %24 %25 %40
144         %25 = OpLabel
145         %35 = OpAccessChain %34 %31 %32 %33
146         %36 = OpLoad %27 %35
147         %37 = OpConvertFToS %6 %36
148         %38 = OpAccessChain %19 %12 %37 %18
149         %39 = OpLoad %6 %38
150               OpStore %17 %39
151               OpBranch %26
152         %40 = OpLabel
153         %42 = OpAccessChain %34 %31 %32 %41
154         %43 = OpLoad %27 %42
155         %44 = OpConvertFToS %6 %43
156         %45 = OpAccessChain %19 %12 %44 %13
157         %46 = OpLoad %6 %45
158               OpStore %17 %46
159               OpBranch %26
160         %26 = OpLabel
161         %47 = OpAccessChain %19 %12 %13 %13
162         %48 = OpLoad %6 %47
163         %49 = OpIEqual %23 %48 %13
164               OpSelectionMerge %51 None
165               OpBranchConditional %49 %50 %58
166         %50 = OpLabel
167               OpStore %54 %57
168               OpBranch %51
169         %58 = OpLabel
170               OpStore %54 %59
171               OpBranch %51
172         %51 = OpLabel
173               OpReturn
174               OpFunctionEnd
175END
176
177# uniforms for variant
178
179# injectionSwitch
180BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
181 0.0 1.0
182END
183
184BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
185
186PIPELINE graphics variant_pipeline
187  ATTACH variant_vertex_shader
188  ATTACH variant_fragment_shader
189  FRAMEBUFFER_SIZE 256 256
190  BIND BUFFER variant_framebuffer AS color LOCATION 0
191  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
192END
193CLEAR_COLOR variant_pipeline 0 0 0 255
194
195CLEAR variant_pipeline
196RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
197
198EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
199