Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / nested-ifs-and-return-in-for-loop.amber
1 #!amber
2
3 # Copyright 2019 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 # Short description: A fragment shader with return in nest of ifs, inside loop
20
21 # The test passes because the fragment shader assigns red to _GLF_color then
22 # assigns black to _GLF_color in the loop. The other assignment to _GLF_color
23 # (in the if statement) is not dynamically reachable.
24
25 # Derived from the following GLSL.
26
27 # Fragment shader GLSL:
28 # #version 310 es
29 #
30 # precision highp float;
31 #
32 # layout(location = 0) out vec4 _GLF_color;
33 #
34 # layout(set = 0, binding = 0) uniform buf0 {
35 #  vec2 injectionSwitch;
36 # };
37 #
38 # void main()
39 # {
40 #  _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
41 #  for(
42 #      int i = 0;
43 #      i < 10;
44 #      i ++
45 #  )
46 #   {
47 #    _GLF_color = vec4(1.0);
48 #    if(1.0 > injectionSwitch.y)
49 #     {
50 #      _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
51 #      if(true)
52 #       {
53 #        return;
54 #       }
55 #     }
56 #   }
57 # }
58
59 SHADER vertex variant_vertex_shader PASSTHROUGH
60
61 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
62 ; SPIR-V
63 ; Version: 1.0
64 ; Generator: Khronos Glslang Reference Front End; 7
65 ; Bound: 46
66 ; Schema: 0
67                OpCapability Shader
68           %1 = OpExtInstImport "GLSL.std.450"
69                OpMemoryModel Logical GLSL450
70                OpEntryPoint Fragment %4 "main" %9
71                OpExecutionMode %4 OriginUpperLeft
72                OpSource ESSL 310
73                OpName %4 "main"
74                OpName %9 "_GLF_color"
75                OpName %15 "i"
76                OpName %28 "buf0"
77                OpMemberName %28 0 "injectionSwitch"
78                OpName %30 ""
79                OpDecorate %9 Location 0
80                OpDecorate %15 RelaxedPrecision
81                OpDecorate %22 RelaxedPrecision
82                OpMemberDecorate %28 0 Offset 0
83                OpDecorate %28 Block
84                OpDecorate %30 DescriptorSet 0
85                OpDecorate %30 Binding 0
86                OpDecorate %43 RelaxedPrecision
87                OpDecorate %45 RelaxedPrecision
88           %2 = OpTypeVoid
89           %3 = OpTypeFunction %2
90           %6 = OpTypeFloat 32
91           %7 = OpTypeVector %6 4
92           %8 = OpTypePointer Output %7
93           %9 = OpVariable %8 Output
94          %10 = OpConstant %6 1
95          %11 = OpConstant %6 0
96          %12 = OpConstantComposite %7 %10 %11 %11 %10
97          %13 = OpTypeInt 32 1
98          %14 = OpTypePointer Function %13
99          %16 = OpConstant %13 0
100          %23 = OpConstant %13 10
101          %24 = OpTypeBool
102          %26 = OpConstantComposite %7 %10 %10 %10 %10
103          %27 = OpTypeVector %6 2
104          %28 = OpTypeStruct %27
105          %29 = OpTypePointer Uniform %28
106          %30 = OpVariable %29 Uniform
107          %31 = OpTypeInt 32 0
108          %32 = OpConstant %31 1
109          %33 = OpTypePointer Uniform %6
110          %39 = OpConstantTrue %24
111          %44 = OpConstant %13 1
112           %4 = OpFunction %2 None %3
113           %5 = OpLabel
114          %15 = OpVariable %14 Function
115                OpStore %9 %12
116                OpStore %15 %16
117                OpBranch %17
118          %17 = OpLabel
119                OpLoopMerge %19 %20 None
120                OpBranch %21
121          %21 = OpLabel
122          %22 = OpLoad %13 %15
123          %25 = OpSLessThan %24 %22 %23
124                OpBranchConditional %25 %18 %19
125          %18 = OpLabel
126                OpStore %9 %26
127          %34 = OpAccessChain %33 %30 %16 %32
128          %35 = OpLoad %6 %34
129          %36 = OpFOrdGreaterThan %24 %10 %35
130                OpSelectionMerge %38 None
131                OpBranchConditional %36 %37 %38
132          %37 = OpLabel
133                OpStore %9 %12
134                OpSelectionMerge %41 None
135                OpBranchConditional %39 %40 %41
136          %40 = OpLabel
137                OpReturn
138          %41 = OpLabel
139                OpBranch %38
140          %38 = OpLabel
141                OpBranch %20
142          %20 = OpLabel
143          %43 = OpLoad %13 %15
144          %45 = OpIAdd %13 %43 %44
145                OpStore %15 %45
146                OpBranch %17
147          %19 = OpLabel
148                OpReturn
149                OpFunctionEnd
150 END
151
152
153 # uniforms for variant
154
155 # injectionSwitch
156 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
157  0.0 1.0
158 END
159
160 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
161
162 PIPELINE graphics variant_pipeline
163   ATTACH variant_vertex_shader
164   ATTACH variant_fragment_shader
165   FRAMEBUFFER_SIZE 256 256
166   BIND BUFFER variant_framebuffer AS color LOCATION 0
167   BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
168 END
169 CLEAR_COLOR variant_pipeline 0 0 0 255
170
171 CLEAR variant_pipeline
172 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
173
174 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 255 255 255