GPU: draws that only read-mark join clamp hoists and windows #3531

Open
neonbyte1 wants to merge 166 commits from upstream-pr/3531 into main
neonbyte1 commented 2026-11-27 14:58:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T14:58:21Z.


Stacked on #2472 and #3197 (plus the Wine compile fix Slay326 is taking into #3197), so this is a draft until they land. The change to review is the last commit, d4e44ed5 (draw.rs, copystat.rs). Follow-up to #3197 as Slay326 asked there.

What's wrong

#2472's hoist and #3197's window both refuse every pipeline that has view marks at all
(pipeline_writes_uav tested p.marks.is_some(), may_store tests marks and
view_marks). Nearly every pixel shader in the title read-marks the textures it takes from
the heap, so the hoisted prefix ends at the first G-buffer draw and almost every G-buffer
draw is clamped on its own. On my stack (RTX 5090, Wine + vkd3d-proton) that is 4,909
single clamps a frame, 35.4 ms of GPU command time; with the rule 1,133 clamps and 9.7 ms
(155.4 → 64.8 ms of command time a frame, 398 → 311 ms a frame in game).

The rule, and why it is safe

Marks come in two kinds, and only one of them can write an argument.

  • A write mark is set beside a store or atomic through an unordered buffer view from
    the heap. mark_view_write only marks handles in view_index, and only heap_handle
    (heap-made views) puts them there; such a view is a table's, the heap's own, or a root
    UAV's view, so a stage that writes marks has one of those write flags anyway. The page
    table's write handle was removed from view_index, and title-memory writes go through
    memory.
  • A read mark is a bit in our own bitmap: u1 (VIEW_WRITES) in MEMORY_SPACE. That
    buffer is host-owned and is never title memory, so it can never be an argument or count
    buffer.
    So a stage with marks and none of the write flags only sets read marks, and a draw or
    dispatch whose only extra write is that bitmap cannot change what any later execution
    reads as arguments. The DXIL of the census shaders agrees: the G-buffer pixel shaders
    (43e24028, 94d28115, 62f761fb) and the mesh shaders (b7a81f5b, df4b2c77) have no
    store op at all, and the one handle they write through is
    createHandleFromBinding(.. [1, 1, 2, i8 1]), props 4107 (a typed buffer), written only
    by read-mark atomics (7, 29, 29, 1, 4 of them); every other handle they make is read.
    43fba464 (one store) and 5ad3a82b (ten) also store through a heap texture UAV, and they
    still clamp on their own.

What changes

One predicate, one decision. draw::may_write_arguments (with
draw::stage_may_write_arguments) replaces pipeline_writes_uav and may_store and tests
only the write flags: table UAVs (used), heap writes (heap_writes), root UAVs as root
descriptors or as their heap views (ROOT_UAV_VIEW), and title memory (memory,
memory_writes, and the stage's memory/memory_dirty). marks and view_marks are not
among them.
draw::clamp_route is that rule's decision, and execute_indirect asks it once:

  • a dispatch, or a pipeline that may write arguments, is clamped on its own, whatever
    the prelude has room for and whatever the window switch says;
  • everything else is hoisted when the prelude takes it (#2472), else joins a
    window
    when VICTORY_CLAMP_WINDOW=1 (#3197), else clamped on its own.
    bind ends the hoisted prefix with the same predicate when a command writes. A draw that
    may write and is clamped on its own goes through crate::indirect::bound, which calls
    end_window first, so the writer always ends the window: no later record can be clamped
    by a pass that runs after the writer's stores, and the writer's own clamp is not moved
    before the window's earlier draws' reads.
    Titles are unaffected: nothing about which draws run, in which order, or what they read
    changes. Only the record clamp of an indirect draw moves, from its own pass into a pass
    that runs before the same draw. Diagnostics: clamps per frame: is now logged whatever
    the switch and splits passes into singles and windows, with draws per window, draws
    hoisted to preludes, the hoisted/windowed ones this rule let in (ClampReadMarked), and
    the ones left alone as they may write arguments (ClampStoring).

Tests (CPU, no device)

  • draw::tests::a_stage_that_only_read_marks_may_join_a_clamp_batch
  • draw::tests::a_table_uav_store_ends_a_clamp_batch
  • draw::tests::a_heap_store_ends_a_clamp_batch
  • draw::tests::a_root_uav_ends_a_clamp_batch (root descriptor, stage facts,
    ROOT_UAV_VIEW; a ROOT_SRV_VIEW does not disqualify)
  • draw::tests::title_memory_ends_a_clamp_batch (shader flags, stage memory and
    memory_dirty)
  • draw::tests::a_read_marking_draw_may_join_a_window_and_the_writer_ends_it: a
    read-marking draw joins a window, the argument-writing draw after it is clamped alone
    (which ends the window) and the next read-marking draw opens a new one; the writer is not
    hoisted even with a free prelude, a dispatch is never hoisted or windowed.
  • indirect::tests::every_clamp_compiles_without_a_root_signature_attribute still covers
    the single, batched and window shaders.

Measured share of the rule (perf stack, #2472 + #3197 + the Wine fix)

Same tree (perf/best2), same binary but for this commit reverted, same switches
(VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info), 420 s runs, medians of the
last 30 heavy reports; RTX 5090, Wine + vkd3d-proton:

windows, old rule windows + rule
passes a frame 2,847 1,138
single clamps 2,780 1,032
windows (draws) 67 (2,150) 106 (3,170)
draws left alone, may write 1,865 117
draws with read marks joined — 1,745 (+706 hoisted)
on the GPU 124.2 ms 78.0 ms
frame 246.8 ms 209.1 ms
So on this stack the rule is worth **46.2 ms of GPU time and 37.7 ms of frame time a
frame** (37 % and 15 %), and 1,709 fewer clamp passes. Four more runs of the same control
binary agree within 197.1–214.0 ms and 73.8–77.0 ms; the norule run's minimum frame
(231.3 ms) is above every control median. The ≈26 µs each removed clamp takes off the GPU is
the barrier and rebind the single-clamp path puts around every draw, not the clamp pass alone
(7.3 µs measured). Frame preparation rises by ≈5 ms (79.1 vs 74.2) for the extra window
bookkeeping, well inside the gain.
Pictures at frames 1700 and 2048 match, judged on luma rather than pixels (two runs of the
same exe differ in 14–16 % of pixels by framing, hint timing and the lit/hazy alternation):
mean luma 31.8 vs 32.5 and 32.5 vs 32.3, luma-histogram correlation 0.994 and 1.000, and the
only blocks that differ are the character's animation phase and the input hint's box. No
missing geometry, shadows or lighting.

Overlap

  • #2472 (hoist) and #3197 (window): the rule changes which draws each may take.
    Because the rule gates both, this branch is stacked: #3197's head 0c997d40 merged onto
    #2472 as 055b5c89, the Wine compile fix 916655cc (Slay326 is taking that into #3197
    with my authorship), then the rule as one commit. Against 0c997d40 the branch therefore
    also shows #2472 and our fork's history (59 files); the change to review is d4e44ed5
    alone — git diff 916655cc d4e44ed5, draw.rs and copystat.rs — or rebased onto your
    head once #2472 and 916655cc are in.
  • Machad3x's "storing draws can close a window": it composes — his change lets a
    storing draw join a window as its last member and end the window right after it is
    recorded, mine widens which draws may be ordinary members. Both go through
    indirect::windowed and both end the window before anything that follows can be
    clamped. His next step (track written table UAVs instead of every table UAV, stores()
    counts used, not written) would narrow the predicate further; I keep used because a
    table's UAV is not classified read or written here yet.
  • VICTORY_CLAMP_WINDOW stays off by default, as you asked. The rule helps with the
    switch either way: without windows it extends the hoisted prefix, with them it fills the
    windows.
    AI-assisted (Claude); measured on my machine, no game data shared.
<!-- greyfinch-sync:Marvisak/VIctory:issue:5528718767 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3531). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T14:58:21Z. --- **Stacked on #2472 and #3197 (plus the Wine compile fix Slay326 is taking into #3197), so this is a draft until they land. The change to review is the last commit, `d4e44ed5` (`draw.rs`, `copystat.rs`). Follow-up to #3197 as Slay326 asked there.** ## What's wrong #2472's hoist and #3197's window both refuse every pipeline that has view marks at all (`pipeline_writes_uav` tested `p.marks.is_some()`, `may_store` tests `marks` and `view_marks`). Nearly every pixel shader in the title read-marks the textures it takes from the heap, so the hoisted prefix ends at the first G-buffer draw and almost every G-buffer draw is clamped on its own. On my stack (RTX 5090, Wine + vkd3d-proton) that is 4,909 single clamps a frame, 35.4 ms of GPU command time; with the rule 1,133 clamps and 9.7 ms (155.4 → 64.8 ms of command time a frame, 398 → 311 ms a frame in game). ## The rule, and why it is safe Marks come in two kinds, and only one of them can write an argument. - A **write mark** is set beside a store or atomic through an unordered buffer view from the heap. `mark_view_write` only marks handles in `view_index`, and only `heap_handle` (heap-made views) puts them there; such a view is a table's, the heap's own, or a root UAV's view, so a stage that writes marks has one of those write flags anyway. The page table's write handle was removed from `view_index`, and title-memory writes go through `memory`. - A **read mark** is a bit in our own bitmap: `u1` (`VIEW_WRITES`) in `MEMORY_SPACE`. That buffer is host-owned and is never title memory, so it can never be an argument or count buffer. So a stage with marks and none of the write flags only sets read marks, and a draw or dispatch whose only extra write is that bitmap cannot change what any later execution reads as arguments. The DXIL of the census shaders agrees: the G-buffer pixel shaders (`43e24028`, `94d28115`, `62f761fb`) and the mesh shaders (`b7a81f5b`, `df4b2c77`) have no store op at all, and the one handle they write through is `createHandleFromBinding(.. [1, 1, 2, i8 1])`, props `4107` (a typed buffer), written only by read-mark atomics (7, 29, 29, 1, 4 of them); every other handle they make is read. `43fba464` (one store) and `5ad3a82b` (ten) also store through a heap texture UAV, and they still clamp on their own. ## What changes One predicate, one decision. `draw::may_write_arguments` (with `draw::stage_may_write_arguments`) replaces `pipeline_writes_uav` and `may_store` and tests only the write flags: table UAVs (`used`), heap writes (`heap_writes`), root UAVs as root descriptors or as their heap views (`ROOT_UAV_VIEW`), and title memory (`memory`, `memory_writes`, and the stage's `memory`/`memory_dirty`). `marks` and `view_marks` are not among them. `draw::clamp_route` is that rule's decision, and `execute_indirect` asks it once: - a dispatch, or a pipeline that may write arguments, is **clamped on its own**, whatever the prelude has room for and whatever the window switch says; - everything else is **hoisted** when the prelude takes it (#2472), else **joins a window** when `VICTORY_CLAMP_WINDOW=1` (#3197), else clamped on its own. `bind` ends the hoisted prefix with the same predicate when a command writes. A draw that may write and is clamped on its own goes through `crate::indirect::bound`, which calls `end_window` first, so the writer always ends the window: no later record can be clamped by a pass that runs after the writer's stores, and the writer's own clamp is not moved before the window's earlier draws' reads. Titles are unaffected: nothing about which draws run, in which order, or what they read changes. Only the record clamp of an indirect draw moves, from its own pass into a pass that runs before the same draw. Diagnostics: `clamps per frame:` is now logged whatever the switch and splits passes into singles and windows, with draws per window, draws hoisted to preludes, the hoisted/windowed ones this rule let in (`ClampReadMarked`), and the ones left alone as they may write arguments (`ClampStoring`). ## Tests (CPU, no device) - `draw::tests::a_stage_that_only_read_marks_may_join_a_clamp_batch` - `draw::tests::a_table_uav_store_ends_a_clamp_batch` - `draw::tests::a_heap_store_ends_a_clamp_batch` - `draw::tests::a_root_uav_ends_a_clamp_batch` (root descriptor, stage facts, `ROOT_UAV_VIEW`; a `ROOT_SRV_VIEW` does not disqualify) - `draw::tests::title_memory_ends_a_clamp_batch` (shader flags, stage `memory` and `memory_dirty`) - `draw::tests::a_read_marking_draw_may_join_a_window_and_the_writer_ends_it`: a read-marking draw joins a window, the argument-writing draw after it is clamped alone (which ends the window) and the next read-marking draw opens a new one; the writer is not hoisted even with a free prelude, a dispatch is never hoisted or windowed. - `indirect::tests::every_clamp_compiles_without_a_root_signature_attribute` still covers the single, batched and window shaders. ## Measured share of the rule (perf stack, #2472 + #3197 + the Wine fix) Same tree (`perf/best2`), same binary but for this commit reverted, same switches (`VICTORY_GPU_OVERLAP=1 VICTORY_CLAMP_WINDOW=1 VICTORY_LOG=info`), 420 s runs, medians of the last 30 heavy reports; RTX 5090, Wine + vkd3d-proton: | | windows, old rule | windows + rule | |---|---:|---:| | passes a frame | 2,847 | **1,138** | | single clamps | 2,780 | 1,032 | | windows (draws) | 67 (2,150) | 106 (3,170) | | draws left alone, may write | 1,865 | 117 | | draws with read marks joined | — | 1,745 (+706 hoisted) | | `on the GPU` | **124.2 ms** | **78.0 ms** | | frame | **246.8 ms** | **209.1 ms** | So on this stack the rule is worth **46.2 ms of GPU time and 37.7 ms of frame time a frame** (37 % and 15 %), and 1,709 fewer clamp passes. Four more runs of the same control binary agree within 197.1–214.0 ms and 73.8–77.0 ms; the norule run's minimum frame (231.3 ms) is above every control median. The ≈26 µs each removed clamp takes off the GPU is the barrier and rebind the single-clamp path puts around every draw, not the clamp pass alone (7.3 µs measured). Frame preparation rises by ≈5 ms (79.1 vs 74.2) for the extra window bookkeeping, well inside the gain. Pictures at frames 1700 and 2048 match, judged on luma rather than pixels (two runs of the same exe differ in 14–16 % of pixels by framing, hint timing and the lit/hazy alternation): mean luma 31.8 vs 32.5 and 32.5 vs 32.3, luma-histogram correlation 0.994 and 1.000, and the only blocks that differ are the character's animation phase and the input hint's box. No missing geometry, shadows or lighting. ## Overlap - **#2472** (hoist) and **#3197** (window): the rule changes which draws each may take. Because the rule gates both, this branch is stacked: #3197's head `0c997d40` merged onto #2472 as `055b5c89`, the Wine compile fix `916655cc` (Slay326 is taking that into #3197 with my authorship), then the rule as one commit. Against `0c997d40` the branch therefore also shows #2472 and our fork's history (59 files); the change to review is `d4e44ed5` alone — `git diff 916655cc d4e44ed5`, `draw.rs` and `copystat.rs` — or rebased onto your head once #2472 and `916655cc` are in. - **Machad3x's "storing draws can close a window"**: it composes — his change lets a storing draw join a window as its *last* member and end the window right after it is recorded, mine widens which draws may be ordinary members. Both go through `indirect::windowed` and both end the window before anything that follows can be clamped. His next step (track written table UAVs instead of every table UAV, `stores()` counts `used`, not written) would narrow the predicate further; I keep `used` because a table's UAV is not classified read or written here yet. - `VICTORY_CLAMP_WINDOW` stays **off** by default, as you asked. The rule helps with the switch either way: without windows it extends the hoisted prefix, with them it fills the windows. _AI-assisted (Claude); measured on my machine, no game data shared._
ColorMeBoom commented 2026-11-27 16:28:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T16:28:26Z.


The CI failure is WARP's wave size, not the change. Your head d4e44ed merged onto main 63bcca4, RX 5700 XT (RDNA1, 32–64 lanes):

  • Hardware: wave_coalesced_marks_equal_per_lane_marks_on_the_gpu passes: "hardware: coalesced marks and results equal the per-lane ones" for all four wave64/coalesced variants. WARP prints no 32-lane waves; skipped.
  • VICTORY_WARP=1 (what the CI runner has): both adapters print no 32-lane waves; skipped, then memory_tests.rs:1220 panics with neither hardware nor WARP SM 6.6 device available. That's the CI failure, not a wrong result.

The fix is the same one valu_tests::run_cases_on uses for a wave of 32 (and that I proposed for the same failure on #2920): remember the wave-size skip, and accept it in the final assert.

let (mut ran, mut wave_skipped) = (0, false);
// ...
if !host.target().runs(32) {
    eprintln!("{label}: no 32-lane waves; skipped");
    wave_skipped = true;
    continue;
}
// ...
assert!(ran > 0 || wave_skipped, "neither hardware nor WARP SM 6.6 device available");

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7223302008 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3531#issuecomment-7223302008). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T16:28:26Z. --- **The CI failure is WARP's wave size, not the change.** Your head `d4e44ed` merged onto `main` `63bcca4`, RX 5700 XT (RDNA1, 32–64 lanes): - Hardware: `wave_coalesced_marks_equal_per_lane_marks_on_the_gpu` passes: "hardware: coalesced marks and results equal the per-lane ones" for all four wave64/coalesced variants. WARP prints `no 32-lane waves; skipped`. - `VICTORY_WARP=1` (what the CI runner has): both adapters print `no 32-lane waves; skipped`, then `memory_tests.rs:1220` panics with `neither hardware nor WARP SM 6.6 device available`. That's the [CI failure](https://github.com/Marvisak/VIctory/actions/runs/46020682387), not a wrong result. The fix is the same one `valu_tests::run_cases_on` uses for a wave of 32 (and that I proposed for the same failure on #2920): remember the wave-size skip, and accept it in the final assert. ```rust let (mut ran, mut wave_skipped) = (0, false); // ... if !host.target().runs(32) { eprintln!("{label}: no 32-lane waves; skipped"); wave_skipped = true; continue; } // ... assert!(ran > 0 || wave_skipped, "neither hardware nor WARP SM 6.6 device available"); ``` AI use: Claude Code (Claude Opus 5.5).
neonbyte1 commented 2026-11-27 16:39:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T16:39:06Z.


@ColorMeBoom thanks, that's exactly it, and thanks for running it on RDNA1 hardware. Taken as you proposed in 869abe58: the wave-size skip is remembered and the final assert accepts it. I checked it with clippy (-D warnings) and formatting; the test itself only runs on a 32-lane adapter here, so the WARP case is your CI run's to confirm.

For reviewers: this test isn't part of the read-mark rule. It comes from the stack this draft sits on (#2958's coalesced marks, compared with per-lane marks), which is why it shows up in this PR's diff against main. The change to review stays the last functional commit, d4e44ed5 (draw.rs, copystat.rs).

AI-assisted (Claude); measured on my machine, no game data shared.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7223511488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3531#issuecomment-7223511488). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T16:39:06Z. --- @ColorMeBoom thanks, that's exactly it, and thanks for running it on RDNA1 hardware. Taken as you proposed in `869abe58`: the wave-size skip is remembered and the final assert accepts it. I checked it with clippy (`-D warnings`) and formatting; the test itself only runs on a 32-lane adapter here, so the WARP case is your CI run's to confirm. For reviewers: this test isn't part of the read-mark rule. It comes from the stack this draft sits on (#2958's coalesced marks, compared with per-lane marks), which is why it shows up in this PR's diff against `main`. The change to review stays the last functional commit, `d4e44ed5` (`draw.rs`, `copystat.rs`). _AI-assisted (Claude); measured on my machine, no game data shared._
ColorMeBoom commented 2026-11-27 17:09:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T17:09:45Z.


@neonbyte1 confirmed at 869abe5, merged onto main 63bcca4:

  • VICTORY_WARP=1 (CI's case): wave_coalesced_marks_equal_per_lane_marks_on_the_gpu passes, with both adapters printing no 32-lane waves; skipped.
  • RX 5700 XT: still passes, "coalesced marks and results equal the per-lane ones", with WARP skipped.
  • The PR's CI run on 869abe5 is green.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7224097244 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3531#issuecomment-7224097244). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-27T17:09:45Z. --- @neonbyte1 confirmed at `869abe5`, merged onto `main` `63bcca4`: - `VICTORY_WARP=1` (CI's case): `wave_coalesced_marks_equal_per_lane_marks_on_the_gpu` **passes**, with both adapters printing `no 32-lane waves; skipped`. - RX 5700 XT: still passes, "coalesced marks and results equal the per-lane ones", with WARP skipped. - The PR's [CI run](https://github.com/Marvisak/VIctory/actions/runs/46035344529/job/140629214466) on `869abe5` is green. AI use: Claude Code (Claude Opus 5.5).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3531:upstream-pr/3531'
git switch 'upstream-pr/3531'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3531'
git switch 'upstream-pr/3531'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3531'
git switch 'upstream-pr/3531'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3531'
git switch 'main'
git merge --squash 'upstream-pr/3531'
git switch 'main'
git merge --ff-only 'upstream-pr/3531'
git switch 'main'
git merge 'upstream-pr/3531'
git push origin 'main'
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
Marvisak/VIctory!3531
No description provided.