Skip to content

feat(d3d12): report console descriptor heap address on Xbox slot 14 - #9576

Closed
Thomas73737 wants to merge 1 commit into
ProjectLeonida:mainfrom
Thomas73737:feat/d3d12-console-descriptor-heap-address
Closed

Thomas73737 wants to merge 1 commit into
ProjectLeonida:mainfrom
Thomas73737:feat/d3d12-console-descriptor-heap-address

Conversation

@Thomas73737

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-313-slot14-console-descriptor-heap-abi (#9522 (comment))

Depends on:

What and why

Retail boot finding in #313 comment 7107265058 reports Xbox device slot 14 CreateDescriptorHeap passing a PC D3D12_DESCRIPTOR_HEAP_DESC followed by address at +0x10 and size at +0x18, and the title asserts GetCPUDescriptorHandleForHeapStart() == address for a shader-visible CBV/SRV/UAV heap.

This PR adds a narrow ABI shim for that observed case:

  • runtime/shims/d3d12_xs_device.cpp: slot 14 probes the extended words only when the PC desc looks valid and the 16-byte tail is readable (VirtualQuery); it only takes the console-extended path when address != 0, then creates the heap through an explicit Leonida helper. Normal 16-byte PC CreateDescriptorHeap calls remain unchanged.
  • runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp: add rt::d3d12::create_console_descriptor_heap(...); DescriptorHeap can report the requested console VA as CPU/GPU start for explicit console-addressed heaps and logs once that §3.3/title-memory aliasing backing is not implemented.
  • runtime/test/d3d12_console_descriptor_heap_test.cpp, runtime/CMakeLists.txt: synthetic test covering the helper and Xbox proxy slot 14 contract; no title-memory aliasing/§3.3 backing coverage.

Not included / not claimed: full §3.3 single-address-space/title-memory aliasing, backing descriptor heap memory with imported title memory, or boot/story/playable completeness.

Tested

  • Not built/run in this Linux environment (Leonida runtime tests target Windows/Vulkan). Added synthetic d3d12_console_descriptor_heap test (SKIP_RETURN_CODE 77) covering explicit console-heap helper and XS proxy slot 14 GetCPU/GPUDescriptorHandleForHeapStart() == address.
  • git diff --check clean.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

Handle the console-extended CreateDescriptorHeap layout observed in ItsNotRexed#313 by reading address/size only on the Xbox slot 14 proxy path after a readable-range check, and report that console VA as the heap CPU/GPU start via an explicit Leonida helper. Normal 16-byte PC CreateDescriptorHeap calls remain unchanged. Title-memory aliasing / section 3.3 backing is still unresolved.
@VibeClauding

Copy link
Copy Markdown

Overlap to settle before review: #7021 clears the same assert (Stop 13: GetCPUDescriptorHandleForHeapStart must equal the title's address) through a different route. It honours the title's __XMemAllocationHooks__, which hand the heap the title's pre-allocated VA, and it translates CPU handles in that range. #7021 is in the boot-path merge order in #8851, the maintainers' integration branch (git.notrexed.dev/enx/leonida) carries it, and #9586 (title-backed descriptor write-back, opened today) builds on it.

The two readings may well both be true at once: the title passes the address in the extended description words (sneylol's measurement, which this PR cites) and also gets it from its XMem hook. But the PRs handle slot 14 differently:

With both merged it's unclear which path owns slot 14, and whether #7021's handle translation still sees heaps created here. Measured: git merge-tree of this head onto forge main (2ac385837, which has #7021) gives a content conflict in runtime/shims/d3d12_xs_device.cpp.

A suggestion: rebase onto #7021 and keep only what it lacks, e.g. reading address/size from the extended words as a cross-check against the hook's VA, or covering a heap created without the hook. Or post the description-words measurement on #7021 so one PR owns slot 14.

AI-assisted (Claude Code). Code read and merge check only; nothing run.

@MatyEjsr

Copy link
Copy Markdown

Tested 3630610ca85ad6fff19727bd3fdeb9f06b84d629 on Windows x64, MSVC 14.44.35207 (VS 2022 Build Tools), CMake/Ninja (--parallel 8), Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 3090 (driver 617.42): fail (does not compile); AI-assisted review and build check.

What ran

  • python -I scripts/check_no_game_data.py on all 5 changed files: pass.
  • git diff --check origin/main...HEAD: clean.
  • cmake -S runtime -B runtime/build + cmake --build runtime/build --config RelWithDebInfo --parallel 8 --target gta6rt_d3d12_com d3d12_console_descriptor_heap_test device_proxy_test xs_proxy_mock_test gta6rt: failed during compilation (no runtime/GPU tests could execute).

Compile and link blockers

  1. runtime/shims/d3d12_xs_device.cpp:1380 — missing declaration and broken dependency boundary

    • d3d12_xs_device.cpp calls rt::d3d12::create_console_descriptor_heap(...) without including d3d12_com.h:
      • C3083: 'd3d12': the symbol to the left of a '::' must be a type
      • C2039: 'create_console_descriptor_heap': is not a member of 'rt'
      • C3861: 'create_console_descriptor_heap': identifier not found
    • Including d3d12_com.h directly from d3d12_xs_device.cpp will also break the 8 non-Vulkan targets that compile shims/d3d12_xs_device.cpp without Vulkan::Headers or gta6rt_d3d12_com (root_sig_test, device_proxy_test, xs_proxy_mock_test, pe_loader_test, test_pe_loader_bounds, fsr_dispatch_test, bvh_builder_test, d3d12_xs_root_signature_test, plus non-Vulkan builds of gta6rt). A registered callback/provider on the proxy (similar to set_device_adapter_provider in runtime/shims/d3d12_xs_device.h:74-76) avoids coupling d3d12_xs_device.cpp to d3d12_vulkan_device.cpp.
  2. runtime/shims/d3d12_vulkan_device.cpp:9494-9495 — const mismatch and private member access

    • Line 9494: d->state() returns const DeviceState& (runtime/shims/d3d12_vulkan_device.cpp:5259), while DescriptorHeap::DescriptorHeap takes non-const DeviceState& (C2665: cannot convert argument 1 from 'const DeviceState' to 'DeviceState &').
    • Line 9495: Device::identity() is private (runtime/shims/d3d12_vulkan_device.cpp:7766), causing C2248: cannot access private member declared in class 'Device'. Delegating to a member function on Device (or using d->holder() at line 5260 plus a mutable accessor) resolves both.
    • Minor: struct ConsoleDescriptorHeapDesc at runtime/shims/d3d12_vulkan_device.cpp:1645-1649 is unused.
  3. runtime/test/d3d12_console_descriptor_heap_test.cpp — fails to compile

    • Lines 45, 51, 57, 87, 93, 114: local Ref<T> (lines 16-28) has get()/put() but no operator->, failing with C2819 / C2039 on every heap->... and proxy->....
    • Line 68: rt::d3d12_xs::create_device_proxy(real_device, IID_PPV_ARGS(&proxy_raw)) passes void** into IID_PPV_ARGS, which expands to __uuidof(**(&proxy_raw)) (C2100: you cannot dereference an operand of type 'void', C2660: function does not take 2 arguments; create_device_proxy takes (ID3D12Device*, REFIID, void**)).

Runtime and safety bugs found in review

  1. Out-of-bounds read and false positives on normal 16-byte PC descriptors (runtime/shims/d3d12_xs_device.cpp:1367-1384)

    • proxy_create_descriptor_heap probes 16 bytes past sizeof(D3D12_DESCRIPTOR_HEAP_DESC) using VirtualQuery and treats any non-zero qword at +0x10 as a console descriptor heap address.
    • A normal 16-byte D3D12_DESCRIPTOR_HEAP_DESC on the stack or heap almost always sits inside committed readable memory, so readable_range(tail, 16) returns true and reads 16 bytes out of bounds from adjacent stack/heap locals (UB). Whenever the adjacent 8 bytes are non-zero:
      • On non-Vulkan devices (WARP in device_proxy_test, mocks in xs_proxy_mock_test, native D3D12), create_console_descriptor_heap fails Device::from<Device>(real) and returns E_INVALIDARG instead of falling back to self->real->CreateDescriptorHeap.
      • On the Vulkan device, the heap is created with cpu_ set to an unrelated stack/heap value rather than an allocated heap; any subsequent Create*View (for example CreateConstantBufferView at runtime/shims/d3d12_vulkan_device.cpp:6127, which memsets destination.ptr) will corrupt memory or access-violate.
    • check_normal_heap_unchanged in runtime/test/d3d12_console_descriptor_heap_test.cpp:104-120 calls device->CreateDescriptorHeap directly rather than through proxy, so it does not exercise slot 14 with a normal 16-byte descriptor.
  2. readable_range masks off PAGE_GUARD (runtime/shims/d3d12_xs_device.cpp:1344-1345)

    • PAGE_GUARD is 0x100, so const DWORD protect = mbi.Protect & 0xffu; can never match PAGE_GUARD. Guard pages pass the check and fault on memcpy; check (mbi.Protect & PAGE_GUARD) != 0 before masking.
  3. Wrong calling convention on the heap proxy in check_xs_proxy_slot14 (runtime/test/d3d12_console_descriptor_heap_test.cpp:93)

    • proxy->CreateDescriptorHeap wraps the heap in HeapProxy, whose slot 9 uses the Xbox convention (returns the 64-bit handle in RAX and ignores RDX, runtime/shims/d3d12_xs_device.cpp:562-563). Invoking GetCPUDescriptorHandleForHeapStart() through the PC ID3D12DescriptorHeap* vtable passes a hidden return pointer in RDX and reads back an uninitialized stack slot instead of RAX (see runtime/test/device_proxy_test.cpp:247-254 for how tests call heap proxy slots 9/10).
  4. Unbacked fake VA in DescriptorHeap::cpu_ and overlap with d3d12_xs: honour __XMemAllocationHooks__ for descriptor heaps and translate CPU handles #7021 / D3D12 → Vulkan layer: critical path, who builds what, open methods #313

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.

4 participants