geometry views: a released range counts in every GPU-only twin it overlaps (RT-GEOMETRY-RELEASE-GPU-RANGES) #2524

Closed
leonida/mandy
Tyrannys wants to merge 0 commits from rt-geometry-release-gpu-ranges into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

Tyrannys commented 2026-11-28 00:39:57 +00:00

Package RT-GEOMETRY-RELEASE-GPU-RANGES: item 1 of @kevincommits' finding on #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230881417). Thank you for the find and the two cases. Claim: https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231091723.

The bug

Geometry views are keyed by the CPU view's address. A released GPU-only range is mapped to its twin's CPU view in two places: geometry_writes::note_released (runtime/src/title_geometry_watch.h) and GeometryViews::drain_released (runtime/shims/d3d12_geometry_views.h). Both did it through title_gpu_views::view_at(begin, 1, pair), which only finds the twin that holds the range's first byte. So:

  • A range that starts before a twin and runs into it (a wider release, or the one covering range a full release queue collapses into) found no twin. note_released dropped it, and drain_released retired nothing for the twin.
  • A range that spans several twins was counted for the first twin only. Views under the second twin's CPU view stayed live, with stale copies.

The fix

  • title_gpu_views::for_each_gpu_overlap(begin, end, f) (runtime/src/title_page_watch.h) calls f once for each twin whose GPU range overlaps [begin, end). It passes the overlapping part, named at that twin's CPU view.
  • note_released queues the range when any such part touches the watched bounds.
  • drain_released retires the views under each part. The parts are collected first, so the twins' lock is not held while views are retired.

#2471 changes other lines of this code (release() and the reopener).

Tests (geometry_views_test, test 8)

Kevin's two cases, on a fake device:

  • A release [twin - 4 KiB, twin + 4 KiB) is queued, and draining it retires the view under the overlapped part only.
  • With a second twin right after the first, a release from the middle of the first twin into the second retires the views under both CPU views, and not the view outside the range.

On main, the 4 new checks fail, plus a knock-on failure in test 9 because the view count is off. With the fix, all 86 checks pass (3 runs). Nearby tests (ctest -R "geometry|title_va|title_page|title_window|gpu_views") pass 16/16, and gta6rt_d3d12_com builds.

Profile M: RTX 4070 SUPER, Windows 11, Ryzen 7 9800X3D, MSVC RelWithDebInfo. CPU only. The full suite was not run because a boot was running. git diff --check and scripts/check_no_game_data.py are clean. No game files used.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Package **RT-GEOMETRY-RELEASE-GPU-RANGES**: item 1 of @kevincommits' finding on #1608 (https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7230881417). Thank you for the find and the two cases. Claim: https://github.com/ProjectLeonida/mandy/issues/1608#issuecomment-7231091723. ## The bug Geometry views are keyed by the CPU view's address. A released GPU-only range is mapped to its twin's CPU view in two places: `geometry_writes::note_released` (`runtime/src/title_geometry_watch.h`) and `GeometryViews::drain_released` (`runtime/shims/d3d12_geometry_views.h`). Both did it through `title_gpu_views::view_at(begin, 1, pair)`, which only finds the twin that holds the range's **first byte**. So: - **A range that starts before a twin** and runs into it (a wider release, or the one covering range a full release queue collapses into) found no twin. `note_released` dropped it, and `drain_released` retired nothing for the twin. - **A range that spans several twins** was counted for the first twin only. Views under the second twin's CPU view stayed live, with stale copies. ## The fix - `title_gpu_views::for_each_gpu_overlap(begin, end, f)` (`runtime/src/title_page_watch.h`) calls `f` once for each twin whose GPU range overlaps `[begin, end)`. It passes the overlapping part, named at that twin's CPU view. - `note_released` queues the range when any such part touches the watched bounds. - `drain_released` retires the views under each part. The parts are collected first, so the twins' lock is not held while views are retired. #2471 changes other lines of this code (`release()` and the reopener). ## Tests (`geometry_views_test`, test 8) Kevin's two cases, on a fake device: - A release `[twin - 4 KiB, twin + 4 KiB)` is queued, and draining it retires the view under the overlapped part only. - With a second twin right after the first, a release from the middle of the first twin into the second retires the views under both CPU views, and not the view outside the range. On main, the 4 new checks fail, plus a knock-on failure in test 9 because the view count is off. With the fix, all 86 checks pass (3 runs). Nearby tests (`ctest -R "geometry|title_va|title_page|title_window|gpu_views"`) pass 16/16, and `gta6rt_d3d12_com` builds. Profile M: RTX 4070 SUPER, Windows 11, Ryzen 7 9800X3D, MSVC RelWithDebInfo. CPU only. The full suite was not run because a boot was running. `git diff --check` and `scripts/check_no_game_data.py` are clean. No game files used. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timbot103 commented 2026-11-28 01:33:47 +00:00

Reviewed at head a855a6a98 on Windows 11 (MSVC 2022 19.44) with dual-GPU Vulkan validation (LEONIDA_VK_VALIDATION=1, Vulkan SDK 1.4.363.0).

Verification

  • Built geometry_views_test, title_write_watch_test, title_memory_map_test, kernel_writes_test, d3d12_title_va_test, and gta6rt.
  • CPU tests: geometry_views_test, title_write_watch_test, title_memory_map_test, and kernel_writes_test all passed.
  • GPU test (LEONIDA_GEOMETRY_MB=16, LEONIDA_VK_VALIDATION=1): d3d12_title_va_test passed with 0 validation errors on both NVIDIA GeForce RTX 5080 (616.64) and AMD Radeon(TM) Graphics (25.10.30.02).

Finding (Request changes)

  • Queued GPU-range release can evict a later reservation's live CPU view (title_page_watch.h:259-272, 350-360; xmem.cpp:2285-2288; d3d12_geometry_views.h:545-558):
    The half-open clipping in for_each_gpu_overlap() is clean for stable pairings, and repeated clips cannot double-retire a live entry because the first retirement removes its key. However, title_gpu_views::note_reservation() only appends to s.views and note_released() only queues the raw GPU interval [begin, end). If GPU range G is paired with CPU view A, G is released (queuing [G, G + size)), and G is then reused and paired with CPU view B before drain_released() runs, for_each_gpu_overlap() walks both {G, A} and {G, B} and calls retire_range() on still-live B as well as A (causing spurious eviction/reupload, even though retirement tickets keep backing memory safe).
    Resolving/recording the overlapping CPU intervals at release time (or removing/versioning released pairings in title_gpu_views) and adding a regression test where G is reused for B before draining A's release would close this cleanly.

AI-assisted review + local MSVC/dual-GPU verification.

Reviewed at head `a855a6a98` on Windows 11 (MSVC 2022 `19.44`) with dual-GPU Vulkan validation (`LEONIDA_VK_VALIDATION=1`, Vulkan SDK `1.4.363.0`). ### Verification - Built `geometry_views_test`, `title_write_watch_test`, `title_memory_map_test`, `kernel_writes_test`, `d3d12_title_va_test`, and `gta6rt`. - CPU tests: `geometry_views_test`, `title_write_watch_test`, `title_memory_map_test`, and `kernel_writes_test` all **passed**. - GPU test (`LEONIDA_GEOMETRY_MB=16`, `LEONIDA_VK_VALIDATION=1`): `d3d12_title_va_test` **passed** with 0 validation errors on both **NVIDIA GeForce RTX 5080** (`616.64`) and **AMD Radeon(TM) Graphics** (`25.10.30.02`). ### Finding (Request changes) - **Queued GPU-range release can evict a later reservation's live CPU view (`title_page_watch.h:259-272`, `350-360`; `xmem.cpp:2285-2288`; `d3d12_geometry_views.h:545-558`):** The half-open clipping in `for_each_gpu_overlap()` is clean for stable pairings, and repeated clips cannot double-retire a live entry because the first retirement removes its key. However, `title_gpu_views::note_reservation()` only appends to `s.views` and `note_released()` only queues the raw GPU interval `[begin, end)`. If GPU range `G` is paired with CPU view `A`, `G` is released (queuing `[G, G + size)`), and `G` is then reused and paired with CPU view `B` before `drain_released()` runs, `for_each_gpu_overlap()` walks both `{G, A}` and `{G, B}` and calls `retire_range()` on still-live `B` as well as `A` (causing spurious eviction/reupload, even though retirement tickets keep backing memory safe). Resolving/recording the overlapping CPU intervals at release time (or removing/versioning released pairings in `title_gpu_views`) and adding a regression test where `G` is reused for `B` before draining `A`'s release would close this cleanly. AI-assisted review + local MSVC/dual-GPU verification.
zmasi commented 2026-11-28 07:18:27 +00:00

#2524 | head a855a6a98dd95315ef38fc7d48fbfe37e303e6f5 (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(geometry_views|d3d12_geometry_views)$" --output-on-failure (LEONIDA_VK_VALIDATION=1) | red on main: geometry_views_test fails (86 checks, 5 failures: note_released and drain_released only looked up view_at(begin, 1), missing released ranges starting before a GPU-only twin or spanning multiple adjacent twins / collapsed overflow ranges) | green on PR+main: 2/2 CTests pass (geometry_views 86/86 checks in 0.16s, and d3d12_geometry_views on RTX 3090 in 0.69s with LEONIDA_VK_VALIDATION=1 and 0 Khronos validation errors); check_no_game_data.py 0 violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2524 | head a855a6a98dd95315ef38fc7d48fbfe37e303e6f5 (merged cleanly with main 09c153948386fd658fe2f999f6176efbaa8c8345) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(geometry_views|d3d12_geometry_views)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`) | red on main: `geometry_views_test` fails (`86 checks, 5 failures`: `note_released` and `drain_released` only looked up `view_at(begin, 1)`, missing released ranges starting before a GPU-only twin or spanning multiple adjacent twins / collapsed overflow ranges) | green on PR+main: `2/2` CTests pass (`geometry_views` `86/86` checks in `0.16s`, and `d3d12_geometry_views` on RTX 3090 in `0.69s` with `LEONIDA_VK_VALIDATION=1` and `0` Khronos validation errors); `check_no_game_data.py` `0` violations | Windows 11, RTX 3090 (610.88), Vulkan SDK 1.4.363.1 | AI-assisted: yes
lixonik approved these changes 2026-11-28 09:28:02 +00:00
lixonik left a comment

Reviewed the diff and tested merged onto main (493867366) with Ninja Release (MSVC).

Adding title_gpu_views::for_each_gpu_overlap and collecting overlapped CPU spans before calling retire_range outside the twin shared lock cleanly fixes both pre-twin-start and multi-twin releases without introducing lock-order issues.

Tests run

  • cmake --build <build> --target geometry_views_test gta6rt_d3d12_com: built cleanly.
  • ctest --output-on-failure -R "^geometry_views$": 1/1 passed (0.11 s).

AI-assisted (Antigravity, Gemini).

Reviewed the diff and tested merged onto `main` (`493867366`) with Ninja Release (MSVC). Adding `title_gpu_views::for_each_gpu_overlap` and collecting overlapped CPU spans before calling `retire_range` outside the twin shared lock cleanly fixes both pre-twin-start and multi-twin releases without introducing lock-order issues. ### Tests run - `cmake --build <build> --target geometry_views_test gta6rt_d3d12_com`: built cleanly. - `ctest --output-on-failure -R "^geometry_views$"`: **1/1 passed** (0.11 s). AI-assisted (Antigravity, Gemini).
timbot103 reviewed 2026-11-29 01:07:03 +00:00
timbot103 left a comment
No description provided.
I reviewed head `a855a6a98` by static inspection only, without running builds, tests, or GPU workloads. For stable reservations, the half-open clipping covers partial and full intersections and excludes ranges that only touch an endpoint. Retirement runs after the pair lock is released. **Request changes.** At `runtime/shims/d3d12_geometry_views.h:553`, the drain translates a queued GPU release using the current pair table. If G is released while paired with CPU range A, then reused and paired with B before the drain, the appended pairing at `runtime/src/title_page_watch.h:268` makes the old release evict a live view created at B. That view disappears from lookup while its retired storage still counts against the cap. Please capture the released reservation's CPU clips before its GPU address can be reused, enqueue them, and remove its pairing on successful `MEM_RELEASE`. A regression should resolve B between the release and the drain and verify that B stays live. The multi-twin test at `runtime/test/geometry_views_test.cpp:335` also leaves `note_released`'s later-twin filter untested. Please add a release whose first CPU clip is outside the watched bounds and whose second CPU clip hits a live view, then check both queueing and retirement. AI-assisted.
TheGeogeo commented 2026-11-29 05:58:26 +00:00

Tested a855a6a98 merged (no commit) with main c8bf0e7b6. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. check_no_game_data.py is clean.

  • Green: geometry_views passes.
  • Red: with title_page_watch.h, title_geometry_watch.h and d3d12_geometry_views.h back to main, it fails 86 checks, 5 failures, for example a range starting before the GPU-only twin and overlapping it is queued and drain_released after overflow retires every view inside the collapsed range.
  • No regression: the merge rebuilds 189 executables. Of their 310 other tests, only xbox_present fails, as on plain main here.
  • LINK: gta6rt.exe linked without ws2_32.lib gives main's 26 unresolved Rust-std symbols, nothing new. Its imports are identical to main's.

Still open from review, with no author reply (I did not test these):

  • A GPU-range release queued while G is paired with A is resolved at drain time against the current pair table. If G is re-paired with B before the drain, the drain evicts B's live view (title_page_watch.h:268, d3d12_geometry_views.h:553). Capturing the CPU clips at release time and dropping the pairing on MEM_RELEASE, with a regression test, was asked.
  • note_released's later-twin filter has no test (geometry_views_test.cpp:335).

AI-assisted (Claude Code).

Tested `a855a6a98` merged (no commit) with `main` `c8bf0e7b6`. GPUs tested: NVIDIA GeForce RTX 3080, driver 621.40, Windows 11 10.0.26300; MSVC 19.52 (Visual Studio 18), Ninja, RelWithDebInfo. `check_no_game_data.py` is clean. - Green: `geometry_views` passes. - Red: with `title_page_watch.h`, `title_geometry_watch.h` and `d3d12_geometry_views.h` back to `main`, it fails `86 checks, 5 failures`, for example `a range starting before the GPU-only twin and overlapping it is queued` and `drain_released after overflow retires every view inside the collapsed range`. - No regression: the merge rebuilds 189 executables. Of their 310 other tests, only `xbox_present` fails, as on plain `main` here. - LINK: `gta6rt.exe` linked without `ws2_32.lib` gives `main`'s 26 unresolved Rust-std symbols, nothing new. Its imports are identical to `main`'s. Still open from review, with no author reply (I did not test these): - A GPU-range release queued while G is paired with A is resolved at drain time against the current pair table. If G is re-paired with B before the drain, the drain evicts B's live view (`title_page_watch.h:268`, `d3d12_geometry_views.h:553`). Capturing the CPU clips at release time and dropping the pairing on MEM_RELEASE, with a regression test, was asked. - `note_released`'s later-twin filter has no test (`geometry_views_test.cpp:335`). AI-assisted (Claude Code).
fiestorra commented 2026-11-30 05:59:36 +00:00

Independent verification on this machine (Windows 11, MSVC 19.44.35226), and the negative control bites: four checks fail on main and pass with the change.

1. It applies. merge-tree clean; a855a6a98 cherry-picks onto main 0ae217ceb without a conflict. Four files, 51 insertions(+), 15 deletions(-): the geometry views shim, two watch headers and the test.

2. It builds and passes, three times:

cmake --build runtime/build-ninja --target geometry_views_test   -> linked
geometry_views_test.exe                                         -> exit 0, 0, 0
  PASS a new 1 MiB view is copied whole
  PASS the copy is found by its device address
  PASS the copy holds the title's bytes
  PASS a refresh with nothing written copies nothing

3. The negative control runs the same test against main's sources and fails four checks:

-> exit 1, 1
  FAIL a range starting before the GPU-only twin and overlapping it is queued
  FAIL draining it retires the view under the overlapped part only
  FAIL a release spanning two twins retires the views under both, and not the one outside it
  FAIL the first twin's view is made again; two live views as before

The four that fail are exactly the subject of the commit - a released range must count in every GPU-only twin it overlaps, and only under the overlapped part. On main it is not queued at all, so the view is never re-made. That is a genuine red->green on the real code path, not a test agreeing with itself.

What I did not test: the pipeline under the title. The test drives note_released/drain_released and the watch headers directly, so what is proved is the bookkeeping - which twin owns which range, what is retired at which ticket - and not what the GPU does with a view after the title releases it.

Written with an AI assistant.

Independent verification on this machine (Windows 11, MSVC 19.44.35226), and **the negative control bites**: four checks fail on `main` and pass with the change. **1. It applies.** `merge-tree` clean; `a855a6a98` cherry-picks onto `main` `0ae217ceb` without a conflict. Four files, `51 insertions(+), 15 deletions(-)`: the geometry views shim, two watch headers and the test. **2. It builds and passes, three times:** ``` cmake --build runtime/build-ninja --target geometry_views_test -> linked geometry_views_test.exe -> exit 0, 0, 0 PASS a new 1 MiB view is copied whole PASS the copy is found by its device address PASS the copy holds the title's bytes PASS a refresh with nothing written copies nothing ``` **3. The negative control runs the same test against `main`'s sources and fails four checks:** ``` -> exit 1, 1 FAIL a range starting before the GPU-only twin and overlapping it is queued FAIL draining it retires the view under the overlapped part only FAIL a release spanning two twins retires the views under both, and not the one outside it FAIL the first twin's view is made again; two live views as before ``` The four that fail are exactly the subject of the commit - **a released range must count in every GPU-only twin it overlaps, and only under the overlapped part**. On `main` it is not queued at all, so the view is never re-made. That is a genuine red->green on the real code path, not a test agreeing with itself. **What I did not test:** the pipeline under the title. The test drives `note_released`/`drain_released` and the watch headers directly, so what is proved is the bookkeeping - which twin owns which range, what is retired at which ticket - and not what the GPU does with a view after the title releases it. Written with an AI assistant.
KelboLive commented 2026-11-30 16:53:49 +00:00

Independent check on Windows (not the author), at a855a6a98.

  • Built geometry_views_test and ran it: 86 checks, 0 failures — including the released-range-counts-in-every-GPU-twin cases and the 65,536-touching-range merge.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.

AI-assisted: yes (opencode).

Independent check on Windows (not the author), at `a855a6a98`. - Built `geometry_views_test` and ran it: **86 checks, 0 failures** — including the released-range-counts-in-every-GPU-twin cases and the 65,536-touching-range merge. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711. AI-assisted: yes (opencode).
aslan2142 commented 2026-12-01 16:45:48 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.