Skip to content

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

Merged
brcly merged 2 commits into
brcly:mainfrom
NickStallman:fix/215-writeback
Nov 27, 2026
Merged

brcly merged 2 commits into
brcly:mainfrom
NickStallman:fix/215-writeback

Conversation

@NickStallman

Copy link
Copy Markdown
Contributor

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

NickStallman and others added 2 commits November 27, 2026 11:41
…ges and memory past it alone

The texture-publication self-test places a tiled RGBA8 100x60 texture across
ordinary and write-watch title memory, learns where each texel lives from a
read, closes one page, and has the GPU write the texture four times while a
compute queue waits for the last write's label. Whether a published write
shows in the write watch depends on the host, so only the watched pages past
the texture must stay unrecorded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Under Wine the native write is a request to the server for every run of
texels, even in the provider's own process. Committed read-write pages that
are not write-watched now take a copy that reports a fault instead of raising
it, since the title can unmap its pages after they were queried. Write-watch,
copy-on-write and executable pages keep their existing writes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@brcly
brcly merged commit 025a0f3 into brcly:main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProjectScarlett: 30 s main-thread watchdog (exe+0x23CF683) at the story intro from cross-queue label-wait deadlocks

2 participants