From 3b542ffbab2dea1fe930775179d7c20345183b05 Mon Sep 17 00:00:00 2001 From: DaniSBR1 <210478648+DaniSBR1@users.noreply.github.com> Date: Sun, 22 Nov 2026 23:27:38 -0600 Subject: [PATCH] xgameruntime: Series S by default on GPUs with less than 10 GiB of VRAM XSystemGetDeviceType reported Series X (Anaconda) unless LEONIDA_DEVICE_TYPE said otherwise. The package is one executable for both consoles, so on an 8 GB GPU the Series S profile is the one that fits. With LEONIDA_DEVICE_TYPE unset it now answers Lockhart (6) on a GPU with less than 10 GiB of VRAM, Series X's GPU-optimal memory, and Anaconda (7) otherwise or when the VRAM can't be read (runtime/src/device_profile.h). The VRAM is read once through DXGI's DedicatedVideoMemory (gta6rt builds without the Vulkan headers), for the GPU the runtime draws with: LEONIDA_VK_DEVICE by name, no software or Microsoft adapter, the most dedicated memory. The choice is logged once. XSystemGetAnalyticsInfo's form follows; XSystemGetAppMemoryUsageLimit is unchanged. The title reads the type through the registry value #3775 serves. Tests: xgameruntime_test (the rule, the default on the machine's GPU with the form matching, the override); tiny_game accepts 6 or 7 from the shim (the stub DLL answers 0). RX 5700 XT (8151 MiB), AMD 26.11.2, Windows 11: Series S; full ctest 173/173. Co-Authored-By: Claude Opus 5.5 --- runtime/README.md | 2 +- runtime/shims/xgameruntime.cpp | 53 +++++++++++++++++++++++++++-- runtime/src/device_profile.h | 28 +++++++++++++++ runtime/test/fixtures/tiny_game.cpp | 4 ++- runtime/test/xgameruntime_test.cpp | 27 +++++++++++++-- 5 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 runtime/src/device_profile.h diff --git a/runtime/README.md b/runtime/README.md index aace038d970..072fd51b71e 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -183,7 +183,7 @@ document names. | variable | default | what it changes | |---|---|---| -| `LEONIDA_DEVICE_TYPE` | `7` | The `XSystemDeviceType` that `XSystemGetDeviceType` returns: `0` Unknown, `1` Pc, `2` XboxOne, `3` XboxOneS, `4` XboxOneX, `5` XboxOneXDevkit, `6` XboxScarlettLockhart (Series S), `7` XboxScarlettAnaconda (Series X), `8` XboxScarlettDevkit. A number outside 0..8 is ignored; text that is not a number counts as `0`. `6` also makes `XSystemGetAnalyticsInfo` report the form `Xbox Series S` instead of `Xbox Series X`. | +| `LEONIDA_DEVICE_TYPE` | `6` under 10 GiB of VRAM, else `7` | The `XSystemDeviceType` that `XSystemGetDeviceType` returns. Unset, it is Series S (`6`) on a GPU with less than Series X's 10 GiB of GPU-optimal memory and Series X (`7`) otherwise or when the VRAM can't be read (`runtime/src/device_profile.h`; the GPU's DXGI `DedicatedVideoMemory`, with `LEONIDA_VK_DEVICE` picking among several), and the runtime logs which and why. Values: `0` Unknown, `1` Pc, `2` XboxOne, `3` XboxOneS, `4` XboxOneX, `5` XboxOneXDevkit, `6` XboxScarlettLockhart (Series S), `7` XboxScarlettAnaconda (Series X), `8` XboxScarlettDevkit. A number outside 0..8 is ignored; text that is not a number counts as `0`. `6` also makes `XSystemGetAnalyticsInfo` report the form `Xbox Series S` instead of `Xbox Series X`. | | `LEONIDA_ANALYTICS_FORM` | unset | The `form` string of `XSystemGetAnalyticsInfo`, in place of the one the device type gives (up to 63 characters). | | `LEONIDA_PACKAGE_ID` | `LeonidaPackageIdentifier00000000` | The identifier `XPackageGetCurrentProcessPackageIdentifier` returns (up to 32 characters). It is also the one identifier `XPackageMount` refuses with `E_ACCESSDENIED`, as the game's own package. | | `LEONIDA_CONTENT_PACKAGES` | unset | The content packages `XPackageMount` can mount: `id1=path1;id2=path2` (up to 1,023 characters). The mount path of a listed identifier is its path, as written; any other identifier is `ERROR_NOT_FOUND`, and a path longer than 259 characters is `ERROR_INSUFFICIENT_BUFFER`. | diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index f6a8ec17524..db814143762 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp @@ -11,6 +11,7 @@ // "xgameruntime.dll" is the name the PC GDK uses. If the executable's import table names another module, register // the same functions under that name too; nothing else changes. #include +#include #include #include @@ -33,6 +34,8 @@ #include "file_system.h" #include "shims.h" +#include "../src/device_profile.h" +#include "../src/vulkan_device_filter.h" namespace rt::shims { bool xgameruntime_user_query(const GUID& class_id, REFIID interface_id, void** out, HRESULT* hr); @@ -546,8 +549,43 @@ enum class XSystemDeviceType : uint32_t { XboxScarlettLockhart = 6, XboxScarlettAnaconda = 7, XboxScarlettDevkit = 8, }; -// XSystemDeviceType XSystemGetDeviceType(). The package is the Xbox Series build, so report Series X (Anaconda). -// LEONIDA_DEVICE_TYPE=<0..8> overrides it, for trying other code paths on day one. +// The dedicated video memory of the GPU the runtime draws with, in bytes; 0 when it can't be read. Read once, through +// DXGI, which needs no Vulkan headers here and can answer before the title creates its device: DedicatedVideoMemory +// is the GPU's largest DEVICE_LOCAL heap, the value the layer's own IDXGIAdapter (dxgi_com.cpp) reports. The GPU is +// the runtime's: LEONIDA_VK_DEVICE filters by name, software and Microsoft adapters are left out (vulkan_device_rank +// puts them last), and the one with the most dedicated memory wins, the discrete GPU on a machine with an iGPU too. +std::uint64_t runtime_gpu_vram() { + static const std::uint64_t bytes = [] { + using CreateFactory = HRESULT(WINAPI*)(REFIID, void**); + const HMODULE dxgi = LoadLibraryW(L"dxgi.dll"); + const auto create = dxgi ? reinterpret_cast( + reinterpret_cast(GetProcAddress(dxgi, "CreateDXGIFactory1"))) + : nullptr; + IDXGIFactory1* factory = nullptr; + if (!create || FAILED(create(__uuidof(IDXGIFactory1), reinterpret_cast(&factory)))) + return std::uint64_t(0); + std::uint64_t best = 0; + IDXGIAdapter1* adapter = nullptr; + for (UINT i = 0; factory->EnumAdapters1(i, &adapter) == S_OK; ++i) { + DXGI_ADAPTER_DESC1 desc{}; + if (SUCCEEDED(adapter->GetDesc1(&desc)) && !(desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) && + desc.VendorId != leonida::microsoft_vulkan_vendor_id) { + char name[128 * 4] = {}; + WideCharToMultiByte(CP_UTF8, 0, desc.Description, -1, name, int(sizeof(name)), nullptr, nullptr); + if (leonida::vulkan_device_wanted(name)) + best = std::max(best, desc.DedicatedVideoMemory); + } + adapter->Release(); + } + factory->Release(); + return best; + }(); + return bytes; +} + +// XSystemDeviceType XSystemGetDeviceType(). The package is the Xbox Series build, one executable for both consoles: +// Series S (Lockhart) on a GPU with less than Series X's 10 GB of GPU-optimal memory, Series X (Anaconda) otherwise +// or when the VRAM can't be read (device_profile.h). LEONIDA_DEVICE_TYPE=<0..8> overrides it. uint32_t __stdcall XSystemGetDeviceType() { char s[16]; const DWORD n = GetEnvironmentVariableA("LEONIDA_DEVICE_TYPE", s, sizeof(s)); @@ -555,7 +593,16 @@ uint32_t __stdcall XSystemGetDeviceType() { int v = std::atoi(s); if (v >= 0 && v <= 8) return static_cast(v); } - return static_cast(XSystemDeviceType::XboxScarlettAnaconda); + const std::uint64_t vram = runtime_gpu_vram(); + const std::uint32_t type = leonida::default_device_type(vram); + static std::atomic logged{false}; + if (!logged.exchange(true, std::memory_order_relaxed)) + std::fprintf(stderr, "[rt] xgameruntime: reporting Xbox Series %s: the GPU has %llu MiB of VRAM%s " + "(LEONIDA_DEVICE_TYPE=6 or 7 picks Series S or X)\n", + type == leonida::device_type_lockhart ? "S" : "X", + static_cast(vram >> 20), + !vram ? " (unknown)" : type == leonida::device_type_lockhart ? ", less than 10 GiB" : ""); + return type; } // HRESULT XSystemGetConsoleId(size_t consoleIdSize, char* consoleId, size_t* consoleIdUsed). diff --git a/runtime/src/device_profile.h b/runtime/src/device_profile.h new file mode 100644 index 00000000000..bcbcb0c090f --- /dev/null +++ b/runtime/src/device_profile.h @@ -0,0 +1,28 @@ +#pragma once + +// Which console the runtime says it is, when LEONIDA_DEVICE_TYPE doesn't name one (shims/xgameruntime.cpp). +// +// The package is the Xbox Series build, one executable for both consoles, so the title reads the console type at run +// time to pick its profile. Series X (Anaconda) has 10 GB of GPU-optimal memory; Series S (Lockhart) is the profile +// a GPU with less VRAM can hold, the 8 GB cards among them (RX 5700 XT, RTX 3060 Ti, RTX 3070). With the GPU's VRAM +// unknown (0), the answer stays Series X, as before. +// +// No Windows, Vulkan or third-party headers. + +#include + +namespace leonida { + +// XSystemDeviceType values (the order of the public documentation). +inline constexpr std::uint32_t device_type_lockhart = 6; // Xbox Series S +inline constexpr std::uint32_t device_type_anaconda = 7; // Xbox Series X + +// Series X's GPU-optimal memory: a GPU with less VRAM gets the Series S profile. +inline constexpr std::uint64_t series_x_gpu_memory = std::uint64_t(10) << 30; + +// The device type for a GPU with `vram` bytes of dedicated video memory (0: unknown). +inline std::uint32_t default_device_type(std::uint64_t vram) { + return vram && vram < series_x_gpu_memory ? device_type_lockhart : device_type_anaconda; +} + +} // namespace leonida diff --git a/runtime/test/fixtures/tiny_game.cpp b/runtime/test/fixtures/tiny_game.cpp index dabe29c25d1..274832074fb 100644 --- a/runtime/test/fixtures/tiny_game.cpp +++ b/runtime/test/fixtures/tiny_game.cpp @@ -85,7 +85,9 @@ int main(int argc, char** argv) { check(sum == 500500, "a second thread ran and joined"); check(XGameRuntimeInitialize() == S_OK, "XGameRuntimeInitialize is answered by the gta6rt shim (S_OK)"); - check(XSystemGetDeviceType() == 7, "XSystemGetDeviceType is answered by the gta6rt shim (Series X)"); + // Series S (6) or X (7), by the GPU's VRAM; the stub DLL a host would load answers 0. + const uint32_t device_type = XSystemGetDeviceType(); + check(device_type == 6 || device_type == 7, "XSystemGetDeviceType is answered by the gta6rt shim (Series S or X)"); XGameRuntimeUninitialize(); if (has_arg(argc, argv, "tls")) { diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index 5102c54ab41..78f550076a9 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp @@ -23,6 +23,9 @@ #include "file_system.h" #include "shims.h" +#include "../src/device_profile.h" + +#include namespace { @@ -730,7 +733,18 @@ int main() { check(init() == S_OK, "XGameRuntimeInitialize returns S_OK"); check(init() == S_OK, "a second XGameRuntimeInitialize also returns S_OK (reference counted)"); - check(get("XSystemGetDeviceType")() == 7, "XSystemGetDeviceType reports XboxScarlettAnaconda (7)"); + // The console type: Series S under 10 GiB of VRAM, Series X from it or when it's unknown (device_profile.h). + check(leonida::default_device_type(std::uint64_t(8) << 30) == 6 && + leonida::default_device_type(std::uint64_t(4) << 30) == 6, + "a GPU with 4 or 8 GiB of VRAM gets XboxScarlettLockhart (6)"); + check(leonida::default_device_type(std::uint64_t(10) << 30) == 7 && + leonida::default_device_type(std::uint64_t(16) << 30) == 7, + "a GPU with 10 or 16 GiB of VRAM gets XboxScarlettAnaconda (7)"); + check(leonida::default_device_type(0) == 7, "unknown VRAM keeps XboxScarlettAnaconda (7)"); + SetEnvironmentVariableA("LEONIDA_DEVICE_TYPE", nullptr); + const uint32_t device_type = get("XSystemGetDeviceType")(); + std::printf("XSystemGetDeviceType on this machine's GPU: %u\n", device_type); + check(device_type == 6 || device_type == 7, "XSystemGetDeviceType reports Series S (6) or Series X (7) by default"); auto console_id = get("XSystemGetConsoleId"); char id[64] = {}; @@ -749,7 +763,16 @@ int main() { info.hostingOsVersion.build == 22000 && info.hostingOsVersion.revision == 0, "XSystemGetAnalyticsInfo returns hostingOsVersion 10.0.22000.0"); check(std::strcmp(info.family, "Xbox") == 0, "XSystemGetAnalyticsInfo returns family 'Xbox'"); - check(std::strcmp(info.form, "Xbox Series X") == 0, "XSystemGetAnalyticsInfo returns form 'Xbox Series X'"); + check(std::strcmp(info.form, device_type == 6 ? "Xbox Series S" : "Xbox Series X") == 0, + "XSystemGetAnalyticsInfo's form follows the default device type"); + // LEONIDA_DEVICE_TYPE still decides, whatever the GPU, and the form follows it. + for (const auto& [value, want, form] : + {std::tuple{"7", 7u, "Xbox Series X"}, std::tuple{"6", 6u, "Xbox Series S"}}) { + SetEnvironmentVariableA("LEONIDA_DEVICE_TYPE", value); + check(get("XSystemGetDeviceType")() == want && std::strcmp(analytics_info().form, form) == 0, + "LEONIDA_DEVICE_TYPE picks the device type and the analytics form"); + } + SetEnvironmentVariableA("LEONIDA_DEVICE_TYPE", nullptr); auto package_id = get("XPackageGetCurrentProcessPackageIdentifier"); check(package_id(0, nullptr) == E_INVALIDARG, "XPackageGetCurrentProcessPackageIdentifier rejects null buffer and size 0");