GPU: sanitize CreateSamplerX LOD range, bias clamp, and invalid enum values #474
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!474
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/474/head"
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?
@nathanbzrr on GitHub · 2026-11-24 03:50 UTC · original
nathanbzrr:fix/gpu-console-sampler-validation→main· +121 −11 · 1 files · 2 commits · merged 2026-11-25 00:11 UTCProblem
Console sampler descriptions translated in
crates/victory-gpu/src/sampler.rs(Fields::host) could pass out-of-range, non-finite, or mismatched values intoD3D12_SAMPLER_DESC:mip == 0(no mip filter),MinLOD/MaxLODused(self.min_lod, self.min_lod)without sanitizing non-finite (NaN/+/-inf) values.mip != 0,MaxLOD < MinLODand non-finite (NaN/+/-inf) LOD values were forwarded verbatim toID3D12Device::CreateSampler.MipLODBiaswas forwarded unclamped outside[D3D12_MIP_LOD_BIAS_MIN, D3D12_MIP_LOD_BIAS_MAX]([-16.0, 15.99]) and could passNaN.AddressU/AddressV/AddressWoutside1..=5andComparisonFuncwhenreduction != 1(non-comparison filters) or outside valid bounds were forwarded verbatim.What changed
address_mode(mode: u32) -> D3D12_TEXTURE_ADDRESS_MODEincrates/victory-gpu/src/sampler.rsmapping1..=5directly and falling back toD3D12_TEXTURE_ADDRESS_MODE_CLAMPfor0or values> 5.MipLODBiasto[D3D12_MIP_LOD_BIAS_MIN, D3D12_MIP_LOD_BIAS_MAX]with a0.0fallback forNaN.ComparisonFunconreduction == 1(whosecompareshelper guarantees2..=7), emittingD3D12_COMPARISON_FUNC_NEVERotherwise.min_lodviafinite_lod(self.min_lod, 0.0)(NaN->0.0, infinities clamped to[-D3D12_FLOAT32_MAX, D3D12_FLOAT32_MAX]). Whenmip == 0, kept(min_lod, min_lod)clamping behavior matchingmain; otherwise sanitizedmax_lodand clampedmax_lod = max_lod.max(min_lod).mip_none_clamps_to_min_lod_and_inverted_lod_range_clampsandbias_address_and_comparison_stay_in_host_bounds.Tests (isolated branch
e34cb53)rustfmt --edition 2024 --check crates\victory-gpu\src\sampler.rs: passed (exit 0).cargo test -p victory-gpu -- --test-threads=1: 45 passed, 0 failed, 1 ignored benchmark (includessampler::tests::console_descriptions_decode,sampler::tests::mip_none_clamps_to_min_lod_and_inverted_lod_range_clamps, andsampler::tests::bias_address_and_comparison_stay_in_host_bounds).cargo clippy -p victory-gpu --all-targets: passed (exit 0; 0 warnings incrates/victory-gpu/src/sampler.rs, 1 pre-existing warning atcrates/victory-gpu/src/host.rs:267).cargo xtask policy:asset policy: 151 files ok.No game files. AI-assisted; reviewed and verified with the tests above.
@DaviTostes on GitHub · 2026-11-24 03:56 UTC · original
Verified
e6fe8econ Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu,--test-threads=1): 45 passed, 0 failed, 1 ignored (one more passing test thanmain, presumably the new sampler case).Not covered: the title's samplers with these enum/edge combinations (no game data here).
@nathanbzrr on GitHub · 2026-11-24 06:49 UTC · original
Thanks @mercuryVM for catching the unverified
mip == 0change!Updated branch
fix/gpu-console-sampler-validationin commite34cb53to keep finite(min_lod, min_lod)whenmip == 0(matchingmain'smin_lodclamping while still sanitizingNaN/+/-infviafinite_lod), keeping the remaining hardening (MaxLOD >= MinLODwhenmip != 0,MipLODBiasclamp/NaNfallback,AddressU/V/Wfallback toCLAMP, andComparisonFuncgated onreduction == 1).Also updated the unit test (
mip_none_clamps_to_min_lod_and_inverted_lod_range_clamps) and PR description. Re-verified one34cb53:rustfmt --edition 2024 --check crates\victory-gpu\src\sampler.rs: passedcargo test -p victory-gpu -- --test-threads=1: 45 passed, 0 failed, 1 ignored (all 3sampler::tests::*pass)cargo clippy -p victory-gpu --all-targets: 0 warnings insampler.rscargo xtask policy:asset policy: 151 files ok