GPU: sanitize plain D3D12 sampler descriptions before CreateSampler #3209
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3209
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3209"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@fuzeofficlal on GitHub · 2026-11-26 12:48 UTC · original
fuzeofficlal:fix/gpu-sanitize-sampler-desc→main· +226 −0 · 2 files · 1 commits · openSummary
CreateSamplerX(View::ConsoleSampler) already sanitizes all sampler fields insampler::console, but plainCreateSampler(View::Sampler) indescriptor::host::makepreviously forwarded raw title[u32; 13]words straight toID3D12Device::CreateSampler.Because
CreateSamplerreturnsvoid, an invalid filter enum, address mode, anisotropy count (> 16), comparison function, out-of-range/NaNMipLODBias, or NaNMinLOD/MaxLODpermanently 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:pub(crate) fn sanitize(desc: D3D12_SAMPLER_DESC, aniso_point_mip: bool) -> D3D12_SAMPLER_DESC, reusing the module's existingaddress_modeandfinite_lodhelpers:Filteragainst D3D12's 40 legal filter encodings (reduction <= 3with standard min/mag/mip bits or anisotropic0x54/0x55), downgrades anisotropic point-mip (0x54) to0x55when the host lacksAnisoFilterWithPointMipSupported, and falls back toD3D12_FILTER_MIN_MAG_MIP_LINEARfor unrecognized values.AddressU/V/W(1..=5, fallbackCLAMP), clampsMaxAnisotropyto0..=16, validatesComparisonFunc(1..=8, fallbackNEVER), clampsMipLODBiasto[D3D12_MIP_LOD_BIAS_MIN, D3D12_MIP_LOD_BIAS_MAX](NaN -> 0.0), and sanitizesMinLOD/MaxLODviafinite_lod.plain_sampler_sanitization_preserves_valid_and_clamps_invalid.crates/victory-gpu/src/descriptor/host.rs:crate::sampler::sanitize(desc, crate::sampler::aniso_point_mip(device))inView::Samplerbefore callingdevice.CreateSampler(&desc, at).plain_sampler_descriptions_are_sanitized_before_host_creationcovering 16 invalid sampler cases and 5 valid boundary cases throughcreate_sampler,HostHeap::mirror, andHostHeap::make_at.Verification
main(63bcca43) —CreateSamplerpermanently removed the device withDXGI_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 zeroCreateSamplerdebug errors.cargo test -p victory-gpu --libpassed 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, andcargo run --locked -p xtask -- policyall passed.@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 (includingplain_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).
@oni-swr on GitHub · 2026-11-26 13:25 UTC · original
WARP test report (head
8b27f29, on top of current main63bcca4)Environment: Windows 11, WARP only (
VICTORY_D3D12_WARP=1with--features diagnostics, which the GPU crate needs to honour it; plusVICTORY_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 newdescriptor::host::tests::plain_sampler_descriptions_are_sanitized_before_host_creationandsampler::tests::plain_sampler_sanitization_preserves_valid_and_clamps_invalid.sanitizecall): 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 insampler.rscallssanitizeitself, so it cannot compile on main.)Diff review: no blocking problem. Two small notes: (1)
MaxAnisotropyis only capped at 16, soMaxAnisotropy == 0with an anisotropic filter still reachesCreateSampler(D3D12 documents 1..16 for anisotropic filters); the tests cover 0 only with a plain filter. (2)MinLOD > MaxLODis 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.