Skip to content

fix(shader): deduplicate sampler table elements in ResolveImageTables - #7882

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
klosixgaming-arch:fix/image-table-sampler-deduplication
Oct 23, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
klosixgaming-arch:fix/image-table-sampler-deduplication

Conversation

@klosixgaming-arch

@klosixgaming-arch klosixgaming-arch commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What

During ResolveImageTables, unique image descriptors are already deduplicated into out.elements via elementIndex. However, sampler table entries previously allocated 4 sampler elements for every entry encountered without checking if an identical sampler descriptor had already been allocated in out.samplers. When tables contain duplicate sampler descriptors across slots or tables, this unnecessarily exhausts the Abi::SamplerElementBudget (1024 elements / 256 unique samplers) and poisons valid entries with PoisonReason::Budget.

Index and deduplicate sampler table elements in samplerRecord() using samplerIndex. If an identical sampler descriptor was already recorded in out.samplers, reuse its element index instead of allocating new elements. Add tests in ShaderMemory.cpp verifying deduplication across tables, reuse when the budget is full, and poisoning when unique samplers exceed the budget, along with verifying existing behaviour that TableOutsideCode still poisons with PoisonReason::Budget when the budget is full.

Tested

  • ctest -R ^agc_shader_memory$ (agc_shader_memory_tests target): passed locally on Windows (x86_64 mingw-w64). CI build jobs (Windows, Linux, relinker) were skipped; only the conventions, labels and eligibility jobs ran in CI.
  • Verified that on plain main without the fix, the new test fails with assertion: "sampler table deduplication: duplicate sampler entries across tables were not deduplicated".
  • Coverage added for the budget edge (256 unique samplers filling budget, 1 duplicate reused, 257th unique sampler poisoned with PoisonReason::Budget) and covering existing behaviour that TableOutsideCode poisons with PoisonReason::Budget when the budget is full.
  • No real title was run for this change.

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 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: n/a
  • AI-assisted: yes. Written with AI assistance and reviewed by me.

@github-actions github-actions Bot added perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 19, 2026
@github-actions

Copy link
Copy Markdown

This pull request is labeled perf, so it needs the summary line of a capture on main and one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste both aps5-summary.jsonl lines, attach the two traces and add the output of tools/trace_digest.py.

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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
PR 10000 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp L1679-1680

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 907 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6280 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7410 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7550 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 7689 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8077 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8429 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8564 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8792 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8898 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 8998 core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9020 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9335 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9356 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9387 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9508 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 9748 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
PR 9897 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 10193 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 19, 2026
Deduplicate sampler descriptor records across image tables during table resolution so identical sampler descriptors share element table indices rather than exceeding the hardware sampler element budget.
@klosixgaming-arch
klosixgaming-arch force-pushed the fix/image-table-sampler-deduplication branch from 17dc42c to 021175c Compare October 19, 2026 14:51
@klosixgaming-arch klosixgaming-arch changed the title perf(shader): deduplicate sampler table elements in ResolveImageTables fix(shader): deduplicate sampler table elements in ResolveImageTables Oct 19, 2026
@github-actions github-actions Bot removed perf Performance change perf numbers missing perf pull request without a before and after summary line labels Oct 19, 2026
@DavidAmsellem

Copy link
Copy Markdown
Contributor

First GPU run of this PR that I can see: AMD on Linux (RADV). Merged onto main dbac9fa15 (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

Full suite (ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1638/1640 with this PR, against 1638/1640 on main. The failures are the same two on both, so this PR adds none: agc_driver_image_table_vouched_lookups (#7766, fixed by #7916) and agc_driver_guest_memory_lifetime (#7784).

agc_shader_memory passes. The PR adds no new ctest entry, and no test is skipped or removed compared with main.

GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38

AI-assisted: yes

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@DavidAmsellem

Copy link
Copy Markdown
Contributor

First AMD-on-Linux (RADV) run of this PR. Merged onto main dbac9fa15 (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

Full suite (ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at abd5914ab: 1638/1640 with this PR, against 1638/1640 on main. The two failures are the same on both, so this PR adds none: agc_driver_image_table_vouched_lookups (#7766, fixed by #7916) and agc_driver_guest_memory_lifetime (#7784).

Comparing the JUnit output with main: this PR adds no ctest entry, and none is skipped or removed.

This checks correctness only; I did not measure performance.

GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38

AI-assisted: yes

@adriadam10
adriadam10 merged commit 15e71db into boykopovar:main Oct 23, 2026
13 of 14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the sampler dedup in ResolveImageTables (elements depend only on the four S# dwords, so reuse is exact; poisoning for unnormalized/reduction is unchanged and the budget check now applies only to new unique samplers). The new test pins the deduplicated element count and indices, reuse of an existing sampler with a full budget, Budget poison on the 257th unique sampler and TableOutsideCode with a full budget; it fails on main. Cross-checked with @DavidAmsellem's full-suite run on RADV (same two pre-existing failures as main); merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants