| 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/formats.h"
7 #include "impeller/core/texture_descriptor.h"
8 #include "impeller/playground/playground_test.h"
9 #include "impeller/renderer/backend/metal/allocator_mtl.h"
10 #include "impeller/renderer/backend/metal/context_mtl.h"
11 #include "impeller/renderer/backend/metal/formats_mtl.h"
12 #include "impeller/renderer/backend/metal/lazy_drawable_holder.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(), 0u);
33
34 // Memoryless texture does not increase allocated size.
35 {
36 TextureDescriptor desc;
37 desc.format = PixelFormat::kR8G8B8A8UNormInt;
38 desc.storage_mode = StorageMode::kDeviceTransient;
39 desc.size = {1024, 1024};
40 auto texture_1 = allocator->CreateTexture(desc);
41
42 EXPECT_EQ(allocator->DebugGetHeapUsage(), 0u);
43
44 // Private storage texture increases allocated size.
45 desc.storage_mode = StorageMode::kDevicePrivate;
46 auto texture_2 = allocator->CreateTexture(desc);
47
48 #ifdef IMPELLER_DEBUG
49 EXPECT_EQ(allocator->DebugGetHeapUsage(), 4u);
50 #else
51 EXPECT_EQ(allocator->DebugGetHeapUsage(), 0u);
52 #endif // IMPELLER_DEBUG
53
54 // Host storage texture increases allocated size.
55 desc.storage_mode = StorageMode::kHostVisible;
56 auto texture_3 = allocator->CreateTexture(desc);
57
58 #ifdef IMPELLER_DEBUG
59 EXPECT_EQ(allocator->DebugGetHeapUsage(), 8u);
60 #else
61 EXPECT_EQ(allocator->DebugGetHeapUsage(), 0u);
62 #endif // IMPELLER_DEBUG
63 }
64
65 // After all textures are out of scope, memory has been decremented.
66 EXPECT_EQ(allocator->DebugGetHeapUsage(), 0u);
67 }
68
69 } // namespace testing
70 } // namespace impeller
context_mtl.h
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
texture_descriptor.h
formats.h
allocator_mtl.h
formats_mtl.h
impeller::testing::INSTANTIATE_METAL_PLAYGROUND_SUITE
INSTANTIATE_METAL_PLAYGROUND_SUITE(AllocatorMTLTest)
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
Definition: aiks_blend_unittests.cc:21
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
capabilities.h
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
lazy_drawable_holder.h
texture_mtl.h
impeller::BackendCast< ContextMTL, Context >::Cast
static ContextMTL & Cast(Context &base)
Definition: backend_cast.h:13
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:39
impeller::PlaygroundTest
Definition: playground_test.h:21
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
Definition: aiks_blend_unittests.cc:18
playground_test.h