Skip to content

d3d12_xs: Xbox device slot 61 is CreateSamplerX, routed to the PC CreateSampler (RT-5 stop 20) - #7115

Closed
mrp1no wants to merge 2 commits into
ProjectLeonida:mainfrom
mrp1no:d3d12-xs-slot61-sampler
Closed

mrp1no wants to merge 2 commits into
ProjectLeonida:mainfrom
mrp1no:d3d12-xs-slot61-sampler

Conversation

@mrp1no

@mrp1no mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: stop 20 of @KkelebekK's RT-5 finding (#6910 (comment)). Claim: #6910 (comment). Finder's go-ahead in #7049.

What and why

The retail title calls Xbox device slot 61 as CreateSamplerX(desc, dest), once per sampler, after its descriptor heaps exist (@KkelebekK's measurement). The proxy's generic thunk forwarded it to the PC slot 61, which is CreateMetaCommand, so no sampler was ever written.

Slot 61 now has its own handler, like 62 and 67:

  • it passes the description's PC D3D12_SAMPLER_DESC prefix and the handle to the PC CreateSampler (slot 22). Under Wine that got the title past this call;
  • whatever follows the prefix in the console description is not known and is not read (marked HYPOTHESIS in the code);
  • a null description is skipped and logged once;
  • the handle is passed as given. A handle in the title's own heap range is the translation in d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles #7021 (@Khuraie).

d3d12_xs_device.h and the §4.9 table in docs/d3d12_vulkan.md get a row for the slot.

Tested

Windows 11, MSVC RelWithDebInfo, main 2c72b0d2:

  • xs_proxy_mock_test: PASS. The new check calls slot 61 and expects the mock's slot 22 with the same two words, never its slot 61; a null description reaches neither. With main's d3d12_xs_device.cpp it fails (line 763).
  • ctest -R xs_proxy: 6/6.
  • python -I tests/test_docs_links.py and tests/test_docs_design_rows.py: OK.
  • Retail executable, own copy, gta6rt --run, 2 runs: the same stop as main, at the first XMemVirtualAlloc. The boot doesn't reach slot 61 on main yet, so this is the synthetic test plus @KkelebekK's Wine run of the same routing.

No game data. AI-assisted (Claude Code).

🤖 Generated with Claude Code

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested on the retail boot: pass. Own 1.0.2.1 copy, Windows 11, RTX 4090 / 617.42, LEONIDA_D3D12=vulkan, on Pipodi:boot-integration (the #6982 stack) with this PR's slot 61 handler in place of the local stand-in I had there.

  • Before this, slot 61 went on to the PC slot 61 (CreateMetaCommand) and ended in an access violation inside gta6rt.
  • With the handler, the title's slot 61 calls arrive as ID3D12Device::CreateSampler on the Vulkan device, and the run continues. It got to 1,661 D3D12 calls, against 1,655 at the old stop.
  • The next stops are later and have nothing to do with slot 61: slot 67 programs with no translation (see docs/retail_boot_chain.md: stops 13-17 (descriptor heap at an address, device slots 70, 127, 25) #6982), then a guest access violation.

I had read slot 61 as a raw view write because it ends in the same descriptor-finishing helper as slot 70. Your sampler reading fits the run better, so I've dropped my stand-in.

AI-assisted (Claude Code).

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Pipodi, that's the retail confirmation this PR was missing (before: an access violation via CreateMetaCommand; now: CreateSampler). The next stop on your stack, slot 41's argument type 105, is #7163. AI-assisted (Claude Code).

@umnitus

umnitus commented Nov 23, 2026

Copy link
Copy Markdown

Independent native Windows check at e22994464b17517624c898ed34b3e03c06ce2261 with clang-cl/xwin. All six xs_proxy_mock CTests passed, including slot 61 CreateSamplerX routing and the null-description case. AI-assisted testing.

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified on Windows 11 (MSVC RelWithDebInfo):

  • Built xs_proxy_mock_test and device_proxy_test cleanly.
  • xs_proxy_mock_test.exe passed: Xbox device slot 61 (CreateSamplerX) correctly forwards the description prefix and handle to PC slot 22 (CreateSampler), ignoring trailing console data and cleanly skipping null descriptions.
  • device_proxy_test.exe passed with 0 failures across all 83 slots.
  • 8/8 CTest targets passed 100% (device_proxy, device_proxy_trace, xs_proxy_mock*).
  • Whitespace clean (git diff HEAD~1..HEAD --check).

@jlric

jlric commented Nov 23, 2026

Copy link
Copy Markdown

Retail A/B on CachyOS / Wine 11.22, RTX 4070 (620.73.04). Before: slot 61 faults in the PC forwarder. With the route from e22994464 using #7021 CPU-handle translation, CreateSampler and the next CopyDescriptorsSimple both return, and startup reaches physical page mapping. AI-assisted testing.

@Stalkerino

Copy link
Copy Markdown

For combining this route with #7021, here is a small cherry-pick with the handler change and a regression test. It applies after both PRs are present. Slot 61 calls the existing CPU descriptor-handle translator before calling the PC device. The mock checks that PC slot 22 receives the host heap start plus the original offset.

I compared the same synthetic guest before and after this change on CachyOS, Wine 11.22 and Mesa lavapipe 26.3.1. With a three-entry sampler heap allocated by the guest hook, two different sampler descriptions both failed the byte-for-byte comparison with PC CreateSampler before the fix. Changing the filter/address mode left the host destination unchanged and modified the guest hook memory. After translating the destination, both descriptions matched their PC references, changing the description updated the host descriptor, and the adjacent descriptor and guest memory guards stayed intact (19/19 checks). The mock also fails on the destination before the change and passes afterwards. AI-assisted.

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Stalkerino, that's the right next step, and the before/after on a guest-allocated sampler heap is convincing. Since it calls #7021's handle translator, I'd keep this PR independent of #7021 so either can land first, and bring your commit in right after both are on main. Feel free to open it as a follow-up PR (Depends on: #7115, #7021), it's your change; if you'd rather not, say so and I'll cherry-pick it with your authorship once both have landed. AI-assisted (Claude Code).

@justr4mzi

Copy link
Copy Markdown
Contributor

Independent native Windows 11 / MSVC 19.44.35230.0 / AMD Radeon RX 6700 XT (gfx1031, Vulkan 1.4.335, driver 2.0.372) verification of e22994464:

  • Build & CTest (standard and LEONIDA_VK_VALIDATION=1):
    • ctest --output-on-failure -R "^(xs_proxy_mock|device_proxy|d3d12_present|d3d12_draw)$": 8/8 passed (2.54 s standard, 1.88 s with LEONIDA_VK_VALIDATION=1, 0 validation errors).
    • xs_proxy_mock_test.exe (all 6 modes, including slot 61 CreateSamplerX routing to PC slot 22 CreateSampler) and device_proxy_test.exe (WARP): PASS (0 failures).
  • Negative control:
    • Reverting runtime/shims/d3d12_xs_device.cpp to parent 66f557b0c while keeping xs_proxy_mock_test.cpp at e22994464 fails at xs_proxy_mock line 763: mock->calls[61] == 0 && mock->calls[22] == 1 && xs::device_slot_hits(61) == 1 (exit 1). Restoring e22994464 passes (exit 0).

AI-assisted (Gemini, Antigravity).

@mrp1no
mrp1no force-pushed the d3d12-xs-slot61-sampler branch from e229944 to 8f756eb Compare November 23, 2026 19:44
@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @nullmarsh, a real regression and a good catch. The earlier runs used only the proxy tests. Fixed in 8f756ebe0 (rebased onto main 867d922f first):

RTX 3060 (610.88): d3d12_vulkan_device_test now stops at line 6574 (tiles == 1), the same as main. It logs slot 61's first call as forwarded to the PC method. ctest -R "^(xs_|device_proxy|loader|run_tiny|d3d12_xs)" passes 26/26.

@jtrudeau1530, @Cresceda, @Zunraz: on a retail stack the title's calls come from its mapped image, so they still get CreateSampler. A re-check that slot 61 still logs Xbox CreateSamplerX there would confirm the classifier sees them. AI-assisted (Claude Code).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

checked: #7115 | with: merge of PR head onto main, then xs_proxy_mock_test (cross-built, run under Wine), plus a negative control | on: Wine 11 on a RunPod RTX 4090 (Linux, Vulkan), cross-built with clang-cl + xwin through the pod's ccache build script; not native Windows, and the host D3D12/WARP comparisons do not run (there is no WARP adapter under Wine). | result: pass

AI-assisted.

@nullmarsh

Copy link
Copy Markdown
Contributor

Re-tested 8f756ebe (on main 867d922f), Windows 11, RX 9060 XT (RDNA4, AMD 26.11.2), MSVC 14.44: fixed. d3d12_vulkan_device stops at line 6574 (tiles == 1) again, the same as main, and slot 61's first call is the host form (a host caller gets PC CreateMetaCommand). Also pass: device_proxy, device_proxy_trace, queue_proxy, xs_proxy_mock (6 variants).

AI-assisted (Claude Code), no game files.

@jtrudeau1530

Copy link
Copy Markdown

@mrp1no Rechecked the caller-classification fix in 8f756eb, answering your retail recheck request. The host regression is fixed here, and the guest sampler route still runs.

Base: our frozen c3m diagnostic stack, plus only the follow-up delta from 2d16047 to 8f756eb; no rebase onto newer main. Same Arch Linux, Wine 11.18, RX 7900 XT / RADV Mesa 26.2.3, clang-cl 23.1.6 + xwin, library and offline sandbox. Existing #7021 handle translation remains in proxy_create_sampler_x. The sole new local test adaptation marks our hook-backed raw slot-61 call as guest and resets the classifier afterward; your no-classifier/guest/host checks remain intact.

Host comparison, same environment/configuration, bounded d3d12_vulkan_device runs:

  • Control: first failing check is CreateMetaCommand(unknown_command, ...) returning E_INVALIDARG and null output, at line 5760; slot 61 was intercepted as CreateSamplerX.
  • With your follow-up: that check no longer fails. The first failing check moves to the later tiles == 1 at line 6571. Both runs still exit 1 overall. We have not classified the remaining tile failure against a local plain-main run.

Guest comparison, one bounded run per checkpoint: slot 61 is followed by traced ID3D12Device::CreateSampler at call 1657, and another CreateSampler at 1660. There is no CreateMetaCommand trace. The full 2,261-call method/outcome sequence matches the control exactly (1,636 ok, 40 void/called, 585 unsupported). Init 0/run 5, same later execute access violation after slot 108; the later fault's cause remains unclassified. This confirms guest routing without claiming the title boots successfully.

Build passes; selected suite 46/51, same five earlier failures. All eight proxy modes pass, including your caller-classification cases. Our guest-marked hook-backed handle test still fails when ONLY translate_cpu_handle is removed, and passes with it restored. This is synthetic translation evidence, separate from whether the retail sampler handle needed translation.

Source/patch/exe/PDB/DLL hashes verified; raw traces stay local. Existing XG E_NOTIMPL fallback and slot-74 S_OK stand-in remain explicit diagnostic limitations.

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

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @jtrudeau1530: host regression fixed and the title's sampler calls still classified as guest on a retail stack. That was the check this change needed. With @nullmarsh's re-run, 8f756ebe0 is confirmed on both sides.

@pvfreis

pvfreis commented Nov 23, 2026

Copy link
Copy Markdown

checked: #71158f756eb | with: xs_proxy_mock_test gta6rt root_sig_test device_proxy_test, ctest -R "xs_proxy|device_proxy" | on: Windows 11 26H2 (26300), MSVC 19.44.35229 (v143) + Ninja, RelWithDebInfo, RTX 3060 617.14 | result: pass, 8/8 (6 xs_proxy_mock variants, device_proxy, device_proxy_trace, including its CreateMetaCommand call)
negative control: a plain source revert doesn't compile against the test's set_console_caller, so at head the slot-61 handler's if (is_console_caller(_ReturnAddress())) was changed to if (false && ...) (old routing: always PC slot 61) | result: xs_proxy_mock fails at xs_proxy_mock_test.cpp:768 (calls[22] stays 0), so the test catches the routing change
note: at this head slot 61 goes to CreateSampler only for calls from the mapped image (is_console_caller), and host callers keep the PC CreateMetaCommand; the description still reads as an unconditional route

AI-assisted (Claude Code).

@7ROBE

7ROBE commented Nov 23, 2026

Copy link
Copy Markdown

checked: #71158f756eb | with: merged onto main@867d922f0 (fast-forward, 5 files, +96/-6), cmake -DLEONIDA_VULKAN_HEADERS_FETCH=ON, ctest -R "^(xs_proxy_mock|device_proxy)", check_no_game_data.py | on: Windows 11, MSVC 19.51.36263.0, AMD Radeon RX 9060 XT (26.11.2) | result: pass (8/8 ctest targets passed; xs_proxy_mock_test PASS with 9 intentional allocation refusals and slot 61 routing to CreateSampler; negative control disabling slot == 61 override in d3d12_xs_device.cpp fails xs_proxy_mock_test at line 779 exit 1; check_no_game_data.py clean)

agent: yes
AI-assisted.

@byPreaZy

Copy link
Copy Markdown

checked: #7115 | with: applied the diff on main 6312c05, built xs_proxy_mock_test (MSVC, Ninja RelWithDebInfo) | on: Windows 11, RX 9060 XT | result: PASS (9 intentional refusals), incl. the new slot-61 cases: host caller reaches PC slot 61, console caller reaches PC CreateSampler slot 22 with the same words, null desc skipped, override on/off

Code read: the _ReturnAddress + mapped_image_base classification is sound (the vtable call site's return address sits inside the mapped game image for the title, outside for host callers), g_console_caller is atomic, slot 61 joins device_slot_overridden, and the host-caller fallback forwards verbatim like any other PC slot. The hypothesis (PC D3D12_SAMPLER_DESC prefix) is clearly labelled and matches stop 20's measurement.

AI-assisted check.

@hammokko

Copy link
Copy Markdown

Integration note from a local stack of #7115 with #7021 and the other boot PRs, on the retail 1.0.2.1 boot. AI-assisted (Claude), checked by building and running.

proxy_create_sampler_x passes dest to the PC CreateSampler as given. Once #7021 is in, that handle lies in the title's own heap range and the other descriptor writes (slots 17-24) translate it, so the sampler lands at the wrong place. With #7021 present it needs

self->real->CreateSampler(desc, translate_cpu_handle(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(dest)}));

(the comment already says the handle is "#7021's translation"; this is just where it has to happen when both land). #7066's slot 70 has the same gap.

With that, the title's slot 61 calls create samplers and the boot goes on to slots 74/86 and the FSR slot-67 programs: 2,262 D3D12 trace events, the remaining stops being outside this PR. Windows 11 26200, RTX 5060 (driver 32.0.16.2124), MSVC 14.44 RelWithDebInfo, LEONIDA_D3D12=vulkan, network blocked.

@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @hammokko. translate_cpu_handle comes with #7021, which isn't in main yet, so this PR can't call it on its own. Whichever of the two merges second needs that one line in proxy_create_sampler_x. If #7021 lands first, I'll rebase this PR and add it.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…SamplerX, routed to the PC CreateSampler (RT-5 stop 20)

Squashed from ItsNotRexed#7115 by mrp1no, head e229944 (security scan PASS).

Conflicts: slot names, device_slot_overridden, the header overview and the mock test's section header take the union with the earlier slots. Reviewers noted the slot-61 destination handle is untranslated once ItsNotRexed#7021 is in; it now goes through ItsNotRexed#7021's translate_cpu_handle, and so does slot 70's destination (ItsNotRexed#7066 left a marked hook point for it).
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…f type 105 is created as DISPATCH (device slot 41, RT-5 stop 19)

Squashed from ItsNotRexed#7163 by mrp1no, head 084c8c6 (security scan PASS).

Conflicts with ItsNotRexed#7115 (slot 61) and the earlier slots: both handlers, routing branches, mock cases, docs rows and test checks kept side by side; device_slot_overridden takes the union.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…t expectations)

ItsNotRexed#7759 carries ItsNotRexed#7201's slot 86/101/108 handlers; its squash added them a second time next to ItsNotRexed#7201's copy (the 101/108 bodies are identical, and ItsNotRexed#7759's slot 86 keeps the PSO stream for slot 55), so ItsNotRexed#7201's copy is removed.

xs_proxy_mock_test: the check_xbox_slots summary line merged for ItsNotRexed#7163 had its \n written as a line break; ItsNotRexed#7235's slot-127 hook check now expects no PC slot 25 call for a listed render target (the console-size port from ItsNotRexed#7240 sizes it, same 33,423,360 B); ItsNotRexed#7821's check_view_heap_cap releases the heaps it makes, since its CreateDescriptorHeap mock case is now ItsNotRexed#7021's, which makes a heap proxy holding the device.

d3d12_vulkan_device_test: the meta-command checks run on the device behind the Xbox proxy, as ItsNotRexed#7125 does for CreateReservedResource2: proxy slot 61 is the title's CreateSamplerX (ItsNotRexed#7115).
@Digit4w

Digit4w commented Nov 23, 2026

Copy link
Copy Markdown

Hardening note from a security read of 8f756ebe (diff only, nothing executed), no malicious code found:

proxy_create_sampler_x passes the title's desc and destination handle straight to the real CreateSampler, so the layer writes a descriptor at a guest-chosen address until the handle translation the comment points to (#7021) is in. Checking that dest falls inside a known CPU descriptor heap before the call would bound it in the meantime. The console-caller check itself (_ReturnAddress() against the images the guest loader mapped, PC CreateMetaCommand for every other caller) looks right.

Findings come from a static, AI-assisted review of this PR's diff (nothing was executed); they were read by the account owner. This comment text is AI-generated.

@SirKingg

Copy link
Copy Markdown
Contributor

Independent temporary Windows/MSVC integration with descriptor-handle translation: 19 focused tests passed, including console-versus-host routing and a title-owned CPU descriptor handle translated before the sampler write. In an offline Windows Sandbox retail run the first slot-61 sampler call was routed, and execution proceeded to a later breakpoint. This is progression evidence only; the console descriptor layout and retail rendering correctness remain unverified.

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.