feat(vk): split the mesh fallback's cost with a record-export stub switch (#1477 BC-0) #1531
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
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1531
Loading…
Reference in a new issue
No description provided.
Delete branch "omgitsgela/Longshot:perf/1477-bc0-fb-export-split"
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: feat · Risk: low · Tested on: Steam Deck LCD (VanGogh, RADV), desktop mode · Needs: none (the Deck arms are done; off unless a diag switch is set, a default run emits byte-identically)
TL;DR
We know the compute mesh fallback costs the Deck 6.8 ms a frame, but not how much of that is the game's own shader work versus the emulator's bookkeeping — and the answer decides which fix to build first. This PR adds a test-only switch that skips just the emulator's part (writing the vertex records) while the game's programs keep running, and measures the difference on the Deck: our share is about 1.5 ms, so the game's decode is the bigger half and the campaign re-ranks to attack it first. Both variants are compiled and validated through the real SPIR-V back end by the extended layout test.
Breakdown
RX_VK_MESH_FB_NO_EXPORT=1, that leaves the record payload unwritten while validity words and the draw's counts stay — a frame-time difference that isolates our traffic.Why
#1477 asks how much of the compute mesh fallback's cost is the game's work versus ours. The 6.8 ms a frame from the #2245 measurements cannot be spent until it is split: the guest mesh program's decode ALU, or our export traffic (shared-memory loads and the VRAM stores that hand records to the vertex stage). The split decides the order of attack — restructure our export (BC-1) or retarget the hot decode programs to native triangle pipelines (BC-2). See #1477; the ceiling and clock pairs that bound the same question from other sides are in its comments 46711 and 47445.
What changed
Both record writers fork at emit time on a new
RuntimeInfoflag, set only from the env at translation: the stub path stores each record's validity word and returns, so allocation, dispatch, and the indirect draw stay real while the payload stops. Nothing else in the frame runs differently, and the switch's name is under the program cache stamp'sRX_VK_MESHsweep, so a stubbed program is never read back by a run that did not ask for it.gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_mesh.cpp—WriteFallbackLines(soa) and the inline aos loop inMeshFallbackEpilogue: the emit-time fork, one path per module.gpu/vk/eden/shader_recompiler/runtime_info.h—mesh_fallback_no_export, documented with what it really measures (the slots hold whatever the records buffer last carried — reused across programs, header-only reset — so the picture is stale garbage and the delta folds in raster-side change; the fb spans read that back out).gpu/vk/vk_shader.cpp—mesh_fb_no_export()read once; set at the task and mesh fallback sites only; the generated vertex stage deliberately never sees it, so its translation is identical in both arms.gpu/vk/switches.def,docs/development.md— the switch's rows.tests/mesh_fallback_layout_ir.cpp+tests/test_mesh_fallback_layout.py— every shape and layout also emits anoexporttwin: it must compile, pass spirv-val (spv1.6 and vulkan1.3), and lose the payload export's shared-memory loads versus its full twin (store count alone cannot see it — one aosOpStoreserved both kinds). 48 modules validated, was 36. This test caught theOpIAddarity bug a Deck build had just hit; that failure mode is local now.Measurements
Verdict: the instrument works and answers the question — our export traffic is ~1.5 ms of the fallback's 6.8 ms; the game's decode (~5.3 ms) is the bulk, which re-ranks #1477 to BC-2 first.
Hardware: Steam Deck LCD, AMD Custom GPU 0405 (RADV VANGOGH), Mesa of that stack, Zen 2 4C/8T, 16 GB shared.
Scene: Hyrule Field (child save copy, slot 05), 1280x800 output, render resolution 4 (50%), shadows 1, quality preset, vsync off, no fps cap (
HOS_FPS_MAX=1000).Method: A B B A on ONE build (
rt-rc6-bc0, this PR's tree): default, stub, default, stub; the scripted route (warm 1200 presents, walks, pans, full-stick turns, circle) twice per arm; medians of per-frameframe-times.csv; 10 Hz busy+sclk sampler; env confirmed per arm from the switches-set log line.Baseline: both columns are this PR's build with the switch unset vs set — main is not the comparison because both arms must share one binary for the difference to isolate the switch.
How to reproduce: the Deck LCD, the copied Hyrule Field save,
~/longshot-investigation/mesh2245-arm3.shroute withRX_VK_MESH_SHADERS=compute, thenRX_VK_MESH_FB_NO_EXPORT=1for the stub arm; rowsdocs/tested/2026-11-17-bc0-export-stub-warm-omgitsgela-run15.md(with run14 ceiling and run16 clock pair bounding the same question).c7f339a6, switch unset (e1/e3)c7f339a6(e2/e4)Flags and settings
This PR adds one switch, shipped off as written.
RX_VK_MESH_FB_NO_EXPORT=1Testing
Tested: Steam Deck LCD desktop mode, this exact build (
rt-rc6-bc0, so=20578111): four full scripted route runs (A B B A), no crash, no amdgpu kernel lines, fallback draws still executing (frame times move exactly the export's share, and the stub arms' game log shows the programs running); switch effect confirmed per arm via theswitches setlog line. Game-free:tests/test_mesh_fallback_layout.py62 cases 0 failed with 48 modules spirv-val clean including the stub twins (VM toolchain, NDK spirv-val);tests/test_mesh_fallback*.py,tests/test_switch_table.py(my row passes; the table's pre-existing main failures named below), stamp tests, and the fulltests/run_all.pysuite (this tree 602/37/126; every failure shared with a same-day clean-main run). A delegated review independently compiled the back end, validated both forks, and verified the cache-stamp isolation with line cites (#1477 comment 46725).Not tested: Windows/other GPUs for the stub arms (it is a measurement switch; the emitted variants are validated tool-side for every fallback shape); no other titles measured with it yet.
Must be tested: Windows, llvm-mingw cross-compile (I have no Windows toolchain on this host): the
build-windows.ymljob on this PR (by hand: read the check on the PR page), expecting the Windows build green for this branch'semit_spirv_mesh.cpp,runtime_info.handvk_shader.cpp, since all three compile on Windows too. Nothing else: the default path is unchanged by construction (byte-identical emit, reviewer-verified), and the Deck ran the switch both ways.Risks
What could break: nothing for a normal run — the forks are only emitted when the flag is set at translation, the vertex stage never sees it, and the cache stamp keeps stubbed programs out of unstubbed runs. Worst realistic case: someone sets the switch in a normal run and sees garbage; the switch row, the docs row and the log line all say it is a measurement build.
Turning it off: unset the variable (it is never on by default; the program cache re-keys automatically).
Compatibility: Nothing changes for a player: no save, ini, ABI or tool change; the new switch's name is hashed into the program-cache stamp only when set, so caches behave exactly as with any
RX_VK_MESH*switch.Issues
See #1477 (this is BC-0 of the campaign plan; results posted there as comments 46711, 46725, 47400, 47445).
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pyon the merged head (main @9af4808fmerged in): 606 passed / 36 failed / 126 skipped — all 36 also fail on that main itself (run individually at9af4808f: exit 1; none caused by this PR; listed here: bug_report_defaults, cpu_report, crt_options, damage_debug_menu, dev_packs, discover, display_startup_failure, dlss_feature_size, failed_compile_keeps_objects, guest_imported, hud_layout_row, invalidate_quick, invalidate_vcore, libc_hooks, lift_lookups, link_skip, linux_pressure, linux_update, log_open_failure, mirror_budget, missing_nup, mods_size_table, pending_guest_import, pipeline_play_cache, present_thread, profiling_mode, psychov35_fsr3_fg, readback_timeout_source, run_all_changed, slow_frames, switch_table, target_image_pool, upscaler_rows, vcore_escape, walk, walk_key). Before the merge: this branch @920899c2was 602/37/126 against main @ 347aa6e8's 599/40/126, same story.third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.docs/tested/for each new measured run (format indocs/tested-configurations.md).tests/that reads changed source updated in this PR, not weakened.Tested in game: Steam Deck LCD (VanGogh, RADV, Mesa 26.1.2), desktop mode, this exact build (rt-rc6-bc0, so=20578111): the scripted Hyrule Field route run four times A B B A (default, stub, default, stub). Defaults: normal play, unchanged (steady pair median 30.9 fps, matching the pre-PR arms). Stub switch set: the programs still run and frames move by the export's ~1.5 ms; the picture is stale garbage exactly as documented; no crash, no amdgpu kernel lines, no hang.
WIP: feat(vk): split the mesh fallback's cost with a record-export stub switch (#1477 BC-0)to feat(vk): split the mesh fallback's cost with a record-export stub switch (#1477 BC-0)Read for a Steam Deck OLED run of this (head
1ec4bac6f, built as main @9af4808fplus exactly this PR; onlylongshot_vk.sodiffers from that main; the PR'stest_mesh_fallback_layout.pygives 62 cases, 48 modulesspirv-valclean here too, and the 8 failures of the changed set all fail on that main). The arms are queued behind tonight's runs; three things from reading it that may be useful before then.A possible over-count in what the stub measures. With
RX_VK_MESH_FB_NO_EXPORT=1the export's loads of the workgroup attributes are gone, so the guest's stores into that workgroup memory become write-only. If ACO then drops those stores, and with them the guest arithmetic that only fed them, the stub removes part of the game's decode as well, and the "export" share (about 1.5 of 6.8 ms) would be too large and the decode share (about 5.3) too small. The layout test pins that the loads are gone in the SPIR-V; nothing pins what the driver keeps after that. One way to settle it without a GPU timer: compare the two arms' compiled sizes for the hot programs (RADV_DEBUG=shaderstats, or the instruction counts from the driver's shader dump) for739acd678ae08655andd905f52b7517c681. If the stub arm's code shrinks by much more than the export's own loads and stores, decode went with it. A stub that keeps the loads and drops only the record stores (or writes the loaded values to one dummy word) would bound it from the other side. I will run the shaderstats comparison on the OLED with the arms.The keyed
fb mesh prog <key>rows are not in this PR. They come from #1460's measurement commit (46973fff6), which neither this branch nor main carries, and the "fb span rows:" canary line is in neither tree. So a tester building main plus this PR gets frame-time deltas only, which fold in the raster and fragment change of the stale draws, as your own wording says. For the compute-only number I built a second renderer with46973fff6on top (it applies clean and touches onlyvk_draw.cpp, so it shares this PR's caches); its numbers will be labelled as that, not as this PR's. It may be worth carrying that commit here, or landing it first, so the instrument and the spans that read it travel together.Cost to testers and players, for the description: every
RX_VK_MESH*entry is hashed into the translator stamp, so default and=1are two stamps and each arm needs its own shader preparation on a Deck (tens of minutes cold); and the PR changes stamped files, so every player's caches retranslate once after it lands even with the switch unset. Neither is a defect; both are worth a line.Nothing in the diff looks able to harm a Deck beyond wrong pictures while the switch is on: reads stay clamped inside the records, no buffer changes size, and it is never a default.
The check from point 1 above, run on a Steam Deck OLED (RADV, Mesa 26.2.0-devel): no sign that the driver drops the guest decode in the stub arm. The stub removes memory traffic, not computation, so the export share is not inflated that way.
Method: main @
9af4808fplus exactly this PR, both arms prepared cold withRADV_DEBUG=shaderstats(default first; the stub arm seeded from the default arm's driver cache, so it compiled only the 1,039 compute pipelines the switch changes, and its statistics are exactly the stubbed fallback programs). The statistics carry no program key, so the two largest twins were paired by shape (8 KB of LDS, 256 VGPRs, about 2,040 branches each, far above every other compute shader): most likely739acd678ae08655andd905f52b7517c681, but that pairing is inferred, not keyed.Stub against default, for those two programs:
Had the decode gone with the loads, VALU, SALU and branches would have fallen by thousands; they did not. What goes is memory instructions, more than the export's own loads and stores account for, which reads as spill and clause traffic around the export relieved when its live values are gone. So the stub's number includes that register-pressure relief as well as the record traffic itself: still "what the export costs the program", but a restructured export (as in #1561) keeps those values live and may recover less than the stub suggests, which fits packed4's roughly 1 ms against the stub's 1.5.
Limits: these are static counts from the compiler, which cannot say how often any instruction runs; the keyed
fb mesh progspans (default against stub, on the renderer with the span commit) remain the number to quote, and are queued here behind the packed-layout arms. Both preparations completed and both arms start; no timed arm has run yet.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.