#45

Apply the game's texture LOD bias in fragment shaders

Opencodedpalettewants to merge intofrom

Follow-up to #22, which set MTLSamplerDescriptor.lodBias from the game's sampler bias (builder +0x24). That property has no effect on Apple7 GPUs such as the M1, so #22 did not fix the blurry line in front of the kart there.

In a standalone Metal test on an M1, a sampler with lodBias of -2, -1 or +2 picked the same mip level as a sampler without it, while bias(-2) in the shader picked level 0. A build with #22 and a build without it rendered the same. Besides the blur line, the lost bias also showed as black dashes between the planks of Dragon Driftway.

  • Res carries each fragment texture's bias in a new lod_bias[32] array at its end.
  • Fragment shaders add it to implicit-LOD samples: bias(res.lod_bias[b]), or added to the shader's own bias.
  • The sampler no longer sets lodBias, so GPUs that honor it do not apply the bias twice.
  • Shaders precompiled by older builds keep working, without the bias, until the next Prepare.

This PR and #32 merge cleanly in either order. A follow-up adds #32's texture LOD bias setting on top of this per-texture bias.

Tests

  • cargo test --workspace passes.
  • Tested on macOS (M1) with update 4.0.1: Dragon Driftway shows sharp plank grain without the dashes, and the blur line in front of the kart is gone there and on the other tracks I tried.