aboutsummaryrefslogtreecommitdiff
path: root/tests/cases/compute_one_buffer_in_multiple_bindings.amber
blob: d16bda5b4b17615a20d8b5c68c69ea2914c7db4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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