Skip to content

fix(shader): answer HW_ID1 and HW_ID2 reads with zero - #671

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/21516
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/21516

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#21516, originally opened by edubox.

Source commit: d3fa3c4e1d50368030fa500941589d32d2000779. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

s_getreg_b32 threw for every hardware register except MODE (1) with "only the MODE round and denormal fields are modeled", so a shader that reads the debug identity registers could not be prepared.

Registers 23 (HW_ID1) and 24 (HW_ID2) are read-only, debug-only registers that the RDNA3 instruction set reference lists as having unpredictable contents, so a fixed answer is within the architecture. Both now answer zero for any field: the host exposes no shader-engine, WGP or wave identity, so every wave reports engine 0, SIMD 0, wave 0 and VMID 0. A field that runs past the 32-bit register still throws, and every other read-only register (STATUS, TRAPSTS, HW_ID, GPR_ALLOC, LDS_ALLOC, IB_STS, TBA, TMA, FLAT_SCR, XNACK_MASK) keeps throwing.

New cases in ShaderModeRegisters: registers 23 and 24 answer a two-bit field at bit 18 and a whole-register read with zero, a field that runs past the register is refused, and register 4 is still refused.

Tested

Linux x86-64 (CachyOS), GCC 16.2.1, Release.

  • agc_shader_mode_register passes with the change and fails without it: on main the new case stops on debugIdentityRegisters: s_getreg_b32 at pc 0 reads hardware register 23 bits 18..19: only the MODE round and denormal fields are modeled.
  • agc_shader_replay --prepare on the captured request of The Last of Us Part II Remastered (PPSA15508) compute shader 0x129fc05a00, which reads s_getreg_b32 s58, 0x0c97 (HW_ID1, bits 18..19), prepares 3476 SPIR-V words with the change and stops at that error on main. The title itself has not been re-run, so nothing is claimed about what it draws.

python3 tools/check_conventions.py --base origin/main: 0 errors. python3 tools/pr_overlap.py --branch fix/shader-sgetreg-topology-registers --jobs 32: no shared exports. It reports file-level sharing only, with pull requests that add their own entries to the same checks table in ShaderModeRegisters.cpp or that touch ScalarInstructions.cpp for unrelated reasons; two of them conflict with main and could not be compared.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Shader reads from two hardware identity registers now return zero for valid fields within the 32-bit register range.
    • Reads that extend beyond the register boundary or access unsupported fields continue to be rejected.
  • Tests
    • Added coverage for zero-valued register reads and for errors on out-of-range and unsupported reads.

s_getreg_b32 threw for every hardware register except MODE (1), with "only
the MODE round and denormal fields are modeled", so a shader that reads the
debug identity registers could not be prepared.

Registers 23 (HW_ID1) and 24 (HW_ID2) are read-only, debug-only registers that
the RDNA3 instruction set reference lists as having unpredictable contents, so a
fixed answer is within the architecture. Both now answer zero for any field: the
host exposes no shader-engine, WGP or wave identity, so every wave reports
engine 0, SIMD 0, wave 0 and VMID 0. A field that runs past the 32-bit register
still throws, and every other register keeps throwing.

The Last of Us Part II Remastered (PPSA15508) registers compute shader
0x129fc05a00, which reads s_getreg_b32 s58, 0x0c97 (HW_ID1 bits 18..19); the
captured request now prepares (3476 SPIR-V words) where main stops at that
error.
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Shader Hardware Register Reads

Layer / File(s) Summary
Register read behavior and coverage
core/shader/recompiler/Translation/src/ScalarInstructions.cpp, core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cpp, docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
Reads from registers 23 and 24 return zero when within the 32-bit bounds and throw a bounds error when they extend past bit 31. Tests cover these cases and rejected reads from register 4. The documentation describes the behavior and remaining throwing cases.

Suggested reviewers: kikoarl, akkadbakkad89

Change: Bug fix

Merge Risk: Minimal · up to d3fa3

Shaders that read the debug-only hardware ID registers now get zero instead of a translation failure, while out-of-range and other unsupported reads are still rejected. The change is small, covered by new tests, and carries no identified risk to merge.

Security architecture risk: Minimal · up to d3fa3

The Shader Recompiler now returns zero for in-bounds reads of HW_ID1 and HW_ID2 without exposing host GPU identity. Out-of-bounds reads still fail, and support for other registers is unchanged.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 861f2e02-614c-40fd-81eb-4aed89c3aa36
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and d3fa3c4.

Files selected for processing: 3

  • core/libs/prx/libSceAgcDriver/tests/ShaderModeRegisters.cpp
  • core/shader/recompiler/Translation/src/ScalarInstructions.cpp
  • docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@github-actions

github-actions Bot commented Dec 4, 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 1 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 3 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 4 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 5 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 6 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 7 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 8 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 9 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 10 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 11 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 12 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 13 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 14 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 15 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 16 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 17 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 18 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 19 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md
PR 20 docs/dev/debt/changes/fix-shader-sgetreg-topology-registers.md

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.

2 participants