7 #include "flutter/fml/build_config.h" 
    8 #include "flutter/fml/logging.h" 
    9 #include "fml/trace_event.h" 
   22   return [device supportsFamily:MTLGPUFamilyApple2];
 
   32   if ([device supportsFamily:MTLGPUFamilyApple3] ||
 
   33       [device supportsFamily:MTLGPUFamilyMacCatalyst1] ||
 
   34       [device supportsFamily:MTLGPUFamilyMac1]) {
 
   35     return {16384, 16384};
 
   41 #ifdef FML_OS_IOS_SIMULATOR 
   44   return [device supportsFamily:MTLGPUFamilyApple8];
 
   49   size_.fetch_add(size, std::memory_order_relaxed);
 
   53   size_.fetch_sub(size, std::memory_order_relaxed);
 
   57   return Bytes{size_.load()};
 
   61     : device_(device), allocator_label_(
std::move(label)) {
 
   67   supports_uma_ = device_.hasUnifiedMemory;
 
   75 bool AllocatorMTL::IsValid()
 const {
 
   80                                                bool supports_memoryless_targets,
 
   85       return MTLResourceStorageModeShared;
 
   88         return MTLResourceStorageModeShared;
 
   90         return MTLResourceStorageModeManaged;
 
   94       return MTLResourceStorageModePrivate;
 
   96       if (supports_memoryless_targets) {
 
   98         if (@available(macOS 11.0, *)) {
 
   99           return MTLResourceStorageModeMemoryless;
 
  101           return MTLResourceStorageModePrivate;
 
  104         return MTLResourceStorageModePrivate;
 
  112                                        bool supports_memoryless_targets,
 
  117       return MTLStorageModeShared;
 
  120         return MTLStorageModeShared;
 
  122         return MTLStorageModeManaged;
 
  126       return MTLStorageModePrivate;
 
  128       if (supports_memoryless_targets) {
 
  130         if (@available(macOS 11.0, *)) {
 
  131           return MTLStorageModeMemoryless;
 
  133           return MTLStorageModePrivate;
 
  136         return MTLStorageModePrivate;
 
  143 std::shared_ptr<DeviceBuffer> AllocatorMTL::OnCreateBuffer(
 
  144     const DeviceBufferDescriptor& desc) {
 
  146       desc.storage_mode, supports_memoryless_targets_, supports_uma_);
 
  148       desc.storage_mode, supports_memoryless_targets_, supports_uma_);
 
  150   auto buffer = [device_ newBufferWithLength:desc.size
 
  151                                      options:resource_options];
 
  155   return std::shared_ptr<DeviceBufferMTL>(
new DeviceBufferMTL(desc,         
 
  161 std::shared_ptr<Texture> AllocatorMTL::OnCreateTexture(
 
  162     const TextureDescriptor& desc) {
 
  169   if (!mtl_texture_desc) {
 
  175       desc.storage_mode, supports_memoryless_targets_, supports_uma_);
 
  177   if (@available(macOS 12.5, ios 15.0, *)) {
 
  180       mtl_texture_desc.compressionType = MTLTextureCompressionTypeLossy;
 
  184 #ifdef IMPELLER_DEBUG 
  186     debug_allocater_->Increment(desc.GetByteSizeOfAllMipLevels());
 
  190   auto texture = [device_ newTextureWithDescriptor:mtl_texture_desc];
 
  194   std::shared_ptr<TextureMTL> result_texture =
 
  196 #ifdef IMPELLER_DEBUG 
  197   result_texture->SetDebugAllocator(debug_allocater_);
 
  200   return result_texture;
 
  203 uint16_t AllocatorMTL::MinimumBytesPerRow(
PixelFormat format)
 const {
 
  204   return static_cast<uint16_t
>([device_
 
  208 ISize AllocatorMTL::GetMaxTextureSizeSupported()
 const {
 
  209   return max_texture_supported_;
 
  213   supports_uma_ = 
value;
 
  217 #ifdef IMPELLER_DEBUG 
  218   return debug_allocater_->GetAllocationSize();
 
  224 void AllocatorMTL::DebugTraceMemoryStatistics()
 const {
 
  225 #ifdef IMPELLER_DEBUG 
  226   FML_TRACE_COUNTER(
"flutter", 
"AllocatorMTL",
 
  227                     reinterpret_cast<int64_t
>(
this),  
 
  228                     "MemoryBudgetUsageMB",
 
void DebugSetSupportsUMA(bool value)
Bytes DebugGetHeapUsage() const override
Bytes GetAllocationSize()
Get the current tracked allocation size.
void Increment(size_t size)
Increment the tracked allocation size in bytes.
void Decrement(size_t size)
Decrement the tracked allocation size in bytes.
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
static MTLStorageMode ToMTLStorageMode(StorageMode mode, bool supports_memoryless_targets, bool supports_uma)
StorageMode
Specified where the allocation resides and how it is used.
static bool SupportsLossyTextureCompression(id< MTLDevice > device)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
ISize DeviceMaxTextureSizeSupported(id< MTLDevice > device)
static MTLResourceOptions ToMTLResourceOptions(StorageMode type, bool supports_memoryless_targets, bool supports_uma)
static bool DeviceSupportsDeviceTransientTargets(id< MTLDevice > device)
constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format)
MTLTextureDescriptor * ToMTLTextureDescriptor(const TextureDescriptor &desc)