Skip to content

vulkan: enable compute dispatch barrier chaining in Android gcopy_mode - #508

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:feat/gcopy-dchain
Nov 20, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:feat/gcopy-dchain

Conversation

@Propinbo

@Propinbo Propinbo commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enables compute dispatch barrier chaining (dchain) in Android gcopy_mode and defers owed post-dispatch barriers (dchain_after) across chains of compute dispatches until the run ends, gfast_prepare() copies, or submission finishes.

Key Changes (runtime/nvn/vulkan/exec.c)

  1. Dispatch Chaining & Deferred dchain_after:
    • Removes the !gcopy_mode restriction so dchain = !gfast_n && vk_cmd() == cb && dchain_ok() works in Android copy mode too.
    • Adds dchain_after tracking: when a storing dispatch (uses_gmem_store or cs_writes_image(), including !gcopy_mode gfast fallbacks when !gfast_handled) is chained or followed by another dispatch / non-GPU op (dchain_keeps()), the vk_full_barrier() is owed (dchain_after = true) rather than emitted eagerly between consecutive dispatches.
    • Flushes any owed dchain_after barrier in:
      • exec_list() before any non-dchain_keeps() command (if ((dchain || dchain_after) && ...)),
      • vk_submit_extra() before command buffer completion,
      • gfast_prepare() before copy_buffer(cb, gmem_buf, gfast_buf, ...),
      • and clears dchain_after in gfast_finish() / gres_get() after their own vk_full_barrier(cb).
  2. Reset Hygiene:
    • Resets dchain, dchain_after, dchain_cb, dchain_env, gwin_mode, and gfast_win across reboots in vk_exec_reset() (and clears gfast_win in gcopy_prepare()).
  3. Tests (tools/test_rt_load_upload.c):
    • Adds Section 8 integration tests covering chained cs_writes_image() + plain dispatches, gcopy_mode storing dispatch chains, dchain_after-only CMD_BARRIER, vk_submit_extra() flush, LARECOMP_VK_DISPATCH_CHAIN=0, plain 0-barrier CMD_BARRIER, !gcopy_mode m==0 fallback, gfast_n > 0 pre-copy barrier ordering, and vk_exec_reset().

Rollback / Zero-Overhead Guarantee

  • LARECOMP_VK_DISPATCH_CHAIN=0 disables dispatch chaining cleanly.
  • Non-gcopy_mode builds and non-compute command streams retain prior dchain behavior (with an added dchain_after reset on reboot).

Isolated On-Device Verification (Exact Commit 7845d58)

Environment: Galaxy Tab S11 (SM-X730), Android 16, Mali-G925-Immortalis MC12 (vendor 0x13b5, device 0xd8300010, driver-id 9, v1.r49p1-03bet0.f8a98b506b89b21c80a508d70abfcb3f), BOTW 1.9.0, upstream base 2c72f20 (v0.4.7-beta), commit 7845d58, USB-powered (plugged: 2, no off-charger power claims made).

1. Official 30 FPS benchmark.c A/B (warmup_s=8, calm_s=3, window_s=10, 301 frames/scene)

Scene Mode FPS 1% low Frame p99 GPU p50 / p95 RT p50 / p95 Headroom p50
zora-plaza Off (LARECOMP_VK_DISPATCH_CHAIN=0) 30.00 29.42 33.95 ms 27.03 / 33.82 ms 18.80 / 21.60 ms 6.31 ms
zora-plaza On (default) 30.00 29.47 33.87 ms 27.31 / 33.74 ms 19.02 / 21.54 ms 6.02 ms
kakariko-day Off (LARECOMP_VK_DISPATCH_CHAIN=0) 30.00 29.35 33.97 ms 27.55 / 32.27 ms 19.60 / 22.70 ms 5.78 ms
kakariko-day On (default) 30.00 29.27 34.01 ms 27.50 / 33.50 ms 20.25 / 23.67 ms 5.84 ms

2. Uncapped 60 FPS Steady-Camera [vk] A/B (LARECOMP_FPS=60, 2s [vk] intervals with 0 skipped, compile 0 during S_WARMUP)

(Note: upstream benchmark.c:810 exits S_WINDOW at non-30 FPS targets, so these are steady [vk] 2s-interval metrics before S_WINDOW exit.)

Scene Mode Samples Median / Mean FPS Worst max ms Mean Dispatches / Chained Chained Ratio
zora-plaza Off (CHAIN=0) 7 43.80 / 43.71 31 ms 4013.9 / 0.0 0.0%
zora-plaza On (default) 6 44.85 / 44.55 31 ms 3978.2 / 1190.3 29.9% (+1.05 fps / +2.4%)
kakariko-day Off (CHAIN=0) 3 37.10 / 37.20 41 ms 2727.7 / 0.0 0.0%
kakariko-day On (default) 7 36.90 / 37.00 32 ms 2780.6 / 1251.1 45.0% (worst max -9 ms, GPU-bound FPS neutral)

Verbatim [vk] sample (zora-plaza):

  • Off: [vk] t=41.1 frame 1488 43.5 fps max 27ms level - (311900 draws, 0 skipped, 16512 passes, 3881 dispatches (0 chained), 728 flushes, wait 33ms, compile 0 (waited 0ms), ...)
  • On: [vk] t=40.9 frame 1520 43.2 fps max 28ms level - (311806 draws, 0 skipped, 16475 passes, 3847 dispatches (1150 chained), 747 flushes, wait 18ms, compile 0 (waited 0ms), ...)

Verbatim [vk] sample (kakariko-day):

  • Off: [vk] t=81.6 frame 2889 37.1 fps max 31ms level - (402215 draws, 0 skipped, 13629 passes, 2717 dispatches (0 chained), 703 flushes, wait 15ms, compile 0 (waited 0ms), ...)
  • On: [vk] t=81.1 frame 2904 36.7 fps max 32ms level - (396108 draws, 0 skipped, 13630 passes, 2628 dispatches (1110 chained), 698 flushes, wait 15ms, compile 0 (waited 0ms), ...)

Visual Verification (zora-plaza, gcopy_mode Dispatch Chaining Active)

zora dchain

Additional Unit & Build Verification

  • Host Python suites (NDK 30): test_vulkan_compat.py (16 PASS), test_vulkan_startup.py (33 PASS), test_shader_cache.py (17 PASS), test_soft_linear.py (23 + 3 + 203 PASS).
  • Android Bionic (SM-X730, tools/test_android_runtime.ps1): 7/7 PASS on 7845d58 (8/8 PASS on consolidated b6ed7e0).
  • Compiler & Gradle: :app:assembleDebug --no-daemon -> BUILD SUCCESSFUL; -U__ANDROID__ compiles with 0 new warnings.

Tested vs Untested GPU Matrix

Target Status Notes
ARM Mali-G925 (SM-X730, r49p1, gcopy_mode) Tested on hardware Exact commit 7845d58: 30 FPS A/B + 60 FPS steady [vk] A/B (29.9%–45.0% chained) + screenshot + Bionic tests
Adreno / Turnip (!gcopy_mode / gmem_buf), Qualcomm stock, Mali < r49, Desktop Untested on physical hardware Guarded by test_rt_load_upload.c mock synchronization validator (0 hazards) & LARECOMP_VK_DISPATCH_CHAIN=0 rollback

Tracks owed post-store compute barriers (dchain_after) across chained dispatches, image-writing shaders, and gcopy_mode storing dispatches so independent dispatches skip redundant vk_full_barrier drains while flushing owed barriers before non-dispatch commands, copy-backs, or vk_submit_extra.
Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 20, 2026
@mamcjr

mamcjr commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thanks! Tested on the POCO in copy mode (LARECOMP_VK_HOST_IMPORT=0, LARECOMP_VK_NO_PLACED=1) and the default path: 422 of 1164 dispatches chained in copy mode (0 with LARECOMP_VK_DISPATCH_CHAIN=0), the same GPU time and frame p99 in all three, no errors. Merging.

@mamcjr
mamcjr merged commit 3d28f80 into mamcjr:main Nov 20, 2026
Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants