GPU: clear unused RTFormats slots and clamp NumRenderTargets #3162

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3164 into main
fuzeofficlal commented 2026-11-26 10:40:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T10:40:52Z.


Summary

GraphicsState::read (subobject kind 15, D3D12_RT_FORMAT_ARRAY) copied all 8 RTFormats entries and mapped them through pc_format, but neither clamped NumRenderTargets to 8 nor cleared unused trailing slots (RTFormats[NumRenderTargets..8]) to DXGI_FORMAT_UNKNOWN.

Per D3D12 pipeline state validation:

  • NumRenderTargets must be <= 8, and
  • every RTFormats[i] for i >= NumRenderTargets must be DXGI_FORMAT_UNKNOWN.

When a stream leaves stale formats past NumRenderTargets (for example after lowering NumRenderTargets or setting it to 0 for a depth-only pass) or passes NumRenderTargets > 8, both CreateGraphicsPipelineState and ID3D12Device2::CreatePipelineState fail with E_INVALIDARG even without the debug layer enabled, causing HostPipeline::new to return None and drop every draw using that pipeline. In addition, GraphicsState::describe() includes all 8 RTFormats slots in the pipeline library key.

Fix

In GraphicsState::read for kind 15 (crates/victory-gpu/src/pipeline/host.rs):

  • Clamp NumRenderTargets to RTFormats.len() (8).
  • Translate only active slots RTFormats[..count] through pc_format (preserving valid sparse DXGI_FORMAT_UNKNOWN entries below NumRenderTargets).
  • Fill unused trailing slots RTFormats[count..] with DXGI_FORMAT_UNKNOWN.

Previously valid pipelines already had NumRenderTargets <= 8 and DXGI_FORMAT_UNKNOWN in trailing slots, so existing pipeline library cache keys are unchanged.

Verification

Added unit and real D3D12 pipeline-creation regression tests in crates/victory-gpu/src/pipeline/host.rs:

  • rt_format_array_clears_unused_slots_and_clamps_count: verifies trailing slot clearing, canonical describe() keys, preservation of sparse active DXGI_FORMAT_UNKNOWN slots, and clamping NumRenderTargets > 8.
  • host_pipeline_accepts_stream_with_trailing_rt_formats: verifies HostPipeline::new succeeds with zero D3D12 debug layer errors for trailing formats past NumRenderTargets, NumRenderTargets = 0 with stale slot 0 (including the stream_pipeline / CreatePipelineState path when depth bounds are supported), and NumRenderTargets > 8. Confirmed both tests fail on main (CreateGraphicsPipelineState rejects the PSO even without VICTORY_D3D12_DEBUG=1) and pass after the fix.

Ran:

  • cargo test -p victory-gpu --lib --locked -- --test-threads=1 (RTX 5090 default, RTX 5090 --features diagnostics + VICTORY_D3D12_DEBUG=1, and VICTORY_D3D12_WARP=1 + --features diagnostics + VICTORY_D3D12_DEBUG=1)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features)
  • cargo test -p xtask --locked policy::tests::repository_passes_policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:5508485460 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3164). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T10:40:52Z. --- ## Summary `GraphicsState::read` (subobject kind 15, `D3D12_RT_FORMAT_ARRAY`) copied all 8 `RTFormats` entries and mapped them through `pc_format`, but neither clamped `NumRenderTargets` to 8 nor cleared unused trailing slots (`RTFormats[NumRenderTargets..8]`) to `DXGI_FORMAT_UNKNOWN`. Per D3D12 pipeline state validation: - `NumRenderTargets` must be `<= 8`, and - every `RTFormats[i]` for `i >= NumRenderTargets` must be `DXGI_FORMAT_UNKNOWN`. When a stream leaves stale formats past `NumRenderTargets` (for example after lowering `NumRenderTargets` or setting it to `0` for a depth-only pass) or passes `NumRenderTargets > 8`, both `CreateGraphicsPipelineState` and `ID3D12Device2::CreatePipelineState` fail with `E_INVALIDARG` even without the debug layer enabled, causing `HostPipeline::new` to return `None` and drop every draw using that pipeline. In addition, `GraphicsState::describe()` includes all 8 `RTFormats` slots in the pipeline library key. ## Fix In `GraphicsState::read` for kind 15 (`crates/victory-gpu/src/pipeline/host.rs`): - Clamp `NumRenderTargets` to `RTFormats.len()` (`8`). - Translate only active slots `RTFormats[..count]` through `pc_format` (preserving valid sparse `DXGI_FORMAT_UNKNOWN` entries below `NumRenderTargets`). - Fill unused trailing slots `RTFormats[count..]` with `DXGI_FORMAT_UNKNOWN`. Previously valid pipelines already had `NumRenderTargets <= 8` and `DXGI_FORMAT_UNKNOWN` in trailing slots, so existing pipeline library cache keys are unchanged. ## Verification Added unit and real D3D12 pipeline-creation regression tests in `crates/victory-gpu/src/pipeline/host.rs`: - `rt_format_array_clears_unused_slots_and_clamps_count`: verifies trailing slot clearing, canonical `describe()` keys, preservation of sparse active `DXGI_FORMAT_UNKNOWN` slots, and clamping `NumRenderTargets > 8`. - `host_pipeline_accepts_stream_with_trailing_rt_formats`: verifies `HostPipeline::new` succeeds with zero D3D12 debug layer errors for trailing formats past `NumRenderTargets`, `NumRenderTargets = 0` with stale slot 0 (including the `stream_pipeline` / `CreatePipelineState` path when depth bounds are supported), and `NumRenderTargets > 8`. Confirmed both tests fail on `main` (`CreateGraphicsPipelineState` rejects the PSO even without `VICTORY_D3D12_DEBUG=1`) and pass after the fix. Ran: - `cargo test -p victory-gpu --lib --locked -- --test-threads=1` (RTX 5090 default, RTX 5090 `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, and `VICTORY_D3D12_WARP=1` + `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`) - `cargo test -p xtask --locked policy::tests::repository_passes_policy`
Dukestar69 commented 2026-11-26 10:47:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T10:47:04Z.

Review: APPROVED


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

  • cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1: 25/25 passed (including host_pipeline_accepts_stream_with_trailing_rt_formats and rt_format_array_clears_unused_slots_and_clamps_count).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly zeroes unused RTFormats entries and clamps NumRenderTargets to 8.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6072747955 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3164#pullrequestreview-6072747955). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T10:47:04Z. **Review:** APPROVED --- Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1`: 25/25 passed (including `host_pipeline_accepts_stream_with_trailing_rt_formats` and `rt_format_array_clears_unused_slots_and_clamps_count`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly zeroes unused `RTFormats` entries and clamps `NumRenderTargets` to 8. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Jackster commented 2026-11-26 23:02:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:02:16Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • cargo test -p victory-gpu --lib: 233 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231; +2).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

rt_format_array_clears_unused_slots_and_clamps_count and host_pipeline_accepts_stream_with_trailing_rt_formats both pass. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205198968 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3164#issuecomment-7205198968). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T23:02:16Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `cargo test -p victory-gpu --lib`: 233 passed / 0 failed / 1 ignored (unpatched `63bcca4` here: 231; +2). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. `rt_format_array_clears_unused_slots_and_clamps_count` and `host_pipeline_accepts_stream_with_trailing_rt_formats` both pass. Synthetic only. AI-assisted.
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/3164:upstream-pr/3164'
git switch 'upstream-pr/3164'

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