feat(agc): sample unnormalized S#s with mirror and mirror-once clamp modes #11126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11126"
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-10-25T18:56:58Z.
What
A FORCE_UNNORMALIZED S# with clamp mode 1 (mirror) or 3 (mirror-once) on X or Y is refused today:
Vulkan allows only clamp-to-edge and clamp-to-border with unnormalized coordinates, so the mirroring has to happen in the shader. I measured what the hardware does with these modes first. The setup:
tools/hw-oraclethrough the AMD Windows driver's comgr and HIP runtime.image_sample_lzandimage_sample_lz_o.x + 1000 * y.What the hardware does:
e1d402c6c(#4736): unnormalized repeat does not wrap on this hardware.Measured rows (excerpt)
X, texel = x, row 1, values are the sampled texel:
Y (64x4, u = 5.5): clamp 1/3 point
-9.5:row 3 -4.5:row 3 -3.5:row 3 -1:row 0; linear-1:row 0.5 -0.75:row 0.25.Offsets (
image_sample_lz_o, mirror):1.5 + (-3)reads texel 1,2.5 + (-5)texel 2,5.5 + (-8)texel 2. With clamp 2 the same rows read texel 0.How the change implements this:
DecodeSamplerResourceaccepts modes 1 and 3 with unnormalized coordinates and binds clamp-to-edge for them, as it already does for mode 0.MirrorUnnormalizedBase) carries the mirrored axes.ProveUnnormalizedsets it from the S# clamp fields, and the binding plan key already includes all four S# words.EmitSampleOpsamples from a coordinate in which each negative component on a mirrored axis is replaced with the float just below its negation, after any texel offset. That maps index i < 0 to -i - 1 and puts each bilinear tap where the hardware does. Clamp-to-edge then gives the clamp past the last texel.agc_shader_memorystill sees the plain folded coordinate.The
debt/libSceAgcDriver.mdentry now records the measured rule for modes 0, 1 and 3 and that gfx1013 is not measured. Modes 4, 5 and 7 still throw.No title I know of uses these modes yet, so
Unblocksis none. Ghost of Yōtei hits only mode 0, which main already accepts. I found this while re-checking an older local change of mine that wrapped mode 0 and mirrored modes 1 and 3 fully; this measurement showed that change was wrong.Tested
Windows 11 Pro 26300, NVIDIA GeForce RTX 4070 Ti SUPER (610.88), WinLibs GCC 15.2.0, Release. Tested head:
098fc2772onmain8a29e0883. The review follow-ups are specialization id 57536, a debt note, and dropping the refusal loops for modes 4, 5 and 7 from the decode test. The last test run was onf636ecd34with the validation settings below plusagc_driver_graphics: 72 of 72 pass, noVUID-errors.098fc2772only shortens the debt entry to under 1000 characters.agc_driver_image_sample_unnormalizedgains three samplers, checked against an index-mirroring reference throughimage_sample_lz,image_sample_l,image_sample, the offset variants andimage_sample_d, on 1-level and 4-level views:The test also adds more negative coordinates.
GuestSamplerResource.cppfrommain, it fails withguest sampler descriptor uses unnormalized coordinates with clamp mode 1 on X; only clamp-to-last-texel and clamp-to-border are implemented.SpirvImageEmitter.cppfrommain, it fails withimage_sample_lz, bilinear mirror on X and Y, point mips, 1-level image: (-1.000000, 2.500000) offset (0, 0) component 0 is 0.000000, expected 120.000000.agc_driver_graphics(the sampler decode test) now expects modes 1 and 3 to decode to clamp-to-edge. It no longer requires modes 4, 5 and 7 to throw: they are valid values that are not supported yet. The code still refuses them.I ran 71 sampling and shader tests on
mainand on this head, each withctest -V,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1. The regex wassample|gather|sampler|shader_memory|offset|unnormalized|shader_disk_cache|on_line|on_plane|on_volume|lod.was not found but was requested, and each log has the same 9 validation warnings.VUID-error.agc_sampled_storage_base_level_usage,agc_multisample_guest_accessandagc_sample_dumps: Not Run, because I did not build them.elf_offsets: a Python helper that cannot find its executable on this machine.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:02:09Z.
Review: APPROVED
Reviewed the eight-file change against base
8a29e088and heade2f17064. The unnormalized proof limits this path to supported 1D/2D sampled images; the emitter applies the negative-coordinate transform after folded offsets, and positive coordinates still use clamp-to-edge. Depth-compare and format-conversion paths are excluded or handled separately. The specialization IDs are in a separate range from the existing sampler and image IDs. The change adds focused decoding and sampling cases for mirror and mirror-once on both axes, point/bilinear filtering, offsets, and mip views. I could not independently run the Vulkan suite on this host; the PR reports 71 focused tests on both the base and change on the same RTX 4070 Ti SUPER with validation enabled, matching warning counts and no VUID errors, plus a separate AMD gfx1036 hardware-oracle measurement. Conventions, eligibility, intake, labels, and report checks pass; product build jobs are skipped on this PR.Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-25T21:45:40Z.
Review: APPROVED
Reviewed head
e2f17064b8by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine.What it does. An unnormalized S# with clamp mode 1 (mirror) or 3 (mirror-once) was refused. It is now accepted; the host sampler still uses clamp-to-edge, and the shader folds negative coordinates in a pipeline specialization (
MirrorUnnormalizedBase + sampler), so positive coordinates keep clamp-to-edge behaviour and negative ones are reflected. Mode 0 keeps its existing mapping.Checked the emitted maths.
MirroredUnnormalizedCoordtakesx < 0and returnsbitcast(bitcast_u32(-x) - 1), i.e.-xminus one ULP. That looked like a bug at first read (it is not-x - 1), but it is the intended continuous reflection: texelfloor(u) = k < 0must map to-k - 1, and subtracting one ULP makes an exact negative integer such as-1.0land in texel 0 rather than 1. The test coordinates include-1.0,-2.0,-width,-0.25,-0.75,-3.25, so the boundary case is exercised. I'd still put that reasoning in a one-line debt note, because the next reader will make the same mistake I nearly did.Other checks:
57728does not collide with anything inPipelineSpecialization.hpp. The other per-sampler bases are 64 apart (57344, 57408, 57472) and this one jumps to 57728, which wastes the 57536 slot for no reason I can see. Harmless, but please use the next free 64-aligned id or explain the gap.MirrorsIfUnnormalizedexcludes depth-compare, table-indexed samplers anddimensionother than 1D/2D, and the emitter additionally excludes cube, so unsupported shapes keep the old rejection path rather than silently sampling wrongly.One caveat to keep in view: the debt entry says the behaviour follows RDNA2 gfx1036 oracle measurements, not gfx1013 (the PS5 GPU family). That is disclosed, which is the honest way to do it, and I'd leave the caveat exactly as written.
Approving.
AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:48:09Z.
Review: COMMENTED
Withdrawn. The validation comparison this review asked for is already in the PR's
Testedsection:mainvs this change,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, no newVUID-. The title-ID demand was not a CONTRIBUTING requirement.