Skip to content

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

Open
Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-geometry-release-gpu-ranges
Open

Tyrannys wants to merge 1 commit into
ProjectLeonida:mainfrom
Tyrannys:rt-geometry-release-gpu-ranges

Conversation

@Tyrannys

Copy link
Copy Markdown
Contributor

Package RT-GEOMETRY-RELEASE-GPU-RANGES: item 1 of @kevincommits' finding on #1608 (#1608 (comment)). Thank you for the find and the two cases. Claim: #1608 (comment).

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

…rlaps (RT-GEOMETRY-RELEASE-GPU-RANGES)

From kevincommits' finding on ProjectLeonida#1608 (item 1). geometry_writes::note_released
and GeometryViews::drain_released mapped a released GPU-only range to its
CPU view through view_at(begin, 1), which only finds the twin holding the
range's first byte. A range that starts before a twin (a wider release, or
the collapsed range of a full release queue) was dropped, and one that
spans several twins was retired under the first twin's CPU view alone.

A new title_gpu_views::for_each_gpu_overlap(begin, end, f) gives each
twin's overlapping part at its CPU view. note_released queues a range when
any such part touches the watched bounds, and drain_released retires the
views under each part. The parts are collected first, so the twins' lock
is not held while views are retired.

Four new checks in geometry_views_test (a release starting before a twin,
one spanning two adjacent twins) fail on main with one more knock-on
failure; all 86 checks pass with the fix.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timbot103

Copy link
Copy Markdown
Contributor

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

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#2524 | head a855a6a (merged cleanly with main 09c1539) | 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 lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants