d3d12: keep title writeback fenced past 64 pending batches (RT-TITLE-WRITEBACK-FENCE-OVERFLOW) #2461

Open
github-bot wants to merge 1 commit from github-bot/gh-2461 into main AGit
Owner

@⁠73N1X on GitHub · 2026-11-27 11:40 UTC · original
73N1X:fix/title-writeback-fence-overflow → main · +219 −13 · 4 files · 1 commits · open

Claimed in the coordination issue as: RT-TITLE-WRITEBACK-FENCE-OVERFLOW

What and why

DeviceState::write_back_titles() copied the oldest pending ranges back to title memory without their completion ticket once more than 64 batches accumulated. A held queue can stall the global retirement prefix while another queue continues submitting and completing work, so backlog size does not prove completion.

Remove that bypass and retain each batch until its ticket retires. No GPU wait is added under shadow_mutex, which another queue may need to submit the work that releases the dependency. Existing per-submission range/byte limits remain. Pending range metadata can grow during a stall; this change favors completion ordering over prematurely consuming it.

Add d3d12_writeback_retirement: hold one native Vulkan queue with an unsignaled timeline semaphore, complete 130 submissions on a second queue, and verify that no title-memory result appears early. Each submission writes a different value to a separate page, so the final check also catches lost batches. After release, a refresh without a new reached range must recover all 130 values. Uses transfers and synthetic buffers only, no shader tools or game files. Skips when two graphics-family queues are unavailable; failure cleanup releases the gate.

Related work: #2352 changes adjacent-range coalescing; #2032 is an alternative writeback implementation. This PR builds on neither and leaves those topics alone.

Tested

Native Windows 11 build 26200, MSVC 2022, AMD Radeon RX 5700 XT 8 GB, Windows driver 32.0.21045.5002:

  • Before the fix, the initial synthetic reproducer failed at refresh 65 in two separate runs on main 63185f4a3, with the first queue still held. The test was then strengthened to use 130 distinct pages and verify every retained result. That final page-isolated test passed three consecutive runs; the committed version, with an added result-count diagnostic, passed again. The final strengthened test was not rebuilt against unmodified main.
  • cmake --build runtime/build --config RelWithDebInfo --target d3d12_writeback_retirement_test -j 2: passed.
  • ctest --test-dir runtime/build -C RelWithDebInfo -R '^d3d12_writeback_retirement$' --output-on-failure: passed.
  • Full translator suite: 500 files, 6,374 tests, zero failed files (-j 4).
  • python -m compileall -q make_game.py tools tests, python -I make_game.py --help, CI-registration tests (18), text-line-ending tests (3), explicit-path no-game-data scan and diff checks passed.
  • Full runtime build encountered the existing vk_null_descriptor_test.cpp:97 C2065 (LEONIDA_TEST_NULL_DESCRIPTORS_SPV) with no glslangValidator installed; #2055 addresses it. Full runtime CTest was not run. Khronos validation was requested but unavailable because VK_LAYER_KHRONOS_validation is not installed; no validation-layer success is claimed.

GPUs tested: AMD Radeon RX 5700 XT, 8 GB desktop, driver 32.0.21045.5002, Windows 11 build 26200 (profile M). No gameplay, performance improvement or retail-crash remediation claimed.

AI-assisted: yes, OpenAI Codex; a second agent reviewed the patch and independently checked the semantic-suite counts.

Checklist

  • Based on current main (63185f4a3).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in quoted logs or reports.
  • A new translator rule is in docs/design.md (not applicable: no translator change).
**@⁠73N1X** on GitHub · 2026-11-27 11:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2461) `73N1X:fix/title-writeback-fence-overflow` → `main` · +219 −13 · 4 files · 1 commits · open Claimed in the coordination issue as: [RT-TITLE-WRITEBACK-FENCE-OVERFLOW](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `DeviceState::write_back_titles()` copied the oldest pending ranges back to title memory without their completion ticket once more than 64 batches accumulated. A held queue can stall the global retirement prefix while another queue continues submitting and completing work, so backlog size does not prove completion. Remove that bypass and retain each batch until its ticket retires. No GPU wait is added under `shadow_mutex`, which another queue may need to submit the work that releases the dependency. Existing per-submission range/byte limits remain. Pending range metadata can grow during a stall; this change favors completion ordering over prematurely consuming it. Add `d3d12_writeback_retirement`: hold one native Vulkan queue with an unsignaled timeline semaphore, complete 130 submissions on a second queue, and verify that no title-memory result appears early. Each submission writes a different value to a separate page, so the final check also catches lost batches. After release, a refresh without a new reached range must recover all 130 values. Uses transfers and synthetic buffers only, no shader tools or game files. Skips when two graphics-family queues are unavailable; failure cleanup releases the gate. Related work: #2352 changes adjacent-range coalescing; #2032 is an alternative writeback implementation. This PR builds on neither and leaves those topics alone. ### Tested Native Windows 11 build 26200, MSVC 2022, AMD Radeon RX 5700 XT 8 GB, Windows driver `32.0.21045.5002`: - Before the fix, the initial synthetic reproducer failed at refresh 65 in two separate runs on `main` `63185f4a3`, with the first queue still held. The test was then strengthened to use 130 distinct pages and verify every retained result. That final page-isolated test passed three consecutive runs; the committed version, with an added result-count diagnostic, passed again. The final strengthened test was not rebuilt against unmodified main. - `cmake --build runtime/build --config RelWithDebInfo --target d3d12_writeback_retirement_test -j 2`: passed. - `ctest --test-dir runtime/build -C RelWithDebInfo -R '^d3d12_writeback_retirement$' --output-on-failure`: passed. - Full translator suite: 500 files, 6,374 tests, zero failed files (`-j 4`). - `python -m compileall -q make_game.py tools tests`, `python -I make_game.py --help`, CI-registration tests (18), text-line-ending tests (3), explicit-path no-game-data scan and diff checks passed. - Full runtime build encountered the existing `vk_null_descriptor_test.cpp:97` C2065 (`LEONIDA_TEST_NULL_DESCRIPTORS_SPV`) with no glslangValidator installed; #2055 addresses it. Full runtime CTest was not run. Khronos validation was requested but unavailable because `VK_LAYER_KHRONOS_validation` is not installed; no validation-layer success is claimed. GPUs tested: AMD Radeon RX 5700 XT, 8 GB desktop, driver `32.0.21045.5002`, Windows 11 build 26200 (profile M). No gameplay, performance improvement or retail-crash remediation claimed. AI-assisted: yes, OpenAI Codex; a second agent reviewed the patch and independently checked the semantic-suite counts. ### Checklist - [x] Based on current `main` (`63185f4a3`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in quoted logs or reports. - [ ] A new translator rule is in `docs/design.md` (not applicable: no translator change).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:03:49 +00:00
Author
Owner

@⁠timbot103 on GitHub · 2026-11-27 12:09 UTC · original

Independently checked head 78158bab9 on Windows 11 Pro 26200, MSVC 2022 (19.44.35230.0, RelWithDebInfo, Ninja), Vulkan SDK 1.4.363.0, no game files.

Local build & dual-GPU verification:

  • Clean MSVC build of d3d12_writeback_retirement_test (zero warnings in PR files).
  • d3d12_writeback_retirement_test with LEONIDA_VK_VALIDATION=1:
    • NVIDIA GeForce RTX 5080 (616.64): PASS (retired writeback results: 130/130 matched; 130 pending writeback batches stayed fenced and drained after release), 0 validation errors.
    • AMD Radeon(TM) Graphics (25.10.30.02): PASS (retired writeback results: 130/130 matched; 130 pending writeback batches stayed fenced and drained after release), 0 validation errors.

Code review notes:

  • The 64-batch unfenced-drain removal is clean, adds no GPU wait under shadow_mutex, and d3d12_writeback_retirement_test genuinely exercises the production writeback queue with a held native queue and a second-queue fence across 130 pages.
  • Small documentation precision suggestion (docs/d3d12_vulkan.md:1729-1739): Because a batch still records a predicted submitted + 1 ticket before its writer submits (d3d12_vulkan_device.cpp:3327-3349) and writeback reads the live shadow buffer (which a later overlapping writer may touch), narrowing the doc wording to say batches are retained until their recorded retirement prefix completes (rather than implying full per-writer isolation across concurrent queues / overlapping later writes) keeps the documented guarantee exact.

The 64-batch fix itself looks solid. AI-assisted.

**@⁠timbot103** on GitHub · 2026-11-27 12:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2461#issuecomment-7217909000) Independently checked head `78158bab9` on Windows 11 Pro 26200, MSVC 2022 (`19.44.35230.0`, RelWithDebInfo, Ninja), Vulkan SDK `1.4.363.0`, no game files. **Local build & dual-GPU verification:** - Clean MSVC build of `d3d12_writeback_retirement_test` (zero warnings in PR files). - `d3d12_writeback_retirement_test` with `LEONIDA_VK_VALIDATION=1`: - **NVIDIA GeForce RTX 5080** (`616.64`): **PASS** (`retired writeback results: 130/130 matched`; `130 pending writeback batches stayed fenced and drained after release`), 0 validation errors. - **AMD Radeon(TM) Graphics** (`25.10.30.02`): **PASS** (`retired writeback results: 130/130 matched`; `130 pending writeback batches stayed fenced and drained after release`), 0 validation errors. **Code review notes:** - The 64-batch unfenced-drain removal is clean, adds no GPU wait under `shadow_mutex`, and `d3d12_writeback_retirement_test` genuinely exercises the production writeback queue with a held native queue and a second-queue fence across 130 pages. - **Small documentation precision suggestion (`docs/d3d12_vulkan.md:1729-1739`):** Because a batch still records a predicted `submitted + 1` ticket before its writer submits (`d3d12_vulkan_device.cpp:3327-3349`) and writeback reads the live shadow buffer (which a later overlapping writer may touch), narrowing the doc wording to say batches are retained until their *recorded* retirement prefix completes (rather than implying full per-writer isolation across concurrent queues / overlapping later writes) keeps the documented guarantee exact. The 64-batch fix itself looks solid. AI-assisted.
Author
Owner

@⁠lixonik on GitHub · 2026-11-27 12:13 UTC · original · reviewed

Tested 78158bab9 locally merged onto main a3bafd05d02b on Windows 11 with MSVC 19.44 (Release), NVIDIA GeForce RTX 5070 (610.88); Vulkan validation was unavailable locally, so the GPU checks ran without it.

  • Red/green control: running d3d12_writeback_retirement against main a3bafd05d02b failed on refresh 65 (premature title writeback on refresh 65 (first queue still held) after logging the 64-batch bypass). With this PR merged, d3d12_writeback_retirement (130/130 matched), d3d12_title_va, shadow_keep, and title_va_alias all passed (4/4).
  • Additional synthetic check (scratch): had the held queue itself write page 0 of title and call note_reached while the second queue ran the remaining 129 batches on distinct pages. On main, the held batch was dropped early and page 0 remained lost after releasing the gate (129/130 matched); with this PR, no premature writeback occurred and all 130/130 pages matched after release.

No findings from these checks.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-27 12:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2461#pullrequestreview-6087943678) · **reviewed** Tested `78158bab9` locally merged onto `main` `a3bafd05d02b` on Windows 11 with MSVC 19.44 (Release), NVIDIA GeForce RTX 5070 (610.88); Vulkan validation was unavailable locally, so the GPU checks ran without it. - Red/green control: running `d3d12_writeback_retirement` against `main` `a3bafd05d02b` failed on refresh 65 (`premature title writeback on refresh 65 (first queue still held)` after logging the 64-batch bypass). With this PR merged, `d3d12_writeback_retirement` (`130/130 matched`), `d3d12_title_va`, `shadow_keep`, and `title_va_alias` all passed (4/4). - Additional synthetic check (scratch): had the held queue itself write page 0 of `title` and call `note_reached` while the second queue ran the remaining 129 batches on distinct pages. On `main`, the held batch was dropped early and page 0 remained lost after releasing the gate (`129/130 matched`); with this PR, no premature writeback occurred and all `130/130` pages matched after release. No findings from these checks. AI-assisted.
Author
Owner

@⁠OreoFR on GitHub · 2026-11-27 12:27 UTC · original

Retail check for regressions on profile M (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Same tree with and without this PR: current main (with #2418/#2412) + #2260 #2020 #2166 #1851 + DadaCap window-retire, async ≥ 1 MiB, classic gate. Window: world phase +60 to +240 s.

without with #2461
frames/s 0.100 0.091
shadows (write-back is in it) ms/submission 102 87
heaps ms/submission 104 78
longest submission stall 2.7 s 1.7 s
peak private bytes 34.0 GB 31.8 GB
freeze / device loss / exceptions none none
device-stall: queue retirement has not advanced for 15 s lines 1 2

No regression seen. The differences are within the run-to-run spread I see here (shadows varies 80-270 ms across same-build runs). Pending-batch growth didn't show up as memory. MEASURED (n=1 each), world phase reached, run cut after 2.5 min of it. AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠OreoFR** on GitHub · 2026-11-27 12:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2461#issuecomment-7218258910) Retail check for regressions on profile M (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11). Same tree with and without this PR: current `main` (with #2418/#2412) + #2260 #2020 #2166 #1851 + DadaCap window-retire, async ≥ 1 MiB, classic gate. Window: world phase +60 to +240 s. | | without | with #2461 | |---|---|---| | frames/s | 0.100 | 0.091 | | shadows (write-back is in it) ms/submission | 102 | 87 | | heaps ms/submission | 104 | 78 | | longest submission stall | 2.7 s | 1.7 s | | peak private bytes | 34.0 GB | 31.8 GB | | freeze / device loss / exceptions | none | none | | `device-stall: queue retirement has not advanced for 15 s` lines | 1 | 2 | No regression seen. The differences are within the run-to-run spread I see here (shadows varies 80-270 ms across same-build runs). Pending-batch growth didn't show up as memory. `MEASURED (n=1 each)`, world phase reached, run cut after 2.5 min of it. AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2461/head:github-bot/gh-2461'
git switch 'github-bot/gh-2461'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2461'
git switch 'github-bot/gh-2461'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2461'
git switch 'github-bot/gh-2461'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2461'
git switch 'main'
git merge --squash 'github-bot/gh-2461'
git switch 'main'
git merge --ff-only 'github-bot/gh-2461'
git switch 'main'
git merge 'github-bot/gh-2461'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.