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 all 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
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
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
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
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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| #include "impeller/core/formats.h" | ||
| #include "impeller/renderer/backend/vulkan/device_buffer_vk.h" | ||
| #include "impeller/renderer/backend/vulkan/formats_vk.h" | ||
| #include "impeller/renderer/backend/vulkan/limits_vk.h" | ||
| #include "impeller/renderer/backend/vulkan/texture_vk.h" | ||
|
|
||
| namespace impeller { | ||
|
|
@@ -198,9 +199,9 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags( | |
| StorageMode mode) { | ||
| switch (mode) { | ||
| case StorageMode::kHostVisible: | ||
| // See https://github.com/flutter/flutter/issues/128556 . Some devices do | ||
| // not have support for coherent host memory so we don't request it here. | ||
| return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; | ||
| return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | | ||
| VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | | ||
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; | ||
| case StorageMode::kDevicePrivate: | ||
| return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; | ||
| case StorageMode::kDeviceTransient: | ||
|
|
@@ -210,18 +211,27 @@ static constexpr VkMemoryPropertyFlags ToVKBufferMemoryPropertyFlags( | |
| } | ||
|
|
||
| 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_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; | ||
| flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; | ||
| } | ||
| return flags; | ||
| case StorageMode::kDevicePrivate: | ||
| if (is_texture && | ||
| size >= kImageSizeThresholdForDedicatedMemoryAllocation) { | ||
| flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; | ||
| } | ||
| return flags; | ||
| case StorageMode::kDeviceTransient: | ||
| return flags; | ||
|
|
@@ -261,7 +271,9 @@ class AllocatedTextureSourceVK final : public TextureSourceVK { | |
| alloc_nfo.usage = ToVMAMemoryUsage(); | ||
| alloc_nfo.preferredFlags = ToVKTextureMemoryPropertyFlags( | ||
| desc.storage_mode, supports_memoryless_textures); | ||
| 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); | ||
|
|
@@ -396,7 +408,8 @@ std::shared_ptr<DeviceBuffer> AllocatorVK::OnCreateBuffer( | |
| allocation_info.usage = ToVMAMemoryUsage(); | ||
| allocation_info.preferredFlags = | ||
| ToVKBufferMemoryPropertyFlags(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 = {}; | ||
|
|
||
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
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
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 |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #pragma once | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| namespace impeller { | ||
|
|
||
| // Maximum size to use VMA image suballocation. Any allocation greater than or | ||
| // equal to this value will use a dedicated VkDeviceMemory. | ||
| // | ||
| // This value was taken from ANGLE. | ||
| constexpr size_t kImageSizeThresholdForDedicatedMemoryAllocation = | ||
| 4 * 1024 * 1024; | ||
|
|
||
| } // namespace impeller |
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
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.
The memory we want actually has all three flags here.