GPU: validate texture SRV and UAV dimensions, ranges, planes, and swizzles #3201

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

@⁠fuzeofficlal on GitHub · 2026-11-26 12:25 UTC · original
fuzeofficlal:fix/gpu-validate-texture-srv-uav → main · +653 −0 · 1 files · 1 commits · open

Summary

descriptor::host::make validates resource permissions and format compatibility in fits(), but previously forwarded explicit texture D3D12_SHADER_RESOURCE_VIEW_DESC and D3D12_UNORDERED_ACCESS_VIEW_DESC structures directly to ID3D12Device::CreateShaderResourceView and ID3D12Device::CreateUnorderedAccessView without validating their view dimensions, mip/slice/plane ranges, or component mapping.

Because both D3D12 view creation methods return void, an invalid texture view description permanently removes the retail GPU device (GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL / 0x887A0001) even without the D3D12 Debug Layer enabled, causing the next Host::execute() submission to abort the process.

What Changed

In crates/victory-gpu/src/descriptor/host.rs:

  • Added cached plane_count(DXGI_FORMAT) via CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO) and valid_plane() checking PlaneSlice < plane_count plus depth/stencil plane-format pairing (R24_UNORM_X8_TYPELESS / R32_FLOAT_X8X24_TYPELESS on plane 0; X24_TYPELESS_G8_UINT / X32_TYPELESS_G8X24_UINT on plane 1).
  • Added valid_component_mapping() validating Shader4ComponentMapping (bit 12 set, upper bits clear, each 3-bit channel selector in 0..=5).
  • Added range_in_bounds() with overflow-free u64 arithmetic preserving D3D12's u32::MAX remaining-range sentinel.
  • Added texture_srv_fits() and texture_uav_fits() before CreateShaderResourceView / CreateUnorderedAccessView in make() (also covering View::Placed texture views via placed_texture()), validating:
    • ViewDimension against resource Dimension and SampleDesc.Count (rejecting mismatched 1D/2D/3D/buffer/unknown dimensions, non-MS views on multisampled textures, and cube views on textures with fewer than 6 slices, while preserving valid MS views on 1x textures).
    • Mip ranges (MostDetailedMip, MipLevels, MipSlice), array slice ranges (FirstArraySlice, ArraySize), cube-array face ranges (First2DArrayFace, NumCubes, including u32::MAX requiring at least 6 remaining faces), and mip-scaled 3D UAV W-slice ranges (FirstWSlice, WSize).
  • Refused descriptions return None from make(), allowing HostHeap::mirror and HostHeap::make_at to install a matching typed null view via null_for().
  • Added regression test texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null covering 47 cases (invalid SRVs, invalid UAVs, invalid placed texture views, and valid boundary views across 1D/2D/2DArray/2DMS/2DMSArray/Cube/CubeArray/3D and planar R24G8_TYPELESS).

Verification

  • Verified RED on unmodified main (63bcca43) and GREEN with the fix on hardware D3D12 (retail + --features diagnostics with VICTORY_D3D12_DEBUG=1) and WARP (VICTORY_D3D12_WARP=1, VICTORY_D3D12_DEBUG=1), confirming GetDeviceRemovedReason().is_ok() and zero view-creation debug errors across all 47 cases.
  • Full cargo test -p victory-gpu --lib passed in default (231 passed), hardware diagnostics+debug (244 passed), and WARP diagnostics+debug (244 passed) modes.
  • 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:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/3201) `fuzeofficlal:fix/gpu-validate-texture-srv-uav` → `main` · +653 −0 · 1 files · 1 commits · open ## Summary `descriptor::host::make` validates resource permissions and format compatibility in `fits()`, but previously forwarded explicit texture `D3D12_SHADER_RESOURCE_VIEW_DESC` and `D3D12_UNORDERED_ACCESS_VIEW_DESC` structures directly to `ID3D12Device::CreateShaderResourceView` and `ID3D12Device::CreateUnorderedAccessView` without validating their view dimensions, mip/slice/plane ranges, or component mapping. Because both D3D12 view creation methods return `void`, an invalid texture view description permanently removes the retail GPU device (`GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL` / `0x887A0001`) even without the D3D12 Debug Layer enabled, causing the next `Host::execute()` submission to abort the process. ## What Changed In `crates/victory-gpu/src/descriptor/host.rs`: - Added cached `plane_count(DXGI_FORMAT)` via `CheckFeatureSupport(D3D12_FEATURE_FORMAT_INFO)` and `valid_plane()` checking `PlaneSlice < plane_count` plus depth/stencil plane-format pairing (`R24_UNORM_X8_TYPELESS` / `R32_FLOAT_X8X24_TYPELESS` on plane 0; `X24_TYPELESS_G8_UINT` / `X32_TYPELESS_G8X24_UINT` on plane 1). - Added `valid_component_mapping()` validating `Shader4ComponentMapping` (bit 12 set, upper bits clear, each 3-bit channel selector in `0..=5`). - Added `range_in_bounds()` with overflow-free `u64` arithmetic preserving D3D12's `u32::MAX` remaining-range sentinel. - Added `texture_srv_fits()` and `texture_uav_fits()` before `CreateShaderResourceView` / `CreateUnorderedAccessView` in `make()` (also covering `View::Placed` texture views via `placed_texture()`), validating: - `ViewDimension` against resource `Dimension` and `SampleDesc.Count` (rejecting mismatched 1D/2D/3D/buffer/unknown dimensions, non-MS views on multisampled textures, and cube views on textures with fewer than 6 slices, while preserving valid MS views on 1x textures). - Mip ranges (`MostDetailedMip`, `MipLevels`, `MipSlice`), array slice ranges (`FirstArraySlice`, `ArraySize`), cube-array face ranges (`First2DArrayFace`, `NumCubes`, including `u32::MAX` requiring at least 6 remaining faces), and mip-scaled 3D UAV W-slice ranges (`FirstWSlice`, `WSize`). - Refused descriptions return `None` from `make()`, allowing `HostHeap::mirror` and `HostHeap::make_at` to install a matching typed null view via `null_for()`. - Added regression test `texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null` covering 47 cases (invalid SRVs, invalid UAVs, invalid placed texture views, and valid boundary views across 1D/2D/2DArray/2DMS/2DMSArray/Cube/CubeArray/3D and planar `R24G8_TYPELESS`). ## Verification - Verified RED on unmodified `main` (`63bcca43`) and GREEN with the fix on hardware D3D12 (retail + `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`) and WARP (`VICTORY_D3D12_WARP=1`, `VICTORY_D3D12_DEBUG=1`), confirming `GetDeviceRemovedReason().is_ok()` and zero view-creation debug errors across all 47 cases. - Full `cargo test -p victory-gpu --lib` passed in default (`231 passed`), hardware diagnostics+debug (`244 passed`), and WARP diagnostics+debug (`244 passed`) modes. - `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 explicit texture shader resource and unordered access view descriptions in descriptor::host::make before calling CreateShaderResourceView or CreateUnorderedAccessView:

- Check ViewDimension compatibility against the host texture's Dimension and SampleDesc.Count (rejecting mismatched 1D/2D/3D/buffer/unknown views, non-MS views on multisampled textures, and cube views on textures with fewer than 6 array slices).
- Validate mip ranges (MostDetailedMip / MipLevels / MipSlice), array slice ranges (FirstArraySlice / ArraySize), cube array face ranges (First2DArrayFace / NumCubes), and mip-scaled 3D UAV W-slice ranges (FirstWSlice / WSize), preserving u32::MAX remaining-range sentinels without overflow.
- Validate PlaneSlice against the host device's cached D3D12_FEATURE_FORMAT_INFO PlaneCount and depth/stencil plane-format pairing.
- Validate SRV Shader4ComponentMapping (bit 12 set, upper bits clear, each 3-bit channel selector in 0..=5).

D3D12 permanently removes the retail GPU device (DXGI_ERROR_INVALID_CALL, 0x887A0001) on invalid CreateShaderResourceView/CreateUnorderedAccessView descriptions even without the debug layer. Refusing incompatible descriptions lets HostHeap::mirror and HostHeap::make_at install a typed null fallback cleanly.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:32:54 +00:00
Author
Owner

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

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

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

Cleanly validates texture SRV and UAV dimensions, mip/array ranges, planes, and component mappings before host descriptor creation.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 12:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/3201#pullrequestreview-6074106033) · **approved these changes** Verified on RTX 5090 against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 22/22 passed (including `texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly validates texture SRV and UAV dimensions, mip/array ranges, planes, and component mappings before host descriptor creation. 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 #3201 at cef7e1c0 (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 descriptor::host::tests::texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null
cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked

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

Control: the same head with only the two new texture_srv_fits / texture_uav_fits calls in make() removed (the PR only adds code, so that is main's behaviour plus the new test). Result: the test fails with the host device removed (DXGI_ERROR_INVALID_CALL, 0x887A0001) at the first case, srv_2d_oob_mip.

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/3201#issuecomment-7194770324) **WARP verification of #3201 at `cef7e1c0`** (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 descriptor::host::tests::texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null cargo test -j 4 -p victory-gpu --lib --features diagnostics --locked ``` **Head:** the new test `descriptor::host::tests::texture_views_with_invalid_dimensions_ranges_or_mapping_fall_back_to_null` passes (1 passed, 0 failed). Full `victory-gpu` lib: 247 passed, 0 failed, 1 ignored. **Control:** the same head with only the two new `texture_srv_fits` / `texture_uav_fits` calls in `make()` removed (the PR only adds code, so that is main's behaviour plus the new test). Result: the test fails with the host device removed (`DXGI_ERROR_INVALID_CALL`, `0x887A0001`) at the first case, `srv_2d_oob_mip`. 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/3201/head:github-bot/gh-3201'
git switch 'github-bot/gh-3201'

Merge

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