| Flutter Impeller |

blit_pass_unittests.cc
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 "gtest/gtest.h"
6 #include "impeller/base/validation.h"
7 #include "impeller/core/device_buffer_descriptor.h"
8 #include "impeller/core/formats.h"
9 #include "impeller/core/texture_descriptor.h"
10 #include "impeller/playground/playground_test.h"
11 #include "impeller/renderer/command_buffer.h"
12
13 namespace impeller {
14 namespace testing {
15
16 using BlitPassTest = PlaygroundTest;
17 INSTANTIATE_PLAYGROUND_SUITE(BlitPassTest);
18
19 TEST_P(BlitPassTest, BlitAcrossDifferentPixelFormatsFails) {
20 ScopedValidationDisable scope; // avoid noise in output.
21 auto context = GetContext();
22 auto cmd_buffer = context->CreateCommandBuffer();
23 auto blit_pass = cmd_buffer->CreateBlitPass();
24
25 TextureDescriptor src_desc;
26 src_desc.format = PixelFormat::kA8UNormInt;
27 src_desc.size = {100, 100};
28 src_desc.storage_mode = StorageMode::kHostVisible;
29 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
30
31 TextureDescriptor dst_format;
32 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
33 dst_format.size = {100, 100};
34 dst_format.storage_mode = StorageMode::kHostVisible;
35 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
36
37 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
38 }
39
40 TEST_P(BlitPassTest, BlitAcrossDifferentSampleCountsFails) {
41 ScopedValidationDisable scope; // avoid noise in output.
42 auto context = GetContext();
43 auto cmd_buffer = context->CreateCommandBuffer();
44 auto blit_pass = cmd_buffer->CreateBlitPass();
45
46 TextureDescriptor src_desc;
47 src_desc.format = PixelFormat::kR8G8B8A8UNormInt;
48 src_desc.sample_count = SampleCount::kCount4;
49 src_desc.size = {100, 100};
50 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
51
52 TextureDescriptor dst_format;
53 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
54 dst_format.size = {100, 100};
55 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
56
57 EXPECT_FALSE(blit_pass->AddCopy(src, dst));
58 }
59
60 TEST_P(BlitPassTest, BlitPassesForMatchingFormats) {
61 ScopedValidationDisable scope; // avoid noise in output.
62 auto context = GetContext();
63 auto cmd_buffer = context->CreateCommandBuffer();
64 auto blit_pass = cmd_buffer->CreateBlitPass();
65
66 TextureDescriptor src_desc;
67 src_desc.format = PixelFormat::kR8G8B8A8UNormInt;
68 src_desc.size = {100, 100};
69 src_desc.storage_mode = StorageMode::kHostVisible;
70 auto src = context->GetResourceAllocator()->CreateTexture(src_desc);
71
72 TextureDescriptor dst_format;
73 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
74 dst_format.size = {100, 100};
75 dst_format.storage_mode = StorageMode::kHostVisible;
76 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
77
78 EXPECT_TRUE(blit_pass->AddCopy(src, dst));
79 }
80
81 TEST_P(BlitPassTest, ChecksInvalidSliceParameters) {
82 ScopedValidationDisable scope; // avoid noise in output.
83 auto context = GetContext();
84 auto cmd_buffer = context->CreateCommandBuffer();
85 auto blit_pass = cmd_buffer->CreateBlitPass();
86
87 TextureDescriptor dst_format;
88 dst_format.storage_mode = StorageMode::kDevicePrivate;
89 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
90 dst_format.size = {100, 100};
91 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
92
93 DeviceBufferDescriptor src_format;
94 src_format.size = 40000;
95 src_format.storage_mode = StorageMode::kHostVisible;
96 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
97
98 ASSERT_TRUE(dst);
99 ASSERT_TRUE(src);
100
101 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
102 std::nullopt, "", /*slice=*/25));
103 EXPECT_FALSE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
104 std::nullopt, "", /*slice=*/6));
105 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
106 std::nullopt, "", /*slice=*/0));
107 }
108
109 TEST_P(BlitPassTest, CanBlitSmallRegionToUninitializedTexture) {
110 auto context = GetContext();
111 auto cmd_buffer = context->CreateCommandBuffer();
112 auto blit_pass = cmd_buffer->CreateBlitPass();
113
114 TextureDescriptor dst_format;
115 dst_format.storage_mode = StorageMode::kDevicePrivate;
116 dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
117 dst_format.size = {1000, 1000};
118 auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);
119
120 DeviceBufferDescriptor src_format;
121 src_format.size = 4;
122 src_format.storage_mode = StorageMode::kHostVisible;
123 auto src = context->GetResourceAllocator()->CreateBuffer(src_format);
124
125 ASSERT_TRUE(dst);
126
127 EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
128 IRect::MakeLTRB(0, 0, 1, 1), "", /*slice=*/0));
129 EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
130 EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
131 }
132
133 } // namespace testing
134 } // namespace impeller
impeller::DeviceBuffer::AsBufferView
static BufferView AsBufferView(std::shared_ptr< DeviceBuffer > buffer)
Create a buffer view of this entire buffer.
Definition: device_buffer.cc:18
impeller::PixelFormat::kA8UNormInt
@ kA8UNormInt
impeller::DeviceBufferDescriptor
Definition: device_buffer_descriptor.h:14
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
texture_descriptor.h
formats.h
impeller::DeviceBufferDescriptor::size
size_t size
Definition: device_buffer_descriptor.h:16
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:45
validation.h
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderAdvancedBlendColorFilterWithSaveLayer)
Definition: aiks_blend_unittests.cc:21
impeller::testing::INSTANTIATE_PLAYGROUND_SUITE
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::DeviceBufferDescriptor::storage_mode
StorageMode storage_mode
Definition: device_buffer_descriptor.h:15
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:42
command_buffer.h
impeller::SampleCount::kCount4
@ kCount4
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:39
impeller::TRect::MakeLTRB
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition: rect.h:129
impeller::PlaygroundTest
Definition: playground_test.h:21
device_buffer_descriptor.h
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::ScopedValidationDisable
Definition: validation.h:38
impeller
Definition: aiks_blend_unittests.cc:18
playground_test.h