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

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented May 2, 2024

part of flutter/flutter#138798

Works around flutter/flutter#144498 for the glyph atlas.

Adds BlitPass::AddCopy implementation for GLES, which is mostly a copy of Texture::SetContents. Updates the glyph atlas to use a blit pass and device private textures instead of set contents (which is unsafely on Metal).

This also removes DeviceBuffer::AsTexture, which isn't actually used anywhere - and creates a linear texture on iOS (and fails with an unsupported API on simulators).

Note that in general, we don't actually have support for hostVisible textures on GLES or Vulkan. Instead, VMA is falling back to device private textures. We may want to, separately, remove the concept of host visible from textures - and similarly remove the concept of transient from buffers.

@jonahwilliams jonahwilliams changed the title [WIP][Impeller] Make BlitPass responsible for setting Texture contents. [WIP][Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. May 3, 2024
@jonahwilliams jonahwilliams changed the title [WIP][Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. [Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. May 3, 2024
@jonahwilliams jonahwilliams marked this pull request as ready for review May 3, 2024 19:11
@@ -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.

@@ -864,6 +853,29 @@ std::optional<Entity> BlendFilterContents::CreateFramebufferAdvancedBlend(

std::shared_ptr<CommandBuffer> cmd_buffer =
renderer.GetContext()->CreateCommandBuffer();

// Generate a 1x1 texture to implement foreground color blending.
if (foreground_color.has_value()) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is better because we don't need to create an extra cmd buffer or host texture for the upload.

@@ -450,6 +473,21 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
}
atlas_context_skia.UpdateBitmap(bitmap);

// If the new atlas size is the same size as the previous texture, reuse the
Copy link
Member Author

Choose a reason for hiding this comment

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

This was an optimization that was reverted because TextureMTL::SetContents is unsafe.

@jonahwilliams jonahwilliams requested a review from chinmaygarde May 4, 2024 21:06
@jonahwilliams
Copy link
Member Author

@chinmaygarde PTAL

@chinmaygarde
Copy link
Member

Whoops. Missing this. Looking.

@@ -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.

@@ -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.

case PixelFormat::kR16G16B16A16Float:
internal_format = GL_RGBA;
external_format = GL_RGBA;
type = GL_HALF_FLOAT;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these are supported by GL ES 2.0 but we will probably put these behind a capability check anyway I suppose.

if (!gl_handle.has_value()) {
VALIDATION_LOG
<< "Texture was collected before it could be uploaded to the GPU.";
return true;
Copy link
Member

Choose a reason for hiding this comment

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

Return false here right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

{
BarrierVK barrier;
barrier.cmd_buffer = cmd_buffer;
barrier.src_access = vk::AccessFlagBits::eColorAttachmentWrite |
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why you need the ColorAttachmentWrite src access. Only the transfer write should be sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Other than the return false; in the GLES blit, I think everything else lgtm with minor nits. I didn't look super closely at the mostly mechanical replacements of the SetContents call but I trust those are fine. Thanks!

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label May 7, 2024
@auto-submit auto-submit bot merged commit 8b0ab93 into flutter:main May 8, 2024
33 checks passed
@jonahwilliams jonahwilliams deleted the make_image_safe branch May 8, 2024 00:03
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 8, 2024
…147955)

flutter/engine@1c52274...8b0ab93

2024-05-08 [email protected] [Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. (flutter/engine#52510)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request May 8, 2024
… of origin for buffer to texture copies. (#52555)

Based on #52510

Work towards flutter/flutter#138798

Change IPoint destination_origin to IRect destination_region, which allows us to specify an area smaller than the entire texture to replace. This will eventually allow us to only upload individual glyphs. This fixes the cubemap issue I previously hit: each face needs to track initialization separately.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants