From 4c362b22426e22622245488388e2dc6d49d8dedb Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 28 Jan 2024 15:32:58 -0800 Subject: [PATCH 01/21] [Impeller] introduce queue abstraction to allow aiks to batch submit. --- impeller/aiks/aiks_context.cc | 1 + impeller/aiks/aiks_unittests.cc | 17 +- impeller/entity/contents/content_context.cc | 3 +- impeller/entity/contents/content_context.h | 13 ++ impeller/entity/entity_pass.cc | 10 +- .../entity/geometry/point_field_geometry.cc | 3 +- impeller/entity/inline_pass_context.cc | 19 +- impeller/entity/inline_pass_context.h | 6 +- impeller/golden_tests/vulkan_screenshotter.mm | 11 +- impeller/playground/playground.cc | 6 +- impeller/renderer/BUILD.gn | 2 + impeller/renderer/backend/gles/context_gles.h | 6 + .../renderer/backend/metal/surface_mtl.mm | 2 +- impeller/renderer/backend/vulkan/BUILD.gn | 2 + .../backend/vulkan/command_buffer_vk.cc | 12 +- .../backend/vulkan/command_encoder_vk.cc | 55 +---- .../backend/vulkan/command_encoder_vk.h | 6 +- .../renderer/backend/vulkan/context_vk.cc | 4 +- impeller/renderer/backend/vulkan/context_vk.h | 8 + .../renderer/backend/vulkan/gpu_tracer_vk.cc | 8 +- .../backend/vulkan/graphics_queue_vk.cc | 84 +++++++ .../backend/vulkan/graphics_queue_vk.h | 29 +++ .../backend/vulkan/surface_context_vk.cc | 4 + .../backend/vulkan/surface_context_vk.h | 4 + .../vulkan/test/gpu_tracer_unittests.cc | 22 +- .../renderer/backend/vulkan/texture_vk.cc | 2 +- impeller/renderer/command_buffer.cc | 25 -- impeller/renderer/command_buffer.h | 53 ++--- impeller/renderer/compute_tessellator.cc | 3 +- impeller/renderer/compute_unittests.cc | 219 ++++++++++-------- impeller/renderer/context.h | 6 +- impeller/renderer/graphics_queue.cc | 25 ++ impeller/renderer/graphics_queue.h | 47 ++++ impeller/renderer/renderer_unittests.cc | 11 +- impeller/scene/scene.cc | 5 +- lib/gpu/command_buffer.cc | 12 +- lib/gpu/command_buffer.h | 4 +- lib/ui/painting/image_decoder_impeller.cc | 4 +- lib/ui/painting/image_decoder_unittests.cc | 7 + lib/ui/painting/image_encoding_impeller.cc | 4 +- shell/common/rasterizer.cc | 4 +- .../android/android_context_gl_unittests.cc | 4 + .../android/image_external_texture_vk.cc | 2 +- 43 files changed, 479 insertions(+), 295 deletions(-) create mode 100644 impeller/renderer/backend/vulkan/graphics_queue_vk.cc create mode 100644 impeller/renderer/backend/vulkan/graphics_queue_vk.h create mode 100644 impeller/renderer/graphics_queue.cc create mode 100644 impeller/renderer/graphics_queue.h diff --git a/impeller/aiks/aiks_context.cc b/impeller/aiks/aiks_context.cc index 3be53f953713b..3ebf87470730b 100644 --- a/impeller/aiks/aiks_context.cc +++ b/impeller/aiks/aiks_context.cc @@ -53,6 +53,7 @@ bool AiksContext::Render(const Picture& picture, } fml::ScopedCleanupClosure closure([&]() { + content_context_->FlushCommandBuffers(); if (reset_host_buffer) { content_context_->GetTransientsBuffer().Reset(); } diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index b8ace127462c5..e66833f185272 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -141,8 +141,7 @@ TEST_P(AiksTest, CanRenderColorFilterWithInvertColorsDrawPaint) { namespace { bool GenerateMipmap(const std::shared_ptr& context, std::shared_ptr texture, - std::string label, - bool async_submit) { + std::string label) { auto buffer = context->CreateCommandBuffer(); if (!buffer) { return false; @@ -152,23 +151,19 @@ bool GenerateMipmap(const std::shared_ptr& context, return false; } pass->GenerateMipmap(std::move(texture), std::move(label)); - if (async_submit) { - return buffer->EncodeAndSubmit(pass, context->GetResourceAllocator()); - } pass->EncodeCommands(context->GetResourceAllocator()); - return buffer->SubmitCommands(); + return context->GetQueue()->Submit({buffer}).ok(); } void CanRenderTiledTexture(AiksTest* aiks_test, Entity::TileMode tile_mode, - bool async_submit = false, Matrix local_matrix = {}) { auto context = aiks_test->GetContext(); ASSERT_TRUE(context); auto texture = aiks_test->CreateTextureForFixture("table_mountain_nx.png", /*enable_mipmapping=*/true); - GenerateMipmap(context, texture, "table_mountain_nx", async_submit); + GenerateMipmap(context, texture, "table_mountain_nx"); Canvas canvas; canvas.Scale(aiks_test->GetContentScale()); canvas.Translate({100.0f, 100.0f, 0}); @@ -215,10 +210,6 @@ TEST_P(AiksTest, CanRenderTiledTextureClamp) { CanRenderTiledTexture(this, Entity::TileMode::kClamp); } -TEST_P(AiksTest, CanRenderTiledTextureClampAsync) { - CanRenderTiledTexture(this, Entity::TileMode::kClamp, /*async_submit=*/true); -} - TEST_P(AiksTest, CanRenderTiledTextureRepeat) { CanRenderTiledTexture(this, Entity::TileMode::kRepeat); } @@ -232,7 +223,7 @@ TEST_P(AiksTest, CanRenderTiledTextureDecal) { } TEST_P(AiksTest, CanRenderTiledTextureClampWithTranslate) { - CanRenderTiledTexture(this, Entity::TileMode::kClamp, /*async_submit=*/false, + CanRenderTiledTexture(this, Entity::TileMode::kClamp, Matrix::MakeTranslation({172.f, 172.f, 0.f})); } diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index f4c186199a817..e47daa59d0a69 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -477,9 +477,10 @@ fml::StatusOr ContentContext::MakeSubpass( return fml::Status(fml::StatusCode::kUnknown, ""); } - if (!sub_command_buffer->EncodeAndSubmit(sub_renderpass)) { + if (!sub_renderpass->EncodeCommands()) { return fml::Status(fml::StatusCode::kUnknown, ""); } + RecordCommandBuffer(std::move(sub_command_buffer)); return subpass_target; } diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 2bcbb725068bf..cc3dfbd1c1253 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -18,6 +18,7 @@ #include "impeller/core/host_buffer.h" #include "impeller/entity/entity.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/command_buffer.h" #include "impeller/renderer/pipeline.h" #include "impeller/renderer/pipeline_descriptor.h" #include "impeller/renderer/render_target.h" @@ -715,6 +716,16 @@ class ContentContext { void SetWireframe(bool wireframe); + void RecordCommandBuffer( + std::shared_ptr command_buffer) const { + command_buffers_.push_back(std::move(command_buffer)); + } + + void FlushCommandBuffers() const { + GetContext()->GetQueue()->Submit(command_buffers_); + command_buffers_.clear(); + } + using SubpassCallback = std::function; @@ -1005,6 +1016,8 @@ class ContentContext { #endif // IMPELLER_ENABLE_3D std::shared_ptr render_target_cache_; std::shared_ptr host_buffer_; + // TODO + mutable std::vector> command_buffers_; bool wireframe_ = false; ContentContext(const ContentContext&) = delete; diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index 74e343f989861..3d2471a21fc9b 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -387,11 +387,11 @@ bool EntityPass::Render(ContentContext& renderer, blit_pass->AddCopy( offscreen_target.GetRenderTarget().GetRenderTargetTexture(), root_render_target.GetRenderTargetTexture()); - if (!command_buffer->EncodeAndSubmit( - blit_pass, renderer.GetContext()->GetResourceAllocator())) { + if (!blit_pass->EncodeCommands(renderer.GetContext()->GetResourceAllocator())) { VALIDATION_LOG << "Failed to encode root pass blit command."; return false; } + renderer.RecordCommandBuffer(std::move(command_buffer)); } else { auto render_pass = command_buffer->CreateRenderPass(root_render_target); render_pass->SetLabel("EntityPass Root Render Pass"); @@ -415,10 +415,11 @@ bool EntityPass::Render(ContentContext& renderer, } } - if (!command_buffer->EncodeAndSubmit(render_pass)) { + if (!render_pass->EncodeCommands()) { VALIDATION_LOG << "Failed to encode root pass command buffer."; return false; } + renderer.RecordCommandBuffer(std::move(command_buffer)); } return true; @@ -855,8 +856,7 @@ bool EntityPass::OnRender( collapsed_parent_pass) const { TRACE_EVENT0("impeller", "EntityPass::OnRender"); - const std::shared_ptr& context = renderer.GetContext(); - InlinePassContext pass_context(context, pass_target, + InlinePassContext pass_context(renderer, pass_target, GetTotalPassReads(renderer), GetElementCount(), collapsed_parent_pass); if (!pass_context.IsValid()) { diff --git a/impeller/entity/geometry/point_field_geometry.cc b/impeller/entity/geometry/point_field_geometry.cc index 5b5cd8caf7813..69d93455134de 100644 --- a/impeller/entity/geometry/point_field_geometry.cc +++ b/impeller/entity/geometry/point_field_geometry.cc @@ -220,9 +220,10 @@ GeometryResult PointFieldGeometry::GetPositionBufferGPU( output = geometry_uv_buffer; } - if (!compute_pass->EncodeCommands() || !cmd_buffer->SubmitCommands()) { + if (!compute_pass->EncodeCommands()) { return {}; } + renderer.RecordCommandBuffer(std::move(cmd_buffer)); return { .type = PrimitiveType::kTriangle, diff --git a/impeller/entity/inline_pass_context.cc b/impeller/entity/inline_pass_context.cc index 2ebfbbfaa32e6..d9258acd7938c 100644 --- a/impeller/entity/inline_pass_context.cc +++ b/impeller/entity/inline_pass_context.cc @@ -10,6 +10,7 @@ #include "impeller/base/allocation.h" #include "impeller/base/validation.h" #include "impeller/core/formats.h" +#include "impeller/entity/contents/content_context.h" #include "impeller/entity/entity_pass_target.h" #include "impeller/renderer/command_buffer.h" #include "impeller/renderer/texture_mipmap.h" @@ -17,12 +18,12 @@ namespace impeller { InlinePassContext::InlinePassContext( - std::shared_ptr context, + const ContentContext& renderer, EntityPassTarget& pass_target, uint32_t pass_texture_reads, uint32_t entity_count, std::optional collapsed_parent_pass) - : context_(std::move(context)), + : renderer_(renderer), pass_target_(pass_target), entity_count_(entity_count), is_collapsed_(collapsed_parent_pass.has_value()) { @@ -67,15 +68,13 @@ bool InlinePassContext::EndPass() { const std::shared_ptr& target_texture = GetPassTarget().GetRenderTarget().GetRenderTargetTexture(); if (target_texture->GetMipCount() > 1) { - fml::Status mip_status = - AddMipmapGeneration(command_buffer_, context_, target_texture); + fml::Status mip_status = AddMipmapGeneration( + command_buffer_, renderer_.GetContext(), target_texture); if (!mip_status.ok()) { return false; } } - if (!command_buffer_->SubmitCommands()) { - return false; - } + renderer_.RecordCommandBuffer(std::move(command_buffer_)); pass_ = nullptr; command_buffer_ = nullptr; @@ -97,7 +96,7 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass( /// time this method is called, but it'll also run if the pass has been /// previously ended via `EndPass`. - command_buffer_ = context_->CreateCommandBuffer(); + command_buffer_ = renderer_.GetContext()->CreateCommandBuffer(); if (!command_buffer_) { VALIDATION_LOG << "Could not create command buffer."; return {}; @@ -122,7 +121,7 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass( ->second.resolve_texture != nullptr; if (pass_count_ > 0 && is_msaa) { result.backdrop_texture = - pass_target_.Flip(*context_->GetResourceAllocator()); + pass_target_.Flip(*renderer_.GetContext()->GetResourceAllocator()); if (!result.backdrop_texture) { VALIDATION_LOG << "Could not flip the EntityPass render target."; } @@ -174,7 +173,7 @@ InlinePassContext::RenderPassResult InlinePassContext::GetRenderPass( result.pass = pass_; - if (!context_->GetCapabilities()->SupportsReadFromResolve() && + if (!renderer_.GetContext()->GetCapabilities()->SupportsReadFromResolve() && result.backdrop_texture == result.pass->GetRenderTarget().GetRenderTargetTexture()) { VALIDATION_LOG << "EntityPass backdrop restore configuration is not valid " diff --git a/impeller/entity/inline_pass_context.h b/impeller/entity/inline_pass_context.h index 595d291b5a1c8..62e8952d7ed68 100644 --- a/impeller/entity/inline_pass_context.h +++ b/impeller/entity/inline_pass_context.h @@ -7,10 +7,10 @@ #include +#include "impeller/entity/contents/content_context.h" #include "impeller/entity/entity_pass_target.h" #include "impeller/renderer/context.h" #include "impeller/renderer/render_pass.h" -#include "impeller/renderer/render_target.h" namespace impeller { @@ -22,7 +22,7 @@ class InlinePassContext { }; InlinePassContext( - std::shared_ptr context, + const ContentContext& renderer, EntityPassTarget& pass_target, uint32_t pass_texture_reads, uint32_t entity_count, @@ -45,7 +45,7 @@ class InlinePassContext { RenderPassResult GetRenderPass(uint32_t pass_depth); private: - std::shared_ptr context_; + const ContentContext& renderer_; EntityPassTarget& pass_target_; std::shared_ptr command_buffer_; std::shared_ptr pass_; diff --git a/impeller/golden_tests/vulkan_screenshotter.mm b/impeller/golden_tests/vulkan_screenshotter.mm index afa3a0262aa88..f96ad307b048d 100644 --- a/impeller/golden_tests/vulkan_screenshotter.mm +++ b/impeller/golden_tests/vulkan_screenshotter.mm @@ -36,10 +36,13 @@ fml::AutoResetWaitableEvent latch; success = - command_buffer->SubmitCommands([&latch](CommandBuffer::Status status) { - FML_CHECK(status == CommandBuffer::Status::kCompleted); - latch.Signal(); - }); + surface_context->GetQueue() + ->Submit({command_buffer}, + [&latch](CommandBuffer::Status status) { + FML_CHECK(status == CommandBuffer::Status::kCompleted); + latch.Signal(); + }) + .ok(); FML_CHECK(success); latch.Wait(); diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc index df44559af8730..dcdb189fa7247 100644 --- a/impeller/playground/playground.cc +++ b/impeller/playground/playground.cc @@ -306,7 +306,7 @@ bool Playground::OpenPlaygroundHere( ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass); pass->EncodeCommands(); - if (!buffer->SubmitCommands()) { + if (!renderer->GetContext()->GetQueue()->Submit({buffer}).ok()) { return false; } } @@ -350,7 +350,7 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) { } pass->EncodeCommands(); - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } return true; @@ -422,7 +422,7 @@ static std::shared_ptr CreateTextureForDecompressedImage( blit_pass->SetLabel("Mipmap Blit Pass"); blit_pass->GenerateMipmap(texture); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!command_buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({command_buffer}).ok()) { FML_DLOG(ERROR) << "Failed to submit blit pass command buffer."; return nullptr; } diff --git a/impeller/renderer/BUILD.gn b/impeller/renderer/BUILD.gn index 1456b65cb3ac2..b1fc85cf67830 100644 --- a/impeller/renderer/BUILD.gn +++ b/impeller/renderer/BUILD.gn @@ -55,6 +55,8 @@ impeller_component("renderer") { "command.h", "command_buffer.cc", "command_buffer.h", + "graphics_queue.h", + "graphics_queue.cc", "compute_pass.cc", "compute_pass.h", "compute_pipeline_builder.cc", diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index 3b1d19870263d..1e1521677aa5c 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -5,7 +5,9 @@ #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ +#include "fml/logging.h" #include "impeller/base/backend_cast.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/gles/allocator_gles.h" #include "impeller/renderer/backend/gles/capabilities_gles.h" #include "impeller/renderer/backend/gles/gpu_tracer_gles.h" @@ -85,6 +87,10 @@ class ContextGLES final : public Context, // |Context| const std::shared_ptr& GetCapabilities() const override; + const std::shared_ptr& GetQueue() const override { + FML_UNREACHABLE(); + } + // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index 20488fee9dd5e..250ee6b143283 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -242,7 +242,7 @@ blit_pass->AddCopy(source_texture_, destination_texture_, std::nullopt, clip_rect_->GetOrigin()); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!blit_command_buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({blit_command_buffer}).ok()) { return false; } } diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 63cf211048970..c0e3fa3182ea4 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -40,6 +40,8 @@ impeller_component("vulkan") { "blit_pass_vk.h", "capabilities_vk.cc", "capabilities_vk.h", + "graphics_queue_vk.h", + "graphics_queue_vk.cc", "command_buffer_vk.cc", "command_buffer_vk.h", "command_encoder_vk.cc", diff --git a/impeller/renderer/backend/vulkan/command_buffer_vk.cc b/impeller/renderer/backend/vulkan/command_buffer_vk.cc index c63dbec45dd9d..62e271f7b195a 100644 --- a/impeller/renderer/backend/vulkan/command_buffer_vk.cc +++ b/impeller/renderer/backend/vulkan/command_buffer_vk.cc @@ -7,6 +7,7 @@ #include #include +#include "fml/logging.h" #include "impeller/renderer/backend/vulkan/blit_pass_vk.h" #include "impeller/renderer/backend/vulkan/command_encoder_vk.h" #include "impeller/renderer/backend/vulkan/compute_pass_vk.h" @@ -49,16 +50,7 @@ const std::shared_ptr& CommandBufferVK::GetEncoder() { } bool CommandBufferVK::OnSubmitCommands(CompletionCallback callback) { - if (!encoder_) { - encoder_ = encoder_factory_->Create(); - } - if (!callback) { - return encoder_->Submit(); - } - return encoder_->Submit([callback](bool submitted) { - callback(submitted ? CommandBuffer::Status::kCompleted - : CommandBuffer::Status::kError); - }); + FML_UNREACHABLE() } void CommandBufferVK::OnWaitUntilScheduled() {} diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk.cc b/impeller/renderer/backend/vulkan/command_encoder_vk.cc index cd8dc86c0562b..3e809a8e28cc5 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk.cc +++ b/impeller/renderer/backend/vulkan/command_encoder_vk.cc @@ -81,29 +81,10 @@ bool CommandEncoderVK::IsValid() const { return is_valid_; } -bool CommandEncoderVK::Submit(SubmitCallback callback) { - // Make sure to call callback with `false` if anything returns early. - bool fail_callback = !!callback; - if (!IsValid()) { - VALIDATION_LOG << "Cannot submit invalid CommandEncoderVK."; - if (fail_callback) { - callback(false); - } - return false; - } - - // Success or failure, you only get to submit once. - fml::ScopedCleanupClosure reset([&]() { - if (fail_callback) { - callback(false); - } - Reset(); - }); - +bool CommandEncoderVK::EndCommandBuffer() const { InsertDebugMarker("QueueSubmit"); auto command_buffer = GetCommandBuffer(); - tracked_objects_->GetGPUProbe().RecordCmdBufferEnd(command_buffer); auto status = command_buffer.end(); @@ -111,39 +92,7 @@ bool CommandEncoderVK::Submit(SubmitCallback callback) { VALIDATION_LOG << "Failed to end command buffer: " << vk::to_string(status); return false; } - std::shared_ptr strong_device = device_holder_.lock(); - if (!strong_device) { - VALIDATION_LOG << "Device lost."; - return false; - } - auto [fence_result, fence] = strong_device->GetDevice().createFenceUnique({}); - if (fence_result != vk::Result::eSuccess) { - VALIDATION_LOG << "Failed to create fence: " << vk::to_string(fence_result); - return false; - } - - vk::SubmitInfo submit_info; - std::vector buffers = {command_buffer}; - submit_info.setCommandBuffers(buffers); - status = queue_->Submit(submit_info, *fence); - if (status != vk::Result::eSuccess) { - VALIDATION_LOG << "Failed to submit queue: " << vk::to_string(status); - return false; - } - - // Submit will proceed, call callback with true when it is done and do not - // call when `reset` is collected. - fail_callback = false; - return fence_waiter_->AddFence( - std::move(fence), - [callback, tracked_objects = std::move(tracked_objects_)]() mutable { - // Ensure tracked objects are destructed before calling any final - // callbacks. - tracked_objects.reset(); - if (callback) { - callback(true); - } - }); + return true; } vk::CommandBuffer CommandEncoderVK::GetCommandBuffer() const { diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk.h b/impeller/renderer/backend/vulkan/command_encoder_vk.h index f24e53c9b0572..16db003557928 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk.h +++ b/impeller/renderer/backend/vulkan/command_encoder_vk.h @@ -13,6 +13,7 @@ #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/descriptor_pool_vk.h" #include "impeller/renderer/backend/vulkan/device_holder.h" +#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/queue_vk.h" #include "impeller/renderer/backend/vulkan/shared_object_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" @@ -60,8 +61,6 @@ class CommandEncoderVK { bool IsValid() const; - bool Submit(SubmitCallback callback = {}); - bool Track(std::shared_ptr object); bool Track(std::shared_ptr buffer); @@ -82,12 +81,15 @@ class CommandEncoderVK { void InsertDebugMarker(std::string_view label) const; + bool EndCommandBuffer() const; + fml::StatusOr AllocateDescriptorSets( const vk::DescriptorSetLayout& layout, const ContextVK& context); private: friend class ContextVK; + friend class GraphicsQueueVK; std::weak_ptr device_holder_; std::shared_ptr tracked_objects_; diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index e573d6aa5bfb9..bdccf481385f6 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -5,6 +5,7 @@ #include "impeller/renderer/backend/vulkan/context_vk.h" #include "fml/concurrent_message_loop.h" +#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #ifdef FML_OS_ANDROID #include @@ -156,7 +157,7 @@ void ContextVK::Setup(Settings settings) { // 1. The user has explicitly enabled it. // 2. We are in a combination of debug mode, and running on Android. // (It's possible 2 is overly conservative and we can simplify this) - auto enable_validation = settings.enable_validation; + auto enable_validation = false; //settings.enable_validation; #if defined(FML_OS_ANDROID) && !defined(NDEBUG) enable_validation = true; @@ -445,6 +446,7 @@ void ContextVK::Setup(Settings settings) { command_pool_recycler_ = std::move(command_pool_recycler); descriptor_pool_recycler_ = std::move(descriptor_pool_recycler); device_name_ = std::string(physical_device_properties.deviceName); + graphics_queue_vk_ = std::make_shared(weak_from_this()); is_valid_ = true; // Create the GPU Tracer later because it depends on state from diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index ac059ebed237c..6f45750087408 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -13,6 +13,8 @@ #include "fml/thread.h" #include "impeller/base/backend_cast.h" #include "impeller/core/formats.h" +#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/vulkan/command_pool_vk.h" #include "impeller/renderer/backend/vulkan/device_holder.h" #include "impeller/renderer/backend/vulkan/pipeline_library_vk.h" @@ -35,6 +37,7 @@ class ResourceManagerVK; class SurfaceContextVK; class GPUTracerVK; class DescriptorPoolRecyclerVK; +class GraphicsQueueVK; class ContextVK final : public Context, public BackendCast, @@ -163,6 +166,10 @@ class ContextVK final : public Context, return descriptor_pool_recycler_; } + const std::shared_ptr& GetQueue() const override { + return graphics_queue_vk_; + } + std::shared_ptr GetGPUTracer() const; void RecordFrameEndTime() const; @@ -197,6 +204,7 @@ class ContextVK final : public Context, std::unique_ptr queue_submit_thread_; std::shared_ptr gpu_tracer_; std::shared_ptr descriptor_pool_recycler_; + std::shared_ptr graphics_queue_vk_; bool sync_presentation_ = false; const uint64_t hash_; diff --git a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc index 19733d6a256ab..56e2840a8b439 100644 --- a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc +++ b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc @@ -34,9 +34,9 @@ GPUTracerVK::GPUTracerVK(std::weak_ptr context) return; } // Disable tracing in release mode. -#ifdef IMPELLER_DEBUG - enabled_ = true; -#endif // IMPELLER_DEBUG +// #ifdef IMPELLER_DEBUG +// enabled_ = true; +// #endif // IMPELLER_DEBUG } void GPUTracerVK::InitializeQueryPool(const ContextVK& context) { @@ -61,7 +61,7 @@ void GPUTracerVK::InitializeQueryPool(const ContextVK& context) { buffer_vk.GetEncoder()->GetCommandBuffer().resetQueryPool( trace_states_[i].query_pool.get(), 0, kPoolSize); } - if (!buffer->SubmitCommands()) { + if (!context.GetQueue()->Submit({buffer}).ok()) { VALIDATION_LOG << "Failed to reset query pool for trace events."; enabled_ = false; } diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.cc b/impeller/renderer/backend/vulkan/graphics_queue_vk.cc new file mode 100644 index 0000000000000..ab7f1567f790f --- /dev/null +++ b/impeller/renderer/backend/vulkan/graphics_queue_vk.cc @@ -0,0 +1,84 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "fml/status.h" + +#include "impeller/base/validation.h" +#include "impeller/renderer/backend/vulkan/command_buffer_vk.h" +#include "impeller/renderer/backend/vulkan/command_encoder_vk.h" +#include "impeller/renderer/backend/vulkan/context_vk.h" +#include "impeller/renderer/backend/vulkan/fence_waiter_vk.h" +#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" +#include "impeller/renderer/backend/vulkan/tracked_objects_vk.h" + +namespace impeller { + +GraphicsQueueVK::GraphicsQueueVK(const std::weak_ptr& context) + : context_(context) {} + +fml::Status GraphicsQueueVK::Submit( + const std::vector>& buffers, + const CompletionCallback& callback) { + if (buffers.empty()) { + return fml::Status(fml::StatusCode::kInvalidArgument, + "No command buffers provided."); + } + + std::vector vk_buffers; + std::vector> tracked_objects; + vk_buffers.reserve(buffers.size()); + tracked_objects.reserve(buffers.size()); + for (const std::shared_ptr& buffer : buffers) { + auto encoder = CommandBufferVK::Cast(*buffer).GetEncoder(); + if (!encoder->EndCommandBuffer()) { + return fml::Status(fml::StatusCode::kCancelled, + "Failed to end command buffer."); + } + tracked_objects.push_back(encoder->tracked_objects_); + vk_buffers.push_back(encoder->GetCommandBuffer()); + encoder->Reset(); + } + + auto context = context_.lock(); + if (!context) { + VALIDATION_LOG << "Device lost."; + return fml::Status(fml::StatusCode::kCancelled, "Device lost."); + } + auto [fence_result, fence] = context->GetDevice().createFenceUnique({}); + if (fence_result != vk::Result::eSuccess) { + VALIDATION_LOG << "Failed to create fence: " << vk::to_string(fence_result); + return fml::Status(fml::StatusCode::kCancelled, "Failed to create fence."); + } + + vk::SubmitInfo submit_info; + submit_info.setCommandBuffers(vk_buffers); + auto status = context->GetGraphicsQueue()->Submit(submit_info, *fence); + if (status != vk::Result::eSuccess) { + VALIDATION_LOG << "Failed to submit queue: " << vk::to_string(status); + return fml::Status(fml::StatusCode::kCancelled, "Failed to submit queue: "); + } + + // Submit will proceed, call callback with true when it is done and do not + // call when `reset` is collected. + auto added_fence = context->GetFenceWaiter()->AddFence( + std::move(fence), + [callback, tracked_objects = std::move(tracked_objects)]() mutable { + // Ensure tracked objects are destructed before calling any final + // callbacks. + for (auto& tracked_object : tracked_objects) { + tracked_object.reset(); + } + if (callback) { + callback(CommandBuffer::Status::kCompleted); + } + }); + if (!added_fence) { + callback(CommandBuffer::Status::kError); + return fml::Status(fml::StatusCode::kCancelled, "Failed to add fence."); + } + + return fml::Status(); +} + +} // namespace impeller diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.h b/impeller/renderer/backend/vulkan/graphics_queue_vk.h new file mode 100644 index 0000000000000..1d3bb27770e59 --- /dev/null +++ b/impeller/renderer/backend/vulkan/graphics_queue_vk.h @@ -0,0 +1,29 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// 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_GRAPHICS_QUEUE_VK_H_ +#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_GRAPHICS_QUEUE_VK_H_ + +#include "impeller/renderer/graphics_queue.h" + +namespace impeller { + +class ContextVK; + +class GraphicsQueueVK : public GraphicsQueue { + public: + explicit GraphicsQueueVK(const std::weak_ptr& context); + + ~GraphicsQueueVK() override {} + + fml::Status Submit(const std::vector>& buffers, + const CompletionCallback& callback = {}) override; + + private: + std::weak_ptr context_; +}; + +} // namespace impeller + +#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_GRAPHICS_QUEUE_VK_H_ diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.cc b/impeller/renderer/backend/vulkan/surface_context_vk.cc index 646d8a8d15591..4fce2823c3e62 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.cc +++ b/impeller/renderer/backend/vulkan/surface_context_vk.cc @@ -48,6 +48,10 @@ std::shared_ptr SurfaceContextVK::CreateCommandBuffer() const { return parent_->CreateCommandBuffer(); } +const std::shared_ptr& SurfaceContextVK::GetQueue() const { + return parent_->GetQueue(); +} + const std::shared_ptr& SurfaceContextVK::GetCapabilities() const { return parent_->GetCapabilities(); diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.h b/impeller/renderer/backend/vulkan/surface_context_vk.h index cf849c576d051..a55ad76abfdd3 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.h +++ b/impeller/renderer/backend/vulkan/surface_context_vk.h @@ -8,6 +8,7 @@ #include #include "impeller/base/backend_cast.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/vulkan/vk.h" #include "impeller/renderer/context.h" @@ -62,6 +63,9 @@ class SurfaceContextVK : public Context, // |Context| const std::shared_ptr& GetCapabilities() const override; + // |Context| + const std::shared_ptr& GetQueue() const override; + // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc b/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc index bb3fa21e278c3..96958b60cadb5 100644 --- a/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc +++ b/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc @@ -7,7 +7,6 @@ #include "fml/synchronization/count_down_latch.h" #include "gtest/gtest.h" #include "impeller/renderer//backend/vulkan/command_encoder_vk.h" -#include "impeller/renderer/backend/vulkan/command_buffer_vk.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/gpu_tracer_vk.h" #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" @@ -29,8 +28,11 @@ TEST(GPUTracerVK, CanTraceCmdBuffer) { auto latch = std::make_shared(1u); - if (!cmd_buffer->SubmitCommands( - [latch](CommandBuffer::Status status) { latch->CountDown(); })) { + if (!context->GetQueue() + ->Submit( + {cmd_buffer}, + [latch](CommandBuffer::Status status) { latch->CountDown(); }) + .ok()) { GTEST_FAIL() << "Failed to submit cmd buffer"; } @@ -56,8 +58,11 @@ TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) { blit_pass->EncodeCommands(context->GetResourceAllocator()); auto latch = std::make_shared(1u); - if (!cmd_buffer->SubmitCommands( - [latch](CommandBuffer::Status status) { latch->CountDown(); })) { + if (!context->GetQueue() + ->Submit( + {cmd_buffer}, + [latch](CommandBuffer::Status status) { latch->CountDown(); }) + .ok()) { GTEST_FAIL() << "Failed to submit cmd buffer"; } @@ -85,8 +90,11 @@ TEST(GPUTracerVK, TracesWithPartialFrameOverlap) { tracer->MarkFrameEnd(); auto latch = std::make_shared(1u); - if (!cmd_buffer->SubmitCommands( - [latch](CommandBuffer::Status status) { latch->CountDown(); })) { + if (!context->GetQueue() + ->Submit( + {cmd_buffer}, + [latch](CommandBuffer::Status status) { latch->CountDown(); }) + .ok()) { GTEST_FAIL() << "Failed to submit cmd buffer"; } diff --git a/impeller/renderer/backend/vulkan/texture_vk.cc b/impeller/renderer/backend/vulkan/texture_vk.cc index 879e5afd317a4..bbf1618d871ef 100644 --- a/impeller/renderer/backend/vulkan/texture_vk.cc +++ b/impeller/renderer/backend/vulkan/texture_vk.cc @@ -125,7 +125,7 @@ bool TextureVK::OnSetContents(const uint8_t* contents, } } - return cmd_buffer->SubmitCommands(); + return context->GetQueue()->Submit({cmd_buffer}).ok(); } bool TextureVK::OnSetContents(std::shared_ptr mapping, diff --git a/impeller/renderer/command_buffer.cc b/impeller/renderer/command_buffer.cc index 7a675f560dbb6..5ff1113c100ec 100644 --- a/impeller/renderer/command_buffer.cc +++ b/impeller/renderer/command_buffer.cc @@ -34,31 +34,6 @@ void CommandBuffer::WaitUntilScheduled() { return OnWaitUntilScheduled(); } -bool CommandBuffer::EncodeAndSubmit( - const std::shared_ptr& render_pass) { - if (!render_pass->IsValid() || !IsValid()) { - return false; - } - if (!render_pass->EncodeCommands()) { - return false; - } - - return SubmitCommands(nullptr); -} - -bool CommandBuffer::EncodeAndSubmit( - const std::shared_ptr& blit_pass, - const std::shared_ptr& allocator) { - if (!blit_pass->IsValid() || !IsValid()) { - return false; - } - if (!blit_pass->EncodeCommands(allocator)) { - return false; - } - - return SubmitCommands(nullptr); -} - std::shared_ptr CommandBuffer::CreateRenderPass( const RenderTarget& render_target) { auto pass = OnCreateRenderPass(render_target); diff --git a/impeller/renderer/command_buffer.h b/impeller/renderer/command_buffer.h index bbc0288cb7cac..380623e57f235 100644 --- a/impeller/renderer/command_buffer.h +++ b/impeller/renderer/command_buffer.h @@ -8,7 +8,6 @@ #include #include -#include "flutter/fml/macros.h" #include "impeller/renderer/blit_pass.h" #include "impeller/renderer/compute_pass.h" @@ -18,6 +17,7 @@ class ComputePass; class Context; class RenderPass; class RenderTarget; +class GraphicsQueue; namespace testing { class CommandBufferMock; @@ -60,42 +60,6 @@ class CommandBuffer { virtual void SetLabel(const std::string& label) const = 0; - //---------------------------------------------------------------------------- - /// @brief Schedule the command encoded by render passes within this - /// command buffer on the GPU. The encoding of these commnands is - /// performed immediately on the calling thread. - /// - /// A command buffer may only be committed once. - /// - /// @param[in] callback The completion callback. - /// - [[nodiscard]] bool SubmitCommands(const CompletionCallback& callback); - - [[nodiscard]] bool SubmitCommands(); - - //---------------------------------------------------------------------------- - /// @brief Schedule the command encoded by render passes within this - /// command buffer on the GPU. The enqueing of this buffer is - /// performed immediately but encoding is pushed to a worker - /// thread if possible. - /// - /// A command buffer may only be committed once. - /// - [[nodiscard]] virtual bool EncodeAndSubmit( - const std::shared_ptr& render_pass); - - //---------------------------------------------------------------------------- - /// @brief Schedule the command encoded by blit passes within this - /// command buffer on the GPU. The enqueing of this buffer is - /// performed immediately but encoding is pushed to a worker - /// thread if possible. - /// - /// A command buffer may only be committed once. - /// - [[nodiscard]] virtual bool EncodeAndSubmit( - const std::shared_ptr& blit_pass, - const std::shared_ptr& allocator); - //---------------------------------------------------------------------------- /// @brief Force execution of pending GPU commands. /// @@ -143,6 +107,21 @@ class CommandBuffer { virtual std::shared_ptr OnCreateComputePass() = 0; private: + friend class GraphicsQueue; + + //---------------------------------------------------------------------------- + /// @brief Schedule the command encoded by render passes within this + /// command buffer on the GPU. The encoding of these commnands is + /// performed immediately on the calling thread. + /// + /// A command buffer may only be committed once. + /// + /// @param[in] callback The completion callback. + /// + [[nodiscard]] bool SubmitCommands(const CompletionCallback& callback); + + [[nodiscard]] bool SubmitCommands(); + CommandBuffer(const CommandBuffer&) = delete; CommandBuffer& operator=(const CommandBuffer&) = delete; diff --git a/impeller/renderer/compute_tessellator.cc b/impeller/renderer/compute_tessellator.cc index f700f3a9fbe02..4989d7b78510b 100644 --- a/impeller/renderer/compute_tessellator.cc +++ b/impeller/renderer/compute_tessellator.cc @@ -6,6 +6,7 @@ #include +#include "impeller/core/host_buffer.h" #include "impeller/renderer/command_buffer.h" #include "impeller/renderer/path_polyline.comp.h" #include "impeller/renderer/pipeline_library.h" @@ -170,7 +171,7 @@ ComputeTessellator::Status ComputeTessellator::Tessellate( return Status::kCommandInvalid; } - if (!cmd_buffer->SubmitCommands(callback)) { + if (!context->GetQueue()->Submit({cmd_buffer}).ok()) { return Status::kCommandInvalid; } diff --git a/impeller/renderer/compute_unittests.cc b/impeller/renderer/compute_unittests.cc index 8a3cb8769412b..5a2ea6a2ae967 100644 --- a/impeller/renderer/compute_unittests.cc +++ b/impeller/renderer/compute_unittests.cc @@ -75,27 +75,33 @@ TEST_P(ComputeTest, CanCreateComputePass) { ASSERT_TRUE(pass->EncodeCommands()); fml::AutoResetWaitableEvent latch; - ASSERT_TRUE(cmd_buffer->SubmitCommands([&latch, output_buffer, &input_0, - &input_1]( - CommandBuffer::Status status) { - EXPECT_EQ(status, CommandBuffer::Status::kCompleted); - - auto view = DeviceBuffer::AsBufferView(output_buffer); - EXPECT_EQ(view.range.length, sizeof(CS::Output)); - - CS::Output* output = - reinterpret_cast*>(output_buffer->OnGetContents()); - EXPECT_TRUE(output); - for (size_t i = 0; i < kCount; i++) { - Vector4 vector = output->elements[i]; - Vector4 computed = input_0.elements[i] * input_1.elements[i]; - EXPECT_EQ(vector, - Vector4(computed.x + 2 + input_1.some_struct.i, - computed.y + 3 + input_1.some_struct.vf.x, - computed.z + 5 + input_1.some_struct.vf.y, computed.w)); - } - latch.Signal(); - })); + ASSERT_TRUE( + context->GetQueue() + ->Submit( + {cmd_buffer}, + [&latch, output_buffer, &input_0, + &input_1](CommandBuffer::Status status) { + EXPECT_EQ(status, CommandBuffer::Status::kCompleted); + + auto view = DeviceBuffer::AsBufferView(output_buffer); + EXPECT_EQ(view.range.length, sizeof(CS::Output)); + + CS::Output* output = + reinterpret_cast*>( + output_buffer->OnGetContents()); + EXPECT_TRUE(output); + for (size_t i = 0; i < kCount; i++) { + Vector4 vector = output->elements[i]; + Vector4 computed = input_0.elements[i] * input_1.elements[i]; + EXPECT_EQ(vector, + Vector4(computed.x + 2 + input_1.some_struct.i, + computed.y + 3 + input_1.some_struct.vf.x, + computed.z + 5 + input_1.some_struct.vf.y, + computed.w)); + } + latch.Signal(); + }) + .ok()); latch.Wait(); } @@ -139,24 +145,29 @@ TEST_P(ComputeTest, CanComputePrefixSum) { ASSERT_TRUE(pass->EncodeCommands()); fml::AutoResetWaitableEvent latch; - ASSERT_TRUE(cmd_buffer->SubmitCommands([&latch, output_buffer]( - CommandBuffer::Status status) { - EXPECT_EQ(status, CommandBuffer::Status::kCompleted); - - auto view = DeviceBuffer::AsBufferView(output_buffer); - EXPECT_EQ(view.range.length, sizeof(CS::OutputData)); - - CS::OutputData* output = reinterpret_cast*>( - output_buffer->OnGetContents()); - EXPECT_TRUE(output); - - constexpr uint32_t expected[kCount] = {1, 3, 6, 10, 15}; - for (size_t i = 0; i < kCount; i++) { - auto computed_sum = output->data[i]; - EXPECT_EQ(computed_sum, expected[i]); - } - latch.Signal(); - })); + ASSERT_TRUE( + context->GetQueue() + ->Submit({cmd_buffer}, + [&latch, output_buffer](CommandBuffer::Status status) { + EXPECT_EQ(status, CommandBuffer::Status::kCompleted); + + auto view = DeviceBuffer::AsBufferView(output_buffer); + EXPECT_EQ(view.range.length, + sizeof(CS::OutputData)); + + CS::OutputData* output = + reinterpret_cast*>( + output_buffer->OnGetContents()); + EXPECT_TRUE(output); + + constexpr uint32_t expected[kCount] = {1, 3, 6, 10, 15}; + for (size_t i = 0; i < kCount; i++) { + auto computed_sum = output->data[i]; + EXPECT_EQ(computed_sum, expected[i]); + } + latch.Signal(); + }) + .ok()); latch.Wait(); } @@ -192,19 +203,24 @@ TEST_P(ComputeTest, 1DThreadgroupSizingIsCorrect) { ASSERT_TRUE(pass->EncodeCommands()); fml::AutoResetWaitableEvent latch; - ASSERT_TRUE(cmd_buffer->SubmitCommands([&latch, output_buffer]( - CommandBuffer::Status status) { - EXPECT_EQ(status, CommandBuffer::Status::kCompleted); - - auto view = DeviceBuffer::AsBufferView(output_buffer); - EXPECT_EQ(view.range.length, sizeof(CS::OutputData)); - - CS::OutputData* output = reinterpret_cast*>( - output_buffer->OnGetContents()); - EXPECT_TRUE(output); - EXPECT_EQ(output->data[kCount - 1], kCount - 1); - latch.Signal(); - })); + ASSERT_TRUE( + context->GetQueue() + ->Submit({cmd_buffer}, + [&latch, output_buffer](CommandBuffer::Status status) { + EXPECT_EQ(status, CommandBuffer::Status::kCompleted); + + auto view = DeviceBuffer::AsBufferView(output_buffer); + EXPECT_EQ(view.range.length, + sizeof(CS::OutputData)); + + CS::OutputData* output = + reinterpret_cast*>( + output_buffer->OnGetContents()); + EXPECT_TRUE(output); + EXPECT_EQ(output->data[kCount - 1], kCount - 1); + latch.Signal(); + }) + .ok()); latch.Wait(); } @@ -247,7 +263,7 @@ TEST_P(ComputeTest, CanComputePrefixSumLargeInteractive) { pass->Compute(ISize(kCount, 1)); pass->EncodeCommands(); host_buffer->Reset(); - return cmd_buffer->SubmitCommands(); + return context->GetQueue()->Submit({cmd_buffer}).ok(); }; ASSERT_TRUE(OpenPlaygroundHere(callback)); } @@ -322,27 +338,34 @@ TEST_P(ComputeTest, MultiStageInputAndOutput) { ASSERT_TRUE(pass->EncodeCommands()); fml::AutoResetWaitableEvent latch; - ASSERT_TRUE(cmd_buffer->SubmitCommands([&latch, &output_buffer_1, - &output_buffer_2]( - CommandBuffer::Status status) { - EXPECT_EQ(status, CommandBuffer::Status::kCompleted); - - CS1::Output* output_1 = reinterpret_cast*>( - output_buffer_1->OnGetContents()); - EXPECT_TRUE(output_1); - EXPECT_EQ(output_1->count, 10u); - EXPECT_THAT(output_1->elements, - ::testing::ElementsAre(0, 0, 2, 3, 4, 6, 6, 9, 8, 12)); - - CS2::Output* output_2 = reinterpret_cast*>( - output_buffer_2->OnGetContents()); - EXPECT_TRUE(output_2); - EXPECT_EQ(output_2->count, 10u); - EXPECT_THAT(output_2->elements, - ::testing::ElementsAre(0, 0, 4, 6, 8, 12, 12, 18, 16, 24)); - - latch.Signal(); - })); + ASSERT_TRUE( + context->GetQueue() + ->Submit({cmd_buffer}, + [&latch, &output_buffer_1, + &output_buffer_2](CommandBuffer::Status status) { + EXPECT_EQ(status, CommandBuffer::Status::kCompleted); + + CS1::Output* output_1 = + reinterpret_cast*>( + output_buffer_1->OnGetContents()); + EXPECT_TRUE(output_1); + EXPECT_EQ(output_1->count, 10u); + EXPECT_THAT( + output_1->elements, + ::testing::ElementsAre(0, 0, 2, 3, 4, 6, 6, 9, 8, 12)); + + CS2::Output* output_2 = + reinterpret_cast*>( + output_buffer_2->OnGetContents()); + EXPECT_TRUE(output_2); + EXPECT_EQ(output_2->count, 10u); + EXPECT_THAT(output_2->elements, + ::testing::ElementsAre(0, 0, 4, 6, 8, 12, 12, + 18, 16, 24)); + + latch.Signal(); + }) + .ok()); latch.Wait(); } @@ -395,27 +418,33 @@ TEST_P(ComputeTest, CanCompute1DimensionalData) { ASSERT_TRUE(pass->EncodeCommands()); fml::AutoResetWaitableEvent latch; - ASSERT_TRUE(cmd_buffer->SubmitCommands([&latch, output_buffer, &input_0, - &input_1]( - CommandBuffer::Status status) { - EXPECT_EQ(status, CommandBuffer::Status::kCompleted); - - auto view = DeviceBuffer::AsBufferView(output_buffer); - EXPECT_EQ(view.range.length, sizeof(CS::Output)); - - CS::Output* output = - reinterpret_cast*>(output_buffer->OnGetContents()); - EXPECT_TRUE(output); - for (size_t i = 0; i < kCount; i++) { - Vector4 vector = output->elements[i]; - Vector4 computed = input_0.elements[i] * input_1.elements[i]; - EXPECT_EQ(vector, - Vector4(computed.x + 2 + input_1.some_struct.i, - computed.y + 3 + input_1.some_struct.vf.x, - computed.z + 5 + input_1.some_struct.vf.y, computed.w)); - } - latch.Signal(); - })); + ASSERT_TRUE( + context->GetQueue() + ->Submit( + {cmd_buffer}, + [&latch, output_buffer, &input_0, + &input_1](CommandBuffer::Status status) { + EXPECT_EQ(status, CommandBuffer::Status::kCompleted); + + auto view = DeviceBuffer::AsBufferView(output_buffer); + EXPECT_EQ(view.range.length, sizeof(CS::Output)); + + CS::Output* output = + reinterpret_cast*>( + output_buffer->OnGetContents()); + EXPECT_TRUE(output); + for (size_t i = 0; i < kCount; i++) { + Vector4 vector = output->elements[i]; + Vector4 computed = input_0.elements[i] * input_1.elements[i]; + EXPECT_EQ(vector, + Vector4(computed.x + 2 + input_1.some_struct.i, + computed.y + 3 + input_1.some_struct.vf.x, + computed.z + 5 + input_1.some_struct.vf.y, + computed.w)); + } + latch.Signal(); + }) + .ok()); latch.Wait(); } diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h index 1f80c296e8fc4..681695bfb8c7a 100644 --- a/impeller/renderer/context.h +++ b/impeller/renderer/context.h @@ -11,9 +11,8 @@ #include "impeller/core/allocator.h" #include "impeller/core/capture.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/capabilities.h" -#include "impeller/renderer/pool.h" #include "impeller/renderer/sampler_library.h" namespace impeller { @@ -163,6 +162,9 @@ class Context { /// virtual std::shared_ptr CreateCommandBuffer() const = 0; + /// @brief Return the graphics queue for submitting command buffers. + virtual const std::shared_ptr& GetQueue() const = 0; + //---------------------------------------------------------------------------- /// @brief Force all pending asynchronous work to finish. This is /// achieved by deleting all owned concurrent message loops. diff --git a/impeller/renderer/graphics_queue.cc b/impeller/renderer/graphics_queue.cc new file mode 100644 index 0000000000000..5e4781fe41d77 --- /dev/null +++ b/impeller/renderer/graphics_queue.cc @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/renderer/graphics_queue.h" + +namespace impeller { + +fml::Status GraphicsQueue::Submit( + const std::vector>& buffers, + const CompletionCallback& cb) { + if (buffers.empty()) { + return fml::Status(fml::StatusCode::kInvalidArgument, + "No command buffers provided."); + } + for (const std::shared_ptr& buffer : buffers) { + if (!buffer->SubmitCommands(cb)) { + return fml::Status(fml::StatusCode::kCancelled, + "Failed to submit command buffer."); + } + } + return fml::Status(); +} + +} // namespace impeller diff --git a/impeller/renderer/graphics_queue.h b/impeller/renderer/graphics_queue.h new file mode 100644 index 0000000000000..7dbcd23417bcf --- /dev/null +++ b/impeller/renderer/graphics_queue.h @@ -0,0 +1,47 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef FLUTTER_IMPELLER_CORE_GRAPHICS_QUEUE_H_ +#define FLUTTER_IMPELLER_CORE_GRAPHICS_QUEUE_H_ + +#include + +#include "fml/status.h" +#include "impeller/renderer/command_buffer.h" + +namespace impeller { + +/// @brief An interface for submitting command buffers to the GPU for +/// encoding and execution. +class GraphicsQueue { + public: + using CompletionCallback = std::function; + + GraphicsQueue() = default; + + virtual ~GraphicsQueue() = default; + + /// @brief Submit one or more command buffer objects to be encoded and + /// executed on the GPU. + /// + /// The order of the provided buffers determines the ordering in which + /// they are submitted. + /// + /// Optionally accepts a ccallback that will fire with an updated + /// status based on encoding state. Only the Metal and Vulkan backend + /// can give a status beyond successful encoding. This callback may + /// be called more than once. + virtual fml::Status Submit( + const std::vector>& buffers, + const CompletionCallback& cb = {}); + + private: + GraphicsQueue(const GraphicsQueue&) = delete; + + GraphicsQueue& operator=(const GraphicsQueue&) = delete; +}; + +} // namespace impeller + +#endif // FLUTTER_IMPELLER_CORE_GRAPHICS_QUEUE_H_ diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index c1cc687096cc6..42b7ddd48f240 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -554,7 +554,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { pass->EncodeCommands(); } - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); @@ -639,10 +639,9 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { // Blit `bridge` to the top left corner of the texture. pass->AddCopy(bridge, device_buffer); - pass->EncodeCommands(context->GetResourceAllocator()); - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } } @@ -690,7 +689,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { pass->Draw().ok(); } pass->EncodeCommands(); - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } } @@ -812,7 +811,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) { pass->EncodeCommands(); } - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); @@ -1257,7 +1256,7 @@ TEST_P(RendererTest, StencilMask) { pass->EncodeCommands(); } - if (!buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); diff --git a/impeller/scene/scene.cc b/impeller/scene/scene.cc index 172e1c1e4a067..24564a2b4d2cd 100644 --- a/impeller/scene/scene.cc +++ b/impeller/scene/scene.cc @@ -53,7 +53,10 @@ bool Scene::Render(const RenderTarget& render_target, // TODO(bdero): Do post processing. - if (!command_buffer->SubmitCommands()) { + if (!scene_context_->GetContext() + ->GetQueue() + ->Submit({command_buffer}) + .ok()) { FML_LOG(ERROR) << "Failed to submit command buffer."; return false; } diff --git a/lib/gpu/command_buffer.cc b/lib/gpu/command_buffer.cc index f0dd7e0234092..c1e86c60e8ec0 100644 --- a/lib/gpu/command_buffer.cc +++ b/lib/gpu/command_buffer.cc @@ -17,8 +17,10 @@ namespace gpu { IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, CommandBuffer); CommandBuffer::CommandBuffer( + std::shared_ptr context, std::shared_ptr command_buffer) - : command_buffer_(std::move(command_buffer)) {} + : context_(std::move(context)), + command_buffer_(std::move(command_buffer)) {} CommandBuffer::~CommandBuffer() = default; @@ -35,7 +37,8 @@ bool CommandBuffer::Submit() { for (auto& encodable : encodables_) { encodable->EncodeCommands(); } - return command_buffer_->SubmitCommands(); + + return context_->GetQueue()->Submit({command_buffer_}).ok(); } bool CommandBuffer::Submit( @@ -43,7 +46,9 @@ bool CommandBuffer::Submit( for (auto& encodable : encodables_) { encodable->EncodeCommands(); } - return command_buffer_->SubmitCommands(completion_callback); + return context_->GetQueue() + ->Submit({command_buffer_}, completion_callback) + .ok(); } } // namespace gpu @@ -57,6 +62,7 @@ bool InternalFlutterGpu_CommandBuffer_Initialize( Dart_Handle wrapper, flutter::gpu::Context* contextWrapper) { auto res = fml::MakeRefCounted( + contextWrapper->GetContext(), contextWrapper->GetContext()->CreateCommandBuffer()); res->AssociateWithDartWrapper(wrapper); diff --git a/lib/gpu/command_buffer.h b/lib/gpu/command_buffer.h index 2125d75cc1c47..9194c3369e8f9 100644 --- a/lib/gpu/command_buffer.h +++ b/lib/gpu/command_buffer.h @@ -18,7 +18,8 @@ class CommandBuffer : public RefCountedDartWrappable { FML_FRIEND_MAKE_REF_COUNTED(CommandBuffer); public: - explicit CommandBuffer( + CommandBuffer( + std::shared_ptr context, std::shared_ptr command_buffer); std::shared_ptr GetCommandBuffer(); @@ -32,6 +33,7 @@ class CommandBuffer : public RefCountedDartWrappable { ~CommandBuffer() override; private: + std::shared_ptr context_; std::shared_ptr command_buffer_; std::vector> encodables_; diff --git a/lib/ui/painting/image_decoder_impeller.cc b/lib/ui/painting/image_decoder_impeller.cc index e577b7ac7357e..65947801eb85d 100644 --- a/lib/ui/painting/image_decoder_impeller.cc +++ b/lib/ui/painting/image_decoder_impeller.cc @@ -340,7 +340,7 @@ static std::pair, std::string> UnsafeUploadTextureToPrivate( } blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!command_buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({command_buffer}).ok()) { std::string decode_error("Failed to submit blit pass command buffer."); FML_DLOG(ERROR) << decode_error; return std::make_pair(nullptr, decode_error); @@ -459,7 +459,7 @@ ImageDecoderImpeller::UploadTextureToStorage( blit_pass->GenerateMipmap(texture); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!command_buffer->SubmitCommands()) { + if (!context->GetQueue()->Submit({command_buffer}).ok()) { decode_error = "Failed to submit blit pass command buffer."; return; } diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index 430dd9c48a450..a2744ddd99e6b 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -23,6 +23,7 @@ #include "flutter/testing/test_dart_native_resolver.h" #include "flutter/testing/test_gl_surface.h" #include "flutter/testing/testing.h" +#include "impeller/core/graphics_queue.h" #include "third_party/skia/include/codec/SkCodecAnimation.h" #include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkImage.h" @@ -35,6 +36,8 @@ namespace impeller { +static const std::shared_ptr kNullQueue = nullptr; + class TestImpellerContext : public impeller::Context { public: TestImpellerContext() = default; @@ -65,6 +68,10 @@ class TestImpellerContext : public impeller::Context { return nullptr; } + const std::shared_ptr& GetQueue() const override { + return kNullQueue; + } + std::shared_ptr CreateCommandBuffer() const override { command_buffer_count_ += 1; return nullptr; diff --git a/lib/ui/painting/image_encoding_impeller.cc b/lib/ui/painting/image_encoding_impeller.cc index a0b61da066ded..831cff6e7c280 100644 --- a/lib/ui/painting/image_encoding_impeller.cc +++ b/lib/ui/painting/image_encoding_impeller.cc @@ -178,7 +178,9 @@ void ImageEncodingImpeller::ConvertDlImageToSkImage( encode_task(sk_image); }; - if (!command_buffer->SubmitCommands(completion)) { + if (!impeller_context->GetQueue() + ->Submit({command_buffer}, completion) + .ok()) { FML_LOG(ERROR) << "Failed to submit commands."; } } diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index d9f3a9e8a1422..d469b2a2ad719 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -911,7 +911,9 @@ ScreenshotLayerTreeAsImageImpeller( sk_data = SkData::MakeWithCopy(buffer->OnGetContents(), buffer_desc.size); }; - if (!command_buffer->SubmitCommands(completion)) { + if (!impeller_context->GetQueue() + ->Submit({command_buffer}, completion) + .ok()) { FML_LOG(ERROR) << "Failed to submit commands."; } latch.Wait(); diff --git a/shell/platform/android/android_context_gl_unittests.cc b/shell/platform/android/android_context_gl_unittests.cc index 859a1d3100bb9..a6f7ceaba1f1e 100644 --- a/shell/platform/android/android_context_gl_unittests.cc +++ b/shell/platform/android/android_context_gl_unittests.cc @@ -74,6 +74,10 @@ class TestImpellerContext : public impeller::Context { FML_UNREACHABLE(); } + const std::shared_ptr& GetQueue() const override { + FML_UNREACHABLE(); + } + void Shutdown() override { did_shutdown = true; } bool did_shutdown = false; diff --git a/shell/platform/android/image_external_texture_vk.cc b/shell/platform/android/image_external_texture_vk.cc index 714b9929def27..77ad1ecb096b7 100644 --- a/shell/platform/android/image_external_texture_vk.cc +++ b/shell/platform/android/image_external_texture_vk.cc @@ -82,7 +82,7 @@ void ImageExternalTextureVK::ProcessFrame(PaintContext& context, if (!texture->SetLayout(barrier)) { return; } - if (!buffer->SubmitCommands()) { + if (!impeller_context_->GetQueue()->Submit({buffer}).ok()) { return; } } From f6f72f5fa41c61509908b8725a4a5ada27853bc7 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Sun, 28 Jan 2024 15:33:43 -0800 Subject: [PATCH 02/21] ++ --- impeller/aiks/testing/context_mock.h | 5 +++++ impeller/aiks/testing/context_spy.cc | 4 ++++ impeller/entity/contents/content_context.cc | 14 +++++++++++++- impeller/entity/contents/content_context.h | 19 +++++++++---------- .../contents/content_context_unittests.cc | 3 +++ impeller/entity/entity_pass.cc | 3 ++- impeller/entity/inline_pass_context.h | 2 +- impeller/renderer/BUILD.gn | 4 ++-- .../renderer/backend/gles/context_gles.cc | 7 +++++++ impeller/renderer/backend/gles/context_gles.h | 7 +++---- impeller/renderer/backend/metal/context_mtl.h | 5 +++++ .../renderer/backend/metal/context_mtl.mm | 7 +++++++ impeller/renderer/backend/vulkan/BUILD.gn | 4 ++-- .../vulkan/command_encoder_vk_unittests.cc | 8 ++++---- .../renderer/backend/vulkan/context_vk.cc | 2 +- impeller/renderer/backend/vulkan/context_vk.h | 4 ++-- .../renderer/backend/vulkan/gpu_tracer_vk.cc | 8 ++++---- .../backend/vulkan/graphics_queue_vk.cc | 11 +++++++++-- .../backend/vulkan/graphics_queue_vk.h | 4 ++-- .../backend/vulkan/surface_context_vk.h | 2 +- impeller/renderer/context.h | 2 +- impeller/renderer/graphics_queue.h | 6 +++--- impeller/renderer/testing/mocks.h | 5 +++++ lib/gpu/command_buffer.h | 5 ++--- lib/ui/painting/image_decoder_unittests.cc | 1 - 25 files changed, 97 insertions(+), 45 deletions(-) diff --git a/impeller/aiks/testing/context_mock.h b/impeller/aiks/testing/context_mock.h index b2d9138503fbb..54fa464d0ba04 100644 --- a/impeller/aiks/testing/context_mock.h +++ b/impeller/aiks/testing/context_mock.h @@ -111,6 +111,11 @@ class ContextMock : public Context { (), (const, override)); + MOCK_METHOD(const std::shared_ptr&, + GetQueue, + (), + (const override)); + MOCK_METHOD(void, Shutdown, (), (override)); }; diff --git a/impeller/aiks/testing/context_spy.cc b/impeller/aiks/testing/context_spy.cc index 460013cc2808a..1a85ff93c1357 100644 --- a/impeller/aiks/testing/context_spy.cc +++ b/impeller/aiks/testing/context_spy.cc @@ -50,6 +50,10 @@ std::shared_ptr ContextSpy::MakeContext( return real_context->GetPipelineLibrary(); }); + ON_CALL(*mock_context, GetQueue).WillByDefault([real_context]() { + return real_context->GetQueue(); + }); + ON_CALL(*mock_context, CreateCommandBuffer) .WillByDefault([real_context, shared_this]() { auto real_buffer = real_context->CreateCommandBuffer(); diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index e47daa59d0a69..148df90649ec9 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -200,7 +200,8 @@ ContentContext::ContentContext( ? std::make_shared( context_->GetResourceAllocator()) : std::move(render_target_allocator)), - host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) { + host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())), + pending_command_buffers_(std::make_unique()) { if (!context_ || !context_->IsValid()) { return; } @@ -533,4 +534,15 @@ void ContentContext::ClearCachedRuntimeEffectPipeline( } } +void ContentContext::RecordCommandBuffer( + std::shared_ptr command_buffer) const { + pending_command_buffers_->command_buffers.push_back( + std::move(command_buffer)); +} + +void ContentContext::FlushCommandBuffers() const { + auto buffers = std::move(pending_command_buffers_->command_buffers); + GetContext()->GetQueue()->Submit(buffers); +} + } // namespace impeller diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index cc3dfbd1c1253..7b43e469a76f7 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -269,6 +269,12 @@ using TiledTextureExternalPipeline = TiledTextureFillExternalFragmentShader>; #endif // IMPELLER_ENABLE_OPENGLES +// A struct used to isolate command buffer storage from the content +// context options to preserve const-ness. +struct PendingCommandBuffers { + std::vector> command_buffers; +}; + /// Pipeline state configuration. /// /// Each unique combination of these options requires a different pipeline state @@ -716,15 +722,9 @@ class ContentContext { void SetWireframe(bool wireframe); - void RecordCommandBuffer( - std::shared_ptr command_buffer) const { - command_buffers_.push_back(std::move(command_buffer)); - } + void RecordCommandBuffer(std::shared_ptr command_buffer) const; - void FlushCommandBuffers() const { - GetContext()->GetQueue()->Submit(command_buffers_); - command_buffers_.clear(); - } + void FlushCommandBuffers() const; using SubpassCallback = std::function; @@ -1016,8 +1016,7 @@ class ContentContext { #endif // IMPELLER_ENABLE_3D std::shared_ptr render_target_cache_; std::shared_ptr host_buffer_; - // TODO - mutable std::vector> command_buffers_; + std::unique_ptr pending_command_buffers_; bool wireframe_ = false; ContentContext(const ContentContext&) = delete; diff --git a/impeller/entity/contents/content_context_unittests.cc b/impeller/entity/contents/content_context_unittests.cc index 38d17c181843d..65d5e8f9f7d2d 100644 --- a/impeller/entity/contents/content_context_unittests.cc +++ b/impeller/entity/contents/content_context_unittests.cc @@ -4,6 +4,7 @@ #include +#include "fml/logging.h" #include "gtest/gtest.h" #include "impeller/core/allocator.h" @@ -11,6 +12,7 @@ #include "impeller/entity/contents/content_context.h" #include "impeller/geometry/color.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/pipeline.h" #include "impeller/renderer/pipeline_descriptor.h" @@ -52,6 +54,7 @@ class FakeContext : public Context { std::shared_ptr GetPipelineLibrary() const { return nullptr; } + const std::shared_ptr& GetQueue() const { FML_UNREACHABLE(); } std::shared_ptr CreateCommandBuffer() const { return nullptr; } void Shutdown() {} diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index 3d2471a21fc9b..94c4cf5061a27 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -387,7 +387,8 @@ bool EntityPass::Render(ContentContext& renderer, blit_pass->AddCopy( offscreen_target.GetRenderTarget().GetRenderTargetTexture(), root_render_target.GetRenderTargetTexture()); - if (!blit_pass->EncodeCommands(renderer.GetContext()->GetResourceAllocator())) { + if (!blit_pass->EncodeCommands( + renderer.GetContext()->GetResourceAllocator())) { VALIDATION_LOG << "Failed to encode root pass blit command."; return false; } diff --git a/impeller/entity/inline_pass_context.h b/impeller/entity/inline_pass_context.h index 62e8952d7ed68..43ee0f6b98f44 100644 --- a/impeller/entity/inline_pass_context.h +++ b/impeller/entity/inline_pass_context.h @@ -45,7 +45,7 @@ class InlinePassContext { RenderPassResult GetRenderPass(uint32_t pass_depth); private: - const ContentContext& renderer_; + const ContentContext& renderer_; EntityPassTarget& pass_target_; std::shared_ptr command_buffer_; std::shared_ptr pass_; diff --git a/impeller/renderer/BUILD.gn b/impeller/renderer/BUILD.gn index b1fc85cf67830..4d361a964818f 100644 --- a/impeller/renderer/BUILD.gn +++ b/impeller/renderer/BUILD.gn @@ -55,8 +55,6 @@ impeller_component("renderer") { "command.h", "command_buffer.cc", "command_buffer.h", - "graphics_queue.h", - "graphics_queue.cc", "compute_pass.cc", "compute_pass.h", "compute_pipeline_builder.cc", @@ -65,6 +63,8 @@ impeller_component("renderer") { "compute_pipeline_descriptor.h", "context.cc", "context.h", + "graphics_queue.cc", + "graphics_queue.h", "pipeline.cc", "pipeline.h", "pipeline_builder.cc", diff --git a/impeller/renderer/backend/gles/context_gles.cc b/impeller/renderer/backend/gles/context_gles.cc index 779255dffa6c4..0647fa6055229 100644 --- a/impeller/renderer/backend/gles/context_gles.cc +++ b/impeller/renderer/backend/gles/context_gles.cc @@ -9,6 +9,7 @@ #include "impeller/base/validation.h" #include "impeller/renderer/backend/gles/command_buffer_gles.h" #include "impeller/renderer/backend/gles/gpu_tracer_gles.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -67,6 +68,7 @@ ContextGLES::ContextGLES( } gpu_tracer_ = std::make_shared(GetReactor()->GetProcTable(), enable_gpu_tracing); + graphics_queue_ = std::make_shared(); is_valid_ = true; } @@ -138,4 +140,9 @@ const std::shared_ptr& ContextGLES::GetCapabilities() return device_capabilities_; } +// |Context| +const std::shared_ptr& ContextGLES::GetQueue() const { + return graphics_queue_; +} + } // namespace impeller diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index 1e1521677aa5c..ef8fbc0c5dee1 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -7,7 +7,6 @@ #include "fml/logging.h" #include "impeller/base/backend_cast.h" -#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/gles/allocator_gles.h" #include "impeller/renderer/backend/gles/capabilities_gles.h" #include "impeller/renderer/backend/gles/gpu_tracer_gles.h" @@ -17,6 +16,7 @@ #include "impeller/renderer/backend/gles/shader_library_gles.h" #include "impeller/renderer/capabilities.h" #include "impeller/renderer/context.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -50,6 +50,7 @@ class ContextGLES final : public Context, std::shared_ptr pipeline_library_; std::shared_ptr sampler_library_; std::shared_ptr resource_allocator_; + std::shared_ptr graphics_queue_; std::shared_ptr gpu_tracer_; // Note: This is stored separately from the ProcTableGLES CapabilitiesGLES @@ -87,9 +88,7 @@ class ContextGLES final : public Context, // |Context| const std::shared_ptr& GetCapabilities() const override; - const std::shared_ptr& GetQueue() const override { - FML_UNREACHABLE(); - } + const std::shared_ptr& GetQueue() const override; // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/metal/context_mtl.h b/impeller/renderer/backend/metal/context_mtl.h index f0735a3219b75..ff90b1b210461 100644 --- a/impeller/renderer/backend/metal/context_mtl.h +++ b/impeller/renderer/backend/metal/context_mtl.h @@ -22,6 +22,7 @@ #include "impeller/renderer/backend/metal/shader_library_mtl.h" #include "impeller/renderer/capabilities.h" #include "impeller/renderer/context.h" +#include "impeller/renderer/graphics_queue.h" #if TARGET_OS_SIMULATOR #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(13.0)) @@ -80,6 +81,9 @@ class ContextMTL final : public Context, // |Context| std::shared_ptr CreateCommandBuffer() const override; + // |Context| + const std::shared_ptr& GetQueue() const override; + // |Context| const std::shared_ptr& GetCapabilities() const override; @@ -126,6 +130,7 @@ class ContextMTL final : public Context, #endif // IMPELLER_DEBUG std::deque> tasks_awaiting_gpu_; std::unique_ptr sync_switch_observer_; + std::shared_ptr graphics_queue_; bool is_valid_ = false; ContextMTL( diff --git a/impeller/renderer/backend/metal/context_mtl.mm b/impeller/renderer/backend/metal/context_mtl.mm index 9c2342d3027fd..cea008b2b9499 100644 --- a/impeller/renderer/backend/metal/context_mtl.mm +++ b/impeller/renderer/backend/metal/context_mtl.mm @@ -16,6 +16,7 @@ #include "impeller/renderer/backend/metal/gpu_tracer_mtl.h" #include "impeller/renderer/backend/metal/sampler_library_mtl.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -128,6 +129,7 @@ static bool DeviceSupportsComputeSubgroups(id device) { device_capabilities_ = InferMetalCapabilities(device_, PixelFormat::kB8G8R8A8UNormInt); + graphics_queue_ = std::make_shared(); #ifdef IMPELLER_DEBUG gpu_tracer_ = std::make_shared(); #endif // IMPELLER_DEBUG @@ -394,4 +396,9 @@ new ContextMTL(device, command_queue, } } +// |Context| +const std::shared_ptr& ContextMTL::GetQueue() const { + return graphics_queue_; +} + } // namespace impeller diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index c0e3fa3182ea4..96e19add8e780 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -40,8 +40,6 @@ impeller_component("vulkan") { "blit_pass_vk.h", "capabilities_vk.cc", "capabilities_vk.h", - "graphics_queue_vk.h", - "graphics_queue_vk.cc", "command_buffer_vk.cc", "command_buffer_vk.h", "command_encoder_vk.cc", @@ -66,6 +64,8 @@ impeller_component("vulkan") { "formats_vk.h", "gpu_tracer_vk.cc", "gpu_tracer_vk.h", + "graphics_queue_vk.cc", + "graphics_queue_vk.h", "limits_vk.h", "pipeline_cache_vk.cc", "pipeline_cache_vk.h", diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc b/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc index 3f17a6e99c1ac..fe488bdd47a6b 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc +++ b/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc @@ -8,6 +8,7 @@ #include "fml/synchronization/waitable_event.h" #include "impeller/renderer/backend/vulkan/command_encoder_vk.h" #include "impeller/renderer/backend/vulkan/test/mock_vulkan.h" +#include "impeller/renderer/command_buffer.h" namespace impeller { namespace testing { @@ -48,10 +49,9 @@ TEST(CommandEncoderVKTest, CleanupAfterSubmit) { fml::AutoResetWaitableEvent wait_for_thread_join; auto context = MockVulkanContextBuilder().Build(); std::thread thread([&] { - CommandEncoderFactoryVK factory(context); - std::shared_ptr encoder = factory.Create(); - encoder->Submit([&](bool success) { - ASSERT_TRUE(success); + auto buffer = context->CreateCommandBuffer(); + context->GetQueue()->Submit({buffer}, [&](CommandBuffer::Status status) { + ASSERT_EQ(status, CommandBuffer::Status::kCompleted); wait_for_thread_join.Wait(); wait_for_submit.Signal(); }); diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index bdccf481385f6..0d82c53a12c53 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -157,7 +157,7 @@ void ContextVK::Setup(Settings settings) { // 1. The user has explicitly enabled it. // 2. We are in a combination of debug mode, and running on Android. // (It's possible 2 is overly conservative and we can simplify this) - auto enable_validation = false; //settings.enable_validation; + auto enable_validation = settings.enable_validation; #if defined(FML_OS_ANDROID) && !defined(NDEBUG) enable_validation = true; diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index 6f45750087408..b024fdc43592e 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -13,16 +13,16 @@ #include "fml/thread.h" #include "impeller/base/backend_cast.h" #include "impeller/core/formats.h" -#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" -#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/vulkan/command_pool_vk.h" #include "impeller/renderer/backend/vulkan/device_holder.h" +#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/pipeline_library_vk.h" #include "impeller/renderer/backend/vulkan/queue_vk.h" #include "impeller/renderer/backend/vulkan/sampler_library_vk.h" #include "impeller/renderer/backend/vulkan/shader_library_vk.h" #include "impeller/renderer/capabilities.h" #include "impeller/renderer/context.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { diff --git a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc index 56e2840a8b439..fa3ddd8b95ef2 100644 --- a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc +++ b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc @@ -33,10 +33,10 @@ GPUTracerVK::GPUTracerVK(std::weak_ptr context) // The device does not support timestamp queries. return; } - // Disable tracing in release mode. -// #ifdef IMPELLER_DEBUG -// enabled_ = true; -// #endif // IMPELLER_DEBUG +// Disable tracing in release mode. +#ifdef IMPELLER_DEBUG + enabled_ = true; +#endif // IMPELLER_DEBUG } void GPUTracerVK::InitializeQueryPool(const ContextVK& context) { diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.cc b/impeller/renderer/backend/vulkan/graphics_queue_vk.cc index ab7f1567f790f..4b8bd09359049 100644 --- a/impeller/renderer/backend/vulkan/graphics_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/graphics_queue_vk.cc @@ -11,6 +11,7 @@ #include "impeller/renderer/backend/vulkan/fence_waiter_vk.h" #include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/tracked_objects_vk.h" +#include "impeller/renderer/command_buffer.h" namespace impeller { @@ -24,6 +25,13 @@ fml::Status GraphicsQueueVK::Submit( return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided."); } + bool fail_callback = !!callback; + // Success or failure, you only get to submit once. + fml::ScopedCleanupClosure reset([&]() { + if (fail_callback) { + callback(CommandBuffer::Status::kError); + } + }); std::vector vk_buffers; std::vector> tracked_objects; @@ -74,10 +82,9 @@ fml::Status GraphicsQueueVK::Submit( } }); if (!added_fence) { - callback(CommandBuffer::Status::kError); return fml::Status(fml::StatusCode::kCancelled, "Failed to add fence."); } - + fail_callback = false; return fml::Status(); } diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.h b/impeller/renderer/backend/vulkan/graphics_queue_vk.h index 1d3bb27770e59..eb8e8b32fccd6 100644 --- a/impeller/renderer/backend/vulkan/graphics_queue_vk.h +++ b/impeller/renderer/backend/vulkan/graphics_queue_vk.h @@ -20,8 +20,8 @@ class GraphicsQueueVK : public GraphicsQueue { fml::Status Submit(const std::vector>& buffers, const CompletionCallback& callback = {}) override; - private: - std::weak_ptr context_; + private: + std::weak_ptr context_; }; } // namespace impeller diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.h b/impeller/renderer/backend/vulkan/surface_context_vk.h index a55ad76abfdd3..f248e6f60ad27 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.h +++ b/impeller/renderer/backend/vulkan/surface_context_vk.h @@ -8,9 +8,9 @@ #include #include "impeller/base/backend_cast.h" -#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/backend/vulkan/vk.h" #include "impeller/renderer/context.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h index 681695bfb8c7a..a787ca91e3400 100644 --- a/impeller/renderer/context.h +++ b/impeller/renderer/context.h @@ -11,8 +11,8 @@ #include "impeller/core/allocator.h" #include "impeller/core/capture.h" #include "impeller/core/formats.h" -#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/sampler_library.h" namespace impeller { diff --git a/impeller/renderer/graphics_queue.h b/impeller/renderer/graphics_queue.h index 7dbcd23417bcf..242d9e1d80f51 100644 --- a/impeller/renderer/graphics_queue.h +++ b/impeller/renderer/graphics_queue.h @@ -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_CORE_GRAPHICS_QUEUE_H_ -#define FLUTTER_IMPELLER_CORE_GRAPHICS_QUEUE_H_ +#ifndef FLUTTER_IMPELLER_RENDERER_GRAPHICS_QUEUE_H_ +#define FLUTTER_IMPELLER_RENDERER_GRAPHICS_QUEUE_H_ #include @@ -44,4 +44,4 @@ class GraphicsQueue { } // namespace impeller -#endif // FLUTTER_IMPELLER_CORE_GRAPHICS_QUEUE_H_ +#endif // FLUTTER_IMPELLER_RENDERER_GRAPHICS_QUEUE_H_ diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 7e7ac5dbe2577..09464d96174ee 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -164,6 +164,11 @@ class MockImpellerContext : public Context { GetCapabilities, (), (const, override)); + + MOCK_METHOD(const std::shared_ptr&, + GetQueue, + (), + (const, override)); }; class MockTexture : public Texture { diff --git a/lib/gpu/command_buffer.h b/lib/gpu/command_buffer.h index 9194c3369e8f9..7e4e3c01985e1 100644 --- a/lib/gpu/command_buffer.h +++ b/lib/gpu/command_buffer.h @@ -18,9 +18,8 @@ class CommandBuffer : public RefCountedDartWrappable { FML_FRIEND_MAKE_REF_COUNTED(CommandBuffer); public: - CommandBuffer( - std::shared_ptr context, - std::shared_ptr command_buffer); + CommandBuffer(std::shared_ptr context, + std::shared_ptr command_buffer); std::shared_ptr GetCommandBuffer(); diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index a2744ddd99e6b..f795b6cbbe7d7 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -23,7 +23,6 @@ #include "flutter/testing/test_dart_native_resolver.h" #include "flutter/testing/test_gl_surface.h" #include "flutter/testing/testing.h" -#include "impeller/core/graphics_queue.h" #include "third_party/skia/include/codec/SkCodecAnimation.h" #include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkImage.h" From 2ac8d59b66780e4ee63562b788a2d9cc75cd728d Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 10:08:43 -0800 Subject: [PATCH 03/21] mock and license fixes. --- ci/licenses_golden/licenses_flutter | 8 ++++++++ impeller/renderer/testing/mocks.h | 10 ++++++++++ lib/ui/painting/image_encoding_unittests.cc | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 0404f6572fb3c..304ebf280c561 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -5464,6 +5464,8 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc + ../../ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_library_vk.cc + ../../../flutter/LICENSE @@ -5527,6 +5529,8 @@ ORIGIN: ../../../flutter/impeller/renderer/compute_tessellator.cc + ../../../flu ORIGIN: ../../../flutter/impeller/renderer/compute_tessellator.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/context.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/context.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/graphics_queue.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/graphics_queue.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/path_polyline.comp + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/pipeline.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/pipeline.h + ../../../flutter/LICENSE @@ -8309,6 +8313,8 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.h +FILE: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.cc +FILE: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/limits_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h @@ -8373,6 +8379,8 @@ FILE: ../../../flutter/impeller/renderer/compute_tessellator.cc FILE: ../../../flutter/impeller/renderer/compute_tessellator.h FILE: ../../../flutter/impeller/renderer/context.cc FILE: ../../../flutter/impeller/renderer/context.h +FILE: ../../../flutter/impeller/renderer/graphics_queue.cc +FILE: ../../../flutter/impeller/renderer/graphics_queue.h FILE: ../../../flutter/impeller/renderer/path_polyline.comp FILE: ../../../flutter/impeller/renderer/pipeline.cc FILE: ../../../flutter/impeller/renderer/pipeline.h diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 09464d96174ee..73ce75d52d42b 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -11,6 +11,7 @@ #include "impeller/core/texture.h" #include "impeller/renderer/command_buffer.h" #include "impeller/renderer/context.h" +#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/render_target.h" #include "impeller/renderer/sampler_library.h" @@ -205,6 +206,15 @@ class MockCapabilities : public Capabilities { MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override)); }; +class MockGraphicsQueue : public GraphicsQueue { + public: + MOCK_METHOD(fml::Status, + Submit, + (const std::vector>& buffers, + const CompletionCallback& cb), + (override)); +}; + class MockSamplerLibrary : public SamplerLibrary { public: MOCK_METHOD(const std::unique_ptr&, diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index 8de593ce4bb73..2a961f27082ae 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -194,10 +194,12 @@ using ::impeller::testing::MockAllocator; using ::impeller::testing::MockBlitPass; using ::impeller::testing::MockCommandBuffer; using ::impeller::testing::MockDeviceBuffer; +using ::impeller::testing::MockGraphicsQueue; using ::impeller::testing::MockImpellerContext; using ::impeller::testing::MockTexture; using ::testing::_; using ::testing::DoAll; +using ::testing::Invoke; using ::testing::InvokeArgument; using ::testing::Return; @@ -208,6 +210,7 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( auto command_buffer = std::make_shared(context); auto allocator = std::make_shared(); auto blit_pass = std::make_shared(); + auto graphics_queue = std::make_shared(); impeller::DeviceBufferDescriptor device_buffer_desc; device_buffer_desc.size = buffer.size(); auto device_buffer = std::make_shared(device_buffer_desc); @@ -222,6 +225,13 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( EXPECT_CALL(*context, GetResourceAllocator).WillRepeatedly(Return(allocator)); EXPECT_CALL(*context, CreateCommandBuffer).WillOnce(Return(command_buffer)); EXPECT_CALL(*device_buffer, OnGetContents).WillOnce(Return(buffer.data())); + EXPECT_CALL(*context, GetQueue).WillRepeatedly(Invoke([graphics_queue]() { + return graphics_queue; + })); + EXPECT_CALL(*graphics_queue, Submit(_, _)) + .WillOnce( + DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), + Return(fml::Status()))); return context; } } // namespace From 7ff7cab7ad18e860c60574b0fb32fad93f6a8dcb Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 10:19:18 -0800 Subject: [PATCH 04/21] add missing include. --- impeller/renderer/testing/mocks.h | 1 + 1 file changed, 1 insertion(+) diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 73ce75d52d42b..53edd47641cf3 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -15,6 +15,7 @@ #include "impeller/renderer/render_pass.h" #include "impeller/renderer/render_target.h" #include "impeller/renderer/sampler_library.h" +#include "impeller/renderer/graphics_queue.h" namespace impeller { namespace testing { From 0a92952ffeafdb6b357795550d0b5369c68abe6e Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 10:23:55 -0800 Subject: [PATCH 05/21] ++ --- impeller/renderer/testing/mocks.h | 1 - 1 file changed, 1 deletion(-) diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 53edd47641cf3..73ce75d52d42b 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -15,7 +15,6 @@ #include "impeller/renderer/render_pass.h" #include "impeller/renderer/render_target.h" #include "impeller/renderer/sampler_library.h" -#include "impeller/renderer/graphics_queue.h" namespace impeller { namespace testing { From aae4d11a21e87a904bc88c0e6b852e29ab6d6193 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 10:25:16 -0800 Subject: [PATCH 06/21] Add dtor. --- impeller/renderer/testing/mocks.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 73ce75d52d42b..610e8adf00382 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -208,6 +208,8 @@ class MockCapabilities : public Capabilities { class MockGraphicsQueue : public GraphicsQueue { public: + ~MockGraphicsQueue() override = default; + MOCK_METHOD(fml::Status, Submit, (const std::vector>& buffers, From 1eac5895fbaaf8c50072db1f522bc6801eb6d898 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 12:12:34 -0800 Subject: [PATCH 07/21] rename to command queue. --- impeller/aiks/aiks_unittests.cc | 2 +- impeller/aiks/testing/context_mock.h | 4 +-- impeller/aiks/testing/context_spy.cc | 4 +-- impeller/entity/contents/content_context.cc | 2 +- .../contents/content_context_unittests.cc | 6 ++-- impeller/golden_tests/vulkan_screenshotter.mm | 2 +- impeller/playground/playground.cc | 6 ++-- impeller/renderer/BUILD.gn | 4 +-- .../renderer/backend/gles/context_gles.cc | 8 ++--- impeller/renderer/backend/gles/context_gles.h | 7 ++-- impeller/renderer/backend/metal/context_mtl.h | 6 ++-- .../renderer/backend/metal/context_mtl.mm | 7 ++-- .../renderer/backend/metal/surface_mtl.mm | 2 +- impeller/renderer/backend/vulkan/BUILD.gn | 4 +-- .../backend/vulkan/command_encoder_vk.h | 4 +-- .../vulkan/command_encoder_vk_unittests.cc | 11 ++++--- ...aphics_queue_vk.cc => command_queue_vk.cc} | 11 +++---- .../backend/vulkan/command_queue_vk.h | 33 +++++++++++++++++++ .../renderer/backend/vulkan/context_vk.cc | 9 +++-- impeller/renderer/backend/vulkan/context_vk.h | 11 +++---- .../renderer/backend/vulkan/gpu_tracer_vk.cc | 2 +- .../backend/vulkan/graphics_queue_vk.h | 29 ---------------- .../backend/vulkan/surface_context_vk.cc | 4 +-- .../backend/vulkan/surface_context_vk.h | 4 +-- .../vulkan/test/gpu_tracer_unittests.cc | 6 ++-- .../renderer/backend/vulkan/texture_vk.cc | 2 +- impeller/renderer/command_buffer.h | 4 +-- .../{graphics_queue.cc => command_queue.cc} | 4 +-- .../{graphics_queue.h => command_queue.h} | 16 ++++----- impeller/renderer/compute_tessellator.cc | 2 +- impeller/renderer/compute_unittests.cc | 12 +++---- impeller/renderer/context.h | 4 +-- impeller/renderer/renderer_unittests.cc | 10 +++--- impeller/renderer/testing/mocks.h | 10 +++--- impeller/scene/scene.cc | 2 +- lib/gpu/command_buffer.cc | 4 +-- lib/ui/painting/image_decoder_impeller.cc | 4 +-- lib/ui/painting/image_encoding_impeller.cc | 2 +- lib/ui/painting/image_encoding_unittests.cc | 11 +++---- shell/common/rasterizer.cc | 2 +- 40 files changed, 141 insertions(+), 136 deletions(-) rename impeller/renderer/backend/vulkan/{graphics_queue_vk.cc => command_queue_vk.cc} (92%) create mode 100644 impeller/renderer/backend/vulkan/command_queue_vk.h delete mode 100644 impeller/renderer/backend/vulkan/graphics_queue_vk.h rename impeller/renderer/{graphics_queue.cc => command_queue.cc} (89%) rename impeller/renderer/{graphics_queue.h => command_queue.h} (76%) diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index e66833f185272..eab7a51b68b44 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -153,7 +153,7 @@ bool GenerateMipmap(const std::shared_ptr& context, pass->GenerateMipmap(std::move(texture), std::move(label)); pass->EncodeCommands(context->GetResourceAllocator()); - return context->GetQueue()->Submit({buffer}).ok(); + return context->GetCommandQueue()->Submit({buffer}).ok(); } void CanRenderTiledTexture(AiksTest* aiks_test, diff --git a/impeller/aiks/testing/context_mock.h b/impeller/aiks/testing/context_mock.h index 54fa464d0ba04..1250bef0ec3bc 100644 --- a/impeller/aiks/testing/context_mock.h +++ b/impeller/aiks/testing/context_mock.h @@ -111,8 +111,8 @@ class ContextMock : public Context { (), (const, override)); - MOCK_METHOD(const std::shared_ptr&, - GetQueue, + MOCK_METHOD(const std::shared_ptr&, + GetCommandQueue, (), (const override)); diff --git a/impeller/aiks/testing/context_spy.cc b/impeller/aiks/testing/context_spy.cc index 1a85ff93c1357..5f1ef0a2331b7 100644 --- a/impeller/aiks/testing/context_spy.cc +++ b/impeller/aiks/testing/context_spy.cc @@ -50,8 +50,8 @@ std::shared_ptr ContextSpy::MakeContext( return real_context->GetPipelineLibrary(); }); - ON_CALL(*mock_context, GetQueue).WillByDefault([real_context]() { - return real_context->GetQueue(); + ON_CALL(*mock_context, GetCommandQueue).WillByDefault([real_context]() { + return real_context->GetCommandQueue(); }); ON_CALL(*mock_context, CreateCommandBuffer) diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 148df90649ec9..be6f63df11f78 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -542,7 +542,7 @@ void ContentContext::RecordCommandBuffer( void ContentContext::FlushCommandBuffers() const { auto buffers = std::move(pending_command_buffers_->command_buffers); - GetContext()->GetQueue()->Submit(buffers); + GetContext()->GetCommandQueue()->Submit(buffers); } } // namespace impeller diff --git a/impeller/entity/contents/content_context_unittests.cc b/impeller/entity/contents/content_context_unittests.cc index 65d5e8f9f7d2d..37c865e1579a6 100644 --- a/impeller/entity/contents/content_context_unittests.cc +++ b/impeller/entity/contents/content_context_unittests.cc @@ -12,7 +12,7 @@ #include "impeller/entity/contents/content_context.h" #include "impeller/geometry/color.h" #include "impeller/renderer/capabilities.h" -#include "impeller/renderer/graphics_queue.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/pipeline.h" #include "impeller/renderer/pipeline_descriptor.h" @@ -54,7 +54,9 @@ class FakeContext : public Context { std::shared_ptr GetPipelineLibrary() const { return nullptr; } - const std::shared_ptr& GetQueue() const { FML_UNREACHABLE(); } + const std::shared_ptr& GetCommandQueue() const { + FML_UNREACHABLE(); + } std::shared_ptr CreateCommandBuffer() const { return nullptr; } void Shutdown() {} diff --git a/impeller/golden_tests/vulkan_screenshotter.mm b/impeller/golden_tests/vulkan_screenshotter.mm index f96ad307b048d..57c109e565cf7 100644 --- a/impeller/golden_tests/vulkan_screenshotter.mm +++ b/impeller/golden_tests/vulkan_screenshotter.mm @@ -36,7 +36,7 @@ fml::AutoResetWaitableEvent latch; success = - surface_context->GetQueue() + surface_context->GetCommandQueue() ->Submit({command_buffer}, [&latch](CommandBuffer::Status status) { FML_CHECK(status == CommandBuffer::Status::kCompleted); diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc index dcdb189fa7247..f070ff316a37d 100644 --- a/impeller/playground/playground.cc +++ b/impeller/playground/playground.cc @@ -306,7 +306,7 @@ bool Playground::OpenPlaygroundHere( ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass); pass->EncodeCommands(); - if (!renderer->GetContext()->GetQueue()->Submit({buffer}).ok()) { + if (!renderer->GetContext()->GetCommandQueue()->Submit({buffer}).ok()) { return false; } } @@ -350,7 +350,7 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) { } pass->EncodeCommands(); - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } return true; @@ -422,7 +422,7 @@ static std::shared_ptr CreateTextureForDecompressedImage( blit_pass->SetLabel("Mipmap Blit Pass"); blit_pass->GenerateMipmap(texture); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!context->GetQueue()->Submit({command_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) { FML_DLOG(ERROR) << "Failed to submit blit pass command buffer."; return nullptr; } diff --git a/impeller/renderer/BUILD.gn b/impeller/renderer/BUILD.gn index 4d361a964818f..9fdc8964bc18f 100644 --- a/impeller/renderer/BUILD.gn +++ b/impeller/renderer/BUILD.gn @@ -55,6 +55,8 @@ impeller_component("renderer") { "command.h", "command_buffer.cc", "command_buffer.h", + "command_queue.cc", + "command_queue.h", "compute_pass.cc", "compute_pass.h", "compute_pipeline_builder.cc", @@ -63,8 +65,6 @@ impeller_component("renderer") { "compute_pipeline_descriptor.h", "context.cc", "context.h", - "graphics_queue.cc", - "graphics_queue.h", "pipeline.cc", "pipeline.h", "pipeline_builder.cc", diff --git a/impeller/renderer/backend/gles/context_gles.cc b/impeller/renderer/backend/gles/context_gles.cc index 0647fa6055229..95a0c7a6c6424 100644 --- a/impeller/renderer/backend/gles/context_gles.cc +++ b/impeller/renderer/backend/gles/context_gles.cc @@ -9,7 +9,7 @@ #include "impeller/base/validation.h" #include "impeller/renderer/backend/gles/command_buffer_gles.h" #include "impeller/renderer/backend/gles/gpu_tracer_gles.h" -#include "impeller/renderer/graphics_queue.h" +#include "impeller/renderer/command_queue.h" namespace impeller { @@ -68,7 +68,7 @@ ContextGLES::ContextGLES( } gpu_tracer_ = std::make_shared(GetReactor()->GetProcTable(), enable_gpu_tracing); - graphics_queue_ = std::make_shared(); + command_queue_ = std::make_shared(); is_valid_ = true; } @@ -141,8 +141,8 @@ const std::shared_ptr& ContextGLES::GetCapabilities() } // |Context| -const std::shared_ptr& ContextGLES::GetQueue() const { - return graphics_queue_; +const std::shared_ptr& ContextGLES::GetCommandQueue() const { + return command_queue_; } } // namespace impeller diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index ef8fbc0c5dee1..24ced93484a08 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -5,7 +5,6 @@ #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ -#include "fml/logging.h" #include "impeller/base/backend_cast.h" #include "impeller/renderer/backend/gles/allocator_gles.h" #include "impeller/renderer/backend/gles/capabilities_gles.h" @@ -15,8 +14,8 @@ #include "impeller/renderer/backend/gles/sampler_library_gles.h" #include "impeller/renderer/backend/gles/shader_library_gles.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/context.h" -#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -50,7 +49,7 @@ class ContextGLES final : public Context, std::shared_ptr pipeline_library_; std::shared_ptr sampler_library_; std::shared_ptr resource_allocator_; - std::shared_ptr graphics_queue_; + std::shared_ptr command_queue_; std::shared_ptr gpu_tracer_; // Note: This is stored separately from the ProcTableGLES CapabilitiesGLES @@ -88,7 +87,7 @@ class ContextGLES final : public Context, // |Context| const std::shared_ptr& GetCapabilities() const override; - const std::shared_ptr& GetQueue() const override; + const std::shared_ptr& GetCommandQueue() const override; // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/metal/context_mtl.h b/impeller/renderer/backend/metal/context_mtl.h index ff90b1b210461..ac7220c300843 100644 --- a/impeller/renderer/backend/metal/context_mtl.h +++ b/impeller/renderer/backend/metal/context_mtl.h @@ -21,8 +21,8 @@ #include "impeller/renderer/backend/metal/pipeline_library_mtl.h" #include "impeller/renderer/backend/metal/shader_library_mtl.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/context.h" -#include "impeller/renderer/graphics_queue.h" #if TARGET_OS_SIMULATOR #define IMPELLER_CA_METAL_LAYER_AVAILABLE API_AVAILABLE(macos(10.11), ios(13.0)) @@ -82,7 +82,7 @@ class ContextMTL final : public Context, std::shared_ptr CreateCommandBuffer() const override; // |Context| - const std::shared_ptr& GetQueue() const override; + const std::shared_ptr& GetCommandQueue() const override; // |Context| const std::shared_ptr& GetCapabilities() const override; @@ -130,7 +130,7 @@ class ContextMTL final : public Context, #endif // IMPELLER_DEBUG std::deque> tasks_awaiting_gpu_; std::unique_ptr sync_switch_observer_; - std::shared_ptr graphics_queue_; + std::shared_ptr command_queue_ip_; bool is_valid_ = false; ContextMTL( diff --git a/impeller/renderer/backend/metal/context_mtl.mm b/impeller/renderer/backend/metal/context_mtl.mm index cea008b2b9499..65d021e5dcc78 100644 --- a/impeller/renderer/backend/metal/context_mtl.mm +++ b/impeller/renderer/backend/metal/context_mtl.mm @@ -16,7 +16,6 @@ #include "impeller/renderer/backend/metal/gpu_tracer_mtl.h" #include "impeller/renderer/backend/metal/sampler_library_mtl.h" #include "impeller/renderer/capabilities.h" -#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -129,7 +128,7 @@ static bool DeviceSupportsComputeSubgroups(id device) { device_capabilities_ = InferMetalCapabilities(device_, PixelFormat::kB8G8R8A8UNormInt); - graphics_queue_ = std::make_shared(); + command_queue_ip_ = std::make_shared(); #ifdef IMPELLER_DEBUG gpu_tracer_ = std::make_shared(); #endif // IMPELLER_DEBUG @@ -397,8 +396,8 @@ new ContextMTL(device, command_queue, } // |Context| -const std::shared_ptr& ContextMTL::GetQueue() const { - return graphics_queue_; +const std::shared_ptr& ContextMTL::GetCommandQueue() const { + return command_queue_ip_; } } // namespace impeller diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index 250ee6b143283..f3d5240807485 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -242,7 +242,7 @@ blit_pass->AddCopy(source_texture_, destination_texture_, std::nullopt, clip_rect_->GetOrigin()); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!context->GetQueue()->Submit({blit_command_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({blit_command_buffer}).ok()) { return false; } } diff --git a/impeller/renderer/backend/vulkan/BUILD.gn b/impeller/renderer/backend/vulkan/BUILD.gn index 96e19add8e780..78a356cb49e82 100644 --- a/impeller/renderer/backend/vulkan/BUILD.gn +++ b/impeller/renderer/backend/vulkan/BUILD.gn @@ -46,6 +46,8 @@ impeller_component("vulkan") { "command_encoder_vk.h", "command_pool_vk.cc", "command_pool_vk.h", + "command_queue_vk.cc", + "command_queue_vk.h", "compute_pass_vk.cc", "compute_pass_vk.h", "compute_pipeline_vk.cc", @@ -64,8 +66,6 @@ impeller_component("vulkan") { "formats_vk.h", "gpu_tracer_vk.cc", "gpu_tracer_vk.h", - "graphics_queue_vk.cc", - "graphics_queue_vk.h", "limits_vk.h", "pipeline_cache_vk.cc", "pipeline_cache_vk.h", diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk.h b/impeller/renderer/backend/vulkan/command_encoder_vk.h index 16db003557928..8e5aa11e7ec70 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk.h +++ b/impeller/renderer/backend/vulkan/command_encoder_vk.h @@ -10,10 +10,10 @@ #include #include "impeller/renderer/backend/vulkan/command_pool_vk.h" +#include "impeller/renderer/backend/vulkan/command_queue_vk.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/descriptor_pool_vk.h" #include "impeller/renderer/backend/vulkan/device_holder.h" -#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/queue_vk.h" #include "impeller/renderer/backend/vulkan/shared_object_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" @@ -89,7 +89,7 @@ class CommandEncoderVK { private: friend class ContextVK; - friend class GraphicsQueueVK; + friend class CommandQueueVK; std::weak_ptr device_holder_; std::shared_ptr tracked_objects_; diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc b/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc index fe488bdd47a6b..7f4dde9b0bec4 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc +++ b/impeller/renderer/backend/vulkan/command_encoder_vk_unittests.cc @@ -50,11 +50,12 @@ TEST(CommandEncoderVKTest, CleanupAfterSubmit) { auto context = MockVulkanContextBuilder().Build(); std::thread thread([&] { auto buffer = context->CreateCommandBuffer(); - context->GetQueue()->Submit({buffer}, [&](CommandBuffer::Status status) { - ASSERT_EQ(status, CommandBuffer::Status::kCompleted); - wait_for_thread_join.Wait(); - wait_for_submit.Signal(); - }); + context->GetCommandQueue()->Submit( + {buffer}, [&](CommandBuffer::Status status) { + ASSERT_EQ(status, CommandBuffer::Status::kCompleted); + wait_for_thread_join.Wait(); + wait_for_submit.Signal(); + }); }); thread.join(); wait_for_thread_join.Signal(); diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.cc b/impeller/renderer/backend/vulkan/command_queue_vk.cc similarity index 92% rename from impeller/renderer/backend/vulkan/graphics_queue_vk.cc rename to impeller/renderer/backend/vulkan/command_queue_vk.cc index 4b8bd09359049..e7cca35398294 100644 --- a/impeller/renderer/backend/vulkan/graphics_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/command_queue_vk.cc @@ -4,21 +4,22 @@ #include "fml/status.h" +#include "impeller/renderer/backend/vulkan/command_queue_vk.h" + #include "impeller/base/validation.h" #include "impeller/renderer/backend/vulkan/command_buffer_vk.h" #include "impeller/renderer/backend/vulkan/command_encoder_vk.h" #include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/fence_waiter_vk.h" -#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/tracked_objects_vk.h" #include "impeller/renderer/command_buffer.h" namespace impeller { -GraphicsQueueVK::GraphicsQueueVK(const std::weak_ptr& context) +CommandQueueVK::CommandQueueVK(const std::weak_ptr& context) : context_(context) {} -fml::Status GraphicsQueueVK::Submit( +fml::Status CommandQueueVK::Submit( const std::vector>& buffers, const CompletionCallback& callback) { if (buffers.empty()) { @@ -74,9 +75,7 @@ fml::Status GraphicsQueueVK::Submit( [callback, tracked_objects = std::move(tracked_objects)]() mutable { // Ensure tracked objects are destructed before calling any final // callbacks. - for (auto& tracked_object : tracked_objects) { - tracked_object.reset(); - } + tracked_objects.clear(); if (callback) { callback(CommandBuffer::Status::kCompleted); } diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.h b/impeller/renderer/backend/vulkan/command_queue_vk.h new file mode 100644 index 0000000000000..f2777ca1f5c48 --- /dev/null +++ b/impeller/renderer/backend/vulkan/command_queue_vk.h @@ -0,0 +1,33 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// 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_COMMAND_QUEUE_VK_H_ +#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_QUEUE_VK_H_ + +#include "impeller/renderer/command_queue.h" + +namespace impeller { + +class ContextVK; + +class CommandQueueVK : public CommandQueue { + public: + explicit CommandQueueVK(const std::weak_ptr& context); + + ~CommandQueueVK() override {} + + fml::Status Submit(const std::vector>& buffers, + const CompletionCallback& callback = {}) override; + + private: + std::weak_ptr context_; + + CommandQueueVK(const CommandQueueVK&) = delete; + + CommandQueueVK& operator=(const CommandQueueVK&) = delete; +}; + +} // namespace impeller + +#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_QUEUE_VK_H_ diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index 0d82c53a12c53..ab35ce88e485f 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -5,7 +5,7 @@ #include "impeller/renderer/backend/vulkan/context_vk.h" #include "fml/concurrent_message_loop.h" -#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" +#include "impeller/renderer/backend/vulkan/command_queue_vk.h" #ifdef FML_OS_ANDROID #include @@ -27,6 +27,7 @@ #include "impeller/renderer/backend/vulkan/command_buffer_vk.h" #include "impeller/renderer/backend/vulkan/command_encoder_vk.h" #include "impeller/renderer/backend/vulkan/command_pool_vk.h" +#include "impeller/renderer/backend/vulkan/command_queue_vk.h" #include "impeller/renderer/backend/vulkan/debug_report_vk.h" #include "impeller/renderer/backend/vulkan/fence_waiter_vk.h" #include "impeller/renderer/backend/vulkan/gpu_tracer_vk.h" @@ -446,7 +447,7 @@ void ContextVK::Setup(Settings settings) { command_pool_recycler_ = std::move(command_pool_recycler); descriptor_pool_recycler_ = std::move(descriptor_pool_recycler); device_name_ = std::string(physical_device_properties.deviceName); - graphics_queue_vk_ = std::make_shared(weak_from_this()); + command_queue_vk_ = std::make_shared(weak_from_this()); is_valid_ = true; // Create the GPU Tracer later because it depends on state from @@ -565,4 +566,8 @@ std::shared_ptr ContextVK::GetGPUTracer() const { return gpu_tracer_; } +const std::shared_ptr& ContextVK::GetCommandQueue() const { + return command_queue_vk_; +} + } // namespace impeller diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index b024fdc43592e..bc55fdfe404c5 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -15,14 +15,13 @@ #include "impeller/core/formats.h" #include "impeller/renderer/backend/vulkan/command_pool_vk.h" #include "impeller/renderer/backend/vulkan/device_holder.h" -#include "impeller/renderer/backend/vulkan/graphics_queue_vk.h" #include "impeller/renderer/backend/vulkan/pipeline_library_vk.h" #include "impeller/renderer/backend/vulkan/queue_vk.h" #include "impeller/renderer/backend/vulkan/sampler_library_vk.h" #include "impeller/renderer/backend/vulkan/shader_library_vk.h" #include "impeller/renderer/capabilities.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/context.h" -#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -37,7 +36,7 @@ class ResourceManagerVK; class SurfaceContextVK; class GPUTracerVK; class DescriptorPoolRecyclerVK; -class GraphicsQueueVK; +class CommandQueueVK; class ContextVK final : public Context, public BackendCast, @@ -166,9 +165,7 @@ class ContextVK final : public Context, return descriptor_pool_recycler_; } - const std::shared_ptr& GetQueue() const override { - return graphics_queue_vk_; - } + const std::shared_ptr& GetCommandQueue() const override; std::shared_ptr GetGPUTracer() const; @@ -204,7 +201,7 @@ class ContextVK final : public Context, std::unique_ptr queue_submit_thread_; std::shared_ptr gpu_tracer_; std::shared_ptr descriptor_pool_recycler_; - std::shared_ptr graphics_queue_vk_; + std::shared_ptr command_queue_vk_; bool sync_presentation_ = false; const uint64_t hash_; diff --git a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc index fa3ddd8b95ef2..85e66d5c01ef8 100644 --- a/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc +++ b/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc @@ -61,7 +61,7 @@ void GPUTracerVK::InitializeQueryPool(const ContextVK& context) { buffer_vk.GetEncoder()->GetCommandBuffer().resetQueryPool( trace_states_[i].query_pool.get(), 0, kPoolSize); } - if (!context.GetQueue()->Submit({buffer}).ok()) { + if (!context.GetCommandQueue()->Submit({buffer}).ok()) { VALIDATION_LOG << "Failed to reset query pool for trace events."; enabled_ = false; } diff --git a/impeller/renderer/backend/vulkan/graphics_queue_vk.h b/impeller/renderer/backend/vulkan/graphics_queue_vk.h deleted file mode 100644 index eb8e8b32fccd6..0000000000000 --- a/impeller/renderer/backend/vulkan/graphics_queue_vk.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// 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_GRAPHICS_QUEUE_VK_H_ -#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_GRAPHICS_QUEUE_VK_H_ - -#include "impeller/renderer/graphics_queue.h" - -namespace impeller { - -class ContextVK; - -class GraphicsQueueVK : public GraphicsQueue { - public: - explicit GraphicsQueueVK(const std::weak_ptr& context); - - ~GraphicsQueueVK() override {} - - fml::Status Submit(const std::vector>& buffers, - const CompletionCallback& callback = {}) override; - - private: - std::weak_ptr context_; -}; - -} // namespace impeller - -#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_GRAPHICS_QUEUE_VK_H_ diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.cc b/impeller/renderer/backend/vulkan/surface_context_vk.cc index 4fce2823c3e62..17c5eed8c6cd9 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.cc +++ b/impeller/renderer/backend/vulkan/surface_context_vk.cc @@ -48,8 +48,8 @@ std::shared_ptr SurfaceContextVK::CreateCommandBuffer() const { return parent_->CreateCommandBuffer(); } -const std::shared_ptr& SurfaceContextVK::GetQueue() const { - return parent_->GetQueue(); +const std::shared_ptr& SurfaceContextVK::GetCommandQueue() const { + return parent_->GetCommandQueue(); } const std::shared_ptr& SurfaceContextVK::GetCapabilities() diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.h b/impeller/renderer/backend/vulkan/surface_context_vk.h index f248e6f60ad27..65b4020c00b28 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.h +++ b/impeller/renderer/backend/vulkan/surface_context_vk.h @@ -9,8 +9,8 @@ #include "impeller/base/backend_cast.h" #include "impeller/renderer/backend/vulkan/vk.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/context.h" -#include "impeller/renderer/graphics_queue.h" namespace impeller { @@ -64,7 +64,7 @@ class SurfaceContextVK : public Context, const std::shared_ptr& GetCapabilities() const override; // |Context| - const std::shared_ptr& GetQueue() const override; + const std::shared_ptr& GetCommandQueue() const override; // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc b/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc index 96958b60cadb5..a9a267b19e67f 100644 --- a/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc +++ b/impeller/renderer/backend/vulkan/test/gpu_tracer_unittests.cc @@ -28,7 +28,7 @@ TEST(GPUTracerVK, CanTraceCmdBuffer) { auto latch = std::make_shared(1u); - if (!context->GetQueue() + if (!context->GetCommandQueue() ->Submit( {cmd_buffer}, [latch](CommandBuffer::Status status) { latch->CountDown(); }) @@ -58,7 +58,7 @@ TEST(GPUTracerVK, DoesNotTraceOutsideOfFrameWorkload) { blit_pass->EncodeCommands(context->GetResourceAllocator()); auto latch = std::make_shared(1u); - if (!context->GetQueue() + if (!context->GetCommandQueue() ->Submit( {cmd_buffer}, [latch](CommandBuffer::Status status) { latch->CountDown(); }) @@ -90,7 +90,7 @@ TEST(GPUTracerVK, TracesWithPartialFrameOverlap) { tracer->MarkFrameEnd(); auto latch = std::make_shared(1u); - if (!context->GetQueue() + if (!context->GetCommandQueue() ->Submit( {cmd_buffer}, [latch](CommandBuffer::Status status) { latch->CountDown(); }) diff --git a/impeller/renderer/backend/vulkan/texture_vk.cc b/impeller/renderer/backend/vulkan/texture_vk.cc index bbf1618d871ef..f96b4940a4d98 100644 --- a/impeller/renderer/backend/vulkan/texture_vk.cc +++ b/impeller/renderer/backend/vulkan/texture_vk.cc @@ -125,7 +125,7 @@ bool TextureVK::OnSetContents(const uint8_t* contents, } } - return context->GetQueue()->Submit({cmd_buffer}).ok(); + return context->GetCommandQueue()->Submit({cmd_buffer}).ok(); } bool TextureVK::OnSetContents(std::shared_ptr mapping, diff --git a/impeller/renderer/command_buffer.h b/impeller/renderer/command_buffer.h index 380623e57f235..4794941f2857a 100644 --- a/impeller/renderer/command_buffer.h +++ b/impeller/renderer/command_buffer.h @@ -17,7 +17,7 @@ class ComputePass; class Context; class RenderPass; class RenderTarget; -class GraphicsQueue; +class CommandQueue; namespace testing { class CommandBufferMock; @@ -107,7 +107,7 @@ class CommandBuffer { virtual std::shared_ptr OnCreateComputePass() = 0; private: - friend class GraphicsQueue; + friend class CommandQueue; //---------------------------------------------------------------------------- /// @brief Schedule the command encoded by render passes within this diff --git a/impeller/renderer/graphics_queue.cc b/impeller/renderer/command_queue.cc similarity index 89% rename from impeller/renderer/graphics_queue.cc rename to impeller/renderer/command_queue.cc index 5e4781fe41d77..29484e41a2473 100644 --- a/impeller/renderer/graphics_queue.cc +++ b/impeller/renderer/command_queue.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "impeller/renderer/graphics_queue.h" +#include "impeller/renderer/command_queue.h" namespace impeller { -fml::Status GraphicsQueue::Submit( +fml::Status CommandQueue::Submit( const std::vector>& buffers, const CompletionCallback& cb) { if (buffers.empty()) { diff --git a/impeller/renderer/graphics_queue.h b/impeller/renderer/command_queue.h similarity index 76% rename from impeller/renderer/graphics_queue.h rename to impeller/renderer/command_queue.h index 242d9e1d80f51..3bad2a112b589 100644 --- a/impeller/renderer/graphics_queue.h +++ b/impeller/renderer/command_queue.h @@ -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_GRAPHICS_QUEUE_H_ -#define FLUTTER_IMPELLER_RENDERER_GRAPHICS_QUEUE_H_ +#ifndef FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_ +#define FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_ #include @@ -14,13 +14,13 @@ namespace impeller { /// @brief An interface for submitting command buffers to the GPU for /// encoding and execution. -class GraphicsQueue { +class CommandQueue { public: using CompletionCallback = std::function; - GraphicsQueue() = default; + CommandQueue() = default; - virtual ~GraphicsQueue() = default; + virtual ~CommandQueue() = default; /// @brief Submit one or more command buffer objects to be encoded and /// executed on the GPU. @@ -37,11 +37,11 @@ class GraphicsQueue { const CompletionCallback& cb = {}); private: - GraphicsQueue(const GraphicsQueue&) = delete; + CommandQueue(const CommandQueue&) = delete; - GraphicsQueue& operator=(const GraphicsQueue&) = delete; + CommandQueue& operator=(const CommandQueue&) = delete; }; } // namespace impeller -#endif // FLUTTER_IMPELLER_RENDERER_GRAPHICS_QUEUE_H_ +#endif // FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_ diff --git a/impeller/renderer/compute_tessellator.cc b/impeller/renderer/compute_tessellator.cc index 4989d7b78510b..41f9925d5651e 100644 --- a/impeller/renderer/compute_tessellator.cc +++ b/impeller/renderer/compute_tessellator.cc @@ -171,7 +171,7 @@ ComputeTessellator::Status ComputeTessellator::Tessellate( return Status::kCommandInvalid; } - if (!context->GetQueue()->Submit({cmd_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({cmd_buffer}).ok()) { return Status::kCommandInvalid; } diff --git a/impeller/renderer/compute_unittests.cc b/impeller/renderer/compute_unittests.cc index 5a2ea6a2ae967..1147f720ae6b3 100644 --- a/impeller/renderer/compute_unittests.cc +++ b/impeller/renderer/compute_unittests.cc @@ -76,7 +76,7 @@ TEST_P(ComputeTest, CanCreateComputePass) { fml::AutoResetWaitableEvent latch; ASSERT_TRUE( - context->GetQueue() + context->GetCommandQueue() ->Submit( {cmd_buffer}, [&latch, output_buffer, &input_0, @@ -146,7 +146,7 @@ TEST_P(ComputeTest, CanComputePrefixSum) { fml::AutoResetWaitableEvent latch; ASSERT_TRUE( - context->GetQueue() + context->GetCommandQueue() ->Submit({cmd_buffer}, [&latch, output_buffer](CommandBuffer::Status status) { EXPECT_EQ(status, CommandBuffer::Status::kCompleted); @@ -204,7 +204,7 @@ TEST_P(ComputeTest, 1DThreadgroupSizingIsCorrect) { fml::AutoResetWaitableEvent latch; ASSERT_TRUE( - context->GetQueue() + context->GetCommandQueue() ->Submit({cmd_buffer}, [&latch, output_buffer](CommandBuffer::Status status) { EXPECT_EQ(status, CommandBuffer::Status::kCompleted); @@ -263,7 +263,7 @@ TEST_P(ComputeTest, CanComputePrefixSumLargeInteractive) { pass->Compute(ISize(kCount, 1)); pass->EncodeCommands(); host_buffer->Reset(); - return context->GetQueue()->Submit({cmd_buffer}).ok(); + return context->GetCommandQueue()->Submit({cmd_buffer}).ok(); }; ASSERT_TRUE(OpenPlaygroundHere(callback)); } @@ -339,7 +339,7 @@ TEST_P(ComputeTest, MultiStageInputAndOutput) { fml::AutoResetWaitableEvent latch; ASSERT_TRUE( - context->GetQueue() + context->GetCommandQueue() ->Submit({cmd_buffer}, [&latch, &output_buffer_1, &output_buffer_2](CommandBuffer::Status status) { @@ -419,7 +419,7 @@ TEST_P(ComputeTest, CanCompute1DimensionalData) { fml::AutoResetWaitableEvent latch; ASSERT_TRUE( - context->GetQueue() + context->GetCommandQueue() ->Submit( {cmd_buffer}, [&latch, output_buffer, &input_0, diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h index a787ca91e3400..c73caad085a4d 100644 --- a/impeller/renderer/context.h +++ b/impeller/renderer/context.h @@ -12,7 +12,7 @@ #include "impeller/core/capture.h" #include "impeller/core/formats.h" #include "impeller/renderer/capabilities.h" -#include "impeller/renderer/graphics_queue.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/sampler_library.h" namespace impeller { @@ -163,7 +163,7 @@ class Context { virtual std::shared_ptr CreateCommandBuffer() const = 0; /// @brief Return the graphics queue for submitting command buffers. - virtual const std::shared_ptr& GetQueue() const = 0; + virtual const std::shared_ptr& GetCommandQueue() const = 0; //---------------------------------------------------------------------------- /// @brief Force all pending asynchronous work to finish. This is diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index 42b7ddd48f240..c5336fb7433e3 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -554,7 +554,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { pass->EncodeCommands(); } - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); @@ -641,7 +641,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { pass->AddCopy(bridge, device_buffer); pass->EncodeCommands(context->GetResourceAllocator()); - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } } @@ -689,7 +689,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { pass->Draw().ok(); } pass->EncodeCommands(); - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } } @@ -811,7 +811,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) { pass->EncodeCommands(); } - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); @@ -1256,7 +1256,7 @@ TEST_P(RendererTest, StencilMask) { pass->EncodeCommands(); } - if (!context->GetQueue()->Submit({buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({buffer}).ok()) { return false; } host_buffer->Reset(); diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 610e8adf00382..28ebd58705eef 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -10,8 +10,8 @@ #include "impeller/core/sampler_descriptor.h" #include "impeller/core/texture.h" #include "impeller/renderer/command_buffer.h" +#include "impeller/renderer/command_queue.h" #include "impeller/renderer/context.h" -#include "impeller/renderer/graphics_queue.h" #include "impeller/renderer/render_pass.h" #include "impeller/renderer/render_target.h" #include "impeller/renderer/sampler_library.h" @@ -166,8 +166,8 @@ class MockImpellerContext : public Context { (), (const, override)); - MOCK_METHOD(const std::shared_ptr&, - GetQueue, + MOCK_METHOD(const std::shared_ptr&, + GetCommandQueue, (), (const, override)); }; @@ -206,9 +206,9 @@ class MockCapabilities : public Capabilities { MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override)); }; -class MockGraphicsQueue : public GraphicsQueue { +class MockCommandQueue : public CommandQueue { public: - ~MockGraphicsQueue() override = default; + ~MockCommandQueue() override = default; MOCK_METHOD(fml::Status, Submit, diff --git a/impeller/scene/scene.cc b/impeller/scene/scene.cc index 24564a2b4d2cd..4e5e656120e55 100644 --- a/impeller/scene/scene.cc +++ b/impeller/scene/scene.cc @@ -54,7 +54,7 @@ bool Scene::Render(const RenderTarget& render_target, // TODO(bdero): Do post processing. if (!scene_context_->GetContext() - ->GetQueue() + ->GetCommandQueue() ->Submit({command_buffer}) .ok()) { FML_LOG(ERROR) << "Failed to submit command buffer."; diff --git a/lib/gpu/command_buffer.cc b/lib/gpu/command_buffer.cc index c1e86c60e8ec0..b2f8fcd6c5098 100644 --- a/lib/gpu/command_buffer.cc +++ b/lib/gpu/command_buffer.cc @@ -38,7 +38,7 @@ bool CommandBuffer::Submit() { encodable->EncodeCommands(); } - return context_->GetQueue()->Submit({command_buffer_}).ok(); + return context_->GetCommandQueue()->Submit({command_buffer_}).ok(); } bool CommandBuffer::Submit( @@ -46,7 +46,7 @@ bool CommandBuffer::Submit( for (auto& encodable : encodables_) { encodable->EncodeCommands(); } - return context_->GetQueue() + return context_->GetCommandQueue() ->Submit({command_buffer_}, completion_callback) .ok(); } diff --git a/lib/ui/painting/image_decoder_impeller.cc b/lib/ui/painting/image_decoder_impeller.cc index 65947801eb85d..3ef8a8de5339c 100644 --- a/lib/ui/painting/image_decoder_impeller.cc +++ b/lib/ui/painting/image_decoder_impeller.cc @@ -340,7 +340,7 @@ static std::pair, std::string> UnsafeUploadTextureToPrivate( } blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!context->GetQueue()->Submit({command_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) { std::string decode_error("Failed to submit blit pass command buffer."); FML_DLOG(ERROR) << decode_error; return std::make_pair(nullptr, decode_error); @@ -459,7 +459,7 @@ ImageDecoderImpeller::UploadTextureToStorage( blit_pass->GenerateMipmap(texture); blit_pass->EncodeCommands(context->GetResourceAllocator()); - if (!context->GetQueue()->Submit({command_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) { decode_error = "Failed to submit blit pass command buffer."; return; } diff --git a/lib/ui/painting/image_encoding_impeller.cc b/lib/ui/painting/image_encoding_impeller.cc index 831cff6e7c280..e2e7cf9e9642d 100644 --- a/lib/ui/painting/image_encoding_impeller.cc +++ b/lib/ui/painting/image_encoding_impeller.cc @@ -178,7 +178,7 @@ void ImageEncodingImpeller::ConvertDlImageToSkImage( encode_task(sk_image); }; - if (!impeller_context->GetQueue() + if (!impeller_context->GetCommandQueue() ->Submit({command_buffer}, completion) .ok()) { FML_LOG(ERROR) << "Failed to submit commands."; diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index 2a961f27082ae..43bfb46fb6124 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -193,8 +193,8 @@ TEST_F(ShellTest, EncodeImageAccessesSyncSwitch) { using ::impeller::testing::MockAllocator; using ::impeller::testing::MockBlitPass; using ::impeller::testing::MockCommandBuffer; +using ::impeller::testing::MockCommandQueue; using ::impeller::testing::MockDeviceBuffer; -using ::impeller::testing::MockGraphicsQueue; using ::impeller::testing::MockImpellerContext; using ::impeller::testing::MockTexture; using ::testing::_; @@ -210,7 +210,7 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( auto command_buffer = std::make_shared(context); auto allocator = std::make_shared(); auto blit_pass = std::make_shared(); - auto graphics_queue = std::make_shared(); + auto command_queue = std::make_shared(); impeller::DeviceBufferDescriptor device_buffer_desc; device_buffer_desc.size = buffer.size(); auto device_buffer = std::make_shared(device_buffer_desc); @@ -225,10 +225,9 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( EXPECT_CALL(*context, GetResourceAllocator).WillRepeatedly(Return(allocator)); EXPECT_CALL(*context, CreateCommandBuffer).WillOnce(Return(command_buffer)); EXPECT_CALL(*device_buffer, OnGetContents).WillOnce(Return(buffer.data())); - EXPECT_CALL(*context, GetQueue).WillRepeatedly(Invoke([graphics_queue]() { - return graphics_queue; - })); - EXPECT_CALL(*graphics_queue, Submit(_, _)) + EXPECT_CALL(*context, GetCommandQueue) + .WillRepeatedly(Invoke([command_queue]() { return command_queue; })); + EXPECT_CALL(*command_queue, Submit(_, _)) .WillOnce( DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), Return(fml::Status()))); diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index d469b2a2ad719..8d6edce8d958a 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -911,7 +911,7 @@ ScreenshotLayerTreeAsImageImpeller( sk_data = SkData::MakeWithCopy(buffer->OnGetContents(), buffer_desc.size); }; - if (!impeller_context->GetQueue() + if (!impeller_context->GetCommandQueue() ->Submit({command_buffer}, completion) .ok()) { FML_LOG(ERROR) << "Failed to submit commands."; From 48220a92456fe4ae44106526ba3bae67ff99ddaa Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 12:42:10 -0800 Subject: [PATCH 08/21] ++ --- .../backend/vulkan/command_queue_vk.cc | 23 ++++++++++--------- .../backend/vulkan/command_queue_vk.h | 7 +++--- impeller/renderer/command_queue.cc | 16 +++++++++---- impeller/renderer/command_queue.h | 20 +++++++++------- .../android/android_context_gl_unittests.cc | 3 ++- .../android/image_external_texture_vk.cc | 2 +- 6 files changed, 43 insertions(+), 28 deletions(-) diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.cc b/impeller/renderer/backend/vulkan/command_queue_vk.cc index e7cca35398294..fea3910c3f7ee 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/command_queue_vk.cc @@ -19,18 +19,19 @@ namespace impeller { CommandQueueVK::CommandQueueVK(const std::weak_ptr& context) : context_(context) {} +CommandQueueVK::~CommandQueueVK() = default; + fml::Status CommandQueueVK::Submit( - const std::vector>& buffers, - const CompletionCallback& callback) { - if (buffers.empty()) { + const std::initializer_list>& buffers, + const CompletionCallback& completion_callback) { + if (buffers.size() == 0u) { return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided."); } - bool fail_callback = !!callback; // Success or failure, you only get to submit once. fml::ScopedCleanupClosure reset([&]() { - if (fail_callback) { - callback(CommandBuffer::Status::kError); + if (completion_callback) { + completion_callback(CommandBuffer::Status::kError); } }); @@ -71,19 +72,19 @@ fml::Status CommandQueueVK::Submit( // Submit will proceed, call callback with true when it is done and do not // call when `reset` is collected. auto added_fence = context->GetFenceWaiter()->AddFence( - std::move(fence), - [callback, tracked_objects = std::move(tracked_objects)]() mutable { + std::move(fence), [completion_callback, tracked_objects = std::move( + tracked_objects)]() mutable { // Ensure tracked objects are destructed before calling any final // callbacks. tracked_objects.clear(); - if (callback) { - callback(CommandBuffer::Status::kCompleted); + if (completion_callback) { + completion_callback(CommandBuffer::Status::kCompleted); } }); if (!added_fence) { return fml::Status(fml::StatusCode::kCancelled, "Failed to add fence."); } - fail_callback = false; + reset.Release(); return fml::Status(); } diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.h b/impeller/renderer/backend/vulkan/command_queue_vk.h index f2777ca1f5c48..04ec7e58a0919 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.h +++ b/impeller/renderer/backend/vulkan/command_queue_vk.h @@ -15,10 +15,11 @@ class CommandQueueVK : public CommandQueue { public: explicit CommandQueueVK(const std::weak_ptr& context); - ~CommandQueueVK() override {} + ~CommandQueueVK() override; - fml::Status Submit(const std::vector>& buffers, - const CompletionCallback& callback = {}) override; + fml::Status Submit( + const std::initializer_list>& buffers, + const CompletionCallback& completion_callback = {}) override; private: std::weak_ptr context_; diff --git a/impeller/renderer/command_queue.cc b/impeller/renderer/command_queue.cc index 29484e41a2473..359e5d66c9c7e 100644 --- a/impeller/renderer/command_queue.cc +++ b/impeller/renderer/command_queue.cc @@ -3,18 +3,26 @@ // found in the LICENSE file. #include "impeller/renderer/command_queue.h" +#include "impeller/renderer/command_buffer.h" namespace impeller { +CommandQueue::CommandQueue() = default; + +CommandQueue::~CommandQueue() = default; + fml::Status CommandQueue::Submit( - const std::vector>& buffers, - const CompletionCallback& cb) { - if (buffers.empty()) { + const std::initializer_list>& buffers, + const CompletionCallback& completion_callback) { + if (buffers.size() == 0u) { + if (completion_callback) { + completion_callback(CommandBuffer::Status::kError); + } return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided."); } for (const std::shared_ptr& buffer : buffers) { - if (!buffer->SubmitCommands(cb)) { + if (!buffer->SubmitCommands(completion_callback)) { return fml::Status(fml::StatusCode::kCancelled, "Failed to submit command buffer."); } diff --git a/impeller/renderer/command_queue.h b/impeller/renderer/command_queue.h index 3bad2a112b589..23cb2b09065f5 100644 --- a/impeller/renderer/command_queue.h +++ b/impeller/renderer/command_queue.h @@ -6,6 +6,7 @@ #define FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_ #include +#include #include "fml/status.h" #include "impeller/renderer/command_buffer.h" @@ -18,9 +19,9 @@ class CommandQueue { public: using CompletionCallback = std::function; - CommandQueue() = default; + CommandQueue(); - virtual ~CommandQueue() = default; + virtual ~CommandQueue(); /// @brief Submit one or more command buffer objects to be encoded and /// executed on the GPU. @@ -28,13 +29,16 @@ class CommandQueue { /// The order of the provided buffers determines the ordering in which /// they are submitted. /// - /// Optionally accepts a ccallback that will fire with an updated - /// status based on encoding state. Only the Metal and Vulkan backend - /// can give a status beyond successful encoding. This callback may - /// be called more than once. + /// The returned status only indicates if the command buffer was + /// successfully submitted. Successful completion of the command buffer + /// can only be checked in the optional completion callback. + /// + /// Only the Metal and Vulkan backends can give a status beyond + /// successful encoding. This callback may be called more than once and + /// potentially on a different thread. virtual fml::Status Submit( - const std::vector>& buffers, - const CompletionCallback& cb = {}); + const std::initializer_list>& buffers, + const CompletionCallback& completion_callback = {}); private: CommandQueue(const CommandQueue&) = delete; diff --git a/shell/platform/android/android_context_gl_unittests.cc b/shell/platform/android/android_context_gl_unittests.cc index a6f7ceaba1f1e..cf64b225d57d5 100644 --- a/shell/platform/android/android_context_gl_unittests.cc +++ b/shell/platform/android/android_context_gl_unittests.cc @@ -74,7 +74,8 @@ class TestImpellerContext : public impeller::Context { FML_UNREACHABLE(); } - const std::shared_ptr& GetQueue() const override { + const std::shared_ptr& GetCommandQueue() + const override { FML_UNREACHABLE(); } diff --git a/shell/platform/android/image_external_texture_vk.cc b/shell/platform/android/image_external_texture_vk.cc index 77ad1ecb096b7..8d2346e69560e 100644 --- a/shell/platform/android/image_external_texture_vk.cc +++ b/shell/platform/android/image_external_texture_vk.cc @@ -82,7 +82,7 @@ void ImageExternalTextureVK::ProcessFrame(PaintContext& context, if (!texture->SetLayout(barrier)) { return; } - if (!impeller_context_->GetQueue()->Submit({buffer}).ok()) { + if (!impeller_context_->GetCommandQueue()->Submit({buffer}).ok()) { return; } } From fc8f1a319e086006b40554ef06388cb70e3655aa Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 13:06:03 -0800 Subject: [PATCH 09/21] Remove initializer list. --- impeller/renderer/backend/vulkan/command_queue_vk.cc | 4 ++-- impeller/renderer/backend/vulkan/command_queue_vk.h | 2 +- impeller/renderer/command_queue.cc | 4 ++-- impeller/renderer/command_queue.h | 3 +-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.cc b/impeller/renderer/backend/vulkan/command_queue_vk.cc index fea3910c3f7ee..11842a10467df 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/command_queue_vk.cc @@ -22,9 +22,9 @@ CommandQueueVK::CommandQueueVK(const std::weak_ptr& context) CommandQueueVK::~CommandQueueVK() = default; fml::Status CommandQueueVK::Submit( - const std::initializer_list>& buffers, + const std::vector>& buffers, const CompletionCallback& completion_callback) { - if (buffers.size() == 0u) { + if (buffers.empty()) { return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided."); } diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.h b/impeller/renderer/backend/vulkan/command_queue_vk.h index 04ec7e58a0919..6397391c845c9 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.h +++ b/impeller/renderer/backend/vulkan/command_queue_vk.h @@ -18,7 +18,7 @@ class CommandQueueVK : public CommandQueue { ~CommandQueueVK() override; fml::Status Submit( - const std::initializer_list>& buffers, + const std::vector>& buffers, const CompletionCallback& completion_callback = {}) override; private: diff --git a/impeller/renderer/command_queue.cc b/impeller/renderer/command_queue.cc index 359e5d66c9c7e..531fa8794220a 100644 --- a/impeller/renderer/command_queue.cc +++ b/impeller/renderer/command_queue.cc @@ -12,9 +12,9 @@ CommandQueue::CommandQueue() = default; CommandQueue::~CommandQueue() = default; fml::Status CommandQueue::Submit( - const std::initializer_list>& buffers, + const std::vector>& buffers, const CompletionCallback& completion_callback) { - if (buffers.size() == 0u) { + if (buffers.empty()) { if (completion_callback) { completion_callback(CommandBuffer::Status::kError); } diff --git a/impeller/renderer/command_queue.h b/impeller/renderer/command_queue.h index 23cb2b09065f5..140b1c396e244 100644 --- a/impeller/renderer/command_queue.h +++ b/impeller/renderer/command_queue.h @@ -6,7 +6,6 @@ #define FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_ #include -#include #include "fml/status.h" #include "impeller/renderer/command_buffer.h" @@ -37,7 +36,7 @@ class CommandQueue { /// successful encoding. This callback may be called more than once and /// potentially on a different thread. virtual fml::Status Submit( - const std::initializer_list>& buffers, + const std::vector>& buffers, const CompletionCallback& completion_callback = {}); private: From a1cad72f31036bab22f5000b838593cbc9c5f272 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 13:18:58 -0800 Subject: [PATCH 10/21] fix image decoder unittests. --- lib/ui/painting/image_decoder_unittests.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index f795b6cbbe7d7..8285123400256 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -23,6 +23,8 @@ #include "flutter/testing/test_dart_native_resolver.h" #include "flutter/testing/test_gl_surface.h" #include "flutter/testing/testing.h" +#include "fml/logging.h" +#include "impeller/renderer/command_queue.h" #include "third_party/skia/include/codec/SkCodecAnimation.h" #include "third_party/skia/include/core/SkData.h" #include "third_party/skia/include/core/SkImage.h" @@ -35,8 +37,6 @@ namespace impeller { -static const std::shared_ptr kNullQueue = nullptr; - class TestImpellerContext : public impeller::Context { public: TestImpellerContext() = default; @@ -67,8 +67,8 @@ class TestImpellerContext : public impeller::Context { return nullptr; } - const std::shared_ptr& GetQueue() const override { - return kNullQueue; + const std::shared_ptr& GetCommandQueue() const override { + FML_UNREACHABLE(); } std::shared_ptr CreateCommandBuffer() const override { From e591b055a51ae9f5b4771a00fd403c3989b157c9 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 13:26:33 -0800 Subject: [PATCH 11/21] fix licenses. --- ci/licenses_golden/licenses_flutter | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 304ebf280c561..4a8451474ab3e 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -5445,6 +5445,8 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_encoder_vk.cc ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_encoder_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_pool_vk.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_queue_vk.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/command_queue_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/compute_pass_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/compute_pass_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/compute_pipeline_vk.cc + ../../../flutter/LICENSE @@ -5464,8 +5466,6 @@ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc + ../../ ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_library_vk.cc + ../../../flutter/LICENSE @@ -5529,8 +5529,6 @@ ORIGIN: ../../../flutter/impeller/renderer/compute_tessellator.cc + ../../../flu ORIGIN: ../../../flutter/impeller/renderer/compute_tessellator.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/context.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/context.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/graphics_queue.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/graphics_queue.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/path_polyline.comp + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/pipeline.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/pipeline.h + ../../../flutter/LICENSE @@ -5685,6 +5683,8 @@ ORIGIN: ../../../flutter/impeller/typographer/typographer_context.cc + ../../../ ORIGIN: ../../../flutter/impeller/typographer/typographer_context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/command_buffer.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/command_buffer.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/command_queue.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/command_queue.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/context.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/device_buffer.cc + ../../../flutter/LICENSE @@ -8294,6 +8294,8 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_encoder_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_encoder_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_pool_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_pool_vk.h +FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_queue_vk.cc +FILE: ../../../flutter/impeller/renderer/backend/vulkan/command_queue_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/compute_pass_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/compute_pass_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/compute_pipeline_vk.cc @@ -8313,8 +8315,6 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/formats_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/gpu_tracer_vk.h -FILE: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.cc -FILE: ../../../flutter/impeller/renderer/backend/vulkan/graphics_queue_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/limits_vk.h FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.cc FILE: ../../../flutter/impeller/renderer/backend/vulkan/pipeline_cache_vk.h @@ -8369,6 +8369,8 @@ FILE: ../../../flutter/impeller/renderer/command.cc FILE: ../../../flutter/impeller/renderer/command.h FILE: ../../../flutter/impeller/renderer/command_buffer.cc FILE: ../../../flutter/impeller/renderer/command_buffer.h +FILE: ../../../flutter/impeller/renderer/command_queue.cc +FILE: ../../../flutter/impeller/renderer/command_queue.h FILE: ../../../flutter/impeller/renderer/compute_pass.cc FILE: ../../../flutter/impeller/renderer/compute_pass.h FILE: ../../../flutter/impeller/renderer/compute_pipeline_builder.cc @@ -8379,8 +8381,6 @@ FILE: ../../../flutter/impeller/renderer/compute_tessellator.cc FILE: ../../../flutter/impeller/renderer/compute_tessellator.h FILE: ../../../flutter/impeller/renderer/context.cc FILE: ../../../flutter/impeller/renderer/context.h -FILE: ../../../flutter/impeller/renderer/graphics_queue.cc -FILE: ../../../flutter/impeller/renderer/graphics_queue.h FILE: ../../../flutter/impeller/renderer/path_polyline.comp FILE: ../../../flutter/impeller/renderer/pipeline.cc FILE: ../../../flutter/impeller/renderer/pipeline.h From 825e66932d293e1d4e9285a7d9da498b345728fa Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 14:01:31 -0800 Subject: [PATCH 12/21] ++ --- ci/licenses_golden/licenses_flutter | 4 ++-- impeller/renderer/backend/gles/context_gles.h | 1 + impeller/renderer/testing/mocks.h | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 4a8451474ab3e..3fb8f1dc15c78 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -5519,6 +5519,8 @@ ORIGIN: ../../../flutter/impeller/renderer/command.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/command.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/command_buffer.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/command_buffer.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/command_queue.cc + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/renderer/command_queue.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/compute_pass.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/compute_pass.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/renderer/compute_pipeline_builder.cc + ../../../flutter/LICENSE @@ -5683,8 +5685,6 @@ ORIGIN: ../../../flutter/impeller/typographer/typographer_context.cc + ../../../ ORIGIN: ../../../flutter/impeller/typographer/typographer_context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/command_buffer.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/command_buffer.h + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/command_queue.cc + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/renderer/command_queue.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/context.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/context.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/lib/gpu/device_buffer.cc + ../../../flutter/LICENSE diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index 24ced93484a08..a752a80ad9a80 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -87,6 +87,7 @@ class ContextGLES final : public Context, // |Context| const std::shared_ptr& GetCapabilities() const override; + // |Context| const std::shared_ptr& GetCommandQueue() const override; // |Context| diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 28ebd58705eef..7f0646e297f69 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -208,8 +208,6 @@ class MockCapabilities : public Capabilities { class MockCommandQueue : public CommandQueue { public: - ~MockCommandQueue() override = default; - MOCK_METHOD(fml::Status, Submit, (const std::vector>& buffers, From 559016a34f6c63d7a784c50b7fb9c9867141d6c9 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 18:29:09 -0800 Subject: [PATCH 13/21] thanks Jason. --- lib/ui/painting/image_encoding_unittests.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index 43bfb46fb6124..f355306c3cff0 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -226,7 +226,9 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( EXPECT_CALL(*context, CreateCommandBuffer).WillOnce(Return(command_buffer)); EXPECT_CALL(*device_buffer, OnGetContents).WillOnce(Return(buffer.data())); EXPECT_CALL(*context, GetCommandQueue) - .WillRepeatedly(Invoke([command_queue]() { return command_queue; })); + .WillRepeatedly( + Invoke([command_queue = std::shared_ptr( + command_queue)]() { return command_queue; })); EXPECT_CALL(*command_queue, Submit(_, _)) .WillOnce( DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), From d777218663c1cac0ddae83a1969a266fff7dac72 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 19:29:32 -0800 Subject: [PATCH 14/21] fix mocks --- lib/ui/painting/image_encoding_unittests.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index f355306c3cff0..7a23376bfb30e 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -218,10 +218,6 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( EXPECT_CALL(*blit_pass, IsValid).WillRepeatedly(Return(true)); EXPECT_CALL(*command_buffer, IsValid).WillRepeatedly(Return(true)); EXPECT_CALL(*command_buffer, OnCreateBlitPass).WillOnce(Return(blit_pass)); - EXPECT_CALL(*command_buffer, OnSubmitCommands(_)) - .WillOnce( - DoAll(InvokeArgument<0>(impeller::CommandBuffer::Status::kCompleted), - Return(true))); EXPECT_CALL(*context, GetResourceAllocator).WillRepeatedly(Return(allocator)); EXPECT_CALL(*context, CreateCommandBuffer).WillOnce(Return(command_buffer)); EXPECT_CALL(*device_buffer, OnGetContents).WillOnce(Return(buffer.data())); From 355bb941ad36f14df66fddc0b1c1cd8f657a8a65 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 20:15:25 -0800 Subject: [PATCH 15/21] fix testing. --- impeller/aiks/testing/context_spy.cc | 4 +++- impeller/renderer/compute_tessellator.cc | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/impeller/aiks/testing/context_spy.cc b/impeller/aiks/testing/context_spy.cc index 5f1ef0a2331b7..c147f1f38be1b 100644 --- a/impeller/aiks/testing/context_spy.cc +++ b/impeller/aiks/testing/context_spy.cc @@ -51,7 +51,9 @@ std::shared_ptr ContextSpy::MakeContext( }); ON_CALL(*mock_context, GetCommandQueue).WillByDefault([real_context]() { - return real_context->GetCommandQueue(); + // Return the base command queue type to avoid vulkan specific behavior with + // mock objects. + return std::make_shared(); }); ON_CALL(*mock_context, CreateCommandBuffer) diff --git a/impeller/renderer/compute_tessellator.cc b/impeller/renderer/compute_tessellator.cc index 41f9925d5651e..8e8d084e7a2cd 100644 --- a/impeller/renderer/compute_tessellator.cc +++ b/impeller/renderer/compute_tessellator.cc @@ -171,7 +171,7 @@ ComputeTessellator::Status ComputeTessellator::Tessellate( return Status::kCommandInvalid; } - if (!context->GetCommandQueue()->Submit({cmd_buffer}).ok()) { + if (!context->GetCommandQueue()->Submit({cmd_buffer}, callback).ok()) { return Status::kCommandInvalid; } From 4fb554826c61ac795f3ed737db8f0e148b189c88 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 20:53:36 -0800 Subject: [PATCH 16/21] ++ --- impeller/aiks/testing/context_spy.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/impeller/aiks/testing/context_spy.cc b/impeller/aiks/testing/context_spy.cc index c147f1f38be1b..5f1ef0a2331b7 100644 --- a/impeller/aiks/testing/context_spy.cc +++ b/impeller/aiks/testing/context_spy.cc @@ -51,9 +51,7 @@ std::shared_ptr ContextSpy::MakeContext( }); ON_CALL(*mock_context, GetCommandQueue).WillByDefault([real_context]() { - // Return the base command queue type to avoid vulkan specific behavior with - // mock objects. - return std::make_shared(); + return real_context->GetCommandQueue(); }); ON_CALL(*mock_context, CreateCommandBuffer) From f7b73067f149707f1772c07c718ba5362d6a4140 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 20:55:16 -0800 Subject: [PATCH 17/21] ++ --- lib/ui/painting/image_encoding_unittests.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index 7a23376bfb30e..38ca0fa52fc47 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -221,14 +221,14 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( EXPECT_CALL(*context, GetResourceAllocator).WillRepeatedly(Return(allocator)); EXPECT_CALL(*context, CreateCommandBuffer).WillOnce(Return(command_buffer)); EXPECT_CALL(*device_buffer, OnGetContents).WillOnce(Return(buffer.data())); + EXPECT_CALL(*command_queue, Submit(_, _)) + .WillRepeatedly( + DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), + Return(fml::Status()))); EXPECT_CALL(*context, GetCommandQueue) .WillRepeatedly( Invoke([command_queue = std::shared_ptr( command_queue)]() { return command_queue; })); - EXPECT_CALL(*command_queue, Submit(_, _)) - .WillOnce( - DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), - Return(fml::Status()))); return context; } } // namespace From b4d81fb76a838a4ad83d0651bd71ff429d56d9ca Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 21:40:37 -0800 Subject: [PATCH 18/21] maybe this works on CI. --- impeller/aiks/testing/context_spy.cc | 15 +++++++++++++-- impeller/aiks/testing/context_spy.h | 10 ++++++++++ .../renderer/backend/vulkan/command_queue_vk.cc | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/impeller/aiks/testing/context_spy.cc b/impeller/aiks/testing/context_spy.cc index 5f1ef0a2331b7..325dc3315547e 100644 --- a/impeller/aiks/testing/context_spy.cc +++ b/impeller/aiks/testing/context_spy.cc @@ -3,12 +3,23 @@ // found in the LICENSE file. #include +#include "impeller/renderer/command_buffer.h" +#include "impeller/renderer/command_queue.h" #include "impeller/aiks/testing/context_spy.h" namespace impeller { namespace testing { +fml::Status NoopCommandQueue::Submit( + const std::vector>& buffers, + const CompletionCallback& completion_callback) { + if (completion_callback) { + completion_callback(CommandBuffer::Status::kCompleted); + } + return fml::Status(); +} + std::shared_ptr ContextSpy::Make() { return std::shared_ptr(new ContextSpy()); } @@ -50,8 +61,8 @@ std::shared_ptr ContextSpy::MakeContext( return real_context->GetPipelineLibrary(); }); - ON_CALL(*mock_context, GetCommandQueue).WillByDefault([real_context]() { - return real_context->GetCommandQueue(); + ON_CALL(*mock_context, GetCommandQueue).WillByDefault([shared_this]() { + return shared_this->command_queue_; }); ON_CALL(*mock_context, CreateCommandBuffer) diff --git a/impeller/aiks/testing/context_spy.h b/impeller/aiks/testing/context_spy.h index fe251b89e5999..c4fb6c84fa947 100644 --- a/impeller/aiks/testing/context_spy.h +++ b/impeller/aiks/testing/context_spy.h @@ -9,10 +9,18 @@ #include "impeller/aiks/testing/context_mock.h" #include "impeller/entity/contents/test/recording_render_pass.h" +#include "impeller/renderer/command_queue.h" namespace impeller { namespace testing { +class NoopCommandQueue : public CommandQueue { + public: + fml::Status Submit( + const std::vector>& buffers, + const CompletionCallback& completion_callback = {}) override; +}; + /// Forwards calls to a real Context but can store information about how /// the Context was used. class ContextSpy : public std::enable_shared_from_this { @@ -23,6 +31,8 @@ class ContextSpy : public std::enable_shared_from_this { const std::shared_ptr& real_context); std::vector> render_passes_; + std::shared_ptr command_queue_ = + std::make_shared(); private: ContextSpy() = default; diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.cc b/impeller/renderer/backend/vulkan/command_queue_vk.cc index 11842a10467df..fe166b7ee6e5a 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/command_queue_vk.cc @@ -24,6 +24,7 @@ CommandQueueVK::~CommandQueueVK() = default; fml::Status CommandQueueVK::Submit( const std::vector>& buffers, const CompletionCallback& completion_callback) { + FML_LOG(ERROR) << "uh -oh!"; if (buffers.empty()) { return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided."); From f33a4b6b591a4b7d017115b32f1438860db9acac Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 22:06:00 -0800 Subject: [PATCH 19/21] ++ --- impeller/aiks/testing/context_mock.h | 2 +- impeller/entity/contents/content_context_unittests.cc | 4 +--- impeller/renderer/backend/gles/context_gles.cc | 2 +- impeller/renderer/backend/gles/context_gles.h | 2 +- impeller/renderer/backend/metal/context_mtl.h | 2 +- impeller/renderer/backend/metal/context_mtl.mm | 2 +- impeller/renderer/backend/vulkan/context_vk.cc | 2 +- impeller/renderer/backend/vulkan/context_vk.h | 2 +- impeller/renderer/backend/vulkan/surface_context_vk.cc | 2 +- impeller/renderer/backend/vulkan/surface_context_vk.h | 2 +- impeller/renderer/context.h | 2 +- impeller/renderer/testing/mocks.h | 2 +- lib/ui/painting/image_decoder_unittests.cc | 2 +- lib/ui/painting/image_encoding_unittests.cc | 5 +---- 14 files changed, 14 insertions(+), 19 deletions(-) diff --git a/impeller/aiks/testing/context_mock.h b/impeller/aiks/testing/context_mock.h index 1250bef0ec3bc..c28b2f5776e21 100644 --- a/impeller/aiks/testing/context_mock.h +++ b/impeller/aiks/testing/context_mock.h @@ -111,7 +111,7 @@ class ContextMock : public Context { (), (const, override)); - MOCK_METHOD(const std::shared_ptr&, + MOCK_METHOD(std::shared_ptr, GetCommandQueue, (), (const override)); diff --git a/impeller/entity/contents/content_context_unittests.cc b/impeller/entity/contents/content_context_unittests.cc index 37c865e1579a6..ca56680aaf3b0 100644 --- a/impeller/entity/contents/content_context_unittests.cc +++ b/impeller/entity/contents/content_context_unittests.cc @@ -54,9 +54,7 @@ class FakeContext : public Context { std::shared_ptr GetPipelineLibrary() const { return nullptr; } - const std::shared_ptr& GetCommandQueue() const { - FML_UNREACHABLE(); - } + std::shared_ptr GetCommandQueue() const { FML_UNREACHABLE(); } std::shared_ptr CreateCommandBuffer() const { return nullptr; } void Shutdown() {} diff --git a/impeller/renderer/backend/gles/context_gles.cc b/impeller/renderer/backend/gles/context_gles.cc index 95a0c7a6c6424..7629eff28e7cd 100644 --- a/impeller/renderer/backend/gles/context_gles.cc +++ b/impeller/renderer/backend/gles/context_gles.cc @@ -141,7 +141,7 @@ const std::shared_ptr& ContextGLES::GetCapabilities() } // |Context| -const std::shared_ptr& ContextGLES::GetCommandQueue() const { +std::shared_ptr ContextGLES::GetCommandQueue() const { return command_queue_; } diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index a752a80ad9a80..2a0f09aca39b1 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -88,7 +88,7 @@ class ContextGLES final : public Context, const std::shared_ptr& GetCapabilities() const override; // |Context| - const std::shared_ptr& GetCommandQueue() const override; + std::shared_ptr GetCommandQueue() const override; // |Context| void Shutdown() override; diff --git a/impeller/renderer/backend/metal/context_mtl.h b/impeller/renderer/backend/metal/context_mtl.h index ac7220c300843..6497871b28b25 100644 --- a/impeller/renderer/backend/metal/context_mtl.h +++ b/impeller/renderer/backend/metal/context_mtl.h @@ -82,7 +82,7 @@ class ContextMTL final : public Context, std::shared_ptr CreateCommandBuffer() const override; // |Context| - const std::shared_ptr& GetCommandQueue() const override; + std::shared_ptr GetCommandQueue() const override; // |Context| const std::shared_ptr& GetCapabilities() const override; diff --git a/impeller/renderer/backend/metal/context_mtl.mm b/impeller/renderer/backend/metal/context_mtl.mm index 65d021e5dcc78..8b23d4bed64a8 100644 --- a/impeller/renderer/backend/metal/context_mtl.mm +++ b/impeller/renderer/backend/metal/context_mtl.mm @@ -396,7 +396,7 @@ new ContextMTL(device, command_queue, } // |Context| -const std::shared_ptr& ContextMTL::GetCommandQueue() const { +std::shared_ptr ContextMTL::GetCommandQueue() const { return command_queue_ip_; } diff --git a/impeller/renderer/backend/vulkan/context_vk.cc b/impeller/renderer/backend/vulkan/context_vk.cc index ab35ce88e485f..1a625f357a609 100644 --- a/impeller/renderer/backend/vulkan/context_vk.cc +++ b/impeller/renderer/backend/vulkan/context_vk.cc @@ -566,7 +566,7 @@ std::shared_ptr ContextVK::GetGPUTracer() const { return gpu_tracer_; } -const std::shared_ptr& ContextVK::GetCommandQueue() const { +std::shared_ptr ContextVK::GetCommandQueue() const { return command_queue_vk_; } diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index bc55fdfe404c5..07884f1f1ef35 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -165,7 +165,7 @@ class ContextVK final : public Context, return descriptor_pool_recycler_; } - const std::shared_ptr& GetCommandQueue() const override; + std::shared_ptr GetCommandQueue() const override; std::shared_ptr GetGPUTracer() const; diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.cc b/impeller/renderer/backend/vulkan/surface_context_vk.cc index 17c5eed8c6cd9..8abea86d3c419 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.cc +++ b/impeller/renderer/backend/vulkan/surface_context_vk.cc @@ -48,7 +48,7 @@ std::shared_ptr SurfaceContextVK::CreateCommandBuffer() const { return parent_->CreateCommandBuffer(); } -const std::shared_ptr& SurfaceContextVK::GetCommandQueue() const { +std::shared_ptr SurfaceContextVK::GetCommandQueue() const { return parent_->GetCommandQueue(); } diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.h b/impeller/renderer/backend/vulkan/surface_context_vk.h index 65b4020c00b28..56d6b0275dbb5 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.h +++ b/impeller/renderer/backend/vulkan/surface_context_vk.h @@ -64,7 +64,7 @@ class SurfaceContextVK : public Context, const std::shared_ptr& GetCapabilities() const override; // |Context| - const std::shared_ptr& GetCommandQueue() const override; + std::shared_ptr GetCommandQueue() const override; // |Context| void Shutdown() override; diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h index c73caad085a4d..41500a97a113f 100644 --- a/impeller/renderer/context.h +++ b/impeller/renderer/context.h @@ -163,7 +163,7 @@ class Context { virtual std::shared_ptr CreateCommandBuffer() const = 0; /// @brief Return the graphics queue for submitting command buffers. - virtual const std::shared_ptr& GetCommandQueue() const = 0; + virtual std::shared_ptr GetCommandQueue() const = 0; //---------------------------------------------------------------------------- /// @brief Force all pending asynchronous work to finish. This is diff --git a/impeller/renderer/testing/mocks.h b/impeller/renderer/testing/mocks.h index 7f0646e297f69..78b1d388ea67e 100644 --- a/impeller/renderer/testing/mocks.h +++ b/impeller/renderer/testing/mocks.h @@ -166,7 +166,7 @@ class MockImpellerContext : public Context { (), (const, override)); - MOCK_METHOD(const std::shared_ptr&, + MOCK_METHOD(std::shared_ptr, GetCommandQueue, (), (const, override)); diff --git a/lib/ui/painting/image_decoder_unittests.cc b/lib/ui/painting/image_decoder_unittests.cc index 8285123400256..210cab29ee5cd 100644 --- a/lib/ui/painting/image_decoder_unittests.cc +++ b/lib/ui/painting/image_decoder_unittests.cc @@ -67,7 +67,7 @@ class TestImpellerContext : public impeller::Context { return nullptr; } - const std::shared_ptr& GetCommandQueue() const override { + std::shared_ptr GetCommandQueue() const override { FML_UNREACHABLE(); } diff --git a/lib/ui/painting/image_encoding_unittests.cc b/lib/ui/painting/image_encoding_unittests.cc index 38ca0fa52fc47..b035e5963124a 100644 --- a/lib/ui/painting/image_encoding_unittests.cc +++ b/lib/ui/painting/image_encoding_unittests.cc @@ -225,10 +225,7 @@ std::shared_ptr MakeConvertDlImageToSkImageContext( .WillRepeatedly( DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted), Return(fml::Status()))); - EXPECT_CALL(*context, GetCommandQueue) - .WillRepeatedly( - Invoke([command_queue = std::shared_ptr( - command_queue)]() { return command_queue; })); + EXPECT_CALL(*context, GetCommandQueue).WillRepeatedly(Return(command_queue)); return context; } } // namespace From 2c82ff41b7ea66ebc1a76f12b1d6a5724bef642d Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 22:11:53 -0800 Subject: [PATCH 20/21] ++ --- shell/platform/android/android_context_gl_unittests.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/android/android_context_gl_unittests.cc b/shell/platform/android/android_context_gl_unittests.cc index cf64b225d57d5..ec6690b912548 100644 --- a/shell/platform/android/android_context_gl_unittests.cc +++ b/shell/platform/android/android_context_gl_unittests.cc @@ -74,8 +74,7 @@ class TestImpellerContext : public impeller::Context { FML_UNREACHABLE(); } - const std::shared_ptr& GetCommandQueue() - const override { + std::shared_ptr GetCommandQueue() const override { FML_UNREACHABLE(); } From 66f9d96fc4797389b1b7c01a903a9a1b37d1c755 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Mon, 29 Jan 2024 22:33:50 -0800 Subject: [PATCH 21/21] remove uh oh --- impeller/renderer/backend/vulkan/command_queue_vk.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/impeller/renderer/backend/vulkan/command_queue_vk.cc b/impeller/renderer/backend/vulkan/command_queue_vk.cc index fe166b7ee6e5a..11842a10467df 100644 --- a/impeller/renderer/backend/vulkan/command_queue_vk.cc +++ b/impeller/renderer/backend/vulkan/command_queue_vk.cc @@ -24,7 +24,6 @@ CommandQueueVK::~CommandQueueVK() = default; fml::Status CommandQueueVK::Submit( const std::vector>& buffers, const CompletionCallback& completion_callback) { - FML_LOG(ERROR) << "uh -oh!"; if (buffers.empty()) { return fml::Status(fml::StatusCode::kInvalidArgument, "No command buffers provided.");