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;
75bool 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;
143std::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,
161std::shared_ptr<Texture> AllocatorMTL::OnCreateTexture(
162 const TextureDescriptor& desc,
170 if (!mtl_texture_desc) {
176 desc.storage_mode, supports_memoryless_targets_, supports_uma_);
178 if (@available(macOS 12.5, ios 15.0, *)) {
181 mtl_texture_desc.compressionType = MTLTextureCompressionTypeLossy;
187 debug_allocater_->Increment(desc.GetByteSizeOfAllMipLevels());
191 auto texture = [device_ newTextureWithDescriptor:mtl_texture_desc];
195 std::shared_ptr<TextureMTL> result_texture =
198 result_texture->SetDebugAllocator(debug_allocater_);
201 return result_texture;
204uint16_t AllocatorMTL::MinimumBytesPerRow(
PixelFormat format)
const {
205 return static_cast<uint16_t
>([device_
209ISize AllocatorMTL::GetMaxTextureSizeSupported()
const {
210 return max_texture_supported_;
214 supports_uma_ =
value;
219 return debug_allocater_->GetAllocationSize();
225void AllocatorMTL::DebugTraceMemoryStatistics()
const {
228 reinterpret_cast<int64_t
>(
this),
229 "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)
#define FML_UNREACHABLE()
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)
#define FML_TRACE_COUNTER(category_group, name, counter_id, arg1,...)