fix(shader): decode a GPU-selected formatted load from a format table #3656
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3656"
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 EdouardSence on 2026-10-11T14:55:21Z.
What
Follow-up to #3655, for the same stop: Ghost of Yōtei (PPSA26344) compute shader
0x8000289300exhausts memory invkCreateComputePipelineson RADV, onmaina11c8f7fwith #757/#758 merged. The diagnosis is in discussion #2884.#2349 moved a GPU-selected formatted access into one shared
DontInlinefunction per shape, which is enough on NVIDIA. RADV inlines every function, so each of the module's 128buffer_load_formatcall sites still gets a copy of all 77 format cases: 31k instructions forload_formatted_gpu_buffer_x4.For loads,
formatSwitchwith a GPU-selected V# no longer emits the 77 cases:Privateconstant table holds, perIrBufferFormat, the component count, the packed flag, the type, the width, byte offset and bit offset of each component (3 words per format, built fromGetFormatInfo).formatted()'s steps for 4 components, withcomponentCountand the widths read at run time:required, as there;address()'s bounds, through a newbyteAddressthat takes the offset and size as values;EmitBdaReadBytes, a loop over the bytes, from #3655);NormalizeFormatComponent/EmitD16FormatComponentof each (type, width) pair a format uses at that component, picked withOpSelect;InvalidDescriptorand stops, as the switch's default did.The conversions are the same functions with the same type and width, so a load returns what the matching switch case returned.
Results for
0x8000289300, on top of #3655:load_formatted_gpu_buffer_x4: 31k → 3.9k instructions.MESA_SHADER_CACHE_DISABLE.Tested
Linux (CachyOS), RX 9070 XT, RADV 26.2.4, GCC, Release, on #3655.
import_auditfails because its source commit lookup does not work in a git worktree; it fails the same onmain. The buffer format execution tests run on the GPU.agc_formatted_buffer_oncenow requires a GPU-selected formatted load to stay under 40,000 SPIR-V words. Onmainit is 112,835 and the test fails; here it is 16,854.tools/check_conventions.pypasses.#2837 also adds
SpirvModule::DefineInitializedGlobalVariable, with the same signature, so one of the two will need a rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Tested and written by Claude (AI assistant) on a contributor's machine.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T15:03:28Z.
Review: DISMISSED
Thanks, the table approach reads equivalent to
formatted()(selectors,required, bounds, address-overflow fault, sign extension and the per-(type, width) conversions all match). The size test fails without the change, as intended. One thing blocks this:agc_driver_buffer_format(tests/execution/BufferFormat.cpp) only uses prepared V#s, where the format is a specialization constant and the switch folds, andFormattedBufferOnce.cpponly counts SPIR-V words. A wrong table entry (a swapped bit offset, a mis-tagged type) would pass everything. Please add an execution test that loads through a GPU-selected descriptor (V# not resolvable at registration) and compares against the expected values for every format the switch handled (at least one per type/width pair: UNORM/SNORM/UINT/SINT/USCALED/SSCALED/FLOAT 8/16/32, the packed ones, 1-4 components,d16, selectors 0/1/4+, a component past the buffer end, format 0 and 78).Also: this contains #3655's commit; it can only land after #3655, so please keep the Depends on and rebase once it merges.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-11T15:19:34Z.
Independent pre-review on Linux (full CI runs only happen on manual trigger, so recording one): CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON.tools/check_conventions.py --base origin/mainpasses.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T15:40:40Z.
The equivalence claim here is structural, and I checked the old shape rather than take it on trust.
On
mainthe 77 cases are not 77 hand-written conversions. The switch (SpirvRuntimeBuffer.cpp:359-377,formatSwitchat:351) builds anOpSwitchover the GPU-selected format in which every case is the same call:One
formatted()with a differentGetFormatInfoconstant per case (:371). The new table is built fromGetFormatInfoas well (formatTable). So the generic path is the same function carrying the same per-format data, selected at run time instead of by anOpSwitch— which is what makes "a load returns what the matching switch case returned" checkable rather than hopeful, and it is the line worth quoting for whoever merges this.The contract the switch's default carried is preserved, verified on
main. For a GPU-selected descriptor the invalid default recordsInvalidDescriptor(:379, inside theif (memory.gpuDescriptor)guard), and the post-mergeunsupportedtest — format 0, or above the count of 77 — stops the invocation (:388-389). Both are guest-visible on a bad V#, so that contract is the part that had to survive, and the new path keeps both under the same conditions.The scoping is what keeps the risk bounded, and it is worth stating in the body. Only the GPU-selected-V# load path goes generic (
if (!store && memory.gpuDescriptor)). Stores and loads through a prepared V# keep the switch, where a specialization-constant format lets it fold, and a GPU-selected load whose format is a compile-time immediate is handled earlier still (:342) and never reaches the switch at all. The change is confined to the path that actually blew up.The word budget is the right shape of guard.
agc_formatted_buffer_oncerequiring under 40,000 SPIR-V words —mainat 112,835, this at 16,854 — is a deterministic RED whose failure mode is exactly the regression that matters, and nothing else in the suite would notice the module growing back.One gap I can name from the tree. That same test is the only one that reaches the GPU-selected formatted-load path, and it is compile-only — it counts emitted words and never creates a device, so it can show the module shrank but it cannot show a load still returns the right value. The execution tests that do dispatch formats (
tests/execution/BufferFormat.cpp, andBufferLoadStore.cpp'sCheckRuntimeDescriptors, whose cases use formats 5/11/18/20 — one- and two-component ones) take the prepared-descriptor shape, which this PR leaves on the switch; their descriptors come from host-filled buffers, so the tracker validates them instead of treating them as GPU-selected. The generic path is therefore covered for size and not covered for behaviour — and the run-time component count is precisely what the switch never had. A GPU-selected dispatch that runs a one- and a two-component format is the test I would add.Two things worth writing down before merging.
mainwhile2d3a970d— #3655's own last commit — is also on this branch, sogh pr diff 3656(615 lines) shows the BDA-lookup rewrite and theShaderMemory.cppassertions alongside your own369928dc: ten files in total, five of them from that commit and two touched by both. It resolves itself once #3655 merges, but until then it is worth knowing so the lookup work is not read as part of this PR.SpirvModule::DefineInitializedGlobalVariablewith the same signature, as the body says. One of the two needs a rebase, and since #3655 already has to be re-measured against #2837'sDefineBdaLookup, landing the pair first keeps both rechecks in one place.Not verified here: I have no RADV device, so the module-size and pipeline figures are yours. What I could check is the emitter's shape, the preserved fault paths, the table's provenance, and this tree's test plumbing. The
import_auditworktree failure matches what this tree does onmain, so taking your note at face value it is not something this PR introduces.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-11T19:15:47Z.
@adriadam10 thanks. Added
agc_driver_gpu_buffer_formatin 6aaae0398 (tests/execution/GpuBufferFormat.cpp).The shader loads the V#'s
NUM_RECORDSand word3 from a buffer and moves them into SGPRs withv_readfirstlane, so the descriptor is GPU-selected and every load goes through the table. One compile, then one dispatch per case. Two lanes each read 16 bytes (signed and unsigned extremes, f16 ±1/±inf, f32 NaN and denormal).buffer_load_format_x,_xy,_xyz,_xyzwandbuffer_load_format_d16_xyzw, for every format 1-77 with identity selectors.8_8_8_8_UNORM,8_8_8_8_UINT,32_32_FLOATand32_FLOAT.NUM_RECORDS= 22 on32_32_32_32_FLOAT,16_16_16_16_FLOAT,32_32_FLOATand8_8_8_8_UNORM, so lane 1 has components past the end (xalone stays in bounds,xyzwdoes not).The expected values were captured from the switch at
2d3a970da(#3655 only). They are identical, bit for bit, to the table's output. Corrupting one bit offset informatTablemakes the test fail on format 30 (0x3f701e04, expected0x3f603c08). I also checked a few values against a hand computation:8_8_8_8_UNORM1/255 →0x3b808081, 127/255 →0x3efefeff,16_SNORM-255/32767 →0xbbff01fe.Linux, RX 9070 XT, Mesa 26.2.4 RADV: the new test passes, and
check_conventions.py --base origin/mainpasses. Still Depends on #3655. I will rebase once it merges.Tested and written by AI assistants (Claude and Gemini) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T04:16:33Z.
Windows/Blackwell cross-test: #3655
2d3a970d+ #3656 369928dc/6aaae039 applied cleanly on our007 runtime-image-table integration, public combined head bc46e2d6f: https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-bda-compact-cross-test . Original author commits retained. Release, SPIRV-Tools OFF, RTX5070Ti/NVIDIA617.14, Vulkan required.Focused checks 6/6 pass,6.50s, no reported skips: agc_shader_memory0.36s, agc_driver_bda_device3.00s, agc_formatted_buffer_once0.17s, agc_driver_flat_loads0.48s, agc_driver_global_loads0.55s, agc_driver_gpu_buffer_format1.72s. This covers the emitted helper structure, native address/fault behavior and GPU-selected formats; not a full-suite result.
Staging a separate007 run next. No game-output/FPS improvement claimed yet. AI-assisted: yes(Codex).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-12T05:05:58Z.
NVIDIA cross-test of #3655 and #3656 (
2d3a970da, 369928dcc, 6aaae0398) on 007 First Light's compute shaders, run offline.Setup. RTX 3080, NVIDIA 615.71.09, CachyOS, GCC 16.2.1, Release. The three commits cherry-picked without conflicts onto a local, unpublished 007 stack: main
62f875871+ 82 commits, not current main.Method.
agc_shader_replay --spv, built separately at each head.vkCreateShaderModule+vkCreateComputePipelines,__GL_SHADER_DISK_CACHE=0.Results.
2d3a970dashrinks the 17 modules that read throughget_bda_pointer, by 828 to 1,491 words each, all of it in the BDA helpers. The other 134 modules are byte-identical. Across all 151: 42,246,335 → 42,225,713 words (−0.05 %).agc_shader|recompiler|spirv|bda|formatpass, includingagc_driver_gpu_buffer_format. Without the PRs, 27/27 pass.Neutral for 007 on NVIDIA.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T13:07:00Z.
Rebase handoff + one open finding — rebased onto current
main, authorship unchanged. One test-file conflict resolved (kept this PR's 40000-word bound check and main's extended vertex-specialization summary line together).The finding: after the rebase,
agc_formatted_buffer_oncefails deterministically — and it's a semantic conflict with main's newer work, not a mechanical rebase issue:The failing check is main's (from
56d5a4985, "read the formatted buffer helper's V# words as specialization constants when the format is known"): it expects the known-descriptor path to stay under half the GPU-selected path's size. This PR's format-table decode makes the GPU-selected path much smaller (16854 words), so the ratio inverts — the known path (26501) is now the larger one. Main's specialization work and this PR's decode change need to meet: either the known-format path should specialize on top of this PR's table decode, or main's ratio check needs recalibrating for the new baseline. I did not adjust the check, since which side should give is a design call.Everything else: builds, conventions pass, full suite 953/954 (only this test).
To pick it up:
Head is
ed64f3a6e.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:46:19Z.
The check is a relative bound, so the calibration is the side that should give — the decode does not need to. On
main,core/libs/prx/libSceAgcDriver/tests/FormattedBufferOnce.cpp:98is:oneis the known-descriptor load andgpuOnethe GPU-selected one. The message says what the assertion means:gpuOneis the stand-in for a path that still contains every format's decoder, and half of it is a proxy for "this path did not keep all of them". Nothing in the file pins the known path's absolute size — line 97 does the same thing on the vertex pair with a different margin (1.5x) — so the GPU-selected path is the yardstick, not a subject of the test.That is why your finding inverts rather than fails: once the table decode takes the GPU-selected path to 16854 words, the yardstick shrinks with it and the ratio stops measuring what its message claims. The resolution that keeps the check's meaning is to compare the known path against something that still keeps every decoder (or against an absolute bound), not to hold the decode back — the decode is the point of the PR. Which side writes that recalibration is @EdouardSence's call with @adriadam10, but it should not be settled by weakening the thing under measurement.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T21:34:23Z.
lavapipe measurement: with #3655 + #3656, pipeline creation for one Ghost of Yōtei compute shader (
0x8000289300) goes from killed at an 8 GB cap to a 1.9 GB peak.What was tested. blawesom's rebase:
blawesom:rebase/3656@ed64f3a6e. It is based on33ae282e4, which predates #4759 and #5022, and carries #3655 as805be46cf. I merged it locally ontomain0aa4cb1c2. The merge is clean, but no pushed commit matches the tree I tested.#5022 is preserved.
load_bda_spanand the selection inread_bda_spanare exactly as #5022 left them;load_bda_spanis still a DontInline function that makes no calls. InSpirvBdaRead.cppthe diff changes only the fallbacks: the per-byte read andread_bda_span's per-dword fallback both become loops. It also addsEmitBdaReadBytesfor the format-table path.Setup. lavapipe 26.2.4, CachyOS, GCC 16.2.1, Release build, SPIRV-Tools OFF, clean environment with
VK_ICD_FILENAMESset to lavapipe. This is not the CI configuration: CI uses Ubuntu'smesa-vulkan-driverswith SPIRV-Tools ON.Method. I built
agc_shader_replay --spvat both heads and replayedshader_8000289300.req, captured from a GoY run. A small standalone program then runsvkCreateShaderModule+vkCreateComputePipelinesonce, undersystemd-run --user --scope -p MemoryMax=8G -p MemorySwapMax=0.Why memory drops more than module size. Module size isn't what drives memory. Mesa's
vk_spirv_to_niralways runsnir_inline_functions(src/vulkan/runtime/vk_nir.c, mesa-26.2.4).nir_functions.ckeeps functions only forMESA_SHADER_KERNELwith driver functions. So on lavapipe every helper is copied into each call site, andDontInlinedoesn't survive. Static sizes after full inlining, counted on the two replayed modules:One call is already too many on main. I kept N calls to the helpers and replaced the rest with
OpUndef; each module passesspirv-val. Results on main's own module:_x4call: 6.2 GB, 50 s. One_x1call gives the same.So cutting call sites wouldn't have been enough. The helper body itself had to shrink, and that's what this PR does.
Focused tests at the merged head, on lavapipe only: 11/11 pass.
agc_formatted_buffer_once,agc_driver_gpu_buffer_format,agc_driver_buffer_format,agc_shader_memory(including the "BDA read functions" check) andagc_driver_bda_device.agc_driver_scalar_wide_loads,agc_driver_flat_apertures(the whole binary, which includes aperture 0),agc_driver_bda_span_readsandagc_driver_pixel_interlock.agc_driver_flat_loadsandagc_driver_global_loads.agc_driver_gpu_buffer_format, the test the review asked for, now passes on RADV, on both NVIDIA cross-tests and on lavapipe.The
agc_formatted_buffer_oncefailure from the rebase handoff doesn't reproduce once the branch is merged onto0aa4cb1c2. The known-descriptor load is 1,947 words (2,349 for 3 loads), down from blawesom's 26,501. The GPU-selected load is 16,398 (17,254 for 3 loads). That is well inside the/2bound, so the recalibration I suggested earlier isn't needed. Something on main since33ae282e4shrank that path; I haven't bisected it.Not covered: NVIDIA 595+ (with and without SPIRV-Tools, as asked on #3655), RADV, a SPIRV-Tools ON build, and a full GoY game run. This is one shader from one title, with focused tests rather than the full suite.
What would unblock this:
6aaae039, conflicting) needs updating, for example by moving it torebase/3656and merging main.AI-assisted: yes (Claude).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T22:14:37Z.
Follow-up: a full Ghost of Yōtei run on lavapipe with these PRs is no longer killed at the memory cap.
Earlier runs (without these PRs). The game was killed (exit 137) under a 22 GB cap. In an instrumented rerun, the last pipeline creation that started and never finished was a 4.1 MB compute shader. Replaying
0x8000289300's captured request on that run's tree gives a byte-identical module, so it is the shader from my comment above.This run (with these PRs merged in). Same title, launch scope and 22 GB cap, with
blawesom:rebase/3656(ed64f3a6e) merged in. It ran to the 900 s timeout and was not killed. It compiled 1,661 shaders. Peak sampled RSS of the game process (every 5 s) was 15,103 MB. Over the last 7 minutes it moved up and down between 12,818 and 15,103 MB.Caveats.
main, plus local run commits. It is notmain.double free or corruption (out)). No run without these PRs got this far, so I can't attribute either yet; I'm looking at them separately.lavapipe 26.2.4, SPIRV-Tools OFF. Details of the shader-level measurement are in my comment above.
AI-assisted: yes (Claude).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T22:15:47Z.
Rebased onto main now that #3655 is in; tests pass.
Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-15T07:20:26Z.
Thanks @oneandonlydean for the rebase and merge, and @Dextroid17 / @blawesom for the lavapipe numbers and the conflict report.
For the record, the recalibration Dextroid17 described was not needed on the final rebase. I rebased the same two commits onto
a050f856flocally, and main's unchangedFormattedBufferOncecheck passes there:1947 words for 1 load, 2349 for 3; GPU-selected 16398 and 17254, soone.words < gpuOne.words / 2uholds (1947 < 8199). The 26501 in blawesom's report came from a rebase on an older base (33ae282e4, see Dextroid17's comment).On that tree, 1172/1188 ctest pass on an RX 9070 XT (RADV, Mesa 26.2.4); 14 are skipped. The two failures,
agc_host_import_sparseandagc_driver_tessellation(a segfault inside RADV duringLinkPipelineFromLibraries), fail the same way ona050f856fwithout this PR.Tested and written by Claude (AI assistant) on a contributor's machine; Gemini ran the build and full ctest. AI-assisted: yes.