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 @@ -3576,6 +3576,7 @@ to be recovered from call sites (or the NDA GDK headers, if a developer has acce
| PresentX / present planes / frame events | Public GDK samples (MIT/zlib), §4.5 | Likely the only present path of a GDKX title. Presenter + vblank-timed frame events; 1-2 planes composed into the Vulkan swapchain (placement, filter, alpha overlay, HDR10 conversions). Call shapes known; slots/layouts **Open**. |
| 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 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
6 changes: 6 additions & 0 deletions runtime/shims/d3d12_xs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons
std::fprintf(stderr,
"[rt] d3d12_xs: D3D12XboxCreateDevice: wrapping the PC ID3D12Device in the Xbox-ABI proxy "
"(slot 62 -> CreateComputePipelineState, slot 76 -> CreateCommittedResource).\n");
// A console method whose slot is another PC method (61) is served only to the title: a caller in an image
// this loader mapped.
rt::d3d12_xs::set_console_caller([](std::uint64_t address) {
std::uint64_t base = 0;
return rt::shims::mapped_image_base(address, base);
});
}

#ifdef LEONIDA_VULKAN_DEVICE
Expand Down
55 changes: 54 additions & 1 deletion runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <windows.h>
#include <dxgi1_4.h>
#include <intrin.h> // _ReturnAddress: slot 61 serves a console caller differently from a host one

#include <atomic>
#include <functional>
Expand Down Expand Up @@ -257,6 +258,7 @@ const char* slot_name(unsigned slot) {
case 48: return "Xbox CreateCommandQueueX -> queue proxy";
case 50: return "EnqueueMakeResident (proxies unwrapped)";
case 56: return "GetResourceAllocationInfo1 (C or PC form)";
case 61: return "Xbox CreateSamplerX -> PC CreateSampler (a host caller gets PC CreateMetaCommand)";
case 62: return "Xbox CreateComputePipelineState";
case 67: return "Xbox DeserializeComputePipelineStateX";
case 70: return "Xbox shader-resource view from raw words";
Expand Down Expand Up @@ -2092,6 +2094,39 @@ HRESULT proxy_create_command_signature(DeviceProxy* self, const D3D12_COMMAND_SI
return forward(self->real, &pc, root_signature, riid, out);
}

// The Xbox slot 61 is CreateSamplerX(desc, dest): a sampler written to a CPU descriptor handle, with the PC
// CreateSampler's two arguments. Measured on the retail title's boot (stop 20 in #6910's RT-5 measurements): the
// title calls it once per sampler after its descriptor heaps exist, and it goes on when the call is served by the PC
// CreateSampler. The PC slot 61 is CreateMetaCommand, which would take these words as (CommandId, NodeMask, ...).
// HYPOTHESIS: the console description begins with the PC D3D12_SAMPLER_DESC (52 bytes), which is what got the title
// past this call; whatever follows it is not known and not read. The title was not seen testing a result, so a null
// description is skipped rather than reported. The handle is passed as given: a handle in the title's own heap range
// is #7021's translation.
// The same proxy also serves host callers (the runtime's own tests drive the Vulkan device through it), for whom slot
// 61 is the PC ID3D12Device5::CreateMetaCommand. So the slot is CreateSamplerX only for a caller in an image the
// guest loader mapped (set_console_caller); any other caller, or every caller when no check is installed, gets the PC
// method. Without the check d3d12_vulkan_device_test's CreateMetaCommand call reached this handler (#7115).
std::atomic<ConsoleCaller> g_console_caller{nullptr};

bool is_console_caller(const void* address) {
const ConsoleCaller classify = g_console_caller.load(std::memory_order_acquire);
return classify && classify(reinterpret_cast<std::uint64_t>(address));
}

void proxy_create_sampler_x(DeviceProxy* self, const D3D12_SAMPLER_DESC* desc, std::uint64_t dest) {
note_slot(61);
if (!desc) {
static std::atomic<bool> logged{false};
if (!logged.exchange(true, std::memory_order_relaxed))
std::fprintf(stderr, "[rt] d3d12_xs: slot 61 CreateSamplerX without a description (skipped)\n");
return;
}
D3D12_CPU_DESCRIPTOR_HANDLE handle{};
// A destination in the title's own descriptor range is translated to the real heap's, as device slots 17 to 24 do.
handle = translate_cpu_handle(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(dest)});
self->real->CreateSampler(desc, handle);
}

// The Xbox slot 67 creates a compute pipeline from native GPU code: (desc, riid, out), named
// DeserializeComputePipelineStateX in amd_fidelityfx_upscaler_xbox.dll's messages (call at RVA 0x56d9). The desc
// passes the root signature at +0x00, followed by pointer/size pairs for the shader's FSPX entries (docs/fspx.md):
Expand Down Expand Up @@ -2545,6 +2580,20 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64
return hr_to_u64(proxy_create_command_signature(
self, reinterpret_cast<const D3D12_COMMAND_SIGNATURE_DESC*>(a1), a2, reinterpret_cast<const IID*>(a3),
reinterpret_cast<void**>(a4)));
} else if constexpr (Slot == 61) {
if (is_console_caller(_ReturnAddress())) {
proxy_create_sampler_x(self, reinterpret_cast<const D3D12_SAMPLER_DESC*>(a1), a2);
return 0;
}
// A host caller: the PC slot 61 (ID3D12Device5::CreateMetaCommand), forwarded like any other PC method.
note_slot(Slot);
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 == 67) {
return hr_to_u64(proxy_create_compute_pipeline_from_native_code(
self, reinterpret_cast<const void*>(a1), reinterpret_cast<const IID*>(a2),
Expand Down Expand Up @@ -2948,7 +2997,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 == 62 || slot == 67 ||
slot == 36 || slot == 41 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 61 || 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 Expand Up @@ -3053,6 +3102,10 @@ bool heap_slot_overridden(unsigned slot) {
return slot <= 2 || slot == 7 || slot == 9 || slot == 10;
}

void set_console_caller(ConsoleCaller classify) {
g_console_caller.store(classify, std::memory_order_release);
}

std::uint64_t device_slot_hits(unsigned slot) {
start_hit_counts();
return slot < kMaxSlots ? g_hits[slot].load(std::memory_order_relaxed) : 0;
Expand Down
8 changes: 8 additions & 0 deletions runtime/shims/d3d12_xs_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// the executable has been seen yet, so they are forwarded in the PC form.
// slot 41 CreateCommandSignature at its PC position; a console argument of type 105 (a 12-byte dispatch, read
// from the retail title's call sites) is created as D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH.
// slot 61 CreateSamplerX(desc, dest) -> PC CreateSampler (slot 22); the description's PC
// D3D12_SAMPLER_DESC prefix is passed. The PC slot 61 is CreateMetaCommand. Measured on the retail title's boot.
// 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
Expand Down Expand Up @@ -187,6 +189,12 @@ bool set_presentation_handler(void* device, const PresentationHandler* handler);
// handles for the allocator proxy.
bool device_slot_overridden(unsigned slot);

// Whether a return address is in an image the guest loader mapped, i.e. the call comes from the title. Device slot 61
// is CreateSamplerX for such a caller and the PC ID3D12Device5::CreateMetaCommand for any other; with no check
// installed every caller is a host one. D3D12XboxCreateDevice installs rt::shims::mapped_image_base.
using ConsoleCaller = bool (*)(std::uint64_t address);
void set_console_caller(ConsoleCaller classify);

// Queue and fence proxies created by device slots 8/75 and 36. The real_* accessors return the wrapped object
// (no reference added), or null when the pointer is not such a proxy.
bool is_queue_proxy(const void* queue);
Expand Down
33 changes: 30 additions & 3 deletions runtime/test/xs_proxy_mock_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,8 @@ int check_allocators() {
return 0;
}



// ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) and the retail title (41) ----
//
// A device that answers ID3D12Device11 (80 PC slots) is the Vulkan layer's shape: slots 78/79 are inside its table
Expand Down Expand Up @@ -1172,14 +1174,39 @@ int check_xbox_slots() {
EXPECT(mock->calls[41] == 2 && mock->args[41][0] == word(&pc_sig));
EXPECT(mock->array[41][1] == D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH);

EXPECT(xs::device_slot_overridden(41) && xs::device_slot_overridden(48) && xs::device_slot_overridden(73) &&
// 61 is CreateSamplerX(desc, dest) for the title and the PC CreateMetaCommand for a host caller. With no
// console-caller check installed (a host program like this one), the call is the PC slot 61.
D3D12_SAMPLER_DESC sampler{};
sampler.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
sampler.AddressU = sampler.AddressV = sampler.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
sampler.MaxLOD = D3D12_FLOAT32_MAX;
const std::uint64_t sampler_handle = 0x7ff012340040ull;
raw(device, 61, word(&sampler), sampler_handle);
EXPECT(mock->calls[61] == 1 && mock->calls[22] == 0 && xs::device_slot_hits(61) == 1);
// A caller the check calls the title's (here every one): the PC CreateSampler (slot 22) gets the same two words,
// not the PC slot 61. A null description is skipped without reaching the device.
xs::set_console_caller([](std::uint64_t) { return true; });
raw(device, 61, word(&sampler), sampler_handle);
EXPECT(mock->calls[61] == 1 && mock->calls[22] == 1 && xs::device_slot_hits(61) == 2);
EXPECT(mock->args[22][0] == word(&sampler) && mock->args[22][1] == sampler_handle);
raw(device, 61, 0, sampler_handle);
EXPECT(mock->calls[61] == 1 && mock->calls[22] == 1 && xs::device_slot_hits(61) == 3);
// A caller outside the title's images is a host one again.
xs::set_console_caller([](std::uint64_t) { return false; });
raw(device, 61, word(&sampler), sampler_handle);
EXPECT(mock->calls[61] == 2 && mock->calls[22] == 1);
xs::set_console_caller(nullptr);

EXPECT(xs::device_slot_overridden(41) && xs::device_slot_overridden(48) && xs::device_slot_overridden(61) &&
xs::device_slot_overridden(73) &&
xs::device_slot_overridden(78) && xs::device_slot_overridden(79) && xs::device_slot_overridden(80));

EXPECT(release(allocator) == 0 && real_allocator->refs == 0);
EXPECT(release(queue) == 0);
EXPECT(release(device) == 0 && mock->refs == 0);
std::printf("%s: device slots 48/73/78/79/80 route to a queue, a list and frame-event tokens without reaching "
"the mock's own PC slots; slot 41 creates argument type 105 as DISPATCH\n", g_label);
std::printf("%s: device slots 48/73/78/79/80 route to a queue, a list and frame-event tokens, and slot 61 to "
"CreateSampler, without reaching the mock's own PC slots; slot 41 creates argument type 105 as DISPATCH\n",
g_label);
return 0;
#else
std::printf("%s: ID3D12Device11 is not in this SDK; Xbox slot 80's beyond-table case is not built\n", g_label);
Expand Down
Loading