feat(shader): opt-in run-time dword 3 for formatted compute buffers #28390
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28390"
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 zeezey on 2026-11-30T11:10:35Z.
What
Extends #28295 (head
6e337d6e8e, on #28102's headd9149614af) to formatted compute buffers, behind two opt-in switches, both off by default. With neither set, every module is the one #28295 builds (the default-switch modules of thetbuffer_*probe below have the same content hash as on6e337d6e8e). #28295 reads V# dword 3 (the format, the DST_SELs, the index stride, the thread-id addition and the bounds mode) at run time only for a direct compute buffer the program reaches through raw accesses; a buffer with any formatted access keeps it a specialization constant. On #27759, the repeat builds of the largest compute programs namebuffer[N].word3going from 0 (a null V#) to a bound one-channel format on three slots, next to image fields; that boot already had #28295, so these are most likely slots with formatted accesses. This PR adds the buffer part in two tiers:APS5_RUNTIME_TYPED_BUFFER_FORMAT=1: buffers whose only formatted accesses aretbuffer_*. This coverstbuffer_load_format_*andtbuffer_store_format_*alike, and a buffer the program stores to or updates atomically as well as a read-only one. Those accesses take their format from the instruction and ignore the V#'s DST_SELs, so their dword 3 only feeds what it feeds for a raw buffer: the index stride, the thread-id addition, the bounds mode and the check that the format field is not 0. With the switch such a buffer reads dword 3 from the V# like a raw one and keeps its module across bounds modes and across null and bound V#s.APS5_RUNTIME_FORMATTED_BUFFER_FORMAT=1: buffers withbuffer_load_format_*accesses that the program never stores to or updates atomically. Their loads already go through a shared function that is not inlined (one per buffer and load shape) and that decodes any format from per-format constants it selects with the format field (genericFormattedLoad); with a constant format the specializer folds that selection to the one format. With the switch the format stays a run-time value, so no field of the buffer's dword 3 is in its module (the tests check that it keeps its module across formats and across null and bound V#s), and the function keeps the decoder of every format:agc_formatted_buffer_once's module with one such load grows from 2,486 to 5,311 SPIR-V words (a GPU-selected descriptor needs 9,080). That test only checks by default that the folded size is under half the GPU-selected one; every driver that inlines the function copies it into each caller, and the driver compile time is not measured. These numbers were taken at954c455293; the commit after it does not touch this tier.A buffer with a
buffer_store_format_*access keeps the constant in every state, since a direct formatted store picks among every format's conversion with a switch that only a constant format folds away; so does a buffer withbuffer_load_format_*accesses that the program also writes.APS5_NO_RUNTIME_BUFFER_FORMATandAPS5_NO_RUNTIME_BUFFER_WORDSoverride both switches. Graphics stages are unchanged.Why the
tbuffer_*tier is opt-in. The first version of this PR (4579af4b12) made it the default. A tester on #27914 booted PPSA38500 on an RTX 3070 under Windows with the default 2 s GPU timeout (TdrDelay): with that default on, 5 of 5 boots lost the device at indirect compute dispatches in a heavy streaming phase, between 39,200 and 46,400 dispatches; a boot with only that tier switched off (APS5_NO_RUNTIME_TYPED_BUFFER_FORMAT=1) passed that window and was still running at 47,900. A review of the code found no address or bounds difference between the run-time and the folded path, and everytbuffer_*access is bounds-guarded in both. The leading explanation, not shown, is that the run-time fields make these dispatches slower and a long one crosses the 2 s timeout. The measurement below shows the run-time fields cost GPU time on a synthetic kernel; it does not show the timeout. So the tier is off by default, like the formatted one, and the debt entry added here says so.APS5_NO_RUNTIME_TYPED_BUFFER_FORMATis removed: with the tier off by default it could only override the opt-in, and a run that still sets it gets the default, which is what it asked for.The decision is one function,
PipelineSpecialization::RuntimeBufferFormat, which for a compute module (never built in registration form) the plan (DescriptorBindingBuilder::Prepare) and the emitter (SpirvRuntimeBuffer.cpp) both ask with the same three facts about the buffer, so a module never reads a constant the plan does not give.Preparestill checks each dispatch's V# format and DST_SELs where it did before. No new specialization constant ids and no cache format version change; both switches are part of the shader disk cache key, since the key holds everyAPS5_*name the recompiler's sources read that is not inNeutralSwitches, andagc_shader_disk_cachechecks that a specialized module stored without either switch is not loaded with it.This PR alone does not remove that title's repeat builds, with either switch. The 17 repeat builds reported on #27759 also differ in
image[2]'s mode and components, which stay specialization constants here (#28228 makes the components run-time data, not the mode). anova44 measured it on #27759 (issuecomment-7286565111, two boots of a stack with954c455293, so with thetbuffer_*tier on): none of the 65 repeat builds differs inbuffer[N].word3alone. Every one also differs in an image mode, andword3still differs in 64 of the 65. They are null-and-bound transitions:buffer[4/12/13].word30 -> a format withimage[2].mode0x18 -> 0 (33), andbuffer[4].word3a format -> 0 with animage[N].mode0 -> 0x2c (31). So those buffer slots are nottbuffer_*-only, and since the image mode differs in every pair, the second build stays even ifAPS5_RUNTIME_FORMATTED_BUFFER_FORMATfolds theword3part away. Our own two boots ofmainwith our open pull requests showed the same:buffer[4],buffer[12]andbuffer[13]still named with the tier on. What this PR offers is the mechanism: the two opt-ins, and the null, bound, bounds-mode and every-format cases its tests check.Three commits on
6e337d6e8e:4579af4b12fix(shader): read dword 3 of formatted compute buffers at run time: the two tiers, with thetbuffer_*one on by default andAPS5_NO_RUNTIME_TYPED_BUFFER_FORMATto turn it off; theENVIRONMENT.mdrows, the debt entries in #28102's pending fragment, and the two test expectations it moved (agc_driver_buffer_unaligned_base,agc_formatted_buffer_once).954c455293test(shader): check formatted compute buffers across null and bound V#s:agc_driver_null_buffer_specializationdispatches three more compute slots null and bound, in its direct, captured and prepared modes, and checks the data and the module of each dispatch: a read-onlytbuffer_load_format_xslot (null V#s of five kinds, bound, bound with the records-only bounds mode, bound with another format in dword 3, which the instruction's format overrides), atbuffer_store_format_xslot (the null stores leave memory alone), and a read-onlybuffer_load_format_xyzwslot bound as 32_UINT, 16_UINT and 32_FLOAT with DST_SEL X,0,0,1.agc_driver_buffer_format --every-format <first> <last>loads every buffer format (1 to 77) withbuffer_load_format_xyzwandbuffer_load_format_d16_xyzwthrough a read-only V# and, in a second program, through a V# of the same memory that the program also stores to, and compares the results. UnderAPS5_RUNTIME_FORMATTED_BUFFER_FORMAT, which its two registrations (formats 1 to 38 and 39 to 77) and one more run of the existing test use, the read-only V#'s format is read at run time and the other's stays a constant; the test also checks that the read-only program keeps one module for every format.agc_formatted_buffer_onceruns under the formatted opt-in, andagc_shader_disk_cachechecks the new switches against the key.c54379f5b5fix(shader): make run-time dword 3 of tbuffer compute buffers opt-in:APS5_RUNTIME_TYPED_BUFFER_FORMATreplacesAPS5_NO_RUNTIME_TYPED_BUFFER_FORMAT(in the function,ENVIRONMENT.md, the debt fragment and the tests), and the two tests whose default expectation changes expect #28295's modules again by default and the run-timetbuffer_*fields under the opt-in:agc_driver_null_buffer_specialization's twotbuffer_*slots get one module for null and bound V#s and for both bounds modes only under the opt-in, and a module per state otherwise. It runs under each opt-in alone, under each opt-in withAPS5_NO_RUNTIME_BUFFER_FORMATand withAPS5_NO_RUNTIME_BUFFER_WORDS, and under both opt-ins together.agc_driver_buffer_unaligned_baseexpects its twotbuffer_*-only buffers to keep the module after another bounds mode only under the opt-in; it runs under the opt-in alone and withAPS5_NO_RUNTIME_BUFFER_FORMAT.agc_shader_disk_cachechecksAPS5_RUNTIME_TYPED_BUFFER_FORMATin place of the removed switch.tbuffer_*tier, and the null-and-bound entry back to #28295's text.agc_formatted_buffer_once,agc_redundant_value_eliminationandagc_subgroup_barrierhave notbuffer_*access, so their expectations do not change.#28295's and #28102's heads are
6e337d6e8eandd9149614af.GPU time of the
tbuffer_*tier, on and off. Not taken withAPS5_PROFILE_GPU: a small test program (not in this PR) that recompiles and dispatches one compute program on the RTX 4090 and times each dispatch on the CPU, from the submit to the end ofWaitIdle, so the times include submission. Each program has onetbuffer_load_format_*loop of 1,024 iterations of 4 loads from one buffer, 64 threads per group; the write kernel adds onetbuffer_store_format_*per iteration to a second buffer. 4,096, 16,384 and 65,536 groups, 30 timed runs after 2 warm-ups per setting and size, the whole grid run in two separate processes per setting (medians below are the two processes'). Both settings run in one build ofc54379f5b5; the module with the tier off has the same content hash as on6e337d6e8e, and the one 16,384-group pair run on6e337d6e8e(5 runs per kernel) gave a read median of 8.10 ms (this head, tier off: 8.09 to 8.18) and a write median of 58.7 ms with a spread of 52 to 62 ms (this head, tier off: 62.7 to 62.9).The two numbers in a cell are the two processes. The tier costs 24% to 47% on a read-only kernel built from nothing but these loads, and 3% to 13% when each iteration also stores. This is the most extreme case (the loads are the whole kernel) on one GPU and one driver, with a dispatch of at most 0.26 s; the title's compute programs are not measured, and no kernel here approaches the 2 s timeout, so the measurement neither confirms nor excludes it as the cause of the lost device.
Tested
Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release,
-DBUILD_TESTING=ON -DANYPS5_RELINKER_CLI=ON -DANYPS5_VIDEO_OUT_TEST_DRIVER=windows, NVIDIA GeForce RTX 4090 (driver 621.24), Khronos validation layer from Vulkan SDK 1.4.363. Every Windows test run below hadANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, on a PC where other builds and tests ran at the same time. The runs of6e337d6e8eused builds of that commit with the same toolchain and the options above. All of it is at headc54379f5b5.Complete
ctest(no-R,-j 4),6e337d6e8eand then this head:6e337d6e8eVUID-,SYNC-HAZARD, layer "was not found"The 14 added tests are the new registrations (each passed). Failures:
agc_driver_linear_target_import_creation.agc_driver_draw_recipe_data,agc_driver_idle_store_resumes,guest_file_lock_queued_upgrade,guest_pthread_mutex_contention. Flakes of the parallel run.6e337d6e8e:test_executable_manifests(5 of 5 alone on6e337d6e8e; it passed on this head).The tests around the change, every
agc_test matchingbuffer|format|null|specializ|descriptor|typed|tbuffer|word3|stride|disk_cache|redundant_value|subgroup_barrier|table_call|scalar_buffer|spirv_module|fold|bda(196 tests),ctest -j 4, with the switch unset and withAPS5_RUNTIME_TYPED_BUFFER_FORMAT=1: unset, 196 of 196 passed, layer inserted in 149, VUID 0. Set, 195 of 196 passed; the one failure isagc_shader_disk_cache, which stops at "cannot read the specialized entry back" whenever a switch that is part of the disk cache key is set (it opens its stored entry at a file name made from the key without the switches). On Linux,APS5_NO_RUNTIME_BUFFER_FORMAT=1andAPS5_NO_RUNTIME_BUFFER_WORDS=1fail it the same way on6e337d6e8etoo;APS5_RUNTIME_TYPED_BUFFER_FORMAThas no effect on6e337d6e8e's key, so there it passes. The other 195 passed under the opt-in on Windows (all 194 others on Linux; 2 of its tests are skipped in every run).Repeats: the 29 tests of the five test programs this PR changes (including every registration with a switch:
frozen_buffer_*,runtime_typed_buffer_format*,runtime_formatted_buffer_format*andruntime_typed_and_formatted_buffer_format, andagc_shader_disk_cache), five times in a row each, one at a time, with the validation layer: 5 of 5 runs passed on Windows (layer inserted in 130 of 145 runs, VUID 0, SYNC-HAZARD 0, longest test 8.8 s) and 5 of 5 on Linux (layer in 130 of 145, VUID 0, SYNC-HAZARD 0, longest 3.3 s).Lavapipe: Ubuntu 24.04 (a chroot in WSL 2), GCC 13.3.0, Ninja, Release, configured as the CI Linux job (
-DANYPS5_ENABLE_SPIRV_TOOLS=ON,GALLIUM_OVERRIDE_CPU_CAPS=avx), lavapipe from Mesa 25.2.8 (llvmpipe, LLVM 20.1.2), Khronos validation layer from Vulkan SDK 1.4.335, the same four variables.ctest(no-R): this head 7343 tests (7116 passed, 219 skipped, 8 failed),6e337d6e8e7329 (7103 passed, 219 skipped, 7 failed); layer inserted in 1692 (base 1679), VUID 0, SYNC-HAZARD 0, "was not found" 0 on both. Seven failures are on both sides (agc_driver_flat_aperture_lds_bounds,agc_driver_gcn_multisample_color_fill,agc_driver_image_d16_load,agc_driver_image_filter_mode_three,agc_driver_image_sample_lod_clamp_shader_lane,agc_driver_upload_cache_read_only_flush,agc_driver_write_back_guest_newer). The eighth,agc_driver_msaa_resolve_publication_order, is flaky on both: alone, 2 of 5 passed on this head and 2 of 5 on6e337d6e8e.APS5_RUNTIME_TYPED_BUFFER_FORMAT=1, 194 passed and the sameagc_shader_disk_cachefailure was the only one.NVIDIA validation gate:
tools/vulkan_validation_gate.pywith6e337d6e8eas the baseline and this head as the candidate, both built from clean trees,--repeat 5 --test-timeout 30 --gpu NVIDIA, on theagc_drivercompute, dispatch, buffer, format and descriptor tests that both commits register, that inserted the layer and passed in both complete runs, and whose CTestTIMEOUTis within the gate's 30 s cap (the longer ones were left out of the gate and are covered by the complete runs above). Result: exit 0, 10 of 10 iterations clean (baseline 5 of 5, candidate 5 of 5), 233 tests, 2,330 test runs, failed or skipped 0, new diagnostics 0, layer missing 0.python3 tools/check_conventions.py --base 6e337d6e8e --head HEAD,python3 tools/debt_fold.py --check,python3 tools/env_reference.py --check, the privacy grep and the merge with the newestmainpass inprepush.shon the final title and this body (the overlap check is not part of that run).buffer_load_format_*); the GPU time of the title's own compute programs; other GPUs; macOS.Checklist
6e337d6e8e, not on currentmain(see Depends on); 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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T11:12:07Z.
Review: COMMENTED
Reviewed — comments
The targeted code review found no verified blocking defect, but I did not read every changed file or run the reported checks, so approval is not justified.
What I ran
No commands were run. I reviewed head
954c455293d98993fab557078eb30640218027ffusing the prepared review bundle andrepo_read.py.Results
Findings
Blocking
None verified in the code reviewed.
Non-blocking
None.
Not verified
I read
description.md,commits.md,manifest.json,diff.patch, and targeted repository context forDescriptorBindingBuilder.cpp,PipelineSpecialization.hpp,SpirvRuntimeBuffer.cpp, andRecompiler.cpp. The other included changed files were not read.ShaderMemory.cppwas excluded from the review folder as too large, and the deletedNullBufferSubstitutes.cpphas no head text to read. I did not run tests or independently verify the author-reported results.To get this to a good state
Nothing is required. Optional: complete review of the unread changed files and independently run relevant checks before requesting approval.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T17:26:10Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
c54379f5b50c790b536c4ee0baab9c01e0a8a45e. I inspected the prepared description, commit list, manifest, targeted diff hunks, and selected source ranges withrepo_read.py. I did not run tests or builds; the test results in the description are author-reported.Results
Negative control
Not run; no tests were executed during this review.
Findings
Blocking
None identified in the inspected ranges.
Non-blocking
No code-specific optional changes identified in the inspected ranges.
Sources
Not verified
This review is incomplete: I did not read every changed line in the files listed as reviewed in
manifest.json. The full text forShaderMemory.cppwas not included infiles/;NullBufferSubstitutes.cppwas deleted. I inspected only selected ranges of the repository files throughrepo_read.py. Tests, builds, and author-reported results were not independently verified.To get this to a good state
Nothing is required. The review remains a comment because the changed code was not fully inspected.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T17:31:13Z.
Review: COMMENTED
🏛️ Architecture findings (1)
Advisory architecture findings (1)
💬 Code review
460de6c7-d2cf-4833-80f8-0a020ca9a319Reviewing files that changed from the base of the PR and between
954c455293andc54379f5b5.core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_buffer_unaligned_base_tests.cmakecore/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_null_buffer_specialization_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/BufferUnalignedBase.cppcore/libs/prx/libSceAgcDriver/tests/execution/NullBufferSpecialization.cppcore/shader/recompiler/PipelineSpecialization.hppdocs/dev/ENVIRONMENT.mddocs/dev/debt/changes/shader-pipeline-variant-identity.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:21:11Z.
Review: COMMENTED
The typed-format switch is already reported to fail
agc_shader_disk_cachebecause the fixture opens the entry using a filename computed without the selected switches. Could the fixture use the same path/key builder as the writer and add a seeded warm lookup with the typed switch set? This change adds the switch to the disk key, so that case would directly verify that supported configuration can load what it writes.Source review at
c54379f5b5. Paired Vulkan execution is pending.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.