gpu: bind one leased XMem range for cached mesh draws #2295

Merged
sydney-0o merged 1 commit from upstream-pr/2303 into main 2026-11-25 11:37:38 +00:00
sydney-0o commented 2026-11-25 11:10:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by sydney-0o on 2026-11-25T11:10:53Z.


A cached slot 86 mesh draw can now consume one GPU-written XMem DWORD through a graphics root SRV when X2W_MESH86_XMEM_SRV=1. The cache publisher proves the shader's four-byte read from DXIL. The runtime checks the physical page and byte offset at bind and submission, orders the consumer queue after the writer's fence, and keeps the lease alive through GPU completion.

The source-built fixture covers the wrapped COPY-to-DIRECT path. An ordered draw reads the fresh value in all eight pixels. Omitting the queue wait reads the old value in all eight pixels. A missing writer, a different page, a wrong offset, and an invalid proof marker leave the target clear. A gated consumer also verifies that the original XMem slot stays pinned after the guest mapping is removed and becomes reusable after completion.

Refs #1914, #870. Uses the XMem section lease from #2280.

Validation

Release on Windows 10 build 19045.6456 with app-local WARP 1.0.22 and Agility SDK 1.620.2. The rebased local commit be2bad9d has the same tree as this PR head (61a2d313).

cmake --build out/build/mesh-agility --target startup_indirect_draw_indexed startup_list_copy_check --parallel 3
ctest --test-dir out/build/mesh-agility --no-tests=error -j1 -R '^(startup_indirect_mesh_lease_|startup_indirect_mesh_cache_warp$|startup_mesh_xmem_writer_(warp|hardware)$|startup_mesh86_srv_proof$|startup_list_copy_validation)' --output-on-failure

10 passed, 0 failed, 2 capability skips. Both wrapped mesh cases passed on WARP with the D3D12 debug layer enabled and zero warnings or errors. GTX 1080 Ti (32.0.15.8278) passed the wrapped writer check and skipped the mesh cases. The documentation link and bidi checks also passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603151412 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2303). Originally posted by [sydney-0o](https://github.com/sydney-0o) on 2026-11-25T11:10:53Z. --- A cached slot 86 mesh draw can now consume one GPU-written XMem DWORD through a graphics root SRV when `X2W_MESH86_XMEM_SRV=1`. The cache publisher proves the shader's four-byte read from DXIL. The runtime checks the physical page and byte offset at bind and submission, orders the consumer queue after the writer's fence, and keeps the lease alive through GPU completion. The source-built fixture covers the wrapped COPY-to-DIRECT path. An ordered draw reads the fresh value in all eight pixels. Omitting the queue wait reads the old value in all eight pixels. A missing writer, a different page, a wrong offset, and an invalid proof marker leave the target clear. A gated consumer also verifies that the original XMem slot stays pinned after the guest mapping is removed and becomes reusable after completion. Refs #1914, #870. Uses the XMem section lease from #2280. ### Validation Release on Windows 10 build 19045.6456 with app-local WARP 1.0.22 and Agility SDK 1.620.2. The rebased local commit `be2bad9d` has the same tree as this PR head (`61a2d313`). ```powershell cmake --build out/build/mesh-agility --target startup_indirect_draw_indexed startup_list_copy_check --parallel 3 ctest --test-dir out/build/mesh-agility --no-tests=error -j1 -R '^(startup_indirect_mesh_lease_|startup_indirect_mesh_cache_warp$|startup_mesh_xmem_writer_(warp|hardware)$|startup_mesh86_srv_proof$|startup_list_copy_validation)' --output-on-failure ``` 10 passed, 0 failed, 2 capability skips. Both wrapped mesh cases passed on WARP with the D3D12 debug layer enabled and zero warnings or errors. GTX 1080 Ti (32.0.15.8278) passed the wrapped writer check and skipped the mesh cases. The documentation link and bidi checks also passed.
upstream-sync closed this pull request 2026-11-25 12:01:44 +00:00
tedin7 commented 2026-11-25 12:01:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:12:48Z.

Review: COMMENTED


Review of head 61a2d3139ccca613420a097018af8a7f881a359d (comment-only; no approval, no merge).

Overlap with #2280: #2280 is merged (76a9189c) and is an ancestor of this head. This PR does not redo it. It builds on the lease API and adds x2w_xmem_match_section (export @21, src/xmem_shim.def), a SectionLease{first_byte,length,slots} record, and two shared helpers (mirrored_range, mirrored_backing). x2w_xmem_lease_section now uses those helpers, so there is one copy of the mirror-range and backing check. No duplicate behavior found.

Scope read: 17 files, +1413/-69 (git diff --stat origin/main...HEAD). Read in detail: src/xmem_mapped_pages.cpp, src/xmem_section_lease.h, src/startup_stubs/mesh_xmem_handoff.inl (lease open, write tracking, SRV bind), tools/startup/mesh86_cache.py.

What looks right

  • x2w_xmem_match_section: the page-offset parity check, the bounds against the leased first_byte/length, and the per-slot recheck of the live mirrored backing against the pinned (slab, offset) all hold. I found no overflow: mirrored_range rejects address + length wrap, and length is bounded by the lease before the slot arithmetic.
  • The !length removal in lease_section is safe, because mirrored_range returns false for length 0.
  • prove_mesh_root_srv accepts only: one raw SRV t0 space 0 count 1; one createHandle(57, 0, 0, 0); exactly one constant-offset 4-byte rawBufferLoad on that handle; and only mesh output ops otherwise. The pixel stage may only do input/output. The proof dumps the bytes staged for publication, not the original paths, so there is no check-then-swap window.
  • The new v2 manifest line is only written after the proof passes.

Findings

  • P1: none.
  • P2: none.
  • nit 1 (tests/startup_mesh86_srv_proof_check.py, reject list): there is no mutant with a second DWORD load on the same handle. I replaced the len(handles) != 1 or loads != handles guard in tools/startup/mesh86_cache.py with if False: and ran synthetic mesh/pixel dumps through prove_mesh_root_srv. The two-load dump was then accepted (two-loads ACCEPTED 4), and no Linux-runnable test covers it. The in-repo test needs dxc and could not run here. The compiler may merge two identical loads, but a different-offset or different-mask load on the same handle is already rejected by the regex. A fixture with Load(0) + Load(0) that survives optimization, or a pure-Python dump unit test, would close this.
  • nit 2: CI on this head was still pending when I looked (gh pr checks: Linux Python checks, Windows build/test, gfx1013 fixtures). Please wait for it to go green before moving on.
  • nit 3: the new fixture/tests (startup_indirect_mesh_lease_*, xmem_section_lease_check) are D3D12/Windows only. I did not run them. The PR body reports 10 passed and 2 capability skips on Win10 + WARP 1.0.22, from a local commit stated to have the same tree. I could not verify that claim from here.

Commands run locally (Linux, in a detached worktree of the PR head)

  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: self-test passed; 18 Markdown files, 442 links OK.
  • python3 tests/bidi_controls_check.py: self-test passed; 1593 files, no bidirectional controls.
  • Synthetic-dump run of prove_mesh_root_srv: good dump -> 4; wide load, offset 4, space 1, range 1, pixel-stage resource access and two loads all rejected. With the mutation above, only the two-load case flipped to accepted. The mutation was reverted with git checkout -- ..
  • tests/startup_indirect_mesh_cache_check.py and tests/startup_mesh86_srv_proof_check.py need dxc and a fixture backend. They were not run (no dxc on this host).
  • No Windows/WARP run from me: the change touches the D3D12 C++ runtime, and the author reports a Windows run. A Win2025 gate belongs to the next stage.

Clean-room and title: title is neutral, body cites only issues (#1914, #870, #2280). Mergeable: yes.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056558356 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2303#pullrequestreview-6056558356). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:12:48Z. **Review:** COMMENTED --- Review of head `61a2d3139ccca613420a097018af8a7f881a359d` (comment-only; no approval, no merge). **Overlap with #2280:** #2280 is merged (`76a9189c`) and is an ancestor of this head. This PR does not redo it. It builds on the lease API and adds `x2w_xmem_match_section` (export @21, `src/xmem_shim.def`), a `SectionLease{first_byte,length,slots}` record, and two shared helpers (`mirrored_range`, `mirrored_backing`). `x2w_xmem_lease_section` now uses those helpers, so there is one copy of the mirror-range and backing check. No duplicate behavior found. **Scope read:** 17 files, +1413/-69 (`git diff --stat origin/main...HEAD`). Read in detail: `src/xmem_mapped_pages.cpp`, `src/xmem_section_lease.h`, `src/startup_stubs/mesh_xmem_handoff.inl` (lease open, write tracking, SRV bind), `tools/startup/mesh86_cache.py`. **What looks right** - `x2w_xmem_match_section`: the page-offset parity check, the bounds against the leased `first_byte`/`length`, and the per-slot recheck of the live mirrored backing against the pinned `(slab, offset)` all hold. I found no overflow: `mirrored_range` rejects `address + length` wrap, and `length` is bounded by the lease before the slot arithmetic. - The `!length` removal in `lease_section` is safe, because `mirrored_range` returns false for length 0. - `prove_mesh_root_srv` accepts only: one raw SRV `t0` space 0 count 1; one `createHandle(57, 0, 0, 0)`; exactly one constant-offset 4-byte `rawBufferLoad` on that handle; and only mesh output ops otherwise. The pixel stage may only do input/output. The proof dumps the bytes staged for publication, not the original paths, so there is no check-then-swap window. - The new `v2` manifest line is only written after the proof passes. **Findings** - P1: none. - P2: none. - nit 1 (`tests/startup_mesh86_srv_proof_check.py`, reject list): there is no mutant with a second DWORD load on the same handle. I replaced the `len(handles) != 1 or loads != handles` guard in `tools/startup/mesh86_cache.py` with `if False:` and ran synthetic mesh/pixel dumps through `prove_mesh_root_srv`. The two-load dump was then accepted (`two-loads ACCEPTED 4`), and no Linux-runnable test covers it. The in-repo test needs `dxc` and could not run here. The compiler may merge two identical loads, but a different-offset or different-mask load on the same handle is already rejected by the regex. A fixture with `Load(0) + Load(0)` that survives optimization, or a pure-Python dump unit test, would close this. - nit 2: CI on this head was still pending when I looked (`gh pr checks`: Linux Python checks, Windows build/test, gfx1013 fixtures). Please wait for it to go green before moving on. - nit 3: the new fixture/tests (`startup_indirect_mesh_lease_*`, `xmem_section_lease_check`) are D3D12/Windows only. I did not run them. The PR body reports 10 passed and 2 capability skips on Win10 + WARP 1.0.22, from a local commit stated to have the same tree. I could not verify that claim from here. **Commands run locally (Linux, in a detached worktree of the PR head)** - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: self-test passed; 18 Markdown files, 442 links OK. - `python3 tests/bidi_controls_check.py`: self-test passed; 1593 files, no bidirectional controls. - Synthetic-dump run of `prove_mesh_root_srv`: good dump -> 4; wide load, offset 4, space 1, range 1, pixel-stage resource access and two loads all rejected. With the mutation above, only the two-load case flipped to accepted. The mutation was reverted with `git checkout -- .`. - `tests/startup_indirect_mesh_cache_check.py` and `tests/startup_mesh86_srv_proof_check.py` need `dxc` and a fixture backend. They were not run (no `dxc` on this host). - No Windows/WARP run from me: the change touches the D3D12 C++ runtime, and the author reports a Windows run. A Win2025 gate belongs to the next stage. Clean-room and title: title is neutral, body cites only issues (#1914, #870, #2280). Mergeable: yes. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 12:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T11:40:21Z.


Independent physical mesh readback at 61a2d313. Both hardware modes in tests/startup_indirect_mesh_cache_check.py exited 0 on a desktop GeForce RTX 4060, driver 32.0.15.9579, Windows 11 build 26100.9711. I verified the commit stamp and SHA-256 values from the Windows source build before running with Agility SDK 1.620.2 and DXC 1.9.2609.5. The physical device reported the debug layer unavailable.

  • ordered_control: all eight pixels matched the freshly published XMem value. The submitted mesh draw still matched all eight after the guest mapping was removed.
  • skip-wait: all eight pixels matched the stale value. Both runs preserved the argument guards.
  • Missing writer/proof, an invalid marker with a writer, a different page and a different byte range on the same page kept all eight pixels clear.

The commands were python -B tests/startup_indirect_mesh_cache_check.py <dxc> <startup_indirect_draw_indexed.exe> hardware <xmem.dll> ordered_control and the same command ending in skip-wait.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7161349051 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2303#issuecomment-7161349051). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T11:40:21Z. --- Independent physical mesh readback at `61a2d313`. Both hardware modes in `tests/startup_indirect_mesh_cache_check.py` exited 0 on a desktop GeForce RTX 4060, driver 32.0.15.9579, Windows 11 build 26100.9711. I verified the commit stamp and SHA-256 values from the [Windows source build](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45604995145) before running with Agility SDK 1.620.2 and DXC 1.9.2609.5. The physical device reported the debug layer unavailable. - `ordered_control`: all eight pixels matched the freshly published XMem value. The submitted mesh draw still matched all eight after the guest mapping was removed. - `skip-wait`: all eight pixels matched the stale value. Both runs preserved the argument guards. - Missing writer/proof, an invalid marker with a writer, a different page and a different byte range on the same page kept all eight pixels clear. The commands were `python -B tests/startup_indirect_mesh_cache_check.py <dxc> <startup_indirect_draw_indexed.exe> hardware <xmem.dll> ordered_control` and the same command ending in `skip-wait`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2295
No description provided.