feat(agc): implement unnormalized S# clamp mode 7 (mirror-once-border) #14963

Merged
shahulmubeen-a merged 2 commits from upstream-pr/14963 into main 2026-11-16 05:37:04 +00:00
shahulmubeen-a commented 2026-11-02 05:36:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by shahulmubeen-a on 2026-11-02T05:36:24Z.


What

A FORCE_UNNORMALIZED S# with clamp mode 7 (mirror-once-border) on X or Y is refused today (after #11126):

guest sampler descriptor uses unnormalized coordinates with clamp mode 7 on X; only wrap, mirror, clamp-to-last-texel, mirror-once and clamp-to-border are implemented

I measured modes 4 to 7 on the hardware first, with the same setup as #11126:

  • GPU: RDNA2 (gfx1036), with tools/hw-oracle through the AMD Windows driver's comgr and HIP runtime.
  • Settings: wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even.
  • Instructions: image_sample_lz and image_sample_lz_o.
  • T#: linear 32_FLOAT, 64x4, texel 100 + x + 1000 * y, so a border value (0 or 1) never equals a texel. A second run used a 2-level chain viewed from mip 1 (32x2, texel 5000 + x + 1000 * y).
  • Borders: transparent black and opaque white. Filters: point and bilinear, plus unequal magnification and minification filters.

What the hardware does with mode 7:

  • Texel index i < 0 reads texel -i - 1, as in modes 1 and 3. Past the last texel, and past the mirrored range, it reads the border colour. The texel offset is added first. Y behaves like X.
  • Each bilinear tap is mirrored on its own. So in [-0.5, 0.5] the tap at index -1 reads texel 0 again, not the border: 0.0 and 0.25 read texel 0 alone.
Measured rows (excerpt)

X, 64x4, v = 1.5 (row 1, texel = 1100 + x), transparent black border:

u               -66.5  -64.5  -63.5   -1.0  -0.75  -0.25    0.0   0.25  63.75   64.0  64.25   64.5
clamp 6 linear      0      0      0      0      0    275    550    825 872.25  581.5 290.75      0
clamp 7 point       0      0   1163   1100   1100   1100   1100   1100   1163      0      0      0
clamp 7 linear      0      0   1163 1100.5 1100.25  1100   1100   1100 872.25  581.5 290.75      0

With the white border each border tap adds its weight, e.g. 872.5, 582 and 291.5 at 63.75, 64.0 and 64.25.

Y (u = 10.5, texel = 110 + 1000 * y), clamp 7 linear, transparent black: -4.5:0 -3.5:3110 -1:610 -0.75:360 -0.25:110 3.75:2332.5 4.0:1555 4.25:777.5 4.5:0.

Offsets (image_sample_lz_o, clamp 7 point): 1.5 + (-3) reads 1101, 5.5 + (-8) 1102, 62.5 + 3 the border.

View from mip 1 (32x2, v = 0.5, texel 5000 + x), clamp 7 point: -33.0:border -32.5:border -31.5:5031 -1.0:5000 31.75:5031 32.0:border.

How the change implements this:

  • DecodeSamplerResource accepts mode 7 with unnormalized coordinates and binds clamp-to-border for that axis.
  • ProveUnnormalized sets the axis bit of the existing MirrorUnnormalizedBase constant for mode 7 as for 1 and 3, so the shader folds a negative coordinate as #11126 does.
  • After the fold, a mirrored coordinate is raised to at least 0.5, the centre of texel 0. With clamp-to-border the bilinear tap at index -1 would otherwise read the border where the hardware reads texel 0 again. For modes 1 and 3 nothing changes, since clamp-to-edge already reads texel 0 there, and a point sample reads texel 0 either way.

A Python model of exactly this (fold to the float below -c, at least 0.5, then the host sampler with 8-bit bilinear weights) matches all 1660 measured values of both runs, modes 2 and 4 to 7. Without the 0.5 step it misses 44 of them, all bilinear mode 5 and 7 samples at -0.25, 0.0 and 0.25.

The probe scripts (probe_border.py, probe_border2.py), their output and the model check are in the first comment.

The debt/libSceAgcDriver.md entry now covers mode 7. Modes 4 and 5 still throw; a follow-up PR implements them.

No title I know of uses mode 7, so Unblocks is none.

Tested

Windows 11 Pro 26300, NVIDIA GeForce RTX 4070 Ti SUPER (610.88), WinLibs GCC 15.2.0, Release. Tested head: c1baa5b78 on #11126's head 1c9c1faf4 (which merges main a644edf30).

  • agc_driver_image_sample_unnormalized gains four mode 7 samplers, checked through image_sample_lz, image_sample_l, image_sample, the offset variants and image_sample_d, on 1-level and 4-level views and on a view from mip 1:

    • bilinear mirror-once-border on X and Y, opaque white border;
    • point mirror-once-border on X with clamp-to-last-texel on Y, opaque black;
    • bilinear clamp-to-border on X with mirror-once-border on Y, transparent black;
    • point mirror on X with mirror-once-border on Y, opaque white.

    The reference now takes each axis's clamp mode and the border colour from the S# words; a mirrored axis maps index i < 0 to -i - 1 and mode 6 or 7 returns the border colour past the edge.

    • With the sources of #11126's head, it fails with guest sampler descriptor uses unnormalized coordinates with clamp mode 7 on X; only wrap, mirror, clamp-to-last-texel, mirror-once and clamp-to-border are implemented.
    • With SpirvImageEmitter.cpp from #11126's head (no 0.5 step), it fails with image_sample_lz, bilinear mirror-once-border on X and Y, opaque white, 1-level image: (0.000000, 3.500000) offset (0, 0) component 0 is 247.501938, expected 240.000000.
  • agc_driver_graphics (the sampler decode test) expects mode 7 to decode to clamp-to-border, with each border colour type, and clamp-to-edge for a mode 2 Y axis. With the sources of #11126's head it fails with the same mode 7 refusal.

  • I ran 84 sampling and shader tests with ctest -V, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 on main 926f7dd49 and on c1baa5b78. The regex was sample|gather|sampler|shader_memory|offset|unnormalized|shader_disk_cache|on_line|on_plane|on_volume|lod|^agc_driver_graphics$.

    • The layer was loaded in every run: there is no was not found but was requested, and each log has the same 9 validation warnings (Undefined-Value-ShaderOutputNotConsumed-DynamicRendering).
    • No log has a VUID- error.
    • Every run passes 83 and skips agc_driver_sample_order_grid_reference, which skips itself on this device (it does not keep depth at custom sample locations).
  • tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #11126
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 610.88, Windows 11 Pro 26300 (tests); AMD Radeon Graphics iGPU of a Ryzen 9 7950X (gfx1036), AMD Windows driver, for the oracle measurement
  • AI-assisted: yes (written with Claude Code; I reviewed and ran it)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5115531180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14963). Originally posted by [shahulmubeen-a](https://github.com/shahulmubeen-a) on 2026-11-02T05:36:24Z. --- ### What A FORCE_UNNORMALIZED S# with clamp mode 7 (mirror-once-border) on X or Y is refused today (after #11126): ``` guest sampler descriptor uses unnormalized coordinates with clamp mode 7 on X; only wrap, mirror, clamp-to-last-texel, mirror-once and clamp-to-border are implemented ``` I measured modes 4 to 7 on the hardware first, with the same setup as #11126: - GPU: RDNA2 (gfx1036), with `tools/hw-oracle` through the AMD Windows driver's comgr and HIP runtime. - Settings: wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even. - Instructions: `image_sample_lz` and `image_sample_lz_o`. - T#: linear 32_FLOAT, 64x4, texel `100 + x + 1000 * y`, so a border value (0 or 1) never equals a texel. A second run used a 2-level chain viewed from mip 1 (32x2, texel `5000 + x + 1000 * y`). - Borders: transparent black and opaque white. Filters: point and bilinear, plus unequal magnification and minification filters. What the hardware does with mode 7: - Texel index i < 0 reads texel -i - 1, as in modes 1 and 3. Past the last texel, and past the mirrored range, it reads the border colour. The texel offset is added first. Y behaves like X. - Each bilinear tap is mirrored on its own. So in [-0.5, 0.5] the tap at index -1 reads texel 0 again, not the border: 0.0 and 0.25 read texel 0 alone. <details><summary>Measured rows (excerpt)</summary> X, 64x4, v = 1.5 (row 1, texel = 1100 + x), transparent black border: ``` u -66.5 -64.5 -63.5 -1.0 -0.75 -0.25 0.0 0.25 63.75 64.0 64.25 64.5 clamp 6 linear 0 0 0 0 0 275 550 825 872.25 581.5 290.75 0 clamp 7 point 0 0 1163 1100 1100 1100 1100 1100 1163 0 0 0 clamp 7 linear 0 0 1163 1100.5 1100.25 1100 1100 1100 872.25 581.5 290.75 0 ``` With the white border each border tap adds its weight, e.g. 872.5, 582 and 291.5 at 63.75, 64.0 and 64.25. Y (u = 10.5, texel = 110 + 1000 * y), clamp 7 linear, transparent black: `-4.5:0 -3.5:3110 -1:610 -0.75:360 -0.25:110 3.75:2332.5 4.0:1555 4.25:777.5 4.5:0`. Offsets (`image_sample_lz_o`, clamp 7 point): `1.5 + (-3)` reads 1101, `5.5 + (-8)` 1102, `62.5 + 3` the border. View from mip 1 (32x2, v = 0.5, texel 5000 + x), clamp 7 point: `-33.0:border -32.5:border -31.5:5031 -1.0:5000 31.75:5031 32.0:border`. </details> How the change implements this: - `DecodeSamplerResource` accepts mode 7 with unnormalized coordinates and binds clamp-to-border for that axis. - `ProveUnnormalized` sets the axis bit of the existing `MirrorUnnormalizedBase` constant for mode 7 as for 1 and 3, so the shader folds a negative coordinate as #11126 does. - After the fold, a mirrored coordinate is raised to at least 0.5, the centre of texel 0. With clamp-to-border the bilinear tap at index -1 would otherwise read the border where the hardware reads texel 0 again. For modes 1 and 3 nothing changes, since clamp-to-edge already reads texel 0 there, and a point sample reads texel 0 either way. A Python model of exactly this (fold to the float below -c, at least 0.5, then the host sampler with 8-bit bilinear weights) matches all 1660 measured values of both runs, modes 2 and 4 to 7. Without the 0.5 step it misses 44 of them, all bilinear mode 5 and 7 samples at -0.25, 0.0 and 0.25. The probe scripts (`probe_border.py`, `probe_border2.py`), their output and the model check are in the first comment. The `debt/libSceAgcDriver.md` entry now covers mode 7. Modes 4 and 5 still throw; a follow-up PR implements them. No title I know of uses mode 7, so `Unblocks` is none. ### Tested Windows 11 Pro 26300, NVIDIA GeForce RTX 4070 Ti SUPER (610.88), WinLibs GCC 15.2.0, Release. Tested head: c1baa5b78 on #11126's head 1c9c1faf4 (which merges `main` a644edf30). - `agc_driver_image_sample_unnormalized` gains four mode 7 samplers, checked through `image_sample_lz`, `image_sample_l`, `image_sample`, the offset variants and `image_sample_d`, on 1-level and 4-level views and on a view from mip 1: - bilinear mirror-once-border on X and Y, opaque white border; - point mirror-once-border on X with clamp-to-last-texel on Y, opaque black; - bilinear clamp-to-border on X with mirror-once-border on Y, transparent black; - point mirror on X with mirror-once-border on Y, opaque white. The reference now takes each axis's clamp mode and the border colour from the S# words; a mirrored axis maps index i < 0 to -i - 1 and mode 6 or 7 returns the border colour past the edge. - With the sources of #11126's head, it fails with `guest sampler descriptor uses unnormalized coordinates with clamp mode 7 on X; only wrap, mirror, clamp-to-last-texel, mirror-once and clamp-to-border are implemented`. - With `SpirvImageEmitter.cpp` from #11126's head (no 0.5 step), it fails with `image_sample_lz, bilinear mirror-once-border on X and Y, opaque white, 1-level image: (0.000000, 3.500000) offset (0, 0) component 0 is 247.501938, expected 240.000000`. - `agc_driver_graphics` (the sampler decode test) expects mode 7 to decode to clamp-to-border, with each border colour type, and clamp-to-edge for a mode 2 Y axis. With the sources of #11126's head it fails with the same mode 7 refusal. - I ran 84 sampling and shader tests with `ctest -V`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` on `main` 926f7dd49 and on c1baa5b78. The regex was `sample|gather|sampler|shader_memory|offset|unnormalized|shader_disk_cache|on_line|on_plane|on_volume|lod|^agc_driver_graphics$`. - The layer was loaded in every run: there is no `was not found but was requested`, and each log has the same 9 validation warnings (`Undefined-Value-ShaderOutputNotConsumed-DynamicRendering`). - No log has a `VUID-` error. - Every run passes 83 and skips `agc_driver_sample_order_grid_reference`, which skips itself on this device (it does not keep depth at custom sample locations). - `tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #11126 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER, driver 610.88, Windows 11 Pro 26300 (tests); AMD Radeon Graphics iGPU of a Ryzen 9 7950X (gfx1036), AMD Windows driver, for the oracle measurement - [x] AI-assisted: yes (written with Claude Code; I reviewed and ran it) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 16:15:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T16:15:32Z.

Review: APPROVED


Tested as part of #14964's stack, which contains this commit (c1baa5b783), on Windows 11 with an AMD Radeon RX 9070 XT (RDNA 4), AMD proprietary driver 32.0.32015.7029, and the Khronos validation layer on:

  • The mode 7 samplers in agc_driver_image_sample_unnormalized and the agc_driver_graphics descriptor checks pass, with 0 VUIDs.
  • With main's sampler and recompiler sources, the test stops on the mode 7 refusal.

Details are on #14964.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5739615681 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14963#pullrequestreview-5739615681). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T16:15:32Z. **Review:** APPROVED --- Tested as part of #14964's stack, which contains this commit (`c1baa5b783`), on Windows 11 with an AMD Radeon RX 9070 XT (RDNA 4), AMD proprietary driver 32.0.32015.7029, and the Khronos validation layer on: - The mode 7 samplers in `agc_driver_image_sample_unnormalized` and the `agc_driver_graphics` descriptor checks pass, with 0 VUIDs. - With `main`'s sampler and recompiler sources, the test stops on the mode 7 refusal. Details are on #14964.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14963
No description provided.