Skip to content

nvn/vis: draws count for occlusion queries only while a later report can see them (OoT −0.2 ms GPU a frame on an M1) - #2574

Closed
AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:occlusion-count-when-reported
Closed

AdyaGMD wants to merge 1 commit into
seedds:mainfrom
AdyaGMD:occlusion-count-when-reported

Conversation

@AdyaGMD

@AdyaGMD AdyaGMD commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

What

Once occlusion-query counting has started, every draw counts samples into the current visibility slot. NVN's samples-passed counter is a running total that a reset zeroes. So after a samples-passed reset or report, if the next samples-passed op in replay order is a reset, the draws up to it add to a total no report ever sees.

With DM_NVN_VIS_NEED (on by default; =0 counts every draw again, ab for the DM_AB phases), each samples-passed reset or report scans ahead (vis_need_scan) for the next one:

  • A reset: the draws until then don't count (visibility mode disabled, no slot).
  • A report, or nothing found (the submission's end, 20,000 ops): they count as before.

The reported values are the same. zskip_vis_dead already reasons this way for skipped draws. The scan uses its own cursor (vis_next), which steps over indirect multi-draws; fz_next stops at them because it moves work, and this scan moves none.

The per-draw counting setup moves into vis_draw_state, which task / mesh draws now call too. Before, they kept whatever mode the last ordinary draw had left.

Why

Ocarina of Time wraps nearly every scene draw in its own query (reset, draw, report: about 1,800 a frame), and the draws between a report and the next reset counted for nothing.

Performance

Ocarina of Time (0400486024DEC000), Kokiri Forest, MacBook M1 (8-core GPU), fullscreen, in a tree with other local changes. The frame is paced at 30 fps, so this measures GPU time (DM_NVN_GPUPROF "first start to last end", frames 1200–3600) in one run per row:

Run On Off
DM_NVN_VIS_NEED=ab, 300-frame phases 32.31 ms 32.53 ms
=ab:0/2 (polarity swapped), 450-frame phases 32.06 ms 32.24 ms

About −0.2 ms of GPU time a frame. Draw counts are the same with it on and off (the same objects pass their queries), and screenshots look right.

Switch (in docs/env_switches.tsv)

  • DM_NVN_VIS_NEED=0|1|ab: on by default.

Checked

  • The host compiles on this branch.

Not run

  • This branch's host in game (it was measured in another tree).
  • Any test suite.
  • iPhone.
  • Other games.

🤖 Generated with Claude Code

…can see them (Ocarina of Time -0.2 ms of GPU time a frame on an M1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) docs Documentation labels Nov 13, 2026
@dpadr

dpadr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Not doubting your results (I'd take -.2ms on my M2) but how are you testing to remove variance for a change so small? I've needed to really add a lot to the test regiment to control for variance to confirm results of -.5 @ p50. On a fan-less M1/M2 temperature alone can create a lot of variance in results.

@AdyaGMD

AdyaGMD commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Not doubting your results (I'd take -.2ms on my M2) but how are you testing to remove variance for a change so small? I've needed to really add a lot to the test regiment to control for variance to confirm results of -.5 @ p50. On a fan-less M1/M2 temperature alone can create a lot of variance in results.

NXNative has features to A/B test different configuration ever X frames

@dpadr

dpadr commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Results on a base M2 (MacBook Air, 10-core GPU, 16 GB, macOS 27.0)

Ocarina of Time, handheld 1440x810, DM_UPSCALER=metalfx, guest files on, a scripted Kokiri Forest route to frame 12000. Each run is an in-run A/B: DM_NVN_VIS_NEED=ab, DM_AB=240, each on-phase compared with its off neighbours, bootstrap 95 % intervals.

1. On main b06f4e0 (11-13), 20 clean pairs: frame p50 −11.7 ms [−24.2, −4.4], GPU p50 −3.8 ms. That main often fell into a launch-wide slow state on this Mac: the residency state #2715 removes, see #2751. Most of that gain came from inside it.

2. On main 0def324 + #2715 (DM_RES_CB=1) + a few other open PRs, 60 fps cap, 20 pairs, none dropped for load:

B − A 95 % interval
frame p50 −0.25 ms [−1.08, +0.50]
GPU p50 ±0.00 ms [−1.05, +0.58]
attachment loads −12.8 MB a frame [−18.5, +6.3]
attachment stores −5.5 MB a frame [−10.8, +5.5]
render passes −2.9 a frame [−3.8, +0.3]

Without the slow state, the effect on this Mac is within run-to-run noise. The traffic and pass counts lean the right way, but none clears its interval. That's consistent with the −0.2 ms you measured on an M1: smaller than this kind of A/B resolves on a fanless Air. No hangs and no new red lines in either test. We're keeping it in our build.

seedds added a commit that referenced this pull request Nov 16, 2026
…can see them (PR #2574)

A samples-passed reset drops the counts gathered since the last report
unread, so draws between a samples-passed report or reset and a following
reset in the same submission never reach a value the game reads. After
each samples-passed report or reset the host now looks ahead through the
submission (stepping over multi-draw records, since the scan moves no
work) and, when the next samples-passed op is a reset, encodes those draws
with visibility counting off. Reported values are unchanged.

DM_NVN_VIS_NEED=0 counts every draw as before; ab alternates with DM_AB.
t_vis_need covers reset/report sequences, a report read across
submissions, multi-draw records and called command buffers, with the
switch on and off (29 checks each).

GPU time: about -0.2 ms a frame in Ocarina of Time on an M1 (the PR's
A/B); within noise on the M4 Pro (-0.05 +/- 0.08 and +0.05 +/- 0.17 ms).
Ocarina gameplay reaches the path and draws whole; BotW regress passes
(19592/19592 shaders, 59.7 fps, no new red lines).

Co-authored-by: Adya <114347520+AdyaGMD@users.noreply.github.com>
@seedds

seedds commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks, landed as 0de2ac2 on main, redone on current main with you credited as co-author.

What changed from the PR:

  • The lookahead steps over multi-draw records (the scan moves no work), and it runs after every samples-passed report and reset; a draw counts only while the next samples-passed op in its submission is a report.
  • The nested-call fix in the scan is kept as a guard, but the case can't happen on main: the queue flattens each submission before it runs.
  • DM_NVN_VIS_NEED=0 restores the old counting; ab alternates with DM_AB.
  • New test t_vis_need (29 checks, with the switch on and off): reset/report sequences, a report read in the next submission, multi-draw records and called command buffers.

Measurements on an M4 Pro: Ocarina GPU time is unchanged within noise (−0.05 ± 0.08 and +0.05 ± 0.17 ms in the two polarities), so the −0.2 ms gain rests on your M1 numbers. Ocarina gameplay reaches the path and draws whole. BotW's regression check passes (19592/19592 shaders, 59.7 fps, no new red lines).

If you can, an A/B on your M1 with main (DM_NVN_VIS_NEED=ab DM_AB=300) would confirm the gain.

@seedds seedds closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants