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 =
28  GetContentContext()->GetRenderTargetCache()->CreateOffscreenMSAA(
29  *content_context->GetContext(), {100, 100},
30  /*mip_count=*/1);
31 
32  auto entity_pass_target = EntityPassTarget(render_target, false, false);
33 
34  auto color0 = entity_pass_target.GetRenderTarget()
35  .GetColorAttachments()
36  .find(0u)
37  ->second;
38  auto msaa_tex = color0.texture;
39  auto resolve_tex = color0.resolve_texture;
40 
41  entity_pass_target.Flip(
42  *content_context->GetContext()->GetResourceAllocator());
43 
44  color0 = entity_pass_target.GetRenderTarget()
45  .GetColorAttachments()
46  .find(0u)
47  ->second;
48 
49  ASSERT_EQ(msaa_tex, color0.texture);
50  ASSERT_NE(resolve_tex, color0.resolve_texture);
51 }
52 
53 TEST_P(EntityPassTargetTest, SwapWithMSAAImplicitResolve) {
54  auto content_context = GetContentContext();
55  auto buffer = content_context->GetContext()->CreateCommandBuffer();
56  auto context = content_context->GetContext();
57  auto& allocator = *context->GetResourceAllocator();
58 
59  // Emulate implicit MSAA resolve by making color resolve and msaa texture the
60  // same.
61  RenderTarget render_target;
62  {
63  PixelFormat pixel_format =
64  context->GetCapabilities()->GetDefaultColorFormat();
65 
66  // Create MSAA color texture.
67 
68  TextureDescriptor color0_tex_desc;
69  color0_tex_desc.storage_mode = StorageMode::kDevicePrivate;
70  color0_tex_desc.type = TextureType::kTexture2DMultisample;
71  color0_tex_desc.sample_count = SampleCount::kCount4;
72  color0_tex_desc.format = pixel_format;
73  color0_tex_desc.size = ISize{100, 100};
74  color0_tex_desc.usage = TextureUsage::kRenderTarget;
75 
76  auto color0_msaa_tex = allocator.CreateTexture(color0_tex_desc);
77 
78  // Color attachment.
79 
80  ColorAttachment color0;
83  color0.texture = color0_msaa_tex;
84  color0.resolve_texture = color0_msaa_tex;
85 
86  render_target.SetColorAttachment(color0, 0u);
87  render_target.SetStencilAttachment(std::nullopt);
88  }
89 
90  auto entity_pass_target = EntityPassTarget(render_target, false, true);
91 
92  auto color0 = entity_pass_target.GetRenderTarget()
93  .GetColorAttachments()
94  .find(0u)
95  ->second;
96  auto msaa_tex = color0.texture;
97  auto resolve_tex = color0.resolve_texture;
98 
99  ASSERT_EQ(msaa_tex, resolve_tex);
100 
101  entity_pass_target.Flip(
102  *content_context->GetContext()->GetResourceAllocator());
103 
104  color0 = entity_pass_target.GetRenderTarget()
105  .GetColorAttachments()
106  .find(0u)
107  ->second;
108 
109  ASSERT_NE(msaa_tex, color0.texture);
110  ASSERT_NE(resolve_tex, color0.resolve_texture);
111  ASSERT_EQ(color0.texture, color0.resolve_texture);
112 }
113 
114 } // namespace testing
115 } // namespace impeller
impeller::StoreAction::kStoreAndMultisampleResolve
@ kStoreAndMultisampleResolve
impeller::Attachment::store_action
StoreAction store_action
Definition: formats.h:642
impeller::ColorAttachment
Definition: formats.h:647
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:169
formats.h
impeller::EntityPassTarget
Definition: entity_pass_target.h:15
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::TextureDescriptor::sample_count
SampleCount sample_count
Definition: texture_descriptor.h:44
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:100
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:639
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::RenderTarget
Definition: render_target.h:38
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:640
impeller::RenderTarget::SetStencilAttachment
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
Definition: render_target.cc:188
impeller::testing::TEST_P
TEST_P(AiksTest, CanRenderMaskBlurHugeSigma)
Definition: aiks_blur_unittests.cc:23
impeller::LoadAction::kDontCare
@ kDontCare
impeller::Attachment::load_action
LoadAction load_action
Definition: formats.h:641
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
Definition: aiks_blur_unittests.cc:20
entity_playground.h