|
| 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/renderer/backend/vulkan/blit_command_vk.h" |
| 7 | +#include "impeller/renderer/backend/vulkan/command_encoder_vk.h" |
| 8 | +#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" |
| 9 | + |
| 10 | +namespace impeller { |
| 11 | +namespace testing { |
| 12 | + |
| 13 | +TEST(BlitCommandVkTest, BlitCopyTextureToTextureCommandVK) { |
| 14 | + auto context = CreateMockVulkanContext(); |
| 15 | + auto pool = CommandPoolVK::GetThreadLocal(context.get()); |
| 16 | + CommandEncoderVK encoder(context->GetDevice(), context->GetGraphicsQueue(), |
| 17 | + pool, context->GetFenceWaiter()); |
| 18 | + BlitCopyTextureToTextureCommandVK cmd; |
| 19 | + cmd.source = context->GetResourceAllocator()->CreateTexture({ |
| 20 | + .size = ISize(100, 100), |
| 21 | + }); |
| 22 | + cmd.destination = context->GetResourceAllocator()->CreateTexture({ |
| 23 | + .size = ISize(100, 100), |
| 24 | + }); |
| 25 | + bool result = cmd.Encode(encoder); |
| 26 | + EXPECT_TRUE(result); |
| 27 | + EXPECT_TRUE(encoder.IsTracking(cmd.source)); |
| 28 | + EXPECT_TRUE(encoder.IsTracking(cmd.destination)); |
| 29 | +} |
| 30 | + |
| 31 | +TEST(BlitCommandVkTest, BlitCopyTextureToBufferCommandVK) { |
| 32 | + auto context = CreateMockVulkanContext(); |
| 33 | + auto pool = CommandPoolVK::GetThreadLocal(context.get()); |
| 34 | + CommandEncoderVK encoder(context->GetDevice(), context->GetGraphicsQueue(), |
| 35 | + pool, context->GetFenceWaiter()); |
| 36 | + BlitCopyTextureToBufferCommandVK cmd; |
| 37 | + cmd.source = context->GetResourceAllocator()->CreateTexture({ |
| 38 | + .size = ISize(100, 100), |
| 39 | + }); |
| 40 | + cmd.destination = context->GetResourceAllocator()->CreateBuffer({ |
| 41 | + .size = 1, |
| 42 | + }); |
| 43 | + bool result = cmd.Encode(encoder); |
| 44 | + EXPECT_TRUE(result); |
| 45 | + EXPECT_TRUE(encoder.IsTracking(cmd.source)); |
| 46 | + EXPECT_TRUE(encoder.IsTracking(cmd.destination)); |
| 47 | +} |
| 48 | + |
| 49 | +TEST(BlitCommandVkTest, BlitGenerateMipmapCommandVK) { |
| 50 | + auto context = CreateMockVulkanContext(); |
| 51 | + auto pool = CommandPoolVK::GetThreadLocal(context.get()); |
| 52 | + CommandEncoderVK encoder(context->GetDevice(), context->GetGraphicsQueue(), |
| 53 | + pool, context->GetFenceWaiter()); |
| 54 | + BlitGenerateMipmapCommandVK cmd; |
| 55 | + cmd.texture = context->GetResourceAllocator()->CreateTexture({ |
| 56 | + .size = ISize(100, 100), |
| 57 | + .mip_count = 2, |
| 58 | + }); |
| 59 | + bool result = cmd.Encode(encoder); |
| 60 | + EXPECT_TRUE(result); |
| 61 | + EXPECT_TRUE(encoder.IsTracking(cmd.texture)); |
| 62 | +} |
| 63 | + |
| 64 | +} // namespace testing |
| 65 | +} // namespace impeller |
0 commit comments