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 1 commit
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
Prev Previous commit
Next Next commit
Add tests ooh boy.
  • Loading branch information
jonahwilliams committed Jan 31, 2024
commit 3cb42e670760e7947dad7647668f269629d43267
1 change: 1 addition & 0 deletions impeller/renderer/backend/vulkan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impeller_component("vulkan_unittests") {
"test/mock_vulkan.cc",
"test/mock_vulkan.h",
"test/mock_vulkan_unittests.cc",
"test/swapchain_unittests.cc",
]
deps = [
":vulkan",
Expand Down
51 changes: 30 additions & 21 deletions impeller/renderer/backend/vulkan/surface_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "impeller/renderer/backend/vulkan/surface_vk.h"

#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/surface.h"
Expand All @@ -13,30 +14,33 @@ namespace impeller {
std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
const std::shared_ptr<Context>& context,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
SwapCallback swap_callback) {
SwapCallback swap_callback,
bool enable_msaa) {
if (!context || !swapchain_image || !swap_callback) {
return nullptr;
}

TextureDescriptor msaa_tex_desc;
msaa_tex_desc.storage_mode = StorageMode::kDeviceTransient;
msaa_tex_desc.type = TextureType::kTexture2DMultisample;
msaa_tex_desc.sample_count = SampleCount::kCount4;
msaa_tex_desc.format = swapchain_image->GetPixelFormat();
msaa_tex_desc.size = swapchain_image->GetSize();
msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);

std::shared_ptr<Texture> msaa_tex;
if (!swapchain_image->HasMSAATexture()) {
msaa_tex = context->GetResourceAllocator()->CreateTexture(msaa_tex_desc);
msaa_tex->SetLabel("ImpellerOnscreenColorMSAA");
if (!msaa_tex) {
VALIDATION_LOG << "Could not allocate MSAA color texture.";
return nullptr;
if (enable_msaa) {
TextureDescriptor msaa_tex_desc;
msaa_tex_desc.storage_mode = StorageMode::kDeviceTransient;
msaa_tex_desc.type = TextureType::kTexture2DMultisample;
msaa_tex_desc.sample_count = SampleCount::kCount4;
msaa_tex_desc.format = swapchain_image->GetPixelFormat();
msaa_tex_desc.size = swapchain_image->GetSize();
msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);

if (!swapchain_image->HasMSAATexture()) {
msaa_tex = context->GetResourceAllocator()->CreateTexture(msaa_tex_desc);
msaa_tex->SetLabel("ImpellerOnscreenColorMSAA");
if (!msaa_tex) {
VALIDATION_LOG << "Could not allocate MSAA color texture.";
return nullptr;
}
swapchain_image->SetMSAATexture(msaa_tex);
} else {
msaa_tex = swapchain_image->GetMSAATexture();
}
swapchain_image->SetMSAATexture(msaa_tex);
} else {
msaa_tex = swapchain_image->GetMSAATexture();
}

TextureDescriptor resolve_tex_desc;
Expand All @@ -60,11 +64,16 @@ std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
resolve_tex->SetLabel("ImpellerOnscreenResolve");

ColorAttachment color0;
color0.texture = msaa_tex;
color0.clear_color = Color::DarkSlateGray();
color0.load_action = LoadAction::kClear;
color0.store_action = StoreAction::kMultisampleResolve;
color0.resolve_texture = resolve_tex;
if (enable_msaa) {
color0.texture = msaa_tex;
color0.store_action = StoreAction::kMultisampleResolve;
color0.resolve_texture = resolve_tex;
} else {
color0.texture = resolve_tex;
color0.store_action = StoreAction::kStore;
}

RenderTarget render_target_desc;
render_target_desc.SetColorAttachment(color0, 0u);
Expand Down
3 changes: 2 additions & 1 deletion impeller/renderer/backend/vulkan/surface_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class SurfaceVK final : public Surface {
static std::unique_ptr<SurfaceVK> WrapSwapchainImage(
const std::shared_ptr<Context>& context,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
SwapCallback swap_callback);
SwapCallback swap_callback,
bool enable_msaa = true);

// |Surface|
~SurfaceVK() override;
Expand Down
10 changes: 7 additions & 3 deletions impeller/renderer/backend/vulkan/swapchain_impl_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,16 @@ std::shared_ptr<SwapchainImplVK> SwapchainImplVK::Create(
const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa,
vk::SwapchainKHR old_swapchain) {
return std::shared_ptr<SwapchainImplVK>(
new SwapchainImplVK(context, std::move(surface), size, old_swapchain));
return std::shared_ptr<SwapchainImplVK>(new SwapchainImplVK(
context, std::move(surface), size, enable_msaa, old_swapchain));
}

SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa,
vk::SwapchainKHR old_swapchain) {
if (!context) {
VALIDATION_LOG << "Cannot create a swapchain without a context.";
Expand Down Expand Up @@ -300,6 +302,7 @@ SwapchainImplVK::SwapchainImplVK(const std::shared_ptr<Context>& context,
synchronizers_ = std::move(synchronizers);
current_frame_ = synchronizers_.size() - 1u;
size_ = size;
enable_msaa_ = enable_msaa;
is_valid_ = true;
}

Expand Down Expand Up @@ -405,7 +408,8 @@ SwapchainImplVK::AcquireResult SwapchainImplVK::AcquireNextDrawable() {
return false;
}
return swapchain->Present(image, image_index);
} // swap callback
}, // swap callback
enable_msaa_ //
)};
}

Expand Down
3 changes: 3 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain_impl_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SwapchainImplVK final
const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa = true,
vk::SwapchainKHR old_swapchain = VK_NULL_HANDLE);

~SwapchainImplVK();
Expand Down Expand Up @@ -72,11 +73,13 @@ class SwapchainImplVK final
std::vector<std::unique_ptr<FrameSynchronizer>> synchronizers_;
size_t current_frame_ = 0u;
ISize size_;
bool enable_msaa_ = true;
bool is_valid_ = false;

SwapchainImplVK(const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa,
vk::SwapchainKHR old_swapchain);

bool Present(const std::shared_ptr<SwapchainImageVK>& image, uint32_t index);
Expand Down
15 changes: 10 additions & 5 deletions impeller/renderer/backend/vulkan/swapchain_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ namespace impeller {
std::shared_ptr<SwapchainVK> SwapchainVK::Create(
const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size) {
auto impl = SwapchainImplVK::Create(context, std::move(surface), size);
const ISize& size,
bool enable_msaa) {
auto impl =
SwapchainImplVK::Create(context, std::move(surface), size, enable_msaa);
if (!impl || !impl->IsValid()) {
VALIDATION_LOG << "Failed to create SwapchainVK implementation.";
return nullptr;
}
return std::shared_ptr<SwapchainVK>(new SwapchainVK(std::move(impl), size));
return std::shared_ptr<SwapchainVK>(
new SwapchainVK(std::move(impl), size, enable_msaa));
}

SwapchainVK::SwapchainVK(std::shared_ptr<SwapchainImplVK> impl,
const ISize& size)
: impl_(std::move(impl)), size_(size) {}
const ISize& size,
bool enable_msaa)
: impl_(std::move(impl)), size_(size), enable_msaa_(enable_msaa) {}

SwapchainVK::~SwapchainVK() = default;

Expand Down Expand Up @@ -60,6 +64,7 @@ std::unique_ptr<Surface> SwapchainVK::AcquireNextDrawable() {
auto new_impl = SwapchainImplVK::Create(context, //
std::move(surface), //
size_, //
enable_msaa_, //
*old_swapchain //
);
if (!new_impl || !new_impl->IsValid()) {
Expand Down
7 changes: 4 additions & 3 deletions impeller/renderer/backend/vulkan/swapchain_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <memory>

#include "flutter/fml/macros.h"
#include "impeller/geometry/size.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "impeller/renderer/context.h"
Expand All @@ -28,7 +27,8 @@ class SwapchainVK {
static std::shared_ptr<SwapchainVK> Create(
const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size);
const ISize& size,
bool enable_msaa = true);

~SwapchainVK();

Expand All @@ -45,8 +45,9 @@ class SwapchainVK {
private:
std::shared_ptr<SwapchainImplVK> impl_;
ISize size_;
const bool enable_msaa_;

SwapchainVK(std::shared_ptr<SwapchainImplVK> impl, const ISize& size);
SwapchainVK(std::shared_ptr<SwapchainImplVK> impl, const ISize& size, bool enable_msaa);

SwapchainVK(const SwapchainVK&) = delete;

Expand Down
Loading