• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2018 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# A test for a bug found by GraphicsFuzz.
18
19# A fragment shader that uses vector swizzles, struct initializers, and min.
20# Derived from the following GLSL fragment shader.
21# We check that the top-left pixel is red. The test passes because the
22# first if statement checks if the x coordinate is less than 10 and if so writes
23# red to _GLF_color and then returns.
24
25# #version 310 es
26#
27# precision highp float;
28# precision highp int;
29#
30# struct S {
31#  vec2 s2;
32# };
33#
34# layout(location=0) out vec4 _GLF_color;
35#
36# layout(set = 0, binding = 0) uniform buf0 {
37#   vec2 injectionSwitch;
38# };
39#
40# void main()
41# {
42#  if (gl_FragCoord.x < 10.0) {
43#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
44#   return;
45#  }
46#  vec4 v4 = vec4(injectionSwitch.y);
47#  vec2 p = S(v4.xy).s2;
48#  v4.xy = p;
49#  v4.xy = (min(vec4(1.0), v4)).xy;
50#  _GLF_color = vec4(v4.x, 0.0, 0.0, 1.0);
51# }
52
53SHADER vertex variant_vertex_shader PASSTHROUGH
54
55SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
56; SPIR-V
57; Version: 1.0
58; Generator: Khronos SPIR-V Tools Assembler; 0
59; Bound: 45
60; Schema: 0
61               OpCapability Shader
62          %1 = OpExtInstImport "GLSL.std.450"
63               OpMemoryModel Logical GLSL450
64               OpEntryPoint Fragment %2 "main" %3 %4
65               OpExecutionMode %2 OriginUpperLeft
66               OpSource ESSL 310
67               OpName %2 "main"
68               OpName %3 "gl_FragCoord"
69               OpName %4 "_GLF_color"
70               OpName %5 "buf0"
71               OpMemberName %5 0 "injectionSwitch"
72               OpName %6 ""
73               OpDecorate %3 BuiltIn FragCoord
74               OpDecorate %4 Location 0
75               OpMemberDecorate %5 0 Offset 0
76               OpDecorate %5 Block
77               OpDecorate %6 DescriptorSet 0
78               OpDecorate %6 Binding 0
79          %7 = OpTypeVoid
80          %8 = OpTypeFunction %7
81          %9 = OpTypeFloat 32
82         %10 = OpTypeVector %9 4
83         %11 = OpTypePointer Input %10
84          %3 = OpVariable %11 Input
85         %12 = OpTypeInt 32 0
86         %13 = OpConstant %12 0
87         %14 = OpTypePointer Input %9
88         %15 = OpConstant %9 10
89         %16 = OpTypeBool
90         %17 = OpTypePointer Output %10
91          %4 = OpVariable %17 Output
92         %18 = OpConstant %9 1
93         %19 = OpConstant %9 0
94         %20 = OpConstantComposite %10 %18 %19 %19 %18
95         %21 = OpTypeVector %9 2
96          %5 = OpTypeStruct %21
97         %22 = OpTypePointer Uniform %5
98          %6 = OpVariable %22 Uniform
99         %23 = OpTypeInt 32 1
100         %24 = OpConstant %23 0
101         %25 = OpConstant %12 1
102         %26 = OpTypePointer Uniform %9
103         %27 = OpConstantComposite %10 %18 %18 %18 %18
104          %2 = OpFunction %7 None %8
105         %28 = OpLabel
106               OpBranch %29
107         %29 = OpLabel
108               OpLoopMerge %30 %31 None
109               OpBranch %32
110         %32 = OpLabel
111         %33 = OpAccessChain %14 %3 %13
112         %34 = OpLoad %9 %33
113         %35 = OpFOrdLessThan %16 %34 %15
114               OpSelectionMerge %36 None
115               OpBranchConditional %35 %37 %36
116         %37 = OpLabel
117               OpStore %4 %20
118               OpBranch %30
119         %36 = OpLabel
120         %38 = OpAccessChain %26 %6 %24 %25
121         %39 = OpLoad %9 %38
122         %40 = OpCompositeConstruct %10 %39 %39 %39 %39
123         %41 = OpVectorShuffle %10 %40 %40 4 5 2 3
124         %42 = OpExtInst %10 %1 FMin %27 %41
125         %43 = OpCompositeExtract %9 %42 0
126         %44 = OpCompositeConstruct %10 %43 %19 %19 %18
127               OpStore %4 %44
128               OpBranch %30
129         %31 = OpLabel
130               OpBranch %29
131         %30 = OpLabel
132               OpReturn
133               OpFunctionEnd
134END
135
136# uniforms for variant
137
138# injectionSwitch
139BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
140 0.0 1.0
141END
142
143BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
144
145PIPELINE graphics variant_pipeline
146  ATTACH variant_vertex_shader
147  ATTACH variant_fragment_shader
148  FRAMEBUFFER_SIZE 256 256
149  BIND BUFFER variant_framebuffer AS color LOCATION 0
150  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
151END
152CLEAR_COLOR variant_pipeline 0 0 0 255
153
154CLEAR variant_pipeline
155RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
156
157EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255
158