Shaders: hoist constant LDS accumulator initialisations behind an entry barrier #35

Open
github-bot wants to merge 1 commit from github-bot/gh-35 into main AGit
Owner

@⁠wike1701 on GitHub · 2026-11-27 11:58 UTC · original
wike1701:feat/lds-init-hoist → main · +228 −0 · 2 files · 1 commits · open

Port of \ xceless/victory-fork\ commit \918163\ (GPL-3.0).

Problem

Tile compute shaders (including the water tile min/max shaders) initialize LDS accumulator dwords from thread 0 after per-pixel early returns, followed by group-wide \ds_min_u32\ / \ds_max_u32\ atomics. When thread 0 takes an early return, the remaining threads accumulate against uninitialized LDS memory, producing flickering dark patches in water tiles.

Fix

  • Detect LDS dwords in compute shaders where every write is a constant \ds_write_b32/\ds_write2_b32\ at a constant address and every atomic treats that constant as its identity (bailing out if any non-constant LDS write or atomic exists).
  • Store those identity values at shader entry behind a group barrier (\Lower::hoist_lds_inits), controllable via \VICTORY_LDS_INIT_HOIST=0\ (enabled by default).
  • Add unit test \ccumulator_inits_are_hoisted_to_the_start\ covering identity hoisting, non-identity rejection, plain stores, dynamic-address bailout, and full DXIL lowering + validation.

Verification

  • \cargo test -p victory-shader --lib\ -> 288 passed, 0 failed, 4 ignored (including \ccumulator_inits_are_hoisted_to_the_start)
  • \cargo xtask policy\ -> 280 files ok
**@⁠wike1701** on GitHub · 2026-11-27 11:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/35) `wike1701:feat/lds-init-hoist` → `main` · +228 −0 · 2 files · 1 commits · open Port of \ xceless/victory-fork\ commit \918163\ (GPL-3.0). ### Problem Tile compute shaders (including the water tile min/max shaders) initialize LDS accumulator dwords from thread 0 after per-pixel early returns, followed by group-wide \ds_min_u32\ / \ds_max_u32\ atomics. When thread 0 takes an early return, the remaining threads accumulate against uninitialized LDS memory, producing flickering dark patches in water tiles. ### Fix - Detect LDS dwords in compute shaders where every write is a constant \ds_write_b32\/\ds_write2_b32\ at a constant address and every atomic treats that constant as its identity (bailing out if any non-constant LDS write or atomic exists). - Store those identity values at shader entry behind a group barrier (\Lower::hoist_lds_inits\), controllable via \VICTORY_LDS_INIT_HOIST=0\ (enabled by default). - Add unit test \ccumulator_inits_are_hoisted_to_the_start\ covering identity hoisting, non-identity rejection, plain stores, dynamic-address bailout, and full DXIL lowering + validation. ### Verification - \cargo test -p victory-shader --lib\ -> **288 passed, 0 failed, 4 ignored** (including \ccumulator_inits_are_hoisted_to_the_start\) - \cargo xtask policy\ -> **280 files ok**
Port of fxceless/victory-fork commit a918163 (GPL-3.0).

Compute tile shaders (such as the water tile min/max programs) have thread 0 store starting accumulator identities in LDS after per-pixel early returns, followed by group-wide ds_min_u32 / ds_max_u32 atomics. When thread 0 returns early, the atomics combine with uninitialised LDS and produce flickering dark patches.

For compute shaders where every LDS write to a dword writes the same constant at a constant address and every atomic on that dword treats that constant as its identity (with no dynamic-address LDS writes), hoist the constant stores to shader entry behind a group barrier (VICTORY_LDS_INIT_HOIST=0 disables).

Tested with cargo test -p victory-shader --lib (288 passed, 0 failed, 4 ignored) including accumulator_inits_are_hoisted_to_the_start, and cargo xtask policy (280 files ok).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:12:51 +00:00
Author
Owner

@⁠jptorres96 on GitHub · 2026-11-27 16:15 UTC · original

Independent run on RTX 4080 SUPER 16 GB (Ada, 32-lane waves), driver 621.01, Ryzen 5 5600X, Windows build 26300, toolchain 1.98.1, DXIL validator from DXC 1.9.2609.5, VICTORY_REQUIRE_HW_GPU=1. Head 759f05c (on its own base 959dcaf; GitHub reports a conflict with current main).

  • accumulator_inits_are_hoisted_to_the_start: passed
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean
  • cargo test -p victory-shader --lib -- --test-threads=1: 288 passed, 0 failed, 4 ignored

No game dump here, so I could not look at the water tiles themselves.

**@⁠jptorres96** on GitHub · 2026-11-27 16:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/35#issuecomment-7223045998) Independent run on RTX 4080 SUPER 16 GB (Ada, 32-lane waves), driver 621.01, Ryzen 5 5600X, Windows build 26300, toolchain 1.98.1, DXIL validator from DXC 1.9.2609.5, `VICTORY_REQUIRE_HW_GPU=1`. Head `759f05c` (on its own base `959dcaf`; GitHub reports a conflict with current `main`). - `accumulator_inits_are_hoisted_to_the_start`: passed - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean - `cargo test -p victory-shader --lib -- --test-threads=1`: 288 passed, 0 failed, 4 ignored No game dump here, so I could not look at the water tiles themselves.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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