Shaders: an immediate sampler's LOD bias stays in D3D12's range #327

Closed
github-bot wants to merge 1 commit from gh-pr/327/head into gh-pr/327/base
Owner

@⁠SkippySteve on GitHub · 2026-11-24 02:19 UTC · original
SkippySteve/victory-pr-own-next24 → main · +21 −2 · 1 files · 1 commits · closed without merging

An immediate sampler's LOD bias comes from bits 0-13 of sampler word 2. That field is signed 5.8 fixed point, so StaticSampler::from_words can decode any value from -32 to 31.996. D3D12 only accepts a static sampler's MipLODBias between -16 and 15.99 (D3D12_MIP_LOD_BIAS_MIN / D3D12_MIP_LOD_BIAS_MAX). A root signature that holds a static sampler outside that range is refused, and the whole pipeline is lost with it.

This change clamps the decoded bias to D3D12's range. Values already inside it come through unchanged. The module doc now says so.

Testing (Linux)

  • cargo test -p victory-shader: 58 passed, including the new lod_bias_stays_in_the_host_range. It covers 15.996, 31.996 and -32, which are clamped, and -16, 14.5 and -0.5, which are kept.
  • cargo clippy -p victory-shader --all-targets: no new warnings. The one remaining warning, constant_color never used, was already there before this change.
  • cargo fmt --check shows no diff for this file, and cargo xtask policy passes.

No game data was used; the test builds its sampler words in code.

**@⁠SkippySteve** on GitHub · 2026-11-24 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/327) `SkippySteve/victory-pr-own-next24` → `main` · +21 −2 · 1 files · 1 commits · closed without merging An immediate sampler's LOD bias comes from bits 0-13 of sampler word 2. That field is signed 5.8 fixed point, so `StaticSampler::from_words` can decode any value from -32 to 31.996. D3D12 only accepts a static sampler's `MipLODBias` between -16 and 15.99 (`D3D12_MIP_LOD_BIAS_MIN` / `D3D12_MIP_LOD_BIAS_MAX`). A root signature that holds a static sampler outside that range is refused, and the whole pipeline is lost with it. This change clamps the decoded bias to D3D12's range. Values already inside it come through unchanged. The module doc now says so. ## Testing (Linux) - `cargo test -p victory-shader`: 58 passed, including the new `lod_bias_stays_in_the_host_range`. It covers 15.996, 31.996 and -32, which are clamped, and -16, 14.5 and -0.5, which are kept. - `cargo clippy -p victory-shader --all-targets`: no new warnings. The one remaining warning, `constant_color` never used, was already there before this change. - `cargo fmt --check` shows no diff for this file, and `cargo xtask policy` passes. No game data was used; the test builds its sampler words in code.
The sampler word's LOD bias is a 14-bit signed 5.8 field, so it decodes
to anything from -32 to 31.996. D3D12 takes a static sampler's MipLODBias
only from -16 to 15.99 (D3D12_MIP_LOD_BIAS_MIN/MAX) and refuses a root
signature holding one outside that, which would lose the whole pipeline.
Clamp the decoded bias to that range; values inside it are unchanged.

The test covers both clamped ends and in-range values on either side,
and runs on every host.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:24 +00:00
github-bot closed this pull request 2026-11-26 03:59:24 +00:00
Author
Owner

@⁠SkippySteve on GitHub · 2026-11-24 02:29 UTC · original

superseded by #326 (combined shader DX/parser robustness)

**@⁠SkippySteve** on GitHub · 2026-11-24 02:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/327#issuecomment-7120197421) superseded by #326 (combined shader DX/parser robustness)

Pull request closed

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!327
No description provided.