3 # Copyright 2020 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a bug found by the GraphicsFuzz project.
20 # Short description: A fragment shader with struct array and always true if
22 # The test passes because the shader always writes the color red.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # precision highp int;
32 # layout(location = 0) out vec4 _GLF_color;
33 # layout(set = 0, binding = 0) uniform buf0
35 # vec2 injectionSwitch; // x == 0.0, y == 1.0
44 # struct_base struct_array[3] = struct_base[3](struct_base(1, 1, 1), struct_base(1, 1, 1), struct_base(1, 1, 1));
50 # struct_array[1].rightIndex = 1;
52 # if (struct_array[1].leftIndex == 1)
55 # index = struct_array[int(injectionSwitch.x)].rightIndex;
60 # index = struct_array[int(injectionSwitch.y)].leftIndex;
63 # if(struct_array[1].leftIndex == 1)
65 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
69 # _GLF_color = vec4(1.0);
72 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
75 ; Generator: Khronos Glslang Reference Front End; 10
79 %1 = OpExtInstImport "GLSL.std.450"
80 OpMemoryModel Logical GLSL450
81 OpEntryPoint Fragment %4 "main" %54
82 OpExecutionMode %4 OriginUpperLeft
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"
92 OpMemberName %29 0 "injectionSwitch"
94 OpName %54 "_GLF_color"
95 OpMemberDecorate %29 0 Offset 0
97 OpDecorate %31 DescriptorSet 0
98 OpDecorate %31 Binding 0
99 OpDecorate %54 Location 0
101 %3 = OpTypeFunction %2
103 %7 = OpTypeStruct %6 %6 %6
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
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
134 %17 = OpVariable %16 Function
137 %20 = OpAccessChain %19 %12 %13 %18
139 %21 = OpAccessChain %19 %12 %13 %13
141 %24 = OpIEqual %23 %22 %13
142 OpSelectionMerge %26 None
143 OpBranchConditional %24 %25 %40
145 %35 = OpAccessChain %34 %31 %32 %33
147 %37 = OpConvertFToS %6 %36
148 %38 = OpAccessChain %19 %12 %37 %18
153 %42 = OpAccessChain %34 %31 %32 %41
155 %44 = OpConvertFToS %6 %43
156 %45 = OpAccessChain %19 %12 %44 %13
161 %47 = OpAccessChain %19 %12 %13 %13
163 %49 = OpIEqual %23 %48 %13
164 OpSelectionMerge %51 None
165 OpBranchConditional %49 %50 %58
177 # uniforms for variant
180 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> STD140 DATA
184 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
186 PIPELINE 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
193 CLEAR_COLOR variant_pipeline 0 0 0 255
195 CLEAR variant_pipeline
196 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
198 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255