From 028001c8293942876375e54349afa8dae21f0746 Mon Sep 17 00:00:00 2001 From: andretuta Date: Tue, 24 Nov 2026 00:53:33 -0300 Subject: [PATCH] d3d12_xs: fill D3D12ConfigureVirtualMemoryX VA bounds, 0x40-byte D3D12_OPTIONS and Xbox slots 81/86/108 (RT-XS-DEVICE-VM-OPTIONS) --- runtime/CMakeLists.txt | 16 +++++ runtime/shims/d3d12_vulkan_device.cpp | 43 ++++++------ runtime/shims/d3d12_xs.cpp | 27 ++++++-- runtime/shims/d3d12_xs_device.cpp | 79 ++++++++++++++++++++--- runtime/shims/d3d12_xs_device.h | 6 +- runtime/test/d3d12_vulkan_device_test.cpp | 6 ++ runtime/test/d3d12_xs_vm_test.cpp | 54 ++++++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 50 +++++++++++++- 8 files changed, 245 insertions(+), 36 deletions(-) create mode 100644 runtime/test/d3d12_xs_vm_test.cpp diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 8fce889eb6..b48e123c4e 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -235,6 +235,19 @@ if(WIN32 AND LEONIDA_BUILD_WINDOWS_RUNTIME) target_compile_options(xg_xs_test PRIVATE /W4 /permissive- /utf-8) target_link_options(xg_xs_test PRIVATE /OPT:NOREF) + # D3D12ConfigureVirtualMemoryX user-space VA range test; needs no GPU or game data. + add_executable(d3d12_xs_vm_test + test/d3d12_xs_vm_test.cpp + shims/d3d12_xs.cpp + shims/d3d12_xs_device.cpp + shims/registry.cpp + ) + target_include_directories(d3d12_xs_vm_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/shims ${CMAKE_CURRENT_SOURCE_DIR}/src) + target_compile_definitions(d3d12_xs_vm_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) + target_compile_options(d3d12_xs_vm_test PRIVATE /W4 /permissive- /utf-8) + target_link_options(d3d12_xs_vm_test PRIVATE /OPT:NOREF) + target_link_libraries(d3d12_xs_vm_test PRIVATE gta6rt_d3d12_xs_rootsig) + # acphal shim ABI test: resolves the registered acphal.dll exports through the registry. add_executable(acphal_test test/acphal_test.cpp @@ -1141,6 +1154,9 @@ if(BUILD_TESTING) if(WIN32 AND TARGET xg_xs_test) add_test(NAME xg_xs COMMAND xg_xs_test) endif() + if(WIN32 AND TARGET d3d12_xs_vm_test) + add_test(NAME d3d12_xs_vm COMMAND d3d12_xs_vm_test) + endif() if(WIN32 AND TARGET acphal_test) add_test(NAME acphal COMMAND acphal_test) endif() diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 0273f9339b..21590be394 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -7589,35 +7589,42 @@ class Device final return d3d12_trace::result(method, S_OK); } case D3D12_FEATURE_D3D12_OPTIONS: { - if (size != sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS)) return d3d12_trace::result(method, E_INVALIDARG); - auto* opts = static_cast(data); - *opts = {}; + constexpr UINT kConsoleOptionsSize = sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS) + sizeof(UINT); + if (size != sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS) && size != kConsoleOptionsSize) + return d3d12_trace::result(method, E_INVALIDARG); + D3D12_FEATURE_DATA_D3D12_OPTIONS pc_opts{}; // Answer what the layer will actually honour, not what the GPU offers: docs/d3d12_vulkan.md 4.1 says a // false "supported" is worse than a false "unsupported" at boot, and the PSO paths refuse these same // features when they are missing (logic ops, per the mapping vkd3d-proton's // d3d12_device_caps_init_feature_options uses). - opts->DoublePrecisionFloatShaderOps = state_.info.features.shaderFloat64; - opts->OutputMergerLogicOp = state_.info.features.logicOp; - opts->MinPrecisionSupport = D3D12_SHADER_MIN_PRECISION_SUPPORT_NONE; - opts->TiledResourcesTier = D3D12_TILED_RESOURCES_TIER_NOT_SUPPORTED; - opts->ResourceBindingTier = D3D12_RESOURCE_BINDING_TIER_3; // Bindless descriptor indexing supported + pc_opts.DoublePrecisionFloatShaderOps = state_.info.features.shaderFloat64; + pc_opts.OutputMergerLogicOp = state_.info.features.logicOp; + pc_opts.MinPrecisionSupport = D3D12_SHADER_MIN_PRECISION_SUPPORT_NONE; + pc_opts.TiledResourcesTier = D3D12_TILED_RESOURCES_TIER_NOT_SUPPORTED; + pc_opts.ResourceBindingTier = D3D12_RESOURCE_BINDING_TIER_3; // Bindless descriptor indexing supported // No VK_EXT_shader_stencil_export is enabled and the translator emits no stencil-ref write, so a pixel // shader that writes the stencil ref would be refused: answer unsupported, the direction 4.1 prefers. - opts->PSSpecifiedStencilRefSupported = FALSE; - opts->TypedUAVLoadAdditionalFormats = TRUE; + pc_opts.PSSpecifiedStencilRefSupported = FALSE; + pc_opts.TypedUAVLoadAdditionalFormats = TRUE; // POPS: the translator only declares PixelInterlockOrderedEXT, enabled exactly when the GPU offers // VK_EXT_fragment_shader_interlock and its fragmentShaderPixelInterlock feature. - opts->ROVsSupported = state_.info.fragment_shader_interlock; - opts->ConservativeRasterizationTier = state_.conservative_raster_tier; - opts->MaxGPUVirtualAddressBitsPerResource = 40; - opts->StandardSwizzle64KBSupported = FALSE; - opts->CrossNodeSharingTier = D3D12_CROSS_NODE_SHARING_TIER_NOT_SUPPORTED; - opts->CrossAdapterRowMajorTextureSupported = FALSE; + pc_opts.ROVsSupported = state_.info.fragment_shader_interlock; + pc_opts.ConservativeRasterizationTier = state_.conservative_raster_tier; + pc_opts.MaxGPUVirtualAddressBitsPerResource = 40; + pc_opts.StandardSwizzle64KBSupported = FALSE; + pc_opts.CrossNodeSharingTier = D3D12_CROSS_NODE_SHARING_TIER_NOT_SUPPORTED; + pc_opts.CrossAdapterRowMajorTextureSupported = FALSE; // A translated vertex shader writing a layer or viewport index needs both Vulkan 1.2 features enabled // (vkCreateShaderModule refuses the module without them, VUID-...-pCode-08740). - opts->VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = + pc_opts.VPAndRTArrayIndexFromAnyShaderFeedingRasterizerSupportedWithoutGSEmulation = state_.info.shader_output_layer && state_.info.shader_output_viewport_index; - opts->ResourceHeapTier = D3D12_RESOURCE_HEAP_TIER_1; + pc_opts.ResourceHeapTier = D3D12_RESOURCE_HEAP_TIER_1; + std::memcpy(data, &pc_opts, sizeof(pc_opts)); + if (size == kConsoleOptionsSize) { + // Console titles query D3D12_FEATURE_D3D12_OPTIONS with a 0x40-byte (16-dword) buffer + // (docs/d3d12_xs_surface.md §7.1): fill the 0x3C-byte PC prefix and zero the trailing 4 bytes. + std::memset(static_cast(data) + sizeof(pc_opts), 0, sizeof(UINT)); + } return d3d12_trace::result(method, S_OK); } case D3D12_FEATURE_D3D12_OPTIONS1: { diff --git a/runtime/shims/d3d12_xs.cpp b/runtime/shims/d3d12_xs.cpp index 8e54c3fd56..83f67e2f56 100644 --- a/runtime/shims/d3d12_xs.cpp +++ b/runtime/shims/d3d12_xs.cpp @@ -217,10 +217,29 @@ static_assert(std::is_same_v); static_assert(std::is_same_v); static_assert(std::is_same_v); -// Measured call (RT-5, 1.0.2.1): the title calls it once at startup with one pointer to a zeroed 32-byte block whose -// dword at +4 it sets (a count), and only checks the result for failure. The PC/Vulkan side owns virtual memory, -// so the policy is accepted and ignored. -HRESULT WINAPI configure_virtual_memory(void* /*desc*/) { return S_OK; } +// Measured call (RT-5, 1.0.2.1): the title calls it once at startup with a 32-byte configuration block. +// Input words configure console page-table sizing (not used on PC/Vulkan); output words at +0x10 and +0x18 return +// the user-space graphics VA range [lowest, highest], which matches the host process's application address range +// because GPU and CPU virtual addresses share the same 64-bit space. +struct XboxVirtualMemoryConfig { + uint32_t flags; + uint32_t page_table_pages; + uint32_t preserved_bytes; + uint32_t reserved; + uint64_t lowest; + uint64_t highest; +}; +static_assert(sizeof(XboxVirtualMemoryConfig) == 0x20, "D3D12ConfigureVirtualMemoryX config must be 32 bytes"); + +HRESULT WINAPI configure_virtual_memory(void* desc) { + if (!desc) return E_INVALIDARG; + auto* cfg = static_cast(desc); + SYSTEM_INFO si{}; + GetSystemInfo(&si); + cfg->lowest = reinterpret_cast(si.lpMinimumApplicationAddress); + cfg->highest = reinterpret_cast(si.lpMaximumApplicationAddress); + return S_OK; +} } // namespace diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 1045b86fb9..a6eec3f12a 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -153,6 +153,9 @@ const char* slot_name(unsigned slot) { case 78: return "Xbox SetFrameIntervalX"; case 79: return "Xbox ScheduleFrameEventX"; case 80: return "Xbox WaitFrameEventX"; + case 81: return "Xbox GetFrameStatisticsX"; + case 86: return "Xbox CreatePipelineState (stream -> PC slot 47)"; + case 108: return "Xbox GetResourceAllocationInfo2 (-> PC slot 25)"; case 133: return "Xbox CreatePlacedResourceX (a buffer on the title's pages)"; default: return "forwarded"; } @@ -174,11 +177,12 @@ void note_slot(unsigned slot) { // that disagrees). A value outside that range is logged once and ignored. The table is read once, on the first // generic slot call, so a test that wants other slots sets the variables before it creates a device. struct XboxDeviceSlotRoutes { - unsigned frame_interval = 78; // SetFrameIntervalX(output, interval_us, latency, flags) - unsigned schedule_event = 79; // ScheduleFrameEventX(event, offset_us, reserved, flags) - unsigned wait_event = 80; // WaitFrameEventX(event, timeout_ms, reserved, flags, &token) - unsigned queue_x = 48; // CreateCommandQueueX(desc, riid, out) - unsigned list_x = 73; // CreateCommandListX(desc, allocator, initial_state, riid, out) + unsigned frame_interval = 78; // SetFrameIntervalX(output, interval_us, latency, flags) + unsigned schedule_event = 79; // ScheduleFrameEventX(event, offset_us, reserved, flags) + unsigned wait_event = 80; // WaitFrameEventX(event, timeout_ms, reserved, flags, &token) + unsigned frame_statistics = 81; // GetFrameStatisticsX(token, type_mask, &count, stats) + unsigned queue_x = 48; // CreateCommandQueueX(desc, riid, out) + unsigned list_x = 73; // CreateCommandListX(desc, allocator, initial_state, riid, out) }; unsigned env_device_slot(const char* name, unsigned fallback) { @@ -206,20 +210,23 @@ const XboxDeviceSlotRoutes& xbox_device_slot_routes() { const unsigned frame_interval = env_device_slot("LEONIDA_XS_FRAME_INTERVAL_SLOT", r.frame_interval); const unsigned schedule_event = env_device_slot("LEONIDA_XS_SCHEDULE_EVENT_SLOT", r.schedule_event); const unsigned wait_event = env_device_slot("LEONIDA_XS_WAIT_EVENT_SLOT", r.wait_event); + const unsigned frame_statistics = env_device_slot("LEONIDA_XS_FRAME_STATISTICS_SLOT", r.frame_statistics); const unsigned queue_x = env_device_slot("LEONIDA_XS_QUEUE_X_SLOT", r.queue_x); const unsigned list_x = env_device_slot("LEONIDA_XS_LIST_X_SLOT", r.list_x); const bool moved = frame_interval != r.frame_interval || schedule_event != r.schedule_event || - wait_event != r.wait_event || queue_x != r.queue_x || list_x != r.list_x; + wait_event != r.wait_event || frame_statistics != r.frame_statistics || + queue_x != r.queue_x || list_x != r.list_x; r.frame_interval = frame_interval; r.schedule_event = schedule_event; r.wait_event = wait_event; + r.frame_statistics = frame_statistics; r.queue_x = queue_x; r.list_x = list_x; if (moved) std::fprintf(stderr, "[rt] d3d12_xs: Xbox device slots: SetFrameIntervalX=%u ScheduleFrameEventX=%u " - "WaitFrameEventX=%u CreateCommandQueueX=%u CreateCommandListX=%u\n", - r.frame_interval, r.schedule_event, r.wait_event, r.queue_x, r.list_x); + "WaitFrameEventX=%u GetFrameStatisticsX=%u CreateCommandQueueX=%u CreateCommandListX=%u\n", + r.frame_interval, r.schedule_event, r.wait_event, r.frame_statistics, r.queue_x, r.list_x); return r; }(); return routes; @@ -1409,6 +1416,21 @@ HRESULT proxy_wait_frame_event_x(DeviceProxy* self, std::uint64_t event, std::ui return S_OK; } +// Xbox device slot 81 (public HLE, docs/d3d12_xs_surface.md §7.1): GetFrameStatisticsX(token, type_mask, &count, stats). +// Matches XboxPresentation::GetFrameStatisticsX (xbox_present.h): before a live presenter is attached, sets *count = 0 +// and returns S_FALSE ("not available yet"), or E_POINTER when the count pointer is null. +HRESULT proxy_get_frame_statistics_x(DeviceProxy* self, std::uint64_t token, std::uint64_t type_mask, + std::uint64_t count_word, std::uint64_t stats_word) { + (void)self; + (void)token; + (void)type_mask; + (void)stats_word; + auto* count = reinterpret_cast(count_word); + if (!count) return E_POINTER; + *count = 0; + return S_FALSE; +} + // Xbox device slot 73 (public HLE): CreateCommandListX(desc, allocator, initial_state, riid, out). The console call is // not the PC six-argument form: the type is the first word of D3D12XBOX_COMMAND_LIST_DESC and there is no node mask // (the HLE passes 0). The second desc word is logged, not interpreted: its public layout is not established. @@ -1817,6 +1839,8 @@ HRESULT proxy_create_placed_resource_x(DeviceProxy* self, void* va, const D3D12_ return handler(self->real, va, pc_desc, state, *riid, out); } +void** get_vtable(); + 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, @@ -1870,6 +1894,37 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 return hr_to_u64(proxy_create_compute_pipeline_from_native_code( self, reinterpret_cast(a1), reinterpret_cast(a2), reinterpret_cast(a3))); + } else if constexpr (Slot == 86) { + // Xbox device slot 86: CreatePipelineState(stream_desc, riid, out) -> PC ID3D12Device2::CreatePipelineState + // (PC slot 47). Slot 86 lies past PC ID3D12Device14 (83 slots) so it never collides with a PC slot. + note_slot(86); + constexpr unsigned kPcCreatePipelineStateSlot = 47; + if (self->slot_count <= kPcCreatePipelineStateSlot) + return hr_to_u64(refuse_beyond_device(86, self->slot_count)); + using CreateStreamPsoFn = HRESULT(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t); + auto fn = reinterpret_cast(self->real_vtable[kPcCreatePipelineStateSlot]); + return hr_to_u64(fn(self->real, a1, a2, a3)); + } else if constexpr (Slot == 108) { + // Xbox device slot 108: GetResourceAllocationInfo2 -> PC GetResourceAllocationInfo (PC slot 25). Supports + // both PC (this, ret_buf, ...) and Xbox swapped (ret_buf, this, ...) calling conventions. + DeviceProxy* proxy = self; + std::uint64_t ret_buf = a1; + void** const expected_vtbl = get_vtable(); + if (!readable_range(proxy, sizeof(void*)) || proxy->vtable != expected_vtbl) { + auto* candidate = reinterpret_cast(a1); + if (readable_range(candidate, sizeof(void*)) && candidate->vtable == expected_vtbl) { + ret_buf = reinterpret_cast(self); + proxy = candidate; + } + } + note_slot(108); + constexpr unsigned kPcAllocInfoSlot = 25; + if (!proxy || proxy->slot_count <= kPcAllocInfoSlot) { + if (proxy) refuse_beyond_device(108, proxy->slot_count); + return ret_buf; + } + using AllocInfoFn = std::uint64_t(WINAPI*)(void*, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); + return reinterpret_cast(proxy->real_vtable[kPcAllocInfoSlot])(proxy->real, ret_buf, a2, a3, a4); } else if constexpr (Slot == 133) { return hr_to_u64(proxy_create_placed_resource_x(self, reinterpret_cast(a1), reinterpret_cast(a2), @@ -1901,6 +1956,10 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 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) { + log_xbox_route_once(Slot, "GetFrameStatisticsX", a1, a2, a3, a4, a5); + return hr_to_u64(proxy_get_frame_statistics_x(self, a1, a2, a3, a4)); + } 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(a1), @@ -2072,11 +2131,11 @@ 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 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || - slot == 75 || slot == 76 || slot == 133) + slot == 75 || slot == 76 || slot == 86 || slot == 108 || slot == 133) return true; const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes(); return slot == routes.frame_interval || slot == routes.schedule_event || slot == routes.wait_event || - slot == routes.queue_x || slot == routes.list_x; + slot == routes.frame_statistics || slot == routes.queue_x || slot == routes.list_x; } bool is_queue_proxy(const void* queue) { return is_child_proxy(queue); } diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 20ed4afc15..0894269d76 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -119,9 +119,9 @@ 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 -// measured 9/10 handle conversion is on the heap proxy, and device slot 9 is CreateCommandAllocator, which the proxy -// handles for the allocator proxy. +// 78/79/80/81 (the Xbox slots above, at their configured indices), 62, 67, 76, 86, 108 and 133. 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); // Queue and fence proxies created by device slots 8/75 and 36. The real_* accessors return the wrapped object diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 892f3a04eb..690fef000a 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -5163,6 +5163,12 @@ int main() { EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)))); EXPECT(options.ResourceBindingTier == D3D12_RESOURCE_BINDING_TIER_3); EXPECT(options.MaxGPUVirtualAddressBitsPerResource == 40); + // Console 0x40-byte (16-dword) D3D12_OPTIONS query (docs/d3d12_xs_surface.md §7.1): 0x3C PC prefix + zero tail. + UINT console_opts[16]{}; + console_opts[15] = 0xdeadbeefu; + EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, console_opts, sizeof(console_opts)))); + EXPECT(std::memcmp(console_opts, &options, sizeof(options)) == 0); + EXPECT(console_opts[15] == 0); D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT va_support{}; EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &va_support, sizeof(va_support)))); diff --git a/runtime/test/d3d12_xs_vm_test.cpp b/runtime/test/d3d12_xs_vm_test.cpp new file mode 100644 index 0000000000..235fa0754e --- /dev/null +++ b/runtime/test/d3d12_xs_vm_test.cpp @@ -0,0 +1,54 @@ +// Checks D3D12ConfigureVirtualMemoryX in runtime/shims/d3d12_xs.cpp without needing a GPU or game data. +#include +#include + +#include +#include +#include + +#include "shims.h" + +namespace { + +int g_checks = 0; +int g_failures = 0; + +void check(bool condition, const char* what) { + ++g_checks; + std::printf("%s %s\n", condition ? "PASS" : "FAIL", what); + if (!condition) ++g_failures; +} + +struct XboxVirtualMemoryConfig { + uint32_t flags; + uint32_t page_table_pages; + uint32_t preserved_bytes; + uint32_t reserved; + uint64_t lowest; + uint64_t highest; +}; +static_assert(sizeof(XboxVirtualMemoryConfig) == 0x20); + +} // namespace + +int main() { + using Fn = HRESULT(WINAPI*)(void*); + const auto fn = reinterpret_cast(rt::shims::find("d3d12_xs.dll", "D3D12ConfigureVirtualMemoryX")); + check(fn != nullptr, "D3D12ConfigureVirtualMemoryX resolves through shim registry"); + if (!fn) return 1; + + check(fn(nullptr) == E_INVALIDARG, "D3D12ConfigureVirtualMemoryX(nullptr) returns E_INVALIDARG"); + + XboxVirtualMemoryConfig cfg{1u, 7u, 0x1000u, 0u, 0u, 0u}; + check(fn(&cfg) == S_OK, "D3D12ConfigureVirtualMemoryX(valid) returns S_OK"); + check(cfg.flags == 1u && cfg.page_table_pages == 7u && cfg.preserved_bytes == 0x1000u, + "input words are preserved"); + check(cfg.lowest > 0 && cfg.lowest < cfg.highest, "output VA range is non-empty (0 < lowest < highest)"); + + auto probe = std::make_unique(42); + const auto addr = reinterpret_cast(probe.get()); + check(addr >= cfg.lowest && addr <= cfg.highest, "a live user-space heap address lies within [lowest, highest]"); + + std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures); + return g_failures ? 1 : 0; +} diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 6af7ad8046..6f9113324e 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -208,6 +208,7 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { if (a1 == kFenceHandle) return static_cast(mock_create(m, Kind::fence, a2, a3)); if (a1 == kResourceHandle) return static_cast(mock_create(m, Kind::resource, a2, a3)); return static_cast(E_INVALIDARG); + case 25: return a1; // GetResourceAllocationInfo returns its hidden buffer pointer case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) @@ -1239,6 +1240,52 @@ int check_console_command_list() { return 0; } +// ---- 11. Beyond-PC Xbox device slots 81 (GetFrameStatisticsX), 86 (stream PSO), 108 (GetResourceAllocationInfo2) ---- + +int check_xbox_extended_slots() { + Mock* mock = nullptr; + void* device = make_device(mock, 11, true); + EXPECT(device != nullptr); + xs::reset_device_proxy_stats(); + + EXPECT(xs::device_slot_overridden(81) && xs::device_slot_overridden(86) && xs::device_slot_overridden(108)); + + // Slot 81: GetFrameStatisticsX(token, type_mask, &count, stats) sets count=0 and returns S_FALSE when no presenter + // is attached, and rejects a null count pointer with E_POINTER. + UINT stat_count = 4; + std::uint8_t stats[64]{}; + EXPECT(hr_of(raw(device, 81, 1, 7, word(&stat_count), word(stats))) == S_FALSE && stat_count == 0 && + mock->calls[81] == 0); + EXPECT(hr_of(raw(device, 81, 1, 7, 0, word(stats))) == E_POINTER); + + // Slot 86: CreatePipelineState (stream) routes to PC ID3D12Device2::CreatePipelineState (slot 47). + EXPECT(hr_of(raw(device, 86, 0x1111, 0x2222, 0x3333)) == S_OK); + EXPECT(mock->calls[86] == 0 && mock->calls[47] == 1 && mock->args[47][0] == 0x1111 && + mock->args[47][1] == 0x2222 && mock->args[47][2] == 0x3333); + + // Slot 108: GetResourceAllocationInfo2 routes to PC slot 25 in both PC and swapped Xbox order. + D3D12_RESOURCE_ALLOCATION_INFO alloc_out{}; + using Raw5 = std::uint64_t(WINAPI*)(std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t, std::uint64_t); + void** const vtbl = *static_cast(device); + EXPECT(reinterpret_cast(vtbl[108])(word(device), word(&alloc_out), 1, 2, 0x4444) == word(&alloc_out)); + EXPECT(mock->calls[25] == 1 && mock->args[25][0] == word(&alloc_out) && mock->args[25][1] == 1 && + mock->args[25][2] == 2 && mock->args[25][3] == 0x4444); + EXPECT(reinterpret_cast(vtbl[108])(word(&alloc_out), word(device), 0, 3, 0x5555) == word(&alloc_out)); + EXPECT(mock->calls[25] == 2 && mock->args[25][0] == word(&alloc_out) && mock->args[25][1] == 0 && + mock->args[25][2] == 3 && mock->args[25][3] == 0x5555); + EXPECT(release(device) == 0 && mock->refs == 0); + + // On a Device1-only mock (47 slots, predates ID3D12Device2), slot 86 refuses with E_NOTIMPL. + Mock* mock1 = nullptr; + void* dev1 = make_device(mock1, 1, true); + EXPECT(dev1 != nullptr); + EXPECT(hr_of(raw(dev1, 86, 0x1111, 0x2222, 0x3333)) == E_NOTIMPL && mock1->calls[47] == 0); + EXPECT(release(dev1) == 0 && mock1->refs == 0); + + std::printf("%s: extended Xbox device slots 81/86/108 passed\n", g_label); + return 0; +} + int main(int argc, char** argv) { no_dialogs(); std::setvbuf(stdout, nullptr, _IONBF, 0); @@ -1249,7 +1296,8 @@ int main(int argc, char** argv) { } if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list()) + check_alloc_failures() || check_allocators() || check_xbox_slots() || check_console_command_list() || + check_xbox_extended_slots()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0;