forked from firka/flutter
Reverts "[Impeller] have Hostbuffer write directly to block allocated device buffers." (flutter/engine#49688)
Reverts flutter/engine#49505 Initiated by: jonahwilliams This change reverts the following previous change: Original Description: part of https://github.com/flutter/flutter/issues/140804 We can't use the existing host buffer abstraction as that requires us to collect all allocations up front. By itself, this isn't sufficient for #140804 , because we'll need a way to mark ranges as dirty and/or flush if we don't have host coherent memory. But by itself this change should be beneficial as we'll create fewer device buffers and should do less allocation in general. The size of the device buffers is 1024 Kb, somewhat arbitrarily chosen.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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> context_;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ std::shared_ptr<Texture> 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;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define FLUTTER_IMPELLER_BASE_ALLOCATION_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include "flutter/fml/mapping.h"
|
||||
|
||||
@@ -16,7 +16,8 @@ class Buffer {
|
||||
public:
|
||||
virtual ~Buffer();
|
||||
|
||||
virtual std::shared_ptr<const DeviceBuffer> GetDeviceBuffer() const = 0;
|
||||
virtual std::shared_ptr<const DeviceBuffer> GetDeviceBuffer(
|
||||
Allocator& allocator) const = 0;
|
||||
};
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -11,12 +11,11 @@ DeviceBuffer::DeviceBuffer(DeviceBufferDescriptor desc) : desc_(desc) {}
|
||||
DeviceBuffer::~DeviceBuffer() = default;
|
||||
|
||||
// |Buffer|
|
||||
std::shared_ptr<const DeviceBuffer> DeviceBuffer::GetDeviceBuffer() const {
|
||||
std::shared_ptr<const DeviceBuffer> DeviceBuffer::GetDeviceBuffer(
|
||||
Allocator& allocator) const {
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
void DeviceBuffer::Flush(std::optional<Range> range) const {}
|
||||
|
||||
BufferView DeviceBuffer::AsBufferView() const {
|
||||
BufferView view;
|
||||
view.buffer = shared_from_this();
|
||||
|
||||
@@ -38,21 +38,13 @@ class DeviceBuffer : public Buffer,
|
||||
uint16_t row_bytes) const;
|
||||
|
||||
// |Buffer|
|
||||
std::shared_ptr<const DeviceBuffer> GetDeviceBuffer() const;
|
||||
std::shared_ptr<const DeviceBuffer> 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> range = std::nullopt) const;
|
||||
|
||||
protected:
|
||||
const DeviceBufferDescriptor desc_;
|
||||
|
||||
|
||||
@@ -4,33 +4,22 @@
|
||||
|
||||
#include "impeller/core/host_buffer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <tuple>
|
||||
|
||||
#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> HostBuffer::Create(
|
||||
const std::shared_ptr<Allocator>& allocator) {
|
||||
return std::shared_ptr<HostBuffer>(new HostBuffer(allocator));
|
||||
std::shared_ptr<HostBuffer> HostBuffer::Create() {
|
||||
return std::shared_ptr<HostBuffer>(new HostBuffer());
|
||||
}
|
||||
|
||||
HostBuffer::HostBuffer(const std::shared_ptr<Allocator>& 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<const DeviceBuffer> 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<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
HostBuffer::HostBufferState::Emplace(size_t length,
|
||||
size_t align,
|
||||
const EmplaceProc& cb) {
|
||||
size_t HostBuffer::GetLength() const {
|
||||
return state_->GetLength();
|
||||
}
|
||||
|
||||
std::pair<uint8_t*, Range> 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();
|
||||
generation++;
|
||||
cb(GetBuffer() + old_length);
|
||||
|
||||
cb(GetCurrentBuffer()->OnGetContents() + old_length);
|
||||
GetCurrentBuffer()->Flush(Range{old_length, 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<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
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<const uint8_t*>(buffer),
|
||||
Range{0, length})) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return std::make_tuple(device_buffer->OnGetContents(), Range{0, length},
|
||||
device_buffer);
|
||||
std::shared_ptr<const DeviceBuffer>
|
||||
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<uint8_t*, Range> 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<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
HostBuffer::HostBufferState::Emplace(const void* buffer,
|
||||
size_t length,
|
||||
size_t align) {
|
||||
std::pair<uint8_t*, Range> 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
|
||||
|
||||
@@ -6,29 +6,20 @@
|
||||
#define FLUTTER_IMPELLER_CORE_HOST_BUFFER_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#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<HostBuffer> Create(
|
||||
const std::shared_ptr<Allocator>& allocator);
|
||||
static std::shared_ptr<HostBuffer> 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<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
Emplace(const void* buffer, size_t length);
|
||||
struct HostBufferState : public Buffer, public Allocation {
|
||||
std::shared_ptr<const DeviceBuffer> GetDeviceBuffer(
|
||||
Allocator& allocator) const override;
|
||||
|
||||
std::tuple<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
Emplace(size_t length, size_t align, const EmplaceProc& cb);
|
||||
[[nodiscard]] std::pair<uint8_t*, Range> Emplace(const void* buffer,
|
||||
size_t length);
|
||||
|
||||
std::tuple<uint8_t*, Range, std::shared_ptr<DeviceBuffer>>
|
||||
Emplace(const void* buffer, size_t length, size_t align);
|
||||
std::pair<uint8_t*, Range> Emplace(size_t length,
|
||||
size_t align,
|
||||
const EmplaceProc& cb);
|
||||
|
||||
std::pair<uint8_t*, Range> Emplace(const void* buffer,
|
||||
size_t length,
|
||||
size_t align);
|
||||
|
||||
void Reset();
|
||||
|
||||
size_t GetLength() const { return offset; }
|
||||
|
||||
void MaybeCreateNewBuffer(size_t required_size);
|
||||
|
||||
std::shared_ptr<DeviceBuffer> GetCurrentBuffer() {
|
||||
return device_buffers[frame_index][current_buffer];
|
||||
}
|
||||
|
||||
std::shared_ptr<Allocator> allocator;
|
||||
std::array<std::vector<std::shared_ptr<DeviceBuffer>>, kHostBufferArenaSize>
|
||||
device_buffers;
|
||||
size_t current_buffer = 0u;
|
||||
size_t offset = 0u;
|
||||
size_t frame_index = 0u;
|
||||
mutable std::shared_ptr<DeviceBuffer> device_buffer;
|
||||
mutable size_t device_buffer_generation = 0u;
|
||||
size_t generation = 1u;
|
||||
std::string label;
|
||||
};
|
||||
|
||||
std::shared_ptr<HostBufferState> state_ = std::make_shared<HostBufferState>();
|
||||
|
||||
// |Buffer|
|
||||
std::shared_ptr<const DeviceBuffer> GetDeviceBuffer(
|
||||
Allocator& allocator) const override;
|
||||
|
||||
[[nodiscard]] BufferView Emplace(const void* buffer, size_t length);
|
||||
|
||||
explicit HostBuffer(const std::shared_ptr<Allocator>& allocator);
|
||||
HostBuffer();
|
||||
|
||||
HostBuffer(const HostBuffer&) = delete;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -217,7 +217,7 @@ bool AtlasContents::Render(const ContentContext& renderer,
|
||||
VertexBufferBuilder<VS::PerVertexData> 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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -96,12 +96,11 @@ bool ClipContents::Render(const ContentContext& renderer,
|
||||
auto vertices =
|
||||
VertexBufferBuilder<VS::PerVertexData>{}
|
||||
.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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -184,12 +184,10 @@ ContentContext::ContentContext(
|
||||
render_target_cache_(render_target_allocator == nullptr
|
||||
? std::make_shared<RenderTargetCache>(
|
||||
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 =
|
||||
|
||||
@@ -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> context_;
|
||||
std::shared_ptr<LazyGlyphAtlas> lazy_glyph_atlas_;
|
||||
@@ -947,7 +940,6 @@ class ContentContext {
|
||||
std::shared_ptr<scene::SceneContext> scene_context_;
|
||||
#endif // IMPELLER_ENABLE_3D
|
||||
std::shared_ptr<RenderTargetAllocator> render_target_cache_;
|
||||
std::shared_ptr<HostBuffer> host_buffer_;
|
||||
bool wireframe_ = false;
|
||||
|
||||
ContentContext(const ContentContext&) = delete;
|
||||
|
||||
@@ -146,7 +146,7 @@ static std::optional<Entity> AdvancedBlend(
|
||||
|
||||
ContentContext::SubpassCallback callback = [&](const ContentContext& renderer,
|
||||
RenderPass& pass) {
|
||||
auto& host_buffer = renderer.GetTransientsBuffer();
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
|
||||
auto size = pass.GetRenderTargetSize();
|
||||
VertexBufferBuilder<typename VS::PerVertexData> vtx_builder;
|
||||
@@ -264,7 +264,7 @@ std::optional<Entity> 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<Entity> 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<Entity> 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)",
|
||||
|
||||
@@ -89,7 +89,7 @@ std::optional<Entity> 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<VS::PerVertexData> vtx_builder;
|
||||
auto origin = coverage.GetOrigin();
|
||||
|
||||
@@ -72,7 +72,7 @@ std::optional<Entity> 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;
|
||||
|
||||
@@ -155,7 +155,7 @@ std::optional<Entity> DirectionalGaussianBlurFilterContents::RenderFilter(
|
||||
ContentContext::SubpassCallback subpass_callback = [&](const ContentContext&
|
||||
renderer,
|
||||
RenderPass& pass) {
|
||||
auto& host_buffer = renderer.GetTransientsBuffer();
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
|
||||
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
|
||||
vtx_builder.AddVertices({
|
||||
|
||||
@@ -75,7 +75,7 @@ fml::StatusOr<RenderTarget> 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<RenderTarget> 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);
|
||||
|
||||
@@ -62,7 +62,7 @@ std::optional<Entity> 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;
|
||||
|
||||
@@ -75,7 +75,7 @@ std::optional<Entity> DirectionalMorphologyFilterContents::RenderFilter(
|
||||
|
||||
ContentContext::SubpassCallback callback = [&](const ContentContext& renderer,
|
||||
RenderPass& pass) {
|
||||
auto& host_buffer = renderer.GetTransientsBuffer();
|
||||
auto& host_buffer = pass.GetTransientsBuffer();
|
||||
|
||||
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
|
||||
vtx_builder.AddVertices({
|
||||
|
||||
@@ -62,7 +62,7 @@ std::optional<Entity> 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;
|
||||
|
||||
@@ -91,7 +91,7 @@ std::optional<Entity> 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() *
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#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<VT*>(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<VT*>(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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -75,7 +75,7 @@ GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer,
|
||||
if (cap_ == Cap::kRound) {
|
||||
std::shared_ptr<Tessellator> 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> 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];
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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_),
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#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"
|
||||
|
||||
|
||||
@@ -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(<int>[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(<double>[
|
||||
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(<double>[
|
||||
-0.5, -0.5, //
|
||||
0.5, 0.5, //
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_
|
||||
#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_CONTEXT_GLES_H_
|
||||
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#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"
|
||||
|
||||
@@ -57,10 +57,6 @@ bool DeviceBufferGLES::OnCopyHostBuffer(const uint8_t* source,
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceBufferGLES::Flush(std::optional<Range> range) const {
|
||||
generation_++;
|
||||
}
|
||||
|
||||
static GLenum ToTarget(DeviceBufferGLES::BindingType type) {
|
||||
switch (type) {
|
||||
case DeviceBufferGLES::BindingType::kArrayBuffer:
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#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> range = std::nullopt) const override;
|
||||
|
||||
private:
|
||||
ReactorGLES::Ref reactor_;
|
||||
HandleGLES handle_;
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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> range) const override;
|
||||
|
||||
DeviceBufferMTL(const DeviceBufferMTL&) = delete;
|
||||
|
||||
DeviceBufferMTL& operator=(const DeviceBufferMTL&) = delete;
|
||||
|
||||
@@ -78,16 +78,6 @@ std::shared_ptr<Texture> DeviceBufferMTL::AsTexture(
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeviceBufferMTL::Flush(std::optional<Range> 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;
|
||||
|
||||
@@ -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 @@ bool RenderPassMTL::EncodeCommands(const std::shared_ptr<Allocator>& allocator,
|
||||
if (!index_buffer) {
|
||||
return false;
|
||||
}
|
||||
auto device_buffer = index_buffer->GetDeviceBuffer();
|
||||
auto device_buffer = index_buffer->GetDeviceBuffer(*allocator);
|
||||
if (!device_buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -95,7 +95,6 @@ class CommandEncoderVK {
|
||||
std::shared_ptr<TrackedObjectsVK> tracked_objects_;
|
||||
std::shared_ptr<QueueVK> queue_;
|
||||
const std::shared_ptr<FenceWaiterVK> fence_waiter_;
|
||||
std::shared_ptr<HostBuffer> host_buffer_;
|
||||
bool is_valid_ = true;
|
||||
|
||||
void Reset();
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
#include <utility>
|
||||
|
||||
#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<CommandPoolMap> 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<std::weak_ptr<CommandPoolVK>>> g_all_pools_map
|
||||
IPLR_GUARDED_BY(g_all_pools_map_mutex);
|
||||
static std::unordered_map<const ContextVK*,
|
||||
std::vector<std::weak_ptr<CommandPoolVK>>>
|
||||
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<CommandPoolVK> CommandPoolRecyclerVK::Get() {
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#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<ContextVK>& context_;
|
||||
|
||||
// Used to retain a reference on these until the pool is reset.
|
||||
std::vector<vk::UniqueCommandBuffer> collected_buffers_ IPLR_GUARDED_BY(
|
||||
pool_mutex_);
|
||||
std::vector<vk::UniqueCommandBuffer> collected_buffers_
|
||||
IPLR_GUARDED_BY(pool_mutex_);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
#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"
|
||||
|
||||
@@ -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> 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);
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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> range) const override;
|
||||
|
||||
DeviceBufferVK(const DeviceBufferVK&) = delete;
|
||||
|
||||
DeviceBufferVK& operator=(const DeviceBufferVK&) = delete;
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <memory>
|
||||
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/core/host_buffer.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
#define FLUTTER_IMPELLER_RENDERER_BLIT_PASS_H_
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#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<Allocator>& transients_allocator) const = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<HostBuffer> transients_buffer_;
|
||||
|
||||
explicit BlitPass();
|
||||
|
||||
virtual void OnSetLabel(std::string label) = 0;
|
||||
|
||||
@@ -5,20 +5,26 @@
|
||||
#include "impeller/renderer/compute_pass.h"
|
||||
#include <memory>
|
||||
|
||||
#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<const Context> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<SS::VertexBufferCount*>(
|
||||
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;
|
||||
|
||||
@@ -62,7 +62,6 @@ ComputeTessellator& ComputeTessellator::SetQuadraticTolerance(Scalar value) {
|
||||
|
||||
ComputeTessellator::Status ComputeTessellator::Tessellate(
|
||||
const Path& path,
|
||||
HostBuffer& host_buffer,
|
||||
const std::shared_ptr<Context>& 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<uint32_t>(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));
|
||||
|
||||
@@ -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>& context,
|
||||
BufferView vertex_buffer,
|
||||
BufferView vertex_buffer_count,
|
||||
|
||||
@@ -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<CS::Output<kCount>>(
|
||||
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<CS::OutputData<kCount>>(
|
||||
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<CS::OutputData<kCount>>(
|
||||
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<CS2>;
|
||||
|
||||
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<CS::Output<kCount>>(
|
||||
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<CS::Output<kCount>>(
|
||||
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)));
|
||||
|
||||
@@ -180,6 +180,10 @@ class Context {
|
||||
/// pending work.
|
||||
virtual void SetSyncPresentation(bool value) {}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Accessor for a pool of HostBuffers.
|
||||
Pool<HostBuffer>& 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<std::function<void()>> per_frame_task_;
|
||||
|
||||
private:
|
||||
mutable Pool<HostBuffer> host_buffer_pool_ = Pool<HostBuffer>(1'000'000);
|
||||
|
||||
Context(const Context&) = delete;
|
||||
|
||||
Context& operator=(const Context&) = delete;
|
||||
|
||||
@@ -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
|
||||
@@ -14,9 +14,19 @@ RenderPass::RenderPass(std::weak_ptr<const Context> 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<HostBuffer> transients_buffer_;
|
||||
std::vector<Command> commands_;
|
||||
const Matrix orthographic_;
|
||||
|
||||
|
||||
@@ -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<VS::PerVertexData> 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);
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <utility>
|
||||
|
||||
#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,
|
||||
|
||||
@@ -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> context)
|
||||
return;
|
||||
}
|
||||
}
|
||||
host_buffer_ = HostBuffer::Create(GetContext()->GetResourceAllocator());
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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<Texture> 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<Texture> placeholder_texture_;
|
||||
std::shared_ptr<HostBuffer> host_buffer_;
|
||||
|
||||
SceneContext(const SceneContext&) = delete;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
#include "impeller/core/allocator.h"
|
||||
#include "impeller/scene/importer/conversions.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 {
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
|
||||
#include "flutter/lib/gpu/host_buffer.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#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<impeller::BufferView> HostBuffer::GetBufferViewForOffset(
|
||||
/// Exports
|
||||
///
|
||||
|
||||
void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper,
|
||||
flutter::gpu::Context* context) {
|
||||
auto res = fml::MakeRefCounted<flutter::gpu::HostBuffer>(context);
|
||||
void InternalFlutterGpu_HostBuffer_Initialize(Dart_Handle wrapper) {
|
||||
auto res = fml::MakeRefCounted<flutter::gpu::HostBuffer>();
|
||||
res->AssociateWithDartWrapper(wrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<HostBuffer> {
|
||||
FML_FRIEND_MAKE_REF_COUNTED(HostBuffer);
|
||||
|
||||
public:
|
||||
explicit HostBuffer(Context* context);
|
||||
explicit HostBuffer();
|
||||
|
||||
~HostBuffer() override;
|
||||
|
||||
|
||||
@@ -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<Void Function(Handle, Handle)>(
|
||||
@Native<Void Function(Handle)>(
|
||||
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.
|
||||
|
||||
@@ -122,8 +122,7 @@ std::unique_ptr<SurfaceFrame> 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);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromCAMetalLa
|
||||
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 @@ std::unique_ptr<SurfaceFrame> GPUSurfaceMetalImpeller::AcquireFrameFromMTLTextur
|
||||
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;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user