fix(agc): treat a TYPE 1 T# in a read-only static image slot as null #5828
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5828"
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 billythemenace2 on 2026-10-14T12:43:51Z.
Requested by billy
What
Before: since #5473 and #4779, a static, read-only image slot whose T# has TYPE 0 is bound as a null image, but a T# with TYPE 1 in the same slot still threw
runtime image descriptor is invalidin the recompiler. In the driver it was not treated as null either.After: TYPE 1 is treated like TYPE 0 in both places:
nullImageDescriptor(const ImageResource&, const DescriptorValue&)inResourceMaterializer.cppandIsNullTextureResourceinGuestTextureResource.cpp. The same limits apply: written, atomic and image-table slots still throw, and the reserved types 2-7 stay refused.Hardware semantics, measured on RDNA1 (gfx1010, AMD Radeon RX 5700 XT) with the
tools/hw-oracletemplate (driver comgr and HIP runtime):image_sample_lz,image_sample_b,image_loadandimage_get_resinfo(DIM 2D, dmask 0xf) through a format-22 T# of TYPE 1 return zeros in all four components without a fault, as TYPE 0 does. A TYPE 9 control with the same words returned the texels. The existing debt entry already notes that gfx1035 reads TYPE 1 as zeros too. Not measured: RDNA2 and the console's gfx1013, other formats, and depth-compare reads (image_sample_c*); the debt entries say so. On the same card a TYPE 2 T# left the driver unusable until a restart, which is why 2-7 stay refused.How
Both predicates accept
TYPE <= 1instead ofTYPE == 0.verifyTypeZeroImageMaterializationnow runs for TYPE 0 and TYPE 1: the read-only slot keeps the words, and the written and atomic slots still throw.verifyGuardedDescriptorSourcesgets a read-only TYPE 1 case, and its invalid T# moves to the reserved TYPE 2. The driver'sIsNullTextureResourcetest adds TYPE 1 (null) and TYPE 2 (not null). The two TYPE 0 debt entries indocs/dev/debt/libSceAgcDriver.mdnow cover TYPE 1 with its limits; I edited them there rather than adding ashader.mdentry, so that the TYPE 0 and TYPE 1 behaviour stay in one place.Tested
Windows 11 (26200), MinGW-w64 GCC 15, Release, on
main92e50418f.agc_shader_type_zero_image_materialization,agc_shader_memory,agc_shader_bindlessandagc_driver_graphicspass. With main'sResourceMaterializer.cppandGuestTextureResource.cpp,agc_shader_type_zero_image_materialization,agc_shader_memoryandagc_driver_graphicsfail.tools/check_conventions.py --base origin/mainpasses. Not tested: Linux, a title with a TYPE 1 slot.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T13:22:13Z.
The new regression covers the S#+V# words with T# type 0, while
nonImageDescriptoralso accepts type 1. Since the report includes an RDNA1 measurement for type 1, could the fixture add the same null-image assertion for a type-1 descriptor as well? That would keep the tested scope aligned with the implementation and the PR claim; the existing type-2 refusal case can remain the neighboring negative control.Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-14T15:51:42Z.
@MarcZX100 Added in
353570feb: the guarded-sources case now also captures a type 1 T# (the valid 2D T#'s words with TYPE 1) and checks that it is bound as a null image, next to the S#+V# type 0 words and the type 2 refusal.agc_shader_memorypasses on an RX 5700 XT, andtools/check_conventions.pypasses.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T16:49:16Z.
Additional CPU evidence from a private Demon's Souls (PPSA01342) capture: four active static sampled-image slots contain TYPE 0 descriptors and stop at
runtime image descriptor is invalid. All four are read-only, with no image stores or atomics. Porting only this PR's four own commits through353570febonto our integration removes that specific refusal. The complete captured preparation path then stops at an independent buffer-descriptor type check, so this is not a successful title run or proof that the level loads.A separate fixture calling the actual
ResourceMaterializer::Materialize,TryRuntimeImageModeandResolveImageTablesAPIs passed 23 CPU checks: static types 0/1 become null, reserved types 2–7 and invalid widths remain refused, inactive guards and valid/null transitions are preserved, and table entries of types 0/1/2 remain poisoned. The same fixture fails with the old Materializer and with a selective control widening the accepted static types through 7. These checks use matching integration headers and the actual production translation unit, rather than claiming a full build of this public PR head.No game request, descriptor payload, shader dump or disassembly is attached. No fresh GPU or numerical shader-output result is claimed. Host: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100; this additional validation is CPU-only.
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-14T22:01:21Z.
@MarcZX100 This PR and your #5473 make the same recompiler change: a static image slot whose T# has TYPE 0 is materialized as a null image instead of throwing
runtime image descriptor is invalid. Yours came first, together with #4779 on the binding side, so I'd like to agree with you on the order, as CONTRIBUTING asks.The one place they differ is TYPE 1. This PR treats TYPE 1 as null too. #5473 uses TYPE 1 as a reserved type in its malformed-image fixtures. The measurement this PR relies on, from the hardware oracle on RDNA1 (gfx1010, RX 5700 XT):
image_sample_lz,image_sample_b,image_loadandimage_get_resinfothrough a format-22 T# of TYPE 1 return zeros in all four components without a fault, as TYPE 0 does. TYPE 1 is not measured on RDNA2. On the same card, a TYPE 2 T# left the driver unusable until a restart, so 2-7 stay refused here.Two options:
OutsideSnapshotpoisoning).I'm happy with either. Which do you prefer?
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T23:23:38Z.
CPU replay of one Demon's Souls (PPSA01342) compute shader request that stops on a static-image TYPE 0 T#. No payload attached. Windows Server 2025 (10.0.26100), MinGW GCC 15.2 Release,
ANYPS5_NO_SHADER_CACHE=1. RTX 3060 12 GB (driver 591.86) unused.Each tree has #5959 (
528bdf5f8) cherry-picked locally.--materializegave the same result in 3 runs per tree:--prepare--materialize0ae1deb856f25722ba4a7a38c43Neither PR gets this shader past capture. Both clear the TYPE 0 image refusal and stop at the same buffer check. Same stop as my earlier port, now on the actual heads. Materialization was not reached, so the zeroed (this PR) and kept (#5473) T# words were not compared.
From the diffs: this PR cites the #4139 hardware measurements and keeps table entries refused. #5473 also nulls TYPE 0 table entries, citing a PPSA01341 run on an RTX 4070, not an AMD measurement.
The buffer stop is a separate issue: the shader reads a static read-only V# whose TYPE is not 0, but only under a lane-dependent guard. I'm preparing a follow-up that defers that check to the lanes that actually execute the read. With it stacked on this PR, the same request passes capture and materialization. It will say
Depends on: #5828.Not tested: game run, GPU execution, Linux, other ctests.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T01:06:19Z.
The null binding is applied to every static image slot, including slots the shader writes (
image_store) or accesses atomically. The measurements in #4139 (gfx1036 TYPE 0, and gfx1010 TYPE 0 and 1 with format 22) only cover reads:image_sample_lz,image_sample,image_sample_b,image_loadandimage_get_resinfo. With this change, a store or atomic through such a T# is dropped instead of refused. An atomic returns 0. On a device withoutnullDescriptor, the store goes into the shared placeholder storage image, so a later null storage read in another dispatch returns that data instead of zeros.Could the null binding be limited to slots the shader only reads? Written and atomic slots would keep throwing
runtime image descriptor is invalid, as they do on main, until stores and atomics are measured:and at the call site in
materializeSnapshot, whereimageis already in scope:Test I used for this, appended to
verifyGuardedDescriptorSources(it reuses itsstoreRequest,fill,samplerAndBufferandtypeOne; without the change bothexpectFailurecalls fail):The debt entry would then say "is bound as a null image when the shader only reads the slot, so every read returns zeros; a slot the shader writes or accesses atomically still throws."
Two further points, which I am only raising here and have not changed:
image_sample_c*) through such a slot are not measured either. Demon's Souls (PPSA01342) reads type 0 slots withimage_sample_c_lzbehindv_cmpx/s_cbranch_execz, so refusing them would block it again. Recording them as unmeasured in the debt entry may be enough.nonImageDescriptoralso accepts IMG_FORMAT 0 (for example an S# with MAX_LOD 0 followed by a V#). The only hardware observation of that case I know of was a gfx1010 driver hang, andvalidImageDescriptorused to refuse format 0. The debt entry could note that format 0 is unmeasured, and that TYPE 1 rests on gfx1010 alone.Demon's Souls still captures with this restriction, because all its slots of this kind are read-only. I replayed its failing dispatch offline (prepare, capture and materialize, with
agc_shader_replay --materializefrom #5959) on main + #5828 + the deferred static V# TYPE PR. It materializes the same 210839 SPIR-V words with or without the restriction. The dispatch also needs that PR, because one of its buffer slots holds a V# with TYPE 2.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T02:02:07Z.
Thanks for laying out the sequence and the scope difference. I prefer #5473 first as the narrower TYPE=0 change; it now accepts only static read-only image slots, with writes, atomics, and table entries still refused. Your TYPE=1 RDNA1 measurement and tests are useful evidence for a separate follow-up on top of #5473, preserving this PR’s authorship and the hardware-oracle report. Maintainers can choose the merge order. One remaining scope note: the read-only predicate also covers depth-compare reads, while the cited oracle does not measure
image_sample_c*; the Demon’s Souls capture exercisesimage_sample_c_lz, so that specific path remains unmeasured even though the title’s four reported static slots are read-only. I have recorded it as uncertainty rather than claiming it is covered by the existing measurements.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:10:02Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceAgcDriver.mdL46-47docs/dev/debt/libSceAgcDriver.mdL46-47Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:18:33Z.
Review: CHANGES_REQUESTED
Thanks for the measurements. #5473 merged today and covers the TYPE 0 part of this change, so this PR now conflicts and mostly duplicates main. What is left is TYPE 1, so please rework it into that follow-up:
mainand drop the TYPE 0 handling.nullImageDescriptor(const ImageResource&, const DescriptorValue&)inResourceMaterializer.cppalready nulls a TYPE 0 T# in a static, read-only slot (no table, no write, no atomic). Extend that predicate for TYPE 1 instead of addingnonImageDescriptor.image_sample_lz,image_sample,image_sample_b,image_loadandimage_get_resinfo; see @fdfawef324's comment above for how a dropped store/atomic behaves.docs/dev/debt/shader.mdentry that TYPE 1 is not measured on RDNA2/gfx1013, nor with other formats, nor with depth-compare reads (image_sample_c*).verifyGuardedDescriptorSources(it must fail without the change), plus a case showing a TYPE 1 T# in a written/atomic slot is still refused. Check the test still passes after the rebase, since #5473 changed that file.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T14:16:07Z.
#6412 handles the buffer stop described above. It does not depend on this PR after all: with #5473 merged, current
mainreaches that same buffer stop on the Demon's Souls dispatch, and #6412 materializes it onmainalone.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by billythemenace2 on 2026-10-15T15:17:36Z.
@adriadam10 Reworked as you asked, in
01d3594c2onmain92e50418f:nullImageDescriptor(const ImageResource&, const DescriptorValue&)now accepts TYPE 1 in the same static, read-only slots. Written, atomic and table slots still throw.IsNullTextureResourcein the driver also accepts TYPE 1. Without that, the T# the recompiler keeps would not be bound as null.verifyTypeZeroImageMaterializationruns for TYPE 0 and 1, including the written and atomic refusals.verifyGuardedDescriptorSourceshas a read-only TYPE 1 case, and its invalid T# is now the reserved TYPE 2. The driver test adds TYPE 1 (null) and TYPE 2 (not null). They fail with main's two source files and pass with the change.docs/dev/debt/libSceAgcDriver.mdrather than adding one toshader.md, so both types are described in one place. They say TYPE 1 is measured only on gfx1010 with format 22, not on RDNA2/gfx1013, with other formats or withimage_sample_c*. If you'd prefer a separateshader.mdentry, I'll move it.The title and description are updated to match.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T19:57:34Z.
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2) at the reworked head
01d3594c2, merged into main44df21632:agc_shader_type_zero_image_materializationandagc_shader_memory:runtime image descriptor is invalidagc_driver_graphics:AGC graphics: a type-1 texture with a nonzero base was not classified as nullAI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T09:47:53Z.
Review: APPROVED
Checked the rework against the four points: only TYPE 1 is added on top of main's read-only static slot predicate, written/atomic slots are still refused, the debt entries state the unmeasured cases, and the TYPE 1 cases in
verifyGuardedDescriptorSources/verifyTypeZeroImageMaterializationfail without the change (agc_shader_type_zero_image_materialization,agc_shader_memory,agc_driver_graphics). Also measured on gfx1035: TYPE 1 returns zeros like TYPE 0 forimage_sample_lz,image_load,image_get_resinfoandimage_sample_c_lzwith formats 22 and 10, TYPE 9 returns texels. Merging.