diff options
author | 2023-12-11 23:46:36 +0000 | |
---|---|---|
committer | 2023-12-12 21:27:07 +0000 | |
commit | 0db7a0919f394aeaaa21e1ee8675002763715e7a (patch) | |
tree | 9c5217a811ec20f7f6bc6d81fb37936b4116dbe2 | |
parent | f0ac70772d768e1dc5deb9f370ed4c8bd4555bf0 (diff) |
Add AHardwareBuffer* to VkNativeBufferANDROID
Bug: 275906506
Test: atest CtsDeqpTestCases -- --module-arg 'CtsDeqpTestCases:include-filter:dEQP-VK.wsi.*'
Change-Id: I9c7d28fe3498f77001d8b6512462fa7787305abf
-rw-r--r-- | vulkan/include/vulkan/vk_android_native_buffer.h | 7 | ||||
-rw-r--r-- | vulkan/libvulkan/swapchain.cpp | 12 | ||||
-rw-r--r-- | vulkan/nulldrv/Android.bp | 5 | ||||
-rw-r--r-- | vulkan/nulldrv/null_driver.cpp | 1 | ||||
-rw-r--r-- | vulkan/nulldrv/null_driver_gen.cpp | 2 |
5 files changed, 25 insertions, 2 deletions
diff --git a/vulkan/include/vulkan/vk_android_native_buffer.h b/vulkan/include/vulkan/vk_android_native_buffer.h index 7c8e695d67..3e3f962ded 100644 --- a/vulkan/include/vulkan/vk_android_native_buffer.h +++ b/vulkan/include/vulkan/vk_android_native_buffer.h @@ -63,7 +63,8 @@ extern "C" { /* * NOTE ON VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 11 * - * This version of the extension deprecates the last of grallocusage + * This version of the extension deprecates the last of grallocusage and + * extends VkNativeBufferANDROID to support passing AHardwareBuffer* */ #define VK_ANDROID_NATIVE_BUFFER_SPEC_VERSION 11 #define VK_ANDROID_NATIVE_BUFFER_EXTENSION_NAME "VK_ANDROID_native_buffer" @@ -111,6 +112,9 @@ typedef struct { * usage: gralloc usage requested when the buffer was allocated * usage2: gralloc usage requested when the buffer was allocated * usage3: gralloc usage requested when the buffer was allocated + * ahb: The AHardwareBuffer* from the actual ANativeWindowBuffer. Caller + * maintains ownership of resource. AHardwareBuffer pointer is only valid + * for the duration of the function call */ typedef struct { VkStructureType sType; @@ -121,6 +125,7 @@ typedef struct { int usage; /* DEPRECATED in SPEC_VERSION 6 */ VkNativeBufferUsage2ANDROID usage2; /* DEPRECATED in SPEC_VERSION 9 */ uint64_t usage3; /* ADDED in SPEC_VERSION 9 */ + AHardwareBuffer* ahb; /* ADDED in SPEC_VERSION 11 */ } VkNativeBufferANDROID; /* diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 4f7b0f4c57..0df5e77181 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -1970,6 +1970,8 @@ VkResult CreateSwapchainKHR(VkDevice device, &image_native_buffer.usage2.producer, &image_native_buffer.usage2.consumer); image_native_buffer.usage3 = img.buffer->usage; + image_native_buffer.ahb = + ANativeWindowBuffer_getHardwareBuffer(img.buffer.get()); image_create.pNext = &image_native_buffer; ATRACE_BEGIN("CreateImage"); @@ -2146,7 +2148,12 @@ VkResult AcquireNextImageKHR(VkDevice device, .stride = buffer->stride, .format = buffer->format, .usage = int(buffer->usage), + .usage3 = buffer->usage, + .ahb = ANativeWindowBuffer_getHardwareBuffer(buffer), }; + android_convertGralloc0To1Usage(int(buffer->usage), + &nb.usage2.producer, + &nb.usage2.consumer); VkBindImageMemoryInfo bimi = { .sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO, .pNext = &nb, @@ -2692,7 +2699,12 @@ static void InterceptBindImageMemory2( .stride = buffer->stride, .format = buffer->format, .usage = int(buffer->usage), + .usage3 = buffer->usage, + .ahb = ANativeWindowBuffer_getHardwareBuffer(buffer), }; + android_convertGralloc0To1Usage(int(buffer->usage), + &native_buffer.usage2.producer, + &native_buffer.usage2.consumer); // Reserve enough space to avoid letting re-allocation invalidate the // addresses of the elements inside. out_native_buffers->reserve(bind_info_count); diff --git a/vulkan/nulldrv/Android.bp b/vulkan/nulldrv/Android.bp index a6d540bb93..5112e14dc8 100644 --- a/vulkan/nulldrv/Android.bp +++ b/vulkan/nulldrv/Android.bp @@ -46,5 +46,8 @@ cc_library_shared { "hwvulkan_headers", "vulkan_headers", ], - shared_libs: ["liblog"], + shared_libs: [ + "liblog", + "libnativewindow", + ], } diff --git a/vulkan/nulldrv/null_driver.cpp b/vulkan/nulldrv/null_driver.cpp index 2e87f1718b..973e71c892 100644 --- a/vulkan/nulldrv/null_driver.cpp +++ b/vulkan/nulldrv/null_driver.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <android/hardware_buffer.h> #include <hardware/hwvulkan.h> #include <errno.h> diff --git a/vulkan/nulldrv/null_driver_gen.cpp b/vulkan/nulldrv/null_driver_gen.cpp index 935535f5bf..d34851e536 100644 --- a/vulkan/nulldrv/null_driver_gen.cpp +++ b/vulkan/nulldrv/null_driver_gen.cpp @@ -16,6 +16,8 @@ // WARNING: This file is generated. See ../README.md for instructions. +#include <android/hardware_buffer.h> + #include <algorithm> #include "null_driver_gen.h" |