Flutter Engine
 
Loading...
Searching...
No Matches
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
6#include "gtest/gtest.h"
11
12namespace impeller {
13namespace testing {
14
16
17TEST_P(RendererTest, CachesRenderPassAndFramebuffer) {
18 if (GetBackend() != PlaygroundBackend::kVulkan) {
19 GTEST_SKIP() << "Test only applies to Vulkan";
20 }
21
22 auto allocator = std::make_shared<RenderTargetAllocator>(
23 GetContext()->GetResourceAllocator());
24
25 RenderTarget render_target =
26 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
27 std::shared_ptr<Texture> resolve_texture =
28 render_target.GetColorAttachment(0).resolve_texture;
29 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
30
32 nullptr);
34 nullptr);
35
36 auto buffer = GetContext()->CreateCommandBuffer();
37 auto render_pass = buffer->CreateRenderPass(render_target);
38
40 nullptr);
42 nullptr);
43
44 render_pass->EncodeCommands();
45 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
46
47 // Can be reused without error.
48 auto buffer_2 = GetContext()->CreateCommandBuffer();
49 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
50
51 EXPECT_TRUE(render_pass_2->EncodeCommands());
52 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
53}
54
55TEST_P(RendererTest, CachesRenderPassAndFramebufferNonMSAA) {
56 if (GetBackend() != PlaygroundBackend::kVulkan) {
57 GTEST_SKIP() << "Test only applies to Vulkan";
58 }
59
60 auto allocator = std::make_shared<RenderTargetAllocator>(
61 GetContext()->GetResourceAllocator());
62
63 RenderTarget render_target =
64 allocator->CreateOffscreen(*GetContext(), {100, 100}, 1);
65 std::shared_ptr<Texture> color_texture =
66 render_target.GetColorAttachment(0).texture;
67 TextureVK& texture_vk = TextureVK::Cast(*color_texture);
68
70 nullptr);
72 nullptr);
73
74 auto buffer = GetContext()->CreateCommandBuffer();
75 auto render_pass = buffer->CreateRenderPass(render_target);
76
78 nullptr);
80 nullptr);
81
82 render_pass->EncodeCommands();
83 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
84
85 // Can be reused without error.
86 auto buffer_2 = GetContext()->CreateCommandBuffer();
87 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
88
89 EXPECT_TRUE(render_pass_2->EncodeCommands());
90 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
91}
92
93TEST_P(RendererTest, CachesRenderPassAndFramebufferMixed) {
94 if (GetBackend() != PlaygroundBackend::kVulkan) {
95 GTEST_SKIP() << "Test only applies to Vulkan";
96 }
97
98 auto allocator = std::make_shared<RenderTargetAllocator>(
99 GetContext()->GetResourceAllocator());
100
101 RenderTarget render_target =
102 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
103 std::shared_ptr<Texture> resolve_texture =
104 render_target.GetColorAttachment(0).resolve_texture;
105 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
106
108 nullptr);
110 nullptr);
111
112 auto buffer = GetContext()->CreateCommandBuffer();
113 auto render_pass = buffer->CreateRenderPass(render_target);
114
116 nullptr);
118 nullptr);
119
120 render_pass->EncodeCommands();
121 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
122
123 // Can be reused without error.
124 auto buffer_2 = GetContext()->CreateCommandBuffer();
125 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
126
127 EXPECT_TRUE(render_pass_2->EncodeCommands());
128 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
129
130 // Now switch to single sample count and demonstrate no validation errors.
131 {
132 RenderTarget other_target;
133 ColorAttachment color0;
136 color0.texture = resolve_texture;
137 other_target.SetColorAttachment(color0, 0);
138 other_target.SetDepthAttachment(std::nullopt);
139 other_target.SetStencilAttachment(std::nullopt);
140
142 nullptr);
144 nullptr);
145
146 auto buffer_3 = GetContext()->CreateCommandBuffer();
147 auto render_pass_3 = buffer_3->CreateRenderPass(other_target);
148
150 nullptr);
152 nullptr);
153
154 EXPECT_TRUE(render_pass_3->EncodeCommands());
155 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_3}).ok());
156 }
157}
158
159} // namespace testing
160} // namespace impeller
static TextureVK & Cast(Texture &base)
ColorAttachment GetColorAttachment(size_t index) const
Get the color attachment at [index].
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
const FramebufferAndRenderPass & GetCachedFrameData(SampleCount sample_count) const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98
TEST_P(AiksTest, DrawAtlasNoColor)
std::shared_ptr< Texture > resolve_texture
Definition formats.h:658
LoadAction load_action
Definition formats.h:659
std::shared_ptr< Texture > texture
Definition formats.h:657
StoreAction store_action
Definition formats.h:660
SharedHandleVK< vk::Framebuffer > framebuffer
SharedHandleVK< vk::RenderPass > render_pass