Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:fix/agc-sampler-reduction-mode-3-blends
Nov 26, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
JJenkx:fix/agc-sampler-reduction-mode-3-blends

Conversation

@JJenkx

@JJenkx JJenkx commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(agc): support unnormalized MC coordinate precision #20891, feat(agc): support MC coordinate precision with min and max sampling #20944 and fix(shader): sample sRGB textures as UNORM when every paired sampler disables degamma #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

FILTER_MODE 3 filters exactly like mode 0 on RDNA2, so decode it as a
weighted average, clear it to 0 in materialized direct samplers so the
min/max rules do not apply, and poison table samplers only for modes 1
and 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JJenkx

JJenkx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the title evidence in this PR's description. The PPSA02306 and PPSA02630 descriptors it cites (image words in buffer and sampler slots) appear to come from pixel programs the driver should not run (draws whose color write masks reach no formatted target); I have not traced each descriptor to its draw, but the stops disappear when those programs are skipped. With only #21747's one-line change to PixelProgramSkipped (ColorWriteMask(cx) == 0 instead of CB_TARGET_MASK & CB_SHADER_MASK) on main 8db3d3761785, and none of my descriptor PRs, 120 s with Cross every 15 s from 30 s on an RX 6650 XT: PPSA02306 (2,725 frames), PPSA02630 (1,531) and PPSA05626 (4,099) each ran the full 120 s with exit 0 (one run each). On main these titles stop within 18 to 72 s on such descriptors.

So these titles do not need this PR once #21747 is merged, and the description's "stops on it" no longer motivates it. What remains is the hardware behaviour this PR implements, measured as the description states; it applies only when a program really samples or loads through such a descriptor. I am leaving the PR open on that basis, and the maintainers may reasonably decide it is not worth the code without a title that needs it.

AI-assisted: yes

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Nov 18, 2026
@milescoviello

Copy link
Copy Markdown
Contributor

Pascal result for this one: Windows 11 (VM, NVIDIA GeForce GT 1030, R580 driver, WinLibs GCC 16.2 POSIX UCRT, Ninja, Release, ANYPS5_REQUIRE_VULKAN=1). Head 1ec4059a1c on its merge base 2c10195389.

agc_driver_image_filter_mode_three passes 3 of 3 runs, and -V prints filter mode 3 tests passed with no skip. The merge base doesn't have the test, so there is no base arm.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5371 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6280 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6412 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6488 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7642 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7684 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9633 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9749 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9969 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 10193 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 11551 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 13928 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 13929 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 14853 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 14964 core/libs/prx/libSceAgcDriver/Graphics/src/GuestSamplerResource.cpp
core/libs/prx/libSceAgcDriver/tests/GuestSamplerResource.cpp
PR 15555 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 16260 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 16472 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 16631 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 16812 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 16814 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 18106 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 18107 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 20248 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 20519 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 22424 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 23111 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 23242 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 23545 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 24523 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp

@Doorriiaann

Copy link
Copy Markdown
Contributor

NVIDIA run: the new filter-mode-3 test passes and the sampler tests do not regress.

Setup: RTX 3070 8 GB, NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13 (kernel 6.12.115), GCC 13.3.0 Release, validation layer 1.4.335. Base is the merge-base 2c10195, head is 1ec4059. ANYPS5_GPU=NVIDIA ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest -R '(filter_mode_three|guest_sampler|sampler|degamma|^agc_driver_image_sample.*|image_table_packed_guards)' -V, 3 runs each.

base this PR
agc_driver_image_filter_mode_three (new) 3/3 pass
the 14 agc_driver_image_sample_* tests, agc_driver_image_table_packed_guards, agc_driver_many_direct_samplers, agc_shader_sampler_limits 3/3 pass 3/3 pass

Every run selects the RTX 3070; every Vulkan test's log shows the layer inserted, none reports it missing, and no log has a VUID- line. (The pattern also matches two audio tests, guest_webrtc_resampler and ngs2_sampler; both pass on both sides.)

AI-assisted: yes

@AbuMshMsh24

Copy link
Copy Markdown
Contributor

AMD Windows driver run: the new agc_driver_image_filter_mode_three passes 3 of 3 on this PR merged onto main 42f6354612, 0 VUID-, so the weighted average matches the RDNA2 measurement under LLPC on RDNA4 as well. Without the PR's production files the test stops at guest sampler descriptor uses an unknown reduction filter mode 3, as on main.

Setup: Windows 10 22H2, AMD Radeon RX 9070 XT (RDNA4, 0x1002:0x7550), AMD Software 26.11.2 (32.0.32029.2010), WinLibs GCC 15.2.0 r7, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer 1.4.363.1 inserted. Head 1ec4059a1c merged with --no-ff (clean).

AI-assisted: yes (Claude Code)

@Script-hpp

Copy link
Copy Markdown
Contributor

Tested on Intel Arc B390 (Mesa 26.2.7 ANV, Linux 7.2.10), PR head 1ec4059a1c merged into main 8c254da48b, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (layer 1.4.341, the loader log shows it inserted) and VK_LOADER_DEBUG=layer:

  • ctest -R '^(agc_driver_graphics|agc_driver_image_filter_mode_three)$' -V: 2/2 pass, no VUID- in the log.
  • Control: the test files alone on main fail on this device; agc_driver_graphics with guest sampler descriptor uses an unknown reduction filter mode 3, and agc_driver_image_filter_mode_three fails too. So the test catches the bug on this device too.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit fbe1357 into boykopovar:main Nov 26, 2026
22 checks passed
oneandonlydean pushed a commit that referenced this pull request Nov 27, 2026
#22665 samples S# filter mode 3 as a weighted average and lets image-table samplers with mode 3 into the table, but ReducesBetweenTexels still counted any nonzero filter mode as a min or max reduction. The point-filtered variant of such a sampler, built for a sint, converted or depth-bits image, then threw 'a min or max reduction sampler that filters between texels or mip levels samples an image that needs point filtering'. Only modes 1 and 2 reduce; mode 3 now point-filters like mode 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants