Skip to content

Fix startup crash on Vulkan devices reporting a huge maxUniformBufferRange.#1510

Merged
shlzxjp merged 1 commit into
mainfrom
bugfix/hparty_vulkan_ubo
Jul 23, 2026
Merged

Fix startup crash on Vulkan devices reporting a huge maxUniformBufferRange.#1510
shlzxjp merged 1 commit into
mainfrom
bugfix/hparty_vulkan_ubo

Conversation

@Hparty

@Hparty Hparty commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

On some Vulkan devices (e.g. OPPO X9, Android 16), the app crashes at startup:

VulkanBuffer::Make() vmaCreateBuffer failed: VK_ERROR_OUT_OF_DEVICE_MEMORY
[GlobalCache::findOrCreateUniformBuffer] failed to create initial uniform buffer, request buffer size: 96

GlobalCache::findOrCreateUniformBuffer used std::max(device maxUBOSize, 64KB) as the pool allocation size. Many mobile GPUs report a maxUniformBufferRange of 2GB~4GB (uint32), so tgfx tried to allocate a multi-GB uniform buffer at startup and ran out of device memory. The value was also narrowed to int, which could overflow.

Close #1509

Fix

Decouple the two roles the device limit used to play, matching the behavior verified by Skia's DrawBufferManager:

  • Single request limit: keeps the original std::max(device, 64KB) semantics, used only to validate one request's bind range.
  • Pool allocation size: fixed at MAX_UNIFORM_BUFFER_SIZE (64KB), no longer follows the device limit. The pool grows with additional 64KB buffers on demand as before.
  • Requests larger than the pool block now get a dedicated buffer instead of being rejected.
  • GPULimits::maxUniformBufferBindingSize and ShaderCaps::maxUBOSize are now int64_t so Vulkan's uint32 limit is stored without overflow.

Verification

  • TGFXFullTest_OpenGL: 591/591 passed on macOS.
  • Vulkan configuration compiles (running Vulkan tests requires a device with a Vulkan loader).

…Range by decoupling the uniform pool allocation size from the device limit.
@Hparty
Hparty force-pushed the bugfix/hparty_vulkan_ubo branch from a69a61a to 08ebb80 Compare July 23, 2026 04:17
@shlzxjp
shlzxjp merged commit 4574c08 into main Jul 23, 2026
14 checks passed
@shlzxjp
shlzxjp deleted the bugfix/hparty_vulkan_ubo branch July 23, 2026 04:52
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.

使用vulkan做后端在有些机器上会崩溃

2 participants