fix(agc): sample S# filter mode 3 as a weighted average #22665

Merged
JJenkx merged 1 commit from upstream-pr/22665 into main 2026-11-26 08:29:20 +00:00
JJenkx commented 2026-11-18 00:56:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-18T00:56:46Z.


What

A sampler whose S# word 0 FILTER_MODE (bits 29-30) is 3 threw guest sampler descriptor uses an unknown reduction filter mode 3. Spirit of the North: Enhanced Edition (PPSA02306) and PPSA05595 have stopped on it.

On RDNA2 mode 3 filters exactly like mode 0 (weighted average). toVkReductionMode now maps 3 to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT. materializeBlendingReductions clears mode 3 to 0 in the materialized S# of directly bound samplers, so the recompiler's min/max rules (reducesBetweenTexels, the converted-image and comparison refusals, the one-slice volume rule) treat it as the blend it is; samplers in descriptor tables are poisoned as reductions only for modes 1 and 2.

Hardware measurement

tools/hw-oracle on an RX 6650 XT (gfx1032, RDNA2, Linux 7.2.14, hsa-rocr 10.1, clang 23.1.5; wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even, FP16 overflow off). A 64x64 8_8_8_8_UNORM gradient, image_sample_lz DIM 2D at 32 coordinates 0.3 texel off the texel centres, bilinear sampler with word 0 0x92 | FILTER_MODE << 29 and words 1-3 00fff000 06500000 00000000, FILTER_MODE 0 to 3:

FILTER_MODE results equal to mode 0 equal to mode 1 equal to mode 2
1 (min) 4/32 32/32 4/32
2 (max) 4/32 4/32 32/32
3 32/32 4/32 4/32

Mode 3 matched mode 0 bit for bit at every coordinate. This is an RDNA2 measurement, not PS5 evidence.

Tested

Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), GCC 16.2.1, Release, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

  • agc_driver_graphics (tests/GuestSamplerResource.cpp): the case that expected unknown reduction filter mode 3 now requires mode 3 with a point and a linear mip filter to decode to VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT, chain no reduction struct into vkCreateSampler and not require min/max filtering. Modes 0 to 2 are unchanged.
  • New agc_driver_image_filter_mode_three: draws a two-texel 8_8_8_8_UNORM texture through a bilinear sampler with FILTER_MODE 0, 1 and 3. Mode 0 and mode 1 must draw different images (so the draw filters between texels), and mode 3 must draw exactly what mode 0 draws. With the source change reverted it fails with unknown reduction filter mode 3.
  • ctest -R "filter_mode_three|guest_sampler|agc_driver_graphics$|sampler|disabled_degamma|shader_memory|image_": 151 of 152 pass. agc_driver_image_table_packed_guards fails (unrecoverable packed table format was not poisoned) here and identically in four of my other local builds without this change, so it is not caused by it.
  • PPSA05595, on a local merge of this branch with #20891, #20944 and #22644 and a log of every rewritten mode 3 sampler, 150 s, Cross every 15 s from 30 s: one run logged the mode 3 S# 610ba140 00100010 00000004 0004dfac, passed the reduction check and then stopped on unnormalized guest sampler uses MC_COORD_TRUNC with an unimplemented clamp mode for the same sampler. Its word 3 looks like T# destination selects, so it is probably not a sampler the title meant to use. This PR therefore does not unblock PPSA05595; it removes the reduction-mode refusal the earlier runs stopped on.
  • Regression check of this branch alone, 70 s each, Cross every 15 s from 30 s: PPSA01546 (3,128 frames), PPSA01886 (3,939), PPSA02664 (3,860) and PPSA02743 (3,704), all exit 0. Frame counts are not a performance comparison.

Independent NVIDIA Linux validation reported by @Doorriiaann: RTX 3070 test results at 1ec4059a1c; the contributor reports passing focused checks with no Vulkan validation errors.

Additional GPU qualification (independent Intel report): Intel Arc B390, ANV Mesa 26.2.7, Linux 7.2.10; head 1ec4059a1c on main 8c254da48b. The graphics fixture and agc_driver_image_filter_mode_three pass (2/2), with actual validation-layer 1.4.341 insertion and no VUIDs reported. The same new fixtures on main fail and detect the targeted bug. These are peer-reported results, not tests run on this machine.

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: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14; Intel Arc B390, ANV Mesa 26.2.7, Linux 7.2.10 (peer report linked above)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5367822061 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22665). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-18T00:56:46Z. --- ### What A sampler whose S# word 0 `FILTER_MODE` (bits 29-30) is 3 threw `guest sampler descriptor uses an unknown reduction filter mode 3`. Spirit of the North: Enhanced Edition (PPSA02306) and PPSA05595 have stopped on it. On RDNA2 mode 3 filters exactly like mode 0 (weighted average). `toVkReductionMode` now maps 3 to `VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT`. `materializeBlendingReductions` clears mode 3 to 0 in the materialized S# of directly bound samplers, so the recompiler's min/max rules (`reducesBetweenTexels`, the converted-image and comparison refusals, the one-slice volume rule) treat it as the blend it is; samplers in descriptor tables are poisoned as reductions only for modes 1 and 2. ### Hardware measurement `tools/hw-oracle` on an RX 6650 XT (gfx1032, RDNA2, Linux 7.2.14, hsa-rocr 10.1, clang 23.1.5; wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even, FP16 overflow off). A 64x64 8_8_8_8_UNORM gradient, `image_sample_lz` DIM 2D at 32 coordinates 0.3 texel off the texel centres, bilinear sampler with word 0 `0x92 | FILTER_MODE << 29` and words 1-3 `00fff000 06500000 00000000`, `FILTER_MODE` 0 to 3: | `FILTER_MODE` | results equal to mode 0 | equal to mode 1 | equal to mode 2 | |---|---|---|---| | 1 (min) | 4/32 | 32/32 | 4/32 | | 2 (max) | 4/32 | 4/32 | 32/32 | | 3 | 32/32 | 4/32 | 4/32 | Mode 3 matched mode 0 bit for bit at every coordinate. This is an RDNA2 measurement, not PS5 evidence. ### Tested Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), GCC 16.2.1, Release, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - `agc_driver_graphics` (`tests/GuestSamplerResource.cpp`): the case that expected `unknown reduction filter mode 3` now requires mode 3 with a point and a linear mip filter to decode to `VK_SAMPLER_REDUCTION_MODE_WEIGHTED_AVERAGE_EXT`, chain no reduction struct into `vkCreateSampler` and not require min/max filtering. Modes 0 to 2 are unchanged. - New `agc_driver_image_filter_mode_three`: draws a two-texel 8_8_8_8_UNORM texture through a bilinear sampler with `FILTER_MODE` 0, 1 and 3. Mode 0 and mode 1 must draw different images (so the draw filters between texels), and mode 3 must draw exactly what mode 0 draws. With the source change reverted it fails with `unknown reduction filter mode 3`. - `ctest -R "filter_mode_three|guest_sampler|agc_driver_graphics$|sampler|disabled_degamma|shader_memory|image_"`: 151 of 152 pass. `agc_driver_image_table_packed_guards` fails (`unrecoverable packed table format was not poisoned`) here and identically in four of my other local builds without this change, so it is not caused by it. - PPSA05595, on a local merge of this branch with #20891, #20944 and #22644 and a log of every rewritten mode 3 sampler, 150 s, Cross every 15 s from 30 s: one run logged the mode 3 S# `610ba140 00100010 00000004 0004dfac`, passed the reduction check and then stopped on `unnormalized guest sampler uses MC_COORD_TRUNC with an unimplemented clamp mode` for the same sampler. Its word 3 looks like T# destination selects, so it is probably not a sampler the title meant to use. This PR therefore does not unblock PPSA05595; it removes the reduction-mode refusal the earlier runs stopped on. - Regression check of this branch alone, 70 s each, Cross every 15 s from 30 s: PPSA01546 (3,128 frames), PPSA01886 (3,939), PPSA02664 (3,860) and PPSA02743 (3,704), all exit 0. Frame counts are not a performance comparison. Independent NVIDIA Linux validation reported by @Doorriiaann: [RTX 3070 test results](https://github.com/boykopovar/AnyPS5/pull/22665#issuecomment-6975658015) at `1ec4059a1c`; the contributor reports passing focused checks with no Vulkan validation errors. Additional GPU qualification ([independent Intel report](https://github.com/boykopovar/AnyPS5/pull/22665#issuecomment-7086437645)): Intel Arc B390, ANV Mesa 26.2.7, Linux 7.2.10; head `1ec4059a1c` on main `8c254da48b`. The graphics fixture and `agc_driver_image_filter_mode_three` pass (2/2), with actual validation-layer 1.4.341 insertion and no VUIDs reported. The same new fixtures on main fail and detect the targeted bug. These are peer-reported results, not tests run on this machine. ### 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) 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: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14; Intel Arc B390, ANV Mesa 26.2.7, Linux 7.2.10 (peer report linked above) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-18 01:17:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T01:17:33Z.

Review: APPROVED


Reviewed — looks good

The reviewed changes contain no verified blocking defects and support approval at head 1ec4059a1c7e9d02121ed2afc9b901817c9c9fa5.

What I ran

Read the prepared diff and changed-file context through repo_read.py; no commands or tests were run by me. The author reports a 151/152 test result, with one failure said to reproduce on unrelated builds.

Results

Check Result Note
Diff and changed code review passed Relevant changes and call sites inspected
Automated checks not run Author-reported results only
Negative control not run No test mutation performed

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

I read the full changed sampler decoder and new rendering test, the changed hunks and relevant sections of the 631-line sampler test and 3041-line materializer, plus the full debt note. The remainder of those two long files was not read. The author-reported test results and hardware measurements were not independently confirmed; no local build, test run, or PS5 behavior was verified.

To get this to a good state

Nothing is required. The author-reported test results and hardware measurement are optional supporting evidence.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5949381230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22665#pullrequestreview-5949381230). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T01:17:33Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed changes contain no verified blocking defects and support approval at head `1ec4059a1c7e9d02121ed2afc9b901817c9c9fa5`. ## What I ran Read the prepared diff and changed-file context through `repo_read.py`; no commands or tests were run by me. The author reports a 151/152 test result, with one failure said to reproduce on unrelated builds. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Relevant changes and call sites inspected | | Automated checks | not run | Author-reported results only | | Negative control | not run | No test mutation performed | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [Sampler reduction mode decoding](https://github.com/boykopovar/AnyPS5/blob/1ec4059a1c7e9d02121ed2afc9b901817c9c9fa5/core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp#L23-L30) - [Sampler descriptor materialization and table handling](https://github.com/boykopovar/AnyPS5/blob/1ec4059a1c7e9d02121ed2afc9b901817c9c9fa5/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L1659-L1664) - [Filter-mode rendering regression test](https://github.com/boykopovar/AnyPS5/blob/1ec4059a1c7e9d02121ed2afc9b901817c9c9fa5/core/libs/prx/libSceAgcDriver/tests/execution/ImageFilterModeThree.cpp#L137-L153) ## Not verified I read the full changed sampler decoder and new rendering test, the changed hunks and relevant sections of the 631-line sampler test and 3041-line materializer, plus the full debt note. The remainder of those two long files was not read. The author-reported test results and hardware measurements were not independently confirmed; no local build, test run, or PS5 behavior was verified. ## To get this to a good state Nothing is required. The author-reported test results and hardware measurement are optional supporting evidence.
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!22665
No description provided.