Skip to content

Round unsigned shader conversions once (port of Marvisak/VIctory#2186) - #2018

Draft
xiepeixuan wants to merge 2 commits into
trustno1-coder:mainfrom
xiepeixuan:auto/v-cvt-f32-u32
Draft

xiepeixuan wants to merge 2 commits into
trustno1-coder:mainfrom
xiepeixuan:auto/v-cvt-f32-u32

Conversation

@xiepeixuan

@xiepeixuan xiepeixuan commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

No issue in this repo. Upstream context: FIND-5 in Marvisak/VIctory#1633.

What it changes

The AMD RDNA 2 ISA reference, §12.8, p. 138 specifies V_CVT_F32_U32 as “0.5ULP accuracy” and D.f = (float)S0.u. WARP can misround a full-width DXIL unsigned cast. The lowering converts the two 16-bit halves separately and computes hi * 65536 + lo. Both casts and the scaled high half are exact, so only the sum rounds.

Ported from Dmitrii (Razdva122), Marvisak/VIctory#2186, merged commit 084d4ff3ae (original b21594a4). The WARP test uses all 34 U32_EDGES values and the 50 midpoint/reported cases: 82 distinct inputs after deduplication, compared exactly with (x as f32).to_bits().

Player-visible effect: The RTX 5080 report in Marvisak/VIctory#2186 found that the plain cast already rounded correctly on NVIDIA hardware: 0xffffff7f returned 0x4f7fffff before and after the fix. No visible change is expected on NVIDIA GPUs. The fix makes WARP match hardware bit-for-bit on the tested inputs and keeps the WARP regression exact. Cost: five DXIL operations instead of one per v_cvt_f32_u32. Physical-GPU performance was not measured.

How it was tested

  • Upstream main: e1f2eb60492d94dd0230606b453ba82b34e1b98d. Fixed head: d2917a17cf80dad3f80a7b3d217ed7111944a9fb. No physical GPU or game run; CPU bitcode evaluator and D3D12 WARP software readback. The new regressions exercise GFX10 Wave32, not Wave64.
  • WARP: main + tests only failed (exit 101): 0xde84975e returned 0x4f5e8498 instead of 0x4f5e8497. The fixed head passed (exit 0) and matched all 82 inputs.
  • Portable Linux regression: main + tests only failed at 0x01000001 (exit 101); the fixed head passed (exit 0).
  • cargo test -p victory-shader --locked: Linux 273 → 274 passed, 0 failed, 2 ignored on each revision. Windows 394 → 396 passed, 1 failed, 8 ignored on each revision. The sole Windows failure on both is nv05d1_native_readlane_gpu_reference, which requires a physical GPU. Filtering out only that test gives 394 → 396 passed, 0 failed, 8 ignored.
  • Windows cargo check --workspace --locked passed on both revisions. Both strict Clippy variants hit the same existing manual_checked_ops lint (Shaders: the host LDS wait cap uses checked_div, so clippy's manual_checked_ops no longer stops the check #1855); the full workspace test step was skipped.

Checked for overlap

Other uses checked

The GFX10 opcode table and VALU dispatch are unchanged; only v_cvt_f32_u32 gets new arithmetic. v_cvt_f32_i32, the four v_cvt_f32_ubyte* paths, and the shared fmad and write_f implementations and their other callers are unchanged, including output modifiers and lane guards. The other uses found are synthetic shader fixtures. The existing shader source fingerprint invalidates cached DXIL on rebuild; no cache key or switch changed.

Opened as a draft early so others know this is being worked on (README: 'Opening a draft pull request early works too').

AI-assisted (Codex). Not run in the game.

Port Dmitrii (Razdva122) in Marvisak/VIctory#2186 (084d4ff3aeade44017851a52220da5e9f004bd38).
@github-actions github-actions Bot added pr-fix Pull request: fixes a bug shaders Shader translation, preload or pipeline building labels Nov 29, 2026
@github-actions github-actions Bot changed the title [pr-fix][shaders] Round unsigned shader conversions once (port of Marvisak/VIctory#2186) Round unsigned shader conversions once (port of Marvisak/VIctory#2186) Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-fix Pull request: fixes a bug shaders Shader translation, preload or pipeline building

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant