feat(shader): decode s_setkill as s_endpgm #771
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/771"
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 Kikoarl on 2026-10-05T22:47:47Z.
What
Decode
s_setkill(SOPP opcode0x0b) asSEndpgm.Per hardware measurement on real RDNA 2 hardware (gfx1035) by adriadam10,
s_setkillwith any immediate ends the wave identically tos_endpgm(a store before it is visible, and nothing past it runs). Decoding directly asSEndpgmshares CFG terminators, program slicing, and SPIR-V emission withs_endpgmby construction, matching thes_endpgm_savedpattern from #436.s_sethalt,s_sendmsghalt, ands_code_endare deliberately left throwing as onmain: halt freezes the wave until a debugger or trap handler resumes it (unrepresentable in SPIR-V),s_sendmsghalthalts similarly, ands_code_endis excluded from program decoding while executing it hangs the wave. All three are documented indocs/dev/TechnicalDebt.md.Credited in
tools/progress.pyunderOPCODE_VARIANTS["SEndpgm"].Tested
core/libs/prx/libSceAgcDriver/tests/execution/ScalarProgramEnd.cppparameterised and verified withSetkillCodekernel, confirming stores befores_setkillare visible and stores after it do not execute.tools/progress.pyconfirms positive progress delta (+1 shader instruction).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T23:37:35Z.
Thanks. The SOPP opcode numbers match the RDNA2 ISA (0x0b
s_setkill, 0x0ds_sethalt, 0x11s_sendmsghalt, 0x1fs_code_end), and treatings_code_endas the end of the program in the decoder and graph builder is fine, since it only marks padding after the last instruction.The other three now translate to a no-op (or a plain
sendmsg), though, while on main they throw:s_setkill 1stops the wave, ands_sethalt 1halts it until the host resumes it. As a no-op the wave keeps running, so any stores or exports after them still happen.s_sendmsghaltsends the message and then halts. The halt is dropped.The project's rule is that unimplemented behaviour throws, or is listed as a silent stub in
docs/dev/TechnicalDebt.md. As with #766, if no title needs these yet, I'd keep the decoding and make the translation throw fors_setkill/s_sethaltwith a non-zero immediate and fors_sendmsghalt(the immediate-0 forms are genuine no-ops). Otherwise please add a TechnicalDebt entry that says the halt/kill is ignored. Thenscalar_control_flowwould check the throw instead ofControlNop.Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T05:11:55Z.
Thanks for the review. I've updated the PR accordingly:
s_setkillands_sethaltwith immediate 0 remain no-ops, while non-zero forms now throw.s_sendmsghaltnow throws since the halt is not yet modelled.scalar_control_flowto verify both the immediate 0 no-op behavior and the throw paths.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T07:56:25Z.
I measured these on RDNA2 hardware (gfx1035, same SOPP encodings as gfx1013): a 32-lane compute kernel that stores, runs the instruction, then overwrites. Two of the lowerings here don't match it:
s_setkill 0ends the wave, likes_endpgm. The store before it is visible and nothing after it runs, fors_setkill 0ands_setkill 1alike. Heres_setkill 0is a no-op, so the code after it keeps running. Both values translate exactly asSEndpgm(ass_endpgm_saved/s_endpgm_ordered_ps_donein #436).s_code_endhangs the wave if it is executed (the kernel never completes). Here, when control flow reaches it, it becomes aReturnterminator, so the shader ends quietly wheremainthrows. The padding pasts_endpgmnever reached translation anyway, sinceDecodeRdnaProgramstops there when no branch goes past it. Throwing when it is reached keeps it exact.The rest matches what I measured:
s_sethalt 0lets execution continue, ands_sethalt 1hangs the kernel, so throwing is right;s_sendmsghaltthrowing is right too.The test only checks decoding and the IR shape (
ControlNoppresent). An execution test undertests/execution/would have caught point 1: run a store, the instruction, then a second store, and check which ones land.Same findings posted on #821, which implements the same four opcodes.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T09:27:49Z.
Thanks, that covers everything I asked. Non-zero
s_setkill/s_sethaltands_sendmsghaltnow throw, the immediate-0 forms stay no-ops, andscalar_control_flowtests both cases.s_code_endending the program in the decoder and graph builder is fine as before.The PR now conflicts with main in
core/libs/prx/libSceAgcDriver/CMakeLists.txt. Main added thescalar_scratch_loadtest block right afterscalar_bitcount64, which is wherescalar_control_flowgoes. Could you rebase? Keep both blocks one after the other, each with its ownif(WIN32) ... endif().Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T13:26:33Z.
@oneandonlydean Rebased onto current
mainand resolved the conflict inCMakeLists.txt, keeping bothscalar_scratch_loadandscalar_control_flowblocks sequential with their respectiveif(WIN32)checks. Local tests pass cleanly.@adriadam10 Thanks for taking the time to test on real RDNA2 hardware. Very interesting and valuable insights on
s_setkillands_code_end. We can definitely refines_setkillto lower asSEndpgmin a follow-up PR once this baseline is merged.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T15:13:32Z.
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.
main)docs/dev/TechnicalDebt.mdL46Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-06T15:42:09Z.
Updated per @adriadam10's hardware measurements on real RDNA2 hardware:
s_setkillis decoded directly asSEndpgm(ending the wave identically tos_endpgmregardless of immediate).ScalarProgramEnd.cppand added theSetkillCodeexecution test verifying that stores befores_setkillland and stores after it do not execute.s_sethalt,s_sendmsghalt, ands_code_enddeliberately remain throwing as onmainand documented indocs/dev/TechnicalDebt.md.OPCODE_VARIANTS["SEndpgm"]intools/progress.py.main, with both Linux and Windows CI tests passing green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T06:41:20Z.
Checked the decoder change against our gfx1035 measurement (
s_setkill0 and 1 end the wave), build + full ctest on currentmain(RADV), and thatscalar_program_endfails without the change.Added one commit on your branch:
docs/dev/TechnicalDebt.md: trimmed thes_setkillentry to the measured behaviour and the one unverified point (the KILL status bit). I dropped the GCN3 section reference (that's a different ISA) and thes_sethalt/s_sendmsghalt/s_code_endpart: those still throw exactly as onmain, so there's no new technical debt to record for them.Merging once CI is green on the new head.