Skip to content

RedMagic 11 Pro display fixes: IMapper5 gralloc backend and UBWC swapchain buffers - #4

Open
Leb-Sun wants to merge 6 commits into
mainfrom
Redmagic-11-Pro-fixes
Open

RedMagic 11 Pro display fixes: IMapper5 gralloc backend and UBWC swapchain buffers#4
Leb-Sun wants to merge 6 commits into
mainfrom
Redmagic-11-Pro-fixes

Conversation

@Leb-Sun

@Leb-Sun Leb-Sun commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Makes vendor display features that consume the app's swapchain — RedMagic GameSpace upscaling and frame generation — work under Turnip. Both device-confirmed on Adreno 840 / Android 16. Supersedes #2 and #3.

Also drops the -e (eco) variant: its only behavioural change was measured worse and already removed, leaving tunables for a closed question. Variants are now b and p.

Root cause — three chained gaps

1. Turnip never requested UBWC. Android's loader asks the driver, via vkGetPhysicalDeviceImageFormatProperties2 + VkAndroidHardwareBufferUsageANDROID, what usage to allocate swapchain buffers with (frameworks/native/vulkan/libvulkan/swapchain.cpp:1450+ — it returns before the legacy GetSwapchainGrallocUsageX chain, which modern Android never calls). Measured with an app-side probe:

driver androidHardwareBufferUsage
Turnip (stock) 0x200
system Adreno 0x10000200
exported Adreno 842.8 (adrenotools-loaded) 0x10000200

0x10000000 is the QTI vendor bit requesting UBWC. Mesa's vk_image_usage_to_ahb_usage() has no vendor-usage concept — there is an in-tree XXX acknowledging this.

2. QTI's mapper misdescribes the resulting buffer. For 1216x2688 RGBA8888 UBWC it reports fourcc=0, modifier=0 (LINEAR — wrong) and two planes with the metadata plane first: plane[0] offset=86016 stride=4864 (data, 12164) and plane[1] offset=0 stride=128 (metadata, 128672=86016).

3. Mesa rejects that. vk_gralloc_to_drm_explicit_layout() treats any plane n>0 at offset 0 as disjoint and returns VK_ERROR_INVALID_EXTERNAL_HANDLE, so vkCreateSwapchainKHR fails and the screen goes black.

Changes

  • add_aimapper_gralloc.py — IMapper5 gralloc backend reached through android_load_sphal_library() + AIMapper_loadIMapper(). A driver loaded into an app process cannot link libui, so Mesa's existing IMapper backends are gated out and u_gralloc falls back to u_gralloc_fallback.c (no YCbCr, UBWC guessed from a private handle offset). Needs only dlopen/dlsym.
  • add_ubwc_swapchain_usage.py — sets the QTI UBWC usage bit, scoped to the allocation query only. It must not go in vk_image_usage_to_ahb_usage(): that function also answers import validation, and demanding UBWC there rejects every linear buffer (observed: 448 nativeImportAhbToVulkan failed).
  • UBWC detection via StandardMetadataType::COMPRESSION — device-measured, QTI returns name="QTI" value=10 for UBWC and name="android.hardware.graphics.common.Compression" value=0 for linear. Plane-layout signature retained as a fallback for vendors that do not populate it.

Verification

aimapper: UBWC via COMPRESSION metadataWN-ANB-LAYOUT: result=0 modifier=0x500000000000001 planes=1, picture renders, upscaling and frame generation both working.

Symptom ladder along the way: green (no RGBA source at all) → black (source exists, swapchain fails) → working.

Not included

add_anb_gralloc_usage34.py (ANB usage3/4 + spec 10) stays on ubwc-swapchain-usage. It closes a real Mesa gap — Mesa dispatches only v1/v2 while its own header is spec 11 — but the modern loader never calls that chain, so it is unproven here and does not belong on a branch named "fixes".

Note

This exact tree has not been built or run; it is assembled from device-confirmed pieces with diagnostics stripped. This PR is the first build of it.

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.

1 participant