radv: Implement vkGetSwapchainGrallocUsage2ANDROID.

This was implemented in version 6 of the VK_ANDROID_native_buffer
extension and we only implement version 5. However, the Android
Vulkan loader only checks whether vkGetInstanceProcAddr for the
function is not NULL.

This all went wrong when we switched to the layer code from ANV.
Because the function may now be different per device, it adds fallback
functions that dispatch to the dispatch table. So if we didn't implement
the function we still returned a pointer to the dispatch function,
which made the Android Vulkan loader believe it was supported.

Dispatch functions:
d555794f30/src/amd/vulkan/radv_entrypoints_gen.py (L328)

Fixes: d555794f30 "radv: update entrypoints generation from ANV"
Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2936
Acked-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5198>
This commit is contained in:
Bas Nieuwenhuizen 2020-05-25 03:58:16 +02:00 committed by Marge Bot
parent 9a74746bd1
commit be784cc77b
1 changed files with 89 additions and 0 deletions

View File

@ -29,6 +29,10 @@
#include <vulkan/vk_android_native_buffer.h>
#include <vulkan/vk_icd.h>
#include <libsync.h>
#if ANDROID_API_LEVEL >= 26
#include <hardware/gralloc1.h>
#endif
#endif
#include "radv_private.h"
@ -289,6 +293,91 @@ VkResult radv_GetSwapchainGrallocUsageANDROID(
return VK_SUCCESS;
}
VkResult radv_GetSwapchainGrallocUsage2ANDROID(
VkDevice device_h,
VkFormat format,
VkImageUsageFlags imageUsage,
VkSwapchainImageUsageFlagsANDROID swapchainImageUsage,
uint64_t* grallocConsumerUsage,
uint64_t* grallocProducerUsage)
{
/* Before level 26 (Android 8.0/Oreo) the loader uses
* vkGetSwapchainGrallocUsageANDROID. */
#if ANDROID_API_LEVEL >= 26
RADV_FROM_HANDLE(radv_device, device, device_h);
struct radv_physical_device *phys_dev = device->physical_device;
VkPhysicalDevice phys_dev_h = radv_physical_device_to_handle(phys_dev);
VkResult result;
*grallocConsumerUsage = 0;
*grallocProducerUsage = 0;
if (swapchainImageUsage & VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID)
return vk_errorf(device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
"The Vulkan loader tried to query shared presentable image support");
const VkPhysicalDeviceImageFormatInfo2 image_format_info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
.format = format,
.type = VK_IMAGE_TYPE_2D,
.tiling = VK_IMAGE_TILING_OPTIMAL,
.usage = imageUsage,
};
VkImageFormatProperties2 image_format_props = {
.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2,
};
/* Check that requested format and usage are supported. */
result = radv_GetPhysicalDeviceImageFormatProperties2(phys_dev_h,
&image_format_info, &image_format_props);
if (result != VK_SUCCESS) {
return vk_errorf(device->instance, result,
"radv_GetPhysicalDeviceImageFormatProperties2 failed "
"inside %s", __func__);
}
if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
*grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET;
}
if (unmask32(&imageUsage, VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT |
VK_IMAGE_USAGE_STORAGE_BIT |
VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) {
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
}
if (imageUsage != 0) {
return vk_errorf(device->instance, VK_ERROR_FORMAT_NOT_SUPPORTED,
"unsupported VkImageUsageFlags(0x%x) for gralloc "
"swapchain", imageUsage);
}
/*
* FINISHME: Advertise all display-supported formats. Mostly
* DRM_FORMAT_ARGB2101010 and DRM_FORMAT_ABGR2101010, but need to check
* what we need for 30-bit colors.
*/
if (format == VK_FORMAT_B8G8R8A8_UNORM ||
format == VK_FORMAT_B5G6R5_UNORM_PACK16) {
*grallocProducerUsage |= GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET;
*grallocConsumerUsage |= GRALLOC1_CONSUMER_USAGE_HWCOMPOSER;
}
if (!*grallocProducerUsage && !*grallocConsumerUsage)
return VK_ERROR_FORMAT_NOT_SUPPORTED;
return VK_SUCCESS;
#else
*grallocConsumerUsage = 0;
*grallocProducerUsage = 0;
return VK_ERROR_FORMAT_NOT_SUPPORTED;
#endif
}
VkResult
radv_AcquireImageANDROID(
VkDevice device,