Flutter Impeller
allocator_mtl_unittests.mm
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
#include "flutter/testing/testing.h"
6
#include "
impeller/core/device_buffer_descriptor.h
"
7
#include "
impeller/core/formats.h
"
8
#include "
impeller/core/texture_descriptor.h
"
9
#include "
impeller/playground/playground_test.h
"
10
#include "
impeller/renderer/backend/metal/allocator_mtl.h
"
11
#include "
impeller/renderer/backend/metal/context_mtl.h
"
12
#include "
impeller/renderer/backend/metal/formats_mtl.h
"
13
#include "
impeller/renderer/backend/metal/texture_mtl.h
"
14
#include "
impeller/renderer/capabilities.h
"
15
16
#include <QuartzCore/CAMetalLayer.h>
17
#include <memory>
18
#include <thread>
19
20
#include "gtest/gtest.h"
21
22
namespace
impeller
{
23
namespace
testing {
24
25
using
AllocatorMTLTest
=
PlaygroundTest
;
26
INSTANTIATE_METAL_PLAYGROUND_SUITE
(
AllocatorMTLTest
);
27
28
TEST_P
(
AllocatorMTLTest
, DebugTraceMemoryStatistics) {
29
auto
& context_mtl =
ContextMTL::Cast
(*GetContext());
30
const
auto
& allocator = context_mtl.GetResourceAllocator();
31
32
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
33
0u);
34
35
// Memoryless texture does not increase allocated size.
36
{
37
TextureDescriptor
desc;
38
desc.
format
=
PixelFormat::kR8G8B8A8UNormInt
;
39
desc.
storage_mode
=
StorageMode::kDeviceTransient
;
40
desc.
size
= {1024, 1024};
41
auto
texture_1 = allocator->CreateTexture(desc);
42
43
// Private storage texture increases allocated size.
44
desc.
storage_mode
=
StorageMode::kDevicePrivate
;
45
auto
texture_2 = allocator->CreateTexture(desc);
46
47
#ifdef IMPELLER_DEBUG
48
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
49
4u);
50
#else
51
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
52
0u);
53
#endif
// IMPELLER_DEBUG
54
55
// Host storage texture increases allocated size.
56
desc.
storage_mode
=
StorageMode::kHostVisible
;
57
auto
texture_3 = allocator->CreateTexture(desc);
58
59
#ifdef IMPELLER_DEBUG
60
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
61
8u);
62
#else
63
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
64
0u);
65
#endif
// IMPELLER_DEBUG
66
}
67
68
// After all textures are out of scope, memory has been decremented.
69
EXPECT_EQ(allocator->DebugGetHeapUsage().ConvertTo<
MebiBytes
>().
GetSize
(),
70
0u);
71
}
72
73
TEST_P
(
AllocatorMTLTest
, ManagedMemory) {
74
auto
& context_mtl =
ContextMTL::Cast
(*GetContext());
75
auto
allocator = std::make_unique<AllocatorMTL>(context_mtl.GetMTLDevice(),
76
"test-allocator"
);
77
allocator->DebugSetSupportsUMA(
false
);
78
79
DeviceBufferDescriptor
desc;
80
desc.
size
= 100;
81
desc.
storage_mode
=
StorageMode::kHostVisible
;
82
83
auto
buffer = allocator->CreateBuffer(desc);
84
ASSERT_TRUE(buffer);
85
86
EXPECT_NE(buffer->OnGetContents(),
nullptr
);
87
}
88
89
}
// namespace testing
90
}
// namespace impeller
allocator_mtl.h
capabilities.h
impeller::AllocationSize
Represents the size of an allocation in different units.
Definition:
allocation_size.h:29
impeller::AllocationSize::GetSize
constexpr double GetSize() const
Definition:
allocation_size.h:76
impeller::BackendCast< ContextMTL, Context >::Cast
static ContextMTL & Cast(Context &base)
Definition:
backend_cast.h:13
impeller::PlaygroundTest
Definition:
playground_test.h:22
formats.h
device_buffer_descriptor.h
formats_mtl.h
impeller::testing::TEST_P
TEST_P(AiksTest, DrawAtlasNoColor)
Definition:
aiks_dl_atlas_unittests.cc:60
impeller::testing::INSTANTIATE_METAL_PLAYGROUND_SUITE
INSTANTIATE_METAL_PLAYGROUND_SUITE(AllocatorMTLTest)
impeller
Definition:
allocation.cc:12
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
playground_test.h
context_mtl.h
impeller::DeviceBufferDescriptor
Definition:
device_buffer_descriptor.h:14
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition:
device_buffer_descriptor.h:15
impeller::DeviceBufferDescriptor::size
size_t size
Definition:
device_buffer_descriptor.h:16
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
impeller::TextureDescriptor::size
ISize size
Definition:
texture_descriptor.h:42
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition:
texture_descriptor.h:39
impeller::TextureDescriptor::format
PixelFormat format
Definition:
texture_descriptor.h:41
texture_descriptor.h
texture_mtl.h
impeller
renderer
backend
metal
allocator_mtl_unittests.mm
Generated by
1.9.1