fix(shader): clamp cbufferLoadLegacy row, keep WaveSize(64) on AMD, and sync water LDS (#288) #457

Open
github-bot wants to merge 2 commits from github-bot/gh-457 into main AGit
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:07 UTC · original
ZerefDragnee1l:fix/shader-cbv-clamp-wave64-and-water-lds → main · +346 −20 · 5 files · 2 commits · open

Shader-translator fixes split out cleanly from #408.

Causal mapping & evidence

  • Issue context (#288 / #280): The DRED report in #288 specifically points to out-of-range view/sampler heap indices (addressed in companion PR #455), while #280's attached play.log records 0x887A0004/0x887A0006 device removal with breadcrumbs off.
  • Defensive RDNA 2 shader hardening (shader.rs, bitcode/opt.rs, lower.rs):
    • cbufferLoadLegacy row clamping (0x0FFF, 4096 vectors / 64 KiB) + Effect::Reads for dynamic rows prevents dynamic/corrupt CBV row indices from indexing past a CBV or being hoisted/merged across writes as Pure, while constant rows (including out-of-range constants clamped at emit time) remain Effect::Pure.
    • Keeping WaveSize(64) on multi-wave Wave64 compute shaders (group % 64 == 0) on Wave64 hosts prevents SM 6.6 drivers such as amdxc64 from defaulting unannotated multi-wave shaders to Wave32.
  • Water dark-block synchronization (lower.rs, by_hash/idle_lds_reads.rs) — companion to the water PR (independent of #288/#280):
    • lds_meetings() now rejects region-boundary-only meetings when a single divergent region mixes plain ds_write* and atomic LDS writes so Wave32 lowering keeps per-access barriers.
    • Adds CS_TV_Tiled, CS_AlphaTransmissionDepthTileGenerationMip1, and CS_AlphaTransmissionDepthTileGenerationMip25 to idle_lds_reads.rs.

Verification

  • git diff --check -> clean
  • cargo check -p larp -> exited 0
  • cargo test -p larp-shader --lib -- --skip buffer_tests::gpu -> 5 passed; 0 failed (emit::shader::tests::cbuffer_load_legacy_clamps_rows_and_preserves_constant_pure_vs_dynamic_reads, emit::lower::tests::lds_meetings_refuses_mixed_plain_and_atomic_writes_but_allows_same_class_writes, emit::lower::tests::emitted_wave_size_differs_between_wave32_and_wave64_hosts_for_multi_wave_groups, plus the 2 existing CPU tests). The 4 emit::buffer_tests::gpu::* tests are filtered out (skipped / require an SM 6.6 GPU device).
**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:07 UTC · [original](https://github.com/gamingwithhomie/larp/pull/457) `ZerefDragnee1l:fix/shader-cbv-clamp-wave64-and-water-lds` → `main` · +346 −20 · 5 files · 2 commits · open Shader-translator fixes split out cleanly from #408. ### Causal mapping & evidence - **Issue context (#288 / #280)**: The DRED report in #288 specifically points to out-of-range view/sampler heap indices (addressed in companion PR #455), while #280's attached `play.log` records `0x887A0004`/`0x887A0006` device removal with breadcrumbs off. - **Defensive RDNA 2 shader hardening (`shader.rs`, `bitcode/opt.rs`, `lower.rs`)**: - `cbufferLoadLegacy` row clamping (`0x0FFF`, 4096 vectors / 64 KiB) + `Effect::Reads` for dynamic rows prevents dynamic/corrupt CBV row indices from indexing past a CBV or being hoisted/merged across writes as `Pure`, while constant rows (including out-of-range constants clamped at emit time) remain `Effect::Pure`. - Keeping `WaveSize(64)` on multi-wave Wave64 compute shaders (`group % 64 == 0`) on Wave64 hosts prevents SM 6.6 drivers such as `amdxc64` from defaulting unannotated multi-wave shaders to Wave32. - **Water dark-block synchronization (`lower.rs`, `by_hash/idle_lds_reads.rs`) — companion to the water PR (independent of #288/#280)**: - `lds_meetings()` now rejects region-boundary-only meetings when a single divergent region mixes plain `ds_write*` and atomic LDS writes so Wave32 lowering keeps per-access barriers. - Adds `CS_TV_Tiled`, `CS_AlphaTransmissionDepthTileGenerationMip1`, and `CS_AlphaTransmissionDepthTileGenerationMip25` to `idle_lds_reads.rs`. ### Verification - `git diff --check` -> clean - `cargo check -p larp` -> exited 0 - `cargo test -p larp-shader --lib -- --skip buffer_tests::gpu` -> `5 passed; 0 failed` (`emit::shader::tests::cbuffer_load_legacy_clamps_rows_and_preserves_constant_pure_vs_dynamic_reads`, `emit::lower::tests::lds_meetings_refuses_mixed_plain_and_atomic_writes_but_allows_same_class_writes`, `emit::lower::tests::emitted_wave_size_differs_between_wave32_and_wave64_hosts_for_multi_wave_groups`, plus the 2 existing CPU tests). The 4 `emit::buffer_tests::gpu::*` tests are filtered out (`skipped` / require an SM 6.6 GPU device).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 01:11:17 +00:00
Author
Owner

@⁠vanya890 on GitHub · 2026-12-06 01:11 UTC · original

Thanks for putting these AMD fixes together. One review gap before this is ready to merge: the validation listed does not exercise the new paths. The two passing CPU tests are existing unrelated tests, while the four GPU tests could not run; there are no CI checks on the head commit.

Could you add focused regression coverage for at least the CPU-side decisions: (1) cbufferLoadLegacy clamps the row operand to 4095 and classifies dynamic rows as Reads while constant rows remain Pure; (2) lds_meetings adds a barrier for mixed ds_write*/atomic LDS writes but not for same-class writes; and (3) the emitted wave-size annotation for multi-wave Wave64 groups differs correctly between Wave32 and Wave64 hosts?

Also, could you map each change to the evidence in #288/#280? The #288 DRED report points at view/sampler heap indices past their ends, while the attached #280 play.log I checked only records device removal (0x887A0004/0x887A0006) with breadcrumbs disabled. I can see how the cbuffer bound and Wave64 changes might be relevant, but the causal link to the reported failures is not yet clear from the PR description. A short explanation plus CPU-side tests would make this much easier to review without requiring the author's hardware to reproduce every case.

**@⁠vanya890** on GitHub · 2026-12-06 01:11 UTC · [original](https://github.com/gamingwithhomie/larp/pull/457#issuecomment-7448974308) Thanks for putting these AMD fixes together. One review gap before this is ready to merge: the validation listed does not exercise the new paths. The two passing CPU tests are existing unrelated tests, while the four GPU tests could not run; there are no CI checks on the head commit. Could you add focused regression coverage for at least the CPU-side decisions: (1) `cbufferLoadLegacy` clamps the row operand to 4095 and classifies dynamic rows as `Reads` while constant rows remain `Pure`; (2) `lds_meetings` adds a barrier for mixed `ds_write*`/atomic LDS writes but not for same-class writes; and (3) the emitted wave-size annotation for multi-wave Wave64 groups differs correctly between Wave32 and Wave64 hosts? Also, could you map each change to the evidence in #288/#280? The #288 DRED report points at view/sampler heap indices past their ends, while the attached #280 `play.log` I checked only records device removal (`0x887A0004`/`0x887A0006`) with breadcrumbs disabled. I can see how the cbuffer bound and Wave64 changes might be relevant, but the causal link to the reported failures is not yet clear from the PR description. A short explanation plus CPU-side tests would make this much easier to review without requiring the author's hardware to reproduce every case.
Author
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:17 UTC · original

for sure

**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:17 UTC · [original](https://github.com/gamingwithhomie/larp/pull/457#issuecomment-7449052294) for sure
Author
Owner

@⁠vanya890 on GitHub · 2026-12-06 01:19 UTC · original · reviewed

The dynamic cbufferLoadLegacy row clamp is the key correctness boundary: the row operand is a vector index, so limiting it to 0x0FFF keeps constant-buffer access within the 4,096-row / 64 KiB CBV range. Keeping constant-index calls pure while treating dynamic calls as reads is also the right direction for the optimizer's effect model. Please ensure regression coverage exercises both a constant row (which should retain the pure path) and a dynamic/out-of-range row (which must be clamped and remain observable to optimization).

**@⁠vanya890** on GitHub · 2026-12-06 01:19 UTC · [original](https://github.com/gamingwithhomie/larp/pull/457#pullrequestreview-6207411757) · **reviewed** The dynamic `cbufferLoadLegacy` row clamp is the key correctness boundary: the row operand is a vector index, so limiting it to `0x0FFF` keeps constant-buffer access within the 4,096-row / 64 KiB CBV range. Keeping constant-index calls pure while treating dynamic calls as reads is also the right direction for the optimizer's effect model. Please ensure regression coverage exercises both a constant row (which should retain the pure path) and a dynamic/out-of-range row (which must be clamped and remain observable to optimization).
Author
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:33 UTC · original

Thank you for the thorough review! I have updated this PR with both the constant-row fold fix and focused CPU-side regression tests, plus an explicit evidence mapping in the PR description:

  1. Constant vs. dynamic cbufferLoadLegacy row clamping & effects (shader.rs, bitcode/opt.rs):

    • While adding the test, I noticed that emitting dx.op.binary.i32 unconditionally for constant rows turned the row operand into a V::Inst prior to FOLD, which would cause Module::class to classify even constant-row calls as Effect::Reads before optimization.
    • Shader::op now folds constant operands directly (k.min(0x0FFF)) so both in-range and out-of-range constant rows stay V::Const (Effect::Pure) and merge across writes during Module::optimise, while dynamic rows emit dx.op.binary.i32(..., 40, ..., 0x0FFF) and stay Effect::Reads across intervening writes.
    • Covered by emit::shader::tests::cbuffer_load_legacy_clamps_rows_and_preserves_constant_pure_vs_dynamic_reads.
  2. lds_meetings mixed plain vs. atomic LDS writes & Wave64 annotation (lower.rs, structure.rs):

    • emit::lower::tests::lds_meetings_refuses_mixed_plain_and_atomic_writes_but_allows_same_class_writes verifies lds_meetings returns None when a divergent block mixes ds_write_b32 and ds_add_u32, while returning region-boundary meetings for same-class ds_write_b32 or ds_add_u32 pairs.
    • emit::lower::tests::emitted_wave_size_differs_between_wave32_and_wave64_hosts_for_multi_wave_groups verifies multi-wave Wave64 groups annotate Some(64) on Wave64 hosts and None on Wave32 hosts.
  3. Evidence mapping:

    • Out-of-range view/sampler heap indices seen in #288's DRED report are addressed in #455, whereas #280's play.log only shows 0x887A0004/0x887A0006 device removal with breadcrumbs disabled.
    • Accordingly, the cbufferLoadLegacy clamp/effect fix and Wave64 multi-wave annotation are presented here as defensive shader-side hardening for AMD RDNA 2 (#288/#280), while the lds_meetings mixed-write fix and idle_lds_reads.rs water shaders specifically address Wave32 split-wave LDS synchronization for the water dark-block issue.

Verification: cargo check -p larp exited 0; cargo test -p larp-shader --lib -- --skip buffer_tests::gpu -> 5 passed; 0 failed; 4 filtered out (the 4 emit::buffer_tests::gpu::* tests require an SM 6.6 device).

**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:33 UTC · [original](https://github.com/gamingwithhomie/larp/pull/457#issuecomment-7449269644) Thank you for the thorough review! I have updated this PR with both the constant-row fold fix and focused CPU-side regression tests, plus an explicit evidence mapping in the PR description: 1. **Constant vs. dynamic `cbufferLoadLegacy` row clamping & effects (`shader.rs`, `bitcode/opt.rs`)**: - While adding the test, I noticed that emitting `dx.op.binary.i32` unconditionally for constant rows turned the row operand into a `V::Inst` prior to `FOLD`, which would cause `Module::class` to classify even constant-row calls as `Effect::Reads` before optimization. - `Shader::op` now folds constant operands directly (`k.min(0x0FFF)`) so both in-range and out-of-range constant rows stay `V::Const` (`Effect::Pure`) and merge across writes during `Module::optimise`, while dynamic rows emit `dx.op.binary.i32(..., 40, ..., 0x0FFF)` and stay `Effect::Reads` across intervening writes. - Covered by `emit::shader::tests::cbuffer_load_legacy_clamps_rows_and_preserves_constant_pure_vs_dynamic_reads`. 2. **`lds_meetings` mixed plain vs. atomic LDS writes & Wave64 annotation (`lower.rs`, `structure.rs`)**: - `emit::lower::tests::lds_meetings_refuses_mixed_plain_and_atomic_writes_but_allows_same_class_writes` verifies `lds_meetings` returns `None` when a divergent block mixes `ds_write_b32` and `ds_add_u32`, while returning region-boundary meetings for same-class `ds_write_b32` or `ds_add_u32` pairs. - `emit::lower::tests::emitted_wave_size_differs_between_wave32_and_wave64_hosts_for_multi_wave_groups` verifies multi-wave Wave64 groups annotate `Some(64)` on Wave64 hosts and `None` on Wave32 hosts. 3. **Evidence mapping**: - Out-of-range view/sampler heap indices seen in #288's DRED report are addressed in #455, whereas #280's `play.log` only shows `0x887A0004`/`0x887A0006` device removal with breadcrumbs disabled. - Accordingly, the `cbufferLoadLegacy` clamp/effect fix and Wave64 multi-wave annotation are presented here as defensive shader-side hardening for AMD RDNA 2 (#288/#280), while the `lds_meetings` mixed-write fix and `idle_lds_reads.rs` water shaders specifically address Wave32 split-wave LDS synchronization for the water dark-block issue. **Verification**: `cargo check -p larp` exited 0; `cargo test -p larp-shader --lib -- --skip buffer_tests::gpu` -> `5 passed; 0 failed; 4 filtered out` (the 4 `emit::buffer_tests::gpu::*` tests require an SM 6.6 device).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/457/head:github-bot/gh-457'
git switch 'github-bot/gh-457'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-457'
git switch 'github-bot/gh-457'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-457'
git switch 'github-bot/gh-457'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-457'
git switch 'main'
git merge --squash 'github-bot/gh-457'
git switch 'main'
git merge --ff-only 'github-bot/gh-457'
git switch 'main'
git merge 'github-bot/gh-457'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.