7 #include "flutter/fml/build_config.h"
8 #include "flutter/fml/logging.h"
9 #include "fml/trace_event.h"
22 if (@available(ios 13.0, tvos 13.0, macos 10.15, *)) {
23 return [device supportsFamily:MTLGPUFamilyApple2];
29 return [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v1];
41 if (@available(ios 13.0, tvos 13.0, macOS 10.15, *)) {
42 return [device hasUnifiedMemory];
62 if (@available(macOS 10.15, iOS 13, tvOS 13, *)) {
63 if ([device supportsFamily:MTLGPUFamilyApple3] ||
64 [device supportsFamily:MTLGPUFamilyMacCatalyst1] ||
65 [device supportsFamily:MTLGPUFamilyMac1]) {
66 return {16384, 16384};
71 if ([device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] ||
72 [device supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
73 return {16384, 16384};
77 return {16384, 16384};
84 #ifdef FML_OS_IOS_SIMULATOR
87 if (@available(macOS 10.15, iOS 13, tvOS 13, *)) {
88 return [device supportsFamily:MTLGPUFamilyApple8];
95 size_.fetch_add(size, std::memory_order_relaxed);
99 size_.fetch_sub(size, std::memory_order_relaxed);
103 return Bytes{size_.load()};
107 : device_(device), allocator_label_(
std::move(label)) {
121 bool AllocatorMTL::IsValid()
const {
126 bool supports_memoryless_targets,
131 return MTLResourceStorageModeShared;
134 return MTLResourceStorageModeShared;
136 return MTLResourceStorageModeManaged;
140 return MTLResourceStorageModePrivate;
142 if (supports_memoryless_targets) {
144 if (@available(macOS 11.0, *)) {
145 return MTLResourceStorageModeMemoryless;
147 return MTLResourceStorageModePrivate;
150 return MTLResourceStorageModePrivate;
158 bool supports_memoryless_targets,
163 return MTLStorageModeShared;
166 return MTLStorageModeShared;
168 return MTLStorageModeManaged;
172 return MTLStorageModePrivate;
174 if (supports_memoryless_targets) {
176 if (@available(macOS 11.0, *)) {
177 return MTLStorageModeMemoryless;
179 return MTLStorageModePrivate;
182 return MTLStorageModePrivate;
189 std::shared_ptr<DeviceBuffer> AllocatorMTL::OnCreateBuffer(
190 const DeviceBufferDescriptor& desc) {
192 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
194 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
196 auto buffer = [device_ newBufferWithLength:desc.size
197 options:resource_options];
201 return std::shared_ptr<DeviceBufferMTL>(
new DeviceBufferMTL(desc,
207 std::shared_ptr<Texture> AllocatorMTL::OnCreateTexture(
208 const TextureDescriptor& desc) {
215 if (!mtl_texture_desc) {
221 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
223 if (@available(macOS 12.5, ios 15.0, *)) {
226 mtl_texture_desc.compressionType = MTLTextureCompressionTypeLossy;
230 #ifdef IMPELLER_DEBUG
232 debug_allocater_->Increment(desc.GetByteSizeOfAllMipLevels());
234 #endif // IMPELLER_DEBUG
236 auto texture = [device_ newTextureWithDescriptor:mtl_texture_desc];
240 std::shared_ptr<TextureMTL> result_texture =
242 #ifdef IMPELLER_DEBUG
243 result_texture->SetDebugAllocator(debug_allocater_);
244 #endif // IMPELLER_DEBUG
246 return result_texture;
249 uint16_t AllocatorMTL::MinimumBytesPerRow(
PixelFormat format)
const {
250 return static_cast<uint16_t
>([device_
254 ISize AllocatorMTL::GetMaxTextureSizeSupported()
const {
255 return max_texture_supported_;
259 #ifdef IMPELLER_DEBUG
260 return debug_allocater_->GetAllocationSize();
263 #endif // IMPELLER_DEBUG
266 void AllocatorMTL::DebugTraceMemoryStatistics()
const {
267 #ifdef IMPELLER_DEBUG
268 FML_TRACE_COUNTER(
"flutter",
"AllocatorMTL",
269 reinterpret_cast<int64_t
>(
this),
270 "MemoryBudgetUsageMB",
272 #endif // IMPELLER_DEBUG