Experimental patch: d16 loads of integer formats where the host does not merge them #2087
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#2087
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Speartone on GitHub · 2026-11-25 04:34 UTC · original
Submitted as an experimental patch, not a production-ready fix, because of a known floating-point regression (first limit below). Author: Speartone. Based on
70564ae.A typed d16 load is lowered to a float load and legacyF32ToF16. On a host that does not merge the two into its own 16-bit load, integer texels arrive as float bits and become 0 or NaN. AMD's driver merges them, so an RDNA2 GPU was right already; an RTX 5080 and WARP were not.
The load and conversion stay. Only where every half is 0 or NaN is the texel loaded again as integers, and 16 bits of each channel kept if all of it is integers of up to 16 bits.
Tests (synthetic): without the change 11,142 wrong channels; with it the covered cases pass on RTX 5080, AMD RDNA2 and WARP. 14 of 15 mutations fail a test; the other cannot change a result. victory-shader: 209 pass, 3 fail; the same 3 fail without the change. Only victory-shader was built.
Limits: coverage is incomplete.
A small conflict with #1693 is likely.
General compatibility defect with no demonstrated GTA VI impact. Actual GTA VI gameplay has not been tested.
AI-assisted: analysis, code, tests and text by Claude Code (Claude Opus 5.5). No game data.
Patch (source and tests)
🤖 Generated with Claude Code
@YaBulochka on GitHub · 2026-11-25 04:58 UTC · original
Data point that this patch targets, measured on the GPU here: on RADV/RDNA3 the host does not merge the d16 loads.
Linux, Vulkan 1.4, Radeon RX 7600 (NAVI33). Minimal compute:
R8_UNORM256x1 andR16_UNORM256x256 filled with every code,imageLoad(...).rinto an SSBO, compared bit-for-bit with nearest-even(float)((double)code/(2^n-1)):So the shader receives the correctly rounded f32, and the round-toward-zero
legacyF32ToF16is the only loss - i.e. this is one of the hosts where the "not merged" path applies. Full method and caveat in #2006.@Marvisak on GitHub · 2026-11-25 12:52 UTC · original · edited 2026-11-25 15:48 UTC
Automated triage for the maintainers.
On current
main(da82e44), the three load paths this patch covers stand as follows. Everything is incrates/victory-shader/src/emit/lower.rs:Lower::imagestill lowers everyd16result throughlegacyF32ToF16of a floattextureLoad. Theshortcut:comment there says integer formats should keep 16 bits. This is the part of the patch that is still needed.mainby4243a96("Shader: 16-bit typed buffer accesses pass bits through integer views"). The view-stride table now carries a view's format kind (VIEW_INTEGER,VIEW_SIGNED, read byinteger_view). Ad16typed load through a UINT or SINT buffer view keeps each channel's low 16 bits instead of converting, so no guessing from the loaded bits is needed there.d16_channels): as upipibi notes, these already know the format and keep the low 16 bits of integer channels.Pull requests are open to everyone: please open this patch as a PR against current
main, limited toLower::image. For textures, a per-view format tag like 4243a96's (or #2030's for #2006) would avoid the known float regression of guessing from the bits. Keepd16_channelsuntouched to stay clear of #1927.Generated by Claude Code
@upipibi on GitHub · 2026-11-25 13:19 UTC · original
For scoping the PR asked for above: the buffer-format path doesn't need this fix.
d16_channels(emit/lower.rs:4719onmain940d32f), used bytbuffer_load_format_d16_*/buffer_load_format_d16_*, knows the format from the instruction or V#. It already keeps the low 16 bits of UINT/SINT channels and doesn't convert them withlegacyF32ToF16. Our #1927 changes only that function, so 32-bit integer channels saturate instead of being masked.So the integer-bits-arriving-as-floats problem here is in the view paths (
Lower::imageand the typed view loads that calllegacyF32ToF16on a float load), and a PR for it wouldn't overlap #1927 in code. If it does touchd16_channels, it would conflict with #1927 in the same lines.AI-assisted (Claude Code). Read from the source only.