fix(vk): AMD's Windows driver on GCN keeps the mesh fallback's warp in workgroup memory, off the 64-lane subgroup emulation #2158
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
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2158
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:fix/gcn-mesh-shared-warp"
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
GCN cards (RX 400/500, Vega) have no mesh shaders, so the game's task and mesh programs run as compute shaders: the mesh
fallback. NVN wrote those programs for 32-lane warps. RDNA, NVIDIA and Intel hold a compute stage to 32 lanes, so the
fallback's warp is the hardware's. GCN can't: its subgroups are 64 lanes and nothing else. The reporters' logs show
lanes 64 to 64 (32 on stages 0)andwarp64=1. So on GCN every fallback stage with a ballot, vote or shuffle takes the translator's64-lane emulation of the 32-lane warp.
On AMD's Windows driver that is slow to compile. An RX 580 2048SP (#1204) and a Radeon Pro 580 (#1836), both on driver
24.9.1, compiled each fallback stage in 53 to 310 s: 24 such lines in #1204's v3.0.0 log, and two stages the driver
faulted on. The draws of a stage still compiling are left out (
fallback draw of ... left out: its compute pipelines are still compiling). Players see geometry loading slowly, grass vanishing for a moment, and freezes in Kokiri Forest. They alsoreport foliage, hair, Link and text drawn as specks (#1204, #717 on 26.1.1, #1836).
This PR gives AMD's Windows driver on those GPUs the shared warp Mesa's Intel driver already uses (
mma_layout.hmesh_fallback_shared_warp). A fallback stage the planner takes (32 invocations, no warp operation in a loop or after anearly return) runs its ballots, votes and shuffles through workgroup memory. Its SPIR-V then has no subgroup instruction, and
it gives the same answers at any lane count.
RADV is left as it is. On the lab's RX 580 (Mesa 26.2.6)
maincompiles the fallback in seconds and draws it right. Theshared warp gave the same answers and fps there, so it would only cost a GCN RADV player one retranslation of the fallback.
gpu/vk/device_policy.h: a new field,mesh_shared_warp. It is on for Mesa's Intel driver, as before. It is also on forAMD's proprietary driver on Windows on a GPU whose
subgroup_max > 32and whosesg32_stageslacks compute: GCN,Polaris and Vega. The policy block logs
mesh_shared_warp_default;coopmat_initalso logs the effectivemesh_shared_warpafter the switch is applied.gpu/vk/vk_coopmat.cpp:coopmat_inittakes the shared warp from the policy throughshared_warp_wanted.RX_VK_MESH_SHARED_WARPstill forces it on (1) or off (0) on any GPU; unset or empty means the default. The pagesand global-attributes switches keep
mesh_pages_wanted, Intel's Mesa driver only.fallback programs once after updating. Every other PC keeps its program cache.
switches.def; a paragraph indocs/dev/reference/architecture.mdon the fallback's warp.Since this branch began,
maingainedmesh_fallback_strict_fmul(RX_VK_MESH_STRICT_FMUL). It is on wherevernan_bitsis, so the reporters' Polaris cards on 24.9.1 get it too. It targets white flashes on grass in the fallback on AMD's older
Windows compiler. The specks may be that bug rather than this one. The Beanstalk run compares this PR against a
mainthatalready has it.
Read first:
device_policy.h(mesh_shared_warp, its rule besidewarp64),vk_coopmat.cpp(shared_warp_wanted,coopmat_init).See #1204
See #1836
See #717
Testing
Tested: Linux, RTX 3090, NVIDIA 620.70.06, this PR @
d02b0fc7as a pack, through the job queue: a memory tour fromkokiri-startthrough Kokiri Forest, Hyrule Field and the Market, in play, no crash,mesh_shared_warp=0in the policy block (no change on NVIDIA); and the same withRX_VK_FORCE_MESH_FALLBACK=1 RX_VK_MESH_SHARED_WARP=1 RX_VK_MESH_SHARED_WARP_CHECK=1:the shared warp's check: 1935858527 answers compared with the subgroup's so far, 0 different; 0 waits gave up.Also Linux, RX 580 8 GB (Polaris10, RADV, Mesa 26.2.6), the AMD lab PC. Kokiri Forest, Hyrule Field and the Castle
Town Market each time, with screenshots.
main: no specks, no freezes, no slow fallback compiles. The reports don't reproduce on RADV.mainwithRX_VK_MESH_SHARED_WARP=1 RX_VK_MESH_SHARED_WARP_CHECK=1: the shared warp's answers matched the 64-lanesubgroup's every time (0 different over billions compared), and no wait for other lanes gave up. On RADV the 64-lane
emulation gives right answers, and the forced shared-warp path is correct.
main. It alsoretranslated the fallback once, about 200 compiles of 1.1-2.7 s landing in play, for no gain shown. So the default now
leaves RADV alone. On this head, RADV GCN gets
main's path by default (mesh_shared_warp=0).Checks: the new and changed checks were written but not run on this PC; CI runs them.
device_policy.hpassesg++ -std=c++20 -fsyntax-only -Wall -Wextrain a small translation unit.tests/test_gcn_mesh_shared_warp.py(new, its own commit before the fix) cuts whatcoopmat_initsetsmesh_fallback_shared_warpto, with the functions it calls, and runs it against the realdevice_policy()on 17 PCs andswitch settings.
driver, and Iris Xe on Mesa.
driver, an RX 6800 XT on RADV, an RTX 3090 and llvmpipe.
RX_VK_MESH_SHARED_WARP=1on RADV GCN, plus=0,=offand empty, all over the default.mesh_shared_warp_default=.mainit should fail on the Windows GCN cases:mesh_pages_wantedgives AMD the subgroup's warp, and the block hasno such default field.
tests/test_device_policy.py:mesh_shared_warpinBOOLS, on only for the Iris Xe row. No row in its table is GCN onAMD's Windows driver.
tests/test_mesh_fallback_shared_warp.py: the switch check now cutsshared_warp_wanted, the policy's default with theswitch over it.
Still to test:
mesh_shared_warp=0in the policy block, nowarps in workgroup memoryline, no retranslation at start, and fps withinnoise of
main(by hand).mainagainst this PR. Look at the fallback compile times, the specks and thefreezes (@Beanstalk, request below).
Measurements
Verdict: no change on RADV GCN by default; the PC it targets (Windows GCN) is not measured yet.
Setup: Linux, RX 580 8 GB (RADV, Mesa 26.2.6), Kokiri Forest, Hyrule Field and the Market. Screenshots in the lab's run
folders (not attached: game frames). Windows Polaris and Vega to come from Beanstalk.
Risks
What could break: GCN on AMD's Windows driver only (RX 400/500 and Vega). The shared warp's waits spin on workgroup
memory. They have run on Mesa's Intel compiler and on RADV (the lab, forced), not yet on AMD's Windows compiler. A wait that
gives up is counted and logged (
the mesh fallback's shared warp: N waits for other lanes gave up), and the answer after itmay be wrong. The workgroup-memory form could also compile or run slower there. Beanstalk measures both.
Turning it off:
RX_VK_MESH_SHARED_WARP=0gives the subgroup's warp, as onmain. Reverting the commit is enough.After updating: on a GCN PC with AMD's Windows driver the fallback's programs are translated and compiled again once,
because the translator's stamp changes there. Every other PC keeps its caches. Nothing changes in saves or
longshot_options.ini.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (not run on this PC; CI runs it)main, or Measurements says why there is nothing to measure. (RADV measured; Windows GCN waitson Beanstalk)
third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (two commits, test first; not run either way here,CI runs it)
gpu/vk/switches.def.(RADV was measured and left off; the Windows GCN default waits on Beanstalk)
tests/that reads changed source is updated, not weakened.mainand here, for a change that shows on screen. (RADV taken, the same bydefault; Windows from Beanstalk)
Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Beanstalk request (post as a comment on the PR once it is open):
@Beanstalk On Windows with AMD's own driver, on an AMD Polaris card (RX 470/480/570/580/590 or Radeon Pro 580) and, if the
farm has one, a Vega card (RX Vega 56/64 or a Ryzen APU with Vega graphics): compare
mainwith this PR, withRX_VK_COMPUTE_LOG_MS=1000set in both. Clear the game's shader caches first, or start both from the same cold state.Load a save in Kokiri Forest, then go to Hyrule Field and the Market. Spend 60 s or more in each, moving the camera through
grass and trees.
For each run, send:
vk: compute pipeline of ... (mesh fallback): the driver compiled it in N sline and anywaits for other lanes gave upline;mesh_shared_warplog line, which should showmesh_shared_warp=1on this PR;🤖 Generated with Claude Code
Tested in game: Linux, RTX 3090, NVIDIA 620.70.06, through the job queue: memory tour Kokiri/Hyrule Field/Market, in play, no crash, mesh_shared_warp=0 (unchanged on NVIDIA); forced shared warp with its check: 1.9 billion answers compared, 0 different, 0 waits gave up. Lab RX 580 (RADV): default unchanged, forced path correct, fps within noise. AMD Windows GCN needs the Test Farm.
@Beanstalk On Windows with AMD's own driver, on an AMD Polaris card (RX 470/480/570/580/590 or Radeon Pro 580) and, if the
farm has one, a Vega card (RX Vega 56/64 or a Ryzen APU with Vega graphics): compare
mainwith this PR, withRX_VK_COMPUTE_LOG_MS=1000set in both. Clear the game's shader caches first, or start both from the same cold state.Load a save in Kokiri Forest, then go to Hyrule Field and the Market. Spend 60 s or more in each, moving the camera through
grass and trees.
Beanstalk test farm
Commit
c890df3· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Read of
d02b0fc7(based76d202f; current main isa2dc5385, 32 commits ahead — WIP, no rebase). The gate and the plan read right to me, and the test is real. The one thing that can settle the PR is a Windows AMD GCN run with cleared caches, and that run is not available as asked — so I stop at the code findings and tick nothing.1. The claim needs the hardware, and the farm declined it. The farm's sticky (23:26) says it can't test this as asked: its controlled cold-cache scenarios run on Linux only, so it cannot establish the "clear the game's shader caches first" condition on Windows, and there is no Vega card online. Its alternative compares main and the PR on a Windows Polaris but cannot control the caches — which is exactly the variable the 53-310 s compile claim depends on. Until a human with a Polaris or Vega on AMD's Windows driver runs the cleared-cache A/B (or the reporters in #1204/#1836 do), the compile-time, speck and freeze claim is unverified. From code I can confirm the gate and the planner, not the compiler.
2. The handshake is relaxed atomics only. Every cross-lane word is
OpAtomicOr/OpAtomicExchange/OpAtomicLoadwithSemantics = 0(Relaxed), Scope Workgroup, and there is noOpControlBarrierbetween a lane's data and its arrival bit or around the wait (emit_spirv_warp.cpp:175-183, 209-219; the wait inspirv_emit_context.cpp:2510-2535). The reader sees the flag with a relaxed load, then reads the data word with another; formally nothing orders the data behind the flag, and the Vulkan memory model does not promise it. It has held on Intel Mesa and on RADV with the check on (billions of answers, 0 different), so it is the practical behaviour of workgroup atomics there — but AMD's Windows compiler is the first where it is unproven, and the whole PR is about that compiler. The check run (RX_VK_MESH_SHARED_WARP_CHECK=1, comparing against the subgroup's answer and counting given-up waits) is the right evidence; if any difference or give-up appears, the fix is a release on the flagOpAtomicOrand an acquire on the wait'sOpAtomicLoad(or a workgroup barrier), not a switch.3. The policy line reports the default, not what the PC got, when the switch overrides it.
mesh_shared_warpis not indevice_policy_env(noflag(Sw::mesh_shared_warp, "RX_VK_MESH_SHARED_WARP", …)), sop.mesh_shared_warpstays the driver/arch default and thevk: policy: can and measured:line prints that (device_policy.h:863-866), whileshared_warp_wanted(vk_coopmat.cpp:673-675) applies the switch at the site. On a GCN Windows PC withRX_VK_MESH_SHARED_WARP=0the policy block still saysmesh_shared_warp=1, and the*"a switch set this" mark never appears; the body says the line "says what the PC got", which is only true with the switch unset. The new test checks the line only for the unset cases (tests/test_gcn_mesh_shared_warp.py), so this is untested. Cleanest: put the switch indevice_policy_envso the field is the effective value and the*marks it; otherwise the row/report should say the policy line is the default and thevk: the mesh fallback's warps in workgroup memoryline is the effective one.4. The switch's empty value now means the default. On main
mesh_pages_wantedread the env as set-or-not, soRX_VK_MESH_SHARED_WARP=(empty) was off;shared_warp_wantedtreats empty as unset, so on Intel Mesa and GCN Windows an empty value now turns the shared warp on. That matchesdevice_policy_env's own rule ("unset or empty: the default",device_policy.h:708-712) but notenv_on_or's (longshot_env.h:57-60), and the row now says "unset or empty the default" (switches.def:525), so it is deliberate and documented — just worth a sentence in the PR that it differs from main's empty behaviour, since a launcher that writes an empty line to clear a switch will now get the new path on these PCs. The test'sRX_VK_MESH_SHARED_WARP empty (the default)case codifies it.5. The rest of the code review.
f.windows && AMD_PROPRIETARY && f.subgroup_max > 32 && !(f.sg32_stages & COMPUTE)is the right shape — GCN is 64-lane only with no 32-lane stage, RDNA holds compute at 32 (0x20/0xFFin the test's facts) and stays off, Intel Mesa keeps its old clause, NVIDIA/llvmpipe off. It is a policy value from driver facts; the test's Polaris facts come from the reporters' logs, which is the best possible without the card.f.windowsalso leaves AMD's proprietary Linux driver (AMDVLK) GCN on the subgroup, untested but the status quo, with no report either way. The row says "off elsewhere (RADV included)".spirv_emit_context.cpp:2397-2486);warp_word_countiswords + 2 × regionsandWarpTakethrows if the emitter ever asks for more, so no out-of-bounds word; the Workgroup array is a plainU32[n](noArrayStride), and the wait is bounded at 65536 reads with a give-up counted (emit_spirv.h:80-85).RX_VK_MESH_SHARED_WARP_CHECKon, the stage still emits the subgroup's answer to compare against ("the stage keeps its subgroup instructions",mma_layout.h), so on GCN Windows the slow 64-lane emulation is still compiled. The farm's compile-time/speck run must be without the check; the answers check is a second run.coopmat_initright-hand side anddevice_policy()and covers 17 PCs and the switch both ways, failing on main;test_mesh_fallback_shared_warp.pykeeps the SPIR-V/planner shape checks.test_device_policy.pyadds the field but has no GCN-on-Windows row, so only the new test guards the new default. Neither, of course, can replace the card.No approval, and no claim on it; the checklist's hardware boxes are the ones I cannot settle.
@fix
d02b0fc772c890df3b72Recommendation: Approve. The code is ready: only testing is left. The targeted Windows AMD GCN path has not been measured or exercised in game, so its compile-time benefit and correctness remain unproven. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
c890df3b72. I rebased it ontomain(e8fce9956e).Conflicts resolved
Changed
Left for the author
Nothing was built or run: the checks run again on the new head.
The change enables the existing workgroup-memory warp fallback by default on AMD Windows GPUs limited to wider-than-32-lane compute subgroups. It may reduce long shader compiles, at the cost of one cache retranslation and an unmeasured change in shader behavior on the target driver.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/device_policy.h:638: The changed default has not been measured or exercised on the Windows AMD hardware it targets. When: On Polaris or Vega with AMD's Windows driver, the new workgroup-memory shaders may compile or run differently from the tested Mesa and NVIDIA paths; there is no comparison of compile time, output, waits or frame pacing against the base. Do: Run repeated cold-cache base and head comparisons on Windows Polaris, and Vega if available, through the named scenes. Record compile times, output, waits, frame times and shared-warp check results; also run without the check to observe the actual shared-warp output.Checks: they run again on this head (
Guide screenshots / Guide images and local UI source review (pull_request),CI / Website build and checks (pull_request)failed on the last one); a failure shows on the pull request.Also noticed (3; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven. Reported Windows compile times were 53–310 seconds per fallback stage on version 3.0.0; there is no comparable result for this change. On RADV RX 580, the forced shared path reportedly matched answers and had fps within noise, but that does not measure the target driver.
Other systems: RADV GCN, NVIDIA and Mesa Intel retain their existing defaults; the override can enable the shared path elsewhere. The synchronization edit affects shared-warp shaders wherever enabled. Linux NVIDIA and RADV runs reported no differing answers or abandoned waits, but AMD Windows remains untested.
Switches: RX_VK_MESH_SHARED_WARP defaults on for Mesa Intel and AMD Windows GPUs without 32-lane compute subgroups, and off elsewhere; 1 forces it on, 0 or an off word forces it off, and unset or empty uses the default. The new Windows default awaits measurement.
Reviewed:
c890df3b72againste8fce9956e: Read AGENTS.md, CONTRIBUTING.md and the pull request template; docs/review-checklist.md is absent. Read the fix diff and the shared-warp emission and wait code around it; inspected the policy and initialization changes. The full base-to-HEAD diff and all changed files were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. CI has not run on the fix head; the recorded Linux runs do not cover AMD's Windows compiler.
Overlaps and merge order: none found
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
WIP: fix(vk): AMD's Windows driver on GCN keeps the mesh fallback's warp in workgroup memory, off the 64-lane subgroup emulationto fix(vk): AMD's Windows driver on GCN keeps the mesh fallback's warp in workgroup memory, off the 64-lane subgroup emulationWindows 10, RX 580, AMD's own driver: the merge fixes the compile times (454-1408 s -> 10-13 s), the specks on hair and foliage are still there
The Windows Polaris half of the Beanstalk request, from a real card instead of the farm. The answer splits in two:
the fallback compiles in seconds now, the specks did not go away.
Machine
The shared warp is the default here
vk: policy: can and measured: mirrors=1 import_chunk=4 MB ub_snapshot=0 split_ub_flush=1 native_float_add=0 warp64=1 mesh_shared_warp_default=1 batch_submits=0 mma_unroll_try=0 global_table_loop=0 occ_copy=0 intel_side_by_side_auto=0 fsr4_tune=1 gpu_clock_peak=0 readback_late_newest=0 acquire_ahead=1 pcache_small_pc=0 bc_small_runs=1
vk: mesh_shared_warp=1 (effective, RX_VK_MESH_SHARED_WARP over the policy default)
vk: the mesh fallback's warps in workgroup memory, its stages at any lane count (RX_VK_MESH_SHARED_WARP=0: the subgroup's)
Compile times
Before (v3.2.0, the emulation):
After (nightly-845, every fallback line in that log):
Same
workgroup 1x1x1, shared memory 0 bytesshape. The worst stage went from 569-1408 s to 190.4 s, the rest are tenseconds. No
waits for other lanes gave upline anywhere in the after log.The specks did not go
Hair and grass still draw as bright specks that flicker. I walked Kokiri Forest, Hyrule Field and the Market for 60 s+
each: to my eye it is the same as v3.2.0, I cannot honestly claim the merge reduced it.
mesh_fallback_strict_fmulison for this PC (it is in
driver fixes on driver version 0x800117), so that is already in place and does not coverthis on this card either.
What I can run next
RX_VK_MESH_STRICT_FMUL=0against=1on the same save, to see whether the specks change at all. Name the build andI'll take both runs.