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

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

@⁠robot00f on GitHub · 2026-11-27 15:20 UTC · original
robot00f:fix/geometry-views-shadow-protect → main · +172 −8 · 5 files · 1 commits · open

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

**@⁠robot00f** on GitHub · 2026-11-27 15:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2471) `robot00f:fix/geometry-views-shadow-protect` → `main` · +172 −8 · 5 files · 1 commits · open 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](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1894) fixes; with that head applied it passes 3/3 with this change. So nothing new fails here. AI-assisted (OpenCode, DeepSeek).
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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 15:23:31 +00:00
This pull request can be merged automatically.
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/2471/head:github-bot/gh-2471'
git switch 'github-bot/gh-2471'

Merge

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