d3d12: evict geometry views on range release and retry refused ranges #2094
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2094
Loading…
Reference in a new issue
No description provided.
Delete branch "cont/geometry-view-eviction"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Item:
RT-GEOMETRY-VIEW-EVICTIONProblem
runtime/shims/d3d12_geometry_views.h: onceLEONIDA_GEOMETRY_MBis used up,resolve()marks a range refused for good, and no view is freed before teardown, even after the title releases the memory it copies.Change
xmemreports title ranges that go away:XMemFree/XMemFreeDefault,VirtualFreeMEM_RELEASE/MEM_DECOMMIT, theXMemMapPhysicalPagesunmap and theCopyPageMappingsBatchXunmap range. They go to a small queue intitle_geometry_watch.h(note_released/take_released). Ranges outside every watched tile are not queued; a GPU-only range counts through its CPU view, where the views are keyed. When the queue is full it collapses into one covering range: retiring a few views too many is harmless (they are made again on the next resolve), dropping a release is not.before_execute_, before the geometry refresh) a released range retires every view over it at once: it leaveskeys_, the address map, the fast lookup, the tile watches and the title VA aliases. Its storage is freed only oncecompleted_retire_ticket()passes thesubmitted_retire_ticket()taken at retirement, so in-flight work keeps reading valid memory. The recording threads never drain, so they do not wait onGeometryViews::mutex_while a refresh holds it (speed-26).resolve()answers it from the fast map without a lock while nothing was freed, and tries again once a reap has returned budget.TitleBufferWindowskeeps coalesced free ranges per block, destroys a block when its last range comes back, and keeps one empty 4 MiB block as a spare (dropped when a larger request needs the cap), so a title that frees and reallocates each frame does not allocate Vulkan memory each frame. The 2 s backoff after a driver refusal is kept.refresh()walks the tiles by key (lower_bound) instead of holding astd::mapiterator and rawTile*across its periodic unlock, because a retirement can now erase a tile in that window.Nothing changes while under the cap, and with
LEONIDA_GEOMETRY_MB=0(default)note_releasedreturns on one atomic load.Testing
Windows 10 Pro 19045, GeForce GTX 1050 Ti (Pascal, 4 GB, no Resizable BAR), NVIDIA 582.66, MSVC (VS 18 Build Tools), RelWithDebInfo, base
9f9a7c5f3.geometry_views_test(extended: small cap, refusal and retry, deferred reap before/at the ticket, block reclamation, watched-bounds filter, GPU-only twin, queue overflow, spare block): 51 checks, 3/3 passes.9f9a7c5f3(16 failures there); the other three ared3d12_computeandd3d12_geometry_views, which #2059 fixes, andxmem, which is flaky on this host (5/5 on rerun, also without this branch). No test that passes on main fails here.LEONIDA_VK_VALIDATION=1:geometry_views,xmem*,d3d12_title_va*,d3d12_geometry_views,d3d12_title_window_cap,d3d12_api_descriptor_copy*,d3d12_rebound*,d3d12_compute,d3d12_xmem_placed: 17/17 pass, no validation messages.d3d12_geometry_viewsonly reaches the geometry code with #2059 (root signature serialization); the integration numbers above were taken with #2059 applied locally.AI-assisted (Claude Code, Opus 5.5, with Antigravity / Gemini 4 Neon for the first draft of the code; every change reviewed and the GPU-only filter case fixed by hand).
🤖 Generated with Claude Code
Thanks, confirmed and fixed in 6fd430ebc. The release queue was process-wide while every
DeviceStateowns its ownGeometryViews, so the first device to drain took every release.title_geometry_watch.h: eachGeometryViewsnow owns aReleaseQueueand subscribes it on construction (unsubscribes in its destructor).note_releasedkeeps the same filters (watched bounds, GPU-only twin) and then appends the range to every subscribed queue, each with the 65536-entry collapse on its own. Lock order is subscribers -> queue;take_releasedtakes only its own queue.before_execute_and retires against its ownsubmitted_retire_ticket()/completed_retire_ticket(), as you suggested.geometry_views_testcase 12 is your scenario: two instances over the same synthetic extent, onenote_released, both drained -> both retire and reap the view and return tobytes() == 0. It also checks that an instance destroyed in a scope stops receiving releases while the survivor still does.GTX 1050 Ti, Windows 10 19045, NVIDIA 582.66, MSVC RelWithDebInfo:
geometry_views_test60 checks, 3/3 passes. Full ctest with #2059 applied (ford3d12_geometry_viewson Windows 10): 449 tests, the same 13 failures as before this commit, all of which fail on plain9f9a7c5f3too;geometry_views,xmem*,d3d12_title_va*,d3d12_geometry_views,d3d12_computeand the other title-VA cases pass 3x plain and 3x withLEONIDA_VK_VALIDATION=1, no validation messages.AI-assisted (Claude Code).
Checked
6fd430ebcon Linux/Wine (clang++ --target=x86_64-w64-windows-gnu):geometry_views_testpasses all 60 checks (0 failures), confirming the per-GeometryViewsReleaseQueuesubscription fix for multi-device release delivery.Three findings still remain on
6fd430ebc:RetireTickets/GeometryViews) + code inspection — Cross-queue retirement ticket race (DeviceState::drain_geometry_releases):retire_ticket = context->submitted_retire_ticket()is sampled before unlinking outside the replay/submit critical section. Another queue that already captured a geometry VA during replay and publishes its submission afterward can get a higher ticket than the retirement cutoff; if the prior ticket is already complete,reapreclaims the backing while the newer submission is still pending (FAIL backing still holds queue A's data while ticket 6 is incomplete).before_execute_ordering (refresh_shadowsbeforedrain_geometry_releases):fix_console_slotcan resolve a title V# into a live geometry view, anddrain_geometry_releasesin the samebefore_execute_can immediately unlink and reap it before the batch executes (and without an alias entry,TitleVaAliases::removewill not bump the generation).ReleaseQueueoverflows,note_releasedcollapses[min_begin, max_end)in the original address space, anddrain_releasedonly translates the collapsed range if its start is a GPU address. An unrelated CPU release below a GPU twin can mask the GPU-only event's CPU twin if the CPU twin lies outside[min_begin, max_end).AI-assisted.
Merged, thanks @qhukz13! Freeing geometry views when the title releases their range is a real gain under a cap. We merged
mainin and fixed what the review found:TitleVaAliases::forget_copy), so heap slots and the GPU key table drop a reaped view.published_and the backed table (layout_generation,title_block_gone).geometry_views_testkeeps its views off the stack; its new case 13 covers the race, the invalidation and the block removal, and fails without these fixes.main3abb99cad: area tests 28/28, and nothing failing that doesn't fail onmaintoo.main86dc3d86e+bbc8ef17c: it merges cleanly; the semantic suite passes (496 files, 6,336 tests, 0 files failed); the 15 docs and writer tests pass;check_no_game_data.pyis clean on the 8 changed files.AI-assisted (Claude Code, Claude Opus 5.5).