Shaders: sweep typed buffer formats and f16 ALU against exact references #1575

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

@⁠DovisLe on GitHub · 2026-11-24 19:23 UTC · original
DovisLe:tests/f16-and-format-sweeps → main · +492 −0 · 2 files · 1 commits · open

Two #[ignore]d synthetic sweeps in crates/victory-shader/src/emit/valu_sweep_tests.rs. Each one runs on the host GPU and on WARP, compares the results with exact references computed on the CPU, and prints every mismatch grouped by backend, operation and channel, with an example input.

  • sweep_typed_buffer_formats: all 77 GFX10 buffer formats through tbuffer_load_format_xyzw, with 72 input sets per format. The reference is the ISA conversion: UNORM and SNORM correctly rounded, the scaled and integer formats, the small floats, and missing channels 0, 0, 0, 1. SWEEP_NORM_ONLY=1 limits it to the 20 norm formats (about 2 minutes). SWEEP_D16=1 adds tbuffer_load_format_d16_xyzw, which needs #169.
  • sweep_f16_alu: v_add/sub/mul/fma_f16, v_pk_add/mul/fma_f16 (both lanes), v_cvt_f16_f32 and v_cvt_f32_f16, against the f64 result rounded to the nearest-even half.

They're meant for checking rounding fixes. Results on a Radeon 860M (RDNA 3.5, driver 32.0.32029.2010) and WARP:

Tree f16 ALU groups norm format groups
main (ccfb029, after the rebase) 0 32 (860M only; WARP exact)
main before the rebase 22 (every op, both backends) 32
#422 0 —
#1387 20 (v_fma_f16 fixed; the rest needs #422) —
#1112 — 0 (11,040 results)

run_wide is run_cases with a 4-dword UAV, so the wide formats' inputs fit. The normal suite is unchanged (cargo test -p victory-shader --lib: 120 passed, 0 failed). cargo clippy -p victory-shader --all-targets [--all-features] --locked -- -D warnings is clean. Run the sweeps with cargo test -p victory-shader --lib sweep -- --ignored --nocapture.

A side finding: WARP's uitofp rounds twice for inputs of 2^31 and up. The 860M is correct.

AI-assisted (Claude). Tested on a Radeon 860M and WARP.

🤖 Generated with Claude Code

**@⁠DovisLe** on GitHub · 2026-11-24 19:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575) `DovisLe:tests/f16-and-format-sweeps` → `main` · +492 −0 · 2 files · 1 commits · open Two `#[ignore]`d synthetic sweeps in `crates/victory-shader/src/emit/valu_sweep_tests.rs`. Each one runs on the host GPU and on WARP, compares the results with exact references computed on the CPU, and prints every mismatch grouped by backend, operation and channel, with an example input. - `sweep_typed_buffer_formats`: all 77 GFX10 buffer formats through `tbuffer_load_format_xyzw`, with 72 input sets per format. The reference is the ISA conversion: UNORM and SNORM correctly rounded, the scaled and integer formats, the small floats, and missing channels 0, 0, 0, 1. `SWEEP_NORM_ONLY=1` limits it to the 20 norm formats (about 2 minutes). `SWEEP_D16=1` adds `tbuffer_load_format_d16_xyzw`, which needs #169. - `sweep_f16_alu`: `v_add/sub/mul/fma_f16`, `v_pk_add/mul/fma_f16` (both lanes), `v_cvt_f16_f32` and `v_cvt_f32_f16`, against the f64 result rounded to the nearest-even half. They're meant for checking rounding fixes. Results on a Radeon 860M (RDNA 3.5, driver 32.0.32029.2010) and WARP: | Tree | f16 ALU groups | norm format groups | |---|---|---| | `main` (ccfb029, after the rebase) | **0** | 32 (860M only; WARP exact) | | `main` before the rebase | 22 (every op, both backends) | 32 | | #422 | **0** | — | | #1387 | 20 (`v_fma_f16` fixed; the rest needs #422) | — | | #1112 | — | **0** (11,040 results) | `run_wide` is `run_cases` with a 4-dword UAV, so the wide formats' inputs fit. The normal suite is unchanged (`cargo test -p victory-shader --lib`: 120 passed, 0 failed). `cargo clippy -p victory-shader --all-targets [--all-features] --locked -- -D warnings` is clean. Run the sweeps with `cargo test -p victory-shader --lib sweep -- --ignored --nocapture`. A side finding: WARP's `uitofp` rounds twice for inputs of 2^31 and up. The 860M is correct. AI-assisted (Claude). Tested on a Radeon 860M and WARP. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two ignored tests run synthetic shaders on the hardware GPU and WARP and
print every mismatch, grouped by backend, operation and channel, with an
example input:

- sweep_typed_buffer_formats: all 77 GFX10 buffer formats through
  tbuffer_load_format_xyzw (one shader per channel), 72 input sets each,
  against the ISA's exact conversions (UNORM x/(2^n-1) and SNORM
  max(x/(2^(n-1)-1), -1) correctly rounded, scaled, integer, the small
  floats, missing channels 0, 0, 0, 1). SWEEP_D16=1 adds
  tbuffer_load_format_d16_xyzw (needs #169); SWEEP_NORM_ONLY=1 keeps the
  20 norm formats.
- sweep_f16_alu: v_add/sub/mul/fma_f16, v_pk_add/mul/fma_f16 (both
  lanes), v_cvt_f16_f32 and v_cvt_f32_f16 against f64 results rounded to
  the nearest-even half.

run_wide is run_cases with a 4-dword UAV, so the wide formats' inputs fit.

Run with: cargo test -p victory-shader --lib sweep -- --ignored --nocapture

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:36:55 +00:00
Author
Owner

@⁠matheusfermiano-source on GitHub · 2026-11-24 19:32 UTC · original

The same sweeps on a second AMD GPU and driver, an RDNA2 Radeon 660M under Proton on Linux (RADV, Mesa 26.3.1, vkd3d-proton 3.1.0). They agree with your table.

Tree f16 ALU groups norm format groups
main + this PR (856f0ce) 22: 11 per backend, every op 64: 32 per backend
#422 (a746d53) + valu_sweep_tests.rs 0 –
#1112 (4f5fa47) + valu_sweep_tests.rs – 0
  • Each count is per backend, so the numbers line up with yours. DXVK has no WARP, so here the "warp" rows are the 660M again, and each GPU group shows up twice. On real WARP you saw no norm mismatches.
  • On main the f16 groups cover v_add, v_sub, v_mul, v_fma, v_pk_add, v_pk_mul, v_pk_fma and v_cvt_f16_f32. Example: v_add_f16(0x7bff, 0x7bff) gives 0x7bff, want 0x7c00.
  • On main the norm groups cover 17 formats, from 8_UNORM to 16_16_16_16_SNORM, all off by one ulp. Example: 8_8_8_8_UNORM of 0x7f gives 0x3efeff00, want 0x3efefeff.
  • With #422 and #1112 the sweeps report no mismatches at all. Their full runs took 10 s (f16) and 140 s (norm).
  • The normal suite on this PR: 119 passed, 2 ignored (the sweeps). The one failure, emit::tests::stub_pipeline_is_created, fails on main here too, because vkd3d-proton accepts a zeroed DXIL hash (see #1218).

Built on Linux with llvm-mingw for x86_64-pc-windows-gnullvm (Rust 1.98.1); dxil.dll from DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.

**@⁠matheusfermiano-source** on GitHub · 2026-11-24 19:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7142253888) The same sweeps on a second AMD GPU and driver, an RDNA2 Radeon 660M under Proton on Linux (RADV, Mesa 26.3.1, vkd3d-proton 3.1.0). They agree with your table. | Tree | f16 ALU groups | norm format groups | |---|---|---| | `main` + this PR (`856f0ce`) | 22: 11 per backend, every op | 64: 32 per backend | | #422 (`a746d53`) + `valu_sweep_tests.rs` | **0** | – | | #1112 (`4f5fa47`) + `valu_sweep_tests.rs` | – | **0** | - Each count is per backend, so the numbers line up with yours. DXVK has no WARP, so here the "warp" rows are the 660M again, and each GPU group shows up twice. On real WARP you saw no norm mismatches. - On `main` the f16 groups cover `v_add`, `v_sub`, `v_mul`, `v_fma`, `v_pk_add`, `v_pk_mul`, `v_pk_fma` and `v_cvt_f16_f32`. Example: `v_add_f16(0x7bff, 0x7bff)` gives `0x7bff`, want `0x7c00`. - On `main` the norm groups cover 17 formats, from `8_UNORM` to `16_16_16_16_SNORM`, all off by one ulp. Example: `8_8_8_8_UNORM` of `0x7f` gives `0x3efeff00`, want `0x3efefeff`. - With #422 and #1112 the sweeps report no mismatches at all. Their full runs took 10 s (f16) and 140 s (norm). - The normal suite on this PR: 119 passed, 2 ignored (the sweeps). The one failure, `emit::tests::stub_pipeline_is_created`, fails on `main` here too, because vkd3d-proton accepts a zeroed DXIL hash (see #1218). Built on Linux with llvm-mingw for `x86_64-pc-windows-gnullvm` (Rust 1.98.1); `dxil.dll` from DXC 1.9.2609 was loaded. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-24 20:32 UTC · original · edited 2026-11-24 20:43 UTC

On PR head 856f0ce, the RTX 5080 reproduced the normalized-buffer rounding differences reported on Radeon. Native WARP matched the CPU reference for every typed-buffer result. Both adapters showed the same half-precision mismatch counts in each operation group.

Sweep Values compared per adapter RTX 5080 mismatches WARP mismatches
Half-precision arithmetic and conversions 2,076 618 across 11 groups 618 across 11 groups
Typed-buffer loads, all 77 formats 21,252 205 across 32 format/channel groups 0

Of the 205 RTX buffer mismatches, 169 were UNORM and 36 were SNORM. For example, loading 0x7f as 8_UNORM should yield the nearest float32 to 127/255, bit pattern 0x3efefeff. The RTX returned 0x3efeff00, one representable float higher. WARP matched the reference. For FP16, both adapters returned 0x7bff (65,504) for v_add_f16(0x7bff, 0x7bff); the nearest-even result is 0x7c00 (positive infinity).

Windows 11 build 26300.10075, NVIDIA driver 32.0.16.2124, Rust 1.98.1 MSVC. Test-only logging identified the D3D12 devices by adapter LUID as NVIDIA GeForce RTX 5080 and Microsoft Basic Render Driver. The FP16 counts above include both lanes of packed operations. The two sweeps completed in 567 s and both failed their reference assertions.

cargo test -p victory-shader --lib --locked --offline sweep -- --ignored --nocapture --test-threads=1

Follow-up with the two rounding fixes. I merged #422 (a746d53, round-to-nearest-even FP16 conversion) and #1112 (4f5fa47, normalized typed-buffer loads) into the same #1575 head and reran both full sweeps on the same adapters. All mismatch counts dropped to zero.

Mismatches, before → after RTX 5080 WARP
Half precision 618 → 0 618 → 0
Typed-buffer loads 205 → 0 0 → 0

Both adapters now return 0x3efefeff for 8_UNORM(0x7f) and 0x7c00 for the FP16 overflow example above. The sweeps passed in 559 s with the same CPU references and all 77 formats enabled. The ordinary shader library suite reported 123 passed, 0 failed and 3 ignored (the two opt-in sweeps and a benchmark). Four optional compiler-comparison cases reported skips within the pass count.

**@⁠steven-seagull27** on GitHub · 2026-11-24 20:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7143699194) · edited 2026-11-24 20:43 UTC On PR head `856f0ce`, the RTX 5080 reproduced the normalized-buffer rounding differences reported on Radeon. Native WARP matched the CPU reference for every typed-buffer result. Both adapters showed the same half-precision mismatch counts in each operation group. | Sweep | Values compared per adapter | RTX 5080 mismatches | WARP mismatches | |---|---:|---:|---:| | Half-precision arithmetic and conversions | 2,076 | 618 across 11 groups | 618 across 11 groups | | Typed-buffer loads, all 77 formats | 21,252 | 205 across 32 format/channel groups | 0 | Of the 205 RTX buffer mismatches, 169 were UNORM and 36 were SNORM. For example, loading `0x7f` as `8_UNORM` should yield the nearest float32 to `127/255`, bit pattern `0x3efefeff`. The RTX returned `0x3efeff00`, one representable float higher. WARP matched the reference. For FP16, both adapters returned `0x7bff` (65,504) for `v_add_f16(0x7bff, 0x7bff)`; the nearest-even result is `0x7c00` (positive infinity). Windows 11 build 26300.10075, NVIDIA driver `32.0.16.2124`, Rust `1.98.1` MSVC. Test-only logging identified the D3D12 devices by adapter LUID as NVIDIA GeForce RTX 5080 and Microsoft Basic Render Driver. The FP16 counts above include both lanes of packed operations. The two sweeps completed in 567 s and both failed their reference assertions. ```sh cargo test -p victory-shader --lib --locked --offline sweep -- --ignored --nocapture --test-threads=1 ``` **Follow-up with the two rounding fixes.** I merged #422 (`a746d53`, round-to-nearest-even FP16 conversion) and #1112 (`4f5fa47`, normalized typed-buffer loads) into the same #1575 head and reran both full sweeps on the same adapters. All mismatch counts dropped to zero. | Mismatches, before → after | RTX 5080 | WARP | |---|---:|---:| | Half precision | 618 → 0 | 618 → 0 | | Typed-buffer loads | 205 → 0 | 0 → 0 | Both adapters now return `0x3efefeff` for `8_UNORM(0x7f)` and `0x7c00` for the FP16 overflow example above. The sweeps passed in 559 s with the same CPU references and all 77 formats enabled. The ordinary shader library suite reported 123 passed, 0 failed and 3 ignored (the two opt-in sweeps and a benchmark). Four optional compiler-comparison cases reported skips within the pass count.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:31 UTC · original · edited 2026-11-25 22:26 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-shader/src/emit/valu_tests.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7149638593) · edited 2026-11-25 22:26 UTC <!-- victory-triage v1 head=2974745532ffa8e8f6e605a4d9646023f5521082 verdict=needs-rebase at=2026-11-25T22:29:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-shader/src/emit/valu_tests.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠StExpeditus on GitHub · 2026-11-25 09:25 UTC · original

Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24. Branch at 2974745. cargo test --workspace --locked --no-fail-fast -> 693 passed, 5 failed, 12 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.

**@⁠StExpeditus** on GitHub · 2026-11-25 09:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7158302873) **Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200, driver 621.24.** Branch at `2974745`. `cargo test --workspace --locked --no-fail-fast` -> 693 passed, 5 failed, 12 ignored. The failures are the same 5 pre-existing NVIDIA 1M-view-heap-cap failures (also on main; see my reports on #2030 and #1940). Nothing introduced by this PR fails on this machine.
Author
Owner

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

@⁠DovisLe I resolved the conflict with main 63bcca43 on your original 2974745 history. Both default sweeps now pass on the RTX 5080 (621.40) and built-in Microsoft WARP. Each adapter independently matched 21,252/21,252 typed-buffer channels and 2,076/2,076 FP16 lane results (1,716 ALU/conversion readback dwords). The 77-format sweep now dispatches all 69 inputs for a format together and fails if neither adapter runs. Tested branch · Conflict resolution alone

The optional D16 reference needed three adjustments. UINT/SINT saturate, normalized channels round the exact ratio once, and 32-bit FLOAT narrows toward zero. I also added the four 16-bit UNORM/SNORM codes that distinguish single rounding from conversion through f32. NaN payloads are still accepted by class. Native RDNA2 buffer measurements · FLOAT behavior and cross-backend regression

D16 mismatches per adapter, across 22,484 field comparisons (77 formats × 73 input rows × 4 channels). @⁠dooprazol, the two middle rows show which conversions your scaled fix and the normalized fix each cover. The RTX 5080 and WARP returned the same counts in every column.

Lowering on 63bcca43 UINT/SINT UNORM/SNORM USCALED/SSCALED FLOAT Total
Current main 1,318 1,155 281 0 2,754
#2843 (628ab89) 1,318 28 0 0 1,346
#1940 (95dc5d2, includes #1927) 0 0 281 0 281
Combined, including #2064 and the 32-bit #1940 follow-up 0 0 0 0 0

For example, #2843 alone gave 0x3bfe for 16_UNORM(0xffaf); a single rounding gives 0x3bfd. Conversely, #1940 alone gave 0x7bff for 16_USCALED(65535); the nearest half is infinity (0x7c00), which #2843 produced. Both backends passed all 22,484 ordinary 32-bit channel checks in the optional run as well. The combined branch passes strict shader Clippy and the asset policy check. These are synthetic Windows readbacks. Reproducible combined branch · 32-bit #1940 follow-up

To pick up the test changes on your PR branch:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1575-sweeps-nov26
git merge --ff-only FETCH_HEAD
cargo test -p victory-shader --lib --locked sweep -- --ignored --nocapture --test-threads=1

In PowerShell, set $env:SWEEP_D16 = '1' before the command to run the optional D16 comparison.

**@⁠steven-seagull27** on GitHub · 2026-11-26 01:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7180273767) @⁠DovisLe I resolved the conflict with main `63bcca43` on your original `2974745` history. Both default sweeps now pass on the RTX 5080 (621.40) and built-in Microsoft WARP. Each adapter independently matched **21,252/21,252 typed-buffer channels** and **2,076/2,076 FP16 lane results** (1,716 ALU/conversion readback dwords). The 77-format sweep now dispatches all 69 inputs for a format together and fails if neither adapter runs. [Tested branch](https://github.com/steven-seagull27/VIctory/commit/c7e0cd37997df7ad4c2ee49bd61e3cb81ff7aede) · [Conflict resolution alone](https://github.com/steven-seagull27/VIctory/commit/133432dbdd1eecda9536f74981b1d51d2bb2c416) The optional D16 reference needed three adjustments. UINT/SINT saturate, normalized channels round the exact ratio once, and 32-bit FLOAT narrows toward zero. I also added the four 16-bit UNORM/SNORM codes that distinguish single rounding from conversion through f32. NaN payloads are still accepted by class. [Native RDNA2 buffer measurements](https://github.com/xcl-dev/xcl/issues/1488#issuecomment-7142540028) · [FLOAT behavior and cross-backend regression](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2064) **D16 mismatches per adapter**, across 22,484 field comparisons (77 formats × 73 input rows × 4 channels). @⁠dooprazol, the two middle rows show which conversions your scaled fix and the normalized fix each cover. The RTX 5080 and WARP returned the same counts in every column. | Lowering on `63bcca43` | UINT/SINT | UNORM/SNORM | USCALED/SSCALED | FLOAT | Total | |---|---:|---:|---:|---:|---:| | Current main | 1,318 | 1,155 | 281 | 0 | 2,754 | | #2843 (`628ab89`) | 1,318 | 28 | 0 | 0 | 1,346 | | #1940 (`95dc5d2`, includes #1927) | 0 | 0 | 281 | 0 | 281 | | Combined, including #2064 and the 32-bit #1940 follow-up | 0 | 0 | 0 | 0 | 0 | For example, #2843 alone gave `0x3bfe` for `16_UNORM(0xffaf)`; a single rounding gives `0x3bfd`. Conversely, #1940 alone gave `0x7bff` for `16_USCALED(65535)`; the nearest half is infinity (`0x7c00`), which #2843 produced. Both backends passed all 22,484 ordinary 32-bit channel checks in the optional run as well. The combined branch passes strict shader Clippy and the asset policy check. These are synthetic Windows readbacks. [Reproducible combined branch](https://github.com/steven-seagull27/VIctory/commit/7f48b7962b63cd5456e3f70b66e8900557ebdee9) · [32-bit #1940 follow-up](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1940) To pick up the test changes on your PR branch: ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1575-sweeps-nov26 git merge --ff-only FETCH_HEAD cargo test -p victory-shader --lib --locked sweep -- --ignored --nocapture --test-threads=1 ``` In PowerShell, set `$env:SWEEP_D16 = '1'` before the command to run the optional D16 comparison.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_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/1575/head:github-bot/gh-1575'
git switch 'github-bot/gh-1575'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1575'
git switch 'github-bot/gh-1575'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1575'
git switch 'github-bot/gh-1575'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1575'
git switch 'main'
git merge --squash 'github-bot/gh-1575'
git switch 'main'
git merge --ff-only 'github-bot/gh-1575'
git switch 'main'
git merge 'github-bot/gh-1575'
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!1575
No description provided.