Commit Graph

328 Commits

Author SHA1 Message Date
Adrià be8a67db1c
Merge pull request #3228 from GustavoGamarra95/feat/agc-alpha-to-coverage
feat(agc): emulate undithered alpha-to-coverage
2026-10-11 09:22:23 +02:00
Adrià 47c8e19eb7
Merge pull request #1619 from fisherjoey/fix/depth-compare-copy
perf(agc): sample comparison-read R32F/R16 surfaces from a GPU depth copy of their storage image
2026-10-11 09:21:23 +02:00
Adrià c757e8eaa7
Merge pull request #3220 from kr4y4/fix/agc-sampler-border-color-class
fix(agc): pick float or integer sampler border colours from the paired images
2026-10-11 09:19:14 +02:00
Adrià 010fad317a
Merge pull request #3194 from XairRrR/feat/agc-8-8-swap-alt-blending
feat(agc-driver): blend into COLOR_8_8 SWAP_ALT targets with a separate alpha equation
2026-10-11 09:17:35 +02:00
Adrià 5beb77f0f6
Merge pull request #3231 from Raghav314/perf/agc-pass-fault-only-draws
perf(agc): continue render passes across draws with only a fault buffer
2026-10-11 09:14:20 +02:00
Adrià 6e52fb8f8c
Merge pull request #3158 from XairRrR/perf/agc-host-import-spans
perf(agc-driver): import adjacent registered ranges as one host-import span
2026-10-11 09:14:15 +02:00
Dean 9480e0c253
Merge pull request #3173 from LeandroLP23/fix/agc-library-module-lifetime
fix(agc): keep a shader library part's modules until the part is destroyed
2026-10-11 18:43:54 +13:00
Dean 33c0cffb7e
Merge pull request #3134 from SleglJan/feat/agc-display-rgba16-float
feat(agc): present 16-bit float display buffers
2026-10-11 18:20:13 +13:00
Joey Fisher b384183505 test(agc): pin the depth copy path, its refresh on reuse, R16 and several mips and layers; drop APS5_NO_DEPTH_COPY 2026-10-11 04:52:36 +02:00
Joey Fisher d024709cff perf(agc): sample comparison-read R32F/R16 surfaces from a GPU depth copy of their storage image 2026-10-11 04:52:36 +02:00
raghav314 70a6dde689 perf(agc): continue render passes across draws with only a fault buffer
A recorded draw counted as reading and writing any guest memory when its
resources needed completion work, which a fault buffer alone (guarded
descriptor slots, rect lists) also needs. Such a draw reaches no guest
memory through it: the buffer is the draw's own, written only on a fault.
Its pass hazards now come from its known ranges and images like any other
draw; address-based draws, draws through the BDA table and draws with
copied writes still count as touching any guest memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 07:53:23 +05:30
XairRrR ba0b042925 feat(agc-driver): blend into COLOR_8_8 SWAP_ALT targets with a separate alpha equation
An 8_8 target with SWAP_ALT keeps the x export in its first channel and
the alpha export in its second, and the color block blends that second
channel with the alpha equation. Blending into such a target threw.

With one equation for color and alpha the draw blends as before. With a
separate alpha equation the pipeline draws twice: the first pass writes
the first channel with the color equation, the second writes the second
channel with the alpha factors and operation moved into its color
equation. The split is refused, by throwing, for draws that write depth
or stencil, use per-face depth bias, or whose pixel shader writes memory,
since those would repeat; factors of the destination alpha throw since
the target keeps it in its second channel. Pipeline libraries are not
used for split pipelines.
2026-10-11 04:00:44 +02:00
krishnaraya 1ce9790481 fix(agc): pick float or integer sampler border colours from the paired images
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 21:57:09 -04:00
Gustavo Ariel Gamarra Rojas 7d92bf70f9 feat(agc): decode undithered alpha-to-coverage
DB_ALPHA_TO_MASK 0xaa01, the enable bit with the four offsets at 2 and no OFFSET_ROUND, reaches the pixel stage, which keeps a pixel when its MRT0 alpha is at least one half. Dithered or rounded settings, and an MRT0 that is missing, swizzled, packed or exported without a floating-point alpha, still throw. God of War Sons of Sparta (PPSA28997) stopped on it a few minutes into play.
2026-10-10 22:50:46 -03:00
Dean Galvin 60f12c888d fix(agc): compare host imports when device writes reach the write watch
The import probe only checked whether a GPU read of an imported range
reports its pages as written. lavapipe runs command buffers on CPU
threads, so its writes into an import go through the page tables and
are collected as CPU stores. In agc_unit_shadow the whole publish's
copy into the import is then collected as a CPU store over unit 3, and
the next partial publish drops the slab's newer bytes as stale: "the
partial publish did not copy exactly the partly covered unit".

The probe now also fills the scratch range on the GPU and collects
again. When the read or the fill reports pages as written, host and
dma-buf imports are compared. lavapipe reports 0 of 4 pages after the
read and 4 of 4 after the fill; NVIDIA reports 0 after the fill.

The probe change is the first commit of #1046.
2026-10-11 14:15:27 +13:00
Adrià a0d669926c
Merge pull request #2996 from MarcZX100/fix/agc-mesh-wave32-subgroup-2815
fix(agc): require 32-lane subgroups for wave32 mesh programs
2026-10-11 01:58:20 +02:00
Adrià b64c75fc12
Merge pull request #2939 from CnRJay/fix/agc-dcc-comp-to-single
fix(agc): expand comp-to-single DCC keys in a DCC decompress pass
2026-10-11 01:46:49 +02:00
poonasor 1d7f8bd365 fix(agc): keep a shader library part's modules until the part is destroyed
Pipeline destroyed its shader modules right after LinkPipelineFromLibraries returned, while the pre-rasterization and fragment shader library parts built from them stay cached and are relinked later with VK_PIPELINE_CREATE_LINK_TIME_OPTIMIZATION_BIT_EXT. On AMD's Windows driver (RX 6700 XT, Adrenalin 25.10.45.05) that link faults inside amdvlk64.dll at varying offsets, reading freed heap memory, in 22 agc tests on a cold driver cache; all of them pass with APS5_NO_PIPELINE_LTO=1. Running the optimized link synchronously or without a pipeline cache did not help, keeping the modules alive did.

When the optimized link is enabled, the library store takes over the modules of each newly built shader part and destroys them in ClearPipelineLibraries after the pending links have finished. Modules of a pipeline whose parts were all cached are destroyed as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 01:42:44 +02:00
Chad b89b7f953c fix(agc): expand comp-to-single DCC keys in a DCC decompress pass
Key 0x10 (GFX9_DCC_CLEAR_SINGLE in Mesa) marks a 256-byte block whose texels all equal its first texel. A CB DCC decompress pass over uniform comp-to-single keys now writes that texel over its block and stores uncompressed keys; a fast-clear eliminate over them throws.
2026-10-11 01:38:27 +02:00
Scott Schuster b352406f70 fix(agc): bound a strided buffer's rounded-up last record by its allocation
RADV rounds a strided buffer descriptor's record count up, so stride * records
can run up to one stride past the end of the buffer's allocation. The guest
buffer region then no longer fits inside the allocation's host import and is
copied on the CPU, whole, for every draw that binds it.

When a strided descriptor ends less than one stride past the end of the
readable registered allocation that contains its base, the range is bound up
to the allocation's end. RetroArch's Dolphin core binds a 48 MiB stream buffer
with stride 20 (records 0x266667, 12 bytes past the allocation) on every draw.
With this change the buffer is bound in place from its import.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 01:37:00 +02:00
Adrià 4b9f07519c
Merge pull request #2864 from MarcZX100/fix/agc-release-deferred-imports
fix(agc): release retired imports while waiting for pins
2026-10-11 01:21:06 +02:00
Adrià a75c0c5759
Merge pull request #1430 from fisherjoey/fix/depth-surface-record
perf(agc): prove sampled depth surfaces in the fast resource proof
2026-10-11 01:12:49 +02:00
XairRrR 70d7aa58e3 perf(agc-driver): import adjacent registered ranges as one host-import span
A host import covered exactly one registered range, so a buffer crossing
two ranges had no import and was copied on the CPU at every use, under
the GPU mutex. Titles that map a GPU heap piece by piece (Uncharted maps
1 MiB direct-memory pieces) hit this for every buffer larger than a
piece.

An import now covers the run of address-adjacent registered ranges that
are readable with the same write and GPU access. Runs never overlap, so
imports do not either; an import is retired when any range of its run
changes, and a refused run is remembered by its base. Callers already
address imports relative to their base.
2026-10-11 01:04:12 +02:00
MarcZX100 f5618d9124 fix(agc): release retired imports while waiting for pins 2026-10-11 01:01:14 +02:00
Adrià 33301449c7
Merge pull request #2757 from TheAggie/fix/agc-mesh-strip-restart
fix(agc): honour primitive restart in mesh-path triangle strips
2026-10-11 00:46:32 +02:00
Adrià 926ad9e35f
Merge pull request #2699 from alfalfa-star/fix/agc-fast-clear-snapshot-watched
perf(agc): read a fast-cleared surface's guest bytes only when the import is compared
2026-10-11 00:43:29 +02:00
Adrià 617256e97f
Merge pull request #2283 from MathiasDevelopes/fix/agc-count-copied-buffers-in-batch-budget
fix(agc): count copied guest buffers and draw snapshots in the batch byte budget
2026-10-11 00:41:22 +02:00
Jan Šlégl 2e19053f63 feat(agc): present 16-bit float display buffers
PPSA11386 registers 3840x2160 tiled display buffers in pixel format
0xC001000622000000, R16G16B16A16 float in KytyPS5 and SharpProspero
(0xC001000600000000 is the blue-first variant), and stops on "VideoOut:
unsupported display pixel format". The buffer is eight bytes per texel; its
tiled layout is assumed to be the 8-byte SW_64KB_R_X equation applied to
full coordinates, as addrlib applies it. The values are taken as linear
light and encoded with the sRGB curve for the 8-bit output. The encoding
compares the raw half-float bits against two tables of 255 thresholds
(color and alpha) that the CPU decode and the color transfer shader share,
so both give the same bytes on any driver; negative and NaN values give 0.
Guest-memory detile, the resident image path and the CPU decode all handle
both formats; DCC metadata on a float buffer throws. Neither the layout nor
the transfer is verified against console frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq
2026-10-11 00:38:12 +02:00
Adrià 4fb937abe9
Merge pull request #1961 from Raghav314/fix/agc-import-gpu-memory-at-map
fix(agc): import GPU-mapped guest memory when it is mapped
2026-10-11 00:34:16 +02:00
Adrià a1f82d238b
Merge pull request #2386 from krishnaraya4/fix/agc-packed-16bit-channel-order
fix(agc): sample 5_6_5, 1_5_5_5 and 4_4_4_4 textures in AMD's channel order
2026-10-11 00:34:09 +02:00
Adrià 015beb3c95
Merge pull request #2233 from TideOPL/pr/pooled-buffer-exact-size
fix(agc): give pooled buffers a VkBuffer of exactly the requested size
2026-10-11 00:33:25 +02:00
MathiasDevelopes 078b6d886f style(agc): drop the comments the conventions check rejects
Comments are reserved for technical debt (docs/dev/TechnicalDebt.md), so
the ones the previous commit added to the recorder, the snapshot keep and
the tests go.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HZHkb8kUwnHAuBBbHywvJf
2026-10-11 00:33:07 +02:00
MathiasDevelopes 4940de5436 fix(agc): count memory shared by a batch's keeps once and test the three keep sites
A ShaderResources from the resource caches is the same object for every
draw or dispatch that uses it, and Recorder::ReusableDrawSnapshot hands
the next draw the same snapshot buffer, so passing their bytes with each
Keep counted one allocation once per use and submitted the batch before
it held the budget. Recorder::KeepBytes counts an owner's bytes once per
batch, and the dispatch, draw and snapshot keeps use it.

The recorded kept bytes test runs a dispatch and a draw that copy a
guest buffer and two draws that snapshot one on the device, and fails
when any of the three sites stops counting or a reused snapshot counts
twice. The BdaResources check pins the copied region it sets up.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HZHkb8kUwnHAuBBbHywvJf
2026-10-11 00:33:07 +02:00
MathiasDevelopes 00fafd4379 fix(agc): count copied guest buffers and draw snapshots in the batch byte budget
The recorder bounds the bytes a batch keeps alive (KeptBytesBudget) and
waits for older batches past twice that. A recorded dispatch or draw kept
its ShaderResources, and a draw its snapshot buffers, with a size of 0, so
the host-visible copies of guest buffers they own never counted. A title
that binds a 124 MiB writable guest buffer in every draw then held about
ninety copies, 11 GB, until the GPU caught up, and aborted with
VK_ERROR_OUT_OF_HOST_MEMORY from vkAllocateMemory.

GuestBufferMemory reports the bytes of its copied regions, and the
dispatch and draw keeps and the draw snapshots pass their bytes to
Recorder::Keep, so the existing bound applies to them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-11 00:33:07 +02:00
raghav314 be1f501525 fix(agc): import GPU-mapped guest memory when it is mapped
The registry calls an observer on the mapping thread, after the registry
lock is released, with the ranges a kernel mapping gave GPU access:
direct and flexible maps with it, and fixed remaps with it over a
registered range (a reservation). The mutation looks them up while it
still holds the lock and hands them over weakly, with the registry
generation it ended at, so the observer does not keep a range alive.
The driver imports those ranges on its current device, so an
address-based build finds the import instead of pinning the memory on
the queue that first uses it. A range that gains GPU access through
sceKernelMprotect, and AnyPS5's own libc heap, are still imported on
first use.

The import at map does not reconcile the other imports with the
registry, so its cost does not grow with the number of imports. It skips
a range that is gone, and any range when the imports were reconciled
with a newer registry since; the next lookup imports those as before.
It installs the pin waiter as the other import paths do, so unmapping a
range imported at map retires its import. The live import bytes are kept as a
running total instead of being summed over every import. Once the import
table belongs to the current device the import takes only the table's
lock; the first import on a device (which runs the write-watch probe)
and a device that was just replaced go through the GPU lock. Clearing
the observer waits for calls already running.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 00:23:23 +02:00
Joey Fisher a8c4f86b46 fix(agc): limit the depth surface fast proof to plain 2D lookups
Array and layered depth views go back to the full walk, so a lookup that
refreshes array slices is not skipped by the fast proof.
2026-10-11 00:22:51 +02:00
Joey Fisher 2828fdc8c6 perf(agc): prove sampled depth surfaces in the fast resource proof 2026-10-11 00:22:51 +02:00
Abdulrahman Elkordy a3437abd11 fix(agc): require 32-lane subgroups for wave32 mesh programs
The mesh stage was compiled at the driver's default subgroup width, while the translated mesh program lays wave64 lanes out on, and ballots over, a 32-lane host subgroup. Intel's Windows driver (Arrow Lake, 32.0.101.8991) reports subgroupSize 32 but prefers 16 for mesh shaders, and every agc_driver_mesh draw drew no triangle there. The mesh stage now gets VkPipelineShaderStageRequiredSubgroupSizeCreateInfo{32} when the program's hostSubgroupSize is 32 and the device lists the mesh stage in requiredSubgroupSizeStages, as compute pipelines already do.
2026-10-10 20:03:49 +00:00
Dean 9206c3e621
Merge pull request #2791 from alfalfa-star/perf/agc-storage-baseline-settled
perf(agc): take a storage image's generation baseline only when its guest bytes are settled
2026-10-11 08:45:14 +13:00
Dean ca349535f5
Merge pull request #2681 from oneandonlydean/up2/swept-buffer-staging
perf(agc): stage read and written buffer elements a dispatch sweeps
2026-10-11 04:36:15 +13:00
krishnaraya 22cb7094ae fix(agc): sample 5_6_5, 1_5_5_5 and 4_4_4_4 textures in AMD's channel order
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 11:15:42 -04:00
alfalfa-star 75b540c216 perf(agc): take a storage image's generation baseline only when its guest bytes are settled
An upload of a storage image up to 1 MiB reads the surface's guest bytes
into a baseline (#1599), which a later write-back compares against for
blocks the CPU stamped. When a unit shadow, another image's pending
results or a recorded GPU store covers the surface, that read goes
through the flush hook: the shadow is published and the worker waits for
the GPU, although the upload itself runs on the GPU from the import.

The baseline is now taken only when nothing of that kind overlaps the
surface. Otherwise the image has none, and its write-back keeps the CPU's
bytes for stamped blocks, the rule before #1599. TechnicalDebt's entry
names the condition.

agc_storage_baseline_settled creates a storage image over a watched host
import with a recorded store pending over part of it and checks that the
upload did not submit the open batch; without the change the baseline
read syncs on that store. agc_unchanged_cpu_stamps (#1599) still passes.

PPSA14632 (LEGO Horizon Adventures) refreshes such images about 870
times per 10 s from queue 0 dispatches: the hook's recorded-store syncs
go from about 3400 waiting 4.0 s to about 630 waiting 0.3 s per 10 s,
and a direct dispatch's device call from 356 to 107 us.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 17:07:47 +02:00
Dean Galvin 63fb5779b3 perf(agc): resolve a sampled element repeating the one before it to the same texture
A build's sampled image elements often repeat the element just before them
in plan order (the same eight descriptor words). Each still took its own
stage-A record (decode, collect, DCC key read, cache entry) and its own
stage-B lookup.

The lookups run in plan order and nothing runs between two consecutive ones,
so a repeated element's lookup would find the state the previous lookup just
left: the entry it validated or made, current against the same collect. Such
an element now binds the previous element's texture (when the depth-compare
flag matches too, which is part of the cache key), and stage A gives it a
record of the decoded descriptor only. An element repeating an earlier but
not the immediately preceding one still takes its own lookup, as does any
element after a storage image lookup.
2026-10-11 03:35:08 +13:00
Dean Galvin 0209c64245 perf(agc): memoize decoded image descriptors and their texture cache entries
A resource build decodes every image element's eight descriptor words,
describes the surface (a mip layout with a vector of levels) and finds the
sampled texture's cache entry by hashing its key, once in stage A and again
in stage B. Most elements repeat a small set of descriptors from build to
build.

Each worker now keeps a small direct-mapped memo by descriptor words of the
decoded resource, its guest size and view component mapping (pure functions
of the words) and of the cache entry the words last found. The entry is
reused only while the sampled texture cache has erased no entry since it
was found (an erase counter bumped by eraseTexture), so the list iterator is
still valid and still holds the same key; anything else takes the hash
lookup.
2026-10-11 03:35:08 +13:00
TideOPL aa9ee1b0ad fix(agc): give pooled buffers a VkBuffer of exactly the requested size
Buffer and DeviceBuffer created their VkBuffer at the pool's size class, so
a robust read past the requested size stayed in bounds and returned the
bytes an earlier user of the pooled memory left there instead of an
out-of-range result. Each VkBuffer now has the requested size, created with
the pool's usage, over memory of its class (or its slab slot); one taken
from the pool for a different size is recreated over the same memory at
the same offset. agc_buffer_pool follows a pooled buffer by its memory, so
its class and reuse cases hold with the exact-size buffers.
2026-10-10 15:25:21 +01:00
Dean 5edae35361
Merge pull request #2657 from oneandonlydean/up2/address-draw-key
perf(agc): skip the resource-cache key and lookup for address-based draws
2026-10-11 03:15:31 +13:00
Dean db343a934c
Merge pull request #2656 from oneandonlydean/up2/buffer-slabs
perf(agc): sub-allocate small host buffers from shared memory blocks
2026-10-11 02:59:36 +13:00
Dean 8b812318b4
Merge pull request #2683 from oneandonlydean/up2/refresh-proof
perf(agc): keep a storage image's refresh proof while nothing it read moved
2026-10-11 02:37:50 +13:00
Dean 808d8dc43a
Merge pull request #2691 from oneandonlydean/up2/parallel-snapshot-compare
perf(agc): compare large stale draw snapshots on helper threads
2026-10-11 02:35:16 +13:00
Dean 9526f0d739
Merge pull request #2685 from oneandonlydean/up2/stale-snapshot-patch
perf(agc): patch a stale storage snapshot's changed blocks in place
2026-10-11 02:34:59 +13:00