d3d12: publish a batch's textures on several threads #574

Merged
NathansDomainSolutions merged 3 commits from upstream-pr/574 into main 2026-11-30 19:33:00 +00:00
NathansDomainSolutions commented 2026-11-30 06:24:47 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NathansDomainSolutions on 2026-11-30T06:24:47Z.


Part of #472. With the digest cost gone (private views, or #573), publication is what's left: @NickStallman's RTX 5090 numbers show 903 ms of publication per 6 s window with private views, and 2291 ms with section backing (store 440, retile 374). All of that ran in order on the queue's one publication thread, although the textures in a batch are independent.

Change

  • publish now hands each texture to publish_texture (the old loop body, unchanged apart from taking its scratch buffers from a Scratch).
  • A batch with at least 4 textures and 8 MiB runs on up to half the cores (2 to 8), using scoped threads that take the next texture in turn. Tallies are merged with Tally::merge_parallel, as the check pool does. The first error stops the other threads and is returned.
  • Order is kept where it matters: if any two textures' title memory overlaps, the batch stays on one thread in its original order, so the later texture's bytes still win.
  • TUXBOX_PARALLEL_PUBLICATION=0 turns it off.

Checks

  • d3d12 placement tests under Wine: 105 passed, including two new ones for the parallel runner (every item visited once with tallies summed, and an error stopping the run early and being returned).
  • cargo clippy -D warnings and fmt --check are clean.
  • No world A/B from me yet, because my cache is still cold. Numbers from a warm-cache run would be welcome (TUXBOX_SUBMIT_PROFILE=1; compare the publish-retile and publish-store steps against TUXBOX_PARALLEL_PUBLICATION=0).

This contribution was written by an AI agent (Claude Opus 5.5) operating under my supervision. I am accountable for it and will respond to review.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5560205823 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574). Originally posted by [NathansDomainSolutions](https://github.com/NathansDomainSolutions) on 2026-11-30T06:24:47Z. --- Part of #472. With the digest cost gone (private views, or #573), publication is what's left: @NickStallman's RTX 5090 numbers show 903 ms of publication per 6 s window with private views, and 2291 ms with section backing (store 440, retile 374). All of that ran in order on the queue's one publication thread, although the textures in a batch are independent. **Change** - `publish` now hands each texture to `publish_texture` (the old loop body, unchanged apart from taking its scratch buffers from a `Scratch`). - A batch with at least 4 textures and 8 MiB runs on up to half the cores (2 to 8), using scoped threads that take the next texture in turn. Tallies are merged with `Tally::merge_parallel`, as the check pool does. The first error stops the other threads and is returned. - **Order is kept where it matters:** if any two textures' title memory overlaps, the batch stays on one thread in its original order, so the later texture's bytes still win. - `TUXBOX_PARALLEL_PUBLICATION=0` turns it off. **Checks** - d3d12 placement tests under Wine: 105 passed, including two new ones for the parallel runner (every item visited once with tallies summed, and an error stopping the run early and being returned). - `cargo clippy -D warnings` and `fmt --check` are clean. - No world A/B from me yet, because my cache is still cold. Numbers from a warm-cache run would be welcome (`TUXBOX_SUBMIT_PROFILE=1`; compare the `publish-retile` and `publish-store` steps against `TUXBOX_PARALLEL_PUBLICATION=0`). This contribution was written by an AI agent (Claude Opus 5.5) operating under my supervision. I am accountable for it and will respond to review. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NickStallman commented 2026-11-30 07:05:52 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T07:05:52Z.


@NathansDomainSolutions thanks; we'll run it tonight on an RTX 5090 (warm cache, world runs) as three 20-minute runs: default with TUXBOX_PARALLEL_PUBLICATION=0, #573's watch on with it off, and watch on with it on, and post the publish-* steps.

One thing from reading, not tested: the overlap check compares title virtual addresses. Two textures at different addresses over the same section pages (aliases, which is the case #464 and #573 are about) wouldn't be seen as overlapping, so their order wouldn't be kept. If wrong bytes appear with it on and not off, that's where I'd look. If you think the pages can't alias inside one batch, I'd be glad to be wrong.

<!-- greyfinch-sync:brcly/TuxBox:comment:7271352300 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574#issuecomment-7271352300). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T07:05:52Z. --- @NathansDomainSolutions thanks; we'll run it tonight on an RTX 5090 (warm cache, world runs) as three 20-minute runs: default with `TUXBOX_PARALLEL_PUBLICATION=0`, #573's watch on with it off, and watch on with it on, and post the `publish-*` steps. One thing from reading, not tested: the overlap check compares title virtual addresses. Two textures at *different* addresses over the same section pages (aliases, which is the case #464 and #573 are about) wouldn't be seen as overlapping, so their order wouldn't be kept. If wrong bytes appear with it on and not off, that's where I'd look. If you think the pages can't alias inside one batch, I'd be glad to be wrong.
brcly commented 2026-11-30 11:46:30 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T11:46:30Z.


The Miri failure is in the new test parallel_publication_stops_at_an_error_and_returns_it (tests/device/placement_writeback.rs:278). Converting E_INVALIDARG into a windows::core::Error calls GetErrorInfo, which Miri can't emulate. Mark it the way main marks the others:

#[test]
#[cfg_attr(miri, ignore = "calls GetErrorInfo, which Miri cannot emulate")]
fn parallel_publication_stops_at_an_error_and_returns_it() {

(Or build the error without that conversion, if you'd rather keep it running under Miri.) Separately, I'll review the PR once @NickStallman's three runs are posted.

<!-- greyfinch-sync:brcly/TuxBox:comment:7277506361 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574#issuecomment-7277506361). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T11:46:30Z. --- The Miri failure is in the new test `parallel_publication_stops_at_an_error_and_returns_it` (`tests/device/placement_writeback.rs:278`). Converting `E_INVALIDARG` into a `windows::core::Error` calls `GetErrorInfo`, which Miri can't emulate. Mark it the way main marks the others: ```rust #[test] #[cfg_attr(miri, ignore = "calls GetErrorInfo, which Miri cannot emulate")] fn parallel_publication_stops_at_an_error_and_returns_it() { ``` (Or build the error without that conversion, if you'd rather keep it running under Miri.) Separately, I'll review the PR once @NickStallman's three runs are posted.
NickStallman commented 2026-11-30 18:28:06 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T18:28:06Z.


@NathansDomainSolutions @brcly the runs on the RTX 5090 (10de:2b85, 620.70.10, GE-Proton11-14, main 8ece312f plus this PR and other open ones, no section watch, warm caches, 20-minute cap). One run each, so read it with that in mind.

90a: parallel off (TUXBOX_PARALLEL_PUBLICATION=0) 95a: parallel on (default)
Minutes in the world 10.6 11.4
Publication, ms per MiB 1.00 (10.7 GiB, 58 profiles) 0.58 (57 GiB, 89 profiles)
- retile, ms per MiB 0.58 0.26
- store, ms per MiB 0.77 0.42
Frame, minute 4 to 6 6.6 s 3.1 s
Frame, minute 6 to 8 5.1 s 1.9 s
Frame, minute 8 to 10 3.7 s 1.6 s
Submit, minute 8 to 10 1.2 s 1.2 s
Placement, minute 8 to 10 1.06 s 1.06 s
  • Publication costs about 40% less per MiB with it on. The volumes differ a lot (the runs did different amounts of it), so the per-MiB figure is the one to look at.
  • I can't credit the frame times to it. The submit and placement times per frame are the same in the last window, and most of each frame is outside the submit. 90a also wrote our raster-root captures (TUXBOX_CAPTURE_RASTER_ROOTS), and 95a started with a warmer vkd3d cache, so the frame difference isn't a clean comparison.
  • The section-watch runs (90b, 90c) ended before the world, see #573, so the pair of PRs isn't measured here. No PresentX failed with #574 on alone, and no device loss in either (which is about the length of the runs only).
  • Aliases: two textures over one physical page at different addresses, not separated by the range check (I read it, didn't test). I can run 91a-style repeats with your head if that would help.
<!-- greyfinch-sync:brcly/TuxBox:comment:7287893227 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574#issuecomment-7287893227). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T18:28:06Z. --- @NathansDomainSolutions @brcly the runs on the RTX 5090 (`10de:2b85`, 620.70.10, GE-Proton11-14, main 8ece312f plus this PR and other open ones, no section watch, warm caches, 20-minute cap). One run each, so read it with that in mind. | | 90a: parallel off (`TUXBOX_PARALLEL_PUBLICATION=0`) | 95a: parallel on (default) | |---|---|---| | Minutes in the world | 10.6 | 11.4 | | Publication, ms per MiB | 1.00 (10.7 GiB, 58 profiles) | **0.58** (57 GiB, 89 profiles) | | - retile, ms per MiB | 0.58 | **0.26** | | - store, ms per MiB | 0.77 | **0.42** | | Frame, minute 4 to 6 | 6.6 s | 3.1 s | | Frame, minute 6 to 8 | 5.1 s | 1.9 s | | Frame, minute 8 to 10 | 3.7 s | 1.6 s | | Submit, minute 8 to 10 | 1.2 s | 1.2 s | | Placement, minute 8 to 10 | 1.06 s | 1.06 s | - **Publication costs about 40% less per MiB with it on.** The volumes differ a lot (the runs did different amounts of it), so the per-MiB figure is the one to look at. - **I can't credit the frame times to it.** The submit and placement times per frame are the same in the last window, and most of each frame is outside the submit. 90a also wrote our raster-root captures (`TUXBOX_CAPTURE_RASTER_ROOTS`), and 95a started with a warmer vkd3d cache, so the frame difference isn't a clean comparison. - The section-watch runs (90b, 90c) ended before the world, see #573, so the pair of PRs isn't measured here. No `PresentX failed` with #574 on alone, and no device loss in either (which is about the length of the runs only). - Aliases: two textures over one physical page at different addresses, not separated by the range check (I read it, didn't test). I can run 91a-style repeats with your head if that would help.
brcly commented 2026-11-30 19:12:19 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T19:12:19Z.


Thanks @NickStallman, that's the number we needed: about 40% less publication time per MiB is worth having. Publication is the largest placement cost in our own world runs as well.

@NathansDomainSolutions three things before it can go in:

  1. It now conflicts with main. Please rebase.
  2. The Miri marker on parallel_publication_stops_at_an_error_and_returns_it from my earlier comment is still needed.
  3. Nick's alias question needs an answer in the code. The overlap check compares title virtual addresses, so two textures at different addresses over the same section pages aren't seen as overlapping, and their stores could land in either order. Either order the work by the physical runs (backing::guest_runs gives them), or show that two textures in one batch can't share a page, with a test that would fail if they did.
<!-- greyfinch-sync:brcly/TuxBox:comment:7289009602 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574#issuecomment-7289009602). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T19:12:19Z. --- Thanks @NickStallman, that's the number we needed: about 40% less publication time per MiB is worth having. Publication is the largest placement cost in our own world runs as well. @NathansDomainSolutions three things before it can go in: 1. It now conflicts with `main`. Please rebase. 2. The Miri marker on `parallel_publication_stops_at_an_error_and_returns_it` from my earlier comment is still needed. 3. Nick's alias question needs an answer in the code. The overlap check compares title virtual addresses, so two textures at different addresses over the same section pages aren't seen as overlapping, and their stores could land in either order. Either order the work by the physical runs (`backing::guest_runs` gives them), or show that two textures in one batch can't share a page, with a test that would fail if they did.
NickStallman commented 2026-11-30 19:41:46 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T19:41:46Z.


A correction to my numbers above, which I should have checked first. Both runs (90a and 95a) used a diagnostic build of vkd3d-proton: the same commit GE-Proton11-14 ships (cae8353e), built by us with enable_trace=true and a GPU timestamp patch. The trace build makes COM QueryInterface and interface comparisons about ten times slower, so any CPU time that includes them is inflated, in both runs alike.

  • What that leaves: the two runs used the same DLLs, so the ratio between them (about 40% less publication time per MiB) is less affected than the absolute values, but I can't rule out that part of the gap is trace overhead. The milliseconds are too high for a normal setup.
  • The crash results I posted on #472 and #232 used the same DLLs. They say whether a run loses the GPU and where, not how long anything takes, so I don't think this changes them, but I hadn't said so.
  • Our next runs (GE-Proton11-15, its own vkd3d-proton) are without it. I'll repeat the with/without pair there and post the plain numbers.
<!-- greyfinch-sync:brcly/TuxBox:comment:7289796777 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/574#issuecomment-7289796777). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T19:41:46Z. --- A correction to my numbers above, which I should have checked first. **Both runs (90a and 95a) used a diagnostic build of vkd3d-proton**: the same commit GE-Proton11-14 ships (cae8353e), built by us with `enable_trace=true` and a GPU timestamp patch. The trace build makes COM `QueryInterface` and interface comparisons about ten times slower, so any CPU time that includes them is inflated, in both runs alike. - What that leaves: the two runs used the same DLLs, so the ratio between them (about 40% less publication time per MiB) is less affected than the absolute values, but I can't rule out that part of the gap is trace overhead. The milliseconds are too high for a normal setup. - The crash results I posted on #472 and #232 used the same DLLs. They say whether a run loses the GPU and where, not how long anything takes, so I don't think this changes them, but I hadn't said so. - Our next runs (GE-Proton11-15, its own vkd3d-proton) are without it. I'll repeat the with/without pair there and post the plain numbers.
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!574
No description provided.