fix(vk): seed_keys is filled only for RX_VK_SEED_CHECK, its one reader #393
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
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
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!393
Loading…
Reference in a new issue
No description provided.
Delete branch "madebyjordan/Longshot:fix/seed-keys-race"
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?
Type: fix · Risk: low · Tested on: Windows 11, AMD RX 6700 XT · Needs: Linux, any GPU
Why
When the shaders' preparation runs during play (
RX_VK_PREPARE_BACKGROUND), it can fill a hash set while the renderer's thread is reading it. That's a data race that can walk freed memory and crash. The set only serves a debugging switch, so now it's filled only when that switch is on.How to reproduce
Seen on: Windows 11, AMD Radeon RX 6700 XT, AMD driver 26.10.1 (Ryzen 5 5600, 16 GB)
Settings and switches:
RX_VK_PREPARE_BACKGROUND=1 RX_VK_NO_STATE_LIST=1 HOS_SKIP_OPENING=1, after an update start (another translator's prepare record kept, caches removed), a cold driver cache. With the state list on, the seed opens before the title and the race can't happen.Steps: New Game into Link's house and Kokiri Forest, headless, 480 s.
prepare_backgroundopens the seed 20 s into play while play misses programs. Count themiss_notelines in the game log after the in-play seed opens, and the ones with a+. Or runtests/test_seed_keys_race.py.Expected: Without
RX_VK_SEED_CHECK, nothing fillsseed_keysin play, so nomiss_noteline has a+and nothing races the reads.Actual: On main, the seed's keys go into
seed_keyswhile the replay's misses read it: everymiss_noteline after the in-play seed opens has a+(135, 150 and 134 of them in three runs). A rehash under a reader can walk freed buckets. The crash itself didn't fire in the runs here; it depends on timing.tests/test_seed_keys_race.pyfails on main ("seed_open fills seed_keys outside RX_VK_SEED_CHECK").What changed
seed_open()now puts the seed's keys intoseed_keysonly whenRX_VK_SEED_CHECK=1, the one switch whose code reads the set. Without it the set stays empty, so the in-play seed open no longer writes a set the renderer is reading. A new test checks this, and the switch gets a row in the switch table.seed_open()(gpu/vk/vk_shader.cpp), every seed stage's key goes intoseed_keysonly whenRX_VK_SEED_CHECK=1(read once,seed_check).seed_keys(astd::unordered_set) has one reader:miss_note, which marks the replay's program misses (the first 1,500 in play) with the stages the seed holds.prepare_backgroundinserted every key while those reads ran. A rehash under a reader can walk freed buckets.RX_VK_SEED_CHECKthe set now stays empty, andmiss_notereads an empty set that nothing writes.tests/test_seed_keys_race.py(new) readsseed_open()and checks that everyseed_keys.insertis underseed_check, and thatseed_checkisRX_VK_SEED_CHECKread once. It fails on main.tests/test_seed_reader.py, which compiles the realseed_open()against stand-ins, gets one forenv_on. Its 20,000 mutations are unchanged.docs/development.md, anRX_VK_SEED_CHECKrow; it wasn't in the switch table, only indocs/BAKE.md.Measurements
Verdict: The fix works and changes nothing else. On main every
miss_noteline after the in-play seed opens has a+(the set read while it was filled); with this PR none does (0 of 131, 144, 147). Full 480 s, no crash on both, 3 of 3. The longest frame (median 141.7 s on main, 127.5 s here) and the fps after the load (median 52.0 against 52.2) are within the runs' spread. A fix of a timing-dependent race, so the evidence for the race is the test; the game runs show the fix changes nothing else.Baseline: the numbers were measured on main
aa95d35f(2026-11-15) and this PR atc8d151de, before the rebase onto main16d87c83. The rebase was clean and didn't touch these files' changes.Hardware: Windows 11, AMD Radeon RX 6700 XT, AMD driver 26.10.1, Ryzen 5 5600, 16 GB
Scene: the path where the seed is first opened in play. An update start (another translator's prepare record kept, caches removed),
RX_VK_PREPARE_BACKGROUND=1 RX_VK_NO_STATE_LIST=1, soprepare_backgroundopens the seed 20 s into play while play misses programs. ThenHOS_SKIP_OPENING=1, New Game into Link's house and Kokiri Forest, headless, 480 s, a cold driver cache each run. With the state list on, the seed opens before the title and the race can't happen.Method:
longshot_vk.dllbuilt from each commit (RX_VK_ONLY=1 RX_RELEASE=1, llvm-mingw clang 23) into the same game folder, with alongshot.exebuilt here from mainaa95d35f(the same exe for every run), main and this PR alternated, 3 runs each, all six in one sitting. Read from the game log (miss_notelines, crash lines) andRX_VK_FRAME_LOG.How to reproduce: the scene above, with each build's
longshot_vk.dll; count themiss_notelines with a+after the in-play seed opens.aa95d35fc8d151demiss_notelines after the seed opened in play+(the set read while it was filled)The frame rate after the load climbs for a few minutes while the in-play preparation finishes, so "fps after the load"
follows how late the load ended (174-186 s on main, 162-181 s here). Minute by minute from 30 s after the load (the last
figure is the run's partial last minute), the runs match: main 32 38 52 52 41 / 32 53 55 53 46 / 40 48 54 55 43, this PR
32 49 53 54 45 / 38 48 53 55 45 / 34 45 57 54 52.
The lines name the same programs: the six runs name 145-164 programs each, and every pair shares at least 136. Programs a
run named that no run of the other build did: 0, 16 and 0 in main's runs, 0, 1 and 6 in this PR's. The race didn't visibly fire in these
six runs; it depends on timing.
The same comparison on earlier mains gave the same result: on
1be60eae(3 runs each)+on all 130, 140 and 134 of main'slines and on none of the PR's; on
5e072fc8(2 each) on 130 and 137 against 0 and 0. Full 480 s, no crash in all ten.aa95d35fc8d151detests/test_seed_keys_race.pytests/run_all.py --jobs 4The 18 fail on main on this PC and touch nothing here: test_appimage_player_build, test_cpm_discovery, test_cpp_preflight,
test_crash_dialog, test_env_on, test_lift_cleanup_error, test_linux_preflight, test_make_game_cache, test_make_game_prepare,
test_missing_nup, test_oot_state_tap, test_options_budget_once, test_portable_builder_home, test_portable_builder_startup,
test_readback_late, test_tested_configurations, test_vk_pgo, test_walk_key.
Flags and settings
No new switch.
RX_VK_SEED_CHECK(existing) now also decides whetherseed_keysis filled, and gets its row in docs/development.md.RX_VK_SEED_CHECK=1(existing)miss_note's+)seed_keysfilled on every seed open, switch or notseed_keysfilled only with the switch onTesting
Tested:
aa95d35fand this PR atc8d151de.tests/test_seed_keys_race.py.tests/test_seed_reader.pywith clang 23.python -I -B tests/run_all.py --jobs 4on mainaa95d35fand this PR atc8d151de(the table above).16d87c83, atee028d58:python -I -B tests/run_all.py --jobs 2: 200 passed, 66 failed, 355 skipped. The same 66 fail in the same run on mainbbe7a078, ten commits earlier (197 passed, 66 failed, 349 skipped; main's newer commits add tests).tests/test_seed_keys_race.pypasses. This shell had no C or C++ compiler on its path, so most compiled checks were skipped or failed for that,tests/test_seed_reader.pyamong them ("no C++ compiler 'g++'"), on main too. The 66: test_alt_enter, test_appimage_player_build, test_audio_deadline, test_audio_output_errors, test_audio_wave_buffer_release, test_bc_levels, test_bind_memo, test_capture_copy_helpers, test_collect_wide, test_dlss_actor, test_dlss_checks, test_dlss_math, test_draw_binds, test_env_file, test_fps_overlay_order, test_fps_rate, test_fps_stats, test_framegen_auto, test_framegen_gate, test_fsr3_math, test_gpu_choice, test_hd_rumble, test_import_span, test_jobs_wait_runs_queued, test_lift_cache, test_lift_cleanup_error, test_make_game_cache, test_make_game_prepare, test_menu_mouse_scroll, test_mirror_inherit, test_missing_nup, test_movie_upscale_policy, test_nvn_texture_handle, test_oot_jitter, test_options_budget_once, test_pass_hazard, test_pool_span, test_portable_builder_startup, test_present_ahead, test_present_thread, test_prof_clock, test_prompt_auto_face, test_push_state, test_quick_pipelines, test_report_words, test_rt_pool_minimum, test_rumble_mapping, test_rumble_menu, test_rumble_refresh, test_same_bind, test_same_draw, test_same_dyn, test_seed_reader, test_skip_code, test_status_line, test_submitted_page, test_table_track, test_tested_configurations, test_tex_spans_once_a_present, test_texture_layout_sizes, test_ub_gap, test_upscale_independent, test_upscale_label, test_vertex_bind, test_vk_pgo, test_wb_pages.Not tested:
static const booland anif, in code Linux already compiles.c8d151deon mainaa95d35f. The rebase onto16d87c83was clean.tests/test_seed_reader.pyafter the rebase: it passed with clang 23 atc8d151de, but the run atee028d58had no C++ compiler, so it failed there as on main.Must be tested:
RX_VK_PREPARE_BACKGROUND=1and play into Kokiri Forest, expecting a clean build and no crash (by hand: test request T-5QMM).Risks
What could break: Only the debugging marks: without
RX_VK_SEED_CHECK,miss_notereads an empty set, so its lines have no+. WithRX_VK_SEED_CHECK=1the set is filled as before, and so is the race; that's a developer switch.Turning it off: Reverting the commit gives main's behaviour.
Compatibility:
gpu/vk/vk_shader.cppis part of the translator's stamp, so every player's programs are translated once more after this lands, as with any release that touches the translator. Saves,longshot_options.iniand the vk ABI don't change.Issues
Found while measuring the in-play shader preparation (#362's shader work). No issue in the tracker is known to come from this race (searched "seed" and "crash").
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.🤖 Generated with Claude Code
WIP: fix(vk): seed_keys is filled only for RX_VK_SEED_CHECK, its one readerto fix(vk): seed_keys is filled only for RX_VK_SEED_CHECK, its one readerPushed
74e7350f:RX_VK_SEED_CHECKgets a row in docs/development.md's switch table (it was only in docs/BAKE.md), since this changes what the switch does. Docs only; no code change.74e7350f2687a2628252Rebased onto main
a00c485c(87a26282; the same three commits, no conflicts) and measured again on main1be60eae, since #400 and #59 had changed the renderer since the first runs.a00c485c) and passes here.+mark (130, 140, 134); none of this PR's did.1be60eae, not nightly-130's.1be60eaemain has changed no line ofgpu/vk/vk_shader.cpp.87a2628252c8d151ded6Rebased onto main
aa95d35f(c8d151de; the same three commits, no conflicts) and measured again there, so the Measurements now name the main the PR sits on.aa95d35f, 3 runs each alternated): everymiss_noteline after the in-play seed opened carries the+on main (135, 150, 134) and none does on this PR (0 of 131, 144, 147). All six went the full 480 s with no crash; fps after the load 52.0 on main against 52.2 here (medians), with the same climb minute by minute.tests/test_seed_keys_race.py: fails on mainaa95d35f, passes here.tests/run_all.py --jobs 4: main 503 passed, 18 failed, 72 skipped; this PR 504 passed, the same 18 failed.c8d151ded6ee028d58b7