Flutter Impeller
entity_pass_target_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 <memory>
6 
7 #include "flutter/testing/testing.h"
8 #include "gtest/gtest.h"
12 
13 namespace impeller {
14 namespace testing {
15 
18 
19 TEST_P(EntityPassTargetTest, SwapWithMSAATexture) {
20  if (GetContentContext()
21  ->GetDeviceCapabilities()
22  .SupportsImplicitResolvingMSAA()) {
23  GTEST_SKIP() << "Implicit MSAA is used on this device.";
24  }
25  auto content_context = GetContentContext();
26  auto buffer = content_context->GetContext()->CreateCommandBuffer();
27  auto render_target = RenderTarget::CreateOffscreenMSAA(
28  *content_context->GetContext(),
29  *GetContentContext()->GetRenderTargetCache(), {100, 100});
30 
31  auto entity_pass_target = EntityPassTarget(render_target, false, false);
32 
33  auto color0 = entity_pass_target.GetRenderTarget()
34  .GetColorAttachments()
35  .find(0u)
36  ->second;
37  auto msaa_tex = color0.texture;
38  auto resolve_tex = color0.resolve_texture;
39 
40  entity_pass_target.Flip(
41  *content_context->GetContext()->GetResourceAllocator());
42 
43  color0 = entity_pass_target.GetRenderTarget()
44  .GetColorAttachments()
45  .find(0u)
46  ->second;
47 
48  ASSERT_EQ(msaa_tex, color0.texture);
49  ASSERT_NE(resolve_tex, color0.resolve_texture);
50 }
51 
52 TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {
53  auto content_context = GetContentContext();
54  auto buffer = content_context->GetContext()->CreateCommandBuffer();
55  auto context = content_context->GetContext();
56  auto& allocator = *context->GetResourceAllocator();
57 
58  // Emulate implicit MSAA resolve by making color resolve and msaa texture the
59  // same.
60  RenderTarget render_target;
61  {
62  PixelFormat pixel_format =
63  context->GetCapabilities()->GetDefaultColorFormat();
64 
65  // Create MSAA color texture.
66 
67  TextureDescriptor color0_tex_desc;
68  color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
69  color0_tex_desc.type = TextureType::kTexture2DMultisample;
70  color0_tex_desc.sample_count = SampleCount::kCount4;
71  color0_tex_desc.format = pixel_format;
72  color0_tex_desc.size = ISize{100, 100};
73  color0_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);
74 
75  auto color0_msaa_tex = allocator.CreateTexture(color0_tex_desc);
76 
77  // Color attachment.
78 
79  ColorAttachment color0;
82  color0.texture = color0_msaa_tex;
83  color0.resolve_texture = color0_msaa_tex;
84 
85  render_target.SetColorAttachment(color0, 0u);
86  render_target.SetStencilAttachment(std::nullopt);
87  }
88 
89  auto entity_pass_target = EntityPassTarget(render_target, false, true);
90 
91  auto color0 = entity_pass_target.GetRenderTarget()
92  .GetColorAttachments()
93  .find(0u)
94  ->second;
95  auto msaa_tex = color0.texture;
96  auto resolve_tex = color0.resolve_texture;
97 
98  ASSERT_EQ(msaa_tex, resolve_tex);
99 
100  entity_pass_target.Flip(
101  *content_context->GetContext()->GetResourceAllocator());
102 
103  color0 = entity_pass_target.GetRenderTarget()
104  .GetColorAttachments()
105  .find(0u)
106  ->second;
107 
108  ASSERT_NE(msaa_tex, color0.texture);
109  ASSERT_NE(resolve_tex, color0.resolve_texture);
110  ASSERT_EQ(color0.texture, color0.resolve_texture);
111 }
112 
113 } // namespace testing
114 } // namespace impeller
impeller::StoreAction::kStoreAndMultisampleResolve
@ kStoreAndMultisampleResolve
impeller::Attachment::store_action
StoreAction store_action
Definition: formats.h:637
impeller::ColorAttachment
Definition: formats.h:642
impeller::TextureDescriptor::format
PixelFormat format
Definition: texture_descriptor.h:40
impeller::RenderTarget::SetColorAttachment
RenderTarget & SetColorAttachment(const ColorAttachment &attachment, size_t index)
Definition: render_target.cc:180
formats.h
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::EntityPassTarget
Definition: entity_pass_target.h:15
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:45
impeller::TextureDescriptor::usage
TextureUsageMask usage
Definition: texture_descriptor.h:43
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:94
impeller::TextureDescriptor::type
TextureType type
Definition: texture_descriptor.h:39
impeller::testing::INSTANTIATE_PLAYGROUND_SUITE
INSTANTIATE_PLAYGROUND_SUITE(AiksTest)
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TSize< int64_t >
impeller::Attachment::texture
std::shared_ptr< Texture > texture
Definition: formats.h:634
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::RenderTarget
Definition: render_target.h:49
entity_pass_target.h
impeller::TextureDescriptor::size
ISize size
Definition: texture_descriptor.h:41
impeller::EntityPlayground
Definition: entity_playground.h:18
impeller::Attachment::resolve_texture
std::shared_ptr< Texture > resolve_texture
Definition: formats.h:635
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:199
impeller::LoadAction::kDontCare
@ kDontCare
impeller::Attachment::load_action
LoadAction load_action
Definition: formats.h:636
impeller::SampleCount::kCount4
@ kCount4
impeller::TextureDescriptor::storage_mode
StorageMode storage_mode
Definition: texture_descriptor.h:38
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderLinearGradientClamp)
Definition: aiks_gradient_unittests.cc:48
impeller
Definition: aiks_context.cc:10
impeller::RenderTarget::CreateOffscreenMSAA
static RenderTarget CreateOffscreenMSAA(const Context &context, RenderTargetAllocator &allocator, ISize size, const std::string &label="Offscreen MSAA", AttachmentConfigMSAA color_attachment_config=kDefaultColorAttachmentConfigMSAA, std::optional< AttachmentConfig > stencil_attachment_config=kDefaultStencilAttachmentConfig)
Definition: render_target.cc:265
entity_playground.h