Skip to content

d3d12: test that a view past the title-window cap is never the raw VA (RT-TITLE-WINDOW-OVERFLOW) - #1631

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
Tyrannys:title-window-overflow
Nov 25, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
Tyrannys:title-window-overflow

Conversation

@Tyrannys

@Tyrannys Tyrannys commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-TITLE-WINDOW-OVERFLOW (#1608 (comment))

Now test-only

This PR first added a zeroed scratch window for title memory past LEONIDA_TITLE_WINDOWS_MB, so the GPU would never get the title's raw VA (#1537: one read of it loses the device). Main has since fixed the runtime side another way, in ba62682: past the cap (or with the arena full) a title address is backed by the persistent geometry copy, or else every view writer writes a zero-size V# (no base, no records: loads 0, stores dropped). The raw VA never comes out. That also covers the review points about a shared, writable scratch and the 16 MiB arena reserve, so the scratch window is dropped and the runtime and docs follow main.

What is left is the test, because main had none that dispatches through an over-cap title address:

  • ctest d3d12_title_window_cap runs d3d12_title_va_test --window-cap with LEONIDA_TITLE_WINDOWS_MB=0. Two CBVs of different pages of private title memory are written zero-size (base 0, 0 records, never the raw VA), no window is made, and a dispatch through one reads 64/64 zero words with no validation errors. No game files.

Tested

Windows 11, RTX 4070 SUPER, RelWithDebInfo, on main 384abe5 merged in:

  • d3d12_title_window_cap, d3d12_title_va, d3d12_title_va_shadow, d3d12_geometry_views, d3d12_unmapped_vsharp, d3d12_title_index_window, d3d12_title_vertex_window, d3d12_api_descriptor_copy(_off), d3d12_rebound_*, title_va_alias, title_window_plan, title_window, geometry_views: 20/20 pass.

The real-boot results earlier in this thread (QemmHD, sodove, whoalin1) were for the scratch-window version, not for main's route.

AI-assisted (Claude Code, Claude Opus 5.5).

🤖 Generated with Claude Code

… (RT-TITLE-WINDOW-OVERFLOW)

Past LEONIDA_TITLE_WINDOWS_MB, or with no arena room for a window,
resolve_title_memory handed the GPU the title's raw VA. That names
nothing of the device's, and one read of it lost the device at the
world start (ProjectLeonida#1537). Reserve 16 MiB + 64 KiB of zero-filled arena with
the first window and point such addresses into it instead: the cost is
a wrong result, not the device. The raw VA is kept only when even the
scratch did not fit (logged once).

d3d12_title_window_cap runs d3d12_title_va_test --window-cap with a cap
of 0: two views of the title's memory name the arena, share the
scratch, and a dispatch through one reads zeros.

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

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Real-boot A/B of this PR (head 6d66718) on Windows 11, RTX 4070 SUPER (NVIDIA 621.24), with the default window cap (no LEONIDA_TITLE_WINDOWS_MB). The tree also had #1558 for the separate NVIDIA landing stop; the shaders were the same in both runs.

  • Without this PR (main c7e82e2 + d3d12_xs: make a D16S8 depth texture without UAV when the depth provider refuses it (RT-D16S8-UAV-NVIDIA-FALLBACK) #1558): the device is lost about 110 s into the load, with VK_EXT_device_fault READ_INVALID and the checkpoint in the first group of pipeline-library compute dispatches. 4 of 4 runs.
  • With this PR: the new line fires once at 63 MiB ("… given the zeroed scratch window …"), and that READ_INVALID loss is gone; the compute group runs. 1 of 1 run. 2,672 PresentX, peak 19.2 GB private, 10.5 of 12 GB VRAM, and no pause over 5 s in the D3D12 call stream during the load.
  • What it doesn't change: the next stop is the same one a raised cap (LEONIDA_TITLE_WINDOWS_MB=1024) leads to, a device loss with WRITE_INVALID in a later compute dispatch (reported on Coordinating who works on what (continued from #14) #1608). Here it comes about 55 s into the load, versus about 160 s with the 1024 MiB cap, because the scratch route skips mirroring 800+ MiB per submission.

So this does what it says on a real boot. The write fault is a separate issue.

AI-assisted (Claude Code, Claude Opus 5.5).

@sodove

sodove commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Independent check on native Windows 11, RTX 5070 Ti, NVIDIA 610.74. I applied the runtime and test changes from 6d66718f3 to c7e82e26e to match our existing baseline. The device implementation's Git blob matches the PR head.

The window-cap test and seven related tests passed (8/8, Khronos validation enabled). In the cap test both views used the arena and the GPU read 64/64 zero words. With the same test linked against our baseline runtime library, both views retained the raw address and the assertion stopped the test before dispatch.

One ordinary offline boot per build, same shader set, settings, default title-window cap, native depth mode and four scheduled menu inputs. Both reached the intro and then reported device loss.

Build Window-cap observation Process outcome Local frame check
Baseline Cap reached 132.0 s, breakpoint exit after device loss 11 sampled frames, intro visible
With #1631 Zeroed scratch selected 119.0 s, same exit after device loss 11 sampled frames, intro and a later loading illustration visible

Neither run reached a verified world frame or the runner time limit. Reviewing both launch configurations afterward confirmed that opt-in Vulkan fault collection was off in both. Neither run collected a typed address record. Windows recorded NVIDIA event 153 in both intervals. This verifies the scratch path on Blackwell, but these runs cannot distinguish an invalid read from an invalid write or establish a timing regression.

No game files or logs attached. AI-assisted (OpenAI Codex).

The only conflict was runtime/test/d3d12_title_va_test.cpp: keep the
--window-cap branch (returns early) and main's declined-import and
import-over-shadow checks after it.

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

Copy link
Copy Markdown
Contributor Author

Brought up to date with main at 604ddff by a merge (2c7440f); the branch history is unchanged, no force-push. The only conflict was runtime/test/d3d12_title_va_test.cpp: the --window-cap branch (returns early) is kept, and main's declined-import and import-over-shadow checks follow it. The shim's scratch-window fallback merged cleanly alongside main's external stream windows.

Tested on Windows 11 (RelWithDebInfo), runtime tests only, no game boot:

  • d3d12_title_window_cap, d3d12_title_va, d3d12_geometry_views, d3d12_title_index_window, d3d12_title_vertex_window, d3d12_api_descriptor_copy(_off), d3d12_rebound_tables(_off), d3d12_rebound_second_device, title_va_alias: all pass
  • full ctest: 404/404 passed (22 skipped: they need the game package or tools not installed here)

AI-assisted (Claude Code).

@kawaii-shakal kawaii-shakal 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.

Review (read-only, not run). The zeroed scratch in place of the raw VA is the right direction, and the test covers both the naming and the read. Three points:

  1. The scratch is writable and shared. A UAV or buffer store through an overflowed address writes into it, so later readers through any other overflowed address read that data, not zeros. The docs say "or what another such shader wrote", which is honest. But it can turn a wrong frame into data-dependent behaviour, for example an index read from scratch that a previous dispatch wrote. If that matters, mapping stores to a separate write-only sink, or re-zeroing the scratch when the title-window refresh runs, would keep reads at zero. If not, a sentence on why it is acceptable would help.
  2. 16 MiB + 64 KiB of arena is reserved with the first window, whether or not the cap is ever reached. With the default 256 MiB arena that is about 6 % taken up front, which can push something else into "GPU address arena full" earlier on small configurations. Reserving early is the reason it works when the arena later fills, so this is a trade-off; maybe note it in the docs next to LEONIDA_ARENA_MB.
  3. std::memset(arena.mapped + scratch, ...) assumes the arena is host-mapped. That holds today, because the arena is HOST_VISIBLE. If the M4+ plan in section 3.3 (a device-local arena with staged writes) lands, this becomes a null dereference. A one-line assert or comment would mark the dependency.

AI-assisted review (Claude Code, Claude Opus 5.5).

@whoalin1

Copy link
Copy Markdown
Contributor

Independent verification (native Windows; RTX 4070 SUPER + AMD gfx1036 iGPU, LEONIDA_VK_VALIDATION=1): builds clean (382 targets). Diff reviewed — 16MiB+64KiB zeroed scratch reserved in arena on first window, shared by over-cap addresses via title_scratch_va; new d3d12_title_window_cap ctest + docs. NVIDIA: all 11 related tests PASS incl. d3d12_title_window_cap, title_va/index/vertex windows, rebound tables, api_descriptor_copy; direct run confirms "a dispatch through the scratch window read 64/64 zero words". AMD iGPU: 10/11 fail but pre-existing platform limit — every d3d12_title_* test needs a compute PSO and the iGPU reports maxPushConstantsSize=128 < 144, so push_constants_fit() refuses pipeline creation before any PR code runs (#224, documented); title_va_alias (no compute) passes. This directly implements the fix #1537 suggested (zeroed range instead of device loss); caveat per issue author: removes READ_INVALID loss but the cap itself still needs raising for world start (WRITE_INVALID remains, tracked separately). AI-assisted verification.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
Main's ba62682 already handles a title address past
LEONIDA_TITLE_WINDOWS_MB: the persistent geometry copy backs it, or
else every view writer emits a zero-size V# (loads 0, stores dropped),
so the raw VA never reaches the GPU (ubiquitarianism#1537). That replaces this branch's
zeroed scratch window, so the runtime and docs side take main's version.

The d3d12_title_window_cap test stays, rewritten for main's behaviour:
with a cap of 0, two CBVs of private title memory are written zero-size
(no base, no records, never the raw VA), no window is made, and a
dispatch through one reads zeros. Main had no test that dispatches
through an over-cap title address.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tyrannys Tyrannys changed the title d3d12: title memory past the window cap names a zeroed scratch window (RT-TITLE-WINDOW-OVERFLOW) d3d12: test that a view past the title-window cap is never the raw VA (RT-TITLE-WINDOW-OVERFLOW) Nov 25, 2026
@Tyrannys

Copy link
Copy Markdown
Contributor Author

Brought up to date with main at 384abe5 by a merge (02d719c); no force-push. Main's ba62682 already fixes the runtime side of this: a title address past LEONIDA_TITLE_WINDOWS_MB is backed by the geometry copy, or else written as a zero-size V# (loads 0, stores dropped), never the raw VA. So the scratch window is dropped in favour of main, and this PR now only adds the d3d12_title_window_cap test, rewritten to check main's behaviour (both views zero-size, a dispatch reads 64/64 zeros). Title and description updated.

Thanks @whoalin1, @QemmHD and @sodove for the verification runs on the earlier version.

Tested on Windows 11 (RelWithDebInfo, RTX 4070 SUPER), runtime tests only, no game boot: the 20 title-window, title-VA, geometry-view and unmapped-V# tests pass, d3d12_title_window_cap included.

AI-assisted (Claude Code).

@aslan2142

Copy link
Copy Markdown
Collaborator

Thanks, @Tyrannys, and thanks to @QemmHD for the boot A/B. Closing this, because #1723 (merged today) replaced the same fallback on main:

If you find a case main still misses (for example a root view that still gets a raw address), a new PR on top of #1723's make_title_window / note_unbacked path is welcome, and so is the --window-cap test reworked to expect a zero-size view.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142 aslan2142 closed this Nov 25, 2026
@aslan2142 aslan2142 reopened this Nov 25, 2026
@aslan2142

Copy link
Copy Markdown
Collaborator

Reopened. Sorry, @Tyrannys: my comment above was based on the head before your 13:41 update, and that update already does what it suggests. The branch is main plus only the window-cap test now. We'll review the test-only version on its own.

AI-assisted (Claude Code, Claude Opus 5.5).

@aslan2142
aslan2142 merged commit b0f3d39 into ProjectLeonida:main Nov 25, 2026
2 of 17 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged, as the test-only version. Thank you, @Tyrannys, for cutting it down to what main was missing, and thanks to @QemmHD, @sodove and @whoalin1 for the runs on the earlier version.

AI-assisted (Claude Code, Claude Opus 5.5).

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

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants