GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3195

Open
Slay326 wants to merge 4 commits from upstream-pr/3197 into main
Slay326 commented 2026-11-26 12:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Slay326 on 2026-11-26T12:06:01Z.


Relation to #2472

This overlaps with #2472 by ESAT586, which takes the same approach: it batches the per-draw argument clamps of runs of indirect draws into fewer passes. Either this PR or #2472 should be merged, not both. Both batch the same clamps but reach different draws: #2472 the start of each list up to its first writing command, this PR anywhere in the list (each window ends at the next other draw). If #2472 is merged, I will close this and only bring the remaining windows back as a follow-up on top of it if in-game numbers show it matters.

I am opening it because we measured this version in game, so the numbers below may help with the decision. The differences I can see:

  • #2472 hoists the clamps into the list prelude and is always on. Here a window's clamp pass is recorded in place, where the first draw's single clamp would have been. The whole path is behind VICTORY_CLAMP_WINDOW=1; with the variable unset it is the same path as main.
  • #2472 copies into scratch chunks through an SRV and stops hoisting for the rest of the list at the first call it cannot hoist. Here a window ends at any other draw, dispatch, UAV clear, library recording or list close, and the next eligible indirect draw opens a new one.
  • #2472 has a synthetic benchmark on an RTX 3060 Ti. This PR has in-game numbers on an RTX 3070, measured on a stack (see Tested).

Problem

Each indirect execution gets its own argument clamp (indirect::bound). That is a UAV barrier, a one-group compute dispatch, another barrier and a transition, then the draw with the graphics pipeline bound again. In the world that comes to about 5,100 clamp passes a frame. The card switches from drawing to compute and back for every record, and no draw overlaps the next. Measured with GPU timestamps, the clamps alone took about 29 ms a frame.

Change

Only crates/victory-gpu changes. With VICTORY_CLAMP_WINDOW=1:

  • indirect.rs: an indirect draw (not a dispatch) whose pipeline stores to no buffer opens a window. The window costs one UAV barrier and one clamp dispatch, placed where the single clamp would be. The clamp shader reads a table in the list's upload memory. The CPU fills that table while it records the following draws, and the GPU reads it only when the list runs. Each following draw that can join appends its record and reads its arguments from its part of the window's buffer. It needs no pass, barrier, transition or pipeline rebind of its own. The budget is charged in draw order, with the same bounds as the single clamp.

  • A window ends at:

    • any other draw, dispatch or UAV clear
    • an indirect dispatch
    • an indirect draw whose shaders may store (UAVs in tables, roots or the heap, view marks, writes to title memory)
    • library recording (external.rs)
    • list close or reset (host.rs)

    A new window starts when one is full (64 draws, 64 KiB, 4,096 records) or when the arguments come from a fifth source buffer.

  • draw.rs: execute_indirect uses the window when it can, and the single clamp as before when it cannot. may_store decides.

  • copystat.rs (diagnostics only): a "clamps per frame" line, printed only with the variable set. It counts single passes, windows, draws per window, and the draws clamped alone because they may store.

The switch is off by default. With the variable unset, the only added work is one cached flag check per draw and one at each list close and reset. The clamp shader is compiled by the host, so the translator's source hash and shader caches stay as they are.

Tested

Windows 11 Pro 26200, RTX 3070 8 GB (driver 610.88), title 1.0.2.1, release + diagnostics, BVH on, VICTORY_BACK_THREADS=4. 480 s runs in A-B-A order, same shader cache.

main alone cannot be measured on this card: it runs at 0.1 fps because the view heap overflows without #1779. The numbers therefore come from our test stack, an older main plus open NVIDIA PRs (among them #1762, #1779 and #2242/#2280/#2409). This commit, with the variable set, was the only change between A and B:

run ms/frame (median) = prepare + GPU + back p95 fps
A, mean of 4 runs (spread 10.7 ms) 405 1,280-1,814 2.4-2.5
B, VICTORY_CLAMP_WINDOW=1 379.1 = 135.4 + 170.1 + 72.0 864 2.6
  • B is 26 ms a frame faster than A, and all of the gain is GPU time (199 -> 170 ms).
  • Clamp passes went from ~5,100 to 2,943 a frame: 71 windows held 2,245 draws (31.8 per window). 1,909 indirect draws were still clamped alone because their shaders may store.
  • No crash or device removal. The world frame looks the same (no missing or extra geometry).
  • RTX 4070 (second machine, same stack): GPU time drops by about 17 ms there too, but the frame as a whole did not get faster beyond the run-to-run spread (A 393-410 ms, B 400 ms). I can't explain that yet.

Unit tests, all with synthetic data (garbage records, no game data):

  • windows_clamp_as_single_clamps_do: a window gives the single clamp's results word for word. Cases: garbage records, the budget running out mid-window, more than 64 draws, two sources, and a 100-record draw across two tiles.
  • a_window_after_a_spent_budget_runs_empty
  • a_store_ends_the_window: includes the counter-check that a window left open would read the old value.
  • a_window_clamps_max_records_whatever_the_count
  • windows_leave_the_argument_buffer_common: in any list order.

Checks on this branch (origin/main 63bcca4 + this commit), RTX 3070:

  • cargo test -p victory-gpu --release -- --test-threads=1: 249 passed / 2 failed with diagnostics, 234 passed / 2 failed without. The two failures are the known heap-size pair on NVIDIA (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views), which fail on main too.
  • cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean with and without diagnostics.
  • cargo xtask policy: ok.

Not addressed

  • The 1,909 draws clamped alone: the "may store" rule is conservative, since any write to title memory counts. Narrowing it is a follow-up.
  • Indirect dispatches keep the single clamp.
  • The unit tests check the window pass itself. Where draw.rs, host.rs and external.rs end windows is covered only by the game runs.
  • With the variable set, the barriers between joined draws are gone, and that could expose missing synchronization elsewhere. I saw none, but I did not run GPU-based validation on a capture.
  • The game numbers come from the same change on our stack, not from this exact branch.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5509713222 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-26T12:06:01Z. --- ## Relation to #2472 This overlaps with #2472 by ESAT586, which takes the same approach: it batches the per-draw argument clamps of runs of indirect draws into fewer passes. Either this PR or #2472 should be merged, not both. Both batch the same clamps but reach different draws: #2472 the start of each list up to its first writing command, this PR anywhere in the list (each window ends at the next other draw). If #2472 is merged, I will close this and only bring the remaining windows back as a follow-up on top of it if in-game numbers show it matters. I am opening it because we measured this version in game, so the numbers below may help with the decision. The differences I can see: - #2472 hoists the clamps into the list prelude and is always on. Here a window's clamp pass is recorded in place, where the first draw's single clamp would have been. The whole path is behind `VICTORY_CLAMP_WINDOW=1`; with the variable unset it is the same path as `main`. - #2472 copies into scratch chunks through an SRV and stops hoisting for the rest of the list at the first call it cannot hoist. Here a window ends at any other draw, dispatch, UAV clear, library recording or list close, and the next eligible indirect draw opens a new one. - #2472 has a synthetic benchmark on an RTX 3060 Ti. This PR has in-game numbers on an RTX 3070, measured on a stack (see Tested). ## Problem Each indirect execution gets its own argument clamp (`indirect::bound`). That is a UAV barrier, a one-group compute dispatch, another barrier and a transition, then the draw with the graphics pipeline bound again. In the world that comes to about 5,100 clamp passes a frame. The card switches from drawing to compute and back for every record, and no draw overlaps the next. Measured with GPU timestamps, the clamps alone took about 29 ms a frame. ## Change Only `crates/victory-gpu` changes. With `VICTORY_CLAMP_WINDOW=1`: - `indirect.rs`: an indirect draw (not a dispatch) whose pipeline stores to no buffer opens a window. The window costs one UAV barrier and one clamp dispatch, placed where the single clamp would be. The clamp shader reads a table in the list's upload memory. The CPU fills that table while it records the following draws, and the GPU reads it only when the list runs. Each following draw that can join appends its record and reads its arguments from its part of the window's buffer. It needs no pass, barrier, transition or pipeline rebind of its own. The budget is charged in draw order, with the same bounds as the single clamp. - A window ends at: - any other draw, dispatch or UAV clear - an indirect dispatch - an indirect draw whose shaders may store (UAVs in tables, roots or the heap, view marks, writes to title memory) - library recording (`external.rs`) - list close or reset (`host.rs`) A new window starts when one is full (64 draws, 64 KiB, 4,096 records) or when the arguments come from a fifth source buffer. - `draw.rs`: `execute_indirect` uses the window when it can, and the single clamp as before when it cannot. `may_store` decides. - `copystat.rs` (diagnostics only): a "clamps per frame" line, printed only with the variable set. It counts single passes, windows, draws per window, and the draws clamped alone because they may store. The switch is off by default. With the variable unset, the only added work is one cached flag check per draw and one at each list close and reset. The clamp shader is compiled by the host, so the translator's source hash and shader caches stay as they are. ## Tested Windows 11 Pro 26200, RTX 3070 8 GB (driver 610.88), title 1.0.2.1, release + `diagnostics`, BVH on, `VICTORY_BACK_THREADS=4`. 480 s runs in A-B-A order, same shader cache. `main` alone cannot be measured on this card: it runs at 0.1 fps because the view heap overflows without #1779. The numbers therefore come from our test stack, an older main plus open NVIDIA PRs (among them #1762, #1779 and #2242/#2280/#2409). This commit, with the variable set, was the only change between A and B: | run | ms/frame (median) = prepare + GPU + back | p95 | fps | |---|---|---|---| | A, mean of 4 runs (spread 10.7 ms) | 405 | 1,280-1,814 | 2.4-2.5 | | B, `VICTORY_CLAMP_WINDOW=1` | 379.1 = 135.4 + 170.1 + 72.0 | 864 | 2.6 | - B is 26 ms a frame faster than A, and all of the gain is GPU time (199 -> 170 ms). - Clamp passes went from ~5,100 to 2,943 a frame: 71 windows held 2,245 draws (31.8 per window). 1,909 indirect draws were still clamped alone because their shaders may store. - No crash or device removal. The world frame looks the same (no missing or extra geometry). - RTX 4070 (second machine, same stack): GPU time drops by about 17 ms there too, but the frame as a whole did not get faster beyond the run-to-run spread (A 393-410 ms, B 400 ms). I can't explain that yet. Unit tests, all with synthetic data (garbage records, no game data): - `windows_clamp_as_single_clamps_do`: a window gives the single clamp's results word for word. Cases: garbage records, the budget running out mid-window, more than 64 draws, two sources, and a 100-record draw across two tiles. - `a_window_after_a_spent_budget_runs_empty` - `a_store_ends_the_window`: includes the counter-check that a window left open would read the old value. - `a_window_clamps_max_records_whatever_the_count` - `windows_leave_the_argument_buffer_common`: in any list order. Checks on this branch (`origin/main` 63bcca4 + this commit), RTX 3070: - `cargo test -p victory-gpu --release -- --test-threads=1`: 249 passed / 2 failed with `diagnostics`, 234 passed / 2 failed without. The two failures are the known heap-size pair on NVIDIA (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`), which fail on `main` too. - `cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings`: clean with and without `diagnostics`. - `cargo xtask policy`: ok. ## Not addressed - The 1,909 draws clamped alone: the "may store" rule is conservative, since any write to title memory counts. Narrowing it is a follow-up. - Indirect dispatches keep the single clamp. - The unit tests check the window pass itself. Where `draw.rs`, `host.rs` and `external.rs` end windows is covered only by the game runs. - With the variable set, the barriers between joined draws are gone, and that could expose missing synchronization elsewhere. I saw none, but I did not run GPU-based validation on a capture. - The game numbers come from the same change on our stack, not from this exact branch. AI-assisted.
Dukestar69 commented 2026-11-26 12:51:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:51:35Z.

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib indirect:: -- --test-threads=1: 11/11 passed on RTX 5090 and WARP (including a_store_ends_the_window, a_window_after_a_spent_budget_runs_empty, a_window_clamps_max_records_whatever_the_count, windows_clamp_as_single_clamps_do, and windows_leave_the_argument_buffer_common).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean opt-in VICTORY_CLAMP_WINDOW batching for consecutive indirect draw clamps.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074431501 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#pullrequestreview-6074431501). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T12:51:35Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib indirect:: -- --test-threads=1`: 11/11 passed on RTX 5090 and WARP (including `a_store_ends_the_window`, `a_window_after_a_spent_budget_runs_empty`, `a_window_clamps_max_records_whatever_the_count`, `windows_clamp_as_single_clamps_do`, and `windows_leave_the_argument_buffer_common`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Clean opt-in `VICTORY_CLAMP_WINDOW` batching for consecutive indirect draw clamps. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
steven-seagull27 commented 2026-11-26 13:04:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T12:13:37Z.


Tested the library-recording boundary on RTX 5080 and Windows WARP. I recorded two valid draw-argument records, replaced both records with a native GPU CopyBufferRegion through the public external::record callback, then clamped the same two offsets again. Each result below repeated in two fresh processes per adapter.

Implementation Before the copy After the copy Correct argument words per run
Base 63bcca43 Per-call Per-call 16/16
#3197 cf33c260 Two records in one window Two records in a new window 16/16
#2472 c673921c Both records hoisted Both clamped per-call 16/16

As a negative control I removed only the end_window(host) call in external::record. The source buffer still contained all eight replacement words, but the clamp returned eight stale words out of eight after the callback on each adapter. For example, the first updated draw was [9, 3, 11, 2] and the unclosed window returned [3, 1, 7, 0].

This exercises the actual public library callback and GPU copy. The harness called the clamp entry points directly and read their output buffers. It establishes ordering at that boundary, without drawing a frame or estimating frame time. Alternative PR

<!-- greyfinch-sync:Marvisak/VIctory:comment:7191729253 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7191729253). Originally posted by [steven-seagull27](https://github.com/steven-seagull27) on 2026-11-26T12:13:37Z. --- Tested the library-recording boundary on **RTX 5080 and Windows WARP**. I recorded two valid draw-argument records, replaced both records with a native GPU `CopyBufferRegion` through the public `external::record` callback, then clamped the same two offsets again. Each result below repeated in two fresh processes per adapter. | Implementation | Before the copy | After the copy | Correct argument words per run | |---|---|---|---:| | Base `63bcca43` | Per-call | Per-call | 16/16 | | #3197 `cf33c260` | Two records in one window | Two records in a new window | 16/16 | | #2472 `c673921c` | Both records hoisted | Both clamped per-call | 16/16 | As a negative control I removed only the `end_window(host)` call in `external::record`. The source buffer still contained all eight replacement words, but the clamp returned **eight stale words out of eight** after the callback on each adapter. For example, the first updated draw was `[9, 3, 11, 2]` and the unclosed window returned `[3, 1, 7, 0]`. This exercises the actual public library callback and GPU copy. The harness called the clamp entry points directly and read their output buffers. It establishes ordering at that boundary, without drawing a frame or estimating frame time. [Alternative PR](https://github.com/Marvisak/VIctory/pull/2472)
slauko commented 2026-11-26 14:01:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slauko on 2026-11-26T13:29:46Z.


Ported this window to a Linux/Wine line (RTX 3080 Ti, vkd3d-proton ec20719, uiliannn's base) — it is the piece that finally served this title's mesh draws, and the numbers may help your decision with #2472:

Before (VICTORY_CLAMP_WINDOW off, this line's older step-based window on): 1,757 to 1,796 indirect clamps a frame in the cell — 313 to 360 compute dispatches, 1,186 to 1,230 mesh draws (kind 10) clamped one at a time, ~250 draws. The mesh records lie in one ~100 MB argument buffer, 16 to 33,056 bytes apart from one draw to the next, so no step-based window can serve them (m42/m44).

With your window (VICTORY_CLAMP_WINDOW=1): 295 to 355 clamps a frame — only the compute dispatches are left, the mesh draws all join (m48). The cell's first steady line came 79 s after the launch, and the frame is in the 230s at ~3,600 draws in the run I could read before the steady stop; the settled-cell A/B is running now and I will add it.

Two things a porter may hit on a tree that has an older step window as well:

  • They must not run together. Both write the list's indirect scratch at offset 0; with the step window still on (m48) the count looked right but the two could overwrite each other's records. On this line the step window now yields when VICTORY_CLAMP_WINDOW is set, and the clean run is m49.
  • The pass is recorded once, the table grows after it — your comment says it; on this line it needed one care point: a draw that cannot join (another buffer, too many records) must end the open window before the single clamp writes the same scratch buffer, or it overwrites the window's records behind the draws that already joined it.

I did not take may_store (this line's translated().stores is an ISA decode over the same accesses), the arguments-as-scratch, or the external/clear hooks (no such sites here).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193429788 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7193429788). Originally posted by [slauko](https://github.com/slauko) on 2026-11-26T13:29:46Z. --- Ported this window to a Linux/Wine line (RTX 3080 Ti, vkd3d-proton `ec20719`, uiliannn's base) — it is the piece that finally served this title's mesh draws, and the numbers may help your decision with #2472: **Before** (`VICTORY_CLAMP_WINDOW` off, this line's older step-based window on): 1,757 to 1,796 indirect clamps a frame in the cell — 313 to 360 compute dispatches, 1,186 to 1,230 **mesh draws** (kind 10) clamped one at a time, ~250 draws. The mesh records lie in one ~100 MB argument buffer, 16 to 33,056 bytes apart from one draw to the next, so no step-based window can serve them (`m42`/`m44`). **With your window** (`VICTORY_CLAMP_WINDOW=1`): **295 to 355 clamps a frame** — only the compute dispatches are left, the mesh draws all join (`m48`). The cell's first steady line came 79 s after the launch, and the frame is in the 230s at ~3,600 draws in the run I could read before the steady stop; the settled-cell A/B is running now and I will add it. Two things a porter may hit on a tree that has an older step window as well: - **They must not run together.** Both write the list's indirect scratch at offset 0; with the step window still on (`m48`) the count looked right but the two could overwrite each other's records. On this line the step window now yields when `VICTORY_CLAMP_WINDOW` is set, and the clean run is `m49`. - **The pass is recorded once, the table grows after it** — your comment says it; on this line it needed one care point: a draw that cannot join (another buffer, too many records) must end the open window *before* the single clamp writes the same scratch buffer, or it overwrites the window's records behind the draws that already joined it. I did not take `may_store` (this line's `translated().stores` is an ISA decode over the same accesses), the `arguments`-as-scratch, or the external/clear hooks (no such sites here).
slauko commented 2026-11-26 14:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slauko on 2026-11-26T13:33:32Z.


The settled-cell numbers, and they go the other way here — worth knowing before #2472's decision:

Same build, same switch set, only VICTORY_CLAMP_WINDOW differs, the cell at ~5,000 draws:

this line's step window (before) your table window
indirect clamps per frame 1,757–1,796 295–355
on the GPU, ms ~85 144–232
frame, cell median 208.1 ms (m47) 274.6 ms (m49)

So it does exactly what it promises for the counts — the 1,190 mesh draws that no step can serve all join, only the compute dispatches remain — and it loses 66 ms on the card. The reason is visible in the shader: the window's pass is one group that loops over every record of the run (for tile ..., one group, to charge the budget in exact order). A run here holds a few thousand records, so that serial walk costs more than the ~1,790 per-call passes it replaces — where a step window's pass is 64 threads over one group of records and ends.

What would win on this stack, if you take it further: the same table, but the records' bounds computed per group (one group per tile of 64, like the single clamp does) and the budget charged with the interlocked walk the single clamp uses, so the pass stops being serial. Your table is the part that is right; the pass's shape is what costs.

(The port is in my tree behind VICTORY_CLAMP_WINDOW, off. Two porters' notes: the two window kinds must not run together — both write the list's indirect scratch at offset 0 — and a draw that cannot join has to end the open window before the single clamp writes that buffer.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193517041 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7193517041). Originally posted by [slauko](https://github.com/slauko) on 2026-11-26T13:33:32Z. --- The settled-cell numbers, and they go **the other way** here — worth knowing before #2472's decision: Same build, same switch set, only `VICTORY_CLAMP_WINDOW` differs, the cell at ~5,000 draws: | | this line's step window (before) | your table window | |---|---:|---:| | indirect clamps per frame | 1,757–1,796 | **295–355** | | `on the GPU`, ms | ~85 | **144–232** | | frame, cell median | **208.1 ms** (`m47`) | **274.6 ms** (`m49`) | So it does exactly what it promises for the *counts* — the 1,190 mesh draws that no step can serve all join, only the compute dispatches remain — and it **loses 66 ms** on the card. The reason is visible in the shader: the window's pass is **one group that loops over every record of the run** (`for tile ...`, one group, to charge the budget in exact order). A run here holds a few thousand records, so that serial walk costs more than the ~1,790 per-call passes it replaces — where a step window's pass is `64` threads over one group of records and ends. What would win on this stack, if you take it further: the same table, but the records' *bounds* computed per group (one group per tile of 64, like the single clamp does) and the budget charged with the interlocked walk the single clamp uses, so the pass stops being serial. Your table is the part that is right; the pass's shape is what costs. (The port is in my tree behind `VICTORY_CLAMP_WINDOW`, off. Two porters' notes: the two window kinds must not run together — both write the list's indirect scratch at offset 0 — and a draw that cannot join has to end the open window before the single clamp writes that buffer.)
andrewpozdnakov7-jpg commented 2026-11-26 14:01:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:45:38Z.


@Slay326 I checked cf33c26 together with #2996 at 5385cc6. They merge cleanly as text, but the mesh argument clamp differs when the window is enabled. The same valid (3, 2, 4) input read back as [24, 1, 1] through the single clamp and [3, 1, 1] through the window. This drops 21 of the 24 mesh groups.

The integration d16ae7d retains both exact heads and applies #2996's group-count rule to the window too. The same GPU readback then agreed on both paths for (3, 2, 4) → [24, 1, 1] and (2, 3, 5) → [30, 1, 1]. The existing draw-order and budget tests passed.

App-local Agility 1.620.2/WARP 1.0.22: 13 indirect tests passed. Full GPU diagnostics with VICTORY_CLAMP_WINDOW=0 and =1 each had 255 passes, 0 failures and 1 ignored. Strict GPU Clippy with all features passed. This checks GPU argument readback with synthetic inputs.

If both changes are taken, the integration is ready for the mesh-clamp side. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the resolution into another commit. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193798510 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7193798510). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T13:45:38Z. --- @Slay326 I checked `cf33c26` together with #2996 at `5385cc6`. They merge cleanly as text, but the mesh argument clamp differs when the window is enabled. The same valid `(3, 2, 4)` input read back as `[24, 1, 1]` through the single clamp and `[3, 1, 1]` through the window. This drops 21 of the 24 mesh groups. The integration [`d16ae7d`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/d16ae7da979642339ae5f665c7d223a0d8e24b3f) retains both exact heads and applies #2996's group-count rule to the window too. The same GPU readback then agreed on both paths for `(3, 2, 4)` → `[24, 1, 1]` and `(2, 3, 5)` → `[30, 1, 1]`. The existing draw-order and budget tests passed. App-local Agility 1.620.2/WARP 1.0.22: 13 indirect tests passed. Full GPU diagnostics with `VICTORY_CLAMP_WINDOW=0` and `=1` each had 255 passes, 0 failures and 1 ignored. Strict GPU Clippy with all features passed. This checks GPU argument readback with synthetic inputs. If both changes are taken, the integration is ready for the mesh-clamp side. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the resolution into another commit. AI-assisted with Codex.
slauko commented 2026-11-26 14:01:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by slauko on 2026-11-26T13:49:56Z.


I took the parallel shape you'd want next, and it is worse than the serial pass here — the numbers, so nobody spends the day on it:

m49/m50, the cell, ~5,000 draws step window (m47) your pass, serial your pass, a group per tile of 64
indirect clamps per frame 1,757–1,796 295–355 331
on the GPU, ms ~85 144–232 204–237
frame, median 208.1 ms 274.6 ms 342.4 ms

The parallel version: one group per tile of 64 records, each tile's bounds worked out by its own lanes exactly as the single clamp does them, and the budget charged through the interlocked walk on the budget word (load, walk the tile, compare-exchange, retry).

The walk is the price. 64 groups retry one word and each retry walks its tile again; the exact order a single clamp had — one call at a time, each seeing the budget the one before left — is not recoverable by contending groups. So on this stack the ~1,790 tiny passes are cheaper than charging the budget in order, in both shapes, and the switch stays off.

What that leaves, if the count is what you want to fix: the order only matters for the budget. A window whose records are charged in table order on one group but with the tile's bounds precomputed (a first pass, one group per tile, writing each record's cost into the table) would take the serial walk down to 64 additions per tile — that is the shape I'd try next, but I'm not building a third variant before something else pays here.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7193898381 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7193898381). Originally posted by [slauko](https://github.com/slauko) on 2026-11-26T13:49:56Z. --- I took the parallel shape you'd want next, and it is worse than the serial pass here — the numbers, so nobody spends the day on it: | `m49`/`m50`, the cell, ~5,000 draws | step window (`m47`) | your pass, serial | your pass, a group per tile of 64 | |---|---:|---:|---:| | indirect clamps per frame | 1,757–1,796 | 295–355 | 331 | | `on the GPU`, ms | ~85 | 144–232 | **204–237** | | frame, median | **208.1 ms** | 274.6 ms | **342.4 ms** | The parallel version: one group per tile of 64 records, each tile's bounds worked out by its own lanes exactly as the single clamp does them, and the budget charged through the interlocked walk on the budget word (load, walk the tile, compare-exchange, retry). The walk is the price. 64 groups retry one word and each retry walks its tile again; the exact order a single clamp had — one call at a time, each seeing the budget the one before left — is not recoverable by contending groups. So on this stack the ~1,790 tiny passes are *cheaper* than charging the budget in order, in both shapes, and the switch stays off. What that leaves, if the count is what you want to fix: the order only matters for the budget. A window whose records are charged **in table order on one group but with the tile's bounds precomputed** (a first pass, one group per tile, writing each record's cost into the table) would take the serial walk down to 64 additions per tile — that is the shape I'd try next, but I'm not building a third variant before something else pays here.
Slay326 commented 2026-11-26 16:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Slay326 on 2026-11-26T15:14:47Z.


Thanks for testing and for the detailed reports, I'm on it.

  • andrewpozdnakov7-jpg: confirmed. This PR on its own clamps mesh grids the same way in both paths (single clamp and window give the same result as main), but the mesh rule is duplicated in indirect.rs (single clamp and window), so a rule change like #2996 merges cleanly and then silently diverges. I have a fix that moves the rule into one shared mesh_groups() function used by both shaders, plus a test that compares both paths word for word. I'm verifying it on hardware now and will push it here once it passes.
  • slauko: looking into it as well. As far as I can tell your comparison was against your own step window rather than main; with thousands of records per window the single-group window pass is slower than many small passes. I'll follow up with numbers.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195992363 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7195992363). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-26T15:14:47Z. --- Thanks for testing and for the detailed reports, I'm on it. - andrewpozdnakov7-jpg: confirmed. This PR on its own clamps mesh grids the same way in both paths (single clamp and window give the same result as main), but the mesh rule is duplicated in `indirect.rs` (single clamp and window), so a rule change like #2996 merges cleanly and then silently diverges. I have a fix that moves the rule into one shared `mesh_groups()` function used by both shaders, plus a test that compares both paths word for word. I'm verifying it on hardware now and will push it here once it passes. - slauko: looking into it as well. As far as I can tell your comparison was against your own step window rather than main; with thousands of records per window the single-group window pass is slower than many small passes. I'll follow up with numbers. AI-assisted.
Slay326 commented 2026-11-26 16:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Slay326 on 2026-11-26T15:20:51Z.


Pushed the fix (bdc4167, plus the test dff6c00): the single clamp and the window now share one mesh_groups() function, so a rule change like #2996 can no longer diverge silently between the two paths. No behaviour change on its own.

Checked on an RTX 3070 (indirect tests):

  • this PR with the fix: 12/12 pass
  • with #2996 merged on top and its rule moved into the shared function: 14/14 pass
  • #2996 merged without the fix: windowed_mesh_grids_are_the_single_clamps fails with single [24, 1, 1], windowed [3, 1, 1], as reported

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196136988 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7196136988). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-26T15:20:51Z. --- Pushed the fix (bdc4167, plus the test dff6c00): the single clamp and the window now share one `mesh_groups()` function, so a rule change like #2996 can no longer diverge silently between the two paths. No behaviour change on its own. Checked on an RTX 3070 (indirect tests): - this PR with the fix: 12/12 pass - with #2996 merged on top and its rule moved into the shared function: 14/14 pass - #2996 merged without the fix: `windowed_mesh_grids_are_the_single_clamps` fails with `single [24, 1, 1], windowed [3, 1, 1]`, as reported AI-assisted.
KainanP commented 2026-11-26 16:22:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T16:22:57Z.


CPU cost per call of 0c997d4, measured with the list bench from #2586 next to #2472. The same table is on #2472.

Method. KainanP/VIctory@perf/list-call-bench now has VICTORY_LIST_BENCH_INDIRECT=1 (commit 427db003). It runs ExecuteIndirect through the title's method table: one indexed draw or one dispatch per call, 2,000 calls per list, on 1 thread and on 5 threads at once, each thread with its own list. The pipeline reads six table textures, two root CBVs and four root constants, and stores nothing, so every draw in the list is eligible here. The list's Close is timed with the calls. For these runs only, I also timed HostList::prelude() at each close through a local test accessor (not on the branch), so #2472's batched clamp, which it records at submission, counts against #2472. This PR's window pass is recorded in the list, so it is timed with the calls. Each value is the best of 5 × 5,000 calls. Builds were interleaved, with the median of 7 runs on the stack and of 21 runs on main (three sets of 7). RTX 4060 Laptop, i7-14650HX, Windows 11, release. Four unrelated Python jobs were using the CPU throughout, which is why the builds were interleaved.

ns per call main 63bcca4 + #2472 + #3197, window off + #3197, VICTORY_CLAMP_WINDOW=1
ExecuteIndirect, indexed draw, 1 thread 4,870 3,212 4,881 3,186
same, 5 threads (per thread) 8,759 7,769 8,517 8,922
ExecuteIndirect, dispatch, 1 thread 3,042 3,072 2,984 3,018

The same on main + #1978 + #2821 + #3258 + #3274 + #3275 (the draw path with the texture-lock contention mostly gone, perf/list-scale-base), median of 7:

ns per call stack + #2472 + #3197, window off + #3197, window on
indexed draw, 1 thread 3,260 1,449 3,135 1,449
same, 5 threads (per thread) 4,345 2,742 4,141 2,687
dispatch, 1 thread 2,740 2,644 2,706 2,773
  • With the window on, this PR removes the same CPU cost as #2472: about 1.7–1.8 µs per indirect draw on one thread. On the stack, both reach 1,449 ns. With the window off, the PR measures the same as main, as described.
  • On main, 5 threads don't improve with either PR (8.9 µs with the window, 7.8 µs with #2472, ranges overlapping). The per-draw texture locks dominate there. On the stack, both PRs take 5 threads from 4.3 to 2.7 µs.
  • Both PRs leave indirect dispatches alone (~3.0 µs vs 0.86 µs for a plain Dispatch on main), by design.
  • This bench is the best case for both PRs: the list never writes and nothing but indirect draws is recorded, so windows hold 64 draws here and #2472 hoists the whole list. In game the coverage differs. Here a window ends at any other draw, and #2472 stops at a list's first writing command. On the CPU, the choice between the two therefore comes down to coverage in a real frame, which this bench can't show. On the GPU, the vkd3d numbers from slauko above point the other way for windows. I haven't measured GPU time.

Tests, 0c997d4 on 63bcca4, cargo test -p victory-gpu --release --lib, each run once with VICTORY_CLAMP_WINDOW unset and once with it set to 1, with the same results:

  • RTX 4060: 235 passed, 2 failed.
  • Intel UHD, selected with a local adapter hook: 234 passed, 3 failed.
  • WARP (--features diagnostics, --test-threads=1): 252 passed, 0 failed.

The failures are the same as on main on each adapter (the NVIDIA heap pair; on Intel that pair plus a_texture_written_in_one_format_reads_in_another_through_a_placed_view). All 12 indirect:: tests pass on all three adapters, including the six new ones (windowed_mesh_grids_are_the_single_clamps among them). On RTX, memory_tests::heap_direct_texture_reads_mark_their_heap_index was skipped because it access-violates on main here.

AI use: Claude Code (Claude Opus 5.5) extended the benchmark, ran the measurements and drafted this comment.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7197569697 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7197569697). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T16:22:57Z. --- CPU cost per call of `0c997d4`, measured with the list bench from #2586 next to #2472. The same table is on #2472. **Method.** [KainanP/VIctory@perf/list-call-bench](https://github.com/KainanP/VIctory/tree/perf/list-call-bench) now has `VICTORY_LIST_BENCH_INDIRECT=1` (commit 427db003). It runs `ExecuteIndirect` through the title's method table: one indexed draw or one dispatch per call, 2,000 calls per list, on 1 thread and on 5 threads at once, each thread with its own list. The pipeline reads six table textures, two root CBVs and four root constants, and stores nothing, so every draw in the list is eligible here. The list's `Close` is timed with the calls. For these runs only, I also timed `HostList::prelude()` at each close through a local test accessor (not on the branch), so #2472's batched clamp, which it records at submission, counts against #2472. This PR's window pass is recorded in the list, so it is timed with the calls. Each value is the best of 5 × 5,000 calls. Builds were interleaved, with the median of 7 runs on the stack and of 21 runs on main (three sets of 7). RTX 4060 Laptop, i7-14650HX, Windows 11, release. Four unrelated Python jobs were using the CPU throughout, which is why the builds were interleaved. | ns per call | main 63bcca4 | + #2472 | + #3197, window off | + #3197, `VICTORY_CLAMP_WINDOW=1` | |---|---:|---:|---:|---:| | ExecuteIndirect, indexed draw, 1 thread | 4,870 | **3,212** | 4,881 | **3,186** | | same, 5 threads (per thread) | 8,759 | 7,769 | 8,517 | 8,922 | | ExecuteIndirect, dispatch, 1 thread | 3,042 | 3,072 | 2,984 | 3,018 | The same on main + #1978 + #2821 + #3258 + #3274 + #3275 (the draw path with the texture-lock contention mostly gone, `perf/list-scale-base`), median of 7: | ns per call | stack | + #2472 | + #3197, window off | + #3197, window on | |---|---:|---:|---:|---:| | indexed draw, 1 thread | 3,260 | **1,449** | 3,135 | **1,449** | | same, 5 threads (per thread) | 4,345 | **2,742** | 4,141 | **2,687** | | dispatch, 1 thread | 2,740 | 2,644 | 2,706 | 2,773 | - With the window on, this PR removes the same CPU cost as #2472: about 1.7–1.8 µs per indirect draw on one thread. On the stack, both reach 1,449 ns. With the window off, the PR measures the same as `main`, as described. - On main, 5 threads don't improve with either PR (8.9 µs with the window, 7.8 µs with #2472, ranges overlapping). The per-draw texture locks dominate there. On the stack, both PRs take 5 threads from 4.3 to 2.7 µs. - Both PRs leave indirect **dispatches** alone (~3.0 µs vs 0.86 µs for a plain `Dispatch` on main), by design. - This bench is the best case for both PRs: the list never writes and nothing but indirect draws is recorded, so windows hold 64 draws here and #2472 hoists the whole list. In game the coverage differs. Here a window ends at any other draw, and #2472 stops at a list's first writing command. On the CPU, the choice between the two therefore comes down to coverage in a real frame, which this bench can't show. On the GPU, the vkd3d numbers from slauko above point the other way for windows. I haven't measured GPU time. **Tests**, `0c997d4` on 63bcca4, `cargo test -p victory-gpu --release --lib`, each run once with `VICTORY_CLAMP_WINDOW` unset and once with it set to 1, with the same results: - RTX 4060: 235 passed, 2 failed. - Intel UHD, selected with a local adapter hook: 234 passed, 3 failed. - WARP (`--features diagnostics`, `--test-threads=1`): 252 passed, 0 failed. The failures are the same as on main on each adapter (the NVIDIA heap pair; on Intel that pair plus `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`). All 12 `indirect::` tests pass on all three adapters, including the six new ones (`windowed_mesh_grids_are_the_single_clamps` among them). On RTX, `memory_tests::heap_direct_texture_reads_mark_their_heap_index` was skipped because it access-violates on main here. _AI use: Claude Code (Claude Opus 5.5) extended the benchmark, ran the measurements and drafted this comment._
andrewpozdnakov7-jpg commented 2026-11-26 17:43:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T17:43:24Z.


The latest 0c997d4 shared mesh rule composes with #2996 once its flattening is applied in that helper. I also resolved the buffer-state conflict against #3307. On verified app-local WARP, the mixed window/single test preserved all records through a buffer grow and returned its buffers to COMMON. The translated mesh test visited the 24 expected indices with the window switch off and on, and all 15 indirect tests passed. Exact integration, full-suite results and the one transient descriptor-test failure. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7199525414 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7199525414). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T17:43:24Z. --- The latest `0c997d4` shared mesh rule composes with #2996 once its flattening is applied in that helper. I also resolved the buffer-state conflict against #3307. On verified app-local WARP, the mixed window/single test preserved all records through a buffer grow and returned its buffers to COMMON. The translated mesh test visited the 24 expected indices with the window switch off and on, and all 15 indirect tests passed. [Exact integration, full-suite results and the one transient descriptor-test failure](https://github.com/Marvisak/VIctory/pull/3307#issuecomment-7199517376). AI-assisted with Codex.
Machad3x commented 2026-11-26 18:58:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-26T18:58:20Z.


In-game numbers for this PR on an RTX 3080 Ti (Ryzen 7 5700X, PCIe 3.0, driver 621.40), plus one change on top that roughly doubles its gain.

Measured

Same scene in each run (the opening interior, about 5000 draws a frame, about 4200 of them indirect). The figures are medians of the steady reports, after loading. The clamp window comes from this PR's approach.

Run Clamp Frame ms GPU ms (frame report) GPU busy ms
A single clamps (main behaviour) 378 184 175
B VICTORY_CLAMP_WINDOW=1 335 153 150
C B, plus storing draws closing windows (below) 304 144 138

In timing runs (VICTORY_GPU_TIMING), B cut the commands' GPU time from about 177 to 135 ms a frame. host-clamp went from 27.9 to 14.9 ms and host-setup from 10.2 to 5.5 ms. No draw was dropped, no device was removed, and the pictures match.

Storing draws can close a window instead of ending it

In B, 63 windows a frame held 2268 draws, and 1916 indirect draws were still clamped alone because their pipeline may_store. A storing draw can join the open window (or open one) as its last member, as long as the window ends right after that draw is recorded:

  • the window's pass reads every record before any member runs, so the storing draw's writes can't reach a record the pass already clamped;
  • no member follows it, so no later record can read something it wrote.

In practice: when the draw's pipeline may store, call windowed() instead of returning early, skip the end_window in bind_dispatch for that draw only (we use a thread-local flag set around its prepare/bind), and call end_window once the draw is recorded. If it doesn't fit (record count, size, another source buffer), it falls back to the single clamp. With this change, run C had 1974 windows a frame holding 4209 draws and none clamped alone. It is about 70 lines in draw.rs plus a test, and I can open it as a follow-up PR on top of this one if that helps.

may_store still over-counts. A table UAV that is only read counts as a store (stores() checks used, not written), so tracking written table UAVs the way written_root_uavs already does would make more draws plain members. Not done yet.

Checking the windows

To make sure the windows are correct, I adapted fxceless's window check (fxceless's fork, commit f85101b6) as VICTORY_CLAMP_WINDOW_CHECK=1 (diagnostics only). It clamps each windowed draw's records again at draw time into a buffer with its own budget, then compares them on the GPU with what the window pass wrote. It compares only each record's own dwords at each stride, and counts records the list budget cut separately. Over a 5-minute run with storing draws closing windows, it checked 1.24 million records: 0 differed and 0 were cut.

These measurements and changes were made with AI assistance (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7201055276 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7201055276). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-26T18:58:20Z. --- In-game numbers for this PR on an RTX 3080 Ti (Ryzen 7 5700X, PCIe 3.0, driver 621.40), plus one change on top that roughly doubles its gain. ## Measured Same scene in each run (the opening interior, about 5000 draws a frame, about 4200 of them indirect). The figures are medians of the steady reports, after loading. The clamp window comes from this PR's approach. | Run | Clamp | Frame ms | GPU ms (frame report) | GPU busy ms | |---|---|---|---|---| | A | single clamps (`main` behaviour) | 378 | 184 | 175 | | B | `VICTORY_CLAMP_WINDOW=1` | 335 | 153 | 150 | | C | B, plus storing draws closing windows (below) | 304 | 144 | 138 | In timing runs (`VICTORY_GPU_TIMING`), B cut the commands' GPU time from about 177 to 135 ms a frame. `host-clamp` went from 27.9 to 14.9 ms and `host-setup` from 10.2 to 5.5 ms. No draw was dropped, no device was removed, and the pictures match. ## Storing draws can close a window instead of ending it In B, 63 windows a frame held 2268 draws, and 1916 indirect draws were still clamped alone because their pipeline `may_store`. A storing draw can join the open window (or open one) as its **last** member, as long as the window ends right after that draw is recorded: - the window's pass reads every record before any member runs, so the storing draw's writes can't reach a record the pass already clamped; - no member follows it, so no later record can read something it wrote. In practice: when the draw's pipeline may store, call `windowed()` instead of returning early, skip the `end_window` in `bind_dispatch` for that draw only (we use a thread-local flag set around its prepare/bind), and call `end_window` once the draw is recorded. If it doesn't fit (record count, size, another source buffer), it falls back to the single clamp. With this change, run C had 1974 windows a frame holding 4209 draws and none clamped alone. It is about 70 lines in `draw.rs` plus a test, and I can open it as a follow-up PR on top of this one if that helps. `may_store` still over-counts. A table UAV that is only read counts as a store (`stores()` checks `used`, not written), so tracking written table UAVs the way `written_root_uavs` already does would make more draws plain members. Not done yet. ## Checking the windows To make sure the windows are correct, I adapted fxceless's window check (fxceless's fork, commit `f85101b6`) as `VICTORY_CLAMP_WINDOW_CHECK=1` (diagnostics only). It clamps each windowed draw's records again at draw time into a buffer with its own budget, then compares them on the GPU with what the window pass wrote. It compares only each record's own dwords at each stride, and counts records the list budget cut separately. Over a 5-minute run with storing draws closing windows, it checked 1.24 million records: 0 differed and 0 were cut. These measurements and changes were made with AI assistance (Claude Code).
neonbyte1 commented 2026-11-27 04:13:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T04:13:32Z.


Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, merged onto #2472 (same stack as my note there).

Under Wine window_clamp() is None. WINDOW_SOURCE has the two problems #2472's batch shader had: Wine's D3DCompile fails with clamp window:71:32: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'. (budget.Load(0)) and ignores [RootSignature(RS)], so every draw clamps on its own. The tests' WRITE shader has the attribute too. Fix: 916655cc (after merging your head 0c997d40 onto #2472 as 055b5c89): RWStructuredBuffer<uint> (budget[0]), no attribute, the root signature built in Rust in open's binding order (t0..t3, t4, u1, u0), WRITE ported the same way, and every_clamp_compiles_without_a_root_signature_attribute covers the window shader.

may_store keeps almost every G-buffer draw out of windows, because their pixel shaders only read-mark (marks/view_marks). A write mark always comes with a table, heap or root UAV store, or a title-memory store, which may_store already tests; without them the marks only touch our own bitmap (u1, space 2), which no execution reads arguments from. aef55c74 merges may_store and #2472's pipeline_writes_uav into one predicate over those write flags, with CPU tests. Order: hoisted if in the non-writing prefix, else joins a window, else a single clamp.

Measured with VICTORY_CLAMP_WINDOW=1, adjacent 600 s runs: 398 → 311 ms per frame, GPU 266 → 170 ms; #2472's compile fix alone gave nothing here. Pictures match the control. Your six window tests (windows_clamp_as_single_clamps_do, windowed_mesh_grids_are_the_single_clamps, a_window_after_a_spent_budget_runs_empty, a_store_ends_the_window, a_window_clamps_max_records_whatever_the_count, windows_leave_the_argument_buffer_common) pass on the GPU under vkd3d-proton with these commits. Given these numbers, I'd suggest windows on by default, at least where the batch shaders compile.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7209623995 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7209623995). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T04:13:32Z. --- Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, merged onto #2472 (same stack as my note there). **Under Wine `window_clamp()` is `None`.** `WINDOW_SOURCE` has the two problems #2472's batch shader had: Wine's `D3DCompile` fails with `clamp window:71:32: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'.` (`budget.Load(0)`) and ignores `[RootSignature(RS)]`, so every draw clamps on its own. The tests' `WRITE` shader has the attribute too. Fix: [`916655cc`](https://github.com/neonbyte1/VIctory/commit/916655cc) (after merging your head `0c997d40` onto #2472 as [`055b5c89`](https://github.com/neonbyte1/VIctory/commit/055b5c89)): `RWStructuredBuffer<uint>` (`budget[0]`), no attribute, the root signature built in Rust in `open`'s binding order (t0..t3, t4, u1, u0), `WRITE` ported the same way, and `every_clamp_compiles_without_a_root_signature_attribute` covers the window shader. **`may_store` keeps almost every G-buffer draw out of windows**, because their pixel shaders only read-mark (`marks`/`view_marks`). A write mark always comes with a table, heap or root UAV store, or a title-memory store, which `may_store` already tests; without them the marks only touch our own bitmap (u1, space 2), which no execution reads arguments from. [`aef55c74`](https://github.com/neonbyte1/VIctory/commit/aef55c74) merges `may_store` and #2472's `pipeline_writes_uav` into one predicate over those write flags, with CPU tests. Order: hoisted if in the non-writing prefix, else joins a window, else a single clamp. **Measured** with `VICTORY_CLAMP_WINDOW=1`, adjacent 600 s runs: **398 → 311 ms per frame, GPU 266 → 170 ms**; #2472's compile fix alone gave nothing here. Pictures match the control. Your six window tests (`windows_clamp_as_single_clamps_do`, `windowed_mesh_grids_are_the_single_clamps`, `a_window_after_a_spent_budget_runs_empty`, `a_store_ends_the_window`, `a_window_clamps_max_records_whatever_the_count`, `windows_leave_the_argument_buffer_common`) pass on the GPU under vkd3d-proton with these commits. Given these numbers, I'd suggest windows on by default, at least where the batch shaders compile. _AI-assisted (Claude); measured on my machine, no game data shared._
neonbyte1 commented 2026-11-27 04:23:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T04:23:34Z.


Timed follow-up (same setup, VICTORY_GPU_TIMING=1, every command in the table, last 30 reports), before and after the commits above:

GPU command time / frame indirect draws clamps
before (inline clamps only) 155.4 ms 98.1 ms (4,909) 35.4 ms (4,909)
hoist + windows + read-mark rule 64.8 ms 32.2 ms (4,884) 9.7 ms (1,133)

So the draws themselves got about three times cheaper, not only the clamps: with a barrier, a one-group dispatch and a rebind between every two indirect draws, the draw stream itself paid far more than the clamps' own 7 µs each. The 1,133 clamps left are the 920 indirect dispatches (never batched) plus window openers.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7209760901 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7209760901). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T04:23:34Z. --- Timed follow-up (same setup, `VICTORY_GPU_TIMING=1`, every command in the table, last 30 reports), before and after the commits above: | | GPU command time / frame | indirect draws | clamps | |---|---|---|---| | before (inline clamps only) | 155.4 ms | 98.1 ms (4,909) | 35.4 ms (4,909) | | hoist + windows + read-mark rule | **64.8 ms** | **32.2 ms** (4,884) | **9.7 ms** (1,133) | So the draws themselves got about three times cheaper, not only the clamps: with a barrier, a one-group dispatch and a rebind between every two indirect draws, the draw stream itself paid far more than the clamps' own 7 µs each. The 1,133 clamps left are the 920 indirect dispatches (never batched) plus window openers. _AI-assisted (Claude); measured on my machine, no game data shared._
Slay326 commented 2026-11-27 06:43:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Slay326 on 2026-11-27T06:43:45Z.


Thanks for testing under Wine and for the fix.

  • Wine compile: confirmed from the code. WINDOW_SOURCE reads the budget through RWByteAddressBuffer::Load and takes its root signature from the [RootSignature] attribute, so with Wine's D3DCompile window_clamp() is None and every draw falls back to the single clamp. The single clamp on main has the same two constructs (budget.Load(0), attribute); on your stack #2472 already ported it, so on this PR alone, without #2472, I'd expect the single clamp to hit the same failure under Wine. Can you confirm whether that matches what you saw before merging #2472?
  • Fix: I'd take the same change here: the budget as RWStructuredBuffer<uint> (budget[0]), no attribute, the root signature built in Rust in open's binding order (t0..t3, t4, u1, u0), WRITE ported the same way, and the window shader added to every_clamp_compiles_without_a_root_signature_attribute. Since make_with only exists on #2472, on this branch it needs a small root-signature builder of its own (sketch below). If #2472 lands first, your 916655cc applies almost as-is. I'd also port the single clamp in the same commit so the PR doesn't depend on #2472 for Wine. I'll keep your authorship on the cherry-pick or add you as co-author.
  • Read marks / may_store (aef55c74): the reasoning reads right to me (a read mark only writes our own bitmap, never an argument or count buffer), but it changes which draws are reordered for both PRs, so I'd keep it as a separate follow-up rather than fold it into this one. Machad3x's "storing draw closes the window" change above goes in the same direction; the two should be checked together.
  • Default on: I'd leave VICTORY_CLAMP_WINDOW off in this PR. Your numbers (398 → 311 ms, GPU command time 155 → 65 ms) and Machad3x's (378 → 335 ms) point one way, slauko's vkd3d numbers on a 3080 Ti the other (against his step window, not main). That decision is better made once the compile fix is in and more stacks have measured it.

What I can check on our side: the ported shaders and root signatures on native D3D12 (RTX 3070 and 4070), all indirect:: tests with the window off and on, and an in-game A/B on Windows. I have not tested under Wine/vkd3d-proton, so for that path I'm relying on your runs.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211791558 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7211791558). Originally posted by [Slay326](https://github.com/Slay326) on 2026-11-27T06:43:45Z. --- Thanks for testing under Wine and for the fix. - **Wine compile:** confirmed from the code. `WINDOW_SOURCE` reads the budget through `RWByteAddressBuffer::Load` and takes its root signature from the `[RootSignature]` attribute, so with Wine's `D3DCompile` `window_clamp()` is `None` and every draw falls back to the single clamp. The single clamp on `main` has the same two constructs (`budget.Load(0)`, attribute); on your stack #2472 already ported it, so on this PR alone, without #2472, I'd expect the single clamp to hit the same failure under Wine. Can you confirm whether that matches what you saw before merging #2472? - **Fix:** I'd take the same change here: the budget as `RWStructuredBuffer<uint>` (`budget[0]`), no attribute, the root signature built in Rust in `open`'s binding order (t0..t3, t4, u1, u0), `WRITE` ported the same way, and the window shader added to `every_clamp_compiles_without_a_root_signature_attribute`. Since `make_with` only exists on #2472, on this branch it needs a small root-signature builder of its own (sketch below). If #2472 lands first, your 916655cc applies almost as-is. I'd also port the single clamp in the same commit so the PR doesn't depend on #2472 for Wine. I'll keep your authorship on the cherry-pick or add you as co-author. - **Read marks / `may_store` (aef55c74):** the reasoning reads right to me (a read mark only writes our own bitmap, never an argument or count buffer), but it changes which draws are reordered for both PRs, so I'd keep it as a separate follow-up rather than fold it into this one. Machad3x's "storing draw closes the window" change above goes in the same direction; the two should be checked together. - **Default on:** I'd leave `VICTORY_CLAMP_WINDOW` off in this PR. Your numbers (398 → 311 ms, GPU command time 155 → 65 ms) and Machad3x's (378 → 335 ms) point one way, slauko's vkd3d numbers on a 3080 Ti the other (against his step window, not `main`). That decision is better made once the compile fix is in and more stacks have measured it. What I can check on our side: the ported shaders and root signatures on native D3D12 (RTX 3070 and 4070), all `indirect::` tests with the window off and on, and an in-game A/B on Windows. **I have not tested under Wine/vkd3d-proton**, so for that path I'm relying on your runs. AI-assisted.
zed6000 commented 2026-11-27 12:08:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-27T12:08:56Z.


An AMD data point for choosing between this PR and #2472, as asked above.

Setup: RX 7900 XTX (driver 32.0.32029.2010), Ryzen 9 7900X3D, Windows 11. Diagnostics builds of each PR merged onto main 63bcca4, Series X profile, the intro cutscene. Runs in the order main, #2472, #3197, #3197, #2472, main, with VICTORY_CLAMP_WINDOW=1 set for all of them (only this PR reads it). Each figure is the median of 36 frame-report lines.

build GPU ms/frame (run 1, run 2) cargo test -p victory-gpu --lib
main 153.1, 152.0 231 passed
#2472 151.5, 151.5 237 passed
this PR 132.5, 132.4 237 passed
  • This PR takes about 20 ms (13 %) off the GPU time per frame. Its counter shows about 2,940 clamp passes a frame: about 2,870 single ones plus about 70 windows of about 31 draws.
  • #2472 is flat here. Its rule (from a list's start to its first writing command) rarely applies in this title: in a similar attempt of ours only about 12 of 5,130 indirect executions a frame qualified.
  • 0 errors and no device removal in any run; draws per frame and dropped draws are about the same in all builds. Whole-frame time is too noisy to rank the builds (CPU preparation dominates it here), so I claim only the GPU figure.
  • Not run: this PR with the switch off.

Given 0 errors here, it may be worth having it on by default.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217895808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7217895808). Originally posted by [zed6000](https://github.com/zed6000) on 2026-11-27T12:08:56Z. --- An AMD data point for choosing between this PR and #2472, as asked above. **Setup:** RX 7900 XTX (driver 32.0.32029.2010), Ryzen 9 7900X3D, Windows 11. Diagnostics builds of each PR merged onto `main` `63bcca4`, Series X profile, the intro cutscene. Runs in the order main, #2472, #3197, #3197, #2472, main, with `VICTORY_CLAMP_WINDOW=1` set for all of them (only this PR reads it). Each figure is the median of 36 frame-report lines. | build | GPU ms/frame (run 1, run 2) | `cargo test -p victory-gpu --lib` | |---|---|---| | `main` | 153.1, 152.0 | 231 passed | | #2472 | 151.5, 151.5 | 237 passed | | this PR | **132.5, 132.4** | 237 passed | - **This PR takes about 20 ms (13 %) off the GPU time per frame.** Its counter shows about 2,940 clamp passes a frame: about 2,870 single ones plus about 70 windows of about 31 draws. - **#2472 is flat here.** Its rule (from a list's start to its first writing command) rarely applies in this title: in a similar attempt of ours only about 12 of 5,130 indirect executions a frame qualified. - 0 errors and no device removal in any run; draws per frame and dropped draws are about the same in all builds. Whole-frame time is too noisy to rank the builds (CPU preparation dominates it here), so I claim only the GPU figure. - Not run: this PR with the switch off. Given 0 errors here, it may be worth having it on by default.
Desamodeth commented 2026-11-27 13:07:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Desamodeth on 2026-11-27T13:07:52Z.


Native Windows RTX 5070 12 GB, driver 621.40, Series X opening car sequence. Tested 0c997d40 on 63bcca43 with #2885 and #2958. Same binary, save and application-cache seed throughout. After one warm-up per mode, four measured runs used on/off/off/on order.

Full-frame metric, switch off → on On ran first Off ran first
Median 480 → 493 ms 486 → 500 ms
p95 865 → 882 ms 889 → 1,013 ms
FPS over measured intervals 2.010 → 2.006 1.989 → 1.915

Each run contributed 96 common Present intervals; captures and their following intervals were excluded. In the shared 25–61 s window after the world marker the medians were 579 → 579 ms and 586 → 591 ms. The window path was active: its counters imply about 801 and 813 clamp dispatches avoided per frame in the two enabled runs (grouped draws minus windows, median of complete report windows). All six launches reached the endpoint and all Presents returned S_OK.

All 12 victory-gpu tests selected by indirect::tests:: passed on the test tree. This adds a native configuration where batching worked and a whole-frame gain did not reproduce. Camera cuts and pipeline waiting varied. These results support keeping the switch opt-in. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7219095711 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7219095711). Originally posted by [Desamodeth](https://github.com/Desamodeth) on 2026-11-27T13:07:52Z. --- Native Windows RTX 5070 12 GB, driver 621.40, Series X opening car sequence. Tested `0c997d40` on `63bcca43` with #2885 and #2958. Same binary, save and application-cache seed throughout. After one warm-up per mode, four measured runs used on/off/off/on order. | Full-frame metric, switch off → on | On ran first | Off ran first | |---|---:|---:| | Median | 480 → 493 ms | 486 → 500 ms | | p95 | 865 → 882 ms | 889 → 1,013 ms | | FPS over measured intervals | 2.010 → 2.006 | 1.989 → 1.915 | Each run contributed 96 common Present intervals; captures and their following intervals were excluded. In the shared 25–61 s window after the world marker the medians were 579 → 579 ms and 586 → 591 ms. The window path was active: its counters imply about **801 and 813 clamp dispatches avoided per frame** in the two enabled runs (grouped draws minus windows, median of complete report windows). All six launches reached the endpoint and all Presents returned S_OK. All 12 `victory-gpu` tests selected by `indirect::tests::` passed on the test tree. This adds a native configuration where batching worked and a whole-frame gain did not reproduce. Camera cuts and pipeline waiting varied. These results support keeping the switch opt-in. AI-assisted with Codex.
neonbyte1 commented 2026-11-27 14:58:30 +00:00 (Migrated from github.com)

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


@Slay326 as you suggested, the read-mark rule is now its own PR: #3531 (draft, stacked on this one and #2472 plus the Wine fix; the change to review is its last commit). Measured share on our stack: windows without the rule 246.8 ms frame / 124.2 ms GPU, with it 209.1 / 78.0, clamp passes 2,847 → 1,138 per frame. It composes with Machad3x's storing-draw idea (details in #3531).

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7221465567 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7221465567). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-27T14:58:30Z. --- @Slay326 as you suggested, the read-mark rule is now its own PR: #3531 (draft, stacked on this one and #2472 plus the Wine fix; the change to review is its last commit). Measured share on our stack: windows without the rule 246.8 ms frame / 124.2 ms GPU, with it 209.1 / 78.0, clamp passes 2,847 → 1,138 per frame. It composes with Machad3x's storing-draw idea (details in #3531). _AI-assisted (Claude); measured on my machine, no game data shared._
neonbyte1 commented 2026-11-28 05:30:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-28T05:30:16Z.


@Slay326 follow-up to this PR as #3676 (draft, stacked on this head 0c997d4, review only its last commit): indirect dispatches and executions whose shaders may store join the windows while no barrier, barrier group or pipeline sync comes between them. Measured on our stack: -8.6 ms frame over two adjacent pairs, all of it from storing draws joining; the dispatch half is unmeasured there because #2312 gives every dispatch the spread layout, as the PR says.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7234709305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7234709305). Originally posted by [neonbyte1](https://github.com/neonbyte1) on 2026-11-28T05:30:16Z. --- @Slay326 follow-up to this PR as #3676 (draft, stacked on this head `0c997d4`, review only its last commit): indirect dispatches and executions whose shaders may store join the windows while no barrier, barrier group or pipeline sync comes between them. Measured on our stack: -8.6 ms frame over two adjacent pairs, all of it from storing draws joining; the dispatch half is unmeasured there because #2312 gives every dispatch the spread layout, as the PR says. _AI-assisted (Claude); measured on my machine, no game data shared._
xianyu408 commented 2026-11-30 09:21:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by xianyu408 on 2026-11-30T09:21:55Z.


A-B measurement on AMD (RX 6700 XT 12 GB, RDNA2), built from this branch, Series S profile, 1080p output,
same shader cache and data directory for both runs; the only difference is the variable.

run frame time (median of samples) GPU part
VICTORY_CLAMP_WINDOW=0 2133 ms (min 1260, max 3846) 294-319 ms
VICTORY_CLAMP_WINDOW=1 1822 ms (min 1213, max 2452) 252-300 ms

So the window takes about 15% off the frame here, and 40-50 ms off the GPU part.

Context for those absolute numbers: upstream main is far slower on this machine than the AMD-tuned
fork the reporter usually runs - it copies 220-250 MB a frame and takes ~1.9 s, against 196 ms there -
so the frame is CPU-bound here and only the relative delta is meaningful. On the tuned fork the same
3,400 clamp passes a frame sat inside a 196 ms frame with 67-77 ms of GPU time, which is where a 29 ms
saving would matter much more.

Two AMD notes that may matter for the window:

  • The card loses the device after about 80 s if the windows share one scratch buffer; each window needs
    its own (we hit this with four windows on the tuned fork's own window path).
  • An upload buffer that grows mid-frame must carry over what was already written into it: the prelude
    copies the current buffer only, and the tail records never reached the card (frame time tripled).

Reporter: xianyu408 on issue #3876 (3,400 clamps a frame, 67-77 ms of GPU time on the same card).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7274105717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3197#issuecomment-7274105717). Originally posted by [xianyu408](https://github.com/xianyu408) on 2026-11-30T09:21:55Z. --- A-B measurement on AMD (RX 6700 XT 12 GB, RDNA2), built from this branch, Series S profile, 1080p output, same shader cache and data directory for both runs; the only difference is the variable. | run | frame time (median of samples) | GPU part | |---|---|---| | VICTORY_CLAMP_WINDOW=0 | 2133 ms (min 1260, max 3846) | 294-319 ms | | VICTORY_CLAMP_WINDOW=1 | 1822 ms (min 1213, max 2452) | 252-300 ms | So the window takes about 15% off the frame here, and 40-50 ms off the GPU part. Context for those absolute numbers: upstream `main` is far slower on this machine than the AMD-tuned fork the reporter usually runs - it copies 220-250 MB a frame and takes ~1.9 s, against 196 ms there - so the frame is CPU-bound here and only the relative delta is meaningful. On the tuned fork the same 3,400 clamp passes a frame sat inside a 196 ms frame with 67-77 ms of GPU time, which is where a 29 ms saving would matter much more. Two AMD notes that may matter for the window: - The card loses the device after about 80 s if the windows share one scratch buffer; each window needs its own (we hit this with four windows on the tuned fork's own window path). - An upload buffer that grows mid-frame must carry over what was already written into it: the prelude copies the current buffer only, and the tail records never reached the card (frame time tripled). Reporter: xianyu408 on issue #3876 (3,400 clamps a frame, 67-77 ms of GPU time on the same card).
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/3197:upstream-pr/3197'
git switch 'upstream-pr/3197'

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/3197'
git switch 'upstream-pr/3197'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3197'
git switch 'upstream-pr/3197'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3197'
git switch 'main'
git merge --squash 'upstream-pr/3197'
git switch 'main'
git merge --ff-only 'upstream-pr/3197'
git switch 'main'
git merge 'upstream-pr/3197'
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!3195
No description provided.