feat(agc): image-table records that hold a pointer to the T# or split it over two loads #4475
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4475"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-12T12:59:10Z.
What
Two more record layouts for #758's image-table columns, both from Ghost of Yōtei (PPSA26344):
key * stride + addend + offsetof a buffer) and then the T# (or S#) at an immediate offset behind that pointer. The column is planned only when the descriptor is read at an immediate offset from aGetAddressResourcewhose two dwords are consecutive reads of one buffer at the same affine offset. The materializer reads each record's pointer when it builds the table, reads the descriptor behind it, and records one read range per record. Pointer columns take their own path ahead of #757's batched record reader, since a descriptor's address is known only once its record's pointer is read. Compute shader0x8000333c00picks a record per lane in a waterfall loop and samples the image behind the record's pointer.0x8000296000reads T# dwords 0-3 with ans_buffer_load_dwordx16atkey * 0x88and dwords 4-7 with ans_buffer_load_dwordx4at48 + key * 0x88.Folding a second load into the first changes where its offset wraps. At a dynamic offset of
0xfffffff0, a second load at+16wraps to the start of the buffer, but the folded read lands past 4 GiB. So a column folds a load only when its addend is no smaller than dword 0's and its immediate is small. The column records dword 0's addend and the largest extra addend. A record whose offset would carry past 32 bits between the two loads is not read; it becomesOffsetCarrypoison.Tested
Windows 11, RTX 4090.
agc_driver_image_table. Each commit adds an execution test toImageTable.cpp.RunPointerRecordTests(IndirectRecordCode): records hold pointers to three T#s of different classes, in reverse order. It checks the texels per record, one table element per distinct T#, and that changing the T# behind one record's pointer changes what that record samples.RunSplitRecordTests(SplitRecordCode): a 256-bit T# read by ans_buffer_load_dwordx8and ans_buffer_load_dwordx4at+0x20of its record. It checks the texels per record and one table element per distinct T#.agc_shader_bindless:verifyPointerTableOffsetCarry.s_load_dwordx4atkey * 32 + 0xffffff10andkey * 32 + 0xffffff20, with memory mapped on both sides of 4 GiB. Record 7's offset is0xfffffff0, so only its second load wraps.OffsetCarrypoison and is never read, and that records 6 and 8 still resolve to their T#s.maine34c47921(#757 and #758 merged). On Windows (RTX 4090),agc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_reuse,agc_shader_memory,agc_shader_bindlessandagc_driver_graphicspass.GetImageResource dword 0 is not a valid runtime value(chainLoadAddressU32 ← GetAddressResource(ReadConstBuffer …)). With only the first commit, the split test fails with the same error at the record's first load. With both, both pass.ctest, Windows, RTX 4090): of 1198 tests, 1183 pass and 14 hardware- or display-dependent tests skip.check_main_syncfailstest_paths_with_spaces_and_unicode_are_reported_verbatimbecause this machine's console code page printséasé; it does not touch this change.0x8000333c00is planned and dispatched without a refusal, and the title reaches its title scene.agc_shader_replayon this head:0x800027c200and0x8000333c00recompile from their captured requests.0x8000296000prepares with--prepare. Its capture lacks the SRT memory needed for a full recompile. Onmain(2a5eca11c, checked on 10-12) all three failed planning withGetImageResource dword 0 is not a valid runtime value.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (none added).mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T15:10:09Z.
Heads-up before review: this PR now collides architecturally with
main— a plain rebase is not possible, and I want to save whoever attempts one a confusing hour.mainhas evolved a runtime image-metadata mechanism of its own while this PR was in flight (indirectRoot/registrationModules:RuntimeImageDword,RuntimeImageMode,RuntimeImageSwizzle, runtime image counts and state dwords in the binding allocator, plus registration-module plumbing through the serializer and cache key). This PR implements the same goal through a different design — image/sampler tables indexed at runtime offsets (image.table,state.tableAccess,tableSelector).The two designs meet head-on in at least 8 files (
ShaderResources.cpp,ShaderValidation.cpp,DescriptorBindingBuilder.hpp/.cpp,BindingAllocator.cpp,ShaderDiskCache.cpp,SpirvImageEmitter.cpp,SpirvDescriptors.cpp), and both sides changed the serialized artifact structs (CompiledShaderArtifact,ShaderInvocation,RecompileResult,DescriptorBinding— the disk-cache size asserts diverge), so the encoders would need re-deriving for a merged layout even after the semantics are unified.As I see it the options are: port this PR's table concept on top of main's indirect-image scheme, argue for the table design as the replacement (in which case the maintainers should weigh the two first), or narrow the PR to whatever the table design adds that
indirectRootdoesn't cover. Happy to attempt the port onto main's scheme if the table design is what should win — but that's a redesign decision, not a rebase.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-12T16:45:49Z.
@blawesom thanks for the heads-up, that saves a confusing hour.
A data point on whether main's runtime-image path already covers these shaders: I replayed the captured recompile requests for Ghost of Yōtei's three table shaders against current main (
2a5eca11c), offline with agc_shader_replay. All three still fail resource analysis with GetImageResource dword 0 is not a valid runtime value:compute 0x800027c200: the T# comes from a buffer record whose index is itself loaded from another buffer (the title's first large dispatch, ~30 s after launch);
compute 0x8000333c00: the record holds a 64-bit pointer to the T#, picked per lane in a waterfall loop (the first layout this PR adds);
pixel 0x8000296000: the T# is read from a record at key * 0x88 (the second layout this PR adds).
So indirectRoot doesn't plan T#s read from buffer records at runtime offsets yet, and that is what #758 and this PR do.
This PR only adds two record layouts on top of #758 and follows its design, so the design question belongs to #758: @Celegans12 and the maintainers. I'll keep this as a draft and redo the two layouts on top of whichever design #758 ends up with, including a port onto main's scheme if that's the route.
(AI-assisted: written with Claude.)
Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-13T07:10:48Z.
Tested on Linux at
e3080a9060907458b988831d851ca552478966b4using a captured Demon's Souls PPSA01342 descriptor-load pattern: two four-dword scalar address loads, with the second offset equal to the first plus 16.The added positive regression runs through
CompileTableand checks captured descriptor codes and consumed read ranges against the equivalent eight-dword load. With the parent tracker (e8e599b),agc_shader_memory_tests --bindlessfails atGetImageResource dword 0 is not a valid runtime value(LoadAddressU32@pc=0x00000034). With this PR's tracker, the same check passes. Built Release with SPIRV-Tools enabled. This is a focused shader test, not a title or full-suite result.One address-semantics gap from source inspection, not yet a failing title observation: at dynamic offset
0xfffffff0, the second load'sIAdd32(offset, 16)wraps to zero before adding its scalar-load metadata displacement. Folding that into the first load's increasing immediate makesScalarAddressDword(base, 0xfffffff0, 0x50)yieldbase + 0x100000040, while the second load should start atbase + 0x40. Keeping the per-load offset arithmetic would preserve this case.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-13T09:46:31Z.
@Celegans12 I've rebased this onto the reworked #757/#758 (#758 head
6ac700240), so no need to do it for me. The split-load commit applied unchanged. In the pointer-record commit, pointer columns now take their own path ahead of #757's batched record reader, since a descriptor's address is known only once its record's pointer is read; plain and address columns go through the batched reader untouched. New head21fe1d172. On Windows (RTX 4090),agc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_reuse,agc_shader_memory,agc_shader_bindlessandagc_driver_graphicspass. Still a draft until #758 settles.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:56:27Z.
Review: CHANGES_REQUESTED
Thanks for the work here. Not mergeable yet, for these reasons:
6ac700240, but #758 now has heada5c63d5249(restacked on #757e7faf20683); the old base is no longer an ancestor. Merging the two commits of this PR (9d99a1416,21fe1d172) onto the current #758 conflicts incore/shader/recompiler/Optimization/src/ResourceMaterializer.cpp(the pointer-column path ahead of the batched record reader), so it needs a logic-aware restack rather than a mechanical rebase.main, and this PR can only land after both. Please restack onto #758's current head, rerunagc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_reuse,agc_shader_memory,agc_shader_bindlessandagc_driver_graphics, and re-push once the bases are merged (then ontomain).main's own runtime-image mechanism (indirectRoot/registrationModules) applies to the whole stack; please confirm the pointer-record and split-load columns still plan the three Ghost of Yōtei shaders after the rebase.Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-14T15:06:09Z.
@adriadam10 Restacked onto #758
a5c63d524. New heade354f9a61.OffsetCarrypoison. Example: dynamic offset0xfffffff0with the second load at +16, where the guest'sIAdd32wraps to the start of the buffer and the fold would read past 4 GiB.verifyPointerTableOffsetCarry(inagc_shader_memory_tests --bindless) builds such a two-load pointer table, with records on both sides of 4 GiB. It checks that the record at offset0xfffffff0isOffsetCarrypoison and is never read, and that its neighbours still resolve. It fails without the guard.Windows, RTX 4090:
agc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_reuse,agc_shader_memory,agc_shader_bindlessandagc_driver_graphicspass, and the full suite has no failures (1140 pass, 9 skip). Conventions pass.On
indirectRoot: the three Ghost of Yōtei table shaders, replayed offline withagc_shader_replayon this head, still plan. Compute0x800027c200and0x8000333c00recompile from their captured requests. Pixel0x8000296000prepares (its capture lacks the SRT memory needed for a full recompile). Onmain(2a5eca11c, checked on 10-12) all three failed planning withGetImageResource dword 0 is not a valid runtime value.As before, this lands after #757 and #758. I'll restack onto
mainonce they are merged.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by Pipodi on 2026-10-14T16:31:33Z.
Rebased onto
maine34c47921now that #757 and #758 are merged. New head55eefe9c5, with the same two commits; the rebase applied cleanly.On Windows (RTX 4090):
verifyPointerTableOffsetCarry.check_main_sync's unicode-path case, from this machine's console code page.0x800027c200and0x8000333c00recompile, and0x8000296000prepares.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:05:33Z.
Review: APPROVED
Re-checked on the current head: the restack points from the previous review are resolved (#757/#758 merged, clean rebase onto
main). Built and ranagc_shader_memory,agc_driver_image_table,_cache,_cache_boundsand_reuseon the merged tree: all pass. TheOffsetCarrytest fails when the guard inResourceMaterializer.cppis disabled. Merging once the full Build is green.