Skip to content

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

Open
0x00trace wants to merge 1 commit into
Marvisak:mainfrom
0x00trace:fix/d16-buffer-toward-zero
Open

0x00trace wants to merge 1 commit into
Marvisak:mainfrom
0x00trace:fix/d16-buffer-toward-zero

Conversation

@0x00trace

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, 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

Copy link
Copy Markdown
Contributor

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

Evidence

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

This verification was AI-assisted.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head f7870d3 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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@steven-seagull27

Copy link
Copy Markdown

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants