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 GraphicsFuzz.
20 # Short description: A fragment shader that uses a struct with an array of size one
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
26 # '--eliminate-dead-branches'
28 # '--inline-entry-points-exhaustive'
29 # '--eliminate-dead-functions'
30 # '--private-to-local'
31 # '--scalar-replacement=0'
35 # '--eliminate-dead-branches'
36 # '--simplify-instructions'
37 # '--scalar-replacement=0'
38 # '--eliminate-local-single-store'
40 # '--simplify-instructions'
41 # '--eliminate-dead-code-aggressive'
42 # '--eliminate-dead-branches'
44 # spirv-opt commit hash: dd3d91691f1e1dc4c0f42818756cf5e165c8918c
48 SHADER vertex variant_vertex_shader PASSTHROUGH
50 # variant_fragment_shader is derived from the following GLSL:
52 # precision highp float;
59 # layout(location = 0) out vec4 _GLF_color;
60 # layout(set = 0, binding = 0) uniform buf0
65 # // Function returns 1 or 2.
66 # int func(S s, int a)
68 # _GLF_color = vec4(0);
81 # int res = func(s, s.x[0]);
85 # _GLF_color = vec4(1, 0, 0, 1);
87 # _GLF_color = vec4(0);
89 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
92 ; Generator: Khronos Glslang Reference Front End; 8
96 %1 = OpExtInstImport "GLSL.std.450"
97 OpMemoryModel Logical GLSL450
98 OpEntryPoint Fragment %4 "main" %21
99 OpExecutionMode %4 OriginUpperLeft
102 OpName %21 "_GLF_color"
104 OpMemberName %38 0 "zero"
106 OpDecorate %21 Location 0
107 OpMemberDecorate %38 0 RelaxedPrecision
108 OpMemberDecorate %38 0 Offset 0
110 OpDecorate %40 DescriptorSet 0
111 OpDecorate %40 Binding 0
112 OpDecorate %43 RelaxedPrecision
113 OpDecorate %50 RelaxedPrecision
114 OpDecorate %74 RelaxedPrecision
115 OpDecorate %81 RelaxedPrecision
116 OpDecorate %86 RelaxedPrecision
117 OpDecorate %89 RelaxedPrecision
119 %3 = OpTypeFunction %2
123 %9 = OpTypeArray %6 %8
124 %12 = OpTypePointer Function %6
126 %19 = OpTypeVector %18 4
127 %20 = OpTypePointer Output %19
128 %21 = OpVariable %20 Output
129 %22 = OpConstant %18 0
130 %23 = OpConstantComposite %19 %22 %22 %22 %22
131 %24 = OpConstant %6 0
133 %32 = OpConstant %6 1
134 %34 = OpConstant %6 2
135 %38 = OpTypeStruct %6
136 %39 = OpTypePointer Uniform %38
137 %40 = OpVariable %39 Uniform
138 %41 = OpTypePointer Uniform %6
139 %56 = OpConstant %18 1
140 %57 = OpConstantComposite %19 %56 %22 %22 %56
141 %63 = OpConstant %7 0
142 %80 = OpTypePointer Function %9
143 %4 = OpFunction %2 None %3
145 %86 = OpVariable %80 Function
146 %81 = OpVariable %80 Function
147 %42 = OpAccessChain %41 %40 %24
149 %82 = OpAccessChain %12 %81 %24
153 %85 = OpAccessChain %12 %81 %24
155 OpSelectionMerge %71 None
159 %88 = OpAccessChain %12 %86 %24
161 %76 = OpIEqual %28 %74 %50
162 OpSelectionMerge %77 None
163 OpBranchConditional %76 %78 %77
169 %89 = OpPhi %6 %32 %78 %34 %77
170 %53 = OpIEqual %28 %89 %32
171 OpSelectionMerge %55 None
172 OpBranchConditional %53 %54 %58
184 # uniforms for variant
187 BUFFER variant_zero DATA_TYPE int32 DATA
191 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
193 PIPELINE graphics variant_pipeline
194 ATTACH variant_vertex_shader
195 ATTACH variant_fragment_shader
196 FRAMEBUFFER_SIZE 256 256
197 BIND BUFFER variant_framebuffer AS color LOCATION 0
198 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0
200 CLEAR_COLOR variant_pipeline 0 0 0 255
202 CLEAR variant_pipeline
203 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
205 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255