Skip to content

Commit

Permalink
[Impeller] Unconditionally cache swapchain msaa texture. (flutter#43529)
Browse files Browse the repository at this point in the history
Even on the Pixel 6 pro device which supports memoryless textures, I can observe creating the memoryless texture sometimes takes a few hundred microseconds, possibly due to stalls in the driver allocating the texture metadata. Lets just unconditionally cache this texture to avoid making the driver do more work.

Here is an example of this happening:

![image](https://github.com/flutter/engine/assets/8975114/a2d0fed7-7a25-4652-9932-2464b272d80c)

flutter/flutter#129392
  • Loading branch information
jonahwilliams authored Jul 11, 2023
1 parent 7b02300 commit 95316fb
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions impeller/renderer/backend/vulkan/surface_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
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 @@ -33,16 +27,14 @@ std::unique_ptr<SurfaceVK> SurfaceVK::WrapSwapchainImage(
msaa_tex_desc.usage = static_cast<uint64_t>(TextureUsage::kRenderTarget);

std::shared_ptr<Texture> msaa_tex;
if (supports_memoryless || !swapchain_image->HasMSAATexture()) {
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 (!supports_memoryless) {
swapchain_image->SetMSAATexture(msaa_tex);
}
swapchain_image->SetMSAATexture(msaa_tex);
} else {
msaa_tex = swapchain_image->GetMSAATexture();
}
Expand Down

0 comments on commit 95316fb

Please sign in to comment.