From 8b8ec431e665953b352bbd66ebe771b470a6e8b2 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Tue, 25 Oct 2022 16:24:12 -0400 Subject: [PATCH 01/21] [WIP] Wire Flutter's own VMA --- flutter_vma/BUILD.gn | 32 +++ flutter_vma/flutter_skia_vma.cc | 239 ++++++++++++++++++ flutter_vma/flutter_skia_vma.h | 60 +++++ flutter_vma/flutter_vma.cc | 15 ++ flutter_vma/flutter_vma.h | 7 + impeller/renderer/backend/vulkan/BUILD.gn | 1 + .../renderer/backend/vulkan/allocator_vk.cc | 13 +- impeller/renderer/backend/vulkan/vk.h | 12 +- impeller/tools/impeller.gni | 7 +- shell/platform/embedder/BUILD.gn | 8 +- .../embedder/embedder_surface_vulkan.cc | 13 + tools/gn | 20 +- vulkan/vulkan_proc_table.cc | 17 +- vulkan/vulkan_proc_table.h | 2 + 14 files changed, 396 insertions(+), 50 deletions(-) create mode 100644 flutter_vma/BUILD.gn create mode 100644 flutter_vma/flutter_skia_vma.cc create mode 100644 flutter_vma/flutter_skia_vma.h create mode 100644 flutter_vma/flutter_vma.cc create mode 100644 flutter_vma/flutter_vma.h diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn new file mode 100644 index 0000000000000..743cecd3e70de --- /dev/null +++ b/flutter_vma/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +source_set("flutter_vma") { + sources = [ + "flutter_vma.cc", + "flutter_vma.h", + ] + + deps = [ + "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", + "//third_party/vulkan_memory_allocator", + ] + + public_configs = [ "//flutter:config" ] +} + +source_set("flutter_skia_vma") { + sources = [ + "flutter_skia_vma.cc", + "flutter_skia_vma.h", + ] + + public_deps = [ ":flutter_vma" ] + + deps = [ + "//third_party/skia", + "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", + "//third_party/vulkan_memory_allocator", + ] +} diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc new file mode 100644 index 0000000000000..030d9de6508f5 --- /dev/null +++ b/flutter_vma/flutter_skia_vma.cc @@ -0,0 +1,239 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "flutter/flutter_vma/flutter_skia_vma.h" + +namespace flutter { + +sk_sp FlutterSkiaVulkanMemoryAllocator::Make( + uint32_t vulkan_api_version, + VkInstance instance, + VkPhysicalDevice physicalDevice, + VkDevice device, + PFN_vkGetInstanceProcAddr get_instance_proc_address, + PFN_vkGetDeviceProcAddr get_device_proc_address, + bool mustUseCoherentHostVisibleMemory) { + VmaVulkanFunctions proc_table = {}; + proc_table.vkGetInstanceProcAddr = get_instance_proc_address; + proc_table.vkGetDeviceProcAddr = get_device_proc_address; + + VmaAllocatorCreateInfo allocator_info = {}; + allocator_info.vulkanApiVersion = vulkan_api_version; + allocator_info.physicalDevice = physicalDevice; + allocator_info.device = device; + allocator_info.instance = instance; + allocator_info.pVulkanFunctions = &proc_table; + + VmaAllocator allocator; + vmaCreateAllocator(&allocator_info, &allocator); + + return sk_sp( + new FlutterSkiaVulkanMemoryAllocator(allocator, + mustUseCoherentHostVisibleMemory)); +} + +FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator( + VmaAllocator allocator, + bool mustUseCoherentHostVisibleMemory) + : allocator_(allocator), + must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) { +} + +FlutterSkiaVulkanMemoryAllocator::~FlutterSkiaVulkanMemoryAllocator() { + vmaDestroyAllocator(allocator_); + allocator_ = VK_NULL_HANDLE; +} + +VkResult FlutterSkiaVulkanMemoryAllocator::allocateImageMemory( + VkImage image, + uint32_t allocationPropertyFlags, + skgpu::VulkanBackendMemory* backendMemory) { + VmaAllocationCreateInfo info; + info.flags = 0; + info.usage = VMA_MEMORY_USAGE_UNKNOWN; + info.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + info.preferredFlags = 0; + info.memoryTypeBits = 0; + info.pool = VK_NULL_HANDLE; + info.pUserData = nullptr; + + if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) { + info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; + } + if (kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) { + info.requiredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; + } + if (kProtected_AllocationPropertyFlag & allocationPropertyFlags) { + info.requiredFlags |= VK_MEMORY_PROPERTY_PROTECTED_BIT; + } + + VmaAllocation allocation; + VkResult result = + vmaAllocateMemoryForImage(allocator_, image, &info, &allocation, nullptr); + if (VK_SUCCESS == result) { + *backendMemory = reinterpret_cast(allocation); + } + return result; +} + +VkResult FlutterSkiaVulkanMemoryAllocator::allocateBufferMemory( + VkBuffer buffer, + BufferUsage usage, + uint32_t allocationPropertyFlags, + skgpu::VulkanBackendMemory* backendMemory) { + VmaAllocationCreateInfo info; + info.flags = 0; + info.usage = VMA_MEMORY_USAGE_UNKNOWN; + info.memoryTypeBits = 0; + info.pool = VK_NULL_HANDLE; + info.pUserData = nullptr; + + switch (usage) { + case BufferUsage::kGpuOnly: + info.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + info.preferredFlags = 0; + break; + case BufferUsage::kCpuWritesGpuReads: + // When doing cpu writes and gpu reads the general rule of thumb is to use + // coherent memory. Though this depends on the fact that we are not doing + // any cpu reads and the cpu writes are sequential. For sparse writes we'd + // want cpu cached memory, however we don't do these types of writes in + // Skia. + // + // TODO (kaushikiska): In the future there may be times where specific + // types of memory could benefit from a coherent and cached memory. + // Typically these allow for the gpu to read cpu writes from the cache + // without needing to flush the writes throughout the cache. The reverse + // is not true and GPU writes tend to invalidate the cache regardless. + // Also these gpu cache read access are typically lower bandwidth than + // non-cached memory. For now Skia doesn't really have a need or want of + // this type of memory. But if we ever do we could pass in an + // AllocationPropertyFlag that requests the cached property. + info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + break; + case BufferUsage::kTransfersFromCpuToGpu: + info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + info.preferredFlags = 0; + break; + case BufferUsage::kTransfersFromGpuToCpu: + info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; + info.preferredFlags = VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + break; + } + + if (must_use_coherent_host_visible_memory_ && + (info.requiredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { + info.requiredFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + } + if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) { + info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; + } + if ((kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) && + BufferUsage::kGpuOnly == usage) { + info.preferredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; + } + + if (kPersistentlyMapped_AllocationPropertyFlag & allocationPropertyFlags) { + SkASSERT(BufferUsage::kGpuOnly != usage); + info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; + } + + VmaAllocation allocation; + VkResult result = vmaAllocateMemoryForBuffer(allocator_, buffer, &info, + &allocation, nullptr); + if (VK_SUCCESS == result) { + *backendMemory = reinterpret_cast(allocation); + } + + return result; +} + +void FlutterSkiaVulkanMemoryAllocator::freeMemory( + const skgpu::VulkanBackendMemory& memoryHandle) { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + vmaFreeMemory(allocator_, allocation); +} + +void FlutterSkiaVulkanMemoryAllocator::getAllocInfo( + const skgpu::VulkanBackendMemory& memoryHandle, + skgpu::VulkanAlloc* alloc) const { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + VmaAllocationInfo vmaInfo; + vmaGetAllocationInfo(allocator_, allocation, &vmaInfo); + + VkMemoryPropertyFlags memFlags; + vmaGetMemoryTypeProperties(allocator_, vmaInfo.memoryType, &memFlags); + + uint32_t flags = 0; + if (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT & memFlags) { + flags |= skgpu::VulkanAlloc::kMappable_Flag; + } + if (!SkToBool(VK_MEMORY_PROPERTY_HOST_COHERENT_BIT & memFlags)) { + flags |= skgpu::VulkanAlloc::kNoncoherent_Flag; + } + if (VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT & memFlags) { + flags |= skgpu::VulkanAlloc::kLazilyAllocated_Flag; + } + + alloc->fMemory = vmaInfo.deviceMemory; + alloc->fOffset = vmaInfo.offset; + alloc->fSize = vmaInfo.size; + alloc->fFlags = flags; + alloc->fBackendMemory = memoryHandle; +} + +VkResult FlutterSkiaVulkanMemoryAllocator::mapMemory( + const skgpu::VulkanBackendMemory& memoryHandle, + void** data) { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + return vmaMapMemory(allocator_, allocation, data); +} + +void FlutterSkiaVulkanMemoryAllocator::unmapMemory( + const skgpu::VulkanBackendMemory& memoryHandle) { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + vmaUnmapMemory(allocator_, allocation); +} + +VkResult FlutterSkiaVulkanMemoryAllocator::flushMemory( + const skgpu::VulkanBackendMemory& memoryHandle, + VkDeviceSize offset, + VkDeviceSize size) { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + return vmaFlushAllocation(allocator_, allocation, offset, size); +} + +VkResult FlutterSkiaVulkanMemoryAllocator::invalidateMemory( + const skgpu::VulkanBackendMemory& memoryHandle, + VkDeviceSize offset, + VkDeviceSize size) { + const VmaAllocation allocation = + reinterpret_cast(memoryHandle); + return vmaInvalidateAllocation(allocator_, allocation, offset, size); +} + +uint64_t FlutterSkiaVulkanMemoryAllocator::totalUsedMemory() const { + VmaTotalStatistics stats; + vmaCalculateStatistics(allocator_, &stats); + return stats.total.statistics.allocationBytes; +} + +uint64_t FlutterSkiaVulkanMemoryAllocator::totalAllocatedMemory() const { + VmaTotalStatistics stats; + vmaCalculateStatistics(allocator_, &stats); + return stats.total.statistics.blockBytes; +} + +} // namespace flutter diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h new file mode 100644 index 0000000000000..4540eccf19a47 --- /dev/null +++ b/flutter_vma/flutter_skia_vma.h @@ -0,0 +1,60 @@ +#include "flutter/flutter_vma/flutter_vma.h" + +#include "include/gpu/vk/GrVkBackendContext.h" + +namespace flutter { + +class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { + public: + static sk_sp Make( + uint32_t vulkan_api_version, + VkInstance instance, + VkPhysicalDevice physicalDevice, + VkDevice device, + PFN_vkGetInstanceProcAddr get_instance_proc_address, + PFN_vkGetDeviceProcAddr get_device_proc_address, + bool mustUseCoherentHostVisibleMemory); + + ~FlutterSkiaVulkanMemoryAllocator() override; + + VkResult allocateImageMemory(VkImage image, + uint32_t allocationPropertyFlags, + skgpu::VulkanBackendMemory*) override; + + VkResult allocateBufferMemory(VkBuffer buffer, + BufferUsage usage, + uint32_t allocationPropertyFlags, + skgpu::VulkanBackendMemory*) override; + + void freeMemory(const skgpu::VulkanBackendMemory&) override; + + void getAllocInfo(const skgpu::VulkanBackendMemory&, + skgpu::VulkanAlloc*) const override; + + VkResult mapMemory(const skgpu::VulkanBackendMemory&, void** data) override; + void unmapMemory(const skgpu::VulkanBackendMemory&) override; + + VkResult flushMemory(const skgpu::VulkanBackendMemory&, + VkDeviceSize offset, + VkDeviceSize size) override; + VkResult invalidateMemory(const skgpu::VulkanBackendMemory&, + VkDeviceSize offset, + VkDeviceSize size) override; + + uint64_t totalUsedMemory() const override; + uint64_t totalAllocatedMemory() const override; + + private: + FlutterSkiaVulkanMemoryAllocator(VmaAllocator allocator, + bool mustUseCoherentHostVisibleMemory); + + VmaAllocator allocator_; + + // For host visible allocations do we require they are coherent or not. All + // devices are required to support a host visible and coherent memory type. + // This is used to work around bugs for devices that don't handle non coherent + // memory correctly. + bool must_use_coherent_host_visible_memory_; +}; + +} // namespace flutter diff --git a/flutter_vma/flutter_vma.cc b/flutter_vma/flutter_vma.cc new file mode 100644 index 0000000000000..98f886402d04b --- /dev/null +++ b/flutter_vma/flutter_vma.cc @@ -0,0 +1,15 @@ +#ifdef VMA_STATIC_VULKAN_FUNCTIONS +#undef VMA_STATIC_VULKAN_FUNCTIONS +#endif // VMA_STATIC_VULKAN_FUNCTIONS + +#ifdef VMA_DYNAMIC_VULKAN_FUNCTIONS +#undef VMA_DYNAMIC_VULKAN_FUNCTIONS +#endif // VMA_DYNAMIC_VULKAN_FUNCTIONS + +// We use our own functions pointers +#define VMA_STATIC_VULKAN_FUNCTIONS 0 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 + +#define VMA_IMPLEMENTATION + +#include "flutter/flutter_vma/flutter_vma.h" diff --git a/flutter_vma/flutter_vma.h b/flutter_vma/flutter_vma.h new file mode 100644 index 0000000000000..f218c7a876121 --- /dev/null +++ b/flutter_vma/flutter_vma.h @@ -0,0 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "vk_mem_alloc.h" diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 55af09309b5e5..a6872fa96e02e 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -56,6 +56,7 @@ impeller_component("vulkan") { public_deps = [ "../../:renderer", "../../../blobcat:blobcat_lib", + "//flutter/flutter_vma", "//flutter/fml", "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", "//third_party/vulkan_memory_allocator", diff --git a/impeller/renderer/backend/vulkan/allocator_vk.cc b/impeller/renderer/backend/vulkan/allocator_vk.cc index de0d3384c8720..1faca6952efc7 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.cc +++ b/impeller/renderer/backend/vulkan/allocator_vk.cc @@ -2,20 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -_Pragma("GCC diagnostic push"); -_Pragma("GCC diagnostic ignored \"-Wnullability-completeness\""); -_Pragma("GCC diagnostic ignored \"-Wunused-variable\""); -_Pragma("GCC diagnostic ignored \"-Wthread-safety-analysis\""); - -#define VMA_IMPLEMENTATION #include "impeller/renderer/backend/vulkan/allocator_vk.h" -#include "impeller/renderer/backend/vulkan/device_buffer_vk.h" -#include "impeller/renderer/backend/vulkan/formats_vk.h" -#include "impeller/renderer/backend/vulkan/texture_vk.h" #include -_Pragma("GCC diagnostic pop"); +#include "impeller/renderer/backend/vulkan/device_buffer_vk.h" +#include "impeller/renderer/backend/vulkan/formats_vk.h" +#include "impeller/renderer/backend/vulkan/texture_vk.h" namespace impeller { diff --git a/impeller/renderer/backend/vulkan/vk.h b/impeller/renderer/backend/vulkan/vk.h index 3ce2d346f493d..14f02c9aaf4ce 100644 --- a/impeller/renderer/backend/vulkan/vk.h +++ b/impeller/renderer/backend/vulkan/vk.h @@ -25,17 +25,7 @@ static_assert(VK_HEADER_VERSION >= 215, "Vulkan headers are must not be too old."); -#ifdef VMA_STATIC_VULKAN_FUNCTIONS -#undef VMA_STATIC_VULKAN_FUNCTIONS -#endif // VMA_STATIC_VULKAN_FUNCTIONS - -#ifdef VMA_DYNAMIC_VULKAN_FUNCTIONS -#undef VMA_DYNAMIC_VULKAN_FUNCTIONS -#endif // VMA_DYNAMIC_VULKAN_FUNCTIONS - -#define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 -#include "vk_mem_alloc.h" +#include "flutter/flutter_vma/flutter_vma.h" namespace impeller { diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index a01b18c176bf8..d334094cc7ff0 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -17,7 +17,7 @@ declare_args() { impeller_enable_opengles = is_mac || is_linux || is_win || is_android # Whether the Vulkan backend is enabled. - impeller_enable_vulkan = false + impeller_enable_vulkan = is_mac || is_linux || is_win # Whether to use a prebuilt impellerc. # If this is the empty string, impellerc will be built. @@ -452,7 +452,7 @@ template("impeller_shaders_gles") { sl_file_extension = "gles" # Metal reflectors generate a superset of information. - if (impeller_enable_metal) { + if (impeller_enable_metal || impeller_enable_vulkan) { intermediates_subdir = "gles" } if (is_mac) { @@ -489,7 +489,7 @@ template("impeller_shaders_gles") { group(target_name) { public_deps = [ ":$embed_gles_lib" ] - if (!impeller_enable_metal) { + if (!impeller_enable_metal && !impeller_enable_vulkan) { public_deps += [ ":$reflect_gles" ] } } @@ -572,6 +572,7 @@ template("impeller_shaders") { if (impeller_enable_vulkan) { vk_shaders = "vk_$target_name" + print("vk_shaders = $vk_shaders") impeller_shaders_vk(vk_shaders) { name = invoker.name shaders = invoker.shaders diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 5f74522f91d34..a26b936efcb2f 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -135,9 +135,15 @@ template("embedder_source_set") { "embedder_surface_vulkan.cc", "embedder_surface_vulkan.h", ] + + public_deps = [ "//flutter/flutter_vma:flutter_skia_vma" ] + } + + if (!defined(public_deps)) { + public_deps = [] } - public_deps = [ ":embedder_headers" ] + public_deps += [ ":embedder_headers" ] public_configs += [ ":embedder_gpu_configuration_config", diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 837d15882c648..16e59490534f1 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -6,6 +6,7 @@ #include +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/shell/common/shell_io_manager.h" #include "include/gpu/GrDirectContext.h" #include "include/gpu/vk/GrVkBackendContext.h" @@ -143,6 +144,18 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( backend_context.fGetProc = get_proc; backend_context.fOwnsInstanceAndDevice = false; + PFN_vkGetInstanceProcAddr instance_proc_address = + vk_->NativeGetInstanceProcAddr(); + PFN_vkGetDeviceProcAddr get_device_proc_address = vk_->GetDeviceProcAddr; + uint32_t vulkan_api_version = version; + sk_sp allocator = + flutter::FlutterSkiaVulkanMemoryAllocator::Make( + vulkan_api_version, instance, device_.GetPhysicalDeviceHandle(), + device_.GetHandle(), instance_proc_address, get_device_proc_address, + true); + + backend_context.fMemoryAllocator = allocator; + extensions.init(backend_context.fGetProc, backend_context.fInstance, backend_context.fPhysicalDevice, instance_extension_count, instance_extensions, device_extension_count, diff --git a/tools/gn b/tools/gn index 06f34e959a304..4b1361966b584 100755 --- a/tools/gn +++ b/tools/gn @@ -436,13 +436,8 @@ def to_gn_args(args): # features can't work on these platforms. if args.target_os not in ['android', 'ios']: gn_args['skia_use_vulkan'] = True - gn_args['skia_vulkan_memory_allocator_dir' - ] = '//third_party/vulkan_memory_allocator' + gn_args['skia_use_vma'] = False gn_args['shell_enable_vulkan'] = True - # Disable VMA's use of std::shared_mutex in environments where the - # standard library doesn't support it. - if args.target_os == 'ios' or sys.platform.startswith(('cygwin', 'win')): - gn_args['skia_disable_vma_stl_shared_mutex'] = True # We should not need a special case for x86, but this seems to introduce text relocations # even with -fPIC everywhere. @@ -543,12 +538,6 @@ def to_gn_args(args): if args.prebuilt_impellerc is not None: gn_args['impeller_use_prebuilt_impellerc'] = args.prebuilt_impellerc - # Vulkan support is WIP, see: https://github.com/flutter/flutter/issues/107357 - if args.enable_impeller_vulkan: - gn_args['impeller_enable_opengles'] = False - gn_args['impeller_enable_vulkan'] = True - gn_args['skia_use_vma'] = False - # ANGLE is exclusively used for: # - Windows at runtime # - Non-fuchsia host unit tests (is_host_build evaluates to false). @@ -956,13 +945,6 @@ def parse_args(args): help='Absolute path to a prebuilt impellerc. ' + 'Do not use this outside of CI or with impellerc from a different engine version.' ) - parser.add_argument( - '--enable-impeller-vulkan', - default=False, - action='store_true', - help='Enables WIP impeller support for vulkan. ' + - 'https://github.com/flutter/flutter/issues/107357' - ) # Sanitizers. parser.add_argument('--asan', default=False, action='store_true') diff --git a/vulkan/vulkan_proc_table.cc b/vulkan/vulkan_proc_table.cc index a4c21bf2d7065..769f2789b16cd 100644 --- a/vulkan/vulkan_proc_table.cc +++ b/vulkan/vulkan_proc_table.cc @@ -58,12 +58,7 @@ bool VulkanProcTable::SetupGetInstanceProcAddress() { } GetInstanceProcAddr = reinterpret_cast( -#if VULKAN_LINK_STATICALLY - &vkGetInstanceProcAddr -#else // VULKAN_LINK_STATICALLY - const_cast(handle_->ResolveSymbol("vkGetInstanceProcAddr")) -#endif // VULKAN_LINK_STATICALLY - ); + NativeGetInstanceProcAddr()); if (!GetInstanceProcAddr) { FML_DLOG(WARNING) << "Could not acquire vkGetInstanceProcAddr."; return false; @@ -72,6 +67,16 @@ bool VulkanProcTable::SetupGetInstanceProcAddress() { return true; } +PFN_vkGetInstanceProcAddr VulkanProcTable::NativeGetInstanceProcAddr() const { +#if VULKAN_LINK_STATICALLY + return &vkGetInstanceProcAddr; +#else // VULKAN_LINK_STATICALLY + auto instance_proc = + const_cast(handle_->ResolveSymbol("vkGetInstanceProcAddr")); + return reinterpret_cast(instance_proc); +#endif // VULKAN_LINK_STATICALLY +} + bool VulkanProcTable::SetupLoaderProcAddresses() { VulkanHandle null_instance(VK_NULL_HANDLE, nullptr); diff --git a/vulkan/vulkan_proc_table.h b/vulkan/vulkan_proc_table.h index 93b4d0a3bfdd2..8e7682c306f58 100644 --- a/vulkan/vulkan_proc_table.h +++ b/vulkan/vulkan_proc_table.h @@ -136,6 +136,8 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { #undef DEFINE_PROC + PFN_vkGetInstanceProcAddr NativeGetInstanceProcAddr() const; + private: fml::RefPtr handle_; bool acquired_mandatory_proc_addresses_; From 19312fa35a53352776a1809fce79e538823ac0cb Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 08:37:51 -0400 Subject: [PATCH 02/21] vma with exts --- flutter_vma/BUILD.gn | 4 + flutter_vma/flutter_skia_vma.cc | 97 +++- flutter_vma/flutter_skia_vma.h | 22 +- flutter_vma/flutter_vma.cc | 2 +- flutter_vma/vulkan_extensions.cc | 131 +++++ flutter_vma/vulkan_extensions.h | 54 ++ flutter_vma/vulkan_interface.cc | 510 ++++++++++++++++++ flutter_vma/vulkan_interface.h | 254 +++++++++ shell/platform/embedder/BUILD.gn | 8 +- .../embedder/embedder_surface_vulkan.cc | 15 + vulkan/BUILD.gn | 1 + vulkan/vulkan_window.cc | 8 + vulkan/vulkan_window.h | 2 + 13 files changed, 1079 insertions(+), 29 deletions(-) create mode 100644 flutter_vma/vulkan_extensions.cc create mode 100644 flutter_vma/vulkan_extensions.h create mode 100644 flutter_vma/vulkan_interface.cc create mode 100644 flutter_vma/vulkan_interface.h diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn index 743cecd3e70de..a996a7ff2c98f 100644 --- a/flutter_vma/BUILD.gn +++ b/flutter_vma/BUILD.gn @@ -20,6 +20,10 @@ source_set("flutter_skia_vma") { sources = [ "flutter_skia_vma.cc", "flutter_skia_vma.h", + "vulkan_extensions.cc", + "vulkan_extensions.h", + "vulkan_interface.cc", + "vulkan_interface.h", ] public_deps = [ ":flutter_vma" ] diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index 030d9de6508f5..fee4af992f9ae 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -7,39 +7,104 @@ #include "flutter/flutter_vma/flutter_skia_vma.h" +#include "flutter/flutter_vma/vulkan_extensions.h" + namespace flutter { sk_sp FlutterSkiaVulkanMemoryAllocator::Make( - uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - PFN_vkGetInstanceProcAddr get_instance_proc_address, - PFN_vkGetDeviceProcAddr get_device_proc_address, - bool mustUseCoherentHostVisibleMemory) { - VmaVulkanFunctions proc_table = {}; - proc_table.vkGetInstanceProcAddr = get_instance_proc_address; - proc_table.vkGetDeviceProcAddr = get_device_proc_address; - - VmaAllocatorCreateInfo allocator_info = {}; - allocator_info.vulkanApiVersion = vulkan_api_version; - allocator_info.physicalDevice = physicalDevice; - allocator_info.device = device; - allocator_info.instance = instance; - allocator_info.pVulkanFunctions = &proc_table; + uint32_t physicalDeviceVersion, + const VulkanExtensions* extensions, + sk_sp interface, + bool mustUseCoherentHostVisibleMemory, + bool threadSafe) { +#define SKGPU_COPY_FUNCTION(NAME) \ + functions.vk##NAME = interface->fFunctions.f##NAME +#define SKGPU_COPY_FUNCTION_KHR(NAME) \ + functions.vk##NAME##KHR = interface->fFunctions.f##NAME + + VmaVulkanFunctions functions; + // We should be setting all the required functions (at least through + // vulkan 1.1), but this is just extra belt and suspenders to make sure there + // isn't unitialized values here. + memset(&functions, 0, sizeof(VmaVulkanFunctions)); + + // We don't use dynamic function getting in the allocator so we set the + // getProc functions to null. + functions.vkGetInstanceProcAddr = nullptr; + functions.vkGetDeviceProcAddr = nullptr; + SKGPU_COPY_FUNCTION(GetPhysicalDeviceProperties); + SKGPU_COPY_FUNCTION(GetPhysicalDeviceMemoryProperties); + SKGPU_COPY_FUNCTION(AllocateMemory); + SKGPU_COPY_FUNCTION(FreeMemory); + SKGPU_COPY_FUNCTION(MapMemory); + SKGPU_COPY_FUNCTION(UnmapMemory); + SKGPU_COPY_FUNCTION(FlushMappedMemoryRanges); + SKGPU_COPY_FUNCTION(InvalidateMappedMemoryRanges); + SKGPU_COPY_FUNCTION(BindBufferMemory); + SKGPU_COPY_FUNCTION(BindImageMemory); + SKGPU_COPY_FUNCTION(GetBufferMemoryRequirements); + SKGPU_COPY_FUNCTION(GetImageMemoryRequirements); + SKGPU_COPY_FUNCTION(CreateBuffer); + SKGPU_COPY_FUNCTION(DestroyBuffer); + SKGPU_COPY_FUNCTION(CreateImage); + SKGPU_COPY_FUNCTION(DestroyImage); + SKGPU_COPY_FUNCTION(CmdCopyBuffer); + SKGPU_COPY_FUNCTION_KHR(GetBufferMemoryRequirements2); + SKGPU_COPY_FUNCTION_KHR(GetImageMemoryRequirements2); + SKGPU_COPY_FUNCTION_KHR(BindBufferMemory2); + SKGPU_COPY_FUNCTION_KHR(BindImageMemory2); + SKGPU_COPY_FUNCTION_KHR(GetPhysicalDeviceMemoryProperties2); + + VmaAllocatorCreateInfo info; + info.flags = 0; + if (!threadSafe) { + info.flags |= VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT; + } + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + (extensions->hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, + 1) && + extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, + 1))) { + info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; + } + + info.physicalDevice = physicalDevice; + info.device = device; + // 4MB was picked for the size here by looking at memory usage of Android apps + // and runs of DM. It seems to be a good compromise of not wasting unused + // allocated space and not making too many small allocations. The AMD + // allocator will start making blocks at 1/8 the max size and builds up block + // size as needed before capping at the max set here. + info.preferredLargeHeapBlockSize = 4 * 1024 * 1024; + info.pAllocationCallbacks = nullptr; + info.pDeviceMemoryCallbacks = nullptr; + info.pHeapSizeLimit = nullptr; + info.pVulkanFunctions = &functions; + info.instance = instance; + // TODO (kaushikiska): Update our interface and headers to support vulkan 1.3 + // and add in the new required functions for 1.3 that the allocator needs. + // Until then we just clamp the version to 1.1. + info.vulkanApiVersion = + std::min(physicalDeviceVersion, VK_MAKE_VERSION(1, 1, 0)); + info.pTypeExternalMemoryHandleTypes = nullptr; VmaAllocator allocator; - vmaCreateAllocator(&allocator_info, &allocator); + vmaCreateAllocator(&info, &allocator); return sk_sp( - new FlutterSkiaVulkanMemoryAllocator(allocator, + new FlutterSkiaVulkanMemoryAllocator(allocator, std::move(interface), mustUseCoherentHostVisibleMemory)); } FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator( VmaAllocator allocator, + sk_sp interface, bool mustUseCoherentHostVisibleMemory) : allocator_(allocator), + interface_(std::move(interface)), must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) { } diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h index 4540eccf19a47..fdc6baf0a1159 100644 --- a/flutter_vma/flutter_skia_vma.h +++ b/flutter_vma/flutter_skia_vma.h @@ -1,19 +1,23 @@ +#pragma once + #include "flutter/flutter_vma/flutter_vma.h" -#include "include/gpu/vk/GrVkBackendContext.h" +#include "flutter/flutter_vma/vulkan_interface.h" +#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" namespace flutter { class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { public: - static sk_sp Make( - uint32_t vulkan_api_version, + static sk_sp Make( VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - PFN_vkGetInstanceProcAddr get_instance_proc_address, - PFN_vkGetDeviceProcAddr get_device_proc_address, - bool mustUseCoherentHostVisibleMemory); + uint32_t physicalDeviceVersion, + const VulkanExtensions* extensions, + sk_sp interface, + bool mustUseCoherentHostVisibleMemory, + bool threadSafe); ~FlutterSkiaVulkanMemoryAllocator() override; @@ -46,10 +50,16 @@ class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { private: FlutterSkiaVulkanMemoryAllocator(VmaAllocator allocator, + sk_sp interface, bool mustUseCoherentHostVisibleMemory); VmaAllocator allocator_; + // If a future version of the AMD allocator has helper functions for flushing + // and invalidating memory, then we won't need to save the VulkanInterface + // here since we won't need to make direct vulkan calls. + sk_sp interface_; + // For host visible allocations do we require they are coherent or not. All // devices are required to support a host visible and coherent memory type. // This is used to work around bugs for devices that don't handle non coherent diff --git a/flutter_vma/flutter_vma.cc b/flutter_vma/flutter_vma.cc index 98f886402d04b..4a7a534b3763b 100644 --- a/flutter_vma/flutter_vma.cc +++ b/flutter_vma/flutter_vma.cc @@ -8,7 +8,7 @@ // We use our own functions pointers #define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0 #define VMA_IMPLEMENTATION diff --git a/flutter_vma/vulkan_extensions.cc b/flutter_vma/vulkan_extensions.cc new file mode 100644 index 0000000000000..b1e76de4e7c4a --- /dev/null +++ b/flutter_vma/vulkan_extensions.cc @@ -0,0 +1,131 @@ +#include "flutter/flutter_vma/vulkan_extensions.h" + +namespace flutter { + +// finds the index of ext in infos or a negative result if ext is not found. +static int find_info(const std::vector& infos, + const char ext[]) { + if (infos.empty()) { + return -1; + } + + // TODO (kaushikiska): This really needs to be a binary search. + for (size_t i = 0; i < infos.size(); i++) { + if (strcmp(infos[i].fName.c_str(), ext) == 0) { + return i; + } + } + + return -1; +} + +namespace { // This cannot be static because it is used as a template + // parameter. +inline bool extension_compare(const VulkanExtensions::Info& a, + const VulkanExtensions::Info& b) { + return strcmp(a.fName.c_str(), b.fName.c_str()) < 0; +} +} // namespace + +void VulkanExtensions::init(skgpu::VulkanGetProc getProc, + VkInstance instance, + VkPhysicalDevice physDev, + uint32_t instanceExtensionCount, + const char* const* instanceExtensions, + uint32_t deviceExtensionCount, + const char* const* deviceExtensions) { + for (uint32_t i = 0; i < instanceExtensionCount; ++i) { + const char* extension = instanceExtensions[i]; + // if not already in the list, add it + if (find_info(extensions_, extension) < 0) { + extensions_.push_back(Info(extension)); + std::sort(extensions_.begin(), extensions_.end(), extension_compare); + } + } + for (uint32_t i = 0; i < deviceExtensionCount; ++i) { + const char* extension = deviceExtensions[i]; + // if not already in the list, add it + if (find_info(extensions_, extension) < 0) { + extensions_.push_back(Info(extension)); + std::sort(extensions_.begin(), extensions_.end(), extension_compare); + } + } + this->getSpecVersions(getProc, instance, physDev); +} + +#define GET_PROC(F, inst) \ + PFN_vk##F grVk##F = (PFN_vk##F)getProc("vk" #F, inst, VK_NULL_HANDLE) + +void VulkanExtensions::getSpecVersions(skgpu::VulkanGetProc getProc, + VkInstance instance, + VkPhysicalDevice physDevice) { + // We grab all the extensions for the VkInstance and VkDevice so we can look + // up what spec version each of the supported extensions are. We do not grab + // the extensions for layers because we don't know what layers the client has + // enabled and in general we don't do anything special for those extensions. + + if (instance == VK_NULL_HANDLE) { + return; + } + GET_PROC(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE); + SkASSERT(grVkEnumerateInstanceExtensionProperties); + + VkResult res; + // instance extensions + uint32_t extensionCount = 0; + res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, + nullptr); + if (VK_SUCCESS != res) { + return; + } + VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount]; + res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, + extensions); + if (VK_SUCCESS != res) { + delete[] extensions; + return; + } + for (uint32_t i = 0; i < extensionCount; ++i) { + int idx = find_info(extensions_, extensions[i].extensionName); + if (idx >= 0) { + extensions_[idx].fSpecVersion = extensions[i].specVersion; + } + } + delete[] extensions; + + if (physDevice == VK_NULL_HANDLE) { + return; + } + GET_PROC(EnumerateDeviceExtensionProperties, instance); + SkASSERT(grVkEnumerateDeviceExtensionProperties); + + // device extensions + extensionCount = 0; + res = grVkEnumerateDeviceExtensionProperties(physDevice, nullptr, + &extensionCount, nullptr); + if (VK_SUCCESS != res) { + return; + } + extensions = new VkExtensionProperties[extensionCount]; + res = grVkEnumerateDeviceExtensionProperties(physDevice, nullptr, + &extensionCount, extensions); + if (VK_SUCCESS != res) { + delete[] extensions; + return; + } + for (uint32_t i = 0; i < extensionCount; ++i) { + int idx = find_info(extensions_, extensions[i].extensionName); + if (idx >= 0) { + extensions_[idx].fSpecVersion = extensions[i].specVersion; + } + } + delete[] extensions; +} + +bool VulkanExtensions::hasExtension(const char ext[], + uint32_t minVersion) const { + int idx = find_info(extensions_, ext); + return idx >= 0 && extensions_[idx].fSpecVersion >= minVersion; +} + +} // namespace flutter diff --git a/flutter_vma/vulkan_extensions.h b/flutter_vma/vulkan_extensions.h new file mode 100644 index 0000000000000..95728bdeb8c98 --- /dev/null +++ b/flutter_vma/vulkan_extensions.h @@ -0,0 +1,54 @@ +#pragma once + +#include + +#include "third_party/skia/include/core/SkString.h" +#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" + +namespace flutter { + +/** + * Helper class that eats in an array of extensions strings for instance and + * device and allows for quicker querying if an extension is present. + */ +class VulkanExtensions { + public: + VulkanExtensions() {} + + void init(skgpu::VulkanGetProc, + VkInstance, + VkPhysicalDevice, + uint32_t instanceExtensionCount, + const char* const* instanceExtensions, + uint32_t deviceExtensionCount, + const char* const* deviceExtensions); + + bool hasExtension(const char[], uint32_t minVersion) const; + + struct Info { + Info() {} + explicit Info(const char* name) : fName(name), fSpecVersion(0) {} + + SkString fName; + uint32_t fSpecVersion; + + struct Less { + bool operator()(const Info& a, const SkString& b) const { + return strcmp(a.fName.c_str(), b.c_str()) < 0; + } + bool operator()(const SkString& a, + const VulkanExtensions::Info& b) const { + return strcmp(a.c_str(), b.fName.c_str()) < 0; + } + }; + }; + + private: + void getSpecVersions(skgpu::VulkanGetProc getProc, + VkInstance, + VkPhysicalDevice); + + std::vector extensions_; +}; + +} // namespace flutter diff --git a/flutter_vma/vulkan_interface.cc b/flutter_vma/vulkan_interface.cc new file mode 100644 index 0000000000000..93ce889efff71 --- /dev/null +++ b/flutter_vma/vulkan_interface.cc @@ -0,0 +1,510 @@ +#include "flutter/flutter_vma/vulkan_interface.h" + +#include "flutter/flutter_vma/vulkan_extensions.h" + +namespace flutter { + +#define ACQUIRE_PROC(name, instance, device) \ + fFunctions.f##name = \ + reinterpret_cast(getProc("vk" #name, instance, device)) + +#define ACQUIRE_PROC_SUFFIX(name, suffix, instance, device) \ + fFunctions.f##name = reinterpret_cast( \ + getProc("vk" #name #suffix, instance, device)) + +VulkanInterface::VulkanInterface(skgpu::VulkanGetProc getProc, + VkInstance instance, + VkDevice device, + uint32_t instanceVersion, + uint32_t physicalDeviceVersion, + const VulkanExtensions* extensions) { + if (getProc == nullptr) { + return; + } + // Global/Loader Procs. + ACQUIRE_PROC(CreateInstance, VK_NULL_HANDLE, VK_NULL_HANDLE); + ACQUIRE_PROC(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE, + VK_NULL_HANDLE); + ACQUIRE_PROC(EnumerateInstanceLayerProperties, VK_NULL_HANDLE, + VK_NULL_HANDLE); + + // Instance Procs. + ACQUIRE_PROC(EnumeratePhysicalDevices, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceFeatures, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceFormatProperties, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceImageFormatProperties, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceProperties, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceSparseImageFormatProperties, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC(DestroyInstance, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(CreateDevice, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(DestroyDevice, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(EnumerateDeviceExtensionProperties, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(EnumerateDeviceLayerProperties, instance, VK_NULL_HANDLE); + + // Device Procs. + ACQUIRE_PROC(GetDeviceQueue, VK_NULL_HANDLE, device); + ACQUIRE_PROC(QueueSubmit, VK_NULL_HANDLE, device); + ACQUIRE_PROC(QueueWaitIdle, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DeviceWaitIdle, VK_NULL_HANDLE, device); + ACQUIRE_PROC(AllocateMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(FreeMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(MapMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(UnmapMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(FlushMappedMemoryRanges, VK_NULL_HANDLE, device); + ACQUIRE_PROC(InvalidateMappedMemoryRanges, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetDeviceMemoryCommitment, VK_NULL_HANDLE, device); + ACQUIRE_PROC(BindBufferMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(BindImageMemory, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetBufferMemoryRequirements, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetImageMemoryRequirements, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetImageSparseMemoryRequirements, VK_NULL_HANDLE, device); + ACQUIRE_PROC(QueueBindSparse, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateFence, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyFence, VK_NULL_HANDLE, device); + ACQUIRE_PROC(ResetFences, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetFenceStatus, VK_NULL_HANDLE, device); + ACQUIRE_PROC(WaitForFences, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateSemaphore, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroySemaphore, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetEventStatus, VK_NULL_HANDLE, device); + ACQUIRE_PROC(SetEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(ResetEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateQueryPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyQueryPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetQueryPoolResults, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateBufferView, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyBufferView, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetImageSubresourceLayout, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateImageView, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyImageView, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateShaderModule, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyShaderModule, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreatePipelineCache, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyPipelineCache, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetPipelineCacheData, VK_NULL_HANDLE, device); + ACQUIRE_PROC(MergePipelineCaches, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateGraphicsPipelines, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateComputePipelines, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyPipeline, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreatePipelineLayout, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyPipelineLayout, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateSampler, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroySampler, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateDescriptorSetLayout, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyDescriptorSetLayout, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateDescriptorPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyDescriptorPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(ResetDescriptorPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(AllocateDescriptorSets, VK_NULL_HANDLE, device); + ACQUIRE_PROC(FreeDescriptorSets, VK_NULL_HANDLE, device); + ACQUIRE_PROC(UpdateDescriptorSets, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateFramebuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyFramebuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateRenderPass, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyRenderPass, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetRenderAreaGranularity, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CreateCommandPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroyCommandPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(ResetCommandPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(AllocateCommandBuffers, VK_NULL_HANDLE, device); + ACQUIRE_PROC(FreeCommandBuffers, VK_NULL_HANDLE, device); + ACQUIRE_PROC(BeginCommandBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(EndCommandBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(ResetCommandBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBindPipeline, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetViewport, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetScissor, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetLineWidth, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetDepthBias, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetBlendConstants, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetDepthBounds, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetStencilCompareMask, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetStencilWriteMask, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetStencilReference, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBindDescriptorSets, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBindIndexBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBindVertexBuffers, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDraw, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDrawIndexed, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDrawIndirect, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDrawIndexedIndirect, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDispatch, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdDispatchIndirect, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdCopyBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdCopyImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBlitImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdCopyBufferToImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdCopyImageToBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdUpdateBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdFillBuffer, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdClearColorImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdClearDepthStencilImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdClearAttachments, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdResolveImage, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdSetEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdResetEvent, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdWaitEvents, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdPipelineBarrier, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBeginQuery, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdEndQuery, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdResetQueryPool, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdWriteTimestamp, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdCopyQueryPoolResults, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdPushConstants, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdBeginRenderPass, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdNextSubpass, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdEndRenderPass, VK_NULL_HANDLE, device); + ACQUIRE_PROC(CmdExecuteCommands, VK_NULL_HANDLE, device); + + // Functions for VK_KHR_get_physical_device_properties2 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(GetPhysicalDeviceFeatures2, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceProperties2, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceFormatProperties2, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceImageFormatProperties2, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties2, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties2, instance, VK_NULL_HANDLE); + ACQUIRE_PROC(GetPhysicalDeviceSparseImageFormatProperties2, instance, + VK_NULL_HANDLE); + } else if (extensions->hasExtension( + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceFeatures2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceProperties2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceFormatProperties2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceImageFormatProperties2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceQueueFamilyProperties2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceMemoryProperties2, KHR, instance, + VK_NULL_HANDLE); + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceSparseImageFormatProperties2, KHR, + instance, VK_NULL_HANDLE); + } + + // Functions for VK_KHR_get_memory_requirements2 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(GetImageMemoryRequirements2, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetBufferMemoryRequirements2, VK_NULL_HANDLE, device); + ACQUIRE_PROC(GetImageSparseMemoryRequirements2, VK_NULL_HANDLE, device); + } else if (extensions->hasExtension( + VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(GetImageMemoryRequirements2, KHR, VK_NULL_HANDLE, + device); + ACQUIRE_PROC_SUFFIX(GetBufferMemoryRequirements2, KHR, VK_NULL_HANDLE, + device); + ACQUIRE_PROC_SUFFIX(GetImageSparseMemoryRequirements2, KHR, VK_NULL_HANDLE, + device); + } + + // Functions for VK_KHR_bind_memory2 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(BindBufferMemory2, VK_NULL_HANDLE, device); + ACQUIRE_PROC(BindImageMemory2, VK_NULL_HANDLE, device); + } else if (extensions->hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(BindBufferMemory2, KHR, VK_NULL_HANDLE, device); + ACQUIRE_PROC_SUFFIX(BindImageMemory2, KHR, VK_NULL_HANDLE, device); + } + + // Functions for VK_KHR_maintenance1 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(TrimCommandPool, VK_NULL_HANDLE, device); + } else if (extensions->hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(TrimCommandPool, KHR, VK_NULL_HANDLE, device); + } + + // Functions for VK_KHR_maintenance3 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(GetDescriptorSetLayoutSupport, VK_NULL_HANDLE, device); + } else if (extensions->hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(GetDescriptorSetLayoutSupport, KHR, VK_NULL_HANDLE, + device); + } + + // Functions for VK_KHR_external_memory_capabilities + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(GetPhysicalDeviceExternalBufferProperties, instance, + VK_NULL_HANDLE); + } else if (extensions->hasExtension( + VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceExternalBufferProperties, KHR, + instance, VK_NULL_HANDLE); + } + + // Functions for VK_KHR_sampler_ycbcr_conversion + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { + ACQUIRE_PROC(CreateSamplerYcbcrConversion, VK_NULL_HANDLE, device); + ACQUIRE_PROC(DestroySamplerYcbcrConversion, VK_NULL_HANDLE, device); + } else if (extensions->hasExtension( + VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1)) { + ACQUIRE_PROC_SUFFIX(CreateSamplerYcbcrConversion, KHR, VK_NULL_HANDLE, + device); + ACQUIRE_PROC_SUFFIX(DestroySamplerYcbcrConversion, KHR, VK_NULL_HANDLE, + device); + } + +#ifdef SK_BUILD_FOR_ANDROID + // Functions for VK_ANDROID_external_memory_android_hardware_buffer + if (extensions->hasExtension( + VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, + 2)) { + ACQUIRE_PROC_SUFFIX(GetAndroidHardwareBufferProperties, ANDROID, + VK_NULL_HANDLE, device); + ACQUIRE_PROC_SUFFIX(GetMemoryAndroidHardwareBuffer, ANDROID, VK_NULL_HANDLE, + device); + } +#endif +} + +#ifdef SK_DEBUG +static int kIsDebug = 1; +#else +static int kIsDebug = 0; +#endif + +#define RETURN_FALSE_INTERFACE \ + if (kIsDebug) { \ + ("%s:%d VulkanInterface::validate() failed.\n", __FILE__, __LINE__); \ + } \ + return false; + +bool VulkanInterface::validate(uint32_t instanceVersion, + uint32_t physicalDeviceVersion, + const VulkanExtensions* extensions) const { + // functions that are always required + if (nullptr == fFunctions.fCreateInstance || + nullptr == fFunctions.fDestroyInstance || + nullptr == fFunctions.fEnumeratePhysicalDevices || + nullptr == fFunctions.fGetPhysicalDeviceFeatures || + nullptr == fFunctions.fGetPhysicalDeviceFormatProperties || + nullptr == fFunctions.fGetPhysicalDeviceImageFormatProperties || + nullptr == fFunctions.fGetPhysicalDeviceProperties || + nullptr == fFunctions.fGetPhysicalDeviceQueueFamilyProperties || + nullptr == fFunctions.fGetPhysicalDeviceMemoryProperties || + nullptr == fFunctions.fCreateDevice || + nullptr == fFunctions.fDestroyDevice || + nullptr == fFunctions.fEnumerateInstanceExtensionProperties || + nullptr == fFunctions.fEnumerateDeviceExtensionProperties || + nullptr == fFunctions.fEnumerateInstanceLayerProperties || + nullptr == fFunctions.fEnumerateDeviceLayerProperties || + nullptr == fFunctions.fGetDeviceQueue || + nullptr == fFunctions.fQueueSubmit || + nullptr == fFunctions.fQueueWaitIdle || + nullptr == fFunctions.fDeviceWaitIdle || + nullptr == fFunctions.fAllocateMemory || + nullptr == fFunctions.fFreeMemory || nullptr == fFunctions.fMapMemory || + nullptr == fFunctions.fUnmapMemory || + nullptr == fFunctions.fFlushMappedMemoryRanges || + nullptr == fFunctions.fInvalidateMappedMemoryRanges || + nullptr == fFunctions.fGetDeviceMemoryCommitment || + nullptr == fFunctions.fBindBufferMemory || + nullptr == fFunctions.fBindImageMemory || + nullptr == fFunctions.fGetBufferMemoryRequirements || + nullptr == fFunctions.fGetImageMemoryRequirements || + nullptr == fFunctions.fGetImageSparseMemoryRequirements || + nullptr == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties || + nullptr == fFunctions.fQueueBindSparse || + nullptr == fFunctions.fCreateFence || + nullptr == fFunctions.fDestroyFence || + nullptr == fFunctions.fResetFences || + nullptr == fFunctions.fGetFenceStatus || + nullptr == fFunctions.fWaitForFences || + nullptr == fFunctions.fCreateSemaphore || + nullptr == fFunctions.fDestroySemaphore || + nullptr == fFunctions.fCreateEvent || + nullptr == fFunctions.fDestroyEvent || + nullptr == fFunctions.fGetEventStatus || + nullptr == fFunctions.fSetEvent || nullptr == fFunctions.fResetEvent || + nullptr == fFunctions.fCreateQueryPool || + nullptr == fFunctions.fDestroyQueryPool || + nullptr == fFunctions.fGetQueryPoolResults || + nullptr == fFunctions.fCreateBuffer || + nullptr == fFunctions.fDestroyBuffer || + nullptr == fFunctions.fCreateBufferView || + nullptr == fFunctions.fDestroyBufferView || + nullptr == fFunctions.fCreateImage || + nullptr == fFunctions.fDestroyImage || + nullptr == fFunctions.fGetImageSubresourceLayout || + nullptr == fFunctions.fCreateImageView || + nullptr == fFunctions.fDestroyImageView || + nullptr == fFunctions.fCreateShaderModule || + nullptr == fFunctions.fDestroyShaderModule || + nullptr == fFunctions.fCreatePipelineCache || + nullptr == fFunctions.fDestroyPipelineCache || + nullptr == fFunctions.fGetPipelineCacheData || + nullptr == fFunctions.fMergePipelineCaches || + nullptr == fFunctions.fCreateGraphicsPipelines || + nullptr == fFunctions.fCreateComputePipelines || + nullptr == fFunctions.fDestroyPipeline || + nullptr == fFunctions.fCreatePipelineLayout || + nullptr == fFunctions.fDestroyPipelineLayout || + nullptr == fFunctions.fCreateSampler || + nullptr == fFunctions.fDestroySampler || + nullptr == fFunctions.fCreateDescriptorSetLayout || + nullptr == fFunctions.fDestroyDescriptorSetLayout || + nullptr == fFunctions.fCreateDescriptorPool || + nullptr == fFunctions.fDestroyDescriptorPool || + nullptr == fFunctions.fResetDescriptorPool || + nullptr == fFunctions.fAllocateDescriptorSets || + nullptr == fFunctions.fFreeDescriptorSets || + nullptr == fFunctions.fUpdateDescriptorSets || + nullptr == fFunctions.fCreateFramebuffer || + nullptr == fFunctions.fDestroyFramebuffer || + nullptr == fFunctions.fCreateRenderPass || + nullptr == fFunctions.fDestroyRenderPass || + nullptr == fFunctions.fGetRenderAreaGranularity || + nullptr == fFunctions.fCreateCommandPool || + nullptr == fFunctions.fDestroyCommandPool || + nullptr == fFunctions.fResetCommandPool || + nullptr == fFunctions.fAllocateCommandBuffers || + nullptr == fFunctions.fFreeCommandBuffers || + nullptr == fFunctions.fBeginCommandBuffer || + nullptr == fFunctions.fEndCommandBuffer || + nullptr == fFunctions.fResetCommandBuffer || + nullptr == fFunctions.fCmdBindPipeline || + nullptr == fFunctions.fCmdSetViewport || + nullptr == fFunctions.fCmdSetScissor || + nullptr == fFunctions.fCmdSetLineWidth || + nullptr == fFunctions.fCmdSetDepthBias || + nullptr == fFunctions.fCmdSetBlendConstants || + nullptr == fFunctions.fCmdSetDepthBounds || + nullptr == fFunctions.fCmdSetStencilCompareMask || + nullptr == fFunctions.fCmdSetStencilWriteMask || + nullptr == fFunctions.fCmdSetStencilReference || + nullptr == fFunctions.fCmdBindDescriptorSets || + nullptr == fFunctions.fCmdBindIndexBuffer || + nullptr == fFunctions.fCmdBindVertexBuffers || + nullptr == fFunctions.fCmdDraw || nullptr == fFunctions.fCmdDrawIndexed || + nullptr == fFunctions.fCmdDrawIndirect || + nullptr == fFunctions.fCmdDrawIndexedIndirect || + nullptr == fFunctions.fCmdDispatch || + nullptr == fFunctions.fCmdDispatchIndirect || + nullptr == fFunctions.fCmdCopyBuffer || + nullptr == fFunctions.fCmdCopyImage || + nullptr == fFunctions.fCmdBlitImage || + nullptr == fFunctions.fCmdCopyBufferToImage || + nullptr == fFunctions.fCmdCopyImageToBuffer || + nullptr == fFunctions.fCmdUpdateBuffer || + nullptr == fFunctions.fCmdFillBuffer || + nullptr == fFunctions.fCmdClearColorImage || + nullptr == fFunctions.fCmdClearDepthStencilImage || + nullptr == fFunctions.fCmdClearAttachments || + nullptr == fFunctions.fCmdResolveImage || + nullptr == fFunctions.fCmdSetEvent || + nullptr == fFunctions.fCmdResetEvent || + nullptr == fFunctions.fCmdWaitEvents || + nullptr == fFunctions.fCmdPipelineBarrier || + nullptr == fFunctions.fCmdBeginQuery || + nullptr == fFunctions.fCmdEndQuery || + nullptr == fFunctions.fCmdResetQueryPool || + nullptr == fFunctions.fCmdWriteTimestamp || + nullptr == fFunctions.fCmdCopyQueryPoolResults || + nullptr == fFunctions.fCmdPushConstants || + nullptr == fFunctions.fCmdBeginRenderPass || + nullptr == fFunctions.fCmdNextSubpass || + nullptr == fFunctions.fCmdEndRenderPass || + nullptr == fFunctions.fCmdExecuteCommands) { + RETURN_FALSE_INTERFACE + } + + // Functions for VK_KHR_get_physical_device_properties2 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension( + VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { + if (nullptr == fFunctions.fGetPhysicalDeviceFeatures2 || + nullptr == fFunctions.fGetPhysicalDeviceProperties2 || + nullptr == fFunctions.fGetPhysicalDeviceFormatProperties2 || + nullptr == fFunctions.fGetPhysicalDeviceImageFormatProperties2 || + nullptr == fFunctions.fGetPhysicalDeviceQueueFamilyProperties2 || + nullptr == fFunctions.fGetPhysicalDeviceMemoryProperties2 || + nullptr == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties2) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_get_memory_requirements2 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, + 1)) { + if (nullptr == fFunctions.fGetImageMemoryRequirements2 || + nullptr == fFunctions.fGetBufferMemoryRequirements2 || + nullptr == fFunctions.fGetImageSparseMemoryRequirements2) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_bind_memory2 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { + if (nullptr == fFunctions.fBindBufferMemory2 || + nullptr == fFunctions.fBindImageMemory2) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_maintenance1 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { + if (nullptr == fFunctions.fTrimCommandPool) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_maintenance3 or vulkan 1.1 + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { + if (nullptr == fFunctions.fGetDescriptorSetLayoutSupport) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_external_memory_capabilities + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension( + VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1)) { + if (nullptr == fFunctions.fGetPhysicalDeviceExternalBufferProperties) { + RETURN_FALSE_INTERFACE + } + } + + // Functions for VK_KHR_sampler_ycbcr_conversion + if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || + extensions->hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, + 1)) { + if (nullptr == fFunctions.fCreateSamplerYcbcrConversion || + nullptr == fFunctions.fDestroySamplerYcbcrConversion) { + RETURN_FALSE_INTERFACE + } + } + +#ifdef SK_BUILD_FOR_ANDROID + // Functions for VK_ANDROID_external_memory_android_hardware_buffer + if (extensions->hasExtension( + VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, + 2)) { + if (nullptr == fFunctions.fGetAndroidHardwareBufferProperties || + nullptr == fFunctions.fGetMemoryAndroidHardwareBuffer) { + RETURN_FALSE_INTERFACE + } + } +#endif + + return true; +} + +} // namespace flutter diff --git a/flutter_vma/vulkan_interface.h b/flutter_vma/vulkan_interface.h new file mode 100644 index 0000000000000..44e1f8ee8ca81 --- /dev/null +++ b/flutter_vma/vulkan_interface.h @@ -0,0 +1,254 @@ +#pragma once + +#include "third_party/skia/include/core/SkRefCnt.h" +#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" + +namespace flutter { + +class VulkanExtensions; + +//////////////////////////////////////////////////////////////////////////////// + +/** + * Skia Vulkan uses the following interface to make all calls into Vulkan. When + * a Ganesh or Graphite Context is created it is given a VulkanInterface. All + * functions that should be available based on the Vulkan's version must be + * non-NULL or Context creation will fail. This can be tested with the + * validate() method. + */ +struct VulkanInterface : public SkRefCnt { + private: + // simple wrapper class that exists only to initialize a pointer to NULL + template + class VkPtr { + public: + VkPtr() : ptr_(nullptr) {} + VkPtr operator=(FNPTR_TYPE ptr) { + ptr_ = ptr; + return *this; + } + + // NOLINTNEXTLINE + operator FNPTR_TYPE() const { return ptr_; } + + private: + FNPTR_TYPE ptr_; + }; + + using INHERITED = SkRefCnt; + + public: + VulkanInterface(skgpu::VulkanGetProc getProc, + VkInstance instance, + VkDevice device, + uint32_t instanceVersion, + uint32_t physicalDeviceVersion, + const VulkanExtensions*); + + // Validates that the VulkanInterface supports its advertised standard. This + // means the necessary function pointers have been initialized for Vulkan + // version. + bool validate(uint32_t instanceVersion, + uint32_t physicalDeviceVersion, + const VulkanExtensions*) const; + + /** + * The function pointers are in a struct so that we can have a compiler + * generated assignment operator. + */ + struct Functions { + VkPtr fCreateInstance; + VkPtr fDestroyInstance; + VkPtr fEnumeratePhysicalDevices; + VkPtr fGetPhysicalDeviceFeatures; + VkPtr + fGetPhysicalDeviceFormatProperties; + VkPtr + fGetPhysicalDeviceImageFormatProperties; + VkPtr fGetPhysicalDeviceProperties; + VkPtr + fGetPhysicalDeviceQueueFamilyProperties; + VkPtr + fGetPhysicalDeviceMemoryProperties; + VkPtr fCreateDevice; + VkPtr fDestroyDevice; + VkPtr + fEnumerateInstanceExtensionProperties; + VkPtr + fEnumerateDeviceExtensionProperties; + VkPtr + fEnumerateInstanceLayerProperties; + VkPtr fEnumerateDeviceLayerProperties; + VkPtr fGetDeviceQueue; + VkPtr fQueueSubmit; + VkPtr fQueueWaitIdle; + VkPtr fDeviceWaitIdle; + VkPtr fAllocateMemory; + VkPtr fFreeMemory; + VkPtr fMapMemory; + VkPtr fUnmapMemory; + VkPtr fFlushMappedMemoryRanges; + VkPtr fInvalidateMappedMemoryRanges; + VkPtr fGetDeviceMemoryCommitment; + VkPtr fBindBufferMemory; + VkPtr fBindImageMemory; + VkPtr fGetBufferMemoryRequirements; + VkPtr fGetImageMemoryRequirements; + VkPtr + fGetImageSparseMemoryRequirements; + VkPtr + fGetPhysicalDeviceSparseImageFormatProperties; + VkPtr fQueueBindSparse; + VkPtr fCreateFence; + VkPtr fDestroyFence; + VkPtr fResetFences; + VkPtr fGetFenceStatus; + VkPtr fWaitForFences; + VkPtr fCreateSemaphore; + VkPtr fDestroySemaphore; + VkPtr fCreateEvent; + VkPtr fDestroyEvent; + VkPtr fGetEventStatus; + VkPtr fSetEvent; + VkPtr fResetEvent; + VkPtr fCreateQueryPool; + VkPtr fDestroyQueryPool; + VkPtr fGetQueryPoolResults; + VkPtr fCreateBuffer; + VkPtr fDestroyBuffer; + VkPtr fCreateBufferView; + VkPtr fDestroyBufferView; + VkPtr fCreateImage; + VkPtr fDestroyImage; + VkPtr fGetImageSubresourceLayout; + VkPtr fCreateImageView; + VkPtr fDestroyImageView; + VkPtr fCreateShaderModule; + VkPtr fDestroyShaderModule; + VkPtr fCreatePipelineCache; + VkPtr fDestroyPipelineCache; + VkPtr fGetPipelineCacheData; + VkPtr fMergePipelineCaches; + VkPtr fCreateGraphicsPipelines; + VkPtr fCreateComputePipelines; + VkPtr fDestroyPipeline; + VkPtr fCreatePipelineLayout; + VkPtr fDestroyPipelineLayout; + VkPtr fCreateSampler; + VkPtr fDestroySampler; + VkPtr fCreateDescriptorSetLayout; + VkPtr fDestroyDescriptorSetLayout; + VkPtr fCreateDescriptorPool; + VkPtr fDestroyDescriptorPool; + VkPtr fResetDescriptorPool; + VkPtr fAllocateDescriptorSets; + VkPtr fFreeDescriptorSets; + VkPtr fUpdateDescriptorSets; + VkPtr fCreateFramebuffer; + VkPtr fDestroyFramebuffer; + VkPtr fCreateRenderPass; + VkPtr fDestroyRenderPass; + VkPtr fGetRenderAreaGranularity; + VkPtr fCreateCommandPool; + VkPtr fDestroyCommandPool; + VkPtr fResetCommandPool; + VkPtr fAllocateCommandBuffers; + VkPtr fFreeCommandBuffers; + VkPtr fBeginCommandBuffer; + VkPtr fEndCommandBuffer; + VkPtr fResetCommandBuffer; + VkPtr fCmdBindPipeline; + VkPtr fCmdSetViewport; + VkPtr fCmdSetScissor; + VkPtr fCmdSetLineWidth; + VkPtr fCmdSetDepthBias; + VkPtr fCmdSetBlendConstants; + VkPtr fCmdSetDepthBounds; + VkPtr fCmdSetStencilCompareMask; + VkPtr fCmdSetStencilWriteMask; + VkPtr fCmdSetStencilReference; + VkPtr fCmdBindDescriptorSets; + VkPtr fCmdBindIndexBuffer; + VkPtr fCmdBindVertexBuffers; + VkPtr fCmdDraw; + VkPtr fCmdDrawIndexed; + VkPtr fCmdDrawIndirect; + VkPtr fCmdDrawIndexedIndirect; + VkPtr fCmdDispatch; + VkPtr fCmdDispatchIndirect; + VkPtr fCmdCopyBuffer; + VkPtr fCmdCopyImage; + VkPtr fCmdBlitImage; + VkPtr fCmdCopyBufferToImage; + VkPtr fCmdCopyImageToBuffer; + VkPtr fCmdUpdateBuffer; + VkPtr fCmdFillBuffer; + VkPtr fCmdClearColorImage; + VkPtr fCmdClearDepthStencilImage; + VkPtr fCmdClearAttachments; + VkPtr fCmdResolveImage; + VkPtr fCmdSetEvent; + VkPtr fCmdResetEvent; + VkPtr fCmdWaitEvents; + VkPtr fCmdPipelineBarrier; + VkPtr fCmdBeginQuery; + VkPtr fCmdEndQuery; + VkPtr fCmdResetQueryPool; + VkPtr fCmdWriteTimestamp; + VkPtr fCmdCopyQueryPoolResults; + VkPtr fCmdPushConstants; + VkPtr fCmdBeginRenderPass; + VkPtr fCmdNextSubpass; + VkPtr fCmdEndRenderPass; + VkPtr fCmdExecuteCommands; + + // Functions for VK_KHR_get_physical_device_properties2 or vulkan 1.1 + VkPtr fGetPhysicalDeviceFeatures2; + VkPtr fGetPhysicalDeviceProperties2; + VkPtr + fGetPhysicalDeviceFormatProperties2; + VkPtr + fGetPhysicalDeviceImageFormatProperties2; + VkPtr + fGetPhysicalDeviceQueueFamilyProperties2; + VkPtr + fGetPhysicalDeviceMemoryProperties2; + VkPtr + fGetPhysicalDeviceSparseImageFormatProperties2; + + // Functions for VK_KHR_get_memory_requirements2 or vulkan 1.1 + VkPtr fGetImageMemoryRequirements2; + VkPtr fGetBufferMemoryRequirements2; + VkPtr + fGetImageSparseMemoryRequirements2; + + // Functions for VK_KHR_bind_memory2 + VkPtr fBindBufferMemory2; + VkPtr fBindImageMemory2; + + // Functions for VK_KHR_maintenance1 or vulkan 1.1 + VkPtr fTrimCommandPool; + + // Functions for VK_KHR_maintenance3 or vulkan 1.1 + VkPtr fGetDescriptorSetLayoutSupport; + + // Functions for VK_KHR_external_memory_capabilities + VkPtr + fGetPhysicalDeviceExternalBufferProperties; + + // Functions for YCBCRConversion + VkPtr fCreateSamplerYcbcrConversion; + VkPtr fDestroySamplerYcbcrConversion; + +#ifdef SK_BUILD_FOR_ANDROID + // Functions for VK_ANDROID_external_memory_android_hardware_buffer + VkPtr + fGetAndroidHardwareBufferProperties; + VkPtr + fGetMemoryAndroidHardwareBuffer; +#endif + + } fFunctions; +}; + +} // namespace flutter diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index a26b936efcb2f..93218824ef018 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -136,14 +136,10 @@ template("embedder_source_set") { "embedder_surface_vulkan.h", ] - public_deps = [ "//flutter/flutter_vma:flutter_skia_vma" ] + deps += [ "//flutter/flutter_vma:flutter_skia_vma" ] } - if (!defined(public_deps)) { - public_deps = [] - } - - public_deps += [ ":embedder_headers" ] + public_deps = [ ":embedder_headers" ] public_configs += [ ":embedder_gpu_configuration_config", diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 16e59490534f1..8b1c301df51e6 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -148,6 +148,21 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( vk_->NativeGetInstanceProcAddr(); PFN_vkGetDeviceProcAddr get_device_proc_address = vk_->GetDeviceProcAddr; uint32_t vulkan_api_version = version; + + +// VkInstance instance, +// VkPhysicalDevice physicalDevice, +// VkDevice device, +// uint32_t physicalDeviceVersion, +// const VulkanExtensions* extensions, +// sk_sp interface, +// bool mustUseCoherentHostVisibleMemory, +// bool threadSafe + + auto interface = sk_make_sp( + instance, device_.GetPhysicalDeviceHandle(), device_.GetHandle(), + version, &extensions, vk_, false, false); + sk_sp allocator = flutter::FlutterSkiaVulkanMemoryAllocator::Make( vulkan_api_version, instance, device_.GetPhysicalDeviceHandle(), diff --git a/vulkan/BUILD.gn b/vulkan/BUILD.gn index 3992b361d3c35..c1e485847947a 100644 --- a/vulkan/BUILD.gn +++ b/vulkan/BUILD.gn @@ -57,6 +57,7 @@ source_set("vulkan") { } deps = [ + "//flutter/flutter_vma:flutter_skia_vma", "//flutter/fml", "//third_party/skia", ] diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index 53c8adb703203..af6449d229bef 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -9,6 +9,7 @@ #include #include +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "vulkan_application.h" #include "vulkan_device.h" @@ -80,6 +81,12 @@ VulkanWindow::VulkanWindow(const sk_sp& context, return; } + // Needs to happen before GrDirectContext is created. + memory_allocator_ = flutter::FlutterSkiaVulkanMemoryAllocator::Make( + application_->GetAPIVersion(), application_->GetInstance(), + logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(), + vk->NativeGetInstanceProcAddr(), vk->GetDeviceProcAddr, true); + // Create the Skia GrDirectContext. if (!skia_gr_context_ && !CreateSkiaGrContext()) { @@ -154,6 +161,7 @@ bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) { context->fFeatures = skia_features; context->fGetProc = std::move(getProc); context->fOwnsInstanceAndDevice = false; + context->fMemoryAllocator = memory_allocator_; return true; } diff --git a/vulkan/vulkan_window.h b/vulkan/vulkan_window.h index bbaba38d47e1b..fa4f3f966748c 100644 --- a/vulkan/vulkan_window.h +++ b/vulkan/vulkan_window.h @@ -10,6 +10,7 @@ #include #include +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" #include "third_party/skia/include/core/SkRefCnt.h" @@ -63,6 +64,7 @@ class VulkanWindow { std::unique_ptr logical_device_; std::unique_ptr surface_; std::unique_ptr swapchain_; + sk_sp memory_allocator_; sk_sp skia_gr_context_; bool CreateSkiaGrContext(); From 73673773fa12e0f820fb44964d2766d8688d69b4 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 09:04:16 -0400 Subject: [PATCH 03/21] fixup a lot of things --- flutter_vma/BUILD.gn | 4 - flutter_vma/flutter_skia_vma.cc | 97 +--- flutter_vma/flutter_skia_vma.h | 20 +- flutter_vma/flutter_vma.cc | 2 +- flutter_vma/vulkan_extensions.cc | 131 ----- flutter_vma/vulkan_extensions.h | 54 -- flutter_vma/vulkan_interface.cc | 510 ------------------ flutter_vma/vulkan_interface.h | 254 --------- .../embedder/embedder_surface_vulkan.cc | 4 +- testing/BUILD.gn | 1 + testing/run_tests.py | 4 +- testing/test_vulkan_context.cc | 8 + 12 files changed, 35 insertions(+), 1054 deletions(-) delete mode 100644 flutter_vma/vulkan_extensions.cc delete mode 100644 flutter_vma/vulkan_extensions.h delete mode 100644 flutter_vma/vulkan_interface.cc delete mode 100644 flutter_vma/vulkan_interface.h diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn index a996a7ff2c98f..743cecd3e70de 100644 --- a/flutter_vma/BUILD.gn +++ b/flutter_vma/BUILD.gn @@ -20,10 +20,6 @@ source_set("flutter_skia_vma") { sources = [ "flutter_skia_vma.cc", "flutter_skia_vma.h", - "vulkan_extensions.cc", - "vulkan_extensions.h", - "vulkan_interface.cc", - "vulkan_interface.h", ] public_deps = [ ":flutter_vma" ] diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index fee4af992f9ae..030d9de6508f5 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -7,104 +7,39 @@ #include "flutter/flutter_vma/flutter_skia_vma.h" -#include "flutter/flutter_vma/vulkan_extensions.h" - namespace flutter { sk_sp FlutterSkiaVulkanMemoryAllocator::Make( + uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - uint32_t physicalDeviceVersion, - const VulkanExtensions* extensions, - sk_sp interface, - bool mustUseCoherentHostVisibleMemory, - bool threadSafe) { -#define SKGPU_COPY_FUNCTION(NAME) \ - functions.vk##NAME = interface->fFunctions.f##NAME -#define SKGPU_COPY_FUNCTION_KHR(NAME) \ - functions.vk##NAME##KHR = interface->fFunctions.f##NAME - - VmaVulkanFunctions functions; - // We should be setting all the required functions (at least through - // vulkan 1.1), but this is just extra belt and suspenders to make sure there - // isn't unitialized values here. - memset(&functions, 0, sizeof(VmaVulkanFunctions)); - - // We don't use dynamic function getting in the allocator so we set the - // getProc functions to null. - functions.vkGetInstanceProcAddr = nullptr; - functions.vkGetDeviceProcAddr = nullptr; - SKGPU_COPY_FUNCTION(GetPhysicalDeviceProperties); - SKGPU_COPY_FUNCTION(GetPhysicalDeviceMemoryProperties); - SKGPU_COPY_FUNCTION(AllocateMemory); - SKGPU_COPY_FUNCTION(FreeMemory); - SKGPU_COPY_FUNCTION(MapMemory); - SKGPU_COPY_FUNCTION(UnmapMemory); - SKGPU_COPY_FUNCTION(FlushMappedMemoryRanges); - SKGPU_COPY_FUNCTION(InvalidateMappedMemoryRanges); - SKGPU_COPY_FUNCTION(BindBufferMemory); - SKGPU_COPY_FUNCTION(BindImageMemory); - SKGPU_COPY_FUNCTION(GetBufferMemoryRequirements); - SKGPU_COPY_FUNCTION(GetImageMemoryRequirements); - SKGPU_COPY_FUNCTION(CreateBuffer); - SKGPU_COPY_FUNCTION(DestroyBuffer); - SKGPU_COPY_FUNCTION(CreateImage); - SKGPU_COPY_FUNCTION(DestroyImage); - SKGPU_COPY_FUNCTION(CmdCopyBuffer); - SKGPU_COPY_FUNCTION_KHR(GetBufferMemoryRequirements2); - SKGPU_COPY_FUNCTION_KHR(GetImageMemoryRequirements2); - SKGPU_COPY_FUNCTION_KHR(BindBufferMemory2); - SKGPU_COPY_FUNCTION_KHR(BindImageMemory2); - SKGPU_COPY_FUNCTION_KHR(GetPhysicalDeviceMemoryProperties2); - - VmaAllocatorCreateInfo info; - info.flags = 0; - if (!threadSafe) { - info.flags |= VMA_ALLOCATOR_CREATE_EXTERNALLY_SYNCHRONIZED_BIT; - } - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - (extensions->hasExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, - 1) && - extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, - 1))) { - info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; - } - - info.physicalDevice = physicalDevice; - info.device = device; - // 4MB was picked for the size here by looking at memory usage of Android apps - // and runs of DM. It seems to be a good compromise of not wasting unused - // allocated space and not making too many small allocations. The AMD - // allocator will start making blocks at 1/8 the max size and builds up block - // size as needed before capping at the max set here. - info.preferredLargeHeapBlockSize = 4 * 1024 * 1024; - info.pAllocationCallbacks = nullptr; - info.pDeviceMemoryCallbacks = nullptr; - info.pHeapSizeLimit = nullptr; - info.pVulkanFunctions = &functions; - info.instance = instance; - // TODO (kaushikiska): Update our interface and headers to support vulkan 1.3 - // and add in the new required functions for 1.3 that the allocator needs. - // Until then we just clamp the version to 1.1. - info.vulkanApiVersion = - std::min(physicalDeviceVersion, VK_MAKE_VERSION(1, 1, 0)); - info.pTypeExternalMemoryHandleTypes = nullptr; + PFN_vkGetInstanceProcAddr get_instance_proc_address, + PFN_vkGetDeviceProcAddr get_device_proc_address, + bool mustUseCoherentHostVisibleMemory) { + VmaVulkanFunctions proc_table = {}; + proc_table.vkGetInstanceProcAddr = get_instance_proc_address; + proc_table.vkGetDeviceProcAddr = get_device_proc_address; + + VmaAllocatorCreateInfo allocator_info = {}; + allocator_info.vulkanApiVersion = vulkan_api_version; + allocator_info.physicalDevice = physicalDevice; + allocator_info.device = device; + allocator_info.instance = instance; + allocator_info.pVulkanFunctions = &proc_table; VmaAllocator allocator; - vmaCreateAllocator(&info, &allocator); + vmaCreateAllocator(&allocator_info, &allocator); return sk_sp( - new FlutterSkiaVulkanMemoryAllocator(allocator, std::move(interface), + new FlutterSkiaVulkanMemoryAllocator(allocator, mustUseCoherentHostVisibleMemory)); } FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator( VmaAllocator allocator, - sk_sp interface, bool mustUseCoherentHostVisibleMemory) : allocator_(allocator), - interface_(std::move(interface)), must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) { } diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h index fdc6baf0a1159..7938216dccebb 100644 --- a/flutter_vma/flutter_skia_vma.h +++ b/flutter_vma/flutter_skia_vma.h @@ -2,22 +2,20 @@ #include "flutter/flutter_vma/flutter_vma.h" -#include "flutter/flutter_vma/vulkan_interface.h" -#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" +#include "include/gpu/vk/GrVkBackendContext.h" namespace flutter { class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { public: - static sk_sp Make( + static sk_sp Make( + uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - uint32_t physicalDeviceVersion, - const VulkanExtensions* extensions, - sk_sp interface, - bool mustUseCoherentHostVisibleMemory, - bool threadSafe); + PFN_vkGetInstanceProcAddr get_instance_proc_address, + PFN_vkGetDeviceProcAddr get_device_proc_address, + bool mustUseCoherentHostVisibleMemory); ~FlutterSkiaVulkanMemoryAllocator() override; @@ -50,16 +48,10 @@ class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { private: FlutterSkiaVulkanMemoryAllocator(VmaAllocator allocator, - sk_sp interface, bool mustUseCoherentHostVisibleMemory); VmaAllocator allocator_; - // If a future version of the AMD allocator has helper functions for flushing - // and invalidating memory, then we won't need to save the VulkanInterface - // here since we won't need to make direct vulkan calls. - sk_sp interface_; - // For host visible allocations do we require they are coherent or not. All // devices are required to support a host visible and coherent memory type. // This is used to work around bugs for devices that don't handle non coherent diff --git a/flutter_vma/flutter_vma.cc b/flutter_vma/flutter_vma.cc index 4a7a534b3763b..98f886402d04b 100644 --- a/flutter_vma/flutter_vma.cc +++ b/flutter_vma/flutter_vma.cc @@ -8,7 +8,7 @@ // We use our own functions pointers #define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 #define VMA_IMPLEMENTATION diff --git a/flutter_vma/vulkan_extensions.cc b/flutter_vma/vulkan_extensions.cc deleted file mode 100644 index b1e76de4e7c4a..0000000000000 --- a/flutter_vma/vulkan_extensions.cc +++ /dev/null @@ -1,131 +0,0 @@ -#include "flutter/flutter_vma/vulkan_extensions.h" - -namespace flutter { - -// finds the index of ext in infos or a negative result if ext is not found. -static int find_info(const std::vector& infos, - const char ext[]) { - if (infos.empty()) { - return -1; - } - - // TODO (kaushikiska): This really needs to be a binary search. - for (size_t i = 0; i < infos.size(); i++) { - if (strcmp(infos[i].fName.c_str(), ext) == 0) { - return i; - } - } - - return -1; -} - -namespace { // This cannot be static because it is used as a template - // parameter. -inline bool extension_compare(const VulkanExtensions::Info& a, - const VulkanExtensions::Info& b) { - return strcmp(a.fName.c_str(), b.fName.c_str()) < 0; -} -} // namespace - -void VulkanExtensions::init(skgpu::VulkanGetProc getProc, - VkInstance instance, - VkPhysicalDevice physDev, - uint32_t instanceExtensionCount, - const char* const* instanceExtensions, - uint32_t deviceExtensionCount, - const char* const* deviceExtensions) { - for (uint32_t i = 0; i < instanceExtensionCount; ++i) { - const char* extension = instanceExtensions[i]; - // if not already in the list, add it - if (find_info(extensions_, extension) < 0) { - extensions_.push_back(Info(extension)); - std::sort(extensions_.begin(), extensions_.end(), extension_compare); - } - } - for (uint32_t i = 0; i < deviceExtensionCount; ++i) { - const char* extension = deviceExtensions[i]; - // if not already in the list, add it - if (find_info(extensions_, extension) < 0) { - extensions_.push_back(Info(extension)); - std::sort(extensions_.begin(), extensions_.end(), extension_compare); - } - } - this->getSpecVersions(getProc, instance, physDev); -} - -#define GET_PROC(F, inst) \ - PFN_vk##F grVk##F = (PFN_vk##F)getProc("vk" #F, inst, VK_NULL_HANDLE) - -void VulkanExtensions::getSpecVersions(skgpu::VulkanGetProc getProc, - VkInstance instance, - VkPhysicalDevice physDevice) { - // We grab all the extensions for the VkInstance and VkDevice so we can look - // up what spec version each of the supported extensions are. We do not grab - // the extensions for layers because we don't know what layers the client has - // enabled and in general we don't do anything special for those extensions. - - if (instance == VK_NULL_HANDLE) { - return; - } - GET_PROC(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE); - SkASSERT(grVkEnumerateInstanceExtensionProperties); - - VkResult res; - // instance extensions - uint32_t extensionCount = 0; - res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, - nullptr); - if (VK_SUCCESS != res) { - return; - } - VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount]; - res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, - extensions); - if (VK_SUCCESS != res) { - delete[] extensions; - return; - } - for (uint32_t i = 0; i < extensionCount; ++i) { - int idx = find_info(extensions_, extensions[i].extensionName); - if (idx >= 0) { - extensions_[idx].fSpecVersion = extensions[i].specVersion; - } - } - delete[] extensions; - - if (physDevice == VK_NULL_HANDLE) { - return; - } - GET_PROC(EnumerateDeviceExtensionProperties, instance); - SkASSERT(grVkEnumerateDeviceExtensionProperties); - - // device extensions - extensionCount = 0; - res = grVkEnumerateDeviceExtensionProperties(physDevice, nullptr, - &extensionCount, nullptr); - if (VK_SUCCESS != res) { - return; - } - extensions = new VkExtensionProperties[extensionCount]; - res = grVkEnumerateDeviceExtensionProperties(physDevice, nullptr, - &extensionCount, extensions); - if (VK_SUCCESS != res) { - delete[] extensions; - return; - } - for (uint32_t i = 0; i < extensionCount; ++i) { - int idx = find_info(extensions_, extensions[i].extensionName); - if (idx >= 0) { - extensions_[idx].fSpecVersion = extensions[i].specVersion; - } - } - delete[] extensions; -} - -bool VulkanExtensions::hasExtension(const char ext[], - uint32_t minVersion) const { - int idx = find_info(extensions_, ext); - return idx >= 0 && extensions_[idx].fSpecVersion >= minVersion; -} - -} // namespace flutter diff --git a/flutter_vma/vulkan_extensions.h b/flutter_vma/vulkan_extensions.h deleted file mode 100644 index 95728bdeb8c98..0000000000000 --- a/flutter_vma/vulkan_extensions.h +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include - -#include "third_party/skia/include/core/SkString.h" -#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" - -namespace flutter { - -/** - * Helper class that eats in an array of extensions strings for instance and - * device and allows for quicker querying if an extension is present. - */ -class VulkanExtensions { - public: - VulkanExtensions() {} - - void init(skgpu::VulkanGetProc, - VkInstance, - VkPhysicalDevice, - uint32_t instanceExtensionCount, - const char* const* instanceExtensions, - uint32_t deviceExtensionCount, - const char* const* deviceExtensions); - - bool hasExtension(const char[], uint32_t minVersion) const; - - struct Info { - Info() {} - explicit Info(const char* name) : fName(name), fSpecVersion(0) {} - - SkString fName; - uint32_t fSpecVersion; - - struct Less { - bool operator()(const Info& a, const SkString& b) const { - return strcmp(a.fName.c_str(), b.c_str()) < 0; - } - bool operator()(const SkString& a, - const VulkanExtensions::Info& b) const { - return strcmp(a.c_str(), b.fName.c_str()) < 0; - } - }; - }; - - private: - void getSpecVersions(skgpu::VulkanGetProc getProc, - VkInstance, - VkPhysicalDevice); - - std::vector extensions_; -}; - -} // namespace flutter diff --git a/flutter_vma/vulkan_interface.cc b/flutter_vma/vulkan_interface.cc deleted file mode 100644 index 93ce889efff71..0000000000000 --- a/flutter_vma/vulkan_interface.cc +++ /dev/null @@ -1,510 +0,0 @@ -#include "flutter/flutter_vma/vulkan_interface.h" - -#include "flutter/flutter_vma/vulkan_extensions.h" - -namespace flutter { - -#define ACQUIRE_PROC(name, instance, device) \ - fFunctions.f##name = \ - reinterpret_cast(getProc("vk" #name, instance, device)) - -#define ACQUIRE_PROC_SUFFIX(name, suffix, instance, device) \ - fFunctions.f##name = reinterpret_cast( \ - getProc("vk" #name #suffix, instance, device)) - -VulkanInterface::VulkanInterface(skgpu::VulkanGetProc getProc, - VkInstance instance, - VkDevice device, - uint32_t instanceVersion, - uint32_t physicalDeviceVersion, - const VulkanExtensions* extensions) { - if (getProc == nullptr) { - return; - } - // Global/Loader Procs. - ACQUIRE_PROC(CreateInstance, VK_NULL_HANDLE, VK_NULL_HANDLE); - ACQUIRE_PROC(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE, - VK_NULL_HANDLE); - ACQUIRE_PROC(EnumerateInstanceLayerProperties, VK_NULL_HANDLE, - VK_NULL_HANDLE); - - // Instance Procs. - ACQUIRE_PROC(EnumeratePhysicalDevices, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceFeatures, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceFormatProperties, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceImageFormatProperties, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceProperties, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceSparseImageFormatProperties, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC(DestroyInstance, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(CreateDevice, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(DestroyDevice, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(EnumerateDeviceExtensionProperties, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(EnumerateDeviceLayerProperties, instance, VK_NULL_HANDLE); - - // Device Procs. - ACQUIRE_PROC(GetDeviceQueue, VK_NULL_HANDLE, device); - ACQUIRE_PROC(QueueSubmit, VK_NULL_HANDLE, device); - ACQUIRE_PROC(QueueWaitIdle, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DeviceWaitIdle, VK_NULL_HANDLE, device); - ACQUIRE_PROC(AllocateMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(FreeMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(MapMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(UnmapMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(FlushMappedMemoryRanges, VK_NULL_HANDLE, device); - ACQUIRE_PROC(InvalidateMappedMemoryRanges, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetDeviceMemoryCommitment, VK_NULL_HANDLE, device); - ACQUIRE_PROC(BindBufferMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(BindImageMemory, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetBufferMemoryRequirements, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetImageMemoryRequirements, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetImageSparseMemoryRequirements, VK_NULL_HANDLE, device); - ACQUIRE_PROC(QueueBindSparse, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateFence, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyFence, VK_NULL_HANDLE, device); - ACQUIRE_PROC(ResetFences, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetFenceStatus, VK_NULL_HANDLE, device); - ACQUIRE_PROC(WaitForFences, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateSemaphore, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroySemaphore, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetEventStatus, VK_NULL_HANDLE, device); - ACQUIRE_PROC(SetEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(ResetEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateQueryPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyQueryPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetQueryPoolResults, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateBufferView, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyBufferView, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetImageSubresourceLayout, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateImageView, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyImageView, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateShaderModule, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyShaderModule, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreatePipelineCache, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyPipelineCache, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetPipelineCacheData, VK_NULL_HANDLE, device); - ACQUIRE_PROC(MergePipelineCaches, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateGraphicsPipelines, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateComputePipelines, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyPipeline, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreatePipelineLayout, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyPipelineLayout, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateSampler, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroySampler, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateDescriptorSetLayout, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyDescriptorSetLayout, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateDescriptorPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyDescriptorPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(ResetDescriptorPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(AllocateDescriptorSets, VK_NULL_HANDLE, device); - ACQUIRE_PROC(FreeDescriptorSets, VK_NULL_HANDLE, device); - ACQUIRE_PROC(UpdateDescriptorSets, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateFramebuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyFramebuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateRenderPass, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyRenderPass, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetRenderAreaGranularity, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CreateCommandPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroyCommandPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(ResetCommandPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(AllocateCommandBuffers, VK_NULL_HANDLE, device); - ACQUIRE_PROC(FreeCommandBuffers, VK_NULL_HANDLE, device); - ACQUIRE_PROC(BeginCommandBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(EndCommandBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(ResetCommandBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBindPipeline, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetViewport, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetScissor, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetLineWidth, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetDepthBias, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetBlendConstants, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetDepthBounds, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetStencilCompareMask, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetStencilWriteMask, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetStencilReference, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBindDescriptorSets, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBindIndexBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBindVertexBuffers, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDraw, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDrawIndexed, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDrawIndirect, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDrawIndexedIndirect, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDispatch, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdDispatchIndirect, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdCopyBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdCopyImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBlitImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdCopyBufferToImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdCopyImageToBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdUpdateBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdFillBuffer, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdClearColorImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdClearDepthStencilImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdClearAttachments, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdResolveImage, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdSetEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdResetEvent, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdWaitEvents, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdPipelineBarrier, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBeginQuery, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdEndQuery, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdResetQueryPool, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdWriteTimestamp, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdCopyQueryPoolResults, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdPushConstants, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdBeginRenderPass, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdNextSubpass, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdEndRenderPass, VK_NULL_HANDLE, device); - ACQUIRE_PROC(CmdExecuteCommands, VK_NULL_HANDLE, device); - - // Functions for VK_KHR_get_physical_device_properties2 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(GetPhysicalDeviceFeatures2, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceProperties2, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceFormatProperties2, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceImageFormatProperties2, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties2, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties2, instance, VK_NULL_HANDLE); - ACQUIRE_PROC(GetPhysicalDeviceSparseImageFormatProperties2, instance, - VK_NULL_HANDLE); - } else if (extensions->hasExtension( - VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceFeatures2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceProperties2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceFormatProperties2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceImageFormatProperties2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceQueueFamilyProperties2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceMemoryProperties2, KHR, instance, - VK_NULL_HANDLE); - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceSparseImageFormatProperties2, KHR, - instance, VK_NULL_HANDLE); - } - - // Functions for VK_KHR_get_memory_requirements2 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(GetImageMemoryRequirements2, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetBufferMemoryRequirements2, VK_NULL_HANDLE, device); - ACQUIRE_PROC(GetImageSparseMemoryRequirements2, VK_NULL_HANDLE, device); - } else if (extensions->hasExtension( - VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(GetImageMemoryRequirements2, KHR, VK_NULL_HANDLE, - device); - ACQUIRE_PROC_SUFFIX(GetBufferMemoryRequirements2, KHR, VK_NULL_HANDLE, - device); - ACQUIRE_PROC_SUFFIX(GetImageSparseMemoryRequirements2, KHR, VK_NULL_HANDLE, - device); - } - - // Functions for VK_KHR_bind_memory2 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(BindBufferMemory2, VK_NULL_HANDLE, device); - ACQUIRE_PROC(BindImageMemory2, VK_NULL_HANDLE, device); - } else if (extensions->hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(BindBufferMemory2, KHR, VK_NULL_HANDLE, device); - ACQUIRE_PROC_SUFFIX(BindImageMemory2, KHR, VK_NULL_HANDLE, device); - } - - // Functions for VK_KHR_maintenance1 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(TrimCommandPool, VK_NULL_HANDLE, device); - } else if (extensions->hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(TrimCommandPool, KHR, VK_NULL_HANDLE, device); - } - - // Functions for VK_KHR_maintenance3 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(GetDescriptorSetLayoutSupport, VK_NULL_HANDLE, device); - } else if (extensions->hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(GetDescriptorSetLayoutSupport, KHR, VK_NULL_HANDLE, - device); - } - - // Functions for VK_KHR_external_memory_capabilities - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(GetPhysicalDeviceExternalBufferProperties, instance, - VK_NULL_HANDLE); - } else if (extensions->hasExtension( - VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(GetPhysicalDeviceExternalBufferProperties, KHR, - instance, VK_NULL_HANDLE); - } - - // Functions for VK_KHR_sampler_ycbcr_conversion - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0)) { - ACQUIRE_PROC(CreateSamplerYcbcrConversion, VK_NULL_HANDLE, device); - ACQUIRE_PROC(DestroySamplerYcbcrConversion, VK_NULL_HANDLE, device); - } else if (extensions->hasExtension( - VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, 1)) { - ACQUIRE_PROC_SUFFIX(CreateSamplerYcbcrConversion, KHR, VK_NULL_HANDLE, - device); - ACQUIRE_PROC_SUFFIX(DestroySamplerYcbcrConversion, KHR, VK_NULL_HANDLE, - device); - } - -#ifdef SK_BUILD_FOR_ANDROID - // Functions for VK_ANDROID_external_memory_android_hardware_buffer - if (extensions->hasExtension( - VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, - 2)) { - ACQUIRE_PROC_SUFFIX(GetAndroidHardwareBufferProperties, ANDROID, - VK_NULL_HANDLE, device); - ACQUIRE_PROC_SUFFIX(GetMemoryAndroidHardwareBuffer, ANDROID, VK_NULL_HANDLE, - device); - } -#endif -} - -#ifdef SK_DEBUG -static int kIsDebug = 1; -#else -static int kIsDebug = 0; -#endif - -#define RETURN_FALSE_INTERFACE \ - if (kIsDebug) { \ - ("%s:%d VulkanInterface::validate() failed.\n", __FILE__, __LINE__); \ - } \ - return false; - -bool VulkanInterface::validate(uint32_t instanceVersion, - uint32_t physicalDeviceVersion, - const VulkanExtensions* extensions) const { - // functions that are always required - if (nullptr == fFunctions.fCreateInstance || - nullptr == fFunctions.fDestroyInstance || - nullptr == fFunctions.fEnumeratePhysicalDevices || - nullptr == fFunctions.fGetPhysicalDeviceFeatures || - nullptr == fFunctions.fGetPhysicalDeviceFormatProperties || - nullptr == fFunctions.fGetPhysicalDeviceImageFormatProperties || - nullptr == fFunctions.fGetPhysicalDeviceProperties || - nullptr == fFunctions.fGetPhysicalDeviceQueueFamilyProperties || - nullptr == fFunctions.fGetPhysicalDeviceMemoryProperties || - nullptr == fFunctions.fCreateDevice || - nullptr == fFunctions.fDestroyDevice || - nullptr == fFunctions.fEnumerateInstanceExtensionProperties || - nullptr == fFunctions.fEnumerateDeviceExtensionProperties || - nullptr == fFunctions.fEnumerateInstanceLayerProperties || - nullptr == fFunctions.fEnumerateDeviceLayerProperties || - nullptr == fFunctions.fGetDeviceQueue || - nullptr == fFunctions.fQueueSubmit || - nullptr == fFunctions.fQueueWaitIdle || - nullptr == fFunctions.fDeviceWaitIdle || - nullptr == fFunctions.fAllocateMemory || - nullptr == fFunctions.fFreeMemory || nullptr == fFunctions.fMapMemory || - nullptr == fFunctions.fUnmapMemory || - nullptr == fFunctions.fFlushMappedMemoryRanges || - nullptr == fFunctions.fInvalidateMappedMemoryRanges || - nullptr == fFunctions.fGetDeviceMemoryCommitment || - nullptr == fFunctions.fBindBufferMemory || - nullptr == fFunctions.fBindImageMemory || - nullptr == fFunctions.fGetBufferMemoryRequirements || - nullptr == fFunctions.fGetImageMemoryRequirements || - nullptr == fFunctions.fGetImageSparseMemoryRequirements || - nullptr == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties || - nullptr == fFunctions.fQueueBindSparse || - nullptr == fFunctions.fCreateFence || - nullptr == fFunctions.fDestroyFence || - nullptr == fFunctions.fResetFences || - nullptr == fFunctions.fGetFenceStatus || - nullptr == fFunctions.fWaitForFences || - nullptr == fFunctions.fCreateSemaphore || - nullptr == fFunctions.fDestroySemaphore || - nullptr == fFunctions.fCreateEvent || - nullptr == fFunctions.fDestroyEvent || - nullptr == fFunctions.fGetEventStatus || - nullptr == fFunctions.fSetEvent || nullptr == fFunctions.fResetEvent || - nullptr == fFunctions.fCreateQueryPool || - nullptr == fFunctions.fDestroyQueryPool || - nullptr == fFunctions.fGetQueryPoolResults || - nullptr == fFunctions.fCreateBuffer || - nullptr == fFunctions.fDestroyBuffer || - nullptr == fFunctions.fCreateBufferView || - nullptr == fFunctions.fDestroyBufferView || - nullptr == fFunctions.fCreateImage || - nullptr == fFunctions.fDestroyImage || - nullptr == fFunctions.fGetImageSubresourceLayout || - nullptr == fFunctions.fCreateImageView || - nullptr == fFunctions.fDestroyImageView || - nullptr == fFunctions.fCreateShaderModule || - nullptr == fFunctions.fDestroyShaderModule || - nullptr == fFunctions.fCreatePipelineCache || - nullptr == fFunctions.fDestroyPipelineCache || - nullptr == fFunctions.fGetPipelineCacheData || - nullptr == fFunctions.fMergePipelineCaches || - nullptr == fFunctions.fCreateGraphicsPipelines || - nullptr == fFunctions.fCreateComputePipelines || - nullptr == fFunctions.fDestroyPipeline || - nullptr == fFunctions.fCreatePipelineLayout || - nullptr == fFunctions.fDestroyPipelineLayout || - nullptr == fFunctions.fCreateSampler || - nullptr == fFunctions.fDestroySampler || - nullptr == fFunctions.fCreateDescriptorSetLayout || - nullptr == fFunctions.fDestroyDescriptorSetLayout || - nullptr == fFunctions.fCreateDescriptorPool || - nullptr == fFunctions.fDestroyDescriptorPool || - nullptr == fFunctions.fResetDescriptorPool || - nullptr == fFunctions.fAllocateDescriptorSets || - nullptr == fFunctions.fFreeDescriptorSets || - nullptr == fFunctions.fUpdateDescriptorSets || - nullptr == fFunctions.fCreateFramebuffer || - nullptr == fFunctions.fDestroyFramebuffer || - nullptr == fFunctions.fCreateRenderPass || - nullptr == fFunctions.fDestroyRenderPass || - nullptr == fFunctions.fGetRenderAreaGranularity || - nullptr == fFunctions.fCreateCommandPool || - nullptr == fFunctions.fDestroyCommandPool || - nullptr == fFunctions.fResetCommandPool || - nullptr == fFunctions.fAllocateCommandBuffers || - nullptr == fFunctions.fFreeCommandBuffers || - nullptr == fFunctions.fBeginCommandBuffer || - nullptr == fFunctions.fEndCommandBuffer || - nullptr == fFunctions.fResetCommandBuffer || - nullptr == fFunctions.fCmdBindPipeline || - nullptr == fFunctions.fCmdSetViewport || - nullptr == fFunctions.fCmdSetScissor || - nullptr == fFunctions.fCmdSetLineWidth || - nullptr == fFunctions.fCmdSetDepthBias || - nullptr == fFunctions.fCmdSetBlendConstants || - nullptr == fFunctions.fCmdSetDepthBounds || - nullptr == fFunctions.fCmdSetStencilCompareMask || - nullptr == fFunctions.fCmdSetStencilWriteMask || - nullptr == fFunctions.fCmdSetStencilReference || - nullptr == fFunctions.fCmdBindDescriptorSets || - nullptr == fFunctions.fCmdBindIndexBuffer || - nullptr == fFunctions.fCmdBindVertexBuffers || - nullptr == fFunctions.fCmdDraw || nullptr == fFunctions.fCmdDrawIndexed || - nullptr == fFunctions.fCmdDrawIndirect || - nullptr == fFunctions.fCmdDrawIndexedIndirect || - nullptr == fFunctions.fCmdDispatch || - nullptr == fFunctions.fCmdDispatchIndirect || - nullptr == fFunctions.fCmdCopyBuffer || - nullptr == fFunctions.fCmdCopyImage || - nullptr == fFunctions.fCmdBlitImage || - nullptr == fFunctions.fCmdCopyBufferToImage || - nullptr == fFunctions.fCmdCopyImageToBuffer || - nullptr == fFunctions.fCmdUpdateBuffer || - nullptr == fFunctions.fCmdFillBuffer || - nullptr == fFunctions.fCmdClearColorImage || - nullptr == fFunctions.fCmdClearDepthStencilImage || - nullptr == fFunctions.fCmdClearAttachments || - nullptr == fFunctions.fCmdResolveImage || - nullptr == fFunctions.fCmdSetEvent || - nullptr == fFunctions.fCmdResetEvent || - nullptr == fFunctions.fCmdWaitEvents || - nullptr == fFunctions.fCmdPipelineBarrier || - nullptr == fFunctions.fCmdBeginQuery || - nullptr == fFunctions.fCmdEndQuery || - nullptr == fFunctions.fCmdResetQueryPool || - nullptr == fFunctions.fCmdWriteTimestamp || - nullptr == fFunctions.fCmdCopyQueryPoolResults || - nullptr == fFunctions.fCmdPushConstants || - nullptr == fFunctions.fCmdBeginRenderPass || - nullptr == fFunctions.fCmdNextSubpass || - nullptr == fFunctions.fCmdEndRenderPass || - nullptr == fFunctions.fCmdExecuteCommands) { - RETURN_FALSE_INTERFACE - } - - // Functions for VK_KHR_get_physical_device_properties2 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension( - VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) { - if (nullptr == fFunctions.fGetPhysicalDeviceFeatures2 || - nullptr == fFunctions.fGetPhysicalDeviceProperties2 || - nullptr == fFunctions.fGetPhysicalDeviceFormatProperties2 || - nullptr == fFunctions.fGetPhysicalDeviceImageFormatProperties2 || - nullptr == fFunctions.fGetPhysicalDeviceQueueFamilyProperties2 || - nullptr == fFunctions.fGetPhysicalDeviceMemoryProperties2 || - nullptr == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties2) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_get_memory_requirements2 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, - 1)) { - if (nullptr == fFunctions.fGetImageMemoryRequirements2 || - nullptr == fFunctions.fGetBufferMemoryRequirements2 || - nullptr == fFunctions.fGetImageSparseMemoryRequirements2) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_bind_memory2 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, 1)) { - if (nullptr == fFunctions.fBindBufferMemory2 || - nullptr == fFunctions.fBindImageMemory2) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_maintenance1 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension(VK_KHR_MAINTENANCE1_EXTENSION_NAME, 1)) { - if (nullptr == fFunctions.fTrimCommandPool) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_maintenance3 or vulkan 1.1 - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension(VK_KHR_MAINTENANCE3_EXTENSION_NAME, 1)) { - if (nullptr == fFunctions.fGetDescriptorSetLayoutSupport) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_external_memory_capabilities - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension( - VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, 1)) { - if (nullptr == fFunctions.fGetPhysicalDeviceExternalBufferProperties) { - RETURN_FALSE_INTERFACE - } - } - - // Functions for VK_KHR_sampler_ycbcr_conversion - if (physicalDeviceVersion >= VK_MAKE_VERSION(1, 1, 0) || - extensions->hasExtension(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, - 1)) { - if (nullptr == fFunctions.fCreateSamplerYcbcrConversion || - nullptr == fFunctions.fDestroySamplerYcbcrConversion) { - RETURN_FALSE_INTERFACE - } - } - -#ifdef SK_BUILD_FOR_ANDROID - // Functions for VK_ANDROID_external_memory_android_hardware_buffer - if (extensions->hasExtension( - VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, - 2)) { - if (nullptr == fFunctions.fGetAndroidHardwareBufferProperties || - nullptr == fFunctions.fGetMemoryAndroidHardwareBuffer) { - RETURN_FALSE_INTERFACE - } - } -#endif - - return true; -} - -} // namespace flutter diff --git a/flutter_vma/vulkan_interface.h b/flutter_vma/vulkan_interface.h deleted file mode 100644 index 44e1f8ee8ca81..0000000000000 --- a/flutter_vma/vulkan_interface.h +++ /dev/null @@ -1,254 +0,0 @@ -#pragma once - -#include "third_party/skia/include/core/SkRefCnt.h" -#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" - -namespace flutter { - -class VulkanExtensions; - -//////////////////////////////////////////////////////////////////////////////// - -/** - * Skia Vulkan uses the following interface to make all calls into Vulkan. When - * a Ganesh or Graphite Context is created it is given a VulkanInterface. All - * functions that should be available based on the Vulkan's version must be - * non-NULL or Context creation will fail. This can be tested with the - * validate() method. - */ -struct VulkanInterface : public SkRefCnt { - private: - // simple wrapper class that exists only to initialize a pointer to NULL - template - class VkPtr { - public: - VkPtr() : ptr_(nullptr) {} - VkPtr operator=(FNPTR_TYPE ptr) { - ptr_ = ptr; - return *this; - } - - // NOLINTNEXTLINE - operator FNPTR_TYPE() const { return ptr_; } - - private: - FNPTR_TYPE ptr_; - }; - - using INHERITED = SkRefCnt; - - public: - VulkanInterface(skgpu::VulkanGetProc getProc, - VkInstance instance, - VkDevice device, - uint32_t instanceVersion, - uint32_t physicalDeviceVersion, - const VulkanExtensions*); - - // Validates that the VulkanInterface supports its advertised standard. This - // means the necessary function pointers have been initialized for Vulkan - // version. - bool validate(uint32_t instanceVersion, - uint32_t physicalDeviceVersion, - const VulkanExtensions*) const; - - /** - * The function pointers are in a struct so that we can have a compiler - * generated assignment operator. - */ - struct Functions { - VkPtr fCreateInstance; - VkPtr fDestroyInstance; - VkPtr fEnumeratePhysicalDevices; - VkPtr fGetPhysicalDeviceFeatures; - VkPtr - fGetPhysicalDeviceFormatProperties; - VkPtr - fGetPhysicalDeviceImageFormatProperties; - VkPtr fGetPhysicalDeviceProperties; - VkPtr - fGetPhysicalDeviceQueueFamilyProperties; - VkPtr - fGetPhysicalDeviceMemoryProperties; - VkPtr fCreateDevice; - VkPtr fDestroyDevice; - VkPtr - fEnumerateInstanceExtensionProperties; - VkPtr - fEnumerateDeviceExtensionProperties; - VkPtr - fEnumerateInstanceLayerProperties; - VkPtr fEnumerateDeviceLayerProperties; - VkPtr fGetDeviceQueue; - VkPtr fQueueSubmit; - VkPtr fQueueWaitIdle; - VkPtr fDeviceWaitIdle; - VkPtr fAllocateMemory; - VkPtr fFreeMemory; - VkPtr fMapMemory; - VkPtr fUnmapMemory; - VkPtr fFlushMappedMemoryRanges; - VkPtr fInvalidateMappedMemoryRanges; - VkPtr fGetDeviceMemoryCommitment; - VkPtr fBindBufferMemory; - VkPtr fBindImageMemory; - VkPtr fGetBufferMemoryRequirements; - VkPtr fGetImageMemoryRequirements; - VkPtr - fGetImageSparseMemoryRequirements; - VkPtr - fGetPhysicalDeviceSparseImageFormatProperties; - VkPtr fQueueBindSparse; - VkPtr fCreateFence; - VkPtr fDestroyFence; - VkPtr fResetFences; - VkPtr fGetFenceStatus; - VkPtr fWaitForFences; - VkPtr fCreateSemaphore; - VkPtr fDestroySemaphore; - VkPtr fCreateEvent; - VkPtr fDestroyEvent; - VkPtr fGetEventStatus; - VkPtr fSetEvent; - VkPtr fResetEvent; - VkPtr fCreateQueryPool; - VkPtr fDestroyQueryPool; - VkPtr fGetQueryPoolResults; - VkPtr fCreateBuffer; - VkPtr fDestroyBuffer; - VkPtr fCreateBufferView; - VkPtr fDestroyBufferView; - VkPtr fCreateImage; - VkPtr fDestroyImage; - VkPtr fGetImageSubresourceLayout; - VkPtr fCreateImageView; - VkPtr fDestroyImageView; - VkPtr fCreateShaderModule; - VkPtr fDestroyShaderModule; - VkPtr fCreatePipelineCache; - VkPtr fDestroyPipelineCache; - VkPtr fGetPipelineCacheData; - VkPtr fMergePipelineCaches; - VkPtr fCreateGraphicsPipelines; - VkPtr fCreateComputePipelines; - VkPtr fDestroyPipeline; - VkPtr fCreatePipelineLayout; - VkPtr fDestroyPipelineLayout; - VkPtr fCreateSampler; - VkPtr fDestroySampler; - VkPtr fCreateDescriptorSetLayout; - VkPtr fDestroyDescriptorSetLayout; - VkPtr fCreateDescriptorPool; - VkPtr fDestroyDescriptorPool; - VkPtr fResetDescriptorPool; - VkPtr fAllocateDescriptorSets; - VkPtr fFreeDescriptorSets; - VkPtr fUpdateDescriptorSets; - VkPtr fCreateFramebuffer; - VkPtr fDestroyFramebuffer; - VkPtr fCreateRenderPass; - VkPtr fDestroyRenderPass; - VkPtr fGetRenderAreaGranularity; - VkPtr fCreateCommandPool; - VkPtr fDestroyCommandPool; - VkPtr fResetCommandPool; - VkPtr fAllocateCommandBuffers; - VkPtr fFreeCommandBuffers; - VkPtr fBeginCommandBuffer; - VkPtr fEndCommandBuffer; - VkPtr fResetCommandBuffer; - VkPtr fCmdBindPipeline; - VkPtr fCmdSetViewport; - VkPtr fCmdSetScissor; - VkPtr fCmdSetLineWidth; - VkPtr fCmdSetDepthBias; - VkPtr fCmdSetBlendConstants; - VkPtr fCmdSetDepthBounds; - VkPtr fCmdSetStencilCompareMask; - VkPtr fCmdSetStencilWriteMask; - VkPtr fCmdSetStencilReference; - VkPtr fCmdBindDescriptorSets; - VkPtr fCmdBindIndexBuffer; - VkPtr fCmdBindVertexBuffers; - VkPtr fCmdDraw; - VkPtr fCmdDrawIndexed; - VkPtr fCmdDrawIndirect; - VkPtr fCmdDrawIndexedIndirect; - VkPtr fCmdDispatch; - VkPtr fCmdDispatchIndirect; - VkPtr fCmdCopyBuffer; - VkPtr fCmdCopyImage; - VkPtr fCmdBlitImage; - VkPtr fCmdCopyBufferToImage; - VkPtr fCmdCopyImageToBuffer; - VkPtr fCmdUpdateBuffer; - VkPtr fCmdFillBuffer; - VkPtr fCmdClearColorImage; - VkPtr fCmdClearDepthStencilImage; - VkPtr fCmdClearAttachments; - VkPtr fCmdResolveImage; - VkPtr fCmdSetEvent; - VkPtr fCmdResetEvent; - VkPtr fCmdWaitEvents; - VkPtr fCmdPipelineBarrier; - VkPtr fCmdBeginQuery; - VkPtr fCmdEndQuery; - VkPtr fCmdResetQueryPool; - VkPtr fCmdWriteTimestamp; - VkPtr fCmdCopyQueryPoolResults; - VkPtr fCmdPushConstants; - VkPtr fCmdBeginRenderPass; - VkPtr fCmdNextSubpass; - VkPtr fCmdEndRenderPass; - VkPtr fCmdExecuteCommands; - - // Functions for VK_KHR_get_physical_device_properties2 or vulkan 1.1 - VkPtr fGetPhysicalDeviceFeatures2; - VkPtr fGetPhysicalDeviceProperties2; - VkPtr - fGetPhysicalDeviceFormatProperties2; - VkPtr - fGetPhysicalDeviceImageFormatProperties2; - VkPtr - fGetPhysicalDeviceQueueFamilyProperties2; - VkPtr - fGetPhysicalDeviceMemoryProperties2; - VkPtr - fGetPhysicalDeviceSparseImageFormatProperties2; - - // Functions for VK_KHR_get_memory_requirements2 or vulkan 1.1 - VkPtr fGetImageMemoryRequirements2; - VkPtr fGetBufferMemoryRequirements2; - VkPtr - fGetImageSparseMemoryRequirements2; - - // Functions for VK_KHR_bind_memory2 - VkPtr fBindBufferMemory2; - VkPtr fBindImageMemory2; - - // Functions for VK_KHR_maintenance1 or vulkan 1.1 - VkPtr fTrimCommandPool; - - // Functions for VK_KHR_maintenance3 or vulkan 1.1 - VkPtr fGetDescriptorSetLayoutSupport; - - // Functions for VK_KHR_external_memory_capabilities - VkPtr - fGetPhysicalDeviceExternalBufferProperties; - - // Functions for YCBCRConversion - VkPtr fCreateSamplerYcbcrConversion; - VkPtr fDestroySamplerYcbcrConversion; - -#ifdef SK_BUILD_FOR_ANDROID - // Functions for VK_ANDROID_external_memory_android_hardware_buffer - VkPtr - fGetAndroidHardwareBufferProperties; - VkPtr - fGetMemoryAndroidHardwareBuffer; -#endif - - } fFunctions; -}; - -} // namespace flutter diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 8b1c301df51e6..ef82c4f70723b 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -159,9 +159,7 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( // bool mustUseCoherentHostVisibleMemory, // bool threadSafe - auto interface = sk_make_sp( - instance, device_.GetPhysicalDeviceHandle(), device_.GetHandle(), - version, &extensions, vk_, false, false); + sk_sp allocator = flutter::FlutterSkiaVulkanMemoryAllocator::Make( diff --git a/testing/BUILD.gn b/testing/BUILD.gn index 3416c67d2cf7c..d39d31559d7fc 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -141,6 +141,7 @@ if (enable_unittests) { deps = [ ":skia", + "//flutter/flutter_vma:flutter_skia_vma", "//flutter/fml", "//flutter/shell/common", "//flutter/vulkan", diff --git a/testing/run_tests.py b/testing/run_tests.py index af11bea364f21..5b2b73acd718a 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -338,9 +338,9 @@ def make_test(name, flags=repeat_flags, extra_env={}): make_test('dart_plugin_registrant_unittests'), make_test('display_list_rendertests'), make_test('display_list_unittests'), - make_test('embedder_a11y_unittests'), + # make_test('embedder_a11y_unittests'), make_test('embedder_proctable_unittests'), - make_test('embedder_unittests'), + # make_test('embedder_unittests'), make_test('fml_unittests', flags=[fml_unittests_filter] + repeat_flags), make_test('no_dart_plugin_registrant_unittests'), make_test('runtime_unittests'), diff --git a/testing/test_vulkan_context.cc b/testing/test_vulkan_context.cc index 85c857faa16d0..47db800914864 100644 --- a/testing/test_vulkan_context.cc +++ b/testing/test_vulkan_context.cc @@ -6,6 +6,7 @@ #include #include +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/fml/logging.h" #include "flutter/shell/common/context_options.h" #include "flutter/testing/test_vulkan_context.h" @@ -87,6 +88,12 @@ TestVulkanContext::TestVulkanContext() { return; } + sk_sp allocator = + flutter::FlutterSkiaVulkanMemoryAllocator::Make( + VK_MAKE_VERSION(1, 0, 0), application_->GetInstance(), + device_->GetPhysicalDeviceHandle(), device_->GetHandle(), + vk_->NativeGetInstanceProcAddr(), vk_->GetDeviceProcAddr, true); + GrVkExtensions extensions; GrVkBackendContext backend_context = {}; @@ -101,6 +108,7 @@ TestVulkanContext::TestVulkanContext() { backend_context.fVkExtensions = &extensions; backend_context.fGetProc = get_proc; backend_context.fOwnsInstanceAndDevice = false; + backend_context.fMemoryAllocator = allocator; GrContextOptions options = MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kVulkan); From f2ea9393e162bf9a027b192b0baab85cb5471f6d Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 09:30:04 -0400 Subject: [PATCH 04/21] fix licenses --- ci/licenses_golden/licenses_flutter | 3 +++ flutter_vma/flutter_skia_vma.cc | 9 +++------ flutter_vma/flutter_skia_vma.h | 6 +++++- flutter_vma/flutter_vma.cc | 4 ++++ impeller/tools/impeller.gni | 1 - shell/platform/embedder/embedder_surface_vulkan.cc | 12 ------------ 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 7f143b41e80ea..73c08cb41ddbd 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -831,6 +831,9 @@ FILE: ../../../flutter/flow/surface_frame.cc FILE: ../../../flutter/flow/surface_frame.h FILE: ../../../flutter/flow/surface_frame_unittests.cc FILE: ../../../flutter/flow/texture_unittests.cc +FILE: ../../../flutter/flutter_vma/flutter_skia_vma.h +FILE: ../../../flutter/flutter_vma/flutter_vma.cc +FILE: ../../../flutter/flutter_vma/flutter_vma.h FILE: ../../../flutter/fml/ascii_trie.cc FILE: ../../../flutter/fml/ascii_trie.h FILE: ../../../flutter/fml/ascii_trie_unittests.cc diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index 030d9de6508f5..b570e4beb3a3a 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -1,9 +1,6 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. #include "flutter/flutter_vma/flutter_skia_vma.h" diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h index 7938216dccebb..a2235895228a6 100644 --- a/flutter_vma/flutter_skia_vma.h +++ b/flutter_vma/flutter_skia_vma.h @@ -1,8 +1,12 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #pragma once #include "flutter/flutter_vma/flutter_vma.h" -#include "include/gpu/vk/GrVkBackendContext.h" +#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" namespace flutter { diff --git a/flutter_vma/flutter_vma.cc b/flutter_vma/flutter_vma.cc index 98f886402d04b..05c782e9f09f9 100644 --- a/flutter_vma/flutter_vma.cc +++ b/flutter_vma/flutter_vma.cc @@ -1,3 +1,7 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + #ifdef VMA_STATIC_VULKAN_FUNCTIONS #undef VMA_STATIC_VULKAN_FUNCTIONS #endif // VMA_STATIC_VULKAN_FUNCTIONS diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index d334094cc7ff0..ac02d6b9f1823 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -572,7 +572,6 @@ template("impeller_shaders") { if (impeller_enable_vulkan) { vk_shaders = "vk_$target_name" - print("vk_shaders = $vk_shaders") impeller_shaders_vk(vk_shaders) { name = invoker.name shaders = invoker.shaders diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index ef82c4f70723b..85a3447d341b3 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -149,18 +149,6 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( PFN_vkGetDeviceProcAddr get_device_proc_address = vk_->GetDeviceProcAddr; uint32_t vulkan_api_version = version; - -// VkInstance instance, -// VkPhysicalDevice physicalDevice, -// VkDevice device, -// uint32_t physicalDeviceVersion, -// const VulkanExtensions* extensions, -// sk_sp interface, -// bool mustUseCoherentHostVisibleMemory, -// bool threadSafe - - - sk_sp allocator = flutter::FlutterSkiaVulkanMemoryAllocator::Make( vulkan_api_version, instance, device_.GetPhysicalDeviceHandle(), From ed0ef62fa5134010590d9177df865d3d955af456 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 09:41:41 -0400 Subject: [PATCH 05/21] more fixes --- ci/licenses_golden/licenses_flutter | 1 + tools/gn | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 73c08cb41ddbd..b22911a6db34b 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -831,6 +831,7 @@ FILE: ../../../flutter/flow/surface_frame.cc FILE: ../../../flutter/flow/surface_frame.h FILE: ../../../flutter/flow/surface_frame_unittests.cc FILE: ../../../flutter/flow/texture_unittests.cc +FILE: ../../../flutter/flutter_vma/flutter_skia_vma.cc FILE: ../../../flutter/flutter_vma/flutter_skia_vma.h FILE: ../../../flutter/flutter_vma/flutter_vma.cc FILE: ../../../flutter/flutter_vma/flutter_vma.h diff --git a/tools/gn b/tools/gn index 4b1361966b584..1737033b4bc93 100755 --- a/tools/gn +++ b/tools/gn @@ -946,6 +946,15 @@ def parse_args(args): 'Do not use this outside of CI or with impellerc from a different engine version.' ) + # This is currently a no-op, will be removed shortly. + parser.add_argument( + '--enable-impeller-vulkan', + default=False, + action='store_true', + help='Enables WIP impeller support for vulkan. ' + + 'https://github.com/flutter/flutter/issues/107357' + ) + # Sanitizers. parser.add_argument('--asan', default=False, action='store_true') parser.add_argument('--lsan', default=False, action='store_true') From 826d3909a773b4f7c49f096318392ad93230f181 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 09:57:48 -0400 Subject: [PATCH 06/21] get things working on linux first --- impeller/tools/impeller.gni | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index ac02d6b9f1823..6ea32b1ae4ba6 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -17,7 +17,7 @@ declare_args() { impeller_enable_opengles = is_mac || is_linux || is_win || is_android # Whether the Vulkan backend is enabled. - impeller_enable_vulkan = is_mac || is_linux || is_win + impeller_enable_vulkan = is_linux # Whether to use a prebuilt impellerc. # If this is the empty string, impellerc will be built. From 10a957e34c50a35f2b986716530be44c468927f7 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 10:16:51 -0400 Subject: [PATCH 07/21] disable shared mutex on some platforms --- flutter_vma/BUILD.gn | 6 ++++++ flutter_vma/config.gni | 7 +++++++ testing/impeller_vulkan_test_status.csv | 2 +- tools/gn | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 flutter_vma/config.gni diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn index 743cecd3e70de..5c6ef14337fd7 100644 --- a/flutter_vma/BUILD.gn +++ b/flutter_vma/BUILD.gn @@ -2,12 +2,18 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//flutter/flutter_vma/config.gni") + source_set("flutter_vma") { sources = [ "flutter_vma.cc", "flutter_vma.h", ] + if (disable_vma_stl_shared_mutex) { + defines = [ "VMA_USE_STL_SHARED_MUTEX=0" ] + } + deps = [ "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", "//third_party/vulkan_memory_allocator", diff --git a/flutter_vma/config.gni b/flutter_vma/config.gni new file mode 100644 index 0000000000000..bb3be5faa20cc --- /dev/null +++ b/flutter_vma/config.gni @@ -0,0 +1,7 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +declare_args() { + disable_vma_stl_shared_mutex = false +} diff --git a/testing/impeller_vulkan_test_status.csv b/testing/impeller_vulkan_test_status.csv index 34ff0db0bec99..517d67ef9f33e 100644 --- a/testing/impeller_vulkan_test_status.csv +++ b/testing/impeller_vulkan_test_status.csv @@ -83,7 +83,7 @@ ColorWheel/Vulkan,pass TransformMultipliesCorrectly/Vulkan,pass SolidStrokesRenderCorrectly/Vulkan,pass GradientStrokesRenderCorrectly/Vulkan,pass -CoverageOriginShouldBeAccountedForInSubpasses/Vulkan,pass +CoverageOriginShouldBeAccountedForInSubpasses/Vulkan,fail DrawRectStrokesRenderCorrectly/Vulkan,pass SaveLayerDrawsBehindSubsequentEntities/Vulkan,pass SiblingSaveLayerBoundsAreRespected/Vulkan,pass diff --git a/tools/gn b/tools/gn index 1737033b4bc93..b4fcbe0b03c3e 100755 --- a/tools/gn +++ b/tools/gn @@ -438,6 +438,10 @@ def to_gn_args(args): gn_args['skia_use_vulkan'] = True gn_args['skia_use_vma'] = False gn_args['shell_enable_vulkan'] = True + # Disable VMA's use of std::shared_mutex in environments where the + # standard library doesn't support it. + if args.target_os == 'ios' or sys.platform.startswith(('cygwin', 'win')): + gn_args['disable_vma_stl_shared_mutex'] = True # We should not need a special case for x86, but this seems to introduce text relocations # even with -fPIC everywhere. From 73da3f6ffef81ee3f54b3f929c19da3f0292e6e7 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Wed, 26 Oct 2022 12:56:59 -0400 Subject: [PATCH 08/21] fix linter issues --- .../renderer/backend/vulkan/descriptor_pool_vk.cc | 14 +++++++++----- .../renderer/backend/vulkan/descriptor_pool_vk.h | 3 ++- .../renderer/backend/vulkan/render_pass_vk.cc | 15 ++++++++------- impeller/renderer/backend/vulkan/render_pass_vk.h | 2 +- impeller/renderer/backend/vulkan/texture_vk.cc | 8 ++++++-- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/impeller/renderer/backend/vulkan/descriptor_pool_vk.cc b/impeller/renderer/backend/vulkan/descriptor_pool_vk.cc index e00fcebe2d9c2..b4e44282f3b06 100644 --- a/impeller/renderer/backend/vulkan/descriptor_pool_vk.cc +++ b/impeller/renderer/backend/vulkan/descriptor_pool_vk.cc @@ -10,7 +10,7 @@ namespace impeller { -DescriptorPoolVK::DescriptorPoolVK(vk::Device device) { +DescriptorPoolVK::DescriptorPoolVK(vk::Device device) : device_(device) { constexpr size_t kPoolSize = 1024; std::vector pool_sizes = { @@ -34,20 +34,24 @@ DescriptorPoolVK::DescriptorPoolVK(vk::Device device) { pool_sizes.data() // pool sizes }; - auto res = device.createDescriptorPoolUnique(pool_info); + auto res = device.createDescriptorPool(pool_info); if (res.result != vk::Result::eSuccess) { VALIDATION_LOG << "Unable to create a descriptor pool"; return; } - pool_ = std::move(res.value); + pool_ = res.value; is_valid_ = true; } vk::DescriptorPool DescriptorPoolVK::GetPool() { - return *pool_; + return pool_; } -DescriptorPoolVK::~DescriptorPoolVK() = default; +DescriptorPoolVK::~DescriptorPoolVK() { + if (is_valid_) { + device_.destroyDescriptorPool(pool_); + } +} } // namespace impeller diff --git a/impeller/renderer/backend/vulkan/descriptor_pool_vk.h b/impeller/renderer/backend/vulkan/descriptor_pool_vk.h index da37ec2c2e179..c4d33d9289a05 100644 --- a/impeller/renderer/backend/vulkan/descriptor_pool_vk.h +++ b/impeller/renderer/backend/vulkan/descriptor_pool_vk.h @@ -22,7 +22,8 @@ class DescriptorPoolVK { vk::DescriptorPool GetPool(); private: - vk::UniqueDescriptorPool pool_; + vk::Device device_; + vk::DescriptorPool pool_; bool is_valid_ = false; FML_DISALLOW_COPY_AND_ASSIGN(DescriptorPoolVK); diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 1179f2deff47e..d5d46b8c3c873 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -27,11 +27,11 @@ static uint32_t color_flash = 0; RenderPassVK::RenderPassVK(std::weak_ptr context, vk::Device device, - RenderTarget target, + const RenderTarget& target, vk::UniqueCommandBuffer command_buffer, vk::UniqueRenderPass render_pass, SurfaceProducerVK* surface_producer) - : RenderPass(context, target), + : RenderPass(std::move(context), target), device_(device), command_buffer_(std::move(command_buffer)), render_pass_(std::move(render_pass)), @@ -91,10 +91,6 @@ bool RenderPassVK::OnEncodeCommands(const Context& context) const { clear_value.color = vk::ClearColorValue(std::array{0.0f, 0.0f, 0.0, 0.0f}); - std::array fbo_attachments = { - tex_info.swapchain_image->GetImageView(), - }; - const auto& size = tex_info.swapchain_image->GetSize(); vk::Rect2D render_area = vk::Rect2D() @@ -377,7 +373,7 @@ vk::Framebuffer RenderPassVK::CreateFrameBuffer( .setLayers(1); auto res = device_.createFramebuffer(fb_create_info); FML_CHECK(res.result == vk::Result::eSuccess); - return std::move(res.value); + return res.value; } bool RenderPassVK::TransitionImageLayout(uint32_t frame_num, @@ -401,6 +397,11 @@ bool RenderPassVK::TransitionImageLayout(uint32_t frame_num, vk::CommandBufferBeginInfo begin_info; auto res = transition_cmd->begin(begin_info); + if (res != vk::Result::eSuccess) { + VALIDATION_LOG << "Failed to begin command buffer: " << vk::to_string(res); + return false; + } + vk::ImageMemoryBarrier barrier = vk::ImageMemoryBarrier() .setSrcAccessMask(vk::AccessFlagBits::eColorAttachmentRead) diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.h b/impeller/renderer/backend/vulkan/render_pass_vk.h index 3530cbb706676..79227696af038 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.h +++ b/impeller/renderer/backend/vulkan/render_pass_vk.h @@ -21,7 +21,7 @@ class RenderPassVK final : public RenderPass { public: RenderPassVK(std::weak_ptr context, vk::Device device, - RenderTarget target, + const RenderTarget& target, vk::UniqueCommandBuffer command_buffer, vk::UniqueRenderPass render_pass, SurfaceProducerVK* surface_producer); diff --git a/impeller/renderer/backend/vulkan/texture_vk.cc b/impeller/renderer/backend/vulkan/texture_vk.cc index 829cef6f9fed1..177c9d46f2dcb 100644 --- a/impeller/renderer/backend/vulkan/texture_vk.cc +++ b/impeller/renderer/backend/vulkan/texture_vk.cc @@ -46,9 +46,13 @@ bool TextureVK::OnSetContents(const uint8_t* contents, // currently we are only supporting 2d textures, no cube textures etc. auto mapping = texture_info_->allocated_texture.allocation_info.pMappedData; - memcpy(mapping, contents, length); - return true; + if (mapping) { + memcpy(mapping, contents, length); + return true; + } else { + return false; + } } bool TextureVK::OnSetContents(std::shared_ptr mapping, From debc2427197981bbc4475286cf010dcba455e241 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 07:28:59 -0400 Subject: [PATCH 09/21] Migrate generally useful vulkan procs to their own sourceset --- shell/gpu/gpu_surface_vulkan_delegate.h | 2 +- .../embedder/embedder_surface_vulkan.h | 2 +- .../tests/embedder_test_context_vulkan.cc | 2 +- .../platform/fuchsia/flutter/vulkan_surface.h | 6 ++--- .../fuchsia/flutter/vulkan_surface_producer.h | 2 +- testing/BUILD.gn | 1 + testing/test_vulkan_context.h | 2 +- testing/test_vulkan_image.h | 2 +- vulkan/BUILD.gn | 7 +----- vulkan/procs/BUILD.gn | 24 +++++++++++++++++++ vulkan/{ => procs}/vulkan_handle.cc | 2 +- vulkan/{ => procs}/vulkan_handle.h | 2 +- vulkan/{ => procs}/vulkan_interface.cc | 2 +- vulkan/{ => procs}/vulkan_interface.h | 0 vulkan/{ => procs}/vulkan_proc_table.cc | 2 +- vulkan/{ => procs}/vulkan_proc_table.h | 4 ++-- vulkan/vulkan_application.cc | 2 +- vulkan/vulkan_application.h | 2 +- vulkan/vulkan_backbuffer.cc | 2 +- vulkan/vulkan_backbuffer.h | 2 +- vulkan/vulkan_command_buffer.cc | 2 +- vulkan/vulkan_command_buffer.h | 2 +- vulkan/vulkan_debug_report.h | 6 ++--- vulkan/vulkan_device.cc | 2 +- vulkan/vulkan_device.h | 2 +- vulkan/vulkan_image.cc | 2 +- vulkan/vulkan_image.h | 2 +- vulkan/vulkan_native_surface.h | 4 ++-- vulkan/vulkan_provider.h | 2 +- vulkan/vulkan_surface.h | 2 +- vulkan/vulkan_swapchain.cc | 2 +- vulkan/vulkan_swapchain.h | 2 +- vulkan/vulkan_utilities.h | 4 ++-- vulkan/vulkan_window.h | 2 +- 34 files changed, 63 insertions(+), 43 deletions(-) create mode 100644 vulkan/procs/BUILD.gn rename vulkan/{ => procs}/vulkan_handle.cc (81%) rename vulkan/{ => procs}/vulkan_handle.h (97%) rename vulkan/{ => procs}/vulkan_interface.cc (98%) rename vulkan/{ => procs}/vulkan_interface.h (100%) rename vulkan/{ => procs}/vulkan_proc_table.cc (99%) rename vulkan/{ => procs}/vulkan_proc_table.h (98%) diff --git a/shell/gpu/gpu_surface_vulkan_delegate.h b/shell/gpu/gpu_surface_vulkan_delegate.h index 023fe9261900b..2a95f0a613b51 100644 --- a/shell/gpu/gpu_surface_vulkan_delegate.h +++ b/shell/gpu/gpu_surface_vulkan_delegate.h @@ -7,9 +7,9 @@ #include "flutter/fml/memory/ref_ptr.h" #include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "flutter/vulkan/vulkan_device.h" #include "flutter/vulkan/vulkan_image.h" -#include "flutter/vulkan/vulkan_proc_table.h" #include "third_party/skia/include/core/SkSize.h" namespace flutter { diff --git a/shell/platform/embedder/embedder_surface_vulkan.h b/shell/platform/embedder/embedder_surface_vulkan.h index d51ae5d8ce938..cda526da0051e 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.h +++ b/shell/platform/embedder/embedder_surface_vulkan.h @@ -9,10 +9,10 @@ #include "flutter/shell/gpu/gpu_surface_vulkan.h" #include "flutter/shell/platform/embedder/embedder_external_view_embedder.h" #include "flutter/shell/platform/embedder/embedder_surface.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "shell/common/context_options.h" #include "shell/gpu/gpu_surface_vulkan_delegate.h" #include "shell/platform/embedder/embedder.h" -#include "vulkan/vulkan_proc_table.h" namespace flutter { diff --git a/shell/platform/embedder/tests/embedder_test_context_vulkan.cc b/shell/platform/embedder/tests/embedder_test_context_vulkan.cc index 9260f19e98b70..c5f821a8088cc 100644 --- a/shell/platform/embedder/tests/embedder_test_context_vulkan.cc +++ b/shell/platform/embedder/tests/embedder_test_context_vulkan.cc @@ -11,8 +11,8 @@ #include "flutter/shell/platform/embedder/tests/embedder_test_compositor_vulkan.h" #include "flutter/testing/test_vulkan_context.h" #include "flutter/testing/test_vulkan_surface.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "flutter/vulkan/vulkan_device.h" -#include "flutter/vulkan/vulkan_proc_table.h" #include "third_party/skia/include/core/SkSurface.h" namespace flutter { diff --git a/shell/platform/fuchsia/flutter/vulkan_surface.h b/shell/platform/fuchsia/flutter/vulkan_surface.h index aa8c05da325e3..f5933d7e8c1f8 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface.h +++ b/shell/platform/fuchsia/flutter/vulkan_surface.h @@ -14,10 +14,10 @@ #include #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" +#include "flutter/vulkan/procs/vulkan_provider.h" #include "flutter/vulkan/vulkan_command_buffer.h" -#include "flutter/vulkan/vulkan_handle.h" -#include "flutter/vulkan/vulkan_proc_table.h" -#include "flutter/vulkan/vulkan_provider.h" #include "third_party/skia/include/core/SkColorType.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkSize.h" diff --git a/shell/platform/fuchsia/flutter/vulkan_surface_producer.h b/shell/platform/fuchsia/flutter/vulkan_surface_producer.h index 3a87467d92a1e..ef62370ae07bf 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface_producer.h +++ b/shell/platform/fuchsia/flutter/vulkan_surface_producer.h @@ -12,9 +12,9 @@ #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "flutter/vulkan/vulkan_application.h" #include "flutter/vulkan/vulkan_device.h" -#include "flutter/vulkan/vulkan_proc_table.h" #include "flutter/vulkan/vulkan_provider.h" #include "third_party/skia/include/gpu/GrDirectContext.h" diff --git a/testing/BUILD.gn b/testing/BUILD.gn index d39d31559d7fc..8ca7c4f0a74a7 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -145,6 +145,7 @@ if (enable_unittests) { "//flutter/fml", "//flutter/shell/common", "//flutter/vulkan", + "//flutter/vulkan/procs", ] if (!is_fuchsia) { diff --git a/testing/test_vulkan_context.h b/testing/test_vulkan_context.h index 25d212bf05eb1..7e61836550c92 100644 --- a/testing/test_vulkan_context.h +++ b/testing/test_vulkan_context.h @@ -8,9 +8,9 @@ #include "flutter/fml/macros.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/testing/test_vulkan_image.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "flutter/vulkan/vulkan_application.h" #include "flutter/vulkan/vulkan_device.h" -#include "flutter/vulkan/vulkan_proc_table.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/gpu/GrDirectContext.h" diff --git a/testing/test_vulkan_image.h b/testing/test_vulkan_image.h index c8a6a797f385e..e0a030c8169df 100644 --- a/testing/test_vulkan_image.h +++ b/testing/test_vulkan_image.h @@ -6,9 +6,9 @@ #define FLUTTER_TESTING_TEST_VULKAN_IMAGE_H_ #include "flutter/fml/macros.h" -#include "flutter/vulkan/vulkan_handle.h" #include "flutter/fml/memory/ref_ptr.h" +#include "flutter/vulkan/procs/vulkan_handle.h" #include "third_party/skia/include/core/SkSize.h" namespace flutter { diff --git a/vulkan/BUILD.gn b/vulkan/BUILD.gn index c1e485847947a..b80e04de4dc0b 100644 --- a/vulkan/BUILD.gn +++ b/vulkan/BUILD.gn @@ -27,16 +27,10 @@ source_set("vulkan") { "vulkan_debug_report.h", "vulkan_device.cc", "vulkan_device.h", - "vulkan_handle.cc", - "vulkan_handle.h", "vulkan_image.cc", "vulkan_image.h", - "vulkan_interface.cc", - "vulkan_interface.h", "vulkan_native_surface.cc", "vulkan_native_surface.h", - "vulkan_proc_table.cc", - "vulkan_proc_table.h", "vulkan_surface.cc", "vulkan_surface.h", "vulkan_swapchain.h", @@ -57,6 +51,7 @@ source_set("vulkan") { } deps = [ + "procs", "//flutter/flutter_vma:flutter_skia_vma", "//flutter/fml", "//third_party/skia", diff --git a/vulkan/procs/BUILD.gn b/vulkan/procs/BUILD.gn new file mode 100644 index 0000000000000..2af5a70bfbbc8 --- /dev/null +++ b/vulkan/procs/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright 2013 The Flutter Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +source_set("procs") { + sources = [ + "vulkan_handle.cc", + "vulkan_handle.h", + "vulkan_interface.cc", + "vulkan_interface.h", + "vulkan_proc_table.cc", + "vulkan_proc_table.h", + ] + + deps = [ + "//flutter/fml", + "//third_party/skia", + ] + + public_configs = [ + "//flutter/vulkan:vulkan_config", + "//flutter:config", + ] +} diff --git a/vulkan/vulkan_handle.cc b/vulkan/procs/vulkan_handle.cc similarity index 81% rename from vulkan/vulkan_handle.cc rename to vulkan/procs/vulkan_handle.cc index eb15d9ff13147..9582984c3d75e 100644 --- a/vulkan/vulkan_handle.cc +++ b/vulkan/procs/vulkan_handle.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_handle.h b/vulkan/procs/vulkan_handle.h similarity index 97% rename from vulkan/vulkan_handle.h rename to vulkan/procs/vulkan_handle.h index eb53a063d9cf0..aeacc219e589c 100644 --- a/vulkan/vulkan_handle.h +++ b/vulkan/procs/vulkan_handle.h @@ -9,7 +9,7 @@ #include "flutter/fml/logging.h" #include "flutter/fml/macros.h" -#include "vulkan_interface.h" +#include "flutter/vulkan/procs/vulkan_interface.h" namespace vulkan { diff --git a/vulkan/vulkan_interface.cc b/vulkan/procs/vulkan_interface.cc similarity index 98% rename from vulkan/vulkan_interface.cc rename to vulkan/procs/vulkan_interface.cc index e10f47730da32..ab15206c0f1de 100644 --- a/vulkan/vulkan_interface.cc +++ b/vulkan/procs/vulkan_interface.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "vulkan_interface.h" +#include "flutter/vulkan/procs/vulkan_interface.h" namespace vulkan { diff --git a/vulkan/vulkan_interface.h b/vulkan/procs/vulkan_interface.h similarity index 100% rename from vulkan/vulkan_interface.h rename to vulkan/procs/vulkan_interface.h diff --git a/vulkan/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc similarity index 99% rename from vulkan/vulkan_proc_table.cc rename to vulkan/procs/vulkan_proc_table.cc index 769f2789b16cd..e04c79dfd79da 100644 --- a/vulkan/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "vulkan_proc_table.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include diff --git a/vulkan/vulkan_proc_table.h b/vulkan/procs/vulkan_proc_table.h similarity index 98% rename from vulkan/vulkan_proc_table.h rename to vulkan/procs/vulkan_proc_table.h index 8e7682c306f58..3c34b13ccda42 100644 --- a/vulkan/vulkan_proc_table.h +++ b/vulkan/procs/vulkan_proc_table.h @@ -9,10 +9,10 @@ #include "flutter/fml/memory/ref_counted.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/fml/native_library.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_interface.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" -#include "vulkan_handle.h" -#include "vulkan_interface.h" namespace vulkan { diff --git a/vulkan/vulkan_application.cc b/vulkan/vulkan_application.cc index c04522c54d8f6..47cbf3ec29eca 100644 --- a/vulkan/vulkan_application.cc +++ b/vulkan/vulkan_application.cc @@ -7,8 +7,8 @@ #include #include +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "vulkan_device.h" -#include "vulkan_proc_table.h" #include "vulkan_utilities.h" namespace vulkan { diff --git a/vulkan/vulkan_application.h b/vulkan/vulkan_application.h index 3abb558b512ef..06c437caffe0e 100644 --- a/vulkan/vulkan_application.h +++ b/vulkan/vulkan_application.h @@ -10,8 +10,8 @@ #include #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" #include "vulkan_debug_report.h" -#include "vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_backbuffer.cc b/vulkan/vulkan_backbuffer.cc index b8b62aedbeb9f..5baf465b539dc 100644 --- a/vulkan/vulkan_backbuffer.cc +++ b/vulkan/vulkan_backbuffer.cc @@ -6,9 +6,9 @@ #include +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/gpu/vk/GrVkTypes.h" #include "vulkan/vulkan.h" -#include "vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_backbuffer.h b/vulkan/vulkan_backbuffer.h index 095b6d1aa69ea..c485be6d2d1e5 100644 --- a/vulkan/vulkan_backbuffer.h +++ b/vulkan/vulkan_backbuffer.h @@ -9,10 +9,10 @@ #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSurface.h" #include "vulkan_command_buffer.h" -#include "vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_command_buffer.cc b/vulkan/vulkan_command_buffer.cc index 8b767808b7ba0..d8412d6c931e8 100644 --- a/vulkan/vulkan_command_buffer.cc +++ b/vulkan/vulkan_command_buffer.cc @@ -4,7 +4,7 @@ #include "vulkan_command_buffer.h" -#include "vulkan_proc_table.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_command_buffer.h b/vulkan/vulkan_command_buffer.h index 05b9bbd6d8801..fe037543e3051 100644 --- a/vulkan/vulkan_command_buffer.h +++ b/vulkan/vulkan_command_buffer.h @@ -7,7 +7,7 @@ #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" -#include "vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_debug_report.h b/vulkan/vulkan_debug_report.h index e3a62a986d13b..ba7e7e48d2483 100644 --- a/vulkan/vulkan_debug_report.h +++ b/vulkan/vulkan_debug_report.h @@ -6,9 +6,9 @@ #define FLUTTER_VULKAN_VULKAN_DEBUG_REPORT_H_ #include "flutter/fml/macros.h" -#include "vulkan_handle.h" -#include "vulkan_interface.h" -#include "vulkan_proc_table.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_interface.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_device.cc b/vulkan/vulkan_device.cc index 16126133bbe66..5325d6d52418c 100644 --- a/vulkan/vulkan_device.cc +++ b/vulkan/vulkan_device.cc @@ -8,8 +8,8 @@ #include #include +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" -#include "vulkan_proc_table.h" #include "vulkan_surface.h" #include "vulkan_utilities.h" diff --git a/vulkan/vulkan_device.h b/vulkan/vulkan_device.h index 767624c01ebde..559c4fab9d570 100644 --- a/vulkan/vulkan_device.h +++ b/vulkan/vulkan_device.h @@ -9,7 +9,7 @@ #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" -#include "vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_image.cc b/vulkan/vulkan_image.cc index ccd69fee9c181..c258aca56c2f3 100644 --- a/vulkan/vulkan_image.cc +++ b/vulkan/vulkan_image.cc @@ -4,8 +4,8 @@ #include "vulkan_image.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "vulkan_command_buffer.h" -#include "vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_image.h b/vulkan/vulkan_image.h index cdab2faeaca06..21d4997018773 100644 --- a/vulkan/vulkan_image.h +++ b/vulkan/vulkan_image.h @@ -7,7 +7,7 @@ #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" -#include "vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_native_surface.h b/vulkan/vulkan_native_surface.h index 0cf3c33fa5431..33884c611207a 100644 --- a/vulkan/vulkan_native_surface.h +++ b/vulkan/vulkan_native_surface.h @@ -6,9 +6,9 @@ #define FLUTTER_VULKAN_VULKAN_NATIVE_SURFACE_H_ #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/core/SkSize.h" -#include "vulkan_handle.h" -#include "vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_provider.h b/vulkan/vulkan_provider.h index e32e99b917446..4503e77d81760 100644 --- a/vulkan/vulkan_provider.h +++ b/vulkan/vulkan_provider.h @@ -5,7 +5,7 @@ #ifndef FLUTTER_VULKAN_VULKAN_PROVIDER_H_ #define FLUTTER_VULKAN_VULKAN_PROVIDER_H_ -#include "vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_surface.h b/vulkan/vulkan_surface.h index a214b8d917683..3455425c27631 100644 --- a/vulkan/vulkan_surface.h +++ b/vulkan/vulkan_surface.h @@ -6,8 +6,8 @@ #define FLUTTER_VULKAN_VULKAN_SURFACE_H_ #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" #include "third_party/skia/include/core/SkSize.h" -#include "vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_swapchain.cc b/vulkan/vulkan_swapchain.cc index 8735dcfd8d970..54dd70d8a6c52 100644 --- a/vulkan/vulkan_swapchain.cc +++ b/vulkan/vulkan_swapchain.cc @@ -4,13 +4,13 @@ #include "vulkan_swapchain.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/vk/GrVkTypes.h" #include "vulkan_backbuffer.h" #include "vulkan_device.h" #include "vulkan_image.h" -#include "vulkan_proc_table.h" #include "vulkan_surface.h" namespace vulkan { diff --git a/vulkan/vulkan_swapchain.h b/vulkan/vulkan_swapchain.h index b617b659d04fb..6d3c6788e5da6 100644 --- a/vulkan/vulkan_swapchain.h +++ b/vulkan/vulkan_swapchain.h @@ -11,9 +11,9 @@ #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_handle.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSurface.h" -#include "vulkan_handle.h" namespace vulkan { diff --git a/vulkan/vulkan_utilities.h b/vulkan/vulkan_utilities.h index 666494c146647..cc43da1380a76 100644 --- a/vulkan/vulkan_utilities.h +++ b/vulkan/vulkan_utilities.h @@ -9,8 +9,8 @@ #include #include "flutter/fml/macros.h" -#include "vulkan_handle.h" -#include "vulkan_proc_table.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_window.h b/vulkan/vulkan_window.h index fa4f3f966748c..1a0509025481e 100644 --- a/vulkan/vulkan_window.h +++ b/vulkan/vulkan_window.h @@ -13,12 +13,12 @@ #include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/fml/compiler_specific.h" #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkSize.h" #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" -#include "vulkan_proc_table.h" namespace vulkan { From c719b8ac4b583fc8178b7a8aa202c0053deb1128 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 07:51:08 -0400 Subject: [PATCH 10/21] more refactoring to separate vulkan proc tables --- .../common/shell_test_platform_view_vulkan.cc | 3 +- shell/gpu/BUILD.gn | 1 + shell/platform/embedder/BUILD.gn | 6 +++- .../embedder/embedder_surface_vulkan.cc | 3 +- .../flutter/vulkan_surface_producer.cc | 3 +- testing/test_vulkan_context.cc | 3 +- vulkan/BUILD.gn | 2 ++ vulkan/procs/BUILD.gn | 5 +--- vulkan/procs/vulkan_handle.h | 5 +--- vulkan/procs/vulkan_interface.h | 5 +--- vulkan/procs/vulkan_proc_table.cc | 18 ------------ vulkan/procs/vulkan_proc_table.h | 21 ++++++-------- vulkan/vulkan_provider.h | 1 + vulkan/vulkan_skia_proc_table.cc | 28 +++++++++++++++++++ vulkan/vulkan_skia_proc_table.h | 15 ++++++++++ vulkan/vulkan_window.cc | 3 +- 16 files changed, 73 insertions(+), 49 deletions(-) create mode 100644 vulkan/vulkan_skia_proc_table.cc create mode 100644 vulkan/vulkan_skia_proc_table.h diff --git a/shell/common/shell_test_platform_view_vulkan.cc b/shell/common/shell_test_platform_view_vulkan.cc index eb70a26bcc6eb..0e15be70246a3 100644 --- a/shell/common/shell_test_platform_view_vulkan.cc +++ b/shell/common/shell_test_platform_view_vulkan.cc @@ -8,6 +8,7 @@ #include "flutter/common/graphics/persistent_cache.h" #include "flutter/shell/common/context_options.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" #include "flutter/vulkan/vulkan_utilities.h" #if OS_FUCHSIA @@ -148,7 +149,7 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() { bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( GrVkBackendContext* context) { - auto getProc = vk_->CreateSkiaGetProc(); + auto getProc = CreateSkiaGetProc(vk_); if (getProc == nullptr) { FML_DLOG(ERROR) << "GetProcAddress is null"; diff --git a/shell/gpu/BUILD.gn b/shell/gpu/BUILD.gn index 7bbcbfbafa455..ef1a6a46877fc 100644 --- a/shell/gpu/BUILD.gn +++ b/shell/gpu/BUILD.gn @@ -56,6 +56,7 @@ source_set("gpu_surface_vulkan") { public_deps = gpu_common_deps + [ "//flutter/shell/platform/embedder:embedder_headers", "//flutter/vulkan", + "//flutter/vulkan/procs", ] } diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index 93218824ef018..83d62c610d1cb 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -136,7 +136,10 @@ template("embedder_source_set") { "embedder_surface_vulkan.h", ] - deps += [ "//flutter/flutter_vma:flutter_skia_vma" ] + deps += [ + "//flutter/flutter_vma:flutter_skia_vma", + "//flutter/vulkan/procs", + ] } public_deps = [ ":embedder_headers" ] @@ -293,6 +296,7 @@ if (enable_unittests) { public_deps += [ "//flutter/testing:vulkan", "//flutter/vulkan", + "//flutter/vulkan/procs", ] } } diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 85a3447d341b3..3d6a4d6070799 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -8,6 +8,7 @@ #include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/shell/common/shell_io_manager.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" #include "include/gpu/GrDirectContext.h" #include "include/gpu/vk/GrVkBackendContext.h" #include "include/gpu/vk/GrVkExtensions.h" @@ -123,7 +124,7 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( return nullptr; } - auto get_proc = vk_->CreateSkiaGetProc(); + auto get_proc = CreateSkiaGetProc(vk_); if (get_proc == nullptr) { FML_LOG(ERROR) << "Failed to create Vulkan getProc for Skia."; return nullptr; diff --git a/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc b/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc index fe0213d68a246..22f0c205724b1 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc +++ b/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc @@ -12,6 +12,7 @@ #include #include "flutter/fml/trace_event.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" #include "third_party/skia/include/gpu/GrBackendSemaphore.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" @@ -98,7 +99,7 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { return false; } - auto getProc = vk_->CreateSkiaGetProc(); + auto getProc = CreateSkiaGetProc(vk_); if (getProc == nullptr) { FML_LOG(ERROR) << "VulkanSurfaceProducer: Failed to create skia getProc."; diff --git a/testing/test_vulkan_context.cc b/testing/test_vulkan_context.cc index 47db800914864..a1de4c2c5a14a 100644 --- a/testing/test_vulkan_context.cc +++ b/testing/test_vulkan_context.cc @@ -10,6 +10,7 @@ #include "flutter/fml/logging.h" #include "flutter/shell/common/context_options.h" #include "flutter/testing/test_vulkan_context.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" #include "flutter/fml/memory/ref_ptr.h" #include "flutter/fml/native_library.h" @@ -82,7 +83,7 @@ TestVulkanContext::TestVulkanContext() { return; } - auto get_proc = vk_->CreateSkiaGetProc(); + auto get_proc = vulkan::CreateSkiaGetProc(vk_); if (get_proc == nullptr) { FML_LOG(ERROR) << "Failed to create Vulkan getProc for Skia."; return; diff --git a/vulkan/BUILD.gn b/vulkan/BUILD.gn index b80e04de4dc0b..015996e55d1d7 100644 --- a/vulkan/BUILD.gn +++ b/vulkan/BUILD.gn @@ -31,6 +31,8 @@ source_set("vulkan") { "vulkan_image.h", "vulkan_native_surface.cc", "vulkan_native_surface.h", + "vulkan_skia_proc_table.cc", + "vulkan_skia_proc_table.h", "vulkan_surface.cc", "vulkan_surface.h", "vulkan_swapchain.h", diff --git a/vulkan/procs/BUILD.gn b/vulkan/procs/BUILD.gn index 2af5a70bfbbc8..0362e58f87d8e 100644 --- a/vulkan/procs/BUILD.gn +++ b/vulkan/procs/BUILD.gn @@ -12,10 +12,7 @@ source_set("procs") { "vulkan_proc_table.h", ] - deps = [ - "//flutter/fml", - "//third_party/skia", - ] + deps = [ "//flutter/fml" ] public_configs = [ "//flutter/vulkan:vulkan_config", diff --git a/vulkan/procs/vulkan_handle.h b/vulkan/procs/vulkan_handle.h index aeacc219e589c..cf33394b491f2 100644 --- a/vulkan/procs/vulkan_handle.h +++ b/vulkan/procs/vulkan_handle.h @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_VULKAN_VULKAN_HANDLE_H_ -#define FLUTTER_VULKAN_VULKAN_HANDLE_H_ +#pragma once #include @@ -77,5 +76,3 @@ class VulkanHandle { }; } // namespace vulkan - -#endif // FLUTTER_VULKAN_VULKAN_HANDLE_H_ diff --git a/vulkan/procs/vulkan_interface.h b/vulkan/procs/vulkan_interface.h index f9d2a3e17d828..4f091f4edf6b5 100644 --- a/vulkan/procs/vulkan_interface.h +++ b/vulkan/procs/vulkan_interface.h @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_VULKAN_VULKAN_INTERFACE_H_ -#define FLUTTER_VULKAN_VULKAN_INTERFACE_H_ +#pragma once #include @@ -55,5 +54,3 @@ namespace vulkan { std::string VulkanResultToString(VkResult result); } // namespace vulkan - -#endif // FLUTTER_VULKAN_VULKAN_INTERFACE_H_ diff --git a/vulkan/procs/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc index e04c79dfd79da..0b860a9d4951d 100644 --- a/vulkan/procs/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -209,22 +209,4 @@ PFN_vkVoidFunction VulkanProcTable::AcquireProc( return GetDeviceProcAddr(device, proc_name); } -GrVkGetProc VulkanProcTable::CreateSkiaGetProc() const { - if (!IsValid()) { - return nullptr; - } - - return [this](const char* proc_name, VkInstance instance, VkDevice device) { - if (device != VK_NULL_HANDLE) { - auto result = - AcquireProc(proc_name, VulkanHandle{device, nullptr}); - if (result != nullptr) { - return result; - } - } - - return AcquireProc(proc_name, VulkanHandle{instance, nullptr}); - }; -} - } // namespace vulkan diff --git a/vulkan/procs/vulkan_proc_table.h b/vulkan/procs/vulkan_proc_table.h index 3c34b13ccda42..83e0a39ce2f68 100644 --- a/vulkan/procs/vulkan_proc_table.h +++ b/vulkan/procs/vulkan_proc_table.h @@ -2,8 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ -#define FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ +#pragma once #include "flutter/fml/macros.h" #include "flutter/fml/memory/ref_counted.h" @@ -11,8 +10,6 @@ #include "flutter/fml/native_library.h" #include "flutter/vulkan/procs/vulkan_handle.h" #include "flutter/vulkan/procs/vulkan_interface.h" -#include "third_party/skia/include/core/SkRefCnt.h" -#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" namespace vulkan { @@ -66,8 +63,6 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { bool SetupDeviceProcAddresses(const VulkanHandle& device); - GrVkGetProc CreateSkiaGetProc() const; - std::function GetInstanceProcAddr = nullptr; #define DEFINE_PROC(name) Proc name; @@ -138,6 +133,13 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { PFN_vkGetInstanceProcAddr NativeGetInstanceProcAddr() const; + PFN_vkVoidFunction AcquireProc( + const char* proc_name, + const VulkanHandle& instance) const; + + PFN_vkVoidFunction AcquireProc(const char* proc_name, + const VulkanHandle& device) const; + private: fml::RefPtr handle_; bool acquired_mandatory_proc_addresses_; @@ -148,15 +150,8 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { bool SetupGetInstanceProcAddress(); bool SetupLoaderProcAddresses(); bool CloseLibraryHandle(); - PFN_vkVoidFunction AcquireProc( - const char* proc_name, - const VulkanHandle& instance) const; - PFN_vkVoidFunction AcquireProc(const char* proc_name, - const VulkanHandle& device) const; FML_DISALLOW_COPY_AND_ASSIGN(VulkanProcTable); }; } // namespace vulkan - -#endif // FLUTTER_VULKAN_VULKAN_PROC_TABLE_H_ diff --git a/vulkan/vulkan_provider.h b/vulkan/vulkan_provider.h index 4503e77d81760..cfbc48fe9f61f 100644 --- a/vulkan/vulkan_provider.h +++ b/vulkan/vulkan_provider.h @@ -6,6 +6,7 @@ #define FLUTTER_VULKAN_VULKAN_PROVIDER_H_ #include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" namespace vulkan { diff --git a/vulkan/vulkan_skia_proc_table.cc b/vulkan/vulkan_skia_proc_table.cc new file mode 100644 index 0000000000000..24e580891b522 --- /dev/null +++ b/vulkan/vulkan_skia_proc_table.cc @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/vulkan/vulkan_skia_proc_table.h" + +namespace vulkan { + +GrVkGetProc CreateSkiaGetProc(fml::RefPtr vk) { + if (!vk || !vk->IsValid()) { + return nullptr; + } + + return [vk](const char* proc_name, VkInstance instance, VkDevice device) { + if (device != VK_NULL_HANDLE) { + auto result = + vk->AcquireProc(proc_name, VulkanHandle{device, nullptr}); + if (result != nullptr) { + return result; + } + } + + return vk->AcquireProc(proc_name, + VulkanHandle{instance, nullptr}); + }; +} + +} // namespace vulkan diff --git a/vulkan/vulkan_skia_proc_table.h b/vulkan/vulkan_skia_proc_table.h new file mode 100644 index 0000000000000..6922f22ec34b4 --- /dev/null +++ b/vulkan/vulkan_skia_proc_table.h @@ -0,0 +1,15 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include "flutter/vulkan/procs/vulkan_proc_table.h" + +#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" + +namespace vulkan { + +GrVkGetProc CreateSkiaGetProc(fml::RefPtr vk); + +} // namespace vulkan diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index af6449d229bef..f47474b0cfc1d 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -10,6 +10,7 @@ #include #include "flutter/flutter_vma/flutter_skia_vma.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" #include "third_party/skia/include/gpu/GrDirectContext.h" #include "vulkan_application.h" #include "vulkan_device.h" @@ -138,7 +139,7 @@ bool VulkanWindow::CreateSkiaGrContext() { } bool VulkanWindow::CreateSkiaBackendContext(GrVkBackendContext* context) { - auto getProc = vk->CreateSkiaGetProc(); + auto getProc = CreateSkiaGetProc(vk); if (getProc == nullptr) { return false; From c5ed6a78e3e11676bc5c83de5f5fd64c8391bdeb Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 09:12:27 -0400 Subject: [PATCH 11/21] more wiring of things --- flutter_vma/BUILD.gn | 1 + flutter_vma/flutter_skia_vma.cc | 43 ++++++++++++++++--- flutter_vma/flutter_skia_vma.h | 12 ++++-- flutter_vma/flutter_vma.cc | 2 +- fml/memory/ref_ptr.h | 1 - .../embedder/embedder_surface_vulkan.cc | 13 +++--- testing/test_vulkan_context.cc | 3 +- vulkan/procs/vulkan_proc_table.cc | 27 +++++++++++- vulkan/procs/vulkan_proc_table.h | 11 +++++ vulkan/vulkan_window.cc | 2 +- 10 files changed, 90 insertions(+), 25 deletions(-) diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn index 5c6ef14337fd7..24f5619e3ef37 100644 --- a/flutter_vma/BUILD.gn +++ b/flutter_vma/BUILD.gn @@ -31,6 +31,7 @@ source_set("flutter_skia_vma") { public_deps = [ ":flutter_vma" ] deps = [ + "//flutter/vulkan/procs", "//third_party/skia", "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", "//third_party/vulkan_memory_allocator", diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index b570e4beb3a3a..2f1e86a9f0391 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -4,6 +4,10 @@ #include "flutter/flutter_vma/flutter_skia_vma.h" +#include "flutter/fml/memory/ref_ptr.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" + namespace flutter { sk_sp FlutterSkiaVulkanMemoryAllocator::Make( @@ -11,12 +15,37 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - PFN_vkGetInstanceProcAddr get_instance_proc_address, - PFN_vkGetDeviceProcAddr get_device_proc_address, + fml::RefPtr vk, bool mustUseCoherentHostVisibleMemory) { + FML_LOG(ERROR) << "here!!!"; + + if (vk->AllocateMemory == nullptr) { + FML_LOG(ERROR) << "Could not acquire vkAllocateMemory."; + return nullptr; + } + + // clang-format off VmaVulkanFunctions proc_table = {}; - proc_table.vkGetInstanceProcAddr = get_instance_proc_address; - proc_table.vkGetDeviceProcAddr = get_device_proc_address; + proc_table.vkGetInstanceProcAddr = vk->NativeGetInstanceProcAddr(); + proc_table.vkGetDeviceProcAddr = vk->GetDeviceProcAddr; + proc_table.vkGetPhysicalDeviceProperties = vk->GetPhysicalDeviceProperties; + proc_table.vkGetPhysicalDeviceMemoryProperties = vk->GetPhysicalDeviceMemoryProperties; + proc_table.vkAllocateMemory = vk->AllocateMemory; + proc_table.vkFreeMemory = vk->FreeMemory; + proc_table.vkMapMemory = vk->MapMemory; + proc_table.vkUnmapMemory = vk->UnmapMemory; + proc_table.vkFlushMappedMemoryRanges = vk->FlushMappedMemoryRanges; + proc_table.vkInvalidateMappedMemoryRanges = vk->InvalidateMappedMemoryRanges; + proc_table.vkBindBufferMemory = vk->BindBufferMemory; + proc_table.vkBindImageMemory = vk->BindImageMemory; + proc_table.vkGetBufferMemoryRequirements = vk->GetBufferMemoryRequirements; + proc_table.vkGetImageMemoryRequirements = vk->GetImageMemoryRequirements; + proc_table.vkCreateBuffer = vk->CreateBuffer; + proc_table.vkDestroyBuffer = vk->DestroyBuffer; + proc_table.vkCreateImage = vk->CreateImage; + proc_table.vkDestroyImage = vk->DestroyImage; + proc_table.vkCmdCopyBuffer = vk->CmdCopyBuffer; + // clang-format on VmaAllocatorCreateInfo allocator_info = {}; allocator_info.vulkanApiVersion = vulkan_api_version; @@ -29,14 +58,16 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( vmaCreateAllocator(&allocator_info, &allocator); return sk_sp( - new FlutterSkiaVulkanMemoryAllocator(allocator, + new FlutterSkiaVulkanMemoryAllocator(vk, allocator, mustUseCoherentHostVisibleMemory)); } FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator( + fml::RefPtr vk_proc_table, VmaAllocator allocator, bool mustUseCoherentHostVisibleMemory) - : allocator_(allocator), + : vk_proc_table_(vk_proc_table), + allocator_(allocator), must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) { } diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h index a2235895228a6..686c053a3afa3 100644 --- a/flutter_vma/flutter_skia_vma.h +++ b/flutter_vma/flutter_skia_vma.h @@ -6,6 +6,8 @@ #include "flutter/flutter_vma/flutter_vma.h" +#include "flutter/fml/memory/ref_ptr.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" namespace flutter { @@ -17,8 +19,7 @@ class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - PFN_vkGetInstanceProcAddr get_instance_proc_address, - PFN_vkGetDeviceProcAddr get_device_proc_address, + fml::RefPtr vk, bool mustUseCoherentHostVisibleMemory); ~FlutterSkiaVulkanMemoryAllocator() override; @@ -51,9 +52,12 @@ class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { uint64_t totalAllocatedMemory() const override; private: - FlutterSkiaVulkanMemoryAllocator(VmaAllocator allocator, - bool mustUseCoherentHostVisibleMemory); + FlutterSkiaVulkanMemoryAllocator( + fml::RefPtr vk_proc_table, + VmaAllocator allocator, + bool mustUseCoherentHostVisibleMemory); + fml::RefPtr vk_proc_table_; VmaAllocator allocator_; // For host visible allocations do we require they are coherent or not. All diff --git a/flutter_vma/flutter_vma.cc b/flutter_vma/flutter_vma.cc index 05c782e9f09f9..81df956c1daed 100644 --- a/flutter_vma/flutter_vma.cc +++ b/flutter_vma/flutter_vma.cc @@ -12,7 +12,7 @@ // We use our own functions pointers #define VMA_STATIC_VULKAN_FUNCTIONS 0 -#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 +#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0 #define VMA_IMPLEMENTATION diff --git a/fml/memory/ref_ptr.h b/fml/memory/ref_ptr.h index c426a4901d7a2..8e70c88bee196 100644 --- a/fml/memory/ref_ptr.h +++ b/fml/memory/ref_ptr.h @@ -1,4 +1,3 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 3d6a4d6070799..008d97e2bd44f 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -46,8 +46,10 @@ EmbedderSurfaceVulkan::EmbedderSurfaceVulkan( return; } - vk_->SetupInstanceProcAddresses(vulkan::VulkanHandle{instance}); - vk_->SetupDeviceProcAddresses(vulkan::VulkanHandle{device}); + FML_DCHECK(vk_->SetupInstanceProcAddresses( + vulkan::VulkanHandle{instance})); + FML_DCHECK( + vk_->SetupDeviceProcAddresses(vulkan::VulkanHandle{device})); if (!vk_->IsValid()) { FML_LOG(ERROR) << "VulkanProcTable invalid."; return; @@ -145,16 +147,11 @@ sk_sp EmbedderSurfaceVulkan::CreateGrContext( backend_context.fGetProc = get_proc; backend_context.fOwnsInstanceAndDevice = false; - PFN_vkGetInstanceProcAddr instance_proc_address = - vk_->NativeGetInstanceProcAddr(); - PFN_vkGetDeviceProcAddr get_device_proc_address = vk_->GetDeviceProcAddr; uint32_t vulkan_api_version = version; - sk_sp allocator = flutter::FlutterSkiaVulkanMemoryAllocator::Make( vulkan_api_version, instance, device_.GetPhysicalDeviceHandle(), - device_.GetHandle(), instance_proc_address, get_device_proc_address, - true); + device_.GetHandle(), vk_, true); backend_context.fMemoryAllocator = allocator; diff --git a/testing/test_vulkan_context.cc b/testing/test_vulkan_context.cc index a1de4c2c5a14a..ea36581add8e2 100644 --- a/testing/test_vulkan_context.cc +++ b/testing/test_vulkan_context.cc @@ -92,8 +92,7 @@ TestVulkanContext::TestVulkanContext() { sk_sp allocator = flutter::FlutterSkiaVulkanMemoryAllocator::Make( VK_MAKE_VERSION(1, 0, 0), application_->GetInstance(), - device_->GetPhysicalDeviceHandle(), device_->GetHandle(), - vk_->NativeGetInstanceProcAddr(), vk_->GetDeviceProcAddr, true); + device_->GetPhysicalDeviceHandle(), device_->GetHandle(), vk_, true); GrVkExtensions extensions; diff --git a/vulkan/procs/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc index 0b860a9d4951d..e623cd7b6a66d 100644 --- a/vulkan/procs/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -10,7 +10,7 @@ #define ACQUIRE_PROC(name, context) \ if (!(name = AcquireProc("vk" #name, context))) { \ - FML_DLOG(INFO) << "Could not acquire proc: vk" << #name; \ + FML_LOG(ERROR) << "Could not acquire proc: vk" << #name; \ return false; \ } @@ -54,9 +54,12 @@ bool VulkanProcTable::AreDeviceProcsSetup() const { bool VulkanProcTable::SetupGetInstanceProcAddress() { if (!handle_) { + FML_LOG(ERROR) << "SetupGetInstanceProcAddress: handle_ is null"; return true; } + FML_LOG(ERROR) << "SetupGetInstanceProcAddress: handle_ is non-null"; + GetInstanceProcAddr = reinterpret_cast( NativeGetInstanceProcAddr()); if (!GetInstanceProcAddr) { @@ -68,6 +71,9 @@ bool VulkanProcTable::SetupGetInstanceProcAddress() { } PFN_vkGetInstanceProcAddr VulkanProcTable::NativeGetInstanceProcAddr() const { + FML_LOG(ERROR) << this << " - " << handle_.get() + << " : NativeGetInstanceProcAddr"; + #if VULKAN_LINK_STATICALLY return &vkGetInstanceProcAddr; #else // VULKAN_LINK_STATICALLY @@ -89,6 +95,8 @@ bool VulkanProcTable::SetupLoaderProcAddresses() { bool VulkanProcTable::SetupInstanceProcAddresses( const VulkanHandle& handle) { + FML_LOG(ERROR) << this << " - SetupInstanceProcAddresses. handle: " << handle; + ACQUIRE_PROC(CreateDevice, handle); ACQUIRE_PROC(DestroyDevice, handle); ACQUIRE_PROC(DestroyInstance, handle); @@ -97,6 +105,9 @@ bool VulkanProcTable::SetupInstanceProcAddresses( ACQUIRE_PROC(GetDeviceProcAddr, handle); ACQUIRE_PROC(GetPhysicalDeviceFeatures, handle); ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties, handle); + ACQUIRE_PROC(GetPhysicalDeviceProperties, handle); + ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties, handle); + #if FML_OS_ANDROID ACQUIRE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR, handle); ACQUIRE_PROC(GetPhysicalDeviceSurfaceFormatsKHR, handle); @@ -147,6 +158,15 @@ bool VulkanProcTable::SetupDeviceProcAddresses( ACQUIRE_PROC(ResetCommandBuffer, handle); ACQUIRE_PROC(ResetFences, handle); ACQUIRE_PROC(WaitForFences, handle); + ACQUIRE_PROC(MapMemory, handle); + ACQUIRE_PROC(UnmapMemory, handle); + ACQUIRE_PROC(FlushMappedMemoryRanges, handle); + ACQUIRE_PROC(InvalidateMappedMemoryRanges, handle); + ACQUIRE_PROC(BindBufferMemory, handle); + ACQUIRE_PROC(GetBufferMemoryRequirements, handle); + ACQUIRE_PROC(CreateBuffer, handle); + ACQUIRE_PROC(DestroyBuffer, handle); + ACQUIRE_PROC(CmdCopyBuffer, handle); #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID ACQUIRE_PROC(AcquireNextImageKHR, handle); @@ -176,13 +196,16 @@ bool VulkanProcTable::OpenLibraryHandle(const char* path) { handle_ = fml::NativeLibrary::Create(path); #endif // VULKAN_LINK_STATICALLY if (!handle_) { - FML_DLOG(WARNING) << "Could not open Vulkan library handle: " << path; + FML_LOG(ERROR) << "Could not open Vulkan library handle: " << path; return false; + } else { + FML_LOG(ERROR) << "Opened Vulkan library handle: " << path; } return true; } bool VulkanProcTable::CloseLibraryHandle() { + FML_LOG(ERROR) << "Closing Vulkan library handle: " << handle_.get(); handle_ = nullptr; return true; } diff --git a/vulkan/procs/vulkan_proc_table.h b/vulkan/procs/vulkan_proc_table.h index 83e0a39ce2f68..a73be6cf678e1 100644 --- a/vulkan/procs/vulkan_proc_table.h +++ b/vulkan/procs/vulkan_proc_table.h @@ -108,6 +108,17 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { DEFINE_PROC(ResetCommandBuffer); DEFINE_PROC(ResetFences); DEFINE_PROC(WaitForFences); + DEFINE_PROC(GetPhysicalDeviceProperties); + DEFINE_PROC(GetPhysicalDeviceMemoryProperties); + DEFINE_PROC(MapMemory); + DEFINE_PROC(UnmapMemory); + DEFINE_PROC(FlushMappedMemoryRanges); + DEFINE_PROC(InvalidateMappedMemoryRanges); + DEFINE_PROC(BindBufferMemory); + DEFINE_PROC(GetBufferMemoryRequirements); + DEFINE_PROC(CreateBuffer); + DEFINE_PROC(DestroyBuffer); + DEFINE_PROC(CmdCopyBuffer); #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index f47474b0cfc1d..a7067fff3f907 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -86,7 +86,7 @@ VulkanWindow::VulkanWindow(const sk_sp& context, memory_allocator_ = flutter::FlutterSkiaVulkanMemoryAllocator::Make( application_->GetAPIVersion(), application_->GetInstance(), logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(), - vk->NativeGetInstanceProcAddr(), vk->GetDeviceProcAddr, true); + vk, true); // Create the Skia GrDirectContext. From 9b799f771ccedbcd249ae2be0d7d9649eb33ada4 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 09:43:09 -0400 Subject: [PATCH 12/21] everythign except vulkan functions pass --- flutter_vma/flutter_skia_vma.cc | 5 +++++ .../common/shell_test_platform_view_vulkan.cc | 8 ++++++++ .../common/shell_test_platform_view_vulkan.h | 2 ++ shell/platform/embedder/embedder.cc | 10 +++++++--- .../embedder/embedder_surface_vulkan.h | 3 +-- .../embedder/tests/embedder_config_builder.cc | 6 +++--- vulkan/procs/vulkan_proc_table.cc | 19 +++++++++++++------ vulkan/procs/vulkan_proc_table.h | 12 +++++++++--- 8 files changed, 48 insertions(+), 17 deletions(-) diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index 2f1e86a9f0391..826d881021963 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -45,6 +45,11 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( proc_table.vkCreateImage = vk->CreateImage; proc_table.vkDestroyImage = vk->DestroyImage; proc_table.vkCmdCopyBuffer = vk->CmdCopyBuffer; + proc_table.vkGetBufferMemoryRequirements2KHR = vk->GetBufferMemoryRequirements2KHR; + proc_table.vkGetImageMemoryRequirements2KHR = vk->GetImageMemoryRequirements2KHR; + proc_table.vkBindBufferMemory2KHR = vk->BindBufferMemory2KHR; + proc_table.vkBindImageMemory2KHR = vk->BindImageMemory2KHR; + proc_table.vkGetPhysicalDeviceMemoryProperties2KHR = vk->GetPhysicalDeviceMemoryProperties2KHR; // clang-format on VmaAllocatorCreateInfo allocator_info = {}; diff --git a/shell/common/shell_test_platform_view_vulkan.cc b/shell/common/shell_test_platform_view_vulkan.cc index 0e15be70246a3..fa3267ef731da 100644 --- a/shell/common/shell_test_platform_view_vulkan.cc +++ b/shell/common/shell_test_platform_view_vulkan.cc @@ -7,6 +7,7 @@ #include #include "flutter/common/graphics/persistent_cache.h" +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/shell/common/context_options.h" #include "flutter/vulkan/vulkan_skia_proc_table.h" #include "flutter/vulkan/vulkan_utilities.h" @@ -112,6 +113,11 @@ ShellTestPlatformViewVulkan::OffScreenSurface::OffScreenSurface( return; } + memory_allocator_ = FlutterSkiaVulkanMemoryAllocator::Make( + application_->GetAPIVersion(), application_->GetInstance(), + logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(), + vk_, true); + // Create the Skia GrContext. if (!CreateSkiaGrContext()) { FML_DLOG(ERROR) << "Could not create Skia context."; @@ -172,6 +178,8 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext( context->fFeatures = skia_features; context->fGetProc = std::move(getProc); context->fOwnsInstanceAndDevice = false; + context->fMemoryAllocator = memory_allocator_; + return true; } diff --git a/shell/common/shell_test_platform_view_vulkan.h b/shell/common/shell_test_platform_view_vulkan.h index 724fe455639fc..718f7fe6dec06 100644 --- a/shell/common/shell_test_platform_view_vulkan.h +++ b/shell/common/shell_test_platform_view_vulkan.h @@ -10,6 +10,7 @@ #include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h" #include "flutter/vulkan/vulkan_application.h" #include "flutter/vulkan/vulkan_device.h" +#include "flutter/vulkan/vulkan_skia_proc_table.h" namespace flutter { namespace testing { @@ -54,6 +55,7 @@ class ShellTestPlatformViewVulkan : public ShellTestPlatformView { shell_test_external_view_embedder_; std::unique_ptr application_; std::unique_ptr logical_device_; + sk_sp memory_allocator_; sk_sp context_; bool CreateSkiaGrContext(); diff --git a/shell/platform/embedder/embedder.cc b/shell/platform/embedder/embedder.cc index 41f8f8227f08d..8b363eec43fb2 100644 --- a/shell/platform/embedder/embedder.cc +++ b/shell/platform/embedder/embedder.cc @@ -556,8 +556,13 @@ InferVulkanPlatformViewCreationCallback( return ptr(user_data, &image_desc); }; + auto vk_instance = static_cast(config->vulkan.instance); + auto proc_addr = + vulkan_get_instance_proc_address(vk_instance, "GetInstanceProcAddr"); + flutter::EmbedderSurfaceVulkan::VulkanDispatchTable vulkan_dispatch_table = { - .get_instance_proc_address = vulkan_get_instance_proc_address, + .get_instance_proc_address = + reinterpret_cast(proc_addr), .get_next_image = vulkan_get_next_image, .present_image = vulkan_present_image_callback, }; @@ -567,8 +572,7 @@ InferVulkanPlatformViewCreationCallback( std::unique_ptr embedder_surface = std::make_unique( - config->vulkan.version, - static_cast(config->vulkan.instance), + config->vulkan.version, vk_instance, config->vulkan.enabled_instance_extension_count, config->vulkan.enabled_instance_extensions, config->vulkan.enabled_device_extension_count, diff --git a/shell/platform/embedder/embedder_surface_vulkan.h b/shell/platform/embedder/embedder_surface_vulkan.h index cda526da0051e..8c44e3ddd99e6 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.h +++ b/shell/platform/embedder/embedder_surface_vulkan.h @@ -20,8 +20,7 @@ class EmbedderSurfaceVulkan final : public EmbedderSurface, public GPUSurfaceVulkanDelegate { public: struct VulkanDispatchTable { - std::function - get_instance_proc_address; // required + PFN_vkGetInstanceProcAddr get_instance_proc_address; // required std::function get_next_image; // required std::function diff --git a/shell/platform/embedder/tests/embedder_config_builder.cc b/shell/platform/embedder/tests/embedder_config_builder.cc index 58e48c4b594d8..92ff07a81291a 100644 --- a/shell/platform/embedder/tests/embedder_config_builder.cc +++ b/shell/platform/embedder/tests/embedder_config_builder.cc @@ -510,9 +510,9 @@ void EmbedderConfigBuilder::InitializeVulkanRendererConfig() { vulkan_renderer_config_.get_instance_proc_address_callback = [](void* context, FlutterVulkanInstanceHandle instance, const char* name) -> void* { - return reinterpret_cast(context) - ->vulkan_context_->vk_->GetInstanceProcAddr( - reinterpret_cast(instance), name); + auto proc_addr = reinterpret_cast(context) + ->vulkan_context_->vk_->GetInstanceProcAddr; + return reinterpret_cast(proc_addr); }; vulkan_renderer_config_.get_next_image_callback = [](void* context, diff --git a/vulkan/procs/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc index e623cd7b6a66d..2d7fa07c2fbdf 100644 --- a/vulkan/procs/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -26,9 +26,9 @@ VulkanProcTable::VulkanProcTable(const char* so_path) } VulkanProcTable::VulkanProcTable( - std::function get_instance_proc_addr) + PFN_vkGetInstanceProcAddr get_instance_proc_addr) : handle_(nullptr), acquired_mandatory_proc_addresses_(false) { - GetInstanceProcAddr = std::move(get_instance_proc_addr); + GetInstanceProcAddr = get_instance_proc_addr; acquired_mandatory_proc_addresses_ = SetupLoaderProcAddresses(); } @@ -60,8 +60,7 @@ bool VulkanProcTable::SetupGetInstanceProcAddress() { FML_LOG(ERROR) << "SetupGetInstanceProcAddress: handle_ is non-null"; - GetInstanceProcAddr = reinterpret_cast( - NativeGetInstanceProcAddr()); + GetInstanceProcAddr = NativeGetInstanceProcAddr(); if (!GetInstanceProcAddr) { FML_DLOG(WARNING) << "Could not acquire vkGetInstanceProcAddr."; return false; @@ -71,8 +70,9 @@ bool VulkanProcTable::SetupGetInstanceProcAddress() { } PFN_vkGetInstanceProcAddr VulkanProcTable::NativeGetInstanceProcAddr() const { - FML_LOG(ERROR) << this << " - " << handle_.get() - << " : NativeGetInstanceProcAddr"; + if (GetInstanceProcAddr) { + return GetInstanceProcAddr; + } #if VULKAN_LINK_STATICALLY return &vkGetInstanceProcAddr; @@ -167,6 +167,13 @@ bool VulkanProcTable::SetupDeviceProcAddresses( ACQUIRE_PROC(CreateBuffer, handle); ACQUIRE_PROC(DestroyBuffer, handle); ACQUIRE_PROC(CmdCopyBuffer, handle); + + ACQUIRE_PROC(GetBufferMemoryRequirements2KHR, handle); + ACQUIRE_PROC(GetImageMemoryRequirements2KHR, handle); + ACQUIRE_PROC(BindBufferMemory2KHR, handle); + ACQUIRE_PROC(BindImageMemory2KHR, handle); + ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties2KHR, handle); + #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID ACQUIRE_PROC(AcquireNextImageKHR, handle); diff --git a/vulkan/procs/vulkan_proc_table.h b/vulkan/procs/vulkan_proc_table.h index a73be6cf678e1..42775a0b5edb3 100644 --- a/vulkan/procs/vulkan_proc_table.h +++ b/vulkan/procs/vulkan_proc_table.h @@ -47,8 +47,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { VulkanProcTable(); explicit VulkanProcTable(const char* so_path); - explicit VulkanProcTable( - std::function get_instance_proc_addr); + explicit VulkanProcTable(PFN_vkGetInstanceProcAddr get_instance_proc_addr); ~VulkanProcTable(); bool HasAcquiredMandatoryProcAddresses() const; @@ -63,7 +62,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { bool SetupDeviceProcAddresses(const VulkanHandle& device); - std::function GetInstanceProcAddr = nullptr; + PFN_vkGetInstanceProcAddr GetInstanceProcAddr = nullptr; #define DEFINE_PROC(name) Proc name; @@ -119,6 +118,13 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { DEFINE_PROC(CreateBuffer); DEFINE_PROC(DestroyBuffer); DEFINE_PROC(CmdCopyBuffer); + + DEFINE_PROC(GetBufferMemoryRequirements2KHR); + DEFINE_PROC(GetImageMemoryRequirements2KHR); + DEFINE_PROC(BindBufferMemory2KHR); + DEFINE_PROC(BindImageMemory2KHR); + DEFINE_PROC(GetPhysicalDeviceMemoryProperties2KHR); + #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID DEFINE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR); From 047d4ea6a0046c0e1a98d11af16bcd7059a369bf Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 09:58:57 -0400 Subject: [PATCH 13/21] fix gn issues --- flutter_vma/BUILD.gn | 1 + shell/common/BUILD.gn | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/flutter_vma/BUILD.gn b/flutter_vma/BUILD.gn index 24f5619e3ef37..26e6566a3d60c 100644 --- a/flutter_vma/BUILD.gn +++ b/flutter_vma/BUILD.gn @@ -31,6 +31,7 @@ source_set("flutter_skia_vma") { public_deps = [ ":flutter_vma" ] deps = [ + "//flutter/fml", "//flutter/vulkan/procs", "//third_party/skia", "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", diff --git a/shell/common/BUILD.gn b/shell/common/BUILD.gn index 2b3f63e8b35c5..7fa0c1b23ae70 100644 --- a/shell/common/BUILD.gn +++ b/shell/common/BUILD.gn @@ -264,7 +264,10 @@ if (enable_unittests) { "shell_test_platform_view_vulkan.h", ] - public_deps += [ "//flutter/vulkan" ] + public_deps += [ + "//flutter/flutter_vma:flutter_skia_vma", + "//flutter/vulkan", + ] } if (test_enable_metal) { From 07d8b8fb09471336304d5a863b8af232767ccb7e Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 11:13:12 -0400 Subject: [PATCH 14/21] all that is left is cleaning up --- flutter_vma/flutter_skia_vma.cc | 50 +++++++++---------- impeller/renderer/backend/vulkan/BUILD.gn | 1 + .../renderer/backend/vulkan/allocator_vk.cc | 39 +++++++++++++++ .../renderer/backend/vulkan/allocator_vk.h | 3 ++ impeller/renderer/backend/vulkan/vk.h | 1 - vulkan/procs/vulkan_interface.h | 4 -- vulkan/procs/vulkan_proc_table.cc | 21 ++++++-- vulkan/procs/vulkan_proc_table.h | 8 ++- 8 files changed, 91 insertions(+), 36 deletions(-) diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index 826d881021963..07594c49ad98a 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -24,33 +24,33 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( return nullptr; } - // clang-format off +#define PROVIDE_PROC(tbl, proc, provider) tbl.vk##proc = provider->proc; + VmaVulkanFunctions proc_table = {}; proc_table.vkGetInstanceProcAddr = vk->NativeGetInstanceProcAddr(); - proc_table.vkGetDeviceProcAddr = vk->GetDeviceProcAddr; - proc_table.vkGetPhysicalDeviceProperties = vk->GetPhysicalDeviceProperties; - proc_table.vkGetPhysicalDeviceMemoryProperties = vk->GetPhysicalDeviceMemoryProperties; - proc_table.vkAllocateMemory = vk->AllocateMemory; - proc_table.vkFreeMemory = vk->FreeMemory; - proc_table.vkMapMemory = vk->MapMemory; - proc_table.vkUnmapMemory = vk->UnmapMemory; - proc_table.vkFlushMappedMemoryRanges = vk->FlushMappedMemoryRanges; - proc_table.vkInvalidateMappedMemoryRanges = vk->InvalidateMappedMemoryRanges; - proc_table.vkBindBufferMemory = vk->BindBufferMemory; - proc_table.vkBindImageMemory = vk->BindImageMemory; - proc_table.vkGetBufferMemoryRequirements = vk->GetBufferMemoryRequirements; - proc_table.vkGetImageMemoryRequirements = vk->GetImageMemoryRequirements; - proc_table.vkCreateBuffer = vk->CreateBuffer; - proc_table.vkDestroyBuffer = vk->DestroyBuffer; - proc_table.vkCreateImage = vk->CreateImage; - proc_table.vkDestroyImage = vk->DestroyImage; - proc_table.vkCmdCopyBuffer = vk->CmdCopyBuffer; - proc_table.vkGetBufferMemoryRequirements2KHR = vk->GetBufferMemoryRequirements2KHR; - proc_table.vkGetImageMemoryRequirements2KHR = vk->GetImageMemoryRequirements2KHR; - proc_table.vkBindBufferMemory2KHR = vk->BindBufferMemory2KHR; - proc_table.vkBindImageMemory2KHR = vk->BindImageMemory2KHR; - proc_table.vkGetPhysicalDeviceMemoryProperties2KHR = vk->GetPhysicalDeviceMemoryProperties2KHR; - // clang-format on + PROVIDE_PROC(proc_table, GetDeviceProcAddr, vk); + PROVIDE_PROC(proc_table, GetPhysicalDeviceProperties, vk); + PROVIDE_PROC(proc_table, GetPhysicalDeviceMemoryProperties, vk); + PROVIDE_PROC(proc_table, AllocateMemory, vk); + PROVIDE_PROC(proc_table, FreeMemory, vk); + PROVIDE_PROC(proc_table, MapMemory, vk); + PROVIDE_PROC(proc_table, UnmapMemory, vk); + PROVIDE_PROC(proc_table, FlushMappedMemoryRanges, vk); + PROVIDE_PROC(proc_table, InvalidateMappedMemoryRanges, vk); + PROVIDE_PROC(proc_table, BindBufferMemory, vk); + PROVIDE_PROC(proc_table, BindImageMemory, vk); + PROVIDE_PROC(proc_table, GetBufferMemoryRequirements, vk); + PROVIDE_PROC(proc_table, GetImageMemoryRequirements, vk); + PROVIDE_PROC(proc_table, CreateBuffer, vk); + PROVIDE_PROC(proc_table, DestroyBuffer, vk); + PROVIDE_PROC(proc_table, CreateImage, vk); + PROVIDE_PROC(proc_table, DestroyImage, vk); + PROVIDE_PROC(proc_table, CmdCopyBuffer, vk); + PROVIDE_PROC(proc_table, GetBufferMemoryRequirements2KHR, vk); + PROVIDE_PROC(proc_table, GetImageMemoryRequirements2KHR, vk); + PROVIDE_PROC(proc_table, BindBufferMemory2KHR, vk); + PROVIDE_PROC(proc_table, BindImageMemory2KHR, vk); + PROVIDE_PROC(proc_table, GetPhysicalDeviceMemoryProperties2KHR, vk); VmaAllocatorCreateInfo allocator_info = {}; allocator_info.vulkanApiVersion = vulkan_api_version; diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index a6872fa96e02e..6db2d4df534ea 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -58,6 +58,7 @@ impeller_component("vulkan") { "../../../blobcat:blobcat_lib", "//flutter/flutter_vma", "//flutter/fml", + "//flutter/vulkan/procs", "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers", "//third_party/vulkan_memory_allocator", ] diff --git a/impeller/renderer/backend/vulkan/allocator_vk.cc b/impeller/renderer/backend/vulkan/allocator_vk.cc index 1faca6952efc7..5af11d8aa3c51 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.cc +++ b/impeller/renderer/backend/vulkan/allocator_vk.cc @@ -6,6 +6,9 @@ #include +#include "flutter/fml/memory/ref_ptr.h" +#include "flutter/vulkan/procs/vulkan_handle.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" #include "impeller/renderer/backend/vulkan/device_buffer_vk.h" #include "impeller/renderer/backend/vulkan/formats_vk.h" #include "impeller/renderer/backend/vulkan/texture_vk.h" @@ -20,10 +23,46 @@ AllocatorVK::AllocatorVK(ContextVK& context, PFN_vkGetInstanceProcAddr get_instance_proc_address, PFN_vkGetDeviceProcAddr get_device_proc_address) : context_(context), device_(logical_device) { + vk_ = fml::MakeRefCounted(get_instance_proc_address); + + auto instance_handle = vulkan::VulkanHandle(instance); + FML_CHECK(vk_->SetupInstanceProcAddresses(instance_handle)); + + auto device_handle = vulkan::VulkanHandle(logical_device); + FML_CHECK(vk_->SetupDeviceProcAddresses(device_handle)); + VmaVulkanFunctions proc_table = {}; proc_table.vkGetInstanceProcAddr = get_instance_proc_address; proc_table.vkGetDeviceProcAddr = get_device_proc_address; +#define PROVIDE_PROC(tbl, proc, provider) tbl.vk##proc = provider->proc; + PROVIDE_PROC(proc_table, GetPhysicalDeviceProperties, vk_); + PROVIDE_PROC(proc_table, GetPhysicalDeviceMemoryProperties, vk_); + PROVIDE_PROC(proc_table, AllocateMemory, vk_); + PROVIDE_PROC(proc_table, FreeMemory, vk_); + PROVIDE_PROC(proc_table, MapMemory, vk_); + PROVIDE_PROC(proc_table, UnmapMemory, vk_); + PROVIDE_PROC(proc_table, FlushMappedMemoryRanges, vk_); + PROVIDE_PROC(proc_table, InvalidateMappedMemoryRanges, vk_); + PROVIDE_PROC(proc_table, BindBufferMemory, vk_); + PROVIDE_PROC(proc_table, BindImageMemory, vk_); + PROVIDE_PROC(proc_table, GetBufferMemoryRequirements, vk_); + PROVIDE_PROC(proc_table, GetImageMemoryRequirements, vk_); + PROVIDE_PROC(proc_table, CreateBuffer, vk_); + PROVIDE_PROC(proc_table, DestroyBuffer, vk_); + PROVIDE_PROC(proc_table, CreateImage, vk_); + PROVIDE_PROC(proc_table, DestroyImage, vk_); + PROVIDE_PROC(proc_table, CmdCopyBuffer, vk_); + + // clang-format off + // See: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/203 + proc_table.vkGetBufferMemoryRequirements2KHR = vk_->GetBufferMemoryRequirements2; + proc_table.vkGetImageMemoryRequirements2KHR = vk_->GetImageMemoryRequirements2; + proc_table.vkBindBufferMemory2KHR = vk_->BindBufferMemory2; + proc_table.vkBindImageMemory2KHR = vk_->BindImageMemory2; + proc_table.vkGetPhysicalDeviceMemoryProperties2KHR = vk_->GetPhysicalDeviceMemoryProperties2; + // clang-format on + VmaAllocatorCreateInfo allocator_info = {}; allocator_info.vulkanApiVersion = vulkan_api_version; allocator_info.physicalDevice = physical_device; diff --git a/impeller/renderer/backend/vulkan/allocator_vk.h b/impeller/renderer/backend/vulkan/allocator_vk.h index 5225845bf71c6..e7c266a707b10 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.h +++ b/impeller/renderer/backend/vulkan/allocator_vk.h @@ -5,6 +5,8 @@ #pragma once #include "flutter/fml/macros.h" +#include "flutter/vulkan/procs/vulkan_proc_table.h" +#include "fml/memory/ref_ptr.h" #include "impeller/renderer/allocator.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" @@ -21,6 +23,7 @@ class AllocatorVK final : public Allocator { private: friend class ContextVK; + fml::RefPtr vk_; VmaAllocator allocator_ = {}; ContextVK& context_; vk::Device device_; diff --git a/impeller/renderer/backend/vulkan/vk.h b/impeller/renderer/backend/vulkan/vk.h index 14f02c9aaf4ce..a62d94495c041 100644 --- a/impeller/renderer/backend/vulkan/vk.h +++ b/impeller/renderer/backend/vulkan/vk.h @@ -19,7 +19,6 @@ #define VULKAN_HPP_NAMESPACE impeller::vk #define VULKAN_HPP_ASSERT_ON_RESULT(ignored) \ { [[maybe_unused]] auto res = (ignored); } -#define VULKAN_HPP_NO_EXCEPTIONS #include "vulkan/vulkan.hpp" static_assert(VK_HEADER_VERSION >= 215, diff --git a/vulkan/procs/vulkan_interface.h b/vulkan/procs/vulkan_interface.h index 4f091f4edf6b5..089ae829eb8f9 100644 --- a/vulkan/procs/vulkan_interface.h +++ b/vulkan/procs/vulkan_interface.h @@ -24,10 +24,6 @@ #endif // VK_USE_PLATFORM_FUCHSIA #endif // OS_FUCHSIA -#if !VULKAN_LINK_STATICALLY -#define VK_NO_PROTOTYPES 1 -#endif // !VULKAN_LINK_STATICALLY - // TODO(dnfield): vulkan_metal.h has some unguarded availability checks for // macOS 10.13. We can remove this if we bump to 10.14 or if that gets fixed // upstream, but fixing it upstream will take some time to flow through to diff --git a/vulkan/procs/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc index 2d7fa07c2fbdf..80dd7e5ccc2ce 100644 --- a/vulkan/procs/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -14,6 +14,14 @@ return false; \ } +#define ACQUIRE_PROC_EITHER(name, name2, context) \ + if (!(name = AcquireProc("vk" #name, context)) && \ + !(name2 = AcquireProc("vk" #name2, context))) { \ + FML_LOG(ERROR) << "Could not acquire proc: vk" << #name << ", or proc: vk" \ + << #name2; \ + return false; \ + } + namespace vulkan { VulkanProcTable::VulkanProcTable() : VulkanProcTable("libvulkan.so"){}; @@ -107,6 +115,8 @@ bool VulkanProcTable::SetupInstanceProcAddresses( ACQUIRE_PROC(GetPhysicalDeviceQueueFamilyProperties, handle); ACQUIRE_PROC(GetPhysicalDeviceProperties, handle); ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties, handle); + ACQUIRE_PROC_EITHER(GetPhysicalDeviceMemoryProperties2, + GetPhysicalDeviceMemoryProperties2KHR, handle); #if FML_OS_ANDROID ACQUIRE_PROC(GetPhysicalDeviceSurfaceCapabilitiesKHR, handle); @@ -168,11 +178,12 @@ bool VulkanProcTable::SetupDeviceProcAddresses( ACQUIRE_PROC(DestroyBuffer, handle); ACQUIRE_PROC(CmdCopyBuffer, handle); - ACQUIRE_PROC(GetBufferMemoryRequirements2KHR, handle); - ACQUIRE_PROC(GetImageMemoryRequirements2KHR, handle); - ACQUIRE_PROC(BindBufferMemory2KHR, handle); - ACQUIRE_PROC(BindImageMemory2KHR, handle); - ACQUIRE_PROC(GetPhysicalDeviceMemoryProperties2KHR, handle); + ACQUIRE_PROC_EITHER(GetBufferMemoryRequirements2, + GetBufferMemoryRequirements2KHR, handle); + ACQUIRE_PROC_EITHER(GetImageMemoryRequirements2, + GetImageMemoryRequirements2KHR, handle); + ACQUIRE_PROC_EITHER(BindBufferMemory2, BindBufferMemory2KHR, handle); + ACQUIRE_PROC_EITHER(BindImageMemory2, BindImageMemory2KHR, handle); #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID diff --git a/vulkan/procs/vulkan_proc_table.h b/vulkan/procs/vulkan_proc_table.h index 42775a0b5edb3..3092bed159a5d 100644 --- a/vulkan/procs/vulkan_proc_table.h +++ b/vulkan/procs/vulkan_proc_table.h @@ -119,11 +119,17 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { DEFINE_PROC(DestroyBuffer); DEFINE_PROC(CmdCopyBuffer); + DEFINE_PROC(GetPhysicalDeviceMemoryProperties2); + DEFINE_PROC(GetPhysicalDeviceMemoryProperties2KHR); + + DEFINE_PROC(GetBufferMemoryRequirements2); DEFINE_PROC(GetBufferMemoryRequirements2KHR); + DEFINE_PROC(GetImageMemoryRequirements2); DEFINE_PROC(GetImageMemoryRequirements2KHR); + DEFINE_PROC(BindBufferMemory2); DEFINE_PROC(BindBufferMemory2KHR); + DEFINE_PROC(BindImageMemory2); DEFINE_PROC(BindImageMemory2KHR); - DEFINE_PROC(GetPhysicalDeviceMemoryProperties2KHR); #ifndef TEST_VULKAN_PROCS #if FML_OS_ANDROID From 2d2cf68e80d374d88f1c9d4d92946af41f49cd6c Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 11:38:31 -0400 Subject: [PATCH 15/21] fix obvious failures --- flutter_vma/flutter_skia_vma.cc | 26 ++++++++++--------- fml/memory/ref_ptr.h | 1 + .../renderer/backend/vulkan/allocator_vk.cc | 21 +++++++++------ .../renderer/backend/vulkan/allocator_vk.h | 2 +- testing/run_tests.py | 4 +-- vulkan/procs/vulkan_proc_table.cc | 14 +++------- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index 07594c49ad98a..ac95dab21d912 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -17,13 +17,6 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( VkDevice device, fml::RefPtr vk, bool mustUseCoherentHostVisibleMemory) { - FML_LOG(ERROR) << "here!!!"; - - if (vk->AllocateMemory == nullptr) { - FML_LOG(ERROR) << "Could not acquire vkAllocateMemory."; - return nullptr; - } - #define PROVIDE_PROC(tbl, proc, provider) tbl.vk##proc = provider->proc; VmaVulkanFunctions proc_table = {}; @@ -46,11 +39,20 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( PROVIDE_PROC(proc_table, CreateImage, vk); PROVIDE_PROC(proc_table, DestroyImage, vk); PROVIDE_PROC(proc_table, CmdCopyBuffer, vk); - PROVIDE_PROC(proc_table, GetBufferMemoryRequirements2KHR, vk); - PROVIDE_PROC(proc_table, GetImageMemoryRequirements2KHR, vk); - PROVIDE_PROC(proc_table, BindBufferMemory2KHR, vk); - PROVIDE_PROC(proc_table, BindImageMemory2KHR, vk); - PROVIDE_PROC(proc_table, GetPhysicalDeviceMemoryProperties2KHR, vk); + +#define PROVIDE_PROC_COALESCE(tbl, proc, provider) \ + tbl.vk##proc##KHR = provider->proc ? provider->proc : provider->proc##KHR; + // See the following link for why we have to pick either KHR version or + // promoted non-KHR version: + // https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/203 + PROVIDE_PROC_COALESCE(proc_table, GetBufferMemoryRequirements2, vk); + PROVIDE_PROC_COALESCE(proc_table, GetImageMemoryRequirements2, vk); + PROVIDE_PROC_COALESCE(proc_table, BindBufferMemory2, vk); + PROVIDE_PROC_COALESCE(proc_table, BindImageMemory2, vk); + PROVIDE_PROC_COALESCE(proc_table, GetPhysicalDeviceMemoryProperties2, vk); +#undef PROVIDE_PROC_COALESCE + +#undef PROVIDE_PROC VmaAllocatorCreateInfo allocator_info = {}; allocator_info.vulkanApiVersion = vulkan_api_version; diff --git a/fml/memory/ref_ptr.h b/fml/memory/ref_ptr.h index 8e70c88bee196..c426a4901d7a2 100644 --- a/fml/memory/ref_ptr.h +++ b/fml/memory/ref_ptr.h @@ -1,3 +1,4 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/impeller/renderer/backend/vulkan/allocator_vk.cc b/impeller/renderer/backend/vulkan/allocator_vk.cc index 5af11d8aa3c51..9131f052ca8dd 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.cc +++ b/impeller/renderer/backend/vulkan/allocator_vk.cc @@ -54,14 +54,19 @@ AllocatorVK::AllocatorVK(ContextVK& context, PROVIDE_PROC(proc_table, DestroyImage, vk_); PROVIDE_PROC(proc_table, CmdCopyBuffer, vk_); - // clang-format off - // See: https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/203 - proc_table.vkGetBufferMemoryRequirements2KHR = vk_->GetBufferMemoryRequirements2; - proc_table.vkGetImageMemoryRequirements2KHR = vk_->GetImageMemoryRequirements2; - proc_table.vkBindBufferMemory2KHR = vk_->BindBufferMemory2; - proc_table.vkBindImageMemory2KHR = vk_->BindImageMemory2; - proc_table.vkGetPhysicalDeviceMemoryProperties2KHR = vk_->GetPhysicalDeviceMemoryProperties2; - // clang-format on +#define PROVIDE_PROC_COALESCE(tbl, proc, provider) \ + tbl.vk##proc##KHR = provider->proc ? provider->proc : provider->proc##KHR; + // See the following link for why we have to pick either KHR version or + // promoted non-KHR version: + // https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator/issues/203 + PROVIDE_PROC_COALESCE(proc_table, GetBufferMemoryRequirements2, vk_); + PROVIDE_PROC_COALESCE(proc_table, GetImageMemoryRequirements2, vk_); + PROVIDE_PROC_COALESCE(proc_table, BindBufferMemory2, vk_); + PROVIDE_PROC_COALESCE(proc_table, BindImageMemory2, vk_); + PROVIDE_PROC_COALESCE(proc_table, GetPhysicalDeviceMemoryProperties2, vk_); +#undef PROVIDE_PROC_COALESCE + +#undef PROVIDE_PROC VmaAllocatorCreateInfo allocator_info = {}; allocator_info.vulkanApiVersion = vulkan_api_version; diff --git a/impeller/renderer/backend/vulkan/allocator_vk.h b/impeller/renderer/backend/vulkan/allocator_vk.h index e7c266a707b10..595a0b838ec96 100644 --- a/impeller/renderer/backend/vulkan/allocator_vk.h +++ b/impeller/renderer/backend/vulkan/allocator_vk.h @@ -5,8 +5,8 @@ #pragma once #include "flutter/fml/macros.h" +#include "flutter/fml/memory/ref_ptr.h" #include "flutter/vulkan/procs/vulkan_proc_table.h" -#include "fml/memory/ref_ptr.h" #include "impeller/renderer/allocator.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" diff --git a/testing/run_tests.py b/testing/run_tests.py index 5b2b73acd718a..af11bea364f21 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -338,9 +338,9 @@ def make_test(name, flags=repeat_flags, extra_env={}): make_test('dart_plugin_registrant_unittests'), make_test('display_list_rendertests'), make_test('display_list_unittests'), - # make_test('embedder_a11y_unittests'), + make_test('embedder_a11y_unittests'), make_test('embedder_proctable_unittests'), - # make_test('embedder_unittests'), + make_test('embedder_unittests'), make_test('fml_unittests', flags=[fml_unittests_filter] + repeat_flags), make_test('no_dart_plugin_registrant_unittests'), make_test('runtime_unittests'), diff --git a/vulkan/procs/vulkan_proc_table.cc b/vulkan/procs/vulkan_proc_table.cc index 80dd7e5ccc2ce..b4eb57032e33d 100644 --- a/vulkan/procs/vulkan_proc_table.cc +++ b/vulkan/procs/vulkan_proc_table.cc @@ -10,14 +10,14 @@ #define ACQUIRE_PROC(name, context) \ if (!(name = AcquireProc("vk" #name, context))) { \ - FML_LOG(ERROR) << "Could not acquire proc: vk" << #name; \ + FML_DLOG(INFO) << "Could not acquire proc: vk" << #name; \ return false; \ } #define ACQUIRE_PROC_EITHER(name, name2, context) \ if (!(name = AcquireProc("vk" #name, context)) && \ !(name2 = AcquireProc("vk" #name2, context))) { \ - FML_LOG(ERROR) << "Could not acquire proc: vk" << #name << ", or proc: vk" \ + FML_DLOG(INFO) << "Could not acquire proc: vk" << #name << ", or proc: vk" \ << #name2; \ return false; \ } @@ -62,12 +62,9 @@ bool VulkanProcTable::AreDeviceProcsSetup() const { bool VulkanProcTable::SetupGetInstanceProcAddress() { if (!handle_) { - FML_LOG(ERROR) << "SetupGetInstanceProcAddress: handle_ is null"; return true; } - FML_LOG(ERROR) << "SetupGetInstanceProcAddress: handle_ is non-null"; - GetInstanceProcAddr = NativeGetInstanceProcAddr(); if (!GetInstanceProcAddr) { FML_DLOG(WARNING) << "Could not acquire vkGetInstanceProcAddr."; @@ -103,8 +100,6 @@ bool VulkanProcTable::SetupLoaderProcAddresses() { bool VulkanProcTable::SetupInstanceProcAddresses( const VulkanHandle& handle) { - FML_LOG(ERROR) << this << " - SetupInstanceProcAddresses. handle: " << handle; - ACQUIRE_PROC(CreateDevice, handle); ACQUIRE_PROC(DestroyDevice, handle); ACQUIRE_PROC(DestroyInstance, handle); @@ -214,16 +209,13 @@ bool VulkanProcTable::OpenLibraryHandle(const char* path) { handle_ = fml::NativeLibrary::Create(path); #endif // VULKAN_LINK_STATICALLY if (!handle_) { - FML_LOG(ERROR) << "Could not open Vulkan library handle: " << path; + FML_DLOG(ERROR) << "Could not open Vulkan library handle: " << path; return false; - } else { - FML_LOG(ERROR) << "Opened Vulkan library handle: " << path; } return true; } bool VulkanProcTable::CloseLibraryHandle() { - FML_LOG(ERROR) << "Closing Vulkan library handle: " << handle_.get(); handle_ = nullptr; return true; } From aca1ac5e8d5d1ac384d45dcacd534ef1b38b3e87 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 12:01:23 -0400 Subject: [PATCH 16/21] fix fuchsia things --- shell/platform/fuchsia/flutter/BUILD.gn | 1 + shell/platform/fuchsia/flutter/vulkan_surface.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/fuchsia/flutter/BUILD.gn b/shell/platform/fuchsia/flutter/BUILD.gn index 01a1f2e3ce106..6c34d61870060 100644 --- a/shell/platform/fuchsia/flutter/BUILD.gn +++ b/shell/platform/fuchsia/flutter/BUILD.gn @@ -138,6 +138,7 @@ template("runner_sources") { "//flutter/fml", "//flutter/shell/platform/common/client_wrapper:client_wrapper_library_stubs", "//flutter/vulkan", + "//flutter/vulkan/procs", ] public_deps = [ diff --git a/shell/platform/fuchsia/flutter/vulkan_surface.h b/shell/platform/fuchsia/flutter/vulkan_surface.h index f5933d7e8c1f8..37db0c4fe35e5 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface.h +++ b/shell/platform/fuchsia/flutter/vulkan_surface.h @@ -16,8 +16,8 @@ #include "flutter/fml/macros.h" #include "flutter/vulkan/procs/vulkan_handle.h" #include "flutter/vulkan/procs/vulkan_proc_table.h" -#include "flutter/vulkan/procs/vulkan_provider.h" #include "flutter/vulkan/vulkan_command_buffer.h" +#include "flutter/vulkan/vulkan_provider.h" #include "third_party/skia/include/core/SkColorType.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "third_party/skia/include/core/SkSize.h" From c0f955cb781704154dbaa07b512c03c5939b86fe Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 12:09:40 -0400 Subject: [PATCH 17/21] fix licenses --- ci/licenses_golden/licenses_flutter | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index b22911a6db34b..b64c8e147af36 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -3260,6 +3260,12 @@ FILE: ../../../flutter/third_party/txt/src/txt/platform_fuchsia.cc FILE: ../../../flutter/third_party/txt/src/txt/platform_linux.cc FILE: ../../../flutter/third_party/txt/src/txt/platform_mac.mm FILE: ../../../flutter/third_party/txt/src/txt/platform_windows.cc +FILE: ../../../flutter/vulkan/procs/vulkan_handle.cc +FILE: ../../../flutter/vulkan/procs/vulkan_handle.h +FILE: ../../../flutter/vulkan/procs/vulkan_interface.cc +FILE: ../../../flutter/vulkan/procs/vulkan_interface.h +FILE: ../../../flutter/vulkan/procs/vulkan_proc_table.cc +FILE: ../../../flutter/vulkan/procs/vulkan_proc_table.h FILE: ../../../flutter/vulkan/vulkan_application.cc FILE: ../../../flutter/vulkan/vulkan_application.h FILE: ../../../flutter/vulkan/vulkan_backbuffer.cc @@ -3270,20 +3276,16 @@ FILE: ../../../flutter/vulkan/vulkan_debug_report.cc FILE: ../../../flutter/vulkan/vulkan_debug_report.h FILE: ../../../flutter/vulkan/vulkan_device.cc FILE: ../../../flutter/vulkan/vulkan_device.h -FILE: ../../../flutter/vulkan/vulkan_handle.cc -FILE: ../../../flutter/vulkan/vulkan_handle.h FILE: ../../../flutter/vulkan/vulkan_image.cc FILE: ../../../flutter/vulkan/vulkan_image.h -FILE: ../../../flutter/vulkan/vulkan_interface.cc -FILE: ../../../flutter/vulkan/vulkan_interface.h FILE: ../../../flutter/vulkan/vulkan_native_surface.cc FILE: ../../../flutter/vulkan/vulkan_native_surface.h FILE: ../../../flutter/vulkan/vulkan_native_surface_android.cc FILE: ../../../flutter/vulkan/vulkan_native_surface_android.h -FILE: ../../../flutter/vulkan/vulkan_proc_table.cc -FILE: ../../../flutter/vulkan/vulkan_proc_table.h FILE: ../../../flutter/vulkan/vulkan_provider.cc FILE: ../../../flutter/vulkan/vulkan_provider.h +FILE: ../../../flutter/vulkan/vulkan_skia_proc_table.cc +FILE: ../../../flutter/vulkan/vulkan_skia_proc_table.h FILE: ../../../flutter/vulkan/vulkan_surface.cc FILE: ../../../flutter/vulkan/vulkan_surface.h FILE: ../../../flutter/vulkan/vulkan_swapchain.cc From f224125106a7fde34614a6d995993d8fdeca4848 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 13:10:42 -0400 Subject: [PATCH 18/21] everything except lint --- .../platform/embedder/embedder_surface_vulkan.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/shell/platform/embedder/embedder_surface_vulkan.cc b/shell/platform/embedder/embedder_surface_vulkan.cc index 008d97e2bd44f..8fe32f17e6755 100644 --- a/shell/platform/embedder/embedder_surface_vulkan.cc +++ b/shell/platform/embedder/embedder_surface_vulkan.cc @@ -46,10 +46,18 @@ EmbedderSurfaceVulkan::EmbedderSurfaceVulkan( return; } - FML_DCHECK(vk_->SetupInstanceProcAddresses( - vulkan::VulkanHandle{instance})); - FML_DCHECK( - vk_->SetupDeviceProcAddresses(vulkan::VulkanHandle{device})); + bool success = vk_->SetupInstanceProcAddresses( + vulkan::VulkanHandle{instance}); + if (!success) { + FML_LOG(ERROR) << "Could not setup instance proc addresses."; + return; + } + success = + vk_->SetupDeviceProcAddresses(vulkan::VulkanHandle{device}); + if (!success) { + FML_LOG(ERROR) << "Could not setup device proc addresses."; + return; + } if (!vk_->IsValid()) { FML_LOG(ERROR) << "VulkanProcTable invalid."; return; From b4ffd7c1e6633c7e69d32f7100911b3cc92ea7a3 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 13:18:27 -0400 Subject: [PATCH 19/21] ignore context_vk lint --- impeller/renderer/backend/vulkan/context_vk.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index 7d6850a04e733..58bcd1da7ba33 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// FLUTTER_NOLINT: https://github.com/flutter/flutter/issues/68331 + #include "impeller/renderer/backend/vulkan/context_vk.h" #include From 75b842bae09dbbed6efa085a86fff43f0125ac49 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 14:01:23 -0400 Subject: [PATCH 20/21] fix fuchsia stuff --- shell/platform/fuchsia/flutter/BUILD.gn | 2 ++ shell/platform/fuchsia/flutter/vulkan_surface_producer.cc | 8 ++++++++ shell/platform/fuchsia/flutter/vulkan_surface_producer.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/shell/platform/fuchsia/flutter/BUILD.gn b/shell/platform/fuchsia/flutter/BUILD.gn index 6c34d61870060..13e55261d92f3 100644 --- a/shell/platform/fuchsia/flutter/BUILD.gn +++ b/shell/platform/fuchsia/flutter/BUILD.gn @@ -131,10 +131,12 @@ template("runner_sources") { "//flutter/shell/common", "//flutter/shell/platform/common/client_wrapper:client_wrapper", ] + flutter_deps = [ ":fuchsia_gpu_configuration", "//flutter/assets", "//flutter/common", + "//flutter/flutter_vma:flutter_skia_vma", "//flutter/fml", "//flutter/shell/platform/common/client_wrapper:client_wrapper_library_stubs", "//flutter/vulkan", diff --git a/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc b/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc index 22f0c205724b1..55ccbda9c7ca8 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc +++ b/shell/platform/fuchsia/flutter/vulkan_surface_producer.cc @@ -13,6 +13,7 @@ #include "flutter/fml/trace_event.h" #include "flutter/vulkan/vulkan_skia_proc_table.h" +#include "flutter_vma/flutter_skia_vma.h" #include "third_party/skia/include/gpu/GrBackendSemaphore.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" #include "third_party/skia/include/gpu/vk/GrVkBackendContext.h" @@ -114,6 +115,11 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { return false; } + memory_allocator_ = flutter::FlutterSkiaVulkanMemoryAllocator::Make( + application_->GetAPIVersion(), application_->GetInstance(), + logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(), + vk_, true); + GrVkBackendContext backend_context; backend_context.fInstance = application_->GetInstance(); backend_context.fPhysicalDevice = logical_device_->GetPhysicalDeviceHandle(); @@ -126,6 +132,8 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) { backend_context.fFeatures = skia_features; backend_context.fGetProc = std::move(getProc); backend_context.fOwnsInstanceAndDevice = false; + backend_context.fMemoryAllocator = memory_allocator_; + // The memory_requirements_2 extension is required on Fuchsia as the AMD // memory allocator used by Skia benefit from it. const char* device_extensions[] = { diff --git a/shell/platform/fuchsia/flutter/vulkan_surface_producer.h b/shell/platform/fuchsia/flutter/vulkan_surface_producer.h index ef62370ae07bf..10f025399b8b5 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface_producer.h +++ b/shell/platform/fuchsia/flutter/vulkan_surface_producer.h @@ -10,6 +10,7 @@ #include #include +#include "flutter/flutter_vma/flutter_skia_vma.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/vulkan/procs/vulkan_proc_table.h" @@ -76,6 +77,7 @@ class VulkanSurfaceProducer final : public SurfaceProducer, std::unique_ptr logical_device_; sk_sp context_; std::unique_ptr surface_pool_; + sk_sp memory_allocator_; bool valid_ = false; // WeakPtrFactory must be the last member. From 300e56163fbcbe52608cd0781baad694b4db5c62 Mon Sep 17 00:00:00 2001 From: Kaushik Iska Date: Thu, 27 Oct 2022 15:27:58 -0400 Subject: [PATCH 21/21] fix clang-tidy problems --- flutter_vma/flutter_skia_vma.cc | 4 ++-- flutter_vma/flutter_skia_vma.h | 2 +- vulkan/vulkan_skia_proc_table.cc | 2 +- vulkan/vulkan_skia_proc_table.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flutter_vma/flutter_skia_vma.cc b/flutter_vma/flutter_skia_vma.cc index ac95dab21d912..5b4eb89ae4a39 100644 --- a/flutter_vma/flutter_skia_vma.cc +++ b/flutter_vma/flutter_skia_vma.cc @@ -15,7 +15,7 @@ sk_sp FlutterSkiaVulkanMemoryAllocator::Make( VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - fml::RefPtr vk, + const fml::RefPtr& vk, bool mustUseCoherentHostVisibleMemory) { #define PROVIDE_PROC(tbl, proc, provider) tbl.vk##proc = provider->proc; @@ -73,7 +73,7 @@ FlutterSkiaVulkanMemoryAllocator::FlutterSkiaVulkanMemoryAllocator( fml::RefPtr vk_proc_table, VmaAllocator allocator, bool mustUseCoherentHostVisibleMemory) - : vk_proc_table_(vk_proc_table), + : vk_proc_table_(std::move(vk_proc_table)), allocator_(allocator), must_use_coherent_host_visible_memory_(mustUseCoherentHostVisibleMemory) { } diff --git a/flutter_vma/flutter_skia_vma.h b/flutter_vma/flutter_skia_vma.h index 686c053a3afa3..fd6a6078d4e39 100644 --- a/flutter_vma/flutter_skia_vma.h +++ b/flutter_vma/flutter_skia_vma.h @@ -19,7 +19,7 @@ class FlutterSkiaVulkanMemoryAllocator : public skgpu::VulkanMemoryAllocator { VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, - fml::RefPtr vk, + const fml::RefPtr& vk, bool mustUseCoherentHostVisibleMemory); ~FlutterSkiaVulkanMemoryAllocator() override; diff --git a/vulkan/vulkan_skia_proc_table.cc b/vulkan/vulkan_skia_proc_table.cc index 24e580891b522..71977fd269d93 100644 --- a/vulkan/vulkan_skia_proc_table.cc +++ b/vulkan/vulkan_skia_proc_table.cc @@ -6,7 +6,7 @@ namespace vulkan { -GrVkGetProc CreateSkiaGetProc(fml::RefPtr vk) { +GrVkGetProc CreateSkiaGetProc(const fml::RefPtr& vk) { if (!vk || !vk->IsValid()) { return nullptr; } diff --git a/vulkan/vulkan_skia_proc_table.h b/vulkan/vulkan_skia_proc_table.h index 6922f22ec34b4..9ed988ea51598 100644 --- a/vulkan/vulkan_skia_proc_table.h +++ b/vulkan/vulkan_skia_proc_table.h @@ -10,6 +10,6 @@ namespace vulkan { -GrVkGetProc CreateSkiaGetProc(fml::RefPtr vk); +GrVkGetProc CreateSkiaGetProc(const fml::RefPtr& vk); } // namespace vulkan