fix(shader): read s_buffer_load through the 44-bit GCN V# base #22060
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22060"
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 B-Howell on 2026-11-17T03:44:37Z.
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 #17105, #17711, #20156, #21944, #21969, #21977, #22033 and #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 #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 #22056 and #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:#5609 changes
SrtEvaluator.cpparound the same read, but not the base line.#9508 moves
AddSignedAddressinline intoSrtAddressArithmetic.hppand deletes the.cpp. That is whyConstBufferBaseis an inline function in the header, not in the.cpp. A merge with #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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T06:13:21Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
Head
d41eb1a84aac15a3bb43758236caceafa902236c, basemain. 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
SrtEvaluator.cppandSrtTape.cpp, the new helper, and the mask definition, all from the head through the reader.Base48()calls named in the debt note, and the build rule that picks up the new test.files.jsonunderreviewed, at the changed hunks. Excluded by rule: none.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.Results
Base48()at 912, 1115 and 1493Findings
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
ConstBufferBaseGcnBufferWord1Mask = 0xffff0fffNot verified
abdf092dacross several GPUs is a third-party report that I did not reproduce.Code(new lines 25–32 ofGcnScalarBufferBase.cpp) were not decoded, so the expected value of the test is not checked by me.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.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.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T07:15:31Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. The reviewed head is
d05009fe4f.What I ran
searchandcat.repo_read.py searchforGcnBufferWord1Mask,GcnGuestShaders,ConstBufferBase,GuestAddressOffset,Base48and the debt-doc link pattern;repo_read.py catforSrtEvaluator.cpplines 214–232.Results
ConstBufferBase../level too fewctestFindings
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.Base48()reads the debt fragment names are atResourceMaterializer.cpplines 912, 1115 and 1493 at the same head. The author's line numbers are correct.GuestArena::GuestAddressOffsetis non-zero, which is the ASan case, and otherwise fails. This matches the review follow-up.Not verified
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.agc_driver_gcn_scalar_buffer_base, and whether the GCN bytes inCodedecode to the instructions the test comments describe.GcnBufferWord1MaskandGcnGuestShadersas seen from the new header, and whether the header compiles.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:
../levels so it reachescore/.Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T07:44:41Z.
Review: COMMENTED
macOS GPU test (Apple M4, MoltenVK 1.4.2, validation layer 1.4.363.1, x86-64 build under Rosetta)
Base:
upstream/maina72186d3cf+ #22056 + #22074 (both needed for the macOS build); PR headd41eb1a84amerged 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.VUID-errors.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.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).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.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