Repository navigation
fix(shader): decode a GPU-selected formatted load from a format table - #3656
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
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:
- No test pins the values of the new path.
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.
|
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,
|
|
The equivalence claim here is structural, and I checked the old shape rather than take it on trust. On formatted(context, instruction, resource,
GetFormatInfo(static_cast<IrBufferFormat>(index + 1u)), components, store, data);One The contract the switch's default carried is preserved, verified on 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 ( The word budget is the right shape of guard. 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 ( Two things worth writing down before merging.
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 Written with AI assistance. |
|
@adriadam10 thanks. Added The shader loads the V#'s
The expected values were captured from the switch at 2d3a970 (#3655 only). They are identical, bit for bit, to the table's output. Corrupting one bit offset in Linux, RX 9070 XT, Mesa 26.2.4 RADV: the new test passes, and Tested and written by AI assistants (Claude and Gemini) on a contributor's machine. |
|
Windows/Blackwell cross-test: #3655 2d3a970 + #3656 369928d/6aaae039 applied cleanly on our007 runtime-image-table integration, public combined head bc46e2d: 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). |
|
NVIDIA cross-test of #3655 and #3656 (2d3a970, 369928d, 6aaae03) 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 62f8758 + 82 commits, not current main. Method.
Results.
Neutral for 007 on NVIDIA. AI-assisted: yes (Claude Code) |
|
Rebase handoff + one open finding — rebased onto current The finding: after the rebase, The failing check is main's (from Everything else: builds, conventions pass, full suite 953/954 (only this test). To pick it up: Head is |
|
The check is a relative bound, so the calibration is the side that should give — the decode does not need to. On
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. |
|
lavapipe measurement: with #3655 + #3656, pipeline creation for one Ghost of Yōtei compute shader ( What was tested. blawesom's rebase: #5022 is preserved. Setup. lavapipe 26.2.4, CachyOS, GCC 16.2.1, Release build, SPIRV-Tools OFF, clean environment with Method. I built Why memory drops more than module size. Module size isn't what drives memory. Mesa's One call is already too many on main. I kept N calls to the helpers and replaced the rest with
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.
The 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:
AI-assisted: yes (Claude). |
|
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 This run (with these PRs merged in). Same title, launch scope and 22 GB cap, with Caveats.
lavapipe 26.2.4, SPIRV-Tools OFF. Details of the shader-level measurement are in my comment above. AI-assisted: yes (Claude). |
* fix(shader): keep each BDA page-table walk to one inlined copy per read RADV inlines every SPIR-V function, DontInline included, so every get_bda_pointer call site becomes its own copy of the page-table search, and NIR's copy propagation of variables grows with each copy. The lookup now keeps its search bounds in phis and records its header and range faults from one call site each, picking the first failing check; a byte read and the byte fallback of a span read loop over one lookup instead of unrolling one per byte or dword. (cherry picked from commit 2d3a970) Ported from upstream PR boykopovar#3655 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): decode a GPU-selected formatted load from a format table A formatted load whose V# is selected on the GPU emitted all 77 format cases in its shared function, and drivers that inline every function, like RADV, copied all of them into each call site. The load now reads the format's component count, widths, byte and bit offsets and type from a constant table and runs one path for its four components, with the existing conversion of each (type, width) pair selected at run time. Stores and loads through a prepared V# keep the format switch. (cherry picked from commit 369928d) Ported from upstream PR boykopovar#3656 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(shader): pin GPU-selected formatted loads for every buffer format agc_driver_gpu_buffer_format loads the V#'s records and word3 from memory and moves them into SGPRs with v_readfirstlane, so the recompiler sees a GPU-selected descriptor and the load goes through the format table. It checks buffer_load_format x/xy/xyz/xyzw and d16_xyzw on two lanes for formats 1-77, selectors 0/1/4-7 on 1-, 2- and 4-component formats, loads with a component past NUM_RECORDS, and that formats 0 and 78 stop the invocation before its stores. The expected values were captured on the format switch (2d3a970) and are identical with the table. (cherry picked from commit 6aaae03) Ported from upstream PR boykopovar#3656 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): try the last resolved range first in BDA lookups Every access by guest address calls a lookup that binary-searches the BDA range table: about 11 dependent steps over ~1200 ranges, 34 table loads per access. Since boykopovar#639 every buffer access goes through it. The lookups (read, probe, write and atomic) now keep the last range a search of the invocation resolved in four private variables: guest begin and end, device base and permissions. An access inside that range with the wanted permissions returns base + (address - begin) at once. Anything else (another range, a missing permission, an unmapped, zero-byte or wrapping access) takes the full search with every check and fault it records today, and a successful search refills the cache. The variables only hold what the table says, and no shader writes the table, so the result is the search's own answer. On one title's busiest scene (Windows, discrete GPU), GPU time of the draws 59.5 -> 35 ms per frame. APS5_NO_BDA_LOOKUP_CACHE=1 emits the lookups without the cache. The switch is part of the shader disk cache key. (cherry picked from commit 443583a) Ported from upstream PR boykopovar#2837 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(shader): read adjacent BDA dword loads of one block through one span read A scalar load of several dwords (s_load_dwordx8) becomes one LoadAddressU32 per dword, and each took its own span read: a probe of the page table and a fallback that looks every byte up. Loads in one block with equal address operands and offsets within 16 bytes of the first now share its span read. Instructions that write memory end a group; the address operands are compared by content, since each load carries its own GetAddressResource and SelectU32 values. A title's main-menu pixel shader goes from 136 span reads to 34. AMD's Windows compiler inlines the read helpers at every call, and did not finish that shader before. (cherry picked from commit 4577633) Ported from upstream PR boykopovar#4931 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(shader): read GPU-selected V#s of s_buffer_load as SMEM does An s_buffer_load_dword* whose V# the recompiler reads at run time (a GPU-selected V#, for example one built with v_readfirstlane) went through the vector buffer descriptor checks. A nonzero TYPE in word 3 made it return 0 and record an invalid-descriptor fault, and the base was used with its two low bits, so a base off a dword boundary read shifted bytes. SMEM uses only the base, stride and num_records of the V#, and the two low bits of the base and of the final address are ignored (AMD RDNA2 ISA guide, 30 November 2020, section 7.1 Table 27 SBASE and section 7.2.1 "Reads using Buffer Constant"). The capture-time evaluator already follows both rules, and the bound path already drops the two low bits. For scalar buffer loads the runtime path now masks the base and skips the TYPE check; vector, formatted and atomic accesses keep it. agc_driver_scalar_buffer_gpu_descriptor runs s_buffer_load_dword and s_buffer_load_dwordx2 through such a V# with the base 0 to 3 bytes off a dword and TYPE 0 to 3, in wave32 and wave64. (cherry picked from commit 86fdb52) Ported from upstream PR boykopovar#5161 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(recompiler): read the buffer stride and presence at run time in compute modules (cherry picked from commit 573ba3b) Ported from upstream PR boykopovar#5353 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: EdouardSence <103503538+EdouardSence@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: DotDebian <quentin.waguet@hotmail.fr> Co-authored-by: poonasor <rickypoon89@icloud.com> Co-authored-by: Niko <nikobilger2000@gmail.com> Co-authored-by: Alex Collini <pipodi93@gmail.com>
A formatted load whose V# is selected on the GPU emitted all 77 format cases in its shared function, and drivers that inline every function, like RADV, copied all of them into each call site. The load now reads the format's component count, widths, byte and bit offsets and type from a constant table and runs one path for its four components, with the existing conversion of each (type, width) pair selected at run time. Stores and loads through a prepared V# keep the format switch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
agc_driver_gpu_buffer_format loads the V#'s records and word3 from memory and moves them into SGPRs with v_readfirstlane, so the recompiler sees a GPU-selected descriptor and the load goes through the format table. It checks buffer_load_format x/xy/xyz/xyzw and d16_xyzw on two lanes for formats 1-77, selectors 0/1/4-7 on 1-, 2- and 4-component formats, loads with a component past NUM_RECORDS, and that formats 0 and 78 stop the invocation before its stores. The expected values were captured on the format switch (2d3a970) and are identical with the table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Gemini <noreply@google.com>
|
Rebased onto main now that #3655 is in; tests pass. |
6aaae03 to
f1c786d
Compare
Met: f1c786d pins the GPU-selected formatted load values for every buffer format.
|
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 On that tree, 1172/1188 ctest pass on an RX 9070 XT (RADV, Mesa 26.2.4); 14 are skipped. The two failures, Tested and written by Claude (AI assistant) on a contributor's machine; Gemini ran the build and full ctest. AI-assisted: yes. |
Adopt EdouardSence's compact table for GPU-selected formatted loads. Retain prepared-descriptor loads and stores on their existing format switch, with the local direct-buffer byte-write path preserved. Keep descriptor, bounds, address-overflow and BDA fault checks intact. Source: boykopovar#3656 Donor commit: 369928d
What
Follow-up to #3655, for the same stop: Ghost of Yōtei (PPSA26344) compute shader
0x8000289300exhausts memory invkCreateComputePipelineson RADV, onmaina11c8f7 with #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 fix(shader): keep each BDA page-table walk to one inlined copy per read #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