• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# A test for a bug found by GraphicsFuzz.
16
17# Short description: A compute shader with a barrier in a loop with a break
18
19# Derived from the following GLSL.
20
21# Compute shader GLSL:
22# #version 310 es
23#
24# layout(set = 0, binding = 1) uniform buf1 {
25#  vec2 injectionSwitch;
26# };
27# layout(std430, binding = 0) buffer doesNotMatter {
28#  int global_seed;
29#  int data[];
30# };
31# layout(local_size_x = 16, local_size_y = 1) in;
32# void main()
33# {
34#  int lid = int(gl_LocalInvocationID.x);
35#  int val = global_seed;
36#  for(
37#      int i = 0;
38#      i < 2;
39#      i ++
40#  )
41#   {
42#    if(lid > 0)
43#     {
44#      val += data[lid - 1];
45#      if(injectionSwitch.x > 100.0)
46#       {
47#        break;
48#       }
49#     }
50#    barrier();
51#  }
52#  if (lid == 0) {
53#    data[0] = 42;
54#  }
55# }
56
57[compute shader spirv]
58; SPIR-V
59; Version: 1.0
60; Generator: Khronos Glslang Reference Front End; 7
61; Bound: 74
62; Schema: 0
63               OpCapability Shader
64          %1 = OpExtInstImport "GLSL.std.450"
65               OpMemoryModel Logical GLSL450
66               OpEntryPoint GLCompute %4 "main" %12
67               OpExecutionMode %4 LocalSize 16 1 1
68               OpSource ESSL 310
69               OpName %4 "main"
70               OpName %8 "lid"
71               OpName %12 "gl_LocalInvocationID"
72               OpName %18 "val"
73               OpName %20 "doesNotMatter"
74               OpMemberName %20 0 "global_seed"
75               OpMemberName %20 1 "data"
76               OpName %22 ""
77               OpName %27 "i"
78               OpName %50 "buf1"
79               OpMemberName %50 0 "injectionSwitch"
80               OpName %52 ""
81               OpDecorate %12 BuiltIn LocalInvocationId
82               OpDecorate %19 ArrayStride 4
83               OpMemberDecorate %20 0 Offset 0
84               OpMemberDecorate %20 1 Offset 4
85               OpDecorate %20 BufferBlock
86               OpDecorate %22 DescriptorSet 0
87               OpDecorate %22 Binding 0
88               OpMemberDecorate %50 0 Offset 0
89               OpDecorate %50 Block
90               OpDecorate %52 DescriptorSet 0
91               OpDecorate %52 Binding 1
92               OpDecorate %73 BuiltIn WorkgroupSize
93          %2 = OpTypeVoid
94          %3 = OpTypeFunction %2
95          %6 = OpTypeInt 32 1
96          %7 = OpTypePointer Function %6
97          %9 = OpTypeInt 32 0
98         %10 = OpTypeVector %9 3
99         %11 = OpTypePointer Input %10
100         %12 = OpVariable %11 Input
101         %13 = OpConstant %9 0
102         %14 = OpTypePointer Input %9
103         %19 = OpTypeRuntimeArray %6
104         %20 = OpTypeStruct %6 %19
105         %21 = OpTypePointer Uniform %20
106         %22 = OpVariable %21 Uniform
107         %23 = OpConstant %6 0
108         %24 = OpTypePointer Uniform %6
109         %34 = OpConstant %6 2
110         %35 = OpTypeBool
111         %41 = OpConstant %6 1
112         %48 = OpTypeFloat 32
113         %49 = OpTypeVector %48 2
114         %50 = OpTypeStruct %49
115         %51 = OpTypePointer Uniform %50
116         %52 = OpVariable %51 Uniform
117         %53 = OpTypePointer Uniform %48
118         %56 = OpConstant %48 100
119         %61 = OpConstant %9 2
120         %62 = OpConstant %9 264
121         %69 = OpConstant %6 42
122         %71 = OpConstant %9 16
123         %72 = OpConstant %9 1
124         %73 = OpConstantComposite %10 %71 %72 %72
125          %4 = OpFunction %2 None %3
126          %5 = OpLabel
127          %8 = OpVariable %7 Function
128         %18 = OpVariable %7 Function
129         %27 = OpVariable %7 Function
130         %15 = OpAccessChain %14 %12 %13
131         %16 = OpLoad %9 %15
132         %17 = OpBitcast %6 %16
133               OpStore %8 %17
134         %25 = OpAccessChain %24 %22 %23
135         %26 = OpLoad %6 %25
136               OpStore %18 %26
137               OpStore %27 %23
138               OpBranch %28
139         %28 = OpLabel
140               OpLoopMerge %30 %31 None
141               OpBranch %32
142         %32 = OpLabel
143         %33 = OpLoad %6 %27
144         %36 = OpSLessThan %35 %33 %34
145               OpBranchConditional %36 %29 %30
146         %29 = OpLabel
147         %37 = OpLoad %6 %8
148         %38 = OpSGreaterThan %35 %37 %23
149               OpSelectionMerge %40 None
150               OpBranchConditional %38 %39 %40
151         %39 = OpLabel
152         %42 = OpLoad %6 %8
153         %43 = OpISub %6 %42 %41
154         %44 = OpAccessChain %24 %22 %41 %43
155         %45 = OpLoad %6 %44
156         %46 = OpLoad %6 %18
157         %47 = OpIAdd %6 %46 %45
158               OpStore %18 %47
159         %54 = OpAccessChain %53 %52 %23 %13
160         %55 = OpLoad %48 %54
161         %57 = OpFOrdGreaterThan %35 %55 %56
162               OpSelectionMerge %59 None
163               OpBranchConditional %57 %58 %59
164         %58 = OpLabel
165               OpBranch %30
166         %59 = OpLabel
167               OpBranch %40
168         %40 = OpLabel
169               OpControlBarrier %61 %61 %62
170               OpBranch %31
171         %31 = OpLabel
172         %63 = OpLoad %6 %27
173         %64 = OpIAdd %6 %63 %41
174               OpStore %27 %64
175               OpBranch %28
176         %30 = OpLabel
177         %65 = OpLoad %6 %8
178         %66 = OpIEqual %35 %65 %23
179               OpSelectionMerge %68 None
180               OpBranchConditional %66 %67 %68
181         %67 = OpLabel
182         %70 = OpAccessChain %24 %22 %41 %23
183               OpStore %70 %69
184               OpBranch %68
185         %68 = OpLabel
186               OpReturn
187               OpFunctionEnd
188
189
190[test]
191## Uniforms
192# injectionSwitch
193uniform ubo 0:1 vec2 0 0.0 1.0
194## SSBO
195ssbo 0 subdata int 0 12345
196ssbo 0 subdata int 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
197
198compute 1 1 1
199probe ssbo int 0 4 == 42
200