GPU: spill oversized host root signatures' user data to root CBVs #644

Closed
github-bot wants to merge 1 commit from gh-pr/644/head into gh-pr/644/base
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 06:06 UTC · original
nathanbzrr:gpu/root-signature-user-data-cbv-spill → main · +1119 −14 · 2 files · 1 commits · closed without merging

Summary

Host D3D12 hard-caps root signatures at 64 DWORDs. HostPipeline::new emits a separate D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS parameter for every shader stage (VS/MS + PS, up to 32+ DWORDs each) plus per-stage 2-DWORD root CBVs/SRVs. Any pipeline whose combined per-stage user data and root descriptors exceeds 64 DWORDs fails D3D12SerializeVersionedRootSignature and drops all draws using that pipeline, even though the DXIL shaders bind b0, space 0 as a normal CBV that accepts both root 32-bit constants and root CBVs identically.

Changes (crates/victory-gpu/src/pipeline/host.rs, crates/victory-gpu/src/draw.rs)

  • Replace Stage::user_data: Option<(u32, u32)> with Option<UserDataBind> (Constants { param, dwords } or Cbv { param, dwords }).
  • Add root_param_cost, root_signature_cost, and fit_root_signature:
    • Phase 1: while total cost > 64 DWORDs, spills the largest stage UserDataBind::Constants (dwords > 2) to D3D12_ROOT_PARAMETER_TYPE_CBV (b0, space 0, D3D12_ROOT_DESCRIPTOR_FLAG_DATA_STATIC, preserving ShaderVisibility), reducing each stage's cost from dwords to 2 DWORDs.
    • Phase 2: if total cost still exceeds 64 DWORDs, merges duplicate (ParameterType, ShaderRegister, RegisterSpace) CBV/SRV/UAV root descriptors across stages into a single D3D12_SHADER_VISIBILITY_ALL parameter and remaps all stage parameter indices (never merging descriptor tables or b0 user data).
  • Call fit_root_signature before serializing the root signature in HostPipeline::new.
  • Update State::bind (returning bool checked by prepare_for, dispatch, and the DISPATCH arm of execute_indirect) to upload UserDataBind::Cbv values into 256-byte-aligned HostList::scratch memory and bind them via SetComputeRootConstantBufferView / SetGraphicsRootConstantBufferView.

Verification

Isolated verification on branch gpu/root-signature-user-data-cbv-spill (6fa53a5):

  • rustfmt --edition 2024 --config skip_children=true --check crates/victory-gpu/src/pipeline/host.rs crates/victory-gpu/src/draw.rs (passed)
  • cargo test -p victory-gpu -- --test-threads=1 (51 passed, 0 failed, 1 ignored; includes 6 fit_* unit tests, host_oversized_graphics_root_signatures_serialize_after_fit, and spilled_user_data_cbv_executes_distinct_dispatches_on_host)
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1 (53 passed, 0 failed, 1 ignored; zero D3D12 debug layer errors)
  • cargo clippy -p victory-gpu --all-targets (0 warnings in pipeline/host.rs and draw.rs; 1 pre-existing warning at host.rs:267)
  • cargo xtask policy (151 files ok)

No game files. AI-assisted; reviewed and verified with the tests above.

**@⁠nathanbzrr** on GitHub · 2026-11-24 06:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/644) `nathanbzrr:gpu/root-signature-user-data-cbv-spill` → `main` · +1119 −14 · 2 files · 1 commits · closed without merging ## Summary Host D3D12 hard-caps root signatures at 64 DWORDs. `HostPipeline::new` emits a separate `D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS` parameter for every shader stage (`VS`/`MS` + `PS`, up to 32+ DWORDs each) plus per-stage 2-DWORD root CBVs/SRVs. Any pipeline whose combined per-stage user data and root descriptors exceeds 64 DWORDs fails `D3D12SerializeVersionedRootSignature` and drops all draws using that pipeline, even though the DXIL shaders bind `b0, space 0` as a normal CBV that accepts both root 32-bit constants and root CBVs identically. ### Changes (`crates/victory-gpu/src/pipeline/host.rs`, `crates/victory-gpu/src/draw.rs`) - Replace `Stage::user_data: Option<(u32, u32)>` with `Option<UserDataBind>` (`Constants { param, dwords }` or `Cbv { param, dwords }`). - Add `root_param_cost`, `root_signature_cost`, and `fit_root_signature`: - Phase 1: while total cost > 64 DWORDs, spills the largest stage `UserDataBind::Constants` (`dwords > 2`) to `D3D12_ROOT_PARAMETER_TYPE_CBV` (`b0, space 0`, `D3D12_ROOT_DESCRIPTOR_FLAG_DATA_STATIC`, preserving `ShaderVisibility`), reducing each stage's cost from `dwords` to 2 DWORDs. - Phase 2: if total cost still exceeds 64 DWORDs, merges duplicate `(ParameterType, ShaderRegister, RegisterSpace)` `CBV`/`SRV`/`UAV` root descriptors across stages into a single `D3D12_SHADER_VISIBILITY_ALL` parameter and remaps all stage parameter indices (never merging descriptor tables or `b0` user data). - Call `fit_root_signature` before serializing the root signature in `HostPipeline::new`. - Update `State::bind` (returning `bool` checked by `prepare_for`, `dispatch`, and the `DISPATCH` arm of `execute_indirect`) to upload `UserDataBind::Cbv` values into 256-byte-aligned `HostList::scratch` memory and bind them via `SetComputeRootConstantBufferView` / `SetGraphicsRootConstantBufferView`. ## Verification Isolated verification on branch `gpu/root-signature-user-data-cbv-spill` (`6fa53a5`): - `rustfmt --edition 2024 --config skip_children=true --check crates/victory-gpu/src/pipeline/host.rs crates/victory-gpu/src/draw.rs` (passed) - `cargo test -p victory-gpu -- --test-threads=1` (51 passed, 0 failed, 1 ignored; includes 6 `fit_*` unit tests, `host_oversized_graphics_root_signatures_serialize_after_fit`, and `spilled_user_data_cbv_executes_distinct_dispatches_on_host`) - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1` (53 passed, 0 failed, 1 ignored; zero D3D12 debug layer errors) - `cargo clippy -p victory-gpu --all-targets` (0 warnings in `pipeline/host.rs` and `draw.rs`; 1 pre-existing warning at `host.rs:267`) - `cargo xtask policy` (151 files ok) No game files. AI-assisted; reviewed and verified with the tests above.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:16 +00:00
github-bot closed this pull request 2026-11-26 04:11:16 +00:00
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 21:36 UTC · original

Rebased onto origin/main (ffe310e, new head b106bcd), resolving the conflict in crates/victory-gpu/src/draw.rs:

  • Kept upstream prepare_for (if !self.bind(list, p, false) { return false; }, #681 null vertex-buffer unbinding, #654 diagnostics) and bind(...) -> bool (#336 self.table_failed drop check).
  • Preserved #644 UserDataBind::Constants / UserDataBind::Cbv handling inside bind, returning false when list.scratch(bytes) returns None.

Re-verified on Windows MSVC (cargo clippy + cargo test --workspace --locked):

  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean
  • cargo test --workspace --locked: 350 passed, 0 failed, 6 ignored (victory-gpu: 58 passed, 0 failed, 1 ignored; xtask: 4 passed including repository_passes_policy)
**@⁠nathanbzrr** on GitHub · 2026-11-24 21:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7145161253) Rebased onto `origin/main` (`ffe310e`, new head `b106bcd`), resolving the conflict in `crates/victory-gpu/src/draw.rs`: - Kept upstream `prepare_for` (`if !self.bind(list, p, false) { return false; }`, `#681` null vertex-buffer unbinding, `#654` diagnostics) and `bind(...) -> bool` (`#336` `self.table_failed` drop check). - Preserved `#644` `UserDataBind::Constants` / `UserDataBind::Cbv` handling inside `bind`, returning `false` when `list.scratch(bytes)` returns `None`. Re-verified on Windows MSVC (`cargo clippy` + `cargo test --workspace --locked`): - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean - `cargo test --workspace --locked`: 350 passed, 0 failed, 6 ignored (`victory-gpu`: 58 passed, 0 failed, 1 ignored; `xtask`: 4 passed including `repository_passes_policy`)
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 22:17 UTC · original

Rebased onto origin/main (70564ae, new head 4eb145b):

  • Resolved crates/victory-gpu/src/draw.rs preserving origin/main's prepare_for/execute_indirect diagnostics (NOT_RUN), describe memory details, root_uavs, view_addresses, memory/memory_dirty binding, and roots page-table setup alongside UserDataBind::{Constants, Cbv} handling.
  • Updated Phase 2 root-descriptor deduplication/remapping in crates/victory-gpu/src/pipeline/host.rs (fit_root_signature) to also remap stage.root_uavs, stage.memory, stage.memory_dirty, and stage.view_addresses (so shared cross-stage root UAVs and MEMORY_SPACE descriptors deduplicate and remap accurately).
  • Added unit test pipeline::host::tests::fit_phase2_deduplicates_uavs_and_memory_params covering root_uavs/memory/memory_dirty/view_addresses Phase 2 deduplication, and updated HostShader/Stage/HostPipeline literals in draw::tests::spilled_user_data_cbv_executes_distinct_dispatches_on_host.

Verified on 4eb145b (Windows MSVC):

  • rustfmt --edition 2024 --check crates/victory-gpu/src/pipeline/host.rs crates/victory-gpu/src/draw.rs: all #644 hunks clean (only pre-existing origin/main formatting diffs remain).
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test --workspace --locked: 485 passed, 0 failed, 7 ignored (victory-gpu: 87 passed, 0 failed, 1 ignored; xtask: 4 passed).
**@⁠nathanbzrr** on GitHub · 2026-11-24 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7146040388) Rebased onto `origin/main` (`70564ae`, new head `4eb145b`): - Resolved `crates/victory-gpu/src/draw.rs` preserving `origin/main`'s `prepare_for`/`execute_indirect` diagnostics (`NOT_RUN`), `describe` memory details, `root_uavs`, `view_addresses`, `memory`/`memory_dirty` binding, and `roots` page-table setup alongside `UserDataBind::{Constants, Cbv}` handling. - Updated Phase 2 root-descriptor deduplication/remapping in `crates/victory-gpu/src/pipeline/host.rs` (`fit_root_signature`) to also remap `stage.root_uavs`, `stage.memory`, `stage.memory_dirty`, and `stage.view_addresses` (so shared cross-stage root UAVs and `MEMORY_SPACE` descriptors deduplicate and remap accurately). - Added unit test `pipeline::host::tests::fit_phase2_deduplicates_uavs_and_memory_params` covering `root_uavs`/`memory`/`memory_dirty`/`view_addresses` Phase 2 deduplication, and updated `HostShader`/`Stage`/`HostPipeline` literals in `draw::tests::spilled_user_data_cbv_executes_distinct_dispatches_on_host`. Verified on `4eb145b` (Windows MSVC): - `rustfmt --edition 2024 --check crates/victory-gpu/src/pipeline/host.rs crates/victory-gpu/src/draw.rs`: all `#644` hunks clean (only pre-existing `origin/main` formatting diffs remain). - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test --workspace --locked`: `485 passed, 0 failed, 7 ignored` (`victory-gpu`: `87 passed, 0 failed, 1 ignored`; `xtask`: `4 passed`).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:16 UTC · original · edited 2026-11-25 06:21 UTC

Automated triage for the maintainers.

Merge candidate. fit_root_signature in crates/victory-gpu/src/pipeline/host.rs keeps host root signatures within D3D12's 64-DWORD limit by turning the largest per-stage user-data root constants into a root CBV at the same b0 register, then, if still over, merging identical root views across stages and remapping every stage index and the view_marks pair; State::bind in draw.rs uploads spilled user data to HostList::scratch (256-byte aligned) and binds it as a root CBV. I checked the cost model (constants 1 per DWORD, root views 2, tables 1), that merging is safe because bind reads root views from the pipeline-wide title roots so every stage binds the same address for a slot, and that all index fields (root_uavs, memory, memory_dirty, view_addresses, marks) are remapped. Minor: the assert_eq!(values.len(), dwords as usize) in the Cbv arm can never fail and could go.

Thanks for the rebase. It now merges cleanly with main and the earlier conflict in pipeline/host.rs is resolved, so this is the first content review.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7149385598) · edited 2026-11-25 06:21 UTC <!-- victory-triage v1 head=226e9fc73a8eb807a2abf9dca7e1cd80a90e5a11 verdict=merge-candidate at=2026-11-25T06:21:17Z --> Automated triage for the maintainers. **Merge candidate.** `fit_root_signature` in `crates/victory-gpu/src/pipeline/host.rs` keeps host root signatures within D3D12's 64-DWORD limit by turning the largest per-stage user-data root constants into a root CBV at the same `b0` register, then, if still over, merging identical root views across stages and remapping every stage index and the `view_marks` pair; `State::bind` in `draw.rs` uploads spilled user data to `HostList::scratch` (256-byte aligned) and binds it as a root CBV. I checked the cost model (constants 1 per DWORD, root views 2, tables 1), that merging is safe because `bind` reads root views from the pipeline-wide title roots so every stage binds the same address for a slot, and that all index fields (`root_uavs`, `memory`, `memory_dirty`, `view_addresses`, `marks`) are remapped. Minor: the `assert_eq!(values.len(), dwords as usize)` in the `Cbv` arm can never fail and could go. Thanks for the rebase. It now merges cleanly with `main` and the earlier conflict in `pipeline/host.rs` is resolved, so this is the first content review. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 03:19 UTC · original

Rebased onto origin/main (940d32f, new head 226e9fc):

  • Resolved conflicts in crates/victory-gpu/src/pipeline/host.rs and crates/victory-gpu/src/draw.rs, preserving origin/main's aligned GraphicsState::elements, aniso_point_mip_supported, view_marks root-parameter pair (HostPipeline.marks), readable(..., marked), and early execute_indirect pipeline-drop check.
  • Updated fit_root_signature to take marks: &mut Option<(u32, u32)> so Phase 1 includes the 4-DWORD view_marks/view_writes parameters in the budget and Phase 2 remaps marks indices alongside stages when deduplicating shared root descriptors.
  • Added pipeline::host::tests::fit_accounts_for_and_remaps_view_marks and updated draw::tests::spilled_user_data_cbv_executes_distinct_dispatches_on_host for view_marks/marks.
  • Dropped the unrelated formatting-only hunks from both pipeline/host.rs and draw.rs.

Verified on 226e9fc (Windows MSVC):

  • cargo run -p xtask -- policy --staged: asset policy: 2 files ok
  • cargo clippy --workspace --all-targets -- -D warnings & --all-features: clean
  • cargo test -p victory-gpu --locked: 153 passed, 0 failed, 2 ignored (--all-features: 156 passed, 0 failed, 2 ignored)
  • cargo test --workspace --locked: 0 failures across all workspace crates
**@⁠nathanbzrr** on GitHub · 2026-11-25 03:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7151803072) Rebased onto `origin/main` (`940d32f`, new head `226e9fc`): - Resolved conflicts in `crates/victory-gpu/src/pipeline/host.rs` and `crates/victory-gpu/src/draw.rs`, preserving `origin/main`'s aligned `GraphicsState::elements`, `aniso_point_mip_supported`, `view_marks` root-parameter pair (`HostPipeline.marks`), `readable(..., marked)`, and early `execute_indirect` pipeline-drop check. - Updated `fit_root_signature` to take `marks: &mut Option<(u32, u32)>` so Phase 1 includes the 4-DWORD `view_marks`/`view_writes` parameters in the budget and Phase 2 remaps `marks` indices alongside `stages` when deduplicating shared root descriptors. - Added `pipeline::host::tests::fit_accounts_for_and_remaps_view_marks` and updated `draw::tests::spilled_user_data_cbv_executes_distinct_dispatches_on_host` for `view_marks`/`marks`. - Dropped the unrelated formatting-only hunks from both `pipeline/host.rs` and `draw.rs`. Verified on `226e9fc` (Windows MSVC): - `cargo run -p xtask -- policy --staged`: `asset policy: 2 files ok` - `cargo clippy --workspace --all-targets -- -D warnings` & `--all-features`: clean - `cargo test -p victory-gpu --locked`: 153 passed, 0 failed, 2 ignored (`--all-features`: 156 passed, 0 failed, 2 ignored) - `cargo test --workspace --locked`: 0 failures across all workspace crates
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-25 21:51 UTC · original

Rebased onto origin/main (61bfc77, new head 4b3d5a2):

  • Resolved the test-block conflict at the end of crates/victory-gpu/src/draw.rs, keeping origin/main's placed_unordered_textures_write_and_read_back_through_placed_views and explicit_and_placed_rgba8_textures_at_one_address_share_compute_writes (61bfc77) alongside spilled_user_data_cbv_executes_distinct_dispatches_on_host.
  • Removed the redundant assert_eq!(values.len(), dwords as usize) in State::bind's UserDataBind::Cbv arm per the triage note.

Verified on 4b3d5a2 (Windows MSVC):

  • cargo run -p xtask -- policy: asset policy: 182 files ok
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings & --all-features: clean
  • cargo test -p victory-gpu --lib --locked -- draw::tests --test-threads=1: 14 passed, 0 failed
  • cargo test -p victory-gpu --lib --locked -- pipeline::host::tests --test-threads=1: 11 passed, 0 failed
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- spilled_user_data_cbv_executes_distinct_dispatches_on_host --test-threads=1: 1 passed, 0 failed
**@⁠nathanbzrr** on GitHub · 2026-11-25 21:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7175631381) Rebased onto `origin/main` (`61bfc77`, new head `4b3d5a2`): - Resolved the test-block conflict at the end of `crates/victory-gpu/src/draw.rs`, keeping `origin/main`'s `placed_unordered_textures_write_and_read_back_through_placed_views` and `explicit_and_placed_rgba8_textures_at_one_address_share_compute_writes` (`61bfc77`) alongside `spilled_user_data_cbv_executes_distinct_dispatches_on_host`. - Removed the redundant `assert_eq!(values.len(), dwords as usize)` in `State::bind`'s `UserDataBind::Cbv` arm per the triage note. Verified on `4b3d5a2` (Windows MSVC): - `cargo run -p xtask -- policy`: `asset policy: 182 files ok` - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` & `--all-features`: clean - `cargo test -p victory-gpu --lib --locked -- draw::tests --test-threads=1`: 14 passed, 0 failed - `cargo test -p victory-gpu --lib --locked -- pipeline::host::tests --test-threads=1`: 11 passed, 0 failed - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --lib --locked -- spilled_user_data_cbv_executes_distinct_dispatches_on_host --test-threads=1`: 1 passed, 0 failed
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:11 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because nothing shows that a title pipeline reaches this case. main logs "host root signature refused" whenever it happens, and that line is in none of more than a hundred recent title runs (thousands of pipelines each), while other refusals do show up there; the tests here are synthetic. Against that, the change rewrites how user data is bound for every pipeline and merges root parameters across stages. If a refusal turns up in a run, a fix can be written against that pipeline.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/644#issuecomment-7176055833) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because nothing shows that a title pipeline reaches this case. `main` logs "host root signature refused" whenever it happens, and that line is in none of more than a hundred recent title runs (thousands of pipelines each), while other refusals do show up there; the tests here are synthetic. Against that, the change rewrites how user data is bound for every pipeline and merges root parameters across stages. If a refusal turns up in a run, a fix can be written against that pipeline. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!644
No description provided.