Skip to content

First Light: ignore depth-clipped fragments when checking GPU draws (TEST-870) - #3967

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
inerthel-agi:fix/first-light-depth-clipping
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
inerthel-agi:fix/first-light-depth-clipping

Conversation

@inerthel-agi

Copy link
Copy Markdown

Related issue

TEST-870, claimed in the coordination thread.

Problem

First Light could reject a correct GPU draw with --keep-z or --no-fit. On aa2988cc, an overlapping triangle beyond the far clip plane supplied the expected centre UV (0.75, 0.125). The RTX actually drew the visible triangle underneath, giving (0.125, 0.75). The previous manifest made first_light.py --check exit 1.

Root cause and solution

The CPU chose the last triangle covering the pixel in XY, including portions clipped in Z. The harness disables depth testing, but Vulkan still clips primitives. For the existing passthrough vertex shader (w=1), interpolate the float32 mesh depths at the pixel centre and accept the fragment only within [0, 1]. This feeds centre UVs, texture probes and clear-corner selection. Visible triangles still win in draw order. Vulkan primitive clipping.

Tests

Windows, NVIDIA GeForce RTX 5070 Ti, driver 621.35. A synthetic passthrough vertex shader and UV-output fragment shader were assembled with tools/spirv_asm.py and run with vk_harness at 64×64. Each scene drew a background triangle, followed by an overlapping triangle with the depths below. The same raw readback was compared to each revision of uv_at. Each row covers 21 interior pixels with RGBA tolerance 0.002.

Foreground vertex depths Mismatches on aa2988cc Mismatches with this change
−0.5, −0.5, −0.5 21 0
1.5, 1.5, 1.5 21 0
−0.5, 0.5, 0.5 3 0
1.5, 0.5, 0.5 3 0
  • On a second synthetic scene the corrected manifest made python -I tools/first_light.py --check --out <fixture> --harness <vk_harness.exe> exit 0 on the same GPU, with 1,568 of 4,096 pixels covered.
  • python -I tests/test_first_light.py -v with LEONIDA_VK_HARNESS set passed 18 tests. Three tests requiring a prepared game draw were skipped. The two new methods produced five failures against the base implementation.
  • python -I tests/test_first_light_harness_paths.py passed 4 tests. python -I tests/test_first_light_bad_json.py passed 9. python -m compileall -q make_game.py tools tests and git diff --cached --check succeeded.

Compatibility and limitations

The change applies to the existing orthographic probe calculation, builds directly on main, and keeps the manifest format. Existing bundles need their manifest regenerated to pick up corrected probes. The hardware comparison used synthetic draws and sampled away from raster edges. The retail corpus and the separate perspective-camera proposal in #2855 were not tested.

AI assistance

AI-assisted with OpenAI Codex (requested model GPT-6.2 Astra), including independent GPU reproduction.

Skip clipped fragments when retained mesh depth crosses the near or far plane. Check partial triangles, visibility in draw order, and clear probes with synthetic geometry (TEST-870).
Copilot AI balanced review requested due to automatic review settings November 22, 2026 22:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@shdann

shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 98a9f7e on Windows, CPython 3.14.7, CPU only (no GPU, no game files): pass.

python -I tests/test_first_light.py gives OK with 4 skipped tests. The skipped tests need a built harness.
With tools/first_light.py from the merge base (aa2988c), 5 tests fail.

I compared uv_at at the merge base and at this head. I used 3,000 random groups of triangles with all depths in the range 0 to 1.
The results are the same in all 12,000 pixel lookups. The change has an effect only when a depth is out of the range.

I did not test a GPU draw. I found no defect. AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants