From ad6045b806173a44b2710174d2403f7ccef76b64 Mon Sep 17 00:00:00 2001 From: quartz-heron-58 <245169279+quartz-heron-58@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:53:41 +0800 Subject: [PATCH] d3d12_xs: say so when LEONIDA_D3D12=vulkan is asked of a runtime built without the Vulkan device (RT-VULKAN-REQUESTED-NOT-BUILT) A gta6rt configured without Vulkan headers is built without LEONIDA_VULKAN_DEVICE. D3D12XboxCreateDevice then ignored LEONIDA_D3D12=vulkan without a word and wrapped the host's D3D12 device, so a run stopped somewhere else and read like a boot result. It now prints one [rt] d3d12_xs line naming the cause and the configure options. Which device is created does not change. The reading of the variable moves to shims/d3d12_backend.h, used by both builds; new CPU-only test d3d12_backend, registered outside the Vulkan-headers block. Co-Authored-By: Claude Fable 5.2 --- docs/boot.md | 4 +-- runtime/CMakeLists.txt | 7 +++++ runtime/shims/d3d12_backend.h | 23 ++++++++++++++++ runtime/shims/d3d12_xs.cpp | 17 ++++++++++-- runtime/test/d3d12_backend_test.cpp | 41 +++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 runtime/shims/d3d12_backend.h create mode 100644 runtime/test/d3d12_backend_test.cpp diff --git a/docs/boot.md b/docs/boot.md index 3ba791f88..47996e0b1 100644 --- a/docs/boot.md +++ b/docs/boot.md @@ -83,8 +83,8 @@ fresh name or delete the old one. `LEONIDA_D3D12=vulkan` selects the Vulkan-back traces command lists, resources and pipelines; without it the layer uses the Windows D3D12 device, and the `[d3d12-trace]` lines are only what the Xbox-ABI proxy forwards (device creation, queue, fence and allocator calls), which `boot_trace.py` summarizes without complaint. A run on the Vulkan device prints -`[rt] d3d12: Vulkan device: `; check the log for it (a runtime built without the Vulkan headers accepts the -variable and stays on the Windows device). Keep the traces out of the repository: they can quote whatever the game prints. +`[rt] d3d12: Vulkan device: `; check the log for it (a runtime built without the Vulkan headers stays on the Windows +device and says so in one `[rt] d3d12_xs: LEONIDA_D3D12=vulkan is set, but ...` line). Keep the traces out of the repository: they can quote whatever the game prints. Useful switches: diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index b8d284d6e..c977b1c2b 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -1892,6 +1892,13 @@ if(NOT TARGET Vulkan::Headers) FetchContent_MakeAvailable(VulkanHeaders) endif() endif() +# LEONIDA_D3D12=vulkan asked of a runtime with no Vulkan-backed device (shims/d3d12_backend.h). Outside the block +# below on purpose: a configure without the Vulkan headers is the case it is about. +add_executable(d3d12_backend_test test/d3d12_backend_test.cpp) +if(WIN32 AND MSVC) + target_compile_options(d3d12_backend_test PRIVATE /W4 /permissive- /utf-8) +endif() +add_test(NAME d3d12_backend COMMAND d3d12_backend_test) if(TARGET Vulkan::Headers) add_executable(vulkan_device_fault_test test/vulkan_device_fault_test.cpp) target_link_libraries(vulkan_device_fault_test PRIVATE Vulkan::Headers) diff --git a/runtime/shims/d3d12_backend.h b/runtime/shims/d3d12_backend.h new file mode 100644 index 000000000..7bba99dc5 --- /dev/null +++ b/runtime/shims/d3d12_backend.h @@ -0,0 +1,23 @@ +// Which device D3D12XboxCreateDevice puts behind the Xbox-ABI proxy, as LEONIDA_D3D12 asks (RT-VULKAN-REQUESTED-NOT-BUILT). +// Header only, so the test needs neither a device nor the Vulkan headers. +#pragma once + +#include + +namespace rt::d3d12_xs::backend { + +// LEONIDA_D3D12=vulkan, exactly: the one value that selects the Vulkan-backed device. +inline bool vulkan_requested(const char* value) { return value && std::strcmp(value, "vulkan") == 0; } + +// What to tell the user when the variable asks for the Vulkan-backed device and this runtime has none, else null. +// A runtime configured without the Vulkan headers is built without LEONIDA_VULKAN_DEVICE: it used to take the variable +// without a word and run the title on the host's D3D12 device, which stops somewhere else and looks like a boot result. +inline const char* vulkan_not_built_note(const char* value, bool vulkan_built) { + if (vulkan_built || !vulkan_requested(value)) return nullptr; + return "LEONIDA_D3D12=vulkan is set, but this runtime was built without the Vulkan-backed device (its configure " + "found no Vulkan headers), so the title gets the host's D3D12 device instead. Configure again with " + "VULKAN_SDK set or -DLEONIDA_VULKAN_HEADERS_FETCH=ON; -DLEONIDA_REQUIRE_VULKAN=ON makes a configure " + "without the headers fail"; +} + +} // namespace rt::d3d12_xs::backend diff --git a/runtime/shims/d3d12_xs.cpp b/runtime/shims/d3d12_xs.cpp index a6c7934e4..b584b0407 100644 --- a/runtime/shims/d3d12_xs.cpp +++ b/runtime/shims/d3d12_xs.cpp @@ -20,6 +20,7 @@ #ifdef LEONIDA_VULKAN_DEVICE #include "d3d12_com.h" #endif +#include "d3d12_backend.h" #include "d3d12_trace.h" #include "d3d12_xs_device.h" #include "d3d12_xs_rootsig.h" @@ -198,12 +199,24 @@ HRESULT WINAPI D3D12XboxCreateDevice(IUnknown* adapter, const void* params, cons const bool pc_lists = getenv_s(&lists_length, lists_mode, "LEONIDA_D3D12_LISTS") == 0 && std::strcmp(lists_mode, "pc") == 0; -#ifdef LEONIDA_VULKAN_DEVICE // Opt-in until the Vulkan device covers the first frame: LEONIDA_D3D12=vulkan puts the Vulkan-backed device // behind the same proxy instead of the host's D3D12 device. char backend[16] = {}; size_t backend_length = 0; - if (getenv_s(&backend_length, backend, "LEONIDA_D3D12") == 0 && std::strcmp(backend, "vulkan") == 0) { + const bool backend_read = getenv_s(&backend_length, backend, "LEONIDA_D3D12") == 0; +#ifdef LEONIDA_VULKAN_DEVICE + constexpr bool vulkan_built = true; +#else + constexpr bool vulkan_built = false; +#endif + // A runtime configured without the Vulkan headers has no such device: say so once instead of running the title on + // the host's device as if nothing had been asked. + if (const char* note = rt::d3d12_xs::backend::vulkan_not_built_note(backend_read ? backend : nullptr, vulkan_built)) { + static std::atomic noted{false}; + if (!noted.exchange(true, std::memory_order_relaxed)) std::fprintf(stderr, "[rt] d3d12_xs: %s\n", note); + } +#ifdef LEONIDA_VULKAN_DEVICE + if (backend_read && rt::d3d12_xs::backend::vulkan_requested(backend)) { ID3D12Device* vulkan = nullptr; HRESULT vhr = rt::d3d12::create_vulkan_device_standalone( __uuidof(ID3D12Device), reinterpret_cast(&vulkan), rt::d3d12::QueueTestSettings::ignore); diff --git a/runtime/test/d3d12_backend_test.cpp b/runtime/test/d3d12_backend_test.cpp new file mode 100644 index 000000000..51c9a1e51 --- /dev/null +++ b/runtime/test/d3d12_backend_test.cpp @@ -0,0 +1,41 @@ +// d3d12_backend.h (RT-VULKAN-REQUESTED-NOT-BUILT): LEONIDA_D3D12=vulkan in a runtime that has no Vulkan-backed device +// gets a note; every other case gets none. CPU only: no device, no Vulkan headers, no game file. +#include "../shims/d3d12_backend.h" + +#include +#include + +namespace backend = rt::d3d12_xs::backend; + +static int failures = 0; +static void check(bool condition, const char* what) { + std::printf("%s %s\n", condition ? "PASS" : "FAIL", what); + if (!condition) ++failures; +} + +int main() { + check(backend::vulkan_requested("vulkan"), "requested: vulkan"); + check(!backend::vulkan_requested(nullptr), "requested: the variable is not set"); + check(!backend::vulkan_requested(""), "requested: an empty value"); + check(!backend::vulkan_requested("Vulkan"), "requested: another case is another value, as the device branch reads it"); + check(!backend::vulkan_requested("vulkan "), "requested: a trailing space is another value"); + check(!backend::vulkan_requested("host"), "requested: another backend name"); + + const char* note = backend::vulkan_not_built_note("vulkan", false); + check(note != nullptr, "note: vulkan asked of a runtime without the device"); + check(note && std::strstr(note, "LEONIDA_D3D12=vulkan") && std::strstr(note, "host's D3D12 device"), + "note: names the variable and the device the title gets"); + check(note && std::strstr(note, "LEONIDA_VULKAN_HEADERS_FETCH") && std::strstr(note, "LEONIDA_REQUIRE_VULKAN") && + std::strstr(note, "VULKAN_SDK"), + "note: names the ways to get the headers and the option that fails the configure"); + + check(backend::vulkan_not_built_note("vulkan", true) == nullptr, "note: none when the device is built in"); + check(backend::vulkan_not_built_note(nullptr, false) == nullptr, "note: none when the variable is not set"); + check(backend::vulkan_not_built_note("", false) == nullptr, "note: none for an empty value"); + check(backend::vulkan_not_built_note("Vulkan", false) == nullptr, + "note: none for a value the Vulkan build would not take either"); + check(backend::vulkan_not_built_note(nullptr, true) == nullptr, "note: none, device built in and nothing asked"); + + std::printf("%d failures\n", failures); + return failures ? 1 : 0; +}