Skip to content

fix(agc): rotate the bank of PS4 array layers like addrlib - #12998

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:fix-agc-gcn-array-bank-rotation
Oct 30, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
xXPBSXx:fix-agc-gcn-array-bank-rotation

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What

The layers of a PS4 macro-tiled array were placed by a plain offset, with the same bank bits in every layer. For the non-PRT modes the AMD address library also rotates the bank by (banks / 2 - 1) times the layer index, and applies it to the bank as one XOR of the sum with the bank swizzle (egbaddrlib.cpp L3002-L3049). That is the XOR form shadPS4 uses; fpPS4 adds the rotation after the XOR instead.

This adds GcnLayerBankXor, the rotation of one layer as a constant in the bank bits of the address (shift taken from the tile geometry, bit 11 for the 8-pipe modes modelled here), and the detiler passes it with its existing bank/pipe XOR, so the shader is unchanged. The product (banks / 2 - 1) * layer is taken modulo the bank count; it is not a bitwise function of the layer index, so it cannot be folded into the swizzle equation. It applies to the non-PRT modes (Display2D, Thin2D, Depth2D*) from layer 1 and only to mips that are macro-tiled; PRT modes and the micro-tiled small mips are unchanged. The bank swizzle of the surface is taken as 0, as before.

Only surfaces with a gcnPitch (PS4 GCN) are affected; PS5 modes are not. A PS4 color target view of an array slice is rejected on main (DecodeGcnColorBuffer throws for a slice other than 0), so no color-target path addresses PS4 array layers yet; a change that allows such a view with a plain slice offset would need this rotation as well. The rotation rests on the address library and the two emulators; it is not measured on a console, and no title that reaches it has been run.

Commits: the test commit comes first and fails on main for the non-PRT modes from layer 1; the fix commit makes it pass.

Overlap

Open PRs that change TextureTiling.hpp, TextureTiling.cpp, TextureDetiler.cpp, TextureDetile.comp or the two tests tests/TextureTiling.cpp and tests/execution/GcnDetile.cpp (file sets from git diff --name-only against each PR head's merge base, all 1470 open pull requests as of 2026-10-29 19:20, main bb04a4f1ea): 26 touch these files or are ours. git merge-tree of this branch against each of them gives the same result with and without these commits, so none of them gets a new conflict from this PR. #9674 (tile mode 19) edits the same files and merges without a text conflict; a trial merge of both builds, and the tests below pass on it. The 16 pull requests opened since then (#12979 to #12994, checked 2026-10-29 20:25 against main 58b2753d74, which did not change these files) touch none of them. No open PR adds a bank rotation for array layers. Re-checked when opening against the 14 pull requests opened since 19:20 and main 420b6a064e (which has not changed these files): none of them touches them.

Tested

Windows 10 Pro 10.0.19045. agc_driver_gcn_detile_tests (GPU) and agc_driver_graphics_tests (the CPU tiling tests among them), with 1 and 2 mip levels and array layers 0 to 5:

  • Test commit a12f933bb8 alone, on top of main bb04a4f1ea: the GPU test fails on an NVIDIA GeForce RTX 4080 SUPER and on an AMD Radeon RX 6400 at array layer 1 (detiled as 204, expected 0), and the tiling test fails with is at 524288, addrlib places it at 538624.
  • With the fix commit c7a3fff544: all three pass, the GPU test on both GPUs (RTX 4080 SUPER, driver package 32.0.16.1074; RX 6400, 32.0.21033.3005, as reported by Windows).
  • Trial merge of this branch with feat(libSceAgcDriver): lay out PS4 textures in tile mode 19 (Thick_1dThick) #9674 (head 356cb639ef): the same three runs pass.
    tools/check_conventions.py --base upstream/main passes. No title was run.

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: NVIDIA GeForce RTX 4080 SUPER (32.0.16.1074) and AMD Radeon RX 6400 (32.0.21033.3005), Windows 10 Pro 10.0.19045
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

xXPBSXx and others added 2 commits October 29, 2026 19:58
The reference address of a PS4 macro-tiled surface now takes the array layer and rotates the bank by (banks / 2 - 1) times the layer for the non-PRT modes, as the AMD addrlib does. The tiling test compares the layers of an array with it, and the GPU detile test writes layers 1, 2, 3 and 5 with that rotation. Both fail on main for the non-PRT modes from layer 1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The layers of a PS4 macro-tiled array were placed by a plain offset. For the non-PRT modes the hardware model also rotates the bank by (banks / 2 - 1) times the layer index, which is not linear in the layer bits, so the detiler gets it as one XOR constant per layer through the existing bank/pipe XOR of its push constants. PRT modes, micro-tiled mips and bankSwizzle (0) are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

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
PR 6905 core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp
PR 7085 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
PR 8246 core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
PR 8484 core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp
PR 9891 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp
PR 9893 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp
core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp

@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head c7a3fff merged onto main bb04a4f · tested 2026-10-29 21:08 UTC · 29 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,232 passed · 6 failed (0 new, 5 also fail on main, 1 unstable on main) · 40 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,278 of 2,918 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (856 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_bda_device 57.7 s, ⚠️ agc_driver_graphics_maps_fallback 33.0 s
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)
agc_driver_submit_progress: failed in 4 of the last 6 main runs
Failing on main too (5, not counted against this PR)
agc_compute_pipeline_inspection
agc_submit_progress
agc_submit_progress_no_timeline
guest_mmap_executable
guest_socket_options_multicast
Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)
agc_driver_job_manager_compute_capacity: Failed in the parallel run; also passed only on retry in 50 other runs in the last 7 days
Validation IDs already present on main (4 IDs in 397 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (397 tests): agc_compute_pipeline_replay, agc_driver, agc_driver_address_passes_draw_transitions, agc_driver_address_passes_targets_split, agc_driver_alias_copy_label, agc_driver_array_layer_target, agc_driver_array_layer_target_cpu, agc_driver_bda_anchor_reads, and 389 more
VUID-vkCmdCopyImage-srcImage-01548 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-vkCmdCopyImage-srcImage-01551 (11 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_cpu_write_after_memo, agc_driver_depth_plane_cpu_write_after_page_unwatch, agc_driver_depth_plane_cpu_write_after_partial_unwatch, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_partial_store_unimported, agc_driver_depth_storage_dispatch, and 3 more
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (2 tests): agc_driver_prepared_exports, agc_driver_srgb8_color_target
Skipped (40)
agc_driver_bda_reads_shadowed_results: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_bda_reads_shadowed_results_per_build: skipped, the device reports watched host memory written when it imports or reads it
agc_driver_msaa_dcc_compared_import_2: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_4: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_msaa_dcc_compared_import_8: skipped, the device reports host imports that keep write protection, so the write-watch probe compares none of them
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_sparse_dma_buf_import: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_driver_stencil_ref_export: skipped, the device lacks VK_EXT_shader_stencil_export
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
agc_import_settle_initial_dcc: skipped, the device has no deferred settle of host imports: imports under 1 MiB wait for one only on Windows
agc_unit_shadow_completion_store: skipped, the device reports watched host memory written when it imports or reads it
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_eop_main: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_fresh: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_labels: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not
Reproduce
git fetch origin c7a3fff5445fae8de8497a87fdabc25c30b0677f bb04a4f1ea0175e9e4f149f0359a764d62ff3296
git checkout bb04a4f1ea0175e9e4f149f0359a764d62ff3296 && git merge --no-ff c7a3fff5445fae8de8497a87fdabc25c30b0677f
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The array-layer bank rotation matches the cited address-library rule and is covered by tiling and GPU detile tests; I found no blocking issue in the exact head reviewed.

What I ran

  • PR head: c7a3fff5445fae8de8497a87fdabc25c30b0677f.
  • Base: upstream/main at d820fef1827f27247cd28da7b4eec7891904bae5; current-main merge preview was clean (3056b89e4d4bd99822a2c30c5dd18cd415163ca6). The changed tiling, detiler, shader, and test paths have not changed on current main since the PR's reported bb04a4f1ea comparison base.
  • Environment: Linux x86_64; no local build or GPU tests run.
git diff --check upstream/main...refs/review/pr-12998-head
git merge-tree --write-tree upstream/main refs/review/pr-12998-head
python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head
git diff --name-only bb04a4f1ea...upstream/main -- core/libs/prx/libSceAgcDriver/Graphics/include/TextureTiling.hpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureTiling.cpp core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetiler.cpp core/libs/prx/libSceAgcDriver/Graphics/shaders/TextureDetile.comp core/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp core/libs/prx/libSceAgcDriver/tests/execution/GcnDetile.cpp

Results

Check Result
Patch whitespace Pass; command exited 0 with no output.
Current-main merge preview Pass; clean tree 3056b89e4d4bd99822a2c30c5dd18cd415163ca6.
Repository conventions Pass.
Source review Pass; the layer contribution is rotated in the bank bits for non-PRT macro-tiled modes, while layer 0, PRT, and micro-tiled mips remain unchanged.
Hosted CI Windows product, eligibility, conventions, intake, labels, and report checks passed; Linux and specialized jobs were skipped.
GPU tests The PR reports Windows tests on RTX 4080 SUPER and RX 6400, including failing controls on the test-only commit and passing results with the fix. An external report also records a GPU run on RTX 2000 Ada with no new failures or validation IDs. These were not run locally.
Unedited local command output

python tools/check_conventions.py --base upstream/main --head refs/review/pr-12998-head

All conventions checks passed.

git merge-tree --write-tree upstream/main refs/review/pr-12998-head

3056b89e4d4bd99822a2c30c5dd18cd415163ca6

git diff --check upstream/main...refs/review/pr-12998-head exited 0 with no output. The current-main changed-path comparison also produced no output.

Sources

Not verified

  • I did not build or run GPU tests locally. Linux product CI was skipped, and no title or physical console was tested.

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@github-actions github-actions Bot added the agc libSceAgc* label Oct 30, 2026
@adriadam10
adriadam10 merged commit eeee85f into boykopovar:main Oct 30, 2026
13 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the rotation against addrlib's non-PRT bank rule ((banks / 2 - 1) * layer, XOR with the split-slice term), the bank shift (bit 11 for 8 pipes), the PRT and micro-tiled exclusions, and that both new tests pin layer ≥ 1 addresses that main gets wrong. Windows CI and the NVIDIA run are green, and MarcZX10 approved; merged.

@bunbeans2-arch

Copy link
Copy Markdown
Contributor

Fail-old/pass-new on RDNA 4, to add to the RX 6400 and RTX 4080 SUPER runs: AMD Radeon RX 9070 XT, AMD's Windows driver 32.0.32015.7029, Windows 11 Pro 22631, MSYS2 UCRT64 GCC 16.1, Release, BUILD_TESTING=ON, with the Khronos validation layer loaded. Every test executable was rebuilt for each tree.

tree agc_driver_gcn_detile (GPU) agc_driver_graphics (CPU tiling) VUID- lines
main 409fe64199 + test commit a12f933bb8 alone fails 3 of 3 fails 3 of 3 0
main 409fe64199 + this PR passes 3 of 3 passes 3 of 3 0

The failures match yours: PS4 tile mode 17 at 1 bytes, array layer 1: element 0,0 byte 0 detiled as 204, expected 0, and array layer 1 is at 524288, addrlib places it at 538624.

AI-assisted: yes (Claude Code)

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

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants