From 32b4baff70cefdf6e3c5b036a7902a0e68951cf4 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 18 Jun 2026 17:28:14 +0200 Subject: [PATCH] More cache-friendly swizzle --- server/compositor/shaders/foveation.comp | 39 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/server/compositor/shaders/foveation.comp b/server/compositor/shaders/foveation.comp index ffc7822c..1c0a5d7d 100644 --- a/server/compositor/shaders/foveation.comp +++ b/server/compositor/shaders/foveation.comp @@ -72,24 +72,38 @@ vec3 from_linear_to_srgb(vec3 linear_rgb) ); } +uint ABfe(uint src,uint off,uint bits){return bitfieldExtract(src,int(off),int(bits));} +uint ABfiM(uint src,uint ins,uint bits){return bitfieldInsert(src,ins,0,int (bits));} + // More complex remap 64x1 to 8x8 which is necessary for 2D wave reductions. + // 543210 + // ====== + // .xx..x + // y..yy. + // Details, + // LANE TO 8x8 MAPPING + // =================== + // 00 01 08 09 10 11 18 19 + // 02 03 0a 0b 12 13 1a 1b + // 04 05 0c 0d 14 15 1c 1d + // 06 07 0e 0f 16 17 1e 1f + // 20 21 28 29 30 31 38 39 + // 22 23 2a 2b 32 33 3a 3b + // 24 25 2c 2d 34 35 3c 3d + // 26 27 2e 2f 36 37 3e 3f + uint ARmpRed8x8_x(uint a){return ABfiM(ABfe(a,2u,3u),a,1u);} + uint ARmpRed8x8_y(uint a){return ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u);} + //uvec2 ARmpRed8x8(uint32_t a){return uvec2(ABfiM(ABfe(a,2u,3u),a,1u),ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u));} + void main() { uint iz = gl_GlobalInvocationID.z; // In order to know how subgroup are mapped, we have to do the swizzling ourselves - // in the work group, consider pixels in the following order: - // - // 0 1 4 5 8 9 12 13 - // 2 3 6 7 10 11 14 15 - // 16 17 20 21 24 25 28 29 - // 18 19 22 23 26 27 30 31 - // ... - + // in the work group. uint id = gl_SubgroupID * gl_SubgroupSize + gl_SubgroupInvocationID; - uint quad = id / 4; - id -= 4 * quad; + uint iy = gl_WorkGroupID.y * gl_WorkGroupSize.y + ARmpRed8x8_y(id); + uint ix = gl_WorkGroupID.x * gl_WorkGroupSize.x + ARmpRed8x8_x(id); - uint iy = gl_WorkGroupID.y * gl_WorkGroupSize.y + 2 * uint(quad / (gl_WorkGroupSize.y / 2)) + id / 2; uint ymin = ubo.y[MAX_DIM * iz + iy]; uint ymax = ubo.y[MAX_DIM * iz + iy + 1]; if (ymin > ymax) @@ -98,7 +112,6 @@ void main() ymin = ymax; ymax = tmp; } - uint ix = gl_WorkGroupID.x * gl_WorkGroupSize.x + 2 * (quad % (gl_WorkGroupSize.y / 2)) + (id % 2); uint xmin = ubo.x[MAX_DIM * iz + ix]; uint xmax = ubo.x[MAX_DIM * iz + ix + 1]; @@ -121,7 +134,7 @@ void main() vec4 sum = colour + subgroupShuffleDown(colour, 1) + subgroupShuffleDown(colour, 2) + subgroupShuffleDown(colour, 3); - if (id == 0) + if ((id % 4)== 0) { // actual chroma imageStore(chroma, ivec3(ix/2, iy/2, iz), vec4(sum.y, sum.z, 0, 0) / 4);