d3d12: publish texture writes to plain data pages with a store #290

Merged
NickStallman merged 2 commits from upstream-pr/290 into main 2026-11-27 01:52:54 +00:00
NickStallman commented 2026-11-27 01:11:21 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-27T01:11:21Z.


Refs #215. A throughput improvement for texture publication. It does not resolve #215; see the measurements there.

Problem

Publication writes each run of texels back to guest memory with one NtWriteVirtualMemory call. Under Wine each call is a wineserver round trip. In the ProjectScarlett intro stall that was about 98k calls per publication job and 90k wineserver context switches per second. The texture readback thread and wineserver spent most of their time on it.

Change

write_mapped copies with a store when the region is committed, exactly PAGE_READWRITE, and not write-watched.

  • The copy is a small rep movsb routine. The provider's existing vectored handler resumes it at its failure return if the store faults (access violation, in-page error or guard page). So a page the title decommits or protects mid-copy gives the same E_FAIL as before, not a crash.
  • Write-watch, PAGE_WRITECOPY and executable regions keep the native write, so what a title's write watch sees is unchanged.

Measured (RTX 5090, driver 620.70.10, GE-Proton11-14, ProjectScarlett story intro, same build with and without the change, probe totals over the world phase):

before with this change
seconds per world frame 13.9 11.9
publication time per job 1.60 s 1.06 s
time inside the write calls (whole phase) at least 129 s 2.3 s
wineserver context switches per second 90k 3.6k
submit time under the submissions lock, per submit 0.43 s 0.26 s

Each job still reads back and copies about 650 MiB, which is why frames stay slow. That cost is the subject of #215.

Tests

  • New Lanes scenario texture-publication.
    • An RGBA8 100x60 layout-0x105 placed texture spans plain read-write memory and a MEM_WRITE_WATCH allocation.
    • A compute queue waits on a label while the direct queue writes the texture in 4 batches.
    • It checks that every texel lands at its console position, that a PAGE_NOACCESS texel page is left unchanged, that all padding keeps its sentinel, and that nothing past the texture in the watched allocation is touched.
    • It is a correctness guard. It passes with and without the change on AMD (both runs measured) and is not a timing gate.
  • Unit tests in tests/device/placement_guarded_copy.rs and tests/device/placement_writeback.rs. These are typechecked for the Windows target but not run, since the d3d12 tests have no runner here.

Checks (on ab644f0)

  • python -m unittest discover -s tests -q: OK.
  • AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: the full python tuxbox.py check --adapter 1002:13c0 --proton … --prefix … --windows-dxc … passed, 128 gates, including lanes-selftest-texture-publication.
  • RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 128 gates.

Overlap: #258 also edits write_mapped, in a different hunk. The only conflict is the region parameter type on the signature line.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5519455547 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/290). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-27T01:11:21Z. --- Refs #215. A throughput improvement for texture publication. It does **not** resolve #215; see the measurements there. **Problem** Publication writes each run of texels back to guest memory with one `NtWriteVirtualMemory` call. Under Wine each call is a wineserver round trip. In the ProjectScarlett intro stall that was about 98k calls per publication job and 90k wineserver context switches per second. The texture readback thread and wineserver spent most of their time on it. **Change** `write_mapped` copies with a store when the region is committed, exactly `PAGE_READWRITE`, and not write-watched. - The copy is a small `rep movsb` routine. The provider's existing vectored handler resumes it at its failure return if the store faults (access violation, in-page error or guard page). So a page the title decommits or protects mid-copy gives the same `E_FAIL` as before, not a crash. - Write-watch, `PAGE_WRITECOPY` and executable regions keep the native write, so what a title's write watch sees is unchanged. **Measured** (RTX 5090, driver 620.70.10, GE-Proton11-14, ProjectScarlett story intro, same build with and without the change, probe totals over the world phase): | | before | with this change | |---|---:|---:| | seconds per world frame | 13.9 | 11.9 | | publication time per job | 1.60 s | 1.06 s | | time inside the write calls (whole phase) | at least 129 s | 2.3 s | | wineserver context switches per second | 90k | 3.6k | | submit time under the submissions lock, per submit | 0.43 s | 0.26 s | Each job still reads back and copies about 650 MiB, which is why frames stay slow. That cost is the subject of #215. **Tests** - New Lanes scenario `texture-publication`. - An RGBA8 100x60 layout-0x105 placed texture spans plain read-write memory and a `MEM_WRITE_WATCH` allocation. - A compute queue waits on a label while the direct queue writes the texture in 4 batches. - It checks that every texel lands at its console position, that a `PAGE_NOACCESS` texel page is left unchanged, that all padding keeps its sentinel, and that nothing past the texture in the watched allocation is touched. - It is a correctness guard. It passes with and without the change on AMD (both runs measured) and is not a timing gate. - Unit tests in `tests/device/placement_guarded_copy.rs` and `tests/device/placement_writeback.rs`. These are typechecked for the Windows target but not run, since the d3d12 tests have no runner here. **Checks** (on `ab644f0`) - `python -m unittest discover -s tests -q`: OK. - AMD Raphael iGPU (1002:13c0), RADV (Mesa 26.0.8), GE-Proton11-14: the full `python tuxbox.py check --adapter 1002:13c0 --proton … --prefix … --windows-dxc …` passed, 128 gates, including `lanes-selftest-texture-publication`. - RTX 5090 (10de:2b85), driver 620.70.10, GE-Proton11-14: the same full check passed, 128 gates. **Overlap:** #258 also edits `write_mapped`, in a different hunk. The only conflict is the `region` parameter type on the signature line. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
brcly/TuxBox!290
No description provided.