GPU: reuse descriptor table scratch buffers and stack roots in bind #1443

Closed
DoktorTK wants to merge 1 commit from upstream-pr/1443 into main
DoktorTK commented 2026-11-27 07:39:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DoktorTK on 2026-11-27T07:39:32Z.


Summary

State::bind (crates/victory-gpu/src/draw.rs) runs on every draw and dispatch call and previously allocated multiple fresh Vecs per stage/draw:

  • State::tables allocated new made, entries, and selected Vecs on every stage invocation.
  • State::memory_ready allocated new addresses and constants Vecs whenever a shader bound SLOT_MEMORY.

This change:

  1. Introduces State::tables_into so State::bind reuses made, entries, and selected scratch Vecs across shader stages (while keeping State::tables intact for callers/tests).
  2. Uses stack-allocated [u64; 64] and [u32; 64] buffers (bounded to D3D12's 64 root parameter / 64 DWORD limit, with an overflow Vec fallback) in State::memory_ready.

Verification

  • cargo clippy -p victory-gpu --lib -- -D warnings
  • cargo test -p victory-gpu --lib -- draw::
<!-- greyfinch-sync:fxceless/victory-fork:issue:5523007113 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1443). Originally posted by [DoktorTK](https://github.com/DoktorTK) on 2026-11-27T07:39:32Z. --- ### Summary `State::bind` (`crates/victory-gpu/src/draw.rs`) runs on every draw and dispatch call and previously allocated multiple fresh `Vec`s per stage/draw: - `State::tables` allocated new `made`, `entries`, and `selected` `Vec`s on every stage invocation. - `State::memory_ready` allocated new `addresses` and `constants` `Vec`s whenever a shader bound `SLOT_MEMORY`. This change: 1. Introduces `State::tables_into` so `State::bind` reuses `made`, `entries`, and `selected` scratch `Vec`s across shader stages (while keeping `State::tables` intact for callers/tests). 2. Uses stack-allocated `[u64; 64]` and `[u32; 64]` buffers (bounded to D3D12's 64 root parameter / 64 DWORD limit, with an overflow `Vec` fallback) in `State::memory_ready`. ### Verification - `cargo clippy -p victory-gpu --lib -- -D warnings` - `cargo test -p victory-gpu --lib -- draw::`
Filip722 commented 2026-11-27 09:08:25 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-27T09:08:25Z.


At 7a61bf0e, the State::bind stage loop still calls self.tables(...). The new wrapper constructs made, entries and selected each time before calling tables_into, so the per-stage allocations in that loop are still present. The stack storage in memory_ready is wired in.

Could the stage loop pass the same three scratch vectors directly to tables_into? That would make the production call site exercise the reuse described here. This is from reading the exact diff.

Assisted by Codex (GPT-6.2-Sol High).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7214325724 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1443#issuecomment-7214325724). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-27T09:08:25Z. --- At `7a61bf0e`, the `State::bind` stage loop still calls `self.tables(...)`. The new wrapper constructs `made`, `entries` and `selected` each time before calling `tables_into`, so the per-stage allocations in that loop are still present. The stack storage in `memory_ready` is wired in. Could the stage loop pass the same three scratch vectors directly to `tables_into`? That would make the production call site exercise the reuse described here. This is from reading the exact diff. Assisted by Codex (GPT-6.2-Sol High).
DoktorTK commented 2026-11-27 12:51:17 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DoktorTK on 2026-11-27T12:51:17Z.


At 7a61bf0e, the State::bind stage loop still calls self.tables(...). The new wrapper constructs made, entries and selected each time before calling tables_into, so the per-stage allocations in that loop are still present. The stack storage in memory_ready is wired in.

Could the stage loop pass the same three scratch vectors directly to tables_into? That would make the production call site exercise the reuse described here. This is from reading the exact diff.

Assisted by Codex (GPT-6.2-Sol High).

Good catch, thank you! When splitting this out onto main separately from stage_spans, the State::bind call site was missed and still called self.tables(...). Updated the PR branch (ff63c74) so State::bind allocates made, entries, and selected once before the stage loop and passes them directly to self.tables_into(...).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7218754701 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1443#issuecomment-7218754701). Originally posted by [DoktorTK](https://github.com/DoktorTK) on 2026-11-27T12:51:17Z. --- > At `7a61bf0e`, the `State::bind` stage loop still calls `self.tables(...)`. The new wrapper constructs `made`, `entries` and `selected` each time before calling `tables_into`, so the per-stage allocations in that loop are still present. The stack storage in `memory_ready` is wired in. > > Could the stage loop pass the same three scratch vectors directly to `tables_into`? That would make the production call site exercise the reuse described here. This is from reading the exact diff. > > Assisted by Codex (GPT-6.2-Sol High). Good catch, thank you! When splitting this out onto `main` separately from `stage_spans`, the `State::bind` call site was missed and still called `self.tables(...)`. Updated the PR branch (`ff63c74`) so `State::bind` allocates `made`, `entries`, and `selected` once before the stage loop and passes them directly to `self.tables_into(...)`.
KainanP commented 2026-11-27 15:13:49 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KainanP on 2026-11-27T15:13:49Z.


Independent A/B of this PR on the RTX 4060 Laptop, against main 9a9091d (its base). This head does change the production caller: bind now calls tables_into with its reused buffers.

Bench: pipeline::list_bench::table_bench (KainanP/victory-fork bench/desc-tables, #[ignore]) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times recording only: lists are not submitted, so fills done at submission do not show here.

build 1 thread 5 threads (per thread)
main 9a9091d 10,244 14,332
PR ff63c74 10,075 (−2 %) 14,289 (0 %)

An earlier run of 7 agrees: main 11,990 / 22,095, PR 11,524 / 22,240.

So it is neutral within noise. The allocations it saves are small next to the roughly 17 µs it takes to make a 6-slot table afresh here (diagnostics build).

Correctness. Our tables_show_their_views passes: every texture slot of the tables made for 64 draws, over three lists, holds the descriptor the host makes of its view, and its host texture.

For the texture-view part: #1484.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7221793751 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1443#issuecomment-7221793751). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-27T15:13:49Z. --- Independent A/B of this PR on the RTX 4060 Laptop, against `main` 9a9091d (its base). This head does change the production caller: `bind` now calls `tables_into` with its reused buffers. **Bench:** `pipeline::list_bench::table_bench` ([KainanP/victory-fork `bench/desc-tables`](https://github.com/KainanP/victory-fork/commit/8099f728afae8ed80ac4deff2f471ae3683aa589), `#[ignore]`) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times **recording only**: lists are not submitted, so fills done at submission do not show here. | build | 1 thread | 5 threads (per thread) | |---|---|---| | `main` 9a9091d | 10,244 | 14,332 | | PR `ff63c74` | 10,075 (−2 %) | 14,289 (0 %) | An earlier run of 7 agrees: `main` 11,990 / 22,095, PR 11,524 / 22,240. So it is neutral within noise. The allocations it saves are small next to the roughly 17 µs it takes to make a 6-slot table afresh here (diagnostics build). **Correctness.** Our `tables_show_their_views` passes: every texture slot of the tables made for 64 draws, over three lists, holds the descriptor the host makes of its view, and its host texture. For the texture-view part: #1484. _AI use: Claude Code (Claude Opus 5.5)._
DoktorTK commented 2026-11-27 15:21:20 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by DoktorTK on 2026-11-27T15:21:20Z.


Independent A/B of this PR on the RTX 4060 Laptop, against main 9a9091d (its base). This head does change the production caller: bind now calls tables_into with its reused buffers.

Bench: pipeline::list_bench::table_bench (KainanP/victory-fork bench/desc-tables, #[ignore]) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times recording only: lists are not submitted, so fills done at submission do not show here.
build 1 thread 5 threads (per thread)
main 9a9091d 10,244 14,332
PR ff63c74 10,075 (−2 %) 14,289 (0 %)

An earlier run of 7 agrees: main 11,990 / 22,095, PR 11,524 / 22,240.

So it is neutral within noise. The allocations it saves are small next to the roughly 17 µs it takes to make a 6-slot table afresh here (diagnostics build).

Correctness. Our tables_show_their_views passes: every texture slot of the tables made for 64 draws, over three lists, holds the descriptor the host makes of its view, and its host texture.

For the texture-view part: #1484.

AI use: Claude Code (Claude Opus 5.5).

Thank you for the thorough A/B benchmark and correctness check on ff63c74, and awesome to see #1484 caching the texture views directly! Closing this PR now since main has rebased onto VIctory-NVIDIA (foxhound) and #1484 tackles the dominant cost.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7221953601 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1443#issuecomment-7221953601). Originally posted by [DoktorTK](https://github.com/DoktorTK) on 2026-11-27T15:21:20Z. --- > Independent A/B of this PR on the RTX 4060 Laptop, against `main` [9a9091d](https://github.com/fxceless/victory-fork/commit/9a9091d180f044726463d3db819808086daeebae) (its base). This head does change the production caller: `bind` now calls `tables_into` with its reused buffers. > > **Bench:** `pipeline::list_bench::table_bench` ([KainanP/victory-fork `bench/desc-tables`](https://github.com/KainanP/victory-fork/commit/8099f728afae8ed80ac4deff2f471ae3683aa589), `#[ignore]`) ports the draw sequence of our VIctory list bench to the fork. Each draw binds a material table (one constant buffer view and five textures the title placed in memory), and each table sits at its own place in the title's heap. A list has 2,000 tables, and half of them repeat the contents of an earlier one, as in #1379. A list is closed (timed) and reset every 2,000 draws. Cells are ns per draw for the whole sequence (table, root CBV, 4 constants, index buffer, draw), each the median of 7 interleaved processes, each process the best of 5. RTX 4060 Laptop, i7-14650HX. A headless Chrome from other work used about 2 cores. This bench times **recording only**: lists are not submitted, so fills done at submission do not show here. > build 1 thread 5 threads (per thread) > `main` [9a9091d](https://github.com/fxceless/victory-fork/commit/9a9091d180f044726463d3db819808086daeebae) 10,244 14,332 > PR `ff63c74` 10,075 (−2 %) 14,289 (0 %) > > An earlier run of 7 agrees: `main` 11,990 / 22,095, PR 11,524 / 22,240. > > So it is neutral within noise. The allocations it saves are small next to the roughly 17 µs it takes to make a 6-slot table afresh here (diagnostics build). > > **Correctness.** Our `tables_show_their_views` passes: every texture slot of the tables made for 64 draws, over three lists, holds the descriptor the host makes of its view, and its host texture. > > For the texture-view part: #1484. > > _AI use: Claude Code (Claude Opus 5.5)._ Thank you for the thorough A/B benchmark and correctness check on `ff63c74`, and awesome to see `#1484` caching the texture views directly! Closing this PR now since `main` has rebased onto `VIctory-NVIDIA` (`foxhound`) and `#1484` tackles the dominant cost.

Pull request closed

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
fxceless/victory-fork!1443
No description provided.