From 89bdfba3d7df1d81287fa7db2d3101487a095196 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 23 Jan 2024 11:17:05 -0800 Subject: [PATCH] [Impeller] fix validation error for playground texture upload. (flutter/engine#49957) Buffer to image is missing barriers. We don't really need to use this for playgrounds though, as set contents does the right thing more or less. Fixes https://github.com/flutter/flutter/issues/142024 --- .../golden_playground_test_mac.cc | 1 + .../flutter/impeller/playground/playground.cc | 74 +++++-------------- 2 files changed, 21 insertions(+), 54 deletions(-) diff --git a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc index c8bbe289d60..2077e7a2bae 100644 --- a/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc +++ b/engine/src/flutter/impeller/golden_tests/golden_playground_test_mac.cc @@ -63,6 +63,7 @@ static const std::vector kSkipTests = { /// TODO(https://github.com/flutter/flutter/issues/142017): Turn on validation /// for all vulkan tests. static const std::vector kVulkanValidationTests = { + "impeller_Play_AiksTest_CanRenderImageRect_Vulkan", "impeller_Play_AiksTest_CanRenderTextFrame_Vulkan", }; diff --git a/engine/src/flutter/impeller/playground/playground.cc b/engine/src/flutter/impeller/playground/playground.cc index c4f4f1338c3..d018885377f 100644 --- a/engine/src/flutter/impeller/playground/playground.cc +++ b/engine/src/flutter/impeller/playground/playground.cc @@ -385,29 +385,26 @@ static std::shared_ptr CreateTextureForDecompressedImage( const std::shared_ptr& context, DecompressedImage& decompressed_image, bool enable_mipmapping) { - // TODO(https://github.com/flutter/flutter/issues/123468): copying buffers to - // textures is not implemented for GLES. - if (context->GetCapabilities()->SupportsBufferToTextureBlits()) { - impeller::TextureDescriptor texture_descriptor; - texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate; - texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt; - texture_descriptor.size = decompressed_image.GetSize(); - texture_descriptor.mip_count = - enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u; + auto texture_descriptor = TextureDescriptor{}; + texture_descriptor.storage_mode = StorageMode::kHostVisible; + texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt; + texture_descriptor.size = decompressed_image.GetSize(); + texture_descriptor.mip_count = + enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u; - auto dest_texture = - context->GetResourceAllocator()->CreateTexture(texture_descriptor); - if (!dest_texture) { - FML_DLOG(ERROR) << "Could not create Impeller texture."; - return nullptr; - } - - auto buffer = context->GetResourceAllocator()->CreateBufferWithCopy( - *decompressed_image.GetAllocation().get()); - - dest_texture->SetLabel( - impeller::SPrintF("ui.Image(%p)", dest_texture.get()).c_str()); + auto texture = + context->GetResourceAllocator()->CreateTexture(texture_descriptor); + if (!texture) { + VALIDATION_LOG << "Could not allocate texture for fixture."; + return nullptr; + } + auto uploaded = texture->SetContents(decompressed_image.GetAllocation()); + if (!uploaded) { + VALIDATION_LOG << "Could not upload texture to device memory for fixture."; + return nullptr; + } + if (enable_mipmapping) { auto command_buffer = context->CreateCommandBuffer(); if (!command_buffer) { FML_DLOG(ERROR) @@ -415,47 +412,16 @@ static std::shared_ptr CreateTextureForDecompressedImage( return nullptr; } command_buffer->SetLabel("Mipmap Command Buffer"); - auto blit_pass = command_buffer->CreateBlitPass(); - if (!blit_pass) { - FML_DLOG(ERROR) << "Could not create blit pass for mipmap generation."; - return nullptr; - } blit_pass->SetLabel("Mipmap Blit Pass"); - blit_pass->AddCopy(DeviceBuffer::AsBufferView(buffer), dest_texture); - if (enable_mipmapping) { - blit_pass->GenerateMipmap(dest_texture); - } - + blit_pass->GenerateMipmap(texture); blit_pass->EncodeCommands(context->GetResourceAllocator()); if (!command_buffer->SubmitCommands()) { FML_DLOG(ERROR) << "Failed to submit blit pass command buffer."; return nullptr; } - return dest_texture; - } else { // Doesn't support buffer-to-texture blits. - auto texture_descriptor = TextureDescriptor{}; - texture_descriptor.storage_mode = StorageMode::kHostVisible; - texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt; - texture_descriptor.size = decompressed_image.GetSize(); - texture_descriptor.mip_count = - enable_mipmapping ? decompressed_image.GetSize().MipCount() : 1u; - - auto texture = - context->GetResourceAllocator()->CreateTexture(texture_descriptor); - if (!texture) { - VALIDATION_LOG << "Could not allocate texture for fixture."; - return nullptr; - } - - auto uploaded = texture->SetContents(decompressed_image.GetAllocation()); - if (!uploaded) { - VALIDATION_LOG - << "Could not upload texture to device memory for fixture."; - return nullptr; - } - return texture; } + return texture; } std::shared_ptr Playground::CreateTextureForMapping(