GPU: validate RTV and DSV dimensions, ranges, formats, and flags #3205

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

@⁠fuzeofficlal on GitHub · 2026-11-26 12:42 UTC · original
fuzeofficlal:fix/gpu-validate-rtv-dsv → main · +670 −8 · 3 files · 1 commits · open

Summary

Host::rtv and Host::dsv previously forwarded title-supplied render target and depth-stencil view descriptions directly to ID3D12Device::CreateRenderTargetView and ID3D12Device::CreateDepthStencilView without validating resource flags, formats, view dimensions, mip/slice/plane ranges, or DSV flags.

Because both D3D12 view creation methods return void, an invalid RTV or DSV description permanently removes the retail D3D12 device (GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL / 0x887A0001) even without the debug layer enabled, aborting the process on the next submission.

What Changed

  • crates/victory-gpu/src/host.rs:
    • Added Host::try_rtv and Host::try_dsv backed by rtv_fits, dsv_fits, cached renders_format (D3D12_FEATURE_FORMAT_SUPPORT / D3D12_FORMAT_SUPPORT1_RENDER_TARGET), cached format_planes (D3D12_FEATURE_FORMAT_INFO), and overflow-free view_range_fits (supporting D3D12's u32::MAX remaining-range sentinel).
    • Validates ALLOW_RENDER_TARGET / ALLOW_DEPTH_STENCIL, format compatibility (rejecting typeless/unsupported view formats, None/UNKNOWN on typeless textures, and non-depth or cross-family DSV formats, while preserving ID3D12Device10 castable-format RTVs), ViewDimension vs resource Dimension and SampleDesc.Count, MipSlice, array slice ranges, mip-scaled 3D RTV W-slice ranges, RTV PlaneSlice, and D3D12_DSV_FLAGS (rejecting unknown flag bits and D3D12_DSV_FLAG_READ_ONLY_STENCIL on depth-only formats without stencil).
  • crates/victory-gpu/src/draw.rs & crates/victory-gpu/src/list.rs:
    • Routed State::set_targets, list::clear_rtv, and list::clear_dsv through Host::try_rtv and Host::try_dsv, avoiding invalid view creation and dead resource transitions when a view is refused.
    • Added end-to-end regression test invalid_rtv_and_dsv_descriptions_are_refused_without_device_removal exercising OMSetRenderTargets, ClearRenderTargetView, and ClearDepthStencilView across 56 invalid and valid boundary RTV/DSV cases (including castable-format RTVs).

Verification

  • Verified RED on unmodified main (63bcca43) — retail D3D12 permanently removed the device with DXGI_ERROR_INVALID_CALL (0x887A0001) and debug builds fatally aborted (exit code 2173) — and GREEN with the fix across retail hardware D3D12, hardware --features diagnostics with VICTORY_D3D12_DEBUG=1, and WARP (VICTORY_D3D12_WARP=1) with VICTORY_D3D12_DEBUG=1.
  • Full cargo test -p victory-gpu --lib passed across default hardware (231 passed), hardware diagnostics+debug (244 passed), and WARP diagnostics+debug (244 passed) runs.
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features), rustfmt --edition 2024, git diff --check, and cargo run --locked -p xtask -- policy all passed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3205) `fuzeofficlal:fix/gpu-validate-rtv-dsv` → `main` · +670 −8 · 3 files · 1 commits · open ## Summary `Host::rtv` and `Host::dsv` previously forwarded title-supplied render target and depth-stencil view descriptions directly to `ID3D12Device::CreateRenderTargetView` and `ID3D12Device::CreateDepthStencilView` without validating resource flags, formats, view dimensions, mip/slice/plane ranges, or DSV flags. Because both D3D12 view creation methods return `void`, an invalid RTV or DSV description permanently removes the retail D3D12 device (`GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL` / `0x887A0001`) even without the debug layer enabled, aborting the process on the next submission. ## What Changed - `crates/victory-gpu/src/host.rs`: - Added `Host::try_rtv` and `Host::try_dsv` backed by `rtv_fits`, `dsv_fits`, cached `renders_format` (`D3D12_FEATURE_FORMAT_SUPPORT` / `D3D12_FORMAT_SUPPORT1_RENDER_TARGET`), cached `format_planes` (`D3D12_FEATURE_FORMAT_INFO`), and overflow-free `view_range_fits` (supporting D3D12's `u32::MAX` remaining-range sentinel). - Validates `ALLOW_RENDER_TARGET` / `ALLOW_DEPTH_STENCIL`, format compatibility (rejecting typeless/unsupported view formats, `None`/`UNKNOWN` on typeless textures, and non-depth or cross-family DSV formats, while preserving `ID3D12Device10` castable-format RTVs), `ViewDimension` vs resource `Dimension` and `SampleDesc.Count`, `MipSlice`, array slice ranges, mip-scaled 3D RTV W-slice ranges, RTV `PlaneSlice`, and `D3D12_DSV_FLAGS` (rejecting unknown flag bits and `D3D12_DSV_FLAG_READ_ONLY_STENCIL` on depth-only formats without stencil). - `crates/victory-gpu/src/draw.rs` & `crates/victory-gpu/src/list.rs`: - Routed `State::set_targets`, `list::clear_rtv`, and `list::clear_dsv` through `Host::try_rtv` and `Host::try_dsv`, avoiding invalid view creation and dead resource transitions when a view is refused. - Added end-to-end regression test `invalid_rtv_and_dsv_descriptions_are_refused_without_device_removal` exercising `OMSetRenderTargets`, `ClearRenderTargetView`, and `ClearDepthStencilView` across 56 invalid and valid boundary RTV/DSV cases (including castable-format RTVs). ## Verification - Verified RED on unmodified `main` (`63bcca43`) — retail D3D12 permanently removed the device with `DXGI_ERROR_INVALID_CALL (0x887A0001)` and debug builds fatally aborted (`exit code 2173`) — and GREEN with the fix across retail hardware D3D12, hardware `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`, and WARP (`VICTORY_D3D12_WARP=1`) with `VICTORY_D3D12_DEBUG=1`. - Full `cargo test -p victory-gpu --lib` passed across default hardware (`231 passed`), hardware diagnostics+debug (`244 passed`), and WARP diagnostics+debug (`244 passed`) runs. - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`), `rustfmt --edition 2024`, `git diff --check`, and `cargo run --locked -p xtask -- policy` all passed.
Validate render target and depth-stencil view descriptions in Host::try_rtv and Host::try_dsv before calling CreateRenderTargetView or CreateDepthStencilView from State::set_targets, list::clear_rtv, and list::clear_dsv:

- Require ALLOW_RENDER_TARGET / ALLOW_DEPTH_STENCIL on the host texture and reject typeless or unsupported view formats (including NULL descriptions on typeless textures and non-depth or cross-family formats on DSVs), while preserving Device10 castable-format RTVs.
- Validate ViewDimension compatibility against resource Dimension and SampleDesc.Count (rejecting mismatched 1D/2D/3D/buffer/unknown views and non-MS views on multisampled textures, while preserving valid MS views on 1x textures).
- Validate MipSlice, array slice ranges (FirstArraySlice / ArraySize), mip-scaled 3D RTV W-slice ranges (FirstWSlice / WSize), and RTV PlaneSlice against cached D3D12_FEATURE_FORMAT_INFO PlaneCount, preserving u32::MAX remaining-range sentinels without overflow.
- Validate DSV Flags (rejecting unknown flag bits and D3D12_DSV_FLAG_READ_ONLY_STENCIL on depth-only formats without a stencil plane).

Invalid CreateRenderTargetView/CreateDepthStencilView calls permanently remove the retail D3D12 device (DXGI_ERROR_INVALID_CALL, 0x887A0001) even without the debug layer. Refusing incompatible views avoids device removal and dead resource barriers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:44:19 +00:00
Author
Owner

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

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

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: passed.
  • cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 21/21 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly validates RTV and DSV dimensions, mip/array ranges, formats, and flags.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 12:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/3205#pullrequestreview-6074380550) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib list:: -- --test-threads=1`: passed. - `cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 21/21 passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly validates RTV and DSV dimensions, mip/array ranges, formats, and flags. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 13:25 UTC · original

WARP test report (head 2ecc9ef, on top of current main 63bcca4)

Environment: Windows 11, WARP only (VICTORY_D3D12_WARP=1 with --features diagnostics, plus VICTORY_WARP=1), rustc/cargo 1.98.1.

  • cargo test -p victory-gpu --lib --locked --features diagnostics -- --test-threads=1: 247 passed, 0 failed, 1 ignored, including list::tests::invalid_rtv_and_dsv_descriptions_are_refused_without_device_removal (all invalid RTV/DSV cases refused, all boundary cases accepted, device not removed, no CreateRenderTargetView/CreateDepthStencilView debug errors).
  • Control (main + the PR's test, with pass-through try_rtv/try_dsv shims that call rtv/dsv unvalidated): FAILS at rtv_no_rt_flag (a resource without the render-target flag is accepted). So the test needs the validation. The shims are needed because the test calls try_rtv/try_dsv directly.
  • No test skipped on WARP.

Diff review: no blocking problem. Notes: the TEXTURE2DMS view on a single-sample texture is treated as valid (rtv_2dms_on_s1); WARP and its validation accept it, but I could not check a hardware driver. renders_format and format_planes cache per format in process-wide statics, which is fine with one host device.

AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Synthetic tests only; no game files, dumps, shader names or retail hashes.

**@⁠oni-swr** on GitHub · 2026-11-26 13:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3205#issuecomment-7193340282) **WARP test report (head 2ecc9ef, on top of current main 63bcca4)** Environment: Windows 11, **WARP only** (`VICTORY_D3D12_WARP=1` with `--features diagnostics`, plus `VICTORY_WARP=1`), rustc/cargo 1.98.1. - `cargo test -p victory-gpu --lib --locked --features diagnostics -- --test-threads=1`: **247 passed, 0 failed, 1 ignored**, including `list::tests::invalid_rtv_and_dsv_descriptions_are_refused_without_device_removal` (all invalid RTV/DSV cases refused, all boundary cases accepted, device not removed, no CreateRenderTargetView/CreateDepthStencilView debug errors). - **Control** (main + the PR's test, with pass-through `try_rtv`/`try_dsv` shims that call `rtv`/`dsv` unvalidated): FAILS at `rtv_no_rt_flag` (a resource without the render-target flag is accepted). So the test needs the validation. The shims are needed because the test calls `try_rtv`/`try_dsv` directly. - No test skipped on WARP. Diff review: no blocking problem. Notes: the `TEXTURE2DMS` view on a single-sample texture is treated as valid (`rtv_2dms_on_s1`); WARP and its validation accept it, but I could not check a hardware driver. `renders_format` and `format_planes` cache per format in process-wide statics, which is fine with one host device. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Claude Code (Claude Opus 5.5). Synthetic tests only; no game files, dumps, shader names or retail hashes.
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/3205/head:github-bot/gh-3205'
git switch 'github-bot/gh-3205'

Merge

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