feat(agc): sample unnormalized anisotropic samplers through scaled coordinates #27670
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27670"
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 JJenkx on 2026-11-26T22:08:56Z.
What
An S# with
FORCE_UNNORMALIZEDand an anisotropic XY filter is refused today ("guest sampler descriptor uses unnormalized coordinates with anisotropic filtering, which is not implemented"), because Vulkan forbids anisotropy on anunnormalizedCoordinatessampler. #27644 measured on RDNA2 that the hardware applies the anisotropic filter in this case. The same measurements show that a normalized anisotropic sample at coordinates divided by the image size returns identical bits for power-of-two sizes. For a non-power-of-two width, one anisotropic-linear sample differed by about 0.01.This PR implements that route:
Proof (
DescriptorBindingBuilder.cpp): a sampler is marked as scaled when all of these hold:MC_COORD_TRUNCis clear;UnnormalizedSampleMismatch), so a 1D array laid out as rows, converted, packed and depth-compare modes are refused.Anything else keeps today's refusal.
Shader (
SpirvImageEmitter.cpp): under a new per-sampler specialization constant,ScaleUnnormalizedBase, the shader first does what the unnormalized path does: texel offsets are added to the coordinate, and mirrored axes are folded about zero. It then divides each spatial coordinate byOpImageQuerySizeLod(image, 0).Sampler (
ShaderResources.cpp): a scaled element gets a normalized Vulkan sampler with the S#'s anisotropy. It is pinned to LOD 0, matching the existing unnormalized rule, and each axis is clamped to the edge or the border as an unnormalized sampler would be. The minification filter is set to the magnification filter, which an unnormalized sample uses on hardware.Plumbing: the new per-element flag
samplerScaledUnnormalizedis added to the binding struct, the shader disk cache (FormatVersion97 → 98), the content key and the memory accounting.Gradient instructions, gathers, depth compare, image tables, arrays, cubes and 3D images are not changed. The debt entry records the measured scope.
Related open PRs:
unnormalizedCoordinatessamplers. That's compatible with this PR, because scaled samplers are created normalized.Tested
Linux 7.3.5, RX 6650 XT (gfx1032), RADV Mesa 26.3.1, Release, GCC 16.2.1, at the PR head
526078a4e294.unnormalized,sampler,single_texel,mirror,image_tableandgather;shader_disk_cacheandagc_driver_graphics.agc_driver_image_sample_unnormalized: three anisotropic S#s (16× clamp-to-last-texel, 4× mirror on X and Y, 2× clamp-to-border). Each is checked against the test's hardware reference on a 1-level image, a 4-level view, and with lane and constant offsets. Onmainthese S#s are refused inGuestSamplerResource.cpp.agc_shader_memory: the proof marks a 2D anisotropic S# as scaled and emits the specialization constant. A bilinear S# stays on the unnormalized path. A 3D T#, a 2D image whose runtime mode is 3D and a 1D array laid out as rows (layerRows) are still refused; without the runtime-mode check thelayerRowscase is scaled.agc_shader_disk_cache: round-trips the new flag.Title run (no-harm check): Destruction AllStars (PPSA02630), offline, Cross every 15 s from 30 s, 150 s, through the native harness:
main97319cf0b9: exit 0 at 148 s.ac75555824plus this commit): exit 0 at 150 s.Both reach the same main menu at 140 s with matching rendering: character, PLAY/SHOP/CUSTOMISE/TRAINING/STORY tabs, "No server". Neither logs the anisotropic refusal. This title, Squirrel with a Gun (PPSA22102) and Thymesia (PPSA05213) last hit the refusal on 17–18 November, on experimental builds of mine. Current
mainno longer reaches it in these titles in my runs, so this run shows no harm but not an unblock. The two runs were not measured performance runs, and the builds sit on differentmaincommits, so no frame-rate comparison is made.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
New Features
Documentation
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T22:17:01Z.
Review: COMMENTED
Actionable comments posted: 2
97edef52-e44b-4fc1-96b9-96b8e0e5c2f0Reviewing files that changed from the base of the PR and between
00b15fcbb0and0e458fccbd.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageSampleUnnormalized.cppcore/shader/recompiler/IntermediateRepresentation/include/IntermediateRepresentation/IrMetadata/Resources.hppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/PipelineSpecialization.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/ShaderDiskCache.hppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppdocs/dev/debt/changes/feat-agc-unnormalized-aniso-sampler.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T22:47:24Z.
Review: COMMENTED
Reviewed — comments
The anisotropic unnormalized path is narrowly gated and its sampler transformation and shader scaling are covered by focused tests; I did not run the reported GPU or cache test suite, so a formal approval is not justified.
What I ran
0e458fccbd78d274445899643f5523c8efd4cb2ausing the prepared review bundle andrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
ShaderResources.cpp,ShaderMemory.cpp, andShaderDiskCache.cpp. I read the relevantShaderResources.cppandShaderDiskCache.cppranges through the pinned reader, but did not readShaderMemory.cppor every other changed-file range. Consider ensuring the merge checks cover the full reported test suite.Not verified
ShaderMemory.cpp; its changed test lines are visible in the diff only in part. The other changed files were either read in full from the bundle or inspected at relevant ranges through the reader.files.jsonwas unavailable in the prepared review folder; the included/excluded status was taken frommanifest.json.To get this to a good state
Nothing is required. Optional: retain CI coverage for the reported GPU and cache tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T00:36:26Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this review; the checks I could perform support the implementation, but I did not run the reported GPU or cache tests.
What I ran
30e4f420bedc7ab667222c991832afa0a7ec6044.repo_read.pyto inspect the added lines at the pinned head.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
ShaderResources.cppandShaderMemory.cppwere excluded from the preparedfiles/bundle because of size; their changed ranges were read throughrepo_read.py.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-27T05:52:06Z.
Review: APPROVED
Checked head
30e4f420beon Windows 11 with WinLibs GCC 15.2 (Release), applied alone tomainad7582bad4, on both GPUs in this machine: AMD Radeon(TM) Graphics (driver 26.11.2) and NVIDIA GeForce RTX 5080 (driver 621.24).tools/check_conventions.py --headandtools/debt_fold.py --checkpassed, and the full build succeeded.The tests matching
unnormalized,sampler,single_texel,mirror,image_table,gather,shader_disk_cache,shader_memoryand^agc_driver_graphics(90 tests) ran onmainand on this PR, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_GPUset to each device, and the layer from Vulkan SDK 1.4.363.0:main(withmain's tests): 90/90 on each GPU.agc_driver_image_sample_unnormalized,agc_shader_memoryandagc_shader_disk_cache.Each of the four logs has 66
Insert instance layer "VK_LAYER_KHRONOS_validation"lines, and none haswas not found but was requested by env var VK_INSTANCE_LAYERSor anyVUID-line. With the PR'sImageSampleUnnormalized.cppandmain's source,agc_driver_image_sample_unnormalizedfails on both GPUs withguest sampler descriptor uses unnormalized coordinates with anisotropic filtering, which is not implemented.The sampler rewrite does what the description says.
FORCE_UNNORMALIZED(word 0 bit 15) is cleared. Each axis's clamp becomes clamp-to-last-texel, or clamp-to-border for modes 6 and 7. The LOD range in word 1 is zeroed, and the minification filter is set from the magnification filter. The proof only accepts clamp modes the unnormalized path already takes (not 4 or 5), withMC_COORD_TRUNCclear. Since the second commit, it judges planarity by the runtime image mode, which addresses CodeRabbit's Major finding even though the thread is still open. CodeRabbit's link comment doesn't apply: the fragment's text is folded intodocs/dev/debt/libSceAgcDriver.md, where../../../core/...is right, and 1,694 fragments onmainuse that prefix (none use../../../../core/).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-27T08:12:17Z.
Review: COMMENTED
Reviewed — comments
Changes are limited to the eligible unnormalized anisotropic sampling path; I found no verified blocking defect in the code ranges inspected, and the reported checks were not run in this review.
What I ran
The prepared bundle pins the review to head
526078a4e2940a3b2251c20e234f4387a765af3a. I inspected the prepared diff and targeted code ranges usingrepo_read.py; no tests or builds were run.Results
Findings
Blocking
None identified in the inspected code.
Non-blocking
None.
Not verified
I read the changed code in
DescriptorBindingBuilder.cpp,SpirvImageEmitter.cpp,ShaderResources.cpp,ShaderDiskCache.cpp,ShaderDiskCache.hpp,Recompiler.cpp,Recompiler.hpp,PipelineSpecialization.hpp,Resources.hpp,ImageSampleUnnormalized.cpp,ShaderDiskCache.cpptests, and the new debt note, plus relevant ranges inShaderMemory.cpp. Full file text was not read.ShaderResources.cppandShaderMemory.cppwere excluded from the prepared full-text bundle as too large; their relevant ranges were inspected through the reader. No build, test, GPU, or console run was performed here; reported hardware and cache test results and the title run were not independently verified.To get this to a good state
Nothing is required. The reported test and runtime results are optional context and were not independently reproduced.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T11:37:22Z.
Review: COMMENTED
Actionable comments posted: 2
12adbb49-55a6-4625-b347-1731731b5744Reviewing files that changed from the base of the PR and between
526078a4e2andc5e0dce3cb.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/PipelineSpecialization.hppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/ShaderDiskCache.cppcore/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cppIncluded 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-29T11:57:42Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the code reviewed; the reported hardware and test results were not rerun here.
What I ran
Reviewed head
c5e0dce3cbe93df9d7f923b1d5da744333f02f3cusing the prepared diff and the pinned repository reader. No build or test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The claimed GPU/cache tests, validation-layer run, and game run were not independently verified.
ShaderMemory.cppandShaderResources.cppwere excluded from the review folder because they were too large; changed sections were inspected through the reader. The other changed files listed in the manifest were read or inspected via the prepared diff. No physical-console behavior or PS5 GPU results were verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T12:33:17Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the review packet and targeted source ranges support merging.
What I ran
Reviewed head
3c57860ec86aa6f2f64b29adaa317f55cfb3fe2cusingrepo_read.pyto inspect the prepared description, commits, manifest, diff, and selected source ranges. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
ShaderResources.cppandShaderMemory.cppwas excluded for size; targeted ranges and their changed hunks were inspected.files.jsonwas not available through the reader, so excluded-by-rule files could not be enumerated. Other included changed files were listed in the manifest but not all were read. No build, automated tests, GPU hardware behavior, or physical-console behavior was verified. The author-reported test results in the description were not independently run.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-30T01:03:10Z.
Review: APPROVED
Re-checked head
3c57860ec8. Since30e4f420be, which I approved, the changes are: the merge ofmain(withScaleUnnormalizedBasemoved to 58688),FormatVersion99, the eleven flag groups in the key diagnostics, and keeping mirrored implicit-LOD samples with a texel offset off the scaled route.Windows 11, WinLibs GCC 15.2, Release, merged onto
mainb3856362f3, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layerand the layer from SDK 1.4.363.0. I ran the same tests as last time: those matchingunnormalized,sampler,single_texel,mirror,image_table,gather,shader_disk_cache,shader_memoryand^agc_driver_graphics, plusagc_driver_key_miss(93 tests in all):main: 93/93 on the RTX 5080 and 93/93 on the Radeon iGPU.Insert instance layer "VK_LAYER_KHRONOS_validation"lines. None haswas not found but was requested by env var VK_INSTANCE_LAYERSor anyVUID-.DescriptorBindingBuilder.cppfrom before3c57860ec8and this head's tests,agc_shader_memoryfails with "a mirrored implicit-LOD sample with a texel offset was scaled, which applies the offset after the mirror". So the new case covers the fix.tools/check_conventions.py --headpasses, with one warning: sincedd8e299a5f, thefeat-agc-unnormalized-aniso-sampler.mddebt entry is 1,013 characters, 13 over the 1,000 limit.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T03:29:53Z.
Review: APPROVED
Reviewed — looks good
The change is sound at
d8288a02e9a0e50c5cced3cea6630bbcef059264; no verified blocking findings were found.What I ran
Reviewed the prepared diff and targeted source context using
repo_read.pyat the pinned head. No tests or builds were run. The author-reported test results were not independently run.Results
Negative control
A negative control could not be run because tests were not run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The reported GPU, cache, validation-layer, and title runs were not independently verified.
ShaderResources.cppandShaderMemory.cppfull text was not included infiles/; the changed hunks and relevant source ranges were read throughrepo_read.py. No files were excluded by thefiles.jsonrules.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T21:02:27Z.
Review: COMMENTED
The scaled path queries and divides by both image dimensions, while the debt entry identifies the measured footprint as a one-row image and the fixture’s new ratios use that geometry. Could the hardware oracle and Vulkan check include a nonsquare 2D image with varying S and T gradients and a nonzero base mip? That would cover both coordinate divisors and the view-relative LOD used for the size query.
Source review at
d8288a02e9. The head trial-merges onto6ef4f2f73b. Focused Linux checks are queued.AI-assisted: yes.
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.