aboutsummaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan
diff options
context:
space:
mode:
authorBas Nieuwenhuizen <[email protected]>2020-05-25 03:58:16 +0200
committerMarge Bot <[email protected]>2020-05-25 15:34:44 +0000
commitbe784cc77b88fee2aad4b6ee3bb49e44d3bf1639 (patch)
tree502b2c5fb4221d01a830e9a6ae1a9da93ed33dea /src/amd/vulkan
parent9a74746bd1f3bd28d4c4c7cba75e3245e1d25530 (diff)
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: https://gitlab.freedesktop.org/mesa/mesa/-/blob/d555794f3032594dbef3623052103900138d2356/src/amd/vulkan/radv_entrypoints_gen.py#L328 Fixes: d555794f303 "radv: update entrypoints generation from ANV" Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2936 Acked-by: Samuel Pitoiset <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5198>
Diffstat (limited to 'src/amd/vulkan')
-rw-r--r--src/amd/vulkan/radv_android.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/amd/vulkan/radv_android.c b/src/amd/vulkan/radv_android.c
index 875cdb50d08..a9f39ec9e02 100644
--- a/src/amd/vulkan/radv_android.c
+++ b/src/amd/vulkan/radv_android.c
@@ -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,