Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ The trace will enumerate them.

| D3D12 / Xbox object | Vulkan / layer object | Notes |
|---|---|---|
| `ID3D12Device` … `ID3D12Device11` | one `Device` object with the public chain plus measured Xbox overrides | The shipped BVH builder names Device11; slots 1/15/18/19/27/38 matched desktop in prior art, slot 62 is called as `CreateComputePipelineState`, slot 76 is Xbox texture creation, and heap slots 9/10 return in RAX. Unknown Xbox IIDs/slots are logged and refused. |
| `ID3D12Device` … `ID3D12Device11` | one `Device` object with the public chain plus measured Xbox overrides | The shipped BVH builder names Device11; slots 1/15/18/19/27/38 matched desktop in prior art, slot 48 is called as `(desc, riid, out)` with `IID_ID3D12CommandQueue` (PC slot 48 is `OpenExistingHeapFromAddress`; the 32-byte desc is a PC `D3D12_COMMAND_QUEUE_DESC` plus four Xbox words, logged once, and the proxy takes the slot 8 path with the PC prefix and only `DISABLE_GPU_TIMEOUT` kept), slot 62 is called as `CreateComputePipelineState`, slot 76 is Xbox texture creation, and heap slots 9/10 return in RAX. Unknown Xbox IIDs/slots are logged and refused. |
| `ID3D12CommandQueue` | one leased `VkQueue` per live queue: direct queues on the graphics family, compute queues on an async-compute family and copy queues on a transfer-only (DMA) family when the GPU has them (`src/queue_families.h`), else graphics-family leases | Distinct Vulkan queues allow cross-queue waits and signals to make progress. With more than one family in use, buffers, images, the arena and staging are created `VK_SHARING_MODE_CONCURRENT` over those families, so no ownership transfers are needed. Barriers on copy and compute queues are narrowed to the stages their family has; render-target and depth clears are refused there (as in D3D12), and the D24/RGB96 copy conversions and bindless flushes stay off a transfer-only queue. Tested by `vk_queue_test`. `PresentX`, `SuspendX`, `ResumeX` are Xbox queue methods, not in the public vtable; public GDKX samples present only through them (§4.5). Call shapes known, slots **Open**. |
| `ID3D12CommandAllocator` | IR arena + `VkCommandPool` | Reset only when the previous submission's fence is complete. |
| `ID3D12GraphicsCommandList` … `8` | `CommandList` with IR | Replay at `ExecuteCommandLists`; bundles inlined. Supports render passes, mesh dispatch, enhanced barriers; records the GCL8 front/back stencil references (applied only once a pipeline path consumes them). `Draw` views are inlined and moved into the command stream (D3D-289), eliminating per-draw heap allocations. |
Expand Down Expand Up @@ -2259,6 +2259,12 @@ The trace will enumerate them.
unknown types and node masks above 1 get an all-zero answer, logged. The test compares `DEFAULT`, `UPLOAD` and
`READBACK` byte for byte with the host runtime's answer when the host adapter has the layer's architecture (RTX
4090: identical); `d3d12_heap_properties` compares the `L1` heaps with the layer's own adapter.
The retail executable calls it (device slot 26) with the buffer for the returned struct in RCX and the device in
RDX, node mask in R8 and heap type in R9: three calls right after device creation, node mask 1 and types 1, 2
and 3 (measured under `gta6rt --run` with a register probe in the slot's thunk). A PC C++ method has the device
in RCX and the buffer in RDX, so the Xbox-ABI proxy takes the console form when RDX holds the proxy
(`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slots 25 and 43 return structs too; the
executable has not been seen calling them yet, so the proxy still forwards them in the PC form.
- Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in
`d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until
`vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident.
Expand Down
82 changes: 75 additions & 7 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
// the same index through a 15-argument integer prototype. Every PC D3D12 device method takes integer/pointer
// arguments only, so the x64 registers and stack words line up exactly; methods that return a struct keep their
// hidden return pointer in RDX, which is passed through as the first argument unchanged. The measured exceptions
// are IUnknown (0-2), slot 14 (which wraps the heap), 62 and 76, plus the heap proxy's 9/10 conversion from the
// PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap
// are IUnknown (0-2), slot 14 (which wraps the heap), 26 (the title passes the return buffer in RCX and the device in
// RDX), 48 (a queue creation, where the PC has OpenExistingHeapFromAddress), 62 and 76, plus the heap proxy's 9/10
// conversion from the PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap
// what they create in queue and fence proxies built the same way, and slots 31/34/35/45/46/50 hand the real objects
// behind heap, queue and fence proxies to the real device (see the command queue and fence section).
//
Expand Down Expand Up @@ -134,6 +135,7 @@ const char* slot_name(unsigned slot) {
case 14: return "CreateDescriptorHeap";
case 16: return "CreateRootSignature";
case 25: return "GetResourceAllocationInfo";
case 26: return "GetCustomHeapProperties";
case 27: return "CreateCommittedResource (PC slot 27)";
case 31: return "CreateSharedHandle (proxies unwrapped)";
case 32: return "OpenSharedHandle (a fence comes back wrapped)";
Expand All @@ -147,6 +149,7 @@ const char* slot_name(unsigned slot) {
case 50: return "EnqueueMakeResident (proxies unwrapped)";
case 62: return "Xbox CreateComputePipelineState";
case 67: return "Xbox DeserializeComputePipelineStateX";
case 70: return "Xbox shader-resource view from raw words";
case 73: return "Xbox CreateCommandListX -> PC CreateCommandList";
case 75: return "CreateCommandQueue1 -> queue proxy";
case 76: return "Xbox resource creation";
Expand Down Expand Up @@ -1444,6 +1447,45 @@ HRESULT proxy_create_command_list_x(DeviceProxy* self, std::uint64_t desc_word,
return wrap_list(static_cast<IUnknown*>(created), self, riid, out);
}

// Device slot 48, measured on the retail title: (desc, riid, out) with riid = IID_ID3D12CommandQueue. On the PC the
// slot is OpenExistingHeapFromAddress, so forwarding it by number fails. desc is a PC D3D12_COMMAND_QUEUE_DESC
// (16 bytes) followed by four more 32-bit Xbox words of unknown meaning, logged once. Only the PC prefix is used and
// only the flag the PC knows is kept; the rest is the slot 8 path.
HRESULT proxy_create_command_queue_xbox(DeviceProxy* self, const std::uint32_t* desc, const IID* riid, void** out) {
if (out) *out = nullptr;
if (!desc) return E_INVALIDARG;
static_assert(sizeof(D3D12_COMMAND_QUEUE_DESC) == 16, "the PC prefix of the Xbox description is 16 bytes");
D3D12_COMMAND_QUEUE_DESC pc{};
std::memcpy(&pc, desc, sizeof(pc));
pc.Flags &= D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT;
static std::atomic<bool> logged{false};
if (!logged.exchange(true, std::memory_order_relaxed))
std::fprintf(stderr,
"[rt] d3d12_xs: slot 48 queue: flags=0x%x extra words=0x%x 0x%x 0x%x 0x%x\n",
static_cast<unsigned>(desc[2]), desc[4], desc[5], desc[6], desc[7]);
return proxy_create_command_queue(self, &pc, riid, out);
}

// Xbox device slot 70: (texture_words, view_desc, destination), no return value. The retail executable's SRV writer
// makes a view from raw descriptions and a GPU address with no resource object (docs/retail_boot_chain.md, stop 14,
// measured by call shape only). The PC slot 70 is ID3D12Device8::CreatePlacedResource1, which would take the
// destination handle for a resource description and write through it. The layout of the raw words is not measured,
// so nothing reads them: the destination gets the PC's null shader-resource view, which a shader reads as zeros, and
// the call returns. A view that reaches the GPU address needs that layout.
void proxy_create_srv_from_raw_x(DeviceProxy* self, std::uint64_t texture_words, std::uint64_t view_desc,
std::uint64_t destination) {
note_slot(70);
log_xbox_route_once(70, "CreateShaderResourceView from raw words (null view)", texture_words, view_desc,
destination, 0, 0);
if (!destination) return;
D3D12_SHADER_RESOURCE_VIEW_DESC null_view{};
null_view.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
null_view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
null_view.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
null_view.Texture2D.MipLevels = 1;
self->real->CreateShaderResourceView(nullptr, &null_view, D3D12_CPU_DESCRIPTOR_HANDLE{destination});
}

// Device slot 75: ID3D12Device9::CreateCommandQueue1(desc, creator_id, riid, out), called by slot index.
HRESULT proxy_create_command_queue1(DeviceProxy* self, std::uint64_t desc, std::uint64_t creator_id,
const IID* riid, void** out) {
Expand Down Expand Up @@ -1817,6 +1859,21 @@ HRESULT proxy_create_placed_resource_x(DeviceProxy* self, void* va, const D3D12_
return handler(self->real, va, pc_desc, state, *riid, out);
}

// Device slot 26, GetCustomHeapProperties, as the retail executable calls it. Measured on 1.0.2.1 under
// gta6rt --run with a register probe in this slot's thunk: three calls right after device creation, each with the
// device proxy in RDX and not in RCX, R8 = 1 and R9 = 1, 2, 3 (node mask 1; DEFAULT, UPLOAD, READBACK). So the
// buffer for the returned D3D12_HEAP_PROPERTIES is in RCX and the device in RDX. That is how x64 passes them to a
// plain function that takes the device as its first argument and returns a struct; a PC C++ method has the device
// in RCX and the buffer in RDX. The forwarder took RCX for the proxy, read the PC vtable out of the title's stack
// buffer and faulted. The buffer's address goes back in RAX, as that convention returns it; what the title does with
// RAX is not measured.
D3D12_HEAP_PROPERTIES* proxy_get_custom_heap_properties(D3D12_HEAP_PROPERTIES* out, DeviceProxy* self,
UINT node_mask, D3D12_HEAP_TYPE heap_type) {
note_slot(26);
*out = self->real->GetCustomHeapProperties(node_mask, heap_type);
return out;
}

template <unsigned Slot>
std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64_t a2, std::uint64_t a3,
std::uint64_t a4, std::uint64_t a5, std::uint64_t a6, std::uint64_t a7,
Expand Down Expand Up @@ -1875,6 +1932,9 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
reinterpret_cast<const D3D12_RESOURCE_DESC*>(a2),
static_cast<std::uint32_t>(a3), reinterpret_cast<const IID*>(a5),
reinterpret_cast<void**>(a6)));
} else if constexpr (Slot == 70) {
proxy_create_srv_from_raw_x(self, a1, a2, a3);
return 0;
} else if constexpr (Slot == 76) {
return hr_to_u64(proxy_create_resource(
self, reinterpret_cast<const D3D12_HEAP_PROPERTIES*>(a1),
Expand All @@ -1884,6 +1944,14 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
reinterpret_cast<const D3D12_CLEAR_VALUE*>(a5), reinterpret_cast<const IID*>(a6),
reinterpret_cast<void**>(a7)));
} else {
if constexpr (Slot == 26) {
// The console form has the device in RDX. A PC C++ caller has the proxy in RCX and its return buffer in
// RDX; that call goes to the forwarder below, as before.
if (is_device_proxy(reinterpret_cast<const void*>(a1)))
return reinterpret_cast<std::uint64_t>(proxy_get_custom_heap_properties(
reinterpret_cast<D3D12_HEAP_PROPERTIES*>(self), reinterpret_cast<DeviceProxy*>(a1),
static_cast<UINT>(a2), static_cast<D3D12_HEAP_TYPE>(static_cast<std::uint32_t>(a3))));
}
note_slot(Slot);
// Xbox device slots, before the PC vtable is indexed: the public HLE's 78/79/80 would otherwise reach
// CreateReservedResource2/CreateSampler2 or fall past an 80-slot table, and 48/73 would reach unrelated PC
Expand All @@ -1903,9 +1971,9 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
}
if (Slot == routes.queue_x) {
log_xbox_route_once(Slot, "CreateCommandQueueX", a1, a2, a3, a4, a5);
return hr_to_u64(proxy_create_command_queue(self, reinterpret_cast<const D3D12_COMMAND_QUEUE_DESC*>(a1),
reinterpret_cast<const IID*>(a2),
reinterpret_cast<void**>(a3)));
return hr_to_u64(proxy_create_command_queue_xbox(self, reinterpret_cast<const std::uint32_t*>(a1),
reinterpret_cast<const IID*>(a2),
reinterpret_cast<void**>(a3)));
}
if (Slot == routes.list_x) {
log_xbox_route_once(Slot, "CreateCommandListX", a1, a2, a3, a4, a5);
Expand Down Expand Up @@ -2070,9 +2138,9 @@ ID3D12Device* device_proxy_real_device(const void* device) {
}

bool device_slot_overridden(unsigned slot) {
if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 ||
if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || slot == 35 ||
slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 ||
slot == 75 || slot == 76 || slot == 133)
slot == 70 || slot == 75 || slot == 76 || slot == 133)
return true;
const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes();
return slot == routes.frame_interval || slot == routes.schedule_event || slot == routes.wait_event ||
Expand Down
14 changes: 12 additions & 2 deletions runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
// Xbox-ABI proxy around a PC ID3D12Device.
//
// Measured Xbox device deviations used here (vtable indices, x64):
// slot 26 GetCustomHeapProperties, the PC slot, but the retail executable calls it with the buffer for the
// returned struct in RCX and the device in RDX (node mask in R8, heap type in R9). A PC C++ method has
// the device in RCX and the buffer in RDX. The thunk takes the console form when RDX holds a device
// proxy, and forwards the PC form otherwise. Slots 25 and 43 return structs too; no call of them by
// the executable has been seen yet, so they are forwarded in the PC form.
// slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown)
// before the IID. The PC slot 62 is CreateStateObject.
// slot 67 CreateComputePipelineState from native code (desc, iid, out): converts the Xbox native-code desc
// (+0x00 root signature, +0x28 code, +0x30 size) to D3D12_COMPUTE_PIPELINE_STATE_DESC and forwards
// to PC CreateComputePipelineState (slot 11). The PC slot 67 is CreateProtectedResourceSession1.
// slot 70 (texture words, view desc, destination handle), no return value: a shader-resource view from raw words
// and a GPU address, with no resource (retail boot chain stop 14). The PC slot 70 is CreatePlacedResource1.
// The words are not measured, so the destination gets the PC null view (PC CreateShaderResourceView
// with no resource) and the call returns.
// slot 76 resource creation -> PC CreateCommittedResource (PC slot 27), with the Xbox layout word ignored.
// slot 48 CreateCommandQueueX(desc, riid, out) -> the same queue proxy as slot 8. The Xbox desc's first fields are
// D3D12_COMMAND_QUEUE_DESC's (public HLE).
Expand Down Expand Up @@ -118,8 +127,9 @@ using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12
void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler);

// True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue
// proxies), 9 (allocator proxies), 14, 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 48/73 and
// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67 and 76. Slot 10 is intentionally false: the
// proxies), 9 (allocator proxies), 14, 26 (the console's struct-return form),
// 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 48/73 and
// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67, 70 and 76. Slot 10 is intentionally false: the
// measured 9/10 handle conversion is on the heap proxy, and device slot 9 is CreateCommandAllocator, which the proxy
// handles for the allocator proxy.
bool device_slot_overridden(unsigned slot);
Expand Down
Loading
Loading