fix(vk): keep NumWorkgroups live in native mesh shaders for RADV < 26.2.5 #2338
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2338
Loading…
Reference in a new issue
No description provided.
Delete branch "GrimVisage/Longshot:fix/radv-mesh-num-workgroups"
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
Native
VK_EXT_mesh_shadermesh shaders (Stage::Meshwhen!runtime_info.mesh_fallback) can trigger a GPU hang (RING_GFP_TIMEOUT/ invalidSET_SH_REGwithreg_count == 0) on RADV RDNA 3/4 GPUs running Mesa < 26.2.5 (before upstream Mesa MR!45092) when a mesh shader does not referencegl_NumWorkGroups(spv::BuiltIn::NumWorkgroups).Following Lichii PR
#1203(see #1285), this declaresspv::BuiltIn::NumWorkgroupson nativeStage::Meshmodules for RADV before Mesa 26.2.5 and keeps a load ofNumWorkgroups.xlive through NIR dead-code elimination by gating the primitive count passed toOpSetMeshOutputsEXTwithOpSelect(NumWorkgroups.x != 0, count, 0). Since every launched mesh workgroup hasNumWorkgroups.x > 0, the emitted primitive count is unchanged while ensuringac_nir_lower_ngg_msreserves the mesh grid-size registers.This PR keeps RADV's default mesh mode unchanged (compute fallback remains the default on RADV pending
#2291and maintainer decision on flipping defaults).Files to read first:
gpu/vk/eden/shader_recompiler/backend/spirv/spirv_emit_context.h/spirv_emit_context.cpp(DefineInputs)gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_mesh.cpp(MeshEpilogue)tests/global_load_16_ir.cpp(check_mesh_num_workgroups)See #1285.
Testing
Tested:
RX_VK_MESH_FALLBACK=0(nativeVK_EXT_mesh_shader) acrosskokiri-forestandcastle-gate(paired A/B runs, 1440p and 67% resolution); shaders translated, validated, and rendered cleanly with no hangs or visual regressions.tests/global_load_16, Clang 23.1.5 C++20):global_load_16_irpassed all checks including the newmesh-num-workgroups-native(verifiesBuiltIn::NumWorkgroupsinput +OpLoad+OpSelectfeedingOpSetMeshOutputsEXT) andmesh-num-workgroups-fallback(verifies compute mesh fallback is untouched), and all 34 emitted.spvmodules passedspirv-val --target-env vulkan1.3 --uniform-buffer-standard-layout.mise run test-changed: 20 passed, 0 failed, 0 skipped.mise run test: 933 passed, 6 failed, 18 skipped onmain@0e32bc10(the 6 failures are unrelated local environment/workspace checks:tests/test_audio_source.py,tests/test_crash_record.py,tests/test_dev_packs.py,tests/test_mise_build.py,tests/test_pipeline_state_computes.py,tests/test_saveload_warm_cache.py).pre-commiton 4 changed files: passed.Still to test:
RX_VK_MESH_FALLBACK=0, expecting noRING_GFP_TIMEOUTGPU hang on native mesh shaders (by hand, or@Beanstalk run on Linux AMD with RX_VK_MESH_FALLBACK=0).@Beanstalk build and run smoke test on Windows and Linux).Measurements
Nothing to measure: this is a correctness/stability workaround for native
Stage::MeshSPIR-V emission on RADV < 26.2.5 (adds oneOpLoad+OpINotEqual+OpSelectinMeshEpilogueon RADV before Mesa 26.2.5 whenRX_VK_MESH_FALLBACK=0); no default or switch is changed.Risks
Stage::Meshshaders (!runtime_info.mesh_fallback) on RADV before Mesa 26.2.5, adding a constant-trueOpSelectonNumWorkgroups.x != 0toOpSetMeshOutputsEXT's primitive count. Compute mesh fallback (mesh_fallback == true) is untouched.RX_VK_MESH_FALLBACK=0on RADV < 26.2.5 avoid theRING_GFP_TIMEOUThang.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.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Assisted-by: Antigravity
Co-Authored-By: Antigravity [email protected]
Tested in game: Fedora 45 Linux, AMD RX 9070 XT (RADV GFX1201, Mesa 26.3.1), Ryzen 5 5600X: ran Longshot with RX_VK_MESH_FALLBACK=0 on kokiri-forest and castle-gate (paired A/B); native mesh shaders translated, validated, and rendered cleanly with no hangs or visual regressions.
@review
Recommendation: Approve. The emitted SPIR-V keeps NumWorkgroups connected to the primitive count, but the workaround has not been tested on the affected RADV versions. Native mesh shaders also change on other drivers, where rendering and performance remain unverified. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.
This aims to prevent a GPU hang on older RADV drivers when native mesh shaders are enabled. It adds a workgroup-count load and conditional selection to every native mesh shader; the practical cost and the fix on affected drivers are unmeasured.
Should fix (1): not blocking, but worth doing before merging.
tests/global_load_16_ir.cpp:973: The fixture follows the dependency chain but does not verify the comparison value or the selected values. (more on the line) Do: Check that the comparison is against zero and that the true and false operands preserve the original count and zero respectively, or evaluate the emitted expression for representative workgroup counts.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_mesh.cpp:497: The claimed hang fix has not been exercised on the affected driver. (more on the line) Do: Reproduce the hang on the base and repeat the same workload on this head with an affected RADV version and native mesh enabled.gpu/vk/eden/shader_recompiler/backend/spirv/spirv_emit_context.cpp:2235: The workaround is emitted for native mesh shaders on all drivers, including drivers that do not need it, without comparative performance or cross-driver results. (more on the line) Do: Run native-mesh rendering smoke tests on the affected Tier 1 Windows and Linux drivers and compare interleaved base/head frame times and 1% lows in representative scenes. (@fixdoes its part first: Restrict the workaround to affected RADV driver versions so other native-mesh drivers retain their existing shaders.)@fixcan do L2 and L3.Checks: Still running: 9 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. The fixture checks the emitted SPIR-V and the RX 9070 XT run rendered cleanly on Mesa 26.3.1, but that driver is newer than the affected versions and the reported run does not reproduce the original hang on the base.
Other systems: Native mesh shaders on Windows and Linux NVIDIA and AMD drivers receive the new instructions; only newer RADV has an in-game result. Compute mesh fallback returns before the changed epilogue and does not declare the new input. Translator changes invalidate the program cache, so shader preparation is also affected.
Switches: None added, changed or removed. The existing RX_VK_MESH_FALLBACK setting was used for testing.
Reviewed:
c4fd9cc36cagainst0e32bc100d: Read the repository rules, PR template, standards, diff and commit, and inspected the changed files and the surrounding input declaration, mesh epilogue, SPIR-V patching, fixture and cache paths. The large changed source files were not all read in full; no recorded runs, translations or generated files were included in the diff. The sibling Tooling AGENTS.md and docs/review-checklist.md were absent.; 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 still has checks 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.
@ -493,0 +494,4 @@// (longshot, #1285, as Lichii #1203) keep the NumWorkgroups load live through NIR's dead-code elimination into// ac_nir_lower_ngg_ms so RADV < 26.2.5 reserves the mesh grid-size registers (NumWorkgroups.x > 0 for every// launched mesh workgroup)const Id grid_x{ctx.OpCompositeExtract(ctx.U32[1], ctx.OpLoad(ctx.U32[3], ctx.num_workgroups), 0U)};L1 (should fix): The claimed hang fix has not been exercised on the affected driver.
When: On RDNA 3 or 4 with RADV Mesa before 26.2.5 and native mesh enabled, the fixture confirms the SPIR-V shape but cannot show whether Mesa retains the load through the relevant lowering or whether the GPU hang is gone.
Do: Reproduce the hang on the base and repeat the same workload on this head with an affected RADV version and native mesh enabled.
@ -2232,6 +2232,12 @@ void EmitContext::DefineInputs(const IR::Program& program) {if (info.uses_workgroup_id) {workgroup_id = DefineInput(*this, U32[3], false, spv::BuiltIn::WorkgroupId);}if (stage == Stage::Mesh && !runtime_info.mesh_fallback) {L2 (should fix): The workaround is emitted for native mesh shaders on all drivers, including drivers that do not need it, without comparative performance or cross-driver results.
When: Windows or Linux NVIDIA and Windows AMD native mesh users receive the additional input and selection; their shader compilation, output and frame times can differ from the tested newer RADV driver.
Do: Run native-mesh rendering smoke tests on the affected Tier 1 Windows and Linux drivers and compare interleaved base/head frame times and 1% lows in representative scenes.
@ -910,0 +970,4 @@extract_id = inst.words[1];if (inst.op == spv::Op::OpINotEqual && inst.words.size() >= 4 &&extract_id && (inst.words[2] == extract_id || inst.words[3] == extract_id))cmp_id = inst.words[1];L3 (should fix): The fixture follows the dependency chain but does not verify the comparison value or the selected values.
When: If the comparison is changed to NumWorkgroups.x != 1, or the select operands are reversed, the test still passes even though a one-workgroup dispatch emits zero primitives.
Do: Check that the comparison is against zero and that the true and false operands preserve the original count and zero respectively, or evaluate the emitted expression for representative workgroup counts.
@fix
c4fd9cc36c9b02a207abRecommendation: Approve. The code is ready: only testing is left. The workaround is limited to affected RADV versions, but its claimed hang fix has not been exercised on an affected driver. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
9b02a207ab. I rebased it ontomain(6acae6aa87). I edited its description to match the change.Changed
Changed in part (the rest is for the author)
Nothing was built or run: the checks run again on the new head.
The change keeps NumWorkgroups live in native mesh shaders on older RADV drivers to avoid a GPU hang. The version gate avoids adding the workaround on unaffected drivers, at the cost of another shader profile and cache distinction.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_mesh.cpp:497: The claimed hang fix has not been exercised on the affected driver. When: On RDNA 3 or 4 with RADV Mesa before 26.2.5 and native mesh enabled, the fixture confirms the SPIR-V shape but cannot show whether Mesa retains the load through the relevant lowering or whether the GPU hang is gone. Do: Reproduce the hang on the base and repeat the same workload on this head with an affected RADV version and native mesh enabled.Checks: they run again on this head; 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: the reported RX 9070 XT run used Mesa 26.3.1, which is newer than the affected range and now bypasses the workaround. No affected-driver result is reported.
Other systems: The profile gate leaves other drivers and newer RADV versions on the original shader path; compute mesh fallback also bypasses the workaround. The shader cache stamp includes the gate so cached translations are distinguished.
Switches: None added, changed or removed. RX_VK_MESH_FALLBACK remains an existing override; RADV retains its compute-fallback default.
Reviewed:
9b02a207abagainst6acae6aa87: Read AGENTS.md, CONTRIBUTING.md and the pull request template in full. Read the fix diff, the relevant shader emission, driver detection, profile and cache-stamp code, and the fixture changes; the broader base diff and 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. The affected-driver run remains outstanding; CI has not run on this head.
Overlaps and merge order: Not established; the supplied base diff contains earlier changes beyond this pull request's stated topic.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
Jer9 referenced this pull request2026-11-23 16:17:47 +00:00