fix(agc): accept the sampler ANISO_OVERRIDE bit #1415

Merged
TheAggie merged 3 commits from upstream-pr/1415 into main 2026-10-10 09:19:54 +00:00
TheAggie commented 2026-10-08 03:12:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T03:12:46Z.


What

A guest sampler with ANISO_OVERRIDE (S# word 2, bit 29) was rejected (guest sampler descriptor uses an anisotropy override which is not implemented). Mesa sets this bit on every GFX10+ sampler unless its aniso_single_level option is on: ac_descriptors.c uses S_008F38_ANISO_OVERRIDE_GFX10(!state->aniso_single_level). With the bit, the texture unit turns anisotropic filtering off when the sampled view has a single mip level (BASE_LEVEL == LAST_LEVEL). The RADV comment in radv_nir_lower_descriptors.c describes it as the TA-side replacement for the shader workaround GFX6–7 needed.

  • DecodeSamplerResource accepts the bit.
  • ShaderResources records, for each sampler of a draw, whether the images paired with it (DescriptorBinding::imageSamplers) are single-level or mipmapped (Texture::SampledViewRange().levels).
  • A sampler with the bit and an anisotropic filter whose paired images are all single-level is bound as the same S# with point or linear filtering in place of the anisotropic filters, taken from the sampler cache (SingleLevelSamplerWords).
  • Samplers of mipmapped images keep their anisotropy, as on the hardware.
  • One sampler descriptor serves every image paired with it, so a sampler paired with both kinds in one draw still throws (... paired with both single-level and mipmapped images in one draw, which is not implemented).
  • GuestSamplerResource test: SingleLevelSamplerWords keeps samplers of mipmapped images, samplers without the bit and samplers without anisotropy unchanged. For a single-level image it gives a non-anisotropic sampler with the same filters and other words, and it throws for the mixed case.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.

  • All 222 agc_* tests pass. They were run from the generated CTestTestfile.cmake commands, because antivirus blocks ctest.exe on this machine.
  • PS5 OpenGL Showcase (PPSA99005, blackbearreloaded/ps5-opengl, Mesa 26.2) sets the bit on the anisotropic samplers of its instanced scene. With this change and other pending fixes on a local branch, the scene renders with no draw skipped and the mixed case never taken.

Not tested on AMD, Intel or Linux.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4781255062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T03:12:46Z. --- ### What A guest sampler with `ANISO_OVERRIDE` (S# word 2, bit 29) was rejected (`guest sampler descriptor uses an anisotropy override which is not implemented`). Mesa sets this bit on every GFX10+ sampler unless its `aniso_single_level` option is on: `ac_descriptors.c` uses `S_008F38_ANISO_OVERRIDE_GFX10(!state->aniso_single_level)`. With the bit, the texture unit turns anisotropic filtering off when the sampled view has a single mip level (BASE_LEVEL == LAST_LEVEL). The RADV comment in `radv_nir_lower_descriptors.c` describes it as the TA-side replacement for the shader workaround GFX6–7 needed. - `DecodeSamplerResource` accepts the bit. - `ShaderResources` records, for each sampler of a draw, whether the images paired with it (`DescriptorBinding::imageSamplers`) are single-level or mipmapped (`Texture::SampledViewRange().levels`). - A sampler with the bit and an anisotropic filter whose paired images are all single-level is bound as the same S# with point or linear filtering in place of the anisotropic filters, taken from the sampler cache (`SingleLevelSamplerWords`). - Samplers of mipmapped images keep their anisotropy, as on the hardware. - One sampler descriptor serves every image paired with it, so a sampler paired with both kinds in one draw still throws (`... paired with both single-level and mipmapped images in one draw, which is not implemented`). - `GuestSamplerResource` test: `SingleLevelSamplerWords` keeps samplers of mipmapped images, samplers without the bit and samplers without anisotropy unchanged. For a single-level image it gives a non-anisotropic sampler with the same filters and other words, and it throws for the mixed case. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti. - All 222 `agc_*` tests pass. They were run from the generated `CTestTestfile.cmake` commands, because antivirus blocks `ctest.exe` on this machine. - PS5 OpenGL Showcase (PPSA99005, [blackbearreloaded/ps5-opengl](https://github.com/blackbearreloaded/ps5-opengl), Mesa 26.2) sets the bit on the anisotropic samplers of its instanced scene. With this change and other pending fixes on a local branch, the scene renders with no draw skipped and the mixed case never taken. Not tested on AMD, Intel or Linux. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
TheAggie commented 2026-10-08 03:25:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T03:25:13Z.


Showcase before/after on the combined local branch: without this change the instanced scene's draws are skipped; with it (together with #1414) the scene renders.
1414-1415-after-showcase-scene
1414-1415-before-showcase-no-scene

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6051533758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6051533758). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T03:25:13Z. --- Showcase before/after on the combined local branch: without this change the instanced scene's draws are skipped; with it (together with #1414) the scene renders. <img width="960" height="540" alt="1414-1415-after-showcase-scene" src="https://github.com/user-attachments/assets/c7bbef33-819e-41e3-a27e-b19d16b90855" /> <img width="960" height="540" alt="1414-1415-before-showcase-no-scene" src="https://github.com/user-attachments/assets/19798127-7362-404d-9c33-3d01b067a589" />
oneandonlydean commented 2026-10-08 05:12:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T05:12:58Z.


Ignoring the bit makes single-level views filter anisotropically where the hardware turns anisotropy off, so this isn't exact yet (GuestSamplerResource.cpp:115). Each sampled image's sampler is already known when the binding is resolved (binding.imageSamplers[element], ShaderResources.cpp:2550-2571). Please either bind a sampler without anisotropy there for single-level views when the bit is set, or accept the bit only when the sampler has no anisotropy and keep the throw otherwise.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6052802470 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6052802470). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-08T05:12:58Z. --- Ignoring the bit makes single-level views filter anisotropically where the hardware turns anisotropy off, so this isn't exact yet (`GuestSamplerResource.cpp:115`). Each sampled image's sampler is already known when the binding is resolved (`binding.imageSamplers[element]`, `ShaderResources.cpp:2550-2571`). Please either bind a sampler without anisotropy there for single-level views when the bit is set, or accept the bit only when the sampler has no anisotropy and keep the throw otherwise.
TheAggie commented 2026-10-08 14:29:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-08T14:29:52Z.


Thanks, done: the first option, decided per draw. Rebased on current main (which also drops the TechnicalDebt entry).

The bound sampler is shared by every image the shader pairs with it, so the choice is made per sampler in ShaderResources once the draw's images are resolved:

  • If all of a sampler's paired images are single-level, the sampler gets its point or linear variant, so anisotropy is off.
  • If they're all mipmapped, it's unchanged.
  • If one draw pairs it with both kinds, it throws, since one descriptor can't be both.

The variant comes from the sampler cache keyed by the rewritten S#, so it's created once.

The Showcase's instanced scene (anisotropic samplers with the bit) renders with no skipped draw and never takes the mixed case.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6062118688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6062118688). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-08T14:29:52Z. --- Thanks, done: the first option, decided per draw. Rebased on current `main` (which also drops the TechnicalDebt entry). The bound sampler is shared by every image the shader pairs with it, so the choice is made per sampler in `ShaderResources` once the draw's images are resolved: - If all of a sampler's paired images are single-level, the sampler gets its point or linear variant, so anisotropy is off. - If they're all mipmapped, it's unchanged. - If one draw pairs it with both kinds, it throws, since one descriptor can't be both. The variant comes from the sampler cache keyed by the rewritten S#, so it's created once. The Showcase's instanced scene (anisotropic samplers with the bit) renders with no skipped draw and never takes the mixed case.
adriadam10 commented 2026-10-09 23:24:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T23:24:03Z.

Review: CHANGES_REQUESTED


Measured on the HW oracle (image_sample_d with anisotropic gradients, S# in SGPRs): with ANISO_OVERRIDE and BASE_LEVEL == LAST_LEVEL the result is bit-identical to the non-anisotropic filter (aniso-point → point, aniso-linear → linear; Z/mip filter and mixed mag/min don't matter), and mipmapped views are unaffected. So SingleLevelSamplerWords matches the hardware. One gap and two smaller points:

  • ShaderResources.cpp:2905: the hardware decides on the T#'s raw BASE_LEVEL == LAST_LEVEL, but SampledViewRange().levels comes from the view after LAST_LEVEL is clamped to MAX_MIP (GuestTextureResource.cpp:142). Measured: BASE=0, LAST=3, MAX_MIP=0 and BASE=1, LAST=2 or 3, MAX_MIP=1 keep anisotropic filtering with the override set (same values as without it, different from point/bilinear), while this PR sees levels == 1 and turns it off. Deciding from the T# fields (e.g. keep the unclamped last level in GuestTextureResource, or compare word 3's BASE_LEVEL/LAST_LEVEL directly) would make it exact.
  • Tests: GuestSamplerResource only covers SingleLevelSamplerWords. The per-draw part (samplerSources indexing, the reset in buildComplete, applyAnisoOverride swapping the sampler, the mixed-case throw) has no test. A draw-level test next to agc_driver_image_sample_shared_sampler with one override sampler paired with a single-level image, a mipmapped image, and both, plus a T# with LAST_LEVEL > MAX_MIP, would cover it.
  • Nit: applyAnisoOverride calls std::getenv("APS5_NO_SAMPLER_CACHE") for every sampler on every draw; addImageBinding already caches it in a static, so reuse that.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5476291876 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#pullrequestreview-5476291876). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T23:24:03Z. **Review:** CHANGES_REQUESTED --- Measured on the HW oracle (`image_sample_d` with anisotropic gradients, S# in SGPRs): with ANISO_OVERRIDE and BASE_LEVEL == LAST_LEVEL the result is bit-identical to the non-anisotropic filter (aniso-point → point, aniso-linear → linear; Z/mip filter and mixed mag/min don't matter), and mipmapped views are unaffected. So `SingleLevelSamplerWords` matches the hardware. One gap and two smaller points: - `ShaderResources.cpp:2905`: the hardware decides on the T#'s raw BASE_LEVEL == LAST_LEVEL, but `SampledViewRange().levels` comes from the view after `LAST_LEVEL` is clamped to `MAX_MIP` (`GuestTextureResource.cpp:142`). Measured: BASE=0, LAST=3, MAX_MIP=0 and BASE=1, LAST=2 or 3, MAX_MIP=1 keep anisotropic filtering with the override set (same values as without it, different from point/bilinear), while this PR sees `levels == 1` and turns it off. Deciding from the T# fields (e.g. keep the unclamped last level in `GuestTextureResource`, or compare word 3's BASE_LEVEL/LAST_LEVEL directly) would make it exact. - Tests: `GuestSamplerResource` only covers `SingleLevelSamplerWords`. The per-draw part (`samplerSources` indexing, the reset in `buildComplete`, `applyAnisoOverride` swapping the sampler, the mixed-case throw) has no test. A draw-level test next to `agc_driver_image_sample_shared_sampler` with one override sampler paired with a single-level image, a mipmapped image, and both, plus a T# with LAST_LEVEL > MAX_MIP, would cover it. - Nit: `applyAnisoOverride` calls `std::getenv("APS5_NO_SAMPLER_CACHE")` for every sampler on every draw; `addImageBinding` already caches it in a `static`, so reuse that.
oneandonlydean commented 2026-10-10 03:18:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:18:38Z.


This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093230087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6093230087). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:18:38Z. --- This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
TheAggie commented 2026-10-10 06:34:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T06:34:22Z.


@adriadam10 thanks for measuring this on the hardware oracle. All three points are addressed in 824ec269:

  • LAST_LEVEL vs MAX_MIP: the single-level decision now reads BASE_LEVEL and LAST_LEVEL from the T#'s word 3 (DescriptorSingleLevel) instead of the view's level count, which is taken after LAST_LEVEL is clamped to MAX_MIP. Your BASE=0, LAST=3, MAX_MIP=0 case now counts as mipmapped, so anisotropic filtering stays on.

  • Draw-level test: new agc_driver_image_sample_aniso_override, next to agc_driver_image_sample_shared_sampler and using its two-texture program. One ANISO_OVERRIDE sampler is shared by two images in one dispatch:

    • two single-level images run;
    • two mipmapped images run;
    • a mipmapped image with a LAST_LEVEL > MAX_MIP descriptor runs (it counts as mipmapped);
    • an anisotropic sampler without the override runs with a mixed pair;
    • single-level + mipmapped is refused as mixed;
    • single-level + the LAST_LEVEL > MAX_MIP descriptor is refused as mixed.

    Each case that runs also checks its samples. With the old view-based check, the LAST_LEVEL > MAX_MIP + mipmapped case is refused, so the test catches the gap you described. The test checks the pairing rules, not filtered values: the program samples at LOD 0 without gradients, where anisotropic and plain filtering agree.

  • Nit: applyAnisoOverride now uses the same cached APS5_NO_SAMPLER_CACHE flag as addImageBinding.

The branch was rebased onto main 001124896 first, as @oneandonlydean asked. On Windows 11 (MinGW-w64 GCC 15.2, NVIDIA GeForce RTX 5070 Ti), 227 of 228 related tests pass (agc_driver, image_sample, guest_sampler, texture). The one failure, agc_driver_prepared_shaders_debug_failure, also fails on clean main on this machine. tools/check_conventions.py passes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094697852 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6094697852). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-10T06:34:22Z. --- @adriadam10 thanks for measuring this on the hardware oracle. All three points are addressed in 824ec269: - **LAST_LEVEL vs MAX_MIP:** the single-level decision now reads BASE_LEVEL and LAST_LEVEL from the T#'s word 3 (`DescriptorSingleLevel`) instead of the view's level count, which is taken after LAST_LEVEL is clamped to MAX_MIP. Your BASE=0, LAST=3, MAX_MIP=0 case now counts as mipmapped, so anisotropic filtering stays on. - **Draw-level test:** new `agc_driver_image_sample_aniso_override`, next to `agc_driver_image_sample_shared_sampler` and using its two-texture program. One ANISO_OVERRIDE sampler is shared by two images in one dispatch: - two single-level images run; - two mipmapped images run; - a mipmapped image with a LAST_LEVEL > MAX_MIP descriptor runs (it counts as mipmapped); - an anisotropic sampler without the override runs with a mixed pair; - single-level + mipmapped is refused as mixed; - single-level + the LAST_LEVEL > MAX_MIP descriptor is refused as mixed. Each case that runs also checks its samples. With the old view-based check, the LAST_LEVEL > MAX_MIP + mipmapped case is refused, so the test catches the gap you described. The test checks the pairing rules, not filtered values: the program samples at LOD 0 without gradients, where anisotropic and plain filtering agree. - **Nit:** `applyAnisoOverride` now uses the same cached `APS5_NO_SAMPLER_CACHE` flag as `addImageBinding`. The branch was rebased onto `main` 001124896 first, as @oneandonlydean asked. On Windows 11 (MinGW-w64 GCC 15.2, NVIDIA GeForce RTX 5070 Ti), 227 of 228 related tests pass (`agc_driver`, `image_sample`, `guest_sampler`, texture). The one failure, `agc_driver_prepared_shaders_debug_failure`, also fails on clean `main` on this machine. `tools/check_conventions.py` passes. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-10 08:06:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T08:06:17Z.


Conflicts with main again in ShaderResources.cpp after #1607 and #1733; please rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095514487 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#issuecomment-6095514487). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T08:06:17Z. --- Conflicts with main again in `ShaderResources.cpp` after #1607 and #1733; please rebase.
adriadam10 commented 2026-10-10 08:59:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T08:59:37Z.

Review: APPROVED


Rebased onto current main as requested (conflict in ShaderResources.cpp next to RequireBorderSwizzle; both blocks kept, no logic change). Build and the libSceAgcDriver tests pass, including guest_sampler_resource and agc_driver_image_sample_aniso_override; merging on green CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5478394400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1415#pullrequestreview-5478394400). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T08:59:37Z. **Review:** APPROVED --- Rebased onto current `main` as requested (conflict in `ShaderResources.cpp` next to `RequireBorderSwizzle`; both blocks kept, no logic change). Build and the libSceAgcDriver tests pass, including `guest_sampler_resource` and `agc_driver_image_sample_aniso_override`; merging on green CI.
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!1415
No description provided.