fix(shader): read zeros through a V# with DATA_FORMAT INVALID #21977
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21977"
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-17T00:26:13Z.
What
A formatted buffer access (
buffer_load_format_*,buffer_store_format_*) through a V# whose data format is 0 madeDescriptorBindingBuilder::Preparethrowbuffer specialization has an unsupported formatwhenever the descriptor was known. On GCN that format isINVALID, andGcnBufferWord3maps every GCNDATA_FORMAT0 to format 0.AMD's GCN3 ISA guide (rev 1.1) defines what such a V# does:
shadPS4 does the same at
143b58aa48(LowerBufferFormatInst,src/shader_recompiler/ir/passes/lower_buffer_format_to_raw.cpp): whendata_format == AmdGpu::DataFormat::FormatInvalid, a load is replaced withCompositeConstruct(0, 0, 0, 0)and a store is invalidated.The emitted shader already handles format 0 this way. In
formatSwitch(SpirvRuntimeBuffer.cpp), loads and GPU-descriptor stores testformat == 0directly and return zeros or write nothing; a store without a GPU descriptor reaches the switch's default label, which also writes nothing. Only the builder's extraknown && format == 0refusal stood in the way, so this PR removes it. Formats aboveFormat32_32_32_32Floatare still refused. Alignment for format 0 stays at the buffer's typed alignment, because nothing is read or written.Two other paths still treat format 0 as an error, and the debt fragment records them: a V# the shader loads from memory at run time (it records an
InvalidDescriptorfault), and a formatted access whose word 3 is a constant (it throws). Neither is reached by the title below.The test
GcnInvalidBufferFormat.cppdispatches a GCN compute shader that runsbuffer_load_format_xyzwandbuffer_store_format_xyzwthrough a user-data V#. A control V# (DATA_FORMAT14,NUM_FORMAT4) must load the resident words and store the new ones. ForDATA_FORMAT0 with eachNUM_FORMAT0-7, the load must return zeros and the buffer must stay unchanged.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, using LunarG layer 1.4.363.1 throughVK_ADD_LAYER_PATH:ctest -R '^agc_driver_(gcn_invalid_buffer_format|gcn_buffer_format_lookup|buffer_format|runtime_formatted_store.*|null_buffer_substitutes|buffer_descriptor_runtime|buffer_load_store.*)$' -Vmain+ the new test: 15/16 pass.agc_driver_gcn_invalid_buffer_formatfails withShaderRecompiler::Recompile: buffer specialization has an unsupported format, the same message the title stops on.This change: 16/16 pass.
Validation layer: both logs contain 16
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
DescriptorBindingBuilder.cpp,SpirvRuntimeBuffer.cppandRecompiler.cppare identical tomain's.Title: Bloodborne CUSA00900 01.09 (my own copy), on
mainplus #17105, #17711, #20156, #21944 and #21969. Before this change, 3 of 3 runs stopped about 1.7 s in atcompute shader 0x2d1f00900: buffer specialization has an unsupported format. Its sixth dispatch binds V# words3983bd40 00040002 00000001 00001f2e:NUM_FORMAT1,DATA_FORMAT0.unsupported format. The title kept dispatching0x2d1f00900, presented about 18 frames a second for a minute, and reached the next stop at 63 s, which is unrelated to this change. The game's ownDantelion2 PanicreportedPthreadMutex.cpp(130) Logical Error. Invalid mutex.(EINVAL)on a newMv_AudioPlayThread.Tested by @tablefrogpillow on
d5cbab44: passes with 0VUID-on RX Vega 56 (RADV gfx900, GCN5), the Ryzen 7000 iGPU (RADV gfx1036, RDNA2) and RX 7900 GRE (RADV gfx1100, RDNA3). It failed on lavapipe: the control V# load returned the stored words0x11111111 0x22222222 0x33333333 0x44444444. The cause was the test, not the change: all 64 invocations loaded and stored the same four words, and lavapipe runs the workgroup's subgroups one after another, so later invocations read what earlier ones had stored.35a9c44c9ce(the test dispatches one invocation): same machine and layer,ctest -R '^agc_driver_gcn_invalid_buffer_format$' -V. Change: passes 5 of 5 (--repeat until-fail:5). Control (main'sDescriptorBindingBuilder.cpp+ this test): fails withbuffer specialization has an unsupported format. Both logs:Insert instance layer "VK_LAYER_KHRONOS_validation"on every run, nowas not found but was requested by env var VK_INSTANCE_LAYERS, nofailed to load, noVUID-. Not rerun on lavapipe here.Tested by @tablefrogpillow on
35a9c44c: passes on lavapipe with 0VUID-, and still passes on the Ryzen 7000 iGPU (RADV gfx1036, RDNA2) and RX 7900 GRE (RADV gfx1100, RDNA3).3b0e22c1(adds<optional>and<exception>to the test, from review): same Windows machine and environment,-R '^agc_driver_gcn_invalid_buffer_format$'. This change 3/3 pass; control (DescriptorBindingBuilder.cppfrom the base78880af3f70) fails withbuffer specialization has an unsupported format. Every log has 1Insert instance layer "VK_LAYER_KHRONOS_validation", nowas not found, nofailed to loadand noVUID-.Tested by @domx4q on
3b0e22c1(merged onto mainf0c01bc69d): Arch Linux, GCC 16.2.1, RTX 4090 (Ada), driver 620.70.06, Khronos layer 1.4.363.1,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, same ctest pattern: 16 of 16 pass (main 15 of 15;agc_driver_gcn_invalid_buffer_formatis new). Nowas not found, 0VUID-on both.Tested by @Jitheswar on
3b0e22c1(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: 16 of 16 pass (main 15 of 15;agc_driver_gcn_invalid_buffer_formatis new), the layer loads in every run, nowas not found, 0VUID-(comment).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 --branchreports #21199 (RDNA V#TYPE2/3) as a textual conflict on the same line. It adds an RDNA-only condition in front of the same check, so the two compose. It could not compare 16 conflicting PRs that touchDescriptorBindingBuilder.cpp: #5371 #5609 #6280 #6412 #7642 #7689 #9852 #9897 #10193 #13928 #13929 #14032 #14944 #20030 #20130 #20248. I read their diffs. None changes this refusal. #14944 skips format 0 in its own read-extent helper, which is consistent with this change.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-17T04:07:49Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
35a9c44c9cefd7d213201071391d27f979cbe985, basemain.repo_read.py.GcnInvalidBufferFormat.cpp(new file, whole text from the diff),fix-shader-invalid-buffer-data-format.md(whole text from the diff),DescriptorBindingBuilder.cpp(the changed line and lines 440–520 at head; the rest not read).files.json: 3 of 3 read.Results
Findings
Blocking
None.
Non-blocking
formatSwitch"has no case for 0, so its default branch returns zeros and writes nothing". The outcome is right, but the mechanism is different: the load path testsformat == 0directly (core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:784), and only the store path without a GPU descriptor reaches the switch's default label (SpirvRuntimeBuffer.cpp:823–830). Suggest rewording the description to match. The removed refusal is atcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp:487.core/libs/prx/libSceAgcDriver/tests/execution/GcnInvalidBufferFormat.cpp:91usesstd::nulloptand:127usesstd::exception, but the file does not include<optional>or<exception>. It compiles today through other headers; the includes would make it self-contained.Sources
Not verified
mainplus the new test, 16/16 with the change, 5/5 repeats, and the lavapipe, RADV gfx900, gfx1036 and gfx1100 reports from the description) are not reproduced.Codearray and the V# word layout inDescriptor()were not decoded.tools/debt_fold.py --check, andtools/pr_overlap.py: not checked.## add Unknown function info: a search ofdocs/dev/debt/changesfor level-2 headings found nothing, so the heading convention is not verified.To get this to a good state
Nothing is required.
Optional: reword the
formatSwitchsentence in the description and add the two includes to the test.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T06:05:58Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head
3b0e22c112a028a63411a8bb937c91e30e6aa64b, basemain. No build and no test run in this pass. Repository reads went throughrepo_read.py:Files read: 3 of 3 in
files.jsonunderreviewed. The new test file and the debt note were read through the diff, since both are new and the diff shows them whole.DescriptorBindingBuilder.cppwas read at head lines 420–500 (of 855) and through the diff. Excluded by rule: none.Results
formatSwitchtests/execution/*.cppFindings
Blocking
None.
Non-blocking
core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp:487: the removed check also refused a format 0 buffer whose word 3 is a constant (fields.known). The debt note atdocs/dev/debt/changes/fix-shader-invalid-buffer-data-format.md:5says that case "still throws". I found no other buffer refusal of format 0 incore/shader, so either that case now takes the zero path without a test, or the throw uses wording I did not search for. The new test only covers user-data V#s.Sources
formatSwitchPrepare, changed lineNot verified
3b0e22c1were not visible in this pass, so the approval rules do not allow APPROVE. Approval can follow once they have passed.143b58aa48and the GCN3 ISA sections cited in the description. These are outside the repository.DescriptorBindingBuilder.cpp. The description reports it, and I did not repeat it.To get this to a good state
Nothing is required. The optional point is the non-blocking finding above: add a constant word 3 format 0 case to the test, or correct the note at line 5 of the debt file.