Shaders: index Lower value/descriptor uses and avoid quadratic BDD walks in structure #226

Open
github-bot wants to merge 1 commit from github-bot/gh-226 into a-publier AGit
Owner

@⁠zaixiakongyiji on GitHub · 2026-11-26 04:55 UTC · original
zaixiakongyiji:perf/shader-precompile → a-publier · +643 −197 · 2 files · 1 commits · open

Summary

Rebases the shader translation speedups cleanly onto a-publier (4eb6cfd, preserving f962387 non-reused getDimensions, 3920dc2 VICTORY_PORT_CBV raw constant buffers, ad0f9dd LDS flag regions, and 06fe22a partial_active masks) with zero change to emitted DXIL / HostShader bytes:

  1. crates/victory-shader/src/emit/lower.rs:
    • Pre-index per-SSA-value read flags (value_uses), move def chains (move_defs), first resource use per descriptor load (load_use), address-grouped scalar loads (twin_loads), sampler load sites (sampler_loads), lane_copied sites (lane_copied_sites), and integer-atomic counter table entries (counter_entries) once in Lower::new / find_coherent, replacing repeated whole-program and whole-descriptor-list linear scans inside descriptor_data, read_as_number, computed_with, sized_view, unused_descriptor_kind, and is_counter.
  2. crates/victory-shader/src/structure.rs:
    • Pack 3-tuple OBDD unique/memo keys into u64 with full 64-bit avalanche finalization in Fx::finish, make Bools::vars sub-quadratic via Seen, evaluate Bools::implies read-only with memoization instead of allocating not/and nodes, reuse forget memo maps in paths, and replace per-variable given walks with a persistent cons-list forced-literal cache (forced_id) shared across the shader plus fast-path guard reduction in Lanes::finish.

Benchmark & Equivalence

  • Bit-exact output: Verified bit-identical HostShader / DXIL output across all 25,689 emitted title shaders (~40.6M IR instructions).
  • Throughput:
    • --jobs 16 (Ryzen 7 5800X): 128.0s -> 70.8s (-44.7%; emit CPU 1085.8s -> 382.9s, structure CPU 690.0s -> 488.1s).
    • --jobs 4 (verified by @⁠adrianmjim on RX 7900 XT): 194.8s -> 118.2s (1.65x faster; CS_ScreenProbes_ActivateRays 5.47s -> 0.46s, 0 differences across all 25,689 programs under default, VICTORY_SHADER_OPT=0, VICTORY_HOST_MAX_WAVE=32, and VICTORY_HOST_RDNA=1).
  • Verification: Passes cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings, randomized ROBDD equivalence tests (vars_implies_and_given_match_reference), WARP size_tests, and hardware wave64_tests / Port 5 constants_raw tests.
**@⁠zaixiakongyiji** on GitHub · 2026-11-26 04:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/226) `zaixiakongyiji:perf/shader-precompile` → `a-publier` · +643 −197 · 2 files · 1 commits · open ### Summary Rebases the shader translation speedups cleanly onto `a-publier` (`4eb6cfd`, preserving `f962387` non-reused `getDimensions`, `3920dc2` `VICTORY_PORT_CBV` raw constant buffers, `ad0f9dd` LDS flag regions, and `06fe22a` `partial_active` masks) with zero change to emitted DXIL / `HostShader` bytes: 1. **`crates/victory-shader/src/emit/lower.rs`**: - Pre-index per-SSA-value read flags (`value_uses`), move def chains (`move_defs`), first resource use per descriptor load (`load_use`), address-grouped scalar loads (`twin_loads`), sampler load sites (`sampler_loads`), `lane_copied` sites (`lane_copied_sites`), and integer-atomic counter table entries (`counter_entries`) once in `Lower::new` / `find_coherent`, replacing repeated whole-program and whole-descriptor-list linear scans inside `descriptor_data`, `read_as_number`, `computed_with`, `sized_view`, `unused_descriptor_kind`, and `is_counter`. 2. **`crates/victory-shader/src/structure.rs`**: - Pack 3-tuple OBDD unique/memo keys into `u64` with full 64-bit avalanche finalization in `Fx::finish`, make `Bools::vars` sub-quadratic via `Seen`, evaluate `Bools::implies` read-only with memoization instead of allocating `not`/`and` nodes, reuse `forget` memo maps in `paths`, and replace per-variable `given` walks with a persistent cons-list forced-literal cache (`forced_id`) shared across the shader plus fast-path guard reduction in `Lanes::finish`. ### Benchmark & Equivalence - **Bit-exact output**: Verified bit-identical `HostShader` / DXIL output across all 25,689 emitted title shaders (~40.6M IR instructions). - **Throughput**: - `--jobs 16` (Ryzen 7 5800X): `128.0s -> 70.8s` (`-44.7%`; `emit` CPU `1085.8s -> 382.9s`, `structure` CPU `690.0s -> 488.1s`). - `--jobs 4` (verified by @⁠adrianmjim on RX 7900 XT): `194.8s -> 118.2s` (`1.65x` faster; `CS_ScreenProbes_ActivateRays` `5.47s -> 0.46s`, `0` differences across all 25,689 programs under default, `VICTORY_SHADER_OPT=0`, `VICTORY_HOST_MAX_WAVE=32`, and `VICTORY_HOST_RDNA=1`). - **Verification**: Passes `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings`, randomized ROBDD equivalence tests (`vars_implies_and_given_match_reference`), WARP `size_tests`, and hardware `wave64_tests` / Port 5 `constants_raw` tests.
- Pre-index per-SSA-value read flags (alue_uses), move def chains (move_defs), first resource use per descriptor load (load_use), address-grouped scalar loads (	win_loads), sampler load sites, lane_copied sites, and integer-atomic counter table entries once in Lower::new / ind_coherent, replacing repeated whole-program and whole-descriptor-list linear scans inside descriptor_data, 
ead_as_number, computed_with, sized_view, unused_descriptor_kind, and is_counter.
- Pack 3-tuple OBDD unique/memo keys into u64 with full 64-bit avalanche finalization in Fx::finish, make Bools::vars sub-quadratic via Seen, evaluate Bools::implies read-only with memoization instead of allocating
ot/nd nodes, reuse orget memo maps in paths, and replace per-variable given walks with a persistent cons-list forced-literal cache (orced_id) shared across the shader plus fast-path guard reduction in Lanes::finish.
- Verified bit-identical HostShader / DXIL output across all 25,689 emitted programs (26,084 total, 40.6M IR instructions); 16-thread batch translation wall time drops from 128.0s to 70.8s (-44.7%, emit CPU 1085.8s -> 382.9s, structure CPU 690.0s -> 488.1s, worst single shader 42.2s -> 3.1s).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:01:38 +00:00
Author
Owner

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

Tested at base 81ebb7b. rx9070xt has since moved to cd8dfc0, which changes emit/lower.rs. The PR still merges into it without conflicts, but I have not re-run on cd8dfc0.

Tested e41cf0f against its base rx9070xt @ 81ebb7b on a different machine: RX 7900 XT, Windows 11, release builds, victory translate --validate --list over the whole shaders.rpf, dxil.dll 10.0.26100.

Output, per program:

  • I compared the emitted <hash> from --list for each program. That hash covers the whole HostShader Debug output (DXIL plus user data, samplers and root tables), not only the DXIL.
  • All 25,689 emitted programs are identical in 3 base runs and 3 PR runs. Every validator outcome is the same too.
  • The same holds in whole-archive runs with other settings, each compared with base under the same setting:
    • VICTORY_SHADER_OPT=0 (changes all 25,689 programs vs the default): 0 differences.
    • VICTORY_HOST_MAX_WAVE=32 (changes 362): 0 differences.
    • VICTORY_HOST_RDNA=1 (changes 23,734): 0 differences.

Time, --jobs 4, base and PR run alternately. Both binaries had the same small local per-program timing patch. Other jobs may have been running on the machine.

  • Wall time: base 194.5 / 194.8 / 195.9 s, PR 117.6 / 118.2 / 118.6 s. That is 1.65x faster at the median.
  • Sum over programs of each program's median time (wall time per program on 4 worker threads, not CPU time): structure 217 -> 146 s, emit 377 -> 143 s.
  • Slowest programs before:
    • indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays: 5.47 -> 0.46 s.
    • rtdirectionalshadows:CS_RTShadowTrace32*_Tiled: about 2.1 -> 0.77 s.
    • PS_DeferredTextured* / PS_MirrorReflectionDeferredTextured* / PS_TexturedLit: about 1.7 s -> 77 ms.
  • Slowest programs after:
    • ped_standard_*:CS_RaytracingResolve: about 1.64 -> 0.98 s.
    • weapon_*:CS_RaytracingResolve: about 1.1 -> 0.6 s.
  • No program got slower by more than 1.5x and 20 ms. The worst slowdown was +5.7 ms (median of 3 runs).

Tests:

  • victory-shader lib tests, single-threaded: 279 passed, 4 ignored (base: 278 / 4).
  • emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index passes here on both base and PR (driver 32.0.32029.2010).
  • cargo clippy -p victory-shader --lib --tests -- -D warnings: clean.

I did not run the game, and I did not try --jobs 16.

**@⁠adrianmjim** on GitHub · 2026-11-26 19:54 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/226#issuecomment-7202092127) Tested at base 81ebb7b. `rx9070xt` has since moved to cd8dfc0, which changes emit/lower.rs. The PR still merges into it without conflicts, but I have not re-run on cd8dfc0. Tested e41cf0f against its base `rx9070xt` @ 81ebb7b on a different machine: RX 7900 XT, Windows 11, release builds, `victory translate --validate --list` over the whole shaders.rpf, dxil.dll 10.0.26100. Output, per program: - I compared the `emitted <hash>` from `--list` for each program. That hash covers the whole `HostShader` Debug output (DXIL plus user data, samplers and root tables), not only the DXIL. - All 25,689 emitted programs are identical in 3 base runs and 3 PR runs. Every validator outcome is the same too. - The same holds in whole-archive runs with other settings, each compared with base under the same setting: - `VICTORY_SHADER_OPT=0` (changes all 25,689 programs vs the default): 0 differences. - `VICTORY_HOST_MAX_WAVE=32` (changes 362): 0 differences. - `VICTORY_HOST_RDNA=1` (changes 23,734): 0 differences. Time, `--jobs 4`, base and PR run alternately. Both binaries had the same small local per-program timing patch. Other jobs may have been running on the machine. - Wall time: base 194.5 / 194.8 / 195.9 s, PR 117.6 / 118.2 / 118.6 s. That is 1.65x faster at the median. - Sum over programs of each program's median time (wall time per program on 4 worker threads, not CPU time): structure 217 -> 146 s, emit 377 -> 143 s. - Slowest programs before: - indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays: 5.47 -> 0.46 s. - rtdirectionalshadows:CS_RTShadowTrace32*_Tiled: about 2.1 -> 0.77 s. - PS_DeferredTextured* / PS_MirrorReflectionDeferredTextured* / PS_TexturedLit: about 1.7 s -> 77 ms. - Slowest programs after: - ped_standard_*:CS_RaytracingResolve: about 1.64 -> 0.98 s. - weapon_*:CS_RaytracingResolve: about 1.1 -> 0.6 s. - No program got slower by more than 1.5x and 20 ms. The worst slowdown was +5.7 ms (median of 3 runs). Tests: - victory-shader lib tests, single-threaded: 279 passed, 4 ignored (base: 278 / 4). - `emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index` passes here on both base and PR (driver 32.0.32029.2010). - `cargo clippy -p victory-shader --lib --tests -- -D warnings`: clean. I did not run the game, and I did not try `--jobs 16`.
github-bot changed target branch from rx9070xt to a-publier 2026-11-27 15:14:23 +00:00
github-bot force-pushed github-bot/gh-226 from e41cf0ff82 to 5791655f8b 2026-11-27 15:14:24 +00:00 Compare
Author
Owner

@⁠zaixiakongyiji on GitHub · 2026-11-27 15:14 UTC · original

Thank you @⁠adrianmjim for running the full 25,689-shader validation and timing across all four flag combinations!

Rebased cleanly onto a-publier (4eb6cfd — preserving #324's non-reused getDimensions, Port 5's VICTORY_PORT_CBV / constants_raw, ad0f9dd LDS flag regions, and 06fe22a partial_active masks), retargeted the base branch from rx9070xt to a-publier, and fixed the escaped control characters in the commit message. Re-verified clippy --workspace --all-targets [--all-features] --locked -- -D warnings and the victory-shader test suite.

**@⁠zaixiakongyiji** on GitHub · 2026-11-27 15:14 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/226#issuecomment-7221799478) Thank you @⁠adrianmjim for running the full 25,689-shader validation and timing across all four flag combinations! Rebased cleanly onto `a-publier` (`4eb6cfd` — preserving #324's non-reused `getDimensions`, Port 5's `VICTORY_PORT_CBV` / `constants_raw`, `ad0f9dd` LDS flag regions, and `06fe22a` `partial_active` masks), retargeted the base branch from `rx9070xt` to `a-publier`, and fixed the escaped control characters in the commit message. Re-verified `clippy --workspace --all-targets [--all-features] --locked -- -D warnings` and the `victory-shader` test suite.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 15:14 UTC · original

Thanks @⁠zaixiakongyiji. Retargeting to a-publier is the right call, since that's the line being developed now, and keeping #324's getDimensions and the other a-publier changes through the rebase is what mattered. Nothing further from me.

**@⁠adrianmjim** on GitHub · 2026-11-27 15:14 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/226#issuecomment-7221814781) Thanks @⁠zaixiakongyiji. Retargeting to `a-publier` is the right call, since that's the line being developed now, and keeping #324's `getDimensions` and the other a-publier changes through the rebase is what mattered. Nothing further from me.
This pull request can be merged automatically.
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/226/head:github-bot/gh-226'
git switch 'github-bot/gh-226'

Merge

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