Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / library / ml / src / main / rust / shaders / probe_texel.comp
probe_texel.comp38 lines · 1.3 KiBRaw
| 1 | #version 450 |
| 2 | //! Reads the same buffer through a `VK_FORMAT_R32G32B32A32_UINT` texel buffer view. |
| 3 | //! |
| 4 | //! # Why this might be faster than `probe_ssbo.comp` |
| 5 | //! |
| 6 | //! A texel buffer is the same memory, bound so that fetches go through the GPU's texture unit |
| 7 | //! and its own cache rather than the general load path. On mobile parts that unit is often the |
| 8 | //! better-provisioned of the two, which is why LiteRT-LM's Android default is |
| 9 | //! `SetPreferTextureWeights(true)` and why its tensor taxonomy has `IMAGE_BUFFER` and |
| 10 | //! `TEXTURE_2D` alongside `BUFFER`. |
| 11 | //! |
| 12 | //! Everything else here matches `probe_ssbo.comp` exactly - same launch, same stride, same fold - |
| 13 | //! so any difference is the fetch path. |
| 14 | layout(local_size_x = 64) in; |
| 15 | |
| 16 | layout(set = 0, binding = 0) uniform usamplerBuffer source; |
| 17 | |
| 18 | layout(set = 0, binding = 1) buffer Sink { |
| 19 | uint sink[]; |
| 20 | }; |
| 21 | |
| 22 | layout(push_constant) uniform Push { |
| 23 | /// Texels in the source, each a `uvec4`. |
| 24 | uint quads; |
| 25 | }; |
| 26 | |
| 27 | void main() { |
| 28 | uint lane = gl_GlobalInvocationID.x; |
| 29 | uint stride = gl_NumWorkGroups.x * 64u; |
| 30 | uvec4 acc = uvec4(0u); |
| 31 | for (uint at = lane; at < quads; at += stride) { |
| 32 | acc ^= texelFetch(source, int(at)); |
| 33 | } |
| 34 | uint folded = acc.x ^ acc.y ^ acc.z ^ acc.w; |
| 35 | if (folded == 0xFFFFFFFFu) { |
| 36 | sink[0] = folded; |
| 37 | } |
| 38 | } |