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

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

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


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.

<!-- greyfinch-sync:ivall/xcl:issue:6610266058 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2393). Originally posted by [KOLESNiii](https://github.com/KOLESNiii) on 2026-11-25T17:43:19Z. --- 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.*
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#2383
No description provided.