Recompiler: patch console FP16 PS exports for 32-bit render targets #3200
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3200"
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 Lakanya on 2026-11-28T19:01:05Z.
Console pixel shaders ship with a default FP16 compressed export epilogue (
v_cvt_pkrtz_f16_f32followed byexp mrtK ... compr) that the console runtime patches into an uncompressed 32-bit export whenever a render target has 32-bit per-channel components (R32*,R32G32*,R32G32B32*,R32G32B32A32*). Lowering that unpatched epilogue literally converts raw 32-bit packed integer bits or 32-bit floats to f16 (e.g.0x7BFF/0x8000in a retail title'sR32_UINTsubsurface-scattering diffuse target), producing bright blue/purple skin blowout and missing diffuse light on lit faces.This PR patches matched
v_cvt_pkrtz_f16_f32+exp mrtK ... comprsequences into uncompressed 32-bit exports right after RDNA2 decoding for both the HLSL and direct-DXIL backends, keyed by a bitmask of 32-bit render targets from the PSO. When no 32-bit RT is bound (rt32_mask == 0), the shader cache key and generated HLSL are unchanged.What is in it
crates/xcl/src/gpu/recomp/mod.rs: addis_rt32_format,rt32_mask_from_formats,Options::ps_rt32_mask, andpatch_ps_32bit_exports(always checks later-read liveness of matchedv_cvt_pkrtz_f16_f32destinations before mutatingEXP; declines the patch if an aliased conversion destination stays live afterEXPor reaches a branch/join; otherwise rewritesexp mrtK ... comprtoCOMPR=0with the original VGPR sources and NOPs dead conversions), called intranslate()for pixel shaders.crates/xcl/src/gpu/dxil/kernel.rs: addtranslate_pixel_rt32and callpatch_ps_32bit_exportsintranslate_on_this_threadso the direct-DXIL backend applies the same patching.crates/xcl/src/gpu/recomp/pso.rs: addconsole_ps_to_dxil_forand threadrt32_maskintoShaderKeyandtranslated::file_for(appending_rt32_<hex>only whenrt32_mask != 0, keeping non-32-bit RT cache keys untouched), plus unit testrt32_mask_formats_and_cache_key.crates/xcl/src/hle/d3d12x/real.rs: computert32_maskfrom PSO render-target formats intranslated_graphics_pso_once,translated_graphics_stream_once,translated_mesh_pso, andtranslated_gs_pso, and pass it to pixel shader translation.crates/xcl/src/gpu/dxil/core_tests.rs: addps_32bit_rt_export_patches_pkrtz_in_both_backends(including in-placev_cvt_pkrtz_f16_f32overwrite and mixed 16-bit/32-bit MRTs) andps_32bit_rt_export_declines_patch_when_aliased_pkrtz_dst_is_live_after_expcovering both HLSL and direct-DXIL lowering.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), debug (tests) and release (smoke / visual check).99f94b04:cargo test -p xcl --lib ps_32bit_rt_export: 2 passed, 0 failed, 0 ignored.cargo test -p xcl --lib rt32_mask_formats_and_cache_key: 1 passed, 0 failed, 0 ignored.c8dde3a1(before the liveness guard commit99f94b04):cargo test -p xcl --lib gpu:: -- --test-threads=4: 788 passed, 4 failed (pre-existinggpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3hittingCreateComputePipelineState: 0x8007000EOOM on this 8 GB GPU), 23 ignored; 24SKIPPEDlines (21 no wave64,3 per-lane form: refused).cargo test -p xcl --lib hle::d3d12x::list_x::tests -- --test-threads=1: 86 passed, 0 failed, 0 ignored.cargo test --workspace --test '*' -- --test-threads=4(aftercargo build --workspace): 131 passed, 0 failed, 20 ignored, 1SKIPPED.2c508222,XCL_DEVICE_TYPE=lockhart,XCL_DIRECT_DXIL=1, 192 s run,frame_2798.bmpvs pre-fixframe_2862.bmp): bright blue/purple subsurface-scattering blowout on character skin is eliminated and skin renders with natural diffuse lighting.Regression run
Not tested
SKIPPED).XCL_DIRECT_DXIL=allon a full retail title run (direct-DXIL 32-bit PS export patching was verified viaps_32bit_rt_export_*+ DXIL validation/disassembly).cargo test --workspacewithhle::lib tests all together (pre-existing cross-test sparse upload state inhle::causesend_title(0x80004005)).AI use
v_cvt_pkrtz_f16_f32+exp mrt1 comprepilogue onR32_UINTtargets.Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-28T19:40:31Z.
Tested
Independently reran the pinned XCL library test executable at
c8dde3a184dfb5ac8dc4e163d83ee36c641cb39bon Windows 11 x64 build 26200.9974 with a Ryzen 7 3800X. It was built with Rust 1.100.1 (x86_64 MSVC) from the exact-head source plus a private test-only module.Both native processes exited 0. Total was 2 passed, 0 failed, 0 ignored, 0 skipped, with 2047 filtered out per invocation. In both synthetic subobject orders the raw RTV format IDs
[28, 42, 86, 67, 10, 41, 115, 43]mapped to[28, 42, 28, 26, 10, 41, 28, 43]. Counts 3, 8, and 0 yielded RT32 masks0x02,0xa2, and0x00, respectively. An absent RTV subobject yielded count 0, eight UNKNOWN formats, and a zero mask. The stock format and cache-key control passed separately.Not tested
Device initialization, live stream adoption, shader translation, cache persistence, GPU, retail titles, and the workspace suite.
AI use
T3 Code through Codex (
gpt-6.2-sol, high) prepared the fixture, verified the source and executable pins, independently reran both tests, and drafted this report.Imported from ivall/xcl. Originally posted by bmjask on 2026-11-28T22:04:15Z.
Review: CHANGES_REQUESTED
The NOP decision is unsafe when the conversion destination overlaps an export source. In
patch_ps_32bit_exports,overwrites_srcsuppresses the later-read scan, and line 323 then replaces the conversion wheneveroverwrites_srcis true. If the packed conversion result is consumed later in the same block, that consumer instead sees the pre-conversion value. The matcher does not establish that the export is terminal.Please always perform the later-read liveness check. If the raw export needs the original source while the converted destination remains live, preserve one value in a temporary or decline the patch. Add a regression where
v_cvt_pkrtz_f16_f32aliases the raw export source and a later instruction reads its destination afterEXP.Reviewed at
c8dde3a184with Codex (GPT-5).Imported from ivall/xcl. Originally posted by Lakanya on 2026-11-28T22:27:09Z.
Fixed in
99f94b04:patch_ps_32bit_exportsnow always runs the later-read liveness scan before mutatingEXP(treating branch targets and branch instructions conservatively as potentially live), and declines the patch whenever an aliasedv_cvt_pkrtz_f16_f32destination remains live afterEXP. Added regression testps_32bit_rt_export_declines_patch_when_aliased_pkrtz_dst_is_live_after_expcovering both HLSL and direct-DXIL backends, and reranscripts/smoke.ps1 -Game <title> -Seconds 60on99f94b04(updated in Regression run).Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T02:41:09Z.
merge-check
base:
fa204595a4head:
1cd8d7fe10merge: clean (fast-forward: the head sits on main
fa204595; tested at1cd8d7fe)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 (XCL_DXC_DIR = DXC 1.9.2609) -> 2611 passed, 0 failed, 49 ignored; SKIPPED: 26, the usual set (21 no wave64 on this 32-lane GPU, 3 per-lane f16/f32 forms refused (#1426 semantics), 2 no heap windows). All three new tests ran and passed:
ps_32bit_rt_export_patches_pkrtz_in_both_backends,ps_32bit_rt_export_declines_patch_when_aliased_pkrtz_dst_is_live_after_exp,rt32_mask_formats_and_cache_key.review: none blocking; whole diff read.
is_rt32_formatnames exactly the R32 / R32G32 / R32G32B32 / R32G32B32A32 DXGI values (1-8, 15-18, 39, 41-43; D32_FLOAT and R32G8X24 excluded). The desc path readsRTVFormatswithoutpc_target_formatwhile the stream paths map them, but that mapping never moves a format into or out of those ranges, so the masks agree.patch_ps_32bit_exportsclears COMPR (bit 10 of the EXP word) and writes the four pkrtz sources into VSRC0-3. It only matches VGPR-sourced pkrtz in VOP2 or modifier-free VOP3, within the export's basic block. It declines when a source is clobbered before the export, or when a pkrtz destination that overwrote a needed source is still read after the export (or at a join). Dead conversions becomes_nopof the same length, so PCs don't move. Both backends run it right after decoding. The mask is part of both the in-memoryShaderKeyand the disk file name (_rt32_XXonly when non-zero, so mask-0 entries keep their names). Gap:warm_graphics(real.rs, "the translation … astranslated_graphics_pso_oncemakes them") still asks for the mask-0 PS throughconsole_to_dxil_for. For a pipeline with an R32 target, the warm-up translates a variant nothing uses, and the real build then translates the rt32 one itself. A one-line follow-up fixes it (rt32_mask_d3d12(desc.NumRenderTargets, &desc.RTVFormats)+console_ps_to_dxil_for). Likewise the standalone pass ofxcl shaders --precompile(standalone_graphics_variants) only makes mask-0 variants; it has no formats to go on, so only its recorded-pipeline replay (throughtranslated_graphics_pso) can fill rt32 entries. I didn't run a precompile to see how many it covers.performance: Title run (release build of the head, scratch/fast-world.py fast profile, about 85 s in world): exit 0, 0 crashes, 0 device removals,
failed_pipelines0, no translation errors, peak commit 30,508 MB, world entry 129.2 s (mainfa204595on the same harness: 76.8 s). This title binds R32 targets often: the run made 135 rt32 PS variants (43 with RT0 R32, 92 with RT1 R32; the cache snapshot had none, since main never makes them), and each one compiled in play. That shows in the log: 186 WARN lines against 86 on main, almost all of them "waited N ms for a graphics pipeline being built" (125 lines, against 23-36 in three other runs this session), plus one 4.5 s Present stall. No new WARN kinds otherwise. This is the one-time cost of changing those shaders' translation, and the next run with the same cache finds them. But see the precompile gap above: until a precompile can make these variants, a precompiled title still builds them in play once. All runs show 0 fps in the world because the cache doesn't match the translator identity, so I couldn't check the visual fix on this title.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74, wave32 only), AMD Ryzen 9 9950X, Windows 11 build 26200; rustc 1.99.0, debug test profile, release build for the title run, DXC 1.9.2609 via XCL_DXC_DIR. Claude Code, Claude Opus 5.5: build, suite, title run and full-diff review; this report.
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T08:41:37Z.
merge-check claim
head:
1cd8d7fe10Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:00:58Z.
merge-check
base:
d8bd9a38head:
1cd8d7fe10merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2621 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at
d8bd9a38: 2618 passed, 0 failed, 49 ignored.review: no blocking finding. For a pipeline whose render target has 32-bit channels, the packed 16-bit export is rewritten into an uncompressed 32-bit one in both backends, and the render-target mask joins the in-memory and on-disk cache keys (mask 0 keeps the old file names, and the changed translator source already changes the cache identity, so build.rs needs nothing). The patch declines when a source is overwritten and handles the case where one half's pack overwrites a source of the other. Notes: (1) three places still translate the pixel shader with mask 0: the pipeline warm-up,
xcl shaders --precompileand the target dump. Not wrong, but the warm-up then compiles a variant the build never uses and the real one is compiled cold at build time; passing the mask in the warm-up would fix that. (2) It does not check for a change of EXEC between the pack and the export. (3) The first direct-DXIL assertion looks for a literal that may also appear without the change, so it is weaker than the HLSL ones. Not checked here: the picture in a title; this check is the suite and the code only.performance: not measured; see note (1) for a possible cold compile per such pipeline.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).