Skip to content

D3D12.X: keep untranslated console graphics and stream shaders out of the driver - #303

Open
pedrocalazans05 wants to merge 1 commit into
xcl-dev:mainfrom
pedrocalazans05:fix/amd-nobc-pso-guard
Open

pedrocalazans05 wants to merge 1 commit into
xcl-dev:mainfrom
pedrocalazans05:fix/amd-nobc-pso-guard

Conversation

@pedrocalazans05

@pedrocalazans05 pedrocalazans05 commented Nov 23, 2026 •

Copy link
Copy Markdown

Mirrors dev_create_compute_pso's console-bytecode guard in graphics_pso and dev_create_pipeline_state so untranslated console DXIL (NOBC / XDAT) never reaches the PC shader compiler. On AMD GPUs (amdxc64.dll), passing stripped console DXIL directly to CreateGraphicsPipelineState / CreatePipelineState triggers a fail-fast crash (0xc0000409) instead of returning E_INVALIDARG.

When translated_graphics_pso returns a failed HRESULT (for example translated_gs_pso on a GPU without D3D12 mesh shaders), graphics_pso now falls through to the stand-in PSO instead of returning the failed HRESULT directly. Inside fallback_stream, console topology types (subobject 14 — anything outside 1..=3, including UNDEFINED, PATCH since HS/DS are stripped, and console RECT_LIST_TYPE = 19), RTV formats (subobject 15), and DSV formats (subobject 16) are rewritten to PC-compatible values.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs:
    • graphics_has_console_shader and stream_has_console_shader guards before raw finish_pso in graphics_pso and dev_create_pipeline_state
    • Fallthrough to the dummy stand-in when translated_graphics_pso returns hr < 0
    • Console topology (14 → TRIANGLE), RTV (15 → pc_target_format), and DSV (16 → pc_view_format) translation in fallback_stream (aligned with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214's fallback_stream subobjects 14/15/16)
    • Unit and behavioral tests in console_pso_guard_tests: predicate tests, fallback_stream rewrite test, plus an isolated FakeAdoptedDevice harness calling graphics_pso and dev_create_pipeline_state directly to verify driver call counts, console shader blocking, translated_gs_pso failure fallthrough, fallback_stream rewriting, and PC-only passthrough

Tested

  • Hardware / OS: AMD Radeon RX 580 2048SP (8170 MiB VRAM, Polaris/GCN4, driver 31.0.21925.1001), Intel Core i3-10100F, Windows 11 Build 26300, rustc 1.100.0 (0ef1bc386 2026-11-09), debug (cargo test) & release (cargo build --release -p xcl)
  • Commit tested: 1193d2c (rebased cleanly onto origin/main 7ebf1b8)
  • cargo test -p xcl --lib console_pso_guard_tests -- --test-threads=4: 7 passed, 0 failed, 0 ignored (also 7 passed with XCL_ASYNC_PSO=0)
  • Negative controls verified on 1193d2c (temporarily removing each runtime change and running console_pso_guard_tests):
    • Removing graphics_has_console_shader guard: 2 behavioral tests fail (CreateGraphicsPipelineState called twice with console bytecode first)
    • Removing if hr >= 0 fallthrough in graphics_pso: graphics_pso_falls_through_to_standin_when_translated_gs_pso_fails fails (E_INVALIDARG returned, 0 driver calls)
    • Removing stream_has_console_shader guard: dev_create_pipeline_state_blocks_console_stream_and_rewrites_fallback fails (CreatePipelineState called twice with console stream first)
  • cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=4: 95 passed, 0 failed, 1 ignored, 0 skipped
  • cargo test -p xcl --test '*' -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched: 39 passed, 0 failed, 20 ignored, 1 filtered out
  • cargo clippy -p xcl --lib --tests: 0 warnings on added/modified lines in real.rs
  • Retail title AMD crash context: on this RX 580 (amdxc64.dll 31.0.21925.1001), untranslated console shaders reaching CreateGraphicsPipelineState/CreatePipelineState caused amdxc64.dll fail-fast 0xc0000409 during extended runs before this guard; with this guard in place, extended runs and the 60 s smoke run below hit 0 amdxc64.dll crashes.

Regression run

xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: AMD Radeon RX 580 2048SP
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1367 (PresentX 1367)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 10019 MB
xcl-smoke v1
commit: 1193d2c5f504a3972788d4be71e86a0779ad01e6
gpu: AMD Radeon RX 580 2048SP
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1339 (PresentX 1339)
presents per 2 s (last 3): 60 60 59
device removals: 0
crashes: 0
peak commit: 10046 MB

Not tested

  • Full gpu::recomp::tests::gpu_* suite on this RX 580 (Polaris lacks Wave32 / native f16 / SM 6.6; gpu_wave64_ps_whole_wave_reductions hits a pre-existing Polaris driver access violation, unrelated to real.rs)
  • GPUs with D3D12 mesh shaders / Wave32 / native f16 (RDNA2+, NVIDIA RTX, Intel Arc — previously green on RX 7900 XTX, RTX 4070 Ti, and RTX 5070 Ti on 80fb3be)
  • test_title_runs_and_game_folder_is_untouched (no System32\xgameruntime.dll / Gaming Services installed on this PC)
  • XCL_SAMPLE_* game-data tests (variables unset)

AI use

  • Tool / model: Antigravity (Google DeepMind), Gemini 4 Neon / Gemini 4 Hydrogen
  • What it did: diagnosed the amdxc64.dll 0xc0000409 crash from logs, implemented the console-shader guards, fallback_stream subobject 14/15/16 rewrites, and FakeAdoptedDevice behavioral tests + negative controls, ran the local tests/smoke runs above, and performed an adversarial code review (APPROVE). Reviewed and verified by the author.

@Fizzonaut

Copy link
Copy Markdown

Independent test run on commit 80fb3be6055be6d47a7389a35586978b6fffec7d (PR #303 head; clean merge onto origin/main 4017f8f checked via git merge-tree) on AMD RDNA3 with mesh shaders, xgameruntime.dll, and the D3D12 debug layer: pass.

Tested

  • Hardware / software: AMD Radeon RX 7900 XTX (24516 MiB VRAM, driver 32.0.31007.5012), AMD Ryzen 7 7800X3D, Windows 11 Pro 26H2 (build 26300.9974), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5 via XCL_DXC_DIR, System32\xgameruntime.dll 10.0.26100.9656, D3D12 debug layer active (D3D12SDKLayers.dll), debug build.
  • Command: powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4), no XCL_SAMPLE_* set:
    • Native (default): 654 passed, 0 failed, 40 ignored, 0 SKIPPED GPU tests (exit 0)
    • XCL_SPLIT_WAVE64=1: 654 passed, 0 failed, 40 ignored, 0 SKIPPED GPU tests (exit 0)
  • All 3 new console_pso_guard_tests (graphics_desc_detects_console_shader_in_any_stage, pipeline_stream_detects_console_shader_subobjects, fallback_stream_rewrites_console_rtv_and_dsv_formats) and test_title_runs_and_game_folder_is_untouched (e2e) ran and passed.

Not tested

  • Retail title / scripts/smoke.ps1 (no unpacked Xbox title available), XCL_SAMPLE_* game-data tests, release build, NVIDIA / wave32-only GPUs.
  • No manual code review performed.

AI use

  • Antigravity (Gemini 4 Neon) checked out the PR, ran both test runs, and drafted this test report from the actual output.

@Kalmarv

Kalmarv commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested 80fb3be merged onto main 4017f8f (merge 365c47f, no conflicts). The change does what the description says; three things to settle.

1. The new tests cover the two predicates and fallback_stream, not the change in behaviour.

  • With both guards taken out of graphics_pso and dev_create_pipeline_state, and a failed translated_graphics_pso returned to the title again as on main, all three tests in console_pso_guard_tests still pass (3 passed, 0 failed).
  • So nothing fails if a console shader reaches finish_pso again, or if a failed translation stops falling through to the stand-in. A test of that needs a device whose CreateGraphicsPipelineState / CreatePipelineState calls can be counted, like the fake list vtable in bind::tests.
  • Negative control on main: fallback_stream_rewrites_console_rtv_and_dsv_formats fails there (formats stay [116, 117, 86, 115, 28, …]) and passes on the merge. The other two tests call the new predicates, so they do not compile on main.

2. It conflicts with #214 in real.rs (at f007d4a, and still at its current head 960162e), and both add the same rewrite.

3. scripts/pr_check.py on main refuses the description as it is: "the PR's run shows fewer frames than main's (47 against 78)". That is 60 %; the rule asks for 80 %.

From reading, where the graphics guard applies: translated_graphics_pso returns None for a console VS when the pipeline has an HS or DS, when a shader does not translate, and when the driver rejects the translated pipeline. In all three, main hands the original description with its console shaders to finish_pso. With the PR those get E_INVALIDARG and then the dummy-shader stand-in.

Tested

RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200, debug.

Not tested

  • AMD: the driver crash this PR is about does not happen on NVIDIA, so I could not show the guard preventing it.
  • A GPU without mesh shaders (the translated_gs_pso failure the fallthrough is for).
  • The retail game, and any pipeline that takes one of the three paths above.

🤖 Claude Fable 5.2

… the driver

Mirror dev_create_compute_pso's console-bytecode guard in graphics_pso and dev_create_pipeline_state so untranslated Xbox DXIL (NOBC/XDAT) never reaches the PC shader compiler (AMD's amdxc64.dll fails fast with 0xc0000409 instead of returning E_INVALIDARG).

Also fall through to the stand-in PSO when translated_graphics_pso returns a failed HRESULT (e.g. translated_gs_pso on GPUs without mesh shaders), and rewrite console topology (subobject 14 -> TRIANGLE since HS/DS are stripped), RTV (subobject 15), and DSV (subobject 16) formats inside fallback_stream.

Adds unit tests for the predicates and fallback_stream rewrites plus fake-device behavioral tests calling graphics_pso and dev_create_pipeline_state directly.
@pedrocalazans05

Copy link
Copy Markdown
Author

Thanks for the thorough review and negative-control check, @Kalmarv! Updated the PR on commit 1193d2c (rebased onto origin/main 7ebf1b8) to address all three points:

  1. Behavioral tests (console_pso_guard_tests): Added an isolated FakeAdoptedDevice vtable harness calling graphics_pso and dev_create_pipeline_state directly and counting driver calls:

    • graphics_pso_blocks_untranslated_console_shaders_and_uses_standin — console VS+HS desc never reaches CreateGraphicsPipelineState; driver sees 1 call with dummy PC shaders (S_OK).
    • graphics_pso_falls_through_to_standin_when_translated_gs_pso_fails — console VS+GS desc where translated_gs_pso returns E_INVALIDARG (fake device reports no mesh shaders) falls through to the stand-in PSO (S_OK, 1 call with dummy PC shaders).
    • dev_create_pipeline_state_blocks_console_stream_and_rewrites_fallback — console PS stream (StreamPipeline::Unknown) never reaches CreatePipelineState; driver sees 1 call with dummy PC PS and rewritten subobjects 14/15/16.
    • pc_only_graphics_and_stream_psos_pass_through_unmodified — cloned PC-only shaders pass directly to the driver unmodified.
    • Verified all three negative controls fail when each runtime change is temporarily removed (graphics_has_console_shader guard, if hr >= 0 fallthrough, stream_has_console_shader guard).
  2. fallback_stream alignment with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214: Added subobject 14 (PrimitiveTopologyType) normalization alongside 15 and 16. Because fallback_stream unconditionally strips HS/DS (3 | 4 | 5 | 24 => put(&mut buf, &[])), anything outside 1..=3 (including UNDEFINED = 0, PATCH = 4, and console RECT_LIST_TYPE = 19) is rewritten to TRIANGLE (3). Since D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 is still open, rebasing onto main keeps this PR standalone and makes reconciling D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 straightforward if this lands first.

  3. Smoke regression run (scripts/pr_check.py): Re-ran scripts/smoke.ps1 (60 s) on both origin/main (7ebf1b8: 1367 frames, 10019 MB) and 1193d2c (1339 frames — 98% of main, 10046 MB, 0 crashes, 0 device removals) on the AMD RX 580 and updated the PR description accordingly.

Also thank you @Fizzonaut and @jleybourne for the independent RDNA3 and NVIDIA test runs on 80fb3be!

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 1193d2c5f504a3972788d4be71e86a0779ad01e6 on AMD RDNA4. I merged it onto current main d5442d2 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200 (native Windows), Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 711 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 670 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the console_pso_guard_tests pass.

Review: Untranslated console shaders are kept out of the driver and the stand-in is used, while PC-only graphics and stream PSOs pass through unmodified, as the tests check. At 499 lines I reviewed the structure, not every line.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@iggyvilla

Copy link
Copy Markdown
Collaborator

Test report and review for 1193d2c5f504a3972788d4be71e86a0779ad01e6 (current head of #303; base 7ebf1b8044bef8f0ef296eb36e85010cceb4633a, one crates/xcl/src/hle/d3d12x/real.rs change) on an AMD RDNA2 card. The builds and runs were done by an agent (omp, DeepSeek V4.1 Flash) and I checked the numbers below against its saved smoke blocks and test log; the text is by Claude Code (Claude Sonnet 5.5).

Tested

  • AMD Radeon RX 6650 XT (RDNA2, 8 GB), driver 32.0.21045.29003; Ryzen 7 5700X, 32 GB; Windows 11 build 26300; rustc 1.100.0; no XCL_SAMPLE_*. Clean worktrees for head and base; debug for the tests, release for the smokes.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on the head: 681 passed, 3 failed, 41 ignored (16 test binaries; sums of the saved log). No SKIPPED lines; adapter-dependent tests are #[ignore]d here instead. The 3 failures are this card's known set: placed_title_textures_share_vram_and_preserve_pixels (3D 64x64x64 4 mips: subresource 2 mismatch, the D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470 defect) and the two PoisonError cascades it leaves (transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory). A first run before a workspace build failed e2e for lack of the test-title binary; it is 3/3 once built.
  • cargo test -p xcl --lib console_pso_guard_tests -- --test-threads=4: 7 passed, 0 failed. The head merged onto main as of 6efdabc (clean) gave the same 7/7; only these guard tests were run on that merge.
  • Smoke (XCL_NETWORK=0, retail title, 60 s, after one unmeasured 60 s warm-up of 1449 frames; head first, then base). Pasted from scripts/smoke.ps1 output:
xcl-smoke v1
commit: 1193d2c5f504a3972788d4be71e86a0779ad01e6
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1444 (PresentX 1445)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15187 MB
xcl-smoke v1
commit: 7ebf1b8044bef8f0ef296eb36e85010cceb4633a
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 1446 (PresentX 1446)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15189 MB

Head shows 99.9 % of base's frames and the same peak commit; no device removal or crash in either.

Review (diff read at 1193d2c; the points marked "hypothesis" were not run)

  1. The new fall-through in graphics_pso should not hide a real driver failure: the only negative HRESULT translated_graphics_pso returns comes from translated_gs_pso, and finish_two_pass reports both driver failures there as E_INVALIDARG, so device-removed or out-of-memory results are not rewritten.
  2. Coverage looks complete for well-formed input: graphics creation (dev_create_graphics_pso, CreateGraphicsPipelineStateX, the stream-to-desc route) funnels into graphics_pso; compute already had its guard; the stream guard only matters for Unknown streams.
  3. Mesh stand-in vs declared topology. fallback_stream rewrites the primitive-topology subobject (14) only when it is outside 1..=3, but with a mesh stand-in the shader is dummy_mesh(), whose HLSL says [outputtopology("triangle")]. A console mesh stream declaring POINT (1) or LINE (2) keeps that, so the stand-in PSO declares a topology its mesh shader does not produce. Hypothesis: D3D12 requires these to match and the debug layer flags it; not run, and no doc is quoted. Using the already-computed mesh (if mesh || !(1..=3).contains(&topo)) would make the stand-in consistent. Not a regression: main leaves the value alone too.
  4. stream_has_console_shader stops at the first unknown subobject type, so a console shader behind one still reaches the driver (malformed or newer-SDK streams only).
  5. When the guard fires, the log says graphics PSO rejected by the driver (0x80070057) – fallback shaders used, although the driver was not called; a distinct message would keep the diagnosis honest. Cosmetic.
  6. The new fake-device tests check call counts and stand-in selection. graphics_pso_falls_through_to_standin_when_translated_gs_pso_fails gets its E_INVALIDARG from console_geometry on a synthetic blob, not from a missing mesh-shader capability as the name suggests, and nothing covers the mesh/topology arm in point 3.
  7. Overlap with D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 (OPEN, not a draft; head now 96e68a46, which GitHub reports as conflicting). D3D12.X: bound driver PSO compile concurrency and surface stage progress (#156) #214 adds arms 14/15/16 in the same fallback_stream: its arm 14 uses (1..=4) and so keeps PATCH (4), where D3D12.X: keep untranslated console graphics and stream shaders out of the driver #303 turns PATCH into TRIANGLE because HS/DS are stripped; its arm 16 uses pc_target_format where D3D12.X: keep untranslated console graphics and stream shaders out of the driver #303 uses pc_view_format (they differ only for B5G5R5A1/B4G4R4A4). Whichever lands second has to choose the semantics. My reading, not measured: keeping PATCH once HS/DS are stripped looks wrong. git merge-tree of D3D12.X: keep untranslated console graphics and stream shaders out of the driver #303 onto main is clean.

Not tested

  • The AMD fail-fast itself was not reproduced: neither 60 s run logs 0xc0000409 or an amdxc64 failure, so the guard is checked by tests, code reading and clean retail runs, not by watching it prevent a crash. (Context only, not this build: an earlier ~295 s menu run on another commit on this card ended 0xc0000409 in amdxc64.dll about six seconds after a console VS/PS pair was logged.)
  • No GPU without D3D12 mesh shaders, no game-data sample tests, no release-build suite, no long run. The suite and the smokes are the PR head, not the merge with main.

AI use
Claude Code, Claude Sonnet 5.5: checked the numbers against the saved smoke blocks and test log, spot-checked the diff and the #214 diff, and wrote this text; it ran nothing. The builds, suite and smokes, and the first review pass, were done by omp with DeepSeek V4.1 Flash, which changed no code.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
philip-roy-jones added a commit to philip-roy-jones/xcl that referenced this pull request Nov 25, 2026
The RX 580 (AMD Polaris) reports no conservative rasterization tier,
and its driver refuses every pipeline that asks for it with
E_INVALIDARG: the translated pipeline, its stand-in and the dummy
fallback alike. In a retail title run on main (80f4819, with logging
added), all 12 stand-ins with ConservativeRaster on were refused and
all 54,193 without it were made. After the translated pipeline was
refused, graphics_pso handed the title's own description, console
shaders included, to the driver, and AMD's shader compiler ended the
process with 0xc0000409 before the first frame (xcl-dev#303 guards that path
on its own).

XCL now asks D3D12_OPTIONS for the tier and turns conservative
rasterization off in the descriptions it makes (translated, stand-in,
fallback) where the GPU has none. Those draws then cover the pixels
whose centres their triangles cover. On the RX 580 the title ran its
menus for 120 s at 30 fps with default settings, with no pipeline
refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants