WIP: fix(vk): keep TLS initialization coherent under COFF ThinLTO #755

Draft
siantm wants to merge 1 commit from siantm/Longshot:fix/coff-thinlto-tls into main
First-time contributor

Type: fix · Risk: medium · Tested on: Windows 11 Pro 26300, LLVM-MinGW 23.1.5, game-free · Needs: recorder-sync completion, full suite and Linux verification

Why

Windows COFF ThinLTO can fail to link the profiler and recorder's inline thread-local initialization routines. This fixes ownership and initialization without enabling ThinLTO or claiming an FPS improvement.

How to reproduce

Seen on: Windows 11 Pro 26300, LLVM-MinGW Clang 23.1.5 and lld.
Settings and switches: C++20 O2; native and -flto=thin, static runtime.
Steps: run python -I -B tests/test_thinlto_tls.py --cxx x86_64-w64-mingw32-clang++ --source-ref 9e6f231d, then the same command without --source-ref on this branch.
Expected: both consumers link and preserve cross-TU identity, per-thread separation and queued cleanup.
Actual: main's native arm succeeds; ThinLTO fails on initialization symbols for mkwvk::prof_t and mkwvk::rec::t_arena.

What changed

Constant-initialize profiler POD TLS and give the recorder arena function-local thread-local ownership. Migrate every arena consumer and preserve destruction-time draining.

  • gpu/vk/vk_internal.h, gpu/vk/vk_recorder.h: focused production fix from local 073ed616.
  • tests/test_thinlto_tls.py: compile real profiler/recorder consumers across translation units, with a baseline adapter.
  • Recorder fixture callers and development documentation follow the accessor.

Measurements

Verdict: main fails during ThinLTO linking; the patched native and ThinLTO consumers pass.
Hardware: Windows 11 Pro 26300, Intel Core i7-9700, 31.8 GiB usable RAM; Python 3.14.7, LLVM-MinGW 23.1.5; no GPU used.
Method: the same authored cross-TU consumer against main and the prepared implementation.

Check Before: main @ 9e6f231d After: this PR @ 484daadbcd
Native consumer Pass Pass
COFF ThinLTO link Undefined TLS initialization routines Pass
Cross-TU/thread ownership and Enc exit drain Native arm passes; ThinLTO cannot run Native and ThinLTO pass

Observed patched output: PASS: native/ThinLTO production cross-TU TLS identity, thread isolation and Enc exit drain. Profiler sampling/exact-mode checks pass, as do recorder own/idle's 22 switch cases and deliberately broken variants. The checks ran on the source snapshot committed as 484daadbcd before browser submission.

Flags and settings

None. Production optimization defaults do not change; this does not enable the broader local ThinLTO experiment.

Testing

Tested: baseline/branch TLS comparison, profiler sampling/exact mode, recorder own/idle; run record accepted by the actual catalogue renderer.
Not tested: full game/renderer build, native Linux, full suite. The enclosing command timed out at 300 seconds while the larger test_recorder_sync.py driver was running; that driver is not reported as passed. The catalogue unit driver also has a Windows CRLF-vs-LF fixture failure.
Must be tested: complete recorder-sync and full suite on Windows; native Linux TLS/recorder checks before readiness, by hand or Test Farm. Investigate any timeout rather than treating it as success.

Risks

What could break: per-thread lifetime, initialization or destruction ordering.
Turning it off: revert this commit; no new toggle.
Compatibility: no save/settings/cache-format, renderer ABI or compiler-default changes.

Checklist

Everyone

  • One topic.
  • Conventional Commit title: fix(vk): keep TLS initialization coherent under COFF ThinLTO.
  • Matching issue search completed; open PR titles reviewed, issue search remains pending.
  • Measurements report the link-failure proof and limitations.
  • Testing names tested, untested and required work.
  • Recheck current main before publishing; prepared on 9e6f231d.
  • Complete game-free suite; not run, recorder-sync timed out.
  • No game files, dumps or build output.
  • Third-party sources untouched.
  • Existing Longshot source and authored fixtures; GPL-3.0-or-later.

When it applies

  • Source commit records Assisted-by: OpenAI Codex.
  • Measured run recorded under docs/tested/.
  • Regression fails on main and passes here.
  • Recorder consumer fixtures migrated without weakened assertions.
  • Windows/Linux host verification complete; native Linux remains required.
  • Development documentation updated.
**Type:** fix · **Risk:** medium · **Tested on:** Windows 11 Pro 26300, LLVM-MinGW 23.1.5, game-free · **Needs:** recorder-sync completion, full suite and Linux verification ## Why Windows COFF ThinLTO can fail to link the profiler and recorder's inline thread-local initialization routines. This fixes ownership and initialization without enabling ThinLTO or claiming an FPS improvement. ## How to reproduce **Seen on:** Windows 11 Pro 26300, LLVM-MinGW Clang 23.1.5 and lld. **Settings and switches:** C++20 O2; native and `-flto=thin`, static runtime. **Steps:** run `python -I -B tests/test_thinlto_tls.py --cxx x86_64-w64-mingw32-clang++ --source-ref 9e6f231d`, then the same command without `--source-ref` on this branch. **Expected:** both consumers link and preserve cross-TU identity, per-thread separation and queued cleanup. **Actual:** main's native arm succeeds; ThinLTO fails on initialization symbols for `mkwvk::prof_t` and `mkwvk::rec::t_arena`. ## What changed Constant-initialize profiler POD TLS and give the recorder arena function-local thread-local ownership. Migrate every arena consumer and preserve destruction-time draining. - `gpu/vk/vk_internal.h`, `gpu/vk/vk_recorder.h`: focused production fix from local 073ed616. - `tests/test_thinlto_tls.py`: compile real profiler/recorder consumers across translation units, with a baseline adapter. - Recorder fixture callers and development documentation follow the accessor. ## Measurements **Verdict:** main fails during ThinLTO linking; the patched native and ThinLTO consumers pass. Hardware: Windows 11 Pro 26300, Intel Core i7-9700, 31.8 GiB usable RAM; Python 3.14.7, LLVM-MinGW 23.1.5; no GPU used. Method: the same authored cross-TU consumer against main and the prepared implementation. | Check | Before: main @ 9e6f231d | After: this PR @ 484daadbcd | |---|---|---| | Native consumer | Pass | Pass | | COFF ThinLTO link | Undefined TLS initialization routines | Pass | | Cross-TU/thread ownership and Enc exit drain | Native arm passes; ThinLTO cannot run | Native and ThinLTO pass | Observed patched output: `PASS: native/ThinLTO production cross-TU TLS identity, thread isolation and Enc exit drain`. Profiler sampling/exact-mode checks pass, as do recorder own/idle's 22 switch cases and deliberately broken variants. The checks ran on the source snapshot committed as 484daadbcd before browser submission. ### Flags and settings None. Production optimization defaults do not change; this does not enable the broader local ThinLTO experiment. ## Testing **Tested:** baseline/branch TLS comparison, profiler sampling/exact mode, recorder own/idle; run record accepted by the actual catalogue renderer. **Not tested:** full game/renderer build, native Linux, full suite. The enclosing command timed out at 300 seconds while the larger `test_recorder_sync.py` driver was running; that driver is not reported as passed. The catalogue unit driver also has a Windows CRLF-vs-LF fixture failure. **Must be tested:** complete recorder-sync and full suite on Windows; native Linux TLS/recorder checks before readiness, by hand or Test Farm. Investigate any timeout rather than treating it as success. ## Risks **What could break:** per-thread lifetime, initialization or destruction ordering. **Turning it off:** revert this commit; no new toggle. **Compatibility:** no save/settings/cache-format, renderer ABI or compiler-default changes. ## Checklist ### Everyone - [x] One topic. - [x] Conventional Commit title: `fix(vk): keep TLS initialization coherent under COFF ThinLTO`. - [ ] Matching issue search completed; open PR titles reviewed, issue search remains pending. - [x] Measurements report the link-failure proof and limitations. - [x] Testing names tested, untested and required work. - [ ] Recheck current main before publishing; prepared on 9e6f231d. - [ ] Complete game-free suite; not run, recorder-sync timed out. - [x] No game files, dumps or build output. - [x] Third-party sources untouched. - [x] Existing Longshot source and authored fixtures; GPL-3.0-or-later. ### When it applies - [x] Source commit records `Assisted-by: OpenAI Codex`. - [x] Measured run recorded under docs/tested/. - [x] Regression fails on main and passes here. - [x] Recorder consumer fixtures migrated without weakened assertions. - [ ] Windows/Linux host verification complete; native Linux remains required. - [x] Development documentation updated.
fix(vk): keep TLS initialization coherent under COFF ThinLTO
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
484daadbcd
Focused extraction of local Longshot changes: 073ed616. Authored tests and verification limits included; no game-derived artifacts.

Assisted-by: OpenAI Codex
HumanBean force-pushed fix/coff-thinlto-tls from 484daadbcd
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 15s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 4150b1f2e9
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 4s
Third-party parts / As their notes say (pull_request) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
2026-11-15 18:45:01 +00:00
Compare
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 3s
CI / Conventional Commit title (pull_request) Successful in 3s
CI / Workflow lint (actionlint) (pull_request) Successful in 5s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 4s
Third-party parts / As their notes say (pull_request) Successful in 8s
Website / Website on Cloudflare (pull_request_target) Has been skipped
This pull request is marked as a work in progress.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/coff-thinlto-tls:siantm-fix/coff-thinlto-tls'
git switch 'siantm-fix/coff-thinlto-tls'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!755
No description provided.