diff options
author | Jason Macnak <natsu@google.com> | 2021-02-22 14:57:35 -0800 |
---|---|---|
committer | swiftshader-scoped@luci-project-accounts.iam.gserviceaccount.com <swiftshader-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2021-02-26 17:51:51 +0000 |
commit | d69cfa3a843407aea541b240a1f0c65a9a802430 (patch) | |
tree | c022693ca7b9ca58ffda7f3a78deec205b0ea3ee | |
parent | 349abccec8f7ebd1259de11965d58790a76b0ba4 (diff) | |
download | swiftshader-d69cfa3a843407aea541b240a1f0c65a9a802430.tar.gz |
Update PhysicalDevice::getProperties(<AHB properties>)
... to use AHardwareBuffer Usage Equivalence Table from
the spec.
Bug: b/169439421
Test: launch Cuttlefish with SwANGLE
Test: dEQP-VK.api.external.memory.android_hardware_buffer.*
Change-Id: Iad6bf6424a1139c623b0fc664b949eb40bbb11bb
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/53148
Presubmit-Ready: Jason Macnak <natsu@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Jason Macnak <natsu@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
-rw-r--r-- | src/Vulkan/VkPhysicalDevice.cpp | 39 | ||||
-rw-r--r-- | src/Vulkan/VkPhysicalDevice.hpp | 2 | ||||
-rw-r--r-- | src/Vulkan/libVulkan.cpp | 2 |
3 files changed, 35 insertions, 8 deletions
diff --git a/src/Vulkan/VkPhysicalDevice.cpp b/src/Vulkan/VkPhysicalDevice.cpp index 419e753d3..581157a6d 100644 --- a/src/Vulkan/VkPhysicalDevice.cpp +++ b/src/Vulkan/VkPhysicalDevice.cpp @@ -710,13 +710,40 @@ void PhysicalDevice::getProperties(VkPhysicalDevicePresentationPropertiesANDROID properties->sharedImage = VK_FALSE; } -void PhysicalDevice::getProperties(VkAndroidHardwareBufferUsageANDROID *properties) const +void PhysicalDevice::getProperties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkAndroidHardwareBufferUsageANDROID *ahbProperties) const { - // TODO(b/169439421) - // This AHB could be either a framebuffer, OR a sampled image - // Here we just say it's both - // Need to pass down info on the type of image in question - properties->androidHardwareBufferUsage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE | AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT; + // Maps VkImageUsageFlags to AHB usage flags using this table from the Vulkan spec + // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#memory-external-android-hardware-buffer-usage + + // VK_IMAGE_CREATE_PROTECTED_BIT not currently supported. + ASSERT((pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) == 0); + + // "It must include at least one GPU usage flag (AHARDWAREBUFFER_USAGE_GPU_*), even if none of the corresponding Vulkan usages or flags are requested." + uint64_t ahbUsage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE; + + // Already covered by the default GPU usage flag above. + // + // if ((vkUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) || (vkUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT)) + // { + // ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE; + // } + + if((pImageFormatInfo->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) || (pImageFormatInfo->usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) + { + ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_FRAMEBUFFER; + } + + if(pImageFormatInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) + { + ahbUsage |= AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP; + } + + if(pImageFormatInfo->flags & VK_IMAGE_CREATE_PROTECTED_BIT) + { + ahbUsage |= AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT; + } + + ahbProperties->androidHardwareBufferUsage = ahbUsage; } #endif diff --git a/src/Vulkan/VkPhysicalDevice.hpp b/src/Vulkan/VkPhysicalDevice.hpp index 525f7421a..b3dd2aac5 100644 --- a/src/Vulkan/VkPhysicalDevice.hpp +++ b/src/Vulkan/VkPhysicalDevice.hpp @@ -50,7 +50,7 @@ public: void getProperties(VkSamplerYcbcrConversionImageFormatProperties *properties) const; #ifdef __ANDROID__ void getProperties(VkPhysicalDevicePresentationPropertiesANDROID *properties) const; - void getProperties(VkAndroidHardwareBufferUsageANDROID *properties) const; + void getProperties(const VkPhysicalDeviceImageFormatInfo2 *pImageFormatInfo, VkAndroidHardwareBufferUsageANDROID *properties) const; #endif void getProperties(const VkPhysicalDeviceExternalBufferInfo *pExternalBufferInfo, VkExternalBufferProperties *pExternalBufferProperties) const; void getProperties(const VkPhysicalDeviceExternalFenceInfo *pExternalFenceInfo, VkExternalFenceProperties *pExternalFenceProperties) const; diff --git a/src/Vulkan/libVulkan.cpp b/src/Vulkan/libVulkan.cpp index 33879b3fe..482e178fa 100644 --- a/src/Vulkan/libVulkan.cpp +++ b/src/Vulkan/libVulkan.cpp @@ -3234,7 +3234,7 @@ VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceImageFormatProperties2(VkPhysi case VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_USAGE_ANDROID: { auto properties = reinterpret_cast<VkAndroidHardwareBufferUsageANDROID *>(extensionProperties); - vk::Cast(physicalDevice)->getProperties(properties); + vk::Cast(physicalDevice)->getProperties(pImageFormatInfo, properties); hasAHBUsage = true; } break; |