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