Repository navigation
runtime: remove TLS-0 static init guards and thread_local in d3d12_vulkan_device, d3d12_com, queue_holds and shader_library - #8364
Open
whoalin1 wants to merge 1 commit into
Conversation
…kan D3D12 runtime Co-authored-by: Gemini <noreply@google.com>
1 task done
3 tasks done
|
Tested
|
|
Tested
AI-assisted (Claude Code). |
2 tasks done
|
Tested 9fe1e2e on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo, applied on
(AI-assisted check, Claude Code.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claim: #8186 (comment)
Why this blocks retail EXE execution
When the mapped retail executable owns static TLS index 0 (#4313), guest threads run with
TEB->ThreadLocalStoragePointer[0]holding guest TLS data instead of the host CRT's_Init_thread_epoch. Under a zeroed guest TLS block (epoch == 0), MSVC's$TSS > _Init_thread_epoch(0 > 0) check skips initialization of function-local dynamic statics, whilethread_localvariables index directly into the guest's TLS slot-0 memory.This PR removes the remaining TLS-slot-0 dependencies across the four core Vulkan D3D12 runtime files not covered by
#7175,#7198,#7359,#7824,#7957,#8178,#8195, orsvds12343'sJsonReaderLC_NUMERICitem:runtime/src/queue_holds.h: replacestatic thread_local bool pumpinginQueueHolds::in_pump()with a per-instancestd::atomic<std::thread::id> pump_thread_{}and RAIIPumpScope(#include <thread>), avoiding reads/writes to guest TLS slot 0 on every queue fence signal/pump.runtime/src/shader_library.h: replace the function-localstatic const auto tablesinzlib_inflate()(BTYPE=1fixed Huffman) withinline constexprdetail::build_huffman+detail::kFixedHuffmanTables.runtime/shims/d3d12_com.cpp: replace function-localstatic std::mutex/static std::setinrt::d3d12::stub()andnote_once()with constant-initializedSRWLOCK(SRWLOCK_INIT) and lazily allocated sets.runtime/shims/d3d12_vulkan_device.cpp: replace function-local dynamic statics inlog_once(),report_subgroup_unavailable(),process_shader_cache_registry()(OpenShaderCacheSession/CreateShaderCacheSession), andcreate_vulkan_device_standalone()(load_vulkan_library()) withSRWLOCK(SRWLOCK_INIT) and acquire/releasestd::atomic.Verification (synthetic only, no game files)
runtime/test/d3d12_tls_safe_test.cpp(CTestd3d12_tls_safe), which swapsTEB->ThreadLocalStoragePointer[0]to aPAGE_READONLYzero page (re-readingTEBon teardown ifLoadLibraryexpands the TLS pointer array) and a writable0xA5canary page, exercising fixed-Huffmanzlib_inflate, concurrentrt::d3d12::stub,QueueHolds,create_vulkan_device_standalone,ID3D12Device9::CreateShaderCacheSession,CheckFeatureSupport(log_once),ExecuteCommandLists(1, nullptr)(note_once), andRSSetViewports(2, ...)(stub).origin/maindde82f27e):d3d12_tls_safe_test.exefailed (rc=1,FAIL line 109: leonida::zlib_inflate(kFixedHuffmanStream, out)because$TSS1 > 0skipped fixed-Huffman table construction).dumpbin /SYMBOLS(RelWithDebInfo):d3d12_com.cpp.obj: removed_Init_thread_header,_tls_index,$TSS0(stub,note_once), andpumping->0_Init_thread_header/_tls_index/$TSShits remain.d3d12_vulkan_device.cpp.obj: removed_Init_thread_header,_tls_index,$TSS0/$TSS1(zlib_inflate,log_once,report_subgroup_unavailable,process_shader_cache_registry,create_vulkan_device_standalone), andpumping->0_Init_thread_header/_tls_index/$TSShits remain.shader_library_test.cpp.obj:3hits (_Init_thread_header,$TSS1,_tls_index) ->0hits.LEONIDA_VK_VALIDATION=1,VK_LOADER_LAYERS_DISABLE=~implicit~):shader_library_test.exe->rc=0.*nv-vk*,4070):d3d12_tls_safe_test.exe(rc=0),d3d12_com_test.exe(rc=0),d3d12_shader_cache_test.exe(rc=0), 0 validation errors.*amd-vulkan*,radeon):d3d12_tls_safe_test.exe(rc=0),d3d12_com_test.exe(rc=0),d3d12_shader_cache_test.exe(rc=0), 0 validation errors.git diff --check origin/main: clean (rc=0).tests/test_runtime_paths.py: 4/5 passed, 1 pre-existingmainfailure (tools/replace_retry.py: missing).AI-assisted.