• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2# Copyright 2020 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Generated from the following GLSL code, but array stride changed
17# from 4 to 8.
18#
19# SHADER compute compute_shader GLSL
20# #version 320 es
21# layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
22# layout(binding = 0) buffer Out0
23# {
24#     uint values[];
25# } sb;
26#
27# void main (void)
28# {
29#     uvec3 size = gl_NumWorkGroups * gl_WorkGroupSize;
30#     uint groupNdx = size.x * size.y * gl_GlobalInvocationID.z + size.x * gl_GlobalInvocationID.y + gl_GlobalInvocationID.x;
31#     uint numValuesPerInv = uint(sb.values.length()) / (size.x * size.y * size.z);
32#     uint offset = numValuesPerInv * groupNdx;
33#
34#     for (uint ndx = 0u; ndx < numValuesPerInv; ndx++)
35#         sb.values[offset + ndx] = offset + ndx;
36# }
37SHADER compute compute_shader SPIRV-ASM
38; SPIR-V
39; Version: 1.0
40; Generator: Khronos Glslang Reference Front End; 7
41; Bound: 83
42; Schema: 0
43               OpCapability Shader
44          %1 = OpExtInstImport "GLSL.std.450"
45               OpMemoryModel Logical GLSL450
46               OpEntryPoint GLCompute %main "main" %gl_NumWorkGroups %gl_GlobalInvocationID
47               OpExecutionMode %main LocalSize 1 1 1
48               OpSource ESSL 320
49               OpName %main "main"
50               OpName %size "size"
51               OpName %gl_NumWorkGroups "gl_NumWorkGroups"
52               OpName %groupNdx "groupNdx"
53               OpName %gl_GlobalInvocationID "gl_GlobalInvocationID"
54               OpName %numValuesPerInv "numValuesPerInv"
55               OpName %Out0 "Out0"
56               OpMemberName %Out0 0 "values"
57               OpName %sb "sb"
58               OpName %offset "offset"
59               OpName %ndx "ndx"
60               OpDecorate %gl_NumWorkGroups BuiltIn NumWorkgroups
61               OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
62               OpDecorate %_runtimearr_uint ArrayStride 8
63               OpMemberDecorate %Out0 0 Offset 0
64               OpDecorate %Out0 BufferBlock
65               OpDecorate %sb DescriptorSet 0
66               OpDecorate %sb Binding 0
67       %void = OpTypeVoid
68          %3 = OpTypeFunction %void
69       %uint = OpTypeInt 32 0
70     %v3uint = OpTypeVector %uint 3
71%_ptr_Function_v3uint = OpTypePointer Function %v3uint
72%_ptr_Input_v3uint = OpTypePointer Input %v3uint
73%gl_NumWorkGroups = OpVariable %_ptr_Input_v3uint Input
74     %uint_1 = OpConstant %uint 1
75         %14 = OpConstantComposite %v3uint %uint_1 %uint_1 %uint_1
76%_ptr_Function_uint = OpTypePointer Function %uint
77     %uint_0 = OpConstant %uint 0
78%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
79     %uint_2 = OpConstant %uint 2
80%_ptr_Input_uint = OpTypePointer Input %uint
81%_runtimearr_uint = OpTypeRuntimeArray %uint
82       %Out0 = OpTypeStruct %_runtimearr_uint
83%_ptr_Uniform_Out0 = OpTypePointer Uniform %Out0
84         %sb = OpVariable %_ptr_Uniform_Out0 Uniform
85        %int = OpTypeInt 32 1
86       %bool = OpTypeBool
87      %int_0 = OpConstant %int 0
88%_ptr_Uniform_uint = OpTypePointer Uniform %uint
89      %int_1 = OpConstant %int 1
90       %main = OpFunction %void None %3
91          %5 = OpLabel
92       %size = OpVariable %_ptr_Function_v3uint Function
93   %groupNdx = OpVariable %_ptr_Function_uint Function
94%numValuesPerInv = OpVariable %_ptr_Function_uint Function
95     %offset = OpVariable %_ptr_Function_uint Function
96        %ndx = OpVariable %_ptr_Function_uint Function
97         %12 = OpLoad %v3uint %gl_NumWorkGroups
98         %15 = OpIMul %v3uint %12 %14
99               OpStore %size %15
100         %19 = OpAccessChain %_ptr_Function_uint %size %uint_0
101         %20 = OpLoad %uint %19
102         %21 = OpAccessChain %_ptr_Function_uint %size %uint_1
103         %22 = OpLoad %uint %21
104         %23 = OpIMul %uint %20 %22
105         %27 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_2
106         %28 = OpLoad %uint %27
107         %29 = OpIMul %uint %23 %28
108         %30 = OpAccessChain %_ptr_Function_uint %size %uint_0
109         %31 = OpLoad %uint %30
110         %32 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_1
111         %33 = OpLoad %uint %32
112         %34 = OpIMul %uint %31 %33
113         %35 = OpIAdd %uint %29 %34
114         %36 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
115         %37 = OpLoad %uint %36
116         %38 = OpIAdd %uint %35 %37
117               OpStore %groupNdx %38
118         %44 = OpArrayLength %uint %sb 0
119         %46 = OpBitcast %int %44
120         %47 = OpBitcast %uint %46
121         %48 = OpAccessChain %_ptr_Function_uint %size %uint_0
122         %49 = OpLoad %uint %48
123         %50 = OpAccessChain %_ptr_Function_uint %size %uint_1
124         %51 = OpLoad %uint %50
125         %52 = OpIMul %uint %49 %51
126         %53 = OpAccessChain %_ptr_Function_uint %size %uint_2
127         %54 = OpLoad %uint %53
128         %55 = OpIMul %uint %52 %54
129         %56 = OpUDiv %uint %47 %55
130               OpStore %numValuesPerInv %56
131         %58 = OpLoad %uint %numValuesPerInv
132         %59 = OpLoad %uint %groupNdx
133         %60 = OpIMul %uint %58 %59
134               OpStore %offset %60
135               OpStore %ndx %uint_0
136               OpBranch %62
137         %62 = OpLabel
138               OpLoopMerge %64 %65 None
139               OpBranch %66
140         %66 = OpLabel
141         %67 = OpLoad %uint %ndx
142         %68 = OpLoad %uint %numValuesPerInv
143         %70 = OpULessThan %bool %67 %68
144               OpBranchConditional %70 %63 %64
145         %63 = OpLabel
146         %72 = OpLoad %uint %offset
147         %73 = OpLoad %uint %ndx
148         %74 = OpIAdd %uint %72 %73
149         %75 = OpLoad %uint %offset
150         %76 = OpLoad %uint %ndx
151         %77 = OpIAdd %uint %75 %76
152         %79 = OpAccessChain %_ptr_Uniform_uint %sb %int_0 %74
153               OpStore %79 %77
154               OpBranch %65
155         %65 = OpLabel
156         %80 = OpLoad %uint %ndx
157         %82 = OpIAdd %uint %80 %int_1
158               OpStore %ndx %82
159               OpBranch %62
160         %64 = OpLabel
161               OpReturn
162               OpFunctionEnd
163END
164
165# Because the array stride was doubled the verification shader
166# skips every second element.
167SHADER compute compute_shader_verify GLSL
168#version 320 es
169layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
170layout(binding = 0) buffer Buf0
171{
172    uint values[];
173};
174
175layout(binding = 1) buffer Buf1
176{
177    int result;
178};
179
180void main()
181{
182    result = 1;
183
184    for (uint i = 0u; i < 512u; i++)
185        if (values[i*2u] != i)
186            result = 0;
187}
188END
189
190BUFFER buf DATA_TYPE uint32 SIZE 1024 FILL 0
191BUFFER result DATA_TYPE int32 SIZE 1 FILL 0
192
193PIPELINE compute verify
194  ATTACH compute_shader_verify
195
196  BIND BUFFER buf AS storage DESCRIPTOR_SET 0 BINDING 0
197  BIND BUFFER result AS storage DESCRIPTOR_SET 0 BINDING 1
198END
199
200PIPELINE compute pipeline
201  ATTACH compute_shader
202
203  BIND BUFFER buf AS storage DESCRIPTOR_SET 0 BINDING 0
204END
205
206RUN pipeline 4 2 2
207RUN verify 1 1 1
208
209EXPECT result IDX 0 EQ 1
210