Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/blit_command_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ bool BlitCopyBufferToTextureCommandGLES::Encode(
0u, // border
data.external_format, // external format
data.type, // type
tex_data // data
nullptr // data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is correctly initialized below, but needs to be nullptr, or the driver may read out of bounds if we're only updating a subregion.

);
texture_gles.MarkSliceInitialized(slice);
}
Expand Down
24 changes: 24 additions & 0 deletions impeller/renderer/blit_pass_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,29 @@ TEST_P(BlitPassTest, ChecksInvalidSliceParameters) {
std::nullopt, "", /*slice=*/0));
}

TEST_P(BlitPassTest, CanBlitSmallRegionToUninitializedTexture) {
auto context = GetContext();
auto cmd_buffer = context->CreateCommandBuffer();
auto blit_pass = cmd_buffer->CreateBlitPass();

TextureDescriptor dst_format;
dst_format.storage_mode = StorageMode::kDevicePrivate;
dst_format.format = PixelFormat::kR8G8B8A8UNormInt;
dst_format.size = {1000, 1000};
auto dst = context->GetResourceAllocator()->CreateTexture(dst_format);

DeviceBufferDescriptor src_format;
src_format.size = 4;
src_format.storage_mode = StorageMode::kHostVisible;
auto src = context->GetResourceAllocator()->CreateBuffer(src_format);

ASSERT_TRUE(dst);

EXPECT_TRUE(blit_pass->AddCopy(DeviceBuffer::AsBufferView(src), dst,
IRect::MakeLTRB(0, 0, 1, 1), "", /*slice=*/0));
EXPECT_TRUE(blit_pass->EncodeCommands(GetContext()->GetResourceAllocator()));
EXPECT_TRUE(context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok());
}

} // namespace testing
} // namespace impeller
55 changes: 41 additions & 14 deletions impeller/typographer/backends/skia/typographer_context_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,43 @@ static bool UpdateAtlasBitmap(const GlyphAtlas& atlas,
return true;
}

// The texture needs to be cleared to transparent black so that linearly
// samplex rotated/skewed glyphs do not grab uninitialized data.
bool ClearTextureToTransparentBlack(Context& context,
HostBuffer& host_buffer,
std::shared_ptr<CommandBuffer>& cmd_buffer,
std::shared_ptr<BlitPass>& blit_pass,
std::shared_ptr<Texture>& texture) {
// The R8/A8 textures used for certain glyphs is not supported as color
// attachments in most graphics drivers. To be safe, just do a CPU clear
// for these.
if (texture->GetTextureDescriptor().format ==
context.GetCapabilities()->GetDefaultGlyphAtlasFormat()) {
size_t byte_size =
texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
BufferView buffer_view =
host_buffer.Emplace(nullptr, byte_size, DefaultUniformAlignment());

::memset(buffer_view.buffer->OnGetContents() + buffer_view.range.offset, 0,
byte_size);
buffer_view.buffer->Flush();
return blit_pass->AddCopy(buffer_view, texture);
}
// In all other cases, we can use a render pass to clear to a transparent
// color.
ColorAttachment attachment;
attachment.clear_color = Color::BlackTransparent();
attachment.load_action = LoadAction::kClear;
attachment.store_action = StoreAction::kStore;
attachment.texture = texture;

RenderTarget render_target;
render_target.SetColorAttachment(attachment, 0u);

auto render_pass = cmd_buffer->CreateRenderPass(render_target);
return render_pass->EncodeCommands();
}

std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
Context& context,
GlyphAtlas::Type type,
Expand Down Expand Up @@ -455,28 +492,18 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
}
descriptor.size = atlas_size;
descriptor.storage_mode = StorageMode::kDevicePrivate;
descriptor.usage = TextureUsage::kShaderRead | TextureUsage::kRenderTarget;
new_texture = context.GetResourceAllocator()->CreateTexture(descriptor);
}

if (!new_texture) {
return nullptr;
}
// The texture needs to be cleared to transparent black so that linearly
// samplex rotated/skewed glyphs do not grab uninitialized data. We could
// instead use a render pass to clear to transparent black, but there are
// more restrictions on what kinds of textures can be bound on GLES.
{
auto bytes =
new_texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
BufferView buffer_view =
host_buffer.Emplace(nullptr, bytes, DefaultUniformAlignment());

::memset(buffer_view.buffer->OnGetContents() + buffer_view.range.offset, 0,
bytes);
blit_pass->AddCopy(buffer_view, new_texture);
}

new_texture->SetLabel("GlyphAtlas");

ClearTextureToTransparentBlack(context, host_buffer, cmd_buffer, blit_pass,
new_texture);
if (!UpdateAtlasBitmap(*glyph_atlas, blit_pass, host_buffer, new_texture,
font_glyph_pairs)) {
return nullptr;
Expand Down