Shaders: round scaled and normalized D16 buffer loads to nearest even #2843

Open
github-bot wants to merge 3 commits from github-bot/gh-2843 into main AGit
Owner

@⁠dooprazol on GitHub · 2026-11-25 22:02 UTC · original
dooprazol:fix/d16-buffer-rounding → main · +58 −8 · 2 files · 3 commits · open

Use the existing bitwise narrowing implementation for scaled and normalized D16 buffer loads. For example, 2051 rounds to 2052. The synthetic shader regression failed before the fix and passed afterward. On b2a97b1, cargo test --locked -p victory-shader passed on Linux with 166 passed and 3 ignored. On the initial base, cargo test --workspace failed during Linux compilation on both clean and patched trees.The Windows shader tests were type-checked. No RX 9060 XT dispatch or gameplay was tested. The device-loss reports remain open.

**@⁠dooprazol** on GitHub · 2026-11-25 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843) `dooprazol:fix/d16-buffer-rounding` → `main` · +58 −8 · 2 files · 3 commits · open Use the existing bitwise narrowing implementation for scaled and normalized D16 buffer loads. For example, 2051 rounds to 2052. The synthetic shader regression failed before the fix and passed afterward. On b2a97b1, cargo test --locked -p victory-shader passed on Linux with 166 passed and 3 ignored. On the initial base, cargo test --workspace failed during Linux compilation on both clean and patched trees.The Windows shader tests were type-checked. No RX 9060 XT dispatch or gameplay was tested. The device-loss reports remain open.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:15:42 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 22:29 UTC · original

Independent Windows verification of a0a2e525 against current main (f3578e38).

  • The synthetic D16 USCALED lowering test passed on the corrected PR-head build. With the same test and its test-only intrinsic probe added to current main, the assertion failed because the lowering still emitted legacyF32ToF16. This check inspects the emitted code.
  • The earlier forced-WARP shader suite had 299 passed, 4 failed, 3 ignored on the PR and 298 passed, 4 failed, 3 ignored on main. The four failures were identical. The force flag also routed the harness's hardware-labelled cases through WARP. With that override removed and a local guard refusing hardware device creation, the explicit WARP gather case passed on the PR. It logged Microsoft Basic Render Driver (0x1414:0x008c, software flag 0x2) with the SDK dxil.dll configured. The full suite was not rerun with this harness change.

Claude Code (claude-opus-5-5) ran the shader suites and rebuilt the PR after detecting stale Cargo artifacts. Codex (gpt-6.2-sol) checked the corrected logs, ran the targeted main comparison and verified the adapter with the focused WARP run. Synthetic data only.

**@⁠oni-swr** on GitHub · 2026-11-25 22:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7176429163) <!-- oni-swr warp verification a0a2e525b5c52968b2972ee0ff902b54ca9aa8b8 --> Independent Windows verification of `a0a2e525` against current `main` (`f3578e38`). - The synthetic D16 USCALED lowering test passed on the corrected PR-head build. With the same test and its test-only intrinsic probe added to current `main`, the assertion failed because the lowering still emitted `legacyF32ToF16`. This check inspects the emitted code. - The earlier forced-WARP shader suite had 299 passed, 4 failed, 3 ignored on the PR and 298 passed, 4 failed, 3 ignored on main. The four failures were identical. The force flag also routed the harness's hardware-labelled cases through WARP. With that override removed and a local guard refusing hardware device creation, the explicit WARP gather case passed on the PR. It logged Microsoft Basic Render Driver (`0x1414:0x008c`, software flag `0x2`) with the SDK `dxil.dll` configured. The full suite was not rerun with this harness change. Claude Code (claude-opus-5-5) ran the shader suites and rebuilt the PR after detecting stale Cargo artifacts. Codex (gpt-6.2-sol) checked the corrected logs, ran the targeted main comparison and verified the adapter with the focused WARP run. Synthetic data only.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 22:47 UTC · original

Reviewed and verified a0a2e525 on Windows 11 (RTX 5090 + WARP + dxil.dll) against main (f3578e3):

  • Splitting narrow16 into narrow16_bits(f, rtz) and routing d16_channels (Uscaled | Sscaled | Unorm | Snorm) through narrow16_bits(f, false) cleanly enforces portable IEEE round-to-nearest-even (including ±0.0, ±Inf, quiet NaN payload, subnormal sticky bit, and USCALED 65520..=65535 -> +Inf) regardless of VALU MODE, while keeping Uint/Sint (& 0xFFFF) and Float (legacyF32ToF16) intact.
  • Local verification: cargo test --locked -p victory-shader --lib d16 5/5 passed (including d16_scaled_buffer_load_uses_portable_rounding and the updated tbuffer_d16_loads_pack_two_channels_per_dword), emit::lower::tests 34/34 passed, cargo clippy --locked -p victory-shader --all-targets -- -D warnings 0 warnings, cargo xtask policy (190 files ok).
  • Three small notes for maintainers/author:
    1. crates/victory-shader/src/emit/lower.rs is at 521,634 bytes (2,654 bytes under the 512 KiB xtask policy cap).
    2. The branch currently carries a merge commit (a0a2e52) that also adds #[cfg(windows)] on 3 Validator::load sites in lower.rs — rebasing onto main would keep the history linear.
    3. Scope is buffer D16 loads (d16_channels); image D16 paths are untouched.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 22:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7176789512) Reviewed and verified `a0a2e525` on Windows 11 (RTX 5090 + WARP + `dxil.dll`) against `main` (`f3578e3`): - Splitting `narrow16` into `narrow16_bits(f, rtz)` and routing `d16_channels` (`Uscaled | Sscaled | Unorm | Snorm`) through `narrow16_bits(f, false)` cleanly enforces portable IEEE round-to-nearest-even (including `±0.0`, `±Inf`, quiet NaN payload, subnormal sticky bit, and `USCALED` `65520..=65535 -> +Inf`) regardless of `VALU MODE`, while keeping `Uint`/`Sint` (`& 0xFFFF`) and `Float` (`legacyF32ToF16`) intact. - Local verification: `cargo test --locked -p victory-shader --lib d16` 5/5 passed (including `d16_scaled_buffer_load_uses_portable_rounding` and the updated `tbuffer_d16_loads_pack_two_channels_per_dword`), `emit::lower::tests` 34/34 passed, `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` 0 warnings, `cargo xtask policy` (`190 files ok`). - Three small notes for maintainers/author: 1. `crates/victory-shader/src/emit/lower.rs` is at `521,634` bytes (`2,654` bytes under the 512 KiB `xtask policy` cap). 2. The branch currently carries a merge commit (`a0a2e52`) that also adds `#[cfg(windows)]` on 3 `Validator::load` sites in `lower.rs` — rebasing onto `main` would keep the history linear. 3. Scope is buffer D16 loads (`d16_channels`); image D16 paths are untouched.
Author
Owner

@⁠dooprazol on GitHub · 2026-11-25 22:51 UTC · original

Confirmed on Windows 11 with a Radeon RX 9060 XT 16 GB at a0a2e525. The focused tbuffer_d16_loads_pack_two_channels_per_dword test passed (1 passed, 0 failed). Local DXGI logging identified the physical adapter as warp=false name=AMD Radeon RX 9060 XT. WARP also ran separately.

The numerical checks included 2051 → 2052, −2051 → −2052, and 2049 → 2048. This run used synthetic buffer data only.

**@⁠dooprazol** on GitHub · 2026-11-25 22:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7176868632) Confirmed on Windows 11 with a Radeon RX 9060 XT 16 GB at a0a2e525. The focused tbuffer_d16_loads_pack_two_channels_per_dword test passed (1 passed, 0 failed). Local DXGI logging identified the physical adapter as warp=false name=AMD Radeon RX 9060 XT. WARP also ran separately. The numerical checks included 2051 → 2052, −2051 → −2052, and 2049 → 2048. This run used synthetic buffer data only.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 03:24 UTC · original

Automated triage for the maintainers.

Verdict: needs work. The code does what the title says. In crates/victory-shader/src/emit/lower.rs, narrow16 is split into narrow16_bits(f, rtz), and the D16 packing loop sends Uscaled/Sscaled/Unorm/Snorm channels through narrow16_bits(f, false) instead of legacyF32ToF16. Float keeps legacyF32ToF16 and the integer formats keep the mask. It merges cleanly.

What is missing is evidence for the console behaviour it encodes. This changes emulation results, and the tests (tbuffer_d16_loads_pack_two_channels_per_dword's new rows, d16_uscaled_keeps_nearest_even_in_valu_rtz_mode) check the emitted conversion against the values the PR expects (2051 to 2052, and RNE under MODE RTZ), not against the console. Please point to something that shows the console's D16 format conversion rounds to nearest even and ignores the VALU MODE round bits: a hardware capture, the public ISA documentation, or the title's own data depending on it. Two further points: why should Float (f32 data narrowed to f16) still use the host's legacyF32ToF16 rounding when the scaled and normalized formats do not? And the #[cfg(windows)] additions on the three Validator::load test sites are unrelated, so they would fit better in a separate PR.

CI: not run on this head yet (awaiting workflow approval).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 03:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7181691206) <!-- victory-triage v1 head=628ab8900ca4ac04b5b7a2f1342193484821bb67 verdict=needs-work at=2026-11-26T03:24:26Z --> Automated triage for the maintainers. **Verdict: needs work.** The code does what the title says. In `crates/victory-shader/src/emit/lower.rs`, `narrow16` is split into `narrow16_bits(f, rtz)`, and the D16 packing loop sends `Uscaled`/`Sscaled`/`Unorm`/`Snorm` channels through `narrow16_bits(f, false)` instead of `legacyF32ToF16`. `Float` keeps `legacyF32ToF16` and the integer formats keep the mask. It merges cleanly. What is missing is evidence for the console behaviour it encodes. This changes emulation results, and the tests (`tbuffer_d16_loads_pack_two_channels_per_dword`'s new rows, `d16_uscaled_keeps_nearest_even_in_valu_rtz_mode`) check the emitted conversion against the values the PR expects (2051 to 2052, and RNE under MODE RTZ), not against the console. Please point to something that shows the console's D16 format conversion rounds to nearest even and ignores the VALU MODE round bits: a hardware capture, the public ISA documentation, or the title's own data depending on it. Two further points: why should `Float` (f32 data narrowed to f16) still use the host's `legacyF32ToF16` rounding when the scaled and normalized formats do not? And the `#[cfg(windows)]` additions on the three `Validator::load` test sites are unrelated, so they would fit better in a separate PR. CI: not run on this head yet (awaiting workflow approval). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 22:11 UTC · original · reviewed

Correct: D16 conversions of scaled/normalized formats are always round-to-nearest-even in the ISA — VALU MODE's rtz applies only to explicit v_cvt_f16_f32. narrow16_bits parameterizing the direction keeps the MODE-sensitive path and the fixed-RNE path sharing one implementation. The legacy_half_conversion test flag checks the right observable. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 22:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#pullrequestreview-6065694809) · **reviewed** Correct: D16 conversions of scaled/normalized formats are always round-to-nearest-even in the ISA — VALU MODE's rtz applies only to explicit v_cvt_f16_f32. narrow16_bits parameterizing the direction keeps the MODE-sensitive path and the fixed-RNE path sharing one implementation. The legacy_half_conversion test flag checks the right observable. LGTM.
Author
Owner

@⁠AwsAli05 on GitHub · 2026-11-25 23:15 UTC · original · reviewed

The focused portable-rounding test passed on Windows at a0a2e525. The distinction between fixed D16 rounding and VALU's configurable rounding is the part I would pin with a second case. Run the same halfway USCALED load after selecting round-toward-zero with the existing MODE fixture. 2051 should still produce 2052. That would catch accidentally routing this path through mode-sensitive narrow16, which would still satisfy the current check for absence of the legacy DXIL conversion.

AI-assisted review and test.

**@⁠AwsAli05** on GitHub · 2026-11-25 23:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#pullrequestreview-6066282858) · **reviewed** The focused portable-rounding test passed on Windows at `a0a2e525`. The distinction between fixed D16 rounding and VALU's configurable rounding is the part I would pin with a second case. Run the same halfway USCALED load after selecting round-toward-zero with the existing MODE fixture. 2051 should still produce 2052. That would catch accidentally routing this path through mode-sensitive `narrow16`, which would still satisfy the current check for absence of the legacy DXIL conversion. AI-assisted review and test.
Author
Owner

@⁠Jackster on GitHub · 2026-11-26 16:06 UTC · original · edited 2026-11-26 16:08 UTC

AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), victory-shader built with --features host:

  • Test-only on 63bcca4: 2 of 6 d16_ cases fail on the hardware backend (format 9 of 0x00000803 → 0x00006801, want 0x00006802).
  • With the PR: 6/6 pass.

Synthetic only. AI-assisted.

**@⁠Jackster** on GitHub · 2026-11-26 16:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7197192833) · edited 2026-11-26 16:08 UTC AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010), `victory-shader` built with `--features host`: - Test-only on 63bcca4: 2 of 6 `d16_` cases fail on the hardware backend (format 9 of `0x00000803` → `0x00006801`, want `0x00006802`). - With the PR: 6/6 pass. Synthetic only. AI-assisted.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-26 20:53 UTC · original · edited 2026-11-26 20:55 UTC

NEW-284 verification on current head, Windows 11, toolchain 1.98.1, --test-threads=1, AMD Radeon 780M (RDNA3 iGPU) and WARP (VICTORY_WARP=1).

  • cargo test -p victory-shader -p victory-gpu --locked --no-fail-fast: no failures on the 780M; on WARP only the four synthetic_tests failures main 63bcca4 also has (fixed by #2225).
  • New tests pass on both: d16_scaled_buffer_load_uses_portable_rounding, d16_uscaled_keeps_nearest_even_in_valu_rtz_mode.
  • The branch is 3 commits behind main (3 tests main has are not on it yet); tested as-is.

AI-assisted (Claude).

**@⁠kilolimaVI** on GitHub · 2026-11-26 20:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2843#issuecomment-7203178291) · edited 2026-11-26 20:55 UTC NEW-284 verification on current head, Windows 11, toolchain 1.98.1, `--test-threads=1`, AMD Radeon 780M (RDNA3 iGPU) and WARP (`VICTORY_WARP=1`). - `cargo test -p victory-shader -p victory-gpu --locked --no-fail-fast`: no failures on the 780M; on WARP only the four synthetic_tests failures main 63bcca4 also has (fixed by #2225). - New tests pass on both: `d16_scaled_buffer_load_uses_portable_rounding`, `d16_uscaled_keeps_nearest_even_in_valu_rtz_mode`. - The branch is 3 commits behind main (3 tests main has are not on it yet); tested as-is. AI-assisted (Claude).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/2843/head:github-bot/gh-2843'
git switch 'github-bot/gh-2843'

Merge

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