Recompiler: unpatch Xbox FP16 placeholder exports for integer SV_Target in direct DXIL #3273
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3273"
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?
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T03:05:35Z.
What is in it
Unpatches Xbox's FP16 placeholder epilogue (
s_nop; s_nop; v_cvt_pkrtz_f16_f32 vTmp, vSrc0, vSrc1; exp mrtN vTmp, ..., compr=1) for integerSV_Targetoutputs (system_value == 64,component_typein{1, 2}foruint/sint) in the direct DXIL pixel shader translator (crates/xcl/src/gpu/dxil/kernel.rs). Xbox retail pixel shaders ship with FP16-compressedexp mrtNplaceholders that the console driver normally patches to uncompressed 32-bit integer exports when bound to integer RTVs; translating the unpatchedv_cvt_pkrtz_f16_f32bitcasted 32-bit packed integers asf32and saturated them to FP16 (0x7bff/0x8000/0x7fff).unpatch_ps_int_exportsrewrites matching integerexp mrtN ... compr=1exports tocompr=0using the original pre-conversion VGPR sources and NOPs dead placeholderv_cvt_pkrtz_f16_f32instructions, while leaving floatSV_Targetexports untouched. Adds a unit + DXC-validation + disassembly test incrates/xcl/src/gpu/dxil/core_tests.rs.Tested
cargo test -p xcl --lib direct_pixel_shader_unpatches_int_mrt_exportspassed (1 passed; 0 failed): verifies floatMRT0keepslegacyF32ToF16, whileuintMRT1(0xFFC0_0FFC) anduint4MRT2export intact 32-bit integers and pass DXC validation.SV_Targetpixel shaders in the local retail shader cache (ea3b5e4d): 648/648 match thev_cvt_pkrtz_f16_f32->exp mrtN compr=1placeholder pattern with 0 VGPR alias or non-VGPR source exceptions.xcl-smokeregression run below on NVIDIA GeForce RTX 5070 Ti (XCL_PREPARE=0,0device removals,0crashes).Regression run
Baseline (
mainancestorf0e8fdd5c3942ddd399d5ee11384c8595c5aacff):PR branch (
a5da9e8303555186d6a8d96925ef6524e676abb2):Not tested
R32_UINT/R32G32B32A32_UINTRTV on D3D12 hardware; verification is via DXC validation, DXIL disassembly of exact 32-bit integer exports, and the 150 s title smoke.ea3b5e4d.AI use
Drafted, implemented, and tested with an AI coding agent; reviewed and verified by hand against shader cache audit, DXC validation, DXIL disassembly, and 150 s smoke logs.
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T14:56:51Z.
Note: since this run the PR conflicts with main (
3b6a91ed). The result above is for this head merged onto the base named above.Merge-check run and written with Claude Code (Claude Opus 5.5): a test merge onto the base above, the full suite, and a 60 s
scripts/smoke.ps1run of a retail title against main on the same machine. The 4fuzz_validate_and_gpu_*failures happen on main on this machine too.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:24:36Z.
merge-check
base:
d0832e614fhead:
a5da9e8303merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: gpu::dxil::core_tests::direct_pixel_shader_unpatches_int_mrt_exports
review: re-review (my earlier merge-check was on
98fc0cd1). Since then the PR was only rebased, but its new base includes #3200 (recomp::patch_ps_32bit_exports), which already turns these placeholder exports into 32-bit exports for 32-bit render targets in both the HLSL and direct DXIL backends, with the mask from the pipeline's formats. On the merged tree it runs first (kernel.rs ~304), so for R32* integer targets this PR does nothing at run time. What it adds is integer targets on 8- and 16-bit formats, in direct DXIL only. Findings: (1) the description and the test (core_tests.rs ~1577, R32-style values, no format mask) still argue the R32_UINT case; they should be about the narrower case. (2) Shaders that fall back to HLSL keep the old packed-f16 output, so the two backends now disagree for those targets. (3)unpatch_ps_int_exportsmostly duplicatespatch_ps_32bit_exports; adding the signature's integer-target bits tops_rt32_maskand reusing it would cover both backends. (4) Minor: the no-op written at ~769 doesn't keep the instruction length as main's helper does. (5) AI use names no tool or model. Fine: it only touches compressed exports to integer targets fed directly by the f16-pack placeholder, keeps the conversion when its result is read later, leaves float targets alone, and the test validates the DXIL. Aside, on main and not from this PR:patch_ps_32bit_exportschecks a VOP3 field "CLMP" (recomp/mod.rs ~211) while the encoding table calls it "CLAMP", so a clamped VOP3 conversion is never declined there; this PR uses the right name.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (9e338067): 1516 -> 1688 frames shown (111 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17556 MB, 0 device removals, 0 crashes.verdict: not yet: the PR's own test fails merged onto current main (core_tests.rs:1718, "MRT1 col 0 should store raw 0xFFC00FFC"), consistent with finding (1): main's #3200 now handles the R32 case the test is built around, so the PR and its test need reworking around the 8/16-bit integer-target case
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 327This unpatch only runs in the direct-DXIL translator. The shared
patch_ps_32bit_exports(recomp/mod.rs:188), which both backends run, is keyed only on 32-bit render target formats. So for a uint SV_Target with rt32_mask 0 (a non-32-bit integer render target, or the precompile path, which passes 0), direct DXIL exports the raw value. The same shader falling back to HLSL (the whole-wave reduction check right after this, ps_debug, or direct graphics turned off) still writes f16-saturated 0x7bff/0x8000. ORing a signature-derived integer-target mask into ps_rt32_mask before the shared pass would fix both backends.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 711The backward scan from an
expstops at the first instruction that isn't S_NOP or V_CVT_PKRTZ_F16_F32. Inv_cvt_pkrtz v2,..; v_cvt_pkrtz v4,v6,v6; exp mrt0 v2..; exp mrt1 v4 compr, the scan fromexp mrt1hitsexp mrt0and gives up, and so does any s_waitcnt or unrelated VALU in between. The uint target is still exported as f16-saturated garbage.find_pkrtzin recomp/mod.rs walks past instructions that don't write the register.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 748COMPR is cleared but EN is copied unchanged. When compressed, each EN bit pair enables a 32-bit half (lower_gfx.rs:300), and uncompressed it's one bit per channel. A compressed export with en=0x1 or 0x5 (accepted today as enabling R,G / B,A) becomes an uncompressed en=0x1/0x5, so channels 1 and 3 are never stored. EN needs widening per pair:
(en&3!=0 ? 3 : 0) | (en&0xC!=0 ? 0xC : 0).Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 717When the export reads the same register twice (vsrc0 == vsrc1),
lotakes the nearest conversion andhitakes an older conversion to that register, whose result was already overwritten.v_cvt_pkrtz v4,v10,v11; v_cvt_pkrtz v4,v12,v13; exp mrt1 v4,v4 en=0xF comprbecomesexp v12,v13,v10,v11, where the console exports (v12,v13) in both halves, and the older conversion is NOPed.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Code review location:
crates/xcl/src/gpu/dxil/kernel.rs; line 768The dead conversion is replaced with a freshly decoded 4-byte S_NOP, so a VOP3-encoded V_CVT_PKRTZ (8 bytes) leaves len=4 at that pc, and the instruction list no longer covers the code. Anything that computes
pc + len(s_getpc at lower.rs:1395, loop ranges at recomp/mod.rs:921/951) sees a 4-byte gap. The existing helper setsnop.len = len.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-01T20:14:46Z.
Review: COMMENTED
Review of
a5da9e83: 5 finding(s). 5 are inline.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:38:46Z.
Closing: superseded by merged #3200 (
0b6217bda, 32-bit exports for FP16 placeholder exports in both backends).Pull request closed