|
| 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" |
| 7 | +#include "impeller/core/formats.h" |
| 8 | +#include "impeller/renderer/backend/vulkan/render_pass_builder_vk.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) { |
| 16 | + RenderPassBuilderVK builder = RenderPassBuilderVK(); |
| 17 | + auto const context = MockVulkanContextBuilder().Build(); |
| 18 | + |
| 19 | + // Create a single color attachment with a transient depth stencil. |
| 20 | + builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt, |
| 21 | + SampleCount::kCount1, LoadAction::kClear, |
| 22 | + StoreAction::kStore); |
| 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) { |
| 31 | + RenderPassBuilderVK builder = RenderPassBuilderVK(); |
| 32 | + auto const context = MockVulkanContextBuilder().Build(); |
| 33 | + |
| 34 | + // Create a single color attachment with a transient depth stencil. |
| 35 | + builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt, |
| 36 | + SampleCount::kCount1, LoadAction::kClear, |
| 37 | + StoreAction::kStore); |
| 38 | + builder.SetDepthStencilAttachment(PixelFormat::kD24UnormS8Uint, |
| 39 | + SampleCount::kCount1, LoadAction::kDontCare, |
| 40 | + StoreAction::kDontCare); |
| 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) { |
| 72 | + RenderPassBuilderVK builder = RenderPassBuilderVK(); |
| 73 | + auto const context = MockVulkanContextBuilder().Build(); |
| 74 | + |
| 75 | + // Create a single color attachment with a transient depth stencil. |
| 76 | + builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt, |
| 77 | + SampleCount::kCount1, LoadAction::kClear, |
| 78 | + StoreAction::kStore); |
| 79 | + builder.SetStencilAttachment(PixelFormat::kS8UInt, SampleCount::kCount1, |
| 80 | + LoadAction::kDontCare, StoreAction::kDontCare); |
| 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 | +} // namespace testing |
| 103 | +} // namespace impeller |
0 commit comments