Flutter Impeller
render_pass_builder_vk_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" // IWYU pragma: keep
6 #include "gtest/gtest.h"
9 #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
10 #include "vulkan/vulkan_enums.hpp"
11 
12 namespace impeller {
13 namespace testing {
14 
15 TEST(RenderPassBuilder, CreatesRenderPassWithNoDepthStencil) {
17  auto const context = MockVulkanContextBuilder().Build();
18 
19  // Create a single color attachment with a transient depth stencil.
23 
24  auto render_pass = builder.Build(context->GetDevice());
25 
26  EXPECT_TRUE(!!render_pass);
27  EXPECT_FALSE(builder.GetDepthStencil().has_value());
28 }
29 
30 TEST(RenderPassBuilder, CreatesRenderPassWithCombinedDepthStencil) {
32  auto const context = MockVulkanContextBuilder().Build();
33 
34  // Create a single color attachment with a transient depth stencil.
41 
42  auto render_pass = builder.Build(context->GetDevice());
43 
44  EXPECT_TRUE(!!render_pass);
45 
46  auto maybe_color = builder.GetColorAttachments().find(0u);
47  ASSERT_NE(maybe_color, builder.GetColorAttachments().end());
48  auto color = maybe_color->second;
49 
50  EXPECT_EQ(color.initialLayout, vk::ImageLayout::eGeneral);
51  EXPECT_EQ(color.finalLayout, vk::ImageLayout::eGeneral);
52  EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eClear);
53  EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eStore);
54 
55  auto maybe_depth_stencil = builder.GetDepthStencil();
56  ASSERT_TRUE(maybe_depth_stencil.has_value());
57  if (!maybe_depth_stencil.has_value()) {
58  return;
59  }
60  auto depth_stencil = maybe_depth_stencil.value();
61 
62  EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
63  EXPECT_EQ(depth_stencil.finalLayout,
64  vk::ImageLayout::eDepthStencilAttachmentOptimal);
65  EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
66  EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
67  EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
68  EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
69 }
70 
71 TEST(RenderPassBuilder, CreatesRenderPassWithOnlyStencil) {
73  auto const context = MockVulkanContextBuilder().Build();
74 
75  // Create a single color attachment with a transient depth stencil.
81 
82  auto render_pass = builder.Build(context->GetDevice());
83 
84  EXPECT_TRUE(!!render_pass);
85 
86  auto maybe_depth_stencil = builder.GetDepthStencil();
87  ASSERT_TRUE(maybe_depth_stencil.has_value());
88  if (!maybe_depth_stencil.has_value()) {
89  return;
90  }
91  auto depth_stencil = maybe_depth_stencil.value();
92 
93  EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
94  EXPECT_EQ(depth_stencil.finalLayout,
95  vk::ImageLayout::eDepthStencilAttachmentOptimal);
96  EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
97  EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
98  EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
99  EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
100 }
101 
102 TEST(RenderPassBuilder, CreatesMSAAResolveWithCorrectStore) {
104  auto const context = MockVulkanContextBuilder().Build();
105 
106  // Create an MSAA color attachment.
110 
111  auto render_pass = builder.Build(context->GetDevice());
112 
113  EXPECT_TRUE(!!render_pass);
114 
115  auto maybe_color = builder.GetColorAttachments().find(0u);
116  ASSERT_NE(maybe_color, builder.GetColorAttachments().end());
117  auto color = maybe_color->second;
118 
119  // MSAA Texture.
120  EXPECT_EQ(color.initialLayout, vk::ImageLayout::eGeneral);
121  EXPECT_EQ(color.finalLayout, vk::ImageLayout::eGeneral);
122  EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eClear);
123  EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eDontCare);
124 
125  auto maybe_resolve = builder.GetResolves().find(0u);
126  ASSERT_NE(maybe_resolve, builder.GetResolves().end());
127  auto resolve = maybe_resolve->second;
128 
129  // MSAA Resolve Texture.
130  EXPECT_EQ(resolve.initialLayout, vk::ImageLayout::eGeneral);
131  EXPECT_EQ(resolve.finalLayout, vk::ImageLayout::eGeneral);
132  EXPECT_EQ(resolve.loadOp, vk::AttachmentLoadOp::eClear);
133  EXPECT_EQ(resolve.storeOp, vk::AttachmentStoreOp::eStore);
134 }
135 
136 } // namespace testing
137 } // namespace impeller
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::PixelFormat::kS8UInt
@ kS8UInt
impeller::RenderPassBuilderVK::SetStencilAttachment
RenderPassBuilderVK & SetStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:74
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
formats.h
impeller::StoreAction::kDontCare
@ kDontCare
impeller::RenderPassBuilderVK
Definition: render_pass_builder_vk.h:17
impeller::RenderPassBuilderVK::GetColorAttachments
const std::map< size_t, vk::AttachmentDescription > & GetColorAttachments() const
Definition: render_pass_builder_vk.cc:189
impeller::RenderPassBuilderVK::SetDepthStencilAttachment
RenderPassBuilderVK & SetDepthStencilAttachment(PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:56
impeller::RenderPassBuilderVK::GetDepthStencil
const std::optional< vk::AttachmentDescription > & GetDepthStencil() const
Definition: render_pass_builder_vk.cc:199
impeller::LoadAction::kClear
@ kClear
impeller::RenderPassBuilderVK::GetResolves
const std::map< size_t, vk::AttachmentDescription > & GetResolves() const
Definition: render_pass_builder_vk.cc:194
impeller::RenderPassBuilderVK::SetColorAttachment
RenderPassBuilderVK & SetColorAttachment(size_t index, PixelFormat format, SampleCount sample_count, LoadAction load_action, StoreAction store_action)
Definition: render_pass_builder_vk.cc:29
impeller::testing::TEST
TEST(CanvasRecorder, Save)
Definition: canvas_recorder_unittests.cc:65
render_pass_builder_vk.h
impeller::PixelFormat::kD24UnormS8Uint
@ kD24UnormS8Uint
impeller::StoreAction::kStore
@ kStore
impeller::LoadAction::kDontCare
@ kDontCare
impeller::SampleCount::kCount1
@ kCount1
impeller::SampleCount::kCount4
@ kCount4
impeller::RenderPassBuilderVK::Build
vk::UniqueRenderPass Build(const vk::Device &device) const
Definition: render_pass_builder_vk.cc:92
impeller
Definition: aiks_blur_unittests.cc:20