Skip to content

TEST-362: compare Vulkan mesh pass coverage with a CPU reference - #4770

Closed
illusionart453-max wants to merge 1 commit into
ItsNotRexed:mainfrom
illusionart453-max:test/mesh-pass-coverage
Closed

illusionart453-max wants to merge 1 commit into
ItsNotRexed:mainfrom
illusionart453-max:test/mesh-pass-coverage

Conversation

@illusionart453-max

Copy link
Copy Markdown

TEST-362 adds a CPU coverage comparator for a Vulkan mesh pass. Give it preprojected framebuffer triangles and the RGBA32F readback from vk_harness. It reports mask intersection over union and the counts of missing and extra pixels.

Claim: #4683 (comment)
Workflow discussion: #1889

Tested on Windows 11. Four CPU-only synthetic mask cases passed. A synthetic mesh and fragment shader rendered at 16 x 16 on an RTX 5060 with driver 610.88 and matched the CPU mask exactly (IoU 1.0, zero missing or extra pixels).

This draft covers the comparator. Running the translated game shader pair with its matching local drawable and descriptor bindings remains pending. No game data is included. AI-assisted (Codex).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ran this at 1fc8fc75e on Windows 11: pytest tests/test_mesh_pass_coverage.py -q -> 1 passed, 4 subtests passed; git diff --check clean.

The new tools/mesh_pass_coverage.py compares the Vulkan mesh pass coverage against a CPU reference over the same primitives; the synthetic subtests cover full coverage, partial coverage and a missing primitive. I cannot run it against a translated game mesh here. No blocking issue.

@Kev-Ball

Copy link
Copy Markdown

I found a case where the default IoU threshold flags a correct draw. On an RTX 3080 Ti (NVIDIA 620.73.04, CachyOS, subPixelPrecisionBits=8), I drew one synthetic white triangle with vk_harness into a 16×16 RGBA32F target. The framebuffer vertices were [(x,2), (13,2), (x,14)]. I passed those same coordinates to the comparator at 1fc8fc75.

x IoU Missing Extra
4.5 1.000000 0 0
4.5009765625 (4.5 + 1/1024) 0.793103 0 12
4.50390625 (4.5 + 1/256) 1.000000 0 0

The first two GPU readbacks are byte-identical. Feeding the middle readback to the comparator with the two x coordinates snapped to 4.5 restores IoU 1.0. The CPU edge test uses the full projected precision, so a subpixel displacement alone can look like a binding or projection error. This also crosses the 0.99 threshold discussed in #1889.

A regression with the middle triangle would help pin the distinction. For this device, snapping projected vertices to the nearest 1/256 pixel before the CPU edge test resolves it. If the comparator keeps full-precision inputs, documenting the rasterizer precision assumption would help users interpret missing and extra pixels. AI-assisted. Synthetic inputs only.

@editrice

Copy link
Copy Markdown

At current head 1fc8fc75, tools/mesh_pass_coverage.py:70-71 treats RGBA (-1, -1, -1, -1) as untouched. The intended input is RGBA32F from a translated fragment shader, which can legitimately write that exact color on a covered pixel. I reproduced a one-pixel case with triangle [[0,0],[2,0],[0,2]]: output (1,1,1,1) gives IoU 1.000000 / missing 0 (exit 0), while output (-1,-1,-1,-1) for the same covered pixel gives IoU 0.000000 / missing 1 (exit 1). Correct coverage is rejected solely because of fragment color. Please use a collision-free coverage signal, such as a separate mask/attachment or instrumented output, and add this boundary case. This is independent of @Kev-Ball's subpixel-precision finding. AI-assisted review; synthetic data only.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At 1fc8fc75, comparing a fully covered 512 × 512 frame uses 55,824,060 bytes of peak traced Python allocations. The RGBA32F file is 4,194,304 bytes. The comparator holds two Python sets of pixel indices and creates temporary sets for the counts.

I tested a local version that stores the CPU mask in a bytearray, reads the GPU output in 64 KiB chunks, and counts matching, missing, and extra pixels in one pass. Its peak is 1,840,999 bytes on the same frame. Both versions give IoU 1.0, zero missing, and zero extra. The local version also passes the four mask cases in the PR. These measurements cover Python allocations during comparison on Windows 11 with CPython 3.14.7.

To repeat the measurement on the PR, save the script below as bench.py and run python -I bench.py 512 from the checkout root.

import json, struct, sys, tracemalloc, runpy
from pathlib import Path
from tempfile import TemporaryDirectory
n=int(sys.argv[1])
with TemporaryDirectory() as d:
    t=Path(d,"triangles.json")
    r=Path(d,"out.raw")
    t.write_text(json.dumps([[[0,0],[n,0],[0,n]],[[n,0],[n,n],[0,n]]]))
    r.write_bytes(struct.pack("<4f",1,1,1,1)*(n*n))
    sys.argv=["tools/mesh_pass_coverage.py",str(t),str(r),str(n),str(n)]
    main=runpy.run_path(sys.argv[0])["main"]
    tracemalloc.start()
    result=main()
    print("input bytes",r.stat().st_size,"peak",tracemalloc.get_traced_memory()[1],"exit",result)

AI-assisted.

@CuteBooty

Copy link
Copy Markdown

Half-subpixel ties on Windows RTX 3070

Following the quarter-step report, I measured the exact half-step on two adjacent subpixel intervals at 1fc8fc75. The RTX 3070 reported subPixelPrecisionBits=8. All ten 16×16 synthetic triangle cases produced byte-identical RGBA32F readbacks on a second draw.

Framebuffer triangle Left endpoint of interval Covered pixels at lower grid / exact tie / upper grid Matching grid at tie
[(x,2),(13,2),(x,14)] 1152/256 58 / 58 / 46 lower
[(x,2),(13,2),(1151/256,13)] 1153/256 48 / 46 / 46 upper

For each interval, I added 0, 3/8, 1/2, 5/8 and 1 times 1/256 to the left endpoint. The 3/8 and 5/8 draws matched the lower and upper reference masks respectively. The exact ties matched the even grid coordinate in both cases on this driver. At x=4.5+1/512, mesh_pass_coverage.py reported IoU 0.793103, 0 missing and 12 extra pixels. Using x=4.5 with the very same readback gave IoU 1.000000 and zero missing or extra pixels. These two triangles distinguish always-round-up or always-round-down from the observed behavior.

Windows, RTX 3070, NVIDIA 617.14, CPython 3.14.10 and SPIRV-Tools 2026.4. Used synthetic mesh/fragment SPIR-V with vk_harness built from a4fb7f3a; all four upstream test_mesh_pass_coverage subtests also passed. Codex assisted with test design and verification.

@Idealism3937

Copy link
Copy Markdown

Picking TEST-362 up per the release in #4683. I will base a branch on 1fc8fc75 (your commit and attribution retained), fix the open findings here (editrice sentinel collision, Kev-Ball plus CuteBooty subpixel/tie precision, shdann peak memory) and add the mesh/PS acceptance slice on top. You can merge or close #4770 as you prefer; I will not edit this branch. AI-assisted.

@lunarminus

Copy link
Copy Markdown

@Idealism3937 I'm doing the TEST-362 game-drawable slice on top of the comparator: a real drawable through its translated game mesh shader on vk_harness (claim in #4683). Two questions so I depend on the right thing:

  1. Should I put Depends on: #4770 or your new branch's PR in my PR?
  2. Will rasterize() keep its signature (framebuffer triangles in, coverage mask out)? Which GPU coverage rule do you land on, after editrice's (-1,-1,-1,-1) collision? I'll use whatever you settle on rather than copy anything.

AI-assisted (Claude Code).

@illusionart453-max

Copy link
Copy Markdown
Author

Superseded by #4809, which retains the original comparator commit and attribution and adds explicit coverage-mask handling and synthetic mesh/pixel acceptance checks. I previously released TEST-362. Please continue with #4809.

lunarminus pushed a commit to lunarminus/Leonida that referenced this pull request Nov 23, 2026
Based on ItsNotRexed#4770's 1fc8fc7 by @illusionart453-max (commit retained).

- VKH_COVERAGE_MASK reads a stencil mask, so a fragment writing (-1,-1,-1,-1) is still covered; ps_coverage_clear regression.
- CPU projection snaps vertices to the 8-bit subpixel grid, ties to even; Kev-Ball 4.5009765625 and CuteBooty half-tie cases.
- Coverage and raw readbacks are streamed; CPU mask is a bytearray. 512x512 peak 591,276 bytes traced.
- ms_coverage fetches six synthetic vertices through a 4-dword V# at 0x1000 and samples an 8-dword T# at 0x100; 52x52 mask, IoU 1.0 on RTX 3060 / NVIDIA 617.14 / Vulkan 1.4.351.
- Docs describe the no-game fixture and leave the game-drawable pass chain as the coordinator's follow-up.

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.

8 participants