WIP: fix(vk): a samples-passed run with no draw reads 0, not 4096 for good (RX_VK_OCC_EMPTY) #2289
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2289
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:fix/occ-empty-run"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
With real occlusion queries on (
RX_VK_OCC_QUERIES, on wherever the device can reset queries from the CPU), the gameresets its samples-passed counter, draws an object's bounding box and reports the count. The replay writes 4096
("visible") into the report at once and the GPU's count over it once the draw's queries are done. A run in which no draw
took a query (no draw at all between the reset and the report, or only draws that render nothing: turned off by a render
condition, or rasterizer discard) never got a count, so its report stayed 4096 for good, where the console's counter reads
0: nothing passed.
It is not rare. The log line this adds counts such runs: about 83 a frame in Kokiri Forest and in Hyrule Field, about 500
a frame in the Market (RTX 4070 Ti; the line is written at the 1st, 10th, 100th ... run, read against the present count).
The report now writes 0 for such a run (
RX_VK_OCC_EMPTY, a kill switch, on). A run with a query taken (its count comesfrom the GPU), a run whose count is not known (a colour draw, or too many draws: overflow), a report with no run open,
other counters and the clear flags the CPU writes itself are as before.
The first commit also logs, once per program and value, fixed function the replay leaves out (a blend factor reading the
target's alpha on an NVN format without alpha, dual-source blend factors, an alpha test, a logic op other than COPY) and
nvnCommandBufferSetPointSizewith a size other than 1. None of these fired in Kokiri Forest, Hyrule Field or the Market,on an RTX 4070 Ti or an AMD iGPU (no X-format target appears at all), so no fix follows for them.
Read first:
NOP_REPORT_COUNTERingpu/vk/vk_replay.cpp;tests/test_occ_empty_run.py.Testing
Tested: Linux 7.0, RTX 4070 Ti (NVIDIA 595.99.02) and the AMD Ryzen 7 9800X3D's iGPU (RADV, Mesa 26.0.8):
tests/test_occ_empty_run.py(new) cuts the real report case andocc_closeout ofvk_replay.cpp: before the fix itfails for the bug's reason ("a counted run with no draw: the count word reads 4096, expected 0"); with it, it passes with
the switch unset,
=1and=0(4096 as before), and its two broken copies fail;tests/test_vk_occlusion_queries.pypasses unchanged; the whole suite: no check fails here only (the 22 failures failon
maintoo, as listed in #2290);mainagainst this branch, 30 s after arrival withRX_VK_OCC_LOG=1: the same objects on screen at each spot (only Navi and fireflies moved), draws a frame 468 / 768 /1637 on
mainand 472 / 769 / 1623 here; the reports that read 0 stay at 54-56 % on both sides;logdiffof the problemlines: nothing new;
Still to test:
mainagainst this PR, expecting noobject missing for a frame or more (by hand, or @Beanstalk with shots)
RX_VK_OCC_COPY): the same three scenes (@Beanstalk)Measurements
Verdict: the bug is gone: runs with no draw now read 0 (about 83 a frame in Kokiri Forest and Hyrule Field, about 500 in
the Market) instead of 4096; the game draws the same (draws a frame within 1 %), so no speed change is claimed.
Setup: Linux 7.0, RTX 4070 Ti, 2560x1440, the runtime's options; tools'
gamerun.py(shared mode: a correctness run, not atiming one), the kokiri-start save, the Debug tab's teleport, 30 s.
a2dc5385tests/test_occ_empty_run.pyRisks
An object whose bounding-box draws the replay leaves out for a reason the console would not would now read occluded and be
left out by the game. None is known: every draw op takes its query before it is recorded (
tests/test_vk_occlusion_queries.py),and a draw that renders nothing renders nothing on the console either.
RX_VK_OCC_EMPTY=0restores 4096; nothing changes ondisk.
Found while checking fixed-function behaviour against Rekarina's notes (another PC port of this game); the fix is our own.
Checklist
Ready for review
main; the title is a Conventional Commit. (the fixed-function log lines ride along as the committhat found this; split them off if review asks)
mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.gpu/vk/switches.def.function in nvn_native.c using its existing Interlocked helpers: Windows not built here)
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Linux 7.0, RTX 4070 Ti (NVIDIA 595.99.02): Kokiri Forest, Hyrule Field and the Market, main vs the fix, screenshots 30 s after arrival show the same objects (only Navi and fireflies moved), draws a frame within spread, no new problem log lines; the empty-run counter fired about 83 a frame (Kokiri, Field) and 500 (Market). Runs made on the original branch at main
a2dc5385; this head is the same commits cherry-picked onto current main, compiled, its checks pass, not yet run in the game.Possibly related, for context:
@review
Recommendation: Request changes. The change mixes an unrelated fixed-function census into the occlusion fix, and the new point-size logger has a data race. The fix also changes the existing occlusion dry-run mode and still needs visibility and performance checks on the systems it can affect.
Empty counted occlusion runs now report zero instead of staying visible at 4096. The game-free test exercises that result, but the added diagnostic census adds work to every recorded draw and belongs in a separate change.
Blocking (1): must change before merging.
gpu/vk/vk_draw.cpp:9401: The fixed-function census is unrelated to the empty-occlusion fix and adds work to every recorded draw, contrary to the repository's one-topic rule. (more on the line) Do: Move the fixed-function and point-size diagnostics to a separate pull request, including their helpers and reporting call.Should fix (2): not blocking, but worth doing before merging.
host/nvn_native.c:2376: The point-size logger reads and writes tell_at without synchronization between guest threads; volatile does not make those accesses atomic. (more on the line) Do: Remove this unrelated logger with the census, or protect the threshold with atomic operations or a lock and bound its multiplication.gpu/vk/vk_replay.cpp:1844: Empty runs now write zero even when RX_VK_OCC_DRY requests that reports remain at 4096. (more on the line) Do: Honor RX_VK_OCC_DRY when choosing the initial empty-run value and add a test for that combination.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/vk_replay.cpp:1844: The new zero result can hide objects if a run is classified empty when the console would count samples; the reported scenes do not cover the wall-occlusion case. (more on the line) Do: Compare base and this head in a wall-occlusion scene, and run the affected Windows and Tier 1 GPU paths, including Steam Deck and the query-copy path.gpu/vk/vk_draw.cpp:9401: The per-draw census has no frame-time or FPS comparison; draw counts do not measure its cost. (more on the line) Do: Measure interleaved base and head runs in a heavy scene, including average FPS, 1% lows and frame times, on affected systems. (@fixdoes its part first: Remove the unrelated census from this pull request.)@fixcan do L1, L2, L3 and L5.Checks: Still running: 9 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the isolated bug: the reported game-free test reads 4096 on the base and 0 with the fix. The reported game runs found the same objects in three outdoor scenes, but did not exercise the requested wall-occlusion scene or this exact head.
Other systems: The report path also serves asynchronous replay, query-copy mode and dry-run diagnostics. The author reports Linux runs on NVIDIA and an AMD iGPU; Windows, Intel Arc, Steam Deck and a wall-occlusion scene remain untested. The census runs on every recorded draw on all platforms.
Switches: RX_VK_OCC_EMPTY is added as an on-by-default kill switch and has a switches.def row; setting it to 0 restores the old empty-run result. Its default still needs the requested visibility checks across affected systems. RX_VK_OCC_DRY retains its documented default of off, but its enabled behavior changes for empty runs.
Reviewed:
b85cf3aabcagainst67ba729d21: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, the diff and commit messages, and the changed test in full. Read the changed code and surrounding occlusion, draw and logging paths; skimmed the switch table and test runner. docs/review-checklist.md and the adjacent Tooling checkout were absent. The large changed renderer and host files were not read in full; no generated files or translations changed.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The author reports the new game-free test passing and Linux game comparisons on NVIDIA and AMD; CI is still running.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -9342,6 +9398,7 @@ void draw(VkCommandBuffer cmd, NvnState& s, const DrawArgs& d) {}ps.sampled_targets |= samples;ps.written |= writes;ff_census(s, at, p); // (fixed function the replay does not carry out: logged)L1 (blocking): The fixed-function census is unrelated to the empty-occlusion fix and adds work to every recorded draw, contrary to the repository's one-topic rule.
When: Every normal draw now inspects fixed-function state, even when no empty occlusion run is involved; matching states can also take a mutex and update a set.
Do: Move the fixed-function and point-size diagnostics to a separate pull request, including their helpers and reporting call.
L5 (should fix): The per-draw census has no frame-time or FPS comparison; draw counts do not measure its cost.
When: CPU-limited scenes execute the added state checks for every draw, and matching states also increment atomics and acquire a mutex.
Do: Measure interleaved base and head runs in a heavy scene, including average FPS, 1% lows and frame times, on affected systems.
@ -1830,3 +1842,3 @@// frames in Kokiri, 4-6 with this, RX 7900 GRE). RX_VK_OCC_FIXED=<n>: that value; -1: the per-draw count as beforestatic const int64_t occ_fixed = getenv("RX_VK_OCC_FIXED") ? atoll(getenv("RX_VK_OCC_FIXED")) : 4096;const uint64_t rec[2] = {samples ? (occ_fixed >= 0 ? (uint64_t)occ_fixed : s.samples_passed) : 0, ns * 12 / 625};const uint64_t count = occ_empty_zero && empty_run ? 0 : occ_fixed >= 0 ? (uint64_t)occ_fixed : s.samples_passed;L3 (should fix): Empty runs now write zero even when RX_VK_OCC_DRY requests that reports remain at 4096.
When: With RX_VK_OCC_DRY=1 and the new switch at its default, an empty counted run immediately writes 0; the dry-mode guard in query collection cannot restore 4096 because this run has no pending query.
Do: Honor RX_VK_OCC_DRY when choosing the initial empty-run value and add a test for that combination.
L4 (should fix): The new zero result can hide objects if a run is classified empty when the console would count samples; the reported scenes do not cover the wall-occlusion case.
When: An affected bounding-box run that takes no replay query now produces 0, so the game can omit the corresponding visible object instead of keeping it visible.
Do: Compare base and this head in a wall-occlusion scene, and run the affected Windows and Tier 1 GPU paths, including Steam Deck and the query-copy path.
@ -2373,0 +2373,4 @@static volatile LONG n, tell_at = 1;if (F(0) != 1.0f) {const LONG k = InterlockedIncrement(&n);if (k == tell_at) tell_at *= 10, hos_log("nvn: SetPointSize %g (%ld so far other than 1): points are one pixel", F(0), (long)k);L2 (should fix): The point-size logger reads and writes tell_at without synchronization between guest threads; volatile does not make those accesses atomic.
When: Two threads calling SetPointSize with a non-default size can access tell_at while one updates it, causing a C data race and undefined behavior.
Do: Remove this unrelated logger with the census, or protect the threshold with atomic operations or a lock and bound its multiplication.
Closing as stale: no update here for 12 days, and none from you on any Longshot pull request for 9 days, and it no longer merges cleanly with main. Nothing is lost: the branch stays, and you can reopen this, or open a new PR on current main, when you pick it up again.
🤖 Generated with Claude Code
Pull request closed