This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Allocate fewer textures in dedicated memory and adjust buffer flags. #43313
Merged
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b6b5f80
[Impeller] allocate fewer textures in dedicated memory.
0798fe1
Update allocator_vk.cc
4826724
format
9c652d1
move to limits.vk
0eeccc9
++
660e641
merge and cleanup.
83aac9e
add sequential access.
4c7ea58
Update licenses_flutter
03c6d7a
Revert "Update licenses_flutter"
549d82e
Revert "add sequential access."
0091faa
back to preferred flags.
3d5b5ba
++
b14537b
Update licenses_flutter
5b5d7ed
Merge branch 'main' into dedicated_memory
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,11 @@ | |
|
|
||
| namespace impeller { | ||
|
|
||
| // Maximum size to use VMA image suballocation. Any allocation greater than or | ||
| // equal to this value will use a dedicated VkDeviceMemory. | ||
| constexpr size_t kImageSizeThresholdForDedicatedMemoryAllocation = | ||
| 4 * 1024 * 1024; | ||
|
|
||
| AllocatorVK::AllocatorVK(std::weak_ptr<Context> context, | ||
| uint32_t vulkan_api_version, | ||
| const vk::PhysicalDevice& physical_device, | ||
|
|
@@ -184,19 +189,25 @@ static constexpr VkMemoryPropertyFlags ToVKMemoryPropertyFlags( | |
| } | ||
|
|
||
| static VmaAllocationCreateFlags ToVmaAllocationCreateFlags(StorageMode mode, | ||
| bool is_texture) { | ||
| bool is_texture, | ||
| size_t size) { | ||
| VmaAllocationCreateFlags flags = 0; | ||
| switch (mode) { | ||
| case StorageMode::kHostVisible: | ||
| if (is_texture) { | ||
| flags |= {}; | ||
| if (size >= kImageSizeThresholdForDedicatedMemoryAllocation) { | ||
| flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; | ||
| } else { | ||
| flags |= {}; | ||
| } | ||
| } else { | ||
| flags |= VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT; | ||
|
Contributor
Author
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. The random access bit was the one causing problems. We shouldn't need this since the memory is coherent for reading in the GPU and we're not using it to readback data on the CPU |
||
| flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; | ||
| } | ||
| return flags; | ||
| case StorageMode::kDevicePrivate: | ||
| if (is_texture) { | ||
| if (is_texture && | ||
| size >= kImageSizeThresholdForDedicatedMemoryAllocation) { | ||
| flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; | ||
| } | ||
| return flags; | ||
|
|
@@ -234,7 +245,9 @@ class AllocatedTextureSourceVK final : public TextureSourceVK { | |
|
|
||
| alloc_nfo.usage = ToVMAMemoryUsage(); | ||
| alloc_nfo.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode); | ||
| alloc_nfo.flags = ToVmaAllocationCreateFlags(desc.storage_mode, true); | ||
| alloc_nfo.flags = | ||
| ToVmaAllocationCreateFlags(desc.storage_mode, /*is_texture=*/true, | ||
| desc.GetByteSizeOfBaseMipLevel()); | ||
|
|
||
| auto create_info_native = | ||
| static_cast<vk::ImageCreateInfo::NativeType>(image_info); | ||
|
|
@@ -366,7 +379,8 @@ std::shared_ptr<DeviceBuffer> AllocatorVK::OnCreateBuffer( | |
| VmaAllocationCreateInfo allocation_info = {}; | ||
| allocation_info.usage = ToVMAMemoryUsage(); | ||
| allocation_info.preferredFlags = ToVKMemoryPropertyFlags(desc.storage_mode); | ||
| allocation_info.flags = ToVmaAllocationCreateFlags(desc.storage_mode, false); | ||
| allocation_info.flags = ToVmaAllocationCreateFlags( | ||
| desc.storage_mode, /*is_texture=*/false, desc.size); | ||
|
|
||
| VkBuffer buffer = {}; | ||
| VmaAllocation buffer_allocation = {}; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's put these in a more discoverable place. I bet we will add more for buffers and all sort of other tunables. Perhaps
//impeller/renderer/backend/vulkan/limits_vk.h? In a later patch is fine.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.
Done