From eaf0b8d0c2136ed2d8ea8a7e0883529fa65439dd Mon Sep 17 00:00:00 2001 From: Brandon Strong Date: Wed, 25 Nov 2026 21:03:49 -0800 Subject: [PATCH] d3d12: keep the replay serial stack a plain thread_local 861bb0546 added geometry_execute_serials() as a function-local thread_local std::vector. A C++ thread_local with a destructor in gta6rt.exe adds TLS callbacks to the image, which the loader's TLS index-0 move must not have (pe_loader.cpp reserve_tls_index0; see VulkanContext::stage_xdxr_table). With it the title's CRT startup hits ucrtbase's one-shot _register_thread_local_exe_atexit_callback guard and terminates: 0xC0000409 (info0=7) at ~1.6 s, before any D3D12 call. Use a fixed aggregate instead: no destructor, no TLS callbacks, the same per-thread LIFO, bounded at 32 replays with overflow reported once. Tested: runtime builds; with LEONIDA_D3D12=vulkan the fix boots past startup and submits, while 0b11d86bc exits 0xC0000409 at ~1.5 s. NVIDIA RTX 4090, driver 616.64, Windows 11. AI-assisted (Claude Code). Co-Authored-By: Claude Code --- runtime/shims/d3d12_vulkan_device.cpp | 35 ++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index ae9fe37a59..2ae425a1aa 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -2601,19 +2601,42 @@ struct DeviceState { forget_geometry_alias); } // ExecuteCommandLists replays in progress, for GeometryViews::kAfterExecutes (see drain_geometry_releases). - static std::vector& geometry_execute_serials() { - thread_local std::vector serials; + // A plain aggregate on purpose: a C++ thread_local with a destructor in gta6rt.exe adds TLS callbacks to the image + // the loader's TLS index-0 move must not have (pe_loader.cpp reserve_tls_index0; VulkanContext::stage_xdxr_table + // keeps its range list a member for the same reason). A std::vector here made the title's CRT abort at startup. + struct GeometryExecuteSerials { + static constexpr unsigned kCapacity = 32; // a replay has not been seen nested this deep + std::uint64_t serials[kCapacity]{}; + unsigned count{}; + unsigned skipped{}; // replays begun while the stack was full: the innermost, ended first + }; + static GeometryExecuteSerials& geometry_execute_serials() { + thread_local GeometryExecuteSerials serials; return serials; } void geometry_execute_begin() { if (!geometry.cap()) return; - geometry_execute_serials().push_back(geometry.execute_begin()); + auto& serials = geometry_execute_serials(); + if (serials.count == GeometryExecuteSerials::kCapacity) { + static std::atomic logged{false}; + if (!logged.exchange(true)) + std::fprintf(stderr, "[rt] d3d12: ExecuteCommandLists nested more than %u deep; a geometry view retired " + "in the extra replay is not deferred to it\n", + GeometryExecuteSerials::kCapacity); + ++serials.skipped; + return; + } + serials.serials[serials.count++] = geometry.execute_begin(); } void geometry_execute_end() { + if (!geometry.cap()) return; auto& serials = geometry_execute_serials(); - if (!geometry.cap() || serials.empty()) return; - const std::uint64_t serial = serials.back(); - serials.pop_back(); + if (serials.skipped != 0) { + --serials.skipped; + return; + } + if (serials.count == 0) return; + const std::uint64_t serial = serials.serials[--serials.count]; geometry.execute_end(serial, [this] { return context->submitted_retire_ticket(); }); } static rt::d3d12::GeometryCopy copy_geometry(std::uint8_t* to, const std::uint8_t* from, std::size_t size) {