Repository navigation
asahi/compiler: don't let the post-opt NIR capture keep stack options - #1264
Conversation
agx_compile_shader_nir_internal() points nir->options at its stack-local agx3_options for the duration of the compile and restores the caller's options only after the post-optimization passes. The post-agx_optimize_nir capture added for monolithic fragment reuse cloned the shader inside that window, so hk_shader::g17p_mono_postopt_nir kept a pointer into a dead stack frame. Pre-linking then validated and compiled the clone with whatever was left on the stack: debug builds abort in nir_validate (float_mul_add16/32 checks) on a cold shader cache, e.g. the vk_meta copy-buffer-to-image fragment in hk-g16s-layered-depth, and release builds can compile with garbage lowering options. Give the clone the caller's options, which is what the deserialized path and agx_compile_shader_nir_postopt() expect. Fixes: 0d342cb ("asahi/compiler,nir: skip no-op NIR passes and optimize ILP scheduler bitsets") Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
There was a problem hiding this comment.
Verified that nir_shader_clone preserves the input options pointer and that the capture runs before the compiler restores original_options. Resetting the clone pointer to original_options matches the Vulkan deserialize path, which uses the persistent agx_nir_options table. The pointer-identity test directly catches the lifetime bug, and the reported cold-cache control and 339/339 host gate cover the observed regression. Code approved at this commit. Record the applicable landing checks and revert sequence in the merge decision.
|
Exact-head
|
|
This fixes a regression on aurora-wip from #1245: the G17P monolithic epilog's saved shader keeps a dangling options pointer, so hk-g16s-layered-depth aborts on a cold cache (tip a0164c9 onwards: 338/339) and release builds can compile that path with garbage options. Cold-cache rows at this head passed on J316s and J700 (above), and the independent App review approved it, but the ruleset needs an approval from a human reviewer. @DjDeveloperr (your #1245) or @satchlj: could one of you approve 88d306b so it can merge? |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed and verified exact head 88d306bc00e5 on Apple M5 Max (J775c, G17C B1).
Code review:
- Confirmed
agx_compile_shader_nir_internal()setsnir->options = &agx3_options(stack-local, line 19911) and only restoresnir->options = original_optionsat line 20031, so cloning into*post_opt_nir_outat line 20004 left a dangling stack pointer. Resetting(*post_opt_nir_out)->options = original_optionsdirectly afternir_shader_clone()cleanly fixes the use-after-return, andtest_postopt_fs_inline_equivalencedirectly locks down the pointer-identity invariant.
Exact-head 88d306bc00e5 verification on Apple M5 Max (J775c, G17C B1):
- Build (
-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true -Dtools=asahi,drm-shim):MESA_SHADER_CACHE_DISABLE=1 MALLOC_PERTURB_=42 meson test --suite asahi --suite poly342/342 PASS (0fail — clears all 5 cold-cachenir_validatevalidate_float_mul_addaborts seen onaurora-wipa0164c9101c:hk-g17p-bind-tail-state-change,hk-g16g-indirect-multi,hk-g17p-indirect-multi-stream,hk-g15s-indirect-multi,hk-g17p-indirect-multi, plusagx3_pso_compile_fastpathandhk-g16s-layered-depth). - Live Borealis overlay ICD (
MESA_SHADER_CACHE_DISABLE=1):dEQP-VK.api.smoke.*8/8 PASS,dEQP-VK.pipeline.monolithic.depth.format.d16_unorm.*224/471 PASS (247NotSupported,0fail) — 232 PASS / 0 FAIL / 0 GPU faults.
LGTM, approved!
Follow-up to #1245, which merged as a0164c9 with a use-after-scope.
agx_compile_shader_nir_internal()pointsnir->optionsat its stack-localagx3_options(agx_compile.c:19768/19911) and restores the caller's options only at line 20031. The new post-agx_optimize_nircapture (*post_opt_nir_out = nir_shader_clone(NULL, nir), line 20004) clones inside that window. Sohk_shader::g17p_mono_postopt_nir->optionspoints into a dead stack frame, andhk_g17p_inline_epilog_part()/agx_compile_shader_nir_postopt()later read whatever is left there.Seen on the tip:
hk-g16s-layered-depthaborts innir_validate("NIR validation failed after nir_opt_copy_prop in hk_cmd_draw.c:9734",validate_float_mul_add) on the vk_meta copy-buffer-to-image fragment whenever the shader cache is cold. That makes the drm-shim suite flaky: it passes once the cache is warm or the pipeline was cached by an earlier test. Release builds skip validation and compile with garbage lowering options instead.The fix gives the clone the caller's options, which is what the deserialize path and
agx_compile_shader_nir_postopt()already expect.test_postopt_fs_inline_equivalencenow also checks that the capture keeps the input options.Tested:
-Dbuildtype=release -Db_ndebug=false,--suite asahi --suite poly) at this head: 339/339.g17p-vulkan-layered-depth --shim --expect-compressed(ASAHI_SHIM_CHIP=g16s), each run with a fresh empty shader cache: tip a0164c9 aborts 20/20; this branch 0/30; pre-asahi,borealis: speed up cold AGX3/Borealis pipeline compilation #1245 c9ec6b9 0/20.agx3_pso_compile_fastpathwith only the test change: FAIL ("postopt capture kept transient compiler options"); with the fix: PASS.Risk: low. It only changes the options pointer of the in-memory capture. The capture is used only for the 1x non-ALU monolithic epilog path from #1245, and that path now runs with the same options as the deserialized path.