Shaders: d16 buffer format loads of UNORM / SNORM data round once to nearest #1940

Open
github-bot wants to merge 4 commits from github-bot/gh-1940 into main AGit
Owner

@⁠upipibi on GitHub · 2026-11-25 01:24 UTC · original
upipibi:fix/d16-norm-single-round → main · +162 −4 · 3 files · 4 commits · open

Stacked on #1927: the second, third and fourth commits (Shaders: d16 format loads of UNORM / SNORM data round once to nearest, and 95dc5d2, which moves this PR's norm_f16 unchanged into the new child module emit/lower/d16.rs to keep lower.rs under the 512 KiB policy limit, and steven-seagull27's f41d919, which drops the 64-bit divide) belong to this PR. Both of the first two change d16_channels. Scope: D16 buffer format loads (tbuffer_load_format_d16* / buffer_load_format_d16*) only.

A d16 buffer format load of a UNORM / SNORM channel went through legacyF32ToF16 of the decoded f32. That's two roundings, and the second rounds toward zero. RDNA2 rounds code / (2^w − 1) once, to nearest even (gfx1031 for buffer format loads, xcl-dev/xcl#1488 XCL-BT-020; gfx1036 for D16 image reads, boykopovar/AnyPS5#22750). So about half of all codes came back one unit in the last place low: 16_UNORM 0x0801 gave 0x2800, where RDNA2 gives 0x2801.

What is in it

  • emit/lower/d16.rs (a child module of emit/lower.rs): norm_f16, used by d16_channels (in lower.rs) for UNORM / SNORM channels of 2 to 16 bits. The width comes from buffer_format, so it's a constant.
    • The code is recovered from the decoded value as round(|f| · (2^w − 1)).
    • code / (2^w − 1) has a binary expansion that repeats the w-bit code, so its first 32 bits decide the rounding, and a tie can't happen. They are built in 32 bits: code · ⌊(2^32 − 1) / (2^w − 1)⌋ places every whole copy, and when w doesn't divide 32 the top 32 mod w bits of the code fill the low bits. No 64-bit arithmetic, so the shader no longer needs Int64ShaderOps. This is steven-seagull27's patch (f41d919, #1940), which replaced the 64-bit udiv the first version used; it also adds d16_normalized_format_loads_do_not_require_int64, which checks that SFI0 bit 0x8000 is clear for all 20 UNORM / SNORM buffer formats.
    • SNORM uses |v| / (2^(w−1) − 1) with the sign put back.
    • Other formats are unchanged. Floats keep legacyF32ToF16, whose toward-zero rounding matches RDNA2's packing of 32-bit float texels.
  • emit/valu_tests.rs: tbuffer_d16_loads_of_16_bit_norms_round_once checks 64 16_UNORM and 64 16_SNORM codes against exact single rounding. Only the low half is compared.

Overlap: #2843 (opened 22:02Z) changes the same d16_channels path and valu_tests.rs. For USCALED / SSCALED / UNORM / SNORM it converts the decoded f32 with narrow16_bits(f, false) (round to nearest even) instead of legacyF32ToF16; this PR instead rounds code / (2^w − 1) once, from the integer code, for UNORM / SNORM only. So #2843 still rounds twice (to f32, then to f16), and also covers the scaled formats, which this PR leaves alone. Measured over all 65536 codes per format at a0a2e52 (RTX 3070, driver 616.56, and WARP, same bits on both): it differs from single rounding on exactly 2 16_UNORM codes (0xFFAF gives 0x3BFE, want 0x3BFD; 0xFFEF gives 0x3C00, want 0x3BFF) and 2 16_SNORM codes (0x7FF7 gives 0x3C00, want 0x3BFF; 0x8009 gives 0xBC00, want 0xBBFF), each 1 ulp larger in magnitude: there the decoded f32 lands exactly on an f16 midpoint. This PR's tbuffer_d16_loads_of_16_bit_norms_round_once, copied onto #2843 unchanged, fails on those codes on both backends. For comparison, main (842b0cb) truncates and differs on 31740 16_UNORM and 30716 16_SNORM codes. #2843's own test checks only that legacyF32ToF16 is gone. dooprazol confirmed the two 16_UNORM codes on a Radeon RX 9060 XT and WARP, with this PR exact on both: #1940 The two conflict in lower.rs (git merge-tree of both heads).

Related: #2030 rounds D16 image reads of UNORM / SNORM textures the same way (code / (2^w − 1) rounded once to nearest even). This PR covers the buffer format-load path (d16_channels) and doesn't touch the image path; the two change different functions, so their own changes don't conflict.

Tested

  • At f41d919 merged with main 63bcca4 (clean): cargo xtask policy passes, cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean, cargo test -p victory-shader --lib d16 -- --nocapture: 7 passed, 0 failed, on both the RTX 3070 (616.56) and WARP (no skip lines). At f41d919 alone: policy and clippy pass, d16 7 passed, 0 failed. lower.rs is unchanged by it (521,518 bytes after the merge). The 32-bit sum equals the old (code << 32) / (2^w − 1) for every code below 2^w − 1 at w = 1…16 (131,054 checks, CPU). steven-seagull27 reports 962,048 / 962,048 exact field values on an RTX 5080 and on WARP.
  • At 95dc5d2 merged with main 63bcca4 (clean): lower.rs 521,518 bytes (limit 524,288; it was 524,906 before the move), cargo xtask policy passes, cargo clippy -p victory-shader --all-targets --locked -- -D warnings clean, cargo test -p victory-shader --lib d16: 6 passed, 0 failed on the RTX 3070 (616.56) and on WARP. Headroom after the merge is 2,770 bytes: another PR that grows lower.rs (e.g. #2942) can use it up.
  • A model of norm_f16 against exact rational rounding: every code at w = 2…16, UNORM and SNORM, with the decoded value off by up to ±2 ULP (524,272 checks). No mismatches.
  • Windows 11, RTX 3070 (Ampere, driver 616.56), and WARP, debug, at the earlier head 4919f2e (base 940d32f):
    • new test: main fails on both backends with 57 of the 128 codes one ULP low. This branch passes.
    • cargo test -p victory-shader --locked: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on main.
    • cargo xtask policy and cargo clippy -p victory-shader --all-targets --locked -- -D warnings: pass.
  • Rebased onto main 67e8ae1 (head d09a715). The conflict with da82e44 was two functions added at the same place in lower.rs (its norm_quotient/exact_norm for f32 loads, and this PR's norm_f16); both are kept. RTX 3070, debug:
    • cargo test -p victory-shader --lib d16: 6 passed, 0 failed.
    • new test on main 67e8ae1 plus #1927's commit, with only this test added (no fix): fails 3 of 3 on the RTX 3070 and on WARP, first at 16_UNORM 0x0801 (0x2800, want 0x2801). So da82e44 doesn't cover the d16 path; this PR is still needed.
    • cargo test -p victory-shader --locked with heap_direct_texture_reads_mark_their_heap_index skipped: 268 passed, 3 failed (the same #1744 failures). That test crashes the test process on main 67e8ae1 on this card too (#2571; a fix is proposed in #2596, open, which passes that test 3 of 3 on this card).
    • cargo xtask policy and cargo clippy -p victory-shader --all-targets --locked -- -D warnings: pass.

Not tested: a title. D16 image reads are not in scope here; #2030 covers them with the same single-rounding rule.

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

**@⁠upipibi** on GitHub · 2026-11-25 01:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940) `upipibi:fix/d16-norm-single-round` → `main` · +162 −4 · 3 files · 4 commits · open Stacked on #1927: the second, third and fourth commits (`Shaders: d16 format loads of UNORM / SNORM data round once to nearest`, and `95dc5d2`, which moves this PR's `norm_f16` unchanged into the new child module `emit/lower/d16.rs` to keep `lower.rs` under the 512 KiB policy limit, and steven-seagull27's `f41d919`, which drops the 64-bit divide) belong to this PR. Both of the first two change `d16_channels`. Scope: D16 **buffer format** loads (`tbuffer_load_format_d16*` / `buffer_load_format_d16*`) only. A d16 buffer format load of a UNORM / SNORM channel went through `legacyF32ToF16` of the decoded f32. That's two roundings, and the second rounds toward zero. RDNA2 rounds `code / (2^w − 1)` once, to nearest even (gfx1031 for buffer format loads, xcl-dev/xcl#1488 XCL-BT-020; gfx1036 for D16 image reads, boykopovar/AnyPS5#22750). So about half of all codes came back one unit in the last place low: 16_UNORM `0x0801` gave `0x2800`, where RDNA2 gives `0x2801`. **What is in it** - `emit/lower/d16.rs` (a child module of `emit/lower.rs`): `norm_f16`, used by `d16_channels` (in `lower.rs`) for UNORM / SNORM channels of 2 to 16 bits. The width comes from `buffer_format`, so it's a constant. - The code is recovered from the decoded value as `round(|f| · (2^w − 1))`. - `code / (2^w − 1)` has a binary expansion that repeats the `w`-bit code, so its first 32 bits decide the rounding, and a tie can't happen. They are built in 32 bits: `code · ⌊(2^32 − 1) / (2^w − 1)⌋` places every whole copy, and when `w` doesn't divide 32 the top `32 mod w` bits of the code fill the low bits. No 64-bit arithmetic, so the shader no longer needs Int64ShaderOps. This is steven-seagull27's patch (`f41d919`, https://git.gtahub.st/github/Marvisak--VIctory/pulls/1940), which replaced the 64-bit `udiv` the first version used; it also adds `d16_normalized_format_loads_do_not_require_int64`, which checks that SFI0 bit 0x8000 is clear for all 20 UNORM / SNORM buffer formats. - SNORM uses `|v| / (2^(w−1) − 1)` with the sign put back. - Other formats are unchanged. Floats keep `legacyF32ToF16`, whose toward-zero rounding matches RDNA2's packing of 32-bit float texels. - `emit/valu_tests.rs`: `tbuffer_d16_loads_of_16_bit_norms_round_once` checks 64 16_UNORM and 64 16_SNORM codes against exact single rounding. Only the low half is compared. **Overlap:** #2843 (opened 22:02Z) changes the same `d16_channels` path and `valu_tests.rs`. For USCALED / SSCALED / UNORM / SNORM it converts the decoded f32 with `narrow16_bits(f, false)` (round to nearest even) instead of `legacyF32ToF16`; this PR instead rounds `code / (2^w − 1)` once, from the integer code, for UNORM / SNORM only. So #2843 still rounds twice (to f32, then to f16), and also covers the scaled formats, which this PR leaves alone. Measured over all 65536 codes per format at `a0a2e52` (RTX 3070, driver 616.56, and WARP, same bits on both): it differs from single rounding on exactly 2 16_UNORM codes (`0xFFAF` gives `0x3BFE`, want `0x3BFD`; `0xFFEF` gives `0x3C00`, want `0x3BFF`) and 2 16_SNORM codes (`0x7FF7` gives `0x3C00`, want `0x3BFF`; `0x8009` gives `0xBC00`, want `0xBBFF`), each 1 ulp larger in magnitude: there the decoded f32 lands exactly on an f16 midpoint. This PR's `tbuffer_d16_loads_of_16_bit_norms_round_once`, copied onto #2843 unchanged, fails on those codes on both backends. For comparison, `main` (`842b0cb`) truncates and differs on 31740 16_UNORM and 30716 16_SNORM codes. #2843's own test checks only that `legacyF32ToF16` is gone. dooprazol confirmed the two 16_UNORM codes on a Radeon RX 9060 XT and WARP, with this PR exact on both: https://git.gtahub.st/github/Marvisak--VIctory/pulls/1940 The two conflict in `lower.rs` (`git merge-tree` of both heads). **Related:** #2030 rounds D16 image reads of UNORM / SNORM textures the same way (`code / (2^w − 1)` rounded once to nearest even). This PR covers the buffer format-load path (`d16_channels`) and doesn't touch the image path; the two change different functions, so their own changes don't conflict. **Tested** - At `f41d919` merged with `main` `63bcca4` (clean): `cargo xtask policy` passes, `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` is clean, `cargo test -p victory-shader --lib d16 -- --nocapture`: 7 passed, 0 failed, on both the RTX 3070 (616.56) and WARP (no skip lines). At `f41d919` alone: policy and clippy pass, d16 7 passed, 0 failed. `lower.rs` is unchanged by it (521,518 bytes after the merge). The 32-bit sum equals the old `(code << 32) / (2^w − 1)` for every code below `2^w − 1` at `w` = 1…16 (131,054 checks, CPU). steven-seagull27 reports 962,048 / 962,048 exact field values on an RTX 5080 and on WARP. - At `95dc5d2` merged with `main` `63bcca4` (clean): `lower.rs` 521,518 bytes (limit 524,288; it was 524,906 before the move), `cargo xtask policy` passes, `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` clean, `cargo test -p victory-shader --lib d16`: 6 passed, 0 failed on the RTX 3070 (616.56) and on WARP. Headroom after the merge is 2,770 bytes: another PR that grows `lower.rs` (e.g. #2942) can use it up. - A model of `norm_f16` against exact rational rounding: every code at `w` = 2…16, UNORM and SNORM, with the decoded value off by up to ±2 ULP (524,272 checks). No mismatches. - Windows 11, RTX 3070 (Ampere, driver 616.56), and WARP, debug, at the earlier head `4919f2e` (base `940d32f`): - new test: `main` fails on both backends with 57 of the 128 codes one ULP low. This branch passes. - `cargo test -p victory-shader --locked`: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on `main`. - `cargo xtask policy` and `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: pass. - Rebased onto `main` `67e8ae1` (head `d09a715`). The conflict with `da82e44` was two functions added at the same place in `lower.rs` (its `norm_quotient`/`exact_norm` for f32 loads, and this PR's `norm_f16`); both are kept. RTX 3070, debug: - `cargo test -p victory-shader --lib d16`: 6 passed, 0 failed. - new test on `main` `67e8ae1` plus #1927's commit, with only this test added (no fix): fails 3 of 3 on the RTX 3070 and on WARP, first at 16_UNORM `0x0801` (`0x2800`, want `0x2801`). So `da82e44` doesn't cover the d16 path; this PR is still needed. - `cargo test -p victory-shader --locked` with `heap_direct_texture_reads_mark_their_heap_index` skipped: 268 passed, 3 failed (the same #1744 failures). That test crashes the test process on `main` `67e8ae1` on this card too (#2571; a fix is proposed in #2596, open, which passes that test 3 of 3 on this card). - `cargo xtask policy` and `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: pass. **Not tested:** a title. D16 image reads are not in scope here; #2030 covers them with the same single-rounding rule. AI-assisted (Claude Code, Claude Opus 5.5). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
RDNA2 saturates a 32-bit UINT channel of a d16 format load to 0xFFFF and
a SINT one to -32768..32767; d16_channels kept the low 16 bits (70000
loaded as 0x1170). Measured on gfx1031 (xcl-dev/xcl#1488, XCL-BT-020) and
gfx1036 (boykopovar/AnyPS5#22750). 8- and 16-bit formats never leave that
range, so they are unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A d16 format load of a UNORM / SNORM channel went through legacyF32ToF16
of the decoded f32: two roundings, the second toward zero. RDNA2 rounds
code / (2^w - 1) once to nearest even, so about half of the codes came
back a unit low (16_UNORM 0x0801: 0x2800 for 0x2801; 57 of 128 sampled
16-bit codes on hardware and WARP). The value's binary expansion repeats
the w-bit code, so its first 32 bits decide the rounding and a tie
cannot happen (checked against exact rounding for every code at w = 2..16).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged onto main, lower.rs was 524,906 bytes, over the 524,288 bytes
cargo xtask policy allows. norm_f16, which this branch adds, moves
unchanged with its doc comment into lower/d16.rs, a child module like
lower/bvh.rs; d16_channels stays in lower.rs and calls it as before.

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

@⁠Headache3318 on GitHub · 2026-11-25 02:04 UTC · original

Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 4919f2e applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The new tbuffer_d16_loads_of_16_bit_norms_round_once test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on main ccfb029). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

**@⁠Headache3318** on GitHub · 2026-11-25 02:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7150287803) Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `4919f2e` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 144 passed, 0 failed, 2 ignored. All tests pass. The new `tbuffer_d16_loads_of_16_bit_norms_round_once` test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 4 pre-existing errors in test code (fail identically on main `ccfb029`). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
Author
Owner

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

Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200

Environment: Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5060 Ti (driver 621.24, 32.0.16.2124) beside an Intel UHD 770 iGPU, Intel Core i5-14600K, 32 GB, Rust 1.98.1 MSVC. Branch fix/d16-norm-single-round at 4919f2e1. No game files; the title was not run.

cargo test --workspace --locked --no-fail-fast -> 694 passed, 5 failed, 10 ignored.

The PR's D16 buffer tests pass on this hardware:

  • tbuffer_d16_loads_of_16_bit_norms_round_once
  • tbuffer_d16_loads_saturate_32_bit_integers

The 5 failures are the same pre-existing NVIDIA 1,000,000-view heap cap (HEAP_VIEWS is 2^21) I also reported on #2030: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views (heap.NumDescriptors >= HEAP_VIEWS), and victory-shader emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros (dispatch E_INVALIDARG) and emit::synthetic_tests::gathers_at_a_level_match_the_hardware. They reproduce identically on main, and match #1835, #1808, #1760 and test report #1744. Nothing introduced by this PR fails on this machine.

Triage note: this branch is based on ccfb0299, older than current main (940d32f6); GitHub reports it mergeable, but the report above is for the branch as-is, not merged onto current main.

**@⁠StExpeditus** on GitHub · 2026-11-25 04:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7152763870) **Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200** **Environment:** Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5060 Ti (driver 621.24, `32.0.16.2124`) beside an Intel UHD 770 iGPU, Intel Core i5-14600K, 32 GB, Rust 1.98.1 MSVC. Branch `fix/d16-norm-single-round` at `4919f2e1`. No game files; the title was not run. `cargo test --workspace --locked --no-fail-fast` -> **694 passed, 5 failed, 10 ignored**. **The PR's D16 buffer tests pass on this hardware:** - `tbuffer_d16_loads_of_16_bit_norms_round_once` - `tbuffer_d16_loads_saturate_32_bit_integers` **The 5 failures are the same pre-existing NVIDIA 1,000,000-view heap cap** (`HEAP_VIEWS` is 2^21) I also reported on #2030: `victory-gpu` `descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views` (`heap.NumDescriptors >= HEAP_VIEWS`), and `victory-shader` `emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` (dispatch `E_INVALIDARG`) and `emit::synthetic_tests::gathers_at_a_level_match_the_hardware`. They reproduce identically on main, and match #1835, #1808, #1760 and test report #1744. Nothing introduced by this PR fails on this machine. **Triage note:** this branch is based on `ccfb0299`, older than current main (`940d32f6`); GitHub reports it mergeable, but the report above is for the branch as-is, not merged onto current main.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:17 UTC · original · edited 2026-11-26 03:23 UTC

Automated triage for the maintainers.

Verdict: merge candidate (unchanged). The new commit f41d919 (steven-seagull27's, taken in with authorship) replaces the 64-bit udiv in Lower::norm_f16 (emit/lower/d16.rs) with 32-bit field replication. I checked it. u32::MAX / d is 2^r · Σ 2^(i·w) with r = 32 mod w, so y · copies places every whole copy of the code, and y >> (w − r) fills the low r bits. The product cannot overflow because y < d. y = 0 and y ≥ d are still selected explicitly, which also covers the 1-bit SNORM case (d = 1). The shader no longer sets INT64, and the new d16_normalized_format_loads_do_not_require_int64 test checks SFI0 bit 0x8000 for all 20 UNORM/SNORM formats.

It merges cleanly with main, and lower.rs comes to 521,518 bytes after the merge (limit 524,288). It is still stacked on #1927 (open), which should land first or together with it. It still conflicts with #2843 on the same path, and only one of the two should land.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7156850427) · edited 2026-11-26 03:23 UTC <!-- victory-triage v1 head=f41d919dd9ace93f669464b911eaa34caac69a02 verdict=merge-candidate at=2026-11-26T03:23:03Z --> Automated triage for the maintainers. **Verdict: merge candidate (unchanged).** The new commit `f41d919` (steven-seagull27's, taken in with authorship) replaces the 64-bit `udiv` in `Lower::norm_f16` (`emit/lower/d16.rs`) with 32-bit field replication. I checked it. `u32::MAX / d` is `2^r · Σ 2^(i·w)` with `r = 32 mod w`, so `y · copies` places every whole copy of the code, and `y >> (w − r)` fills the low `r` bits. The product cannot overflow because `y < d`. `y = 0` and `y ≥ d` are still selected explicitly, which also covers the 1-bit SNORM case (`d = 1`). The shader no longer sets `INT64`, and the new `d16_normalized_format_loads_do_not_require_int64` test checks SFI0 bit `0x8000` for all 20 UNORM/SNORM formats. It merges cleanly with `main`, and `lower.rs` comes to 521,518 bytes after the merge (limit 524,288). It is still stacked on #1927 (open), which should land first or together with it. It still conflicts with #2843 on the same path, and only one of the two should land. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 11:19 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 4919f2e1 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 11:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7160902248) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 4919f2e1 onto `main` 940d32f (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠dooprazol on GitHub · 2026-11-25 23:10 UTC · original

I tested the double-rounding question on Windows 11 with a Radeon RX 9060 XT 16 GB. I ran the same synthetic 16_UNORM D16 buffer-load probe on #2843 (a0a2e525) and #1940 (d09a7159). The physical Radeon and WARP produced identical results on each revision.

Input code #2843 #1940 Exact nearest-even FP16
65455 0x3bfe 0x3bfd 0x3bfd
65519 0x3c00 0x3bff 0x3bff

Both revisions also returned the expected values for the endpoint controls, 0 and 65535. This confirms two inputs where the intermediate f32 rounding in #2843 changes the final FP16 result by one ULP. The single-rounding path in #1940 matched the exact reference for both. This probe covered 16_UNORM buffer loads only.

**@⁠dooprazol** on GitHub · 2026-11-25 23:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7177234487) I tested the double-rounding question on Windows 11 with a Radeon RX 9060 XT 16 GB. I ran the same synthetic `16_UNORM` D16 buffer-load probe on #2843 (`a0a2e525`) and #1940 (`d09a7159`). The physical Radeon and WARP produced identical results on each revision. | Input code | #2843 | #1940 | Exact nearest-even FP16 | |---:|---:|---:|---:| | 65455 | `0x3bfe` | `0x3bfd` | `0x3bfd` | | 65519 | `0x3c00` | `0x3bff` | `0x3bff` | Both revisions also returned the expected values for the endpoint controls, 0 and 65535. This confirms two inputs where the intermediate f32 rounding in #2843 changes the final FP16 result by one ULP. The single-rounding path in #1940 matched the exact reference for both. This probe covered `16_UNORM` buffer loads only.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:46 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head d09a71591c42 merged onto main (63bcca43c6a0):

  • 512 KiB file-size policy blocker (xtask):
    • Code merges cleanly, but crates/victory-shader/src/emit/lower.rs reaches 524,906 bytes (+618 B over the 524,288-byte limit), causing cargo xtask policy to fail (rc=1). Moving norm_f16/d16_channels (or another ~1–2 KiB helper) into a submodule under emit/ will clear the policy gate with headroom.
  • Numerical & code audit:
    • norm_f16 (lower.rs:5202-5263) recovers the integer code y from format_load's f32 via round_to_nearest_even + FpToUi, then computes (y << 32) / d in i64 (flags::INT64) where d = (1 << bits) - 1 is always odd — so exact y / d is never a binary half-way tie for 0 < y < d, eliminating double rounding through f32 -> legacyF32ToF16.
    • Edge cases (y == 0 -> 0x0000, y >= d -> ±1.0, normal exponent carry, subnormal-to-min-normal 0x0400 carry, and RDNA2 UINT/SINT saturation in d16_channels) all check out cleanly (note: covers tbuffer_load_format_d16_*, not image_load D16).
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, Rust 1.98.1):
    • cargo xtask policy: FAIL (lower.rs: 524906 bytes exceeds the 524288-byte limit)
    • cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • emit::lower::tests buffer_formats_by_number tbuffer_d16: 36/36 passed across both RTX 5090 (hardware) and WARP (warp + explicit VICTORY_WARP=1), including all 3 new tbuffer_d16_loads_* tests.

Math and hardware tests look solid — just needs extracting out of lower.rs to satisfy the 512 KiB policy check.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7179100074) Code review and RTX 5090 + WARP + DXIL verification at head `d09a71591c42` merged onto `main` (`63bcca43c6a0`): - **512 KiB file-size policy blocker (`xtask`)**: - Code merges cleanly, but `crates/victory-shader/src/emit/lower.rs` reaches **`524,906` bytes** (`+618` B over the `524,288`-byte limit), causing `cargo xtask policy` to fail (`rc=1`). Moving `norm_f16`/`d16_channels` (or another ~1–2 KiB helper) into a submodule under `emit/` will clear the policy gate with headroom. - **Numerical & code audit**: - `norm_f16` (`lower.rs:5202-5263`) recovers the integer code `y` from `format_load`'s `f32` via `round_to_nearest_even` + `FpToUi`, then computes `(y << 32) / d` in `i64` (`flags::INT64`) where `d = (1 << bits) - 1` is always odd — so exact `y / d` is never a binary half-way tie for `0 < y < d`, eliminating double rounding through `f32 -> legacyF32ToF16`. - Edge cases (`y == 0 -> 0x0000`, `y >= d -> ±1.0`, normal exponent carry, subnormal-to-min-normal `0x0400` carry, and RDNA2 `UINT`/`SINT` saturation in `d16_channels`) all check out cleanly (note: covers `tbuffer_load_format_d16_*`, not `image_load` D16). - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, Rust 1.98.1)**: - `cargo xtask policy`: **FAIL** (`lower.rs: 524906 bytes exceeds the 524288-byte limit`) - `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `emit::lower::tests buffer_formats_by_number tbuffer_d16`: **36/36 passed** across both RTX 5090 (`hardware`) and WARP (`warp` + explicit `VICTORY_WARP=1`), including all 3 new `tbuffer_d16_loads_*` tests. Math and hardware tests look solid — just needs extracting out of `lower.rs` to satisfy the 512 KiB policy check.
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 00:55 UTC · original

@⁠fuzeofficlal thanks. 95dc5d2 moves this PR's norm_f16 unchanged into a new child module, emit/lower/d16.rs (set up like lower/bvh.rs); d16_channels stays in lower.rs. Merged with current main (63bcca4), lower.rs is now 521,518 bytes (was 524,906; the limit is 524,288), and the merge is clean.

On that merge, RTX 3070 (driver 616.56) and WARP: cargo xtask policy passes, cargo clippy -p victory-shader --all-targets --locked -- -D warnings is clean, and the 6 d16 tests pass on both backends.

On scope: you're right that it covers buffer format loads only (tbuffer / buffer_load_format D16), so I've narrowed the title. D16 image reads are #2030, which uses the same single-rounding rule.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-11-26 00:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7179248434) @⁠fuzeofficlal thanks. `95dc5d2` moves this PR's `norm_f16` unchanged into a new child module, `emit/lower/d16.rs` (set up like `lower/bvh.rs`); `d16_channels` stays in `lower.rs`. Merged with current `main` (`63bcca4`), `lower.rs` is now 521,518 bytes (was 524,906; the limit is 524,288), and the merge is clean. On that merge, RTX 3070 (driver 616.56) and WARP: `cargo xtask policy` passes, `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` is clean, and the 6 `d16` tests pass on both backends. On scope: you're right that it covers buffer format loads only (`tbuffer` / `buffer_load_format` D16), so I've narrowed the title. D16 image reads are #2030, which uses the same single-rounding rule. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

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

The single-rounding result can be kept without requiring Int64ShaderOps. I put a one-commit patch on top of your current head. It computes the first 32 fractional bits by repeating the normalized code in a 32-bit word. The field width is known at translation time. For a width that doesn't divide 32, a shift and OR fill the final partial copy.

The new DXIL feature regression failed on 95dc5d2 at format 1 with SFI0 bit 0x8000 set. With the patch, all 20 UNORM/SNORM format shaders clear the bit. I adapted the exhaustive readback from #1112 to compare the packed D16 halves against the directly rounded ratio. The RTX 5080 (621.40) and built-in Microsoft WARP each returned 962,048/962,048 exact field values across all 20 formats, including both signed and unsigned 16-bit midpoints. Each adapter ran separately and was identified by its DXGI adapter name. Strict all-targets Clippy passed.

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1940-d16-i32
git cherry-pick f41d919dd9ace93f669464b911eaa34caac69a02
cargo test --locked -p victory-shader --lib d16
**@⁠steven-seagull27** on GitHub · 2026-11-26 01:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7180209029) The single-rounding result can be kept without requiring `Int64ShaderOps`. I put a [one-commit patch on top of your current head](https://github.com/steven-seagull27/VIctory/commit/f41d919dd9ace93f669464b911eaa34caac69a02). It computes the first 32 fractional bits by repeating the normalized code in a 32-bit word. The field width is known at translation time. For a width that doesn't divide 32, a shift and OR fill the final partial copy. The new DXIL feature regression failed on `95dc5d2` at format 1 with SFI0 bit `0x8000` set. With the patch, all 20 UNORM/SNORM format shaders clear the bit. I adapted the exhaustive readback from #1112 to compare the packed D16 halves against the directly rounded ratio. The RTX 5080 (621.40) and built-in Microsoft WARP each returned **962,048/962,048 exact field values** across all 20 formats, including both signed and unsigned 16-bit midpoints. Each adapter ran separately and was identified by its DXGI adapter name. Strict all-targets Clippy passed. ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr1940-d16-i32 git cherry-pick f41d919dd9ace93f669464b911eaa34caac69a02 cargo test --locked -p victory-shader --lib d16 ```
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 02:49 UTC · original

@⁠steven-seagull27 thanks, pushed as f41d919 on the branch, with your authorship. Here at f41d919 merged with main 63bcca4: cargo test -p victory-shader --lib d16 -- --nocapture 7 passed, 0 failed on an RTX 3070 (616.56) and on WARP, and cargo xtask policy and clippy -D warnings pass. Your 32-bit sum also equals the old (code << 32) / (2^w − 1) for every code below 2^w − 1 at w = 1…16 (131,054 checks on the CPU), so the f16 results are unchanged and Int64ShaderOps is gone. The description now credits the patch.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-11-26 02:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1940#issuecomment-7181146397) @⁠steven-seagull27 thanks, pushed as `f41d919` on the branch, with your authorship. Here at `f41d919` merged with `main` `63bcca4`: `cargo test -p victory-shader --lib d16 -- --nocapture` 7 passed, 0 failed on an RTX 3070 (616.56) and on WARP, and `cargo xtask policy` and clippy `-D warnings` pass. Your 32-bit sum also equals the old `(code << 32) / (2^w − 1)` for every code below `2^w − 1` at `w` = 1…16 (131,054 checks on the CPU), so the f16 results are unchanged and Int64ShaderOps is gone. The description now credits the patch. AI-assisted (Claude Code, Claude Opus 5.5).
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/1940/head:github-bot/gh-1940'
git switch 'github-bot/gh-1940'

Merge

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