Shaders: d16 buffer loads of floats truncate on every host #2062

Open
astrosteveo wants to merge 1 commit from upstream-pr/2064 into main
astrosteveo commented 2026-11-25 04:20:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by astrosteveo on 2026-11-25T04:20:04Z.


legacyF32ToF16 truncates on Windows but rounds to nearest under vkd3d-proton (RTX 5080, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1). So a 32_FLOAT d16 format load there gives 0x3c02 for 1 + 3/2048 and infinity for 70000. d16_channels now uses the existing f16_toward_zero for float formats. Other formats are unchanged: every 8- and 16-bit UNORM/SNORM code I probed (all 8-bit ones, 256 per 16-bit format) is right there today, and truncating them broke 123 of 256 8_UNORM codes.

That RDNA2 truncates here is from #1927 and #1940; I did not measure it. The new test fails on 940d32f on this stack and passes with the change. victory-shader: 244 passed, 4 failed, all 4 also on main here. Clippy and policy clean.

Overlap: conflicts with #1927 and #1940 in the same branch of d16_channels (keep their integer and norm arms, use this one for Numeric::Float).

Not covered: buffer_load_format_d16_* through a typed view, where the format is unknown (as in #2006). Not tested: Windows, the title.

🌴 AI-assisted, made with Claude Code · from astrosteveo/VIctory

<!-- greyfinch-sync:Marvisak/VIctory:issue:6597125872 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064). Originally posted by [astrosteveo](https://github.com/astrosteveo) on 2026-11-25T04:20:04Z. --- `legacyF32ToF16` truncates on Windows but rounds to nearest under vkd3d-proton (RTX 5080, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1). So a `32_FLOAT` d16 format load there gives `0x3c02` for 1 + 3/2048 and infinity for 70000. `d16_channels` now uses the existing `f16_toward_zero` for float formats. Other formats are unchanged: every 8- and 16-bit UNORM/SNORM code I probed (all 8-bit ones, 256 per 16-bit format) is right there today, and truncating them broke 123 of 256 8_UNORM codes. That RDNA2 truncates here is from #1927 and #1940; I did not measure it. The new test fails on `940d32f` on this stack and passes with the change. `victory-shader`: 244 passed, 4 failed, all 4 also on `main` here. Clippy and policy clean. Overlap: conflicts with #1927 and #1940 in the same branch of `d16_channels` (keep their integer and norm arms, use this one for `Numeric::Float`). Not covered: `buffer_load_format_d16_*` through a typed view, where the format is unknown (as in #2006). Not tested: Windows, the title. 🌴 AI-assisted, made with [Claude Code](https://claude.com/claude-code) · from [astrosteveo/VIctory](https://github.com/astrosteveo/VIctory)
DenRakEiw commented 2026-11-25 05:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:31:11Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib tbuffer_d16_loads_cut_32_bit_floats_toward_zero — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix ensuring d16 float buffer loads truncate toward zero consistently on every host GPU, verified on RTX 5090 + WARP. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051883150 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#pullrequestreview-6051883150). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:31:11Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib tbuffer_d16_loads_cut_32_bit_floats_toward_zero` — passed on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean fix ensuring `d16` float buffer loads truncate toward zero consistently on every host GPU, verified on RTX 5090 + WARP. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 05:05:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:33:52Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. d16 buffer loads of floats truncate on every host — consistent d16 truncation across hosts.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051901476 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#pullrequestreview-6051901476). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:33:52Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. d16 buffer loads of floats truncate on every host — consistent d16 truncation across hosts.
jeremygold02 commented 2026-11-25 05:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:35:34Z.


Triage verdict — Keep the float-buffer rounding fix (f7870d3)

Evidence

  • @astrosteveo applies the step-toward-zero correction only to the typed buffer Numeric::Float arm. #1940 addresses the normalized-buffer arm in the same function, while #2030 concerns image reads. The typed float and normalized cases need distinct rounding behavior. Correction · Buffer branch

Checks and limits

  • An independent CPU model started with nearest-even conversion and applied the emitted one-step correction. It matched all 12 supplied fixtures and three extra overflow-boundary controls. This checks the arithmetic on a nearest-even starting point. The hardware and WARP executions are reported in the existing Windows review. The vkd3d-proton result is author-reported. Fixture

Next step

  • Preserve this float arm when integrating normalized rounds from #1940. A combined buffer regression with a float tie and a normalized midpoint would protect the format distinction across the shared lowering path. The typed-view case where the format is unknown remains separate.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152984608 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7152984608). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:35:34Z. --- **Triage verdict — Keep the float-buffer rounding fix** (`f7870d3`) **Evidence** - @astrosteveo applies the step-toward-zero correction only to the typed buffer `Numeric::Float` arm. #1940 addresses the normalized-buffer arm in the same function, while #2030 concerns image reads. The typed float and normalized cases need distinct rounding behavior. [Correction](https://github.com/Marvisak/VIctory/blob/f7870d3e262435d40bf8304a5afed08708023557/crates/victory-shader/src/emit/lower.rs#L2211-L2236) · [Buffer branch](https://github.com/Marvisak/VIctory/blob/f7870d3e262435d40bf8304a5afed08708023557/crates/victory-shader/src/emit/lower.rs#L4715-L4746) **Checks and limits** - An independent CPU model started with nearest-even conversion and applied the emitted one-step correction. It matched all 12 supplied fixtures and three extra overflow-boundary controls. This checks the arithmetic on a nearest-even starting point. The hardware and WARP executions are reported in the existing Windows review. The vkd3d-proton result is author-reported. [Fixture](https://github.com/Marvisak/VIctory/blob/f7870d3e262435d40bf8304a5afed08708023557/crates/victory-shader/src/emit/valu_tests.rs#L354-L389) **Next step** - Preserve this float arm when integrating normalized rounds from #1940. A combined buffer regression with a float tie and a normalized midpoint would protect the format distinction across the shared lowering path. The typed-view case where the format is unknown remains separate. This verification was AI-assisted.
sinan-cmyk commented 2026-11-25 10:07:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:18:20Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head f7870d3e 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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158150838 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7158150838). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:18:20Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head f7870d3e 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).
Marvisak commented 2026-11-25 11:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:23:27Z.


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/lower.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159628247 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7159628247). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:23:27Z. --- <!-- victory-triage v1 head=f7870d3e262435d40bf8304a5afed08708023557 verdict=needs-rebase at=2026-11-25T22:25: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/lower.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)_
steven-seagull27 commented 2026-11-26 02:07:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T01:58:46Z.


@astrosteveo I resolved the conflict on your f7870d3 head with main 63bcca43. The diff against main still contains your original D16 change and regression. The standalone tbuffer_d16_loads_cut_32_bit_floats_toward_zero test passes here on Windows with the RTX 5080 and built-in Microsoft WARP. Fast-forwardable merge

The broader D16 run also found zero FLOAT mismatches on both native Windows adapters before and after integrating your fix alongside the integer, normalized and scaled fixes. Your vkd3d-proton result remains the distinguishing cross-platform check. 77-format comparison

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2064-d16-float-nov26
git merge --ff-only FETCH_HEAD
<!-- greyfinch-sync:Marvisak/VIctory:comment:7180337911 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7180337911). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T01:58:46Z. --- @astrosteveo I resolved the conflict on your `f7870d3` head with main `63bcca43`. The diff against main still contains your original D16 change and regression. The standalone `tbuffer_d16_loads_cut_32_bit_floats_toward_zero` test passes here on Windows with the RTX 5080 and built-in Microsoft WARP. [Fast-forwardable merge](https://github.com/steven-seagull27/VIctory/commit/f1f76002bc9984d25c29d77f6261217e220f797c) The broader D16 run also found zero FLOAT mismatches on both native Windows adapters before and after integrating your fix alongside the integer, normalized and scaled fixes. Your vkd3d-proton result remains the distinguishing cross-platform check. [77-format comparison](https://github.com/Marvisak/VIctory/pull/1575#issuecomment-7180273767) ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2064-d16-float-nov26 git merge --ff-only FETCH_HEAD ```
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2064:upstream-pr/2064'
git switch 'upstream-pr/2064'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2064'
git switch 'upstream-pr/2064'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2064'
git switch 'upstream-pr/2064'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2064'
git switch 'main'
git merge --squash 'upstream-pr/2064'
git switch 'main'
git merge --ff-only 'upstream-pr/2064'
git switch 'main'
git merge 'upstream-pr/2064'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2062
No description provided.