Skip to content

vk: use VK_EXT_vertex_input_dynamic_state to cut pipeline permutations - #483

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:feat/vk-dyn-vertex-input
Nov 18, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:feat/vk-dyn-vertex-input

Conversation

@Propinbo

@Propinbo Propinbo commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

PipeKey baked all 32 vertex attributes (attr_fmt, attr_off, attr_bind, attr_mask) and 17 stream descriptors (stride, divisor, used_streams) into every VkPipeline. Draws sharing the same shaders, render targets, and blend/raster state still compiled duplicate VkPipeline objects whenever vertex stride or attribute layout differed—driving compile hitches and pushing Mali drivers toward LARECOMP_PIPE_KEEP LRU eviction:

  1. Extension query & safe gating (runtime/nvn/vulkan/vk.h, runtime/nvn/vulkan/device.c):
    • Queries VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME via QUERY_OPTIONAL (widening ext to 48), gates g_vk.dyn_vi on g_vk.eds && have_dyn_vi && vids_have.vertexInputDynamicState && g_vk.props.limits.maxVertexInputBindings > 16 (ZERO_BINDING = 16), logs [vk-cap] dynamic vertex input: on|off, and provides LARECOMP_DYN_VI=0 / LARECOMP_NO_DYN_VI=1 opt-out.
  2. Dynamic vertex input builder & draw state (runtime/nvn/vulkan/dyn_vi.h, runtime/nvn/vulkan/exec.c):
    • When g_vk.dyn_vi is active, build_pipeline() adds VK_DYNAMIC_STATE_VERTEX_INPUT_EXT and sets .pVertexInputState = NULL (guarded under #ifdef __ANDROID__ to match device.c).
    • CMD_BIND_VERTEX_ATTRIB / CMD_BIND_VERTEX_STREAM and st_defaults() bump vi_gen instead of setting pipeline_dirty, leaving vertex layout fields zeroed in PipeKey (last_pipeline reuse and LARECOMP_VK_PIPE_VERIFY stay consistent).
    • draw_() rebuilds cur_vi via vk_build_dyn_vi() only when (vi_gen, pr->vi->attr_mask) changes, emits vkCmdSetVertexInputEXT through SS_VI redundant-state filtering (ss_on == 0 emits every draw), and resolves stream copy bounds from cur_vi.
    • Calls ss_forget() after internal static-VI passes (post_pass, vk_present_draw, renderer_save_texture_tex) so SS_VI is re-bound on subsequent game draws.
  3. Unit test (tools/test_dyn_vertex_input.c):
    • Validates vk_build_dyn_vi() attribute/binding packing, ZERO_BINDING fallback, zero-stride VERTEX rate handling, divisor >= 1 invariant (including !have_divisor clamping), empty inputs, and 32-attribute / 17-binding max capacity.

Verification

Standalone Branch Checks (this commit)

  • Host WASM/Node (NDK 30.0.16248370): test_vulkan_compat.py (16), test_vulkan_startup.py (33), test_shader_cache.py (17) — all passed.
  • Host Linux (cc -Wall -Wextra -Werror -O2 -pthread) & Android ARM64 Bionic (SM-X730): tools/test_dyn_vertex_input.c — passed.
  • Android :app:assembleDebug (JDK 17): BUILD SUCCESSFUL with 0 warnings in modified/added files.
  • Cross-check: merges cleanly (git merge-tree exit 0, zero conflicts) with sibling PRs feat/urgent-shader-builds and feat/shader-meta-cache.

Combined Physical-GPU Measurements (with toggle ablation on unified prototype before splitting)

  • SM-X730 (Mali-G925 MC12 r49p1, hateno-night, cap30, sgsr1 1080p, warm caches, 0 Vulkan errors): Enabling LARECOMP_DYN_VI=1 vs LARECOMP_DYN_VI=0 in steady state reduced live VkPipeline count 1222 -> 802 (-34.4%) at identical 30.00 fps (gpu.p50 27.279 vs 27.323 ms, 0 frames >50 ms).
  • Adreno 830 (Turnip_Gen8_V38_Patched, driver-id 18, 3-pass A/B on a1ef820): Live gpipes dropped 1247 -> 799 (-35.9%) with 0 Vulkan errors (30.17 fps, gpu.p50 24.602 -> 21.918 ms).

Companion Focused PRs

Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 17, 2026
@Propinbo
Propinbo force-pushed the feat/vk-dyn-vertex-input branch from 122ec0c to 3383e1e Compare November 17, 2026 19:47
Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 17, 2026
…rebases, PR mamcjr#485 async slots, Mali perf ABBA & release rollout
@mamcjr

mamcjr commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks, the change looks right (internal binds forget the state, prewarm records carry the flag). The risk is drivers: it turns on wherever the extension is reported, including Qualcomm's own driver and older Mali, which weren't tested, and emulators have blocklisted this extension on some vendor drivers. Please keep it on only where it was tested (Mali r49, Turnip) and off on Qualcomm's driver for now, with an env switch to try it elsewhere. I'll A/B it here on Turnip, looking at the 1% lows, not only fps.

@Propinbo
Propinbo force-pushed the feat/vk-dyn-vertex-input branch from 3383e1e to 8146cfa Compare November 17, 2026 22:57
@Propinbo

Copy link
Copy Markdown
Contributor Author

Rebased onto upstream/main (011e1da → 8146cfa, resolving Pipe.used_s and updating tools/test_pipeline_prewarm.c) and gated default activation strictly to tested drivers:

  1. Driver default policy (runtime/nvn/vulkan/dyn_vi.h, device.c):
    • Enabled by default only on VK_DRIVER_ID_MESA_TURNIP (18) and VK_DRIVER_ID_ARM_PROPRIETARY (9) r49+ (parsed strictly by boundary-delimited r<major>p<patch> in driverInfo).
    • Off by default on Qualcomm proprietary, older Mali (< r49), and all other/unknown drivers ([vk-cap] dynamic vertex input: off (driver excluded by default) / no driver properties).
    • Added env overrides LARECOMP_DYN_VI=1 (opt-in on excluded drivers if extension/feature/maxVertexInputBindings > 16 checks pass) and LARECOMP_DYN_VI=0 / LARECOMP_NO_DYN_VI (opt-out), plus a post-volkLoadDevice() check disabling g_vk.dyn_vi if vkCmdSetVertexInputEXT == NULL.
  2. Verification (SM-X730, Mali-G925-Immortalis MC12 v1.r49p1, 30 fps cap, warm .spv + cold vk_pipelines.bin):
    • Native Bionic regressions on SM-X730: test_dyn_vertex_input PASS, test_pipeline_prewarm (covering Pipe.used_s and dyn_vi = true prewarm save/load/tick + invalidation) PASS.
Mode [vk-cap] Status Logged Compiles Render Wait cam_s low1 low01 p99 gt>100ms (CSV)
Default (Mali r49p1) on (driver default) 1,196 (-23.3%) 4,520 ms 7.9 s 29.63 29.56 33.615 ms 17
Opt-out (LARECOMP_DYN_VI=0) off (LARECOMP_DYN_VI=0) 1,559 5,016 ms 8.4 s 29.51 29.48 33.864 ms 20

Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 17, 2026
@mamcjr

mamcjr commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks, the driver gate is exactly right. You didn't test Turnip, so I'll A/B it here (the 1% lows with LARECOMP_DYN_VI=0 and =1) and merge.

@mamcjr

mamcjr commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks! On the POCO (Turnip) it turns on by default and off with LARECOMP_DYN_VI=0, and renders right. The speed A/B was within noise there (the phone was warm), no regressions. Merging.

@mamcjr
mamcjr merged commit 5c55081 into mamcjr:main Nov 18, 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