Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / graphicsfuzz / find-msb-from-lsb.amber
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 GraphicsFuzz.
19
20 # Short description: A fragment shader that finds MSB from LSB
21
22 # The test passes because shader always writes red.
23
24 SHADER vertex variant_vertex_shader PASSTHROUGH
25
26 # variant_fragment_shader is derived from the following GLSL:
27 # #version 310 es
28 # precision highp float;
29 # precision highp int;
30 #
31 # layout(location = 0) out vec4 _GLF_color;
32 #
33 # void main()
34 # {
35 #     // State of variables/expressions after "result += x;".
36 #     //
37 #     // i  x  i >> x  findLSB  findMSB  result
38 #     // 0  0  0       -1       -1       0
39 #     // 0  1  0       -1       -1       1
40 #     // 1  0  1        0       -1       1
41 #     // 1  1  0       -1       -1       2
42 #
43 #     int result = 0;
44 #     for (int i = 0; i < 2; i++)
45 #     {
46 #         for (int x = 0; x < 2; x++)
47 #         {
48 #             // findMSB(findLSB(i >> x)) is always -1.
49 #             for ( ; x > findMSB(findLSB(i >> x)) && x < 2; x++)
50 #             {
51 #                 result += x;
52 #             }
53 #         }
54 #     }
55 #     if (result == 2)
56 #         _GLF_color = vec4(1, 0, 0, 1);
57 #     else
58 #         _GLF_color = vec4(0, 0, 0, 1);
59 # }
60 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
61 ; SPIR-V
62 ; Version: 1.0
63 ; Generator: Khronos Glslang Reference Front End; 8
64 ; Bound: 66
65 ; Schema: 0
66                OpCapability Shader
67           %1 = OpExtInstImport "GLSL.std.450"
68                OpMemoryModel Logical GLSL450
69                OpEntryPoint Fragment %4 "main" %60
70                OpExecutionMode %4 OriginUpperLeft
71                OpSource ESSL 310
72                OpName %4 "main"
73                OpName %8 "result"
74                OpName %10 "i"
75                OpName %20 "x"
76                OpName %60 "_GLF_color"
77                OpDecorate %60 Location 0
78           %2 = OpTypeVoid
79           %3 = OpTypeFunction %2
80           %6 = OpTypeInt 32 1
81           %7 = OpTypePointer Function %6
82           %9 = OpConstant %6 0
83          %17 = OpConstant %6 2
84          %18 = OpTypeBool
85          %47 = OpConstant %6 1
86          %57 = OpTypeFloat 32
87          %58 = OpTypeVector %57 4
88          %59 = OpTypePointer Output %58
89          %60 = OpVariable %59 Output
90          %61 = OpConstant %57 1
91          %62 = OpConstant %57 0
92          %63 = OpConstantComposite %58 %61 %62 %62 %61
93          %65 = OpConstantComposite %58 %62 %62 %62 %61
94           %4 = OpFunction %2 None %3
95           %5 = OpLabel
96           %8 = OpVariable %7 Function
97          %10 = OpVariable %7 Function
98          %20 = OpVariable %7 Function
99                OpStore %8 %9
100                OpStore %10 %9
101                OpBranch %11
102          %11 = OpLabel
103                OpLoopMerge %13 %14 None
104                OpBranch %15
105          %15 = OpLabel
106          %16 = OpLoad %6 %10
107          %19 = OpSLessThan %18 %16 %17
108                OpBranchConditional %19 %12 %13
109          %12 = OpLabel
110                OpStore %20 %9
111                OpBranch %21
112          %21 = OpLabel
113                OpLoopMerge %23 %24 None
114                OpBranch %25
115          %25 = OpLabel
116          %26 = OpLoad %6 %20
117          %27 = OpSLessThan %18 %26 %17
118                OpBranchConditional %27 %22 %23
119          %22 = OpLabel
120                OpBranch %28
121          %28 = OpLabel
122                OpLoopMerge %30 %31 None
123                OpBranch %32
124          %32 = OpLabel
125          %33 = OpLoad %6 %20
126          %34 = OpLoad %6 %10
127          %35 = OpLoad %6 %20
128          %36 = OpShiftRightArithmetic %6 %34 %35
129          %37 = OpExtInst %6 %1 FindILsb %36
130          %38 = OpExtInst %6 %1 FindSMsb %37
131          %39 = OpSGreaterThan %18 %33 %38
132          %40 = OpLoad %6 %20
133          %41 = OpSLessThan %18 %40 %17
134          %42 = OpLogicalAnd %18 %39 %41
135                OpBranchConditional %42 %29 %30
136          %29 = OpLabel
137          %43 = OpLoad %6 %20
138          %44 = OpLoad %6 %8
139          %45 = OpIAdd %6 %44 %43
140                OpStore %8 %45
141                OpBranch %31
142          %31 = OpLabel
143          %46 = OpLoad %6 %20
144          %48 = OpIAdd %6 %46 %47
145                OpStore %20 %48
146                OpBranch %28
147          %30 = OpLabel
148                OpBranch %24
149          %24 = OpLabel
150          %49 = OpLoad %6 %20
151          %50 = OpIAdd %6 %49 %47
152                OpStore %20 %50
153                OpBranch %21
154          %23 = OpLabel
155                OpBranch %14
156          %14 = OpLabel
157          %51 = OpLoad %6 %10
158          %52 = OpIAdd %6 %51 %47
159                OpStore %10 %52
160                OpBranch %11
161          %13 = OpLabel
162          %53 = OpLoad %6 %8
163          %54 = OpIEqual %18 %53 %17
164                OpSelectionMerge %56 None
165                OpBranchConditional %54 %55 %64
166          %55 = OpLabel
167                OpStore %60 %63
168                OpBranch %56
169          %64 = OpLabel
170                OpStore %60 %65
171                OpBranch %56
172          %56 = OpLabel
173                OpReturn
174                OpFunctionEnd
175 END
176
177
178 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
179
180 PIPELINE graphics variant_pipeline
181   ATTACH variant_vertex_shader
182   ATTACH variant_fragment_shader
183   FRAMEBUFFER_SIZE 256 256
184   BIND BUFFER variant_framebuffer AS color LOCATION 0
185 END
186 CLEAR_COLOR variant_pipeline 0 0 0 255
187
188 CLEAR variant_pipeline
189 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
190
191 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255