Repository navigation
fix(shader): read s_buffer_load through the 44-bit GCN V# base - #22060
Conversation
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>
|
Cross-gen confirmation on real AMD —
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 |
|
Thanks, @tablefrogpillow. That covers GCN5, RDNA2, RDNA3 and lavapipe on top of my NVIDIA run, with no |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@PrivacyOnion @MarcZX10 could one of you review this when you have time? All checks pass on |
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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.cppandSrtTape.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.jsonunderreviewed, 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.cppandSrtTape.cppwere 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:79and:114:std::nulloptandstd::exceptionare 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
- Helper
ConstBufferBase - Mask
GcnBufferWord1Mask = 0xffff0fff - Emit path clears the same bits
- Test sources are globbed
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
abdf092dacross several GPUs is a third-party report that I did not reproduce. - The shader bytes in
Code(new lines 25–32 ofGcnScalarBufferBase.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) andSrtTape.cpp(705 lines) were not read in full. I read the changed hunks and searched the names the change touches.ResourceMaterializer.cpplines 912, 1115 and 1493 are confirmed asBase48()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.pyandtools/debt_fold.pyare 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>
|
@MarcZX10 thanks, I took both points in
The test passes 3 of 3 runs on the RTX 4080 SUPER with the validation layer and no |
MarcZX10
left a comment
There was a problem hiding this comment.
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
searchandcat. - No build and no test run. The house rules say to skip builds in this pass.
- Commands:
repo_read.py searchforGcnBufferWord1Mask,GcnGuestShaders,ConstBufferBase,GuestAddressOffset,Base48and the debt-doc link pattern;repo_read.py catforSrtEvaluator.cpplines 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 fromdocs/dev/debt/changes/, so three levels reachdocs/, not the repository root. It resolves todocs/core/…. Four../levels reachcore/. No other file in the repository uses that link depth, so I have no local convention to compare against.SrtAddressArithmetic.hppnow includesRdnaInstructionDecoder.hppandRdnaDescriptorFormat.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
GcnBufferWord1Maskis defined at RdnaDescriptorFormat.hpp:53 as0xffff0fffu.ConstBufferBaseis at SrtAddressArithmetic.hpp:14 and is used at SrtEvaluator.cpp:226 and SrtTape.cpp:420.- The
Base48()reads the debt fragment names are atResourceMaterializer.cpplines 912, 1115 and 1493 at the same head. The author's line numbers are correct. - The test skips only when
GuestArena::GuestAddressOffsetis 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) andSrtTape.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 inCodedecode to the instructions the test comments describe. - Namespaces of
GcnBufferWord1MaskandGcnGuestShadersas 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 thetablefrogpillowruns on other GPUs. I did not run any of these. check_conventions.pyand thedebt_fold.pyclash: 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 reachescore/. - Check whether the walker header needs the decoder include, or whether a forward declaration is enough.
|
@MarcZX10 thanks. No change for either point, so the head stays
|
kurexw
left a comment
There was a problem hiding this comment.
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 logswas 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 noshaderFloat64);agc_driver_recorderfails witha kept vertex window was not mirrored(#20831); the recorder tests each log oneVUID-VkDeviceCreateInfo-sType-uniquefor a duplicatedVkPhysicalDevicePortabilitySubsetFeaturesKHRin the test's own device (#21965). - New
agc_driver_gcn_scalar_buffer_base: passes 3/3 with the layer inserted and 0VUID-.agc_driver_scalar_buffer_runtime_word3passes 3/3 on both. - Tested head was
d41eb1a84a; the later test-only commitd05009fe4f(fail when the block is unexpectedly high) was pushed after my run and I have not rerun it.
AI-assisted: yes
|
@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 |
|
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
Negative control: with main's No new AI-assisted: yes (Claude Code) |
|
@domx4q thanks for testing |
|
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,
On both devices the only difference is the new AI-assisted: yes (Claude) |
|
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 |
What
On PS4 (GCN) shaders, the descriptor walker read an
s_buffer_loadat the V#'s full 48-bit base. The emitted shader uses a 44-bit base instead:SpirvRuntimeBuffer.cppandResourceMaterializer.cppclear word 1 bits [15:12] withGcnBufferWord1Mask, as the debt entry "GCN buffer and image descriptors" describes (shadPS4'sAmdGpu::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 withguest memory is not readableat an address above 2^44.SrtEvaluator::EvaluateRawReadandSrtTape::computenow take a constant buffer's base throughConstBufferBaseinSrtAddressArithmetic.hpp. In GCN mode it appliesGcnBufferWord1Maskto word 1, and in PS5 mode it keeps the 48-bit base, so the PS5 path is unchanged.s_loadthrough a 64-bit scalar pointer is not a V#, so its address does not change.The test
GcnScalarBufferBase.cppcaptures and dispatches a GCN compute shader throughShaderMemory, asGuardedNullPointer.cppdoes. The shader runss_buffer_load_dwordthrough 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.d41eb1a84aaadds 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 throughVK_ADD_LAYER_PATH:ctest -R '^(agc_driver_gcn_.*|agc_driver_guarded_null_pointer|agc_driver_guarded_direct_root)$' -E '_trigger$' -Vmain's walker + the new test: 14/15 pass.agc_driver_gcn_scalar_buffer_basefails withAGC driver: guest memory is not readable at 0x100200000104 (range 0x100200000104+0x4), the 0x1 case, which is the title's message below.This change: 15/15 pass. The new test passes 3 of 3 runs (
--repeat until-fail:3).Validation layer: both logs have 15
Insert instance layer "VK_LAYER_KHRONOS_validation"lines, nowas not found but was requested by env var VK_INSTANCE_LAYERS, nofailed to loadand noVUID-.Build tree: the tests ran in my Bloodborne tree. Its
SrtWalkerfiles,SrtAddressArithmetic.hppandRdnaDescriptorFormat.hppmatchmain's.Title: Bloodborne CUSA00900 01.09 (my own copy), on
mainf2a25e5b42aplus fix(relinker): import undefined global symbols with non-default visibility #17105, feat(libSceGnmDriver): share mode-independent command writers #17711, fix(agc): run the device startup probes as RDNA when a PS4 title has selected GCN shaders #20156, fix(agc): accept PS4 tile modes on 1D array textures #21944, fix(libkernel): allocate thread objects in guest memory #21969, fix(shader): read zeros through a V# with DATA_FORMAT INVALID #21977, fix(libSceAvPlayer): report PS4 stream types in a PS4 process #22033 and feat(agc): materialize single-sample and one-fragment PS4 color target fast clears #18177.shader 0x2d409d100 stage 1: AGC driver: guest memory is not readable at 0x800243ae1560. The vertex shader runss_buffer_load_dword s0, s[12:15], 0x80, thens_cmp_eq_i32 s0, 0ands_cbranch_scc1. Its V# is user data words 12-15,43aa14e0 00108002 00000009 00077fac: word 1 bits [15:12] are 0x8, and the 44-bit base is0x243aa14e0.scalar call link register s[0] ... escapes the constant-offset call/return model). That is a separate issue, fixed in fix(shader): read a MIMG sampler only for ops that sample #22076.Tested by @tablefrogpillow on
abdf092d:agc_driver_gcn_scalar_buffer_basepasses on RX Vega 56 (RADV gfx900, GCN5), the Ryzen 7000 iGPU (RADV gfx1036, RDNA2), RX 7900 GRE (RADV gfx1100, RDNA3) and lavapipe, with the Khronos layer 1.4.363 and 0VUID-(comment).Tested by @kurexw on
d41eb1a84aa: Apple M4, MoltenVK 1.4.2, Khronos layer 1.4.363.1, x86-64 build under Rosetta, 3 runs each onmaina72186d3cf(plus fix(libSceLibcInternal): build TimeGetFields with Apple clang #22056 and fix(libkernel): include link.h only on Linux in the dynamic loader test #22074 for the macOS build) and on this PR:agc_driver_gcn_scalar_buffer_basepasses 3/3 with the layer inserted and 0VUID-; every other selected test has the same status on both, with no newVUID-(review).Review follow-up
d05009fe4f0(test only, from MarcZX10's review): the test now fails instead of skipping when the arena block is above 2^44, except in the ASan build, whose guest offset puts the arena there by design. It also includes<exception>and<optional>directly. Same machine and layer,ctest -R gcn_scalar_buffer_base --repeat until-fail:3 -V: PR headd41eb1a84aaand this commit each pass 3 of 3, never skip, and each log has 3Insert instance layerlines, nowas not found, nofailed to loadand noVUID-.python3 tools/check_conventions.py --base origin/mainpasses.tools/debt_fold.py --checkstops on a clash between two libSceLibreSsl3 fragments that is already onmain, not on this fragment.tools/pr_overlap.py --branchcould not compare two conflicting PRs, so I read their diffs:perf(agc): reuse cached draw stages when only buffer base addresses moved #5609 changes
SrtEvaluator.cpparound the same read, but not the base line.feat(agc): GPU descriptor heap on VK_EXT_descriptor_heap (APS5_GPU_HEAP) #9508 moves
AddSignedAddressinline intoSrtAddressArithmetic.hppand deletes the.cpp. That is whyConstBufferBaseis an inline function in the header, not in the.cpp. A merge with feat(agc): GPU descriptor heap on VK_EXT_descriptor_heap (APS5_GPU_HEAP) #9508 keeps both functions in the header.domx4q on head
d05009fe4fmerged onto mainfbaae8a79d: Arch Linux, GCC 16.2.1, RTX 4090 (Ada), NVIDIA 620.70.06, Khronos layer 1.4.363.1. 12 of 12 pass (main 11 of 11;agc_driver_gcn_scalar_buffer_baseis new), the layer loads in every run, and no log has awas not foundorVUID-line. With main'sSrtEvaluator.cppandSrtTape.cppthe new test fails withguest memory is not readable at 0x100200000104.Tested by @Jitheswar on
d05009fe4f(merged onto main223cc23237): Arch Linux, GCC 16.2.1, Khronos layer 1.4.363, Intel UHD Raptor Lake-S (Mesa 26.2.5 ANV) and RTX 3050 Laptop (GA107, 615.78.08). On both: 13 of 13 pass (main 12 of 12;agc_driver_gcn_scalar_buffer_baseis new), the layer loads in every run, nowas not found, 0VUID-(comment).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)