feat(agc): sample unsigned scaled textures through UNORM views #16260
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16260"
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 ycbuzi on 2026-11-06T01:40:13Z.
What
A texture in an unsigned scaled format is refused today: the recompiler stops with
sampled image descriptor uses an unsupported formatand the driver withunsupported guest texture format 3. My First Gran Turismo (PPSA24157) stops on 8_USCALED (T# f41e7a40 c0300000 021bc3bf 90000204 ...) 136 s in.A USCALED read returns the integer in each component as a float (0..255 for 8 bits). This stores and views the six unsigned scaled formats whose components are whole bytes or halfwords, 8, 16, 8_8, 16_16, 8_8_8_8 and 16_16_16_16 (guest 3, 9, 16, 25, 58, 67), as their UNORM layouts, and the shader multiplies every sampled, loaded or gathered texel by 255 or 65535. UNORM sampling is supported on every device, so this does not depend on scaled-image sampling, which NVIDIA does not offer. The technique is KytyPS5's (
RemapTextureFormatingpu_format.cppand theUscaledscaling inspirvEmitterImage.cpp), written here for AnyPS5's runtime image modes:ScaledUnormBits(RdnaDescriptorFormat) gives the component width of each covered format; the six formats are marked sampled.ImageResource::scaledUnormBits: each plain float runtime image mode gets an 8-bit and a 16-bit scaled twin, chosen from the descriptor like the sRGB-decode twins, and saved in the shader disk cache.UnpackImageTexelandUnpackImageGatherscale the result. A component whose runtime selector is ONE (the view already reads 1.0 there) keeps factor 1.0.Filtering happens in the normalized range, which equals filtering the integers up to float rounding. Signed scaled formats are not read through SNORM views (an SNORM view clamps -128 to -1, so the shader cannot recover it): they keep #14709's native
*_SSCALEDviews and throw where the device cannot sample them. Storage images, depth comparisons and packed (BY2/BY4) accesses of a scaled format throw, and so does a 1- or 2-channel scaled format whose T# selects its missing alpha (the view reads 1.0 there and the shader can't tell it from data without another runtime image mode per format). All are in the debt file.#14709 (merged 11-02) maps every scaled format to its native
*_SCALEDVulkan format where the device can sample it. On an RTX 4070 SUPER that gets PPSA24157 past the recompiler stop and then stops in the driver onunsupported guest texture format 3, because the device can't sample it. Withmainmerged in, the six unsigned formats above resolve to their UNORM views on every device, and #14709's native mapping and device check (ScaledSampledFormats) stay for the signed and 10_10_10_2 scaled formats (guest 4, 10, 17, 26, 52, 53, 59, 68); its tests are adjusted to match.Overlap (
tools/pr_overlap.pystopped on #15136, whose head GitHub no longer serves, so I read every open PR's file list and test-merged the ones sharing a file with this branch): #14709, #15450 and #16253 conflict inkFormatInfoTable(its size and neighbouring entries) and, for #14709, the driver table; #14628, #15948 and #15973 merge cleanly with it. #5371 conflicts in files this doesn't touch.Tested
Windows 11, Ryzen 9 7900, RTX 4070 SUPER (NVIDIA 621.14), WinLibs GCC 15.2.0, Release. Head
bd34b03934(main2e48261498merged in, after #14709 landed).*_SSCALEDandA2B10G10R10_*SCALEDentries and its device check stay for guest 4, 10, 17, 26, 52, 53, 59, 68. #14709's tests now cover those eight, and a new check asserts the unsigned formats sample through their UNORM views on a device that cannot sample scaled formats.main2e48261498againstbd34b03934, same build dir and GPU (RTX 4070 SUPER), non-elevated,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(SDK 1.4.363.0),ctest -R '^(agc_driver_image_scaled_unorm|agc_driver_image_converted_unorm|agc_driver_vertex_fetch|agc_driver_graphics|agc_shader_memory)$' -V: 4/4 onmain(the scaled test doesn't exist there) and 5/5 on the branch, noVUID-and no missing-layer line on either side; the layer's best-practices control log had 43 lines on both; the test binaries differ.python3 tools/check_conventions.py --base origin/mainpasses.Earlier, before the merge with #14709:
Head
43f73f60b7(main merged in at6a37dfbed9), NVIDIA 616.92.Game check of head
52578922b1merged ontomain9d2e737432(11-11), My First Gran Turismo (PPSA24157), RTX 4070 SUPER, both runs with no input:main9d2e737432: stops after 151 s onsampled image descriptor uses an unsupported format(the 8_USCALED T# above).With this PR (every library from the PR build): runs 243 s and draws 6881 frames, then stops on
AGC graphics: layered rendering with a depth target is unsupported. That's a separate gap, whichmaindoesn't get far enough to reach.agc_driver_image_scaled_unorm(new, on the GPU): loads, point- and bilinear-samples and gathers all six formats under XYZ1, ZYX1, X011 and X001 (PPSA24157's) selects, plus XYZW and WZYX on the 4-channel formats, and checks the refusal of XYZW on the 1- and 2-channel ones. Loads and point samples must return the exact integers. With the factor forced to 255 for ONE selects, it fails:image_load of 8_USCALED with DST_SEL 0x3ac: texel 0 component 3 is 255.000000, expected 1.000000.At
43f73f60b7:agc_driver_image_scaled_unorm,agc_driver_image_converted_unorm,agc_driver_vertex_fetch,agc_driver_graphicsandagc_shader_memorypass withANYPS5_REQUIRE_VULKAN=1.Validation layer,
mainea07ec82d3against580f261227(the ONE fix, before the main merge and the byte-wide field): the same five tests (four onmain), non-elevated,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(SDK 1.4.363.0): 4/4 and 5/5, noVUID-and no missing-layer line on either side; the layer's control log had 61 lines on both; the test binaries differ.Earlier, on
0ec1ce69a0:agc_driver_graphicsandagc_shader_memorypass. New checks: each covered format resolves and is sized like its UNORM format, has its component width and samples as float, and the UNORM view maps back to the UNORM guest format; the signed and 2_10_10_10 scaled formats have no scaling; PPSA24157's descriptor, and the five other formats, select a float runtime mode scaling by 8 or 16 bits, 8_UNORM selects none, and a scaled storage image is refused.main'sTextureFormat.cppfail withAGC graphics: unsupported guest texture format 3.ctest -R '^(agc_driver_graphics|agc_shader_memory|agc_driver_vertex_fetch)$' -Vonmainand on this branch from a non-elevated process withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(SDK 1.4.363.0): 3/3 on both, noVUID-line and nowas not found but was requested by env var VK_INSTANCE_LAYERSline in either log. The layer loaded on both sides (a best-practices control run ofagc_driver_vertex_fetchwrote 43 lines to the layer's log file each time), and the two sides' test binaries differ.agc_driver_graphicsandagc_shader_memorydon't open a device;agc_driver_vertex_fetchran on the 4070 SUPER.mainit stops after 136 s (2365 frames) on the format above. With this change (and the matchinglibc.prx/libkernel.prx, since my game build is on an oldermain) it gets through the save screen at about 60 FPS and stops after 295 s (3729 frames) onAGC graphics: layered rendering with a depth target is unsupported, which #7256 removes (I asked on #7256 for a rebase to test it).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
Summary by CodeRabbit
New Features
Documentation
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T06:59:23Z.
Review: COMMENTED
Reviewed unsigned scaled texture change — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
ac03ccbe143c9b05d836a20fa0800b629dde15a6, basemain.diff.patchfrom the review folder.Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/libSceAgcDriver.md:271: the new debt entry says the six unsigned formats are UNORM-backed and scaled in the shader. The older entry on the next lines still says "USCALED and SSCALED need a shader-side scale (open #14709)". The two now disagree for the unsigned formats. Narrow the older sentence to the signed formats.Not verified
kFormatLookup.ResolveTextureFormatis also used on the write paths (for exampleTexture.cpparound line 1080 andDepthSurface.cpp). I did not read those paths, so I cannot say whether a write through an unsigned scaled format is refused or stored unscaled.RuntimeImageModestwins andUnpackImageTexel/UnpackImageGatheronly as diff hunks. I did not read the call sites ofImageGatherComponentandRuntimeImageSwizzle, so the gather component mapping is unchecked.ShaderMemory.cpp. Its full text is too large for the review folder and is not infiles/. I read its changed hunk only (verifyScaledUnormModes).To get this to a good state
Nothing is required.
Optional:
docs/dev/debt/libSceAgcDriver.md(see Findings).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T09:30:57Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected implementation maps the six unsigned scaled formats to UNORM views and restores their integer scale for sampled, loaded, and gathered texels; I found no verified blocking defect.
What I ran
No commands or tests were run. I inspected the prepared diff and repository files at head
20498c5e0b4d0caece8ea1a19c8021d3af36b50cusingrepo_read.pytools.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas read only around the new test; its remaining contents were not reviewed. No tests were run.files.jsonwas not available as a review document; the file listing identifiesShaderMemory.cppas the sole changed file excluded from the review folder because it is too large. All other changed files listed in the manifest were read in relevant ranges, and the prepared diff was inspected.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T02:34:17Z.
Review: COMMENTED
Actionable comments posted: 2
Architecture findings (1)
Advisory architecture findings (1)
bad85bba-137c-4c5d-819e-a32f47fed8d3Reviewing files that changed from the base of the PR and between
5ed18b5d5aandfb7995b68d.core/libs/prx/libSceAgcDriver/Graphics/src/TextureFormat.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/TextureFormat.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageScaledUnorm.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaDescriptorFormat.hppcore/shader/recompiler/RdnaDecoder/src/RdnaDescriptorFormat.cppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/libSceAgcDriver.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T02:48:17Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional. No optional points were identified.
What I ran
Reviewed head
fb7995b68d21818469246f700c6234cad48faa30usingrepo_read.py's read-only review tools. No tests or other commands were run.Results
Negative control
Could not run a negative control because tests could not be executed in this review session.
Findings
Blocking
None.
Non-blocking
None.
Sources
Reviewed the prepared diff and the changed code at the pinned head. The author's reported test and hardware results were not independently verified.
Not verified
No tests, builds, validation layers, or console behavior were run or confirmed. The full
ShaderMemory.cppfile was not read; its changed hunk and surrounding lines were read. No changed files were excluded by the prepared review bundle.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:11:45Z.
Review: COMMENTED
The new unsigned-scaled texture debt entry directly edits
docs/dev/debt/libSceAgcDriver.md. Please put the addition in a debt fragment. It should also update the adjacent texture-format entry, which still says USCALED shader-side scaling is pending for all formats and points to #14709. The folded result should distinguish the six newly covered formats from the remaining gaps.Source review at
c7babf6696. On Linux lavapipe, the scalar, graphics and shader-memory CTests passed on pinned main and the merge with this head. The change-onlyagc_driver_image_scaled_unormfixture failed at texel 0, component 0 of8_USCALEDwithDST_SEL 0x3ac. It returned55.000004where the fixture expects55.000000. Both arms and the added fixture inserted Khronos validation layer 1.4.369 with shader caching disabled and showed no missing-layer messages orVUID-errors. Please check the exact integer reconstruction in the unfilteredimage_loadpath.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T19:25:44Z.
Review: APPROVED
Reviewed — looks good
The implementation maps the six unsigned scaled texture formats to UNORM views and restores their integer range in sampled, loaded, and gathered shader results; I found no verified blocking defect.
What I ran
Reviewed head
c7babf66969382cfc420ce0f5fa2af175e682dd5using the prepared description, commits, manifest, diff, andrepo_read.pyfor source context. Commands includedcaton the prepared review files,rg -nondiff.patch, andpython3 repo_read.py searchandcatfor changed code and callers. I did not run builds or tests. The hardware, validation-layer, and test results in the PR description are author-reported.Results
Negative control
Not run; no source mutation or test execution was performed.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No build, tests, validation-layer run, or console/GPU behavior was independently verified. The reviewed files were
core/libs/prx/libSceAgcDriver/Graphics/src/TextureFormat.cpp,core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp,core/libs/prx/libSceAgcDriver/tests/TextureFormat.cpp,core/libs/prx/libSceAgcDriver/tests/execution/ImageScaledUnorm.cpp,core/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hpp,core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp,core/shader/recompiler/RdnaDecoder/include/RdnaDecoder/RdnaDescriptorFormat.hpp,core/shader/recompiler/RdnaDecoder/src/RdnaDescriptorFormat.cpp,core/shader/recompiler/ShaderDiskCache.cpp,core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp, anddocs/dev/debt/libSceAgcDriver.md.files.jsonlists no excluded paths.To get this to a good state
Nothing is required.
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.