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

Closed
opened 2026-11-25 17:43:18 +00:00 by KOLESNiii · 0 comments
KOLESNiii commented 2026-11-25 17:43:18 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-25T17:43:18Z.


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.

<!-- greyfinch-sync:ivall/xcl:issue:6610265708 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2392). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-25T17:43:18Z. --- 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.*
Sign in to join this conversation.
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
xcl-dev/xcl#2382
No description provided.