Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / library / ml / src / main / rust / shaders / probe_ssbo.comp

probe_ssbo.comp37 lines · 1.2 KiBRaw
1#version 450
2//! Reads a buffer as a plain SSBO, for comparison against `probe_texel.comp`.
3//!
4//! The two shaders differ in exactly one respect - how the same bytes are fetched - so the gap
5//! between them is the value of the texture path and nothing else. See `vulkan::imageprobe`.
6//!
7//! The accumulator is xored rather than added so no arithmetic can be strength-reduced away, and
8//! is written out so the whole loop cannot be eliminated as dead.
9layout(local_size_x = 64) in;
10
11layout(set = 0, binding = 0) readonly buffer Source {
12 uvec4 data[];
13};
14
15layout(set = 0, binding = 1) buffer Sink {
16 uint sink[];
17};
18
19layout(push_constant) uniform Push {
20 /// `uvec4`s in the source.
21 uint quads;
22};
23
24void main() {
25 uint lane = gl_GlobalInvocationID.x;
26 uint stride = gl_NumWorkGroups.x * 64u;
27 uvec4 acc = uvec4(0u);
28 // Grid-stride so a fixed launch covers any size, and consecutive lanes read consecutive
29 // quads - the access pattern a weight sweep has.
30 for (uint at = lane; at < quads; at += stride) {
31 acc ^= data[at];
32 }
33 uint folded = acc.x ^ acc.y ^ acc.z ^ acc.w;
34 if (folded == 0xFFFFFFFFu) {
35 sink[0] = folded;
36 }
37}