Skip to content

feat(agc): draw PS4 color targets with CB_COLOR_INFO LINEAR_GENERAL - #1268

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/25684
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/25684

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#25684, originally opened by puridanish284.

Source commit: 2afe985b20e745e3bde5416d7d6c7e13eb623682. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

A PS4 (GCN) color target with CB_COLOR_INFO.LINEAR_GENERAL (bit 7) set threw endian-swapped or linear-general GCN color targets are not implemented, although the texture path already reads GCN tile index 31 (linear general) as an unpadded linear surface. DecodeGcnColorBuffer now decodes such a target the way shadPS4 reads these registers (GetTileMode, Address, BaseSlice):

  • the tile mode index in CB_COLOR_ATTRIB is ignored and the target is linear, as a new ColorTileMode::GcnLinearGeneral (0x109, clear of feat(agc): draw PS4 color targets in the PRT tile modes boykopovar/AnyPS5#22514's 0x105 to 0x108);
  • rows are CB_COLOR_PITCH texels apart with no further padding (GcnLinear, the linear-aligned mode, still pads to max(8, 64 / bytes per texel));
  • the target starts at CB_COLOR_BASE plus CB_COLOR_VIEW.SLICE_START[7:0] bytes, and no slice offset is added.

ColorTileModeBlockBytes gives the new mode a 1-byte alignment. The post-draw range check in Draw.cpp, which required 256-byte alignment for every target, now takes the smaller of 256 and the target's ColorTileModeBlockBytes; that is still 256 for every other mode. Linear-general targets take the same CPU staging path as GcnLinear ones.

Still refused: SLICE_START[10:8] set on a linear-general view, multisampled linear-general targets, endian-swapped targets (ENDIAN != 0), and a TILE_MODE_INDEX of 31 without LINEAR_GENERAL. A single-sample FAST_CLEAR keeps main's refusal. A debt fragment adds a PS4 (GCN) linear-general color targets entry (not checked on a console).

Tests:

  • New execution test GcnLinearGeneralColorTarget (agc_driver_gcn_linear_general_color_target): an unpadded 72x64 RGBA8 target (72 is not a multiple of the 16 texels linear-aligned would pad to) with tile mode index 14 in CB_COLOR_ATTRIB, at CB_COLOR_BASE and at CB_COLOR_BASE + 0x44. A triangle is drawn into each; every texel must hold its background or the drawn color at its row-major place, and the 256 guard bytes around the target (plus the 0x44 skipped bytes) must stay unchanged.
  • GcnColorTarget.cpp LinearGeneralTargetsDecode: the byte offset and tile-index override, an 8-bit target with a 24-texel pitch (accepted as linear-general, refused as linear-aligned), and the refusals listed above.
  • Mutation checks: decoding without the SLICE_START byte fails both tests; padding the pitch as GcnLinear does fails both (PS4 color target pitch or slice is not padded the way its tile mode pads them). Without the Draw.cpp change the execution test fails at the 0x44 target with null or misaligned address.

Tested

WSL2 Ubuntu on Windows 11, Release build with GCC, lavapipe (Mesa 25.2.8). Same 29 focused tests (agc_driver_gcn_*, agc_gcn_*, agc_driver_linear_target_*, agc_driver_cmask_fast_clear, agc_driver_eqaa_color_target) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer:

  • main 526b7b1: 29/29 passed, 28 Insert instance layer "VK_LAYER_KHRONOS_validation" lines, no was not found line, 84 VUID-VkDeviceCreateInfo-pNext-pNext.
  • This PR: 30/30 passed (the 29 plus agc_driver_gcn_linear_general_color_target), 29 insert lines, no was not found line, 87 VUID-VkDeviceCreateInfo-pNext-pNext.

The only validation ID on both is the device-creation one from Ubuntu's older 1.3.275 layer (boykopovar#17693), three per test; the change adds no new VUID-. 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 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: lavapipe (Mesa 25.2.8 llvmpipe, Vulkan 1.4.318), WSL2 Ubuntu on Windows 11
  • AI-assisted: yes

tools/pr_overlap.py failed closed. boykopovar#18177, boykopovar#22140 and boykopovar#22514 conflict only on adjacent lines: GcnColorTarget.cpp's main() call list and, for boykopovar#22514, the end of the ColorTileMode enum and ColorTileModeIsGcn; whichever merges second keeps both sides. The 41 PRs it could not compare were each merged by hand against this branch and against main: none gains a conflicting file or hunk from this branch.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for linear-general GCN color targets, including byte-offset addressing and drawing into unpadded target extents.
  • Bug Fixes
    • Updated target-memory alignment checks to account for the selected tile mode’s block size.
  • Documentation
    • Documented linear-general color-target addressing and conditions that may cause errors.

A GCN color target with LINEAR_GENERAL set threw. It is now a linear
surface with the pitch CB_COLOR_PITCH gives, unpadded, at CB_COLOR_BASE
plus the low byte of CB_COLOR_VIEW SLICE_START, whatever its tile mode
index, as shadPS4 reads these registers. The post-draw range check
takes the target's own alignment, at most the 256 bytes it required.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes

The graphics code adds GCN linear-general color-target support. It decodes supported target views with byte-offset addressing and unpadded pitch. Unit and Vulkan execution tests cover decoding, rendered texels, and surrounding guard bytes.

GCN Linear-General Color Targets

Layer / File(s) Summary
Tile mode and layout handling
core/libs/prx/libSceAgcDriver/Graphics/include/ColorTargetLayout.hpp, core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp, core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
The tile-mode definitions recognize linear-general targets. Layout uses the surface width as pitch, and target-range validation uses the smaller of 256 bytes and the tile-mode block size.
Linear-general buffer decoding
core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
DecodeGcnColorBuffer accepts single-sample linear-general targets with clear upper SLICE_START bits. It uses the low address byte as an offset and continues to reject endian-swapped targets.
Decoder and rendering validation
core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp, core/libs/prx/libSceAgcDriver/tests/execution/GcnLinearGeneralColorTarget.cpp, docs/dev/debt/changes/claude-ps4-linear-general-color-targets.md
Unit tests cover supported and rejected configurations. The execution test draws into targets at two byte offsets and checks texels and guard bytes. The documentation records the behavior and notes that it has not been checked on a console.

Change: Feature

Merge Risk: Minimal · up to 2afe9

This adds support for drawing to PS4 linear-general color targets and keeps the existing refusals for unsupported configurations. Tests cover decoding and drawing, and no merge-blocking risk was found. Console behavior has not been verified.

Security architecture risk: Minimal · up to 2afe9

Eligible PS4 linear-general color targets now work at byte offsets. The driver still validates the entire target range, and previously supported color modes keep their existing alignment rules. The inspected change did not establish a new isolation or writeback failure.

Security review details

Security Blast Radius

  • observed — The newly reachable path lets GCN guest register values select a byte-granular start for an unpadded color-target span. The transfer takes that exact span through the existing GuestMemory read and write functions rather than giving Vulkan a direct mapping of the target address.

Trust Boundaries and Controls

  • observed — GuestMemory keeps the null-address, range-overflow, and mapped-access checks separate from alignment. Its write path flushes pending GPU writes and rechecks writability before copying. These are access checks, not allocation-ownership checks.

Hardening Proposals

  • proposed — Extend the guarded Vulkan execution case to an odd byte offset and a target spanning a page boundary, including rejection when the backing range is not fully writable.

Rollout and rollback

  • inferred — The driver decoder permits the new mode from guest register state; the production diff adds no operator approval or migration step. Reverting restores the earlier rejection of the encoding, so workloads that need it lose support on rollback.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 7
  • Waived: $1.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cfc3064a-05f1-468d-81d1-46738db10c9a
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 2afe985.

Files selected for processing: 7

  • core/libs/prx/libSceAgcDriver/Graphics/include/ColorTargetLayout.hpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/ColorTargetLayout.cpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/State.cpp
  • core/libs/prx/libSceAgcDriver/tests/GcnColorTarget.cpp
  • core/libs/prx/libSceAgcDriver/tests/execution/GcnLinearGeneralColorTarget.cpp
  • docs/dev/debt/changes/claude-ps4-linear-general-color-targets.md

Limit details: You’ve used all 10 included reviews currently available.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants