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

Merged
klosixgaming-arch merged 1 commit from upstream-pr/7882 into main 2026-10-23 15:47:26 +00:00
klosixgaming-arch commented 2026-10-19 12:20:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T12:20:23Z.


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.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4920829420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7882). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-19T12:20:23Z. --- ### 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 - [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 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: n/a - [x] AI-assisted: yes. Written with AI assistance and reviewed by me.
github-actions[bot] commented 2026-10-19 12:20:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:20:37Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267065148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7882#issuecomment-6267065148). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T12:20:37Z. --- <!-- pr-labels-perf --> 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`.
DavidAmsellem commented 2026-10-19 17:22:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T17:22:13Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273050802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7882#issuecomment-6273050802). Originally posted by [DavidAmsellem](https://github.com/DavidAmsellem) on 2026-10-19T17:22:13Z. --- 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
DavidAmsellem commented 2026-10-19 18:17:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:17:02Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274108846 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7882#issuecomment-6274108846). Originally posted by [DavidAmsellem](https://github.com/DavidAmsellem) on 2026-10-19T18:17:02Z. --- 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
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!7882
No description provided.