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
2 changes: 1 addition & 1 deletion impeller/playground/backend/vulkan/playground_impl_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/surface_context_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/surface_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/vk/compute_shaders_vk.h"
#include "impeller/scene/shaders/vk/scene_shaders_vk.h"
Expand Down
8 changes: 6 additions & 2 deletions impeller/renderer/backend/vulkan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ impeller_component("vulkan") {
"shared_object_vk.h",
"surface_context_vk.cc",
"surface_context_vk.h",
"swapchain/khr/khr_surface_vk.cc",
"swapchain/khr/khr_surface_vk.h",
"swapchain/khr/khr_swapchain_image_vk.cc",
"swapchain/khr/khr_swapchain_image_vk.h",
"swapchain/khr/khr_swapchain_impl_vk.cc",
"swapchain/khr/khr_swapchain_impl_vk.h",
"swapchain/khr/khr_swapchain_vk.cc",
"swapchain/khr/khr_swapchain_vk.h",
"swapchain/surface_vk.cc",
"swapchain/surface_vk.h",
"swapchain/swapchain_transients_vk.cc",
"swapchain/swapchain_transients_vk.h",
"swapchain/swapchain_vk.cc",
"swapchain/swapchain_vk.h",
"texture_source_vk.cc",
"texture_source_vk.h",
"texture_vk.cc",
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/surface_context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void SurfaceContextVK::Shutdown() {

bool SurfaceContextVK::SetWindowSurface(vk::UniqueSurfaceKHR surface,
const ISize& size) {
auto swapchain = KHRSwapchainVK::Create(parent_, std::move(surface), size);
auto swapchain = SwapchainVK::Create(parent_, std::move(surface), size);
if (!swapchain) {
VALIDATION_LOG << "Could not create swapchain.";
return false;
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/vulkan/surface_context_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace impeller {

class ContextVK;
class Surface;
class KHRSwapchainVK;
class SwapchainVK;

/// For Vulkan, there is both a ContextVK that implements Context and a
/// SurfaceContextVK that also implements Context and takes a ContextVK as its
Expand Down Expand Up @@ -90,7 +90,7 @@ class SurfaceContextVK : public Context,

private:
std::shared_ptr<ContextVK> parent_;
std::shared_ptr<KHRSwapchainVK> swapchain_;
std::shared_ptr<SwapchainVK> swapchain_;
};

} // namespace impeller
Expand Down
104 changes: 0 additions & 104 deletions impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.cc

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ bool KHRSwapchainImageVK::IsValid() const {
return is_valid_;
}

std::shared_ptr<Texture> KHRSwapchainImageVK::GetMSAATexture() const {
return msaa_texture_;
}

std::shared_ptr<Texture> KHRSwapchainImageVK::GetDepthStencilTexture() const {
return depth_stencil_texture_;
}

void KHRSwapchainImageVK::SetMSAATexture(std::shared_ptr<Texture> texture) {
msaa_texture_ = std::move(texture);
}

void KHRSwapchainImageVK::SetDepthStencilTexture(
std::shared_ptr<Texture> texture) {
depth_stencil_texture_ = std::move(texture);
}

PixelFormat KHRSwapchainImageVK::GetPixelFormat() const {
return desc_.format;
}

ISize KHRSwapchainImageVK::GetSize() const {
return desc_.size;
}

// |TextureSourceVK|
vk::Image KHRSwapchainImageVK::GetImage() const {
return image_;
Expand All @@ -75,4 +50,9 @@ vk::ImageView KHRSwapchainImageVK::GetRenderTargetView() const {
return image_view_.get();
}

// |TextureSourceVK|
bool KHRSwapchainImageVK::IsSwapchainImage() const {
return true;
}

} // namespace impeller
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/texture_source_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "vulkan/vulkan_handles.hpp"

namespace impeller {

Expand All @@ -24,33 +23,21 @@ class KHRSwapchainImageVK final : public TextureSourceVK {

bool IsValid() const;

PixelFormat GetPixelFormat() const;

ISize GetSize() const;

// |TextureSourceVK|
vk::Image GetImage() const override;

std::shared_ptr<Texture> GetMSAATexture() const;

std::shared_ptr<Texture> GetDepthStencilTexture() const;

// |TextureSourceVK|
vk::ImageView GetImageView() const override;

// |TextureSourceVK|
vk::ImageView GetRenderTargetView() const override;

void SetMSAATexture(std::shared_ptr<Texture> texture);

void SetDepthStencilTexture(std::shared_ptr<Texture> texture);

bool IsSwapchainImage() const override { return true; }
// |TextureSourceVK|
bool IsSwapchainImage() const override;

private:
vk::Image image_ = VK_NULL_HANDLE;
vk::UniqueImageView image_view_ = {};
std::shared_ptr<Texture> msaa_texture_;
std::shared_ptr<Texture> depth_stencil_texture_;
bool is_valid_ = false;

KHRSwapchainImageVK(const KHRSwapchainImageVK&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/gpu_tracer_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/surface_vk.h"
#include "impeller/renderer/context.h"
#include "vulkan/vulkan_structs.hpp"

namespace impeller {

Expand Down Expand Up @@ -228,40 +227,6 @@ KHRSwapchainImplVK::KHRSwapchainImplVK(const std::shared_ptr<Context>& context,
texture_desc.size = ISize::MakeWH(swapchain_info.imageExtent.width,
swapchain_info.imageExtent.height);

// Allocate a single onscreen MSAA texture and Depth+Stencil Texture to
// be shared by all swapchain images.
TextureDescriptor msaa_desc;
msaa_desc.storage_mode = StorageMode::kDeviceTransient;
msaa_desc.type = TextureType::kTexture2DMultisample;
msaa_desc.sample_count = SampleCount::kCount4;
msaa_desc.format = texture_desc.format;
msaa_desc.size = texture_desc.size;
msaa_desc.usage = TextureUsage::kRenderTarget;

// The depth+stencil configuration matches the configuration used by
// RenderTarget::SetupDepthStencilAttachments and matching the swapchain
// image dimensions and sample count.
TextureDescriptor depth_stencil_desc;
depth_stencil_desc.storage_mode = StorageMode::kDeviceTransient;
if (enable_msaa) {
depth_stencil_desc.type = TextureType::kTexture2DMultisample;
depth_stencil_desc.sample_count = SampleCount::kCount4;
} else {
depth_stencil_desc.type = TextureType::kTexture2D;
depth_stencil_desc.sample_count = SampleCount::kCount1;
}
depth_stencil_desc.format =
context->GetCapabilities()->GetDefaultDepthStencilFormat();
depth_stencil_desc.size = texture_desc.size;
depth_stencil_desc.usage = TextureUsage::kRenderTarget;

std::shared_ptr<Texture> msaa_texture;
if (enable_msaa) {
msaa_texture = context->GetResourceAllocator()->CreateTexture(msaa_desc);
}
std::shared_ptr<Texture> depth_stencil_texture =
context->GetResourceAllocator()->CreateTexture(depth_stencil_desc);

std::vector<std::shared_ptr<KHRSwapchainImageVK>> swapchain_images;
for (const auto& image : images) {
auto swapchain_image = std::make_shared<KHRSwapchainImageVK>(
Expand All @@ -273,9 +238,6 @@ KHRSwapchainImplVK::KHRSwapchainImplVK(const std::shared_ptr<Context>& context,
VALIDATION_LOG << "Could not create swapchain image.";
return;
}
swapchain_image->SetMSAATexture(msaa_texture);
swapchain_image->SetDepthStencilTexture(depth_stencil_texture);

ContextVK::SetDebugName(
vk_context.GetDevice(), swapchain_image->GetImage(),
"SwapchainImage" + std::to_string(swapchain_images.size()));
Expand All @@ -302,6 +264,8 @@ KHRSwapchainImplVK::KHRSwapchainImplVK(const std::shared_ptr<Context>& context,
surface_ = std::move(surface);
surface_format_ = swapchain_info.imageFormat;
swapchain_ = std::move(swapchain);
transients_ = std::make_shared<SwapchainTransientsVK>(context, texture_desc,
enable_msaa);
images_ = std::move(swapchain_images);
synchronizers_ = std::move(synchronizers);
current_frame_ = synchronizers_.size() - 1u;
Expand Down Expand Up @@ -403,17 +367,16 @@ KHRSwapchainImplVK::AcquireResult KHRSwapchainImplVK::AcquireNextDrawable() {

auto image = images_[index % images_.size()];
uint32_t image_index = index;
return AcquireResult{KHRSurfaceVK::WrapSwapchainImage(
context_strong, // context
image, // swapchain image
return AcquireResult{SurfaceVK::WrapSwapchainImage(
transients_, // transients
image, // swapchain image
[weak_swapchain = weak_from_this(), image, image_index]() -> bool {
auto swapchain = weak_swapchain.lock();
if (!swapchain) {
return false;
}
return swapchain->Present(image, image_index);
}, // swap callback
enable_msaa_ //
} // swap callback
)};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <variant>

#include "impeller/geometry/size.h"
#include "impeller/renderer/backend/vulkan/swapchain/swapchain_transients_vk.h"
#include "impeller/renderer/backend/vulkan/vk.h"
#include "vulkan/vulkan_enums.hpp"

namespace impeller {

Expand Down Expand Up @@ -68,6 +68,7 @@ class KHRSwapchainImplVK final
vk::UniqueSurfaceKHR surface_;
vk::Format surface_format_ = vk::Format::eUndefined;
vk::UniqueSwapchainKHR swapchain_;
std::shared_ptr<SwapchainTransientsVK> transients_;
std::vector<std::shared_ptr<KHRSwapchainImageVK>> images_;
std::vector<std::unique_ptr<KHRFrameSynchronizerVK>> synchronizers_;
size_t current_frame_ = 0u;
Expand Down
27 changes: 12 additions & 15 deletions impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@

namespace impeller {

std::shared_ptr<KHRSwapchainVK> KHRSwapchainVK::Create(
const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa) {
auto impl = KHRSwapchainImplVK::Create(context, std::move(surface), size,
enable_msaa);
KHRSwapchainVK::KHRSwapchainVK(const std::shared_ptr<Context>& context,
vk::UniqueSurfaceKHR surface,
const ISize& size,
bool enable_msaa)
: size_(size), enable_msaa_(enable_msaa) {
auto impl = KHRSwapchainImplVK::Create(context, //
std::move(surface), //
size_, //
enable_msaa_ //
);
if (!impl || !impl->IsValid()) {
VALIDATION_LOG << "Failed to create SwapchainVK implementation.";
return nullptr;
return;
}
return std::shared_ptr<KHRSwapchainVK>(
new KHRSwapchainVK(std::move(impl), size, enable_msaa));
impl_ = std::move(impl);
}

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

KHRSwapchainVK::~KHRSwapchainVK() = default;

bool KHRSwapchainVK::IsValid() const {
Expand Down
Loading