GPU: sanitize plain D3D12 sampler descriptions before CreateSampler #3209

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

@⁠fuzeofficlal on GitHub · 2026-11-26 12:48 UTC · original
fuzeofficlal:fix/gpu-sanitize-sampler-desc → main · +226 −0 · 2 files · 1 commits · open

Summary

CreateSamplerX (View::ConsoleSampler) already sanitizes all sampler fields in sampler::console, but plain CreateSampler (View::Sampler) in descriptor::host::make previously forwarded raw title [u32; 13] words straight to ID3D12Device::CreateSampler.

Because CreateSampler returns void, an invalid filter enum, address mode, anisotropy count (> 16), comparison function, out-of-range/NaN MipLODBias, or NaN MinLOD/MaxLOD permanently removes the retail D3D12 device (GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL / 0x887A0001) even without the debug layer enabled.

What Changed

  • crates/victory-gpu/src/sampler.rs:
    • Added pub(crate) fn sanitize(desc: D3D12_SAMPLER_DESC, aniso_point_mip: bool) -> D3D12_SAMPLER_DESC, reusing the module's existing address_mode and finite_lod helpers:
      • Validates Filter against D3D12's 40 legal filter encodings (reduction <= 3 with standard min/mag/mip bits or anisotropic 0x54/0x55), downgrades anisotropic point-mip (0x54) to 0x55 when the host lacks AnisoFilterWithPointMipSupported, and falls back to D3D12_FILTER_MIN_MAG_MIP_LINEAR for unrecognized values.
      • Sanitizes AddressU/V/W (1..=5, fallback CLAMP), clamps MaxAnisotropy to 0..=16, validates ComparisonFunc (1..=8, fallback NEVER), clamps MipLODBias to [D3D12_MIP_LOD_BIAS_MIN, D3D12_MIP_LOD_BIAS_MAX] (NaN -> 0.0), and sanitizes MinLOD/MaxLOD via finite_lod.
    • Added unit test plain_sampler_sanitization_preserves_valid_and_clamps_invalid.
  • crates/victory-gpu/src/descriptor/host.rs:
    • Applied crate::sampler::sanitize(desc, crate::sampler::aniso_point_mip(device)) in View::Sampler before calling device.CreateSampler(&desc, at).
    • Added end-to-end GPU test plain_sampler_descriptions_are_sanitized_before_host_creation covering 16 invalid sampler cases and 5 valid boundary cases through create_sampler, HostHeap::mirror, and HostHeap::make_at.

Verification

  • Verified RED on unmodified main (63bcca43) — CreateSampler permanently removed the device with DXGI_ERROR_INVALID_CALL (0x887A0001) on retail hardware D3D12, debug hardware D3D12, and debug WARP — and GREEN with the fix across all three modes with zero device removal and zero CreateSampler debug errors.
  • Full cargo test -p victory-gpu --lib passed in default hardware (231 passed), hardware diagnostics+debug (245 passed), and WARP diagnostics+debug (245 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:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3209) `fuzeofficlal:fix/gpu-sanitize-sampler-desc` → `main` · +226 −0 · 2 files · 1 commits · open ## Summary `CreateSamplerX` (`View::ConsoleSampler`) already sanitizes all sampler fields in `sampler::console`, but plain `CreateSampler` (`View::Sampler`) in `descriptor::host::make` previously forwarded raw title `[u32; 13]` words straight to `ID3D12Device::CreateSampler`. Because `CreateSampler` returns `void`, an invalid filter enum, address mode, anisotropy count (`> 16`), comparison function, out-of-range/NaN `MipLODBias`, or NaN `MinLOD`/`MaxLOD` permanently removes the retail D3D12 device (`GetDeviceRemovedReason() == DXGI_ERROR_INVALID_CALL` / `0x887A0001`) even without the debug layer enabled. ## What Changed - `crates/victory-gpu/src/sampler.rs`: - Added `pub(crate) fn sanitize(desc: D3D12_SAMPLER_DESC, aniso_point_mip: bool) -> D3D12_SAMPLER_DESC`, reusing the module's existing `address_mode` and `finite_lod` helpers: - Validates `Filter` against D3D12's 40 legal filter encodings (`reduction <= 3` with standard min/mag/mip bits or anisotropic `0x54`/`0x55`), downgrades anisotropic point-mip (`0x54`) to `0x55` when the host lacks `AnisoFilterWithPointMipSupported`, and falls back to `D3D12_FILTER_MIN_MAG_MIP_LINEAR` for unrecognized values. - Sanitizes `AddressU/V/W` (`1..=5`, fallback `CLAMP`), clamps `MaxAnisotropy` to `0..=16`, validates `ComparisonFunc` (`1..=8`, fallback `NEVER`), clamps `MipLODBias` to `[D3D12_MIP_LOD_BIAS_MIN, D3D12_MIP_LOD_BIAS_MAX]` (`NaN -> 0.0`), and sanitizes `MinLOD`/`MaxLOD` via `finite_lod`. - Added unit test `plain_sampler_sanitization_preserves_valid_and_clamps_invalid`. - `crates/victory-gpu/src/descriptor/host.rs`: - Applied `crate::sampler::sanitize(desc, crate::sampler::aniso_point_mip(device))` in `View::Sampler` before calling `device.CreateSampler(&desc, at)`. - Added end-to-end GPU test `plain_sampler_descriptions_are_sanitized_before_host_creation` covering 16 invalid sampler cases and 5 valid boundary cases through `create_sampler`, `HostHeap::mirror`, and `HostHeap::make_at`. ## Verification - Verified RED on unmodified `main` (`63bcca43`) — `CreateSampler` permanently removed the device with `DXGI_ERROR_INVALID_CALL (0x887A0001)` on retail hardware D3D12, debug hardware D3D12, and debug WARP — and GREEN with the fix across all three modes with zero device removal and zero `CreateSampler` debug errors. - Full `cargo test -p victory-gpu --lib` passed in default hardware (`231 passed`), hardware diagnostics+debug (`245 passed`), and WARP diagnostics+debug (`245 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.
Sanitize title-supplied D3D12_SAMPLER_DESC records in sampler::sanitize before calling ID3D12Device::CreateSampler for View::Sampler in descriptor::host::make:

- Validate Filter against D3D12's 40 legal enum values (reduction 0..=3 with standard min/mag/mip bits or anisotropic 0x54/0x55), downgrade anisotropic point-mip filters (0x54) to 0x55 when the host lacks AnisoFilterWithPointMipSupported, and fall back to MIN_MAG_MIP_LINEAR on unrecognized values.
- Sanitize AddressU/V/W (1..=5, fallback CLAMP), clamp MaxAnisotropy to 0..=16, validate ComparisonFunc (1..=8, fallback NEVER), clamp MipLODBias to D3D12_MIP_LOD_BIAS_MIN..=MAX (NaN -> 0.0), and replace NaN/infinite MinLOD/MaxLOD bounds via finite_lod.

ID3D12Device::CreateSampler returns void and permanently removes the retail D3D12 device (DXGI_ERROR_INVALID_CALL, 0x887A0001) on invalid sampler descriptions even without the debug layer. CreateSamplerX (View::ConsoleSampler) already sanitized these fields; plain CreateSampler (View::Sampler) previously passed raw title words straight to the host.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:50:12 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 13:07 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 plain_sampler_descriptions_are_sanitized_before_host_creation).
  • cargo test -p victory-gpu --lib sampler:: -- --test-threads=1: passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly sanitizes plain D3D12 sampler descriptions before CreateSampler.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 13:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3209#pullrequestreview-6074658741) · **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 `plain_sampler_descriptions_are_sanitized_before_host_creation`). - `cargo test -p victory-gpu --lib sampler:: -- --test-threads=1`: passed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly sanitizes plain D3D12 sampler descriptions before `CreateSampler`. 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 8b27f29, on top of current main 63bcca4)

Environment: Windows 11, WARP only (VICTORY_D3D12_WARP=1 with --features diagnostics, which the GPU crate needs to honour it; plus VICTORY_WARP=1), rustc/cargo 1.98.1.

  • cargo test -p victory-gpu --lib --locked --features diagnostics -- --test-threads=1: 248 passed, 0 failed, 1 ignored. This includes the new descriptor::host::tests::plain_sampler_descriptions_are_sanitized_before_host_creation and sampler::tests::plain_sampler_sanitization_preserves_valid_and_clamps_invalid.
  • Control (main + the PR's host test, without the sanitize call): FAILS at the first case, bad_filter_ffff removed the host device: HRESULT(0x887A0001). So the test exercises the fix on WARP. (The unit test in sampler.rs calls sanitize itself, so it cannot compile on main.)
  • No test skipped on WARP.

Diff review: no blocking problem. Two small notes: (1) MaxAnisotropy is only capped at 16, so MaxAnisotropy == 0 with an anisotropic filter still reaches CreateSampler (D3D12 documents 1..16 for anisotropic filters); the tests cover 0 only with a plain filter. (2) MinLOD > MaxLOD is passed through. Neither is covered by the new cases.

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/3209#issuecomment-7193339795) **WARP test report (head 8b27f29, on top of current main 63bcca4)** Environment: Windows 11, **WARP only** (`VICTORY_D3D12_WARP=1` with `--features diagnostics`, which the GPU crate needs to honour it; plus `VICTORY_WARP=1`), rustc/cargo 1.98.1. - `cargo test -p victory-gpu --lib --locked --features diagnostics -- --test-threads=1`: **248 passed, 0 failed, 1 ignored**. This includes the new `descriptor::host::tests::plain_sampler_descriptions_are_sanitized_before_host_creation` and `sampler::tests::plain_sampler_sanitization_preserves_valid_and_clamps_invalid`. - **Control** (main + the PR's host test, without the `sanitize` call): FAILS at the first case, `bad_filter_ffff removed the host device: HRESULT(0x887A0001)`. So the test exercises the fix on WARP. (The unit test in `sampler.rs` calls `sanitize` itself, so it cannot compile on main.) - No test skipped on WARP. Diff review: no blocking problem. Two small notes: (1) `MaxAnisotropy` is only capped at 16, so `MaxAnisotropy == 0` with an anisotropic filter still reaches `CreateSampler` (D3D12 documents 1..16 for anisotropic filters); the tests cover 0 only with a plain filter. (2) `MinLOD > MaxLOD` is passed through. Neither is covered by the new cases. 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/3209/head:github-bot/gh-3209'
git switch 'github-bot/gh-3209'

Merge

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