aboutsummaryrefslogtreecommitdiff
path: root/tests/cases/compute_one_buffer_in_multiple_bindings.amber
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cases/compute_one_buffer_in_multiple_bindings.amber')
-rw-r--r--tests/cases/compute_one_buffer_in_multiple_bindings.amber94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/cases/compute_one_buffer_in_multiple_bindings.amber b/tests/cases/compute_one_buffer_in_multiple_bindings.amber
new file mode 100644
index 0000000..d16bda5
--- /dev/null
+++ b/tests/cases/compute_one_buffer_in_multiple_bindings.amber
@@ -0,0 +1,94 @@
+#!amber
+# Copyright 2021 The Amber Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+SHADER compute compute_shader GLSL
+#version 430
+
+layout(set = 0, binding = 0) uniform uniform_0 {
+ vec4 uniform_data_0;
+};
+layout(set = 0, binding = 1) buffer block_0 {
+ vec4 storage_data_0;
+};
+
+layout(set = 1, binding = 0) uniform uniform_1 {
+ vec4 uniform_data_1;
+};
+layout(set = 1, binding = 1) buffer block_1 {
+ vec4 storage_data_1;
+};
+
+uniform layout(set = 2, binding = 0, rgba32f) imageBuffer texelBuffer;
+uniform layout(set = 2, binding = 1) samplerBuffer texelsIn;
+
+void main() {
+ // Verify that the uniform and storage buffers have the same contents and multiply by 2 if true)
+ if (uniform_data_0 == storage_data_0) {
+ storage_data_0 = storage_data_0 * 2;
+ }
+ if (uniform_data_1 == storage_data_1) {
+ storage_data_1 = storage_data_1 * 2;
+ }
+
+ // Load values from index 1 using storage texel buffer.
+ vec4 texel = imageLoad(texelBuffer, 1);
+
+ // Load values from index 2 using uniform texel buffer.
+ vec4 color = texelFetch(texelsIn, 2);
+
+ // Store values to index 3.
+ imageStore(texelBuffer, 3, texel + color);
+}
+END
+
+# The Vulkan spec lists the maximum value of minStorageBufferOffsetAlignment
+# (i.e. the maximum possible alignment requirement) as 256 bytes.
+# Meaningful data is placed at this offset.
+BUFFER buf0 DATA_TYPE R32G32B32A32_SFLOAT DATA
+1.0 2.0 3.0 4.0
+0.1 0.2 0.3 0.4
+0.5 0.6 0.7 0.8
+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
+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
+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
+0.0 0.0 0.0 0.0
+5.0 6.0 7.0 8.0
+END
+
+PIPELINE compute pipeline
+ ATTACH compute_shader
+
+ BIND BUFFER buf0 AS uniform DESCRIPTOR_SET 0 BINDING 0
+ BIND BUFFER buf0 AS storage DESCRIPTOR_SET 0 BINDING 1
+ BIND BUFFER buf0 AS uniform DESCRIPTOR_SET 1 BINDING 0 DESCRIPTOR_OFFSET 256
+ BIND BUFFER buf0 AS storage DESCRIPTOR_SET 1 BINDING 1 DESCRIPTOR_OFFSET 256
+ BIND BUFFER buf0 AS storage_texel_buffer DESCRIPTOR_SET 2 BINDING 0
+ BIND BUFFER buf0 AS uniform_texel_buffer DESCRIPTOR_SET 2 BINDING 1
+END
+
+RUN pipeline 1 1 1
+
+EXPECT buf0 IDX 0 EQ 2.0 4.0 6.0 8.0 # Values written to the first storage buffer binding
+EXPECT buf0 IDX 48 EQ 0.6 0.8 1.0 1.2 # Values written to the storage texel buffer binding
+EXPECT buf0 IDX 256 EQ 10.0 12.0 14.0 16.0 # Values written to the second storage buffer binding