• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2# Copyright 2019 The Amber Authors.
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#     https://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
16SHADER compute my_compute SPIRV-ASM
17OpCapability Shader
18OpExtension "SPV_KHR_storage_buffer_storage_class"
19OpMemoryModel Logical GLSL450
20OpEntryPoint GLCompute %main "main" %lid_var %gid_var %idx_var %wgid_var
21OpDecorate %lid_var BuiltIn LocalInvocationId
22OpDecorate %gid_var BuiltIn GlobalInvocationId
23OpDecorate %idx_var BuiltIn LocalInvocationIndex
24OpDecorate %wgid_var BuiltIn WorkgroupId
25OpDecorate %wg_size BuiltIn WorkgroupSize
26OpDecorate %x SpecId 1
27OpDecorate %y SpecId 2
28OpDecorate %z SpecId 3
29OpDecorate %struct Block
30OpMemberDecorate %struct 0 Offset 0
31OpDecorate %rta ArrayStride 4
32OpDecorate %x_var DescriptorSet 0
33OpDecorate %x_var Binding 0
34OpDecorate %y_var DescriptorSet 0
35OpDecorate %y_var Binding 1
36OpDecorate %z_var DescriptorSet 0
37OpDecorate %z_var Binding 2
38OpDecorate %s_var DescriptorSet 0
39OpDecorate %s_var Binding 3
40%void = OpTypeVoid
41%int = OpTypeInt 32 0
42%int_0 = OpConstant %int 0
43%device = OpConstant %int 1
44%relaxed = OpConstant %int 0
45%int3 = OpTypeVector %int 3
46%x = OpSpecConstant %int 1
47%y = OpSpecConstant %int 1
48%z = OpSpecConstant %int 1
49%wg_size = OpSpecConstantComposite %int3 %x %y %z
50%rta = OpTypeRuntimeArray %int
51%struct = OpTypeStruct %rta
52%ptr_input_int3 = OpTypePointer Input %int3
53%ptr_input_int = OpTypePointer Input %int
54%lid_var = OpVariable %ptr_input_int3 Input
55%gid_var = OpVariable %ptr_input_int3 Input
56%idx_var = OpVariable %ptr_input_int Input
57%wgid_var = OpVariable %ptr_input_int3 Input
58%ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
59%ptr_ssbo_int = OpTypePointer StorageBuffer %int
60%x_var = OpVariable %ptr_ssbo_struct StorageBuffer
61%y_var = OpVariable %ptr_ssbo_struct StorageBuffer
62%z_var = OpVariable %ptr_ssbo_struct StorageBuffer
63%s_var = OpVariable %ptr_ssbo_struct StorageBuffer
64%void_fn = OpTypeFunction %void
65%main = OpFunction %void None %void_fn
66%entry = OpLabel
67%lid = OpLoad %int3 %lid_var
68%lid_x = OpCompositeExtract %int %lid 0
69%lid_y = OpCompositeExtract %int %lid 1
70%lid_z = OpCompositeExtract %int %lid 2
71%gid = OpLoad %int3 %gid_var
72%gid_x = OpCompositeExtract %int %gid 0
73%gid_y = OpCompositeExtract %int %gid 1
74%gid_z = OpCompositeExtract %int %gid 2
75%wgid = OpLoad %int3 %wgid_var
76%wgid_x = OpCompositeExtract %int %wgid 0
77%wgid_y = OpCompositeExtract %int %wgid 1
78%wgid_z = OpCompositeExtract %int %wgid 2
79%local_index = OpLoad %int %idx_var
80%wg_x = OpCompositeExtract %int %wg_size 0
81%wg_y = OpCompositeExtract %int %wg_size 1
82%wg_z = OpCompositeExtract %int %wg_size 2
83%x_y = OpIMul %int %wg_x %wg_y
84%x_y_z = OpIMul %int %x_y %wg_z
85%mul = OpIMul %int %wgid_x %x_y_z
86; only support multiple wgs on x
87%linear = OpIAdd %int %mul %local_index
88%x_gep = OpAccessChain %ptr_ssbo_int %x_var %int_0 %linear
89%y_gep = OpAccessChain %ptr_ssbo_int %y_var %int_0 %linear
90%z_gep = OpAccessChain %ptr_ssbo_int %z_var %int_0 %linear
91%s_gep = OpAccessChain %ptr_ssbo_int %s_var %int_0 %linear
92OpStore %x_gep %lid_x
93OpStore %y_gep %lid_y
94OpStore %z_gep %lid_z
95OpStore %s_gep %linear
96OpReturn
97OpFunctionEnd
98END
99
100BUFFER x_buf DATA_TYPE uint32 SIZE 16 FILL 0
101BUFFER y_buf DATA_TYPE uint32 SIZE 16 FILL 0
102BUFFER z_buf DATA_TYPE uint32 SIZE 16 FILL 0
103BUFFER s_buf DATA_TYPE uint32 SIZE 16 FILL 0
104
105PIPELINE compute small
106  ATTACH my_compute \
107    SPECIALIZE 1 AS uint32 2 \
108    SPECIALIZE 2 AS uint32 2 \
109    SPECIALIZE 3 AS uint32 2
110  BIND BUFFER x_buf AS storage DESCRIPTOR_SET 0 BINDING 0
111  BIND BUFFER y_buf AS storage DESCRIPTOR_SET 0 BINDING 1
112  BIND BUFFER z_buf AS storage DESCRIPTOR_SET 0 BINDING 2
113  BIND BUFFER s_buf AS storage DESCRIPTOR_SET 0 BINDING 3
114END
115
116RUN small 2 1 1
117
118EXPECT s_buf IDX 0 EQ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
119EXPECT x_buf IDX 0 EQ 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
120EXPECT y_buf IDX 0 EQ 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
121EXPECT z_buf IDX 0 EQ 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1
122
123