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 3 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
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