WIP: [pr-feature][rendering] Texture LOD bias for the title's samplers (DARNER_MIP_BIAS, off by default) #8

Manually merged
TrustNo1 merged 0 commits from Jesper-A/Darner:up-mip-bias into main 2026-12-03 18:36:02 +00:00
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

Re-filed from CodeFloe #345 (the CodeFloe repo is gone; nothing was migrated). Same branch and commit.

Base: the branch is on 4db98e011, the main commit it was cut from. main is now dd2f061d5. Not rebased (we rebase only if you ask). A text-only trial merge (git merge-tree --write-tree trustno1/main up-mip-bias) conflicts in crates/darner-gpu/src/host/menu.rs (the F1 menu table); README.md and streamline.rs merge cleanly.

Under DLSS the game draws a smaller picture than the display shows, so it picks texture mip levels for the small picture and textures can look soft. NVIDIA's DLSS guide asks the engine to lower the texture LOD bias to make up for it. This adds an optional bias. It is off by default, so nothing changes unless you turn it on.

  • New switch DARNER_MIP_BIAS: empty or unset = the game's own bias (the default); auto; auto-soft; or a number such as -1.5.
  • New F1 row PICTURE > TEXTURE LOD BIAS: OFF, AUTO (DLSS), AUTO SOFT, then -3.00 to +1.00 in steps of 0.25. It is a live row.
  • The offset is added to the bias the game already set. The sum is clamped to the D3D12 range.
  • auto = log2(render width / display width) - 1, NVIDIA's formula (DLSS Programming Guide 3.5: DlssMipLevelBias = NativeBias + log2(Render XResolution / Display XResolution) - 1.0 + epsilon; we use epsilon = 0). It applies only while DLSS is on; without DLSS it adds 0. At 720p to 1080p / 1440p / 2160p that is -1.585 / -2.0 / -2.585. At DLAA (ratio 1) the literal formula gives -1.0, and that is what auto does there.
  • auto-soft = log2(render/display) only, the bound the guide gives if auto flickers (-0.585 / -1.0 / -1.585).
  • Where: when the game creates a sampler descriptor (descriptor/host.rs, the View::ConsoleSampler arm), right after sampler::console. The new code is in crates/darner-gpu/src/mip_bias.rs. The render ratio comes from a new streamline::render_ratio() (two atomic loads: the last DLSS upscaling's render/output width, else the asked mode's scale). With the switch off, the cost is one atomic load per sampler.
  • Left as the game made them: comparison samplers, min/max-reduction samplers, samplers with a flat LOD range (MinLOD >= MaxLOD; samplers without a mip filter arrive flat already, because sampler::console sets MaxLOD to MinLOD when the title's mip filter is none, crates/darner-gpu/src/sampler.rs:57), and point-filtered samplers (point minification and magnification, not anisotropic).
  • Two INFO log lines: the mode (once), and one summary after 30 s or 256 samplers: a histogram of the game's own biases, and how many samplers were changed or kept, by reason. The histogram tells us whether the game already biases for its own upscaler.
  • A README table row, a docs/findings.md entry, and unit tests.

Precedents for adding a bias to the game's own: DXVK d3d11.samplerLodBias (additive, range -2..1) and OptiScaler [Mipmap] MipmapBiasOverride (additive). Intel's XeSS guide uses log2(input/target) without the -1, which matches our auto-soft. The formulas are the vendors', not ours.

Not covered in this first step:

  • Static samplers in root signatures are not touched. Their bias bits are part of the pipeline and shader cache keys, so changing them would cost a cold pipeline cache.
  • Descriptors that already exist are not rewritten. Moving the F1 row applies to samplers made from then on; the full effect comes at the next start.
  • Whether it looks better, shimmers more, or costs fps has not been tested (see below). The values are NVIDIA's, not measured by us.

Spec dependence. Likely general: the fixed offsets only change D3D12 sampler descriptors and should behave the same on any GPU. May depend on our specs: auto and auto-soft need DLSS (NVIDIA RTX); on other setups they add 0. Our expectation of the visual result comes from NVIDIA's guidance, and we only have an RTX 2070 SUPER with Series S + DLSS Performance. Untested elsewhere: other GPUs, Series X, DLSS modes other than Performance, other render sizes.

No upstream issue covers this, so there is no Fixes or Refs line.

How it was tested

  • Tested revision: 1b45773b6 (on main 4db98e011; main has moved since, now dd2f061d5, see the checklist).
  • Commands and results (build and tests; the game was not run):
    • cargo clippy --workspace --all-targets --locked -- -D warnings -A clippy::unnecessary_lazy_evaluations: exit 0. Note the extra -A clippy::unnecessary_lazy_evaluations; the gate as upstream states it, without that flag, was not run.
    • The same with --all-features, same extra flag: exit 0.
    • Targeted cargo test runs: mip_bias 6 passed; host::menu 38 passed, 1 ignored; sampler:: 5 passed.
    • cargo xtask policy: 543 ok.
    • Not yet run: cargo test -p darner-gpu in full and cargo test --workspace --locked. Results will be added here.
  • Gameplay, when relevant: not run yet. No game result exists for this change. Pending: the same scene with OFF and AUTO, shimmer in motion, fps. Planned setup: RTX 2070 SUPER 8 GB, Series S profile, DLSS Performance, GPU clocks unlocked.
  • Before and after: pending; nothing measured.
  • Shader wave sizes tested: not relevant (no shader change).
  • Coverage gaps: everything about picture and speed (see above); static samplers; live rewrite of existing descriptors; DLAA with auto (-1.0 by the literal formula, not looked at in game); any GPU other than the 2070 SUPER; the clippy gate without the -A flag. There is no CI upstream; none of this is a CI result.

Checklist

  • This PR contains one change based on main. (The branch is directly on 4db98e011; main is now at dd2f061d5; the branch stays on its base unless you ask for a rebase; a trial merge conflicts in host/menu.rs, see Base.)
  • The diff follows docs/asset-policy.md. (Text only; cargo xtask policy 543 ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found for mip/LOD bias. On 2026-12-03 this host had 3 issues and 1 pull request in total; I searched their titles and bodies for mip, LOD and bias: nothing. The one open pull request (#3, ray tracing mode in F1) changes host/menu.rs, host/panel.rs and hwrt.rs: same file menu.rs as this change's F1 row, different change. Our own other F1 rows from earlier CodeFloe PRs (depth of field, aspect ratio and others; not migrated) also edit menu.rs; the depth of field one is re-filed as branch pr4-dof. Expect small merge conflicts in the F1 menu table.

This change was made with AI assistance (Claude Code).

## Contributor role (optional) - Fluxer ID: ## What it changes Re-filed from CodeFloe #345 (the CodeFloe repo is gone; nothing was migrated). Same branch and commit. **Base:** the branch is on `4db98e011`, the `main` commit it was cut from. `main` is now `dd2f061d5`. Not rebased (we rebase only if you ask). A text-only trial merge (`git merge-tree --write-tree trustno1/main up-mip-bias`) **conflicts** in `crates/darner-gpu/src/host/menu.rs` (the F1 menu table); `README.md` and `streamline.rs` merge cleanly. Under DLSS the game draws a smaller picture than the display shows, so it picks texture mip levels for the small picture and textures can look soft. NVIDIA's DLSS guide asks the engine to lower the texture LOD bias to make up for it. This adds an optional bias. It is off by default, so nothing changes unless you turn it on. - New switch `DARNER_MIP_BIAS`: empty or unset = the game's own bias (the default); `auto`; `auto-soft`; or a number such as `-1.5`. - New F1 row PICTURE > TEXTURE LOD BIAS: OFF, AUTO (DLSS), AUTO SOFT, then -3.00 to +1.00 in steps of 0.25. It is a live row. - The offset is added to the bias the game already set. The sum is clamped to the D3D12 range. - `auto` = `log2(render width / display width) - 1`, NVIDIA's formula (DLSS Programming Guide 3.5: `DlssMipLevelBias = NativeBias + log2(Render XResolution / Display XResolution) - 1.0 + epsilon`; we use epsilon = 0). It applies only while DLSS is on; without DLSS it adds 0. At 720p to 1080p / 1440p / 2160p that is -1.585 / -2.0 / -2.585. At DLAA (ratio 1) the literal formula gives -1.0, and that is what `auto` does there. - `auto-soft` = `log2(render/display)` only, the bound the guide gives if `auto` flickers (-0.585 / -1.0 / -1.585). - Where: when the game creates a sampler descriptor (`descriptor/host.rs`, the `View::ConsoleSampler` arm), right after `sampler::console`. The new code is in `crates/darner-gpu/src/mip_bias.rs`. The render ratio comes from a new `streamline::render_ratio()` (two atomic loads: the last DLSS upscaling's render/output width, else the asked mode's scale). With the switch off, the cost is one atomic load per sampler. - Left as the game made them: comparison samplers, min/max-reduction samplers, samplers with a flat LOD range (`MinLOD >= MaxLOD`; samplers without a mip filter arrive flat already, because `sampler::console` sets `MaxLOD` to `MinLOD` when the title's mip filter is none, `crates/darner-gpu/src/sampler.rs:57`), and point-filtered samplers (point minification and magnification, not anisotropic). - Two INFO log lines: the mode (once), and one summary after 30 s or 256 samplers: a histogram of the game's own biases, and how many samplers were changed or kept, by reason. The histogram tells us whether the game already biases for its own upscaler. - A README table row, a `docs/findings.md` entry, and unit tests. Precedents for adding a bias to the game's own: DXVK `d3d11.samplerLodBias` (additive, range -2..1) and OptiScaler `[Mipmap] MipmapBiasOverride` (additive). Intel's XeSS guide uses `log2(input/target)` without the -1, which matches our `auto-soft`. The formulas are the vendors', not ours. **Not covered in this first step:** - Static samplers in root signatures are not touched. Their bias bits are part of the pipeline and shader cache keys, so changing them would cost a cold pipeline cache. - Descriptors that already exist are not rewritten. Moving the F1 row applies to samplers made from then on; the full effect comes at the next start. - Whether it looks better, shimmers more, or costs fps has not been tested (see below). The values are NVIDIA's, not measured by us. **Spec dependence.** Likely general: the fixed offsets only change D3D12 sampler descriptors and should behave the same on any GPU. May depend on our specs: `auto` and `auto-soft` need DLSS (NVIDIA RTX); on other setups they add 0. Our expectation of the visual result comes from NVIDIA's guidance, and we only have an RTX 2070 SUPER with Series S + DLSS Performance. Untested elsewhere: other GPUs, Series X, DLSS modes other than Performance, other render sizes. No upstream issue covers this, so there is no `Fixes` or `Refs` line. ## How it was tested - Tested revision: `1b45773b6` (on main `4db98e011`; main has moved since, now `dd2f061d5`, see the checklist). - Commands and results (build and tests; the game was not run): - `cargo clippy --workspace --all-targets --locked -- -D warnings -A clippy::unnecessary_lazy_evaluations`: exit 0. Note the extra `-A clippy::unnecessary_lazy_evaluations`; the gate as upstream states it, without that flag, was not run. - The same with `--all-features`, same extra flag: exit 0. - Targeted `cargo test` runs: `mip_bias` 6 passed; `host::menu` 38 passed, 1 ignored; `sampler::` 5 passed. - `cargo xtask policy`: 543 ok. - Not yet run: `cargo test -p darner-gpu` in full and `cargo test --workspace --locked`. Results will be added here. - Gameplay, when relevant: **not run yet.** No game result exists for this change. Pending: the same scene with OFF and AUTO, shimmer in motion, fps. Planned setup: RTX 2070 SUPER 8 GB, Series S profile, DLSS Performance, GPU clocks unlocked. - Before and after: pending; nothing measured. - Shader wave sizes tested: not relevant (no shader change). - Coverage gaps: everything about picture and speed (see above); static samplers; live rewrite of existing descriptors; DLAA with `auto` (-1.0 by the literal formula, not looked at in game); any GPU other than the 2070 SUPER; the clippy gate without the `-A` flag. There is no CI upstream; none of this is a CI result. ## Checklist - [x] This PR contains one change based on `main`. (The branch is directly on `4db98e011`; main is now at `dd2f061d5`; the branch stays on its base unless you ask for a rebase; a trial merge conflicts in `host/menu.rs`, see Base.) - [x] The diff follows `docs/asset-policy.md`. (Text only; `cargo xtask policy` 543 ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found for mip/LOD bias. On 2026-12-03 this host had 3 issues and 1 pull request in total; I searched their titles and bodies for mip, LOD and bias: nothing. The one open pull request (#3, ray tracing mode in F1) changes `host/menu.rs`, `host/panel.rs` and `hwrt.rs`: same file `menu.rs` as this change's F1 row, different change. Our own other F1 rows from earlier CodeFloe PRs (depth of field, aspect ratio and others; not migrated) also edit `menu.rs`; the depth of field one is re-filed as branch `pr4-dof`. Expect small merge conflicts in the F1 menu table. This change was made with AI assistance (Claude Code).
Adds an offset to the LOD bias of the samplers the title creates
(CreateSampler/CreateSamplerX). Unset keeps the descriptor as it is.
auto = NVIDIA's DLSS guide (3.5) log2(render/display) - 1 while DLSS is on,
auto-soft = log2(render/display) only, a number = that offset. Added to the
title's bias, clamped to the D3D12 range. Comparison, min/max reduction,
flat-LOD-range and point samplers are kept. Live through F1 PICTURE > TEXTURE
LOD BIAS for samplers made from then on. Static samplers and cache keys are
untouched. Two INFO log lines (mode; histogram of the title's own biases and
counts changed/kept). Not played.

This change was made with AI assistance (Claude Code).
TrustNo1 manually merged commit 15dea1b665 into main 2026-12-03 18:36:02 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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
TrustNo1/Darner!8
No description provided.