feat(agc): lay out PS4 multisampled depth textures #22629

Merged
adam25136 merged 1 commit from upstream-pr/22629 into main 2026-11-19 16:47:14 +00:00
adam25136 commented 2026-11-17 23:34:15 +00:00 (Migrated from github.com)

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


What

On main, describing a PS4 (GCN) 2D multisampled texture throws in describeGcnSurface (PS4 multisampled textures are not implemented), so a PS4 multisampled texture has no guest size or layout. inFAMOUS Second Son stops there once #21961 lets its compute shader load the title's 2-sample depth buffer (see Tested). This gives a 2D multisampled T# in a depth tile mode its PS4 layout.

  • The layout: GcnTiling and ComputeGcnMipLayout take a sample count (default 1, so every existing caller is unchanged). Depth surfaces use addrlib's depth sample order: the samples of an element are stored next to each other, so an 8x8 micro tile holds 64 elements times the sample count. The tile split then cuts that larger micro tile into slices a whole surface apart, and the smaller of the tile split and the micro tile picks the macro tile mode, as ComputeSurfaceAddrFromCoordMacroTiled (r800/egbaddrlib.cpp) and HwlComputeMacroModeIndex (r800/ciaddrlib.cpp) in Mesa's addrlib compute them. In the address equation the sample index takes the bits between the byte bits and the pixel bits (a new GcnSampleShift names its coordinate bits); everything after that is the existing split, pipe and bank code.
  • The size: describeGcnSurface gives such a T# (2, 4 or 8 samples, one level, one slice) one level of pitch x padded height x element bytes x samples, with a row pitch that holds every sample of a row, as the PS5 multisampled description has. inFAMOUS's 2-sample 32-bit depth T# (pitch 1792, height 1800, tiling index 1: the 128-byte split, four split slices, and in this base layout macro tiles of 128x128) comes to 1792 x 1920 x 4 x 2 = 0x1a40000 bytes, the distance between its DB_Z_READ_BASE (0x3054a0000) and DB_STENCIL_READ_BASE (0x306ee0000); the 64-byte-split mode (256x128) pads to the same size. The test checks both. The title's depth target uses PS4 Pro alternate tiling, which neither main nor this PR models: its DB_DEPTH_INFO (0x00131241) gives pipe config 18 (P16, 16 pipes), 8 banks, bank width 1, bank height 4 and aspect 2, so its macro tiles are 256x128 and its addresses are not this layout's; 1792 is a multiple of 128 and 256 and 1920 of 128, so the size is the same. #23672 has more on alternate tiling. An earlier version of this description gave the base layout's 128x128 as the title's.
  • Still throwing: multisampled textures outside the 2D and PRT depth tile modes (color modes, whose FMASK is not modeled, and the 1D depth mode, index 5, which the driver reads as thin 1D), block-compressed ones, ones of other than 2, 4 or 8 samples, with mips or array layers, or split into more than 16 slices (the equation keeps four split-slice bits, as the GPU detiler takes them); and, as before, a PS4 multisampled texture no draw rendered (createFilled has no PS4 tile modes). Only the size and the address equation are new: sampling still goes through the resident depth target. The sample bits sit at bits 28 to 30, in the equation's slice field (bits 24 and up); the GPU detiler, which puts the layer there, never gets a multisampled equation (it calls GcnTiling without samples).
  • What it does not do yet: inFAMOUS now stops at the next layer, the native multisampled depth import (native multisample depth arrays or non-Z_X layout are not implemented), which assumes PS5 layouts. Importing and publishing the samples in the PS4 layout builds on this equation and is follow-up work; sending the layout first lets it be checked against addrlib on its own and keeps that change smaller.
  • Technical debt: a fragment adds an Unknown function info entry, PS4 (GCN) multisampled depth textures, next to the other PS4 tiling entries.

Tested

Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 (r7), CMake 4.3.1, Release, this branch on main bef2f1f77d for everything below; then rebased onto 92b7c3747d, whose new commits touch none of the files this changes, where agc_driver_graphics passes again. main's own agc_driver_upload_cache_read_only_flush_tests does not build with MinGW (setenv; open #19899 fixes it), so the builds went on past it.

  • RunTextureTilingTests (ctest agc_driver_graphics), with a new gcnMultisampleTilingTests:
    • every 2D and PRT depth tile mode (2D 64 B to 1 KiB tile split and the two PRT depth modes) at 1, 2, 4 and 8 bytes per element and 2, 4 and 8 samples: on a surface of 4 x 4 macro tiles, each sample of each element is placed by the equation where a separate implementation of addrlib's formulas (the test's referenceGcnAddress, extended with the sample) places it, and no two samples share an address. That is 80 layouts; the 4 that would split into more than 16 slices throw instead;
    • a 2-sample 32-bit depth T# of pitch 1792 and height 1800 is 1792 x 1920 x 4 x 2 bytes, in eight split slices with the 64-byte split and in four, in 128x128 macro tiles, with the 128-byte split; its row pitch holds both samples; an 8-bit one is 1792 x 1920 x 2 bytes;
    • a multisampled T# in a color tile mode, one with two mips, and GcnTiling with samples in a color mode still throw.
      It passes, and each of 8 deliberate breaks fails it: samples after the pixel bits (color order), no sample bits, a micro tile without the samples, the size, split stride or row pitch without the samples, the color-mode refusal removed (the layout's own check then throws another message, which the test rejects), and the 2D multisampled refusal kept. It also passes in a build configured with -DANYPS5_ENABLE_SPIRV_TOOLS=ON.
  • The 3,222 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. agc_driver_bda_device, agc_driver_msaa_dcc_unwatch (DCC unwatch did not preserve unchanged data or refused a real write incorrectly), agc_driver_stencil_plane_memory, agc_driver_store_over_untracked and performance_runner_PerformanceRunTests (a clean performance capture refuses ANYPS5_NO_SHADER_CACHE) fail on both, agc_driver_upload_cache_read_only_flush is not run on both (it does not build, as above), and the same 25 tests are skipped on both. Three VideoOut tests, guest_video_out_flip_rate, guest_video_out_window_margins_bounds and video_out_hdr_present, went over their own time limits (20 s, 20 s and 30 s) on this branch only, while another build was running on the machine; rerun by themselves three times on this branch, all three passed every time in about 1 s.
  • With VK_LAYER_KHRONOS_validation 1.4.367 (VK_ADD_LAYER_PATH=<the layer's folder> VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer VK_LOADER_LAYERS_DISABLE=~implicit~ ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), the 56 tests matching agc_driver_graphics$|gcn|tiling|detile|multisample|msaa, ctest -V, on main and on this branch: each log has 55 Insert instance layer "VK_LAYER_KHRONOS_validation" lines from 49 tests, no "was not found" line and no VUID- message; on both, 52 pass, 3 are skipped and agc_driver_msaa_dcc_unwatch fails as above.
  • inFAMOUS Second Son (CUSA00223 01.07, my own dump), unwrapped by main's tools/unwrap_self.py and converted with --windows --registry --trace-imports. Both starts ran on main bef2f1f77d (which has the output-mode fix, #22517) with #21961, #18235, #17711 and #18184 merged locally (#17711's one conflicting file, libSceGnmDriverForNeoMode/Export.cpp, kept main's version) and a local answer for libSceDiscMap's fJgP+wqifno (asked about on closed #10531): the open PRs it needs to reach this shader. One traced start each:
    • without this change: stops 27.3 s in, in compute shader 0x2f2fa2500, with PS4 multisampled textures are not implemented;
    • with it: gets past that, and stops 27.2 s in, in the same shader, with native multisample depth arrays or non-Z_X layout are not implemented.
  • python tools/check_conventions.py --base origin/main with this title and description: all checks passed.
  • python tools/pr_overlap.py --branch: open #20786 (Gag21, PS4 2D thick tile mode 20) changes the same lines of GcnTiling (how the bit order and the micro tile size are formed) and conflicts with this branch in TextureTiling.hpp, TextureTiling.cpp and the tests. The two compose (sample bits for depth modes, the thick order for mode 20); I will rebase on it if it lands first. Open draft #6280 also touches TextureTiling.hpp and TextureTiling.cpp; it conflicts with main, so pr_overlap could not compare it.

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

AI-assisted: Claude Code wrote the change and its tests from addrlib's formulas, ran the tests and the inFAMOUS starts, and drafted this description; separate review agents checked it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5366940325 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22629). Originally posted by [adam25136](https://github.com/adam25136) on 2026-11-17T23:34:15Z. --- ### What On `main`, describing a PS4 (GCN) 2D multisampled texture throws in `describeGcnSurface` (`PS4 multisampled textures are not implemented`), so a PS4 multisampled texture has no guest size or layout. inFAMOUS Second Son stops there once #21961 lets its compute shader load the title's 2-sample depth buffer (see Tested). This gives a 2D multisampled T# in a depth tile mode its PS4 layout. - **The layout:** `GcnTiling` and `ComputeGcnMipLayout` take a sample count (default 1, so every existing caller is unchanged). Depth surfaces use addrlib's depth sample order: the samples of an element are stored next to each other, so an 8x8 micro tile holds 64 elements times the sample count. The tile split then cuts that larger micro tile into slices a whole surface apart, and the smaller of the tile split and the micro tile picks the macro tile mode, as `ComputeSurfaceAddrFromCoordMacroTiled` (`r800/egbaddrlib.cpp`) and `HwlComputeMacroModeIndex` (`r800/ciaddrlib.cpp`) in Mesa's addrlib compute them. In the address equation the sample index takes the bits between the byte bits and the pixel bits (a new `GcnSampleShift` names its coordinate bits); everything after that is the existing split, pipe and bank code. - **The size:** `describeGcnSurface` gives such a T# (2, 4 or 8 samples, one level, one slice) one level of pitch x padded height x element bytes x samples, with a row pitch that holds every sample of a row, as the PS5 multisampled description has. inFAMOUS's 2-sample 32-bit depth T# (pitch 1792, height 1800, tiling index 1: the 128-byte split, four split slices, and in this base layout macro tiles of 128x128) comes to 1792 x 1920 x 4 x 2 = 0x1a40000 bytes, the distance between its `DB_Z_READ_BASE` (0x3054a0000) and `DB_STENCIL_READ_BASE` (0x306ee0000); the 64-byte-split mode (256x128) pads to the same size. The test checks both. The title's depth target uses PS4 Pro alternate tiling, which neither `main` nor this PR models: its DB_DEPTH_INFO (0x00131241) gives pipe config 18 (P16, 16 pipes), 8 banks, bank width 1, bank height 4 and aspect 2, so its macro tiles are 256x128 and its addresses are not this layout's; 1792 is a multiple of 128 and 256 and 1920 of 128, so the size is the same. #23672 has more on alternate tiling. An earlier version of this description gave the base layout's 128x128 as the title's. - **Still throwing:** multisampled textures outside the 2D and PRT depth tile modes (color modes, whose FMASK is not modeled, and the 1D depth mode, index 5, which the driver reads as thin 1D), block-compressed ones, ones of other than 2, 4 or 8 samples, with mips or array layers, or split into more than 16 slices (the equation keeps four split-slice bits, as the GPU detiler takes them); and, as before, a PS4 multisampled texture no draw rendered (`createFilled` has no PS4 tile modes). Only the size and the address equation are new: sampling still goes through the resident depth target. The sample bits sit at bits 28 to 30, in the equation's slice field (bits 24 and up); the GPU detiler, which puts the layer there, never gets a multisampled equation (it calls `GcnTiling` without samples). - **What it does not do yet:** inFAMOUS now stops at the next layer, the native multisampled depth import (`native multisample depth arrays or non-Z_X layout are not implemented`), which assumes PS5 layouts. Importing and publishing the samples in the PS4 layout builds on this equation and is follow-up work; sending the layout first lets it be checked against addrlib on its own and keeps that change smaller. - **Technical debt:** a fragment adds an Unknown function info entry, `PS4 (GCN) multisampled depth textures`, next to the other PS4 tiling entries. ### 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.1, Release, this branch on `main` `bef2f1f77d` for everything below; then rebased onto `92b7c3747d`, whose new commits touch none of the files this changes, where `agc_driver_graphics` passes again. `main`'s own `agc_driver_upload_cache_read_only_flush_tests` does not build with MinGW (`setenv`; open #19899 fixes it), so the builds went on past it. - **`RunTextureTilingTests` (ctest `agc_driver_graphics`)**, with a new `gcnMultisampleTilingTests`: - every 2D and PRT depth tile mode (2D 64 B to 1 KiB tile split and the two PRT depth modes) at 1, 2, 4 and 8 bytes per element and 2, 4 and 8 samples: on a surface of 4 x 4 macro tiles, each sample of each element is placed by the equation where a separate implementation of addrlib's formulas (the test's `referenceGcnAddress`, extended with the sample) places it, and no two samples share an address. That is 80 layouts; the 4 that would split into more than 16 slices throw instead; - a 2-sample 32-bit depth T# of pitch 1792 and height 1800 is 1792 x 1920 x 4 x 2 bytes, in eight split slices with the 64-byte split and in four, in 128x128 macro tiles, with the 128-byte split; its row pitch holds both samples; an 8-bit one is 1792 x 1920 x 2 bytes; - a multisampled T# in a color tile mode, one with two mips, and `GcnTiling` with samples in a color mode still throw. It passes, and each of 8 deliberate breaks fails it: samples after the pixel bits (color order), no sample bits, a micro tile without the samples, the size, split stride or row pitch without the samples, the color-mode refusal removed (the layout's own check then throws another message, which the test rejects), and the 2D multisampled refusal kept. It also passes in a build configured with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`. - **The 3,222 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. `agc_driver_bda_device`, `agc_driver_msaa_dcc_unwatch` (`DCC unwatch did not preserve unchanged data or refused a real write incorrectly`), `agc_driver_stencil_plane_memory`, `agc_driver_store_over_untracked` and `performance_runner_PerformanceRunTests` (a clean performance capture refuses `ANYPS5_NO_SHADER_CACHE`) fail on both, `agc_driver_upload_cache_read_only_flush` is not run on both (it does not build, as above), and the same 25 tests are skipped on both. Three VideoOut tests, `guest_video_out_flip_rate`, `guest_video_out_window_margins_bounds` and `video_out_hdr_present`, went over their own time limits (20 s, 20 s and 30 s) on this branch only, while another build was running on the machine; rerun by themselves three times on this branch, all three passed every time in about 1 s. - **With `VK_LAYER_KHRONOS_validation`** 1.4.367 (`VK_ADD_LAYER_PATH=<the layer's folder> VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer VK_LOADER_LAYERS_DISABLE=~implicit~ ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`), the 56 tests matching `agc_driver_graphics$|gcn|tiling|detile|multisample|msaa`, `ctest -V`, on `main` and on this branch: each log has 55 `Insert instance layer "VK_LAYER_KHRONOS_validation"` lines from 49 tests, no "was not found" line and no `VUID-` message; on both, 52 pass, 3 are skipped and `agc_driver_msaa_dcc_unwatch` fails as above. - **inFAMOUS Second Son** (CUSA00223 01.07, my own dump), unwrapped by `main`'s `tools/unwrap_self.py` and converted with `--windows --registry --trace-imports`. Both starts ran on `main` `bef2f1f77d` (which has the output-mode fix, #22517) with #21961, #18235, #17711 and #18184 merged locally (#17711's one conflicting file, `libSceGnmDriverForNeoMode/Export.cpp`, kept `main`'s version) and a local answer for libSceDiscMap's `fJgP+wqifno` (asked about on closed #10531): the open PRs it needs to reach this shader. One traced start each: - without this change: stops 27.3 s in, in compute shader `0x2f2fa2500`, with `PS4 multisampled textures are not implemented`; - with it: gets past that, and stops 27.2 s in, in the same shader, with `native multisample depth arrays or non-Z_X layout are not implemented`. - **`python tools/check_conventions.py --base origin/main`** with this title and description: all checks passed. - **`python tools/pr_overlap.py --branch`:** open #20786 (Gag21, PS4 2D thick tile mode 20) changes the same lines of `GcnTiling` (how the bit order and the micro tile size are formed) and conflicts with this branch in `TextureTiling.hpp`, `TextureTiling.cpp` and the tests. The two compose (sample bits for depth modes, the thick order for mode 20); I will rebase on it if it lands first. Open draft #6280 also touches `TextureTiling.hpp` and `TextureTiling.cpp`; it conflicts with `main`, so `pr_overlap` could not compare it. ### 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: CUSA00223 #8214 <!-- 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 wrote the change and its tests from addrlib's formulas, ran the tests and the inFAMOUS starts, and drafted this description; separate review agents checked it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!22629
No description provided.