[Impeller] Reland: add interface for submitting multiple command buffers at once. (flutter/engine#50180)
Reland of: https://github.com/flutter/engine/pull/50139 Metal does not seem to like it when we collect 50+ command buffers at once. Adjust the aiks context logic to regularly flush the cmd buffers.
This commit is contained in:
@@ -5449,6 +5449,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
|
||||
@@ -5521,6 +5523,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
|
||||
@@ -8300,6 +8304,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
|
||||
@@ -8373,6 +8379,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
|
||||
|
||||
@@ -53,6 +53,7 @@ bool AiksContext::Render(const Picture& picture,
|
||||
}
|
||||
|
||||
fml::ScopedCleanupClosure closure([&]() {
|
||||
content_context_->FlushCommandBuffers();
|
||||
if (reset_host_buffer) {
|
||||
content_context_->GetTransientsBuffer().Reset();
|
||||
}
|
||||
|
||||
@@ -141,8 +141,7 @@ TEST_P(AiksTest, CanRenderColorFilterWithInvertColorsDrawPaint) {
|
||||
namespace {
|
||||
bool GenerateMipmap(const std::shared_ptr<Context>& context,
|
||||
std::shared_ptr<Texture> 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>& 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->GetCommandQueue()->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}));
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,11 @@ class ContextMock : public Context {
|
||||
(),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(std::shared_ptr<CommandQueue>,
|
||||
GetCommandQueue,
|
||||
(),
|
||||
(const override));
|
||||
|
||||
MOCK_METHOD(void, Shutdown, (), (override));
|
||||
};
|
||||
|
||||
|
||||
@@ -3,12 +3,23 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <memory>
|
||||
#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<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& completion_callback) {
|
||||
if (completion_callback) {
|
||||
completion_callback(CommandBuffer::Status::kCompleted);
|
||||
}
|
||||
return fml::Status();
|
||||
}
|
||||
|
||||
std::shared_ptr<ContextSpy> ContextSpy::Make() {
|
||||
return std::shared_ptr<ContextSpy>(new ContextSpy());
|
||||
}
|
||||
@@ -50,6 +61,10 @@ std::shared_ptr<ContextMock> ContextSpy::MakeContext(
|
||||
return real_context->GetPipelineLibrary();
|
||||
});
|
||||
|
||||
ON_CALL(*mock_context, GetCommandQueue).WillByDefault([shared_this]() {
|
||||
return shared_this->command_queue_;
|
||||
});
|
||||
|
||||
ON_CALL(*mock_context, CreateCommandBuffer)
|
||||
.WillByDefault([real_context, shared_this]() {
|
||||
auto real_buffer = real_context->CreateCommandBuffer();
|
||||
|
||||
@@ -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<std::shared_ptr<CommandBuffer>>& 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<ContextSpy> {
|
||||
@@ -23,6 +31,8 @@ class ContextSpy : public std::enable_shared_from_this<ContextSpy> {
|
||||
const std::shared_ptr<Context>& real_context);
|
||||
|
||||
std::vector<std::shared_ptr<RecordingRenderPass>> render_passes_;
|
||||
std::shared_ptr<CommandQueue> command_queue_ =
|
||||
std::make_shared<NoopCommandQueue>();
|
||||
|
||||
private:
|
||||
ContextSpy() = default;
|
||||
|
||||
@@ -201,7 +201,8 @@ ContentContext::ContentContext(
|
||||
? std::make_shared<RenderTargetCache>(
|
||||
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<PendingCommandBuffers>()) {
|
||||
if (!context_ || !context_->IsValid()) {
|
||||
return;
|
||||
}
|
||||
@@ -493,9 +494,7 @@ fml::StatusOr<RenderTarget> ContentContext::MakeSubpass(
|
||||
}
|
||||
}
|
||||
|
||||
if (!sub_command_buffer->SubmitCommands()) {
|
||||
return fml::Status(fml::StatusCode::kUnknown, "");
|
||||
}
|
||||
RecordCommandBuffer(std::move(sub_command_buffer));
|
||||
|
||||
return subpass_target;
|
||||
}
|
||||
@@ -548,4 +547,24 @@ void ContentContext::ClearCachedRuntimeEffectPipeline(
|
||||
}
|
||||
}
|
||||
|
||||
void ContentContext::RecordCommandBuffer(
|
||||
std::shared_ptr<CommandBuffer> command_buffer) const {
|
||||
// Metal systems seem to have a limit on the number of command buffers that
|
||||
// can be created concurrently, which appears to be in the range of 50 or so
|
||||
// command buffers. When this limit is hit, creation of further command
|
||||
// buffers will fail. To work around this, we regularly flush the
|
||||
// command buffers on the metal backend.
|
||||
if (GetContext()->GetBackendType() == Context::BackendType::kMetal) {
|
||||
GetContext()->GetCommandQueue()->Submit({command_buffer});
|
||||
} else {
|
||||
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()->GetCommandQueue()->Submit(buffers);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -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"
|
||||
@@ -268,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<std::shared_ptr<CommandBuffer>> command_buffers;
|
||||
};
|
||||
|
||||
/// Pipeline state configuration.
|
||||
///
|
||||
/// Each unique combination of these options requires a different pipeline state
|
||||
@@ -715,6 +722,10 @@ class ContentContext {
|
||||
|
||||
void SetWireframe(bool wireframe);
|
||||
|
||||
void RecordCommandBuffer(std::shared_ptr<CommandBuffer> command_buffer) const;
|
||||
|
||||
void FlushCommandBuffers() const;
|
||||
|
||||
using SubpassCallback =
|
||||
std::function<bool(const ContentContext&, RenderPass&)>;
|
||||
|
||||
@@ -1006,6 +1017,7 @@ class ContentContext {
|
||||
#endif // IMPELLER_ENABLE_3D
|
||||
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
|
||||
std::shared_ptr<HostBuffer> host_buffer_;
|
||||
std::unique_ptr<PendingCommandBuffers> pending_command_buffers_;
|
||||
bool wireframe_ = false;
|
||||
|
||||
ContentContext(const ContentContext&) = delete;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#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/command_queue.h"
|
||||
#include "impeller/renderer/pipeline.h"
|
||||
#include "impeller/renderer/pipeline_descriptor.h"
|
||||
|
||||
@@ -52,6 +54,7 @@ class FakeContext : public Context {
|
||||
std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const {
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const { FML_UNREACHABLE(); }
|
||||
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const { return nullptr; }
|
||||
void Shutdown() {}
|
||||
|
||||
|
||||
@@ -387,11 +387,12 @@ 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 +416,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 +857,7 @@ bool EntityPass::OnRender(
|
||||
collapsed_parent_pass) const {
|
||||
TRACE_EVENT0("impeller", "EntityPass::OnRender");
|
||||
|
||||
const std::shared_ptr<Context>& 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()) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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> context,
|
||||
const ContentContext& renderer,
|
||||
EntityPassTarget& pass_target,
|
||||
uint32_t pass_texture_reads,
|
||||
uint32_t entity_count,
|
||||
std::optional<RenderPassResult> 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<Texture>& 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 "
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#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> 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> context_;
|
||||
const ContentContext& renderer_;
|
||||
EntityPassTarget& pass_target_;
|
||||
std::shared_ptr<CommandBuffer> command_buffer_;
|
||||
std::shared_ptr<RenderPass> pass_;
|
||||
|
||||
@@ -36,10 +36,13 @@ std::unique_ptr<Screenshot> ReadTexture(
|
||||
|
||||
fml::AutoResetWaitableEvent latch;
|
||||
success =
|
||||
command_buffer->SubmitCommands([&latch](CommandBuffer::Status status) {
|
||||
FML_CHECK(status == CommandBuffer::Status::kCompleted);
|
||||
latch.Signal();
|
||||
});
|
||||
surface_context->GetCommandQueue()
|
||||
->Submit({command_buffer},
|
||||
[&latch](CommandBuffer::Status status) {
|
||||
FML_CHECK(status == CommandBuffer::Status::kCompleted);
|
||||
latch.Signal();
|
||||
})
|
||||
.ok();
|
||||
FML_CHECK(success);
|
||||
latch.Wait();
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ bool Playground::OpenPlaygroundHere(
|
||||
ImGui_ImplImpeller_RenderDrawData(ImGui::GetDrawData(), *pass);
|
||||
|
||||
pass->EncodeCommands();
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!renderer->GetContext()->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -350,7 +350,7 @@ bool Playground::OpenPlaygroundHere(SinglePassCallback pass_callback) {
|
||||
}
|
||||
|
||||
pass->EncodeCommands();
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -422,7 +422,7 @@ static std::shared_ptr<Texture> CreateTextureForDecompressedImage(
|
||||
blit_pass->SetLabel("Mipmap Blit Pass");
|
||||
blit_pass->GenerateMipmap(texture);
|
||||
blit_pass->EncodeCommands(context->GetResourceAllocator());
|
||||
if (!command_buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
|
||||
FML_DLOG(ERROR) << "Failed to submit blit pass command buffer.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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/command_queue.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -67,6 +68,7 @@ ContextGLES::ContextGLES(
|
||||
}
|
||||
gpu_tracer_ = std::make_shared<GPUTracerGLES>(GetReactor()->GetProcTable(),
|
||||
enable_gpu_tracing);
|
||||
command_queue_ = std::make_shared<CommandQueue>();
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
@@ -138,4 +140,9 @@ const std::shared_ptr<const Capabilities>& ContextGLES::GetCapabilities()
|
||||
return device_capabilities_;
|
||||
}
|
||||
|
||||
// |Context|
|
||||
std::shared_ptr<CommandQueue> ContextGLES::GetCommandQueue() const {
|
||||
return command_queue_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#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"
|
||||
|
||||
namespace impeller {
|
||||
@@ -48,6 +49,7 @@ class ContextGLES final : public Context,
|
||||
std::shared_ptr<PipelineLibraryGLES> pipeline_library_;
|
||||
std::shared_ptr<SamplerLibraryGLES> sampler_library_;
|
||||
std::shared_ptr<AllocatorGLES> resource_allocator_;
|
||||
std::shared_ptr<CommandQueue> command_queue_;
|
||||
std::shared_ptr<GPUTracerGLES> gpu_tracer_;
|
||||
|
||||
// Note: This is stored separately from the ProcTableGLES CapabilitiesGLES
|
||||
@@ -85,6 +87,9 @@ class ContextGLES final : public Context,
|
||||
// |Context|
|
||||
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
|
||||
|
||||
// |Context|
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const override;
|
||||
|
||||
// |Context|
|
||||
void Shutdown() override;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#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"
|
||||
|
||||
#if TARGET_OS_SIMULATOR
|
||||
@@ -80,6 +81,9 @@ class ContextMTL final : public Context,
|
||||
// |Context|
|
||||
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override;
|
||||
|
||||
// |Context|
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const override;
|
||||
|
||||
// |Context|
|
||||
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
|
||||
|
||||
@@ -126,6 +130,7 @@ class ContextMTL final : public Context,
|
||||
#endif // IMPELLER_DEBUG
|
||||
std::deque<std::function<void()>> tasks_awaiting_gpu_;
|
||||
std::unique_ptr<SyncSwitchObserver> sync_switch_observer_;
|
||||
std::shared_ptr<CommandQueue> command_queue_ip_;
|
||||
bool is_valid_ = false;
|
||||
|
||||
ContextMTL(
|
||||
|
||||
@@ -128,6 +128,7 @@ ContextMTL::ContextMTL(
|
||||
|
||||
device_capabilities_ =
|
||||
InferMetalCapabilities(device_, PixelFormat::kB8G8R8A8UNormInt);
|
||||
command_queue_ip_ = std::make_shared<CommandQueue>();
|
||||
#ifdef IMPELLER_DEBUG
|
||||
gpu_tracer_ = std::make_shared<GPUTracerMTL>();
|
||||
#endif // IMPELLER_DEBUG
|
||||
@@ -394,4 +395,9 @@ void ContextMTL::SyncSwitchObserver::OnSyncSwitchUpdate(bool new_is_disabled) {
|
||||
}
|
||||
}
|
||||
|
||||
// |Context|
|
||||
std::shared_ptr<CommandQueue> ContextMTL::GetCommandQueue() const {
|
||||
return command_queue_ip_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -242,7 +242,7 @@ bool SurfaceMTL::Present() const {
|
||||
blit_pass->AddCopy(source_texture_, destination_texture_, std::nullopt,
|
||||
clip_rect_->GetOrigin());
|
||||
blit_pass->EncodeCommands(context->GetResourceAllocator());
|
||||
if (!blit_command_buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({blit_command_buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#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<CommandEncoderVK>& 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() {}
|
||||
|
||||
@@ -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<const DeviceHolder> 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<vk::CommandBuffer> 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 {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <optional>
|
||||
|
||||
#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"
|
||||
@@ -60,8 +61,6 @@ class CommandEncoderVK {
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Submit(SubmitCallback callback = {});
|
||||
|
||||
bool Track(std::shared_ptr<SharedObjectVK> object);
|
||||
|
||||
bool Track(std::shared_ptr<const DeviceBuffer> buffer);
|
||||
@@ -82,12 +81,15 @@ class CommandEncoderVK {
|
||||
|
||||
void InsertDebugMarker(std::string_view label) const;
|
||||
|
||||
bool EndCommandBuffer() const;
|
||||
|
||||
fml::StatusOr<vk::DescriptorSet> AllocateDescriptorSets(
|
||||
const vk::DescriptorSetLayout& layout,
|
||||
const ContextVK& context);
|
||||
|
||||
private:
|
||||
friend class ContextVK;
|
||||
friend class CommandQueueVK;
|
||||
|
||||
std::weak_ptr<const DeviceHolder> device_holder_;
|
||||
std::shared_ptr<TrackedObjectsVK> tracked_objects_;
|
||||
|
||||
@@ -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,13 +49,13 @@ TEST(CommandEncoderVKTest, CleanupAfterSubmit) {
|
||||
fml::AutoResetWaitableEvent wait_for_thread_join;
|
||||
auto context = MockVulkanContextBuilder().Build();
|
||||
std::thread thread([&] {
|
||||
CommandEncoderFactoryVK factory(context);
|
||||
std::shared_ptr<CommandEncoderVK> encoder = factory.Create();
|
||||
encoder->Submit([&](bool success) {
|
||||
ASSERT_TRUE(success);
|
||||
wait_for_thread_join.Wait();
|
||||
wait_for_submit.Signal();
|
||||
});
|
||||
auto buffer = context->CreateCommandBuffer();
|
||||
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();
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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/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/tracked_objects_vk.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
CommandQueueVK::CommandQueueVK(const std::weak_ptr<ContextVK>& context)
|
||||
: context_(context) {}
|
||||
|
||||
CommandQueueVK::~CommandQueueVK() = default;
|
||||
|
||||
fml::Status CommandQueueVK::Submit(
|
||||
const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& completion_callback) {
|
||||
if (buffers.empty()) {
|
||||
return fml::Status(fml::StatusCode::kInvalidArgument,
|
||||
"No command buffers provided.");
|
||||
}
|
||||
// Success or failure, you only get to submit once.
|
||||
fml::ScopedCleanupClosure reset([&]() {
|
||||
if (completion_callback) {
|
||||
completion_callback(CommandBuffer::Status::kError);
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<vk::CommandBuffer> vk_buffers;
|
||||
std::vector<std::shared_ptr<TrackedObjectsVK>> tracked_objects;
|
||||
vk_buffers.reserve(buffers.size());
|
||||
tracked_objects.reserve(buffers.size());
|
||||
for (const std::shared_ptr<CommandBuffer>& 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), [completion_callback, tracked_objects = std::move(
|
||||
tracked_objects)]() mutable {
|
||||
// Ensure tracked objects are destructed before calling any final
|
||||
// callbacks.
|
||||
tracked_objects.clear();
|
||||
if (completion_callback) {
|
||||
completion_callback(CommandBuffer::Status::kCompleted);
|
||||
}
|
||||
});
|
||||
if (!added_fence) {
|
||||
return fml::Status(fml::StatusCode::kCancelled, "Failed to add fence.");
|
||||
}
|
||||
reset.Release();
|
||||
return fml::Status();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
@@ -0,0 +1,34 @@
|
||||
// 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<ContextVK>& context);
|
||||
|
||||
~CommandQueueVK() override;
|
||||
|
||||
fml::Status Submit(
|
||||
const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& completion_callback = {}) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<ContextVK> context_;
|
||||
|
||||
CommandQueueVK(const CommandQueueVK&) = delete;
|
||||
|
||||
CommandQueueVK& operator=(const CommandQueueVK&) = delete;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_COMMAND_QUEUE_VK_H_
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "impeller/renderer/backend/vulkan/context_vk.h"
|
||||
|
||||
#include "fml/concurrent_message_loop.h"
|
||||
#include "impeller/renderer/backend/vulkan/command_queue_vk.h"
|
||||
|
||||
#ifdef FML_OS_ANDROID
|
||||
#include <pthread.h>
|
||||
@@ -26,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"
|
||||
@@ -445,6 +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);
|
||||
command_queue_vk_ = std::make_shared<CommandQueueVK>(weak_from_this());
|
||||
is_valid_ = true;
|
||||
|
||||
// Create the GPU Tracer later because it depends on state from
|
||||
@@ -563,4 +566,8 @@ std::shared_ptr<GPUTracerVK> ContextVK::GetGPUTracer() const {
|
||||
return gpu_tracer_;
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandQueue> ContextVK::GetCommandQueue() const {
|
||||
return command_queue_vk_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#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"
|
||||
|
||||
namespace impeller {
|
||||
@@ -35,6 +36,7 @@ class ResourceManagerVK;
|
||||
class SurfaceContextVK;
|
||||
class GPUTracerVK;
|
||||
class DescriptorPoolRecyclerVK;
|
||||
class CommandQueueVK;
|
||||
|
||||
class ContextVK final : public Context,
|
||||
public BackendCast<ContextVK, Context>,
|
||||
@@ -163,6 +165,8 @@ class ContextVK final : public Context,
|
||||
return descriptor_pool_recycler_;
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const override;
|
||||
|
||||
std::shared_ptr<GPUTracerVK> GetGPUTracer() const;
|
||||
|
||||
void RecordFrameEndTime() const;
|
||||
@@ -197,6 +201,7 @@ class ContextVK final : public Context,
|
||||
std::unique_ptr<fml::Thread> queue_submit_thread_;
|
||||
std::shared_ptr<GPUTracerVK> gpu_tracer_;
|
||||
std::shared_ptr<DescriptorPoolRecyclerVK> descriptor_pool_recycler_;
|
||||
std::shared_ptr<CommandQueue> command_queue_vk_;
|
||||
|
||||
bool sync_presentation_ = false;
|
||||
const uint64_t hash_;
|
||||
|
||||
@@ -33,7 +33,7 @@ GPUTracerVK::GPUTracerVK(std::weak_ptr<ContextVK> context)
|
||||
// The device does not support timestamp queries.
|
||||
return;
|
||||
}
|
||||
// Disable tracing in release mode.
|
||||
// Disable tracing in release mode.
|
||||
#ifdef IMPELLER_DEBUG
|
||||
enabled_ = true;
|
||||
#endif // IMPELLER_DEBUG
|
||||
@@ -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.GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
VALIDATION_LOG << "Failed to reset query pool for trace events.";
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ std::shared_ptr<CommandBuffer> SurfaceContextVK::CreateCommandBuffer() const {
|
||||
return parent_->CreateCommandBuffer();
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandQueue> SurfaceContextVK::GetCommandQueue() const {
|
||||
return parent_->GetCommandQueue();
|
||||
}
|
||||
|
||||
const std::shared_ptr<const Capabilities>& SurfaceContextVK::GetCapabilities()
|
||||
const {
|
||||
return parent_->GetCapabilities();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/command_queue.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -62,6 +63,9 @@ class SurfaceContextVK : public Context,
|
||||
// |Context|
|
||||
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
|
||||
|
||||
// |Context|
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const override;
|
||||
|
||||
// |Context|
|
||||
void Shutdown() override;
|
||||
|
||||
|
||||
@@ -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<fml::CountDownLatch>(1u);
|
||||
|
||||
if (!cmd_buffer->SubmitCommands(
|
||||
[latch](CommandBuffer::Status status) { latch->CountDown(); })) {
|
||||
if (!context->GetCommandQueue()
|
||||
->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<fml::CountDownLatch>(1u);
|
||||
if (!cmd_buffer->SubmitCommands(
|
||||
[latch](CommandBuffer::Status status) { latch->CountDown(); })) {
|
||||
if (!context->GetCommandQueue()
|
||||
->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<fml::CountDownLatch>(1u);
|
||||
if (!cmd_buffer->SubmitCommands(
|
||||
[latch](CommandBuffer::Status status) { latch->CountDown(); })) {
|
||||
if (!context->GetCommandQueue()
|
||||
->Submit(
|
||||
{cmd_buffer},
|
||||
[latch](CommandBuffer::Status status) { latch->CountDown(); })
|
||||
.ok()) {
|
||||
GTEST_FAIL() << "Failed to submit cmd buffer";
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ bool TextureVK::OnSetContents(const uint8_t* contents,
|
||||
}
|
||||
}
|
||||
|
||||
return cmd_buffer->SubmitCommands();
|
||||
return context->GetCommandQueue()->Submit({cmd_buffer}).ok();
|
||||
}
|
||||
|
||||
bool TextureVK::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
|
||||
|
||||
@@ -34,31 +34,6 @@ void CommandBuffer::WaitUntilScheduled() {
|
||||
return OnWaitUntilScheduled();
|
||||
}
|
||||
|
||||
bool CommandBuffer::EncodeAndSubmit(
|
||||
const std::shared_ptr<RenderPass>& 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<BlitPass>& blit_pass,
|
||||
const std::shared_ptr<Allocator>& allocator) {
|
||||
if (!blit_pass->IsValid() || !IsValid()) {
|
||||
return false;
|
||||
}
|
||||
if (!blit_pass->EncodeCommands(allocator)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return SubmitCommands(nullptr);
|
||||
}
|
||||
|
||||
std::shared_ptr<RenderPass> CommandBuffer::CreateRenderPass(
|
||||
const RenderTarget& render_target) {
|
||||
auto pass = OnCreateRenderPass(render_target);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#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 CommandQueue;
|
||||
|
||||
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<RenderPass>& 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<BlitPass>& blit_pass,
|
||||
const std::shared_ptr<Allocator>& allocator);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Force execution of pending GPU commands.
|
||||
///
|
||||
@@ -143,6 +107,21 @@ class CommandBuffer {
|
||||
virtual std::shared_ptr<ComputePass> OnCreateComputePass() = 0;
|
||||
|
||||
private:
|
||||
friend class CommandQueue;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @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;
|
||||
|
||||
33
engine/src/flutter/impeller/renderer/command_queue.cc
Normal file
33
engine/src/flutter/impeller/renderer/command_queue.cc
Normal file
@@ -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.
|
||||
|
||||
#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<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& completion_callback) {
|
||||
if (buffers.empty()) {
|
||||
if (completion_callback) {
|
||||
completion_callback(CommandBuffer::Status::kError);
|
||||
}
|
||||
return fml::Status(fml::StatusCode::kInvalidArgument,
|
||||
"No command buffers provided.");
|
||||
}
|
||||
for (const std::shared_ptr<CommandBuffer>& buffer : buffers) {
|
||||
if (!buffer->SubmitCommands(completion_callback)) {
|
||||
return fml::Status(fml::StatusCode::kCancelled,
|
||||
"Failed to submit command buffer.");
|
||||
}
|
||||
}
|
||||
return fml::Status();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
50
engine/src/flutter/impeller/renderer/command_queue.h
Normal file
50
engine/src/flutter/impeller/renderer/command_queue.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// 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_COMMAND_QUEUE_H_
|
||||
#define FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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 CommandQueue {
|
||||
public:
|
||||
using CompletionCallback = std::function<void(CommandBuffer::Status)>;
|
||||
|
||||
CommandQueue();
|
||||
|
||||
virtual ~CommandQueue();
|
||||
|
||||
/// @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.
|
||||
///
|
||||
/// 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<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& completion_callback = {});
|
||||
|
||||
private:
|
||||
CommandQueue(const CommandQueue&) = delete;
|
||||
|
||||
CommandQueue& operator=(const CommandQueue&) = delete;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
#endif // FLUTTER_IMPELLER_RENDERER_COMMAND_QUEUE_H_
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#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->GetCommandQueue()->Submit({cmd_buffer}, callback).ok()) {
|
||||
return Status::kCommandInvalid;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
ASSERT_TRUE(
|
||||
context->GetCommandQueue()
|
||||
->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<kCount>));
|
||||
auto view = DeviceBuffer::AsBufferView(output_buffer);
|
||||
EXPECT_EQ(view.range.length, sizeof(CS::Output<kCount>));
|
||||
|
||||
CS::Output<kCount>* output =
|
||||
reinterpret_cast<CS::Output<kCount>*>(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();
|
||||
}));
|
||||
CS::Output<kCount>* output =
|
||||
reinterpret_cast<CS::Output<kCount>*>(
|
||||
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);
|
||||
ASSERT_TRUE(
|
||||
context->GetCommandQueue()
|
||||
->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<kCount>));
|
||||
auto view = DeviceBuffer::AsBufferView(output_buffer);
|
||||
EXPECT_EQ(view.range.length,
|
||||
sizeof(CS::OutputData<kCount>));
|
||||
|
||||
CS::OutputData<kCount>* output = reinterpret_cast<CS::OutputData<kCount>*>(
|
||||
output_buffer->OnGetContents());
|
||||
EXPECT_TRUE(output);
|
||||
CS::OutputData<kCount>* output =
|
||||
reinterpret_cast<CS::OutputData<kCount>*>(
|
||||
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();
|
||||
}));
|
||||
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);
|
||||
ASSERT_TRUE(
|
||||
context->GetCommandQueue()
|
||||
->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<kCount>));
|
||||
auto view = DeviceBuffer::AsBufferView(output_buffer);
|
||||
EXPECT_EQ(view.range.length,
|
||||
sizeof(CS::OutputData<kCount>));
|
||||
|
||||
CS::OutputData<kCount>* output = reinterpret_cast<CS::OutputData<kCount>*>(
|
||||
output_buffer->OnGetContents());
|
||||
EXPECT_TRUE(output);
|
||||
EXPECT_EQ(output->data[kCount - 1], kCount - 1);
|
||||
latch.Signal();
|
||||
}));
|
||||
CS::OutputData<kCount>* output =
|
||||
reinterpret_cast<CS::OutputData<kCount>*>(
|
||||
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->GetCommandQueue()->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);
|
||||
ASSERT_TRUE(
|
||||
context->GetCommandQueue()
|
||||
->Submit({cmd_buffer},
|
||||
[&latch, &output_buffer_1,
|
||||
&output_buffer_2](CommandBuffer::Status status) {
|
||||
EXPECT_EQ(status, CommandBuffer::Status::kCompleted);
|
||||
|
||||
CS1::Output<kCount2>* output_1 = reinterpret_cast<CS1::Output<kCount2>*>(
|
||||
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));
|
||||
CS1::Output<kCount2>* output_1 =
|
||||
reinterpret_cast<CS1::Output<kCount2>*>(
|
||||
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<kCount2>* output_2 = reinterpret_cast<CS2::Output<kCount2>*>(
|
||||
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));
|
||||
CS2::Output<kCount2>* output_2 =
|
||||
reinterpret_cast<CS2::Output<kCount2>*>(
|
||||
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();
|
||||
}));
|
||||
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);
|
||||
ASSERT_TRUE(
|
||||
context->GetCommandQueue()
|
||||
->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<kCount>));
|
||||
auto view = DeviceBuffer::AsBufferView(output_buffer);
|
||||
EXPECT_EQ(view.range.length, sizeof(CS::Output<kCount>));
|
||||
|
||||
CS::Output<kCount>* output =
|
||||
reinterpret_cast<CS::Output<kCount>*>(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();
|
||||
}));
|
||||
CS::Output<kCount>* output =
|
||||
reinterpret_cast<CS::Output<kCount>*>(
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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/capabilities.h"
|
||||
#include "impeller/renderer/pool.h"
|
||||
#include "impeller/renderer/command_queue.h"
|
||||
#include "impeller/renderer/sampler_library.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -163,6 +162,9 @@ class Context {
|
||||
///
|
||||
virtual std::shared_ptr<CommandBuffer> CreateCommandBuffer() const = 0;
|
||||
|
||||
/// @brief Return the graphics queue for submitting command buffers.
|
||||
virtual std::shared_ptr<CommandQueue> GetCommandQueue() const = 0;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Force all pending asynchronous work to finish. This is
|
||||
/// achieved by deleting all owned concurrent message loops.
|
||||
|
||||
@@ -554,7 +554,7 @@ TEST_P(RendererTest, CanBlitTextureToTexture) {
|
||||
pass->EncodeCommands();
|
||||
}
|
||||
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->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->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -690,7 +689,7 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) {
|
||||
pass->Draw().ok();
|
||||
}
|
||||
pass->EncodeCommands();
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -812,7 +811,7 @@ TEST_P(RendererTest, CanGenerateMipmaps) {
|
||||
pass->EncodeCommands();
|
||||
}
|
||||
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
host_buffer->Reset();
|
||||
@@ -1257,7 +1256,7 @@ TEST_P(RendererTest, StencilMask) {
|
||||
pass->EncodeCommands();
|
||||
}
|
||||
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return false;
|
||||
}
|
||||
host_buffer->Reset();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#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/render_pass.h"
|
||||
#include "impeller/renderer/render_target.h"
|
||||
@@ -164,6 +165,11 @@ class MockImpellerContext : public Context {
|
||||
GetCapabilities,
|
||||
(),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(std::shared_ptr<CommandQueue>,
|
||||
GetCommandQueue,
|
||||
(),
|
||||
(const, override));
|
||||
};
|
||||
|
||||
class MockTexture : public Texture {
|
||||
@@ -200,6 +206,15 @@ class MockCapabilities : public Capabilities {
|
||||
MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override));
|
||||
};
|
||||
|
||||
class MockCommandQueue : public CommandQueue {
|
||||
public:
|
||||
MOCK_METHOD(fml::Status,
|
||||
Submit,
|
||||
(const std::vector<std::shared_ptr<CommandBuffer>>& buffers,
|
||||
const CompletionCallback& cb),
|
||||
(override));
|
||||
};
|
||||
|
||||
class MockSamplerLibrary : public SamplerLibrary {
|
||||
public:
|
||||
MOCK_METHOD(const std::unique_ptr<const Sampler>&,
|
||||
|
||||
@@ -53,7 +53,10 @@ bool Scene::Render(const RenderTarget& render_target,
|
||||
|
||||
// TODO(bdero): Do post processing.
|
||||
|
||||
if (!command_buffer->SubmitCommands()) {
|
||||
if (!scene_context_->GetContext()
|
||||
->GetCommandQueue()
|
||||
->Submit({command_buffer})
|
||||
.ok()) {
|
||||
FML_LOG(ERROR) << "Failed to submit command buffer.";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,10 @@ namespace gpu {
|
||||
IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, CommandBuffer);
|
||||
|
||||
CommandBuffer::CommandBuffer(
|
||||
std::shared_ptr<impeller::Context> context,
|
||||
std::shared_ptr<impeller::CommandBuffer> 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_->GetCommandQueue()->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_->GetCommandQueue()
|
||||
->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<flutter::gpu::CommandBuffer>(
|
||||
contextWrapper->GetContext(),
|
||||
contextWrapper->GetContext()->CreateCommandBuffer());
|
||||
res->AssociateWithDartWrapper(wrapper);
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ class CommandBuffer : public RefCountedDartWrappable<CommandBuffer> {
|
||||
FML_FRIEND_MAKE_REF_COUNTED(CommandBuffer);
|
||||
|
||||
public:
|
||||
explicit CommandBuffer(
|
||||
std::shared_ptr<impeller::CommandBuffer> command_buffer);
|
||||
CommandBuffer(std::shared_ptr<impeller::Context> context,
|
||||
std::shared_ptr<impeller::CommandBuffer> command_buffer);
|
||||
|
||||
std::shared_ptr<impeller::CommandBuffer> GetCommandBuffer();
|
||||
|
||||
@@ -32,6 +32,7 @@ class CommandBuffer : public RefCountedDartWrappable<CommandBuffer> {
|
||||
~CommandBuffer() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<impeller::Context> context_;
|
||||
std::shared_ptr<impeller::CommandBuffer> command_buffer_;
|
||||
std::vector<std::shared_ptr<impeller::RenderPass>> encodables_;
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@ static std::pair<sk_sp<DlImage>, std::string> UnsafeUploadTextureToPrivate(
|
||||
}
|
||||
|
||||
blit_pass->EncodeCommands(context->GetResourceAllocator());
|
||||
if (!command_buffer->SubmitCommands()) {
|
||||
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 (!command_buffer->SubmitCommands()) {
|
||||
if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
|
||||
decode_error = "Failed to submit blit pass command buffer.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
@@ -65,6 +67,10 @@ class TestImpellerContext : public impeller::Context {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const override {
|
||||
command_buffer_count_ += 1;
|
||||
return nullptr;
|
||||
|
||||
@@ -178,7 +178,9 @@ void ImageEncodingImpeller::ConvertDlImageToSkImage(
|
||||
encode_task(sk_image);
|
||||
};
|
||||
|
||||
if (!command_buffer->SubmitCommands(completion)) {
|
||||
if (!impeller_context->GetCommandQueue()
|
||||
->Submit({command_buffer}, completion)
|
||||
.ok()) {
|
||||
FML_LOG(ERROR) << "Failed to submit commands.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,11 +193,13 @@ 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::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<impeller::Context> MakeConvertDlImageToSkImageContext(
|
||||
auto command_buffer = std::make_shared<MockCommandBuffer>(context);
|
||||
auto allocator = std::make_shared<MockAllocator>();
|
||||
auto blit_pass = std::make_shared<MockBlitPass>();
|
||||
auto command_queue = std::make_shared<MockCommandQueue>();
|
||||
impeller::DeviceBufferDescriptor device_buffer_desc;
|
||||
device_buffer_desc.size = buffer.size();
|
||||
auto device_buffer = std::make_shared<MockDeviceBuffer>(device_buffer_desc);
|
||||
@@ -215,13 +218,14 @@ std::shared_ptr<impeller::Context> 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()));
|
||||
EXPECT_CALL(*command_queue, Submit(_, _))
|
||||
.WillRepeatedly(
|
||||
DoAll(InvokeArgument<1>(impeller::CommandBuffer::Status::kCompleted),
|
||||
Return(fml::Status())));
|
||||
EXPECT_CALL(*context, GetCommandQueue).WillRepeatedly(Return(command_queue));
|
||||
return context;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -911,7 +911,9 @@ ScreenshotLayerTreeAsImageImpeller(
|
||||
sk_data = SkData::MakeWithCopy(buffer->OnGetContents(), buffer_desc.size);
|
||||
};
|
||||
|
||||
if (!command_buffer->SubmitCommands(completion)) {
|
||||
if (!impeller_context->GetCommandQueue()
|
||||
->Submit({command_buffer}, completion)
|
||||
.ok()) {
|
||||
FML_LOG(ERROR) << "Failed to submit commands.";
|
||||
}
|
||||
latch.Wait();
|
||||
|
||||
@@ -74,6 +74,10 @@ class TestImpellerContext : public impeller::Context {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
std::shared_ptr<impeller::CommandQueue> GetCommandQueue() const override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
void Shutdown() override { did_shutdown = true; }
|
||||
|
||||
bool did_shutdown = false;
|
||||
|
||||
@@ -95,7 +95,7 @@ void ImageExternalTextureVK::ProcessFrame(PaintContext& context,
|
||||
if (!texture->SetLayout(barrier)) {
|
||||
return;
|
||||
}
|
||||
if (!buffer->SubmitCommands()) {
|
||||
if (!impeller_context_->GetCommandQueue()->Submit({buffer}).ok()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user