feat(agc): implement min and max sampler reduction modes #815

Merged
Celegans12 merged 2 commits from upstream-pr/815 into main 2026-10-07 07:40:20 +00:00
Celegans12 commented 2026-10-06 06:21:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T06:21:31Z.


What

An S# with FILTER_MODE (word0 bits 29-30) set throws in DecodeSamplerResource.

  • Modes 0-2 are blend, min and max (Mesa SQ_IMG_FILTER_TYPE, PAL TexFilterMode); min and max chain VkSamplerReductionModeCreateInfoEXT (VK_EXT_sampler_filter_minmax, both filterMinmax* properties). Vulkan and D3D11.3 (5.9.4.5.6) reduce the texels of non-zero weight.
  • DescriptorBinding::imageSamplers (disk cache format 5) carries the image-sampler pairs: only a texture sampled through a linear min/max S# needs SAMPLED_IMAGE_FILTER_MINMAX, else it throws.
  • Also throws: mode 3, no device support, anisotropy, a linear mip filter (NVIDIA and lavapipe disagree), depth or emulated color compare, and filtering min/max on a point-sampled (sint, converted, depth-bits) image, checked in PointFilteredSamplerWord so #757's table point copy is covered once both land. TechnicalDebt gets two lines.
  • PPSA26344 v1.008: compute shaders 0x80003af600, 0x8000253100 and 0x8000265d00 sample float textures through the min S# 20000092 00fff000 05500000 00000000 (bilinear, point mip); the last also image_loads two 8_8 SRGB textures.
  • #757-#759 edit the forcePointFiltering block, #639 that block's condition. #757-#759, #799 and #822 add DescriptorBinding fields; they and #639 bump the disk cache format. #293, #426 and #805 edit resolveImageBinding; #285 buildPrepare.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 5895ea72: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 358/358 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 357/357 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • New agc_driver_image_sample_reduction: exact R32F min/max (bilinear or point, point or no mip), unreduced image_gather4_lz, an image_loaded 8_8_8_8 texture beside a min-sampled one; min/max throws on 32_SINT, and on 8_8_8_8 on lavapipe (NVIDIA filters it).
  • Extended agc_driver_graphics (PointFilteredSamplerWord throws for the min S# and a linear-mip max S#), agc_shader_disk_cache and agc_driver_emulated_color_compare; these and the new test fail or do not build on main.
  • Not tested: a PPSA26344 run, Linux (CI), console behaviour.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4754967541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T06:21:31Z. --- ### What An S# with `FILTER_MODE` (word0 bits 29-30) set throws in `DecodeSamplerResource`. - Modes 0-2 are blend, min and max (Mesa `SQ_IMG_FILTER_TYPE`, PAL `TexFilterMode`); min and max chain `VkSamplerReductionModeCreateInfoEXT` (`VK_EXT_sampler_filter_minmax`, both `filterMinmax*` properties). Vulkan and D3D11.3 (5.9.4.5.6) reduce the texels of non-zero weight. - `DescriptorBinding::imageSamplers` (disk cache format 5) carries the image-sampler pairs: only a texture sampled through a linear min/max S# needs `SAMPLED_IMAGE_FILTER_MINMAX`, else it throws. - Also throws: mode 3, no device support, anisotropy, a linear mip filter (NVIDIA and lavapipe disagree), depth or emulated color compare, and filtering min/max on a point-sampled (sint, converted, depth-bits) image, checked in `PointFilteredSamplerWord` so #757's table point copy is covered once both land. TechnicalDebt gets two lines. - PPSA26344 v1.008: compute shaders 0x80003af600, 0x8000253100 and 0x8000265d00 sample float textures through the min S# `20000092 00fff000 05500000 00000000` (bilinear, point mip); the last also `image_load`s two 8_8 SRGB textures. - #757-#759 edit the `forcePointFiltering` block, #639 that block's condition. #757-#759, #799 and #822 add `DescriptorBinding` fields; they and #639 bump the disk cache format. #293, #426 and #805 edit `resolveImageBinding`; #285 `buildPrepare`. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 5895ea72: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 358/358 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 357/357 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - New `agc_driver_image_sample_reduction`: exact R32F min/max (bilinear or point, point or no mip), unreduced `image_gather4_lz`, an `image_load`ed 8_8_8_8 texture beside a min-sampled one; min/max throws on 32_SINT, and on 8_8_8_8 on lavapipe (NVIDIA filters it). - Extended `agc_driver_graphics` (`PointFilteredSamplerWord` throws for the min S# and a linear-mip max S#), `agc_shader_disk_cache` and `agc_driver_emulated_color_compare`; these and the new test fail or do not build on `main`. - Not tested: a PPSA26344 run, Linux (CI), console behaviour. ### 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
oneandonlydean commented 2026-10-06 09:27:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T09:27:45Z.


Thanks, the mapping looks right to me: FILTER_MODE 1/2 go to VK_SAMPLER_REDUCTION_MODE_MIN/MAX, 3 throws, and since the bits are in word 0 the sampler cache key already separates the modes. Compare samplers are refused, which Vulkan requires anyway (VUID-VkSamplerCreateInfo-compareEnable-01423). The format check is only applied with a linear filter, which matches when Vulkan requires SAMPLED_IMAGE_FILTER_MINMAX_BIT.

One thing for whichever of this and #757 lands second. Both change the forcePointFiltering block in DescriptorBindingBuilder::Populate, so they conflict there. #757 also adds a second place that point-filters a sampler: the point copy in the SamplerTable case (copy == 1u && entry.point, through PointFilteredSamplerWord). The min/max check in this PR only covers the direct path. After both are merged, a min/max sampler in a table with bilinear filtering, used on an image that needs point sampling, would quietly become a point sample instead of throwing. Moving the check into a helper that both paths call (or into PointFilteredSamplerWord itself, with access to word 0) would cover both.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6013353079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815#issuecomment-6013353079). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-06T09:27:45Z. --- Thanks, the mapping looks right to me: FILTER_MODE 1/2 go to `VK_SAMPLER_REDUCTION_MODE_MIN`/`MAX`, 3 throws, and since the bits are in word 0 the sampler cache key already separates the modes. Compare samplers are refused, which Vulkan requires anyway (VUID-VkSamplerCreateInfo-compareEnable-01423). The format check is only applied with a linear filter, which matches when Vulkan requires `SAMPLED_IMAGE_FILTER_MINMAX_BIT`. One thing for whichever of this and #757 lands second. Both change the `forcePointFiltering` block in `DescriptorBindingBuilder::Populate`, so they conflict there. #757 also adds a second place that point-filters a sampler: the point copy in the `SamplerTable` case (`copy == 1u && entry.point`, through `PointFilteredSamplerWord`). The min/max check in this PR only covers the direct path. After both are merged, a min/max sampler in a table with bilinear filtering, used on an image that needs point sampling, would quietly become a point sample instead of throwing. Moving the check into a helper that both paths call (or into `PointFilteredSamplerWord` itself, with access to word 0) would cover both.
Celegans12 commented 2026-10-06 10:57:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T10:57:20Z.


Thanks, good catch. The min/max check now lives in PointFilteredSamplerWord(word0, filter), which this PR adds: it reads S# words 0 and 2, throws for a min or max S# that filters between texels or mips, and otherwise returns the point-filtered word 2. The forcePointFiltering block only calls it, so every caller gets the check, not just the direct path.

For #757: whichever of the two lands second, I'll rebase it so that #757's one-word helper goes away and the table point copy (copy == 1u && entry.point) calls PointFilteredSamplerWord(physical.guestDescriptor[first], physical.guestDescriptor[first + 2u]). Then a min/max sampler in a table with bilinear filtering, used on an image that needs point sampling, throws there too. This PR still has no dependency on #757.

New rows in agc_driver_graphics call PointFilteredSamplerWord directly and require the throw for the bilinear min S# 20000092 00fff000 05500000 00000000 and for a max S# with a linear mip filter. With the check removed from the helper, that test fails. Updated: still one commit, rebased onto main 5895ea72.

One more change since your review. The min/max format check was object-wide, and on PPSA26344 it rejected two image_load-only 8_8 SRGB textures in 0x8000265d00 that are never sampled. It now applies only to textures actually sampled through a linear min/max S#. DescriptorBinding::imageSamplers carries each sampled-image element's sampler pairs (disk cache format 5), and RequireFilterMinmax checks only those pairs. agc_driver_image_sample_reduction covers an image_loaded RGBA8 texture next to a min-sampled R32F one. With this, 0x80003af600, 0x8000253100 and 0x8000265d00 dispatch in the title. CI: Windows ctest 358/358; lavapipe 357/357.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6014765004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815#issuecomment-6014765004). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T10:57:20Z. --- Thanks, good catch. The min/max check now lives in `PointFilteredSamplerWord(word0, filter)`, which this PR adds: it reads S# words 0 and 2, throws for a min or max S# that filters between texels or mips, and otherwise returns the point-filtered word 2. The `forcePointFiltering` block only calls it, so every caller gets the check, not just the direct path. For #757: whichever of the two lands second, I'll rebase it so that #757's one-word helper goes away and the table point copy (`copy == 1u && entry.point`) calls `PointFilteredSamplerWord(physical.guestDescriptor[first], physical.guestDescriptor[first + 2u])`. Then a min/max sampler in a table with bilinear filtering, used on an image that needs point sampling, throws there too. This PR still has no dependency on #757. New rows in `agc_driver_graphics` call `PointFilteredSamplerWord` directly and require the throw for the bilinear min S# `20000092 00fff000 05500000 00000000` and for a max S# with a linear mip filter. With the check removed from the helper, that test fails. Updated: still one commit, rebased onto `main` 5895ea72. One more change since your review. The min/max format check was object-wide, and on PPSA26344 it rejected two `image_load`-only 8_8 SRGB textures in 0x8000265d00 that are never sampled. It now applies only to textures actually sampled through a linear min/max S#. `DescriptorBinding::imageSamplers` carries each sampled-image element's sampler pairs (disk cache format 5), and `RequireFilterMinmax` checks only those pairs. `agc_driver_image_sample_reduction` covers an `image_load`ed RGBA8 texture next to a min-sampled R32F one. With this, 0x80003af600, 0x8000253100 and 0x8000265d00 dispatch in the title. CI: Windows ctest 358/358; lavapipe 357/357.
adriadam10 commented 2026-10-07 07:23:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T07:23:19Z.


Measured on RDNA2 (gfx1035) with the HW oracle: bilinear blend/min/max, point min/max and image_gather4_lz through min/max S#s over 24 coordinates (generic, exact texel centres and edges, 1/512 to 1/4096 texel from a centre, clamped). Point stays point and gathers return the four texels unreduced, as the PR does. Min/max reduce only the texels of non-zero weight, Vulkan's rule, after the weight is rounded to the 8-bit subtexel grid (a sample within 1/512 texel of a centre reduces that texel alone, the same rounding blend shows). RADV programs the same SQ_IMG_FILTER_MODE values for Vulkan's reduction modes (radv_sampler.c), so on AMD this is the hardware filter.

What we pushed:

  • Rebased onto main after #799/#805: kept both sides of every conflict, ShaderDiskCache::FormatVersion 6 (both PRs had moved it to 5), DescriptorBinding size assert 408.
  • The TechnicalDebt line now says what was measured instead of "assumed", including that a driver with other subTexelPrecisionBits reduces a different set near texel centres.

Full ctest green on RADV, touched tests on CI's lavapipe (new test 0.4 s cold); the new tests don't build without the change. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033065634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815#issuecomment-6033065634). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T07:23:19Z. --- Measured on RDNA2 (gfx1035) with the HW oracle: bilinear blend/min/max, point min/max and `image_gather4_lz` through min/max S#s over 24 coordinates (generic, exact texel centres and edges, 1/512 to 1/4096 texel from a centre, clamped). Point stays point and gathers return the four texels unreduced, as the PR does. Min/max reduce only the texels of non-zero weight, Vulkan's rule, after the weight is rounded to the 8-bit subtexel grid (a sample within 1/512 texel of a centre reduces that texel alone, the same rounding blend shows). RADV programs the same `SQ_IMG_FILTER_MODE` values for Vulkan's reduction modes (`radv_sampler.c`), so on AMD this is the hardware filter. What we pushed: - Rebased onto main after #799/#805: kept both sides of every conflict, `ShaderDiskCache::FormatVersion` 6 (both PRs had moved it to 5), `DescriptorBinding` size assert 408. - The TechnicalDebt line now says what was measured instead of "assumed", including that a driver with other `subTexelPrecisionBits` reduces a different set near texel centres. Full ctest green on RADV, touched tests on CI's lavapipe (new test 0.4 s cold); the new tests don't build without the change. Merging once CI is green.
Celegans12 commented 2026-10-07 07:27:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-07T07:27:03Z.


Thanks a lot for measuring this on gfx1035 and for doing the rebase. The note about the 8-bit subtexel rounding near texel centres is a good catch, and I hadn't been able to check it without hardware. I'll leave the branch as you pushed it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033117545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815#issuecomment-6033117545). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-07T07:27:03Z. --- Thanks a lot for measuring this on gfx1035 and for doing the rebase. The note about the 8-bit subtexel rounding near texel centres is a good catch, and I hadn't been able to check it without hardware. I'll leave the branch as you pushed it.
github-actions[bot] commented 2026-10-07 07:35:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T07:35:27Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#934 core/libs/prx/libSceAgcDriver/tests/execution/EmulatedColorCompare.cpp L55
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp L538-539
#938 docs/dev/TechnicalDebt.md L224
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033242006 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/815#issuecomment-6033242006). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T07:35:27Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #934 | `core/libs/prx/libSceAgcDriver/tests/execution/EmulatedColorCompare.cpp` [L55](https://github.com/boykopovar/AnyPS5/blob/d4c196c20795e96203ed31278ce4cf86505b1e86/core/libs/prx/libSceAgcDriver/tests/execution/EmulatedColorCompare.cpp#L55)<br>`core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp` [L538-539](https://github.com/boykopovar/AnyPS5/blob/d4c196c20795e96203ed31278ce4cf86505b1e86/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L538-L539) | | | | #938 | `docs/dev/TechnicalDebt.md` [L224](https://github.com/boykopovar/AnyPS5/blob/d4c196c20795e96203ed31278ce4cf86505b1e86/docs/dev/TechnicalDebt.md#L224) | | |
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!815
No description provided.