fix(vk): the write-back diff writes only the vectors the GPU changed, so the lock-on arrows no longer go missing #2863
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2863
Loading…
Reference in a new issue
No description provided.
Delete branch "llun/Longshot:claude/issue-2079-45b3f6"
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
When you Z-target an enemy, the four arrows around it often show only two or three (sometimes fewer), and the missing ones stay missing for the whole lock-on. On
main: lock on to the Tektites on Death Mountain Trail a dozen times; about half the lock-ons lose one or two arrows.Why: the arrows are four particles of one effect, and the game writes each arrow's 256-byte record once, when the arrow is born (0, 4, 8 and 12 frames after the lock), often on a worker thread after the frame's submission was captured. The effect's own GPU pass (
15e70c016d50a89c) changes words of records 0 and 2 every frame, so its range is written back to guest memory every frame. The write-back diff's vector path wrote a subgroup's whole span when any vector of it differed, unchanged vectors with the mirror's words. On a 32-lane GPU a span is 512 bytes, two records, so spans (0,1) and (2,3) were written whole, and a late birth of record 1 or 3 went back to the effect heap's0x6f6f6f6ffill. The game never writes the record again, and the arrows' vertex program never draws a record that isn't born. The full trace is on the issue.The change: in
gpu/vk/shaders/wb_diff.comp's vector path, each invocation takes one 16-byte vector and writes it, whole, only when it differs from the shadow. A vector the GPU didn't change is never written, so a CPU write to it made after the capture stays, as the design note above the diff invk_memory.cppsays it should. Stamps (the late pages' fix), the shadow update and the observations are as they were.A first version of this PR also wrote only the changed words within a vector. It fixed the bug too, but took ~4x the write-back's GPU time (Measurements), so the vector is the unit.
Read first:
gpu/vk/shaders/wb_diff.comp, then the new pass intests/wb_diff_observations_gpu.cpp.Fixes #2079. Likely also #1803 (the same arrows, "after aiming repeatedly", since Hookshot 2.1).
Testing
Tested: Windows 11, NVIDIA RTX 5080 (driver 621.40). Death Mountain Trail, child, the Tektites:
3588ae8bwith this vector-path shader; local only), at the 60 fps cap, a dump 25 frames into each lock-on: all four arrow records present in 19 of 19 lock-ons. Onmain, 53 of 81 dumped lock-ons over eight runs had lost one or two.tests/wb_diff_observations_gpu.cpp's new pass "CPU-newer words kept" (python -I -B tests/test_wb_diff_observations_gpu.py --cxx clang++ --headers <Vulkan headers> --run): fails onmain(FAIL:238: vector 1, which the CPU wrote and the GPU didn't change, overwritten) and passes here, with the five earlier passes still passing.tests/test_late_fix_shaders.py(the SPIR-V header matches the source, with the pinned glslang 16.6.0),test_late_fix_build.py,test_msync_pass.py,test_wb_diff_stale_shadow.py,test_vulkan_fixtures_ci.py: pass.spirv-val --target-env vulkan1.3on the header: passes.mise run lintpasses.mise run test(Windows, llvm-mingw) on the first version (same files touched): 811 passed, 52 failed; the same 49 fail onmain@9b342b46on this PC, and the other three (test_audio_voice_biquad,test_audio_wave_buffer_release,test_frame_wait_bounds) were timeouts under load and pass alone.Still to test:
main, expecting no change (by hand)Measurements
Verdict: the write-back's GPU time is the same as
main's (0.154 against 0.162 ms a frame at the lock-ons), fps within the spread; the first version's word-by-word writes cost ~4x.Setup: Windows 11, RTX 5080, driver 621.40, every build on the same base (
main@9b342b46);dev.py ab's pinned options (1280x720 at 67%, uncapped, frame generation and V-Sync off),RX_VK_PASS_TIMING=1on every side, each run a timing job of the queue, interleaved. "wb copies" is the write-back's GPU time a frame, the median of the pass-timing reports in the measured stretch. This change was measured as502127270(local:3588ae8bwith this vector-path shader; the committed shader has the same rule, without an unused variable); rebased since ontoae32c0dd3with nothing in between touching the write-back.Baseline:
main@9b342b46is the baseline; this PR's first version (3588ae8b, word by word) is shown beside it because it was what this PR held before, and its cost is why the vector is the unit.Death Mountain Trail, Z-targeting the Tektites, 40 lock-ons a run (~80 s), Link at the Tektites in every run, 2 runs a side:
9b342b46Hyrule Field,
dev.py ab's scene (teleport 1, no input, ~60 s measured after ~20 s), 3 pairs, this PR against the first version:For scale,
mainthere (dev.py ab --set RX_VK_PASS_TIMING=1, an earlier pair of runs): 0.188 / 0.190 ms a frame.Risks
main's does; low-bandwidth setups (iGPUs, the Deck) are in Still to test.GL_KHR_shader_subgroup_voteline andwbd_pipe_ready's vote gate (the diff off on GPUs without compute votes) stay; dropping them is a separate change. A few comments invk_memory.cppandtests/test_late_fix_build.pystill give whole-span writes as a reason.Checklist
Ready for review
main; the title is a Conventional Commit.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.tests/that reads changed source is updated, not weakened.mainand here, for a change that shows on screen.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: Windows 11, NVIDIA RTX 5080 (driver 621.40), Death Mountain Trail (child), Z-targeting the Tektites at the 60 fps cap: 12 of 12 lock-ons with this PR's build showed their top arrow 15 frames in, where main's build lost it in about half; with a local logging build of this PR all four arrow records were present in 12 of 12 dumped lock-ons (main: 53 of 81 had lost one or two). Hyrule Field's fps unchanged within the spread (dev.py ab, 3 pairs).
The same spot on main and with this PR (Death Mountain Trail, a Tektite, 15 frames into a lock-on): main's build has lost the top arrow; this PR's draws all four.
WIP: fix(vk): the write-back diff writes only the words the GPU changed, so the lock-on arrows no longer go missingto fix(vk): the write-back diff writes only the words the GPU changed, so the lock-on arrows no longer go missingPossibly related, for context:
The write-back's GPU time, Hyrule Field. It costs more than the fps shows.
Setup: as the Measurements above (Windows 11, RTX 5080, driver 621.40; Hyrule Field, child, 1280x720 at 67%, uncapped), plus
RX_VK_PASS_TIMING=1on both sides;dev.py ab --set RX_VK_PASS_TIMING=1 --runs 2 --seconds 40. The number is thewb copiesspan (the write-back's copies and the diff pass), ms of GPU time a frame, the median of each run's later-half reports (every 600 presents).9b342b46The same 18 MB a frame takes about three times the GPU time: about 0.4 ms more a frame. This card isn't held up by it at ~165 fps, so the fps doesn't move. A GPU-bound frame, a low-bandwidth link (PCIe 3.0, an iGPU, the Deck) or AMD would pay more. The cause is the smaller writes: whole vectors written lane by lane, and partly changed vectors written word by word (up to four 4-byte stores at a 16-byte stride).
Next, already running: Death Mountain Trail with repeated lock-ons, interleaved, main against this PR against a cheaper variant that writes a changed vector whole and never word by word. The variant still fixes this bug, since each arrow's record is in vectors of its own. If it costs about what main does, I'll switch this PR to it.
A cheaper variant: same fix, no write-back cost. It's measured but not pushed: this PR still has the word-by-word version.
The variant writes a vector that differs from the shadow whole, and never word by word. A vector the GPU didn't change is still never written, so the arrows' records (each in vectors of their own) are still safe. What it gives up: if the GPU and the CPU change different words of the same 16-byte vector, the GPU's write of that vector still overwrites the CPU's word. This bug doesn't hit that case.
Setup for both tables: Windows 11, RTX 5080, driver 621.40, all three builds on the same base (
main@9b342b46): main, this PR @3588ae8b, and the variant (3588ae8bplus the variant shader, local).dev.py ab's pinned options (1280x720 at 67%, uncapped, frame generation and V-Sync off),RX_VK_PASS_TIMING=1on every side, each run a timing job of the queue, interleaved. "wb copies" is the write-back's GPU time a frame, the median of the reports in the measured stretch.Death Mountain Trail, Z-targeting the Tektites (40 lock-ons a run, ~80 s; Link at the Tektites in every run; 2 runs a side, main, PR, variant interleaved):
9b342b46Hyrule Field,
dev.py ab's scene (teleport 1, no input, ~60 s measured after ~20 s; 3 pairs, PR and variant interleaved;dev.py abcompares a checkout only against main, so this was scripted the same way):Does the variant fix the bug? A logging build of it (local only), Death Mountain Trail at the 60 fps cap, a dump 25 frames into each lock-on: all four arrow records present in 19 of 19 lock-ons. On main, 53 of 81 had lost one or two.
So the word-by-word step costs ~0.45-0.8 ms of GPU a frame and ~4-7% fps on this card. Writing a changed vector whole costs about what main does. Unless review prefers the exact per-word version, I plan to switch this PR to the variant (the shader, and the test's vector-2 case to its whole-vector rule).
4954dab012eb7d967e7ffix(vk): the write-back diff writes only the words the GPU changed, so the lock-on arrows no longer go missingto fix(vk): the write-back diff writes only the vectors the GPU changed, so the lock-on arrows no longer go missingSwitched to the cheaper version: the PR now writes a changed 16-byte vector whole, and never word by word (
eb7d967e7, rebased onto mainae32c0dd3). The description's Summary, Testing, Measurements and Risks are updated. The test's new pass now checks the vector rule: vector 1, which the CPU wrote and the GPU didn't change, keeps the CPU's words; vectors 0 and 2, which the GPU changed, are written whole. It still fails on main (FAIL:238, vector 1) and passes here.Tested in game with this head: Windows 11, RTX 5080 (driver 621.40), Death Mountain Trail (child), the Tektites at the 60 fps cap, 12 lock-ons with a screenshot 15 frames into each: every one shows its arrows, the top one every time (main loses it in about half). With the same rule's logging build: all four arrow records in 19 of 19 dumped lock-ons.
@review
Recommendation: Request changes. The reported arrow fix works in the supplied NVIDIA game runs and the fixture checks the adjacent-vector case. The shader also runs in mirror syncs, and its behavior and cost on the affected AMD and Linux systems remain unmeasured. (It stands on L2: The check
CI / Third-party parts and guide screenshots (pull_request)fails on this head and passes on the base branch: Failing after 12s.)The write-back now leaves unchanged 16-byte vectors alone, preserving later CPU writes beside GPU changes. It keeps the existing whole-vector tradeoff: a CPU word beside a GPU-changed word in the same vector can still be overwritten.
Blocking (1): must change before merging.
CI / Third-party parts and guide screenshots (pull_request)fails on this head and passes on the base branch: Failing after 12s.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/shaders/wb_diff.comp:53: The new per-vector stores affect both write-back and mirror sync on GPUs beyond the tested NVIDIA card. (more on the line) Do: Run repeated lock-ons and compare write-back and mirror-sync GPU times and frame times against main on representative affected Tier 1 AMD and Linux systems.@fixcan do L2.Checks: Still running: 7 checks.
More: does it help, other systems, switches, what was read
Does it help: Yes for the reported case on Windows RTX 5080: all four records were present in 19 of 19 lock-ons with the same shader rule, against 53 of 81 lock-ons losing records on main. On that GPU, reported write-back time was 0.150/0.158 ms per frame versus 0.155/0.169 ms on main; other affected hardware and the mirror-sync pass need measurement.
Other systems: The shader is also used for mirror syncs, where shadow and destination alias; the changed comparison still copies differing vectors correctly, but its performance is not separately reported. Stamped write-backs and observations retain their prior logic. AMD, Intel, Linux and Steam Deck game behavior and performance have not been reported.
Switches: None added, changed or removed. The existing compute subgroup-vote gate remains in place.
Reviewed:
eb7d967e7fagainstae32c0dd3c: Read AGENTS.md, CONTRIBUTING.md, the PR template, relevant standards, the full shader, fixture and fixture runner, their diffs, commits, test wrapper and the write-back and mirror-sync callers. Skimmed the generated SPIR-V diff. docs/review-checklist.md and the sibling Tooling checkout were absent; the rest of vk_memory.cpp and other generated files were not read in full.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no commands from the project, builds or tests were run. The supplied CI has one head-only failing check and several checks still running; the bot handles the failing check separately.
Overlaps and merge order: Not checked; network access is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by llun. Nothing was run; a maintainer decides.
@ -65,2 +52,2 @@if (v[k] != sv[k]) st.w[i * 4u + k] = pc.stamp;}for (uint i = gl_LocalInvocationID.x; i < c.count; i += 256u) {const uvec4 v = m.v[i], sv = s.v[i];L1 (should fix): The new per-vector stores affect both write-back and mirror sync on GPUs beyond the tested NVIDIA card.
When: On AMD RADV or Windows AMD, and on Linux NVIDIA, the two passes can have different store and memory behavior from the tested Windows NVIDIA driver; the supplied runs do not show their game behavior or cost.
Do: Run repeated lock-ons and compare write-back and mirror-sync GPU times and frame times against main on representative affected Tier 1 AMD and Linux systems.
Answers to the review (#2863 (comment)):
L2,
CI / Third-party parts and guide screenshots: main fails it too. The job'scheck_third_party.pysteps pass. Itscheck_guide_screenshots.py --review-sourcesstep fails, on three files this PR doesn't touch:Running the same command on a clean checkout of
main@ae32c0dd3(this PR's base) gives the same three lines. This PR changes onlygpu/vk/shaders/wb_diff.comp, its SPIR-V header,tests/wb_diff_observations_gpu.cppandtests/run_vulkan_fixtures.py. The settings screenshot's review hash needs a look at the UI and a new hash onmain, in a change of its own (the checker says to review before updating hashes), so I've left it out of this one.L1, the mirror sync. The same shader runs in the mirror-sync pass. Its GPU time was in the pass-timing logs of the runs above (
msync pass, the median of the reports in each measured stretch), and it doesn't change:9b342b46In a mirror sync the shadow is the destination, so a vector that differs is written whole, as before. A vector that doesn't differ was already equal in both, so skipping its write changes nothing there.
AMD (Windows and RADV), Intel and Linux NVIDIA need other hardware: asking the Test Farm below.
@Beanstalk On AMD (a Windows driver and Linux RADV), and if possible Intel Arc and Linux NVIDIA: start from the castle-gate save, teleport to Death Mountain Trail, walk up to the Tektites, and Z-target them about a dozen times. Count the arrows around the target in each lock-on: there should be four every time (main often shows two or three). Then, with RX_VK_PASS_TIMING=1 on both main and this PR, compare the 'wb copies' and 'msync pass' GPU times in the log and the frame times, during repeated lock-ons and in Hyrule Field. Expect the arrows fixed and the times about the same as main's.
Beanstalk test farm · 🔄 testing (0 of 4 reports so far)
Commit
eb7d967· approved by llun (reviewed) · dashboard⚠️ Note: The farm cannot count arrows or verify that the scripted movement reaches and locks onto a Tektite; the post-input picture is not automatically compared, so the main correctness claim remains unjudged.
⚠️ Note: The pass-timing probe replaces the prohibited timing switch, but the plan judges total GPU time rather than separate wb copies and msync pass times; the trail measurement follows, rather than overlaps, the targeting inputs.
⚠️ Note: The added GPU fixture and the frame-generation reproduction are not run by this gameplay plan.
Done (started 04:57 UTC). Comment
@Beanstalkto run it again.windows+amdlinux+radvintel+gpu-arc-*(GPU "arc *")linux+nvidiaWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)The alternative plan starts at the castle gate, attempts repeated targeting on Death Mountain Trail, and measures GPU and frame times there and in Hyrule Field for 30 seconds per place, over three starts per side. It fails on a crash, a picture regression at the stationary teleport locations, or a frame-time or total-GPU-time regression above 20% against main. The Intel Arc target waits for a matching tester. No tester online now matches intel+gpu-arc-*: that target waits for one.
castle-gate(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, frame_generation=0; switchesHOS_OUTPUT_RES=gpu,RX_VK_AUTO_TUNE=0), then teleport to Death Mountain Trail, take the picture trail-arrival to compare with main, move the stick, 12 times: press buttons, take the picture trail-after-targeting, measure trail for 30 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field-arrival to compare with main, measure field for 30 s (after 10 s warm-up); 3 runs on each side.llun referenced this pull request2026-11-30 05:09:46 +00:00