diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index a39ad9f223..b50ce4a096 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -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. | diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 0dff57ed38..de10c26e81 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -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) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index e2791dc6ac..ec8501e7a6 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -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"; @@ -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(a2), reinterpret_cast(a3), + reinterpret_cast(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(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(a1), + reinterpret_cast(a2), + reinterpret_cast(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(a4), + reinterpret_cast(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 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(a1), static_cast(a2), + static_cast(a3)); + return hr_to_u64(S_OK); +} + template 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, @@ -2524,6 +2586,20 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 reinterpret_cast(a3))); } else if constexpr (Slot == 31 || Slot == 34 || Slot == 35 || Slot == 45 || Slot == 46 || Slot == 50) { return hr_to_u64(proxy_unwrapping_call(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(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(a3), reinterpret_cast(a4))); @@ -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(a2), reinterpret_cast(a3), - reinterpret_cast(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(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(a1), - reinterpret_cast(a2), - reinterpret_cast(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(a4), - reinterpret_cast(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 @@ -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(); diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 57eca36a06..c5b0bf8e78 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -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 @@ -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); diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 7e08d407e5..70d29a6190 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -1220,8 +1220,8 @@ struct EnvPresenter { int stats = 0, present = 0, suspend = 0, resume = 0; }; -int run_env_slots(bool valid) { - const char* frame_interval = valid ? "96" : "2"; +int run_env_slots(bool valid, bool on_slot74 = false) { + const char* frame_interval = on_slot74 ? "74" : valid ? "96" : "2"; const char* schedule_event = valid ? "97" : "2"; const char* wait_event = valid ? "98" : "2"; const char* queue_x = valid ? "99" : "2"; @@ -1243,7 +1243,12 @@ int run_env_slots(bool valid) { EXPECT(device); xs::reset_device_proxy_stats(); std::uint64_t token = 0; - if (valid) { + if (on_slot74) { + // SetFrameIntervalX moved onto 74, which also has a built-in handler: the override wins, so (output, interval, + // latency, flags) is a frame-interval call that reaches no PC slot, not the stand-in that ignores its words. + EXPECT(hr_of(raw(device, 74, 0, 16667, 1, 0)) == S_OK && mock->calls[74] == 0); + EXPECT(hr_of(raw(device, 78, 0, 16667, 1, 0)) == S_OK && mock->calls[78] == 1); // the old default is a PC slot now + } else if (valid) { // Every route moved: the new slot is handled, the default slot is forwarded to the mock. EXPECT(hr_of(raw(device, 96, 0, 16667, 1, 0)) == S_OK && mock->calls[96] == 0); EXPECT(hr_of(raw(device, 97, 0, 0, 0, 0)) == S_OK && mock->calls[97] == 0); @@ -1426,6 +1431,47 @@ int check_slot70() { return 0; } +// ---- 8b. Device slot 74: (pointer, u32, pointer) succeeds and touches nothing, never the PC ShaderCacheControl ---- + +int check_slot74() { + // Level 9 has the PC slot 74 (ShaderCacheControl); level 0 does not (44 PC slots). Neither may reach it. + for (const int level : {9, 0}) { + Mock* mock = nullptr; + void* device = make_device(mock, level, true); + EXPECT(device && xs::device_slot_overridden(74)); + xs::reset_device_proxy_stats(); + std::uint32_t first[4] = {0x11111111, 0x22222222, 0x33333333, 0x44444444}; + std::uint32_t second[4] = {0x55555555, 0x66666666, 0x77777777, 0x88888888}; + const std::uint32_t first_before[4] = {first[0], first[1], first[2], first[3]}; + const std::uint32_t second_before[4] = {second[0], second[1], second[2], second[3]}; + // The title's call (a caller the classifier takes for a guest image): the stand-in. + xs::set_console_caller([](std::uint64_t) { return true; }); + EXPECT(hr_of(raw(device, 74, word(first), 7, word(second))) == S_OK); + EXPECT(mock->calls[74] == 0 && xs::device_slot_hits(74) == 1); + EXPECT(std::memcmp(first, first_before, sizeof(first)) == 0 && std::memcmp(second, second_before, sizeof(second)) == 0); + // A host caller, under a classifier and with none installed: the PC slot 74 (ShaderCacheControl) with the + // same words where the PC device has it, and the refusal past its table where it does not (found on Windows + // in the review of this change: the stand-in used to take a host's ShaderCacheControl too). + for (const bool installed : {true, false}) { + if (installed) + xs::set_console_caller([](std::uint64_t) { return false; }); + else + xs::set_console_caller(nullptr); + const std::uint64_t before = mock->calls[74]; + const HRESULT hr = hr_of(raw(device, 74, 0x1, 0x2)); + if (level >= 9) { + EXPECT(hr == S_OK && mock->calls[74] == before + 1); + EXPECT(mock->args[74][0] == 0x1 && mock->args[74][1] == 0x2); + } else { + EXPECT(hr == E_NOTIMPL && mock->calls[74] == before); + } + } + xs::set_console_caller(nullptr); + EXPECT(release(device) == 0 && mock->refs == 0); + } + return 0; +} + // ---- 7. Device slot 25, GetResourceAllocationInfo: a render target takes whole console tiles ---- D3D12_RESOURCE_DESC target_desc(std::uint64_t width, UINT height, DXGI_FORMAT format, UINT slices = 1) { @@ -2403,6 +2449,7 @@ int main(int argc, char** argv) { if (argc == 2) { if (std::strcmp(argv[1], "--env-slots") == 0) return run_env_slots(true); if (std::strcmp(argv[1], "--env-slots-invalid") == 0) return run_env_slots(false); + if (std::strcmp(argv[1], "--env-slots-74") == 0) return run_env_slots(true, true); return run_fault_mode(argv[1]); } if (argc != 1) return 2; @@ -2415,6 +2462,7 @@ int main(int argc, char** argv) { check_allocation_descriptions_cleaned() || check_render_target_layout() || check_committed_resource_leases() || + check_slot74() || check_presentation_wiring()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news);