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

Merged
wike1701 merged 1 commit from upstream-pr/35 into main 2026-11-28 19:01:28 +00:00
wike1701 commented 2026-11-27 11:58:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by wike1701 on 2026-11-27T11:58:38Z.


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
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5526233481 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/35). Originally posted by [wike1701](https://github.com/wike1701) on 2026-11-27T11:58:38Z. --- 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**
jptorres96 commented 2026-11-27 16:15:31 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-27T16:15:31Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7223045998 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/35#issuecomment-7223045998). Originally posted by [jptorres96](https://github.com/jptorres96) on 2026-11-27T16:15:31Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!35
No description provided.