mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Remove dependency on //flutter/vulkan and use a single proc table. (flutter/engine#45741)
Fixes https://github.com/flutter/flutter/issues/121947
This commit is contained in:
parent
dd95dd60df
commit
d97bd0c303
@ -110,7 +110,6 @@ 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",
|
||||
]
|
||||
|
||||
@ -88,64 +88,47 @@ AllocatorVK::AllocatorVK(std::weak_ptr<Context> context,
|
||||
const vk::PhysicalDevice& physical_device,
|
||||
const std::shared_ptr<DeviceHolder>& device_holder,
|
||||
const vk::Instance& instance,
|
||||
PFN_vkGetInstanceProcAddr get_instance_proc_address,
|
||||
PFN_vkGetDeviceProcAddr get_device_proc_address,
|
||||
const CapabilitiesVK& capabilities)
|
||||
: context_(std::move(context)), device_holder_(device_holder) {
|
||||
TRACE_EVENT0("impeller", "CreateAllocatorVK");
|
||||
vk_ = fml::MakeRefCounted<vulkan::VulkanProcTable>(get_instance_proc_address);
|
||||
|
||||
auto instance_handle = vulkan::VulkanHandle<VkInstance>(instance);
|
||||
if (!vk_->SetupInstanceProcAddresses(instance_handle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto device_handle =
|
||||
vulkan::VulkanHandle<VkDevice>(device_holder->GetDevice());
|
||||
if (!vk_->SetupDeviceProcAddresses(device_handle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto limits = physical_device.getProperties().limits;
|
||||
max_texture_size_.width = max_texture_size_.height =
|
||||
limits.maxImageDimension2D;
|
||||
|
||||
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_);
|
||||
|
||||
#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
|
||||
#define BIND_VMA_PROC(x) proc_table.x = VULKAN_HPP_DEFAULT_DISPATCHER.x;
|
||||
#define BIND_VMA_PROC_KHR(x) \
|
||||
proc_table.x##KHR = VULKAN_HPP_DEFAULT_DISPATCHER.x \
|
||||
? VULKAN_HPP_DEFAULT_DISPATCHER.x \
|
||||
: VULKAN_HPP_DEFAULT_DISPATCHER.x##KHR;
|
||||
BIND_VMA_PROC(vkGetInstanceProcAddr);
|
||||
BIND_VMA_PROC(vkGetDeviceProcAddr);
|
||||
BIND_VMA_PROC(vkGetPhysicalDeviceProperties);
|
||||
BIND_VMA_PROC(vkGetPhysicalDeviceMemoryProperties);
|
||||
BIND_VMA_PROC(vkAllocateMemory);
|
||||
BIND_VMA_PROC(vkFreeMemory);
|
||||
BIND_VMA_PROC(vkMapMemory);
|
||||
BIND_VMA_PROC(vkUnmapMemory);
|
||||
BIND_VMA_PROC(vkFlushMappedMemoryRanges);
|
||||
BIND_VMA_PROC(vkInvalidateMappedMemoryRanges);
|
||||
BIND_VMA_PROC(vkBindBufferMemory);
|
||||
BIND_VMA_PROC(vkBindImageMemory);
|
||||
BIND_VMA_PROC(vkGetBufferMemoryRequirements);
|
||||
BIND_VMA_PROC(vkGetImageMemoryRequirements);
|
||||
BIND_VMA_PROC(vkCreateBuffer);
|
||||
BIND_VMA_PROC(vkDestroyBuffer);
|
||||
BIND_VMA_PROC(vkCreateImage);
|
||||
BIND_VMA_PROC(vkDestroyImage);
|
||||
BIND_VMA_PROC(vkCmdCopyBuffer);
|
||||
BIND_VMA_PROC_KHR(vkGetBufferMemoryRequirements2);
|
||||
BIND_VMA_PROC_KHR(vkGetImageMemoryRequirements2);
|
||||
BIND_VMA_PROC_KHR(vkBindBufferMemory2);
|
||||
BIND_VMA_PROC_KHR(vkBindImageMemory2);
|
||||
BIND_VMA_PROC_KHR(vkGetPhysicalDeviceMemoryProperties2);
|
||||
#undef BIND_VMA_PROC_KHR
|
||||
#undef BIND_VMA_PROC
|
||||
|
||||
VmaAllocatorCreateInfo allocator_info = {};
|
||||
allocator_info.vulkanApiVersion = vulkan_api_version;
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/memory/ref_ptr.h"
|
||||
#include "flutter/vulkan/procs/vulkan_proc_table.h"
|
||||
#include "impeller/core/allocator.h"
|
||||
#include "impeller/renderer/backend/vulkan/context_vk.h"
|
||||
#include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
|
||||
@ -26,7 +25,6 @@ class AllocatorVK final : public Allocator {
|
||||
private:
|
||||
friend class ContextVK;
|
||||
|
||||
fml::RefPtr<vulkan::VulkanProcTable> vk_;
|
||||
UniqueAllocatorVMA allocator_;
|
||||
UniquePoolVMA staging_buffer_pool_;
|
||||
std::weak_ptr<Context> context_;
|
||||
@ -44,8 +42,6 @@ class AllocatorVK final : public Allocator {
|
||||
const vk::PhysicalDevice& physical_device,
|
||||
const std::shared_ptr<DeviceHolder>& device_holder,
|
||||
const vk::Instance& instance,
|
||||
PFN_vkGetInstanceProcAddr get_instance_proc_address,
|
||||
PFN_vkGetDeviceProcAddr get_device_proc_address,
|
||||
const CapabilitiesVK& capabilities);
|
||||
|
||||
// |Allocator|
|
||||
|
||||
@ -331,14 +331,12 @@ void ContextVK::Setup(Settings settings) {
|
||||
/// Create the allocator.
|
||||
///
|
||||
auto allocator = std::shared_ptr<AllocatorVK>(new AllocatorVK(
|
||||
weak_from_this(), //
|
||||
application_info.apiVersion, //
|
||||
device_holder->physical_device, //
|
||||
device_holder, //
|
||||
device_holder->instance.get(), //
|
||||
dispatcher.vkGetInstanceProcAddr, //
|
||||
dispatcher.vkGetDeviceProcAddr, //
|
||||
*caps //
|
||||
weak_from_this(), //
|
||||
application_info.apiVersion, //
|
||||
device_holder->physical_device, //
|
||||
device_holder, //
|
||||
device_holder->instance.get(), //
|
||||
*caps //
|
||||
));
|
||||
|
||||
if (!allocator->IsValid()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user