Flutter Impeller
render_pass_cache_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 "gtest/gtest.h"
10 
11 namespace impeller {
12 namespace testing {
13 
15 
16 TEST_P(RendererTest, CachesRenderPassAndFramebuffer) {
17  if (GetBackend() != PlaygroundBackend::kVulkan) {
18  GTEST_SKIP() << "Test only applies to Vulkan";
19  }
20 
21  auto allocator = std::make_shared<RenderTargetAllocator>(
22  GetContext()->GetResourceAllocator());
23 
24  RenderTarget render_target =
25  allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
26  std::shared_ptr<Texture> resolve_texture =
27  render_target.GetColorAttachment(0).resolve_texture;
28  TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
29 
30  EXPECT_EQ(texture_vk.GetCachedFramebuffer(), nullptr);
31  EXPECT_EQ(texture_vk.GetCachedRenderPass(), nullptr);
32 
33  auto buffer = GetContext()->CreateCommandBuffer();
34  auto render_pass = buffer->CreateRenderPass(render_target);
35 
36  EXPECT_NE(texture_vk.GetCachedFramebuffer(), nullptr);
37  EXPECT_NE(texture_vk.GetCachedRenderPass(), nullptr);
38 
39  render_pass->EncodeCommands();
40  EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
41 
42  // Can be reused without error.
43  auto buffer_2 = GetContext()->CreateCommandBuffer();
44  auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
45 
46  EXPECT_TRUE(render_pass_2->EncodeCommands());
47  EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
48 }
49 
50 TEST_P(RendererTest, CachesRenderPassAndFramebufferNonMSAA) {
51  if (GetBackend() != PlaygroundBackend::kVulkan) {
52  GTEST_SKIP() << "Test only applies to Vulkan";
53  }
54 
55  auto allocator = std::make_shared<RenderTargetAllocator>(
56  GetContext()->GetResourceAllocator());
57 
58  RenderTarget render_target =
59  allocator->CreateOffscreen(*GetContext(), {100, 100}, 1);
60  std::shared_ptr<Texture> color_texture =
61  render_target.GetColorAttachment(0).texture;
62  TextureVK& texture_vk = TextureVK::Cast(*color_texture);
63 
64  EXPECT_EQ(texture_vk.GetCachedFramebuffer(), nullptr);
65  EXPECT_EQ(texture_vk.GetCachedRenderPass(), nullptr);
66 
67  auto buffer = GetContext()->CreateCommandBuffer();
68  auto render_pass = buffer->CreateRenderPass(render_target);
69 
70  EXPECT_NE(texture_vk.GetCachedFramebuffer(), nullptr);
71  EXPECT_NE(texture_vk.GetCachedRenderPass(), nullptr);
72 
73  render_pass->EncodeCommands();
74  EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
75 
76  // Can be reused without error.
77  auto buffer_2 = GetContext()->CreateCommandBuffer();
78  auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
79 
80  EXPECT_TRUE(render_pass_2->EncodeCommands());
81  EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
82 }
83 
84 } // namespace testing
85 } // namespace impeller
static TextureVK & Cast(Texture &base)
Definition: backend_cast.h:13
ColorAttachment GetColorAttachment(size_t index) const
Get the color attachment at [index].
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
Definition: texture_vk.cc:213
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
Definition: texture_vk.cc:209
TEST_P(AiksTest, DrawAtlasNoColor)
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:658
std::shared_ptr< Texture > texture
Definition: formats.h:657