fix(shader): keep the destination of a buffer load through a TYPE 2 or 3 V# #21199
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21199"
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 edubox on 2026-11-15T23:33:03Z.
What
A vector buffer load through a V# whose TYPE (word 3 bits 30-31) is 2 or 3 used to throw
buffer descriptor uses an unsupported type. The firmware measurement in the technical debt says the console does the opposite: such a load leaves the destination VGPR unchanged and does not fault (a null V# cannot reproduce that, which is why the host threw).This change implements that:
LoadBufferU8/U16/U32/x2/x3/x4) carry one more operand, the value the destination register held before the instruction.TranslationContext::bufferPreviousValuetakes it from the register the same instruction writes; the translation inserts it before the existing EXEC operand, soArgumentCount() - 1still names EXEC everywhere.EmitRuntimeBufferLoadselects that value when the descriptor's TYPE is non-zero, and leaves every other path untouched.The two litmus tests in
BufferDescriptorRuntimechange with the behaviour: a type-1 descriptor still has to be refused, and a type-2 and type-3 descriptor with a valid format now have to leave the destination as it was (the probe reads the loaded value into a register that already holds a value, and the valid case still reads the buffer).Tested
Linux x86-64 (CachyOS), GCC 16.2.1, Release, RTX 4080 SUPER,
ANYPS5_REQUIRE_VULKAN=1:agc_driver_buffer_descriptor_runtimepasses, including the new type-2 and type-3 preserve cases (a descriptor with a valid format now leaves the destination as it was, where a type-0 descriptor still reads the buffer).shaderctest selection passes (118/118), includingshader_ir_use_rewrite,shader_ssa_pass_reads,agc_shader_disk_cache_large_fileand theagc_driver_prepared_shaders*suites.agc_driver_buffer_descriptor_runtime,agc_driver_graphics, theagc_shader_memory*cases and the prepared-shader cases, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationand no newVUID-lines.buffer_d16_previous_value_translationchecks the translation ofbuffer_load_format_d16_xyand_xyzthrough a TYPE 2/3 V#: the preserved value is one halfword per loaded component, taken from the low and high half of each destination VGPR (v2/v3for an odd count). With the old one-dword-per-component value the test fails on the first halfword.Title evidence: The Last of Us Part II Remastered (
PPSA15508, 02.001.010) stopped at 40 s withshader 0x129fc30200 stage 1: buffer descriptor uses an unsupported type (buffer 0 V# ... 8000027d) first used at pc 0x5c, abuffer_load_format_*read through a TYPE 2 descriptor whose other fields are garbage (the decode gives DST_SEL Z = 2, a reserved selector, and FORMAT 0). With this change the same draw compiles and the title runs to the end of a 240 s window with no driver failure; it still shows a black frame and 1.5-2 FPS, so it has not reached a rendered scene.python3 tools/check_conventions.py --base origin/main: 0 errors.Overlap
Another open change defers invalid buffer-descriptor type faults for read-only pixel-stage loads to the moment the shader executes the load, and stops the invocation there. That is a different case from this one: the console measurement this change follows says a load through TYPE 2 or 3 does not fault and leaves the destination as it was, while TYPE 1 faults on every access. Both changes touch
addGuestBuffer,materializeTables,DescriptorBindingBuilderandEmitRuntimeBufferLoad, so whichever lands second has to keep the TYPE 2/3 case out of the fault path.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T04:19:54Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed head is
79666f026ddb9b0a761da03ad645b8e3bbeef42a; no checks were run here, and one non-blocking scope issue is noted below.What I ran
No commands were run. I inspected the prepared diff and changed code at the pinned head; the diff was not fetched again.
Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:1789accepts TYPE 2/3 for any read-only, non-atomic buffer, andcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1040applies the preserve behavior to every buffer load. The change note says scalar loads through these descriptors should still throw, but the acceptance condition does not distinguish scalar loads from vector loads. Consider retaining the prior rejection for scalar loads and adding a regression case.Not verified
ShaderResources.cpphunk. Other portions of that large file and unchanged repository context were not read.To get this to a good state
Nothing is required. The scalar-load scope point is optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T16:45:53Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: fix the translation of D16 buffer loads so it preserves the prior packed VGPR contents for TYPE 2/3 descriptors.
What I ran
Inspected prepared review materials at head
04cbfeca7aa472e7f57d8606d07bf38bee4c0748and targeted repository context throughrepo_read.py. No tests or build commands were run.Results
Findings
Blocking
core/shader/recompiler/Translation/src/MemoryInstructions/BufferInstructions.cpp:117reads the old destination throughbufferPreviousValue, butbufferLoadFormatD16writes the loaded halfwords withwriteRawU32at lines 120–134. That write does not match the raw destination value used for preservation: for a partial final halfword,target.sdwaSel = 4uwrites only the low half of the destination VGPR, while the fallback select returns the entire old 32-bit VGPR. The discarded load must preserve the unaffected half while replacing only the written half, or use a destination value shaped to the instruction's actual write mask. Add a regression case for a TYPE 2/3 D16 load into the partial final destination.Non-blocking
None.
Not verified
No tests, build, GPU execution, or title run were performed.
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwas read through the pinned reader despite being excluded from the preparedfiles/bundle due to size. All changed files listed inreview/manifest.jsonwere read;review/files.jsonwas unavailable as a repository file, so the reader’s file listing was used to confirm the changed-file inventory. Author-reported tests and console measurements were not independently verified.To get this to a good state
Fix D16 preservation to respect SDWA destination writes, then run the affected buffer descriptor runtime tests and shader test selection on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T11:26:38Z.
Review: COMMENTED
Reviewed — comments
This review covers the implementation and selected tests at head
6c5535c2f243af57f0933b6a83dd20409d2fd69d; the reported runs are author-supplied and were not rerun here.What I ran
Read the prepared description, commits, manifest, diff, and targeted source and test ranges. The review reader was pinned to the stated head. No commands or tests were run.
Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1056:preserveskips the TYPE select when the previous-value SPIR-V ID is zero. SPIR-V IDs are nonzero, so this appears safe; however, the guard obscures the intended distinction between “no previous operand” and an operand whose emitted ID is zero. Consider tracking operand presence fromArgumentCount()separately, especially since the new IR metadata makes the previous operand mandatory for these loads.Not verified
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwas excluded from the review folder because of its size; the changedaddGuestBufferlines were read through the pinned reader. Other changed files were read at their added lines, and selected surrounding ranges were inspected.To get this to a good state
Nothing is required. The optional point above is a maintainability suggestion.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:40:52Z.
Review: COMMENTED
Reviewed — comments
Changes are limited to descriptor handling and preserving destination values for RDNA buffer loads through TYPE 2/3 descriptors; I found one issue in the new translation test registration.
What I ran
b46a0b05734bec3047894f6dba34acb5e4bc6088; no merged-preview check was run.repo_read.py.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/BufferD16PreviousValueTranslation.cpp, but its CMake registration uses${LIBS_INCLUDE_DIR}/tests/BufferD16PreviousValueTranslation.cpp(core/libs/prx/libSceAgcDriver/tests/cmake/buffer_d16_previous_value_translation_tests.cmake:2). The declared source path does not match the changed file path, so the new target may fail to configure or locate the test source. Point the registration at the file’s actual location, or move the file to the registered location.Not verified
ShaderResources.cppfull text via the pinned reader; its changed lines are visible in the prepared diff. Other changed files listed as included in the manifest were not all read in full. The new test registration and test source were checked by path/diff, but the source could not be read through the repository reader.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp.To get this to a good state
Nothing is required. The CMake source path mismatch is optional feedback to resolve before relying on the new test target.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T22:23:30Z.
Review: COMMENTED
Actionable comments posted: 3
c66de33a-60f1-4931-b6e6-4d43e477f861Reviewing files that changed from the base of the PR and between
00b15fcbb0andc54d19a350.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/GuardedMemoryLoads.cppcore/libs/prx/libSceAgcDriver/tests/TessellationLowering.cppcore/libs/prx/libSceAgcDriver/tests/cmake/buffer_d16_previous_value_translation_tests.cmakecore/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cppcore/libs/prx/libSceAgcDriver/tests/execution/DrawUnsupportedBufferType.cppcore/libs/tests/BufferD16PreviousValueTranslation.cppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/shader/recompiler/Translation/src/MemoryInstructions/BufferInstructions.cppdocs/dev/debt/changes/fix-shader-buffer-type2-loads.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T22:41:00Z.
Review: COMMENTED
Reviewed — no blocking findings
This review covers the prepared diff at head
c54d19a350990d7a5144c49959101f523adaf756; no checks were run independently, so the supplied test results do not support a formal approval.What I ran
No commands or tests were run. I read the prepared description, commits, manifest, and diff, and inspected targeted source ranges with
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cpp:148).Not verified
The full
ShaderResources.cppfile was excluded as too large; I read the changedaddGuestBufferrange. I read changed hunks and targeted ranges forBufferInstructions.cpp,SpirvRuntimeBuffer.cpp,DescriptorBindingBuilder.cpp,ResourceMaterializer.cpp, and the buffer runtime tests. I did not read every full changed file or run the reported test suites, title, or convention check. The other changed files listed in the manifest were not read in full.To get this to a good state
Nothing is required. Optional: add a runtime assertion for preservation of a nonzero prior destination value.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T17:24:27Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the findings below are optional.
What I ran
Reviewed head
5f0d3ed1ed664a1044c09b94fab1471bd7fb607dusing the prepared diff andrepo_read.py. No commands or tests were run; the test results in the PR description are author-reported.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1128treats a zero-valued previous operand as “no previous value” and skips the TYPE select. Zero is also a valid prior VGPR value, so such a load can still read the buffer instead of preserving zero. Consider distinguishing legacy IR producers from a zero-valued operand by argument count, then selecting whenever the operand exists.Not verified
The full text of
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwas excluded from the review bundle; the changedaddGuestBufferlines were read throughrepo_read.py. All other changed files listed in the manifest were read. Runtime tests, builds, the claimed console behavior, and the disk-cache version change were not independently verified. The review bundle excluded only the oversizedShaderResources.cppfull text.To get this to a good state
Nothing is required. The zero-value preservation case is optional feedback.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T17:29:02Z.
Review: COMMENTED
Actionable comments posted: 2
3a8b3206-e567-4729-b646-91409b668455Reviewing files that changed from the base of the PR and between
c54d19a350and5f0d3ed1ed.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cppcore/shader/recompiler/IntermediateRepresentation/src/IrOpcode.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/InstructionTranslator.cppcore/shader/recompiler/Translation/src/MemoryInstructions/BufferInstructions.cppdocs/dev/debt/changes/fix-shader-buffer-type2-loads.mddocs/dev/debt/changes/fix-type23-multi-dword-stores.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T18:07:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent formatted loads through TYPE 2 or 3 descriptors from faulting on discarded descriptor fields.
What I ran
Reviewed head
f245901a48dd21da17992b4ba39214b3fdce41ec. I read the prepared description, commits, manifest, diff, and targeted source ranges inShaderResources.cpp,DescriptorBindingBuilder.cpp,ResourceMaterializer.cpp,SpirvRuntimeBuffer.cpp,BufferInstructions.cpp, andBufferDescriptorRuntime.cpp. No tests were run. The reader wasrepo_read.py.Results
Findings
Blocking
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1134wraps the formatted load result inpreserve, but still callsformattedDispatch. That function checks reserved selectors and emits an invalid-descriptor fault (core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:833-835). The planner skips selector validation for discarded types (DescriptorBindingBuilder.cpp:543), so a TYPE 2/3 formatted load with a reserved selector can reach this fault path instead of preserving the destination. The description identifies such a descriptor as the motivating case. Make the discarded-type branch bypass formatted dispatch and its fault checks.Non-blocking
None.
Not verified
The full text of
ShaderResources.cppwas excluded from the review bundle; I read only its changed function range through the reader. Other included changed files were not read in full. Execution tests, builds, and the reported hardware behavior were not independently verified.To get this to a good state
Bypass formatted dispatch and selector fault checks for discarded TYPE 2/3 loads, then rerun the descriptor runtime test and relevant shader test selection.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:52:01Z.
Review: DISMISSED
Reviewed — comments
Changes are required before merge: address the two verified gaps in how the new test is integrated and how a TYPE 2/3 formatted load handles a null descriptor.
What I ran
Reviewed head
2034dab8855a040a9afeadb6137d943296619449using the prepared diff andrepo_read.py. No build or test commands were run; the test results below are author reported.Results
Findings
Blocking
core/libs/prx/libSceAgcDriver/tests/cmake/buffer_d16_previous_value_translation_tests.cmake:1: The new CMake fragment defines the D16 translation test, but I found no inclusion of this fragment incore/libs/prx/libSceAgcDriver/CMakeLists.txt. As written, the test is not registered by the driver build, so its reported coverage will not run in the normal test configuration. Include the fragment from the driver CMake configuration.core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1138: The formatted path selects the previous destination only when TYPE is nonzero, thenformattedReadreturns zero whenresource.validis false. The unformatted path’spreserveselection wraps the read, including its out-of-bounds zero fallback. For a discarded TYPE 2/3 formatted load with an invalid/null resource, this instead overwrites the destination with zero. Preserve the destination around the validity check as well.Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppwas excluded from the review bundle as too large. The changed lines and nearby function were read through the pinned reader.To get this to a good state
Include the new CMake test fragment and preserve the destination for invalid formatted descriptors, then rerun the affected translation and runtime tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T06:55:01Z.
Review: COMMENTED
Actionable comments posted: 1
Architecture findings (1)
Advisory architecture findings (1)
40952694-95e9-44a1-9850-f7ce9f25f288Reviewing files that changed from the base of the PR and between
f245901a48and2034dab885.core/libs/prx/libSceAgcDriver/tests/execution/BufferDescriptorRuntime.cppcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:24:39Z.
Review: COMMENTED
On Linux/lavapipe,
agc_driver_buffer_descriptor_runtimeandagc_driver_gcn_scalar_buffer_basepassed on main atba0ff896612band with this head integrated. Both runs loaded Khronos validation 1.4.369 with Vulkan required and the shader cache disabled. Neither log reported a missing layer or a VUID. The branch'sbuffer_d16_previous_value_translationtest also passed and checks that translation reads the previous destination for these buffer forms.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T22:21:12Z.
Review: COMMENTED
Actionable comments
100197e7-ce8d-46af-ab24-6933b1c39e30Reviewing files that changed from the base of the PR and between
2034dab885andcb8984a42f.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T01:15:15Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed change has no verified blocking defects; a few manually constructed test IR loads still use the old operand layout.
What I ran
Reviewed head
cb8984a42f49016ed3881c10bf33c5a9db23f910using the prepared diff and targeted reads withrepo_read.py. No tests or builds were run.Results
Negative control
Not run; no executable checks were run.
Findings
Blocking
None.
Non-blocking
LoadBufferU32test IR still uses five operands. The updated signature adds a previous-value operand before EXEC, so those fixtures place the old EXEC value in the previous-value slot. Examples areShaderMemory.cpp:841andMaskedSelect.cpp:3081. The changed signature is atIrOpcode.cpp:401. I did not verify whether those fixtures exercise code paths affected by the new operand.Sources
IrOpcode.cpp:401BufferInstructions.cpp:94SpirvRuntimeBuffer.cpp:1126Not verified
No tests, builds, or console behavior were run or independently confirmed. Reviewed all 17 paths in
manifest.json; none were excluded by the supplied file rules. For included files, review was limited to changed hunks and relevant context rather than reading each full file.To get this to a good state
Nothing is required. Optional: update remaining hand-built test loads to use the new operand layout.
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.