diff --git a/ci/licenses_golden/excluded_files b/ci/licenses_golden/excluded_files index 9847624da5f78..e722a97a9cd25 100644 --- a/ci/licenses_golden/excluded_files +++ b/ci/licenses_golden/excluded_files @@ -146,7 +146,6 @@ ../../../flutter/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents_unittests.cc ../../../flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents_unittests.cc ../../../flutter/impeller/entity/contents/filters/inputs/filter_input_unittests.cc -../../../flutter/impeller/entity/contents/host_buffer_unittests.cc ../../../flutter/impeller/entity/contents/test ../../../flutter/impeller/entity/contents/tiled_texture_contents_unittests.cc ../../../flutter/impeller/entity/contents/vertices_contents_unittests.cc @@ -188,6 +187,7 @@ ../../../flutter/impeller/renderer/compute_subgroup_unittests.cc ../../../flutter/impeller/renderer/compute_unittests.cc ../../../flutter/impeller/renderer/device_buffer_unittests.cc +../../../flutter/impeller/renderer/host_buffer_unittests.cc ../../../flutter/impeller/renderer/pipeline_descriptor_unittests.cc ../../../flutter/impeller/renderer/pool_unittests.cc ../../../flutter/impeller/renderer/renderer_dart_unittests.cc diff --git a/impeller/aiks/aiks_context.cc b/impeller/aiks/aiks_context.cc index 01da062362acd..86baab74d7953 100644 --- a/impeller/aiks/aiks_context.cc +++ b/impeller/aiks/aiks_context.cc @@ -40,9 +40,7 @@ ContentContext& AiksContext::GetContentContext() const { return *content_context_; } -bool AiksContext::Render(const Picture& picture, - RenderTarget& render_target, - bool reset_host_buffer) { +bool AiksContext::Render(const Picture& picture, RenderTarget& render_target) { if (!IsValid()) { return false; } @@ -50,9 +48,6 @@ bool AiksContext::Render(const Picture& picture, if (picture.pass) { return picture.pass->Render(*content_context_, render_target); } - if (reset_host_buffer) { - content_context_->GetTransientsBuffer().Reset(); - } return true; } diff --git a/impeller/aiks/aiks_context.h b/impeller/aiks/aiks_context.h index ad8d6429c4d01..650465d770dfc 100644 --- a/impeller/aiks/aiks_context.h +++ b/impeller/aiks/aiks_context.h @@ -39,9 +39,7 @@ class AiksContext { ContentContext& GetContentContext() const; - bool Render(const Picture& picture, - RenderTarget& render_target, - bool reset_host_buffer); + bool Render(const Picture& picture, RenderTarget& render_target); private: std::shared_ptr context_; diff --git a/impeller/aiks/aiks_playground.cc b/impeller/aiks/aiks_playground.cc index 8714b54697ac2..b9ed2a828e7ae 100644 --- a/impeller/aiks/aiks_playground.cc +++ b/impeller/aiks/aiks_playground.cc @@ -53,7 +53,7 @@ bool AiksPlayground::OpenPlaygroundHere(AiksPlaygroundCallback callback) { if (!picture.has_value()) { return false; } - return renderer.Render(*picture, render_target, true); + return renderer.Render(*picture, render_target); }); } diff --git a/impeller/aiks/picture.cc b/impeller/aiks/picture.cc index ea07dfd27a58c..907bbf6ca49ba 100644 --- a/impeller/aiks/picture.cc +++ b/impeller/aiks/picture.cc @@ -84,7 +84,7 @@ std::shared_ptr Picture::RenderToTexture( return nullptr; } - if (!context.Render(*this, target, false)) { + if (!context.Render(*this, target)) { VALIDATION_LOG << "Could not render Picture to Texture."; return nullptr; } diff --git a/impeller/base/allocation.h b/impeller/base/allocation.h index bd9b2370ef7fb..dd1b06befa6fe 100644 --- a/impeller/base/allocation.h +++ b/impeller/base/allocation.h @@ -6,6 +6,7 @@ #define FLUTTER_IMPELLER_BASE_ALLOCATION_H_ #include +#include #include #include "flutter/fml/mapping.h" diff --git a/impeller/core/buffer.h b/impeller/core/buffer.h index df58b56c0c62c..0664f1afc53b3 100644 --- a/impeller/core/buffer.h +++ b/impeller/core/buffer.h @@ -16,7 +16,8 @@ class Buffer { public: virtual ~Buffer(); - virtual std::shared_ptr GetDeviceBuffer() const = 0; + virtual std::shared_ptr GetDeviceBuffer( + Allocator& allocator) const = 0; }; } // namespace impeller diff --git a/impeller/core/device_buffer.cc b/impeller/core/device_buffer.cc index 5c6ecf4077ed3..741a4d7ee2386 100644 --- a/impeller/core/device_buffer.cc +++ b/impeller/core/device_buffer.cc @@ -11,12 +11,11 @@ DeviceBuffer::DeviceBuffer(DeviceBufferDescriptor desc) : desc_(desc) {} DeviceBuffer::~DeviceBuffer() = default; // |Buffer| -std::shared_ptr DeviceBuffer::GetDeviceBuffer() const { +std::shared_ptr DeviceBuffer::GetDeviceBuffer( + Allocator& allocator) const { return shared_from_this(); } -void DeviceBuffer::Flush(std::optional range) const {} - BufferView DeviceBuffer::AsBufferView() const { BufferView view; view.buffer = shared_from_this(); diff --git a/impeller/core/device_buffer.h b/impeller/core/device_buffer.h index 7f0cb99f3ba3f..c3ed289922d30 100644 --- a/impeller/core/device_buffer.h +++ b/impeller/core/device_buffer.h @@ -38,21 +38,13 @@ class DeviceBuffer : public Buffer, uint16_t row_bytes) const; // |Buffer| - std::shared_ptr GetDeviceBuffer() const; + std::shared_ptr GetDeviceBuffer( + Allocator& allocator) const; const DeviceBufferDescriptor& GetDeviceBufferDescriptor() const; virtual uint8_t* OnGetContents() const = 0; - /// Make any pending writes visible to the GPU. - /// - /// This method must be called if the device pointer provided by - /// [OnGetContents] is written to without using [CopyHostBuffer]. On Devices - /// with coherent host memory, this method will not perform extra work. - /// - /// If the range is not provided, the entire buffer is flushed. - virtual void Flush(std::optional range = std::nullopt) const; - protected: const DeviceBufferDescriptor desc_; diff --git a/impeller/core/host_buffer.cc b/impeller/core/host_buffer.cc index fdfc30d2e26a0..7e2eae85ac97f 100644 --- a/impeller/core/host_buffer.cc +++ b/impeller/core/host_buffer.cc @@ -4,33 +4,22 @@ #include "impeller/core/host_buffer.h" +#include #include -#include + +#include "flutter/fml/logging.h" #include "impeller/core/allocator.h" #include "impeller/core/buffer_view.h" #include "impeller/core/device_buffer.h" -#include "impeller/core/device_buffer_descriptor.h" -#include "impeller/core/formats.h" namespace impeller { -constexpr size_t kAllocatorBlockSize = 1024000; // 1024 Kb. - -std::shared_ptr HostBuffer::Create( - const std::shared_ptr& allocator) { - return std::shared_ptr(new HostBuffer(allocator)); +std::shared_ptr HostBuffer::Create() { + return std::shared_ptr(new HostBuffer()); } -HostBuffer::HostBuffer(const std::shared_ptr& allocator) { - state_->allocator = allocator; - DeviceBufferDescriptor desc; - desc.size = kAllocatorBlockSize; - desc.storage_mode = StorageMode::kHostVisible; - for (auto i = 0u; i < kHostBufferArenaSize; i++) { - state_->device_buffers[i].push_back(allocator->CreateBuffer(desc)); - } -} +HostBuffer::HostBuffer() = default; HostBuffer::~HostBuffer() = default; @@ -41,143 +30,104 @@ void HostBuffer::SetLabel(std::string label) { BufferView HostBuffer::Emplace(const void* buffer, size_t length, size_t align) { - auto [data, range, device_buffer] = state_->Emplace(buffer, length, align); + auto [device_buffer, range] = state_->Emplace(buffer, length, align); if (!device_buffer) { return {}; } - return BufferView{std::move(device_buffer), data, range}; + return BufferView{state_, device_buffer, range}; } BufferView HostBuffer::Emplace(const void* buffer, size_t length) { - auto [data, range, device_buffer] = state_->Emplace(buffer, length); + auto [device_buffer, range] = state_->Emplace(buffer, length); if (!device_buffer) { return {}; } - return BufferView{std::move(device_buffer), data, range}; + return BufferView{state_, device_buffer, range}; } BufferView HostBuffer::Emplace(size_t length, size_t align, const EmplaceProc& cb) { - auto [data, range, device_buffer] = state_->Emplace(length, align, cb); - if (!device_buffer) { + auto [buffer, range] = state_->Emplace(length, align, cb); + if (!buffer) { return {}; } - return BufferView{std::move(device_buffer), data, range}; + return BufferView{state_, buffer, range}; } -HostBuffer::TestStateQuery HostBuffer::GetStateForTest() { - return HostBuffer::TestStateQuery{ - .current_frame = state_->frame_index, - .current_buffer = state_->current_buffer, - .total_buffer_count = state_->device_buffers[state_->frame_index].size(), - }; +std::shared_ptr HostBuffer::GetDeviceBuffer( + Allocator& allocator) const { + return state_->GetDeviceBuffer(allocator); } void HostBuffer::Reset() { state_->Reset(); } -void HostBuffer::HostBufferState::MaybeCreateNewBuffer(size_t required_size) { - current_buffer++; - if (current_buffer >= device_buffers[frame_index].size()) { - FML_DCHECK(required_size <= kAllocatorBlockSize); - DeviceBufferDescriptor desc; - desc.size = kAllocatorBlockSize; - desc.storage_mode = StorageMode::kHostVisible; - device_buffers[frame_index].push_back(allocator->CreateBuffer(desc)); - } - offset = 0; +size_t HostBuffer::GetSize() const { + return state_->GetReservedLength(); } -std::tuple> -HostBuffer::HostBufferState::Emplace(size_t length, - size_t align, - const EmplaceProc& cb) { +size_t HostBuffer::GetLength() const { + return state_->GetLength(); +} + +std::pair HostBuffer::HostBufferState::Emplace( + size_t length, + size_t align, + const EmplaceProc& cb) { if (!cb) { return {}; } - - // If the requested allocation is bigger than the block size, create a one-off - // device buffer and write to that. - if (length > kAllocatorBlockSize) { - DeviceBufferDescriptor desc; - desc.size = length; - desc.storage_mode = StorageMode::kHostVisible; - auto device_buffer = allocator->CreateBuffer(desc); - if (!device_buffer) { - return {}; - } - if (cb) { - cb(device_buffer->OnGetContents()); - device_buffer->Flush(Range{0, length}); - } - return std::make_tuple(device_buffer->OnGetContents(), Range{0, length}, - device_buffer); - } - auto old_length = GetLength(); - if (old_length + length > kAllocatorBlockSize) { - MaybeCreateNewBuffer(length); + if (!Truncate(old_length + length)) { + return {}; } - old_length = GetLength(); - - cb(GetCurrentBuffer()->OnGetContents() + old_length); - GetCurrentBuffer()->Flush(Range{old_length, length}); + generation++; + cb(GetBuffer() + old_length); - offset += length; - return std::make_tuple(GetCurrentBuffer()->OnGetContents(), - Range{old_length, length}, GetCurrentBuffer()); + return std::make_pair(GetBuffer(), Range{old_length, length}); } -std::tuple> -HostBuffer::HostBufferState::Emplace(const void* buffer, size_t length) { - // If the requested allocation is bigger than the block size, create a one-off - // device buffer and write to that. - if (length > kAllocatorBlockSize) { - DeviceBufferDescriptor desc; - desc.size = length; - desc.storage_mode = StorageMode::kHostVisible; - auto device_buffer = allocator->CreateBuffer(desc); - if (!device_buffer) { - return {}; - } - if (buffer) { - if (!device_buffer->CopyHostBuffer(static_cast(buffer), - Range{0, length})) { - return {}; - } - } - return std::make_tuple(device_buffer->OnGetContents(), Range{0, length}, - device_buffer); +std::shared_ptr +HostBuffer::HostBufferState::GetDeviceBuffer(Allocator& allocator) const { + if (generation == device_buffer_generation) { + return device_buffer; } + auto new_buffer = allocator.CreateBufferWithCopy(GetBuffer(), GetLength()); + if (!new_buffer) { + return nullptr; + } + new_buffer->SetLabel(label); + device_buffer_generation = generation; + device_buffer = std::move(new_buffer); + return device_buffer; +} +std::pair HostBuffer::HostBufferState::Emplace( + const void* buffer, + size_t length) { auto old_length = GetLength(); - if (old_length + length > kAllocatorBlockSize) { - MaybeCreateNewBuffer(length); + if (!Truncate(old_length + length)) { + return {}; } - old_length = GetLength(); - + generation++; if (buffer) { - ::memmove(GetCurrentBuffer()->OnGetContents() + old_length, buffer, length); - GetCurrentBuffer()->Flush(Range{old_length, length}); + ::memmove(GetBuffer() + old_length, buffer, length); } - offset += length; - return std::make_tuple(GetCurrentBuffer()->OnGetContents(), - Range{old_length, length}, GetCurrentBuffer()); + return std::make_pair(GetBuffer(), Range{old_length, length}); } -std::tuple> -HostBuffer::HostBufferState::Emplace(const void* buffer, - size_t length, - size_t align) { +std::pair HostBuffer::HostBufferState::Emplace( + const void* buffer, + size_t length, + size_t align) { if (align == 0 || (GetLength() % align) == 0) { return Emplace(buffer, length); } { - auto [buffer, range, device_buffer] = - Emplace(nullptr, align - (GetLength() % align)); + auto [buffer, range] = Emplace(nullptr, align - (GetLength() % align)); if (!buffer) { return {}; } @@ -187,15 +137,10 @@ HostBuffer::HostBufferState::Emplace(const void* buffer, } void HostBuffer::HostBufferState::Reset() { - // When resetting the host buffer state at the end of the frame, check if - // there are any unused buffers and remove them. - while (device_buffers[frame_index].size() > current_buffer + 1) { - device_buffers[frame_index].pop_back(); - } - - offset = 0u; - current_buffer = 0u; - frame_index = (frame_index + 1) % kHostBufferArenaSize; + generation += 1; + device_buffer = nullptr; + bool did_truncate = Truncate(0); + FML_CHECK(did_truncate); } } // namespace impeller diff --git a/impeller/core/host_buffer.h b/impeller/core/host_buffer.h index 9d50bc5051d64..5c3a69c75dcbf 100644 --- a/impeller/core/host_buffer.h +++ b/impeller/core/host_buffer.h @@ -6,29 +6,20 @@ #define FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_ #include -#include -#include #include #include #include +#include "impeller/base/allocation.h" #include "impeller/core/buffer.h" #include "impeller/core/buffer_view.h" #include "impeller/core/platform.h" namespace impeller { -/// Approximately the same size as the max frames in flight. -static const constexpr size_t kHostBufferArenaSize = 3u; - -/// The host buffer class manages one more 1024 Kb blocks of device buffer -/// allocations. -/// -/// These are reset per-frame. -class HostBuffer { +class HostBuffer final : public Buffer { public: - static std::shared_ptr Create( - const std::shared_ptr& allocator); + static std::shared_ptr Create(); // |Buffer| virtual ~HostBuffer(); @@ -123,51 +114,48 @@ class HostBuffer { /// reused. void Reset(); - /// Test only internal state. - struct TestStateQuery { - size_t current_frame; - size_t current_buffer; - size_t total_buffer_count; - }; + //---------------------------------------------------------------------------- + /// @brief Returns the capacity of the HostBuffer in memory in bytes. + size_t GetSize() const; - /// @brief Retrieve internal buffer state for test expectations. - TestStateQuery GetStateForTest(); + //---------------------------------------------------------------------------- + /// @brief Returns the size of the currently allocated HostBuffer memory in + /// bytes. + size_t GetLength() const; private: - struct HostBufferState { - [[nodiscard]] std::tuple> - Emplace(const void* buffer, size_t length); - - std::tuple> - Emplace(size_t length, size_t align, const EmplaceProc& cb); + struct HostBufferState : public Buffer, public Allocation { + std::shared_ptr GetDeviceBuffer( + Allocator& allocator) const override; - std::tuple> - Emplace(const void* buffer, size_t length, size_t align); + [[nodiscard]] std::pair Emplace(const void* buffer, + size_t length); - void Reset(); - - size_t GetLength() const { return offset; } + std::pair Emplace(size_t length, + size_t align, + const EmplaceProc& cb); - void MaybeCreateNewBuffer(size_t required_size); + std::pair Emplace(const void* buffer, + size_t length, + size_t align); - std::shared_ptr GetCurrentBuffer() { - return device_buffers[frame_index][current_buffer]; - } + void Reset(); - std::shared_ptr allocator; - std::array>, kHostBufferArenaSize> - device_buffers; - size_t current_buffer = 0u; - size_t offset = 0u; - size_t frame_index = 0u; + mutable std::shared_ptr device_buffer; + mutable size_t device_buffer_generation = 0u; + size_t generation = 1u; std::string label; }; std::shared_ptr state_ = std::make_shared(); + // |Buffer| + std::shared_ptr GetDeviceBuffer( + Allocator& allocator) const override; + [[nodiscard]] BufferView Emplace(const void* buffer, size_t length); - explicit HostBuffer(const std::shared_ptr& allocator); + HostBuffer(); HostBuffer(const HostBuffer&) = delete; diff --git a/impeller/display_list/dl_playground.cc b/impeller/display_list/dl_playground.cc index a9c510a076701..ba94de2be370a 100644 --- a/impeller/display_list/dl_playground.cc +++ b/impeller/display_list/dl_playground.cc @@ -51,7 +51,7 @@ bool DlPlayground::OpenPlaygroundHere(DisplayListPlaygroundCallback callback) { list->Dispatch(dispatcher); auto picture = dispatcher.EndRecordingAsPicture(); - return context.Render(picture, render_target, true); + return context.Render(picture, render_target); }); } diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index c3fc2a8dca355..4dd5d9fe19eb3 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -269,7 +269,6 @@ impeller_component("entity_unittests") { "contents/filters/directional_gaussian_blur_filter_contents_unittests.cc", "contents/filters/gaussian_blur_filter_contents_unittests.cc", "contents/filters/inputs/filter_input_unittests.cc", - "contents/host_buffer_unittests.cc", "contents/tiled_texture_contents_unittests.cc", "contents/vertices_contents_unittests.cc", "entity_pass_target_unittests.cc", diff --git a/impeller/entity/contents/atlas_contents.cc b/impeller/entity/contents/atlas_contents.cc index 206273d554765..380fa276ce212 100644 --- a/impeller/entity/contents/atlas_contents.cc +++ b/impeller/entity/contents/atlas_contents.cc @@ -217,7 +217,7 @@ bool AtlasContents::Render(const ContentContext& renderer, VertexBufferBuilder vtx_builder; vtx_builder.Reserve(texture_coords_.size() * 6); const auto texture_size = texture_->GetSize(); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); for (size_t i = 0; i < texture_coords_.size(); i++) { auto sample_rect = texture_coords_[i]; @@ -399,7 +399,7 @@ bool AtlasTextureContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "AtlasTexture"); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); @@ -486,7 +486,7 @@ bool AtlasColorContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "AtlasColors"); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform(); diff --git a/impeller/entity/contents/checkerboard_contents.cc b/impeller/entity/contents/checkerboard_contents.cc index 91f6959bf6d6f..f58bb38850891 100644 --- a/impeller/entity/contents/checkerboard_contents.cc +++ b/impeller/entity/contents/checkerboard_contents.cc @@ -21,7 +21,7 @@ CheckerboardContents::~CheckerboardContents() = default; bool CheckerboardContents::Render(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); using VS = CheckerboardPipeline::VertexShader; using FS = CheckerboardPipeline::FragmentShader; diff --git a/impeller/entity/contents/clip_contents.cc b/impeller/entity/contents/clip_contents.cc index 16f10b0603fc4..a9eaf8a6be953 100644 --- a/impeller/entity/contents/clip_contents.cc +++ b/impeller/entity/contents/clip_contents.cc @@ -96,12 +96,11 @@ bool ClipContents::Render(const ContentContext& renderer, auto vertices = VertexBufferBuilder{} .AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}}) - .CreateVertexBuffer(renderer.GetTransientsBuffer()); + .CreateVertexBuffer(pass.GetTransientsBuffer()); cmd.BindVertices(std::move(vertices)); info.mvp = pass.GetOrthographicTransform(); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info)); options.primitive_type = PrimitiveType::kTriangleStrip; cmd.pipeline = renderer.GetClipPipeline(options); @@ -129,7 +128,7 @@ bool ClipContents::Render(const ContentContext& renderer, cmd.BindVertices(std::move(geometry_result.vertex_buffer)); info.mvp = geometry_result.transform; - VS::BindFrameInfo(cmd, renderer.GetTransientsBuffer().EmplaceUniform(info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info)); pass.AddCommand(std::move(cmd)); return true; @@ -198,12 +197,11 @@ bool ClipRestoreContents::Render(const ContentContext& renderer, {Point(ltrb[0], ltrb[3])}, {Point(ltrb[2], ltrb[3])}, }); - cmd.BindVertices( - vtx_builder.CreateVertexBuffer(renderer.GetTransientsBuffer())); + cmd.BindVertices(vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo info; info.mvp = pass.GetOrthographicTransform(); - VS::BindFrameInfo(cmd, renderer.GetTransientsBuffer().EmplaceUniform(info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(info)); pass.AddCommand(std::move(cmd)); return true; diff --git a/impeller/entity/contents/conical_gradient_contents.cc b/impeller/entity/contents/conical_gradient_contents.cc index 28c738ec9b65a..c6d52fd78d768 100644 --- a/impeller/entity/contents/conical_gradient_contents.cc +++ b/impeller/entity/contents/conical_gradient_contents.cc @@ -78,7 +78,7 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.focus_radius = 0.0; } - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); frag_info.colors_length = colors.size(); @@ -105,11 +105,9 @@ bool ConicalGradientContents::RenderSSBO(const ContentContext& renderer, cmd.pipeline = renderer.GetConicalGradientSSBOFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -173,16 +171,14 @@ bool ConicalGradientContents::RenderTexture(const ContentContext& renderer, cmd.pipeline = renderer.GetConicalGradientFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; FS::BindTextureSampler( cmd, gradient_texture, renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index 17c194e64e022..606420b0ece98 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -184,12 +184,10 @@ ContentContext::ContentContext( render_target_cache_(render_target_allocator == nullptr ? std::make_shared( context_->GetResourceAllocator()) - : std::move(render_target_allocator)), - host_buffer_(HostBuffer::Create(context_->GetResourceAllocator())) { + : std::move(render_target_allocator)) { if (!context_ || !context_->IsValid()) { return; } - auto options = ContentContextOptions{ .sample_count = SampleCount::kCount4, .color_attachment_pixel_format = diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index c1b287e633dda..d8217da6d5e35 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -15,7 +15,6 @@ #include "flutter/fml/status_or.h" #include "impeller/base/validation.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" #include "impeller/entity/entity.h" #include "impeller/renderer/capabilities.h" #include "impeller/renderer/pipeline.h" @@ -730,12 +729,6 @@ class ContentContext { return render_target_cache_; } - /// @brief Retrieve the currnent host buffer for transient storage. - /// - /// This is only safe to use from the raster threads. Other threads should - /// allocate their own device buffers. - HostBuffer& GetTransientsBuffer() const { return *host_buffer_; } - private: std::shared_ptr context_; std::shared_ptr lazy_glyph_atlas_; @@ -947,7 +940,6 @@ class ContentContext { std::shared_ptr scene_context_; #endif // IMPELLER_ENABLE_3D std::shared_ptr render_target_cache_; - std::shared_ptr host_buffer_; bool wireframe_ = false; ContentContext(const ContentContext&) = delete; diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc index 6cec6f769b083..9b12d641a383c 100644 --- a/impeller/entity/contents/filters/blend_filter_contents.cc +++ b/impeller/entity/contents/filters/blend_filter_contents.cc @@ -146,7 +146,7 @@ static std::optional AdvancedBlend( ContentContext::SubpassCallback callback = [&](const ContentContext& renderer, RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto size = pass.GetRenderTargetSize(); VertexBufferBuilder vtx_builder; @@ -264,7 +264,7 @@ std::optional BlendFilterContents::CreateForegroundAdvancedBlend( using VS = BlendScreenPipeline::VertexShader; using FS = BlendScreenPipeline::FragmentShader; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(coverage); if (!maybe_dst_uvs.has_value()) { @@ -433,7 +433,7 @@ std::optional BlendFilterContents::CreateForegroundPorterDuffBlend( using VS = PorterDuffBlendPipeline::VertexShader; using FS = PorterDuffBlendPipeline::FragmentShader; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(coverage); if (!maybe_dst_uvs.has_value()) { @@ -550,7 +550,7 @@ static std::optional PipelineBlend( ContentContext::SubpassCallback callback = [&](const ContentContext& renderer, RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); Command cmd; DEBUG_COMMAND_INFO(cmd, SPrintF("Pipeline Blend Filter (%s)", diff --git a/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc b/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc index fddd2c3b0bcde..c246b4ff24a76 100644 --- a/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/border_mask_blur_filter_contents.cc @@ -89,7 +89,7 @@ std::optional BorderMaskBlurFilterContents::RenderFilter( outer_blur_factor = outer_blur_factor_, sigma]( const ContentContext& renderer, const Entity& entity, RenderPass& pass) -> bool { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VertexBufferBuilder vtx_builder; auto origin = coverage.GetOrigin(); diff --git a/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/impeller/entity/contents/filters/color_matrix_filter_contents.cc index 837416118210d..89fd478de4396 100644 --- a/impeller/entity/contents/filters/color_matrix_filter_contents.cc +++ b/impeller/entity/contents/filters/color_matrix_filter_contents.cc @@ -72,7 +72,7 @@ std::optional ColorMatrixFilterContents::RenderFilter( {Point(0, 1)}, {Point(1, 1)}, }); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); VS::FrameInfo frame_info; diff --git a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc index 3115d9624b48b..791a457e3ecef 100644 --- a/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/directional_gaussian_blur_filter_contents.cc @@ -155,7 +155,7 @@ std::optional DirectionalGaussianBlurFilterContents::RenderFilter( ContentContext::SubpassCallback subpass_callback = [&](const ContentContext& renderer, RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VertexBufferBuilder vtx_builder; vtx_builder.AddVertices({ diff --git a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index c83f0e0d79647..0710dc6275cb7 100644 --- a/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -75,7 +75,7 @@ fml::StatusOr MakeDownsampleSubpass( Entity::TileMode tile_mode) { ContentContext::SubpassCallback subpass_callback = [&](const ContentContext& renderer, RenderPass& pass) { - HostBuffer& host_buffer = renderer.GetTransientsBuffer(); + HostBuffer& host_buffer = pass.GetTransientsBuffer(); Command cmd; DEBUG_COMMAND_INFO(cmd, "Gaussian blur downsample"); @@ -139,7 +139,7 @@ fml::StatusOr MakeBlurSubpass( .mvp = Matrix::MakeOrthographic(ISize(1, 1)), .texture_sampler_y_coord_scale = 1.0}; - HostBuffer& host_buffer = renderer.GetTransientsBuffer(); + HostBuffer& host_buffer = pass.GetTransientsBuffer(); Command cmd; ContentContextOptions options = OptionsFromPass(pass); diff --git a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc index 3c7d864b06dfa..7b768bc708af9 100644 --- a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc +++ b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc @@ -62,7 +62,7 @@ std::optional LinearToSrgbFilterContents::RenderFilter( {Point(1, 1)}, }); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); VS::FrameInfo frame_info; diff --git a/impeller/entity/contents/filters/morphology_filter_contents.cc b/impeller/entity/contents/filters/morphology_filter_contents.cc index 9b7bb80e64d7b..a90aa853b7a1c 100644 --- a/impeller/entity/contents/filters/morphology_filter_contents.cc +++ b/impeller/entity/contents/filters/morphology_filter_contents.cc @@ -75,7 +75,7 @@ std::optional DirectionalMorphologyFilterContents::RenderFilter( ContentContext::SubpassCallback callback = [&](const ContentContext& renderer, RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VertexBufferBuilder vtx_builder; vtx_builder.AddVertices({ diff --git a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc index 567e6c204a983..a1a36abc154d6 100644 --- a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc +++ b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc @@ -62,7 +62,7 @@ std::optional SrgbToLinearFilterContents::RenderFilter( {Point(1, 1)}, }); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); VS::FrameInfo frame_info; diff --git a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc index 78874b335ce4a..9d3c418bdb5af 100644 --- a/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc +++ b/impeller/entity/contents/filters/yuv_to_rgb_filter_contents.cc @@ -91,7 +91,7 @@ std::optional YUVToRGBFilterContents::RenderFilter( {Point(1, 1)}, }); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); cmd.BindVertices(vtx_builder.CreateVertexBuffer(host_buffer)); VS::FrameInfo frame_info; diff --git a/impeller/entity/contents/framebuffer_blend_contents.cc b/impeller/entity/contents/framebuffer_blend_contents.cc index 91445c39c7bcd..d48b5d5ffe1bb 100644 --- a/impeller/entity/contents/framebuffer_blend_contents.cc +++ b/impeller/entity/contents/framebuffer_blend_contents.cc @@ -38,7 +38,7 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer, using VS = FramebufferBlendScreenPipeline::VertexShader; using FS = FramebufferBlendScreenPipeline::FragmentShader; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto src_snapshot = child_contents_->RenderToSnapshot( renderer, // renderer diff --git a/impeller/entity/contents/host_buffer_unittests.cc b/impeller/entity/contents/host_buffer_unittests.cc deleted file mode 100644 index 3ae3c285e07c0..0000000000000 --- a/impeller/entity/contents/host_buffer_unittests.cc +++ /dev/null @@ -1,150 +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. - -#include "flutter/testing/testing.h" -#include "impeller/core/host_buffer.h" -#include "impeller/entity/entity_playground.h" - -namespace impeller { -namespace testing { - -using HostBufferTest = EntityPlayground; -INSTANTIATE_PLAYGROUND_SUITE(HostBufferTest); - -TEST_P(HostBufferTest, CanEmplace) { - struct Length2 { - uint8_t pad[2]; - }; - static_assert(sizeof(Length2) == 2u); - - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - for (size_t i = 0; i < 12500; i++) { - auto view = buffer->Emplace(Length2{}); - ASSERT_TRUE(view); - ASSERT_EQ(view.range, Range(i * sizeof(Length2), 2u)); - } -} - -TEST_P(HostBufferTest, CanEmplaceWithAlignment) { - struct Length2 { - uint8_t pad[2]; - }; - static_assert(sizeof(Length2) == 2); - struct alignas(16) Align16 { - uint8_t pad[2]; - }; - static_assert(alignof(Align16) == 16); - static_assert(sizeof(Align16) == 16); - - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - ASSERT_TRUE(buffer); - - { - auto view = buffer->Emplace(Length2{}); - ASSERT_TRUE(view); - ASSERT_EQ(view.range, Range(0u, 2u)); - } - - { - auto view = buffer->Emplace(Align16{}); - ASSERT_TRUE(view); - ASSERT_EQ(view.range.offset, 16u); - ASSERT_EQ(view.range.length, 16u); - } - { - auto view = buffer->Emplace(Length2{}); - ASSERT_TRUE(view); - ASSERT_EQ(view.range, Range(32u, 2u)); - } - - { - auto view = buffer->Emplace(Align16{}); - ASSERT_TRUE(view); - ASSERT_EQ(view.range.offset, 48u); - ASSERT_EQ(view.range.length, 16u); - } -} - -TEST_P(HostBufferTest, HostBufferInitialState) { - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u); -} - -TEST_P(HostBufferTest, ResetIncrementsFrameCounter) { - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - - buffer->Reset(); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 1u); - - buffer->Reset(); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 2u); - - buffer->Reset(); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); -} - -TEST_P(HostBufferTest, - EmplacingLargerThanBlockSizeCreatesOneOffBufferCallback) { - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - // Emplace an amount larger than the block size, to verify that the host - // buffer does not create a buffer. - auto buffer_view = buffer->Emplace(1024000 + 10, 0, [](uint8_t* data) {}); - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u); -} - -TEST_P(HostBufferTest, EmplacingLargerThanBlockSizeCreatesOneOffBuffer) { - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - // Emplace an amount larger than the block size, to verify that the host - // buffer does not create a buffer. - auto buffer_view = buffer->Emplace(nullptr, 1024000 + 10, 0); - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u); -} - -TEST_P(HostBufferTest, UnusedBuffersAreDiscardedWhenResetting) { - auto buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); - - // Emplace two large allocations to force the allocation of a second buffer. - auto buffer_view_a = buffer->Emplace(1020000, 0, [](uint8_t* data) {}); - auto buffer_view_b = buffer->Emplace(1020000, 0, [](uint8_t* data) {}); - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 1u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 2u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - - // Reset until we get back to this frame. - for (auto i = 0; i < 3; i++) { - buffer->Reset(); - } - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 2u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); - - // Now when we reset, the buffer should get dropped. - // Reset until we get back to this frame. - for (auto i = 0; i < 3; i++) { - buffer->Reset(); - } - - EXPECT_EQ(buffer->GetStateForTest().current_buffer, 0u); - EXPECT_EQ(buffer->GetStateForTest().total_buffer_count, 1u); - EXPECT_EQ(buffer->GetStateForTest().current_frame, 0u); -} - -} // namespace testing -} // namespace impeller diff --git a/impeller/entity/contents/linear_gradient_contents.cc b/impeller/entity/contents/linear_gradient_contents.cc index 60e903c81fb98..fbee0df907bb6 100644 --- a/impeller/entity/contents/linear_gradient_contents.cc +++ b/impeller/entity/contents/linear_gradient_contents.cc @@ -106,16 +106,14 @@ bool LinearGradientContents::RenderTexture(const ContentContext& renderer, cmd.pipeline = renderer.GetLinearGradientFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; FS::BindTextureSampler( cmd, std::move(gradient_texture), renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -142,7 +140,7 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); frag_info.colors_length = colors.size(); @@ -169,11 +167,9 @@ bool LinearGradientContents::RenderSSBO(const ContentContext& renderer, cmd.pipeline = renderer.GetLinearGradientSSBOFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/entity/contents/radial_gradient_contents.cc b/impeller/entity/contents/radial_gradient_contents.cc index 3706ca224497a..37c5cdef2b3c3 100644 --- a/impeller/entity/contents/radial_gradient_contents.cc +++ b/impeller/entity/contents/radial_gradient_contents.cc @@ -77,7 +77,7 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); frag_info.colors_length = colors.size(); @@ -104,11 +104,9 @@ bool RadialGradientContents::RenderSSBO(const ContentContext& renderer, cmd.pipeline = renderer.GetRadialGradientSSBOFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -165,16 +163,14 @@ bool RadialGradientContents::RenderTexture(const ContentContext& renderer, cmd.pipeline = renderer.GetRadialGradientFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; FS::BindTextureSampler( cmd, gradient_texture, renderer.GetContext()->GetSamplerLibrary()->GetSampler(sampler_desc)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/entity/contents/runtime_effect_contents.cc b/impeller/entity/contents/runtime_effect_contents.cc index 7cf6e931986af..20f73299a49cd 100644 --- a/impeller/entity/contents/runtime_effect_contents.cc +++ b/impeller/entity/contents/runtime_effect_contents.cc @@ -199,8 +199,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = geometry_result.transform; - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); //-------------------------------------------------------------------------- /// Fragment stage uniforms. @@ -229,7 +228,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer, case kFloat: { size_t alignment = std::max(uniform.bit_width / 8, DefaultUniformAlignment()); - auto buffer_view = renderer.GetTransientsBuffer().Emplace( + auto buffer_view = pass.GetTransientsBuffer().Emplace( uniform_data_->data() + buffer_offset, uniform.GetSize(), alignment); diff --git a/impeller/entity/contents/solid_color_contents.cc b/impeller/entity/contents/solid_color_contents.cc index 2683bf07e04bd..323da22797e7c 100644 --- a/impeller/entity/contents/solid_color_contents.cc +++ b/impeller/entity/contents/solid_color_contents.cc @@ -72,8 +72,7 @@ bool SolidColorContents::Render(const ContentContext& renderer, VS::FrameInfo frame_info; frame_info.mvp = capture.AddMatrix("Transform", geometry_result.transform); frame_info.color = capture.AddColor("Color", GetColor()).Premultiply(); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/entity/contents/solid_rrect_blur_contents.cc b/impeller/entity/contents/solid_rrect_blur_contents.cc index 4aa04d0fa63d0..a05002b3d3709 100644 --- a/impeller/entity/contents/solid_rrect_blur_contents.cc +++ b/impeller/entity/contents/solid_rrect_blur_contents.cc @@ -106,14 +106,12 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer, cmd.pipeline = renderer.GetRRectBlurPipeline(opts); cmd.stencil_reference = entity.GetClipDepth(); - cmd.BindVertices( - vtx_builder.CreateVertexBuffer(renderer.GetTransientsBuffer())); + cmd.BindVertices(vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * entity.GetTransform() * Matrix::MakeTranslation(positive_rect.GetOrigin()); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.color = color; @@ -122,8 +120,7 @@ bool SolidRRectBlurContents::Render(const ContentContext& renderer, frag_info.corner_radius = std::min(corner_radius_, std::min(positive_rect.GetWidth() / 2.0f, positive_rect.GetHeight() / 2.0f)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/entity/contents/sweep_gradient_contents.cc b/impeller/entity/contents/sweep_gradient_contents.cc index eda81794695c8..87f7774d0a3d9 100644 --- a/impeller/entity/contents/sweep_gradient_contents.cc +++ b/impeller/entity/contents/sweep_gradient_contents.cc @@ -84,7 +84,7 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, frag_info.decal_border_color = decal_border_color_; frag_info.alpha = GetOpacityFactor(); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto colors = CreateGradientColors(colors_, stops_); frag_info.colors_length = colors.size(); @@ -111,11 +111,9 @@ bool SweepGradientContents::RenderSSBO(const ContentContext& renderer, cmd.pipeline = renderer.GetSweepGradientSSBOFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); FS::BindColorData(cmd, color_buffer); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -173,10 +171,8 @@ bool SweepGradientContents::RenderTexture(const ContentContext& renderer, cmd.pipeline = renderer.GetSweepGradientFillPipeline(options); cmd.BindVertices(std::move(geometry_result.vertex_buffer)); - FS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + FS::BindFragInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frag_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); SamplerDescriptor sampler_desc; sampler_desc.min_filter = MinMagFilter::kLinear; sampler_desc.mag_filter = MinMagFilter::kLinear; diff --git a/impeller/entity/contents/text_contents.cc b/impeller/entity/contents/text_contents.cc index 89438851afaf0..8bfb68340d381 100644 --- a/impeller/entity/contents/text_contents.cc +++ b/impeller/entity/contents/text_contents.cc @@ -117,15 +117,14 @@ bool TextContents::Render(const ContentContext& renderer, frame_info.entity_transform = entity.GetTransform(); frame_info.text_color = ToVector(color.Premultiply()); - VS::BindFrameInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (type == GlyphAtlas::Type::kColorBitmap) { using FSS = GlyphAtlasColorPipeline::FragmentShader; FSS::FragInfo frag_info; frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0; FSS::BindFragInfo(cmd, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); + pass.GetTransientsBuffer().EmplaceUniform(frag_info)); } SamplerDescriptor sampler_desc; @@ -161,7 +160,7 @@ bool TextContents::Render(const ContentContext& renderer, Point{0, 1}, Point{1, 0}, Point{0, 1}, Point{1, 1}}; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); size_t vertex_count = 0; for (const auto& run : frame_->GetRuns()) { vertex_count += run.GetGlyphPositions().size(); diff --git a/impeller/entity/contents/texture_contents.cc b/impeller/entity/contents/texture_contents.cc index dddbf879d360b..e109d1e575334 100644 --- a/impeller/entity/contents/texture_contents.cc +++ b/impeller/entity/contents/texture_contents.cc @@ -138,7 +138,7 @@ bool TextureContents::Render(const ContentContext& renderer, {destination_rect.GetRightBottom(), texture_coords.GetRightBottom()}, }); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * diff --git a/impeller/entity/contents/tiled_texture_contents.cc b/impeller/entity/contents/tiled_texture_contents.cc index 28d5af604b168..a71c3ca50c39d 100644 --- a/impeller/entity/contents/tiled_texture_contents.cc +++ b/impeller/entity/contents/tiled_texture_contents.cc @@ -128,7 +128,7 @@ bool TiledTextureContents::Render(const ContentContext& renderer, bool is_external_texture = texture_->GetTextureDescriptor().type == TextureType::kTextureExternalOES; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto geometry_result = GetGeometry()->GetPositionUVBuffer( Rect::MakeSize(texture_size), GetInverseEffectTransform(), renderer, diff --git a/impeller/entity/contents/vertices_contents.cc b/impeller/entity/contents/vertices_contents.cc index 46ff686220c1b..37885ac371fe1 100644 --- a/impeller/entity/contents/vertices_contents.cc +++ b/impeller/entity/contents/vertices_contents.cc @@ -121,7 +121,7 @@ bool VerticesUVContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "VerticesUV"); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto geometry = parent_.GetGeometry(); auto coverage = src_contents->GetCoverage(Entity{}); @@ -175,7 +175,7 @@ bool VerticesColorContents::Render(const ContentContext& renderer, Command cmd; DEBUG_COMMAND_INFO(cmd, "VerticesColors"); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto geometry = parent_.GetGeometry(); auto geometry_result = diff --git a/impeller/entity/entity_pass.cc b/impeller/entity/entity_pass.cc index 67e343de8a6d5..495b038273b68 100644 --- a/impeller/entity/entity_pass.cc +++ b/impeller/entity/entity_pass.cc @@ -304,10 +304,6 @@ bool EntityPass::Render(ContentContext& renderer, renderer.GetContext()->capture.GetDocument(kCaptureDocumentName); renderer.GetRenderTargetCache()->Start(); - fml::ScopedCleanupClosure reset_state([&renderer]() { - renderer.GetLazyGlyphAtlas()->ResetTextFrames(); - renderer.GetRenderTargetCache()->End(); - }); auto root_render_target = render_target; @@ -321,6 +317,11 @@ bool EntityPass::Render(ContentContext& renderer, Rect::MakeSize(root_render_target.GetRenderTargetSize()), {.readonly = true}); + fml::ScopedCleanupClosure reset_state([&renderer]() { + renderer.GetLazyGlyphAtlas()->ResetTextFrames(); + renderer.GetRenderTargetCache()->End(); + }); + IterateAllEntities([lazy_glyph_atlas = renderer.GetLazyGlyphAtlas()](const Entity& entity) { if (const auto& contents = entity.GetContents()) { diff --git a/impeller/entity/entity_playground.cc b/impeller/entity/entity_playground.cc index d74e177e2e382..3763cac125780 100644 --- a/impeller/entity/entity_playground.cc +++ b/impeller/entity/entity_playground.cc @@ -53,7 +53,6 @@ bool EntityPlayground::OpenPlaygroundHere(Entity entity) { content_context->GetRenderTargetCache()->Start(); bool result = entity.Render(*content_context, pass); content_context->GetRenderTargetCache()->End(); - content_context->GetTransientsBuffer().Reset(); return result; }; return Playground::OpenPlaygroundHere(callback); @@ -77,7 +76,6 @@ bool EntityPlayground::OpenPlaygroundHere(EntityPlaygroundCallback callback) { content_context.GetRenderTargetCache()->Start(); bool result = callback(content_context, pass); content_context.GetRenderTargetCache()->End(); - content_context.GetTransientsBuffer().Reset(); return result; }; return Playground::OpenPlaygroundHere(pass_callback); diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 452cf7ba38ebb..4cfc06fbb7987 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -881,13 +881,13 @@ TEST_P(EntityTest, BlendingModeOptions) { options.primitive_type = PrimitiveType::kTriangle; cmd.pipeline = context.GetSolidFillPipeline(options); cmd.BindVertices( - vtx_builder.CreateVertexBuffer(context.GetTransientsBuffer())); + vtx_builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo frame_info; frame_info.mvp = pass.GetOrthographicTransform() * world_matrix; frame_info.color = color.Premultiply(); - VS::BindFrameInfo( - cmd, context.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); return pass.AddCommand(std::move(cmd)); }; diff --git a/impeller/entity/geometry/circle_geometry.cc b/impeller/entity/geometry/circle_geometry.cc index bd9aa8c796378..908485a811924 100644 --- a/impeller/entity/geometry/circle_geometry.cc +++ b/impeller/entity/geometry/circle_geometry.cc @@ -41,7 +41,7 @@ GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer, auto generator = tessellator->StrokedCircle(transform, center_, radius_, half_width); - return ComputePositionGeometry(renderer, generator, entity, pass); + return ComputePositionGeometry(generator, entity, pass); } // |Geometry| @@ -65,8 +65,7 @@ GeometryResult CircleGeometry::GetPositionUVBuffer( auto generator = tessellator->StrokedCircle(transform, center_, radius_, half_width); - return ComputePositionUVGeometry(renderer, generator, uv_transform, entity, - pass); + return ComputePositionUVGeometry(generator, uv_transform, entity, pass); } GeometryVertexType CircleGeometry::GetVertexType() const { diff --git a/impeller/entity/geometry/cover_geometry.cc b/impeller/entity/geometry/cover_geometry.cc index 29518da1efbfc..bae1b8d034b81 100644 --- a/impeller/entity/geometry/cover_geometry.cc +++ b/impeller/entity/geometry/cover_geometry.cc @@ -15,7 +15,7 @@ GeometryResult CoverGeometry::GetPositionBuffer(const ContentContext& renderer, RenderPass& pass) const { auto rect = Rect::MakeSize(pass.GetRenderTargetSize()); constexpr uint16_t kRectIndicies[4] = {0, 1, 2, 3}; - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); return GeometryResult{ .type = PrimitiveType::kTriangleStrip, .vertex_buffer = diff --git a/impeller/entity/geometry/ellipse_geometry.cc b/impeller/entity/geometry/ellipse_geometry.cc index b0d21324b437e..ef4438e6ede67 100644 --- a/impeller/entity/geometry/ellipse_geometry.cc +++ b/impeller/entity/geometry/ellipse_geometry.cc @@ -17,7 +17,6 @@ GeometryResult EllipseGeometry::GetPositionBuffer( const Entity& entity, RenderPass& pass) const { return ComputePositionGeometry( - renderer, renderer.GetTessellator()->FilledEllipse(entity.GetTransform(), bounds_), entity, pass); } @@ -30,7 +29,6 @@ GeometryResult EllipseGeometry::GetPositionUVBuffer( const Entity& entity, RenderPass& pass) const { return ComputePositionUVGeometry( - renderer, renderer.GetTessellator()->FilledEllipse(entity.GetTransform(), bounds_), texture_coverage.GetNormalizingTransform() * effect_transform, entity, pass); diff --git a/impeller/entity/geometry/fill_path_geometry.cc b/impeller/entity/geometry/fill_path_geometry.cc index a906a661636de..6365f4123903a 100644 --- a/impeller/entity/geometry/fill_path_geometry.cc +++ b/impeller/entity/geometry/fill_path_geometry.cc @@ -14,7 +14,7 @@ GeometryResult FillPathGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); VertexBuffer vertex_buffer; if (path_.GetFillType() == FillType::kNonZero && // @@ -94,7 +94,7 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer( return GeometryResult{ .type = PrimitiveType::kTriangleStrip, .vertex_buffer = - vertex_builder.CreateVertexBuffer(renderer.GetTransientsBuffer()), + vertex_builder.CreateVertexBuffer(pass.GetTransientsBuffer()), .transform = pass.GetOrthographicTransform() * entity.GetTransform(), .prevent_overdraw = false, }; @@ -127,7 +127,7 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer( return GeometryResult{ .type = PrimitiveType::kTriangle, .vertex_buffer = - vertex_builder.CreateVertexBuffer(renderer.GetTransientsBuffer()), + vertex_builder.CreateVertexBuffer(pass.GetTransientsBuffer()), .transform = pass.GetOrthographicTransform() * entity.GetTransform(), .prevent_overdraw = false, }; diff --git a/impeller/entity/geometry/geometry.cc b/impeller/entity/geometry/geometry.cc index c29ceb13c31b1..9d32e883e0c65 100644 --- a/impeller/entity/geometry/geometry.cc +++ b/impeller/entity/geometry/geometry.cc @@ -7,7 +7,6 @@ #include #include -#include "impeller/entity/contents/content_context.h" #include "impeller/entity/geometry/circle_geometry.h" #include "impeller/entity/geometry/cover_geometry.h" #include "impeller/entity/geometry/ellipse_geometry.h" @@ -22,7 +21,6 @@ namespace impeller { GeometryResult Geometry::ComputePositionGeometry( - const ContentContext& renderer, const Tessellator::VertexGenerator& generator, const Entity& entity, RenderPass& pass) { @@ -34,7 +32,7 @@ GeometryResult Geometry::ComputePositionGeometry( .type = generator.GetTriangleType(), .vertex_buffer = { - .vertex_buffer = renderer.GetTransientsBuffer().Emplace( + .vertex_buffer = pass.GetTransientsBuffer().Emplace( count * sizeof(VT), alignof(VT), [&generator](uint8_t* buffer) { auto vertices = reinterpret_cast(buffer); @@ -55,7 +53,6 @@ GeometryResult Geometry::ComputePositionGeometry( } GeometryResult Geometry::ComputePositionUVGeometry( - const ContentContext& renderer, const Tessellator::VertexGenerator& generator, const Matrix& uv_transform, const Entity& entity, @@ -68,7 +65,7 @@ GeometryResult Geometry::ComputePositionUVGeometry( .type = generator.GetTriangleType(), .vertex_buffer = { - .vertex_buffer = renderer.GetTransientsBuffer().Emplace( + .vertex_buffer = pass.GetTransientsBuffer().Emplace( count * sizeof(VT), alignof(VT), [&generator, &uv_transform](uint8_t* buffer) { auto vertices = reinterpret_cast(buffer); @@ -117,7 +114,7 @@ GeometryResult ComputeUVGeometryForRect(Rect source_rect, const ContentContext& renderer, const Entity& entity, RenderPass& pass) { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto uv_transform = texture_coverage.GetNormalizingTransform() * effect_transform; diff --git a/impeller/entity/geometry/geometry.h b/impeller/entity/geometry/geometry.h index 685820fe9ed6b..a958f8e5aacaa 100644 --- a/impeller/entity/geometry/geometry.h +++ b/impeller/entity/geometry/geometry.h @@ -123,13 +123,11 @@ class Geometry { protected: static GeometryResult ComputePositionGeometry( - const ContentContext& renderer, const Tessellator::VertexGenerator& generator, const Entity& entity, RenderPass& pass); static GeometryResult ComputePositionUVGeometry( - const ContentContext& renderer, const Tessellator::VertexGenerator& generator, const Matrix& uv_transform, const Entity& entity, diff --git a/impeller/entity/geometry/line_geometry.cc b/impeller/entity/geometry/line_geometry.cc index 80b166bd3d056..0036278f765db 100644 --- a/impeller/entity/geometry/line_geometry.cc +++ b/impeller/entity/geometry/line_geometry.cc @@ -75,7 +75,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer, if (cap_ == Cap::kRound) { std::shared_ptr tessellator = renderer.GetTessellator(); auto generator = tessellator->RoundCapLine(transform, p0_, p1_, radius); - return ComputePositionGeometry(renderer, generator, entity, pass); + return ComputePositionGeometry(generator, entity, pass); } Point corners[4]; @@ -83,7 +83,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer, return kEmptyResult; } - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); size_t count = 4; BufferView vertex_buffer = host_buffer.Emplace( @@ -115,7 +115,7 @@ GeometryResult LineGeometry::GetPositionUVBuffer(Rect texture_coverage, const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); using VT = TextureFillVertexShader::PerVertexData; auto& transform = entity.GetTransform(); @@ -127,8 +127,7 @@ GeometryResult LineGeometry::GetPositionUVBuffer(Rect texture_coverage, if (cap_ == Cap::kRound) { std::shared_ptr tessellator = renderer.GetTessellator(); auto generator = tessellator->RoundCapLine(transform, p0_, p1_, radius); - return ComputePositionUVGeometry(renderer, generator, uv_transform, entity, - pass); + return ComputePositionUVGeometry(generator, uv_transform, entity, pass); } Point corners[4]; diff --git a/impeller/entity/geometry/point_field_geometry.cc b/impeller/entity/geometry/point_field_geometry.cc index 2b7a1af87bf2f..fcd986de8e522 100644 --- a/impeller/entity/geometry/point_field_geometry.cc +++ b/impeller/entity/geometry/point_field_geometry.cc @@ -26,7 +26,7 @@ GeometryResult PointFieldGeometry::GetPositionBuffer( return {}; } - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); return { .type = PrimitiveType::kTriangleStrip, .vertex_buffer = vtx_builder->CreateVertexBuffer(host_buffer), @@ -54,7 +54,7 @@ GeometryResult PointFieldGeometry::GetPositionUVBuffer( ComputeUVGeometryCPU(vtx_builder.value(), {0, 0}, texture_coverage.GetSize(), effect_transform); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); return { .type = PrimitiveType::kTriangleStrip, .vertex_buffer = uv_vtx_builder.CreateVertexBuffer(host_buffer), @@ -152,7 +152,7 @@ GeometryResult PointFieldGeometry::GetPositionBufferGPU( auto cmd_buffer = renderer.GetContext()->CreateCommandBuffer(); auto compute_pass = cmd_buffer->CreateComputePass(); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = compute_pass->GetTransientsBuffer(); auto points_data = host_buffer.Emplace(points_.data(), points_.size() * sizeof(Point), diff --git a/impeller/entity/geometry/rect_geometry.cc b/impeller/entity/geometry/rect_geometry.cc index 000e834bb4018..1f9336ec50030 100644 --- a/impeller/entity/geometry/rect_geometry.cc +++ b/impeller/entity/geometry/rect_geometry.cc @@ -11,7 +11,7 @@ RectGeometry::RectGeometry(Rect rect) : rect_(rect) {} GeometryResult RectGeometry::GetPositionBuffer(const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); return GeometryResult{ .type = PrimitiveType::kTriangleStrip, .vertex_buffer = diff --git a/impeller/entity/geometry/round_rect_geometry.cc b/impeller/entity/geometry/round_rect_geometry.cc index 28cf77d9798ec..b8f3883033049 100644 --- a/impeller/entity/geometry/round_rect_geometry.cc +++ b/impeller/entity/geometry/round_rect_geometry.cc @@ -17,8 +17,7 @@ GeometryResult RoundRectGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, RenderPass& pass) const { - return ComputePositionGeometry(renderer, - renderer.GetTessellator()->FilledRoundRect( + return ComputePositionGeometry(renderer.GetTessellator()->FilledRoundRect( entity.GetTransform(), bounds_, radii_), entity, pass); } @@ -31,7 +30,6 @@ GeometryResult RoundRectGeometry::GetPositionUVBuffer( const Entity& entity, RenderPass& pass) const { return ComputePositionUVGeometry( - renderer, renderer.GetTessellator()->FilledRoundRect(entity.GetTransform(), bounds_, radii_), texture_coverage.GetNormalizingTransform() * effect_transform, entity, diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 87eca5da815bf..4b0b5258308b3 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -451,7 +451,7 @@ GeometryResult StrokePathGeometry::GetPositionBuffer( Scalar min_size = 1.0f / sqrt(std::abs(determinant)); Scalar stroke_width = std::max(stroke_width_, min_size); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto vertex_builder = CreateSolidStrokeVertices( path_, stroke_width, miter_limit_ * stroke_width_ * 0.5, GetJoinProc(stroke_join_), GetCapProc(stroke_cap_), @@ -482,7 +482,7 @@ GeometryResult StrokePathGeometry::GetPositionUVBuffer( Scalar min_size = 1.0f / sqrt(std::abs(determinant)); Scalar stroke_width = std::max(stroke_width_, min_size); - auto& host_buffer = renderer.GetTransientsBuffer(); + auto& host_buffer = pass.GetTransientsBuffer(); auto stroke_builder = CreateSolidStrokeVertices( path_, stroke_width, miter_limit_ * stroke_width_ * 0.5, GetJoinProc(stroke_join_), GetCapProc(stroke_cap_), diff --git a/impeller/entity/inline_pass_context.cc b/impeller/entity/inline_pass_context.cc index b8295c2cb444a..a1904b743bce8 100644 --- a/impeller/entity/inline_pass_context.cc +++ b/impeller/entity/inline_pass_context.cc @@ -6,9 +6,9 @@ #include -#include "impeller/base/allocation.h" #include "impeller/base/validation.h" #include "impeller/core/formats.h" +#include "impeller/core/texture_descriptor.h" #include "impeller/entity/entity_pass_target.h" #include "impeller/renderer/command_buffer.h" diff --git a/impeller/fixtures/dart_tests.dart b/impeller/fixtures/dart_tests.dart index 8105f04b2e5ce..19596fed70375 100644 --- a/impeller/fixtures/dart_tests.dart +++ b/impeller/fixtures/dart_tests.dart @@ -21,7 +21,7 @@ void instantiateDefaultContext() { @pragma('vm:entry-point') void canEmplaceHostBuffer() { - final gpu.HostBuffer hostBuffer = gpu.HostBuffer(gpu.gpuContext); + final gpu.HostBuffer hostBuffer = gpu.HostBuffer(); final gpu.BufferView view0 = hostBuffer .emplace(Int8List.fromList([0, 1, 2, 3]).buffer.asByteData()); @@ -216,7 +216,7 @@ void uniformBindFailsForInvalidHostBufferOffset() { final gpu.RenderPipeline pipeline = createUnlitRenderPipeline(); encoder.bindPipeline(pipeline); - final gpu.HostBuffer transients = gpu.HostBuffer(gpu.gpuContext); + final gpu.HostBuffer transients = gpu.HostBuffer(); final gpu.BufferView vertInfoData = transients.emplace(float32([ 1, 0, 0, 0, // mvp 0, 1, 0, 0, // mvp @@ -262,7 +262,7 @@ void canCreateRenderPassAndSubmit() { encoder.setColorBlendEnable(true); encoder.setColorBlendEquation(gpu.ColorBlendEquation()); - final gpu.HostBuffer transients = gpu.HostBuffer(gpu.gpuContext); + final gpu.HostBuffer transients = gpu.HostBuffer(); final gpu.BufferView vertices = transients.emplace(float32([ -0.5, -0.5, // 0.5, 0.5, // diff --git a/impeller/playground/imgui/imgui_impl_impeller.cc b/impeller/playground/imgui/imgui_impl_impeller.cc index 6d61f369f197e..990f2c6b102c6 100644 --- a/impeller/playground/imgui/imgui_impl_impeller.cc +++ b/impeller/playground/imgui/imgui_impl_impeller.cc @@ -9,8 +9,6 @@ #include #include -#include "impeller/core/host_buffer.h" -#include "impeller/core/platform.h" #include "impeller/geometry/scalar.h" #include "impeller/geometry/vector.h" #include "impeller/playground/imgui/imgui_raster.frag.h" @@ -125,8 +123,6 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data, if (draw_data->CmdListsCount == 0) { return; // Nothing to render. } - auto host_buffer = impeller::HostBuffer::Create( - render_pass.GetContext().lock()->GetResourceAllocator()); using VS = impeller::ImguiRasterVertexShader; using FS = impeller::ImguiRasterFragmentShader; @@ -160,7 +156,8 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data, VS::UniformBuffer uniforms; uniforms.mvp = impeller::Matrix::MakeOrthographic(display_rect.GetSize()) .Translate(-display_rect.GetOrigin()); - auto vtx_uniforms = host_buffer->EmplaceUniform(uniforms); + auto vtx_uniforms = + render_pass.GetTransientsBuffer().EmplaceUniform(uniforms); size_t vertex_buffer_offset = 0; size_t index_buffer_offset = total_vtx_bytes; @@ -272,5 +269,4 @@ void ImGui_ImplImpeller_RenderDrawData(ImDrawData* draw_data, vertex_buffer_offset += draw_list_vtx_bytes; index_buffer_offset += draw_list_idx_bytes; } - host_buffer->Reset(); } diff --git a/impeller/renderer/BUILD.gn b/impeller/renderer/BUILD.gn index 6b17817b849f3..8d6a2061f9e59 100644 --- a/impeller/renderer/BUILD.gn +++ b/impeller/renderer/BUILD.gn @@ -125,6 +125,7 @@ impeller_component("renderer_unittests") { "blit_pass_unittests.cc", "capabilities_unittests.cc", "device_buffer_unittests.cc", + "host_buffer_unittests.cc", "pipeline_descriptor_unittests.cc", "pool_unittests.cc", "renderer_unittests.cc", diff --git a/impeller/renderer/backend/gles/buffer_bindings_gles.cc b/impeller/renderer/backend/gles/buffer_bindings_gles.cc index 168053efdbdd9..899cbbb5b7224 100644 --- a/impeller/renderer/backend/gles/buffer_bindings_gles.cc +++ b/impeller/renderer/backend/gles/buffer_bindings_gles.cc @@ -232,7 +232,8 @@ bool BufferBindingsGLES::BindUniformBuffer(const ProcTableGLES& gl, Allocator& transients_allocator, const BufferResource& buffer) { const auto* metadata = buffer.GetMetadata(); - auto device_buffer = buffer.resource.buffer->GetDeviceBuffer(); + auto device_buffer = + buffer.resource.buffer->GetDeviceBuffer(transients_allocator); if (!device_buffer) { VALIDATION_LOG << "Device buffer not found."; return false; diff --git a/impeller/renderer/backend/gles/context_gles.h b/impeller/renderer/backend/gles/context_gles.h index 3b1d19870263d..a81b10ec75fb3 100644 --- a/impeller/renderer/backend/gles/context_gles.h +++ b/impeller/renderer/backend/gles/context_gles.h @@ -5,6 +5,9 @@ #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ #define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_ +#include +#include +#include "flutter/fml/macros.h" #include "impeller/base/backend_cast.h" #include "impeller/renderer/backend/gles/allocator_gles.h" #include "impeller/renderer/backend/gles/capabilities_gles.h" diff --git a/impeller/renderer/backend/gles/device_buffer_gles.cc b/impeller/renderer/backend/gles/device_buffer_gles.cc index 3cbc9ea5139d9..0ba29c1b67e31 100644 --- a/impeller/renderer/backend/gles/device_buffer_gles.cc +++ b/impeller/renderer/backend/gles/device_buffer_gles.cc @@ -57,10 +57,6 @@ bool DeviceBufferGLES::OnCopyHostBuffer(const uint8_t* source, return true; } -void DeviceBufferGLES::Flush(std::optional range) const { - generation_++; -} - static GLenum ToTarget(DeviceBufferGLES::BindingType type) { switch (type) { case DeviceBufferGLES::BindingType::kArrayBuffer: diff --git a/impeller/renderer/backend/gles/device_buffer_gles.h b/impeller/renderer/backend/gles/device_buffer_gles.h index 932a2df69bef0..8aee746127fea 100644 --- a/impeller/renderer/backend/gles/device_buffer_gles.h +++ b/impeller/renderer/backend/gles/device_buffer_gles.h @@ -8,6 +8,7 @@ #include #include +#include "flutter/fml/macros.h" #include "impeller/base/allocation.h" #include "impeller/base/backend_cast.h" #include "impeller/core/device_buffer.h" @@ -38,8 +39,6 @@ class DeviceBufferGLES final [[nodiscard]] bool BindAndUploadDataIfNecessary(BindingType type) const; - void Flush(std::optional range = std::nullopt) const override; - private: ReactorGLES::Ref reactor_; HandleGLES handle_; diff --git a/impeller/renderer/backend/gles/render_pass_gles.cc b/impeller/renderer/backend/gles/render_pass_gles.cc index c13dbb196f627..7209050f64b2b 100644 --- a/impeller/renderer/backend/gles/render_pass_gles.cc +++ b/impeller/renderer/backend/gles/render_pass_gles.cc @@ -386,7 +386,8 @@ struct RenderPassData { return false; } - auto vertex_buffer = vertex_buffer_view.buffer->GetDeviceBuffer(); + auto vertex_buffer = + vertex_buffer_view.buffer->GetDeviceBuffer(*transients_allocator); if (!vertex_buffer) { return false; @@ -445,7 +446,8 @@ struct RenderPassData { } else { // Bind the index buffer if necessary. auto index_buffer_view = command.vertex_buffer.index_buffer; - auto index_buffer = index_buffer_view.buffer->GetDeviceBuffer(); + auto index_buffer = + index_buffer_view.buffer->GetDeviceBuffer(*transients_allocator); const auto& index_buffer_gles = DeviceBufferGLES::Cast(*index_buffer); if (!index_buffer_gles.BindAndUploadDataIfNecessary( DeviceBufferGLES::BindingType::kElementArrayBuffer)) { diff --git a/impeller/renderer/backend/metal/compute_pass_mtl.mm b/impeller/renderer/backend/metal/compute_pass_mtl.mm index 3f3f7c3fd18e7..0cbce56c48c31 100644 --- a/impeller/renderer/backend/metal/compute_pass_mtl.mm +++ b/impeller/renderer/backend/metal/compute_pass_mtl.mm @@ -171,7 +171,7 @@ static bool Bind(ComputePassBindingsCache& pass, return false; } - auto device_buffer = view.buffer->GetDeviceBuffer(); + auto device_buffer = view.buffer->GetDeviceBuffer(allocator); if (!device_buffer) { return false; } diff --git a/impeller/renderer/backend/metal/device_buffer_mtl.h b/impeller/renderer/backend/metal/device_buffer_mtl.h index 936bc449e0a9c..93e548895ef8c 100644 --- a/impeller/renderer/backend/metal/device_buffer_mtl.h +++ b/impeller/renderer/backend/metal/device_buffer_mtl.h @@ -52,9 +52,6 @@ class DeviceBufferMTL final : public DeviceBuffer, // |DeviceBuffer| bool SetLabel(const std::string& label, Range range) override; - // |DeviceBuffer| - void Flush(std::optional range) const override; - DeviceBufferMTL(const DeviceBufferMTL&) = delete; DeviceBufferMTL& operator=(const DeviceBufferMTL&) = delete; diff --git a/impeller/renderer/backend/metal/device_buffer_mtl.mm b/impeller/renderer/backend/metal/device_buffer_mtl.mm index c2ea8d89ef731..860e216264975 100644 --- a/impeller/renderer/backend/metal/device_buffer_mtl.mm +++ b/impeller/renderer/backend/metal/device_buffer_mtl.mm @@ -78,16 +78,6 @@ return true; } -void DeviceBufferMTL::Flush(std::optional range) const { -#if !FML_OS_IOS - auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size}); - if (storage_mode_ == MTLStorageModeManaged) { - [buffer_ - didModifyRange:NSMakeRange(flush_range.offset, flush_range.length)]; - } -#endif -} - bool DeviceBufferMTL::SetLabel(const std::string& label) { if (label.empty()) { return false; diff --git a/impeller/renderer/backend/metal/render_pass_mtl.mm b/impeller/renderer/backend/metal/render_pass_mtl.mm index 8b22881000def..3f414ad2a6ced 100644 --- a/impeller/renderer/backend/metal/render_pass_mtl.mm +++ b/impeller/renderer/backend/metal/render_pass_mtl.mm @@ -364,7 +364,7 @@ static bool Bind(PassBindingsCache& pass, return false; } - auto device_buffer = view.buffer->GetDeviceBuffer(); + auto device_buffer = view.buffer->GetDeviceBuffer(allocator); if (!device_buffer) { return false; } @@ -508,7 +508,7 @@ static bool Bind(PassBindingsCache& pass, if (!index_buffer) { return false; } - auto device_buffer = index_buffer->GetDeviceBuffer(); + auto device_buffer = index_buffer->GetDeviceBuffer(*allocator); if (!device_buffer) { return false; } diff --git a/impeller/renderer/backend/vulkan/binding_helpers_vk.cc b/impeller/renderer/backend/vulkan/binding_helpers_vk.cc index 6a96d0119c059..676980689ce65 100644 --- a/impeller/renderer/backend/vulkan/binding_helpers_vk.cc +++ b/impeller/renderer/backend/vulkan/binding_helpers_vk.cc @@ -70,7 +70,7 @@ static bool BindBuffers(const Bindings& bindings, for (const BufferAndUniformSlot& data : bindings.buffers) { const auto& buffer_view = data.view.resource.buffer; - auto device_buffer = buffer_view->GetDeviceBuffer(); + auto device_buffer = buffer_view->GetDeviceBuffer(allocator); if (!device_buffer) { VALIDATION_LOG << "Failed to get device buffer for vertex binding"; return false; diff --git a/impeller/renderer/backend/vulkan/command_encoder_vk.h b/impeller/renderer/backend/vulkan/command_encoder_vk.h index 4c682e8284884..612c63f213034 100644 --- a/impeller/renderer/backend/vulkan/command_encoder_vk.h +++ b/impeller/renderer/backend/vulkan/command_encoder_vk.h @@ -95,7 +95,6 @@ class CommandEncoderVK { std::shared_ptr tracked_objects_; std::shared_ptr queue_; const std::shared_ptr fence_waiter_; - std::shared_ptr host_buffer_; bool is_valid_ = true; void Reset(); diff --git a/impeller/renderer/backend/vulkan/command_pool_vk.cc b/impeller/renderer/backend/vulkan/command_pool_vk.cc index 1c5d0dec6c843..018a2199882c2 100644 --- a/impeller/renderer/backend/vulkan/command_pool_vk.cc +++ b/impeller/renderer/backend/vulkan/command_pool_vk.cc @@ -9,9 +9,8 @@ #include #include "fml/thread_local.h" -#include "impeller/renderer/backend/vulkan/context_vk.h" +#include "fml/trace_event.h" #include "impeller/renderer/backend/vulkan/resource_manager_vk.h" - #include "impeller/renderer/backend/vulkan/vk.h" // IWYU pragma: keep. #include "vulkan/vulkan_structs.hpp" @@ -135,10 +134,9 @@ FML_THREAD_LOCAL fml::ThreadLocalUniquePtr tls_command_pool_map; // Map each context to a list of all thread-local command pools associated // with that context. static Mutex g_all_pools_map_mutex; -static std::unordered_map< - const ContextVK*, - std::vector>> g_all_pools_map - IPLR_GUARDED_BY(g_all_pools_map_mutex); +static std::unordered_map>> + g_all_pools_map IPLR_GUARDED_BY(g_all_pools_map_mutex); // TODO(matanlurey): Return a status_or<> instead of nullptr when we have one. std::shared_ptr CommandPoolRecyclerVK::Get() { diff --git a/impeller/renderer/backend/vulkan/command_pool_vk.h b/impeller/renderer/backend/vulkan/command_pool_vk.h index 4db6c098c98ae..6fb1bcadcd3e2 100644 --- a/impeller/renderer/backend/vulkan/command_pool_vk.h +++ b/impeller/renderer/backend/vulkan/command_pool_vk.h @@ -8,8 +8,9 @@ #include #include #include - +#include "fml/macros.h" #include "impeller/base/thread.h" +#include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/vk.h" // IWYU pragma: keep. namespace impeller { @@ -66,8 +67,8 @@ class CommandPoolVK final { std::weak_ptr& context_; // Used to retain a reference on these until the pool is reset. - std::vector collected_buffers_ IPLR_GUARDED_BY( - pool_mutex_); + std::vector collected_buffers_ + IPLR_GUARDED_BY(pool_mutex_); }; //------------------------------------------------------------------------------ diff --git a/impeller/renderer/backend/vulkan/context_vk.h b/impeller/renderer/backend/vulkan/context_vk.h index ac059ebed237c..2bb9927dca65d 100644 --- a/impeller/renderer/backend/vulkan/context_vk.h +++ b/impeller/renderer/backend/vulkan/context_vk.h @@ -8,6 +8,7 @@ #include #include "flutter/fml/concurrent_message_loop.h" +#include "flutter/fml/macros.h" #include "flutter/fml/mapping.h" #include "flutter/fml/unique_fd.h" #include "fml/thread.h" diff --git a/impeller/renderer/backend/vulkan/device_buffer_vk.cc b/impeller/renderer/backend/vulkan/device_buffer_vk.cc index 9aec90beb3038..483bfab7c2f7f 100644 --- a/impeller/renderer/backend/vulkan/device_buffer_vk.cc +++ b/impeller/renderer/backend/vulkan/device_buffer_vk.cc @@ -5,8 +5,6 @@ #include "impeller/renderer/backend/vulkan/device_buffer_vk.h" #include "flutter/fml/trace_event.h" -#include "impeller/renderer/backend/vulkan/context_vk.h" -#include "vulkan/vulkan_core.h" namespace impeller { @@ -64,13 +62,6 @@ bool DeviceBufferVK::SetLabel(const std::string& label) { label); } -void DeviceBufferVK::Flush(std::optional range) const { - auto flush_range = range.value_or(Range{0, GetDeviceBufferDescriptor().size}); - ::vmaFlushAllocation(resource_->buffer.get().allocator, - resource_->buffer.get().allocation, flush_range.offset, - flush_range.length); -} - bool DeviceBufferVK::SetLabel(const std::string& label, Range range) { // We do not have the ability to name ranges. Just name the whole thing. return SetLabel(label); diff --git a/impeller/renderer/backend/vulkan/device_buffer_vk.h b/impeller/renderer/backend/vulkan/device_buffer_vk.h index 33182c52f31af..c2e617dff3b8f 100644 --- a/impeller/renderer/backend/vulkan/device_buffer_vk.h +++ b/impeller/renderer/backend/vulkan/device_buffer_vk.h @@ -7,8 +7,11 @@ #include +#include "flutter/fml/macros.h" +#include "flutter/fml/trace_event.h" #include "impeller/base/backend_cast.h" #include "impeller/core/device_buffer.h" +#include "impeller/renderer/backend/vulkan/context_vk.h" #include "impeller/renderer/backend/vulkan/resource_manager_vk.h" #include "impeller/renderer/backend/vulkan/vma.h" @@ -66,9 +69,6 @@ class DeviceBufferVK final : public DeviceBuffer, // |DeviceBuffer| bool SetLabel(const std::string& label, Range range) override; - // |DeviceBuffer| - void Flush(std::optional range) const override; - DeviceBufferVK(const DeviceBufferVK&) = delete; DeviceBufferVK& operator=(const DeviceBufferVK&) = delete; diff --git a/impeller/renderer/backend/vulkan/render_pass_vk.cc b/impeller/renderer/backend/vulkan/render_pass_vk.cc index 67066c0878d0c..bf0a54e9cefa3 100644 --- a/impeller/renderer/backend/vulkan/render_pass_vk.cc +++ b/impeller/renderer/backend/vulkan/render_pass_vk.cc @@ -410,7 +410,7 @@ static bool EncodeCommand(const Context& context, } auto& allocator = *context.GetResourceAllocator(); - auto vertex_buffer = vertex_buffer_view.buffer->GetDeviceBuffer(); + auto vertex_buffer = vertex_buffer_view.buffer->GetDeviceBuffer(allocator); if (!vertex_buffer) { VALIDATION_LOG << "Failed to acquire device buffer" @@ -435,7 +435,7 @@ static bool EncodeCommand(const Context& context, return false; } - auto index_buffer = index_buffer_view.buffer->GetDeviceBuffer(); + auto index_buffer = index_buffer_view.buffer->GetDeviceBuffer(allocator); if (!index_buffer) { VALIDATION_LOG << "Failed to acquire device buffer" << " for index buffer view"; diff --git a/impeller/renderer/backend/vulkan/surface_context_vk.h b/impeller/renderer/backend/vulkan/surface_context_vk.h index 0394d45c9650f..5c8a327685dba 100644 --- a/impeller/renderer/backend/vulkan/surface_context_vk.h +++ b/impeller/renderer/backend/vulkan/surface_context_vk.h @@ -8,7 +8,6 @@ #include #include "impeller/base/backend_cast.h" -#include "impeller/core/host_buffer.h" #include "impeller/renderer/backend/vulkan/vk.h" #include "impeller/renderer/context.h" diff --git a/impeller/renderer/blit_pass.cc b/impeller/renderer/blit_pass.cc index 81c4e500b0494..e521a6a6543ca 100644 --- a/impeller/renderer/blit_pass.cc +++ b/impeller/renderer/blit_pass.cc @@ -9,17 +9,24 @@ #include "impeller/base/strings.h" #include "impeller/base/validation.h" #include "impeller/core/formats.h" +#include "impeller/core/host_buffer.h" +#include "impeller/renderer/blit_command.h" namespace impeller { -BlitPass::BlitPass() {} +BlitPass::BlitPass() : transients_buffer_(HostBuffer::Create()) {} BlitPass::~BlitPass() = default; +HostBuffer& BlitPass::GetTransientsBuffer() { + return *transients_buffer_; +} + void BlitPass::SetLabel(std::string label) { if (label.empty()) { return; } + transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str())); OnSetLabel(std::move(label)); } diff --git a/impeller/renderer/blit_pass.h b/impeller/renderer/blit_pass.h index 64ab734c1035b..61f53b49dc5f1 100644 --- a/impeller/renderer/blit_pass.h +++ b/impeller/renderer/blit_pass.h @@ -6,9 +6,11 @@ #define FLUTTER_IMPELLER_RENDERER_BLIT_PASS_H_ #include +#include #include "impeller/core/device_buffer.h" #include "impeller/core/texture.h" +#include "impeller/renderer/blit_command.h" namespace impeller { @@ -31,6 +33,8 @@ class BlitPass { void SetLabel(std::string label); + HostBuffer& GetTransientsBuffer(); + //---------------------------------------------------------------------------- /// @brief Record a command to copy the contents of one texture to /// another texture. The blit area is limited by the intersection @@ -124,6 +128,8 @@ class BlitPass { const std::shared_ptr& transients_allocator) const = 0; protected: + std::shared_ptr transients_buffer_; + explicit BlitPass(); virtual void OnSetLabel(std::string label) = 0; diff --git a/impeller/renderer/compute_pass.cc b/impeller/renderer/compute_pass.cc index 8446fffdc53a2..95478f964acf9 100644 --- a/impeller/renderer/compute_pass.cc +++ b/impeller/renderer/compute_pass.cc @@ -5,20 +5,26 @@ #include "impeller/renderer/compute_pass.h" #include -#include "fml/logging.h" +#include "impeller/base/strings.h" #include "impeller/base/validation.h" +#include "impeller/core/host_buffer.h" namespace impeller { ComputePass::ComputePass(std::weak_ptr context) - : context_(std::move(context)) {} + : context_(std::move(context)), transients_buffer_(HostBuffer::Create()) {} ComputePass::~ComputePass() = default; +HostBuffer& ComputePass::GetTransientsBuffer() { + return *transients_buffer_; +} + void ComputePass::SetLabel(const std::string& label) { if (label.empty()) { return; } + transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str())); OnSetLabel(label); } diff --git a/impeller/renderer/compute_pass.h b/impeller/renderer/compute_pass.h index 4ba6e802c3275..bd32e6f4713af 100644 --- a/impeller/renderer/compute_pass.h +++ b/impeller/renderer/compute_pass.h @@ -32,6 +32,8 @@ class ComputePass { void SetThreadGroupSize(const ISize& size); + HostBuffer& GetTransientsBuffer(); + //---------------------------------------------------------------------------- /// @brief Record a command for subsequent encoding to the underlying /// command buffer. No work is encoded into the command buffer at diff --git a/impeller/renderer/compute_subgroup_unittests.cc b/impeller/renderer/compute_subgroup_unittests.cc index e93bec3b28f0f..3d2f5798967a7 100644 --- a/impeller/renderer/compute_subgroup_unittests.cc +++ b/impeller/renderer/compute_subgroup_unittests.cc @@ -12,7 +12,6 @@ #include "gmock/gmock.h" #include "impeller/base/strings.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" #include "impeller/display_list/skia_conversions.h" #include "impeller/entity/contents/content_context.h" #include "impeller/fixtures/golden_paths.h" @@ -89,12 +88,11 @@ TEST_P(ComputeSubgroupTest, PathPlayground) { auto future = promise.get_future(); auto path = skia_conversions::ToPath(sk_path); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); auto status = ComputeTessellator{} .SetStrokeWidth(stroke_width) .Tessellate( - path, *host_buffer, context, vertex_buffer->AsBufferView(), + path, context, vertex_buffer->AsBufferView(), vertex_buffer_count->AsBufferView(), [vertex_buffer_count, &vertex_count, &promise](CommandBuffer::Status status) { @@ -164,8 +162,8 @@ TEST_P(ComputeSubgroupTest, PathPlayground) { auto world_matrix = Matrix::MakeScale(GetContentScale()); frame_info.mvp = pass.GetOrthographicTransform() * world_matrix; frame_info.color = Color::Red().Premultiply(); - VS::BindFrameInfo( - cmd, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -318,22 +316,22 @@ TEST_P(ComputeSubgroupTest, LargePath) { ::memset(vertex_buffer->AsBufferView().contents, 0, sizeof(SS::VertexBuffer<2048>)); - ContentContext renderer(context, nullptr); - if (!renderer.IsValid()) { - return false; - } - ComputeTessellator{} .SetStrokeWidth(stroke_width) .Tessellate( - complex_path, renderer.GetTransientsBuffer(), context, - vertex_buffer->AsBufferView(), vertex_buffer_count->AsBufferView(), + complex_path, context, vertex_buffer->AsBufferView(), + vertex_buffer_count->AsBufferView(), [vertex_buffer_count, &vertex_count](CommandBuffer::Status status) { vertex_count = reinterpret_cast( vertex_buffer_count->AsBufferView().contents) ->count; }); + ContentContext renderer(context, nullptr); + if (!renderer.IsValid()) { + return false; + } + using VS = SolidFillPipeline::VertexShader; Command cmd; @@ -366,8 +364,8 @@ TEST_P(ComputeSubgroupTest, LargePath) { auto world_matrix = Matrix::MakeScale(GetContentScale()); frame_info.mvp = pass.GetOrthographicTransform() * world_matrix; frame_info.color = Color::Red().Premultiply(); - VS::BindFrameInfo( - cmd, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; @@ -400,9 +398,8 @@ TEST_P(ComputeSubgroupTest, QuadAndCubicInOnePath) { fml::AutoResetWaitableEvent latch; - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); auto status = tessellator.Tessellate( - path, *host_buffer, context, vertex_buffer->AsBufferView(), + path, context, vertex_buffer->AsBufferView(), vertex_buffer_count->AsBufferView(), [&latch](CommandBuffer::Status status) { EXPECT_EQ(status, CommandBuffer::Status::kCompleted); @@ -449,8 +446,8 @@ TEST_P(ComputeSubgroupTest, QuadAndCubicInOnePath) { auto world_matrix = Matrix::MakeScale(GetContentScale()); frame_info.mvp = pass.GetOrthographicTransform() * world_matrix; frame_info.color = Color::Red().Premultiply(); - VS::BindFrameInfo( - cmd, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); if (!pass.AddCommand(std::move(cmd))) { return false; diff --git a/impeller/renderer/compute_tessellator.cc b/impeller/renderer/compute_tessellator.cc index 1c6a22f2d77da..87f27fc88f31b 100644 --- a/impeller/renderer/compute_tessellator.cc +++ b/impeller/renderer/compute_tessellator.cc @@ -62,7 +62,6 @@ ComputeTessellator& ComputeTessellator::SetQuadraticTolerance(Scalar value) { ComputeTessellator::Status ComputeTessellator::Tessellate( const Path& path, - HostBuffer& host_buffer, const std::shared_ptr& context, BufferView vertex_buffer, BufferView vertex_buffer_count, @@ -128,11 +127,13 @@ ComputeTessellator::Status ComputeTessellator::Tessellate( DEBUG_COMMAND_INFO(cmd, "Generate Polyline"); cmd.pipeline = compute_pipeline; - PS::BindConfig(cmd, host_buffer.EmplaceUniform(config)); - PS::BindCubics(cmd, host_buffer.EmplaceStorageBuffer(cubics)); - PS::BindQuads(cmd, host_buffer.EmplaceStorageBuffer(quads)); - PS::BindLines(cmd, host_buffer.EmplaceStorageBuffer(lines)); - PS::BindComponents(cmd, host_buffer.EmplaceStorageBuffer(components)); + PS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config)); + PS::BindCubics(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(cubics)); + PS::BindQuads(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(quads)); + PS::BindLines(cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(lines)); + PS::BindComponents( + cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(components)); PS::BindPolyline(cmd, polyline_buffer->AsBufferView()); if (!pass->AddCommand(std::move(cmd))) { @@ -162,7 +163,7 @@ ComputeTessellator::Status ComputeTessellator::Tessellate( .join = static_cast(stroke_join_), .miter_limit = miter_limit_, }; - SS::BindConfig(cmd, host_buffer.EmplaceUniform(config)); + SS::BindConfig(cmd, pass->GetTransientsBuffer().EmplaceUniform(config)); SS::BindPolyline(cmd, polyline_buffer->AsBufferView()); SS::BindVertexBufferCount(cmd, std::move(vertex_buffer_count)); diff --git a/impeller/renderer/compute_tessellator.h b/impeller/renderer/compute_tessellator.h index 0dc6b56bc1e76..f8ccd0d8dfe2a 100644 --- a/impeller/renderer/compute_tessellator.h +++ b/impeller/renderer/compute_tessellator.h @@ -65,7 +65,6 @@ class ComputeTessellator { // and heap allocated buffers on Metal. Status Tessellate( const Path& path, - HostBuffer& host_buffer, const std::shared_ptr& context, BufferView vertex_buffer, BufferView vertex_buffer_count, diff --git a/impeller/renderer/compute_unittests.cc b/impeller/renderer/compute_unittests.cc index 03eb2686806d5..bcaeff41bb924 100644 --- a/impeller/renderer/compute_unittests.cc +++ b/impeller/renderer/compute_unittests.cc @@ -8,7 +8,6 @@ #include "gmock/gmock.h" #include "impeller/base/strings.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" #include "impeller/fixtures/sample.comp.h" #include "impeller/fixtures/stage1.comp.h" #include "impeller/fixtures/stage2.comp.h" @@ -36,7 +35,6 @@ TEST_P(ComputeTest, CapabilitiesReportSupport) { TEST_P(ComputeTest, CanCreateComputePass) { using CS = SampleComputeShader; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -76,9 +74,11 @@ TEST_P(ComputeTest, CanCreateComputePass) { auto output_buffer = CreateHostVisibleDeviceBuffer>( context, "Output Buffer"); - CS::BindInfo(cmd, host_buffer->EmplaceUniform(info)); - CS::BindInput0(cmd, host_buffer->EmplaceStorageBuffer(input_0)); - CS::BindInput1(cmd, host_buffer->EmplaceStorageBuffer(input_1)); + CS::BindInfo(cmd, pass->GetTransientsBuffer().EmplaceUniform(info)); + CS::BindInput0(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_0)); + CS::BindInput1(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_1)); CS::BindOutput(cmd, output_buffer->AsBufferView()); ASSERT_TRUE(pass->AddCommand(std::move(cmd))); @@ -113,7 +113,6 @@ TEST_P(ComputeTest, CanCreateComputePass) { TEST_P(ComputeTest, CanComputePrefixSum) { using CS = PrefixSumTestComputeShader; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -146,7 +145,8 @@ TEST_P(ComputeTest, CanComputePrefixSum) { auto output_buffer = CreateHostVisibleDeviceBuffer>( context, "Output Buffer"); - CS::BindInputData(cmd, host_buffer->EmplaceStorageBuffer(input_data)); + CS::BindInputData( + cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(input_data)); CS::BindOutputData(cmd, output_buffer->AsBufferView()); ASSERT_TRUE(pass->AddCommand(std::move(cmd))); @@ -231,8 +231,6 @@ TEST_P(ComputeTest, CanComputePrefixSumLargeInteractive) { using CS = PrefixSumTestComputeShader; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); - ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -262,12 +260,12 @@ TEST_P(ComputeTest, CanComputePrefixSumLargeInteractive) { auto output_buffer = CreateHostVisibleDeviceBuffer>( context, "Output Buffer"); - CS::BindInputData(cmd, host_buffer->EmplaceStorageBuffer(input_data)); + CS::BindInputData( + cmd, pass->GetTransientsBuffer().EmplaceStorageBuffer(input_data)); CS::BindOutputData(cmd, output_buffer->AsBufferView()); pass->AddCommand(std::move(cmd)); pass->EncodeCommands(); - host_buffer->Reset(); return cmd_buffer->SubmitCommands(); }; ASSERT_TRUE(OpenPlaygroundHere(callback)); @@ -280,7 +278,6 @@ TEST_P(ComputeTest, MultiStageInputAndOutput) { using Stage2PipelineBuilder = ComputePipelineBuilder; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -329,7 +326,8 @@ TEST_P(ComputeTest, MultiStageInputAndOutput) { ComputeCommand cmd; cmd.pipeline = compute_pipeline_1; - CS1::BindInput(cmd, host_buffer->EmplaceStorageBuffer(input_1)); + CS1::BindInput(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_1)); CS1::BindOutput(cmd, output_buffer_1->AsBufferView()); ASSERT_TRUE(pass->AddCommand(std::move(cmd))); @@ -375,7 +373,6 @@ TEST_P(ComputeTest, MultiStageInputAndOutput) { TEST_P(ComputeTest, CanCompute1DimensionalData) { using CS = SampleComputeShader; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -414,9 +411,11 @@ TEST_P(ComputeTest, CanCompute1DimensionalData) { auto output_buffer = CreateHostVisibleDeviceBuffer>( context, "Output Buffer"); - CS::BindInfo(cmd, host_buffer->EmplaceUniform(info)); - CS::BindInput0(cmd, host_buffer->EmplaceStorageBuffer(input_0)); - CS::BindInput1(cmd, host_buffer->EmplaceStorageBuffer(input_1)); + CS::BindInfo(cmd, pass->GetTransientsBuffer().EmplaceUniform(info)); + CS::BindInput0(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_0)); + CS::BindInput1(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_1)); CS::BindOutput(cmd, output_buffer->AsBufferView()); ASSERT_TRUE(pass->AddCommand(std::move(cmd))); @@ -451,7 +450,6 @@ TEST_P(ComputeTest, CanCompute1DimensionalData) { TEST_P(ComputeTest, ReturnsEarlyWhenAnyGridDimensionIsZero) { using CS = SampleComputeShader; auto context = GetContext(); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); ASSERT_TRUE(context); ASSERT_TRUE(context->GetCapabilities()->SupportsCompute()); @@ -493,9 +491,11 @@ TEST_P(ComputeTest, ReturnsEarlyWhenAnyGridDimensionIsZero) { auto output_buffer = CreateHostVisibleDeviceBuffer>( context, "Output Buffer"); - CS::BindInfo(cmd, host_buffer->EmplaceUniform(info)); - CS::BindInput0(cmd, host_buffer->EmplaceStorageBuffer(input_0)); - CS::BindInput1(cmd, host_buffer->EmplaceStorageBuffer(input_1)); + CS::BindInfo(cmd, pass->GetTransientsBuffer().EmplaceUniform(info)); + CS::BindInput0(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_0)); + CS::BindInput1(cmd, + pass->GetTransientsBuffer().EmplaceStorageBuffer(input_1)); CS::BindOutput(cmd, output_buffer->AsBufferView()); ASSERT_TRUE(pass->AddCommand(std::move(cmd))); diff --git a/impeller/renderer/context.h b/impeller/renderer/context.h index 1f80c296e8fc4..2b76e8f3bfa93 100644 --- a/impeller/renderer/context.h +++ b/impeller/renderer/context.h @@ -180,6 +180,10 @@ class Context { /// pending work. virtual void SetSyncPresentation(bool value) {} + //---------------------------------------------------------------------------- + /// @brief Accessor for a pool of HostBuffers. + Pool& GetHostBufferPool() const { return host_buffer_pool_; } + CaptureContext capture; /// Stores a task on the `ContextMTL` that is awaiting access for the GPU. @@ -198,9 +202,9 @@ class Context { protected: Context(); - std::vector> per_frame_task_; - private: + mutable Pool host_buffer_pool_ = Pool(1'000'000); + Context(const Context&) = delete; Context& operator=(const Context&) = delete; diff --git a/impeller/renderer/host_buffer_unittests.cc b/impeller/renderer/host_buffer_unittests.cc new file mode 100644 index 0000000000000..3046e801b24c0 --- /dev/null +++ b/impeller/renderer/host_buffer_unittests.cc @@ -0,0 +1,79 @@ +// 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 "flutter/testing/testing.h" +#include "impeller/core/host_buffer.h" + +namespace impeller { +namespace testing { + +TEST(HostBufferTest, TestInitialization) { + ASSERT_TRUE(HostBuffer::Create()); + // Newly allocated buffers don't touch the heap till they have to. + ASSERT_EQ(HostBuffer::Create()->GetLength(), 0u); + ASSERT_EQ(HostBuffer::Create()->GetSize(), 0u); +} + +TEST(HostBufferTest, CanEmplace) { + struct Length2 { + uint8_t pad[2]; + }; + static_assert(sizeof(Length2) == 2u); + + auto buffer = HostBuffer::Create(); + + for (size_t i = 0; i < 12500; i++) { + auto view = buffer->Emplace(Length2{}); + ASSERT_TRUE(view); + ASSERT_EQ(buffer->GetLength(), (i + 1) * sizeof(Length2)); + ASSERT_EQ(view.range, Range(i * sizeof(Length2), 2u)); + } +} + +TEST(HostBufferTest, CanEmplaceWithAlignment) { + struct Length2 { + uint8_t pad[2]; + }; + static_assert(sizeof(Length2) == 2); + struct alignas(16) Align16 { + uint8_t pad[2]; + }; + static_assert(alignof(Align16) == 16); + static_assert(sizeof(Align16) == 16); + + auto buffer = HostBuffer::Create(); + ASSERT_TRUE(buffer); + + { + auto view = buffer->Emplace(Length2{}); + ASSERT_TRUE(view); + ASSERT_EQ(buffer->GetLength(), 2u); + ASSERT_EQ(view.range, Range(0u, 2u)); + } + + { + auto view = buffer->Emplace(Align16{}); + ASSERT_TRUE(view); + ASSERT_EQ(view.range.offset, 16u); + ASSERT_EQ(view.range.length, 16u); + ASSERT_EQ(buffer->GetLength(), 32u); + } + { + auto view = buffer->Emplace(Length2{}); + ASSERT_TRUE(view); + ASSERT_EQ(buffer->GetLength(), 34u); + ASSERT_EQ(view.range, Range(32u, 2u)); + } + + { + auto view = buffer->Emplace(Align16{}); + ASSERT_TRUE(view); + ASSERT_EQ(view.range.offset, 48u); + ASSERT_EQ(view.range.length, 16u); + ASSERT_EQ(buffer->GetLength(), 64u); + } +} + +} // namespace testing +} // namespace impeller diff --git a/impeller/renderer/render_pass.cc b/impeller/renderer/render_pass.cc index e8dd476d45134..8710a397a4320 100644 --- a/impeller/renderer/render_pass.cc +++ b/impeller/renderer/render_pass.cc @@ -14,9 +14,19 @@ RenderPass::RenderPass(std::weak_ptr context, has_stencil_attachment_(target.GetStencilAttachment().has_value()), render_target_size_(target.GetRenderTargetSize()), render_target_(target), - orthographic_(Matrix::MakeOrthographic(render_target_size_)) {} + transients_buffer_(), + orthographic_(Matrix::MakeOrthographic(render_target_size_)) { + auto strong_context = context_.lock(); + FML_DCHECK(strong_context); + transients_buffer_ = strong_context->GetHostBufferPool().Grab(); +} -RenderPass::~RenderPass() {} +RenderPass::~RenderPass() { + auto strong_context = context_.lock(); + if (strong_context) { + strong_context->GetHostBufferPool().Recycle(transients_buffer_); + } +} SampleCount RenderPass::GetSampleCount() const { return sample_count_; @@ -42,10 +52,15 @@ const Matrix& RenderPass::GetOrthographicTransform() const { return orthographic_; } +HostBuffer& RenderPass::GetTransientsBuffer() { + return *transients_buffer_; +} + void RenderPass::SetLabel(std::string label) { if (label.empty()) { return; } + transients_buffer_->SetLabel(SPrintF("%s Transients", label.c_str())); OnSetLabel(std::move(label)); } diff --git a/impeller/renderer/render_pass.h b/impeller/renderer/render_pass.h index 3dc4ab943f45d..33bb8abd0ddba 100644 --- a/impeller/renderer/render_pass.h +++ b/impeller/renderer/render_pass.h @@ -49,6 +49,8 @@ class RenderPass { commands_.reserve(command_count); } + HostBuffer& GetTransientsBuffer(); + //---------------------------------------------------------------------------- /// @brief Record a command for subsequent encoding to the underlying /// command buffer. No work is encoded into the command buffer at @@ -99,6 +101,7 @@ class RenderPass { const bool has_stencil_attachment_; const ISize render_target_size_; const RenderTarget render_target_; + std::shared_ptr transients_buffer_; std::vector commands_; const Matrix orthographic_; diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index f63ee2a263615..c54e213f10caa 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -6,7 +6,6 @@ #include "impeller/core/device_buffer_descriptor.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" #include "impeller/core/sampler_descriptor.h" #include "impeller/fixtures/array.frag.h" #include "impeller/fixtures/array.vert.h" @@ -71,8 +70,6 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { ASSERT_TRUE(bridge && boston); auto sampler = context->GetSamplerLibrary()->GetSampler({}); ASSERT_TRUE(sampler); - - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); static bool wireframe; @@ -96,7 +93,8 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { Matrix::MakeOrthographic(pass.GetRenderTargetSize())); uniforms.mvp = pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindUniformBuffer(cmd, host_buffer->EmplaceUniform(uniforms)); + VS::BindUniformBuffer(cmd, + pass.GetTransientsBuffer().EmplaceUniform(uniforms)); FS::FrameInfo frame_info; frame_info.current_time = GetSecondsElapsed(); @@ -104,11 +102,10 @@ TEST_P(RendererTest, CanCreateBoxPrimitive) { frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; - FS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + FS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::BindContents1(cmd, boston, sampler); FS::BindContents2(cmd, bridge, sampler); - - host_buffer->Reset(); if (!pass.AddCommand(std::move(cmd))) { return false; } @@ -173,7 +170,6 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { ASSERT_TRUE(sampler); Vector3 euler_angles; - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { static Degrees fov_y(60); static Scalar distance = 10; @@ -199,9 +195,8 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { Matrix::MakeRotationX(Radians(euler_angles.x)) * Matrix::MakeRotationY(Radians(euler_angles.y)) * Matrix::MakeRotationZ(Radians(euler_angles.z)); - VS::BindUniformBuffer(cmd, host_buffer->EmplaceUniform(uniforms)); - - host_buffer->Reset(); + VS::BindUniformBuffer(cmd, + pass.GetTransientsBuffer().EmplaceUniform(uniforms)); if (!pass.AddCommand(std::move(cmd))) { return false; } @@ -245,7 +240,6 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { auto sampler = context->GetSamplerLibrary()->GetSampler({}); ASSERT_TRUE(sampler); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { Command cmd; DEBUG_COMMAND_INFO(cmd, "Box"); @@ -259,7 +253,8 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; - FS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + FS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::BindContents1(cmd, boston, sampler); FS::BindContents2(cmd, bridge, sampler); @@ -271,14 +266,14 @@ TEST_P(RendererTest, CanRenderMultiplePrimitives) { uniforms.mvp = pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()) * Matrix::MakeTranslation({i * 50.0f, j * 50.0f, 0.0f}); - VS::BindUniformBuffer(cmd, host_buffer->EmplaceUniform(uniforms)); + VS::BindUniformBuffer( + cmd, pass.GetTransientsBuffer().EmplaceUniform(uniforms)); if (!pass.AddCommand(std::move(cmd))) { return false; } } } - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -298,7 +293,6 @@ TEST_P(RendererTest, CanRenderToTexture) { auto box_pipeline = context->GetPipelineLibrary()->GetPipeline(pipeline_desc).Get(); ASSERT_TRUE(box_pipeline); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); VertexBufferBuilder vertex_builder; vertex_builder.SetLabel("Box"); @@ -375,14 +369,16 @@ TEST_P(RendererTest, CanRenderToTexture) { frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; - FS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + FS::BindFrameInfo(cmd, + r2t_pass->GetTransientsBuffer().EmplaceUniform(frame_info)); FS::BindContents1(cmd, boston, sampler); FS::BindContents2(cmd, bridge, sampler); VS::UniformBuffer uniforms; uniforms.mvp = Matrix::MakeOrthographic(ISize{1024, 768}) * Matrix::MakeTranslation({50.0f, 50.0f, 0.0f}); - VS::BindUniformBuffer(cmd, host_buffer->EmplaceUniform(uniforms)); + VS::BindUniformBuffer( + cmd, r2t_pass->GetTransientsBuffer().EmplaceUniform(uniforms)); ASSERT_TRUE(r2t_pass->AddCommand(std::move(cmd))); ASSERT_TRUE(r2t_pass->EncodeCommands()); } @@ -437,21 +433,20 @@ TEST_P(RendererTest, CanRenderInstanced) { instances.colors[i] = Color::Random(); } - auto host_buffer = HostBuffer::Create(GetContext()->GetResourceAllocator()); ASSERT_TRUE(OpenPlaygroundHere([&](RenderPass& pass) -> bool { VS::FrameInfo frame_info; EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(pass.GetRenderTargetSize())); frame_info.mvp = pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); - VS::BindInstanceInfo(cmd, host_buffer->EmplaceStorageBuffer(instances)); - cmd.BindVertices(builder.CreateVertexBuffer(*host_buffer)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); + VS::BindInstanceInfo( + cmd, pass.GetTransientsBuffer().EmplaceStorageBuffer(instances)); + cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer())); cmd.instance_count = kInstancesCount; pass.AddCommand(std::move(cmd)); - - host_buffer->Reset(); return true; })); } @@ -503,7 +498,6 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator()); ASSERT_TRUE(vertex_buffer); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); Renderer::RenderCallback callback = [&](RenderTarget& render_target) { auto buffer = context->CreateCommandBuffer(); if (!buffer) { @@ -548,11 +542,13 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { Matrix::MakeOrthographic(pass->GetRenderTargetSize())); frame_info.mvp = pass->GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo( + cmd, pass->GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.lod = 0; - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, + pass->GetTransientsBuffer().EmplaceUniform(frag_info)); auto sampler = context->GetSamplerLibrary()->GetSampler({}); FS::BindTex(cmd, texture, sampler); @@ -565,7 +561,6 @@ TEST_P(RendererTest, CanBlitTextureToTexture) { if (!buffer->SubmitCommands()) { return false; } - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -623,7 +618,6 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { vertex_builder.CreateVertexBuffer(*context->GetResourceAllocator()); ASSERT_TRUE(vertex_buffer); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); Renderer::RenderCallback callback = [&](RenderTarget& render_target) { { auto buffer = context->CreateCommandBuffer(); @@ -675,11 +669,13 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { Matrix::MakeOrthographic(pass->GetRenderTargetSize())); frame_info.mvp = pass->GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo( + cmd, pass->GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.lod = 0; - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, + pass->GetTransientsBuffer().EmplaceUniform(frag_info)); auto sampler = context->GetSamplerLibrary()->GetSampler({}); auto buffer_view = device_buffer->AsBufferView(); @@ -699,7 +695,6 @@ TEST_P(RendererTest, CanBlitTextureToBuffer) { return false; } } - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -739,7 +734,6 @@ TEST_P(RendererTest, CanGenerateMipmaps) { ASSERT_TRUE(vertex_buffer); bool first_frame = true; - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); Renderer::RenderCallback callback = [&](RenderTarget& render_target) { const char* mip_filter_names[] = {"Nearest", "Linear"}; const MipFilter mip_filters[] = {MipFilter::kNearest, MipFilter::kLinear}; @@ -798,11 +792,13 @@ TEST_P(RendererTest, CanGenerateMipmaps) { Matrix::MakeOrthographic(pass->GetRenderTargetSize())); frame_info.mvp = pass->GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo( + cmd, pass->GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo frag_info; frag_info.lod = lod; - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(frag_info)); + FS::BindFragInfo(cmd, + pass->GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; sampler_desc.mip_filter = mip_filters[selected_mip_filter]; @@ -818,7 +814,6 @@ TEST_P(RendererTest, CanGenerateMipmaps) { if (!buffer->SubmitCommands()) { return false; } - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -850,7 +845,6 @@ TEST_P(RendererTest, TheImpeller) { "table_mountain_py.png", "table_mountain_ny.png", "table_mountain_pz.png", "table_mountain_nz.png"}); auto cube_map_sampler = context->GetSamplerLibrary()->GetSampler({}); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); @@ -865,22 +859,23 @@ TEST_P(RendererTest, TheImpeller) { {Point(size.width, 0)}, {Point(0, size.height)}, {Point(size.width, size.height)}}); - cmd.BindVertices(builder.CreateVertexBuffer(*host_buffer)); + cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo frame_info; EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size)); frame_info.mvp = pass.GetOrthographicTransform(); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo fs_uniform; fs_uniform.texture_size = Point(size); fs_uniform.time = GetSecondsElapsed(); - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(fs_uniform)); + FS::BindFragInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(fs_uniform)); FS::BindBlueNoise(cmd, blue_noise, noise_sampler); FS::BindCubeMap(cmd, cube_map, cube_map_sampler); pass.AddCommand(std::move(cmd)); - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -900,7 +895,6 @@ TEST_P(RendererTest, ArrayUniforms) { context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get(); ASSERT_TRUE(pipeline && pipeline->IsValid()); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); @@ -914,13 +908,14 @@ TEST_P(RendererTest, ArrayUniforms) { {Point(size.width, 0)}, {Point(0, size.height)}, {Point(size.width, size.height)}}); - cmd.BindVertices(builder.CreateVertexBuffer(*host_buffer)); + cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo frame_info; EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size)); frame_info.mvp = pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); auto time = GetSecondsElapsed(); auto y_pos = [&time](float x) { @@ -935,10 +930,10 @@ TEST_P(RendererTest, ArrayUniforms) { Color::MakeRGBA8(244, 180, 0, 255), Color::MakeRGBA8(15, 157, 88, 255)}, }; - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(fs_uniform)); + FS::BindFragInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(fs_uniform)); pass.AddCommand(std::move(cmd)); - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -958,7 +953,6 @@ TEST_P(RendererTest, InactiveUniforms) { context->GetPipelineLibrary()->GetPipeline(pipeline_descriptor).Get(); ASSERT_TRUE(pipeline && pipeline->IsValid()); - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); SinglePassCallback callback = [&](RenderPass& pass) { auto size = pass.GetRenderTargetSize(); @@ -972,20 +966,21 @@ TEST_P(RendererTest, InactiveUniforms) { {Point(size.width, 0)}, {Point(0, size.height)}, {Point(size.width, size.height)}}); - cmd.BindVertices(builder.CreateVertexBuffer(*host_buffer)); + cmd.BindVertices(builder.CreateVertexBuffer(pass.GetTransientsBuffer())); VS::FrameInfo frame_info; EXPECT_EQ(pass.GetOrthographicTransform(), Matrix::MakeOrthographic(size)); frame_info.mvp = pass.GetOrthographicTransform() * Matrix::MakeScale(GetContentScale()); - VS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + VS::BindFrameInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(frame_info)); FS::FragInfo fs_uniform = {.unused_color = Color::Red(), .color = Color::Green()}; - FS::BindFragInfo(cmd, host_buffer->EmplaceUniform(fs_uniform)); + FS::BindFragInfo(cmd, + pass.GetTransientsBuffer().EmplaceUniform(fs_uniform)); pass.AddCommand(std::move(cmd)); - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); @@ -1158,8 +1153,6 @@ TEST_P(RendererTest, StencilMask) { CompareFunctionUI().IndexOf(CompareFunction::kLessEqual); static int current_back_compare = CompareFunctionUI().IndexOf(CompareFunction::kLessEqual); - - auto host_buffer = HostBuffer::Create(context->GetResourceAllocator()); Renderer::RenderCallback callback = [&](RenderTarget& render_target) { auto buffer = context->CreateCommandBuffer(); if (!buffer) { @@ -1245,7 +1238,8 @@ TEST_P(RendererTest, StencilMask) { if (mirror) { uniforms.mvp = Matrix::MakeScale(Vector2(-1, 1)) * uniforms.mvp; } - VS::BindUniformBuffer(cmd, host_buffer->EmplaceUniform(uniforms)); + VS::BindUniformBuffer( + cmd, pass->GetTransientsBuffer().EmplaceUniform(uniforms)); FS::FrameInfo frame_info; frame_info.current_time = GetSecondsElapsed(); @@ -1253,7 +1247,8 @@ TEST_P(RendererTest, StencilMask) { frame_info.window_size.x = GetWindowSize().width; frame_info.window_size.y = GetWindowSize().height; - FS::BindFrameInfo(cmd, host_buffer->EmplaceUniform(frame_info)); + FS::BindFrameInfo(cmd, + pass->GetTransientsBuffer().EmplaceUniform(frame_info)); FS::BindContents1(cmd, boston, sampler); FS::BindContents2(cmd, bridge, sampler); if (!pass->AddCommand(std::move(cmd))) { @@ -1265,7 +1260,6 @@ TEST_P(RendererTest, StencilMask) { if (!buffer->SubmitCommands()) { return false; } - host_buffer->Reset(); return true; }; OpenPlaygroundHere(callback); diff --git a/impeller/scene/scene.cc b/impeller/scene/scene.cc index 172e1c1e4a067..ca7202afb04b4 100644 --- a/impeller/scene/scene.cc +++ b/impeller/scene/scene.cc @@ -8,7 +8,6 @@ #include #include "flutter/fml/logging.h" -#include "fml/closure.h" #include "impeller/renderer/render_target.h" #include "impeller/scene/scene_context.h" #include "impeller/scene/scene_encoder.h" @@ -33,9 +32,6 @@ Node& Scene::GetRoot() { bool Scene::Render(const RenderTarget& render_target, const Matrix& camera_transform) { - fml::ScopedCleanupClosure reset_state( - [context = scene_context_]() { context->GetTransientsBuffer().Reset(); }); - // Collect the render commands from the scene. SceneEncoder encoder; if (!root_.Render(encoder, diff --git a/impeller/scene/scene_context.cc b/impeller/scene/scene_context.cc index c4637837b3644..baece932832a2 100644 --- a/impeller/scene/scene_context.cc +++ b/impeller/scene/scene_context.cc @@ -4,7 +4,6 @@ #include "impeller/scene/scene_context.h" #include "impeller/core/formats.h" -#include "impeller/core/host_buffer.h" #include "impeller/scene/material.h" #include "impeller/scene/shaders/skinned.vert.h" #include "impeller/scene/shaders/unlit.frag.h" @@ -81,7 +80,7 @@ SceneContext::SceneContext(std::shared_ptr context) return; } } - host_buffer_ = HostBuffer::Create(GetContext()->GetResourceAllocator()); + is_valid_ = true; } diff --git a/impeller/scene/scene_context.h b/impeller/scene/scene_context.h index 4c99e99867213..24d49249f7ac0 100644 --- a/impeller/scene/scene_context.h +++ b/impeller/scene/scene_context.h @@ -7,7 +7,6 @@ #include -#include "impeller/core/host_buffer.h" #include "impeller/renderer/context.h" #include "impeller/renderer/pipeline.h" #include "impeller/renderer/pipeline_descriptor.h" @@ -54,8 +53,6 @@ class SceneContext { std::shared_ptr GetPlaceholderTexture() const; - HostBuffer& GetTransientsBuffer() const { return *host_buffer_; } - private: class PipelineVariants { public: @@ -147,7 +144,6 @@ class SceneContext { // A 1x1 opaque white texture that can be used as a placeholder binding. // Available for the lifetime of the scene context std::shared_ptr placeholder_texture_; - std::shared_ptr host_buffer_; SceneContext(const SceneContext&) = delete; diff --git a/impeller/scene/scene_encoder.cc b/impeller/scene/scene_encoder.cc index 43c9c85af8caa..e0572ffdb6971 100644 --- a/impeller/scene/scene_encoder.cc +++ b/impeller/scene/scene_encoder.cc @@ -24,7 +24,7 @@ static void EncodeCommand(const SceneContext& scene_context, const Matrix& view_transform, RenderPass& render_pass, const SceneCommand& scene_command) { - auto& host_buffer = scene_context.GetTransientsBuffer(); + auto& host_buffer = render_pass.GetTransientsBuffer(); Command cmd; DEBUG_COMMAND_INFO(cmd, scene_command.label); diff --git a/impeller/scene/skin.cc b/impeller/scene/skin.cc index ffabd8253b243..b3ea96993a6e7 100644 --- a/impeller/scene/skin.cc +++ b/impeller/scene/skin.cc @@ -6,10 +6,10 @@ #include #include +#include #include #include "flutter/fml/logging.h" -#include "impeller/base/allocation.h" #include "impeller/core/allocator.h" #include "impeller/scene/importer/conversions.h" diff --git a/lib/gpu/device_buffer.h b/lib/gpu/device_buffer.h index a2b262b3795c9..707d01f150ba4 100644 --- a/lib/gpu/device_buffer.h +++ b/lib/gpu/device_buffer.h @@ -8,7 +8,7 @@ #include "flutter/lib/gpu/context.h" #include "flutter/lib/gpu/export.h" #include "flutter/lib/ui/dart_wrapper.h" - +#include "impeller/core/device_buffer_descriptor.h" #include "third_party/tonic/typed_data/dart_byte_data.h" namespace flutter { diff --git a/lib/gpu/host_buffer.cc b/lib/gpu/host_buffer.cc index 6d76464c6c787..e7600e8d98592 100644 --- a/lib/gpu/host_buffer.cc +++ b/lib/gpu/host_buffer.cc @@ -4,9 +4,6 @@ #include "flutter/lib/gpu/host_buffer.h" -#include - -#include "dart_api.h" #include "impeller/core/host_buffer.h" #include "impeller/core/platform.h" #include "third_party/tonic/typed_data/dart_byte_data.h" @@ -16,9 +13,7 @@ namespace gpu { IMPLEMENT_WRAPPERTYPEINFO(flutter_gpu, HostBuffer); -HostBuffer::HostBuffer(Context* context) - : host_buffer_(impeller::HostBuffer::Create( - context->GetContext()->GetResourceAllocator())) {} +HostBuffer::HostBuffer() : host_buffer_(impeller::HostBuffer::Create()) {} HostBuffer::~HostBuffer() = default; @@ -47,9 +42,8 @@ std::optional HostBuffer::GetBufferViewForOffset( /// Exports /// -void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper, - flutter::gpu::Context* context) { - auto res = fml::MakeRefCounted(context); +void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper) { + auto res = fml::MakeRefCounted(); res->AssociateWithDartWrapper(wrapper); } diff --git a/lib/gpu/host_buffer.h b/lib/gpu/host_buffer.h index 75d33c739ac39..7b25f5182c721 100644 --- a/lib/gpu/host_buffer.h +++ b/lib/gpu/host_buffer.h @@ -9,7 +9,6 @@ #include "flutter/lib/ui/dart_wrapper.h" #include "impeller/core/buffer_view.h" #include "impeller/core/host_buffer.h" -#include "lib/gpu/context.h" #include "third_party/tonic/typed_data/dart_byte_data.h" namespace flutter { @@ -20,7 +19,7 @@ class HostBuffer : public RefCountedDartWrappable { FML_FRIEND_MAKE_REF_COUNTED(HostBuffer); public: - explicit HostBuffer(Context* context); + explicit HostBuffer(); ~HostBuffer() override; diff --git a/lib/gpu/lib/src/buffer.dart b/lib/gpu/lib/src/buffer.dart index abed1a7a04949..0e0edd7b50132 100644 --- a/lib/gpu/lib/src/buffer.dart +++ b/lib/gpu/lib/src/buffer.dart @@ -135,8 +135,8 @@ base class DeviceBuffer extends NativeFieldWrapperClass1 with Buffer { /// and automatically inserts padding between emplaced data if necessary. base class HostBuffer extends NativeFieldWrapperClass1 with Buffer { /// Creates a new HostBuffer. - HostBuffer(GpuContext gpuContext) { - _initialize(gpuContext); + HostBuffer() { + _initialize(); } @override @@ -161,9 +161,9 @@ base class HostBuffer extends NativeFieldWrapperClass1 with Buffer { } /// Wrap with native counterpart. - @Native( + @Native( symbol: 'InternalFlutterGpu_HostBuffer_Initialize') - external void _initialize(GpuContext gpuContext); + external void _initialize(); /// Append byte data to the end of the [HostBuffer] and produce a [BufferView] /// that references the new data in the buffer. diff --git a/shell/gpu/gpu_surface_gl_impeller.cc b/shell/gpu/gpu_surface_gl_impeller.cc index 53c457bdda6a4..19e2669c997a2 100644 --- a/shell/gpu/gpu_surface_gl_impeller.cc +++ b/shell/gpu/gpu_surface_gl_impeller.cc @@ -122,8 +122,7 @@ std::unique_ptr GPUSurfaceGLImpeller::AcquireFrame( fml::MakeCopyable( [aiks_context, picture = std::move(picture)]( impeller::RenderTarget& render_target) -> bool { - return aiks_context->Render(picture, render_target, - /*reset_host_buffer=*/true); + return aiks_context->Render(picture, render_target); })); }); diff --git a/shell/gpu/gpu_surface_metal_impeller.mm b/shell/gpu/gpu_surface_metal_impeller.mm index e08587ef64461..94302399c8481 100644 --- a/shell/gpu/gpu_surface_metal_impeller.mm +++ b/shell/gpu/gpu_surface_metal_impeller.mm @@ -163,7 +163,7 @@ std::move(surface), fml::MakeCopyable([aiks_context, picture = std::move(picture)]( impeller::RenderTarget& render_target) -> bool { - return aiks_context->Render(picture, render_target, /*reset_host_buffer=*/true); + return aiks_context->Render(picture, render_target); })); }); @@ -257,12 +257,12 @@ display_list->Dispatch(impeller_dispatcher, sk_cull_rect); auto picture = impeller_dispatcher.EndRecordingAsPicture(); - bool render_result = renderer->Render( - std::move(surface), - fml::MakeCopyable([aiks_context, picture = std::move(picture)]( - impeller::RenderTarget& render_target) -> bool { - return aiks_context->Render(picture, render_target, /*reset_host_buffer=*/true); - })); + bool render_result = + renderer->Render(std::move(surface), + fml::MakeCopyable([aiks_context, picture = std::move(picture)]( + impeller::RenderTarget& render_target) -> bool { + return aiks_context->Render(picture, render_target); + })); if (!render_result) { FML_LOG(ERROR) << "Failed to render Impeller frame"; return false; diff --git a/shell/gpu/gpu_surface_vulkan_impeller.cc b/shell/gpu/gpu_surface_vulkan_impeller.cc index cf2733baab5ea..917b5f0e6e11d 100644 --- a/shell/gpu/gpu_surface_vulkan_impeller.cc +++ b/shell/gpu/gpu_surface_vulkan_impeller.cc @@ -94,8 +94,7 @@ std::unique_ptr GPUSurfaceVulkanImpeller::AcquireFrame( fml::MakeCopyable( [aiks_context, picture = std::move(picture)]( impeller::RenderTarget& render_target) -> bool { - return aiks_context->Render(picture, render_target, - /*reset_host_buffer=*/true); + return aiks_context->Render(picture, render_target); })); }); diff --git a/shell/platform/embedder/embedder_external_view.cc b/shell/platform/embedder/embedder_external_view.cc index 592b89f9fdba2..23ecd22415424 100644 --- a/shell/platform/embedder/embedder_external_view.cc +++ b/shell/platform/embedder/embedder_external_view.cc @@ -107,7 +107,7 @@ bool EmbedderExternalView::Render(const EmbedderRenderTarget& render_target, auto dispatcher = impeller::DlDispatcher(); dispatcher.drawDisplayList(dl_builder.Build(), 1); return aiks_context->Render(dispatcher.EndRecordingAsPicture(), - *impeller_target, /*reset_host_buffer=*/true); + *impeller_target); } #endif // IMPELLER_SUPPORTS_RENDERING