Skip to content

vk: handle UNIFORM_BUFFER_DYNAMIC in descriptor_plan - #537

Merged
mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:fix/vk-descriptor-plan-dynamic-ubo
Nov 24, 2026
Merged

mamcjr merged 1 commit into
mamcjr:mainfrom
Propinbo:fix/vk-descriptor-plan-dynamic-ubo

Conversation

@Propinbo

Copy link
Copy Markdown
Contributor

Summary

Fixes descriptor_plan() in runtime/nvn/vulkan/exec.c (and aligns tools/test_descriptor_plan.py) so LARECOMP_VK_DESCRIPTOR_PLAN=1 handles VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC bindings identically to stage_set() instead of dropping them and crashing in the driver.

  • Default behavior unchanged: LARECOMP_VK_DESCRIPTOR_PLAN remains off (0) by default — zero hot-path overhead and zero behavior change on any GPU unless opted in.
  • Strictly single-concern: Only fixes descriptor_plan() parity and updates tools/test_descriptor_plan.py (which also missed #define CBPATCH_BUFFER_INDEX 23 and VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC).

Root Cause

In compile_program_from_spirv() (runtime/nvn/vulkan/exec.c), UBO bindings (1..16, then 0, 18, 19, 20, 23) are promoted from VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER to VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC up to maxDescriptorSetUniformBuffersDynamic before make_layout() calls descriptor_plan().

stage_set() accepts both descriptor types via is_ubo(b->type), but descriptor_plan() checked only b->type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER in both its regular (binding < 17) and deferred (18, 19, GMAP_BUFFER_INDEX, CBPATCH_BUFFER_INDEX) branches — silently omitting every promoted dynamic UBO descriptor write when LARECOMP_VK_DESCRIPTOR_PLAN=1 was set.

Additionally, tools/test_descriptor_plan.py lacked #define CBPATCH_BUFFER_INDEX 23 and VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC in its mock enum, boundary table, and reference loops.

Changes

  • runtime/nvn/vulkan/exec.c (#ifdef __ANDROID__ descriptor_plan()): match both VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER and VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC in the regular and deferred branches.
  • tools/test_descriptor_plan.py: add #define CBPATCH_BUFFER_INDEX 23, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC (6 descriptor types, boundary[] expanded to 12 entries including 22 and 23), and dynamic UBO coverage in both legacy reference loops.

Verification

Host & Bionic (c27c1b7de86f)

  • tools/test_descriptor_plan.py (NDK 30.0.16248370 wasm32 + Node): 31040 descriptor-plan equivalence cases passed.
  • tools/test_soft_linear.py (NDK 30.0.16248370): 23 C checks + 3 GLSL->SPIR-V checks + 203 1/256 bilinear math checks passed.
  • tools/test_vulkan_compat.py (16), tools/test_vulkan_startup.py (33), tools/test_gpu_timing_trace.py (8), tools/test_pipeline_cache_save.py, tools/test_workspace160_guard.py, tools/test_command_snapshot.py: all passed.
  • tools/test_android_runtime.ps1 on Galaxy Tab S11 (SM-X730): 8/8 Bionic tests passed.

Physical Device (SM-X730, Mali-G925-Immortalis MC12 r49p1, Android 16 API 36, BOTW 1.9.0)

Tested in isolated scratch (output=screen, resolution=1x, upscaler=sgsr1, shadows=1, frame_rate=30) on exact commit c27c1b7de86f:

  • Before (v0.4.10-beta 1c02adf9, LARECOMP_VK_DESCRIPTOR_PLAN=1): black screen on plateau, 2455 GROUP_ERROR_FATAL errors, SIGSEGV in libGLES_mali.so (0 benchmark results).
  • After (c27c1b7de86f, LARECOMP_VK_DESCRIPTOR_PLAN=1): plateau 30.00 fps (1% low 29.48 fps, render_thread_ms p50 17.74) -> clean reboot (432 progs / 865 pipelines / 15 compute freed, 0 kept) -> zora-plaza 30.00 fps (1% low 29.53 fps, render_thread_ms p50 18.69), 0 errors.
  • Default (c27c1b7de86f, LARECOMP_VK_DESCRIPTOR_PLAN unset): plateau 30.00 fps (1% low 29.45 fps, 0 errors), behavior unchanged.
Before (v0.4.10-beta, PLAN=1) After (plateau, PLAN=1) After (zora-plaza, PLAN=1)
stock black screen fixed plateau fixed zora-plaza

GPU Coverage Matrix

GPU / Platform Status Notes
ARM Mali-G925-Immortalis MC12 (r49p1, SM-X730, Android 16) Tested Fixed PLAN=1 crash/black screen; 0 errors across scenes + reboot; default off unchanged
Host wasm32 + Node (31,040 equivalence cases) Tested Exact equivalence vs legacy stage_set() scan
Adreno (Turnip / Qualcomm), older Mali, Xclipse, PowerVR Untested on hardware No behavior change (flag remains off by default unless LARECOMP_VK_DESCRIPTOR_PLAN=1)
Desktop (#ifndef __ANDROID__) Untested (guarded out) descriptor_plan() is compiled only under #ifdef __ANDROID__

Propinbo added a commit to Propinbo/BOTWRecompAndroid that referenced this pull request Nov 21, 2026
@mamcjr
mamcjr merged commit 371ad00 into mamcjr:main Nov 24, 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