[PR #768] [CLOSED] OLD-8364: runtime: remove TLS-0 static init guards and thread_local in core Vulkan D3D12 runtime #807

Closed
opened 2026-11-26 20:19:06 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/768
Author: @whoalin1
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: d3d12-tls0-static-guards


📝 Commits (1)

  • 6f9252b runtime: remove TLS-0 static init guards and thread_local in core Vulkan D3D12 runtime

📊 Changes

13 files changed (+652 additions, -78 deletions)

View changed files

📝 runtime/CMakeLists.txt (+8 -0)
📝 runtime/shims/d3d12_com.cpp (+24 -8)
📝 runtime/shims/d3d12_pipeline_compile.h (+13 -2)
📝 runtime/shims/d3d12_vulkan_device.cpp (+69 -18)
📝 runtime/src/fsdraw_probe.h (+10 -2)
📝 runtime/src/queue_holds.h (+26 -13)
📝 runtime/src/shader_library.h (+26 -15)
📝 runtime/src/title_page_watch.h (+15 -7)
📝 runtime/src/title_va_alias.h (+13 -2)
📝 runtime/src/vulkan_aftermath.cpp (+2 -1)
📝 runtime/src/vulkan_aftermath.h (+67 -4)
📝 runtime/src/vulkan_indirect_clamp.h (+13 -6)
➕ runtime/test/d3d12_tls_safe_test.cpp (+366 -0)

📄 Description

Restores my open PR from the original repository (OLD-8364), rebased onto current main (2d73c242f, updated for ZlibError return from inflate_codes and kRev4 constexpr placement).

Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133003627

Summary

When guest retail threads run with their own TLS block in gs:[0x58] slot 0, MSVC function-local magic statics (_Init_thread_header / _tls_index / $TSS) and thread_local variables crash on first touch inside D3D12 runtime calls.

This PR removes all MSVC static initialization guards and thread_local uses from the core Vulkan D3D12 runtime and adds a TLS-slot-0-poisoned regression test:

  • runtime/shims/d3d12_vulkan_device.cpp: replaces function-local magic statics and thread_local with TLS-0-safe INIT_ONCE / lock-free initialization.
  • runtime/shims/d3d12_com.cpp: removes function-local static std::mutex / static std::set guards in log_once / note_once.
  • runtime/src/queue_holds.h: eliminates thread_local / magic-static TLS-slot-0 dependencies.
  • runtime/src/shader_library.h: promotes deflate fixed Huffman tables (kFixedHuffmanTables) and kRev4 to inline constexpr at namespace scope so fixed-Huffman zlib inflation never emits a function-local static init guard.
  • runtime/test/d3d12_tls_safe_test.cpp & runtime/CMakeLists.txt: adds d3d12_tls_safe test that poisons TLS slot 0 before exercising device creation, shader cache, log_once, note_once, and unimplemented-stub logging across threads.

Verification (rebased on 2d73c242f, LEONIDA_VK_VALIDATION=1)

  • dumpbin /SYMBOLS on d3d12_vulkan_device.cpp.obj and d3d12_com.cpp.obj: 0 hits for _Init_thread_header, _tls_index, or $TSS
  • CPU: shader_library_test — pass (rc=0)
  • NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88):
    • d3d12_tls_safe_test (rc=0, 0 validation errors)
    • d3d12_com_test (rc=0, 0 validation errors)
    • d3d12_shader_cache_test (rc=0, 0 validation errors)
  • AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, driver 24.10.24, 128B push constants):
    • d3d12_tls_safe_test (rc=0, 0 validation errors)
    • d3d12_com_test (rc=0, 0 validation errors)
    • d3d12_shader_cache_test (rc=0, 0 validation errors)

AI-assisted (Gemini 4 Neon).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/768 **Author:** [@whoalin1](https://github.com/whoalin1) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `d3d12-tls0-static-guards` --- ### 📝 Commits (1) - [`6f9252b`](https://github.com/ubiquitarianism/leonida/commit/6f9252bc85f52633cf0cee4f8d56da5086cf45be) runtime: remove TLS-0 static init guards and thread_local in core Vulkan D3D12 runtime ### 📊 Changes **13 files changed** (+652 additions, -78 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+8 -0) 📝 `runtime/shims/d3d12_com.cpp` (+24 -8) 📝 `runtime/shims/d3d12_pipeline_compile.h` (+13 -2) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+69 -18) 📝 `runtime/src/fsdraw_probe.h` (+10 -2) 📝 `runtime/src/queue_holds.h` (+26 -13) 📝 `runtime/src/shader_library.h` (+26 -15) 📝 `runtime/src/title_page_watch.h` (+15 -7) 📝 `runtime/src/title_va_alias.h` (+13 -2) 📝 `runtime/src/vulkan_aftermath.cpp` (+2 -1) 📝 `runtime/src/vulkan_aftermath.h` (+67 -4) 📝 `runtime/src/vulkan_indirect_clamp.h` (+13 -6) ➕ `runtime/test/d3d12_tls_safe_test.cpp` (+366 -0) </details> ### 📄 Description Restores my open PR from the original repository (OLD-8364), rebased onto current `main` (`2d73c242f`, updated for `ZlibError` return from `inflate_codes` and `kRev4` constexpr placement). Claim: https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133003627 ### Summary When guest retail threads run with their own TLS block in `gs:[0x58]` slot 0, MSVC function-local magic statics (`_Init_thread_header` / `_tls_index` / `$TSS`) and `thread_local` variables crash on first touch inside D3D12 runtime calls. This PR removes all MSVC static initialization guards and `thread_local` uses from the core Vulkan D3D12 runtime and adds a TLS-slot-0-poisoned regression test: - `runtime/shims/d3d12_vulkan_device.cpp`: replaces function-local magic statics and `thread_local` with TLS-0-safe `INIT_ONCE` / lock-free initialization. - `runtime/shims/d3d12_com.cpp`: removes function-local `static std::mutex` / `static std::set` guards in `log_once` / `note_once`. - `runtime/src/queue_holds.h`: eliminates `thread_local` / magic-static TLS-slot-0 dependencies. - `runtime/src/shader_library.h`: promotes deflate fixed Huffman tables (`kFixedHuffmanTables`) and `kRev4` to `inline constexpr` at namespace scope so fixed-Huffman zlib inflation never emits a function-local static init guard. - `runtime/test/d3d12_tls_safe_test.cpp` & `runtime/CMakeLists.txt`: adds `d3d12_tls_safe` test that poisons TLS slot 0 before exercising device creation, shader cache, `log_once`, `note_once`, and unimplemented-stub logging across threads. ### Verification (rebased on `2d73c242f`, `LEONIDA_VK_VALIDATION=1`) - **`dumpbin /SYMBOLS`** on `d3d12_vulkan_device.cpp.obj` and `d3d12_com.cpp.obj`: **0** hits for `_Init_thread_header`, `_tls_index`, or `$TSS` - **CPU**: `shader_library_test` — pass (`rc=0`) - **NVIDIA GeForce RTX 4070 SUPER (Windows 11, driver 610.88)**: - `d3d12_tls_safe_test` (`rc=0`, 0 validation errors) - `d3d12_com_test` (`rc=0`, 0 validation errors) - `d3d12_shader_cache_test` (`rc=0`, 0 validation errors) - **AMD Radeon(TM) Graphics (Ryzen 5 7600 RDNA2 iGPU, Windows 11, driver 24.10.24, 128B push constants)**: - `d3d12_tls_safe_test` (`rc=0`, 0 validation errors) - `d3d12_com_test` (`rc=0`, 0 validation errors) - `d3d12_shader_cache_test` (`rc=0`, 0 validation errors) AI-assisted (Gemini 4 Neon). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:06 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#807
No description provided.