| Flutter Impeller |

allocator_mtl.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_METAL_ALLOCATOR_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_ALLOCATOR_MTL_H_
7
8 #include <Metal/Metal.h>
9 #include <atomic>
10
11 #include "impeller/base/thread.h"
12 #include "impeller/core/allocator.h"
13
14 namespace impeller {
15
16 class DebugAllocatorStats {
17 public:
18 DebugAllocatorStats() {}
19
20 ~DebugAllocatorStats() {}
21
22 /// Increment the tracked allocation size in bytes.
23 void Increment(size_t size);
24
25 /// Decrement the tracked allocation size in bytes.
26 void Decrement(size_t size);
27
28 /// Get the current tracked allocation size.
29 Bytes GetAllocationSize();
30
31 private:
32 std::atomic<size_t> size_ = 0;
33 };
34
35 ISize DeviceMaxTextureSizeSupported(id<MTLDevice> device);
36
37 class AllocatorMTL final : public Allocator {
38 public:
39 AllocatorMTL();
40
41 // |Allocator|
42 ~AllocatorMTL() override;
43
44 // |Allocator|
45 Bytes DebugGetHeapUsage() const override;
46
47 // visible for testing.
48 void DebugSetSupportsUMA(bool value);
49
50 AllocatorMTL(id<MTLDevice> device, std::string label);
51
52 private:
53 friend class ContextMTL;
54
55 id<MTLDevice> device_;
56 std::string allocator_label_;
57 bool supports_memoryless_targets_ = false;
58 bool supports_uma_ = false;
59 bool is_valid_ = false;
60
61 #ifdef IMPELLER_DEBUG
62 std::shared_ptr<DebugAllocatorStats> debug_allocater_ =
63 std::make_shared<DebugAllocatorStats>();
64 #endif // IMPELLER_DEBUG
65
66 ISize max_texture_supported_;
67
68 // |Allocator|
69 bool IsValid() const;
70
71 // |Allocator|
72 std::shared_ptr<DeviceBuffer> OnCreateBuffer(
73 const DeviceBufferDescriptor& desc) override;
74
75 // |Allocator|
76 std::shared_ptr<Texture> OnCreateTexture(const TextureDescriptor& desc,
77 bool threadsafe) override;
78
79 // |Allocator|
80 uint16_t MinimumBytesPerRow(PixelFormat format) const override;
81
82 // |Allocator|
83 ISize GetMaxTextureSizeSupported() const override;
84
85 // |Allocator|
86 void DebugTraceMemoryStatistics() const override;
87
88 AllocatorMTL(const AllocatorMTL&) = delete;
89
90 AllocatorMTL& operator=(const AllocatorMTL&) = delete;
91 };
92
93 } // namespace impeller
94
95 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_ALLOCATOR_MTL_H_
allocator.h
impeller::AllocationSize< 1u >
impeller::Allocator
An object that allocates device memory.
Definition: allocator.h:24
impeller::AllocatorMTL
Definition: allocator_mtl.h:37
impeller::AllocatorMTL::DebugSetSupportsUMA
void DebugSetSupportsUMA(bool value)
Definition: allocator_mtl.mm:213
impeller::AllocatorMTL::AllocatorMTL
AllocatorMTL()
impeller::AllocatorMTL::DebugGetHeapUsage
Bytes DebugGetHeapUsage() const override
Definition: allocator_mtl.mm:217
impeller::AllocatorMTL::~AllocatorMTL
~AllocatorMTL() override
impeller::ContextMTL
Definition: context_mtl.h:67
impeller::DebugAllocatorStats
Definition: allocator_mtl.h:16
impeller::DebugAllocatorStats::~DebugAllocatorStats
~DebugAllocatorStats()
Definition: allocator_mtl.h:20
impeller::DebugAllocatorStats::DebugAllocatorStats
DebugAllocatorStats()
Definition: allocator_mtl.h:18
impeller::DebugAllocatorStats::GetAllocationSize
Bytes GetAllocationSize()
Get the current tracked allocation size.
Definition: allocator_mtl.mm:56
impeller::DebugAllocatorStats::Increment
void Increment(size_t size)
Increment the tracked allocation size in bytes.
Definition: allocator_mtl.mm:48
impeller::DebugAllocatorStats::Decrement
void Decrement(size_t size)
Decrement the tracked allocation size in bytes.
Definition: allocator_mtl.mm:52
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::DeviceMaxTextureSizeSupported
ISize DeviceMaxTextureSizeSupported(id< MTLDevice > device)
Definition: allocator_mtl.mm:25
impeller::ISize
ISize64 ISize
Definition: size.h:162
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::TSize
Definition: size.h:25
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
thread.h