Skip to content

fix(agc): sample 10_10_10_2 SNorm and SInt textures - #5149

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/agc-texture-snorm-sint-2101010
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/agc-texture-snorm-sint-2101010

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Guest texture formats 51 (10_10_10_2 SNorm) and 55 (10_10_10_2 SInt) were missing from kFormatLookup (TextureFormat.cpp) and from the sampled-format table in RdnaDescriptorFormat.cpp, so a texture descriptor using them threw unsupported guest texture format 51 (or 55), while UNorm (50) and UInt (54) of the same group worked. The buffer-format path (SpirvBufferFormat.cpp) and the vertex-input table (VertexInput.hpp, which already maps 50 to 55 to A2B10G10R10_*) already knew them.

  • 51 maps to VK_FORMAT_A2B10G10R10_SNORM_PACK32, 55 to VK_FORMAT_A2B10G10R10_SINT_PACK32 (4 bytes, not block compressed).
  • Sampled numeric class: 51 float, 55 signed integer (54 is unsigned integer).
  • IntegerFormat in Texture.cpp lists the SINT packing next to the UINT one.
  • The RunTextureFormatTests cases in tests/TextureFormat.cpp check the mappings, the element size and the numeric class of 51, 54 and 55.

Why the codes are right: the numbers are the GFX10 unified texture format values. Mesa's register database (src/amd/registers/gfx10-rsrc.json, enum GFX10_FORMAT; older Mesa trees call the enum IMG_FORMAT) lists GFX10_FORMAT_2_10_10_10_{UNORM,SNORM,USCALED,SSCALED,UINT,SINT} as 50 to 55. The repo's IrBufferFormat calls the same codes 10_10_10_2 (the name runs in the other direction), and 50 and 54 were already mapped to A2B10G10R10 the same way. This is a spec-based fix; no title is named as evidence.

Not covered: no GPU test of sampling 51/55 (no existing execution test creates such a texture); the clear-layout table (ClearKind in Texture.cpp) has no entry for the new packings (it returns false for them, as before); the scaled variants 52 and 53 stay unmapped (Vulkan has no sampled USCALED/SSCALED images). Code 135 (5_5_5_1) is also missing from the table; that is left for a separate change.

Tested

Windows 10, MinGW-w64 GCC 15.2.0, Release, on main 14036cb0e plus this commit (rebased afterwards onto main 0f2683cb7 without a conflict, not rebuilt there):

  • agc_driver_graphics (it runs RunTextureFormatTests): 5 of 5 runs pass (about 7 s each).
  • With TextureFormat.cpp, RdnaDescriptorFormat.cpp and Texture.cpp taken back to main and the new test kept, it fails 2 of 2 runs with AGC graphics: unsupported guest texture format 51.
  • python tools/check_conventions.py --base upstream/main passes.
  • git merge-tree of the current head c6a422342 against main 068ab2aba (13 October) is clean.
  • Linux validation by coltken95 in the comments (13 October, 18:51Z; Linux x86-64, Release, lavapipe / llvmpipe LLVM 20.1.2; c6a422342 merged into main 9d0a41d5a): the five tests in this PR's targets (agc_driver_graphics, agc_sparse_buffer_holes, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags, agc_driver_covered_centroid_state) pass with the PR; with main's sources and this PR's tests only agc_driver_graphics fails.
  • Not tested: the other agc_* tests on this branch, a GPU draw that samples 51/55, a title run.

Checklist

  • Based on current main; no other open PR implements the same functions (searched open PRs for A2B10G10R10 and the format codes: none)
  • 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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a for the GPU selection: the test that covers this change (agc_driver_graphics, RunTextureFormatTests) is a host test that selects no GPU (it gives the same result with ANYPS5_GPU set to a name no GPU has). Machine: Windows 10 (19045), NVIDIA GeForce RTX 4080 SUPER (driver 32.0.16.1074) and AMD Radeon RX 6400 present, neither selected by this test. Not tested: a draw that samples 51/55 on any GPU.
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

Guest texture formats 51 (SNorm) and 55 (SInt) of the 10-bit packed group were missing from the texture lookup and the descriptor format table, so a descriptor using them threw 'unsupported guest texture format' while the UNorm (50) and UInt (54) siblings worked. Map them to A2B10G10R10_SNORM_PACK32 / A2B10G10R10_SINT_PACK32, classify them for sampling (float / signed integer), and list SINT among the integer formats.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 13, 2026
@coltken95

Copy link
Copy Markdown

Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with c6a4223 merged into main 9d0a41d:

  • With the PR: all five tests in the PR's targets pass (agc_driver_graphics, agc_sparse_buffer_holes, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags, agc_driver_covered_centroid_state).
  • With main's sources and the PR's tests: agc_driver_graphics fails; the other four pass.

AI-assisted: yes (Claude Code)

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the Linux test, @coltken95. It matches the Windows result in the description: with main's sources and this PR's tests agc_driver_graphics fails (there with AGC graphics: unsupported guest texture format 51, 2 of 2 runs), and it passes with the change. The other four tests in the targets do not exercise the format, so it is expected that they pass either way.

AI-assisted (Claude Code).

@CnRJay CnRJay 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.

The table entries look right. One thing a host-only test can't catch: Vulkan doesn't require sampled-image support for these two host formats. In the spec's mandatory format support table for packed 32-bit formats, VK_FORMAT_A2B10G10R10_UNORM_PACK32 and VK_FORMAT_A2B10G10R10_UINT_PACK32 must support SAMPLED_IMAGE, but A2B10G10R10_SNORM_PACK32 and A2B10G10R10_SINT_PACK32 are optional. They are missing on some drivers; vulkan.gpuinfo.org lists which devices expose them.

On such a device, the first texture with format 51 or 55 reaches vkCreateImage / vkCreateImageView with a format the device doesn't support for sampling. That is undefined behaviour or a driver error, not a clean "unsupported" throw. The storage path already checks per physical device (StorageFormatOrUndefined in Texture.cpp). For the sampled path, I'd suggest either:

  • checking optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT for these two formats (cached the same way) and throwing unsupported guest texture format 51 on this device when it's missing; or
  • decoding them in the shader from an R32_UINT view (sign-extend each 10/2-bit field, then scale for SNORM). That works everywhere but costs ALU per sample, so I'd only do it as a fallback.

A GPU run that samples format 51 on NVIDIA and AMD would also confirm the SNORM edge case: -512 and -511 both map to -1.0, and the 2-bit alpha -2 maps to -1.0. The console and Vulkan should agree there, but nothing currently tests it.

@oneandonlydean
oneandonlydean merged commit b9e0e4e into boykopovar:main Oct 14, 2026
13 checks passed
RINNECODER added a commit to RINNECODER/AnyPS5 that referenced this pull request Oct 14, 2026
#484)

* fix(agc): sample 10_10_10_2 SNorm and SInt textures

Guest texture formats 51 (SNorm) and 55 (SInt) of the 10-bit packed group
were missing from the texture lookup and the descriptor format table, so a
descriptor using them threw 'unsupported guest texture format' while the
UNorm (50) and UInt (54) siblings worked. Map them to
A2B10G10R10_SNORM_PACK32 / A2B10G10R10_SINT_PACK32, classify them for
sampling (float / signed integer), and list SINT among the integer
formats. TextureFormat.cpp and RdnaDescriptorFormat.cpp are shared with
our Metal path.

Metal has no signed RGB10A2 pixel format, so MetalTexture still refuses
these two formats, now by name ("no supported pixel format for guest
format 51") instead of failing the shared lookup. Recorded in
TechnicalDebt.

Test: metal_utility_tests (TextureResource.mm) checks that 51 and 55
resolve to the signed packings, are four bytes and not block compressed,
and that a native texture refuses them by name. The upstream
RunTextureFormatTests cases (tests/TextureFormat.cpp) are carried too;
they build in the Vulkan graphics tests, not on macOS.

Ported from upstream PR boykopovar#5149
(cherry picked from commit c6a4223)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

* fix(agc): share a depth plane's contents across its stencil pairings on Metal

A title can bind one depth plane with several stencil planes (or one
stencil plane with several depth planes). MetalDepthSurfaceCache keys a
surface by both plane addresses, so each pairing got its own textures,
cleared on creation: depth written through one pairing never reached the
others, and later draws tested against stale depth.

The cache now records, per depth and per stencil plane address, the
surface that bound it last. Binding a single-sample surface without
DB_DEPTH_VIEW slices takes each of its planes from that surface when both
have the same format and extent: a blit copies the texture layer, or, for
a combined Depth32Float_Stencil8 texture, only that plane's aspect through
a buffer. The blit is committed on the backend's queue, after the passes
that wrote the other surface and before the draw that binds this one.
Multisampled surfaces and depth-array slices keep their own planes, as
before. Clear() forgets the owners.

Upstream does this in the Vulkan DepthSurface.cpp (vkCmdCopyImage, plus a
pending fast clear carried over); our Metal path has no HTILE fast-clear
state, so only the copy applies.

Test: metal_utility_tests (DepthResource.mm, sharedPlanes) binds a depth
plane with a second stencil plane, binds the same pairing again, goes
back to the first pairing, binds the stencil plane with another depth
plane and binds a pairing of another extent, for D16S8 and D32S8. It
fails without this change ("Sampled depth plane returned incorrect GPU
values").

Ported from upstream PR boykopovar#4683

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

* fix(agc): retire a Metal depth surface once another writer covers its memory

A depth surface lives only in its Metal textures: nothing writes it back
to guest memory. When a color target or another depth target is later
bound over its memory, the surface still answered every view of that
address, so a texture of another layout there threw ("resident depth
view is incompatible") and a matching one read the dead depth.

The surface is now retired by the last writer:
- binding a color target drops the depth surfaces whose depth or stencil
  plane it overlaps from the draw's resident surfaces (the ones views
  and depth-array gathers search);
- binding a depth target moves its surface last and retires the other
  surfaces its planes overlap: another stencil pairing of its depth
  plane, or a surface of another extent at its address. The lookup then
  finds the surface bound last, not the one bound first.
The cache keeps a retired surface; binding its target again brings it
back with the texels it held (with boykopovar#4683's change, a plane another
pairing wrote since is copied over first).

Not ported: upstream also retires a surface on a written storage image
over its planes and, with write watching, on CPU or driver stores. Our
Metal path has no storage view of a depth plane (a storage image at its
address throws) and no write tracking for this cache, so those cases keep
throwing. Recorded in TechnicalDebt.

Test: metal_utility_tests (DepthResource.mm, retiredDepth): writes next
to the planes retire nothing; the surface being bound is kept; a writer
inside the depth or stencil plane retires it; the cache still returns it;
binding a depth target of another extent at the address retires the
other surface.

Ported from upstream PR #454

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

* docs(agc): record the Metal depth-plane views and storage writes not modeled

Upstream boykopovar#4722, boykopovar#4873, boykopovar#5054, boykopovar#5113 and boykopovar#5446 fix the Vulkan depth-plane
copy (padded detiled rows and slices, a cube with a mip chain) and the
storage writes over a depth plane. Our Metal path has neither: a resident
depth surface is served only as a single-level 2D view or a 2D array of
its extent, and a storage image over its plane is bound to guest memory.
Record that in TechnicalDebt instead of porting the fixes.

Refs upstream-pr-batch-1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

---------

Co-authored-by: xXPBSXx <20614131+xXPBSXx@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants