Skip to content

fix(shader): read s_buffer_load through the 44-bit GCN V# base - #22060

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
B-Howell:fix/shader-gcn-scalar-buffer-base
Nov 19, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
B-Howell:fix/shader-gcn-scalar-buffer-base

Conversation

@B-Howell

@B-Howell B-Howell commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

On PS4 (GCN) shaders, the descriptor walker read an s_buffer_load at the V#'s full 48-bit base. The emitted shader uses a 44-bit base instead: SpirvRuntimeBuffer.cpp and ResourceMaterializer.cpp clear word 1 bits [15:12] with GcnBufferWord1Mask, as the debt entry "GCN buffer and image descriptors" describes (shadPS4's AmdGpu::Buffer; Limbo leaves 0x7 there). So a V# with any of those bits set made the draw capture read memory the shader never reads. When the walker needed the value, for example as a branch condition, the draw stopped with guest memory is not readable at an address above 2^44.

SrtEvaluator::EvaluateRawRead and SrtTape::compute now take a constant buffer's base through ConstBufferBase in SrtAddressArithmetic.hpp. In GCN mode it applies GcnBufferWord1Mask to word 1, and in PS5 mode it keeps the 48-bit base, so the PS5 path is unchanged. s_load through a 64-bit scalar pointer is not a V#, so its address does not change.

The test GcnScalarBufferBase.cpp captures and dispatches a GCN compute shader through ShaderMemory, as GuardedNullPointer.cpp does. The shader runs s_buffer_load_dword through a user-data V# in a guest-arena block below 2^44, branches on the loaded value, and stores it. It runs four times, with word 1 bits [15:12] set to 0x0, 0x1, 0x8 and 0xf, and each run must store the resident dword.

The debt fragment adds the walker to the existing entry. It also records a gap that this PR leaves: ResourceMaterializer's descriptor-table reads (key scans and table heaps, Base48() at about lines 912, 1115 and 1493) still use the 48-bit base for a GCN V#. None of the stops in my Bloodborne runs came from them. Changing them needs its own table test, so it is a follow-up. d41eb1a84aa adds only that debt sentence.

Tested

Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4080 SUPER (driver 621.14). Run with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, using the LunarG layer 1.4.363.1 through VK_ADD_LAYER_PATH:
ctest -R '^(agc_driver_gcn_.*|agc_driver_guarded_null_pointer|agc_driver_guarded_direct_root)$' -E '_trigger$' -V

python3 tools/check_conventions.py --base origin/main passes. tools/debt_fold.py --check stops on a clash between two libSceLibreSsl3 fragments that is already on main, not on this fragment. tools/pr_overlap.py --branch could not compare two conflicting PRs, so I read their diffs:

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: CUSA00900 Bloodborne PS4 executables on AnyPS5: first results (a PS4 homebrew runs) and what retail PS4 games would need #3094
  • GPUs tested: NVIDIA GeForce RTX 4080 SUPER, driver 621.14, Windows 11 Pro 10.0.26300
  • AI-assisted: yes

The descriptor walker read an s_buffer_load at the full 48-bit V# base,
while the emitted shader masks a GCN V#'s word 1 bits [15:12] off, as the
descriptor rules in RdnaDescriptorFormat.hpp say. A PS4 V# with a high
bit set there (Bloodborne sets bit 15) made the draw capture throw
"guest memory is not readable" at an address above 2^47. The walker and
its tape now take a constant buffer's base through ConstBufferBase, which
applies GcnBufferWord1Mask in GCN mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Nov 17, 2026
@tablefrogpillow

Copy link
Copy Markdown
Contributor

Cross-gen confirmation on real AMD — s_buffer_load through the 44-bit GCN V# base holds on GCN5, RDNA2 and RDNA3. agc_driver_gcn_scalar_buffer_base, head abdf092d, Khronos validation 1.4.363, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:

GPU arch result
RX Vega 56 (RADV VEGA10, gfx900, Wave64) GCN5 Pass, 0 VUID — "GCN scalar buffer base tests passed"
Ryzen 7000 iGPU (RADV RAPHAEL, gfx1036) RDNA2 Pass
RX 7900 GRE (RADV NAVI31, gfx1100) RDNA3 Pass, 0 VUID
lavapipe SW Pass

GCN5 is the native arch the V# base format comes from, so good to have the 44-bit base path confirmed there alongside RDNA, outside the NVIDIA run.

AI-assisted: yes

@B-Howell

Copy link
Copy Markdown
Contributor Author

Thanks, @tablefrogpillow. That covers GCN5, RDNA2, RDNA3 and lavapipe on top of my NVIDIA run, with no VUID- errors. I've added your results to the Tested section.

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

Copy link
Copy Markdown
Contributor Author

@PrivacyOnion @MarcZX10 could one of you review this when you have time? All checks pass on d41eb1a84aa and it merges cleanly. tablefrogpillow confirmed the new test on GCN5, RDNA2, RDNA3 and lavapipe. It fixes the Bloodborne (CUSA00900) stop when character creation opens.

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Nov 17, 2026
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5609 core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp
PR 9508 core/shader/recompiler/Optimization/include/Optimization/SrtWalker/SrtAddressArithmetic.hpp
PR 22647 core/shader/recompiler/Optimization/src/SrtWalker/SrtTape.cpp

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

Head d41eb1a84aac15a3bb43758236caceafa902236c, base main. The walker now reads a GCN constant buffer's base through the same 44-bit mask the emitted shader uses, and the PS5 path keeps its 48-bit base.

What I ran

  • Read the description, commit list, manifest and diff for this head. Read the changed hunks of SrtEvaluator.cpp and SrtTape.cpp, the new helper, and the mask definition, all from the head through the reader.
  • Searched the head for the callers of the helper, the remaining 48-bit walker bases, the Base48() calls named in the debt note, and the build rule that picks up the new test.
  • Read: all five files in files.json under reviewed, at the changed hunks. Excluded by rule: none.
  • No build and no test ran in this review. The test results in the description are the author's, from their own machine.
  • Not approved: SrtEvaluator.cpp and SrtTape.cpp were read only at the changed hunks, not in full, and nothing was built, so there is no passing check to approve on.
repo_read.py search GcnBufferWord1Mask
repo_read.py search GcnGuestShaders
repo_read.py cat core/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cpp 205 240
repo_read.py cat core/shader/recompiler/Optimization/src/SrtWalker/SrtTape.cpp 405 435
repo_read.py search ConstBufferBase core/shader
repo_read.py search AddressMask core/shader/recompiler/Optimization
repo_read.py search Base48 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
repo_read.py search execution core/libs/prx/libSceAgcDriver

Results

Check Result Note
Changed hunks and helper passed Argument order and masks match
Other 48-bit walker bases passed No other constant-buffer base is left
Test registration passed Built by the CMake glob
Debt note line numbers passed Base48() at 912, 1115 and 1493
Build and tests here not run Author-reported only
Full read of the two long files not run Hunks read only

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceAgcDriver/tests/execution/GcnScalarBufferBase.cpp:107: the test returns as skipped when the guest arena block lies above 2^44. On a host where the arena lands high, the test passes without dispatching the shader, so it does not guard the bug there. A failure or an explicit assertion on the block's address would keep the guard.
  • core/libs/prx/libSceAgcDriver/tests/execution/GcnScalarBufferBase.cpp:79 and :114: std::nullopt and std::exception are used without <optional> or <exception> in the includes (lines 1–20). It builds on the author's setup, probably through transitive includes, so this is include hygiene only.

Sources

Not verified

  • Nothing was built or run here. The 14/15 and 15/15 results, the three repeat runs and the validation-layer counts are the author's, on Windows with an RTX 4080 SUPER. The run on abdf092d across several GPUs is a third-party report that I did not reproduce.
  • The shader bytes in Code (new lines 25–32 of GcnScalarBufferBase.cpp) were not decoded, so the expected value of the test is not checked by me.
  • The PS5 path is unchanged: that rests on reading the expression, not on a run.
  • SrtEvaluator.cpp (981 lines) and SrtTape.cpp (705 lines) were not read in full. I read the changed hunks and searched the names the change touches.
  • ResourceMaterializer.cpp lines 912, 1115 and 1493 are confirmed as Base48() calls. I did not read them in context, and the claim that none of the author's stops came from them is the author's.
  • The results of tools/check_conventions.py and tools/debt_fold.py are author-reported. I did not run them.

To get this to a good state

Nothing is required. The two non-blocking points above are optional.

…unexpectedly high

The guest arena lies below the 44-bit GCN V# range unless the ASan guest
address offset moves it, so only that build may skip. Also include
<exception> and <optional> directly.

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

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks, I took both points in d05009fe4f0 (test only).

  • Skip above 2^44: the guest arena is placed below 0xFC00000000 (GuestArena.cpp), so the block can only land above the GCN range in the ASan build, where GuestAddressOffset is 2^44. The test now fails when the block is high in any other build, and still skips under ASan.
  • Includes: added <exception> and <optional>.

The test passes 3 of 3 runs on the RTX 4080 SUPER with the validation layer and no VUID-; details are under Tested.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — no blocking findings

Nothing blocks this; the points below are optional. The reviewed head is d05009f.

What I ran

  • Read the description, commit list, manifest and diff for the head. Read the changed hunks and their callers in the repository at the same head, with the reader's search and cat.
  • No build and no test run. The house rules say to skip builds in this pass.
  • Commands: repo_read.py search for GcnBufferWord1Mask, GcnGuestShaders, ConstBufferBase, GuestAddressOffset, Base48 and the debt-doc link pattern; repo_read.py cat for SrtEvaluator.cpp lines 214–232.

Results

Check Result Note
Changed hunks read passed all five files in the diff
Mask arithmetic in ConstBufferBase passed clears word 1 bits [15:12]; PS5 path unchanged
Debt doc relative links failed one ../ level too few
Build and ctest not run no build in this pass
Author's Windows and GPU runs not run author-reported only

Findings

Blocking

None.

Non-blocking

  • docs/dev/debt/changes/fix-shader-gcn-scalar-buffer-base.md:5: the link ../../../core/shader/… is written from docs/dev/debt/changes/, so three levels reach docs/, not the repository root. It resolves to docs/core/…. Four ../ levels reach core/. No other file in the repository uses that link depth, so I have no local convention to compare against.
  • SrtAddressArithmetic.hpp now includes RdnaInstructionDecoder.hpp and RdnaDescriptorFormat.hpp. Every file that includes the walker header now pulls in the decoder. This may be fine; it is worth a look if the header is included widely.

Sources

  • GcnBufferWord1Mask is defined at RdnaDescriptorFormat.hpp:53 as 0xffff0fffu.
  • ConstBufferBase is at SrtAddressArithmetic.hpp:14 and is used at SrtEvaluator.cpp:226 and SrtTape.cpp:420.
  • The Base48() reads the debt fragment names are at ResourceMaterializer.cpp lines 912, 1115 and 1493 at the same head. The author's line numbers are correct.
  • The test skips only when GuestArena::GuestAddressOffset is non-zero, which is the ASan case, and otherwise fails. This matches the review follow-up.

Not verified

  • The full text of SrtEvaluator.cpp (981 lines) and SrtTape.cpp (705 lines). I read the changed hunks and the context around them, not the whole files.
  • files.json. I did not read it, so I have not confirmed which files it lists as reviewed or excluded.
  • Whether the new test is registered with CMake under the name agc_driver_gcn_scalar_buffer_base, and whether the GCN bytes in Code decode to the instructions the test comments describe.
  • Namespaces of GcnBufferWord1Mask and GcnGuestShaders as seen from the new header, and whether the header compiles.
  • The author's test results: 15/15 on Windows with the RTX 4080 SUPER, the three-run repeat, the negative control on main, and the tablefrogpillow runs on other GPUs. I did not run any of these.
  • check_conventions.py and the debt_fold.py clash: author-reported, not run.

To get this to a good state

Nothing is required.

Optional:

  • Change the debt doc link to four ../ levels so it reaches core/.
  • Check whether the walker header needs the decoder include, or whether a forward declaration is enough.

@B-Howell

Copy link
Copy Markdown
Contributor Author

@MarcZX10 thanks. No change for either point, so the head stays d05009fe4f0.

  • Debt link depth: the link is right as written. docs/dev/TechnicalDebt.md#fragments says "Links are written as in the debt file", because tools/debt_fold.py copies the entry into docs/dev/debt/shader.md, where three ../ reach the root. The entry this fragment changes already uses that link in shader.md on main: ](../../../core/shader/recompiler/RdnaDecoder/src/RdnaDescriptorFormat.cpp). Four levels would break it after the fold.
  • Decoder includes in SrtAddressArithmetic.hpp: I'll keep them. The inline ConstBufferBase needs both GcnGuestShaders() and GcnBufferWord1Mask, and a forward declaration would copy a declaration from another header. Only the three SrtWalker sources include this header, and that library already links the decoder.

@kurexw kurexw 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.

macOS GPU test (Apple M4, MoltenVK 1.4.2, validation layer 1.4.363.1, x86-64 build under Rosetta)

Base: upstream/main a72186d + #22056 + #22074 (both needed for the macOS build); PR head d41eb1a84a merged on top. Built clean (only the known libcurl link failure, #17425).
Env per AGENTS.md: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, ctest -R 'recorder|constant_phi|masked_select|sample_bit_descriptor|pixel_ancillary|scalar_buffer|shader_mode_registers|agc_driver_f64|command_batch|awaited_slot|agc_driver_idle|detiler' -V, 3 runs each on base and PR.

  • Every test has the same status on base and PR in all 3 runs; no new VUID- errors.
  • Every test that creates a Vulkan instance logs Insert instance layer "VK_LAYER_KHRONOS_validation"; none logs was not found but was requested. The tests without layer lines (agc_constant_phi, agc_masked_select, agc_command_batch_*, pixel_ancillary, ...) never touch the loader.
  • Same on base and PR: 11 agc_driver_f64_* tests skip (the M4 has no shaderFloat64); agc_driver_recorder fails with a kept vertex window was not mirrored (#20831); the recorder tests each log one VUID-VkDeviceCreateInfo-sType-unique for a duplicated VkPhysicalDevicePortabilitySubsetFeaturesKHR in the test's own device (#21965).
  • New agc_driver_gcn_scalar_buffer_base: passes 3/3 with the layer inserted and 0 VUID-. agc_driver_scalar_buffer_runtime_word3 passes 3/3 on both.
  • Tested head was d41eb1a84a; the later test-only commit d05009fe4f (fail when the block is unexpectedly high) was pushed after my run and I have not rerun it.

AI-assisted: yes

@B-Howell

Copy link
Copy Markdown
Contributor Author

@kurexw thank you for the macOS run, three times on each arm. I added it to Tested.

No change is needed from it, so the head stays d05009fe4f0. On the head you note: d41eb1a84aa..d05009fe4f0 changes only the test (GcnScalarBufferBase.cpp, 4 lines added, 1 removed: it now fails instead of skipping when the arena block is above 2^44, outside ASan), so your result covers the walker change as it is now. The agc_driver_recorder failure and the VkPhysicalDevicePortabilitySubsetFeaturesKHR VUID- appear on main too, as you found, and come from #20831 and #21965, not this PR.

@github-actions github-actions Bot added review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 19, 2026
@domx4q

domx4q commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Ran the focused tests with the Khronos validation layer on Linux and an NVIDIA GPU, since CI runs the GPU tests only on lavapipe and the NVIDIA run in the Tested section is on Windows.

Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor 0x10de, device 0x2684, Ada), proprietary driver 620.70.06, Vulkan 1.4.357, Khronos validation layer 1.4.363.1. Head d05009fe4f merged onto main fbaae8a79d with --no-ff (clean, as 33c951e936). Main baseline is a Release build of fbaae8a79d on the same machine.

ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer \
ctest --test-dir build -R '^(agc_driver_gcn_.*|agc_driver_guarded_null_pointer|agc_driver_guarded_direct_root)$' -E '_trigger$' -V
main fbaae8a79d this PR
Result 11 of 11 passed 12 of 12 passed
Insert instance layer "VK_LAYER_KHRONOS_validation" 11 12
was not found but was requested by env var VK_INSTANCE_LAYERS 0 0
VUID- none none

agc_driver_gcn_scalar_buffer_base is new and does not exist on main; it passes on this PR. Every device selected the RTX 4090.

Negative control: with main's SrtEvaluator.cpp and SrtTape.cpp and the rest of this PR, agc_driver_gcn_scalar_buffer_base fails with AGC driver: guest memory is not readable at 0x100200000104 (range 0x100200000104+0x4), the message in the Tested section. With the change restored it passes.

No new VUID- errors; all focused tests pass on Ada.

AI-assisted: yes (Claude Code)

@B-Howell

Copy link
Copy Markdown
Contributor Author

@domx4q thanks for testing d05009fe4f on the RTX 4090 (Linux): 12 of 12 pass with no VUID- lines, and the new test fails with main's walker. Added to Tested.

@github-actions github-actions Bot removed the review queue Next in the maintainer review queue: checks pass, no open change request, no conflict label Nov 19, 2026
@Jitheswar

Copy link
Copy Markdown
Contributor

Intel ANV and an Ampere NVIDIA on Linux, using the description's ctest pattern and the Khronos validation layer. The runs so far are NVIDIA and AMD; this adds Intel.

Setup: Arch Linux, kernel 7.2.15, GCC 16.2.1, Release. Intel UHD Graphics (Raptor Lake-S, 8086:a78b, Mesa 26.2.5 ANV) and NVIDIA GeForce RTX 3050 Laptop (GA107, 10de:25ec, 615.78.08) in one laptop, picked with ANYPS5_GPU. Khronos validation layer 1.4.363. main 223cc23237 and head d05009fe4f merged onto it with --no-ff (clean), from the same build directory.

VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 \
  ctest --test-dir build -R '^(agc_driver_gcn_.*|agc_driver_guarded_null_pointer|agc_driver_guarded_direct_root)$' -V
Intel RPL-S (ANV) NVIDIA RTX 3050 (GA107)
main 12 of 12 pass 12 of 12 pass
this PR 13 of 13 pass 13 of 13 pass
VUID- lines (main / PR) 0 / 0 0 / 0

On both devices the only difference is the new agc_driver_gcn_scalar_buffer_base, which passes. Every process logged Insert instance layer "VK_LAYER_KHRONOS_validation", and none logged was not found but was requested by env var VK_INSTANCE_LAYERS.

AI-assisted: yes (Claude)

@B-Howell

Copy link
Copy Markdown
Contributor Author

Thank you @Jitheswar. Intel ANV is the first Intel run on this, and the RTX 3050 adds Ampere: 13 of 13 on both with the layer loaded and no VUID-. Added to Tested.

@oneandonlydean
oneandonlydean merged commit bc0e188 into boykopovar:main Nov 19, 2026
22 of 26 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 unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants