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

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

@⁠astrosteveo on GitHub · 2026-11-25 04:20 UTC · original
astrosteveo:fix/d16-buffer-toward-zero → main · +44 −4 · 2 files · 1 commits · open

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

**@⁠astrosteveo** on GitHub · 2026-11-25 04:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2064) `astrosteveo:fix/d16-buffer-toward-zero` → `main` · +44 −4 · 2 files · 1 commits · open `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)
legacyF32ToF16 truncates on Windows but rounds to nearest under vkd3d-proton on an RTX 5080, so a 32_FLOAT d16 format load gave 0x3c02 for 1 + 3/2048 and infinity for 70000. f16_toward_zero gives the truncated half for either rounding. UNORM and SNORM channels, which the console rounds to nearest, are left as they were.

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

@⁠jeremygold02 on GitHub · 2026-11-25 04:35 UTC · original

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.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7152984608) **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.
Author
Owner

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

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7158150838) ### 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:23 UTC · original · edited 2026-11-25 22:21 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/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

**@⁠Marvisak** on GitHub · 2026-11-25 10:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7159628247) · edited 2026-11-25 22:21 UTC <!-- 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)_
Author
Owner

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

@⁠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
**@⁠steven-seagull27** on GitHub · 2026-11-26 01:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2064#issuecomment-7180337911) @⁠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://git.gtahub.st/github/Marvisak--VIctory/pulls/1575) ```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 has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.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/2064/head:github-bot/gh-2064'
git switch 'github-bot/gh-2064'

Merge

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