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 write GLSL 17#version 450 18layout(set=0, binding=0, rgba32i) uniform iimage3D im3d; 19void main() { 20 uvec3 gid = gl_GlobalInvocationID; 21 ivec3 coord = ivec3(gid.x, gid.y, gid.z); 22 ivec4 data = ivec4(gid.x + 1, gid.y + 1, gid.z + 1, 0); 23 imageStore(im3d, coord, data); 24} 25END 26 27SHADER compute read GLSL 28#version 450 29 30layout(set=0, binding=0) uniform itexture3D im3d; 31layout(set=0, binding=1) uniform sampler s; 32layout(set=0, binding=2) buffer A { ivec4 x[]; } data; 33 34void main() { 35 uvec3 gid = gl_GlobalInvocationID; 36 ivec3 coord = ivec3(gid.x, gid.y, gid.z); 37 uint linear = 4 * gid.z + 2 * gid.y + gid.x; 38 data.x[linear] = texture(isampler3D(im3d, s), coord); 39} 40END 41 42BUFFER out_buf DATA_TYPE vec4<int32> SIZE 8 FILL 15 43IMAGE im3d DATA_TYPE vec4<int32> DIM_3D \ 44 WIDTH 2 HEIGHT 2 DEPTH 2 FILL 0 45SAMPLER sampler \ 46 ADDRESS_MODE_U clamp_to_edge \ 47 ADDRESS_MODE_V clamp_to_edge \ 48 ADDRESS_MODE_W clamp_to_edge \ 49 MIN_FILTER nearest \ 50 MAG_FILTER nearest \ 51 MIN_LOD 0.0 \ 52 MAX_LOD 0.0 53 54PIPELINE compute write_pipe 55 ATTACH write 56 BIND BUFFER im3d AS storage_image DESCRIPTOR_SET 0 BINDING 0 57END 58 59PIPELINE compute read_pipe 60 ATTACH read 61 BIND BUFFER im3d AS sampled_image DESCRIPTOR_SET 0 BINDING 0 62 BIND SAMPLER sampler DESCRIPTOR_SET 0 BINDING 1 63 BIND BUFFER out_buf AS storage DESCRIPTOR_SET 0 BINDING 2 64END 65 66RUN write_pipe 2 2 2 67RUN read_pipe 2 2 2 68 69EXPECT out_buf IDX 0 EQ 1 1 1 0 70EXPECT out_buf IDX 16 EQ 2 1 1 0 71EXPECT out_buf IDX 32 EQ 1 2 1 0 72EXPECT out_buf IDX 48 EQ 2 2 1 0 73EXPECT out_buf IDX 64 EQ 1 1 2 0 74EXPECT out_buf IDX 80 EQ 2 1 2 0 75EXPECT out_buf IDX 96 EQ 1 2 2 0 76EXPECT out_buf IDX 112 EQ 2 2 2 0 77