Skip to content

feat(agc): pass custom sample locations through VK_EXT_sample_locations - #2183

Closed
Raghav314 wants to merge 9 commits into
boykopovar:mainfrom
Raghav314:feat/agc-msaa-sample-locations
Closed

Raghav314 wants to merge 9 commits into
boykopovar:mainfrom
Raghav314:feat/agc-msaa-sample-locations

Conversation

@Raghav314

Copy link
Copy Markdown
Contributor

What

Follow-up to #419, as discussed there. decodeSamples refused any PA_SC_AA_SAMPLE_LOCS pattern other than the standard one for the sample count, so a title that rasterizes with its own pattern threw "nonstandard sample locations are unsupported".

The registers give each sample's position as a signed 4-bit offset in 1/16 pixel from the pixel center. VK_EXT_sample_locations takes positions in [0, 1) of the pixel, so a register offset x is 0.5 + x / 16. The console's standard 4x pattern maps exactly onto Vulkan's standard 4x positions this way, which checks both the scale and the direction of y.

  • A pattern that is the same for all four pixels of the quad becomes the pipeline's sample locations (a 1x1 grid). It is part of the pipeline key. Patterns that differ between the pixels still throw.
  • The device needs the extension with variableSampleLocations, 4 sub-pixel bits and a coordinate range covering 0 to 15/16, for the draw's sample count. Otherwise a draw with custom locations throws. Requiring variable locations means pipelines with different patterns can share a render pass.
  • A multisampled depth image is created with SAMPLE_LOCATIONS_COMPATIBLE_DEPTH when the device supports that for its format and sample count (vkGetPhysicalDeviceImageFormatProperties with the flag and the image's usage). A draw with custom locations whose depth target the device cannot make compatible throws. The depth image stays in GENERAL after creation, so no layout transition needs the locations.
  • A CB resolve does not depend on where the samples are, so it now accepts any quad-uniform pattern instead of only the standard one.
  • TechnicalDebt gets an entry.

PPSA36082

Hades II rasterizes its 4x targets with an ordered grid: the PA_SC_AA_SAMPLE_LOCS words are 0x444cc4cc for all four pixels, that is (±4, ±4)/16. On main f145139 with the fixes it needs to get that far plus #419, it threw the error above while rendering (it showed up as a failed presentation). With this change, #2121 and #2132, the game renders those passes correctly in gameplay. On the RTX 4090 every depth format it supports is compatible at 1x to 8x, and the game ran into gameplay with this change with no refusals or skipped draws in the log.

Tested

Linux (CachyOS), x86-64, GCC, 7800X3D / RTX 4090.

  • agc_driver_graphics (new checks):
    • The game's 4x ordered grid decodes; 2x positions in another order decode; a pattern that differs between the quad's pixels is refused; the standard 4x pattern is not treated as custom.
    • An 8x pattern decodes from both register words of each pixel.
    • The console's standard 4x offsets convert to Vulkan's standard 4x positions; the extreme offsets convert to 0 and 15/16.
    • Depth compatibility on a stub device: no extension, a supported format and count, an unsupported count, a refused format, and a single-sample target. The query uses the flag and the usage the depth image is created with.
  • Mutations, each failing a check: y flipped, 1/8 pixel instead of 1/16, one register word per pixel, the format not queried, the format's sample counts ignored, the extension's sample counts ignored, single-sample allowed.
  • Not covered by a device test: the pipeline actually rasterizing at the custom positions. That part was checked in game.
  • The linux job of current build.yml run locally (SPIRV tools on, test registration check, build, libs, ctest), both on this head (468/468) and on it merged with main d70b899 (517/518). feat(agc): multisampled color and depth targets with CB resolves #419 conflicts with main on one line of Texture.hpp since perf(agc): size the storage and sampled texture caches to the device #1059 (both add a declaration there); for that merge I kept both. agc_driver_dcc_keys_first_write fails on main without this change too.

Checklist

MichonGoddijn231849 and others added 9 commits October 8, 2026 17:20
Titles fast-clear a depth surface by filling its HTILE with ZMASK 0
(DMA_DATA immediate fills or the buffer-fill kernel) instead of drawing.
Depth surfaces were only cleared when they were made, so every later
frame kept the previous frame's depth and stencil and most draws failed
the depth test.

The depth target now records DB_HTILE_DATA_BASE. A uniform fill whose
ZMASK is 0 and which covers a surface's HTILE marks the surface cleared;
its next use as a target or a texture clears it to DB_DEPTH_CLEAR and
DB_STENCIL_CLEAR.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ds; HTILE only with TILE_SURFACE_ENABLE

A fill over a depth surface's whole HTILE fast-clears the depth when ZMask is 0
and, when the HTILE holds the stencil state (TILE_STENCIL_DISABLE clear), the
stencil when SMem is 0; a fill writing an aspect's fields otherwise cancels its
pending clear. DB_HTILE_DATA_BASE is taken only with DB_Z_INFO.TILE_SURFACE_ENABLE.
Tests cover the decode and HtileFillClears/HtileFillCovers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…erage and clear value as inferred

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A whole-HTILE fill of ZMask 0 clears the depth to DB_DEPTH_CLEAR at the next draw; a fill shorter
than the HTILE and an expanded fill (ZMask 0xf) clear nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…el DCBs; a CPU-stored fill clears too

agc_driver_depth_fast_clear_submit submits the fills the title uses (a DMA_DATA immediate
fill and the fill kernel's dispatch) over the HTILE and checks the next depth-tested draw;
a depth-only fill over an HTILE with stencil keeps the stencil (a stencil-tested draw).
The depth metadata note now also follows the CPU fallback of a fill the device could not
store.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Draws with PA_SC_AA_CONFIG multisampling (2, 4 or 8 samples, every target with as many
fragments, the standard sample locations, MSAA_ENABLE) render into host-only multisampled
color images and multisampled depth surfaces; the pipeline rasterizes with that sample
count. A CB_COLOR_CONTROL resolve over a multisampled CB0 runs as a render pass whose
resolve attachment is CB1's resident image. A zero fill over a target's CMASK fast-clears
it to the CB_COLOR_CLEAR_WORD values of its next use. EQAA, coverage conversion,
nonstandard sample locations, sampling a multisampled surface and multisampled mips stay
refused.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tate refuses what it cannot model

The duplicate ColorTarget::cmaskAddress, decode and size helper are gone: multisampled targets
use main's cmaskAddress/cmaskBytes (whole metablocks). Single-sample targets keep main's rule
(CMASK under FAST_CLEAR); a multisampled one takes it under FAST_CLEAR or COMPRESSION. A zero
fill of the whole CMASK clears at the next use, 0xFFFFFFFF marks it expanded, any other or
partial fill refuses the next use; eliminate/DCC passes over a multisampled target and a CB
resolve into a fast-clear destination are refused. The draw key adds CMASK_BASE_EXT (0x398),
which main decodes but did not key.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
decodeSamples refused any PA_SC_AA_SAMPLE_LOCS pattern other than the
standard one for the sample count, so a title that rasterizes with an
ordered grid threw "nonstandard sample locations are unsupported".

The registers give each sample's position as a signed 4-bit offset in
1/16 pixel from the pixel center, which is VK_EXT_sample_locations'
1/16-pixel grid shifted by half a pixel; the console's standard 4x
pattern maps exactly onto Vulkan's standard 4x positions. A pattern that
is the same for all four pixels of the quad becomes the pipeline's
sample locations (a 1x1 grid, part of the pipeline key) on a device with
variable sample locations at 1/16 pixel for that sample count; patterns
that differ between the pixels still throw.

Multisampled depth images are created with
SAMPLE_LOCATIONS_COMPATIBLE_DEPTH when the device supports it for their
format and sample count, and a draw with custom locations and a depth
target the device cannot make compatible throws.

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

Copy link
Copy Markdown
Contributor Author

Closing in favour of #2169, which implements the same thing and was opened first. I've left my Hades II results and a depth-format note there.

@Raghav314 Raghav314 closed this Oct 9, 2026
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