Skip to content

fix(shader): test an empty exec mask in s_subvector_loop_begin with one compare - #7623

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/subvector-loop-exec-zero
Oct 19, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/subvector-loop-exec-zero

Conversation

@thuanquang

@thuanquang thuanquang commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

s_subvector_loop_begin skips the loop when the whole wave64 exec mask is zero. The recompiler tested that as two 32-bit compares joined by a logical and: exec_lo == 0 && exec_hi == 0. It now tests it as one compare: (exec_lo | exec_hi) == 0. It is the same condition, and entered and the new exec_hi still use exec_lo == 0 as before.

AMD's Windows driver compiles the two-compare form wrongly once the guest's exec mask comes from a loaded value. This is the agc_driver_subvector_loop failure in #7376 (lane 0 exec hi after the loop is 0, expected 4294967295). #7351 hides it by keeping robustBufferAccess2 off on that driver. With the single compare, the test passes on that driver with robustBufferAccess2 on. The exclusion stays: the two layered-volume failures in #7351 are a separate question (#7376), so this PR does not change which devices get the feature. The debt entry for the guest memory load guards now records that subvector_loop is no longer one of the failures.

The pipeline's ISA, read back with VK_KHR_pipeline_executable_properties, shows where it goes wrong. Case "initial exec high half": the guest v_cmpx leaves exec_lo 0 and exec_hi set.

  • target.robustBufferAccess2 = false (test passes): the low and high halves are tested separately.
    v_cmp_ne_i32_e64 s8, v2, 0
    s_cmp_eq_i32 s8, 0
    s_cselect_b64 s[10:11], exec, 0
    s_cmp_eq_i32 s9, 0
    s_cselect_b64 s[12:13], exec, 0
    
  • target.robustBufferAccess2 = true (test fails): the load's lane guard is now an s_and_b64 in the same block. Both exec_lo == 0 and exec_hi == 0 are taken from that instruction's SCC, which says whether all 64 bits are zero. So exec_lo == 0 comes out false, and exec_hi after the begin instruction is selected to 0 (s_cselect_b32 s22, 0, s5).
    v_cmp_ne_i32_e64 s4, v2, 0
    s_and_b64 vcc, s[4:5], vcc
    s_and_b64 s[4:5], vcc, exec
    s_cselect_b64 s[8:9], 0, exec
    s_cselect_b64 vcc, 0, exec
    
  • With this change and robustBufferAccess2 on (test passes): exec_lo == 0 is a 32-bit compare again, and the empty-mask test is s_or_b32 plus a compare.
    s_and_b64 s[4:5], vcc, exec
    s_or_b32 s2, s4, s5
    s_cmp_eq_i32 s4, 0
    s_cselect_b64 vcc, exec, 0
    s_cmp_eq_i32 s2, 0
    

The two SPIR-V modules differ only around the guest load: a selection in one, an OpSelect over a guarded index in the other, as @Mouad-Scriptz-0 found on #7376. The begin instruction's ops are the same, and both modules pass spirv-val --target-env vulkan1.3.

Tested

Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, APS5_NO_PIPELINE_JOURNAL=1. Each subvector_loop run used a renamed copy of the test executable, so AMD's per-executable pipeline cache started empty:

  • agc_driver_subvector_loop on main 218aa8f00, with RobustBufferAccess2Usable changed locally to return true (that change is not part of this PR):

    • without this change: fails 2 of 2, lane 0 exec hi after the loop is 0, expected 4294967295;
    • with it: passes 2 of 2.
  • agc_driver_subvector_loop with this change and the exclusion kept, as merged: passes.

  • The three ISA listings above come from main 3e3e8b905, read back through a local capture hook that is not part of this PR.

  • Full ctest --parallel 4 --timeout 120 on main 3e3e8b905, with an earlier form of this change that also kept the now unused exec_hi == 0 compare, and robustBufferAccess2 forced on: 1479 tests. These fail:

    agc_driver_subvector_loop and agc_driver_layered_volume_vertex_no_gpl pass.

  • AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001, Windows 11 26300), run by @LeandroLP23 on main c3591adf9 with this PR and six others merged (comment):

  • Not run: the full suite on 218aa8f00.

  • python tools/check_conventions.py --base origin/main with this title and body passes.

  • NVIDIA RTX 3070 (595.99.02, Ubuntu 26.04), run by @jotitadev on f65b4bb merged onto main 84c1a4d9a: agc_driver_subvector_loop passes 3 runs, and passes with main's two-compare form too, so the miscompile is specific to AMD's Windows driver.

  • Not tested: AMD drivers other than these two, and Intel hardware runs of subvector_loop with this change. CI's lavapipe skips that test because its subgroup is too small.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, Windows 11 26200; AMD Radeon 860M (RDNA 3.5), driver 32.0.13058.8001, Windows 11 26300 (by @LeandroLP23); NVIDIA RTX 3070, 595.99.02, Ubuntu 26.04 (by @jotitadev)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

…ne compare

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6612 docs/dev/debt/shader.md L171
PR 6679 docs/dev/debt/shader.md L171
PR 6959 docs/dev/debt/shader.md L171
PR 8077 docs/dev/debt/shader.md L171
PR 8134 docs/dev/debt/shader.md L171

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6280 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6488 docs/dev/debt/shader.md
PR 6604 docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 6977 docs/dev/debt/shader.md
PR 7085 docs/dev/debt/shader.md
PR 7223 docs/dev/debt/shader.md
PR 7332 docs/dev/debt/shader.md
PR 7392 docs/dev/debt/shader.md
PR 7395 docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7684 docs/dev/debt/shader.md
PR 7888 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md

@LeandroLP23

Copy link
Copy Markdown
Contributor

Another AMD driver, since the description lists other AMD drivers as not tested. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. Build: main c3591adf9 with #7623, #7612, #7611, #7603, #7579, #7563 and #7541 merged together (each merge clean, built once).

  • As merged (robustBufferAccess2 still off on AMD's proprietary driver): agc_driver_subvector_loop, agc_driver_layered_volume_draw, agc_driver_layered_volume_vertex, agc_driver_lds_lock_budget, agc_driver_lds_mixed_width_atomics and agc_robust_buffer_access pass 3 runs of 3. The one failure in the list, agc_driver_layered_volume_vertex_no_gpl, which fails the same way on main here (agc_* tests: 3 of 483 fail on AMD Radeon RX 6400, pass on NVIDIA RTX 4080 SUPER #5271), is not from this PR.
  • With RobustBufferAccess2Usable forced to true, from renamed copies of the test executables so the driver cache starts empty: agc_driver_subvector_loop, agc_driver_layered_volume_draw (with and without --vertex-only) and agc_driver_lds_mixed_width_atomics --lock-budget (robustBufferAccess2=1) pass, 2 runs of 2.

This driver didn't show the subvector_loop failure before either (#7376), so this shows no regression on a second AMD driver, not the fix itself.

AI-assisted

@MarcZX10

Copy link
Copy Markdown
Contributor

The Radeon 860M follow-up is useful additional coverage: it passes the six listed tests 3/3 with the AMD exclusion in place, and the forced-true subvector/volume/lock-budget cases pass 2/2 from renamed executables. Could you add this GPU and OS/driver to the GPUs tested checklist and note that agc_driver_layered_volume_vertex_no_gpl is a #5271 main failure? The current checklist lists only the RX 6700 XT.

@thuanquang

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Added: @LeandroLP23's Radeon 860M run is under Tested and on the GPUs tested line, with agc_driver_layered_volume_vertex_no_gpl noted as the #5271 failure main has on that machine.

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An NVIDIA run of agc_driver_subvector_loop, since NVIDIA is listed under "Not tested" and CI's lavapipe skips the test.

Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02; it reports robustBufferAccess2, and only the AMD Windows driver is excluded from it) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged onto main 84c1a4d9a (clean). ANYPS5_NO_SHADER_CACHE=1, -j1 --timeout 30.

agc_driver_subvector_loop RTX 3070 lavapipe
head f65b4bbe9 Passed, 3 runs Skipped
ControlFlowInstructions.cpp from main (two compares) Passed Skipped

So the single compare gives the same result on NVIDIA, and NVIDIA's compiler handles the two-compare form correctly too. The exec_lo/exec_hi miscompile looks specific to AMD's Windows driver, as described.

Not run: Windows, AMD, Intel, the layered-volume tests from #7351.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit 25ab351 into boykopovar:main Oct 19, 2026
13 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the diff: (exec_lo | exec_hi) == 0 is the same condition as the two compares, entered and exec_hi are unchanged, and the debt entry now matches. Covered by the existing agc_driver_subvector_loop, with the AMD 6700 XT / 860M and NVIDIA 3070 runs in the thread; merged.

thuanquang added a commit to thuanquang/AnyPS5 that referenced this pull request Oct 20, 2026
boykopovar#7351 kept robustBufferAccess2 off on AMD's proprietary driver because
enabling it broke agc_driver_layered_volume_draw, agc_driver_layered_volume_vertex
and agc_driver_subvector_loop on an RX 6700 XT. With boykopovar#7623 and boykopovar#7828 on
main, those tests pass with the feature on, in either library-mode order.
This reverts 48b394d and keeps the record of boykopovar#7623's empty-mask test in
the s_subvector_loop debt entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thuanquang added a commit to thuanquang/AnyPS5 that referenced this pull request Oct 20, 2026
enabling it broke agc_driver_layered_volume_draw, agc_driver_layered_volume_vertex
and agc_driver_subvector_loop on an RX 6700 XT. With boykopovar#7623 and boykopovar#7828 on
main, those tests pass with the feature on, in either library-mode order.
This reverts 48b394d and keeps the record of boykopovar#7623's empty-mask test in
the s_subvector_loop debt entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thuanquang added a commit to thuanquang/AnyPS5 that referenced this pull request Oct 21, 2026
enabling it broke agc_driver_layered_volume_draw, agc_driver_layered_volume_vertex
and agc_driver_subvector_loop on an RX 6700 XT. With boykopovar#7623 and boykopovar#7828 on
main, those tests pass with the feature on, in either library-mode order.
This reverts 48b394d and keeps the record of boykopovar#7623's empty-mask test in
the s_subvector_loop debt entry.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants