Skip to content

Fixes crash of import memory with vkMemoryDedicatedAllocateInfo that have mismatched import handles - #8

Merged
utkarshdalal merged 3 commits into
GameNative:wrapper-25from
leegao:fix-AllocateMemory-import
Jul 25, 2026
Merged

Fixes crash of import memory with vkMemoryDedicatedAllocateInfo that have mismatched import handles#8
utkarshdalal merged 3 commits into
GameNative:wrapper-25from
leegao:fix-AllocateMemory-import

Conversation

@leegao

@leegao leegao commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Commit 1

Currently, some drivers will hard-crash the dispatch->AllocateMemory (on older Mali drivers) if trying to import an image created with VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT into a:

   (VkExportMemoryAllocateInfo) {
      .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
      .pNext = pAllocateInfo->pNext,
      .handleTypes =
         VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID,
   };

This PR introduces handle type tracking and validates the call to dispatch->AllocateMemory in the 3 handle import paths in wrapper_AllocateMemory to ensure that the wrong handle type won't crash the driver.


Commit 2

Fixes the blitting fallback path swapping blue/red on certain game engines (those preferring rgba8 swapchain)

Investigation: leegao/bionic-vulkan-wrapper#157 (comment)

The flow for a blit goes something like this:

GAME - renders to the primary image [r, g, b, a] or [b, g, r, a], physically backed by device local memory (so under TILING_OPTIMAL, configured in either RGBA or BGRA mode)
WSI - copies (byte-for-byte) the primary image to the secondary image, which is hardcoded as AHB_RGBA (since Mali doesn't support AHB_BGRA), but physically contains [b, g, r, a] memory for x11
X11 - imports the AHB_RGBA buffer containing assumed to be [b, g, r, a] data

this fails when the game picks [r, g, b, a] as the swapchain image, as the vkCopyImage will place [r, g, b, a] data instead of the expected [b, g, r, a] data into the AHB_RGBA secondary image (I know, this is confusing), hence swapping the b/r channels.

This commit reverts the part of 2af0e2e that introduced [r, g, b, a] as a valid swapchain format (originally meant as a fast path to avoid emulating bgra8)


Testing: see leegao/bionic-vulkan-wrapper#157 (comment) (still has to be done by thirdparty tester, many thanks to https://github.com/gtaforever00 and https://github.com/Artewar67)

For @utkarshdalal - would appreciate feeding this patch through code-review to double check everything as well

have mismatched import handles

Currently, some drivers will hard-crash the AllocateMemory if trying to
import an image crated with
VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT into AHB
@leegao
leegao force-pushed the fix-AllocateMemory-import branch from c4cbcf7 to c4c42fa Compare July 24, 2026 01:16
@leegao
leegao marked this pull request as ready for review July 24, 2026 01:17
@leegao leegao changed the title Fixes crash while import memory with vkMemoryDedicatedAllocateInfo that have mismatched import handles Fixes crash of import memory with vkMemoryDedicatedAllocateInfo that have mismatched import handles Jul 24, 2026
leegao added 2 commits July 24, 2026 12:35
Reverts part of
GameNative@2af0e2e
that broken blitting for some games

See
leegao/bionic-vulkan-wrapper#157 (comment)

GAME - renders to the primary image [r, g, b, a] or [b, g, r, a],
physically backed by device local memory (so under TILING_OPTIMAL,
configured in either RGBA or BGRA mode)
WSI - copies (byte-for-byte) the primary image to the secondary image,
which is hardcoded as AHB_RGBA (since Mali doesn't support AHB_BGRA),
but physically contains [b, g, r, a] memory for x11
X11 - imports the AHB_RGBA buffer containing assumed to be [b, g, r, a]
data
@leegao

leegao commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

@utkarshdalal see 0bd55cb

the handle_types check is lifted up now, and we do an explicit unlink of the MemoryDedicatedAllocateInfo without an external import handle type

@utkarshdalal
utkarshdalal merged commit b866365 into GameNative:wrapper-25 Jul 25, 2026
1 check passed
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