fix(agc): sample point-filtered clamp-half-border axes like clamp-to-last-texel #22753

Open
MichonGoddijn231849 wants to merge 1 commit from upstream-pr/22753 into main
MichonGoddijn231849 commented 2026-11-18 07:07:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-18T07:07:14Z.


What

An S# with clamp mode 4 (clamp, half border) on X or Y was always created as VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER. With point XY filters RDNA2 never reads the border in that mode: past an edge it returns the edge texel, exactly like clamp-to-last-texel. AnyPS5 returned the border colour there.

  • GuestSamplerResource.cpp: when neither XY filter is bilinear or anisotropic (both 0, point), an X or Y axis in mode 4 maps to VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE. With a bilinear or anisotropic filter it keeps CLAMP_TO_BORDER, which is still not what the hardware does: the hardware blends half the border at the edge. Z keeps CLAMP_TO_BORDER too, since that axis was not measured. Unnormalized samplers have their own path (#14964) and are unchanged.
  • test: tests/GuestSamplerResource.cpp (run by agc_driver_graphics) checks that:
    • a point-filtered S# with mode 4 on X, Y and Z decodes to clamp-to-edge on U and V and clamp-to-border on W;
    • the same S# with a bilinear magnification filter keeps clamp-to-border on U and V;
    • the existing linear-filter case (mode 4 on Z decodes to clamp-to-border) is unchanged.
  • debt: the "Normalized S# clamp modes 4, 5 and 7" entry added by #22729 is still a pending fragment on main, so a ## change fragment cannot name it yet (debt_fold --check reports 0 matching entries). This PR therefore updates that fragment in place to record the new mapping, as #22579 did for a libc fragment. The rest of the entry (bilinear modes 4 and 5, mode 7) is unchanged.

Source of the semantics: the hardware-oracle measurement in #22729 (gfx1036, AMD Windows driver 32.0.21045.16010): an 8×1 32_FLOAT texture, image_sample_lz at 16 normalized x from −2.3 to 2.6, clamp modes 0 to 7, border colour types 0, 1 and 2. With point filters mode 4 returns the edge texel at every x past either edge, the same as mode 2.

Tested

pr_overlap.py --branch failed closed on one open PR that conflicts with main and shares GuestSamplerResource.cpp or its test; its diff does not touch the address-mode mapping or the clamp-mode fragment.

Windows 11 Pro 10.0.26200, validation layer 1.4.363, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer:

  • The point-filter sweep, hardware against agc_oracle_runner. Before: mode 4 differed at 13 of 16 x for each border type on both GPUs. After: mode 4 matches on both GPUs for all three border types. Modes 0–3, 5 and 6 still match, and mode 7 differs as before (documented).
  • agc_driver_graphics: passes on NVIDIA GeForce RTX 5080 (610.74) and AMD Radeon(TM) Graphics (gfx1036, 32.0.21045.16010), 0 VUID-.
  • The 101 sampling execution tests (ctest -R 'agc_driver_.*(sample|gather|unnormalized|cube|color_compare|border|clamp)'):
    • AMD: 101/101;
    • NVIDIA: 99/101, where image_sample_lod_clamp and image_sample_lod_clamp_shader_lane fail as they do on main on this GPU;
    • 0 VUID- on both.

Each log shows Insert instance layer "VK_LAYER_KHRONOS_validation" and no was not found but was requested.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5371526110 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22753). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-11-18T07:07:14Z. --- ### What An S# with clamp mode 4 (clamp, half border) on X or Y was always created as `VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER`. With point XY filters RDNA2 never reads the border in that mode: past an edge it returns the edge texel, exactly like clamp-to-last-texel. AnyPS5 returned the border colour there. - **`GuestSamplerResource.cpp`:** when neither XY filter is bilinear or anisotropic (both 0, point), an X or Y axis in mode 4 maps to `VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE`. With a bilinear or anisotropic filter it keeps `CLAMP_TO_BORDER`, which is still not what the hardware does: the hardware blends half the border at the edge. Z keeps `CLAMP_TO_BORDER` too, since that axis was not measured. Unnormalized samplers have their own path (#14964) and are unchanged. - **test:** `tests/GuestSamplerResource.cpp` (run by `agc_driver_graphics`) checks that: - a point-filtered S# with mode 4 on X, Y and Z decodes to clamp-to-edge on U and V and clamp-to-border on W; - the same S# with a bilinear magnification filter keeps clamp-to-border on U and V; - the existing linear-filter case (mode 4 on Z decodes to clamp-to-border) is unchanged. - **debt:** the "Normalized S# clamp modes 4, 5 and 7" entry added by #22729 is still a pending fragment on `main`, so a `## change` fragment cannot name it yet (`debt_fold --check` reports 0 matching entries). This PR therefore updates that fragment in place to record the new mapping, as #22579 did for a libc fragment. The rest of the entry (bilinear modes 4 and 5, mode 7) is unchanged. **Source of the semantics:** the hardware-oracle measurement in #22729 (gfx1036, AMD Windows driver 32.0.21045.16010): an 8×1 32_FLOAT texture, `image_sample_lz` at 16 normalized x from −2.3 to 2.6, clamp modes 0 to 7, border colour types 0, 1 and 2. With point filters mode 4 returns the edge texel at every x past either edge, the same as mode 2. ### Tested `pr_overlap.py --branch` failed closed on one open PR that conflicts with `main` and shares `GuestSamplerResource.cpp` or its test; its diff does not touch the address-mode mapping or the clamp-mode fragment. Windows 11 Pro 10.0.26200, validation layer 1.4.363, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`: - **The point-filter sweep, hardware against `agc_oracle_runner`.** Before: mode 4 differed at 13 of 16 x for each border type on both GPUs. After: mode 4 matches on both GPUs for all three border types. Modes 0–3, 5 and 6 still match, and mode 7 differs as before (documented). - **`agc_driver_graphics`:** passes on NVIDIA GeForce RTX 5080 (610.74) and AMD Radeon(TM) Graphics (gfx1036, 32.0.21045.16010), 0 `VUID-`. - **The 101 sampling execution tests** (`ctest -R 'agc_driver_.*(sample|gather|unnormalized|cube|color_compare|border|clamp)'`): - AMD: 101/101; - NVIDIA: 99/101, where `image_sample_lod_clamp` and `image_sample_lod_clamp_shader_lane` fail as they do on `main` on this GPU; - 0 `VUID-` on both. Each log shows `Insert instance layer "VK_LAYER_KHRONOS_validation"` and no `was not found but was requested`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 610.74, Windows 11 Pro 10.0.26200; AMD Radeon(TM) Graphics (RDNA2 iGPU, gfx1036), driver 32.0.21045.16010, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-18 16:51:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T16:51:36Z.

Review: APPROVED


Reviewed — looks good

The reviewed change maps normalized point-filtered mode 4 on X and Y to clamp-to-edge, and I found no blocking defect in the changed code.

What I ran

Reviewed head 1052422828fabb44774a7cc38a90574e0c4fc554 against the prepared diff; no tests or build commands were run. Read the description, commits, manifest, diff, GuestSamplerResource.cpp, and tests/GuestSamplerResource.cpp. All three changed files were marked included in the manifest; I also read the changed debt fragment from the diff.

Results

Check Result Note
Diff and targeted code review passed Three changed files inspected
Tests and build not run No commands executed

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author-reported hardware sweeps and test runs were not independently verified. The remaining lines of the sampler test file and repository context beyond the targeted code were not read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5961178923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22753#pullrequestreview-5961178923). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T16:51:36Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change maps normalized point-filtered mode 4 on X and Y to clamp-to-edge, and I found no blocking defect in the changed code. ## What I ran Reviewed head `1052422828fabb44774a7cc38a90574e0c4fc554` against the prepared diff; no tests or build commands were run. Read the description, commits, manifest, diff, `GuestSamplerResource.cpp`, and `tests/GuestSamplerResource.cpp`. All three changed files were marked included in the manifest; I also read the changed debt fragment from the diff. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Three changed files inspected | | Tests and build | not run | No commands executed | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The author-reported hardware sweeps and test runs were not independently verified. The remaining lines of the sampler test file and repository context beyond the targeted code were not read. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 22:00:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:00:58Z.

Review: COMMENTED


The decode change requires both XY filters to be point and keeps Z outside the measured change. The mock verifies address-mode selection, while #22942 checks that the chosen mode affects actual sampling. Please retain the full-border control when landing the dependent fixture. The common graphics control and the combined behavior check are queued on lavapipe.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179363606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22753#pullrequestreview-6179363606). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:00:58Z. **Review:** COMMENTED --- The decode change requires both XY filters to be point and keeps Z outside the measured change. The mock verifies address-mode selection, while #22942 checks that the chosen mode affects actual sampling. Please retain the full-border control when landing the dependent fixture. The common graphics control and the combined behavior check are queued on lavapipe. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/22753:upstream-pr/22753'
git switch 'upstream-pr/22753'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/22753'
git switch 'upstream-pr/22753'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/22753'
git switch 'upstream-pr/22753'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/22753'
git switch 'main'
git merge --squash 'upstream-pr/22753'
git switch 'main'
git merge --ff-only 'upstream-pr/22753'
git switch 'main'
git merge 'upstream-pr/22753'
git push origin 'main'
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!22753
No description provided.