Skip to content

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

Open
Its3rr0rsWRLD wants to merge 2 commits into
R0Y00:mainfrom
Its3rr0rsWRLD:startup/no-probe-faults
Open

Its3rr0rsWRLD wants to merge 2 commits 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.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

This PR now conflicts with main. Conflicting files:

  • CMakeLists.txt
  • src/startup_stubs/d3d12_xs_device.cpp

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

Resolved conflicts:
- CMakeLists.txt: kept both xmem_mapped_bytes and main's xmem_physical_write_owner tests.
- src/xmem_shim.def: main's exports keep @23-@27; x2w_xmem_mapped_bytes moves to @28.
- src/xmem_mapped_pages.cpp: main's Run struct for runs, plus this branch's commits map.
- src/startup_stubs/d3d12_xs_device.cpp: both includes; main's upload_from_title and this branch's xmem lookup before readable_window.
- src/startup_stubs/d3d12_memory_srv.inl: main's max_published_texture_bytes limit with this branch's registry-based readability test.
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I merged main (b1e92256) into this branch as e95f5377, a plain merge commit with no rebase or force-push. It conflicted with main.

Conflicts, each resolved by keeping both sides:

  • CMakeLists.txt: this branch's xmem_mapped_bytes test and main's xmem_physical_write_owner test, both kept.
  • src/xmem_shim.def: main now uses @23–@27 (x2w_xmem_copy_to_destination … x2w_xmem_alias_counts), so x2w_xmem_mapped_bytes moves to @28. tests/xmem_mapped_bytes_check.py binds it by name.
  • src/xmem_mapped_pages.cpp: main's Run struct for runs is kept, followed by this branch's commits map. This branch doesn't read runs.
  • src/startup_stubs/d3d12_xs_device.cpp: both includes are kept, and main's upload_from_title comes before this branch's xmem_mapped_bytes() lookup and readable_window.
  • src/startup_stubs/d3d12_memory_srv.inl publish_tiled_texture: the size test uses main's x2w_startup::max_published_texture_bytes with this branch's !bytes || address < 0x10000. This branch's recently_unreadable / readable_window test then replaces x2w_local::readable as before.

git diff --check origin/main...HEAD is clean, and the net diff against main is this branch's 8 files.

What I ran on e95f5377. I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 8 -E '_hardware$|startup_audio' -R '^(xmem_|startup_queue_probe_|startup_address_|startup_memory_srv|startup_single_element_srv|startup_placed_buffer|startup_compute_dispatch_input|startup_tiled)'
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_(queue_probe_.*|address_.*|single_element_srv.*|placed_buffer.*)_hardware$'
  • Release: 107 of 110 pass and 15 of 15 hardware tests pass. xmem_placeholder_split_{control,deployed,partial} return 77 (capability skip) in both presets.
  • Dev: the same, except startup_address_console_{warp,hardware} hit their 180 s timeout under load. Rerun alone, they pass in 32 s and 43 s.

This merge doesn't address R0Y00's earlier changes request on c0e5f06d, which still needs an answer from you. A different reviewer will re-review the merged head.

Environment: AMD Ryzen 7 9800X3D, NVIDIA GeForce RTX 5090 driver 32.0.16.1088, WARP 10.0.26100.9818, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10.

This reply was AI-assisted.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thanks for keeping this branch current. I reviewed head e95f5377 against current main (1f07b2c1); git merge-tree --write-tree 1f07b2c1 e95f5377 exits 0. The only commit since R0Y00's changes request on c0e5f06d is the merge of main, so that request is still open:

  1. The same-frame case is still refused. publish_tiled_texture still runs if (recently_unreadable(address)) { InterlockedIncrement(&address_probe_skipped); return nullptr; } before readable_window, and nothing in that path lets a later mapping through. A guest that probes an unmapped address, maps it and asks for the view again within 30 frames gets nullptr; before this PR that second call reached the real check. Skipping the timed cache in this path, as R0Y00 suggested, or consulting it only when xmem's registry has no answer, would keep the registry saving without changing the result.
  2. The requested source-built test is missing: unmapped → map → publish/readback in one frame, with an untouched sentinel on the first call. git grep -c recently_unreadable e95f5377 -- tests/ finds nothing.

Also worth fixing:

  • Nothing tests the 30-frame cache in publish_tiled_texture or upload_texture: git grep -cE 'unreadable_retry_frames|address_probe_skipped' e95f5377 -- tests/ finds nothing, and neither new test calls those paths. From reading the code, unreadable_retry_frames = 0 or dropping !announced in upload_texture would leave every test green.
  • The commit-at-address exclusion in x2w_xmem_mapped_bytes (the memory.commits overlap check that returns FALSE) is unpinned. xmem_mapped_bytes_check.py defines WIN_COMMIT but never uses it; its only allocation is virtual_alloc(None, 4 * PAGE_BYTES, WIN_RESERVE, 0, NOACCESS).
  • The body still opens the timing note with "By my testing it takes the time to the intro from ~4000 frames to ~200 frames". As R0Y00 asked, please scope it to the earlier reports (a different local build, not measured on this head) unless there is a matched run on the final candidate.
  • CI is green, but its ctest --preset pr step ran 69 tests and none of the new ones (grep -cE 'xmem_mapped_bytes|startup_queue_probe' on the Windows job log → 0), so the new tests rest on local Windows runs.
  • Hygiene: merge commit e95f5377 has a non-noreply author email, and c0e5f06d carries a Claude-Session: trailer. A squash merge would keep both out of main's history.

Environment: Linux, static review of git objects, git merge-tree and the CI job log. I did no build, WARP or GPU run.

This comment was 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.

6 participants