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
26 changes: 20 additions & 6 deletions impeller/renderer/backend/vulkan/surface_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ namespace impeller {

std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
const std::shared_ptr<Context>& context,
const std::shared_ptr<SwapchainImageVK>& swapchain_image,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
SwapCallback swap_callback) {
if (!context || !swapchain_image || !swap_callback) {
return nullptr;
}

// Some Vulkan devices may not support memoryless (lazily allocated) textures.
// In this case we will cache the MSAA texture on the swapchain image to avoid
// thrasing the VMA heap.
bool supports_memoryless =
context->GetCapabilities()->SupportsMemorylessTextures();

TextureDescriptor msaa_tex_desc;
msaa_tex_desc.storage_mode = StorageMode::kDeviceTransient;
msaa_tex_desc.type = TextureType::kTexture2DMultisample;
Expand All @@ -26,12 +32,20 @@ std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
msaa_tex_desc.size = swapchain_image->GetSize();
msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);

auto msaa_tex = context->GetResourceAllocator()->CreateTexture(msaa_tex_desc);
if (!msaa_tex) {
VALIDATION_LOG << "Could not allocate MSAA color texture.";
return nullptr;
std::shared_ptr<Texture> msaa_tex;
if (supports_memoryless || !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 (!supports_memoryless) {
swapchain_image->SetMSAATexture(msaa_tex);
}
} else {
msaa_tex = swapchain_image->GetMSAATexture();
}
msaa_tex->SetLabel("ImpellerOnscreenColorMSAA");

TextureDescriptor resolve_tex_desc;
resolve_tex_desc.type = TextureType::kTexture2D;
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/vulkan/surface_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SurfaceVK final : public Surface {

static std::unique_ptr<SurfaceVK> WrapSwapchainImage(
const std::shared_ptr<Context>& context,
const std::shared_ptr<SwapchainImageVK>& swapchain_image,
std::shared_ptr<SwapchainImageVK>& swapchain_image,
SwapCallback swap_callback);

// |Surface|
Expand Down
12 changes: 12 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain_image_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ bool SwapchainImageVK::IsValid() const {
return is_valid_;
}

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

bool SwapchainImageVK::HasMSAATexture() const {
return msaa_tex_ != nullptr;
}

void SwapchainImageVK::SetMSAATexture(std::shared_ptr<Texture> msaa_tex) {
msaa_tex_ = std::move(msaa_tex);
}

PixelFormat SwapchainImageVK::GetPixelFormat() const {
return desc_.format;
}
Expand Down
7 changes: 7 additions & 0 deletions impeller/renderer/backend/vulkan/swapchain_image_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ class SwapchainImageVK final : public TextureSourceVK {
// |TextureSourceVK|
vk::Image GetImage() const override;

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

bool HasMSAATexture() const;

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

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

private:
vk::Image image_ = VK_NULL_HANDLE;
vk::UniqueImageView image_view_ = {};
std::shared_ptr<Texture> msaa_tex_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rough as these textures are huge. We should measure memory usage but I doubt we can use the Vulkan backend in this instance. This is just the the swapchain images. These will add up for intermediates as well.

If this is to stabilize the benchmarks, its fine I suppose. But we should then find a device to put in the lab that does support lazily allocated images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd like to punt on whether or not we decided to ship Vulkan on these devices. We'll likely learn even more once we actually attempt the Vulkan to GL texture interop.

Though for the short term, we must keep something on CI using Vulkan and I don't think we have any other devices.

Copy link
Member

@gaaclarke gaaclarke Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt we can use the Vulkan backend in this instance

Couldn't we use a different AA than MSAA, like fxaa?

bool is_valid_ = false;

FML_DISALLOW_COPY_AND_ASSIGN(SwapchainImageVK);
Expand Down