Shaders, GPU: clamp immediate static sampler MipLODBias to D3D12 bounds #3041
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3043"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T05:10:28Z.
Problem
StaticSampler::from_wordsdecodes the hardware's 14-bit signed 6.8 fixed-pointLOD_BIASfield faithfully across[-32.0, +31.996]. Dynamic samplers incrates/victory-gpu/src/sampler.rsclampMipLODBiastoD3D12_MIP_LOD_BIAS_MIN..=D3D12_MIP_LOD_BIAS_MAX([-16.0, 15.99]), but both static-sampler conversion sites (crates/victory-gpu/src/pipeline/host.rsandcrates/victory-shader/src/emit/host.rs) copiedmip_lod_biasdirectly intoD3D12_STATIC_SAMPLER_DESC::MipLODBias.When an immediate sampler encodes a bias outside
[-16.0, 15.99](e.g.-24.0or+24.0),D3D12SerializeVersionedRootSignaturefails withE_INVALIDARGand the host pipeline is refused.Fix
StaticSampler::mip_lod_bias_for_host(&self) -> f32mirroringStaticSampler::filter_for_host, clamping to[-16.0, 15.99](and mappingNaNto0.0) while leaving the decodedmip_lod_biasfield inStaticSampler::from_wordsunchanged.mip_lod_bias_for_host()when fillingD3D12_STATIC_SAMPLER_DESCincrates/victory-gpu/src/pipeline/host.rsandcrates/victory-shader/src/emit/host.rs.Verification
cargo test --locked -p victory-shader --lib emit::sampler::(7 passed, includingmip_lod_bias_for_host_clamps_to_d3d12_bounds)cargo test --locked -p victory-gpu --lib pipeline::host::tests::on RTX 5090 and WARP (out_of_range_static_sampler_mip_lod_bias_serializes_for_hostconfirms clamped-32.0/-24.0/+24.0/+31.996serialize cleanly while unclamped-24.0is rejected byD3D12SerializeVersionedRootSignature)cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warningsrustfmt --edition 2024 --checkcargo xtask policy(191 files ok)Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T05:26:45Z.
Review: APPROVED
Verified: the console's signed 14-bit 6.8 field spans [-32, +31.996] while D3D12 static samplers accept only [-16, 15.99] — an unclamped bias makes
D3D12SerializeVersionedRootSignaturefail the whole signature.mip_lod_bias_for_hostis applied at both build sites (pipeline host + emit host), NaN maps to 0, and the host test proves D3D12 itself rejects the raw -24.0 while all four clamped values serialize.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:28:23Z.
Review: APPROVED
Tested locally merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):StaticSampler::mip_lod_bias_for_host(mappingNaNto0.0and clamping to D3D12's[-16.0, 15.99]static-sampler bounds) and using it in bothvictory-gpu/src/pipeline/host.rsandvictory-shader/src/emit/host.rscleanly preventsD3D12SerializeVersionedRootSignaturefailures for console 6.8 signed mip LOD biases outside D3D12's range.cargo test -p victory-shader emit::sampler::tests: 7 passed, 0 failed (includingmip_lod_bias_for_host_clamps_to_d3d12_bounds).cargo test -p victory-gpu pipeline::host::tests -- --test-threads=1(RTX 5090): 5 passed, 0 failed (includingout_of_range_static_sampler_mip_lod_bias_serializes_for_host).VICTORY_WARP=1 cargo test -p victory-gpu pipeline::host::tests -- --test-threads=1(WARP): 5 passed, 0 failed.cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:17:00Z.
Automated triage for the maintainers.
StaticSampler::from_words(crates/victory-shader/src/emit/sampler.rs) decodes the 14-bit signed 6.8 bias, which covers [-32, +31.996]. Both static-sampler sites,HostPipeline's root signature incrates/victory-gpu/src/pipeline/host.rsandHostincrates/victory-shader/src/emit/host.rs, passed that value toD3D12_STATIC_SAMPLER_DESC::MipLODBiaswithout clamping. Root signature serialization rejects values outside D3D12's range. The newmip_lod_bias_for_hostclamps to[-16, 15.99]and maps NaN to 0. Dynamic samplers already do the same withD3D12_MIP_LOD_BIAS_MIN/MAXincrates/victory-gpu/src/sampler.rs, so static and dynamic samplers now agree. The decoded value is still kept unclamped in the shader cache.CI:
checkpassing.A small improvement: use
D3D12_MIP_LOD_BIAS_MIN/MAXin the clamp instead of the literals, ifvictory-shadercan reach them.Generated by Claude Code
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.