runtime: preserve in-flight GPU label targets when expanding a non-heap region (RT-GPU-LABEL-MEMORY-EXPAND) #1788

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

@⁠IlyassRS3 on GitHub · 2026-11-25 12:11 UTC · original
IlyassRS3:fix/rt-gpu-label-memory-expand → main · +207 −2 · 3 files · 1 commits · open

Summary

Fixes leonida::label::Memory::track() in runtime/src/gpu_label_memory.h so growing a tracked non-heap region at the same base and allocation_base updates Region::end in place instead of overwriting regions_[base] and dropping in-flight GPU completion value writes.

  • Coordination item: RT-GPU-LABEL-MEMORY-EXPAND
  • Claim: #1608

Root cause

In Memory::track(base, bytes, allocation_base, heap):

  • Previously, if a non-heap region at base with the same allocation_base already existed and a new track() call covered a larger range (end > r.end), the early-return check end <= r.end failed and line 41 executed regions_[base] = std::make_shared<Region>(...).
  • Replacing regions_[base] destroyed the previous Region shared_ptr (and caused it->second != region in publish()), silently dropping any in-flight label::Target GPU completion writes captured from [base, old_end) before the expansion.

Changes

  • runtime/src/gpu_label_memory.h:
    • When !heap and an existing non-heap region at the same base and allocation_base is expanded (base == r.begin && end > r.end), update r.end = end in place under mutex_.
    • Preserves existing Region identity and generation (so stale pre-decommit targets remain rejected, live post-decommit targets survive further expansion, adjacent pages stay isolated from each other's partial decommits, and heap regions or distinct allocation_base reservations still allocate a fresh Region).
  • runtime/test/gpu_label_memory_test.cpp & runtime/CMakeLists.txt:
    • Add portable gpu_label_memory CTest covering in-place expansion, post-partial-release generation retention, subrange and adjacent-page isolation, heap and new-reservation invalidation, base-0 GPU arena tracking, alignment/overflow bounds, and concurrent expand/capture/publish under TSan.

Verification

  • AI-assisted: yes
  • GPUs tested: none (portable standard-library C++20 header + test, verified locally on macOS Apple Silicon ARM64 with Clang; Windows MSVC build and Windows-only gpu_label_store / xbox_gpu_label tests rely on Windows CI).
  • Commands run:
    • clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/gpu_label_memory_test.cpp — pass
    • clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/gpu_label_memory_test.cpp — pass (zero data races)
    • clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/gpu_label_memory_test.cpp — pass
    • Mutation test compiling gpu_label_memory_test.cpp against unpatched main:runtime/src/gpu_label_memory.h — fails on test_expand_preserves_inflight_targets, confirming regression coverage
    • python3 -I scripts/check_no_game_data.py runtime/src/gpu_label_memory.h runtime/test/gpu_label_memory_test.cpp runtime/CMakeLists.txt — pass
    • python3 -I tests/test_text_write_line_endings.py — 3/3 pass
**@⁠IlyassRS3** on GitHub · 2026-11-25 12:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1788) `IlyassRS3:fix/rt-gpu-label-memory-expand` → `main` · +207 −2 · 3 files · 1 commits · open ## Summary Fixes `leonida::label::Memory::track()` in `runtime/src/gpu_label_memory.h` so growing a tracked non-heap region at the same `base` and `allocation_base` updates `Region::end` in place instead of overwriting `regions_[base]` and dropping in-flight GPU completion value writes. - **Coordination item**: `RT-GPU-LABEL-MEMORY-EXPAND` - **Claim**: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### Root cause In `Memory::track(base, bytes, allocation_base, heap)`: - Previously, if a non-heap region at `base` with the same `allocation_base` already existed and a new `track()` call covered a larger range (`end > r.end`), the early-return check `end <= r.end` failed and line 41 executed `regions_[base] = std::make_shared<Region>(...)`. - Replacing `regions_[base]` destroyed the previous `Region` `shared_ptr` (and caused `it->second != region` in `publish()`), silently dropping any in-flight `label::Target` GPU completion writes captured from `[base, old_end)` before the expansion. ### Changes - [`runtime/src/gpu_label_memory.h`](runtime/src/gpu_label_memory.h): - When `!heap` and an existing non-heap region at the same `base` and `allocation_base` is expanded (`base == r.begin && end > r.end`), update `r.end = end` in place under `mutex_`. - Preserves existing `Region` identity and `generation` (so stale pre-decommit targets remain rejected, live post-decommit targets survive further expansion, adjacent pages stay isolated from each other's partial decommits, and heap regions or distinct `allocation_base` reservations still allocate a fresh `Region`). - [`runtime/test/gpu_label_memory_test.cpp`](runtime/test/gpu_label_memory_test.cpp) & [`runtime/CMakeLists.txt`](runtime/CMakeLists.txt): - Add portable `gpu_label_memory` CTest covering in-place expansion, post-partial-release generation retention, subrange and adjacent-page isolation, heap and new-reservation invalidation, base-0 GPU arena tracking, alignment/overflow bounds, and concurrent expand/capture/publish under TSan. ## Verification - **AI-assisted**: yes - **GPUs tested**: none (portable standard-library C++20 header + test, verified locally on macOS Apple Silicon ARM64 with Clang; Windows MSVC build and Windows-only `gpu_label_store` / `xbox_gpu_label` tests rely on Windows CI). - Commands run: - `clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/gpu_label_memory_test.cpp` — pass - `clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/gpu_label_memory_test.cpp` — pass (zero data races) - `clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/gpu_label_memory_test.cpp` — pass - Mutation test compiling `gpu_label_memory_test.cpp` against unpatched `main:runtime/src/gpu_label_memory.h` — fails on `test_expand_preserves_inflight_targets`, confirming regression coverage - `python3 -I scripts/check_no_game_data.py runtime/src/gpu_label_memory.h runtime/test/gpu_label_memory_test.cpp runtime/CMakeLists.txt` — pass - `python3 -I tests/test_text_write_line_endings.py` — 3/3 pass
In runtime/src/gpu_label_memory.h, Memory::track() previously returned early
when the new range lay within an existing non-heap region, but fell through
to overwrite regions_[base] with a fresh std::shared_ptr<Region> whenever an
existing non-heap region at the same base and allocation_base grew (end >
r.end). Overwriting the shared_ptr invalidated every in-flight label::Target
captured from that region, causing publish() to silently drop GPU completion
value writes.

Update r.end in place when base == r.begin with the same non-heap
allocation_base so live targets retain their Region identity and generation
(while preserving stale-target rejection across partial releases, separate
tracking of adjacent pages, and fresh Region replacement for heap blocks or
new reservations).

Add portable unit and TSan concurrency test runtime/test/gpu_label_memory_test.cpp.

Item: RT-GPU-LABEL-MEMORY-EXPAND
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:05:20 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 12:11 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 12:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1788#pullrequestreview-6057366929) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠Tyrannys on GitHub · 2026-11-25 16:18 UTC · original

Independent verification of head 0267290f9c7ec35bece4e0b81a132f7d8310e4e6, merged onto current main (b0f3d3998) without conflicts.

Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo.

  • With the PR: gpu_label_memory (new), plus neighbours gpu_label_store and xbox_gpu_label_completion: 3/3 pass.
  • The new test against main's gpu_label_memory.h: fails at line 56: publish_ok(mem, t4, kBase + 0x10, 4, kAlloc) (the region is replaced on growth, so the in-flight target is dropped), which is the bug the PR fixes.

Diff read: Region::end is changed under the same mutex_ that capture/publish take, and only for the same base and allocation base, so targets keep their owner. No problem found.

No game files used. AI-assisted (Claude Code).

**@⁠Tyrannys** on GitHub · 2026-11-25 16:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1788#issuecomment-7167775395) **Independent verification** of head `0267290f9c7ec35bece4e0b81a132f7d8310e4e6`, merged onto current `main` (b0f3d3998) without conflicts. Windows 11 Pro, RTX 4070 SUPER (NVIDIA 621.01), MSVC 19.52.37029, RelWithDebInfo. - With the PR: `gpu_label_memory` (new), plus neighbours `gpu_label_store` and `xbox_gpu_label_completion`: **3/3 pass**. - The new test against `main`'s `gpu_label_memory.h`: **fails** at `line 56: publish_ok(mem, t4, kBase + 0x10, 4, kAlloc)` (the region is replaced on growth, so the in-flight target is dropped), which is the bug the PR fixes. Diff read: `Region::end` is changed under the same `mutex_` that `capture`/`publish` take, and only for the same base and allocation base, so targets keep their owner. No problem found. No game files used. AI-assisted (Claude Code).
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/1788/head:github-bot/gh-1788'
git switch 'github-bot/gh-1788'

Merge

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