Shader tests: verify every normalized MTBUF field without Int64ShaderOps #1112

Closed
github-bot wants to merge 2 commits from github-bot/gh-1112 into main AGit
Owner

@⁠Razdva122 on GitHub · 2026-11-24 15:49 UTC · original
Razdva122:shader/mtbuf-normalize-i32 → main · +180 −0 · 2 files · 2 commits · closed without merging

This PR adds regression coverage for normalized MTBUF loads from #1060. Main already contains the 32-bit rounding implementation from da82e44. The remaining diff adds a test module and registers it in the shader test suite.

The first test checks the DXIL feature flags for all 20 normalized formats and validates the shaders when a validator is available. The second dispatches synthetic shaders with separate input and output buffers, reads back the results and compares every present channel with an f64 reference rounded to f32. Together the cases cover 962,048 field values, including the packed 11-bit fields.

@⁠steven-seagull27 supplied the updated merge and ran the tests separately on an RTX 5080 and Microsoft WARP. Both recorded zero mismatches, and all 20 shaders kept the Int64ShaderOps flag clear. Hardware and WARP results

AI-assisted with Codex.

**@⁠Razdva122** on GitHub · 2026-11-24 15:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112) `Razdva122:shader/mtbuf-normalize-i32` → `main` · +180 −0 · 2 files · 2 commits · closed without merging This PR adds regression coverage for normalized MTBUF loads from #1060. Main already contains the 32-bit rounding implementation from da82e44. The remaining diff adds a test module and registers it in the shader test suite. The first test checks the DXIL feature flags for all 20 normalized formats and validates the shaders when a validator is available. The second dispatches synthetic shaders with separate input and output buffers, reads back the results and compares every present channel with an f64 reference rounded to f32. Together the cases cover 962,048 field values, including the packed 11-bit fields. @⁠steven-seagull27 supplied the updated merge and ran the tests separately on an RTX 5080 and Microsoft WARP. Both recorded zero mismatches, and all 20 shaders kept the Int64ShaderOps flag clear. [Hardware and WARP results](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1112) AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:23 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 15:55 UTC · original

We ran the two focused Win64 tests on the exact PR head 4f5fa47 on an RTX 4090 under Wine/GE 3.2. Both passed. We then replaced the normalization arithmetic on our #1060 integration branch with this PR’s 32-bit rounder, retaining #1060’s missing-channel rule. Across all 20 normalized MTBUF formats, the GPU readback matched the f64 reference rounded to f32 for each present field, and every absent channel returned zero. The emitted DXIL for all 20 formats also passed the check for an absent Int64ShaderOps flag.

This verifies that the two changes compose. The RTX 4090 supports Int64, so execution on hardware lacking that capability and any effect on title output remain open.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 15:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7136844890) We ran the two focused Win64 tests on the exact PR head `4f5fa47` on an RTX 4090 under Wine/GE 3.2. Both passed. We then replaced the normalization arithmetic on our #1060 integration branch with this PR’s 32-bit rounder, retaining #1060’s missing-channel rule. Across all 20 normalized MTBUF formats, the GPU readback matched the f64 reference rounded to f32 for each present field, and every absent channel returned zero. The emitted DXIL for all 20 formats also passed the check for an absent Int64ShaderOps flag. This verifies that the two changes compose. The RTX 4090 supports Int64, so execution on hardware lacking that capability and any effect on title output remain open.
Author
Owner

@⁠adamdotpy on GitHub · 2026-11-24 16:34 UTC · original

Deep review on Windows 11 / Rust 1.98.1, 4f5fa47 on current main (ffe310e, merges as it stands), isolated target dir.

Verified here: cargo test -p victory-shader --lib 122 passed / 1 ignored, including both new tests — normalized_mtbuf_loads_need_no_int64 (asserts SFI0 bit 0x8000 is clear for all twenty unorm/snorm formats and validates with dxil.dll when present) and normalized_mtbuf_loads_round_every_field_value, which ran on the hardware GPU and WARP here. Clippy --all-targets --all-features --locked -D warnings clean; cargo build --release -p victory builds.

I checked the rounding exhaustively, independently of the GPU test. I reimplemented norm_bits's integer steps in Python and compared them against exact round-to-nearest-even (via Fraction) for every possible field value: all unorm widths n = 1..16 — 131,070 values — and all snorm widths w = 2..16 — 131,068 values. Zero mismatches in both. The most negative snorm input yields exactly -1.0, which is the console's behaviour and comes from clamping to -(2^(w-1)-1) rather than to the minimum representable. So the claim "correctly rounded for every field value" is now proven for the whole input space, not just the sampled rows the GPU test runs.

Why the bit trick is right, which is the part worth a second read: base = bits - (n << 23) is exactly v / 2^n in f32 bits (no underflow for v >= 1 and n <= 16), and multiplying by 2^n/(2^n-1) adds M/(2^n-1) ULPs where M is the 24-bit significand — an odd denominator, so (M + max/2)/max rounds with no ties. Adding the correction to the bit pattern lets a full-scale input carry into the next exponent for free. The snorm sign survives because base is computed from the signed bit pattern, and the sign bit is above the exponent field that gets decremented.

Three smaller notes.

  • norm_bits silently assumes n <= 24 (exact significand) and n < 31 (1 << n on i32). buffer_format only yields norm widths up to 16 — the 32-bit families are Uint/Sint/Float and never reach norm_bits — so it holds today; a debug_assert!(n <= 24) would pin it if a wider norm format ever appeared.
  • The new mtbuf_tests module takes super::valu_tests::ONE_AT_A_TIME before touching a device, which is exactly right and worth calling out because #383's run_cases_on missed it and its parallel release runs segfault 2-in-6. This one will not.
  • Removing the old shortcut comment ("the AMD driver does [the division] 1 ULP off… correct it with an integer check if a title compares exactly") is the right call now: the code no longer does the division at all, so the comment described a path that no longer exists.

Nothing I would change. The one thing I could not verify from here is the gfx1036 console measurement the test's expectations come from (#1060) — but with the formula exhaustively equal to round-to-nearest-even, that measurement and the implementation agree by construction.

**@⁠adamdotpy** on GitHub · 2026-11-24 16:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7137880435) Deep review on Windows 11 / Rust 1.98.1, `4f5fa47` on current `main` (`ffe310e`, merges as it stands), isolated target dir. **Verified here:** `cargo test -p victory-shader --lib` 122 passed / 1 ignored, including both new tests — `normalized_mtbuf_loads_need_no_int64` (asserts SFI0 bit `0x8000` is clear for all twenty unorm/snorm formats and validates with `dxil.dll` when present) and `normalized_mtbuf_loads_round_every_field_value`, which ran on the hardware GPU and WARP here. Clippy `--all-targets --all-features --locked -D warnings` clean; `cargo build --release -p victory` builds. **I checked the rounding exhaustively, independently of the GPU test.** I reimplemented `norm_bits`'s integer steps in Python and compared them against exact round-to-nearest-even (via `Fraction`) for every possible field value: all unorm widths `n = 1..16` — 131,070 values — and all snorm widths `w = 2..16` — 131,068 values. **Zero mismatches in both.** The most negative snorm input yields exactly `-1.0`, which is the console's behaviour and comes from clamping to `-(2^(w-1)-1)` rather than to the minimum representable. So the claim "correctly rounded for every field value" is now proven for the whole input space, not just the sampled rows the GPU test runs. **Why the bit trick is right, which is the part worth a second read:** `base = bits - (n << 23)` is exactly `v / 2^n` in f32 bits (no underflow for `v >= 1` and `n <= 16`), and multiplying by `2^n/(2^n-1)` adds `M/(2^n-1)` ULPs where `M` is the 24-bit significand — an odd denominator, so `(M + max/2)/max` rounds with no ties. Adding the correction to the bit pattern lets a full-scale input carry into the next exponent for free. The snorm sign survives because `base` is computed from the signed bit pattern, and the sign bit is above the exponent field that gets decremented. **Three smaller notes.** - `norm_bits` silently assumes `n <= 24` (exact significand) and `n < 31` (`1 << n` on i32). `buffer_format` only yields norm widths up to 16 — the 32-bit families are `Uint/Sint/Float` and never reach `norm_bits` — so it holds today; a `debug_assert!(n <= 24)` would pin it if a wider norm format ever appeared. - The new `mtbuf_tests` module takes `super::valu_tests::ONE_AT_A_TIME` before touching a device, which is exactly right and worth calling out because #383's `run_cases_on` missed it and its parallel release runs segfault 2-in-6. This one will not. - Removing the old shortcut comment ("the AMD driver does [the division] 1 ULP off… correct it with an integer check if a title compares exactly") is the right call now: the code no longer does the division at all, so the comment described a path that no longer exists. Nothing I would change. The one thing I could not verify from here is the gfx1036 console measurement the test's expectations come from (#1060) — but with the formula exhaustively equal to round-to-nearest-even, that measurement and the implementation agree by construction.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:01 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4f5fa47: cargo test -p victory-shader passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7140053017) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 4f5fa47: `cargo test -p victory-shader` passes, 122 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠DovisLe on GitHub · 2026-11-24 19:23 UTC · original

Physical-GPU result: Radeon 860M (RDNA 3.5, driver 32.0.32029.2010) and WARP, at 4f5fa47. Both normalized_mtbuf_loads_* tests pass, and the victory-shader lib suite passes. A sweep of all 20 UNORM/SNORM formats through tbuffer_load_format_xyzw (72 inputs per format, every channel, 11,040 results against the correctly rounded quotient; #1575) finds 32 mismatch groups on main. All of them are 1 ULP and on the 860M only; WARP is exact. The example is 8_UNORM 0x7F, which gives 0x3efeff00 instead of 0x3efefeff. With this PR there are 0 on both.

**@⁠DovisLe** on GitHub · 2026-11-24 19:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7142038398) Physical-GPU result: Radeon 860M (RDNA 3.5, driver 32.0.32029.2010) and WARP, at `4f5fa47`. Both `normalized_mtbuf_loads_*` tests pass, and the `victory-shader` lib suite passes. A sweep of all 20 UNORM/SNORM formats through `tbuffer_load_format_xyzw` (72 inputs per format, every channel, 11,040 results against the correctly rounded quotient; #1575) finds 32 mismatch groups on `main`. All of them are 1 ULP and on the 860M only; WARP is exact. The example is 8_UNORM `0x7F`, which gives `0x3efeff00` instead of `0x3efefeff`. With this PR there are **0** on both.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-24 20:46 UTC · original

Your normalized MTBUF load fix covers a rounding difference we also reproduced on an RTX 5080. I ran all 77 typed-buffer formats from #1575 (856f0ce) on native Windows, then repeated the sweep with this PR (4f5fa47) and #422 (a746d53) merged together. The RTX 5080 went from 205 mismatches to zero (169 UNORM and 36 SNORM across 32 format/channel groups). Microsoft WARP matched all 21,252 reference values in both runs.

For 8_UNORM input 0x7f, the RTX originally returned 0x3efeff00, one float32 step above the correctly rounded value of 127/255. In the combined run, it returned 0x3efefeff, matching the CPU reference and WARP. NVIDIA driver 32.0.16.2124, Windows 11 build 26300.10075. Full results and reproduction command on #1575

**@⁠steven-seagull27** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7144033696) Your normalized MTBUF load fix covers a rounding difference we also reproduced on an RTX 5080. I ran all 77 typed-buffer formats from #1575 (`856f0ce`) on native Windows, then repeated the sweep with this PR (`4f5fa47`) and #422 (`a746d53`) merged together. **The RTX 5080 went from 205 mismatches to zero** (169 UNORM and 36 SNORM across 32 format/channel groups). Microsoft WARP matched all 21,252 reference values in both runs. For `8_UNORM` input `0x7f`, the RTX originally returned `0x3efeff00`, one float32 step above the correctly rounded value of `127/255`. In the combined run, it returned `0x3efefeff`, matching the CPU reference and WARP. NVIDIA driver `32.0.16.2124`, Windows 11 build 26300.10075. [Full results and reproduction command on #1575](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1575)
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:35 UTC · original · edited 2026-11-25 16:01 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge-candidate) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7148668113) · edited 2026-11-25 16:01 UTC <!-- victory-triage v1 head=a291bc609819104e2de6a7a02e0239c68cf5e7bb verdict=needs-rebase at=2026-11-25T15:59:50Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (merge-candidate) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 01:37 UTC · original

@⁠Razdva122 I resolved the conflict on your a291bc6 head. Main already rounds these loads with 32-bit DXIL operations. The merge keeps that implementation and adds your two regression tests unchanged. They exercise every field value in all 20 packed and unpacked UNORM/SNORM formats, including 11-bit fields. Tested merge · Rounding change already on main

Backend Format IDs tested Field values compared Mismatches
RTX 5080, driver 621.40 20 962,048 0
Built-in Microsoft WARP 20 962,048 0

Both tests passed on main 63bcca43 with your test file added. I also ran each adapter separately and confirmed its DXGI name. All 20 emitted shaders had the Int64ShaderOps flag clear.

On the PR branch at a291bc6, you can fast-forward to the tested merge:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1112-exhaustive-nov26
git merge --ff-only FETCH_HEAD
cargo test --locked -p victory-shader --lib normalized_mtbuf_loads -- --nocapture
**@⁠steven-seagull27** on GitHub · 2026-11-26 01:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7179956028) @⁠Razdva122 I resolved the conflict on your `a291bc6` head. Main already rounds these loads with 32-bit DXIL operations. The merge keeps that implementation and adds your two regression tests unchanged. They exercise every field value in all 20 packed and unpacked UNORM/SNORM formats, including 11-bit fields. [Tested merge](https://github.com/steven-seagull27/VIctory/commit/3e85d5c3e1c7078bbe4b6f67485a872736b44492) · [Rounding change already on main](https://github.com/Marvisak/VIctory/commit/da82e444ec46a162ca779c82d4cf191a69182971) | Backend | Format IDs tested | Field values compared | Mismatches | |---|---:|---:|---:| | RTX 5080, driver 621.40 | 20 | 962,048 | 0 | | Built-in Microsoft WARP | 20 | 962,048 | 0 | Both tests passed on main `63bcca43` with your test file added. I also ran each adapter separately and confirmed its DXGI name. All 20 emitted shaders had the `Int64ShaderOps` flag clear. On the PR branch at `a291bc6`, you can fast-forward to the tested merge: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1112-exhaustive-nov26 git merge --ff-only FETCH_HEAD cargo test --locked -p victory-shader --lib normalized_mtbuf_loads -- --nocapture ```
github-bot changed title from Shaders: round normalized MTBUF loads without Int64ShaderOps to Shader tests: verify every normalized MTBUF field without Int64ShaderOps 2026-11-26 12:19:37 +00:00
github-bot closed this pull request 2026-11-26 12:19:38 +00:00
Author
Owner

@⁠mercuryVM on GitHub · 2026-11-24 19:27 UTC · original · approved these changes

Tested 4f5fa479 on Windows 11, RTX 5070, MSVC:

  • cargo test -p victory-shader -- --test-threads=1 passes on the head (122 passed, 1 ignored), including the 20-format MTBUF tests against the f64 reference.
  • Merged into our fork: workspace tests, shader tests and clippy -D warnings (default and all features) are all clean.

I checked the integer rounding by hand:

  • x / 2^n is exact: an exponent subtract on an exactly converted integer, n ≤ 16.
  • The significand then needs S + S/max. round(S/max) never ties, because max = 2^n - 1 is odd.
  • Adding the correction to the bits only carries into the exponent at x = max, where the result is exactly 1.0. Every other x stays in its own power of two.
  • SNORM's sign-magnitude bits work the same way, and clamping the most negative input before the conversion matches the hardware.

On a full game package, translate --validate --list keeps every program's result, with 0 programs changed (counts only compared).

AI-assisted (Claude Code).

**@⁠mercuryVM** on GitHub · 2026-11-24 19:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#pullrequestreview-6045917050) · **approved these changes** Tested 4f5fa479 on Windows 11, RTX 5070, MSVC: - `cargo test -p victory-shader -- --test-threads=1` passes on the head (122 passed, 1 ignored), including the 20-format MTBUF tests against the f64 reference. - Merged into our fork: workspace tests, shader tests and `clippy -D warnings` (default and all features) are all clean. I checked the integer rounding by hand: - `x / 2^n` is exact: an exponent subtract on an exactly converted integer, n ≤ 16. - The significand then needs `S + S/max`. `round(S/max)` never ties, because `max = 2^n - 1` is odd. - Adding the correction to the bits only carries into the exponent at `x = max`, where the result is exactly 1.0. Every other `x` stays in its own power of two. - SNORM's sign-magnitude bits work the same way, and clamping the most negative input before the conversion matches the hardware. On a full game package, `translate --validate --list` keeps every program's result, with 0 programs changed (counts only compared). AI-assisted (Claude Code).
Author
Owner

@⁠Razdva122 on GitHub · 2026-11-26 12:19 UTC · original

Closing this PR because main already includes the 32-bit normalized MTBUF rounding fix in da82e444ec. The final diff contains only the additional exhaustive tests. They passed for all 20 formats on an RTX 5080 and Microsoft WARP, with zero mismatches across 962,048 field values on each backend. The tests remain available at commit 3e85d5c3e1. Test report

**@⁠Razdva122** on GitHub · 2026-11-26 12:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1112#issuecomment-7191849485) Closing this PR because main already includes the 32-bit normalized MTBUF rounding fix in da82e444ec46a162ca779c82d4cf191a69182971. The final diff contains only the additional exhaustive tests. They passed for all 20 formats on an RTX 5080 and Microsoft WARP, with zero mismatches across 962,048 field values on each backend. The tests remain available at commit 3e85d5c3e1c7078bbe4b6f67485a872736b44492. [Test report](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1112)

Pull request closed

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!1112
No description provided.