-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Check for lazy memory support. #43339
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ AllocatorVK::AllocatorVK(std::weak_ptr<Context> context, | |
const std::shared_ptr<DeviceHolder>& device_holder, | ||
const vk::Instance& instance, | ||
PFN_vkGetInstanceProcAddr get_instance_proc_address, | ||
PFN_vkGetDeviceProcAddr get_device_proc_address) | ||
PFN_vkGetDeviceProcAddr get_device_proc_address, | ||
const CapabilitiesVK& capabilities) | ||
: context_(std::move(context)), device_holder_(device_holder) { | ||
vk_ = fml::MakeRefCounted<vulkan::VulkanProcTable>(get_instance_proc_address); | ||
|
||
|
@@ -91,6 +92,7 @@ AllocatorVK::AllocatorVK(std::weak_ptr<Context> context, | |
return; | ||
} | ||
allocator_ = allocator; | ||
supports_memoryless_textures_ = capabilities.SupportsMemorylessTextures(); | ||
is_valid_ = true; | ||
} | ||
|
||
|
@@ -110,17 +112,21 @@ ISize AllocatorVK::GetMaxTextureSizeSupported() const { | |
return max_texture_size_; | ||
} | ||
|
||
static constexpr vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, | ||
TextureUsageMask usage, | ||
StorageMode mode) { | ||
static constexpr vk::ImageUsageFlags ToVKImageUsageFlags( | ||
PixelFormat format, | ||
TextureUsageMask usage, | ||
StorageMode mode, | ||
bool supports_memoryless_textures) { | ||
vk::ImageUsageFlags vk_usage; | ||
|
||
switch (mode) { | ||
case StorageMode::kHostVisible: | ||
case StorageMode::kDevicePrivate: | ||
break; | ||
case StorageMode::kDeviceTransient: | ||
vk_usage |= vk::ImageUsageFlagBits::eTransientAttachment; | ||
if (supports_memoryless_textures) { | ||
vk_usage |= vk::ImageUsageFlagBits::eTransientAttachment; | ||
} | ||
break; | ||
} | ||
|
||
|
@@ -168,7 +174,25 @@ static constexpr VmaMemoryUsage ToVMAMemoryUsage() { | |
return VMA_MEMORY_USAGE_AUTO; | ||
} | ||
|
||
static constexpr VkMemoryPropertyFlags ToVKMemoryPropertyFlags( | ||
static constexpr VkMemoryPropertyFlags ToVKTextureMemoryPropertyFlags( | ||
StorageMode mode, | ||
bool supports_memoryless_textures) { | ||
switch (mode) { | ||
case StorageMode::kHostVisible: | ||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; | ||
case StorageMode::kDevicePrivate: | ||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | ||
case StorageMode::kDeviceTransient: | ||
if (supports_memoryless_textures) { | ||
return VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT | | ||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | ||
} | ||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | ||
} | ||
FML_UNREACHABLE(); | ||
} | ||
|
||
static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags( | ||
StorageMode mode) { | ||
switch (mode) { | ||
case StorageMode::kHostVisible: | ||
|
@@ -196,9 +220,6 @@ static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode, | |
} | ||
return flags; | ||
case StorageMode::kDevicePrivate: | ||
if (is_texture) { | ||
flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; | ||
} | ||
return flags; | ||
case StorageMode::kDeviceTransient: | ||
return flags; | ||
|
@@ -210,7 +231,8 @@ class AllocatedTextureSourceVK final : public TextureSourceVK { | |
public: | ||
AllocatedTextureSourceVK(const TextureDescriptor& desc, | ||
VmaAllocator allocator, | ||
vk::Device device) | ||
vk::Device device, | ||
bool supports_memoryless_textures) | ||
: TextureSourceVK(desc) { | ||
vk::ImageCreateInfo image_info; | ||
image_info.flags = ToVKImageCreateFlags(desc.type); | ||
|
@@ -227,13 +249,15 @@ class AllocatedTextureSourceVK final : public TextureSourceVK { | |
image_info.tiling = vk::ImageTiling::eOptimal; | ||
image_info.initialLayout = vk::ImageLayout::eUndefined; | ||
image_info.usage = | ||
ToVKImageUsageFlags(desc.format, desc.usage, desc.storage_mode); | ||
ToVKImageUsageFlags(desc.format, desc.usage, desc.storage_mode, | ||
supports_memoryless_textures); | ||
image_info.sharingMode = vk::SharingMode::eExclusive; | ||
|
||
VmaAllocationCreateInfo alloc_nfo = {}; | ||
|
||
alloc_nfo.usage = ToVMAMemoryUsage(); | ||
alloc_nfo.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode); | ||
alloc_nfo.preferredFlags = ToVKTextureMemoryPropertyFlags( | ||
desc.storage_mode, supports_memoryless_textures); | ||
alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode, true); | ||
|
||
auto create_info_native = | ||
|
@@ -336,11 +360,12 @@ std::shared_ptr<Texture> AllocatorVK::OnCreateTexture( | |
if (!device_holder) { | ||
return nullptr; | ||
} | ||
auto source = | ||
std::make_shared<AllocatedTextureSourceVK>(desc, // | ||
allocator_, // | ||
device_holder->GetDevice() // | ||
); | ||
auto source = std::make_shared<AllocatedTextureSourceVK>( | ||
desc, // | ||
allocator_, // | ||
device_holder->GetDevice(), // | ||
supports_memoryless_textures_ // | ||
); | ||
if (!source->IsValid()) { | ||
return nullptr; | ||
} | ||
|
@@ -365,7 +390,8 @@ std::shared_ptr<DeviceBuffer> AllocatorVK::OnCreateBuffer( | |
|
||
VmaAllocationCreateInfo allocation_info = {}; | ||
allocation_info.usage = ToVMAMemoryUsage(); | ||
allocation_info.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode); | ||
allocation_info.preferredFlags = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably use required instead of preferred flags now since we are sure the device supports the type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto for the texture allocation too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah can do that. We will also need to cap check for host visible textures as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to get this working with some quick effort. lets track switching to required flags once we've chased down all the loose ends. |
||
ToVKBufferMemoryPropertyFlags(desc.storage_mode); | ||
allocation_info.flags = ToVmaAllocationCreateFlags(desc.storage_mode, false); | ||
|
||
VkBuffer buffer = {}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets not use VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT until we have a case where it performs better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought Angle did that for > 4MB allocations though. Perhaps just start off with that assumption, but for non-render targets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets follow up on this one in #43325 ?
If we don't remove this bit we'll have the same performance issues as dedicated allocations don't go into the pool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.