Repository navigation
d3d12_xs: handle slot 25 swapped ABI, slot 127 CreateCommittedResourceX, and __XMemAllocationHooks__ - #8072
d3d12_xs: handle slot 25 swapped ABI, slot 127 CreateCommittedResourceX, and __XMemAllocationHooks__#8072JIFO0 wants to merge 5 commits into
Conversation
|
Slot 127 loses the pointer from the guest allocation hook at 388faa1. Each successful resource creation calls I tested the unchanged helper on Windows 11 with MSVC and a counting allocator. The device reports 65,536 bytes per call. After 32 calls, the allocator still owns 32 blocks (2,097,152 bytes). The expected count for a notification with no retained storage is zero. This test exercises the helper with a synthetic device. It does not exercise a GPU or the retail executable. Please use an accounting operation if this is only a budget notification. If the resource needs the allocation, store the pointer with the resource and call the matching free hook when the resource releases it. Standalone checkSave as #include <atomic>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <vector>
struct D3D12_RESOURCE_DESC {};
struct D3D12_RESOURCE_ALLOCATION_INFO { std::uint64_t SizeInBytes; };
struct ID3D12Device { D3D12_RESOURCE_ALLOCATION_INFO GetResourceAllocationInfo(int,int,const D3D12_RESOURCE_DESC*) {return {65536};} };
std::vector<void*> live;
namespace rt::shims {
struct Hooks { void* (*alloc_fn)(size_t,uint64_t); void (*free_fn)(void*,uint64_t); };
Hooks* find_guest_xmem_hooks() { static Hooks hooks{
[](size_t n,uint64_t){auto p=std::malloc(n); if(!p) std::abort(); live.push_back(p); return p;},
[](void* p,uint64_t){for(auto i=live.begin();i!=live.end();++i) if(*i==p){live.erase(i);break;} std::free(p);} }; return &hooks; }
}
bool first_call(std::atomic<bool>& logged){return !logged.exchange(true);}
void notify_xbox_d3d12_committed_alloc(ID3D12Device* real, const D3D12_RESOURCE_DESC& pc_desc) {
const auto* hooks = rt::shims::find_guest_xmem_hooks();
if (!hooks || !hooks->alloc_fn || !real) return;
const D3D12_RESOURCE_ALLOCATION_INFO info = real->GetResourceAllocationInfo(0, 1, &pc_desc);
if (info.SizeInBytes == 0 || info.SizeInBytes == UINT64_MAX) return;
// Bits 23:16 = 0x80 (eXMemAllocatorId_D3D12), bit 15 = 0x8000 (D3D12 allocation attribute).
constexpr std::uint64_t kD3d12CommittedAttr = 0x00808000ULL;
void* mem = hooks->alloc_fn(static_cast<std::size_t>(info.SizeInBytes), kD3d12CommittedAttr);
static std::atomic<bool> logged{false};
if (first_call(logged)) {
std::fprintf(stderr, "[rt] d3d12_xs: slot 127 D3D12 hook alloc size=0x%llx attr=0x%llx -> %p\n",
static_cast<unsigned long long>(info.SizeInBytes),
static_cast<unsigned long long>(kD3d12CommittedAttr), mem);
}
}
int main(){ID3D12Device dev; for(int i=0;i<32;i++) notify_xbox_d3d12_committed_alloc(&dev,{}); std::printf("live blocks %zu, bytes %zu\n",live.size(),live.size()*65536); for(void* p:live) std::free(p);}
AI-assisted. |
…hims, and D3D12_xs proxy
…eX, and __XMemAllocationHooks__
|
Heads-up: rebasing |
388faa1 to
e710a30
Compare
|
Re-tested 9c9b841 on Windows 11 with the WARP adapter. This fixes the leak I reported for a paired allocation hook and free hook. Slot 127 creates 32 resources. An extra reference keeps the first allocation live. The last release frees it. After all releases, the test counts 32 allocations, 32 frees, and zero live blocks. I built AI-assisted. |
|
Code read of the PR head (four commits; the slot 127 hook-block leak is fixed by 9c9b841, thanks). Remaining points, by function since lines moved:
AI-assisted (Claude Code). |
…slot 25 stride, and hook safety
|
Addressed all review items on
Verification (
|
|
✅ Automated security review: CLEAN (commit
Scope: static analysis of added diff lines only; no code was executed. Please review findings manually. |
|
Independent Windows/NVIDIA synthetic check of current head c6ae7c7 (AI-assisted with Codex). Setup: Windows 11 Pro build 26200, RTX 4060 Ti (10de:2803), NVIDIA driver 610.88 / Windows 32.0.16.1088, MSVC 14.44, CMake/Ninja, RelWithDebInfo, Vulkan enabled. No retail game data or services used. Compared two separate worktrees, both trial-merged cleanly with main 867d922:
Results:
Broader check, recorded separately: d3d12_vulkan_device FAILED on BOTH trees at runtime/test/d3d12_vulkan_device_test.cpp:6574, This supports the current PR's synthetic behavior on this Windows/NVIDIA setup. It does not establish retail boot/playability or validate actual guest export discovery: the hook regression tests use a test override. Reproduction: configure runtime with Ninja, RelWithDebInfo and LEONIDA_REQUIRE_VULKAN=ON; build gta6rt, device_proxy_test, xs_proxy_mock_test, xmem_test, loader_test, winhttp_offline_test, queue_proxy_test, d3d12_vulkan_device_test. Run: |
|
Tested
AI-assisted: yes |
|
Tested c6ae7c7 merged onto main 867d922 (clean merge) on NVIDIA GeForce RTX 4070, driver 621.24, native Windows 11 Pro 26300, MSVC 14.44.35207, Ninja RelWithDebInfo: pass.
No game data used. AI-assisted (Claude Code). |
|
Tested c6ae7c7 on Windows 11 Pro 10.0.26300, MSVC 14.51 (VS Build Tools 2026), Windows SDK 10.0.26100, RTX 4060 / 621.24: does not build on current main. Merged onto main 6312c05 (the textual merge is clean), then a full runtime build: Since c884234 ("xgameruntime: serve XThreadingImpl and XErrorImpl through QueryApiImpl") and 6312c05, main has its own Two notes from reading the diff, for after the rebase:
AI-assisted (Claude Code). No game files. |
LaugeM
left a comment
There was a problem hiding this comment.
Read at c6ae7c776, together with #7503, which it is stacked on.
It does not build on main. This comes from #7503. When I merge the head into upstream main 5d74c2723, runtime/shims/xgameruntime.cpp defines XErrorReport twice (lines 262 and 271) and lists it twice in the table (1347 and 1353). Main got its own copy in 6312c057f. @Kerwinss reported this already; it is still there at this head.
Each part already has an earlier open PR:
- Slot 26 (
d3d12_xs_device.cpp:2378, from #7503) does what #6964 does. - Slot 25 is #7078 plus #7110.
- Slot 127 is #7052.
- The descriptor heap hook is #7021, and the committed-resource lease is #7235 and #7240.
Those are about two hours older, and several are tested on the retail boot. I'd rebase onto them and keep only what they lack.
Slot 25's register order is right; please don't change it. In the swapped branch (2265-2324) the buffer is in RCX, the device in RDX, the mask in R8, the count in R9, the descriptions on the stack, and the buffer comes back in RAX. On #8930 it was suggested that a 16-byte D3D12_RESOURCE_ALLOCATION_INFO comes back in RAX:RDX. That is the System V rule, not Windows x64. A standalone MSVC 14.52 probe puts it in a hidden RCX buffer when it is called as a function, and in a hidden RDX buffer when it is called as a method.
The lease uses the PC size. notify_xbox_d3d12_committed_alloc (2046, called at 2131) leases GetResourceAllocationInfo's PC answer through the title's hook, and slot 25 forwards the PC size too. #6982's stop 17 is the title's budget check on exactly that lease. On #7240 it was measured that the PC answer misses it in both directions: smaller than the console's tiles on NVIDIA, and 513 instead of 510 tiles for a 3840 x 2160 RGBA8 target on AMD's Windows driver, which overran the title's range. #7235 has the same problem. #7240 leases the console tile size (d3d12_xs_alloc_size.h) and is the one reported to clear stop 17 on both vendors. I expect this PR to stop at stop 17 on AMD (plausible, not run).
The attribute word is right, but the comment is not. 0x00808000 (2063) is (0x80 << 16) | (2 << 14): allocator 0x80 and XALLOC page-size field 2 in bits 14..15, the same value as #7235's and #7240's kXmemCommittedResourceAttributes, which is what the title's measured matcher reads. The comment at 2062 calls bit 15 a "D3D12 allocation attribute". Please name it the page-size field and build it the same way, so the value has a source.
A second way to find the hook export. shims.h:128 walks the guest export table, and shims.h:5 now pulls <windows.h> into every file that includes shims.h. #7021 registers the same export once from Loader::load_one. Two lookups for one export will drift apart; keep one.
Slot 127 drops what the console call carries. #6982 §3.7 measured that slot 127 has CreateCommittedResource3's argument list. This PR maps it to the legacy CreateCommittedResource (2129). That ignores the castable formats and the protected session, and it forces the heap flags to NONE, which also drops PC flags such as ALLOW_DISPLAY. #7052 forwards to CreateCommittedResource3 and keeps them.
The heap code from #7503 returns the title's address from heap slot 10 as well as slot 9 (543, 557), and slots 17 to 24 don't translate CPU handles. Views go into the title's memory, the real heap stays empty, and the GPU handle the title then passes to the command list is not one the layer can resolve (plausible). #7021 keeps the real GPU start on slot 10 and translates the CPU handles.
AI-assisted review (Opus 5.5). Read the diff against main; not built. I merged the head into upstream main with git merge-tree and read the result, and compiled a standalone MSVC 14.52 ABI probe.
Depends on: #7503
What and why
Extends the Xbox D3D12_xs device proxy and xmem shim to unblock resource allocation queries, committed resource creation, and title D3D12 memory-budget hooks past #7503:
Device slot 25 (GetResourceAllocationInfo) (
untime/shims/d3d12_xs_device.cpp):
Device slot 127 (CreateCommittedResourceX) & shared resource sanitization (
untime/shims/d3d12_xs_device.cpp):
XMemAllocationHooks dispatch & D3D12 budget hook notification (
untime/shims/shims.h,
untime/shims/xmem.cpp,
untime/shims/d3d12_xs_device.cpp):
Unit tests (
untime/test/device_proxy_test.cpp):
Tested