Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Add the KHR prefix to existing swapchain utilities. #51295

Merged
merged 2 commits into from
Mar 8, 2024
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
2 changes: 2 additions & 0 deletions ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
../../../flutter/impeller/renderer/backend/vulkan/fence_waiter_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
../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/README.md
../../../flutter/impeller/renderer/backend/vulkan/test
../../../flutter/impeller/renderer/blit_pass_unittests.cc
../../../flutter/impeller/renderer/capabilities_unittests.cc
Expand Down
32 changes: 16 additions & 16 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -38136,14 +38136,14 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/shared_object_vk.cc +
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/shared_object_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/surface_context_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/surface_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/surface_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_image_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_image_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/texture_source_vk.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/texture_source_vk.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/texture_vk.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -40988,14 +40988,14 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/shared_object_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/shared_object_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/surface_context_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/surface_context_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/surface_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/surface_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_image_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_image_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_impl_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_impl_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/texture_source_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/texture_source_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/texture_vk.cc
Expand Down
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/surface_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_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
16 changes: 8 additions & 8 deletions impeller/renderer/backend/vulkan/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ impeller_component("vulkan") {
"shared_object_vk.h",
"surface_context_vk.cc",
"surface_context_vk.h",
"surface_vk.cc",
"surface_vk.h",
"swapchain_image_vk.cc",
"swapchain_image_vk.h",
"swapchain_impl_vk.cc",
"swapchain_impl_vk.h",
"swapchain_vk.cc",
"swapchain_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",
"texture_source_vk.cc",
"texture_source_vk.h",
"texture_vk.cc",
Expand Down
4 changes: 2 additions & 2 deletions impeller/renderer/backend/vulkan/surface_context_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "flutter/fml/trace_event.h"
#include "impeller/renderer/backend/vulkan/command_pool_vk.h"
#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_vk.h"
#include "impeller/renderer/surface.h"

namespace impeller {
Expand Down Expand Up @@ -64,7 +64,7 @@ void SurfaceContextVK::Shutdown() {

bool SurfaceContextVK::SetWindowSurface(vk::UniqueSurfaceKHR surface,
const ISize& size) {
auto swapchain = SwapchainVK::Create(parent_, std::move(surface), size);
auto swapchain = KHRSwapchainVK::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 SwapchainVK;
class KHRSwapchainVK;

/// 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 @@ -88,7 +88,7 @@ class SurfaceContextVK : public Context,

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

} // namespace impeller
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Vulkan Swapchains
=================

Contains implementations of swapchains for Window System Integration (WSI) on different platforms.
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain/khr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
KHR Swapchain
=============

An implementation of a Vulkan swapchain that depends on [`VK_KHR_swapchain`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_swapchain.html). This swapchain is available on most platforms but may not be ideal on all. But, it is a good fallback.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/renderer/backend/vulkan/surface_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h"

#include "impeller/core/formats.h"
#include "impeller/renderer/backend/vulkan/swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/surface.h"

namespace impeller {

std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
std::unique_ptr<KHRSurfaceVK> KHRSurfaceVK::WrapSwapchainImage(
const std::shared_ptr<Context>& context,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
std::shared_ptr<KHRSwapchainImageVK>& swapchain_image,
SwapCallback swap_callback,
bool enable_msaa) {
if (!context || !swapchain_image || !swap_callback) {
Expand Down Expand Up @@ -88,16 +88,17 @@ std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
);

// The constructor is private. So make_unique may not be used.
return std::unique_ptr<SurfaceVK>(
new SurfaceVK(render_target_desc, std::move(swap_callback)));
return std::unique_ptr<KHRSurfaceVK>(
new KHRSurfaceVK(render_target_desc, std::move(swap_callback)));
}

SurfaceVK::SurfaceVK(const RenderTarget& target, SwapCallback swap_callback)
KHRSurfaceVK::KHRSurfaceVK(const RenderTarget& target,
SwapCallback swap_callback)
: Surface(target), swap_callback_(std::move(swap_callback)) {}

SurfaceVK::~SurfaceVK() = default;
KHRSurfaceVK::~KHRSurfaceVK() = default;

bool SurfaceVK::Present() const {
bool KHRSurfaceVK::Present() const {
return swap_callback_ ? swap_callback_() : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_VK_H_
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SURFACE_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SURFACE_VK_H_

#include <memory>

#include "impeller/renderer/backend/vulkan/context_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h"
#include "impeller/renderer/surface.h"

namespace impeller {

class SurfaceVK final : public Surface {
class KHRSurfaceVK final : public Surface {
public:
using SwapCallback = std::function<bool(void)>;

Expand All @@ -22,28 +22,28 @@ class SurfaceVK final : public Surface {
/// target by Impeller.
///
/// This creates the associated MSAA and depth+stencil texture.
static std::unique_ptr<SurfaceVK> WrapSwapchainImage(
static std::unique_ptr<KHRSurfaceVK> WrapSwapchainImage(
const std::shared_ptr<Context>& context,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
std::shared_ptr<KHRSwapchainImageVK>& swapchain_image,
SwapCallback swap_callback,
bool enable_msaa = true);

// |Surface|
~SurfaceVK() override;
~KHRSurfaceVK() override;

private:
SwapCallback swap_callback_;

SurfaceVK(const RenderTarget& target, SwapCallback swap_callback);
KHRSurfaceVK(const RenderTarget& target, SwapCallback swap_callback);

// |Surface|
bool Present() const override;

SurfaceVK(const SurfaceVK&) = delete;
KHRSurfaceVK(const KHRSurfaceVK&) = delete;

SurfaceVK& operator=(const SurfaceVK&) = delete;
KHRSurfaceVK& operator=(const KHRSurfaceVK&) = delete;
};

} // namespace impeller

#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SURFACE_VK_H_
#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SURFACE_VK_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/renderer/backend/vulkan/swapchain_image_vk.h"
#include "impeller/renderer/backend/vulkan/swapchain/khr/khr_swapchain_image_vk.h"

namespace impeller {

SwapchainImageVK::SwapchainImageVK(TextureDescriptor desc,
const vk::Device& device,
vk::Image image)
KHRSwapchainImageVK::KHRSwapchainImageVK(TextureDescriptor desc,
const vk::Device& device,
vk::Image image)
: TextureSourceVK(desc), image_(image) {
vk::ImageViewCreateInfo view_info;
view_info.image = image_;
Expand All @@ -29,49 +29,49 @@ SwapchainImageVK::SwapchainImageVK(TextureDescriptor desc,
is_valid_ = true;
}

SwapchainImageVK::~SwapchainImageVK() = default;
KHRSwapchainImageVK::~KHRSwapchainImageVK() = default;

bool SwapchainImageVK::IsValid() const {
bool KHRSwapchainImageVK::IsValid() const {
return is_valid_;
}

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

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

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

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

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

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

// |TextureSourceVK|
vk::Image SwapchainImageVK::GetImage() const {
vk::Image KHRSwapchainImageVK::GetImage() const {
return image_;
}

// |TextureSourceVK|
vk::ImageView SwapchainImageVK::GetImageView() const {
vk::ImageView KHRSwapchainImageVK::GetImageView() const {
return image_view_.get();
}

// |TextureSourceVK|
vk::ImageView SwapchainImageVK::GetRenderTargetView() const {
vk::ImageView KHRSwapchainImageVK::GetRenderTargetView() const {
return image_view_.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_IMAGE_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_IMAGE_VK_H_
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMAGE_VK_H_
#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMAGE_VK_H_

#include "impeller/geometry/size.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
Expand All @@ -13,14 +13,14 @@

namespace impeller {

class SwapchainImageVK final : public TextureSourceVK {
class KHRSwapchainImageVK final : public TextureSourceVK {
public:
SwapchainImageVK(TextureDescriptor desc,
const vk::Device& device,
vk::Image image);
KHRSwapchainImageVK(TextureDescriptor desc,
const vk::Device& device,
vk::Image image);

// |TextureSourceVK|
~SwapchainImageVK() override;
~KHRSwapchainImageVK() override;

bool IsValid() const;

Expand Down Expand Up @@ -53,11 +53,11 @@ class SwapchainImageVK final : public TextureSourceVK {
std::shared_ptr<Texture> depth_stencil_texture_;
bool is_valid_ = false;

SwapchainImageVK(const SwapchainImageVK&) = delete;
KHRSwapchainImageVK(const KHRSwapchainImageVK&) = delete;

SwapchainImageVK& operator=(const SwapchainImageVK&) = delete;
KHRSwapchainImageVK& operator=(const KHRSwapchainImageVK&) = delete;
};

} // namespace impeller

#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_IMAGE_VK_H_
#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMAGE_VK_H_
Loading