fix(shader): accept TYPE=0 images during materialization #5473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5473"
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 MarcZX10 on 2026-10-13T20:40:20Z.
What
Treats AMD image descriptors with
TYPE=0as null for read-only static image slots, even when the descriptor base and other words are nonzero. It leaves table entries, writable image slots, and atomic image slots refused because the available hardware evidence does not establish null behavior for those cases. The runtime binding behavior is in #4779, so this follow-up depends on that PR. The case was reported for PPSA01341 (Demon's Souls); its capturedTYPE=0descriptors caused the recompiler to reject the shader request before runtime binding.Malformed-image fixtures use reserved
TYPE=1, while the dedicated nonzero-payloadTYPE=0read-only regression remains. Table snapshots track which descriptor dwords were captured and poison an image record only when the requiredTYPEdword is missing. Partial captures that includeTYPEcontinue through normal materialization.Tested
agc_shader_memory_testsandagc_driver_image_table_tests.agc_shader_memory_testspassed end to end, including the straddling-record regression and deterministic replay.agc_shader_memory_tests --bindlesspassed, including the TYPE=0 table-entry refusal regression.agc_shader_memory_tests --type-zero-image-materializationpassed, including rejection of writable and atomic TYPE=0 descriptors.agc_driver_image_table_testsbuilt but cannot run on this host: the emulator's CPU guard requires LZCNT, BMI1, BMI2, MOVBE, AVX2, and FMA, which its Xeon E5-1620 v2 does not provide.tools/check_conventions.py --base upstream/mainandgit diff --checkpass.Checklist
main; no other open PR implements this recompiler behaviorImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T23:19:17Z.
Windows test of this PR (stacked on #4779). Windows 10 (19045), MinGW-w64 GCC 15.2, Release,
ninja -j 4,ctest -R ^<name>$called directly, 3 runs each. Tree:main30f961266+ merge of #4779 (7e1e1ce05) + merge of #5473 (52992026a) = local merge commit1f3be6bba.agc_shader_type_zero_image_materialization: exit 0, 3 of 3.agc_driver_graphics: exit 0, 3 of 3.agc_shader_bindless: exit 8, 0 of 3,bindless: an invalid T# was accepted.agc_shader_memory: exit 8, 0 of 3,guarded sources: an invalid T# behind a taken branch was accepted.Baseline on the same machine and in the same build directory, same commands:
main+ #4779 only (5bd44d17b) and plainmain(7a0c838ca, it had moved after30f961266) passagc_shader_bindlessandagc_shader_memoryin 3 of 3 runs each. So on this Windows build the two existing tests pass before this PR and fail with it. The PR description mentions that the fullagc_shader_memorytest failed earlier on the same assertion (on its Linux build); on Windows it does not fail without this PR.Not tested: Linux, a title run, AMD, other ctest targets. These tests select no GPU (GPUs on the machine: NVIDIA GeForce RTX 4080 SUPER, AMD Radeon RX 6400).
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T23:40:29Z.
Thanks for the Windows comparison; it exposed that the two malformed-descriptor fixtures still used
TYPE=0, which this change now deliberately treats as null. I updated both the guarded-source and bindless invalid-descriptor cases to use reservedTYPE=1; the dedicated nonzero-payloadTYPE=0materialization test remains in place.On Linux with GCC 12.2 / Ninja Release,
agc_shader_bindless,agc_shader_memory, andagc_shader_type_zero_image_materializationall pass (3/3), andtools/check_conventions.py --base upstream/mainpasses. The fix is pushed as9add44799; could you rerun the two affected checks on Windows against this head when convenient?AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T02:28:48Z.
Update to my Windows test above: the head of this PR has changed since (now
9add447991162ccb5c558530b888a8b799d5a747; my first run was on52992026a). Re-run onmain016db923afd3bfc210654ce59073a19f27c879be+ #4779 (7e1e1ce05) + this head, one run each withctest -V, Windows 10 (19045), MinGW-w64 GCC 15.2, Release:agc_shader_bindless,agc_shader_memory,agc_shader_type_zero_image_materializationandagc_driver_graphicsall pass (exit code 0). The two failures I reported (agc_shader_bindless,agc_shader_memory) belong to the earlier head and no longer occur. Thectest -Voutput of these runs contains no Vulkan device orSelected GPUline.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T07:02:43Z.
Title evidence for this pull request (and #4779), PPSA01746 (Kena: Bridge of Spirits), Windows 10 (19045), RTX 4080 SUPER, one run each, no picture checked.
On
main52283005901the title stops at the storage-image write-back throw, so this stop cannot be reached there. To see what comes after it I removed the twoRequire(!unsavedOutsideWatch ...)checks inTexture.cpplocally. That local change is a diagnostic experiment only, it is not proposed anywhere.presentation failed: runtime image descriptor is invalid/what(): runtime image descriptor is invalid(ResourceMaterializer.cpp:496),PPSA01746_rT/run_083039.errlines 124-126.7e1e1ce05) and this head (9add44799) merged into that tree (merge tree2352738758d): nowhat(), noFATAL, nopresentation failedinPPSA01746_rT/run_085421.err(129 lines, last line a[shader-disk-cache]statistic); the run was started with a 300 s limit and was over at 09:00:36 local time (started 08:54:16).Not known: whether the descriptor of this title really has TYPE=0 (the dwords were not logged), so the link to this change is indirect.
Test conditions: libraries
ninja -j 8 libsexit 0 (08:50:49 to 08:53:50 local time, 128.prx,libSceAgcDriver.prx08:53:36,libkernel.prx08:53:48);app.exeof 2026-10-14 07:29:50 from another session's relink of this title (relinker commit and relink command not recorded by me), directory reused for both runs.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T14:40:59Z.
Rebased onto current
main(f3434892b), preserving the new layout-pair CMake entries while keeping the dedicated test in the Windows test environment. On Linux/GCC 12.2,agc_shader_memory_testsrebuilt andagc_shader_type_zero_image_materializationpassed 1/1;tools/check_conventions.py --base upstream/mainandgit diff --checkpass. I have not rerun the full shader-memory suite or a title on this rebased head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T19:56:25Z.
Rebased the follow-up onto current
main(411e5e6d9) after #4779 merged, resolving the test-file conflict while preserving the current image-table coverage and the TYPE=0/reserved-type regressions. The full Linuxagc_shader_memoryCTest passes (1/1),agc_shader_memory_testsrebuilt, and local plus hosted conventions pass. The dedicated TYPE=0 CTest is not registered in the reused build tree, so I verified it as part of the full shader-memory test instead. Current hosted Build checks are still running; eligibility and the progress report passed. Commit825a26751is authored as MarcZX100.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T19:59:52Z.
CI has finished on rebased head
825a26751: the Windows relinker CTest passed, as did the selected Linux/macOS relinker, register-context, and write-watch jobs, eligibility, conventions, and report. The separate full Linux and Windows build jobs were skipped by the workflow path policy. GitHub now reports the PR CLEAN.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:09:46Z.
Review: CHANGES_REQUESTED
Thanks for the rebase. Checked on this PR merged onto current
main:agc_shader_type_zero_image_materializationpasses, but three existing tests now fail because they still useTYPE=0as their "invalid descriptor":agc_shader_memoryandagc_shader_bindless:core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:1269(heap[0][3] &= 0x0fffffffuclears TYPE) fails withimage tables: an invalid T# was bound. Use a reserved type (e.g.TYPE=1) there, as you did for the guarded-source case.agc_driver_image_table:tests/execution/ImageTable.cpp:544(SetRecord(7, ..., 0x0000ffacu)) and:1006(invalid{... 0x0000ffacu}) have TYPE=0, so the "not an image" fault checks at:753,:875and:1041no longer fire (log:deferred write-back failed ... outside the snapshot, thendid not report its address, words and reason).Please switch those fixtures to a reserved type and rerun
agc_shader_memory,agc_shader_bindlessandagc_driver_image_table; CI doesn't run them on this PR, so the full suites need a local run. The rest looks fine.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T20:26:54Z.
Linux follow-up on local head
825a26751(GCC 12.2, Ninja, Release): I applied the three requested reserved-TYPE fixture changes and built all three test binaries successfully. The focused CTest run did not pass:agc_shader_bindless: fails later in the shader-memory fixture withimage tables: a straddling record was bound.agc_shader_memory: same failure.agc_driver_image_table: aborts before test logic because this host Xeon E5-1620 v2 lacks the AVX2/BMI/LZCNT/FMA features required by the emulator.I verified that restoring the original TYPE=0 shader fixture instead fails earlier with
image tables: an invalid T# was bound, so that does not establish a passing baseline. I have not pushed the fixture edits while the shader-suite failure remains unresolved. The CMake configure and all three builds succeeded.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T20:31:31Z.
Follow-up on the local Linux run: the straddling test exposed that the table snapshot padded an incomplete descriptor to eight zero-filled dwords, making its missing TYPE look like a null descriptor. I now preserve the number of dwords actually captured and materialize incomplete image/sampler records as
OutsideSnapshotpoison. I also changed the two additional malformed TYPE=0 image fixtures inShaderMemory.cppto reserved TYPE=1; the dedicated TYPE=0 materialization regression remains unchanged.On the updated head
4a7a38c43(GCC 12.2, Ninja, Release): build ofagc_shader_memory_tests,agc_driver_bindless_images_tests, andagc_driver_image_table_testssucceeded. CTest passedagc_shader_bindless,agc_shader_memory, andagc_shader_type_zero_image_materialization(3/3).agc_driver_image_tablewas attempted but aborts before test logic because this host Xeon E5-1620 v2 lacks the CPU extensions required by the emulator.tools/check_conventions.py --base upstream/mainandgit diff --checkpass.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T20:49:05Z.
Review: CHANGES_REQUESTED
Thanks for the update. The reserved-type fixtures fix
agc_shader_memoryandagc_shader_bindlesson my side too, but the new commit (4a7a38c43, poison incomplete records) breaks two other tests. Checked on this PR merged onto currentmain(Linux, Release):agc_driver_image_tablefails withimage table: valid entries faultedanddeferred write-back failed: ... selected the descriptor at ... (words a795ce4c c1600055 8000c00f 90000fac): outside the snapshot. A valid descriptor (TYPE=9) is now poisoned asOutsideSnapshotbecause the shader only reads part of its dwords, sowords.dwordCount != 8u(ResourceMaterializer.cpp:1057,:1147) is true for a record that is not truncated.agc_driver_image_table_reusefails withthe shader does not bind the whole table.Both pass when
ResourceMaterializer.cppis reverted tomainand fail with it, so the regression comes from this change. (agc_driver_tessellationsegfaults with and without the PR, unrelated.)The capture count at
:684-697cannot tell "dwords the shader did not read" from "dwords outside the snapshot". Either track which dwords the record needs (TYPE sits in dword 3, so only that one decides null vs. not) or drop this commit and handle the straddling case separately.agc_driver_image_tablecannot run on your host, so please check the CTest list above on a machine with AVX2/BMI, or say so and I will run it after your next push.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T21:11:24Z.
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)core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL827core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL893Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T23:23:56Z.
Replay comparison of this head (
4a7a38c43), #5828 and main on a Demon's Souls TYPE 0 shader request: https://github.com/boykopovar/AnyPS5/pull/5828#issuecomment-6180693005. Both PRs clear the image refusal and stop at the same buffer-descriptor check. AI-assisted: yesImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T01:54:15Z.
Thanks for identifying that
dwordCountconflates unread fields with missing data. Commit682b07eb0now records the available dword positions and requires only dword 3 (TYPE) before classifying an image record. Records with an unreadTYPEare poisoned; partial captures that includeTYPEremain eligible for normal materialization.On Linux with GCC 12.2,
agc_shader_memory_testspasses end to end, as do its--bindlessand--type-zero-image-materializationcases.agc_driver_image_table_testsbuilds, but this Xeon E5-1620 v2 host lacks the AVX2/BMI features required to run it. Could you rerunagc_driver_image_tableandagc_driver_image_table_reuseon your capable host?Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T02:00:25Z.
Follow-up to my earlier validation note: commit
0e7e149ccnarrows TYPE=0 null handling to read-only static image slots. Writable and atomic image slots still fail materialization, and TYPE=0 table records remain poisoned; the fixture now covers all three boundaries. The available hardware evidence covers reads, not writes or atomics, so this keeps those paths unsupported.On Linux with GCC 12.2, the full
agc_shader_memory_tests,--bindless, and--type-zero-image-materializationruns pass.agc_driver_image_table_testsrebuilds, but this Xeon E5-1620 v2 host cannot pass its AVX2/BMI CPU guard. Please rerunagc_driver_image_tableandagc_driver_image_table_reuseon a capable host and review the narrowed head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T02:02:09Z.
Follow-up after the new hosted run: current head
0e7e149cchas successful eligibility, conventions, and report checks; the full Linux/Windows build jobs were skipped by path policy. Review remainsCHANGES_REQUESTED. The Linux regressions and CPU limitation are described above. The remaining review request is foragc_driver_image_tableandagc_driver_image_table_reuseon a host that passes the emulator CPU-feature guard.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:13:18Z.
Review: APPROVED
Thanks for the update. Checked on this PR merged onto current
main(Linux, Release):agc_shader_memory,agc_driver_image_table,agc_driver_image_table_reuseand the other image-table tests pass, andagc_shader_memoryfails without the change. Both regressions from the previous round are gone; tracking only dword 3 (TYPE) inavailableDwordMaskfixes the straddling case without poisoning partially read valid descriptors. (agc_driver_tessellationsegfaults onmaintoo.)Measured on gfx1035:
image_loadthrough a T# withTYPE=0and a nonzero base returns 0,0,0,0, like a null image, so treating it as null for read-only slots matches hardware. Leaving writes, atomics and table entries throwing is right, there is no measurement for them.I added one commit on your branch: the
docs/dev/debt/libSceAgcDriver.mdline said direct and table-backed reads are treated as null, but the code only accepts read-only slots outside tables. It now states the real scope and the measurement. Merging once the full Build is green.