feat(shader): offer a 2D MSAA mode to GCN image loads #21961

Merged
adam25136 merged 1 commit from upstream-pr/21961 into main 2026-11-27 17:21:42 +00:00
adam25136 commented 2026-11-16 23:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adam25136 on 2026-11-16T23:15:06Z.


What

GCN MIMG instructions have no DIM field, so a GCN image instruction is decoded as 2D (2D array with DA), and the T# type picks one of the runtime modes the recompiler offers for it (for example 1D, 3D or cube; see the GCN image dimensions entry in docs/dev/debt/shader.md). In inFAMOUS Second Son, compute shader 0x2f2fa2500 loads fragment 0 of the title's 2-sample depth buffer this way. No 2D MSAA mode was offered, so a GCN shader that loads a multisampled depth or colour target was refused with image descriptor is incompatible with the static runtime image interface ... dim 6.

  • The mode: an image every use of which is a load without a mip or sampler, without DA and outside tables, now also gets a 2D MSAA mode. Its address is x, y and a fragment index, as LLVM's image_load takes for its 2D MSAA dimension (IntrinsicsAMDGPU.td L1119, L1403-L1406, the commit the existing entry cites). image_load_mip has no multisampled form (L1407-L1410), so a mip load is not offered the mode.
  • The address: SpirvImageEmitter.cpp's GCN address remap counts the extra component of a multisampled mode, so the fragment index becomes the Sample operand of the image fetch, through the multisampled read path PS5 (RDNA) shaders already use.
  • Which images: only those whose fmaskCompatible and cubeFaceCompatible are both set, which means every use is a 32-bit load without a mip, sample flags or packing (the same pair the RDNA plane mode of a multisampled image requires). All modes of an image are emitted into one shader, so a mode that could not serve every use would fail the whole compile.
  • Still throwing: a sample, mip load, query or store through a 2D MSAA T#, and a load with DA; a load through a 2D MSAA-array T# now reaches the driver, which throws when it binds the texture.
  • What it does not do yet: the driver side. By the code, binding a PS4 2D MSAA texture of 2 or more fragments still throws in describeGcnSurface (PS4 multisampled textures are not implemented); inFAMOUS stops there (see Tested). This is the recompiler half; the driver half needs the GCN multisampled surface layout.
  • Technical debt: a fragment adds a GCN multisampled loads entry, including that the fragment index is used as the host image's sample index while guest FMASK is not modelled.

Tested

Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 (r7), CMake 4.3.2, Release, this branch on main bc84729655. main's own agc_driver_upload_cache_read_only_flush_tests does not build with MinGW (setenv; #19899 fixes it), so the builds went on past it.

  • The new rows in agc_shader_memory_tests (ctest agc_shader_memory_coherent_atomic_loads) pass:
    • offers: a load-only image gets the 2D MSAA mode; an image that is not read, has another use (fmaskCompatible false), is not a plain load (cubeFaceCompatible false), sits in a table, or has DA does not;
    • selection: a load through a 2-fragment 2D MSAA T# selects it, and a sample through that T# is still refused;
    • address: a GCN image_load program through that T# compiles to an OpImageFetch of a multisampled image, with x and y from the first two address registers and the Sample operand from the third;
    • a mip load (image_load_mip) and a sample through that T# are still refused.
  • Deliberate breaks: each of 7 makes that test fail: removing the offer, not counting the fragment component, offering with DA, ignoring both flags, ignoring either flag, offering to table images.
  • SPIR-V validation: the test also passes in a build configured with -DANYPS5_ENABLE_SPIRV_TOOLS=ON, where the recompiler runs SPIRV-Tools' validator on each module it compiles.
  • The 3,112 tests tools/select_tests.py selects for the 4 changed files (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), on main and on this branch: no test fails only on the branch, and both runs skip the same 19. Three fail on both: agc_driver_bda_device, agc_driver_stencil_plane_memory, and agc_driver_upload_cache_read_only_flush (not built). agc_driver_store_over_untracked also failed in main's run. In earlier runs on 3c9ddc9668 and e2e155da47 it failed on both sides from run to run (a pending storage result was stored over bytes the CPU wrote to untracked memory). frame_capture_minimize, which passed on both here, failed in 2 of 4 branch runs on 3c9ddc9668 and 0 of 4 on main there, each time a PermissionError deleting a temporary file.
  • Validation layer: VK_LAYER_KHRONOS_validation 1.4.367 (through VK_ADD_LAYER_PATH) with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer, VK_LOADER_LAYERS_DISABLE=~implicit~, ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, ctest -V, on main and on this branch. The 50 tests run were those matching gcn|multisample|msaa plus agc_shader_memory_coherent_atomic_loads, and all pass. Each log has 49 Insert instance layer "VK_LAYER_KHRONOS_validation" lines, no "was not found" line and no VUID- message. 43 of the 50 create a Vulkan instance. 7 create none, agc_shader_memory_coherent_atomic_loads among them, so the layer sees none of the new rows; SPIRV-Tools validates the module the address row compiles.
  • inFAMOUS Second Son (CUSA00223 01.07), two traced starts on main 3c9ddc9668 merged locally with #18235, #17711 (keeping main's text where it conflicts in libSceGnmDriverForNeoMode/Export.cpp), #18184 and two local changes the title needs to get this far, not open as PRs yet: the DiscMap export the closed #10531 implemented, and the all-"any" case of sceVideoOutConfigureOutputMode_ asked about on #15134. One start ran with this branch and one without it (as e228d90fca, the same diff before its rebase). Without it, the start ends with the dim 6 refusal of compute shader 0x2f2fa2500 quoted above. With it, that refusal is gone, and the start ends at the same dispatch with AGC graphics: PS4 multisampled textures are not implemented.
  • python tools/check_conventions.py --base origin/main --title "<this title>" --body <this description>: All conventions checks passed.
  • python tools/pr_overlap.py --branch: 89 of the 1,589 open PRs share files or exports with this branch. It compared 50 with no overlap and could not compare 39 that conflict with main (exit 2). Checked by text, no hunk of those 39 contains, changes or adds a line of this branch's hunks (lines that repeat in the file or are under 12 characters not counted). The exceptions are #5371 and #16260: each adds a test call near this branch's in ShaderMemory.cpp's main(), and that call merges with ours without a conflict (git merge-file on bc84729655's file).

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: NVIDIA GeForce RTX 5080, driver 621.14, Windows 10 22H2
  • AI-assisted: yes

AI-assisted: Claude Code found the refused shader in an inFAMOUS Second Son run, wrote the change and its tests, ran the tests, and drafted this description; separate review agents checked it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5346962717 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21961). Originally posted by [adam25136](https://github.com/adam25136) on 2026-11-16T23:15:06Z. --- ### What GCN MIMG instructions have no DIM field, so a GCN image instruction is decoded as 2D (2D array with DA), and the T# type picks one of the runtime modes the recompiler offers for it (for example 1D, 3D or cube; see the `GCN image dimensions` entry in `docs/dev/debt/shader.md`). In inFAMOUS Second Son, compute shader `0x2f2fa2500` loads fragment 0 of the title's 2-sample depth buffer this way. No 2D MSAA mode was offered, so a GCN shader that loads a multisampled depth or colour target was refused with `image descriptor is incompatible with the static runtime image interface ... dim 6`. - **The mode:** an image every use of which is a load without a mip or sampler, without DA and outside tables, now also gets a 2D MSAA mode. Its address is x, y and a fragment index, as LLVM's `image_load` takes for its 2D MSAA dimension ([IntrinsicsAMDGPU.td L1119](https://github.com/llvm/llvm-project/blob/48d0dc8f61a7680190a144ef89bd80543c0ec4f9/llvm/include/llvm/IR/IntrinsicsAMDGPU.td#L1119), [L1403-L1406](https://github.com/llvm/llvm-project/blob/48d0dc8f61a7680190a144ef89bd80543c0ec4f9/llvm/include/llvm/IR/IntrinsicsAMDGPU.td#L1403-L1406), the commit the existing entry cites). `image_load_mip` has no multisampled form (L1407-L1410), so a mip load is not offered the mode. - **The address:** `SpirvImageEmitter.cpp`'s GCN address remap counts the extra component of a multisampled mode, so the fragment index becomes the `Sample` operand of the image fetch, through the multisampled read path PS5 (RDNA) shaders already use. - **Which images:** only those whose `fmaskCompatible` and `cubeFaceCompatible` are both set, which means every use is a 32-bit load without a mip, sample flags or packing (the same pair the RDNA plane mode of a multisampled image requires). All modes of an image are emitted into one shader, so a mode that could not serve every use would fail the whole compile. - **Still throwing:** a sample, mip load, query or store through a 2D MSAA T#, and a load with DA; a load through a 2D MSAA-array T# now reaches the driver, which throws when it binds the texture. - **What it does not do yet:** the driver side. By the code, binding a PS4 2D MSAA texture of 2 or more fragments still throws in `describeGcnSurface` (`PS4 multisampled textures are not implemented`); inFAMOUS stops there (see Tested). This is the recompiler half; the driver half needs the GCN multisampled surface layout. - **Technical debt:** a fragment adds a `GCN multisampled loads` entry, including that the fragment index is used as the host image's sample index while guest FMASK is not modelled. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 (r7), CMake 4.3.2, Release, this branch on `main` `bc84729655`. `main`'s own `agc_driver_upload_cache_read_only_flush_tests` does not build with MinGW (`setenv`; #19899 fixes it), so the builds went on past it. - **The new rows in `agc_shader_memory_tests`** (ctest `agc_shader_memory_coherent_atomic_loads`) pass: - offers: a load-only image gets the 2D MSAA mode; an image that is not read, has another use (`fmaskCompatible` false), is not a plain load (`cubeFaceCompatible` false), sits in a table, or has DA does not; - selection: a load through a 2-fragment 2D MSAA T# selects it, and a sample through that T# is still refused; - address: a GCN `image_load` program through that T# compiles to an `OpImageFetch` of a multisampled image, with x and y from the first two address registers and the `Sample` operand from the third; - a mip load (`image_load_mip`) and a sample through that T# are still refused. - **Deliberate breaks:** each of 7 makes that test fail: removing the offer, not counting the fragment component, offering with DA, ignoring both flags, ignoring either flag, offering to table images. - **SPIR-V validation:** the test also passes in a build configured with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, where the recompiler runs SPIRV-Tools' validator on each module it compiles. - **The 3,112 tests `tools/select_tests.py` selects for the 4 changed files** (`ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`), on `main` and on this branch: no test fails only on the branch, and both runs skip the same 19. Three fail on both: `agc_driver_bda_device`, `agc_driver_stencil_plane_memory`, and `agc_driver_upload_cache_read_only_flush` (not built). `agc_driver_store_over_untracked` also failed in `main`'s run. In earlier runs on `3c9ddc9668` and `e2e155da47` it failed on both sides from run to run (`a pending storage result was stored over bytes the CPU wrote to untracked memory`). `frame_capture_minimize`, which passed on both here, failed in 2 of 4 branch runs on `3c9ddc9668` and 0 of 4 on `main` there, each time a `PermissionError` deleting a temporary file. - **Validation layer:** `VK_LAYER_KHRONOS_validation` 1.4.367 (through `VK_ADD_LAYER_PATH`) with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`, `VK_LOADER_LAYERS_DISABLE=~implicit~`, `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, `ctest -V`, on `main` and on this branch. The 50 tests run were those matching `gcn|multisample|msaa` plus `agc_shader_memory_coherent_atomic_loads`, and all pass. Each log has 49 `Insert instance layer "VK_LAYER_KHRONOS_validation"` lines, no "was not found" line and no `VUID-` message. 43 of the 50 create a Vulkan instance. 7 create none, `agc_shader_memory_coherent_atomic_loads` among them, so the layer sees none of the new rows; SPIRV-Tools validates the module the address row compiles. - **inFAMOUS Second Son** (CUSA00223 01.07), two traced starts on `main` `3c9ddc9668` merged locally with #18235, #17711 (keeping `main`'s text where it conflicts in `libSceGnmDriverForNeoMode/Export.cpp`), #18184 and two local changes the title needs to get this far, not open as PRs yet: the DiscMap export the closed #10531 implemented, and the all-"any" case of `sceVideoOutConfigureOutputMode_` asked about on #15134. One start ran with this branch and one without it (as `e228d90fca`, the same diff before its rebase). Without it, the start ends with the `dim 6` refusal of compute shader `0x2f2fa2500` quoted above. With it, that refusal is gone, and the start ends at the same dispatch with `AGC graphics: PS4 multisampled textures are not implemented`. - **`python tools/check_conventions.py --base origin/main --title "<this title>" --body <this description>`:** `All conventions checks passed.` - **`python tools/pr_overlap.py --branch`:** 89 of the 1,589 open PRs share files or exports with this branch. It compared 50 with no overlap and could not compare 39 that conflict with `main` (exit 2). Checked by text, no hunk of those 39 contains, changes or adds a line of this branch's hunks (lines that repeat in the file or are under 12 characters not counted). The exceptions are #5371 and #16260: each adds a test call near this branch's in `ShaderMemory.cpp`'s `main()`, and that call merges with ours without a conflict (`git merge-file` on `bc84729655`'s file). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 5080, driver 621.14, Windows 10 22H2 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> AI-assisted: Claude Code found the refused shader in an inFAMOUS Second Son run, wrote the change and its tests, ran the tests, and drafted this description; separate review agents checked it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 17:03:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T17:03:22Z.

Review: COMMENTED


Reviewed — no blocking findings

The inspected changes add a GCN 2D MSAA image-load mode and remap the fragment address component to the SPIR-V sample operand; I found no verified blocking defect.

What I ran

Reviewed head b1bc3a90f5353870184081307441fe959cde9827 using repo_read.py. No tests or builds were run.

Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, ResourceMaterializer.cpp, SpirvImageEmitter.cpp, the changed ranges and relevant context in ShaderMemory.cpp, and docs/dev/debt/changes/fix-gcn-msaa-image-loads.md. The test file’s full text was excluded as too large for the review folder; only changed ranges and relevant context were read. review/files.json was not available through the reader.

Results

Check Result Note
Diff and changed code review passed Inspected changed behavior and targeted context
Tests and build not run Description reports author-run checks

Findings

Blocking

None verified in the inspected changes.

Non-blocking

None.

Not verified

Tests, builds, and runtime behavior were not independently verified. The full ShaderMemory.cpp file and review/files.json were not read. Hardware behavior and the driver-side multisampled surface implementation are outside the inspected change; the description reports that binding still throws.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5996439955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21961#pullrequestreview-5996439955). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T17:03:22Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The inspected changes add a GCN 2D MSAA image-load mode and remap the fragment address component to the SPIR-V sample operand; I found no verified blocking defect. ## What I ran Reviewed head `b1bc3a90f5353870184081307441fe959cde9827` using `repo_read.py`. No tests or builds were run. Read `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `ResourceMaterializer.cpp`, `SpirvImageEmitter.cpp`, the changed ranges and relevant context in `ShaderMemory.cpp`, and `docs/dev/debt/changes/fix-gcn-msaa-image-loads.md`. The test file’s full text was excluded as too large for the review folder; only changed ranges and relevant context were read. `review/files.json` was not available through the reader. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code review | passed | Inspected changed behavior and targeted context | | Tests and build | not run | Description reports author-run checks | ## Findings ### Blocking None verified in the inspected changes. ### Non-blocking None. ## Not verified Tests, builds, and runtime behavior were not independently verified. The full `ShaderMemory.cpp` file and `review/files.json` were not read. Hardware behavior and the driver-side multisampled surface implementation are outside the inspected change; the description reports that binding still throws. ## To get this to a good state Nothing is required.
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!21961
No description provided.