mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-08 04:10:10 +01:00
panvk: add panvk_android_get_wsi_memory for AHB spec v8+
Android Vulkan loader relies on aliased ANB image support to advertise KHR_swapchain spec v69+. This change adds panvk_android_get_wsi_memory helper based on deep copied (and sanitized) image create info to perform deferred image initialization and ANB memory alloc. Also we switch to use VK_USE_PLATFORM_ANDROID_KHR instead. Acked-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36603>
This commit is contained in:
parent
2f54020f29
commit
8aa2f1a94f
3 changed files with 67 additions and 11 deletions
|
|
@ -306,3 +306,36 @@ panvk_android_create_gralloc_image(VkDevice device,
|
|||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
panvk_android_get_wsi_memory(struct panvk_device *dev,
|
||||
const VkBindImageMemoryInfo *bind_info,
|
||||
VkDeviceMemory *out_mem_handle)
|
||||
{
|
||||
VK_FROM_HANDLE(panvk_image, img, bind_info->image);
|
||||
VkResult result;
|
||||
|
||||
struct panvk_android_deferred_image *deferred =
|
||||
container_of(img, struct panvk_android_deferred_image, base);
|
||||
assert(deferred->create_info && !deferred->initialized);
|
||||
|
||||
const VkNativeBufferANDROID *anb =
|
||||
vk_find_struct_const(bind_info->pNext, NATIVE_BUFFER_ANDROID);
|
||||
|
||||
/* Inject ANB into the deferred pNext chain to leverage the existing common
|
||||
* Android helper vk_android_get_anb_layout, which could be refactored to
|
||||
* take ANB directly instead.
|
||||
*/
|
||||
VkNativeBufferANDROID local_anb = *anb;
|
||||
local_anb.pNext = deferred->create_info->pNext;
|
||||
deferred->create_info->pNext = &local_anb;
|
||||
result = panvk_android_anb_init(dev, deferred->create_info, anb,
|
||||
&dev->vk.alloc, img);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
deferred->initialized = true;
|
||||
*out_mem_handle = img->vk.anb_memory;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@
|
|||
#include "util/detect_os.h"
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
struct panvk_device;
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
|
||||
bool panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo);
|
||||
|
|
@ -19,6 +21,10 @@ VkResult panvk_android_create_gralloc_image(
|
|||
VkDevice device, const VkImageCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *pAllocator, VkImage *pImage);
|
||||
|
||||
VkResult panvk_android_get_wsi_memory(struct panvk_device *dev,
|
||||
const VkBindImageMemoryInfo *bind_info,
|
||||
VkDeviceMemory *out_mem_handle);
|
||||
|
||||
#else /* VK_USE_PLATFORM_ANDROID_KHR */
|
||||
|
||||
static inline bool
|
||||
|
|
@ -36,6 +42,14 @@ panvk_android_create_gralloc_image(VkDevice device,
|
|||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
}
|
||||
|
||||
static inline VkResult
|
||||
panvk_android_get_wsi_memory(struct panvk_device *dev,
|
||||
const VkBindImageMemoryInfo *bind_info,
|
||||
VkDeviceMemory *out_mem_handle)
|
||||
{
|
||||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
||||
}
|
||||
|
||||
#endif /* VK_USE_PLATFORM_ANDROID_KHR */
|
||||
|
||||
#endif /* PANVK_ANDROID_H */
|
||||
|
|
|
|||
|
|
@ -639,27 +639,31 @@ panvk_GetDeviceImageSparseMemoryRequirements(VkDevice device,
|
|||
*pSparseMemoryRequirementCount = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static VkResult
|
||||
panvk_image_bind(struct panvk_device *dev,
|
||||
const VkBindImageMemoryInfo *bind_info) {
|
||||
const VkBindImageMemoryInfo *bind_info)
|
||||
{
|
||||
VK_FROM_HANDLE(panvk_image, image, bind_info->image);
|
||||
VK_FROM_HANDLE(panvk_device_memory, mem, bind_info->memory);
|
||||
uint64_t offset = bind_info->memoryOffset;
|
||||
|
||||
if (!mem) {
|
||||
#if DETECT_OS_ANDROID
|
||||
/* TODO handle VkNativeBufferANDROID when we support ANB */
|
||||
UNREACHABLE("VkBindImageMemoryInfo with no memory");
|
||||
VkDeviceMemory mem_handle;
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
VkResult result =
|
||||
panvk_android_get_wsi_memory(dev, bind_info, &mem_handle);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
#else
|
||||
const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
|
||||
vk_find_struct_const(bind_info->pNext,
|
||||
BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR);
|
||||
assert(swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE);
|
||||
VkDeviceMemory mem_handle = wsi_common_get_memory(
|
||||
swapchain_info->swapchain, swapchain_info->imageIndex);
|
||||
mem_handle = wsi_common_get_memory(swapchain_info->swapchain,
|
||||
swapchain_info->imageIndex);
|
||||
#endif
|
||||
mem = panvk_device_memory_from_handle(mem_handle);
|
||||
offset = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
assert(mem);
|
||||
|
|
@ -677,6 +681,8 @@ panvk_image_bind(struct panvk_device *dev,
|
|||
mem->addr.dev, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VKAPI_ATTR VkResult VKAPI_CALL
|
||||
|
|
@ -684,14 +690,17 @@ panvk_BindImageMemory2(VkDevice device, uint32_t bindInfoCount,
|
|||
const VkBindImageMemoryInfo *pBindInfos)
|
||||
{
|
||||
VK_FROM_HANDLE(panvk_device, dev, device);
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
for (uint32_t i = 0; i < bindInfoCount; i++) {
|
||||
const VkBindMemoryStatus *bind_status =
|
||||
vk_find_struct_const(&pBindInfos[i], BIND_MEMORY_STATUS);
|
||||
panvk_image_bind(dev, &pBindInfos[i]);
|
||||
VkResult bind_result = panvk_image_bind(dev, &pBindInfos[i]);
|
||||
if (bind_status)
|
||||
*bind_status->pResult = VK_SUCCESS;
|
||||
*bind_status->pResult = bind_result;
|
||||
if (bind_result != VK_SUCCESS)
|
||||
result = bind_result;
|
||||
}
|
||||
|
||||
return VK_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue