#44

Fix sky domes cut by the depth test

Opencodedpalettewants to merge intofrom

Some skies were cut by the depth test, differently in every run: coral shards in the Sky-High Sundae sky, and dark wedges with straight edges in the Wii Rainbow Road stars.

These skies are drawn on the far plane (pos.z == pos.w) after a depth pre-pass, then tested EQUAL or LEQUAL with depth writes off. On a Switch every such mesh lands on exactly 1.0. On Metal two sky meshes can differ by a few ulps, so whole triangles fail the test, and the sky behind shows through.

  • The shader translator marks vertex shaders that set pos.z and pos.w from the same register. In the 4.0.1 shader cache, 135 of about 16,000 vertex shader variants are marked.
  • The shader cache stores the mark in the writes_depth column (bit 1), so older caches still load. They have no marks, so the fix needs a Prepare.
  • Only marked draws with an EQUAL or LEQUAL test and depth writes off test LEQUAL with a depth bias of 4 ulps toward the camera. All other geometry keeps its exact depth test.
  • A bias of 0 does not fix the sky domes. A bias of 64 drew the Mute City sky over its most distant skyscrapers, which flickered as brown blotches during the course intro.

Tests

  • cargo test --workspace passes, with new tests for the far-plane check.
  • Tested on macOS (M1) with update 4.0.1: Sky-High Sundae and Wii Rainbow Road were clean in every run (3 to 5 runs each), and the Mute City intro keeps its skyline. Other tracks looked unchanged.