| Flutter Impeller |

allocator_vk.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ALLOCATOR_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ALLOCATOR_VK_H_
7
8 #include "impeller/core/allocator.h"
9 #include "impeller/renderer/backend/vulkan/context_vk.h"
10 #include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
11 #include "impeller/renderer/backend/vulkan/device_holder_vk.h"
12 #include "impeller/renderer/backend/vulkan/vk.h"
13
14 #include <cstdint>
15 #include <memory>
16
17 namespace impeller {
18
19 class AllocatorVK final : public Allocator {
20 public:
21 // |Allocator|
22 ~AllocatorVK() override;
23
24 // |Allocator|
25 size_t DebugGetHeapUsage() const override;
26
27 /// @brief Select a matching memory type for the given
28 /// [memory_type_bits_requirement], or -1 if none is found.
29 ///
30 /// This only returns memory types with deviceLocal allocations.
31 static int32_t FindMemoryTypeIndex(
32 uint32_t memory_type_bits_requirement,
33 vk::PhysicalDeviceMemoryProperties& memory_properties);
34
35 // Visible for testing.
36 static vk::ImageUsageFlags ToVKImageUsageFlags(
37 PixelFormat format,
38 TextureUsageMask usage,
39 StorageMode mode,
40 bool supports_memoryless_textures);
41
42 private:
43 friend class ContextVK;
44
45 UniqueAllocatorVMA allocator_;
46 UniquePoolVMA staging_buffer_pool_;
47 std::weak_ptr<Context> context_;
48 std::weak_ptr<DeviceHolderVK> device_holder_;
49 ISize max_texture_size_;
50 bool is_valid_ = false;
51 bool supports_memoryless_textures_ = false;
52 // TODO(jonahwilliams): figure out why CI can't create these buffer pools.
53 bool created_buffer_pool_ = true;
54 vk::PhysicalDeviceMemoryProperties memory_properties_;
55
56 AllocatorVK(std::weak_ptr<Context> context,
57 uint32_t vulkan_api_version,
58 const vk::PhysicalDevice& physical_device,
59 const std::shared_ptr<DeviceHolderVK>& device_holder,
60 const vk::Instance& instance,
61 const CapabilitiesVK& capabilities);
62
63 // |Allocator|
64 bool IsValid() const;
65
66 // |Allocator|
67 std::shared_ptr<DeviceBuffer> OnCreateBuffer(
68 const DeviceBufferDescriptor& desc) override;
69
70 // |Allocator|
71 std::shared_ptr<Texture> OnCreateTexture(
72 const TextureDescriptor& desc) override;
73
74 // |Allocator|
75 ISize GetMaxTextureSizeSupported() const override;
76
77 // |Allocator|
78 void DebugTraceMemoryStatistics() const override;
79
80 AllocatorVK(const AllocatorVK&) = delete;
81
82 AllocatorVK& operator=(const AllocatorVK&) = delete;
83 };
84
85 } // namespace impeller
86
87 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ALLOCATOR_VK_H_
impeller::AllocatorVK::FindMemoryTypeIndex
static int32_t FindMemoryTypeIndex(uint32_t memory_type_bits_requirement, vk::PhysicalDeviceMemoryProperties &memory_properties)
Select a matching memory type for the given [memory_type_bits_requirement], or -1 if none is found.
Definition: allocator_vk.cc:173
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::UniquePoolVMA
fml::UniqueObject< PoolVMA, PoolVMATraits > UniquePoolVMA
Definition: vma.h:63
impeller::AllocatorVK::~AllocatorVK
~AllocatorVK() override
vk.h
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
device_holder_vk.h
impeller::AllocatorVK::ToVKImageUsageFlags
static vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
Definition: allocator_vk.cc:199
impeller::Mask< TextureUsage >
impeller::TSize
Definition: size.h:19
impeller::StorageMode
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:32
impeller::AllocatorVK
Definition: allocator_vk.h:19
impeller::Allocator
An object that allocates device memory.
Definition: allocator.h:22
impeller::CapabilitiesVK
The Vulkan layers and extensions wrangler.
Definition: capabilities_vk.h:140
impeller::ContextVK
Definition: context_vk.h:42
impeller::UniqueAllocatorVMA
fml::UniqueObject< VmaAllocator, AllocatorVMATraits > UniqueAllocatorVMA
Definition: vma.h:31
allocator.h
device_buffer_vk.h
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:38
context_vk.h
impeller
Definition: aiks_blend_unittests.cc:18
impeller::AllocatorVK::DebugGetHeapUsage
size_t DebugGetHeapUsage() const override
Definition: allocator_vk.cc:512