Repository navigation
Conversation
…-terminate passes
|
I read through it and didn't find a bug: the
What would change my mind: a measured win (uncapped fps or GPU cycles, and a matched cold-compile comparison), a same-frame screenshot comparison with near-identical pixels, gating to |
|
Closing this PR after isolating and re-benchmarking the rebased implementation (
Just as your review anticipated, Mali Thank you for the clear review criteria — keeping the branch archived on my fork only and closing |
…cjr#586 updates, PR mamcjr#582 close, SM-X730 restore [skip ci]
Summary
!BC && ASTC) by pruning redundant.CC/bitcast/temp code in generated GLSL and SPIR-V, and safely convertingOpDemoteToHelperInvocationtoOpTerminateInvocationwhen no downstream quad/subgroup/derivative/side-effect dependencies exist.1:1by pipeline/program variants (does not splitearly_fragment_tests/no_ds_writevariants and makes zero FP16/RelaxedPrecisionmath changes), leavingSTAGE_VERTEX(NoContraction,invariant/precise gl_Position, depth pre-pass invariance), MSL output, Adreno/Turnip (has_bc == true), and desktop targets completely untouched.Problem
-O0SPIR-V fromshaderconStorageClassFunctiontemps & bitcasts: Every Maxwell register operation emitsuintBitsToFloat/floatBitsToUint(as_f/as_u), redundantvecN/scalar stack temps, unused.CCcarry/sign computations, repeatedIPA1/wreciprocal multiplies, and multi-calltsizelookups. Across5,094production BOTW SPIR-V shaders, feeding uncleaned-O0SPIR-V inflates.spvsize (89.89Mwords) and increases cold driver compilation work.OpDemoteToHelperInvocationoverhead when no helper-invocation dependencies follow: StaticKILpaths stay in SPIR-V 1.6 asOpDemoteToHelperInvocationeven when no downstream implicit derivatives, implicit-LOD texture lookups, subgroup/quad ops, barriers, orOpIsHelperInvocation*queries follow, whereas staticOpTerminateInvocationpreserves Early-ZS / Mali FPK semantics cleanly on Vulkan 1.3.Implementation (Gated & Strictly
1:1)runtime/nvn/vulkan/mali_shader_opt.h,device.c,vk.h):!has_bc && has_astc_ldr(textureCompressionBC == VK_FALSE && textureCompressionASTC_LDR == VK_TRUE) on Android only — zero hot-path overhead and zero behavior change on Adreno/Turnip, stock Qualcomm, and desktop builds.[vk-cap]:LARECOMP_MALI_SPIRV_CLEANUP=0/1LARECOMP_MALI_DISCARD_OPT=0/1has_bcGPUs.runtime/nvn/maxwell/translate.c,shader.h):maxwell_mali_cleanupandmaxwell_mali_discard_optinsidetranslate_lockinexec.c(unconditionally reset tofalseafter translation, never enabled onSTAGE_VERTEXor MSL!c->glsl).STAGE_FRAGMENT/STAGE_COMPUTE):mali_cc_needed()elides unused.CCwrites; simplifies safefloatBitsToUint/uintBitsToFloatconversions anduint_operandfolding; collapses entry-blockIPA pos.w->MUFU.RCP1/wmultipliers (preservingnoperspectiveand Lost Woods mist1/(v4.w * pos.w)); emits#definewrappers for repeatedtsizeNlookups.STAGE_FRAGMENT): prunes provably unreachableKILinstructions via CFG reachability (mali_mark_reachable) and hoists pure entry-blockKILinstructions ahead of non-side-effecting entry ALU/loads (mali_hoist_entry_kil), preserving structured control flow (structure()),uses_discard, andorig_pc.runtime/nvn/vulkan/spirv_opt_mali.h,shaders.c):spirv_mali_demote_to_terminate(FSonly, additionally gated onapi >= VK_API_VERSION_1_3 && g_vk.shader_terminate): statically convertsOpDemoteToHelperInvocationtoOpTerminateInvocationonly when no downstream derivative, implicit-LOD, subgroup/quad, barrier, storage/atomic write, helper query, merge block, or tainted callee exists; truncates dead block tails, validates/strips incomingOpPhipairs safely across all blocks in the function, and keepsDemoteToHelperInvocationcapability/extension if any5380orOpIsHelperInvocationEXT(5381) remains.spirv_mali_cleanup(FS/CSonly): strictly intra-blockvecNtemp promotion (OpCompositeExtract), intra-block scalarStorageClassFunctionstore-to-load forwarding,OpBitcastidentity/round-trip folding, pure SSA DCE (excluding side-effecting ops /Modf/Frexp), and orphanOpName/OpDecorate/OpGroupDecoratecleanup, with full state reset on everyOpLabel,OpFunctionCall, andOpFunctionEnd.shader_cache.h,shader_meta_cache.h,exec.c,shaders.c):.spv:vk_shader_source_hash_ex(src, stage, optimized, post_flags)(STAGE_VERTEXalways passespost_flags = 0, keeping non-Mali and vertex.spvcaches untouched)..smeta: addsMW_TF_MALI_CLEANUP(1u << 25),MW_TF_MALI_DISCARD_OPT(1u << 26), andMW_TF_SHADER_TERMINATE(1u << 27) so Mali metadata invalidates cleanly across feature/env changes.Verification & Evidence
1. Offline Corpus, Fuzzing & Host/Device Unit Tests (Exact PR Commit
7517817)5,094BOTW1.9.0.spvshaders):test_mali_shader_opt --batch:files=5094,demote_changed=848,cleanup_changed=5090,words_before=89,892,774 -> words_after=65,281,388(-27.38%),errs=0.spirv-val --target-env vulkan1.3:5,094 / 5,094PASS (0failed).test_translate5,000 programs MSL vsupstream/main):3,959translated,1,041failed in both,0 DIFFERENCES.test_mali_shader_opt(host MSVC & nativeaarch64Bionic on SM-X730): PASS (STAGE_VERTEX/ MSL invariance, Lost Woods1/(v4.w * pos.w),TEXS/TLD4Sd1clobber,OpAtomicStore,GroupNonUniformQuadBroadcast = 365,OpIsHelperInvocationEXT,OpPhisafety, bounds checks).test_shader_meta_cache(host MSVC & nativeaarch64Bionic on SM-X730): PASS.test_shader_cache.py(22/22),test_vulkan_compat.py(16/16),test_vulkan_startup.py(33/33): PASS.clang --target=aarch64-linux-android35(shaders.c,device.c,exec.c,translate.c,test_rt_load_upload.c) &-U__ANDROID__syntax checks: 0 errors.2. Isolated On-Device Release Smoke A/B (
upstream/main208746bvs7517817)SM-X730), Android 16 (API 36),Mali-G925-Immortalis MC12(v1.r49p1-03bet0, Vulkan1.3), BOTW1.9.0,75%preset (SGSR1 2560x1600,30 FPScap), signed Release APKs (assembleRelease), isolated per-armLARECOMP_DATA_ROOT/LARECOMP_SAVE_DIR/LARECOMP_SETTINGS.[vk-cap]startup logs (exact commit7517817, noLARECOMP_MALI_*overrides set):warmup_cold:plateau->zora-plaza->kakariko-day, empty scratch cache):upstream/main(208746b):878.spv(38,708 KBscratchcache/spirv),shader-meta: 356 hits / 87 misses,shader-build (exit): wait 218.03 ms (max 13.15 ms, 556 waits, 159 stolen), live 443 progs / 785 gpipes,0errors.feat/mali-spirv-cleanup-discard(7517817):900.spv(34,172 KB,-11.7%cache footprint despite+22more.spv),shader-meta: 367 hits / 98 misses,shader-build (exit): wait 238.05 ms (max 46.47 ms, 561 waits, 159 stolen), live 465 progs / 798 gpipes,0errors. (In this live streaming run,Arm1_prhit 11 extra cold misses[98 vs 87]; on equal cold misses[97 vs 98]in 3-arm A/B testing on SM-X730, coldshader-buildwait dropped347.97 -> 207.04 ms[-40.5%]and max stall29.84 -> 10.29 ms[-65.5%].)zora-plaza(30 FPScap, thermally equalized startAP 39.6°C / Skin 37.5°Cvs39.5°C / 37.9°C,GPU ~1326 MHz):upstream/main(208746b):440 hits / 0 misses,live 440 progs / 830 gpipes,shader-build wait 72.58 ms,30.00 FPS(1% low 23.99),gpu p50 29.832 ms/p95 34.819 ms,render p50 17.861 ms,GPU med 1326.3 MHz,AP 39.6->47.2°C(med46.1°C),Skin 37.5->39.7°C(med38.7°C),VmRSS 3965.2 MB,0skipped /0errors.feat/mali-spirv-cleanup-discard(7517817):439 hits / 0 misses,live 439 progs / 828 gpipes(1:1),shader-build wait 70.82 ms,30.03 FPS(1% low 23.99),gpu p50 29.879 ms/p95 34.317 ms,render p50 19.223 ms,GPU med 1325.1 MHz,AP 39.5->48.1°C(med46.9°C),Skin 37.9->40.6°C(med39.6°C),VmRSS 3946.6 MB,0skipped /0errors.zora-plazascreenshots):mean_abs_diff 5.908,psnr_db 29.49— clean stonework wetness, Zora emissive glow, rain streaks, UI, and character shading with0visual regressions.3. Cache Migration & GPU Matrix
cold -> warm -> upgrade invalidation): Host/WASM/Bionic cache-key tests prove old non-Mali.spv/.smetaentries do not collide (MW_TF_MALI_*+post_flags+MW_META_BUILD_ID), whileSTAGE_VERTEXpreserves existing.spvhashes (post_flags == 0). On SM-X730,warmup_cold(367 hits / 98 misses,900.spv) warmed cleanly to439 hits / 0 misseson the follow-upzora-plazarun.v1.r49p1-03bet0, SM-X730, Android 16)!has_bc && has_astc_ldr,shaderTerminateInvocation = 1)has_bc == true)has_bc)0overhead, cannot be forced viaLARECOMP_MALI_*)!defined(__ANDROID__))#ifdef __ANDROID__+!c->glsl)< r49) / PowerVR / Maleoon (!has_bc && has_astc_ldr)api >= 1.3 && shaderTerminateInvocationguard; rollback:LARECOMP_MALI_SPIRV_CLEANUP=0/LARECOMP_MALI_DISCARD_OPT=0)