Skip to content

fix(agc): pick float or integer sampler border colours from the paired images - #3220

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
kr4y4:fix/agc-sampler-border-color-class
Oct 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
kr4y4:fix/agc-sampler-border-color-class

Conversation

@kr4y4

@kr4y4 kr4y4 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

DecodeSamplerResource maps the S# BORDER_COLOR_TYPE values 0, 1 and 2 to VK_BORDER_COLOR_INT_TRANSPARENT_BLACK, INT_OPAQUE_BLACK and INT_OPAQUE_WHITE, whatever the sampler is used with. Vulkan returns poison when the border colour class doesn't match the view (Instruction/Format/Sampler/Image View Validation): "The sampler borderColor is an integer type and the image view format is not one of the VkFormat integer types or a stencil component of a depth/stencil format", and the reverse for a float border on a non-float view. On GFX10 the hardware field doesn't depend on the format; radv maps the FLOAT and INT variants to the same BORDER_COLOR_TYPE.

The problem shows on real devices. On main, sampling a black 8_8_8_8_UNORM texture outside [0, 1] with CLAMP_BORDER and an opaque black border returns alpha 0 instead of 1.0. This happens on an RTX 4070 and on an Intel Raptor Lake-S iGPU:

8_8_8_8_UNORM opaque black border: thread 0 component 3 is 0x00000000, expected 0x3f800000

Shadow maps are the usual case, since they clamp to a white border so that lookups outside the map read as lit.

Each sampler descriptor now carries samplerIntegerBorder, which picks between the FLOAT and INT border colours:

  • DescriptorBindingBuilder already sorts the images paired with a guest sampler into the two physical sampler elements (samplerModes). It now also notes whether those images have an integer numeric class.
  • An element gets an INT border only when every image paired with it is Uint or Sint. Float, unorm, snorm and depth images, and elements shared by both kinds, get FLOAT.
  • The flag goes through the sampler cache key (bit 4), DecodeSamplerResource, SamplerCache::Get, the binding pack and the shader disk cache. FormatVersion moves to 25.
  • ShaderResources::applyAnisoOverride rebuilds samplers for single-level images, so SamplerSource keeps the flag and passes it again there.
  • A producer that leaves the vector empty gets FLOAT, the common case.

Tests:

  • agc_driver_image_sample_border_color (new) samples outside a 8_8_8_8_UNORM and a 8_8_8_8_UINT texture with each border type and checks (0,0,0,0), (0,0,0,1) and (1,1,1,1) as floats and as integers. Two more cases sample with ANISO_OVERRIDE and anisotropic filters, which go through applyAnisoOverride.
  • RunGuestSamplerResourceTests expects FLOAT borders by default and INT with integerBorder.
  • The ShaderDiskCache round trip covers the new flag.

Found while comparing AnyPS5's S# decoding with Mesa's gfx10-rsrc.json / navi10_enum.h and the Vulkan spec. The field decode itself is right; only the Vulkan colour class is wrong.

This is #2392 again, which was closed by the intake pause. Rebased onto current main: it now sits beside #1487's forceDegammaPaired parameter and the applyAnisoOverride from 17d9efc.

Overlap:

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at d31b57a (rebased onto 6040a96, which only splits agc_driver_flat_apertures):

  • agc_driver_image_sample_border_color, agc_driver_image_sample_aniso_override, agc_driver_image_sample_shared_sampler, agc_driver_graphics and agc_shader_disk_cache pass with --repeat until-fail:3 on an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU.
  • Each of these makes agc_driver_image_sample_border_color fail on both GPUs:
    • INT borders for every sampler, as on main: 8_8_8_8_UNORM opaque white border: thread 0 component 0 is 0x00000000, expected 0x3f800000. agc_driver_graphics also fails, with unnormalized clamp-to-border S# decoded incorrectly.
    • FLOAT borders for every sampler: 8_8_8_8_UINT opaque black border: thread 0 component 3 is 0x00000000, expected 0x00000001 (0x000000ff on the Intel iGPU).
    • applyAnisoOverride without the flag: 8_8_8_8_UINT opaque white border under ANISO_OVERRIDE: thread 0 component 0 is 0x00000000, expected 0x00000001.
  • Full suite on the RTX 4070 with -j 8: 759/759 passed in three runs. guest_filesystem needs Developer Mode for its symlinks, which this machine doesn't have. In a fourth run, agc_driver_draw_cache_reuse exited with 0xc0000374 once. It binds no samplers, and it passed 35 times on its own.
  • tools/check_conventions.py passes.

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 in TechnicalDebt
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

kr4y4 and others added 2 commits October 10, 2026 21:57
…d images

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…Border

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

Copy link
Copy Markdown
Collaborator

Checked the binding builder, sampler cache key, disk cache and tests; the S# border behaviour matches hardware (measured on gfx1035: UNORM opaque black → alpha 1.0f, UINT opaque white → 1,1,1,1).

One fix added as a separate commit: static_assert(sizeof(DescriptorBinding) == 488, ...) in ShaderDiskCache.cpp fails on Linux x86_64 now that samplerIntegerBorder is added; updated to 528. Build and the scoped ctest are green after it.

Merging once CI is green.

@adriadam10
adriadam10 merged commit c757e8e into boykopovar:main Oct 11, 2026
14 checks passed
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.

2 participants