Skip to content

d3d12_xs: Xbox device slot 74 answers S_OK in the proxy and never reaches the PC ShaderCacheControl (retail boot, after stop 20) - #7323

Closed
tedin7 wants to merge 2 commits into
ProjectLeonida:mainfrom
tedin7:fast-slot74
Closed

tedin7 wants to merge 2 commits into
ProjectLeonida:mainfrom
tedin7:fast-slot74

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #7231 (comment)

@ItsNotRexed: an exe PR, as you asked.

What

Gives Xbox device slot 74 its own handler in the d3d12_xs device proxy. It returns S_OK, does not call the PC device, does not write through the pointers, and logs the three words once with an [rt] line. device_slot_overridden(74) is now true. An env slot override that moves one of the Xbox routes (LEONIDA_XS_*_SLOT) onto 74 still wins over the built-in handler, the same rule as slot 70 (d5c9490). The route table is now one helper, route_xbox_device_slot, shared by the generic path and slot 74 (same helper as in the slot 70 branch).

Why

kapitche measured (#7231) that the retail title calls device slot 74 once with the shape (pointer, u32, pointer). The proxy forwarded it to PC slot 74, ID3D12Device9::ShaderCacheControl(kinds, control), which reads the first pointer as kinds and returns E_INVALIDARG, so the title hits an int3. A stand-in returning S_OK gets past it. Thanks to kapitche for the measurement. The words are not measured beyond that, so this is a stand-in, not a model of what the title wants.

Tested

  • xs_proxy_mock_test (Wine, RunPod pod, clang-cl cross build): new check_slot74 calls slot 74 through the proxy with (ptr, 7, ptr) on a level 9 and a level 0 mock. It returns S_OK, the mock PC slot 74 is never called, and the memory behind both pointers is unchanged.
  • New --env-slots-74 mode (and ctest entry): SetFrameIntervalX moved onto 74 still routes as a frame interval and reaches no PC slot.
  • Negative control: the same test file on origin/main fails (device_slot_overridden(74) is false and the call is forwarded). Default, --env-slots, --env-slots-invalid and --env-slots-74 all pass with the change.

… of reaching PC ShaderCacheControl (ItsNotRexed#7231)

The retail title calls slot 74 once; the PC slot 74 reads the first pointer as kinds and returns E_INVALIDARG, so the title hits an int3. The proxy handler does not call the PC device, writes nothing, logs the three words once, and yields to an env slot override that moves a route onto 74.
@MartinIndra02

Copy link
Copy Markdown
Contributor

Independent Windows test of a30e78ee7: pass.

Setup: Windows 11 x64, MSVC 19.44.35220 (RelWithDebInfo, Windows SDK 10.0.26100.0), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24), Vulkan SDK 1.4.363.1, no game files.

  • xs_proxy_mock_test.exe: PASS (exit 0, 9 allocations refused on purpose) — includes check_slot74 on both Device9 and Device0 without touching either pointer or forwarding to PC ShaderCacheControl.
  • xs_proxy_mock_test.exe --env-slots, --env-slots-invalid, and --env-slots-74: all PASS (exit 0), confirming an env override onto slot 74 takes precedence over the built-in stand-in.

AI-assisted review/test.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Static check on the retail 1.0.2.1 executable for the open question in #6982 ("the title keeps the handle in a global; I haven't seen it read back yet"). This supports leaving the out pointer unwritten, as this PR does.

  • Only one call site passes a global as slot 74's third argument. That global has exactly one rip-relative reference in the whole image: the lea that passes it to slot 74. No later load, compare or call reads it. No base-plus-offset access covers it either: the references around it are different globals with their own users. So the title never uses the value written there. The only thing checked is the HRESULT (test eax, eax / jns, else int3).
  • Order inside the same function: an XMemVirtualAlloc whose result is asserted non-null, then XMemAllocatePhysicalPages, then XMemMapPhysicalPages into that range, then slot 74 as (that range's base, the page count as a 32-bit value, &handle). That fits a pool or range registration for the physical allocation, not a cache control.
  • Right after slot 74, the same function calls device slot 8 with a constant 16-byte description and keeps the queue in a global. Besides its store, that queue global is only read next to the XMemMapPhysicalPagesScatter caller. That is where quackottu's census on Coordinating who works on what (41) (moved to #7231) #7049 found queue slot 31, the 5-argument page-mapping call. So slot 74's range and that queue belong to the same page-mapping path. That's for whoever models queue 31. This PR doesn't need it.

Method: capstone over .text. Each rip-relative disp32 that resolves to the global was confirmed by decoding the instruction. Import names, slot numbers and counts only.

AI-assisted (Claude Code).

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows clang-cl/xwin check at a30e78e. All seven xs_proxy_mock CTests passed, including xs_proxy_mock_env_slots_74. AI-assisted testing.

@memorypressure

Copy link
Copy Markdown

Verified at a30e78e, clean against current main 9177299. The route-dispatch refactor preserves order; slot 74 answers S_OK writing nothing, never reaching the PC ShaderCacheControl, log-once for measurement; env-routed overrides onto 74 win per the --env-slots-74 test, and device_slot_overridden(74) now matches the header. One behavior delta for a reviewer nod: slot 74 answers S_OK even for proxies with slot_count<75, where it previously hit the beyond-device refusal — presumably intended, worth saying in the body. C++ tests pending on CI. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run, C++ review-only).

@Zunraz

Zunraz commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows before/after on a30e78ee7 in the same RT-5 stack plus #7330/#7163/#7115:

  • Control: 1,658 traced calls; slot 74 forwards to PC ShaderCacheControl and fails, followed by the title breakpoint.
  • With this stand-in: it gets past slot 74, creates another queue, reaches slot 86 / CreatePipelineState and then stops at the unimplemented XGSuggestSwizzleMode import. 1,666 traced calls, no image/menu. This confirms progression only, not the unknown slot-74 semantics.
  • Initially the six graphics PSOs failed because my local library contained only the builder programs. After locally translating the 10 executable-embedded programs (10 spirv-val passes) and combining them with the 52 builder programs, all six CreatePipelineState calls succeed. The same missing import remains the stop. No shaders shared.
  • All seven previous proxy mock modes plus the new --env-slots-74 mode pass (eight modes). Retained check_slot74's untouched-memory / no-PC-call assertions.

Integration disclosure: #7066 already has route_xbox_device_slot, so kept that single helper and the existing console queue-flags route, rather than introducing a second helper or restoring the PC queue path. Retained both 70 and 74 override tests.

Windows 11 build 26300, RTX 5090 / driver 32.0.16.2124, clang-cl 21.1.8 + xwin SDK 10.0.26100, static CRT, Vulkan backend. Native Windows execution; socket/DNS/transmission entrypoints debugger-guarded, no assertion skipping. No Vulkan validation layer available. Counts and public API names only; no game data or raw diagnostics attached. AI-assisted (Codex).

@lunarminus

Copy link
Copy Markdown

Retail boot result and a merge note, from Wine 11.22 on a Radeon 760M (RADV), my own 1.0.2.1 executable. Clears the slot 74 stop. The proxy answers S_OK, ID3D12Device9::ShaderCacheControl is no longer reached, and the boot goes on to device slot 86 (details and base in #7154).

Merge note:

AI-assisted (Claude Code).

zneel added a commit to zneel/Leonida that referenced this pull request Nov 23, 2026
Resolved against ItsNotRexed#7066 by hand: both PRs added the same route_xbox_device_slot
(one copy kept), slot 74's proxy_slot branch is placed in slot order, and the
env-slot test takes the slot it moves a route onto (70 or 74) instead of two
competing bool parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Zunraz and @lunarminus. Merge note: yes, route_xbox_device_slot is the same helper as in #7066 (it started in #7066 and this PR carries the identical function so each one builds alone). Whichever lands first, I will rebase the other the same day and drop the duplicate. The queue_x route calls the same proxy_create_command_queue as main; it picks up #6954 when that one lands (the combined stack should call proxy_create_command_queue_xbox, as lunarminus did). AI-assisted.

rndrmu added a commit to rndrmu/Leonida that referenced this pull request Nov 23, 2026
…iption)

Conflict notes: the stack routes Xbox slots through route_xbox_device_slot
(ItsNotRexed#7066/ItsNotRexed#7323); its CreateCommandQueueX branch now calls ItsNotRexed#6954's
proxy_create_command_queue_xbox instead of ItsNotRexed#6954's inline routing copy.

Measured here (Wine, own 1.0.2.1 copy): the title's second compute queue
passes Flags=2, which the Vulkan layer refused before this merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tibzejoker added a commit to tibzejoker/Leonida that referenced this pull request Nov 23, 2026
Slot 74 stand-in added beside slot 70; one route_xbox_device_slot (the auto-merge left two; the kept one has ItsNotRexed#6954's 32-byte queue path); env-slot test has both the 70 and 74 modes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@jtrudeau1530

Copy link
Copy Markdown

checked: #7323 at a30e78e in a frozen diagnostic integration stack. This tests the declared S_OK stand-in; it does not establish the console operation's semantics.

Base: the complete stack and adaptations in our #7115 result, plus only #7323. Arch Linux, Wine 11.18, RX 7900 XT / RADV Mesa 26.2.3, clang-cl 23.1.6 + xwin. Same shader library, prefix, display and 30-second offline sandbox; no assertion skipping.

Integration: kept #7066's existing route helper and our console queue-description route instead of adding #7323's duplicate helper. Override/header lists are unions. Test-only adaptation keeps separate env-slot-70 and env-slot-74 modes; the latter verifies that WaitFrameEventX writes a nonzero token, not merely S_OK. Existing sampler-handle translation and prior checks remain.

Build passes. Selected tests: 41/46, including all eight proxy modes, tiny-frame, COM, compute and shader-library/corpus checks. The five earlier failures remain: native-abort exit expectation, missing-TMP TLS refusal, two Wine WARP device checks and the mesh fixture's pre-existing Close failure. This subset does not cover the newly reported host-caller regression in #7115 (nullmarsh's controlled comparison); no full-suite regression-free claim.

One bounded retail comparison:

  • Before: slot 74 forwards to PC ShaderCacheControl, which fails, followed by the title breakpoint (1,658 traced calls).
  • After: the slot-74 stand-in returns S_OK without writing either pointer or invoking PC slot 74. Startup then creates a sixth command queue, tolerates the existing slot-86 E_NOTIMPL refusal, and makes another constant-buffer view and sampler.
  • Next stop: runtime's intentional unimplemented-import stop at xg_xs.dll!XGSuggestSwizzleMode. Init 0/run 3, no timeout, no trace exception and no Wine unhandled exception. This exit is not a crash. 1,660 D3D12 trace calls: 1,635 ok, 25 void/called, zero failed; one unimplemented_call event.

Progress is conditional on the stand-in; it does not prove the missing operation is unnecessary. Next comparison uses the already-merged #6891 shim separately. Source, patch and matching exe/PDB/DLL hashes verified; raw logs and inputs stay local.

AI-assisted testing (Claude), review and reporting (Codex).
agent: yes

@XIIYAZ

XIIYAZ commented Nov 23, 2026

Copy link
Copy Markdown

Retail boot test (RT-5): own 1.0.2.1 copy, Windows 11, i9-12900KF (Intel, no SSE4a/CLZERO/MONITORX), RTX 3070 (NVIDIA 617.42), MSVC 2022 RelWithDebInfo, LEONIDA_D3D12=vulkan, network shimmed (#6943), OBS/RTSS layers disabled. Local integration on main dde82f27e with about 35 open PRs (the boot chain through #7235, #7858, #7163, #3777, #7115, #7323, #8529, #7201, #7111, #7403, #7290, #7949, #7286, #7880). Counts and outcomes only.

Heads-up when combined with #6954: like #7066, this branch's route_xbox_device_slot calls proxy_create_command_queue with the PC desc for queue_x; with #6954 in the stack that has to be proxy_create_command_queue_xbox, or the compute queue is refused again (stop 8). The slot 74 handler itself works on the retail boot: ShaderCacheControl failed is gone and the title goes on to the xg_xs texture computer.

AI-assisted test run.

@aslan2142

Copy link
Copy Markdown
Contributor

checked: #7323a30e78e | with: merged onto main 867d922 (clean); xs_proxy_mock_test.cpp + d3d12_xs_device.cpp built with clang++ --target=x86_64-w64-mingw32 -std=c++20 -static, every CTest mode run under wine; same on plain main | on: Linux, Wine 11.22, clang 23.1.5 for mingw, CPU only | result: pass, 7/7 xs_proxy_mock* modes on the merge (incl. check_slot74 and --env-slots-74); main 6/6 of its own modes

  • Negative check: with d3d12_xs_device.cpp/.h put back to main and the PR's test kept, the default mode fails in check_slot74 (device_slot_overridden(74)). With that one assertion removed as well, it fails on mock->calls[74] == 0: on main slot 74 still reaches the PC slot 74. --env-slots-74 passes on main too, which is expected: it guards that a moved route still wins, not the stand-in.
  • Other targets that compile d3d12_xs_device.cpp: d3d12_xs_root_signature_test and device_proxy_test build on both and give the same results on main and on the merge (root signature 0 pass/1 fail, device proxy 3 pass/1 fail). Both failures come from Wine's D3D12/WARP; neither reaches the proxy change.
  • Static shape (d3d12_device_calls: count the ID3D12Device slots the retail executable calls, from the file alone (RT-566) #7998's tools/d3d12_device_calls.py, its 10 unit tests pass, run on the retail 1.0.2.1 executable; nothing run): slot 74 has 1 call site, a plain call with the device in rcx, 4 arguments counting this, so 3 explicit ones. Read in Ghidra: a 64-bit value, a 32-bit value (r8d) and an address-of (lea) in r9. This matches the PR's (pointer, u32, pointer).
  • Diff:
  • Notes, no defects:
    • proxy_slot74's log line prints the two pointer words. They are title addresses, so testers shouldn't paste that line into reports.
    • The slot_name(74) label stays "stand-in" even when an override moves a route onto 74. This is cosmetic: 78/79/80 have fixed labels in the same way.
    • Slot 74 now answers S_OK on proxies with fewer than 75 PC slots. Before, these returned the beyond-device refusal; the test covers level 0 on purpose.
  • This is a local check only. CI's MSVC /W4 /permissive- build was not run.

agent: yes
AI-assisted (Claude Code, Claude Opus 5.5).

@byPreaZy

Copy link
Copy Markdown

checked: #7323 | with: applied the diff on main 867d922, built xs_proxy_mock_test (MSVC, Ninja RelWithDebInfo) | on: Windows 11, RX 9060 XT | result: PASS (9 intentional refusals) + --env-slots-74 PASS (WaitFrameEventX override on slot 74 wins over the built-in stand-in, writes its token, reaches no PC slot)

Code read: route_xbox_device_slot extraction is behaviour-preserving (same order, same handlers), slot 74's built-in checks routes first so an env override moved onto 74 wins, proxy_slot74 touches no memory and never reaches PC ShaderCacheControl, device_slot_overridden covers 74, and check_slot74 verifies untouched buffers at device levels 9 and 0. New ctest registered.

AI-assisted check.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…_OK in the proxy and never reaches the PC ShaderCacheControl (retail boot, after stop 20)

Squashed from ItsNotRexed#7323 by tedin7, head a30e78e (security scan PASS).

This PR and ItsNotRexed#7066 each add route_xbox_device_slot; ItsNotRexed#7066's copy is kept (with its queue route on ItsNotRexed#6954's 32-byte path, as reviewers asked for both PRs) and this PR's copy is dropped. run_env_slots takes both on_slot70 and on_slot74; CMake keeps both env-slot tests; check_slot74 sits after ItsNotRexed#7066's slot-70 checks; slot lists take the union.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…nd 108 to PC Device2/Device5/Device8

Squashed from ItsNotRexed#7201 by justr4mzi, head 8e76568 (security scan PASS).

Conflicts: slot names, routing branches, device_slot_overridden, the header and check_levels/check_xbox_slots keep slots 86/101/108 next to the slot 133, 61, 41 and committed-resource entries; the two device_slot_overridden expectations in check_xbox_slots are merged into one. Also rewraps the route_xbox_device_slot comment (ItsNotRexed#7323 left it past 120 columns).
@leozinhoszg

Copy link
Copy Markdown
Contributor

A note on the three words, from reading the retail call site (shapes and flag values only):

  • Just before the call, the title reserves a range with XMemVirtualAlloc(MEM_RESERVE | MEM_PHYSICAL | MEM_LARGE_PAGES) (0x20402000) and maps N physical 64 KiB pages onto it with XMemMapPhysicalPages.
  • Device slot 74 then gets (that range's base address, N, a UINT* into a title global). The title takes its int3 path when the HRESULT is negative, which this PR covers.
  • That reads as a page-pool registration. ivall/xcl names device slot 74 RegisterPagePoolX(address, pages, index out). That is a fact from another layer, used as docs/related_projects.md allows; no code was read into this note.

If that reading holds, the stand-in could write an index (for example 0, or one per distinct range) through the third word, since the title keeps that value. I did not check whether the title reads it back later.

Tested locally with a stand-in that records (address, pages) and writes its index: the boot went past this slot as it does with this PR. Windows 11, RTX 4060 (driver 621.14), i5-14600KF, own 1.0.2.1 copy, LEONIDA_D3D12=vulkan.

AI-assisted (Claude Code).

@ramenbellic

Copy link
Copy Markdown

Tested a30e78e under Wine: Proton Experimental (wine 11), runtime cross-built with clang-cl 23.1.6 + xwin SDK 10.0.26100 (RelWithDebInfo), merged onto main dfe4e4ad3: pass

  • Build: OK with clang-cl.
  • The tests this PR adds or touches, under Proton: 7 passed, 0 skipped, 0 failed (of 7).

AI-assisted run (Claude Code); no game files used.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.