Repository navigation
perf(shader): judge first-lane and constant reads by what they read - #6053
Conversation
f8a0809 to
7b47325
Compare
7b47325 to
1d41c15
Compare
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
One case I'd like covered. |
1d41c15 to
e14a4e5
Compare
|
@oneandonlydean Added in e14a4e5, with the branch rebased onto
The second one overflowed the stack, in The fix:
The invariant is now stated in the plan section of AI-assisted: yes |
MayEvaluate took ReadFirstLane and ReadConst as evaluable without looking at their sources, so plans kept conditions behind per-lane values.
MayEvaluate and the evaluator track the first-lane reads they are inside, so a read reached again through a loop-carried phi or a constant slot is not evaluable instead of recursing.
What
Since #5181, a resource plan keeps a control-flow condition only when
Detail::Evaluator::MayEvaluatefinds that the evaluator could compute it. As @AnthonyClemens found on Resident Evil 2 (#5181),MayEvaluatetookReadFirstLaneandReadConstas evaluable without looking at what they read. A condition behind either was kept with everything it depends on, though the evaluator could not compute it.MayEvaluatenow judges both the way the evaluator reads them:ReadFirstLaneis evaluable when its source is, judged under the read's active mask. Inside it, a runtime select on that mask needs only its first arm, which is the arm the evaluator takes there.ReadConstis evaluable when the SRT read its slot names is. A slot that is not an immediate below the number of SRT reads is not evaluable, as in the evaluator.#6095 compiles these walks and treats both opcodes the same way (a first-lane read under its own mask, a constant read through its slot), so the rule matches it too.
The rule is one way only. A value the evaluator can compute is never judged not evaluable, so no condition the walk could use is dropped. A value judged evaluable may still fail at run time (for example a
ReadConstanswered by the clean-memory evaluator, which has no active mask); that costs memory, as before.Tested
Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake iGPU, Mesa 26.2.3 ANV).
verifyMayEvaluate(agc_shader_memory) has eight new cases, each checked against the evaluator itself:MayEvaluateand the evaluator recursed until the stack overflowed on these. Both now track the first-lane reads they are inside and judge such a read not evaluable.ReadFirstLaneandReadConstalso left the list of opcodes the over-constants sweep skips.ctest(1360 tests) on Arc and on lavapipe, rebased ontomain47a266cf9. All pass except two that don't involve this change:application_heap_lazy, on both: a segfault inapplication_heap_tests, which links onlylibc. fix(libc): open closed standard descriptors on /dev/null when libc loads #6107 is about it.agc_driver_sample_multisample_target, on Arc only. It fails the same way onmain: the Arc has no multisampled storage images.agc_shader_memoryalso passes withAPS5_VERIFY_SRT_COMPACT=1. On earlier bases,agc_driver_preparation_scope_settlefailed sometimes on Arc. It is flaky without this change: run alone ten times, it failed 6 times on this branch, 8 on perf(shader): keep only evaluable branch conditions in resource plans #5181's head and 5 onmain19fc5a8ed.Plan sizes, Stray (PPSA02101) and Dreaming Sarah (PPSA02929): I extracted the plans of the 227 distinct shader requests I have dumped from both titles (
ExtractPlan), with and without this commit. They hold the same 36,699 values either way: these plans contain noReadFirstLane, and their 4,594ReadConsts all read slots that can be evaluated. So on these two titles the commit changes nothing. I have no title where the case occurs.@AnthonyClemens measured 5.6 GB down to about 0.43 GB of decoded plans on Resident Evil 2, but with a pass that differs from this one and with both opcodes changed at once. A run of this branch with a warm cache would give the number for this rule, and show how the saving splits between the two opcodes.
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)