feat(agc): implement unnormalized S# clamp modes 4 and 5 (half border) #14964
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14964"
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 shahulmubeen-a on 2026-11-02T05:36:50Z.
What
A FORCE_UNNORMALIZED S# with clamp mode 4 (clamp-half-border) or 5 (mirror-once-half-border) on X or Y is refused today (after #14963):
These are the last two clamp modes an unnormalized S# refuses. The measurement is the one from #14963 (RDNA2 gfx1036 through
tools/hw-oracle,image_sample_lzandimage_sample_lz_o, 64x4 linear 32_FLOAT with texel100 + x + 1000 * y, transparent black and opaque white borders, point and bilinear, a run with unequal filters and a run on a view from mip 1).What the hardware does:
Measured rows (excerpt)
X, 64x4, v = 1.5 (row 1, texel = 1100 + x), transparent black border:
With the white border: 550.5, 825.25, 872.5 and 582 in place of 550, 825, 872.25 and 581.5.
Y (u = 10.5, texel = 110 + 1000 * y), linear, transparent black: clamp 4
-9.5:55 0.0:55 0.5:110 3.75:2332.5 4.0:1555 8.5:1555; clamp 5-9.5:1555 -3.5:3110 -1.0:610 0.0:110 4.5:1555.Offsets (
image_sample_lz_o, linear, transparent black): clamp 41.5 + (-3):550 -1.5 + 3:1101 62.5 + 3:581.5; clamp 52.5 + (-5):1102 63.5 + 1:581.5.Unequal filters, clamp 4, transparent black,
-1.0 / 0.25 / 64.0: magnification point, minification bilinear1100 / 1100 / 1163; magnification bilinear, minification point550 / 825 / 581.5.View from mip 1 (32x2, v = 0.5, texel 5000 + x), linear, transparent black: clamp 4
-0.25:2500 0.25:3750 31.75:3773.25 32.0:2515.5 64.0:2515.5; clamp 5-32.5:2515.5 -31.5:5031 0.0:5000 32.5:2515.5.How the change implements this:
DecodeSamplerResourceaccepts modes 4 and 5 with unnormalized coordinates. It binds clamp-to-border for that axis when the magnification filter is bilinear and clamp-to-edge when it is point (the host sampler already uses the magnification filter for both).ProveUnnormalizedsets the mirror axis bit for mode 5, as for 1, 3 and 7, and a new per-sampler constantHalfBorderUnnormalizedBase(58688, the next free base after main'sStorageReadBase58560, which spansMaxImages= 128 IDs) carries the axes in mode 4 or 5. Earlier heads used 57792, and the later merge of main used 58560, which collides withStorageReadBase. Thestatic_assertchain inDescriptorBindingBuilder.cppnow checksStorageReadBase, thenHalfBorderUnnormalizedBase, thenImageComponentBase.OpImageQuerySizeLodat level 0 of the bound view, the level an unnormalized sample reads. With a point filter the clamp changes nothing, since clamp-to-edge reads the last texel at size anyway.The model check in #14963's first comment (fold to the float below -c, at least 0.5, this clamp, then the host sampler with 8-bit bilinear weights) matches all 1660 measured values, including every mode 4 and 5 row and the mip-1 view.
The
debt/libSceAgcDriver.mdentry now covers modes 4 and 5; with this change no clamp mode throws for unnormalized coordinates. Anisotropy and MC_COORD_TRUNC still do.No title I know of uses these modes, so
Unblocksis none.Tested
Windows 11 Pro 26300, NVIDIA GeForce RTX 4070 Ti SUPER (610.88), WinLibs GCC 15.2.0, Release. Tested head: 51aaebd7d on c1baa5b78 (#14963) on #11126's head
1c9c1faf4.agc_driver_image_sample_unnormalizedgains six mode 4 and 5 samplers, checked like the others (all sample instructions, 1-level and 4-level views, and the view from mip 1, whose 6x3 size the clamp has to use):The reference clamps a bilinear coordinate on a mode 4 axis to [0, size] and on a mode 5 axis to [-size, size] before the footprint, mirrors index i < 0 on mode 5, and returns the border colour past the edge for a bilinear mode 4 or 5.
guest sampler descriptor uses unnormalized coordinates with clamp mode 4 on X; only wrap, mirror, clamp-to-last-texel, mirror-once, clamp-to-border and mirror-once-border are implemented.SpirvImageEmitter.cppfrom c1baa5b78 (no clamp in the shader), it fails withimage_sample_lz, bilinear clamp-half-border on X and Y, opaque white, 1-level image: (-1.000000, 2.500000) offset (0, 0) component 0 is 255.000000, expected 127.500000.agc_driver_graphics(the sampler decode test) expects modes 4 and 5 to decode to clamp-to-border with a bilinear magnification filter and clamp-to-edge with a point one, each with the other minification filter. With the sources of c1baa5b78 it fails with the same mode 4 refusal.I ran 84 sampling and shader tests with
ctest -V,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1onmain926f7dd49and on c1baa5b78 and 51aaebd7d. The regex wassample|gather|sampler|shader_memory|offset|unnormalized|shader_disk_cache|on_line|on_plane|on_volume|lod|^agc_driver_graphics$.was not found but was requested, and each log has the same 9 validation warnings (Undefined-Value-ShaderOutputNotConsumed-DynamicRendering).VUID-error.agc_driver_sample_order_grid_reference, which skips itself on this device (it does not keep depth at custom sample locations).Retested on the head with main merged in (
05700f8da7, mainef0d852ccd): the same regex now matches 104 tests. Run with the validation layer, whichVK_LOADER_DEBUG=layershows inserted as an instance and a device layer: 103 pass andagc_driver_sample_order_grid_referenceskips itself. NoVUID-lines.Rebased onto main
184c5100c1(head6718fcc63a), with the base moved to 58688. The 148 tests matched by the regex above withagc_driver_graphicspass with the validation layer,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1; noVUID-lines.tools/check_conventions.py --base origin/mainpasses.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
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T16:15:31Z.
Review: APPROVED
An RDNA 4 run, to go with JJenkx's RDNA 2 one. Windows 11, AMD Radeon RX 9070 XT (RDNA 4), AMD proprietary driver 32.0.32015.7029, WinLibs GCC,
BUILD_TESTING=ON, withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1.Head
51aaebd7d6(which carries #14963'sc1baa5b783), merged into currentmain:agc_driver_image_sample_unnormalizedandagc_driver_graphicspass, with 0 VUIDs.main'sGuestSamplerResource.cppand the four recompiler files restored, both fail, with 0 VUIDs.image_sample_unnormalizedstops onguest sampler descriptor uses unnormalized coordinates with clamp mode 7 on X.So the emitted modes 4, 5 and 7 give the measured gfx1036 values on RDNA 4 as well. The half-border bilinear result and the per-tap mirroring hold on this generation too.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T16:08:25Z.
Review: APPROVED
@shahulmubeen-a re-checked at
9b4cca8cb6.git range-diffof my approved51aaebd7d6against this head shows one change to this PR's own patch:HalfBorderUnnormalizedBasemoves from 57600 to 57728 (core/shader/recompiler/PipelineSpecialization.hpp:54), becausemainnow uses 57600 forMinLodBase(:52). #14963's commit underneath is unchanged.What I ran: head
9b4cca8cb6merged ontomainb11c7bf84f(mergebd34bba607), Windows 11, WinLibs GCC, Release, AMD Radeon RX 9070 XT, driver 32.0.32015.12012, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:agc_driver_image_sample_unnormalized: passes, including the mode 4 and 5 half-border cases. The log has noVUID-,SYNC-HAZARDor missing-layer line.check_conventions.py --base upstream/mainpasses.pr_overlap.py --branch: 63 open PRs touch the same files, none the same exports. The 57728 clash with #14621 is in my note above. Whichever of you lands second takes the next free base.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T21:28:39Z.
Review: APPROVED
Reviewed — looks good
Nothing in the changed code I inspected shows a blocking defect; the core coordinate handling and sampler decoding appear consistent with the stated behavior.
What I ran
fc9cefe2313f5a1ba94e8ca57c602dbf60603b01usingrepo_read.py.review/files.jsonwas unavailable through the reader, so any exclusions recorded there are not verified.Results
review/files.jsonunavailableFindings
Blocking
None.
Non-blocking
None.
Not verified
review/files.jsonwere not verified; that file could not be read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T12:20:52Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
6718fcc63a8750f093a92ab9aab196a0c9e47a63using the prepared diff and included file text. The changed hunks in all 7 reviewed files were read; no files were excluded. No tests or runtime checks were run.Commands used:
The first search returned usages. The second could not complete because the reader could not write its read log in the read-only workspace. Relevant changed-file context was inspected from the prepared files.
Results
Negative control
Not run; no tests were executed during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The unmodified
MirrorsIfUnnormalizeddefinition and runtime behavior were not independently verified because the reader could not complete its source lookup. The hardware measurements, author-reported test runs, and console behavior were not independently reproduced.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T12:26:33Z.
Review: COMMENTED
Actionable comments posted (1)
11440f92-6d8b-4a84-b44a-cb114029809bReviewing files that changed from the base of the PR and between
184c5100c1and6718fcc63a.core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cppcore/libs/prx/libSceAgcDriver/tests/GuestSamplerResource.cppcore/libs/prx/libSceAgcDriver/tests/execution/ImageSampleUnnormalized.cppcore/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cppcore/shader/recompiler/PipelineSpecialization.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-12-03T05:24:45Z.
Review: APPROVED
Reviewed — looks good
The inspected changes implement the described unnormalized clamp modes, and I found no verified blocking defect.
What I ran
Reviewed head
03f654f6c9437abbc9ece375ec39a1c3f2cce65cagainst the prepared diff; the manifest lists basemain. I inspected source withrepo_read.pyin the review environment; no build or tests were run.Results
Negative control
Not run; no test assertion was changed to confirm it fails on the defect.
Findings
Blocking
None.
Non-blocking
None.
Sources
The sampler decode selects the host address mode based on the magnification filter, and the shader applies mirror and half-border coordinate handling before sampling: GuestSamplerResource.cpp, DescriptorBindingBuilder.cpp, SpirvImageEmitter.cpp.
Not verified
Author-reported hardware measurements and test runs were not independently reproduced. Read:
core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp,core/libs/prx/libSceAgcDriver/tests/GuestSamplerResource.cpp,core/libs/prx/libSceAgcDriver/tests/execution/ImageSampleUnnormalized.cpp,core/shader/recompiler/Optimization/src/DescriptorBindingBuilder.cpp,core/shader/recompiler/PipelineSpecialization.hpp,core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp, anddocs/dev/debt/libSceAgcDriver.md. Excluded: none.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:45:21Z.
Review: COMMENTED
The trial merge onto
c1601e56d5was clean. The added cases distinguish point-filtered mode 4/5 from bilinear half-border and include unequal filters. Please retain an offset case at the mirror boundary, because the order of the integer offset and mirroring matters there. The hardware evidence covers gfx1036, and the debt change belongs in a fragment. Paired local shader and sampler tests are pending.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.