Repository navigation
vk/textures: parallelize CPU BC1-BC7 and BC1->ASTC decode on BC-less GPUs - #531
Conversation
mamcjr#534, held 2B-2 & 40 FPS validation
mamcjr
left a comment
There was a problem hiding this comment.
Thanks! The pool logic looks right to me: remaining = active-1 matches the workers, the owner drains too, the generation counter prevents stale wakeups, and both callers of bc_upload_blocks are on the render thread. On the POCO (native BC) nothing runs, and no threads start.
Before merging:
plat_render_thread_pin()(android.c) now changes more than BC. It savesg_all_coresand setsg_pinnedwhen nothing pinned first. From then on, every thread that callsplat_thread_unpin()restores that mask: dispatch.c, kernel.c, hle/vi.c and async.c, Adreno included, on low-RAM devices or withLARECOMP_RENDER_BIG=1. On main that call does nothing in that case. It may be the right fix, but it isn't BC-only. Also,pin_to_fastest_cores()still rewritesg_all_coreswithout checkingg_pinned, so if it runs after the render pin another thread can read a half-writtencpu_set_t. Could you guard that write too, or move this part to its own PR?
Smaller ones:
- The 4-thread default doesn't depend on the core count. On a 4+4 phone
vk_bc_select_fast_cpusreturns 0 and the workers run on the little cores too. Maybemin(4, big cores)? bc_decode_rowsreturns silently whenpitch64 > INT_MAX, leaving the staging buffer as garbage. A log once would help.WD_R_BC_DECODEis inserted mid-list in watchdog.h, which renumbers the later stages. Fine unless a tool reads those numbers.
|
Rebased onto
Verified after the final edit on
|
122e11e to
3abb640
Compare
…t on Mali r49+) Conflict in tools/test_android_runtime.ps1 with #531: both test lists kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Merged, thanks! All four points addressed, and nothing changes on Turnip. It's in 0.4.13-beta. |
Problem
On mobile GPUs that lack native BC1–BC7 texture compression (such as Mali),
textures.cdecodes BC textures on the CPU during upload (bcdecfor BC2–BC7/fallback andbc1_to_astcfor BC1→ASTC 4×4). Previously this decoding ran single-threaded on the render thread, causing up to ~1.2 s CPU decode spikes during scene loads and ~50–230 ms hitches when streaming new area/object textures during camera movement.Changes
runtime/nvn/vulkan/bc_parallel.h):VkBcPool) using atomic chunk draining (_Atomic uint64_t next, targetthreads * 16chunks with per-taskmin_chunkfloors of2block-rows forbcdecand256blocks forbc1_to_astc) to avoid tail stalls across heterogeneous big.LITTLE/dynamically-clocked cores.vk_bc_parallel_should_split) leave small textures inline (blocks >= 512 && hb >= 4for BC6H/BC7,blocks >= 2048 && hb >= 4for BC1–BC5,blocks >= 4096for BC1→ASTC) so small uploads incur zero synchronization overhead.init_failed,spawn_failed), generation tracking per worker (start_gen), and clean full-struct reset onvk_bc_pool_destroy.runtime/nvn/vulkan/bc_parallel.h,runtime/platform/android.c):vk-bc, restore the pre-pin process affinity viaplat_thread_unpin()(updatedplat_render_thread_pin()to save pre-ping_all_coresatomically so workers created lazily onrender_mainin low-RAM /RAM saving/LARECOMP_RENDER_BIG=1configs do not inherit a 1–2 core pin), and exclude the slowest core tier only when>= max(3, threads)faster cores remain in the allowed mask.runtime/nvn/vulkan/textures.c,watchdog.h,watchdog.c):WD_R_BC_DECODE:"waiting for parallel BC texture decode").wb * 4 * bppagainstINT_MAXpitch overflow before 64-bit row offsets inbc_decode_rows().bc_cpu_device()is true (!g_vk.phys, missing hardware BC1/BC7, orLARECOMP_NO_BC), logged once at first parallel-eligible decode, with env rollback (LARECOMP_NO_BC_PARALLEL=1for 1T;LARECOMP_BC_THREADS=<1-8>override).tools/test_bc_parallel.c,tools/test_bc_shadow.c,tools/test_android_runtime.ps1):1..8threads, 10× destroy/reuse stress, affinity tier selection, bit-exactness against 1T across all 12 BC formats + BC1→ASTC across odd and power-of-2 sizes, and multi-thread speedups.vk_readback()'s scratch buffer fromvk_transient()'sstagingintools/test_bc_shadow.cto avoid test-harness buffer aliasing on2048x16shadow resolves.Zero-Cost Guarantee & Non-Target GPUs
bc_parallel.h/textures.cparallel decode is guarded under#ifdef __ANDROID__— desktop builds have zero code changes.LARECOMP_NO_BC),b->bc_vfremainsVK_FORMAT_UNDEFINED, so neitherbc_decodenorbc_upload_blocksexecutes, zerovkGetPhysicalDeviceFormatPropertiescalls occur, and zero worker threads are spawned.LARECOMP_NO_BC_PARALLEL=1disables parallel decode cleanly;LARECOMP_BC_THREADS=1..8overrides thread count.Verification (Exact Final Commit
122e11e9fdb5af850fe0b59fce3915bec17acdd7)Environment
SM-X730), SoCMT6991(Dimensity 9400+: 4× A720 + 3× Cortex-X4 + 1× Cortex-X925), Android 16 (API 36)Mali-G925-Immortalis MC12 - v1.r49p1-03bet0.f8a98b506b89b21c80a508d70abfcb3f1.9.0(native), stacked cleanly onv0.4.10-beta(1c02adf9)475714955e2636174e4fd2fcef4bbd0e334abab7f7027a317f20fcc6afb3c84c(0compiler warnings in touched files)Tested vs. Untested Matrix
r49p1,SM-X730)122e11e9)cap30A/B + post-teleport visual checkVK_FORMAT_BC*supported)b->bc_vfguardbc_upload_blocksunreachable withoutLARECOMP_NO_BC; zero threads spawned; not runtime-tested on hardware this run< r49/ Xclipse / 4+4 / 2+6vk_bc_select_fast_cpusunit-tested on4+4,2+6,1+3+4, homogeneous; on-device tested on1+3+4only#ifndef __ANDROID__)-U__ANDROID__)-fsyntax-only -Wall -Wextraclean ontest_bc_parallel.c; desktop builds skip#ifdef __ANDROID__decode pathUnit & Regression Tests (
tools/test_android_runtime.ps1+ NDK Clang)tools/test_android_runtime.ps1onSM-X730: 9/9 Bionic tests passed (test_kernel_affinity,test_bc_shadow,test_buffer_copy,test_rt_load_upload,test_cbwin_snap,test_nvn_lifetime,test_object_cache,test_benchmark_trace,test_bc_parallel),0warnings in modified files:BC7 512x512 (128x128 blocks):1T 1.22 msvs4T 0.97 ms(1.26×)BC7 1024x1024 (256x256 blocks):1T 5.29 msvs4T 3.73 ms(1.42×)BC1->ASTC 1024x1024 (256x256 blocks):1T 18.68 msvs4T 6.04 ms(3.09×)-fsyntax-only -Wall -Wextra(test_bc_parallel.c):0warnings acrossaarch64-linux-android30,armv7a-linux-androideabi30,-U__ANDROID__, and-U__ANDROID__ -U__linux__.In-Game Isolated A/B (
cap30,screen 75% SGSR1,shadows=1,inplace_reads=1, warm cache10401.spv)Both arms started from an identical warm cache snapshot (
SKIN=36.5C,TS=0):1Tbaseline viaLARECOMP_NO_BC_PARALLEL=1):[vk] parallel BC CPU decode: 1 thread (LARECOMP_NO_BC_PARALLEL)(passport.commit = 122e11e9fdb5)4Tdriver default, no BC env vars):[vk] parallel BC CPU decode: 4 threads (driver default)(passport.commit = 122e11e9fdb5)status=okboth arms)1T)4Tdefault)5,031vs5,071frames)bc_decode_ns(ms)9,369.58 ms3,618.61 ms-61.4%,-5.75 s)bc_decode1,244.51 ms397.72 msbc_decode > 50 ms(all / camera)24/614/0plateau(load_s+camera_s)18.3s+8.0s17.3s+7.6s-1.4sload+cambc_mssum (cam max)3,975.81 ms(92.38 ms)1,487.16 ms(19.92 ms)display_fps/1% low/gpu p50/render p5030.02/23.95/27.42/17.5030.00/23.98/27.32/18.20zora-plaza(load_s+camera_s)17.7s+6.2s16.9s+6.1s-0.9sload+cambc_mssum (cam max)2,591.24 ms(102.73 ms)1,068.43 ms(21.17 ms)display_fps/1% low/gpu p50/render p5030.02/23.04/27.41/18.5930.00/26.04/27.50/18.72disp_p99 41.74 -> 33.44 mskakariko-day(load_s+camera_s)17.6s+6.9s16.4s+6.4s-1.7sload+cambc_mssum (cam max)2,801.36 ms(228.15 ms)1,051.15 ms(48.51 ms)display_fps/1% low/gpu p50/render p5030.02/23.97/27.69/20.1230.00/22.19/27.90/20.08Honest note: Once scene textures are resident, steady-state
windowframes perform0.00–0.01 msof CPU BC decoding, so steady-statewindowFPS stays neutral at30.00fps; all decode gains occur during cold boots, scene streaming, teleports, and camera sweeps (4.64×–4.85×lower camera-phase peak decode hitches,2.59×faster overall).Teleport Visual Check & Evidence Branch
[vk] parallel BC CPU decode: 4 threads (driver default)) completed with0errors,0watchdog stalls, and clean BC textures verified visually in pre/post PNG screenshots (pre_tp1.png/post_tp1.png).CODE_REVIEW.md,ab_summary.json,ArmA_1T_report.json,ArmB_4T_default_report.json,pre_tp1.png,post_tp1.png) are archived on orphan branchevidence/pr-bc-parallel-decode-20261121(6df6519).