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 
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  Bytes 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_
An object that allocates device memory.
Definition: allocator.h:24
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.
static vk::ImageUsageFlags ToVKImageUsageFlags(PixelFormat format, TextureUsageMask usage, StorageMode mode, bool supports_memoryless_textures)
Bytes DebugGetHeapUsage() const override
The Vulkan layers and extensions wrangler.
StorageMode
Specified where the allocation resides and how it is used.
Definition: formats.h:32
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
fml::UniqueObject< VmaAllocator, AllocatorVMATraits > UniqueAllocatorVMA
Definition: vma.h:31
fml::UniqueObject< PoolVMA, PoolVMATraits > UniquePoolVMA
Definition: vma.h:63
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...