Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
../../../flutter/impeller/renderer/backend/vulkan/descriptor_pool_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/driver_info_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/render_pass_builder_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/render_pass_cache_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/resource_manager_vk_unittests.cc
../../../flutter/impeller/renderer/backend/vulkan/swapchain/README.md
Expand Down
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impeller_component("vulkan_unittests") {
"descriptor_pool_vk_unittests.cc",
"driver_info_vk_unittests.cc",
"fence_waiter_vk_unittests.cc",
"render_pass_builder_vk_unittests.cc",
"render_pass_cache_unittests.cc",
"resource_manager_vk_unittests.cc",
"test/gpu_tracer_unittests.cc",
Expand Down
23 changes: 19 additions & 4 deletions impeller/renderer/backend/vulkan/render_pass_builder_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ RenderPassBuilderVK& RenderPassBuilderVK::SetDepthStencilAttachment(
desc.storeOp = ToVKAttachmentStoreOp(store_action);
desc.stencilLoadOp = desc.loadOp; // Not separable in Impeller.
desc.stencilStoreOp = desc.storeOp; // Not separable in Impeller.
desc.initialLayout = vk::ImageLayout::eGeneral;
desc.finalLayout = vk::ImageLayout::eGeneral;
desc.initialLayout = vk::ImageLayout::eUndefined;
desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
depth_stencil_ = desc;
return *this;
}
Expand All @@ -80,8 +80,8 @@ RenderPassBuilderVK& RenderPassBuilderVK::SetStencilAttachment(
desc.storeOp = vk::AttachmentStoreOp::eDontCare;
desc.stencilLoadOp = ToVKAttachmentLoadOp(load_action);
desc.stencilStoreOp = ToVKAttachmentStoreOp(store_action);
desc.initialLayout = vk::ImageLayout::eGeneral;
desc.finalLayout = vk::ImageLayout::eGeneral;
desc.initialLayout = vk::ImageLayout::eUndefined;
desc.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal;
depth_stencil_ = desc;
return *this;
}
Expand Down Expand Up @@ -184,4 +184,19 @@ void InsertBarrierForInputAttachmentRead(const vk::CommandBuffer& buffer,
);
}

const std::map<size_t, vk::AttachmentDescription>&
RenderPassBuilderVK::GetColorAttachments() const {
return colors_;
}

const std::map<size_t, vk::AttachmentDescription>&
RenderPassBuilderVK::GetResolves() const {
return resolves_;
}

const std::optional<vk::AttachmentDescription>&
RenderPassBuilderVK::GetDepthStencil() const {
return depth_stencil_;
}

} // namespace impeller
10 changes: 10 additions & 0 deletions impeller/renderer/backend/vulkan/render_pass_builder_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ class RenderPassBuilderVK {

vk::UniqueRenderPass Build(const vk::Device& device) const;

// Visible for testing.
const std::map<size_t, vk::AttachmentDescription>& GetColorAttachments()
const;

// Visible for testing.
const std::map<size_t, vk::AttachmentDescription>& GetResolves() const;

// Visible for testing.
const std::optional<vk::AttachmentDescription>& GetDepthStencil() const;

private:
std::map<size_t, vk::AttachmentDescription> colors_;
std::map<size_t, vk::AttachmentDescription> resolves_;
Expand Down
103 changes: 103 additions & 0 deletions impeller/renderer/backend/vulkan/render_pass_builder_vk_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/testing/testing.h" // IWYU pragma: keep
#include "gtest/gtest.h"
#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/render_pass_builder_vk.h"
#include "impeller/renderer/backend/vulkan/test/mock_vulkan.h"
#include "vulkan/vulkan_enums.hpp"

namespace impeller {
namespace testing {

TEST(RenderPassBuilder, CreatesRenderPassWithNoDepthStencil) {
RenderPassBuilderVK builder = RenderPassBuilderVK();
auto const context = MockVulkanContextBuilder().Build();

// Create a single color attachment with a transient depth stencil.
builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
SampleCount::kCount1, LoadAction::kClear,
StoreAction::kStore);

auto render_pass = builder.Build(context->GetDevice());

EXPECT_TRUE(!!render_pass);
EXPECT_FALSE(builder.GetDepthStencil().has_value());
}

TEST(RenderPassBuilder, CreatesRenderPassWithCombinedDepthStencil) {
RenderPassBuilderVK builder = RenderPassBuilderVK();
auto const context = MockVulkanContextBuilder().Build();

// Create a single color attachment with a transient depth stencil.
builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
SampleCount::kCount1, LoadAction::kClear,
StoreAction::kStore);
builder.SetDepthStencilAttachment(PixelFormat::kD24UnormS8Uint,
SampleCount::kCount1, LoadAction::kDontCare,
StoreAction::kDontCare);

auto render_pass = builder.Build(context->GetDevice());

EXPECT_TRUE(!!render_pass);

auto maybe_color = builder.GetColorAttachments().find(0u);
ASSERT_NE(maybe_color, builder.GetColorAttachments().end());
auto color = maybe_color->second;

EXPECT_EQ(color.initialLayout, vk::ImageLayout::eGeneral);
EXPECT_EQ(color.finalLayout, vk::ImageLayout::eGeneral);
EXPECT_EQ(color.loadOp, vk::AttachmentLoadOp::eClear);
EXPECT_EQ(color.storeOp, vk::AttachmentStoreOp::eStore);

auto maybe_depth_stencil = builder.GetDepthStencil();
ASSERT_TRUE(maybe_depth_stencil.has_value());
if (!maybe_depth_stencil.has_value()) {
return;
}
auto depth_stencil = maybe_depth_stencil.value();

EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
EXPECT_EQ(depth_stencil.finalLayout,
vk::ImageLayout::eDepthStencilAttachmentOptimal);
EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
}

TEST(RenderPassBuilder, CreatesRenderPassWithOnlyStencil) {
RenderPassBuilderVK builder = RenderPassBuilderVK();
auto const context = MockVulkanContextBuilder().Build();

// Create a single color attachment with a transient depth stencil.
builder.SetColorAttachment(0, PixelFormat::kR8G8B8A8UNormInt,
SampleCount::kCount1, LoadAction::kClear,
StoreAction::kStore);
builder.SetStencilAttachment(PixelFormat::kS8UInt, SampleCount::kCount1,
LoadAction::kDontCare, StoreAction::kDontCare);

auto render_pass = builder.Build(context->GetDevice());

EXPECT_TRUE(!!render_pass);

auto maybe_depth_stencil = builder.GetDepthStencil();
ASSERT_TRUE(maybe_depth_stencil.has_value());
if (!maybe_depth_stencil.has_value()) {
return;
}
auto depth_stencil = maybe_depth_stencil.value();

EXPECT_EQ(depth_stencil.initialLayout, vk::ImageLayout::eUndefined);
EXPECT_EQ(depth_stencil.finalLayout,
vk::ImageLayout::eDepthStencilAttachmentOptimal);
EXPECT_EQ(depth_stencil.loadOp, vk::AttachmentLoadOp::eDontCare);
EXPECT_EQ(depth_stencil.storeOp, vk::AttachmentStoreOp::eDontCare);
EXPECT_EQ(depth_stencil.stencilLoadOp, vk::AttachmentLoadOp::eDontCare);
EXPECT_EQ(depth_stencil.stencilStoreOp, vk::AttachmentStoreOp::eDontCare);
}

} // namespace testing
} // namespace impeller
2 changes: 0 additions & 2 deletions impeller/renderer/backend/vulkan/render_pass_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
depth->load_action, //
depth->store_action //
);
TextureVK::Cast(*depth->texture).SetLayout(barrier);
} else if (auto stencil = render_target_.GetStencilAttachment();
stencil.has_value()) {
builder.SetStencilAttachment(
Expand All @@ -122,7 +121,6 @@ SharedHandleVK<vk::RenderPass> RenderPassVK::CreateVKRenderPass(
stencil->load_action, //
stencil->store_action //
);
TextureVK::Cast(*stencil->texture).SetLayout(barrier);
}

if (recycled_renderpass != nullptr) {
Expand Down