| Flutter Impeller |

blit_pass_vk_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 "flutter/testing/testing.h"
6 #include "fml/macros.h"
7 #include "impeller/renderer/backend/vulkan/blit_pass_vk.h"
8 #include "impeller/renderer/backend/vulkan/command_buffer_vk.h"
9 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
10
11 namespace impeller {
12
13 TEST(BlitPassVKTest, MipmapGenerationTransitionsAllLevelsCorrectly) {
14 auto context = testing::MockVulkanContextBuilder().Build();
15 ASSERT_TRUE(context->IsValid());
16
17 auto cmd_buffer = context->CreateCommandBuffer();
18 ASSERT_TRUE(cmd_buffer);
19 auto blit_pass = cmd_buffer->CreateBlitPass();
20 ASSERT_TRUE(blit_pass);
21
22 auto vk_blit_pass = reinterpret_cast<BlitPassVK*>(blit_pass.get());
23 auto vk_cmd_buffer = reinterpret_cast<CommandBufferVK*>(cmd_buffer.get());
24
25 TextureDescriptor desc;
26 desc.size = ISize(100, 65);
27 desc.format = PixelFormat::kR8G8B8A8UNormInt;
28 desc.mip_count = 6;
29 auto texture = context->GetResourceAllocator()->CreateTexture(desc);
30 ASSERT_TRUE(texture);
31
32 ASSERT_TRUE(vk_blit_pass->OnGenerateMipmapCommand(texture, "TestMipmap"));
33
34 auto& barriers =
35 testing::GetImageMemoryBarriers(vk_cmd_buffer->GetCommandBuffer());
36
37 ASSERT_EQ(barriers.size(), 8u);
38
39 EXPECT_EQ(barriers[0].oldLayout, VK_IMAGE_LAYOUT_UNDEFINED);
40 EXPECT_EQ(barriers[0].newLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
41 EXPECT_EQ(barriers[0].subresourceRange.baseMipLevel, 0u);
42 EXPECT_EQ(barriers[0].subresourceRange.levelCount, 6u);
43
44 for (uint32_t i = 1; i < 7; ++i) {
45 EXPECT_EQ(barriers[i].oldLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) << i;
46 EXPECT_EQ(barriers[i].newLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) << i;
47 EXPECT_EQ(barriers[i].subresourceRange.baseMipLevel, i - 1) << i;
48 EXPECT_EQ(barriers[i].subresourceRange.levelCount, 1u) << i;
49 }
50
51 EXPECT_EQ(barriers[7].oldLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
52 EXPECT_EQ(barriers[7].newLayout, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
53 EXPECT_EQ(barriers[7].subresourceRange.baseMipLevel, 0u);
54 EXPECT_EQ(barriers[7].subresourceRange.levelCount, 6u);
55 }
56
57 } // namespace impeller
blit_pass_vk.h
impeller::BlitPassVK
Definition: blit_pass_vk.h:19
impeller::CommandBufferVK
Definition: command_buffer_vk.h:27
command_buffer_vk.h
impeller
Definition: allocation.cc:12
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::TEST
TEST(RationalTest, Make)
Definition: rational_unittests.cc:11
impeller::ISize
ISize64 ISize
Definition: size.h:162
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::mip_count
size_t mip_count
Definition: texture_descriptor.h:43
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:41