Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion impeller/renderer/backend/vulkan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
81 changes: 32 additions & 49 deletions impeller/renderer/backend/vulkan/allocator_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, did these even do anything? These tripped me up, I made them load in my injected proc and they had zero effect. It's like they load the procs and do nothing with them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew I hit a debug assert when I messed up not resolving them earlier. About their use, I can't say.

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;
Expand Down
4 changes: 0 additions & 4 deletions impeller/renderer/backend/vulkan/allocator_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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_;
Expand All @@ -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|
Expand Down
14 changes: 6 additions & 8 deletions impeller/renderer/backend/vulkan/context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down