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
1 change: 1 addition & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3577,6 +3577,7 @@ to be recovered from call sites (or the NDA GDK headers, if a developer has acce
| Device slots 48/73/78/79/80 | Public HLE `Freminet`/`ScarlettX` (third-party, not Microsoft documentation) | `d3d12_xs_device.cpp` routes `CreateCommandQueueX` (48), `CreateCommandListX` (73), `SetFrameIntervalX` (78), `ScheduleFrameEventX` (79) and `WaitFrameEventX` (80) before it indexes the PC vtable. Queue and list creation use the existing create paths. The frame-event calls are a per-device token counter: `WaitFrameEventX` returns at once with a fresh non-zero token, because there is no vblank source before a presenter exists. The five indices can be moved with `LEONIDA_XS_QUEUE_X_SLOT`, `LEONIDA_XS_LIST_X_SLOT`, `LEONIDA_XS_FRAME_INTERVAL_SLOT`, `LEONIDA_XS_SCHEDULE_EVENT_SLOT` and `LEONIDA_XS_WAIT_EVENT_SLOT` (3..127; a value that names a slot the proxy already handles keeps that slot's handler); a trace that disagrees wins. |
| Indirect argument type 105 | The retail title's startup creates five one-argument command signatures (device slot 41) with no root signature; one has type 105 and a 12-byte stride. Its two `ExecuteIndirect` sites, read statically, set the compute state first, as the `DISPATCH` sites do, and pass one command from the same argument buffer, on a second command list | `d3d12_xs_device.cpp` creates it as `DISPATCH` (`D3D12_DISPATCH_ARGUMENTS`). What the console does differently for it is **Open**. |
| Device slot 61 | The retail title's boot under `gta6rt --run` (stop 20 of the RT-5 measurements in #6910): called as `(desc, dest handle)` once per sampler | `d3d12_xs_device.cpp` routes it to the PC `CreateSampler` (slot 22) with the description's PC `D3D12_SAMPLER_DESC` prefix, for a caller in an image the guest loader mapped; the PC slot 61 is `CreateMetaCommand`, which any other caller (a host test driving the device through the proxy) still gets. The layout of the description beyond the PC fields is **Open**. |
| Device slot 74 | The retail title's boot under `gta6rt --run`: called as `(pointer, u32, pointer)` | **Stand-in.** `d3d12_xs_device.cpp` answers `S_OK` and does nothing, for a caller in an image the guest loader mapped; the PC slot 74 is `ShaderCacheControl`, which the call does not fit and which any other caller still gets. What the console method is, and what it should do, is **Open**. |
| Device slot 81, queue `PresentX`/`SuspendX`/`ResumeX` | XCL (GPL-2.0-only, third-party): `GetFrameStatisticsX` at device slot 81, `PresentX` at queue slot 30 (older runtime layout) or 32 (newer); `SuspendX`/`ResumeX` slots unmeasured | `set_presentation_handler` forwards 78-81 and the queue routes to a presenter (`attach_xbox_presentation`; `gta6rt` creates no `XboxPresentation` yet). Without one, slot 81 answers `S_FALSE` with a zero count (no statistics yet) and the queue slots stay refused. Moved with `LEONIDA_XS_FRAME_STATISTICS_SLOT` (3..127) and `LEONIDA_XS_PRESENT_X_SLOT` (default 30); `SuspendX` and `ResumeX` are routed only when `LEONIDA_XS_SUSPEND_X_SLOT` / `LEONIDA_XS_RESUME_X_SLOT` are set (queue slots 19..127; two routes on one slot are refused with a log). |
| VRS | Public `D3D12_SHADING_RATE` / `D3D12_AXIS_SHADING_RATE` | `VK_KHR_fragment_shading_rate`; `RSSetShadingRate`/image-based rate map to `vkCmdSetFragmentShadingRateKHR`. |
| Mesh shader tier | Public `D3D12_MESH_SHADER_TIER` | `VK_EXT_mesh_shader`; the 9,282 translated mesh shaders make this a hard requirement for any content that uses them. |
Expand Down
1 change: 1 addition & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ if(BUILD_TESTING)
# The routes are read once per process, so each override case is its own test.
add_test(NAME xs_proxy_mock_env_slots COMMAND xs_proxy_mock_test --env-slots)
add_test(NAME xs_proxy_mock_env_slots_invalid COMMAND xs_proxy_mock_test --env-slots-invalid)
add_test(NAME xs_proxy_mock_env_slots_74 COMMAND xs_proxy_mock_test --env-slots-74)
endif()
if(TARGET root_sig_test)
add_test(NAME root_sig COMMAND root_sig_test)
Expand Down
120 changes: 79 additions & 41 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const char* slot_name(unsigned slot) {
case 67: return "Xbox DeserializeComputePipelineStateX";
case 70: return "Xbox shader-resource view from raw words";
case 73: return "Xbox CreateCommandListX -> PC CreateCommandList";
case 74: return "Xbox (pointer, u32, pointer) stand-in";
case 75: return "CreateCommandQueue1 -> queue proxy";
case 76: return "Xbox resource creation";
case 127: return "Xbox CreateCommittedResource3";
Expand Down Expand Up @@ -2486,6 +2487,67 @@ HRESULT proxy_create_committed_resource3_x(DeviceProxy* self, std::uint64_t heap
return hr;
}

// The Xbox routes at their configured indices. Returns false when `slot` is none of them. Built-in handlers (slot 74) ask
// too, because an override that moves a route onto their slot must win over the built-in handler.
bool route_xbox_device_slot(DeviceProxy* self, unsigned slot, std::uint64_t a1, std::uint64_t a2, std::uint64_t a3,
std::uint64_t a4, std::uint64_t a5, std::uint64_t& result) {
const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes();
if (slot == routes.frame_interval) {
log_xbox_route_once(slot, "SetFrameIntervalX", a1, a2, a3, a4, a5);
result = hr_to_u64(proxy_set_frame_interval_x(self, a1, a2, a3, a4));
} else if (slot == routes.schedule_event) {
log_xbox_route_once(slot, "ScheduleFrameEventX", a1, a2, a3, a4, a5);
result = hr_to_u64(proxy_schedule_frame_event_x(self, a1, a2, a4));
} else if (slot == routes.wait_event) {
log_xbox_route_once(slot, "WaitFrameEventX", a1, a2, a3, a4, a5);
result = hr_to_u64(proxy_wait_frame_event_x(self, a1, a2, a4, a5));
} else if (slot == routes.frame_statistics) {
HRESULT hr = S_OK;
if (call_presentation(self, [&](const PresentationHandler& p) {
if (!p.get_frame_statistics) return false;
log_xbox_route_once(slot, "GetFrameStatisticsX", a1, a2, a3, a4, a5);
hr = p.get_frame_statistics(p.context, a1, static_cast<UINT>(a2), reinterpret_cast<UINT*>(a3),
reinterpret_cast<void*>(a4));
return true;
})) {
result = hr_to_u64(hr);
} else {
// No presenter: no statistics yet (S_FALSE with a zero count, the "not available yet" answer in
// docs/d3d12_vulkan.md), and never the PC slot 81 (ID3D12Device13::OpenExistingHeapFromAddress1).
log_xbox_route_once(slot, "GetFrameStatisticsX", a1, a2, a3, a4, a5);
if (auto* count = reinterpret_cast<UINT*>(a3)) *count = 0;
result = hr_to_u64(S_FALSE);
}
} else if (slot == routes.queue_x) {
log_xbox_route_once(slot, "CreateCommandQueueX", a1, a2, a3, a4, a5);
result = 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)));
} else if (slot == routes.list_x) {
log_xbox_route_once(slot, "CreateCommandListX", a1, a2, a3, a4, a5);
result = hr_to_u64(proxy_create_command_list_x(self, a1, a2, a3, reinterpret_cast<const IID*>(a4),
reinterpret_cast<void**>(a5)));
} else {
return false;
}
return true;
}

// Slot 74: the retail title calls it once with (pointer, u32, pointer) (kapitche, issue 7231). The PC slot 74 is
// ID3D12Device9::ShaderCacheControl(kinds, control), which reads the first word as a flags value and returns
// E_INVALIDARG, and the title then stops on an int3. The words are not measured: nothing is written through the
// pointers, the PC device is not called, and the call succeeds. Only for the title's calls (set_console_caller, as
// slot 61): a host caller of ID3D12Device9::ShaderCacheControl through the proxy gets the PC method.
std::uint64_t proxy_slot74(std::uint64_t a1, std::uint64_t a2, std::uint64_t a3) {
static std::atomic<bool> logged{false};
bool expected = false;
if (logged.compare_exchange_strong(expected, true, std::memory_order_relaxed))
std::fprintf(stderr, "[rt] d3d12_xs: slot 74 (pointer, u32, pointer) returns S_OK; words 0x%llx 0x%llx 0x%llx\n",
static_cast<unsigned long long>(a1), static_cast<unsigned long long>(a2),
static_cast<unsigned long long>(a3));
return hr_to_u64(S_OK);
}

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 @@ -2524,6 +2586,20 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
reinterpret_cast<void**>(a3)));
} else if constexpr (Slot == 31 || Slot == 34 || Slot == 35 || Slot == 45 || Slot == 46 || Slot == 50) {
return hr_to_u64(proxy_unwrapping_call<Slot>(self, a1, a2, a3, a4, a5));
} else if constexpr (Slot == 74) {
std::uint64_t routed = 0;
if (route_xbox_device_slot(self, Slot, a1, a2, a3, a4, a5, routed)) return routed; // an override moved a route here
note_slot(Slot);
if (is_console_caller(_ReturnAddress())) return proxy_slot74(a1, a2, a3);
// A host caller: the PC slot 74 (ID3D12Device9::ShaderCacheControl), forwarded like any other PC method, as
// slot 61 does. With no classifier installed every caller is a host one.
if (Slot >= self->slot_count) return hr_to_u64(refuse_beyond_device(Slot, self->slot_count));
using ForwardFn = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t,
std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t,
std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t,
std::uint64_t, std::uint64_t, std::uint64_t);
auto fn = reinterpret_cast<ForwardFn>(self->real_vtable[Slot]);
return fn(self->real, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
} else if constexpr (Slot == 75) {
return hr_to_u64(proxy_create_command_queue1(self, a1, a2, reinterpret_cast<const IID*>(a3),
reinterpret_cast<void**>(a4)));
Expand Down Expand Up @@ -2629,46 +2705,8 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
// 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
// methods. The check is before the slot-count refusal because slot 80 is outside a PC ID3D12Device11 table.
const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes();
if (Slot == routes.frame_interval) {
log_xbox_route_once(Slot, "SetFrameIntervalX", a1, a2, a3, a4, a5);
return hr_to_u64(proxy_set_frame_interval_x(self, a1, a2, a3, a4));
}
if (Slot == routes.schedule_event) {
log_xbox_route_once(Slot, "ScheduleFrameEventX", a1, a2, a3, a4, a5);
return hr_to_u64(proxy_schedule_frame_event_x(self, a1, a2, a4));
}
if (Slot == routes.wait_event) {
log_xbox_route_once(Slot, "WaitFrameEventX", a1, a2, a3, a4, a5);
return hr_to_u64(proxy_wait_frame_event_x(self, a1, a2, a4, a5));
}
if (Slot == routes.frame_statistics) {
HRESULT hr = S_OK;
if (call_presentation(self, [&](const PresentationHandler& p) {
if (!p.get_frame_statistics) return false;
log_xbox_route_once(Slot, "GetFrameStatisticsX", a1, a2, a3, a4, a5);
hr = p.get_frame_statistics(p.context, a1, static_cast<UINT>(a2), reinterpret_cast<UINT*>(a3),
reinterpret_cast<void*>(a4));
return true;
}))
return hr_to_u64(hr);
// No presenter: no statistics yet (S_FALSE with a zero count, the "not available yet" answer in
// docs/d3d12_vulkan.md), and never the PC slot 81 (ID3D12Device13::OpenExistingHeapFromAddress1).
log_xbox_route_once(Slot, "GetFrameStatisticsX", a1, a2, a3, a4, a5);
if (auto* count = reinterpret_cast<UINT*>(a3)) *count = 0;
return hr_to_u64(S_FALSE);
}
if (Slot == routes.queue_x) {
log_xbox_route_once(Slot, "CreateCommandQueueX", a1, a2, a3, a4, a5);
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);
return hr_to_u64(proxy_create_command_list_x(self, a1, a2, a3, reinterpret_cast<const IID*>(a4),
reinterpret_cast<void**>(a5)));
}
std::uint64_t routed = 0;
if (route_xbox_device_slot(self, Slot, a1, a2, a3, a4, a5, routed)) return routed;
if (Slot >= self->slot_count) return hr_to_u64(refuse_beyond_device(Slot, self->slot_count));

// The PC vtable entry, called with the PC device as `this`. Integer/pointer arguments, the hidden
Expand Down Expand Up @@ -2997,7 +3035,7 @@ ID3D12Device* device_proxy_real_device(const void* device) {

bool device_slot_overridden(unsigned slot) {
if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || (slot >= 17 && slot <= 24) || slot == 25 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || slot == 35 ||
slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 61 || slot == 62 || slot == 67 ||
slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 61 || slot == 74 || slot == 62 || slot == 67 ||
slot == 70 || slot == 75 || slot == 76 || slot == 133 || slot == kCreateCommittedResource3X)
return true;
const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes();
Expand Down
4 changes: 3 additions & 1 deletion runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// 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 74 (pointer, u32, pointer): not measured, returns S_OK. The PC slot 74 is ShaderCacheControl(kinds, control),
// which reads the first word as flags and returns E_INVALIDARG. Nothing is written, the PC device is not called.
// slot 76 resource creation -> PC CreateCommittedResource (PC slot 27), with the Xbox layout word ignored.
// slot 127 CreateCommittedResource3 (heap, flags, desc1, layout, clear, session, castable count/list, riid, out) ->
// PC ID3D12Device10::CreateCommittedResource3 (PC slot 76), with the Xbox layout word replaced and the
Expand Down Expand Up @@ -184,7 +186,7 @@ bool set_presentation_handler(void* device, const PresentationHandler* handler);
// proxies), 9 (allocator proxies), 14 (descriptor heap proxy), 17-24 (CPU descriptor handle translation), 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, 76 and 127. Slot 10 is intentionally false: the
// 78/79/80 (the Xbox slots above, at their configured indices), 62, 67, 70, 74, 76 and 127. 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