GPU: validate ResolveSubresource sample counts, dimensions, and subresource bounds #3193

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

@⁠fuzeofficlal on GitHub · 2026-11-26 11:48 UTC · original
fuzeofficlal:fix/gpu-resolve-subresource-validation → main · +164 −7 · 1 files · 1 commits · open

Problem

list::resolve in crates/victory-gpu/src/list.rs previously emitted ensure_state, marked texture::host_writes(list, dst), and recorded ID3D12GraphicsCommandList::ResolveSubresource / ResolveSubresourceRegion without validating D3D12's resolve contract:

  1. Passing a non-MSAA source (SampleDesc.Count < 2), a multisampled destination (SampleDesc.Count != 1), a non-2D texture (such as TEXTURE3D), or an out-of-bounds dst_sub / src_sub causes ID3D12GraphicsCommandList::Close() to fail with E_INVALIDARG (0x80070057) even on retail D3D12 (without the Debug Layer) on both hardware and WARP, which aborts HostList::close().
  2. Comparing mip-0 dimensions (a.Width, a.Height) instead of the resolved subresource's mip dimensions produced wrong size comparisons and clip rectangles when resolving into non-zero destination mip levels.

Fix

  • Add texture_subresources using ID3D12Device::CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, ...) to determine each format's exact D3D12 PlaneCount (preserving valid multi-plane depth/stencil resolves) and total subresource count MipLevels * DepthOrArraySize * PlaneCount.
  • Before calling ensure_state or texture::host_writes, verify both textures are D3D12_RESOURCE_DIMENSION_TEXTURE2D, dst.SampleDesc.Count == 1, src.SampleDesc.Count >= 2, and both subresource indices are in bounds; ignore invalid resolves cleanly.
  • Compute (dst_w, dst_h) and (src_w, src_h) at each subresource's mip level (sub % MipLevels) when deciding between ResolveSubresource and ResolveSubresourceRegion and when building the clip RECT.

Verification

Added list::tests::resolve_validates_sample_counts_dimensions_and_subresources covering 5 invalid cases (non_msaa_src, msaa_dst, oob_dst_sub, oob_src_sub, tex3d_dst) and 4 valid resolves (exact match, clipped larger source, multi-mip exact match, multi-mip clipped):

  • Before fix (origin/main): fails list.Close() with HRESULT(0x80070057) (E_INVALIDARG) on retail RTX 5090 (no Debug Layer), Debug RTX 5090, and Debug WARP.
  • After fix:
    • Targeted test passes on hardware default, hardware --features diagnostics + VICTORY_D3D12_DEBUG=1, and WARP --features diagnostics + VICTORY_D3D12_DEBUG=1 with host.log_messages() == None.
    • Full cargo test -p victory-gpu --lib --locked passes on hardware default (230 passed), hardware diagnostics + DEBUG=1 (244 passed), and WARP diagnostics + DEBUG=1 (246 passed).
    • cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features) and xtask policy checks pass cleanly.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3193) `fuzeofficlal:fix/gpu-resolve-subresource-validation` → `main` · +164 −7 · 1 files · 1 commits · open ### Problem `list::resolve` in `crates/victory-gpu/src/list.rs` previously emitted `ensure_state`, marked `texture::host_writes(list, dst)`, and recorded `ID3D12GraphicsCommandList::ResolveSubresource` / `ResolveSubresourceRegion` without validating D3D12's resolve contract: 1. Passing a non-MSAA source (`SampleDesc.Count < 2`), a multisampled destination (`SampleDesc.Count != 1`), a non-2D texture (such as `TEXTURE3D`), or an out-of-bounds `dst_sub` / `src_sub` causes `ID3D12GraphicsCommandList::Close()` to fail with `E_INVALIDARG` (`0x80070057`) even on retail D3D12 (without the Debug Layer) on both hardware and WARP, which aborts `HostList::close()`. 2. Comparing mip-0 dimensions `(a.Width, a.Height)` instead of the resolved subresource's mip dimensions produced wrong size comparisons and clip rectangles when resolving into non-zero destination mip levels. ### Fix - Add `texture_subresources` using `ID3D12Device::CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO, ...)` to determine each format's exact D3D12 `PlaneCount` (preserving valid multi-plane depth/stencil resolves) and total subresource count `MipLevels * DepthOrArraySize * PlaneCount`. - Before calling `ensure_state` or `texture::host_writes`, verify both textures are `D3D12_RESOURCE_DIMENSION_TEXTURE2D`, `dst.SampleDesc.Count == 1`, `src.SampleDesc.Count >= 2`, and both subresource indices are in bounds; ignore invalid resolves cleanly. - Compute `(dst_w, dst_h)` and `(src_w, src_h)` at each subresource's mip level (`sub % MipLevels`) when deciding between `ResolveSubresource` and `ResolveSubresourceRegion` and when building the clip `RECT`. ### Verification Added `list::tests::resolve_validates_sample_counts_dimensions_and_subresources` covering 5 invalid cases (`non_msaa_src`, `msaa_dst`, `oob_dst_sub`, `oob_src_sub`, `tex3d_dst`) and 4 valid resolves (exact match, clipped larger source, multi-mip exact match, multi-mip clipped): - **Before fix (`origin/main`)**: fails `list.Close()` with `HRESULT(0x80070057)` (`E_INVALIDARG`) on retail RTX 5090 (no Debug Layer), Debug RTX 5090, and Debug WARP. - **After fix**: - Targeted test passes on hardware default, hardware `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, and WARP `--features diagnostics` + `VICTORY_D3D12_DEBUG=1` with `host.log_messages() == None`. - Full `cargo test -p victory-gpu --lib --locked` passes on hardware default (`230 passed`), hardware `diagnostics + DEBUG=1` (`244 passed`), and WARP `diagnostics + DEBUG=1` (`246 passed`). - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`) and `xtask` policy checks pass cleanly.
list::resolve previously issued ensure_state, host_writes, and ID3D12GraphicsCommandList::ResolveSubresource / ResolveSubresourceRegion without validating D3D12's resolve contract:

- Passing a non-MSAA source (SampleDesc.Count < 2), a multisampled destination (SampleDesc.Count != 1), a non-2D texture, or an out-of-bounds subresource index causes ID3D12GraphicsCommandList::Close to fail with E_INVALIDARG even on retail D3D12 (without the Debug Layer) on both hardware and WARP, aborting HostList::close.
- Comparing mip-0 dimensions instead of the resolved subresource's mip dimensions also built mismatched sizes/rects when resolving into non-zero mip levels.

Query the host device's format plane count via D3D12_FEATURE_FORMAT_INFO to validate both resources (TEXTURE2D, dst SampleDesc.Count == 1, src SampleDesc.Count >= 2, and in-bounds subresource indices) before emitting state transitions or marking host_writes, and compare/clip using the selected mip dimensions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:51:20 +00:00
Author
Owner

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

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

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: 5/5 passed (including resolve_validates_sample_counts_dimensions_and_subresources).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly validates ResolveSubresource sample counts, dimensions, and subresource bounds.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 12:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3193#pullrequestreview-6073865204) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: 5/5 passed (including `resolve_validates_sample_counts_dimensions_and_subresources`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly validates `ResolveSubresource` sample counts, dimensions, and subresource bounds. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 14:24 UTC · original

WARP verification of #3193 at ec7f2edb (base 63bcca4, origin/main). Software adapter only; synthetic tests only; no GPU, game files, dumps, shader names or hashes.

Environment: Windows 11 Pro 10.0.26200; WARP d3d10warp.dll 10.0.26100.9818; Windows SDK dxil.dll 10.0.19041.5609 on PATH; rustc 1.98.1. VICTORY_WARP=1 VICTORY_D3D12_WARP=1. A throwaway probe (reverted) asserted the adapter description is "Microsoft Basic Render Driver" before any device was created; it held in every run.

Commands (exact head, --features diagnostics, because that is where the WARP switch lives):

cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked list::tests::resolve_validates_sample_counts_dimensions_and_subresources
cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked

Head: the new test list::tests::resolve_validates_sample_counts_dimensions_and_subresources passes (1 passed, 0 failed). Full victory-gpu lib: 247 passed, 0 failed, 1 ignored.

Control: origin/main's list.rs with only this PR's test module appended. Result: the test fails with list.Close() E_INVALIDARG (0x80070057) at the first invalid case, non_msaa_src.

Test report only; no source changes. AI use: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-26 14:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/3193#issuecomment-7194771637) **WARP verification of #3193 at `ec7f2edb`** (base `63bcca4`, `origin/main`). Software adapter only; synthetic tests only; no GPU, game files, dumps, shader names or hashes. **Environment:** Windows 11 Pro 10.0.26200; WARP `d3d10warp.dll` 10.0.26100.9818; Windows SDK `dxil.dll` 10.0.19041.5609 on `PATH`; rustc 1.98.1. `VICTORY_WARP=1 VICTORY_D3D12_WARP=1`. A throwaway probe (reverted) asserted the adapter description is "Microsoft Basic Render Driver" before any device was created; it held in every run. **Commands** (exact head, `--features diagnostics`, because that is where the WARP switch lives): ``` cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked list::tests::resolve_validates_sample_counts_dimensions_and_subresources cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked ``` **Head:** the new test `list::tests::resolve_validates_sample_counts_dimensions_and_subresources` passes (1 passed, 0 failed). Full `victory-gpu` lib: 247 passed, 0 failed, 1 ignored. **Control:** `origin/main`'s `list.rs` with only this PR's test module appended. Result: the test fails with `list.Close()` `E_INVALIDARG` (`0x80070057`) at the first invalid case, `non_msaa_src`. Test report only; no source changes. AI use: Claude Code (Claude Sonnet 5.5).
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/3193/head:github-bot/gh-3193'
git switch 'github-bot/gh-3193'

Merge

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