Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. #52510

Merged
merged 17 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/licenses_golden/excluded_files
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@
../../../flutter/impeller/display_list/skia_conversions_unittests.cc
../../../flutter/impeller/docs
../../../flutter/impeller/entity/contents/clip_contents_unittests.cc
../../../flutter/impeller/entity/contents/content_context_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
Expand Down
10 changes: 4 additions & 6 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "flutter/impeller/aiks/aiks_unittests.h"

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
Expand All @@ -22,7 +21,6 @@
#include "impeller/aiks/paint_pass_delegate.h"
#include "impeller/aiks/testing/context_spy.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/render_target_cache.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
#include "impeller/geometry/geometry_asserts.h"
Expand All @@ -35,7 +33,6 @@
#include "impeller/renderer/command_buffer.h"
#include "impeller/renderer/snapshot.h"
#include "impeller/typographer/backends/skia/text_frame_skia.h"
#include "impeller/typographer/backends/skia/typographer_context_skia.h"
#include "impeller/typographer/backends/stb/text_frame_stb.h"
#include "impeller/typographer/backends/stb/typeface_stb.h"
#include "impeller/typographer/backends/stb/typographer_context_stb.h"
Expand Down Expand Up @@ -3061,12 +3058,13 @@ TEST_P(AiksTest, MipmapGenerationWorksCorrectly) {
auto texture =
GetContext()->GetResourceAllocator()->CreateTexture(texture_descriptor);

ASSERT_TRUE(!!texture);
ASSERT_TRUE(texture->SetContents(mapping));

auto device_buffer =
GetContext()->GetResourceAllocator()->CreateBufferWithCopy(*mapping);
auto command_buffer = GetContext()->CreateCommandBuffer();
auto blit_pass = command_buffer->CreateBlitPass();

blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(device_buffer)),
texture);
blit_pass->GenerateMipmap(texture);
EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
EXPECT_TRUE(GetContext()->GetCommandQueue()->Submit({command_buffer}).ok());
Expand Down
15 changes: 0 additions & 15 deletions impeller/core/device_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ BufferView DeviceBuffer::AsBufferView(std::shared_ptr<DeviceBuffer> buffer) {
return view;
}

std::shared_ptr<Texture> DeviceBuffer::AsTexture(
Allocator& allocator,
const TextureDescriptor& descriptor,
uint16_t row_bytes) const {
auto texture = allocator.CreateTexture(descriptor);
if (!texture) {
return nullptr;
}
if (!texture->SetContents(std::make_shared<fml::NonOwnedMapping>(
OnGetContents(), desc_.size))) {
return nullptr;
}
return texture;
}

const DeviceBufferDescriptor& DeviceBuffer::GetDeviceBufferDescriptor() const {
return desc_;
}
Expand Down
6 changes: 0 additions & 6 deletions impeller/core/device_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "impeller/core/buffer_view.h"
#include "impeller/core/device_buffer_descriptor.h"
#include "impeller/core/range.h"
#include "impeller/core/texture.h"

namespace impeller {

Expand All @@ -31,11 +30,6 @@ class DeviceBuffer {
/// @brief Create a buffer view of this entire buffer.
static BufferView AsBufferView(std::shared_ptr<DeviceBuffer> buffer);

virtual std::shared_ptr<Texture> AsTexture(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, I didn't know this API existed.

Allocator& allocator,
const TextureDescriptor& descriptor,
uint16_t row_bytes) const;

const DeviceBufferDescriptor& GetDeviceBufferDescriptor() const;

virtual uint8_t* OnGetContents() const = 0;
Expand Down
6 changes: 6 additions & 0 deletions impeller/core/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class Texture {

virtual void SetLabel(std::string_view label) = 0;

// Deprecated: use BlitPass::AddCopy instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An issue to followup on cleaning this up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[[nodiscard]] bool SetContents(const uint8_t* contents,
size_t length,
size_t slice = 0,
bool is_opaque = false);

// Deprecated: use BlitPass::AddCopy instead.
[[nodiscard]] bool SetContents(std::shared_ptr<const fml::Mapping> mapping,
size_t slice = 0,
bool is_opaque = false);
Expand All @@ -39,6 +41,10 @@ class Texture {

const TextureDescriptor& GetTextureDescriptor() const;

/// Update the coordinate system used by the texture.
///
/// The setting is used to conditionally invert the coordinates to
/// account for the different origin of GLES textures.
void SetCoordinateSystem(TextureCoordinateSystem coordinate_system);

TextureCoordinateSystem GetCoordinateSystem() const;
Expand Down
1 change: 0 additions & 1 deletion impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impeller_component("entity_unittests") {

sources = [
"contents/clip_contents_unittests.cc",
"contents/content_context_unittests.cc",
"contents/filters/gaussian_blur_filter_contents_unittests.cc",
"contents/filters/inputs/filter_input_unittests.cc",
"contents/host_buffer_unittests.cc",
Expand Down
12 changes: 11 additions & 1 deletion impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,17 @@ ContentContext::ContentContext(
desc.size = ISize{1, 1};
empty_texture_ = GetContext()->GetResourceAllocator()->CreateTexture(desc);
auto data = Color::BlackTransparent().ToR8G8B8A8();
if (!empty_texture_->SetContents(data.data(), 4)) {
auto cmd_buffer = GetContext()->CreateCommandBuffer();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to change a few places to use the blitpass to make sure it works. We should eventually remove Texture::SetContents.

auto blit_pass = cmd_buffer->CreateBlitPass();
auto& host_buffer = GetTransientsBuffer();
auto buffer_view = host_buffer.Emplace(data);
blit_pass->AddCopy(buffer_view, empty_texture_);

if (!blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()) ||
!GetContext()
->GetCommandQueue()
->Submit({std::move(cmd_buffer)})
.ok()) {
VALIDATION_LOG << "Failed to create empty texture.";
}
}
Expand Down
Loading