Repository navigation
fix(agc): keep CPU writes when a pending storage result is stored over untracked memory - #5024
Merged
oneandonlydean merged 1 commit intoOct 13, 2026
Conversation
…r untracked memory On memory outside the write watch a write-back compares guest memory with the bytes saved at the upload and leaves the 64 KiB blocks that differ to the CPU. A store of some of an image's units marked the whole saved copy invalid, and a fill turned into an image clear or an image copy never saved the bytes under it, so the next store had nothing to compare and wrote its layers whole over what the CPU had written since. The saved copy is now valid per tracked unit. A store, a drop or a stale eviction invalidates only its own units, a CPU-path store makes the units it stored valid again, and the write-back compares each run of selected units that still has saved bytes. FillClear and CopyFrom save the bytes of the units they fill when the surface is not watched, as an upload does. Results over a range that left the watch while they were pending still have no saved bytes; storing them now throws instead of overwriting the CPU's writes (technical debt).
9 tasks done
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
This was referenced Oct 13, 2026
This was referenced Oct 13, 2026
Sanjaysrinivas
added a commit
to Sanjaysrinivas/AnyPS5
that referenced
this pull request
Oct 13, 2026
Create uploads before publishing snapshot validity. Keep allocation edits separate from the per-unit validity changes in boykopovar#5024.
11 tasks done
Contributor
|
@oneandonlydean confirmation from GTA V (PPSA04264), the title from #4410's regression report. Windows 11, RTX 4090. On AI-assisted (Claude Code). |
11 tasks done
11 tasks done
10 tasks done
RINNECODER
added a commit
to RINNECODER/AnyPS5
that referenced
this pull request
Oct 14, 2026
* fix(agc): handle the fill kernel that reads its pattern from a buffer The 16-byte fill kernel has a variant that loads its pattern with s_buffer_load_dwordx4 through the V# in s[4:7] instead of taking it from the user SGPRs. A title clears its UI canvas HTILE with it every frame; run as a shader, the depth surface never cleared and every UI draw failed its GEQUAL depth test, leaving the screen black. (cherry picked from commit 3bc3e35) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): sample non-sRGB textures through FORCE_DEGAMMA samplers as sRGB views A sampler with FORCE_DEGAMMA decodes the texels of a non-sRGB 8-bit texture as sRGB. Such a binding was refused; it now samples an sRGB view of the same image. Snapshot images whose format has an sRGB twin (R8, R8G8, RGBA8, BGRA8, ABGR8 packed, BC1/2/3/7 UNORM) are created with MUTABLE_FORMAT, and storage images are already mutable. The view is made on first use for the full, first-layer or base-level range, with sampled usage only and the descriptor's minimum LOD. A format without an sRGB twin is still refused. (cherry picked from commit ff3eae6) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): skip the draws and dispatches of one shader with APS5_SKIP_SHADER APS5_SKIP_SHADER=<code address, hex> drops every draw that runs a program at that address and every dispatch of a compute program at that address, as if the packet had run. Skipping one pass at a time shows which pass first writes a wrong value into an image: One title's green sky light was bisected this way to the copy into its sky cube (boykopovar#4551). (cherry picked from commit 0900586) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): release cached address space on device teardown (cherry picked from commit abc997b) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): give R8 and R8G8 no sRGB twin where the device decodes them in the shader SrgbTwinFormat mapped R8_UNORM and R8G8_UNORM to R8_SRGB and R8G8_SRGB without asking the device. Where 8_SRGB or 8_8_SRGB is decoded in the shader (context.srgbDecodeFormats: the device cannot sample the sRGB format, or APS5_SRGB_SHADER_DECODE=1), the forced view would have been created with a format the device cannot sample. Those two formats now get no twin there, so a FORCE_DEGAMMA sampler on them keeps the refusal. The image is no longer created MUTABLE_FORMAT either. (cherry picked from commit 12d07b8) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): drop the comment in SrgbTwinFormat (cherry picked from commit a141b8e) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * perf(agc): allocate CPU snapshots on demand (cherry picked from commit e2ee943) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): avoid snapshot upload PR conflict (cherry picked from commit 65eb466) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): register snapshot fixture GPU memory (cherry picked from commit a296b9c) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): use storage factory in snapshot test (cherry picked from commit 3f31403) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): avoid storage snapshot overlap Create uploads before publishing snapshot validity. Keep allocation edits separate from the per-unit validity changes in boykopovar#5024. (cherry picked from commit 0612c18) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): skip an indexed draw with no indices or instances (cherry picked from commit 0ba462f) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * test(agc): skip an indexed draw with no indices or instances (cherry picked from commit af19dbf) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * perf(agc): cache a draw key the second time it is seen A draw whose key has no entry captured its stages, built a variant per stage (a copy of every captured region) and inserted a draw entry. A key that never comes back paid for the variants and the entry for nothing, and its entry pushed a live one out of the cache. Draws whose user data changes every frame are such keys. The driver now remembers the keys it has seen once, in a table of four-way buckets holding four times the cache's size in keys. A key gets its entry at its second sight; a key that already has an entry still takes new variants at once. A full bucket replaces its oldest key, so keys that share a bucket do not push each other out until more than four of them come between two sights of one. Test: agc_driver_draw_cache_reuse draws three times. The first two draws find no entry, one entry is inserted, and the third draw hits it. A sighting table of one bucket keeps two keys drawn in turn and replaces its oldest key when full. (cherry picked from commit 0adbdcf) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): decode GS_FAST_LAUNCH geometry with one point per subgroup VGT_SHADER_STAGES_EN.GS_FAST_LAUNCH = 1 (mesh-style NGG, as RADV programs it on gfx10.3) was refused. With a point list and GE_CNTL groups of one point, it launches one subgroup per input point and the first thread reads that point's index in the ES vertex id VGPR, which the mesh prologue already provides. The subgroup's primitive limit comes from GE_NGG_SUBGRP_CNTL.PRIM_AMP_FACTOR, and the GS and ES VGPR counts are not required to be full. Fast launch 2, other group sizes or inputs, and indexed fast-launch draws still throw. (cherry picked from commit 7370aaf) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): start the sample location registers at their clear-state value A draw with PA_SC_AA_CONFIG.MSAA_NUM_SAMPLES > 0 whose context never wrote PA_SC_AA_SAMPLE_LOCS_PIXEL_* (context 0x2fe-0x30d) was rejected with "missing register in context bank at DWORD 0x2fe", because the registers were absent from the initial context (a title stops on it after two frames). The MSAA_ENABLE single-sample path read them the same way. The sixteen registers now start at 0, both initially and after CLEAR_STATE. That is the value in libSceAgc's own register defaults (sceAgcGetRegisterDefaults2, every public table that holds context registers, the tables the initial context already follows for PA_SU_VTX_CNTL and PA_SC_CONSERVATIVE_RASTERIZATION_CNTL), in amdgpu's GFX10 clear-state table (clearstate_gfx10.h, gfx10_SECT_CONTEXT_def_8, loaded by gfx_v10_0_cp_gfx_start before CLEAR_STATE) and the GC 10.3 register reset value (gc_10_3_0_default.h). RADV, radeonsi and PAL always write the locations themselves and do not settle the unwritten value. 0 puts every sample at the pixel center. That is not the standard pattern for any sample count, so such a draw decodes as custom locations at the center, as a single-sample scan into a multisampled target already does. (cherry picked from commit 15955c0) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): make host imports over writable pages on macOS (cherry picked from commit 3960519) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): keep fused geometry programs out of the caller's memory sceAgcFuseShaderHalves copied both halves' code, the fused header and its tables into the caller's memory and registered the program at that address. A title fuses different halves into the same memory a few calls apart, while draws that use the earlier result are still queued. The registry keeps one program per code address, so those draws were compiled from the later program: its code read a user-data word the bound layout does not have, and the device reported "BDA access failed" for the mesh stage. The PS5 5.02 module writes only the back half's register list into that memory (sceAgcGetFusedShaderSize reports eight bytes per register, alignment 4) and leaves the code where the halves are. The fused code, header and tables now live in memory libSceAgc owns, one program per distinct pair of halves, registered once. The caller's memory receives the fused register list and the size query reports that list. A second fusion of the same halves returns the same program; halves whose contents changed get a new one. The driver looked a header up by comparing its fields with the registered header, including the register list's address. A header whose register list is a copy elsewhere with the same contents now matches too, which is what the title passes after a fusion. (cherry picked from commit d6f67d1) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(libSceAgcDriver): skip CMASK decode on single-sample views with viewMip > 0 (cherry picked from commit acbc573) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(libSceAgc): ignore address argument on non-sample-dump events in sceAgcDcbEventWrite (cherry picked from commit fbf619e) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): execute INDEX_ATTRIBUTES_INDIRECT (PM4 0x91) The driver had no handler for the PFP INDEX_ATTRIBUTES_INDIRECT packet, so a submission with it threw "opcode is not known in the reference". The packet now reads the 16-byte record at attribute_base + attribute_index * 16 when it executes and loads INDEX_BASE, INDEX_BUFFER_SIZE and INDEX_TYPE from it as the direct packets do. The packet encoding follows PAL's BuildIndexAttributesIndirect and the record layout PAL's IndexAttribIndirect (gfx9Chip.h, c5e80007). indirect_mode 1, reserved bits and record index types above 3 throw. (cherry picked from commit dd3c13f) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): keep stores after occlusion dumps after them in a queued run A queued store run records each group's plain stores first and its occlusion counter dumps after them. A store started a new group only when it overlapped an earlier dump, so a label the title writes after its dumps was recorded before them. A title that polls that label then reads counters from before the dumps land. Any store after a dump now starts a new group. A title read stale or zero occlusion results every other frame and left visible geometry undrawn on alternate frames. (cherry picked from commit fce8aa8) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * test(agc): run the queued write group tests in ctest (cherry picked from commit 9a1ac6a) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): describe which layers of an array surface a texture view reads (cherry picked from commit 7199916) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): sample a slice-0 array color target as a 2D texture through its image (cherry picked from commit faef399) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * test(agc): flush the slice-0 draw before clearing the cached textures SampleSliceZero cleared the cached textures while its draw's results were still pending, so the storage image was torn down with them, which ClearCachedTextures only expects at device teardown. On some runs the next Run then read the first pass's slice 0 after filling it with the initial value (3 of 20 on an RTX 4070, reported on the PR). It now flushes and waits first, as Run does before its own clear. (cherry picked from commit 7262b10) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * docs(agc): record INDEX_ATTRIBUTES_INDIRECT in TechnicalDebt.md Upstream 23eb459 put its debt note in docs/dev/debt/libSceAgcDriver.md; the fork keeps the AGC driver notes in docs/dev/TechnicalDebt.md, so the note moves there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * test(agc): check the sync 9 shared decode fixes on the Metal path anyps5_metal_render_state_tests builds the State.cpp, QueueState.hpp and Pm4.cpp the Metal backend runs. Sync9SharedDecode checks three of this batch's shared fixes there: the sample location registers start at 0, so a 4x draw that never wrote them decodes as custom locations instead of throwing for a missing register; a single-sample view of mip 1 of a fast-clear target decodes no CMASK, while mip 0 of a mipmapped target is still refused; and INDEX_ATTRIBUTES_INDIRECT loads the index base, size and type from its record and refuses an index type above 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * fix(agc): refuse indexed fast-launch mesh draws on Metal The shared State decode now accepts VGT_SHADER_STAGES_EN.GS_FAST_LAUNCH 1 with one point per subgroup (upstream 7370aaf), and upstream's Vulkan Draw refuses such a draw when it is indexed. The Metal mesh path takes the same decoded state, so it refuses indexed fast-launch draws the same way instead of running them through the indexed mesh prologue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj * feat(agc): sample non-sRGB textures through FORCE_DEGAMMA samplers as sRGB views on Metal Upstream ff3eae6 samples a texture whose format has an sRGB twin through an sRGB view of the same image when a sampler forces sRGB decoding (S# FORCE_DEGAMMA), and refuses only formats without one. The Metal binding refused every non-sRGB format. It now does the same as the Vulkan driver: the bound view (sampled or resident) is re-viewed with the sRGB twin of its pixel format (R8, RG8, RGBA8, BGRA8, BC1, BC2, BC3, BC7), keeping its levels, slices and swizzle; a format without a twin throws "which is not sRGB and has no sRGB view". Test: anyps5_metal_driver_semantics_imagesampleforcedegamma (the upstream execution test run on the Metal driver) fails on the previous commit with "guest format 56, which is not sRGB, ... not implemented" and passes here: 8_8_8_8_UNORM through FORCE_DEGAMMA samples the decoded values of 8_8_8_8_SRGB, point and bilinear, and 32_FLOAT is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj --------- Co-authored-by: marcio-ch <marcio.zacarias@conniehealth.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alex Collini <pipodi93@gmail.com> Co-authored-by: john.maia <johnmaia@gmail.com> Co-authored-by: MarcZX100 <marczxrr@gmail.com> Co-authored-by: Sanjaysrinivas <sanjaysrinivas47@gmail.com> Co-authored-by: mrfelek <17274927+mrfelek@users.noreply.github.com> Co-authored-by: Dean Galvin <dean.galvin@live.com> Co-authored-by: Lexroid <x.to@hotmail.com> Co-authored-by: fdfawef324 <287205748+fdfawef324@users.noreply.github.com> Co-authored-by: Zheorgyan <zheorgyan@gmail.com> Co-authored-by: fma-rc <188743521+fma-rc@users.noreply.github.com> Co-authored-by: pushkarreddyy <212133856+pushkarreddyy@users.noreply.github.com> Co-authored-by: Yossi Yadgar <yadgar360@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A storage image's results stay on the GPU until something reads their memory. If the CPU writes that memory first, the store has to leave the 64 KiB blocks it wrote alone. On write-watched memory the block stamps decide that. On memory outside the watch (direct host imports on Windows, imports on Linux when the driver resolves write protection, any range the tracker does not cover) the store compares guest memory with the bytes saved at the upload. On
mainthree things leave it with nothing to compare, and the layer is then stored whole over the CPU's bytes:originalValid), so every later store of the other units is whole.StorageTexture::FillClear) never saves the bytes under it.StorageTexture::CopyFrom) never saves them either.GTA V (PPSA04264) showed it on Windows, reported on #4410: an image over memory the title reuses as its JobManager pool stays pending, the pool is written, and after
the kernels read
ffffffffbuffer descriptors. #4410 did not introduce this. Results stay pending longer since it went in, so the store now lands after the CPU write more often. The new test fails onmainwith or without it.The change:
layerOriginal). A store, a drop or a stale eviction invalidates only the units it touched. A CPU-path store makes the units it stored valid again and reads guest memory only for the units without saved bytes.writeBackLayerscompares each run of selected units that has saved bytes, instead of the whole stored span or nothing.FillClearandCopyFromsave the bytes of the units they fill when the surface is not watched, as an upload already does.docs/dev/debt/libSceAgcDriver.md.On watched memory nothing is saved or compared, as before; the only additions there are one
GuestMemory::Watchedcall per fill and per copy, and per-unit flags where there was one.Tested
Linux, RTX 4090 (NVIDIA 610.57.04), Release, at cac4e96.
mainis the same tree withTexture.cppandTexture.hppfrommainand the new test kept.New test
agc_driver_store_over_untracked(0.3 s): a surface outside the watch, a CPU write while its result is pending, then a read through the flush hook and a store of everything. Five cases: another block read after the CPU write, another block read before it, a fill of the surface, an image copy into it, and a surface that leaves the watch while its result is pending (that one expects the throw and the CPU's bytes intact). 10 runs each:APS5_WRITE_WATCH_IMPORTS=unwatchmainOn
mainthe read/fill/copy cases lose bytes (32 or all 4096 of the 4096 written in the first, all 4096 in the others), and the surface that left the watch is stored whole. WithAPS5_WRITE_WATCH_IMPORTS=unwatchthe import already unwatches the surface at the upload, before anything is pending, so the last case does not apply there (the test prints that) and the bytes are saved as for any unwatched upload.ctest -R '^agc_' -E 'agc_driver_flat_|agc_driver_scalar_wide_loads|agc_driver_bda_span_reads|agc_driver_pixel_interlock', 441 tests, with this PR: all pass in both modes (agc_driver_stencil_ref_exportskips on this device). No existing test reaches the new throw. The excluded tests hang on this driver onmaintoo.Not tested: Windows (not built here), so the new throw has not been seen there and whether a Windows run reaches it is unknown. No lavapipe, no title. GTA V was not run, so whether its failure is one of these cases is not confirmed. No speed measurement; none is claimed.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)