D3D12.X: the per-draw mirror sync checks its source with readable() at every draw #2392

Open
opened 2026-11-26 05:29:49 +00:00 by github-bot · 0 comments
Owner

@⁠KOLESNiii on GitHub · 2026-11-25 17:43 UTC · original

Part of #2389.

On every draw with a mirrored vertex or index buffer, sync_title_buffers (crates/xcl/src/hle/d3d12x/list_x.rs:3556-3562 on main 3f4495a) checks the source range with gpu::shader::readable before copying it. The indexed path does the same over the index range (list_x.rs:3572). For more than 16 pages (64 KiB), resident_and_readable gives up and readable walks the range with VirtualQuery. The comment on resident_and_readable (gpu/shader.rs:232-238) measures that at 20–25 ms a call in a title's 2 GB block of committed memory.

#693 took this check out of the bind for the same reason ("most of a retail title's render thread at a bind per draw"), but the per-draw copy still makes it. Any instanced draw, or any draw with a non-zero first instance, copies the whole buffer (list_x.rs:3597). So a mirrored buffer of more than 64 KiB pays a VirtualQuery walk on each of those draws.

Proposal: check a mirror's source once, when mirror_of creates the mirror (it already calls readable there), and keep the result until kernelx frees, decommits or reprotects memory in that range. A generation counter that VirtualFree / VirtualProtect / decommit bump would do: compare it per draw, and check again only when it has changed.

Test: a mirrored range stays copied without a readable call while nothing is freed, and it is checked again (and skipped when it is no longer readable) after a decommit in that range.

Found by code reading with Claude Code (Claude Opus 5.5); not measured yet. #2391 gives the numbers.

**@⁠KOLESNiii** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/xcl-dev/xcl/issues/2392) Part of #2389. On every draw with a mirrored vertex or index buffer, `sync_title_buffers` (`crates/xcl/src/hle/d3d12x/list_x.rs:3556-3562` on `main` 3f4495a) checks the source range with `gpu::shader::readable` before copying it. The indexed path does the same over the index range (`list_x.rs:3572`). For more than 16 pages (64 KiB), `resident_and_readable` gives up and `readable` walks the range with `VirtualQuery`. The comment on `resident_and_readable` (`gpu/shader.rs:232-238`) measures that at 20–25 ms a call in a title's 2 GB block of committed memory. #693 took this check out of the bind for the same reason ("most of a retail title's render thread at a bind per draw"), but the per-draw copy still makes it. Any instanced draw, or any draw with a non-zero first instance, copies the whole buffer (`list_x.rs:3597`). So a mirrored buffer of more than 64 KiB pays a `VirtualQuery` walk on each of those draws. **Proposal:** check a mirror's source once, when `mirror_of` creates the mirror (it already calls `readable` there), and keep the result until kernelx frees, decommits or reprotects memory in that range. A generation counter that `VirtualFree` / `VirtualProtect` / decommit bump would do: compare it per draw, and check again only when it has changed. **Test:** a mirrored range stays copied without a `readable` call while nothing is freed, and it is checked again (and skipped when it is no longer readable) after a decommit in that range. *Found by code reading with Claude Code (Claude Opus 5.5); not measured yet. #2391 gives the numbers.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:49 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.