mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 20:08:06 +02: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;
|
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 "util/detect_os.h"
|
||||||
#include "vulkan/vulkan.h"
|
#include "vulkan/vulkan.h"
|
||||||
|
|
||||||
|
struct panvk_device;
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
|
||||||
bool panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo);
|
bool panvk_android_is_gralloc_image(const VkImageCreateInfo *pCreateInfo);
|
||||||
|
|
@ -19,6 +21,10 @@ VkResult panvk_android_create_gralloc_image(
|
||||||
VkDevice device, const VkImageCreateInfo *pCreateInfo,
|
VkDevice device, const VkImageCreateInfo *pCreateInfo,
|
||||||
const VkAllocationCallbacks *pAllocator, VkImage *pImage);
|
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 */
|
#else /* VK_USE_PLATFORM_ANDROID_KHR */
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
|
|
@ -36,6 +42,14 @@ panvk_android_create_gralloc_image(VkDevice device,
|
||||||
return VK_ERROR_FEATURE_NOT_PRESENT;
|
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 /* VK_USE_PLATFORM_ANDROID_KHR */
|
||||||
|
|
||||||
#endif /* PANVK_ANDROID_H */
|
#endif /* PANVK_ANDROID_H */
|
||||||
|
|
|
||||||
|
|
@ -639,27 +639,31 @@ panvk_GetDeviceImageSparseMemoryRequirements(VkDevice device,
|
||||||
*pSparseMemoryRequirementCount = 0;
|
*pSparseMemoryRequirementCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static VkResult
|
||||||
panvk_image_bind(struct panvk_device *dev,
|
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_image, image, bind_info->image);
|
||||||
VK_FROM_HANDLE(panvk_device_memory, mem, bind_info->memory);
|
VK_FROM_HANDLE(panvk_device_memory, mem, bind_info->memory);
|
||||||
uint64_t offset = bind_info->memoryOffset;
|
uint64_t offset = bind_info->memoryOffset;
|
||||||
|
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
#if DETECT_OS_ANDROID
|
VkDeviceMemory mem_handle;
|
||||||
/* TODO handle VkNativeBufferANDROID when we support ANB */
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
UNREACHABLE("VkBindImageMemoryInfo with no memory");
|
VkResult result =
|
||||||
|
panvk_android_get_wsi_memory(dev, bind_info, &mem_handle);
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
return result;
|
||||||
#else
|
#else
|
||||||
const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
|
const VkBindImageMemorySwapchainInfoKHR *swapchain_info =
|
||||||
vk_find_struct_const(bind_info->pNext,
|
vk_find_struct_const(bind_info->pNext,
|
||||||
BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR);
|
BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR);
|
||||||
assert(swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE);
|
assert(swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE);
|
||||||
VkDeviceMemory mem_handle = wsi_common_get_memory(
|
mem_handle = wsi_common_get_memory(swapchain_info->swapchain,
|
||||||
swapchain_info->swapchain, swapchain_info->imageIndex);
|
swapchain_info->imageIndex);
|
||||||
|
#endif
|
||||||
mem = panvk_device_memory_from_handle(mem_handle);
|
mem = panvk_device_memory_from_handle(mem_handle);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(mem);
|
assert(mem);
|
||||||
|
|
@ -677,6 +681,8 @@ panvk_image_bind(struct panvk_device *dev,
|
||||||
mem->addr.dev, offset);
|
mem->addr.dev, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
VKAPI_ATTR VkResult VKAPI_CALL
|
VKAPI_ATTR VkResult VKAPI_CALL
|
||||||
|
|
@ -684,14 +690,17 @@ panvk_BindImageMemory2(VkDevice device, uint32_t bindInfoCount,
|
||||||
const VkBindImageMemoryInfo *pBindInfos)
|
const VkBindImageMemoryInfo *pBindInfos)
|
||||||
{
|
{
|
||||||
VK_FROM_HANDLE(panvk_device, dev, device);
|
VK_FROM_HANDLE(panvk_device, dev, device);
|
||||||
|
VkResult result = VK_SUCCESS;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < bindInfoCount; i++) {
|
for (uint32_t i = 0; i < bindInfoCount; i++) {
|
||||||
const VkBindMemoryStatus *bind_status =
|
const VkBindMemoryStatus *bind_status =
|
||||||
vk_find_struct_const(&pBindInfos[i], BIND_MEMORY_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)
|
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