Console lane ids collide in compute groups whose host waves are not aligned runs (2-D/3-D groups, wave32 and wave64 hosts) #216

Open
opened 2026-11-26 03:38:07 +00:00 by github-bot · 1 comment
Owner

@⁠j-fuxa on GitHub · 2026-11-26 01:41 UTC · original

What we found

A compute thread's console id is rebuilt as waveReadLaneFirst(flattenedThreadIdInGroup) rounded down to the wave size, plus the host lane index. That is exact only if every host wave holds an aligned run of flat ids. On an RTX 4060 Laptop (32-lane waves) and a Radeon 780M (WaveSize(32)) it does not: 2-D groups are filled with rows of 24+ threads taken from 16x2 tiles, so two waves can get the same base and some ids are never produced.

Evidence

A probe shader stored each thread's relabelled id. Distinct ids / threads in the group, the same on both GPUs: 32x2 32/64, 32x8 128/256, 64x4 128/256, 32x32 512/1024, 32x2x2 64/128, 10x10 68/100. 12x12 and 24x8 failed pipeline creation on the 4060 ("Not enough memory resources") and gave 96/144 and 128/192 on the 780M. This agrees with the probe in a comment on #48 (Radeon 8060S: 64x2, 64x4, 24x8, 12x12 and 10x10 under WaveSize(64)).

Why it matters here

Both branches still use the rounding: Lower::thread_id and console_flat on main @ 4f62c2a (emit/lower.rs 4242-4262 and 12607-12636), thread_id and console_thread on rx9070xt @ 81ebb7b (4520-4575 and 4099-4111). The group-shared counter wave_base (4068-4095) is used only when a console wave64 program runs as 32-lane halves (halves, set at 1522-1526). Console wave32 programs, and wave64 programs on 64-lane hosts, take the rounding path.

In the title's shader archive three programs were wrong with the rounding, all 32x2 sky ambient-map compute passes. In our build 221 compute programs use console lanes in a group larger than one host wave and take the ticket below. These are the sky ambient-map passes; we have not checked what it changes in the picture on your side.

Suggested fix

For console-lane programs in groups larger than one host wave: zero a group-shared counter, barrier, then the first lane of each full host wave takes a block of wave-size ids with an atomic add (a partial wave takes the last block); console id = block base + host lane. A form that does not assume one partial wave filled from lane 0: every wave does atomicAdd(counter, WaveActiveCountBits(true)) and lanes use base + WavePrefixCountBits(true) (dx.op.waveAllOp, opcode 135).

Caveats

Measured with a probe on our tree, not on your build. Which shapes fail depends on GPU and driver. The wave64-host data is only the #48 comment.

**@⁠j-fuxa** on GitHub · 2026-11-26 01:41 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/216) **What we found** A compute thread's console id is rebuilt as `waveReadLaneFirst(flattenedThreadIdInGroup)` rounded down to the wave size, plus the host lane index. That is exact only if every host wave holds an aligned run of flat ids. On an RTX 4060 Laptop (32-lane waves) and a Radeon 780M (`WaveSize(32)`) it does not: 2-D groups are filled with rows of 24+ threads taken from 16x2 tiles, so two waves can get the same base and some ids are never produced. **Evidence** A probe shader stored each thread's relabelled id. Distinct ids / threads in the group, the same on both GPUs: 32x2 32/64, 32x8 128/256, 64x4 128/256, 32x32 512/1024, 32x2x2 64/128, 10x10 68/100. 12x12 and 24x8 failed pipeline creation on the 4060 ("Not enough memory resources") and gave 96/144 and 128/192 on the 780M. This agrees with the probe in a comment on #48 (Radeon 8060S: 64x2, 64x4, 24x8, 12x12 and 10x10 under `WaveSize(64)`). **Why it matters here** Both branches still use the rounding: `Lower::thread_id` and `console_flat` on `main` @ 4f62c2a (`emit/lower.rs` 4242-4262 and 12607-12636), `thread_id` and `console_thread` on `rx9070xt` @ 81ebb7b (4520-4575 and 4099-4111). The group-shared counter `wave_base` (4068-4095) is used only when a console wave64 program runs as 32-lane halves (`halves`, set at 1522-1526). Console wave32 programs, and wave64 programs on 64-lane hosts, take the rounding path. In the title's shader archive three programs were wrong with the rounding, all 32x2 sky ambient-map compute passes. In our build 221 compute programs use console lanes in a group larger than one host wave and take the ticket below. These are the sky ambient-map passes; we have not checked what it changes in the picture on your side. **Suggested fix** For console-lane programs in groups larger than one host wave: zero a group-shared counter, barrier, then the first lane of each full host wave takes a block of wave-size ids with an atomic add (a partial wave takes the last block); console id = block base + host lane. A form that does not assume one partial wave filled from lane 0: every wave does `atomicAdd(counter, WaveActiveCountBits(true))` and lanes use base + `WavePrefixCountBits(true)` (`dx.op.waveAllOp`, opcode 135). **Caveats** Measured with a probe on our tree, not on your build. Which shapes fail depends on GPU and driver. The wave64-host data is only the #48 comment.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:38:07 +00:00
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 19:52 UTC · original

Data point from an RX 7900 XT (RDNA3 discrete, Windows 11, driver 32.0.32029.2010), plus a census of the archive on main @ 4f62c2a.

Probe

A compute shader stores, per thread, its lane, its wave's first flat id, and (first & ~(W-1)) + lane, with W the declared wave size. Distinct relabelled ids / threads (4 groups, all the same):

group WaveSize(32) WaveSize(64)
32x2 32/64 64/64
32x4 64/128 128/128
32x8 128/256 256/256
64x2 64/128 64/128
64x4 128/256 128/256
32x32 512/1024 1024/1024
32x2x2 64/128 128/128
10x10 68/100 64/100
12x12 96/144 80/144
24x8 128/192 128/192
6x6 32/36 36/36
8x8, 16x16, 8x16, 4x4x4, 8x8x2, 16x2x4 exact exact
64x1, 256x1 exact exact
  • On this GPU every 2-D and 3-D group is filled in 2x2 quads. At WaveSize(32), 32x2 gives two waves: x 0-15 and x 16-31, both rows each, with first flat ids 0 and 16. 1-D groups are aligned runs.
  • The WaveSize(32) column matches your 780M numbers. The WaveSize(64) column matches the 8060S counts in #48. 6x6 at WaveSize(32) also collides here.
  • Without a declared wave size the driver picked 64 lanes for every shape, with the same results as WaveSize(64).
  • WARP (4-lane waves) packs each wave as one 2x2 quad and collides on every 2-D and 3-D shape. It never runs console-lane programs, though: the translator refuses wave sizes the host does not run.
  • A hand-assembled console program (a ds_swizzle, so it gets console lanes) that stores f+1 at its flat id f gives the same counts through the translator.

Archive census on main (local counters, names and counts only)

main has no group-shared counter, so every console-lane compute program takes the rounding.

  • Host lanes 32-64: 1155 of 2682 compute programs use console lanes. 56 are in groups larger than one host wave: 29 are 1-D and 27 are 2-D. The 27 are:
    • shapes: 16x16 at 64 (16), 8x16 at 64 (6), 8x8 at 32 (3), 32x32 at 64 (2)
    • families: cascadeshadows_rendering 19, cascadeshadows_classify 2, GpuParticleEmit 2, and 1 each of ShallowWaterSim, scattering_transmittance_system, TAA2 and TAA2U
  • Host lanes 32-32: 989 of the 2389 emitted compute programs use console lanes. 121 are larger than one host wave: 31 are 1-D and 90 are 2-D/3-D. The 90 are:
    • shapes: 8x8 at 32 (88), 4x4x4 at 32 (2)
    • families: im 24, depth_pyramid 24, scattering_transmittance_system 7, cascadeshadows_processing 6, EntityMask 4; trailmapCompute, rtdirectionalshadows, firevbuffer and MotionBlur 3 each; tiled_lighting, shadowmask and DepthOfField 2 each; 7 others with 1
  • All of these shapes give distinct ids on the 7900 XT, so on this GPU no archive program collides on main. I cannot test whether 8x8 or 4x4x4 at 32 lanes collide on NVIDIA.
  • The three 32x2 sky ambient-map programs (CS_AmbientMapSky32, CS_AmbientMapSkyClassified32, CS_AmbientMapSkyLocal32) do not use console lanes on main:
    • At 32-64 they get WaveSize(64) as one-wave LDS groups and use the host's thread ids.
    • At 32-32 they are refused ("a wave64 group sharing LDS without barriers on a host without 64-lane waves").
    • So on main they do not take the rounding path.

Fix

#236 has since proposed a fix along the same lines (one shared counter per group, full host waves get aligned ranges, a partial wave takes the tail). I have not tested #236. The probe and the census above may help to check it.

Not tested: no game run (the game is not on this machine), and no NVIDIA card.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/216#issuecomment-7202059055) Data point from an RX 7900 XT (RDNA3 discrete, Windows 11, driver 32.0.32029.2010), plus a census of the archive on `main` @ 4f62c2a. **Probe** A compute shader stores, per thread, its lane, its wave's first flat id, and `(first & ~(W-1)) + lane`, with W the declared wave size. Distinct relabelled ids / threads (4 groups, all the same): | group | WaveSize(32) | WaveSize(64) | |---|---|---| | 32x2 | 32/64 | 64/64 | | 32x4 | 64/128 | 128/128 | | 32x8 | 128/256 | 256/256 | | 64x2 | 64/128 | 64/128 | | 64x4 | 128/256 | 128/256 | | 32x32 | 512/1024 | 1024/1024 | | 32x2x2 | 64/128 | 128/128 | | 10x10 | 68/100 | 64/100 | | 12x12 | 96/144 | 80/144 | | 24x8 | 128/192 | 128/192 | | 6x6 | 32/36 | 36/36 | | 8x8, 16x16, 8x16, 4x4x4, 8x8x2, 16x2x4 | exact | exact | | 64x1, 256x1 | exact | exact | - On this GPU every 2-D and 3-D group is filled in 2x2 quads. At WaveSize(32), 32x2 gives two waves: x 0-15 and x 16-31, both rows each, with first flat ids 0 and 16. 1-D groups are aligned runs. - The WaveSize(32) column matches your 780M numbers. The WaveSize(64) column matches the 8060S counts in #48. 6x6 at WaveSize(32) also collides here. - Without a declared wave size the driver picked 64 lanes for every shape, with the same results as WaveSize(64). - WARP (4-lane waves) packs each wave as one 2x2 quad and collides on every 2-D and 3-D shape. It never runs console-lane programs, though: the translator refuses wave sizes the host does not run. - A hand-assembled console program (a `ds_swizzle`, so it gets console lanes) that stores f+1 at its flat id f gives the same counts through the translator. **Archive census on main (local counters, names and counts only)** `main` has no group-shared counter, so every console-lane compute program takes the rounding. - Host lanes 32-64: 1155 of 2682 compute programs use console lanes. 56 are in groups larger than one host wave: 29 are 1-D and 27 are 2-D. The 27 are: - shapes: 16x16 at 64 (16), 8x16 at 64 (6), 8x8 at 32 (3), 32x32 at 64 (2) - families: cascadeshadows_rendering 19, cascadeshadows_classify 2, GpuParticleEmit 2, and 1 each of ShallowWaterSim, scattering_transmittance_system, TAA2 and TAA2U - Host lanes 32-32: 989 of the 2389 emitted compute programs use console lanes. 121 are larger than one host wave: 31 are 1-D and 90 are 2-D/3-D. The 90 are: - shapes: 8x8 at 32 (88), 4x4x4 at 32 (2) - families: im 24, depth_pyramid 24, scattering_transmittance_system 7, cascadeshadows_processing 6, EntityMask 4; trailmapCompute, rtdirectionalshadows, firevbuffer and MotionBlur 3 each; tiled_lighting, shadowmask and DepthOfField 2 each; 7 others with 1 - All of these shapes give distinct ids on the 7900 XT, so on this GPU no archive program collides on main. I cannot test whether 8x8 or 4x4x4 at 32 lanes collide on NVIDIA. - The three 32x2 sky ambient-map programs (CS_AmbientMapSky32, CS_AmbientMapSkyClassified32, CS_AmbientMapSkyLocal32) do not use console lanes on main: - At 32-64 they get WaveSize(64) as one-wave LDS groups and use the host's thread ids. - At 32-32 they are refused ("a wave64 group sharing LDS without barriers on a host without 64-lane waves"). - So on main they do not take the rounding path. **Fix** #236 has since proposed a fix along the same lines (one shared counter per group, full host waves get aligned ranges, a partial wave takes the tail). I have not tested #236. The probe and the census above may help to check it. Not tested: no game run (the game is not on this machine), and no NVIDIA card.
This discussion has been locked. Commenting is limited to contributors.
No description provided.