Skip to content

feat(shader): implement s_getreg_b32 for the MODE round mode fields - #577

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
CnRJay:feat/s-getreg-mode
Oct 5, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
CnRJay:feat/s-getreg-mode

Conversation

@CnRJay

@CnRJay CnRJay commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What

s_getreg_b32 (SOPK 0x12) threw unsupported SOPK opcode 18 in the decoder.

The recompiler always emits round to nearest even: s_setreg_imm32_b32 throws for any other round mode. So a read that stays within MODE bits 0..3 (the f32 and f64/f16 round mode fields) returns 0. Any other hardware register or field (denormal modes, HW_ID, GPR_ALLOC, ...) throws with the register and bits it reads, rather than returning a guess.

The embedded vertex-fetch SGPR tracker clears the destination of s_getreg_b32, as it does for s_cmovk_i32.

Tested

Windows 11, MinGW GCC 15.2.0 r7, NVIDIA Vulkan, -DANYPS5_ENABLE_SPIRV_TOOLS=ON.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

SOPK 0x12 threw in the decoder. The recompiler emits round to nearest
even, which s_setreg_imm32_b32 already requires, so reads that stay
within MODE bits 0..3 return 0. Other hardware registers and fields
throw with the register and bits read.

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

Copy link
Copy Markdown
Collaborator

Thanks. llvm-mc for gfx1013 gives s_getreg_b32 s20, hwreg(HW_REG_MODE, 0, 4) and hwreg(HW_REG_MODE, 2, 2) for the two reads, and the refusals are hwreg(HW_REG_MODE, 4, 4) and hwreg(4). Small naming detail: on gfx10 id 4 has no name in LLVM (HW_ID became HW_ID1 and HW_ID2, ids 23 and 24), so the test label could say "hardware register 4"; it's refused either way.

One thing before it goes in. Returning 0 is right for s_setreg_imm32_b32, which throws for anything but round to nearest even, but main ignores the register form s_setreg_b32 entirely (it's a TechnicalDebt line: "writes to MODE ... have no effect"). So a shader that writes another round mode with s_setreg_b32 and reads it back gets 0 here, while the hardware returns what was written. The initial round mode from the shader's program registers isn't read anywhere either. The 0 does match the rounding the recompiled code actually uses, so I think that's acceptable, but it should be written down: could you extend the existing s_setreg_b32 line in docs/dev/TechnicalDebt.md to say that s_getreg_b32 reads of the MODE round fields report round to nearest even even after s_setreg_b32 wrote another mode? With that it's ready to merge from my side.

agc_driver_scalar_getreg passes here on NVIDIA and fails on main ("unsupported SOPK opcode 18").

This fits #436's s_round_mode (no-op for 0, throws otherwise). PPSA21564 has no real s_getreg_b32, so this doesn't affect my runs. The CI run still needs approval.

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Progress report (221ea3c → 53928c7)

📈 GPU shader instructions: 83.96% (+0.08%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
SOPK S_GETREG_B32

…treg_b32

s_setreg_b32 has no effect, so a read of the MODE round fields after it
wrote another mode still reports round to nearest even, the rounding the
recompiled code uses. The refused HW_ID test row is named as hardware
register 4, which has no name on gfx10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, the TechnicalDebt line now says that s_getreg_b32 reports round to nearest even even after s_setreg_b32 wrote another mode, and that the initial mode isn't read either, which covers it. agc_driver_scalar_getreg passes here and fails on main's code.

The new push needs workflow approval again before CI runs. Ready to merge from my side once it's green.

@oneandonlydean
oneandonlydean merged commit 70596d7 into boykopovar:main Oct 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants