feat(shader): decode s_setkill as s_endpgm #821
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/821"
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?
Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T07:11:53Z.
What
s_setkill(SOPP 0x0b) makes shaders die at translation today (unsupported SOPP opcode). Measured on RDNA2 hardware (gfx1035, same SOPP encodings) by adriadam10:s_setkillwith ANY immediate ends the wave exactly likes_endpgm— a store before it is visible, nothing after it runs — so this decodes it asSEndpgm. Program slicing, CFG terminators and the SPIR-V path are shared withs_endpgmby construction, andS_SETKILLis credited intools/progress.pythrough the existingOPCODE_VARIANTSseam ofSEndpgm, thes_endpgm_savedpattern from #436. Shader progress: 1125 to 1126 out of 1166.s_sethalt,s_sendmsghaltands_code_endare deliberately not implemented and keep throwing as on main: the measurement shows halt freezes the wave until a debugger or trap handler resumes it (no Vulkan equivalent — discard or termination would pretend a plausible result wheremainis explicit),s_sendmsghalthalts after its message the same way, ands_code_endpadding never reaches translation (DecodeRdnaProgramstops ats_endpgm) while executing it hangs the wave. All three are recorded in the updateddocs/dev/TechnicalDebt.mdentry with the measurement and ISA references. No shared path changes — one decode row that is a no-op for every other opcode.Tested
Windows 11:
core/libs/tests/ScalarSetkill.cpp(registered asscalar_setkillbesidescalar_saveexec) checks decode identity withSEndpgmfor immediates 0, 1 and 0xFFFF and that translation takes theSEndpgmpath; scoped CMake/CTest suite (winlibs GCC 15.2.0 per BUILD.md):scalar_setkill,scalar_saveexec,scalar_bitcount64,guest_rtc— 4/4 passed. After the alias there is no distinct instruction left to execute, so this argues covered-by-existing instead of adding totests/execution/(#765 precedent).tools/progress.py: shaders 1125 -> 1126 out of 1166.Checklist
main; #771 implements the same four opcodes with rows the hardware measurement rules out and is CONFLICTING with main — disposition discussed with adriadam10 in the thread; one open PR per function will hold either wayNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T07:56:24Z.
Thanks for picking these up. I measured them on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013) when I did #436, and left them out on purpose. Some of the lowerings here don't match what the hardware does:
s_setkillends the wave for any immediate, including 0. A store before it is visible and nothing after it runs, fors_setkill 0,s_setkill 1ands_endpgmalike (compute kernel on the GPU, 32 lanes, store, then the instruction, then an overwrite). In this PRs_setkill 0is a no-op, so the code after it keeps running, ands_setkill 1is a per-invocation kill instead of the end of the wave. The exact translation is the same ass_endpgm(ass_endpgm_saved/s_endpgm_ordered_ps_donein #436).s_sethalt 1ands_sendmsghaltdon't kill the wave:s_sethalt 1halts it on hardware (the dispatch never completes), and per the ISAs_sendmsghalthalts it after the message, until a debugger or the trap handler resumes it. Turning them into a discard gives a plausible result wheremainthrows, which is what TechnicalDebt's "exactly what it should or throws" rules out.EmitDiscardemitsOpKillin every stage.OpKillis only valid in the Fragment execution model, so a compute or vertex shader withs_setkill 1,s_sethalt 1ors_sendmsghaltproduces an invalid SPIR-V module. The existing kill path (EmitKillIfPixelValidMaskInactive) is only reached from pixel shaders.tests/execution/would.s_code_end:DecodeRdnaProgramalready stops ats_endpgmwhen no branch goes past it, so the padding never reached translation. Executing it hangs the wave on hardware, so throwing (asmaindoes) is already exact.#771 implements the same four opcodes (CONTRIBUTING: one open PR per function), so one of the two will need to give way. I'd suggest keeping
s_sethalt/s_sendmsghalt/s_code_endthrowing, and decodings_setkillasSEndpgm.Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T08:01:41Z.
Measured beats read — all five points accepted, thanks for the gfx1035 data. Reworking to your suggested shape, pushed shortly:
s_setkilldecodes asSEndpgmfor any immediate (credited through progress.pyOPCODE_VARIANTS, thes_endpgm_savedpattern from #436),s_sethalt/s_sendmsghalt/s_code_endstay unimplemented and throw as on main, and theOpKilldiscard path is removed entirely — point 3 stands regardless, that module would have been invalid outside Fragment. On point 4: after the alias there is no distinct instruction left to execute, so the test checks decode identity withSEndpgmincluding the program-slicing and terminator paths and argues covered-by-existing rather than duplicating the execution harness (#765 precedent) — say if you want the store/overwrite execution probe anyway. On #771: happy to yield this to Kikoarl reworked to your shape if you prefer that attribution; note its current rows makes_setkill 0/s_sethalt 0no-ops, which your measurement rules out, and it is CONFLICTING with main. One open PR per function will hold either way.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T08:57:10Z.
Thanks, this matches what I measured. Yes to the execution probe: it's ready, and you're welcome to take it. It reuses
tests/execution/ScalarProgramEnd.cpp(the #436 test) with a second kernel. Lanes store befores_setkill 0and again on a path that ends withs_setkill 1, and the kernel checks that nothing past either one is written. The shape and the expected results are those of the hardware run (gfx1035). It passes on RADV and lavapipe, takes 0 s cold on CI's lavapipe (Mesa 25.2.8), and fails withunsupported SOPP opcode 11without the decoder line. With it,core/libs/tests/ScalarSetkill.cppand its CMake block could go: decoding is covered by the execution path.patch
Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T09:50:33Z.
Took the probe exactly as you provided it (
744b61f5): ScalarProgramEnd.cpp gains the SetkillCode kernel and the Run(code) parameterisation, and per your note core/libs/tests/ScalarSetkill.cpp plus its CMake block are deleted — the execution path covers decoding and fails with unsupported SOPP opcode 11 without the decoder line. Your RADV/lavapipe/CI runs stand as the test evidence in the body; I could not improve on them. Thank you for the measurement work and the patch.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T07:27:13Z.
Thanks for reworking this to match the hardware measurement. The same change landed on
mainwith #771 (c8e4a17f8):s_setkilldecodes asSEndpgm, theSetkillCodekernel is inScalarProgramEnd.cpp, the TechnicalDebt entry is there, andS_SETKILLis credited inprogress.py. Apart from a blank line in CMakeLists and the TechnicalDebt wording, this PR's diff is identical to what's onmainnow, so I'm closing it as a duplicate.s_sethalt,s_sendmsghaltands_code_endstill throw onmain, which is the state this PR wanted for them too.Pull request closed