Shaders, GPU: clamp immediate static sampler MipLODBias to D3D12 bounds #3043
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!3043
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-26 05:10 UTC · original
fuzeofficlal:fix/static-sampler-mip-lod-bias→main· +89 −2 · 3 files · 1 commits · openProblem
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)@Marvisak on GitHub · 2026-11-26 06:17 UTC · original
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.