perf(shader): group signature elements by row for interpolation normalization #3483

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

@⁠Damokles2 on GitHub · 2026-11-27 07:37 UTC · original
Damokles2:perf-shader-signature-row-grouping → main · +103 −9 · 1 files · 1 commits · open

Summary

Optimize same_mode_per_row() in victory-shader by grouping signature elements by register row.

  • Reduce worst-case complexity from O(E log E + E × R) to O(E log E), where E is the number of signature elements and R is the number of distinct rows.
  • Use inline scratch storage for signatures containing up to 16 elements, avoiding heap allocations.
  • Preserve original signature element order and interpolation semantics, including conflicting modes, undecided modes, sparse row IDs, unallocated elements, and used pixel inputs.
  • Add two fixed-expectation regression tests.

Performance

The CPU-only A/B benchmark compared the upstream and optimized helpers on the same native Windows-MSVC AMD EPYC runner. Both variants used identical compiler settings, 512 warm-up calls, and 15 alternating batches of 4,096 calls. The matrix covers 144 workloads with varying signature sizes, row distributions, element ordering, and interpolation modes.

Signature elements Median runtime reduction
2 70.8%
4 59.6%
8 71.9%
16 72.5%
32 23.5%
64 39.8%
128 53.1%

The final hosted benchmark showed no meaningful small-signature regression. The weakest 32-element result was within measurement variation. These measurements apply only to the normalization helper.

Memory trade-off

Signatures with up to 16 elements use 256 bytes of inline scratch on x64 and require no heap allocation. For larger signatures, allocation counts match upstream and temporary heap storage increases fourfold. At 128 elements, peak heap scratch increases from 512 bytes to 2,048 bytes.

Correctness and validation

  • 20,000 deterministic differential cases matched the original upstream implementation across all element fields.
  • 24 synthetic DXBC containers matched byte for byte, including DXIL bitcode and PSV0 metadata.
  • Native Windows workspace tests passed with 873 passed, 0 failed, and 10 ignored.
  • Shader package tests passed with 304 passed, 0 failed, and 3 ignored.
  • Both new regression tests passed.
  • Strict workspace Clippy passed with default and all features.
  • The repository policy check passed.
  • Whitespace and baseline-relative formatting checks passed.

The synthetic comparisons and benchmark required no proprietary game files or GPU execution.

Evidence

Validated feature aa5f45ec805543b03f80f75fcaf412099a86fa3d, upstream base 63bcca43c6a00a758510398fa43096ce7e4f7df0, and fork CI merge 5ac7583f6c767936080f5b1901de39f722e4fa55.

AI-assisted with OpenAI Codex.

**@⁠Damokles2** on GitHub · 2026-11-27 07:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3483) `Damokles2:perf-shader-signature-row-grouping` → `main` · +103 −9 · 1 files · 1 commits · open ## Summary Optimize `same_mode_per_row()` in `victory-shader` by grouping signature elements by register row. - Reduce worst-case complexity from O(E log E + E × R) to O(E log E), where E is the number of signature elements and R is the number of distinct rows. - Use inline scratch storage for signatures containing up to 16 elements, avoiding heap allocations. - Preserve original signature element order and interpolation semantics, including conflicting modes, undecided modes, sparse row IDs, unallocated elements, and used pixel inputs. - Add two fixed-expectation regression tests. ## Performance The CPU-only A/B benchmark compared the upstream and optimized helpers on the same native Windows-MSVC AMD EPYC runner. Both variants used identical compiler settings, 512 warm-up calls, and 15 alternating batches of 4,096 calls. The matrix covers 144 workloads with varying signature sizes, row distributions, element ordering, and interpolation modes. | Signature elements | Median runtime reduction | | ---: | ---: | | 2 | 70.8% | | 4 | 59.6% | | 8 | 71.9% | | 16 | 72.5% | | 32 | 23.5% | | 64 | 39.8% | | 128 | 53.1% | The final hosted benchmark showed no meaningful small-signature regression. The weakest 32-element result was within measurement variation. These measurements apply only to the normalization helper. ### Memory trade-off Signatures with up to 16 elements use 256 bytes of inline scratch on x64 and require no heap allocation. For larger signatures, allocation counts match upstream and temporary heap storage increases fourfold. At 128 elements, peak heap scratch increases from 512 bytes to 2,048 bytes. ## Correctness and validation - 20,000 deterministic differential cases matched the original upstream implementation across all element fields. - 24 synthetic DXBC containers matched byte for byte, including DXIL bitcode and PSV0 metadata. - Native Windows workspace tests passed with 873 passed, 0 failed, and 10 ignored. - Shader package tests passed with 304 passed, 0 failed, and 3 ignored. - Both new regression tests passed. - Strict workspace Clippy passed with default and all features. - The repository policy check passed. - Whitespace and baseline-relative formatting checks passed. The synthetic comparisons and benchmark required no proprietary game files or GPU execution. ## Evidence - [Coordination claim in #1633](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) - [Fork validation PR](https://github.com/Damokles2/VIctory/pull/2) - [Native Windows workspace CI](https://github.com/Damokles2/VIctory/actions/runs/45958561325) - [Benchmark and differential validation](https://github.com/Damokles2/VIctory/actions/runs/45958693586) - [Raw benchmark artifact](https://github.com/Damokles2/VIctory/actions/runs/45958693586/artifacts/15178969925) Validated feature `aa5f45ec805543b03f80f75fcaf412099a86fa3d`, upstream base `63bcca43c6a00a758510398fa43096ce7e4f7df0`, and fork CI merge `5ac7583f6c767936080f5b1901de39f722e4fa55`. AI-assisted with OpenAI Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:39:27 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 08:35 UTC · original

Independent WARP verification of #3483 (head aa5f45ec)

Setup. Windows 11 Pro 10.0.26200, AMD Ryzen 7 5700X3D, rustc 1.98.1. No physical GPU used: VICTORY_WARP=1 and VICTORY_D3D12_WARP=1; VICTORY_DXIL = Windows SDK 10.0.26100.0 x64 dxil.dll (1.8.2502.11). Command: cargo test -j 4 -p victory-shader --lib --locked -- --test-threads=1. The PR's merge-base is ffe310e, so I compared base main 63bcca43 with a clean test merge of aa5f45ec onto 63bcca43 (no conflicts; only emit/container.rs differs).

Tests

passed failed ignored
base 63bcca43 298 4 3
63bcca43 + #3483 300 4 3

The 2 extra passes are the PR's new tests (interpolation_modes_follow_rows_without_reordering, interpolation_modes_leave_empty_and_singleton_signatures_alone). The same 4 fail on base and head, so they are not caused by this PR: synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}. They assert hardware lane behaviour and fail on WARP.

Review: no behaviour change found.

  • Per row, the "decided" set (!free && interp != 0), the conflict check and the "undecided" set (free) use the same predicates as before. free does not depend on interp, so writing during the group walk cannot change what later elements see.
  • Order is preserved: only a scratch (row, index) list is sorted; elements is never reordered.
  • A one-element row cannot change in base (an element is not both decided and free), so the group.len() < 2 and len() < 2 early-outs are safe. Empty and one-element signatures are no-ops. Duplicate rows, row: None, sparse rows and u32::MAX rows are handled.
  • The inline array holds 16 entries and is used when elements.len() <= 16. The row-bearing entries number at most len(), so it cannot overflow. 17 or more elements take the Vec path.
  • Differential check: I copied both functions verbatim into a standalone harness (outside the repo) and compared them on 1,256,000 randomized cases (sizes 0-40, 1-40 rows, both read values, mixed kind/comp/interp/usage, None and u32::MAX rows). All results were identical field for field.

Timing (standalone rustc -O, 15 alternating batches of 4,096 calls, median ns per call, idle machine):

elements rows base head head/base
2 2 87 25 0.29
4 4 128 39 0.30
8 8 380 87 0.23
16 16 1113 182 0.16
17 17 1055 768 0.73
32 32 2475 837 0.34
64 64 7239 1425 0.20
128 128 20525 3213 0.16

Head is faster at every size, in line with the PR's numbers. The step at 17 elements is the heap fallback: still faster, but less so. In absolute terms the function takes under about 20 µs even at 128 elements, so the practical effect is small.

Blocking findings: none.

No game files, dumps, install paths, shader names or hashes were used. AI-assisted: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-27 08:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/3483#issuecomment-7213709485) ## Independent WARP verification of #3483 (head aa5f45ec) **Setup.** Windows 11 Pro 10.0.26200, AMD Ryzen 7 5700X3D, rustc 1.98.1. No physical GPU used: `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1`; `VICTORY_DXIL` = Windows SDK 10.0.26100.0 x64 `dxil.dll` (1.8.2502.11). Command: `cargo test -j 4 -p victory-shader --lib --locked -- --test-threads=1`. The PR's merge-base is `ffe310e`, so I compared base `main` 63bcca43 with a clean test merge of `aa5f45ec` onto 63bcca43 (no conflicts; only `emit/container.rs` differs). **Tests** | | passed | failed | ignored | |---|---:|---:|---:| | base 63bcca43 | 298 | 4 | 3 | | 63bcca43 + #3483 | 300 | 4 | 3 | The 2 extra passes are the PR's new tests (`interpolation_modes_follow_rows_without_reordering`, `interpolation_modes_leave_empty_and_singleton_signatures_alone`). The same 4 fail on base and head, so they are not caused by this PR: `synthetic_tests::{a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_mask_high_address_bits_and_divergent_branches, permutes_read_the_lane_named_and_zero_from_lanes_left_out}`. They assert hardware lane behaviour and fail on WARP. **Review: no behaviour change found.** - Per row, the "decided" set (`!free && interp != 0`), the conflict check and the "undecided" set (`free`) use the same predicates as before. `free` does not depend on `interp`, so writing during the group walk cannot change what later elements see. - Order is preserved: only a scratch `(row, index)` list is sorted; `elements` is never reordered. - A one-element row cannot change in base (an element is not both decided and free), so the `group.len() < 2` and `len() < 2` early-outs are safe. Empty and one-element signatures are no-ops. Duplicate rows, `row: None`, sparse rows and `u32::MAX` rows are handled. - The inline array holds 16 entries and is used when `elements.len() <= 16`. The row-bearing entries number at most `len()`, so it cannot overflow. 17 or more elements take the `Vec` path. - Differential check: I copied both functions verbatim into a standalone harness (outside the repo) and compared them on 1,256,000 randomized cases (sizes 0-40, 1-40 rows, both `read` values, mixed kind/comp/interp/usage, `None` and `u32::MAX` rows). All results were identical field for field. **Timing** (standalone `rustc -O`, 15 alternating batches of 4,096 calls, median ns per call, idle machine): | elements | rows | base | head | head/base | |---:|---:|---:|---:|---:| | 2 | 2 | 87 | 25 | 0.29 | | 4 | 4 | 128 | 39 | 0.30 | | 8 | 8 | 380 | 87 | 0.23 | | 16 | 16 | 1113 | 182 | 0.16 | | 17 | 17 | 1055 | 768 | 0.73 | | 32 | 32 | 2475 | 837 | 0.34 | | 64 | 64 | 7239 | 1425 | 0.20 | | 128 | 128 | 20525 | 3213 | 0.16 | Head is faster at every size, in line with the PR's numbers. The step at 17 elements is the heap fallback: still faster, but less so. In absolute terms the function takes under about 20 µs even at 128 elements, so the practical effect is small. **Blocking findings:** none. No game files, dumps, install paths, shader names or hashes were used. AI-assisted: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-27 09:05 UTC · original

Independent CPU-only verification of PR #3483 (shader signature row grouping).

  • Windows, rustc/cargo 1.100.0/MSVC, worktree-local CARGO_TARGET_DIR (D:\Victory-Contrib\target-3483-verify), CARGO_BUILD_JOBS=2.
  • Head aa5f45ec805543b03f80f75fcaf412099a86fa3d, merge base 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • Command: cargo test --locked -p victory-shader --lib -- emit::container::tests::interpolation_modes_follow_rows_without_reordering --exact --test-threads=1 --quiet -> 1 passed; 0 failed; 306 filtered out.
  • Negative control: git grep -F for the new test name on 63bcca4 returned no hits (test absent on base).
  • git diff --check 63bcca4 HEAD exit 0 (clean).
  • Only the named synthetic test was replayed; full suite and DXIL/signature generation were not exercised.
  • AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only). No game data, assets, shaders, DRM or decrypt used.
**@⁠cloph-dsp** on GitHub · 2026-11-27 09:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3483#issuecomment-7214274843) Independent CPU-only verification of PR #3483 (shader signature row grouping). - Windows, rustc/cargo 1.100.0/MSVC, worktree-local `CARGO_TARGET_DIR` (`D:\Victory-Contrib\target-3483-verify`), `CARGO_BUILD_JOBS=2`. - Head `aa5f45ec805543b03f80f75fcaf412099a86fa3d`, merge base `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - Command: `cargo test --locked -p victory-shader --lib -- emit::container::tests::interpolation_modes_follow_rows_without_reordering --exact --test-threads=1 --quiet` -> `1 passed; 0 failed; 306 filtered out`. - Negative control: `git grep -F` for the new test name on `63bcca4` returned no hits (test absent on base). - `git diff --check 63bcca4 HEAD` exit 0 (clean). - Only the named synthetic test was replayed; full suite and DXIL/signature generation were not exercised. - AI-assisted (Hy4 flash). GPU/driver: N/A (CPU-only). No game data, assets, shaders, DRM or decrypt used.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-27 18:46 UTC · original

NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head aa5f45e (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 868 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: interpolation_modes_follow_rows_without_reordering, interpolation_modes_leave_empty_and_singleton_signatures_alone.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-27 18:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/3483#issuecomment-7225857978) NVIDIA full-suite run, to go with the reports above by cloph-dsp, oni-swr, since none of them names a GPU run. Tested exact head `aa5f45e` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **868 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `interpolation_modes_follow_rows_without_reordering`, `interpolation_modes_leave_empty_and_singleton_signatures_alone`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/3483/head:github-bot/gh-3483'
git switch 'github-bot/gh-3483'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3483'
git switch 'github-bot/gh-3483'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3483'
git switch 'github-bot/gh-3483'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3483'
git switch 'main'
git merge --squash 'github-bot/gh-3483'
git switch 'main'
git merge --ff-only 'github-bot/gh-3483'
git switch 'main'
git merge 'github-bot/gh-3483'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3483
No description provided.