Loading vulkan/libvulkan/code-generator.tmpl +8 −0 Original line number Original line Diff line number Diff line Loading @@ -703,6 +703,7 @@ VK_KHR_get_surface_capabilities2 {{Macro "driver.InterceptedExtensions"}} {{Macro "driver.InterceptedExtensions"}} VK_KHR_get_physical_device_properties2 VK_KHR_get_physical_device_properties2 VK_ANDROID_external_memory_android_hardware_buffer VK_ANDROID_external_memory_android_hardware_buffer VK_KHR_bind_memory2 {{end}} {{end}} Loading Loading @@ -750,6 +751,9 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetInstanceProcAddr"}}true {{else if eq $.Name "vkGetInstanceProcAddr"}}true {{else if eq $.Name "vkGetDeviceProcAddr"}}true {{else if eq $.Name "vkGetDeviceProcAddr"}}true {{/* VK_KHR_swapchain v69 requirement */}} {{else if eq $.Name "vkBindImageMemory2"}}true {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{end}} {{$ext := GetAnnotation $ "extension"}} {{$ext := GetAnnotation $ "extension"}} Loading Loading @@ -985,6 +989,10 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true {{/* VK_KHR_swapchain v69 requirement */}} {{else if eq $.Name "vkBindImageMemory2"}}true {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{end}} {{$ext := GetAnnotation $ "extension"}} {{$ext := GetAnnotation $ "extension"}} Loading vulkan/libvulkan/driver.cpp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -537,6 +537,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // Extensions we don't need to do anything about at this level // Extensions we don't need to do anything about at this level break; break; case ProcHook::KHR_bind_memory2: case ProcHook::KHR_incremental_present: case ProcHook::KHR_incremental_present: case ProcHook::KHR_shared_presentable_image: case ProcHook::KHR_shared_presentable_image: case ProcHook::KHR_swapchain: case ProcHook::KHR_swapchain: Loading Loading @@ -577,6 +578,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // return now as these extensions do not require HAL support // return now as these extensions do not require HAL support return; return; case ProcHook::EXT_hdr_metadata: case ProcHook::EXT_hdr_metadata: case ProcHook::KHR_bind_memory2: hook_extensions_.set(ext_bit); hook_extensions_.set(ext_bit); break; break; case ProcHook::ANDROID_external_memory_android_hardware_buffer: case ProcHook::ANDROID_external_memory_android_hardware_buffer: Loading vulkan/libvulkan/driver_gen.cpp +26 −0 Original line number Original line Diff line number Diff line Loading @@ -137,6 +137,15 @@ VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR } } } } VKAPI_ATTR VkResult checkedBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfoKHR* pBindInfos) { if (GetData(device).hook_extensions[ProcHook::KHR_bind_memory2]) { return BindImageMemory2KHR(device, bindInfoCount, pBindInfos); } else { Logger(device).Err(device, "VK_KHR_bind_memory2 not enabled. vkBindImageMemory2KHR not executed."); return VK_SUCCESS; } } // clang-format on // clang-format on const ProcHook g_proc_hooks[] = { const ProcHook g_proc_hooks[] = { Loading Loading @@ -169,6 +178,20 @@ const ProcHook g_proc_hooks[] = { reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers), reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers), nullptr, nullptr, }, }, { "vkBindImageMemory2", ProcHook::DEVICE, ProcHook::EXTENSION_CORE, reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2), nullptr, }, { "vkBindImageMemory2KHR", ProcHook::DEVICE, ProcHook::KHR_bind_memory2, reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2KHR), reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2KHR), }, { { "vkCreateAndroidSurfaceKHR", "vkCreateAndroidSurfaceKHR", ProcHook::INSTANCE, ProcHook::INSTANCE, Loading Loading @@ -458,6 +481,7 @@ ProcHook::Extension GetProcHookExtension(const char* name) { if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2; if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2; // clang-format on // clang-format on return ProcHook::EXTENSION_UNKNOWN; return ProcHook::EXTENSION_UNKNOWN; } } Loading Loading @@ -517,11 +541,13 @@ bool InitDriverTable(VkDevice dev, INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, AllocateCommandBuffers); INIT_PROC(true, dev, AllocateCommandBuffers); INIT_PROC(false, dev, BindImageMemory2); INIT_PROC(false, dev, GetDeviceQueue2); INIT_PROC(false, dev, GetDeviceQueue2); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR); // clang-format on // clang-format on return success; return success; Loading vulkan/libvulkan/driver_gen.h +3 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ struct ProcHook { KHR_get_surface_capabilities2, KHR_get_surface_capabilities2, KHR_get_physical_device_properties2, KHR_get_physical_device_properties2, ANDROID_external_memory_android_hardware_buffer, ANDROID_external_memory_android_hardware_buffer, KHR_bind_memory2, EXTENSION_CORE, // valid bit EXTENSION_CORE, // valid bit EXTENSION_COUNT, EXTENSION_COUNT, Loading Loading @@ -85,11 +86,13 @@ struct DeviceDriverTable { PFN_vkCreateImage CreateImage; PFN_vkCreateImage CreateImage; PFN_vkDestroyImage DestroyImage; PFN_vkDestroyImage DestroyImage; PFN_vkAllocateCommandBuffers AllocateCommandBuffers; PFN_vkAllocateCommandBuffers AllocateCommandBuffers; PFN_vkBindImageMemory2 BindImageMemory2; PFN_vkGetDeviceQueue2 GetDeviceQueue2; PFN_vkGetDeviceQueue2 GetDeviceQueue2; PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; PFN_vkGetSwapchainGrallocUsage2ANDROID GetSwapchainGrallocUsage2ANDROID; PFN_vkGetSwapchainGrallocUsage2ANDROID GetSwapchainGrallocUsage2ANDROID; PFN_vkAcquireImageANDROID AcquireImageANDROID; PFN_vkAcquireImageANDROID AcquireImageANDROID; PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; PFN_vkBindImageMemory2KHR BindImageMemory2KHR; // clang-format on // clang-format on }; }; Loading vulkan/libvulkan/swapchain.cpp +108 −5 Original line number Original line Diff line number Diff line Loading @@ -16,17 +16,19 @@ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <algorithm> #include <android/hardware/graphics/common/1.0/types.h> #include <grallocusage/GrallocUsageConversion.h> #include <grallocusage/GrallocUsageConversion.h> #include <log/log.h> #include <log/log.h> #include <ui/BufferQueueDefs.h> #include <sync/sync.h> #include <sync/sync.h> #include <system/window.h> #include <ui/BufferQueueDefs.h> #include <utils/StrongPointer.h> #include <utils/StrongPointer.h> #include <utils/Trace.h> #include <utils/Trace.h> #include <utils/Vector.h> #include <utils/Vector.h> #include <system/window.h> #include <android/hardware/graphics/common/1.0/types.h> #include <algorithm> #include <unordered_set> #include <vector> #include "driver.h" #include "driver.h" Loading Loading @@ -1818,5 +1820,106 @@ VKAPI_ATTR void SetHdrMetadataEXT( return; return; } } static void InterceptBindImageMemory2( uint32_t bind_info_count, const VkBindImageMemoryInfo* bind_infos, std::vector<VkNativeBufferANDROID>* out_native_buffers, std::vector<VkBindImageMemoryInfo>* out_bind_infos) { out_native_buffers->clear(); out_bind_infos->clear(); if (!bind_info_count) return; std::unordered_set<uint32_t> intercepted_indexes; for (uint32_t idx = 0; idx < bind_info_count; idx++) { auto info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( bind_infos[idx].pNext); while (info && info->sType != VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR) { info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( info->pNext); } if (!info) continue; ALOG_ASSERT(info->swapchain != VK_NULL_HANDLE, "swapchain handle must not be NULL"); const Swapchain* swapchain = SwapchainFromHandle(info->swapchain); ALOG_ASSERT( info->imageIndex < swapchain->num_images, "imageIndex must be less than the number of images in swapchain"); ANativeWindowBuffer* buffer = swapchain->images[info->imageIndex].buffer.get(); VkNativeBufferANDROID native_buffer = { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wold-style-cast" .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, #pragma clang diagnostic pop .pNext = bind_infos[idx].pNext, .handle = buffer->handle, .stride = buffer->stride, .format = buffer->format, .usage = int(buffer->usage), }; // Reserve enough space to avoid letting re-allocation invalidate the // addresses of the elements inside. out_native_buffers->reserve(bind_info_count); out_native_buffers->emplace_back(native_buffer); // Reserve the space now since we know how much is needed now. out_bind_infos->reserve(bind_info_count); out_bind_infos->emplace_back(bind_infos[idx]); out_bind_infos->back().pNext = &out_native_buffers->back(); intercepted_indexes.insert(idx); } if (intercepted_indexes.empty()) return; for (uint32_t idx = 0; idx < bind_info_count; idx++) { if (intercepted_indexes.count(idx)) continue; out_bind_infos->emplace_back(bind_infos[idx]); } } VKAPI_ATTR VkResult BindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) { ATRACE_CALL(); // out_native_buffers is for maintaining the lifecycle of the constructed // VkNativeBufferANDROID objects inside InterceptBindImageMemory2. std::vector<VkNativeBufferANDROID> out_native_buffers; std::vector<VkBindImageMemoryInfo> out_bind_infos; InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, &out_bind_infos); return GetData(device).driver.BindImageMemory2( device, bindInfoCount, out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); } VKAPI_ATTR VkResult BindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) { ATRACE_CALL(); std::vector<VkNativeBufferANDROID> out_native_buffers; std::vector<VkBindImageMemoryInfo> out_bind_infos; InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, &out_bind_infos); return GetData(device).driver.BindImageMemory2KHR( device, bindInfoCount, out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); } } // namespace driver } // namespace driver } // namespace vulkan } // namespace vulkan Loading
vulkan/libvulkan/code-generator.tmpl +8 −0 Original line number Original line Diff line number Diff line Loading @@ -703,6 +703,7 @@ VK_KHR_get_surface_capabilities2 {{Macro "driver.InterceptedExtensions"}} {{Macro "driver.InterceptedExtensions"}} VK_KHR_get_physical_device_properties2 VK_KHR_get_physical_device_properties2 VK_ANDROID_external_memory_android_hardware_buffer VK_ANDROID_external_memory_android_hardware_buffer VK_KHR_bind_memory2 {{end}} {{end}} Loading Loading @@ -750,6 +751,9 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetInstanceProcAddr"}}true {{else if eq $.Name "vkGetInstanceProcAddr"}}true {{else if eq $.Name "vkGetDeviceProcAddr"}}true {{else if eq $.Name "vkGetDeviceProcAddr"}}true {{/* VK_KHR_swapchain v69 requirement */}} {{else if eq $.Name "vkBindImageMemory2"}}true {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{end}} {{$ext := GetAnnotation $ "extension"}} {{$ext := GetAnnotation $ "extension"}} Loading Loading @@ -985,6 +989,10 @@ VK_ANDROID_external_memory_android_hardware_buffer {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true {{else if eq $.Name "vkGetPhysicalDeviceProperties2KHR"}}true {{/* VK_KHR_swapchain v69 requirement */}} {{else if eq $.Name "vkBindImageMemory2"}}true {{else if eq $.Name "vkBindImageMemory2KHR"}}true {{end}} {{end}} {{$ext := GetAnnotation $ "extension"}} {{$ext := GetAnnotation $ "extension"}} Loading
vulkan/libvulkan/driver.cpp +2 −0 Original line number Original line Diff line number Diff line Loading @@ -537,6 +537,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // Extensions we don't need to do anything about at this level // Extensions we don't need to do anything about at this level break; break; case ProcHook::KHR_bind_memory2: case ProcHook::KHR_incremental_present: case ProcHook::KHR_incremental_present: case ProcHook::KHR_shared_presentable_image: case ProcHook::KHR_shared_presentable_image: case ProcHook::KHR_swapchain: case ProcHook::KHR_swapchain: Loading Loading @@ -577,6 +578,7 @@ void CreateInfoWrapper::FilterExtension(const char* name) { // return now as these extensions do not require HAL support // return now as these extensions do not require HAL support return; return; case ProcHook::EXT_hdr_metadata: case ProcHook::EXT_hdr_metadata: case ProcHook::KHR_bind_memory2: hook_extensions_.set(ext_bit); hook_extensions_.set(ext_bit); break; break; case ProcHook::ANDROID_external_memory_android_hardware_buffer: case ProcHook::ANDROID_external_memory_android_hardware_buffer: Loading
vulkan/libvulkan/driver_gen.cpp +26 −0 Original line number Original line Diff line number Diff line Loading @@ -137,6 +137,15 @@ VKAPI_ATTR VkResult checkedGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR } } } } VKAPI_ATTR VkResult checkedBindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfoKHR* pBindInfos) { if (GetData(device).hook_extensions[ProcHook::KHR_bind_memory2]) { return BindImageMemory2KHR(device, bindInfoCount, pBindInfos); } else { Logger(device).Err(device, "VK_KHR_bind_memory2 not enabled. vkBindImageMemory2KHR not executed."); return VK_SUCCESS; } } // clang-format on // clang-format on const ProcHook g_proc_hooks[] = { const ProcHook g_proc_hooks[] = { Loading Loading @@ -169,6 +178,20 @@ const ProcHook g_proc_hooks[] = { reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers), reinterpret_cast<PFN_vkVoidFunction>(AllocateCommandBuffers), nullptr, nullptr, }, }, { "vkBindImageMemory2", ProcHook::DEVICE, ProcHook::EXTENSION_CORE, reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2), nullptr, }, { "vkBindImageMemory2KHR", ProcHook::DEVICE, ProcHook::KHR_bind_memory2, reinterpret_cast<PFN_vkVoidFunction>(BindImageMemory2KHR), reinterpret_cast<PFN_vkVoidFunction>(checkedBindImageMemory2KHR), }, { { "vkCreateAndroidSurfaceKHR", "vkCreateAndroidSurfaceKHR", ProcHook::INSTANCE, ProcHook::INSTANCE, Loading Loading @@ -458,6 +481,7 @@ ProcHook::Extension GetProcHookExtension(const char* name) { if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2; if (strcmp(name, "VK_KHR_get_surface_capabilities2") == 0) return ProcHook::KHR_get_surface_capabilities2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; if (strcmp(name, "VK_KHR_get_physical_device_properties2") == 0) return ProcHook::KHR_get_physical_device_properties2; if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; if (strcmp(name, "VK_ANDROID_external_memory_android_hardware_buffer") == 0) return ProcHook::ANDROID_external_memory_android_hardware_buffer; if (strcmp(name, "VK_KHR_bind_memory2") == 0) return ProcHook::KHR_bind_memory2; // clang-format on // clang-format on return ProcHook::EXTENSION_UNKNOWN; return ProcHook::EXTENSION_UNKNOWN; } } Loading Loading @@ -517,11 +541,13 @@ bool InitDriverTable(VkDevice dev, INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, CreateImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, DestroyImage); INIT_PROC(true, dev, AllocateCommandBuffers); INIT_PROC(true, dev, AllocateCommandBuffers); INIT_PROC(false, dev, BindImageMemory2); INIT_PROC(false, dev, GetDeviceQueue2); INIT_PROC(false, dev, GetDeviceQueue2); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, false, dev, GetSwapchainGrallocUsage2ANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, AcquireImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); INIT_PROC_EXT(ANDROID_native_buffer, true, dev, QueueSignalReleaseImageANDROID); INIT_PROC_EXT(KHR_bind_memory2, true, dev, BindImageMemory2KHR); // clang-format on // clang-format on return success; return success; Loading
vulkan/libvulkan/driver_gen.h +3 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,7 @@ struct ProcHook { KHR_get_surface_capabilities2, KHR_get_surface_capabilities2, KHR_get_physical_device_properties2, KHR_get_physical_device_properties2, ANDROID_external_memory_android_hardware_buffer, ANDROID_external_memory_android_hardware_buffer, KHR_bind_memory2, EXTENSION_CORE, // valid bit EXTENSION_CORE, // valid bit EXTENSION_COUNT, EXTENSION_COUNT, Loading Loading @@ -85,11 +86,13 @@ struct DeviceDriverTable { PFN_vkCreateImage CreateImage; PFN_vkCreateImage CreateImage; PFN_vkDestroyImage DestroyImage; PFN_vkDestroyImage DestroyImage; PFN_vkAllocateCommandBuffers AllocateCommandBuffers; PFN_vkAllocateCommandBuffers AllocateCommandBuffers; PFN_vkBindImageMemory2 BindImageMemory2; PFN_vkGetDeviceQueue2 GetDeviceQueue2; PFN_vkGetDeviceQueue2 GetDeviceQueue2; PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; PFN_vkGetSwapchainGrallocUsageANDROID GetSwapchainGrallocUsageANDROID; PFN_vkGetSwapchainGrallocUsage2ANDROID GetSwapchainGrallocUsage2ANDROID; PFN_vkGetSwapchainGrallocUsage2ANDROID GetSwapchainGrallocUsage2ANDROID; PFN_vkAcquireImageANDROID AcquireImageANDROID; PFN_vkAcquireImageANDROID AcquireImageANDROID; PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; PFN_vkQueueSignalReleaseImageANDROID QueueSignalReleaseImageANDROID; PFN_vkBindImageMemory2KHR BindImageMemory2KHR; // clang-format on // clang-format on }; }; Loading
vulkan/libvulkan/swapchain.cpp +108 −5 Original line number Original line Diff line number Diff line Loading @@ -16,17 +16,19 @@ #define ATRACE_TAG ATRACE_TAG_GRAPHICS #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <algorithm> #include <android/hardware/graphics/common/1.0/types.h> #include <grallocusage/GrallocUsageConversion.h> #include <grallocusage/GrallocUsageConversion.h> #include <log/log.h> #include <log/log.h> #include <ui/BufferQueueDefs.h> #include <sync/sync.h> #include <sync/sync.h> #include <system/window.h> #include <ui/BufferQueueDefs.h> #include <utils/StrongPointer.h> #include <utils/StrongPointer.h> #include <utils/Trace.h> #include <utils/Trace.h> #include <utils/Vector.h> #include <utils/Vector.h> #include <system/window.h> #include <android/hardware/graphics/common/1.0/types.h> #include <algorithm> #include <unordered_set> #include <vector> #include "driver.h" #include "driver.h" Loading Loading @@ -1818,5 +1820,106 @@ VKAPI_ATTR void SetHdrMetadataEXT( return; return; } } static void InterceptBindImageMemory2( uint32_t bind_info_count, const VkBindImageMemoryInfo* bind_infos, std::vector<VkNativeBufferANDROID>* out_native_buffers, std::vector<VkBindImageMemoryInfo>* out_bind_infos) { out_native_buffers->clear(); out_bind_infos->clear(); if (!bind_info_count) return; std::unordered_set<uint32_t> intercepted_indexes; for (uint32_t idx = 0; idx < bind_info_count; idx++) { auto info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( bind_infos[idx].pNext); while (info && info->sType != VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR) { info = reinterpret_cast<const VkBindImageMemorySwapchainInfoKHR*>( info->pNext); } if (!info) continue; ALOG_ASSERT(info->swapchain != VK_NULL_HANDLE, "swapchain handle must not be NULL"); const Swapchain* swapchain = SwapchainFromHandle(info->swapchain); ALOG_ASSERT( info->imageIndex < swapchain->num_images, "imageIndex must be less than the number of images in swapchain"); ANativeWindowBuffer* buffer = swapchain->images[info->imageIndex].buffer.get(); VkNativeBufferANDROID native_buffer = { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wold-style-cast" .sType = VK_STRUCTURE_TYPE_NATIVE_BUFFER_ANDROID, #pragma clang diagnostic pop .pNext = bind_infos[idx].pNext, .handle = buffer->handle, .stride = buffer->stride, .format = buffer->format, .usage = int(buffer->usage), }; // Reserve enough space to avoid letting re-allocation invalidate the // addresses of the elements inside. out_native_buffers->reserve(bind_info_count); out_native_buffers->emplace_back(native_buffer); // Reserve the space now since we know how much is needed now. out_bind_infos->reserve(bind_info_count); out_bind_infos->emplace_back(bind_infos[idx]); out_bind_infos->back().pNext = &out_native_buffers->back(); intercepted_indexes.insert(idx); } if (intercepted_indexes.empty()) return; for (uint32_t idx = 0; idx < bind_info_count; idx++) { if (intercepted_indexes.count(idx)) continue; out_bind_infos->emplace_back(bind_infos[idx]); } } VKAPI_ATTR VkResult BindImageMemory2(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) { ATRACE_CALL(); // out_native_buffers is for maintaining the lifecycle of the constructed // VkNativeBufferANDROID objects inside InterceptBindImageMemory2. std::vector<VkNativeBufferANDROID> out_native_buffers; std::vector<VkBindImageMemoryInfo> out_bind_infos; InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, &out_bind_infos); return GetData(device).driver.BindImageMemory2( device, bindInfoCount, out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); } VKAPI_ATTR VkResult BindImageMemory2KHR(VkDevice device, uint32_t bindInfoCount, const VkBindImageMemoryInfo* pBindInfos) { ATRACE_CALL(); std::vector<VkNativeBufferANDROID> out_native_buffers; std::vector<VkBindImageMemoryInfo> out_bind_infos; InterceptBindImageMemory2(bindInfoCount, pBindInfos, &out_native_buffers, &out_bind_infos); return GetData(device).driver.BindImageMemory2KHR( device, bindInfoCount, out_bind_infos.empty() ? pBindInfos : out_bind_infos.data()); } } // namespace driver } // namespace driver } // namespace vulkan } // namespace vulkan