feat(agc): fold samples of views whose channels all select constants #1417
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1417"
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 gjonn on 2026-10-08T03:13:28Z.
What
When every
dst_selof a sampled view selects constant 0 or 1, a sample or gather returns that constant whatever the texel, filter, LOD or coordinates. Titles sample such placeholders through views the static runtime image interface has no mode for: a 1x1x1 3D R8 texture under a 2D sample with an unnormalized sampler, or a 1D texture under a 2D gather. Both stop at runtime image mode selection ("image descriptor is incompatible with the static runtime image interface"), and the 3D one would then fail the unnormalized proof ("samples a 1D-array, 2D-array, 3D, cube or multisampled image").RuntimeImageModesappends three constant modes (float, uint, sint) to a direct sampled image whose accesses are all non-compare samples or gathers (constantSwizzleCompatible, tracked byResourceTracker). Storage, depth-compare, packed and table images get none.RuntimeImageModeselects the constant mode of the view's numeric class when all fourdst_selare 0 or 1, before dimensions are matched. FMASK, depth-bits, converted and sRGB-decoded views keep their existing modes.ProveUnnormalizedskips a constant mode only after the run-time-selected check, so bindless table roots still throw.ImageResourcefields are serialized andFormatVersiongoes from 20 to 21.Tested
agc_driver_image_sample_unnormalizedhas new cases, which fail without the change:dst_sel(1, 0, 1, 0) sampled withimage_sample_lz,image_sample_landimage_samplethrough all five unnormalized samplers returns exactly (1.0f, 0, 1.0f, 0);image_sample_lzdmask 0x6,image_gather4_lzdmask 0x2 andimage_gather4_lzdmask 0x4 under a 2D access return (0, 1.0f), all 0 and all 1.0f on a 3D UNORM view selecting (1, 0, 1, 0); (0, 1), all 0 and all 1 on 32_UINT and 32_SINT views; and zeros on a 1D view selecting (0, 0, 0, 0). These are the values measured on gfx1035.agc_shader_memory: a 3D view selecting constants passes the unnormalized proof and is not bound; a table root with the same descriptor still fails with "samples an image selected at run time".ctest: 507/507 pass (one skipped as usual).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:45:11Z.
Review: CHANGES_REQUESTED
Measured on gfx1035 (HW oracle): with all four
dst_selconstant,image_sample_lzreturns 1.0f/0 for float and unorm formats and integer 1/0 for32_UINT/32_SINT;image_gather4_lzreturns thedst_selof the dmask component in all four texels; dmask 0x6 packs channels 1 and 2; a 3D T# sampled with a 2D dim and an unnormalized sampler gives the same. That matches what the emitter produces. Build + ctest pass and the new case fails without the change. Three things before it can go in:DescriptorBindingBuilder.cpp:221: theconstantSwizzleskip runs before theindirectRootcheck, butEmitSamplingOponly folds direct images (SpirvImageEmitter.cpp:1308,access.slot == 0). A bindless table root whose snapshot descriptor has a constant swizzle used to throw "samples an image selected at run time"; now it passes the proof and gets sampled through the table path with an unnormalized sampler, and the other entries of the table don't have to be constant. Skip only direct images (image.constantSwizzle != 0u && image.indirectRoot == ImageResource::NoIndirectImage), so tables keep throwing.ImageGatherComponent(EffectiveDmask(...))), the uint/sint constants and a partial dmask aren't exercised. Please add cases pinning them, for exampleimage_gather4_lzwith dmask 0x2 and 0x4 ondst_sel(1, 0, 1, 0) (expected all 0 and all 1.0f), a32_UINTor32_SINTview (expected integer1, not0x3f800000), andimage_sample_lzwith dmask 0x6 (expected 0, 1.0f). These are the values measured on hardware above.main:ShaderDiskCache.hppis already atFormatVersion = 9, so this needs 10 after rebasing.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-09T16:04:42Z.
After #639, PPSA26344 (Ghost of Yōtei) hits the case this PR covers, at runtime image mode selection rather than in
DescriptorBindingBuilder.A compute program gathers (DIM 2D) through a 1D T# whose four
dst_sels all select constant 0:50091c00 03800000 00000000 80000000 00000000 00700000 00000000 00000000. No runtime mode matches a 1D T# under a 2D access, so it throws "image descriptor is incompatible with the static runtime image interface". Every read through that view returns 0 whatever the texel, so the view's own dimension doesn't matter.Locally I treat a sampled, non-comparison T# whose
dst_selis all zero (word3 & 0xfff == 0) like a null descriptor: mode 0 inTryRuntimeImageMode, and no texture inShaderResources. That's the all-zero subset of what this PR does. It gets the title past this stop, and with robustness2'snullDescriptorthe reads return zeros.This PR's base predates #639 and now conflicts with main in
ResourceMaterializer,DescriptorBindingBuilderand the disk cache. Are you planning to rebase it? If not, I can open the all-zero runtime-mode version separately, but I didn't want to compete with this one.Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-09T16:11:14Z.
Lost track of this one. I'll get it rebased now.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:04:01Z.
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/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppL189, L297-298core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL705-706, L729core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppL189, L297-298core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL705-706, L729core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleUnnormalized.cppL45-46, L131, L145core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppL85core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppL187-197core/shader/recompiler/ShaderDiskCache.cppL476, L553, L577core/shader/recompiler/ShaderDiskCache.hppL15core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppL85core/shader/recompiler/Optimization/src/ResourceTracker.cppL1063core/shader/recompiler/ShaderDiskCache.cppL476, L577core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL729Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:26:34Z.
Review: APPROVED
Thanks for the rebase. The three points from the earlier review are done: the constant-swizzle skip now runs after the
indirectRootcheck (table roots still throw), and the tests pin gather dmask 0x2/0x4, dmask 0x6 and the 32_UINT/32_SINT constants.Checked on current
main: build and ctest pass, andagc_shader_memoryandagc_driver_image_sample_unnormalizedfail without the change. The sample/gather results match what the gfx1035 hardware returns.Added one commit on top:
FormatVersionis 21 onmainalready, so the 20 → 21 bump disappeared in the rebase; it is now 22 sinceImageResourcegained two serialized fields.Merging once CI is green.