Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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"
12
13namespace impeller {
14namespace testing {
15
17
18TEST_P(RendererTest, CachesRenderPassAndFramebuffer) {
19 if (GetBackend() != PlaygroundBackend::kVulkan) {
20 GTEST_SKIP() << "Test only applies to Vulkan";
21 }
22
23 auto allocator = std::make_shared<RenderTargetAllocator>(
24 GetContext()->GetResourceAllocator());
25
26 RenderTarget render_target =
27 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
28 std::shared_ptr<Texture> resolve_texture =
29 render_target.GetColorAttachment(0).resolve_texture;
30 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
31
33 nullptr);
35 nullptr);
36
37 auto buffer = GetContext()->CreateCommandBuffer();
38 auto render_pass = buffer->CreateRenderPass(render_target);
39
41 nullptr);
43 nullptr);
44
45 render_pass->EncodeCommands();
46 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
47
48 // Can be reused without error.
49 auto buffer_2 = GetContext()->CreateCommandBuffer();
50 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
51
52 EXPECT_TRUE(render_pass_2->EncodeCommands());
53 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
54}
55
56TEST_P(RendererTest, CachesRenderPassAndFramebufferNonMSAA) {
57 if (GetBackend() != PlaygroundBackend::kVulkan) {
58 GTEST_SKIP() << "Test only applies to Vulkan";
59 }
60
61 auto allocator = std::make_shared<RenderTargetAllocator>(
62 GetContext()->GetResourceAllocator());
63
64 RenderTarget render_target =
65 allocator->CreateOffscreen(*GetContext(), {100, 100}, 1);
66 std::shared_ptr<Texture> color_texture =
67 render_target.GetColorAttachment(0).texture;
68 TextureVK& texture_vk = TextureVK::Cast(*color_texture);
69
71 nullptr);
73 nullptr);
74
75 auto buffer = GetContext()->CreateCommandBuffer();
76 auto render_pass = buffer->CreateRenderPass(render_target);
77
79 nullptr);
81 nullptr);
82
83 render_pass->EncodeCommands();
84 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
85
86 // Can be reused without error.
87 auto buffer_2 = GetContext()->CreateCommandBuffer();
88 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
89
90 EXPECT_TRUE(render_pass_2->EncodeCommands());
91 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
92}
93
94TEST_P(RendererTest, CachesRenderPassAndFramebufferMixed) {
95 if (GetBackend() != PlaygroundBackend::kVulkan) {
96 GTEST_SKIP() << "Test only applies to Vulkan";
97 }
98
99 auto allocator = std::make_shared<RenderTargetAllocator>(
100 GetContext()->GetResourceAllocator());
101
102 RenderTarget render_target =
103 allocator->CreateOffscreenMSAA(*GetContext(), {100, 100}, 1);
104 std::shared_ptr<Texture> resolve_texture =
105 render_target.GetColorAttachment(0).resolve_texture;
106 TextureVK& texture_vk = TextureVK::Cast(*resolve_texture);
107
109 nullptr);
111 nullptr);
112
113 auto buffer = GetContext()->CreateCommandBuffer();
114 auto render_pass = buffer->CreateRenderPass(render_target);
115
117 nullptr);
119 nullptr);
120
121 render_pass->EncodeCommands();
122 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer}).ok());
123
124 // Can be reused without error.
125 auto buffer_2 = GetContext()->CreateCommandBuffer();
126 auto render_pass_2 = buffer_2->CreateRenderPass(render_target);
127
128 EXPECT_TRUE(render_pass_2->EncodeCommands());
129 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_2}).ok());
130
131 // Now switch to single sample count and demonstrate no validation errors.
132 {
133 RenderTarget other_target;
134 ColorAttachment color0;
137 color0.texture = resolve_texture;
138 other_target.SetColorAttachment(color0, 0);
139 other_target.SetDepthAttachment(std::nullopt);
140 other_target.SetStencilAttachment(std::nullopt);
141
143 nullptr);
145 nullptr);
146
147 auto buffer_3 = GetContext()->CreateCommandBuffer();
148 auto render_pass_3 = buffer_3->CreateRenderPass(other_target);
149
151 nullptr);
153 nullptr);
154
155 EXPECT_TRUE(render_pass_3->EncodeCommands());
156 EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({buffer_3}).ok());
157 }
158}
159
160} // namespace testing
161} // 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)
FramebufferAndRenderPass GetCachedFrameData(SampleCount sample_count, uint32_t mip_level=0u, uint32_t slice=0u) const
std::shared_ptr< ImpellerAllocator > allocator
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< RenderPass > render_pass
std::shared_ptr< Texture > resolve_texture
Definition formats.h:910
LoadAction load_action
Definition formats.h:911
std::shared_ptr< Texture > texture
Definition formats.h:909
StoreAction store_action
Definition formats.h:912
SharedHandleVK< vk::Framebuffer > framebuffer
SharedHandleVK< vk::RenderPass > render_pass