perf(shader): build a shader's front end once on first use #471
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/471"
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 adriadam10 on 2026-10-03T16:45:29Z.
What
On the first use of a shader through the cache the front end (decode, translate, SSA, fold, SRT plan, resource tracking) ran twice:
getSourcebuilt the program to extract the resource plan, andfindOrCompileVariantrebuilt it to compile the first variant. The program could not be reused because the plan pointed into it (descriptor dwords, SRT reads, control-flow conditions, uniform fill),Materializewalks those values on every draw, andcompileVariantrewrites the program (Apply, dead-code elimination invalidates values). SomakeResourcePlankept the whole program alive next to the plan.ExtractPlannow copies the values the plan reaches (through arguments, phis included) intoIrResourcePlan::valueStorage, which existed and was unused, with one placeholder block per phi predecessor in a newblockStorage. A copy keeps opcode, type, id, flags, immediate, register and arguments: what the walk,ResolveInvariantPhiandEquivalentValueread. The plan no longer points into the program.getSourceparks the program it built in the source entry, and the first variant compiled for it takes it instead of running the front end again. The entry drops it after its first variant (compiled or loaded from the disk cache), so it no longer keeps a whole program alive per shader for the life of the cache.Callgrind, one
Recompilewith the cache on (first use), on compute shaders assembled withllvm-mc -mcpu=gfx1030(ALU chains with a branch every 40 instructions, results stored):First use now costs one recompile; copying the plan's values is within noise.
Tested
agc_driver_pixel_helper_lanes, which fails the same way onmainon this machine.compileVariantoutput, temporary logging not included).agc_*tests under AddressSanitizer (-fsanitize=address): no errors from this change.agc_shader_memoryreports a stack-buffer-overflow inGuestMemory::Readonmaintoo (the page read around a stack table inverifyBindlessTable); withreplace_intrin=0it passes on this branch.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)