Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adam25136:fix/gcn-msaa-depth-layout
Nov 19, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adam25136:fix/gcn-msaa-depth-layout

Conversation

@adam25136

@adam25136 adam25136 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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. feat(agc): lay out PS4 multisampled color textures in 2D tile modes #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, fix(libSceVideoOut): accept an output mode left at any in every field #22517) with feat(shader): offer a 2D MSAA mode to GCN image loads #21961, feat(libSceGnmDriver): export the workload, trace and tessellation si… #18235, feat(libSceGnmDriver): share mode-independent command writers #17711 and fix(libSceSysmodule): accept four PS4-only module ids in a PS4 process #18184 merged locally (feat(libSceGnmDriver): share mode-independent command writers #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 feat(libs): PS4 imports and a buffer option inFAMOUS Second Son needs #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 feat(libSceAgcDriver): support PS4 2D thick tile mode 20 for volumes #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 fix(agc): keep texture images inside their extent's mip chain #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 inFAMOUS Second Son (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

A 2D multisampled PS4 T# in a depth tile mode (2, 4 or 8 samples, one
level, one slice) now has a size and an address equation instead of
throwing in describeGcnSurface. GcnTiling and ComputeGcnMipLayout take a
sample count: the samples of an element sit next to each other in the
micro tile (addrlib's depth sample order), so a micro tile holds 64
elements times the sample count, and the tile split and macro tile mode
follow from that larger micro tile, as in addrlib's
ComputeSurfaceAddrFromCoordMacroTiled and HwlComputeMacroModeIndex.

Color tile modes (FMASK), mips, arrays and more than 16 split slices
still throw. The test compares the equation with a separate addrlib-style
implementation for every depth tile mode, element size and sample count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line docs agc libSceAgc* labels Nov 17, 2026
@github-actions

github-actions Bot commented Nov 18, 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 20786 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp L102-103
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp L538-539
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp L622

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 6280 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp

@Colewiz7

Copy link
Copy Markdown
Contributor

Head 3e90432d21 merged onto main 7c836568c8 as 3b7fd230c2, no conflict. Linux 7.3.4, GCC 16.2.1 Release, Mesa 26.2.6 RADV, RX 7900 XT (gfx1100) and 7800X3D iGPU (gfx1036).

No new failures and no new validation messages on either GPU.

RX 7900 XT iGPU
tests run (6206 on the 7900 XT, the 2007 GPU ones on the iGPU), new failures vs main none none
-R '^agc' (1940 tests) with the layer, new failures vs main none none
VUID- / SYNC-HAZARD lines 0 / 0 0 / 0

Layer runs used VK_LAYER_KHRONOS_validation 1.4.363.1 with VK_LOADER_DEBUG=layer and ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; the loader inserted the layer in every run, and the set of distinct validation messages matches main.

AI-assisted: yes

@oneandonlydean
oneandonlydean merged commit 263f350 into boykopovar:main Nov 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants