Skip to content

Shaders: apply the console's pixel shader export patches - #3209

Open
Eterst wants to merge 1 commit into
xcl-dev:mainfrom
Eterst:shaders/ps-export-patch
Open

Eterst wants to merge 1 commit into
xcl-dev:mainfrom
Eterst:shaders/ps-export-patch

Conversation

@Eterst

@Eterst Eterst commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

A pixel shader's render-target exports are stored for one export format, the compiler's default FP16 (v_cvt_pkrtz_f16_f32 and a compressed exp). The console patches them at pipeline creation for each target's SPI_SHADER_COL_FORMAT, from a table in the PS stage data. XCL never applied that table, so a target of 32 bits a channel got the FP16 conversion of its value. In a retail title, a packed R32_UINT lighting target held f16(asfloat(bits)) (0x7BFF where the packed value was large) instead of its bits; on screen that showed as a blue-white glow on skin and lit surfaces. This applies the table: every target gets the 32_ABGR variant, so the channels leave the shader unconverted and the PC target converts them. Part of #505.

How this relates to #3200 (merged 2026-11-29, after this PR was opened; it fixes the same symptom)

What is in it (one commit)

  • crates/xcl/src/gpu/xbox.rs: patch_ps_exports, called from analyze_fssm for FSSMs whose code region comes from the header (version 0x101). Per render target it copies the 32_ABGR variant over the stored export code. A table that is implausible (no PS record, a patch size of 0 or over ten dwords, a patch past the end of the code, an empty variant) changes nothing. XCL_PS_EXPORT_PATCH=0 keeps the stored exports. Two tests: the patch lands on the right dwords and nothing around them changes; each kind of implausible table leaves the buffer byte for byte the same.
  • crates/xcl/src/gpu/recomp/pso.rs: a pixel shader's entry in the translated-shader cache names its export mode (translated::exports_mode), so a warm cache does not hand one mode's translation to the other; older unlabelled pixel entries are not read. Found and fixed by @andrewDoing in review; the cache-name test asserts it.
  • README.md: one note on the patches and the switch.
  • THIRD_PARTY.md: the table layout (record at payload + 0x30, stage data at record + 0x54, size at + 0x148, eight entries from + 0x14C, ten variants of ten dwords) is as VIctory documents it in victory-shader/src/native.rs (GPL-3.0). The code here is written independently; VIctory's row says so.

gpu/xbox.rs is one of the translator's sources, so the translation cache identity changes with this PR.

Tested

  • Suite counts below: head bb0679fb on main 3b6a91ed. The head is now 710a5f4f, the same commit rebased onto main 0fe06eb0 to pick up main's test fixes: main's geometry tests failed CI at 3b6a91ed and were fixed in 468190c2, and CI on 601481ed (on bc2cbb72) failed in the four pipeline_library / warm_library tests of CI: tests that fail by timing or shared state keep unrelated PRs red (5 sightings on 28 Nov) #3180, which Tests: serialise the pipeline tests that store into the library builder #3221 (2c003dd6) fixes. On 710a5f4f, cargo test -p xcl --lib -- recomp::pso xbox:: rt32 ps_32bit_rt_export pipeline_library warm_library pipeline_cap_tests --test-threads=4: 72 passed, 0 failed, 1 ignored, no SKIPPED. RTX 4070 SUPER 12 GB (driver 621.40), Ryzen 7 5700X, 32 GB RAM, Windows 10 19045, Rust 1.100.0; tests in debug, the title in release; all runs with a cache directory of their own (XCL_DXIL_CACHE).
  • cargo test -p xcl --lib -- recomp::pso xbox:: rt32 ps_32bit_rt_export: 57 passed, 0 failed, 1 ignored (this PR's tests and Recompiler: patch console FP16 PS exports for 32-bit render targets #3200's).
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: the integration harnesses 138 passed, 1 failed, 20 ignored. The failure, e2e::test_title_runs_and_game_folder_is_untouched ("a texture in title memory (XG layout, Split wave32 geometry: refuse prefix counts over a mask #44) follows CPU writes: subresource 2 row 0 differs"), passed 2 of 2 runs on its own on both this head and main 3b6a91ed. The library harness ended early, with exit code 0x80004005 after "sparse upload preparation still failed after bounded retries – the title is stopped before its GPU submission" (prepare_title_submission → end_title), as it does on main (reported before on this PR).
  • So the library tests ran single-threaded (--test-threads=1) in parts, on this head and on main 3b6a91ed:
    • list_x::tests: 104 passed, 0 failed on both; sparse::tests: 140 passed, 0 failed, 1 ignored on both. (A full single-threaded run ended with the abort above inside these groups, at sparse::tests::a_buffer_over_a_remapped_tile_reads_the_new_page, which passes on its own on both.)
    • the rest (--skip list_x::tests --skip sparse::tests): on both, the run ended with the same abort at the same test, texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays. Up to there: this PR 1,585 passed, 4 failed; main 1,583 passed and the same 4 failed (the 2 more are this PR's tests). The 4 are main's own geometry tests: geometry_tests::gpu_geometry_msg_gs_done_records, geometry_tests::msg_gs_done_emits_in_dxil, lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits, lower_mem::stage_guard_tests::geometry_export_rejected.
    • The tests after that point did not run in this round; on the head before the rebase (e8782653 on main 10d27297) the whole library ran single-threaded: 2,012 passed, 7 failed, 28 ignored, against main's 2,010 / 7 / 28, the failures main's own.
  • SKIPPED on this adapter, 26 lines, the same on both: 22 "no wave64", 3 per-lane f16 refusals ("its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"), 1 "no heap windows (opt-in: XCL_HEAP_WINDOWS=1)". None is a test of this PR.
  • The retail title, on a local test tree with this change (not this branch): with the patch, the packed lighting target holds full 32-bit values, the HDR target has no NaNs or blue-only spikes, and the blue-white glow is gone from the frames dumped in the cutscene. Reports in this thread from @jessenic and @BBareth on their trees agree.

Regression run

scripts/smoke.ps1, 200 s, the same title, no input, XCL_PREPARE=0 on both (both build in game what they use), each run with its tree's own scripts/smoke.ps1 and with a cache directory of its own.

main:

xcl-smoke v1
commit: 3b6a91ed096d6d6e0fee52cfb86dc0a7d7c8c1b0
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 5662 (PresentX 5662)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15231 MB

this PR's head:

xcl-smoke v1
commit: 710a5f4fe38763a8f901e70eeff212c32544e3d1
gpu: NVIDIA GeForce RTX 4070 SUPER
title: 9cc6a39e
seconds: 200
exit: 0x0
frames shown: 5867 (PresentX 5867)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14522 MB

Not tested

  • These 200 s runs with no input most likely don't reach the 3D scenes whose targets the patch changes: both held a steady 60 presents per 2 s, while the 3D scenes run at a few frames a second on this machine (no frames were dumped in these runs). The visible effect was checked on the local test tree above, not on this branch.
  • How many of a retail pack's pixel shaders this PR patches where Recompiler: patch console FP16 PS exports for 32-bit render targets #3200 declines (see above).
  • AMD, other NVIDIA cards and drivers, other titles.
  • 16-bit integer targets (UINT16 / SINT16 formats): not by me; @andrewDoing checked them on an RTX 5070 in review (in-range values preserved on both shader paths).

AI use

🤖 Generated with Claude Code

@jessenic

jessenic commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

A test report from another card and another tree: the blue-white skin is gone with this patch.

Tested

  • This PR's commit e8782653 cherry-picked onto my lab line (jessenic/xcl lab/two-pass-batch, bdac3b84; the two doc files conflicted and I kept mine, xbox.rs applied cleanly). Not this PR's own head on main.
  • RTX 5070 Ti 16 GB, driver 610.88, Ryzen 7 9700X, Windows 11, release, Series S profile, network off. The newer build of the retail title, the cell at the start of the story (day), no input.
  • cargo test --release -p xcl --lib ps_export_patch: 2 passed, 0 failed.
  • Two runs (1,000 s on a cold cache, 660 s warm), a frame dumped every 300 presents: no crash, no device removal, 4.4 and 4.6 presents/s over the last two minutes.
  • In all 9 frames dumped in the world, the head is drawn and is not blue or blue-white. In the first run it has a natural skin tone, lit from the window. Before the patch, on the same line, the head was blue-white, had a blue rim at the neck or (one run) a small blue spot in every run where it was drawn (5 of the last 8 runs; not drawn in the other 3).
  • XCL_DEBUG_MAGENTA=42a7d936b37ac3e1 (TL_PS_PBR_MATERIAL_SKIN) had shown earlier that this program's output is what goes wrong on the head (Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505, 7242576967), which fits the cause given here.

One thing I had to add on my line, which may matter here too: the patch changes the code a pixel program is translated from, not the blob the title hands over. Where the translated cache is keyed by that blob's hash, a translation cached before the patch is served as it was. I gave the cache identity a salt when the patches are on (every shader is translated again once, about 5 more minutes to the world on the first launch). I did not check how main keys it.

Not tested

  • This PR's head on main; AMD; other scenes than the cell.
  • In the second run the skin has bright orange speckle around the neck and hairline. Whether that is from this change or was hidden under the blue before, I can't say from two runs.
  • No count of texels; by eye on downscaled frames.

AI use: Claude Code with Claude Fable 5.2 cherry-picked the commit, ran the tests and the runs on this machine, and wrote this report. No frame posted.

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the 16-bit integer render-target case listed under “Not tested” on exact head e87826532e98a43353e255665ff19bf2bd93106c, RTX 5070 / NVIDIA 616.92. In both tested cases the patched export preserved the intended in-range integer, with identical results through HLSL + DXC and direct DXIL.

The synthetic v0x101 FSSM had a header-located pixel program, a stored V_CVT_PKRTZ_F16_F32 and compressed export, and a 32_ABGR variant exporting the source VGPR directly. I used the production analyze_fssm path, asserted the switch actually changed the code, translated that code with the corresponding signed or unsigned output signature, drew to a native 4×4 target, and read back each 16-bit texel after a fence.

Native RTV Source VGPR bits Patch off Patch on
R16_UINT 00001234 (+4660) 0000 1234 (+4660)
R16_SINT fffffedc (−292) 7fff fedc (−292)

All eight shaded texels per draw matched the value shown. The eight texels outside the scissor retained the clear value 0011 in every draw. Four fresh switch/format processes exercised both translators, for eight native draws and zero skips.

This establishes the PC output for these two representable values in a one-target synthetic shader. It does not compare against a console capture, cover out-of-range conversion, or establish whether a retail title uses these formats.

AI use: OpenAI Codex built the test-only FSSM and typed render-target fixture, ran the controls, and wrote this report.

@BBareth

BBareth commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

A test report from GTA 6's intro cutscene (#505): with this patch the night, sunset and daylight shots are exposed far closer to correct.

Tested

Seen, same shots, without the PR → with it

  • Night street: mostly black with a few lamps → building facades, windows and street lights all lit.
  • Sunset over the city: flat brown haze → sun disc, red/orange clouds, lit treeline.
  • Prison yard in daylight: blown-out white sky → blue sky with clouds and a normally exposed horizon. The ground and buildings are now somewhat dark.
  • Aerial sea shot: clouds and sea look right.

Not fixed / not attributable to this PR

  • The game fell to ~1.3 fps near the end (process 7.2 GB over its video memory budget; 75k pipelines still in the build-ahead backlog), and the run hit the time limit at frame ~6,780 while in the prison yard. That limit also hit without the PR.
  • One later yard frame shows flat blue shapes with missing geometry (probably draws skipped while pipelines were still building).
  • Close-up crowd shots are still darker than on VIctory-NVIDIA on the same machine.
  • No GPU hang or crash in either run.

AI use: test run and report by Claude Code, Claude Opus 5.5.

@andrewDoing

Copy link
Copy Markdown
Contributor

A warm translated-shader cache can mask XCL_PS_EXPORT_PATCH in either direction on e8782653. I ran four fresh Windows processes through the production pso::console_to_dxil_in pixel caller, using the same synthetic v0x101 Xbox pixel container, a real uint SV_Target output signature and a valid 32_ABGR table. Each process also independently parsed the container and asserted that the actual export instructions matched its switch setting.

Cache First process (cold) Second process (warm)
A patch=1 → DXIL hash 5ad4c1e3259a2aa9 patch=0 → 5ad4c1e3259a2aa9
B patch=0 → DXIL hash 9be258cbc57a259c patch=1 → 9be258cbc57a259c

The two cold translations differ as expected. In both warm processes the decoded instructions switched, but the returned DXIL still matched the first process. The translated cache uses the original Xbox container and translator build identity; toggling a runtime switch changes neither. A narrowly scoped correction is to bypass translated pixel cache reads and writes when the export patch is effectively disabled, leaving the default cache available. An explicitly mode-keyed pixel cache is another option. Until then, separate XCL_DXIL_CACHE directories give a valid A/B control. This measured returned DXIL bytes, without drawing or making a retail performance claim.

AI assistance: OpenAI Codex traced the production path, assembled the synthetic fixture, ran the four controls and drafted this comment.

@andrewDoing

Copy link
Copy Markdown
Contributor

I tested a small candidate on e8782653. It uses the parser's process-wide effective switch for both the success and error disk paths. Unset and explicit 1 share the patched entry; 0 has its own entry. Neither mode reads an old unlabelled pixel entry, whose origin cannot be inferred. The in-process translation key can stay unchanged because the parser freezes the setting on first use.

Fresh processes calling console_to_dxil_in on the same synthetic Xbox pixel container returned these DXIL hashes:

Shared cache Mode sequence Hash sequence
D unset → 0 → 1 5ad4c1e3259a2aa9 → 9be258cbc57a259c → 5ad4c1e3259a2aa9
E 0 → unset → 0 9be258cbc57a259c → 5ad4c1e3259a2aa9 → 9be258cbc57a259c

I also seeded a third cache with only a valid stored-mode entry under the old filename, using the candidate's exact translator identity and shader blob. An unset launch returned the patched hash and wrote a separate patched entry. This checks migration even when a build fingerprint change cannot hide stale entries. The patch preserves non-pixel filenames; as usual, changing a translator source can invalidate the build fingerprint. No retail or GPU run for this cache-only follow-up.

Apply-checked against the pristine PR head. The following is the entire production patch.

--- a/crates/xcl/src/gpu/xbox.rs
+++ b/crates/xcl/src/gpu/xbox.rs
@@ -364,7 +364,7 @@
 }
 
 /// `XCL_PS_EXPORT_PATCH=0` leaves pixel shaders' render-target exports as the compiler stored them.
-fn ps_exports_patched() -> bool {
+pub(crate) fn ps_exports_patched() -> bool {
     static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
     *ON.get_or_init(|| !std::env::var("XCL_PS_EXPORT_PATCH").is_ok_and(|v| v.trim() == "0"))
 }
--- a/crates/xcl/src/gpu/recomp/pso.rs
+++ b/crates/xcl/src/gpu/recomp/pso.rs
@@ -374,10 +374,16 @@
     }
 
     pub(super) fn file(dir: &Path, ident: u64, blob: &[u8], stage: Stage, sampler_base: u32, windows: u32, split: bool) -> PathBuf {
+        // Older pixel entries do not identify the export mode that produced them.
+        let exports = match stage {
+            Stage::Pixel if crate::gpu::xbox::ps_exports_patched() => "_exports_patched",
+            Stage::Pixel => "_exports_stored",
+            _ => "",
+        };
         dir.join("translated")
             .join("v2")
             .join(format!("{ident:016x}"))
-            .join(format!("{:016x}_{stage:?}_{sampler_base}_{windows}_{}.bin", crate::gpu::shader::fnv64(blob), split as u8))
+            .join(format!("{:016x}_{stage:?}_{sampler_base}_{windows}_{}{exports}.bin", crate::gpu::shader::fnv64(blob), split as u8))
     }
 
     fn header(ident: u64, blob: &[u8]) -> Vec<u8> {

AI assistance: OpenAI Codex implemented the candidate, ran the fresh-process controls, and wrote this report.

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving on a merge-check run on an RTX 3060 Ti 8 GB (driver 32.0.16.1714, i5-10400, Windows 11 Pro 26200, Rust 1.100.0).

  • Head e87826532e98a43353e255665ff19bf2bd93106c merged cleanly onto main 7db2f391, and the workspace builds.
  • cargo test --workspace --no-fail-fast -- --test-threads=4, with --skip for three uma_driver tests that can end the library harness on this PC on plain main too: 2,593 passed, 0 failed, 49 ignored, 28 SKIPPED (21 of them no wave64). main with the same skips: 2,591 passed, 0 failed. Both new tests pass.
  • The cold case on an 8 GB card: a 420 s scripts/smoke.ps1 world run (scripted confirm presses, Series S profile, XCL_PREPARE=0, a private shader cache) gave 3,529 frames and a peak commit of 22,048 MB with this change, against 3,463 frames and 23,115 MB on main. No device removal and no crash on either. Both stop presenting after about 240 s with some 83,000 pipelines in the build-ahead backlog, so that stall is main's. One run a side.
  • 60 s smoke: 1,411 frames against 1,385 on main, no device removal, no crash.
  • xbox.rs read in full, no blocking finding. Not checked here: the picture itself; no frames were dumped on this card.
  • The red Build and test run on this head failed in one timing test, hle::kernelx::tests::fine_timer_makes_short_sleeps_short, which this change does not touch.

AI use: Claude Code ran the builds, tests and game runs on Prime's PC and wrote this text. Approving is Prime's decision.

I use a temporary Discord to coordinate my work. Anyone helping test XCL or compare results is welcome. Test coordination on Discord

@Eterst
Eterst force-pushed the shaders/ps-export-patch branch from e878265 to 6931baa Compare November 29, 2026 00:41
@Eterst

Eterst commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@andrewDoing thank you, both points taken.

  • The cache: your fix is in, squashed into the PR's one commit (now 6931baaf, credited in its message). The mode suffix comes from a small helper, translated::exports_mode(stage, patched), so the test can check both modes in one process. translated_namespace_tracks_every_request_input now also asserts that a pixel shader's entry names its mode, that the two modes differ, and that vertex and compute entries keep their old names. Run here against a cache of its own: cargo test -p xcl --lib -- recomp::pso xbox:: 52 passed, 0 failed, 1 ignored.
  • 16-bit integer targets: thanks for checking that case; the description's Not tested now points to your report.

The regression block in the description is rerun on the new head.

Thanks also to @jessenic and @BBareth for the runs on their trees.

AI use: Claude Code (Claude Opus 5.5) applied the change, ran the tests and the regression run, and wrote this reply.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026

@Prime1997 Prime1997 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving again on the updated head, after a rerun on the same RTX 3060 Ti 8 GB (driver 32.0.16.1714).

  • Head 6931baaf92e3693f0e48b023a5b368da27b713af merged cleanly onto main 7db2f391, and the workspace builds.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 with the same three uma_driver tests skipped: 2,593 passed, 0 failed, 49 ignored, 28 SKIPPED. Same counts as on the previous head.
  • 60 s scripts/smoke.ps1 with XCL_PREPARE=0: 1,420 frames against 1,385 on main, peak commit 15,283 MB against 15,626 MB, no device removal, no crash.
  • The 420 s cold-cache world run in my earlier review was made on the previous head e8782653 and was not repeated: the patch code is the same, and this update only adds the export mode to the translated-cache file name.

AI use: Claude Code ran the builds, tests and game runs on Prime's PC and wrote this text. Approving is Prime's decision.

I use a temporary Discord to coordinate my work. Anyone helping test XCL or compare results is welcome. Test coordination on Discord

@andrewDoing

Copy link
Copy Markdown
Contributor

Confirmed the squashed cache fix on 6931baa. Seven fresh Windows processes called the production console_to_dxil_in path with the same synthetic Xbox pixel shader. With one shared cache, unset → 0 → 1 returned patched → stored → patched DXIL. With a second cache, 0 → unset → 0 returned stored → patched → stored. The hashes were 5ad4c1e3259a2aa9 (patched) and 9be258cbc57a259c (stored).

For the seventh launch I seeded a third cache with only the valid stored entry under the old unlabelled filename, in the current translator identity directory. Unset produced the patched hash and created its labelled entry alongside the legacy one. This closes my disk-cache finding on the author's implementation. Synthetic translation only; no new title or GPU run. OpenAI Codex prepared the test overlay, ran the controls and drafted this comment.

@Eterst

Eterst commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 3b6a91ed (head bb0679fb) and marked ready for review.

#3200 was merged in the meantime and fixes the same symptom from the other side: it rewrites the FP16 export epilogue during translation for pipelines with 32-bit render targets, behind a liveness check. This PR applies the console's own export patch table while the FSSM is parsed, for every target and format. The two coexist; the only conflict was the translated-cache file name, which now carries both this PR's export mode and #3200's _rt32_<mask> (#3200's test is unchanged). The description has a section on the difference, the suite counts on the new head (compared with main 3b6a91ed part by part, since the library harness ends early on both at the same test), and a new regression pair: 5,787 frames against main's 5,662, peak commit 15,377 MB against 15,231 MB, no removals or crashes.

AI use: Claude Code (Claude Opus 5.5) did the rebase, ran the tests and the regression runs, and wrote this comment.

@Eterst
Eterst force-pushed the shaders/ps-export-patch branch from bb0679f to 601481e Compare November 29, 2026 15:52
@Eterst

Eterst commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

CI on bb0679fb failed on six tests, none of them in this change: two geometry tests that failed on main 3b6a91ed itself (geometry_tests::msg_gs_done_emits_in_dxil, lower_mem::stage_guard_tests::geometry_export_rejected; fixed on main in 468190c2), and four shaders::pipeline_library / warm_library tests, the group listed in #3180 as failing on unrelated PRs (they pass here, 10 of 10, twice). Rebased onto main bc2cbb72 (head 601481ed): the two geometry tests pass, and the regression block in the description is of the new head.

AI use: Claude Code (Claude Opus 5.5) read the CI log, rebased, reran the tests and the regression run, and wrote this comment.

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
A pixel shader's render-target exports are stored for one export format,
the compiler's default FP16 (v_cvt_pkrtz_f16_f32 and a compressed exp).
The console patches them at pipeline creation for each target's
SPI_SHADER_COL_FORMAT from a table in the PS stage data: per render
target, the code offset and ten variants of the export code. XCL never
applied it, so a target of 32 bits a channel got the FP16 conversion of
its value: a packed R32_UINT lighting target of a retail title held
f16(asfloat(bits)), 0x7BFF where the packed value was large, instead of
its bits. On screen: a blue-white glow on skin and lit surfaces.

Every target is patched to the 32_ABGR variant: the channels leave the
shader unconverted and the PC target converts them, which is right for
every PC format. A table that is implausible (no PS record, a size of 0
or over ten dwords, a patch past the code, an empty variant) changes
nothing. XCL_PS_EXPORT_PATCH=0 keeps the stored exports.

The table layout (record at payload + 0x30, stage data at record + 0x54,
size at + 0x148, eight entries from + 0x14C) is as VIctory documents it
in victory-shader/src/native.rs (GPL-3.0); the code is written
independently. THIRD_PARTY.md says so.

A pixel shader's entry in the translated-shader cache names its export
mode (translated::exports_mode): neither the shader's bytes nor the
translator's identity record XCL_PS_EXPORT_PATCH, so a warm cache handed one
mode's translation to the other. Older unlabelled pixel entries are not
read. Found and fixed by andrewDoing in review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Eterst
Eterst force-pushed the shaders/ps-export-patch branch from 601481e to 710a5f4 Compare November 29, 2026 17:34
@Eterst

Eterst commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

The PR is now at 710a5f4f, on main 0fe06eb0, with every check green. The merge queue (#3041) counts test reports and merge checks only on the current head. The reports and approvals here are on e8782653 and 6931baaf, so it no longer lists this PR.

What changed since 6931baaf (git range-diff):

@Prime1997 @andrewDoing, if you have time, a rerun on 710a5f4fe38763a8f901e70eeff212c32544e3d1 would count for the queue: suite counts, or an xcl-smoke block, naming that commit, or a merge check in #3041's format. Thank you for the earlier runs.

AI use: Claude Code (Claude Opus 5.5) compared the heads and wrote this comment.

@claudetools-gh

Copy link
Copy Markdown

A data point for this PR, from an RTX 5070 Ti (driver 621.40). We tested a local port of the same idea, not this PR's code.

Our tree is an older base that already has #3200. On top of it we apply the console's export patch table first: the 32_ABGR slot, for the render targets #3200's rt32_mask names. What the table does not cover falls back to #3200's pattern. In one run, 287 pixel shaders were patched from the table, and none were left for the pattern.

Result in the prologue cell, compared with #3200 alone, at the same shot:

  • Lucia's back goes from a near-black silhouette to the orange "INMATE" shirt.
  • Her ponytail shows.

The difference showed up after we fixed the tile lighting's material-class plane, which is described in #505. Since that fix, skin and cloth tiles go through the R32_UINT subsurface path. With #3200's pattern alone, some of those shaders still wrote the FP16 form. We have not narrowed down which ones, or which of #3200's liveness declines they hit.

This is one run (360 s, no device removal), with the same switches as our earlier runs. Untested: AMD, and this PR's own code on main, since the PR currently conflicts.

AI-assisted.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Review (head 710a5f4, diff read, not a merge-check; conflicts with main, a textual conflict next to branch_targets in gpu/xbox.rs):

  • The offsets may be measured from the wrong code (unverified). The patch offsets are applied relative to the code pointer at FSSM+0xC0, the record at payload 0xB0. The table, though, is read from the PS record at payload+0x30, and VIctory measures the offsets from the PS record's own code. If the two can differ, patches land in the wrong words. Requiring record == 0xB0, or using the PS record's code, would settle it.
  • No test of the switch-on. The tests call patch_ps_exports directly, so the gate in analyze_fssm (xbox.rs ~339) that decides whether a title's shaders get patched isn't tested.
  • XCL_PS_EXPORT_PATCH is an env switch in the same PR, and the extra cache-naming code exists only for it. CONTRIBUTING puts switches in their own PR.
  • Nit: e + 0x148 (~421) isn't overflow-checked. A malformed record wraps in release and can patch arbitrary words; checked_add would match the surrounding reads.
  • Unverified: whether the graphics driver-blob persistence key separates the two switch modes.

Fine:

  • The layout matches VIctory's native.rs, credited in THIRD_PARTY.md: payload+0x30 is the PS slot, other stages hold 0xDEADBEEF, the table is at +0x148 / +0x14C, and variant 9 is 32_ABGR.
  • Bounds are checked, and empty variants are skipped.
  • Pixel shader cache entries carry the patch mode, so old entries aren't reused.
  • Two testers saw the visual fix.

It is on by default and runs in xbox::parse for every v0x101 FSSM, so it changes every retail pixel shader. After the rebase, a full suite run and a smoke pair on the new head matter. Related: #3200 (merged, same symptom at translation) and #3273 (integer render targets).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 710a5f4

Main already handles 32-bit render targets per pipeline (ps_rt32_mask / recomp::patch_ps_32bit_exports, which rewrites compressed exports for R32 targets); this PR instead applies the console's own export patch table (32_ABGR variant) to every pixel shader in xbox::analyze_fssm, so the two coexist (the rt32 pass skips exports that are no longer compressed).
The same patch table is also applied on the amd-dev branch (recomp::patch_ps_exports in commit 8942a5b, part of the open amd-dev merge PRs), with a different implementation; whichever lands second should drop its copy.
The translated-cache key gains an export-mode suffix for pixel shaders only, so existing pixel entries are rebuilt once.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants