Skip to content

fix(agc): select the alpha clear value for single-channel Vulkan storage images - #1995

Open
Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/28198
Open

Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/28198

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28198, originally opened by lgqdaxia.

Source commit: 335d7fc6a14643873c56fccdbe637b0b944cce9c. 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 single-channel storage image can represent alpha. On GFX10, the DCC keys 0001 and 1110 give color and alpha opposite values. Vulkan clears the only component from the red slot, and the storage path always put the color value there. An R16 alpha image therefore received the opposite value. Use the descriptor's alpha value on upload and refill. When a new descriptor keeps the image and key addresses but changes alpha placement, rebuild the resident image. Repeated binds with unchanged placement still reuse it. AMD PAL's GFX10 rule.

Found while reviewing boykopovar#28192, which handles clear values decoded into guest bytes. This PR covers the command that clears the Vulkan storage image. boykopovar#28118 proposes rejecting these mixed keys on single-channel surfaces. boykopovar#24445 touches the same upload condition for uncompressed images.

Tested

Windows 11, NVIDIA RTX 3080 Laptop GPU (621.14). All seven existing DCC first-write and key-update tests passed on both main (e0ef70639d7e) and this PR (335d7fc6a146). The PR's new regression also passed all 16 full-image pixel readbacks across upload, same-address rebind and refill. The logs show Khronos validation 1.4.368 loaded for every case, with zero skips, VUID errors or synchronization errors on either revision.

On Arch Linux, all eight tests passed on the same PR revision with an RX 6650 XT (RADV Mesa 26.3.1), zero skips and no VUID or synchronization messages. Linux recheck

Earlier Windows regression results · 2026-11-29

On main f61eb307c0, four alpha-selected R16 readbacks returned the opposite value. The initial fix at 58a294887015 passed all 12 upload and refill checks on separate images. Switching only alpha placement on the same image still gave the opposite value on all four rebinds and their following refills.

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 3080 Laptop GPU, NVIDIA 621.14, Windows 11. AMD Radeon RX 6650 XT, RADV Mesa 26.3.1, Arch Linux.
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Storage texture clears now handle single-channel formats with alpha-on-most-significant-bit settings more accurately.
    • Texture images are reused only when their metadata is compatible with the requested resource, helping prevent incorrect results when sampling, drawing, or clearing textures.
  • Tests
    • Added coverage for storage texture clears across multiple formats and metadata configurations.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: DCC Metadata and Storage Clears

Layer / File(s) Summary
Metadata compatibility and clear values
core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp, core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp, core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
Adds StorageImageServesMetadata, which checks alpha placement for nonzero DCC addresses. Storage key clear values account for alpha placement on single-channel formats.
Compatibility checks and execution tests
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp, core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp, core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_dcc_keys_first_write_tests.cmake
Sampled views, storage images, attachment memos, and draw recipes use metadata compatibility checks. The new execution mode tests storage clear values and verifies cache reuse behavior when alpha placement changes.

Suggested reviewers: oneandonlydean, slegljan, eaglebearerys

Change: Bug fix

Merge Risk: Minimal · up to 335d7

This change fixes single-channel storage-image clears when alpha is placed in the most significant bit, and rebuilds a cached image when its alpha placement changes. No concrete defect was found, and pending GPU results are written back before the image is replaced. It looks safe to merge.

Security architecture risk: Minimal · up to 335d7

AGC Graphics now rebuilds DCC-backed images when the requested alpha placement differs, instead of reusing an image that can clear to the wrong value. Replacement uses the existing path for preserving pending GPU writes. The reviewed change does not introduce a new guest-facing operation or expand what it can access.

Security review details

Security Blast Radius

  • inferred — A guest descriptor can cause more cache misses by changing alpha placement at the same DCC address. In the inspected paths this changes reuse within the existing device-and-surface cache and the clear value sent to the selected Vulkan image; it does not grant access to a new resource class.

Resilience and Maintainability Implications

  • observed — Replacement runs under the cache mutex and does not publish the new entry until after creation and adoption. If creation unwinds with a detached image still held by the handover, the handover destructor flushes it. If sampled storage creation fails, the sampled path can fall back to a snapshot and checks for pending writes before reading guest bytes.
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
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: 80c8eb80-2725-4919-8609-f0058bc6993e
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 335d7fc.

Files selected for processing: 6

  • core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp
  • core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp
  • core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_dcc_keys_first_write_tests.cmake
  • core/libs/prx/libSceAgcDriver/tests/execution/DccKeysFirstWrite.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants