7 #include "flutter/fml/build_config.h"
8 #include "flutter/fml/logging.h"
9 #include "fml/trace_event.h"
21 if (@available(ios 13.0, tvos 13.0, macos 10.15, *)) {
22 return [device supportsFamily:MTLGPUFamilyApple2];
28 return [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v1];
40 if (@available(ios 13.0, tvos 13.0, macOS 10.15, *)) {
41 return [device hasUnifiedMemory];
61 if (@available(macOS 10.15, iOS 13, tvOS 13, *)) {
62 if ([device supportsFamily:MTLGPUFamilyApple3] ||
63 [device supportsFamily:MTLGPUFamilyMacCatalyst1] ||
64 [device supportsFamily:MTLGPUFamilyMac1]) {
65 return {16384, 16384};
70 if ([device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] ||
71 [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
72 return {16384, 16384};
76 return {16384, 16384};
83 #ifdef FML_OS_IOS_SIMULATOR
86 if (@available(macOS 10.15, iOS 13, tvOS 13, *)) {
87 return [device supportsFamily:MTLGPUFamilyApple8];
94 size_.fetch_add(size, std::memory_order_relaxed);
98 size_.fetch_sub(size, std::memory_order_relaxed);
103 size_t new_value = size_ / (1024 * 1024);
108 : device_(device), allocator_label_(
std::move(label)) {
122 bool AllocatorMTL::IsValid()
const {
127 bool supports_memoryless_targets,
132 return MTLResourceStorageModeShared;
135 return MTLResourceStorageModeShared;
137 return MTLResourceStorageModeManaged;
141 return MTLResourceStorageModePrivate;
143 if (supports_memoryless_targets) {
145 if (@available(macOS 11.0, *)) {
146 return MTLResourceStorageModeMemoryless;
148 return MTLResourceStorageModePrivate;
151 return MTLResourceStorageModePrivate;
159 bool supports_memoryless_targets,
164 return MTLStorageModeShared;
167 return MTLStorageModeShared;
169 return MTLStorageModeManaged;
173 return MTLStorageModePrivate;
175 if (supports_memoryless_targets) {
177 if (@available(macOS 11.0, *)) {
178 return MTLStorageModeMemoryless;
180 return MTLStorageModePrivate;
183 return MTLStorageModePrivate;
190 std::shared_ptr<DeviceBuffer> AllocatorMTL::OnCreateBuffer(
191 const DeviceBufferDescriptor& desc) {
193 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
195 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
197 auto buffer = [device_ newBufferWithLength:desc.size
198 options:resource_options];
202 return std::shared_ptr<DeviceBufferMTL>(
new DeviceBufferMTL(desc,
208 std::shared_ptr<Texture> AllocatorMTL::OnCreateTexture(
209 const TextureDescriptor& desc) {
216 if (!mtl_texture_desc) {
222 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
224 if (@available(macOS 12.5, ios 15.0, *)) {
227 mtl_texture_desc.compressionType = MTLTextureCompressionTypeLossy;
231 #ifdef IMPELLER_DEBUG
233 debug_allocater_->Increment(desc.GetByteSizeOfAllMipLevels());
235 #endif // IMPELLER_DEBUG
237 auto texture = [device_ newTextureWithDescriptor:mtl_texture_desc];
241 std::shared_ptr<TextureMTL> result_texture =
243 #ifdef IMPELLER_DEBUG
244 result_texture->SetDebugAllocator(debug_allocater_);
245 #endif // IMPELLER_DEBUG
247 return result_texture;
250 uint16_t AllocatorMTL::MinimumBytesPerRow(
PixelFormat format)
const {
251 return static_cast<uint16_t
>([device_
255 ISize AllocatorMTL::GetMaxTextureSizeSupported()
const {
256 return max_texture_supported_;
260 #ifdef IMPELLER_DEBUG
261 return debug_allocater_->GetAllocationSizeMB();
264 #endif // IMPELLER_DEBUG
267 void AllocatorMTL::DebugTraceMemoryStatistics()
const {
268 #ifdef IMPELLER_DEBUG
270 FML_TRACE_COUNTER(
"flutter",
"AllocatorMTL",
271 reinterpret_cast<int64_t
>(
this),
272 "MemoryBudgetUsageMB", allocated_size);
273 #endif // IMPELLER_DEBUG