D3D12.X: the per-draw mirror sync copies and index-scans buffers the title has not written #2393

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.

sync_title_buffers (crates/xcl/src/hle/d3d12x/list_x.rs:3539 on main 3f4495a) does the full work on every draw, whether or not the title has written the source since the last draw:

  • Index scan: an indexed draw reads every index it uses on the CPU to find the vertex range (list_x.rs:3577-3583), at every draw, for an index buffer that usually never changes.
  • Whole-buffer copies: with instances > 1 (callers pass at least 2 when the first instance is not 0), an unknown range, or a stride of 0, the whole vertex buffer is copied (list_x.rs:3597). This is 1.1 MiB per draw for the buffer seen below.
  • Allocations: each draw locks LISTS, collects the vertex bindings into a new Vec (list_x.rs:3546), then locks MIRRORS and scans it linearly for each binding (mirrored, list_x.rs:3496).

Proposal:

  1. Skip the copy when the source has not changed since it was last synced. #252 already write-watches GPU-visible title memory outside the windows. A mirror's source could join that watch, or carry a hash per 64 KiB block if it cannot.
  2. Cache the (lo, hi) vertex range per (index buffer, first index, count, base vertex), and drop it when the index source changes.
  3. Use a fixed-size scratch array for the bindings instead of collecting into a Vec.

Seen: in my title's menus, on an RTX 2070 SUPER with main 3f4495a, the first two mirrors appear 36 s in: a 384 KiB index buffer and a 1.1 MiB vertex buffer. Every draw after that goes through this path. I have no numbers from inside a world yet.

Found by code reading with Claude Code (Claude Opus 5.5); not measured yet.

**@⁠KOLESNiii** on GitHub · 2026-11-25 17:43 UTC · [original](https://github.com/xcl-dev/xcl/issues/2393) Part of #2389. `sync_title_buffers` (`crates/xcl/src/hle/d3d12x/list_x.rs:3539` on `main` 3f4495a) does the full work on every draw, whether or not the title has written the source since the last draw: - **Index scan:** an indexed draw reads every index it uses on the CPU to find the vertex range (`list_x.rs:3577-3583`), at every draw, for an index buffer that usually never changes. - **Whole-buffer copies:** with `instances > 1` (callers pass at least 2 when the first instance is not 0), an unknown range, or a stride of 0, the whole vertex buffer is copied (`list_x.rs:3597`). This is 1.1 MiB per draw for the buffer seen below. - **Allocations:** each draw locks `LISTS`, collects the vertex bindings into a new `Vec` (`list_x.rs:3546`), then locks `MIRRORS` and scans it linearly for each binding (`mirrored`, `list_x.rs:3496`). **Proposal:** 1. Skip the copy when the source has not changed since it was last synced. #252 already write-watches GPU-visible title memory outside the windows. A mirror's source could join that watch, or carry a hash per 64 KiB block if it cannot. 2. Cache the `(lo, hi)` vertex range per (index buffer, first index, count, base vertex), and drop it when the index source changes. 3. Use a fixed-size scratch array for the bindings instead of collecting into a `Vec`. **Seen:** in my title's menus, on an RTX 2070 SUPER with `main` 3f4495a, the first two mirrors appear 36 s in: a 384 KiB index buffer and a 1.1 MiB vertex buffer. Every draw after that goes through this path. I have no numbers from inside a world yet. *Found by code reading with Claude Code (Claude Opus 5.5); not measured yet.*
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.