Skip to content

rdna2spirv: s_cbranch_cdbg*, s_wait_idle, s_endpgm_ordered_ps_done - #4023

Open
Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/sopp-misc
Open

Vonsek wants to merge 1 commit into
ItsNotRexed:mainfrom
Vonsek:claude/sopp-misc

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-SOPP-MISC, #3796 (comment)

What and why

Six valid gfx1013 SOPP forms raised Unsupported. I found them by translating every gfx1013 opcode form on main. In the open PR diffs, only #2323's decoder tables name them.

Change (tools/rdna2spirv.py, normalize_sopp, called at the start of fold_far_branches at both of its call sites):

  • The four debugger branches (s_cbranch_cdbgsys, s_cbranch_cdbguser, s_cbranch_cdbgsys_or_user, s_cbranch_cdbgsys_and_user) test the debugger-present bits. Those bits are clear when no shader debugger is attached, so the branches are never taken. Each becomes an s_nop at the same pc, so there is no branch edge and the fall-through chain is unchanged.
  • s_wait_idle waits for outstanding operations. It has no register or memory effect here, so it joins NOOPS.
  • s_endpgm_ordered_ps_done ends the program and signals the end of an ordered pixel-shader section. That signal is already a no-op here, because the fragment-shader interlock ends at shader exit. So the instruction becomes s_endpgm.

Measured natively on RDNA2 gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D, driver 26.10.1, tools/hw_oracle raw wave32 kernel): none of the four branches is taken, and nothing after s_endpgm_ordered_ps_done runs. The kernel returned 0x11 0x22 0x33 0x44, the fixture's first four words.

New contract row in docs/design.md.

Tested

Windows 11, LLVM llvm-mc (-mcpu=gfx1013), VK_LOADER_LAYERS_DISABLE=~implicit~, one GPU at a time, python -I scripts/run_gpu_tests.py --filter cs_w32_sopp_misc:

GPU Driver Result
AMD Radeon RDNA2 iGPU, Ryzen 9 9950X3D 26.10.1 PASS 17 34 51 68 5 6 7 8
NVIDIA GeForce RTX 5080 616.92 PASS, same words
  • New fixture: runtime/test/shaders/cs_w32_sopp_misc.asm, with the words derived in its header. It is registered in check.py, run_gpu_tests.py and regen_fixtures.py.
  • New test: tests/semantic/test_sopp_misc.py checks the fixture words through spirv_mini_interp on 32 lanes, the normalize_sopp rewrite, and that s_wait_idle is in NOOPS.
  • Before the change: on main the test errors with Unsupported: s_wait_idle.
  • Negative control: with s_endpgm_ordered_ps_done made a no-op, the code after it runs. The test fails, and the Radeon run gives 2989 (0xbad) in out[0]. Reverted afterwards.
  • Passing: python -m unittest discover -s tests/semantic (no new failures: the 7 failures and 3 errors it reports fail the same way on main aa2988cc, in test_loop_ballot_barrier (emulate), test_vcmp16_opsel (spirv-val), test_cmp_class_f64 (TEST-853) and test_mutations (v_mul_legacy_f32 anchor)), python tests/semantic/regen_fixtures.py --check (clean), python -I tests/test_shader_checks.py, and pytest tests/test_docs_design_rows.py tests/test_run_gpu_tests.py.

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

The four debugger branches are never taken without a shader debugger (an
s_nop in place), s_wait_idle has no effect, and s_endpgm_ordered_ps_done is
an s_endpgm (the ordered-PS-done signal is already a no-op). Measured
natively on gfx1036. GPU fixture cs_w32_sopp_misc, semantic test
test_sopp_misc.py, design.md row.

AI-assisted.
@SweatierKey

Copy link
Copy Markdown
Contributor

Tested fb7791af on Linux (WSL2, Python 3.13.5, spirv-as/spirv-val, CPU only, no GPU, no game files): pass (CPU / SPIR-V — GPU run not repeated here).

  • Tests & fixture checks:
    • python3 -I tests/semantic/test_sopp_misc.py -v: 2/2 OK (all 32 lanes via spirv_mini_interp, output words match [0x11, 0x22, 0x33, 0x44, 5, 6, 7, 8], normalize_sopp unit check OK).
    • python3 -I tests/semantic/regen_fixtures.py --check: clean (exit 0).
    • python3 -I tests/test_semantic_translator_use.py: 3/3 OK.
    • tests/test_docs_repo_paths.py (2/2), tests/test_docs_links.py (6/6), tests/test_text_write_line_endings.py (3/3), tests/test_text_encoding.py (2/2): all OK.
  • SPIR-V validation: Translated cs_w32_sopp_misc with its compute_header and validated with spirv-as --target-env vulkan1.2 + spirv-val --target-env vulkan1.2 — valid (rc=0).
  • Code read:
    • Calling normalize_sopp(insns) at the start of fold_far_branches covers both call sites (translate and the wave64/direct path) before CFG construction and all downstream s_endpgm checks, while preserving pc/enc on the replaced s_nop / s_endpgm instructions.
    • s_wait_idle added to NOOPS, and cs_w32_sopp_misc wired into runtime/test/shaders/check.py (both WAVE32_DUMPS and expected words) and scripts/run_gpu_tests.py (dump list, expected words, and wave32 exclusion from wave64).
  • Not checked: Vulkan GPU execution of cs_w32_sopp_misc.

@KiryaAfimin

Copy link
Copy Markdown

Tested fb7791a on Windows 11 with an RTX 4070 (driver 621.01). I also checked s_endpgm_ordered_ps_done in a fragment shader with VK_EXT_fragment_shader_interlock enabled. All 4096 pixels kept the color written before the instruction. Removing the instruction let the second color write run, and all 4096 pixels changed to that color.

The full GPU suite had no failures in either mode (165 passed, 46 skipped by default; 196 passed, 15 skipped with wave64 emulation). Both new semantic tests passed. I reproduced all nine failures/errors from the full semantic run on the parent commit aa2988c.

AI-assisted

@slopradish slopradish left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CPU verification: checked out pull/4023/head in an isolated worktree and ran pytest -q tests/semantic/test_sopp_misc.py: 2 passed.

The change handles the remaining miscellaneous scalar opcodes (s_cbranch_cdbg*, s_wait_idle, s_endpgm_ordered_ps_done) with the same pattern as the neighbouring opcode work: translator rule, semantic fixture, semantic test, GPU fixture, checker word list, GPU runner registration and contract row all updated together. The semantic test drives the real translator rather than a private model, so the CPU path is genuinely covered.

I could not run the GPU fixture on this host; the hardware-visible behaviour is the author's measurement. No game files or keys involved.

@slopradish

Copy link
Copy Markdown

Follow-up correction to my approval: a later full pytest -q tests/semantic run on this head (4,367 s) reported 48 failures, including test_wave64_subgroup_ops.py::NegativeControl::test_partial_wave_bpermute_without_its_source_lane_fallback and LockstepMemoryOrder::test_a_load_after_a_store_sees_every_lane. I re-ran those two tests in isolation on both upstream/main and this PR head: 2 passed on each.

So the failures are order-dependent rather than introduced by this PR. I can't attribute them to the sopp_misc change, and I'm not retracting the approval — but the semantic suite has a cross-test state problem worth a separate item (similar in kind to TEST-874). My original evidence stands: test_sopp_misc.py 2 passed on the PR head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants