aboutsummaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan/radv_android.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/amd/vulkan/radv_android.c')
-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,