GPU: clear unused RTFormats slots and clamp NumRenderTargets #3164

Open
github-bot wants to merge 1 commit from github-bot/gh-3164 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 10:40 UTC · original
fuzeofficlal:fix/gpu-rt-format-array-unused-slots → main · +279 −1 · 1 files · 1 commits · open

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
**@⁠fuzeofficlal** on GitHub · 2026-11-26 10:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3164) `fuzeofficlal:fix/gpu-rt-format-array-unused-slots` → `main` · +279 −1 · 1 files · 1 commits · open ## 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`
GraphicsState::read converted all 8 entries of D3D12_RT_FORMAT_ARRAY without clamping NumRenderTargets to 8 or clearing trailing RTFormats[NumRenderTargets..8] to DXGI_FORMAT_UNKNOWN. D3D12 CreateGraphicsPipelineState and CreatePipelineState reject non-unknown trailing formats or NumRenderTargets > 8 with E_INVALIDARG, dropping every draw that uses the pipeline, and GraphicsState::describe hashed the stale trailing slots into the pipeline cache key.

Clamp NumRenderTargets to RTFormats.len() (8), translate only active slots [..count], and fill unused trailing slots [count..] with DXGI_FORMAT_UNKNOWN. Previously valid pipelines already had NumRenderTargets <= 8 and DXGI_FORMAT_UNKNOWN in trailing slots, so existing pipeline cache keys are unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:09 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 10:47 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 10:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3164#pullrequestreview-6072747955) · **approved these changes** 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).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3164/head:github-bot/gh-3164'
git switch 'github-bot/gh-3164'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3164'
git switch 'github-bot/gh-3164'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3164'
git switch 'github-bot/gh-3164'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3164'
git switch 'main'
git merge --squash 'github-bot/gh-3164'
git switch 'main'
git merge --ff-only 'github-bot/gh-3164'
git switch 'main'
git merge 'github-bot/gh-3164'
git push origin 'main'
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!3164
No description provided.