fix(shader): plan a descriptor merged with unrebuildable values from its one SRT read and fault on a mismatch #22767
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22767"
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 frankea on 2026-11-18T07:58:21Z.
What
A T#, an S#, or the V# of a pointer-record image table column can reach its image instruction as a Phi web. When that web mixed one SRT read with values the resource tracker cannot rebuild, the shader failed to plan and threw
GetImageResource dword 0 is not a valid runtime value. Examples of such values are a load in a linked table-call callee and av_readlanerestore of a VGPR lane spill. This PR plans such a descriptor from its one SRT read and checks, at run time, that the live words match. A lane whose live descriptor is not that read records anInvalidDescriptorfault. The fault reports the mismatch; it does not stop the access (see Limits).GuardedSingleSourcewalks each dword's Phi web and puts each leaf in one of three classes. Immediates, lane-mask and EXEC values (HoldsFoldableValue), and valuesRebuildBlockerrejects are ignored. Every other leaf is a candidate. The descriptor is planned only when each dword has candidates that are all equivalent, and the planned dwords are consecutive words of one SRT read (same pointer, byte offsets first + 4·d). Two distinct SRT reads, no SRT read, or more than 512 leaves still throw as before.The new path is used at two sites. In
TryMakeIndirectColumn, the record V# of a pointer-record column is planned from the SRT read whenMakeRuntimeSourcefails on it. Each live V# word must dominate the image handle. InGetHandle, the same applies to a direct T# or S# that fails validation. A handle whose descriptor web split already failed (SplitFailure) keeps its throw.APS5_STRICT_DESCRIPTOR_WEBS, which already makes the descriptor web throw instead of selecting a descriptor and faulting, turns this path off too, so such a descriptor throws as onmain(itsENVIRONMENT.mdrow says so).After
Collect, every image instruction fed by a guarded descriptor compares each live word with the planned word, usingINotEqual32combined withLogicalOr. It emitsDescriptorFaultunder the instruction's own EXEC, the same mechanism the descriptor web uses for folded arms. The comparison covers all 4 or 8 words. A leaf that differs only in words the access does not use therefore also faults; this is stricter than the access needs. No backend or ABI change is needed (DescriptorFaultandFaultReason::InvalidDescriptorexist). The shader cache key already hashes the recompiler sources.Why compare values and not paths: the ISA defines no callee-saved registers.
s_swappc_b64,s_setpc_b64ands_call_b64only swap or set the PC (RDNA2 ISA, Program Flow Control chapter and the SOP1/SOPK opcode tables). Whether a callee preserves s84–s87 or a lane-spill VGPR is therefore an ABI question that the shader cannot settle.s_load_dword*,s_buffer_load_dword*andv_readlane_b32/v_writelane_b32write their destination regardless of EXEC (Scalar Memory Operations chapter; VOP3 opcodes 0x360/0x361). An image instruction's access is decided by the descriptor words it is given (Vector Memory Operations chapter, image instructions). If the live words equal the planned words, the planned access is the one the console makes, whatever path produced them. If they differ, the lane records the fault, so the mismatch is reported instead of passing silently.Gran Turismo 7 (PPSA01317) compute shader 0x120aed7f00 is the motivating shape, described here without its code. A main-body loop makes one table call (
s_swappc_b64, which the linker resolves to 33 callees). The record V# used by the pointer → pointer → T# chain (#6191) is a loop-carried Phi of the main body's SRT read and callee loads. A T# used by fourimage_stores is a Phi of an SRT read and av_readlanerestore from the lane-spill VGPR. Most callees overwrite that VGPR, which suggests they never run from this call site, but that is an inference. The guards make it a run-time check.A debt entry records that this is not measured on hardware.
Limits
DescriptorFaultonly writes a fault record under the condition; the image instruction after it still runs with the planned words. On a mismatch, animage_storetherefore writes through the planned T# and a sample reads through the planned V# in the same dispatch that records the fault. The host sees the fault only after the dispatch, when the wrong texels are already written. The descriptor web's folded arms onmainbehave the same way. The tests check that the fault is recorded on a mismatch; they do not check the texels of the mismatching case.mainallows. Together with #22359 (APS5_SPLIT_TABLE_CALLS=1), which runs this shader as continued dispatches instead of linking it, the shader's continued parts prepare and run (see Tested).Tested
agc_driver_guarded_descriptor_sourceuses hand-encoded RDNA2 programs and runs each case in wave32 and wave64.InvalidDescriptorat the sample pc.image_storeT# that is Phi(SRT read,v_readlanerestore of a spill VGPR that a third path re-spills with another read).mainrefuses the column and spill programs withGetImageResource dword 0 is not a valid runtime valuein both wave sizes.agc_shader_replay --prepare,ANYPS5_NO_SHADER_CACHE=1).maineb20410673: still refuses at theLoadAddressU32@0x19a0 <- LoadAddressU32@0x198c <- ReadConstBuffer@0xac8chain.[spanned-wave]two-lanes-per-invocation note. About 500 image instructions use the guarded record V# (most of them in linked callees), and the 4image_stores use the guarded T#.mainrefuses at the same chain.mainand this branch on the same machine withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layerandctest -V. The set isagc_driver_guarded_descriptor_source,descriptor_web_faults,image_table,image_table_variants,image_table_packed,nested_image_table,compute_table_calls,compute_nested_table_call,compute_fs_table_calls,bindless_images,buffer_descriptor_runtime,guarded_null_pointer,guarded_direct_root,read_lane,write_lane,window_lane_spill,image_store_sint,agc_read_lane_elimination,agc_goto_junction_descriptor,agc_goto_junction_guards,agc_guarded_memory_loads,agc_shader_memoryandagc_shader_bindless.compute_fs_table_callsskipped.main(new test file copied in): the same, and the new test fails because the column program is refused.agc_driver_image_tableandagc_driver_image_table_packedfail ctest'sVUID-regex on both sides with the same counts (VUID-vkCreateDescriptorSetLayout-support-09582, layouts over MoltenVK'smaxPerSetDescriptors). The new test logs the same pre-existing VUID twice. Per-test VUID counts are otherwise identical, and both logs showInsert instance layer "VK_LAYER_KHRONOS_validation".main(head227933141a, which brings in #7395 and #22359), the same set on the M5 Max: 20 passed andcompute_fs_table_callsskipped;agc_driver_image_tableandagc_driver_image_table_packedagain fail only on the sameVUID-vkCreateDescriptorSetLayout-support-09582lines, and each test's own pass line is printed.agc_driver_guarded_descriptor_sourcepasses and logs its four expectedInvalidDescriptorwrite-back faults.main, with the new test file copied in, passes 22/23 three times; the new test fails because the column program is refused. Each log showsInsert instance layer "VK_LAYER_KHRONOS_validation"19 times, none showswas not found but was requested by env var VK_INSTANCE_LAYERS, and none has aVUID-line.main604828bd44with #7256 merged locally (the title needs it to reach its menu). #7256 conflicts withmainonly inDepthSurface.cpp, and the conflict was resolved keeping both sides. This commit applies cleanly on top. Every run uses the same scripted input: wait for the main menu, then press CROSS, which opens the World Map. After about two minutes idle there, the game shows a photo scene.LoadAddressU32@0x19a0 <- LoadAddressU32@0x198c <- ReadConstBuffer@0xac8.InvalidDescriptorfault and no device loss. The frame counter stops within 20 s of the photo scene appearing (116–126 s after CROSS) and does not move again before the time limit, 785–3,198 s later. A gdb snapshot of one frozen run shows one thread insidenvgpucomp64, called fromvkCreateComputePipelinesinCreateComputePipeline. In the run that prepared the shader without a cached copy, the last line logged before the freeze is the[spanned-wave]note for 0x120aed7f00. That points to this shader's pipeline but does not prove it.d8f0610d43,APS5_SPLIT_TABLE_CALLS=1, 3 runs): the shader takes the continuation path ("continues across dispatches from the loop at pc 0x740, replaying from pc 0xa48, 34 callees, 264 state slots"), then one part is refused 121–129 s after CROSS withGetImageResource dword 4 is not a valid runtime value; the dword is a Phi of SRT reads and a field masked out of the load at pc 0x7dc.APS5_SPLIT_TABLE_CALLS=1, 3 runs): no refusal of 0x120aed7f00. The entry part (180,400 SPIR-V words), the resume part (244,657) and the one callee part the lanes selected (160,163) prepare and run, with noSplitStatefault, noInvalidDescriptorfault and no device loss. The run then stops 120–141 s after CROSS on a different shader, 0x120aec1a00, which #22359 also splits:a thread-dimension dispatch has no ShaderData thread limit; DISPATCH_INDIRECT. That stop is outside this commit; without the split setting, 0x120aec1a00 logs no error.227933141amerged ontomainc75a81520bwith #24083 (layered depth, needed for the menu) and, from run B on, #16935. Path: menu, World Map, garage with an owned car. Every earlier build aborts there when the car model loads, with the same refusal of 0x120aed7f00 at a different chain,0x19c4 <- 0x19a0 <- 0xac8.main33876d3742+ #9020 + #7256; prepared with this PR, 1,942,712 SPIR-V words, wave64, with the[spanned-wave]note.its call table holds 307 distinct targets; at most 64 are linked, the limit of the table-call linker onmain, outside this PR.APS5_SPLIT_TABLE_CALLS=1): the shader is split (12 callees, 260 state slots, parts of 184,519 to 303,709 words), the garage is reached and the car and its interior are drawn; the run stayed up 85 min. The single-car scene ran at 0.6 to 1.6 FPS with a wrong picture, and 323[gpu] loop guardlines name loop exits of 0x120aed7f00 (pcs 0x744 to 0x1360) that ran past 4096 evaluations. Runs A and B cannot log such lines: a linked build has no loop guard unlessAPS5_LOOP_GUARDis set, while a split part gets a 4096-exit guard by default (SplitLoopGuardLimitinSpirvEmitter.cpp, from #22359), and the guard makes an invocation leave its loops. This PR adds no loop and no guest branch; it adds the planned words, the word compare and a conditional fault write per guarded image instruction. The cause of the picture was not separated.InvalidDescriptorand noSplitStateline, no device loss. So the guards were dispatched in the title (linked in A and B, split in C) and did not fire. In run C this is weaker for the dispatches with a loop-guard line: a fault record keeps only the first fault written to it, so a loop-guard trip there could hide a laterInvalidDescriptor.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:17:55Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the source and diff reviewed; hardware and runtime checks were reported by the author and were not run here.
What I ran
Inspected head
68f043a1ac54063d345df370675797fd82dca75eusingrepo_read.pytools. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build/test execution, runtime execution, and physical-console behavior were not verified. The author reports focused Vulkan tests across MoltenVK and RTX 4090, and a GT7 replay; those are not tests run by this reviewer. All changed files listed in the manifest were read:
GuardedDescriptorSource.cpp,ResourceTracker.cpp,ENVIRONMENT.md, andfix-table-record-pointer-image-chain.md. No changed files were excluded.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.