Skip to content

d3d12: a geometry tile dropped while slot-133 shadows guard it reopens them too (RT-NULL-VTABLE-P4E683D6) - #2471

Open
robot00f wants to merge 1 commit into
ProjectLeonida:mainfrom
robot00f:fix/geometry-views-shadow-protect
Open

robot00f wants to merge 1 commit into
ProjectLeonida:mainfrom
robot00f:fix/geometry-views-shadow-protect

Conversation

@robot00f

@robot00f robot00f commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

d3d12: a geometry tile dropped while slot-133 shadows guard it reopens them too (RT-NULL-VTABLE-P4E683D6)

Claimed in the coordination issue as: RT-NULL-VTABLE-P4E683D6.

What and why

The geometry watch (runtime/src/title_geometry_watch.h) makes a title tile read-only so it sees the title's writes to it. A 4 KiB page of that tile can also be one a slot-133 shadow (ShadowPages in runtime/shims/d3d12_vulkan_device.cpp) keeps read-only: both guard the title's geometry, each queries and protects under its own lock.

Two of the three ways a tile is opened again already tell the shadows, and the third did not:

  • a write fault: shadow_write_fault asks the watch first, and when the watch reopened the whole 64 KiB tile (tile_reopened) every shadow over it calls reopen_range (commit ba626820);
  • a kernel write: open_shadow_pages does the same for the range, rounded out to the tiles the watch reopened;
  • the last reference to a cell going away (release): it made the pages writable and only left a title_memory_map::changed entry, whose effect reaches the shadows at their next refresh().

Between that opening and the next refresh, ShadowPages::write_back still sees the page as kProtected, its held() predicate is false, and it copies the shadow's older bytes over the title's write. That is the measured shape of +0x4e683d6: the title read an object at [arg+0x10], found its vtable word zero ([rcx] = 0, fault at address 0x0, rax = 0) and called through it. The stop only happened in the run that had LEONIDA_GEOMETRY_MB=2048, the only one where the geometry watch guarded thousands of 64 KiB tiles; the run without it went past that point.

What

release() now calls a reopener the layer installs, over the tile whose pages it just made writable, with the watch's mutex released: the fault handler takes a shadow's lock and then the watch's mutex, so calling the shadows under it would invert the order and deadlock. The D3D12 layer points the reopener at reopen_shadow_ranges, the same shadow half open_shadow_pages used. The journal entry stays, for shadows that cover a page of the tile but are not open at the time.

Test

runtime/test/geometry_writes_test.cpp (ctest -R ^geometry_writes$), on a private allocation, no GPU and no game data:

  • an armed cell is read-only; releasing it opens the page, calls the reopener once with the whole tile, records the journal entry and leaves the page read-write and the watch empty;
  • the hook asks the watch again (notify), which takes the watch's mutex: a release that called it with the mutex held deadlocks there (ctest reports the timeout);
  • a cell that guarded nothing calls nothing and records nothing;
  • two holders: nothing until the last one goes.

Negative control: with the reopener call removed, the test fails 5 checks (calls == 1, the two range checks, the mutex check and the two-holder case).

Which GPU

Measured on the card of the report: GeForce GTX 1050 Ti, NVIDIA 582.28, Windows 10 Pro 19045. geometry_writes_test passes there, and d3d12_existing_heap (the slot-133 shadow test) fails exactly as it does on main — texture memory unavailable: 2048 bytes, alignment 1024, type bits 0x0 (vk format 9 256x8), the case #1894 fixes; with that head applied it passes 3/3 with this change. So nothing new fails here.

AI-assisted (OpenCode, DeepSeek).

…s them too (RT-NULL-VTABLE-P4E683D6)

The geometry watch makes a title tile read-only to see the title's writes; a page of it can also be one a slot-133
shadow keeps read-only. A write fault and a kernel write already have the shadows reopen the tile, but release(), the
last cell over it going away, opened the pages and only left a title_memory_map entry for the next refresh: a
write-back in between still took them for unchanged and copied the shadow's older bytes over the title's write.

release() now calls a reopener the layer installs, over the tile, with the watch's mutex released (the fault handler
takes a shadow's lock and then this mutex); the layer points it at the shadows' reopen_range.

Test: geometry_writes_test, on private pages, negative control included (5 checks fail with the call removed).

@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 and locally tested at 1de863bca (merged cleanly onto main ec91d695c).

Verification

  • Environment: Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
  • ctest: geometry_writes, d3d12_existing_heap, d3d12_existing_heap_no_write_watch, d3d12_title_window_write_back, and d3d12_title_window_write_back_fault all passed (5/5).
  • scripts/check_no_game_data.py and git diff --check: clean.

Review notes

  • Lock ordering looks sound across all geometry_writes::release() callers: release() restores protections and erases the cell under s.mutex, unlocks s.mutex, and only then invokes reopen_shadow_ranges() (g_shadow_pages_lock shared --> ShadowPages::lock_ exclusive --> geometry_writes::notify), matching shadow_write_fault's order. Both ShadowPages::reopen_all() and ShadowPages::update_aliased() already release ShadowPages::lock_ before calling release_cells() / geometry_writes::release(), and GeometryViews only holds its own mutex.
  • Keeping reopen(va, it->second) before s.cells.erase(it) avoids leaving a page PAGE_READONLY with no live cell to answer a concurrent write fault. There is still a narrow concurrent window between reopen() making the page writable and reopen_ranges() acquiring ShadowPages::lock_ where another thread's ShadowPages::write_back() (e.g., if release() runs on the async geometry refresher thread) could observe kProtected before the reopen lands, though that is much tighter than leaving kProtected stale until the next refresh.
  • No blocking issues found.

AI-assisted.

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.

2 participants