| Flutter Impeller |

swapchain_transients_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/swapchain_transients_mtl.h"
13 #include "impeller/renderer/backend/metal/texture_mtl.h"
14 #include "impeller/renderer/capabilities.h"
15
16 #include <memory>
17 #include <thread>
18
19 #include "gtest/gtest.h"
20
21 namespace impeller {
22 namespace testing {
23
24 using SwapchainTransientsMTLTest = PlaygroundTest;
25 INSTANTIATE_METAL_PLAYGROUND_SUITE(SwapchainTransientsMTLTest);
26
27 TEST_P(SwapchainTransientsMTLTest, CanAllocateSwapchainTextures) {
28 const auto& transients = std::make_shared<SwapchainTransientsMTL>(
29 GetContext()->GetResourceAllocator());
30
31 transients->SetSizeAndFormat({1, 1}, PixelFormat::kB8G8R8A8UNormInt);
32
33 auto resolve = transients->GetResolveTexture();
34 EXPECT_NE(resolve, nullptr);
35 EXPECT_NE(transients->GetMSAATexture(), nullptr);
36 EXPECT_NE(transients->GetDepthStencilTexture(), nullptr);
37
38 // Texture properties are correct for resolve.
39 EXPECT_EQ(resolve->GetTextureDescriptor().size, ISize(1, 1));
40 EXPECT_EQ(resolve->GetTextureDescriptor().format,
41 PixelFormat::kB8G8R8A8UNormInt);
42 EXPECT_EQ(resolve->GetTextureDescriptor().sample_count, SampleCount::kCount1);
43 EXPECT_EQ(resolve->GetTextureDescriptor().storage_mode,
44 StorageMode::kDevicePrivate);
45
46 // Texture properties are correct for MSAA.
47 auto msaa = transients->GetMSAATexture();
48 EXPECT_EQ(msaa->GetTextureDescriptor().size, ISize(1, 1));
49 EXPECT_EQ(msaa->GetTextureDescriptor().format,
50 PixelFormat::kB8G8R8A8UNormInt);
51 EXPECT_EQ(msaa->GetTextureDescriptor().sample_count, SampleCount::kCount4);
52 EXPECT_EQ(msaa->GetTextureDescriptor().storage_mode,
53 StorageMode::kDeviceTransient);
54
55 // Texture properties are correct for Depth+Stencil.
56 auto depth_stencil = transients->GetDepthStencilTexture();
57 EXPECT_EQ(depth_stencil->GetTextureDescriptor().size, ISize(1, 1));
58 EXPECT_EQ(depth_stencil->GetTextureDescriptor().format,
59 PixelFormat::kD32FloatS8UInt);
60 EXPECT_EQ(depth_stencil->GetTextureDescriptor().sample_count,
61 SampleCount::kCount4);
62 EXPECT_EQ(depth_stencil->GetTextureDescriptor().storage_mode,
63 StorageMode::kDeviceTransient);
64
65 // Textures are cached.
66 EXPECT_EQ(transients->GetResolveTexture(), resolve);
67
68 // Texture cache is invalidated when size changes.
69 transients->SetSizeAndFormat({2, 2}, PixelFormat::kB8G8R8A8UNormInt);
70 EXPECT_NE(resolve, transients->GetResolveTexture());
71 resolve = transients->GetResolveTexture();
72
73 // Texture cache is invalidated when pixel format changes.
74 transients->SetSizeAndFormat({2, 2}, PixelFormat::kB10G10R10A10XR);
75 EXPECT_NE(resolve, transients->GetResolveTexture());
76 }
77
78 } // namespace testing
79 } // namespace impeller
allocator_mtl.h
capabilities.h
impeller::PlaygroundTest
Definition: playground_test.h:22
formats.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::kDeviceTransient
@ kDeviceTransient
impeller::PixelFormat::kB10G10R10A10XR
@ kB10G10R10A10XR
impeller::PixelFormat::kB8G8R8A8UNormInt
@ kB8G8R8A8UNormInt
impeller::PixelFormat::kD32FloatS8UInt
@ kD32FloatS8UInt
impeller::SampleCount::kCount4
@ kCount4
impeller::SampleCount::kCount1
@ kCount1
playground_test.h
context_mtl.h
impeller::TSize
Definition: size.h:25
swapchain_transients_mtl.h
texture_descriptor.h
texture_mtl.h