upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBrandon Strong <brandostrong@gmail.com>2026-11-25 21:03:49 -0800
committerBrandon Strong <brandostrong@gmail.com>2026-11-25 21:03:49 -0800
commiteaf0b8d0c2136ed2d8ea8a7e0883529fa65439dd (patch)
tree7203e4359f5a1238da641f85a5e0d3033429ac6f /runtime
parent0b11d86bc07a9be41aa28793eaa651bec768ddf6 (diff)
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_vulkan_device.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index ae9fe37a5..2ae425a1a 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -2601,19 +2601,42 @@ struct DeviceState {
2601 forget_geometry_alias); 2601 forget_geometry_alias);
2602 } 2602 }
2603 // ExecuteCommandLists replays in progress, for GeometryViews::kAfterExecutes (see drain_geometry_releases). 2603 // ExecuteCommandLists replays in progress, for GeometryViews::kAfterExecutes (see drain_geometry_releases).
2604 static std::vector<std::uint64_t>& geometry_execute_serials() { 2604 // A plain aggregate on purpose: a C++ thread_local with a destructor in gta6rt.exe adds TLS callbacks to the image
2605 thread_local std::vector<std::uint64_t> serials; 2605 // the loader's TLS index-0 move must not have (pe_loader.cpp reserve_tls_index0; VulkanContext::stage_xdxr_table
2606 // keeps its range list a member for the same reason). A std::vector here made the title's CRT abort at startup.
2607 struct GeometryExecuteSerials {
2608 static constexpr unsigned kCapacity = 32; // a replay has not been seen nested this deep
2609 std::uint64_t serials[kCapacity]{};
2610 unsigned count{};
2611 unsigned skipped{}; // replays begun while the stack was full: the innermost, ended first
2612 };
2613 static GeometryExecuteSerials& geometry_execute_serials() {
2614 thread_local GeometryExecuteSerials serials;
2606 return serials; 2615 return serials;
2607 } 2616 }
2608 void geometry_execute_begin() { 2617 void geometry_execute_begin() {
2609 if (!geometry.cap()) return; 2618 if (!geometry.cap()) return;
2610 geometry_execute_serials().push_back(geometry.execute_begin()); 2619 auto& serials = geometry_execute_serials();
2620 if (serials.count == GeometryExecuteSerials::kCapacity) {
2621 static std::atomic<bool> logged{false};
2622 if (!logged.exchange(true))
2623 std::fprintf(stderr, "[rt] d3d12: ExecuteCommandLists nested more than %u deep; a geometry view retired "
2624 "in the extra replay is not deferred to it\n",
2625 GeometryExecuteSerials::kCapacity);
2626 ++serials.skipped;
2627 return;
2628 }
2629 serials.serials[serials.count++] = geometry.execute_begin();
2611 } 2630 }
2612 void geometry_execute_end() { 2631 void geometry_execute_end() {
2632 if (!geometry.cap()) return;
2613 auto& serials = geometry_execute_serials(); 2633 auto& serials = geometry_execute_serials();
2614 if (!geometry.cap() || serials.empty()) return; 2634 if (serials.skipped != 0) {
2615 const std::uint64_t serial = serials.back(); 2635 --serials.skipped;
2616 serials.pop_back(); 2636 return;
2637 }
2638 if (serials.count == 0) return;
2639 const std::uint64_t serial = serials.serials[--serials.count];
2617 geometry.execute_end(serial, [this] { return context->submitted_retire_ticket(); }); 2640 geometry.execute_end(serial, [this] { return context->submitted_retire_ticket(); });
2618 } 2641 }
2619 static rt::d3d12::GeometryCopy copy_geometry(std::uint8_t* to, const std::uint8_t* from, std::size_t size) { 2642 static rt::d3d12::GeometryCopy copy_geometry(std::uint8_t* to, const std::uint8_t* from, std::size_t size) {