turnip: Add support for GetSwapchainGrallocUsage2ANDROID().

This is lifted straight from anv, which seems like a reasonable way to go.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7015>
This commit is contained in:
Eric Anholt
2020-09-22 11:05:14 -07:00
committed by Marge Bot
parent 5a595cd3af
commit 3a1f22c38b

View File

@@ -24,6 +24,11 @@
#include "tu_private.h" #include "tu_private.h"
#include <hardware/gralloc.h> #include <hardware/gralloc.h>
#if ANDROID_API_LEVEL >= 26
#include <hardware/gralloc1.h>
#endif
#include <hardware/hardware.h> #include <hardware/hardware.h>
#include <hardware/hwvulkan.h> #include <hardware/hwvulkan.h>
@@ -228,19 +233,15 @@ fail_create_image:
return result; return result;
} }
VkResult static VkResult
tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h, format_supported_with_usage(VkDevice device_h, VkFormat format,
VkFormat format, VkImageUsageFlags imageUsage)
VkImageUsageFlags imageUsage,
int *grallocUsage)
{ {
TU_FROM_HANDLE(tu_device, device, device_h); TU_FROM_HANDLE(tu_device, device, device_h);
struct tu_physical_device *phys_dev = device->physical_device; struct tu_physical_device *phys_dev = device->physical_device;
VkPhysicalDevice phys_dev_h = tu_physical_device_to_handle(phys_dev); VkPhysicalDevice phys_dev_h = tu_physical_device_to_handle(phys_dev);
VkResult result; VkResult result;
*grallocUsage = 0;
/* WARNING: Android Nougat's libvulkan.so hardcodes the VkImageUsageFlags /* WARNING: Android Nougat's libvulkan.so hardcodes the VkImageUsageFlags
* returned to applications via * returned to applications via
* VkSurfaceCapabilitiesKHR::supportedUsageFlags. * VkSurfaceCapabilitiesKHR::supportedUsageFlags.
@@ -277,6 +278,13 @@ tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h,
__func__); __func__);
} }
return VK_SUCCESS;
}
static VkResult
setup_gralloc0_usage(struct tu_device *device, VkFormat format,
VkImageUsageFlags imageUsage, int *grallocUsage)
{
if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT | if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT))
*grallocUsage |= GRALLOC_USAGE_HW_RENDER; *grallocUsage |= GRALLOC_USAGE_HW_RENDER;
@@ -315,17 +323,68 @@ tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h,
} }
VkResult VkResult
tu_GetSwapchainGrallocUsage2ANDROID(VkDevice device, tu_GetSwapchainGrallocUsageANDROID(VkDevice device_h,
VkFormat format,
VkImageUsageFlags imageUsage,
int *grallocUsage)
{
TU_FROM_HANDLE(tu_device, device, device_h);
VkResult result;
result = format_supported_with_usage(device_h, format, imageUsage);
if (result != VK_SUCCESS)
return result;
*grallocUsage = 0;
return setup_gralloc0_usage(device, format, imageUsage, grallocUsage);
}
#if ANDROID_API_LEVEL >= 26
VkResult
tu_GetSwapchainGrallocUsage2ANDROID(VkDevice device_h,
VkFormat format, VkFormat format,
VkImageUsageFlags imageUsage, VkImageUsageFlags imageUsage,
VkSwapchainImageUsageFlagsANDROID swapchainImageUsage, VkSwapchainImageUsageFlagsANDROID swapchainImageUsage,
uint64_t *grallocConsumerUsage, uint64_t *grallocConsumerUsage,
uint64_t *grallocProducerUsage) uint64_t *grallocProducerUsage)
{ {
tu_stub(); TU_FROM_HANDLE(tu_device, device, device_h);
VkResult result;
*grallocConsumerUsage = 0;
*grallocProducerUsage = 0;
mesa_logd("%s: format=%d, usage=0x%x", __func__, format, imageUsage);
result = format_supported_with_usage(device_h, format, imageUsage);
if (result != VK_SUCCESS)
return result;
int32_t grallocUsage = 0;
result = setup_gralloc0_usage(device, format, imageUsage, &grallocUsage);
if (result != VK_SUCCESS)
return result;
/* Setup gralloc1 usage flags from gralloc0 flags. */
if (grallocUsage & GRALLOC_USAGE_HW_RENDER) {
*grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET;
}
if (grallocUsage & GRALLOC_USAGE_HW_TEXTURE) {
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
}
if (grallocUsage & (GRALLOC_USAGE_HW_FB |
GRALLOC_USAGE_HW_COMPOSER |
GRALLOC_USAGE_EXTERNAL_DISP)) {
*grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER;
}
return VK_SUCCESS; return VK_SUCCESS;
} }
#endif
VkResult VkResult
tu_AcquireImageANDROID(VkDevice device, tu_AcquireImageANDROID(VkDevice device,