Skip to content

startup: stop probing unmapped guest memory from the texture and no-op paths - #2245

Open
Its3rr0rsWRLD wants to merge 1 commit into
R0Y00:mainfrom
Its3rr0rsWRLD:startup/no-probe-faults
Open

Its3rr0rsWRLD wants to merge 1 commit into
R0Y00:mainfrom
Its3rr0rsWRLD:startup/no-probe-faults

Conversation

@Its3rr0rsWRLD

@Its3rr0rsWRLD Its3rr0rsWRLD commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What it does

One commit (aa355f63, rebased onto main b079f84). No intended behaviour change: the same addresses are found readable or unreadable as before; only how that is found changes.

  • xmem: new export x2w_xmem_mapped_bytes(address, bytes, &mapped) (src/xmem_mapped_pages.cpp, src/xmem_shim.def @23, since @17-@22 are now taken on main). It answers from xmem's page registry, without touching memory, how many bytes from address are mapped. It answers only inside xmem's page-mapping reservations. In every other case it gives no answer and the caller probes as before: an address outside those reservations (including the lazy startup blocks, which are not such reservations), a range that runs past its reservation, a range that a "commit at address" may cover (now recorded), or an "unmapped" answer that VirtualQuery does not confirm as MEM_RESERVE, such as a released reservation.
  • d3d12_xs: readable_window asks xmem first. An unmapped answer is returned without touching the page. A mapped prefix is still probed exactly as before. If xmem.dll or the export is missing, it falls back to the old probe.
  • These paths now go through readable_window instead of x2w_local::readable:
    • publish_tiled_texture (slot-70 by-address textures)
    • the no-op argument checks: names_known_iid and hex_text
    • the ExecuteCommandLists shape test in queue_dynamic
  • 30-frame retry cache: a by-address texture address that a probe found unmapped is not probed again for 30 frames, unless a write to it is announced. This applies in publish_tiled_texture and in upload_texture. It is the only timing difference: such a texture can be picked up up to 30 frames later than before.
  • queue_dynamic checks only the first 32 calls of a slot for an IID, like noop_slot and device_noop_slot already do.
  • New line in the 5 s report: x2w-d3d12 readability: unmapped by xmem's page registry N, unreadable probes skipped N.
  • Tests:
    • xmem_mapped_bytes (tests/xmem_mapped_bytes_check.py) checks the export's answers for: outside memory, an unmapped page, a mapped prefix, a range past the reservation, and a released reservation.
    • startup_queue_probe_{reserved,xmem}_{warp,hardware} (tests/startup_queue_probe.cpp) makes 200 calls of queue slot 30 (a slot still left to queue_dynamic) with r9 set to a reserved, unmapped address. Without xmem at most 32 calls may fault (the first calls are still checked). With xmem's reservation, 0 may fault. Every call must return 0.

Why

Every probe that touches an unmapped page raises a first-chance access violation. Under the debug launcher, each one stops the process for a debugger round trip. On the title tested there were about 21k-25k of these per run, mostly before the intro. Almost all came from slot-70 by-address textures whose pages were not mapped yet. Another ~400 came from queue slot 31, which was called every frame with the base of a pool whose mapping had failed. Slot 31 is now handled on main by queue_page_mappings (#2307), so that source no longer reaches queue_dynamic; the test above uses an unknown slot instead. With this change there are only tens per run.

By my testing it takes the time to the intro from ~4000 frames to ~200 frames. That measurement came from a build that also published by-address textures before their pages were mapped, which is a separate change and is not in this PR.

Independent result from @NiiRoZz (comment, on the earlier head e72dc34d): 52,820 first-chance access violations over a ~255 s run without this change, 125 with it.

Tests

Release build (cmake --preset release, Ninja, MSVC), Windows, on the rebased head. unified_buffer_paths* and vm_page_provenance* are excluded from every run (they leak system commit on this machine).

ctest -j 2 --output-on-failure --timeout 300 -R "xmem_mapped_bytes|startup_queue_probe|startup_address|memory_srv|xmem" -E "unified_buffer_paths|vm_page_provenance"
ctest -j 2 --output-on-failure --timeout 300 -R "^startup_" -E "unified_buffer_paths|vm_page_provenance"
Run Result
xmem_mapped_bytes Passed
startup_queue_probe_reserved_warp / _hardware Passed: 32 access violations in 200 calls (allowed 32)
startup_queue_probe_xmem_warp / _hardware Passed: 0 access violations in 200 calls (allowed 0)
targeted set: startup_address*, *memory_srv*, *xmem*, the new tests 97/97 passed
broad ^startup_ 679/679 passed (4 skipped: startup_view_heap_warp, startup_small_texture_4k_addrlib, startup_logical_view_warp, startup_run_sh)

Fail-first. I built d3d12_xs.dll and xmem.dll from unmodified main (b079f84) and ran the new tests against them:

Against unmodified main Result
startup_queue_probe warp/hardware reserved with main's d3d12_xs.dll 200 access violations in 200 calls, exit 9 (fail)
startup_queue_probe warp/hardware xmem with main's d3d12_xs.dll and the new xmem.dll 200 access violations in 200 calls, exit 9 (fail)
startup_queue_probe warp/hardware xmem with main's xmem.dll exit 21: export missing (fail)
xmem_mapped_bytes_check.py with main's xmem.dll function 'x2w_xmem_mapped_bytes' not found (fail)

There were no failures on this branch, so I did not run a separate broad baseline on unmodified main.

What's left out

  • Publishing a by-address texture whose first page is unmapped (blank until its pages are mapped), instead of refusing it. This was a separate behaviour change in my local branch and is better as its own PR: publish_tiled_texture now has three callers, each with its own outcome handling, and log_partial_tile_view hashes the texels right after publishing, relying on the whole range being readable.
  • Local diagnostics not included: the per-slot no-op call census and the extra [rdx]/[r8] hex logging in queue_dynamic.
  • Unrelated changes from the same local branch not included: DirectStorage spill, the stream-cache cap, the BCPack page-end decode, and the shader lowerings.

Prepared by Claude Opus 5.5 (Claude Code).

🤖 Generated with Claude Code

https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc

@NiiRoZz

NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Local test feedback on head e72dc34d (tested before the current conflict with main; merged into a local instrumented build; one run each, under a debugger-based launcher, not reproducible from the repository):

  • First-chance access violations logged by the launcher over a ~255 s run: 52,820 without this change, 125 with it. Without it, every one of them was at the single probe instruction that reads one byte per 4 KiB page.
  • The 5 s report ended at unmapped by xmem's page registry 34032, unreadable probes skipped 35623.
  • Without the change, the longest by-address SRV calls (2.7-6.3 s) each contained 1,571-10,183 of those faults.
  • Not a clean A/B: the two runs reached different scenes and the shader cache differed, so I am not giving a frame-rate figure. The by-address SRV path stayed CPU-bound with the faults gone; the remaining cost was the linear resource-table lookups, which startup: look up memory SRV resources through an address index #2343 addresses separately (no overlap with this diff: it does not touch publish_tiled_texture's readability check).
  • xmem_mapped_bytes, startup_queue_probe_reserved_warp and startup_queue_probe_xmem_warp passed on the merged build (WARP).
  • Not evaluated: the visual effect of the 30-frame retry delay for a texture found unmapped, and the _hardware variants.

AI-assisted (Claude Code); the runs above were made locally.

@Its3rr0rsWRLD
Its3rr0rsWRLD force-pushed the startup/no-probe-faults branch from e72dc34 to aa355f6 Compare November 25, 2026 20:08
@Its3rr0rsWRLD Its3rr0rsWRLD changed the title startup: stop probing unmapped guest memory from the texture and no-op paths (draft, shared for testing) startup: stop probing unmapped guest memory from the texture and no-op paths Nov 25, 2026
@Its3rr0rsWRLD
Its3rr0rsWRLD marked this pull request as ready for review November 25, 2026 20:09

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of head aa355f6 (comment only, code and fixtures; no merge from this side).

Scope: new xmem export x2w_xmem_mapped_bytes, readable_window in d3d12_xs asks it first, four callers moved onto readable_window, a 30-frame retry cache for unmapped by-address textures, and an IID-shape check limited to the first 32 calls per queue slot. Shared runtime plus a main-executable startup path.

What I read and found sound:

  • x2w_xmem_mapped_bytes only answers inside a page-mapping reservation. It returns no answer (caller probes as before) for other addresses, a range past its reservation, a range a recorded "commit at address" may cover, and an "unmapped" answer that VirtualQuery does not confirm as MEM_RESERVE. The fallback is the old behavior, which is the safe direction.
  • A mapped prefix is still probed with probe_readable, so a race between the registry answer and an unmap costs a fault, not a wrong answer.
  • The shape_checks counter in queue_dynamic sits inside template <int N>, so it is per slot, like noop_slot and device_noop_slot. This matches the PR text.
  • Fixtures: startup_queue_probe_{reserved,xmem}_{warp,hardware} has a control (reserved address without xmem: at most 32 faults in 200 calls) and the xmem case (0 faults). That is a reasonable regression test plus negative control for the fault count.

Open points for the merger:

  • The PR claims to move time-to-intro (~4000 to ~200 frames) and cites a run with 52,820 vs 125 first-chance faults on the title. Those are executable results from the author and @NiiRoZz under a debugger-based launcher. We do not have the title, so we cannot reproduce or confirm them. I report only the fixture side.
  • Timing change: a by-address texture can now appear up to 30 frames later than before. It is documented; whoever verifies on the title should check that it does not hide a texture that was visible before.
  • x2w_xmem_mapped_bytes is a new xmem_shim.def ordinal (@23). Main has moved since (52 commits); the ordinal and the CMakeLists.txt hunk need a fresh conflict check against current main.
  • tests/xmem_mapped_bytes_check.py needs the Windows build tree; I did not run it on Linux.

Commands run locally (worktree on this exact head): git diff --stat origin/main...HEAD, targeted rg and sed reads of the diff, git diff --check origin/main...HEAD (clean), python3 tests/bidi_controls_check.py (PASS). I did not run Win2025 for this PR.

Because the PR claims to advance startup on the real title, the merge decision stays with MasterDomino or @R0Y00, who can verify it on the game. The branch is 52 commits behind main and needs an update first.

AI-assisted; commands listed were executed locally.

…p paths

Every readability probe that touches an unmapped page raises a first-chance access violation. Under
the debug launcher each one stops the process for a debugger round trip. On the title tested there
were about 21000-25000 of them per run, almost all before the intro: by-address (slot-70) textures
whose pages were not mapped yet, and a queue no-op slot (31) called every frame with the base of a
physical-page pool whose mapping had failed. Slot 31 is now handled by queue_page_mappings (R0Y00#2307);
the shape-check cap below still covers the slots left to queue_dynamic.

No intended behaviour change: the same addresses are found readable or unreadable as before; only how
that is found changes. The one timing difference is the 30-frame retry interval for by-address
texture addresses found unmapped (below).

- xmem: new export x2w_xmem_mapped_bytes(address, bytes, &mapped) answers from the page registry,
  without touching memory, how many bytes from address are mapped. It answers only inside xmem's
  page-mapping reservations; for any other address, a range past the reservation, a range a commit at
  address may cover, or an unmapped answer Windows does not confirm as reserved, it gives no answer
  and the caller probes as before.
- d3d12_xs: readable_window asks xmem first (unmapped: no touch; mapped prefix: probed as before).
  publish_tiled_texture, names_known_iid, hex_text and the ExecuteCommandLists shape test in
  queue_dynamic go through readable_window instead of x2w_local::readable.
- A by-address texture address that a probe found unmapped is not probed again for 30 frames
  (unless a write to it is announced).
- queue_dynamic checks only the first 32 calls of a slot for an IID, like noop_slot and
  device_noop_slot already do.
- The 5 s report logs "x2w-d3d12 readability: unmapped by xmem's page registry N, unreadable probes
  skipped N".
- xmem_shim.def: x2w_xmem_mapped_bytes is ordinal 23 (17-22 are taken on main).
- Tests: xmem_mapped_bytes (the export's answers), startup_queue_probe_{reserved,xmem}_{warp,hardware}
  (200 calls of unknown queue slot 30 with a reserved, unmapped r9: at most 32 faults without xmem,
  0 with it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
@Its3rr0rsWRLD
Its3rr0rsWRLD force-pushed the startup/no-probe-faults branch from aa355f6 to c0e5f06 Compare November 25, 2026 20:32

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I rebuilt c0e5f06d in Release and ran six tests for mapped bytes, mapped pages, and reserved/XMem queue probes. All passed on WARP and RTX with zero skips. The new early return in publish_tiled_texture still changes what the caller can see: it applies the frame-based unreadable cache to this path and rejects the new SRV before readable_window can see that pages have since been mapped. A guest can probe an unmapped address, map and populate it, and request the view again in the same frame. Previously the second call reached the actual check. Please retain the registry optimization, but keep the second call's result unchanged (for example, skip the timed negative cache in this path). Add a source-built unmapped → map → publish/readback in one frame with an untouched sentinel for the first call. The older executable reports used different cache/scene conditions. Please keep the timing claim scoped to those reports unless there is a matched run at the final candidate.

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