forked from firka/flutter
[Impeller] Support copy from buffer to texture for GLES blitpass, use blit pass to set contents in glyph atlas. (flutter/engine#52510)
part of https://github.com/flutter/flutter/issues/138798 Works around https://github.com/flutter/flutter/issues/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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "flutter/impeller/aiks/aiks_unittests.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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());
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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(
|
||||
Allocator& allocator,
|
||||
const TextureDescriptor& descriptor,
|
||||
uint16_t row_bytes) const;
|
||||
|
||||
const DeviceBufferDescriptor& GetDeviceBufferDescriptor() const;
|
||||
|
||||
virtual uint8_t* OnGetContents() const = 0;
|
||||
|
||||
@@ -20,11 +20,13 @@ class Texture {
|
||||
|
||||
virtual void SetLabel(std::string_view label) = 0;
|
||||
|
||||
// Deprecated: use BlitPass::AddCopy instead.
|
||||
[[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);
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
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.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,356 +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 <cstdint>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fml/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "impeller/base/backend_cast.h"
|
||||
#include "impeller/base/comparable.h"
|
||||
#include "impeller/core/allocator.h"
|
||||
#include "impeller/core/device_buffer_descriptor.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/core/texture_descriptor.h"
|
||||
#include "impeller/entity/contents/content_context.h"
|
||||
#include "impeller/entity/contents/test/recording_render_pass.h"
|
||||
#include "impeller/geometry/color.h"
|
||||
#include "impeller/renderer/capabilities.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
#include "impeller/renderer/command_queue.h"
|
||||
#include "impeller/renderer/pipeline.h"
|
||||
#include "impeller/renderer/pipeline_descriptor.h"
|
||||
#include "impeller/renderer/pipeline_library.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
#include "impeller/renderer/shader_function.h"
|
||||
#include "impeller/renderer/shader_library.h"
|
||||
|
||||
namespace impeller {
|
||||
namespace testing {
|
||||
|
||||
namespace {
|
||||
class FakeTexture : public Texture {
|
||||
public:
|
||||
explicit FakeTexture(const TextureDescriptor& desc) : Texture(desc) {}
|
||||
|
||||
~FakeTexture() override {}
|
||||
|
||||
void SetLabel(std::string_view label) {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
|
||||
ISize GetSize() const override { return {1, 1}; }
|
||||
|
||||
Scalar GetYCoordScale() const override { return 1.0; }
|
||||
|
||||
bool OnSetContents(const uint8_t* contents,
|
||||
size_t length,
|
||||
size_t slice) override {
|
||||
if (GetTextureDescriptor().GetByteSizeOfBaseMipLevel() != length) {
|
||||
return false;
|
||||
}
|
||||
did_set_contents = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
|
||||
size_t slice) override {
|
||||
did_set_contents = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool did_set_contents = false;
|
||||
};
|
||||
|
||||
class FakeAllocator : public Allocator,
|
||||
public BackendCast<FakeAllocator, Allocator> {
|
||||
public:
|
||||
FakeAllocator() : Allocator() {}
|
||||
|
||||
uint16_t MinimumBytesPerRow(PixelFormat format) const override { return 0; }
|
||||
ISize GetMaxTextureSizeSupported() const override { return ISize(1, 1); }
|
||||
|
||||
std::shared_ptr<DeviceBuffer> OnCreateBuffer(
|
||||
const DeviceBufferDescriptor& desc) override {
|
||||
return nullptr;
|
||||
}
|
||||
std::shared_ptr<Texture> OnCreateTexture(
|
||||
const TextureDescriptor& desc) override {
|
||||
if (desc.size == ISize{1, 1}) {
|
||||
auto result = std::make_shared<FakeTexture>(desc);
|
||||
textures.push_back(result);
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<FakeTexture>> textures = {};
|
||||
};
|
||||
|
||||
class FakePipeline : public Pipeline<PipelineDescriptor> {
|
||||
public:
|
||||
FakePipeline(std::weak_ptr<PipelineLibrary> library,
|
||||
const PipelineDescriptor& desc)
|
||||
: Pipeline(std::move(library), desc) {}
|
||||
|
||||
~FakePipeline() override {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
};
|
||||
|
||||
class FakeComputePipeline : public Pipeline<ComputePipelineDescriptor> {
|
||||
public:
|
||||
FakeComputePipeline(std::weak_ptr<PipelineLibrary> library,
|
||||
const ComputePipelineDescriptor& desc)
|
||||
: Pipeline(std::move(library), desc) {}
|
||||
|
||||
~FakeComputePipeline() override {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
};
|
||||
|
||||
class FakePipelineLibrary : public PipelineLibrary {
|
||||
public:
|
||||
FakePipelineLibrary() {}
|
||||
|
||||
~FakePipelineLibrary() override {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
|
||||
PipelineFuture<PipelineDescriptor> GetPipeline(PipelineDescriptor descriptor,
|
||||
bool async) override {
|
||||
auto pipeline =
|
||||
std::make_shared<FakePipeline>(weak_from_this(), descriptor);
|
||||
std::promise<std::shared_ptr<Pipeline<PipelineDescriptor>>> promise;
|
||||
promise.set_value(std::move(pipeline));
|
||||
return PipelineFuture<PipelineDescriptor>{
|
||||
.descriptor = descriptor,
|
||||
.future =
|
||||
std::shared_future<std::shared_ptr<Pipeline<PipelineDescriptor>>>(
|
||||
promise.get_future())};
|
||||
}
|
||||
|
||||
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
|
||||
ComputePipelineDescriptor descriptor,
|
||||
bool async) override {
|
||||
auto pipeline =
|
||||
std::make_shared<FakeComputePipeline>(weak_from_this(), descriptor);
|
||||
std::promise<std::shared_ptr<Pipeline<ComputePipelineDescriptor>>> promise;
|
||||
promise.set_value(std::move(pipeline));
|
||||
return PipelineFuture<ComputePipelineDescriptor>{
|
||||
.descriptor = descriptor,
|
||||
.future = std::shared_future<
|
||||
std::shared_ptr<Pipeline<ComputePipelineDescriptor>>>(
|
||||
promise.get_future())};
|
||||
}
|
||||
|
||||
void RemovePipelinesWithEntryPoint(
|
||||
std::shared_ptr<const ShaderFunction> function) {}
|
||||
};
|
||||
|
||||
class FakeShaderFunction : public ShaderFunction {
|
||||
public:
|
||||
FakeShaderFunction(UniqueID parent_library_id,
|
||||
std::string name,
|
||||
ShaderStage stage)
|
||||
: ShaderFunction(parent_library_id, std::move(name), stage){};
|
||||
|
||||
~FakeShaderFunction() override {}
|
||||
};
|
||||
|
||||
class FakeShaderLibrary : public ShaderLibrary {
|
||||
public:
|
||||
~FakeShaderLibrary() override {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
|
||||
std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
|
||||
ShaderStage stage) {
|
||||
return std::make_shared<FakeShaderFunction>(UniqueID{}, std::string(name),
|
||||
stage);
|
||||
}
|
||||
|
||||
void RegisterFunction(std::string name,
|
||||
ShaderStage stage,
|
||||
std::shared_ptr<fml::Mapping> code,
|
||||
RegistrationCallback callback) override {}
|
||||
|
||||
void UnregisterFunction(std::string name, ShaderStage stage) override {}
|
||||
};
|
||||
|
||||
class FakeCommandBuffer : public CommandBuffer {
|
||||
public:
|
||||
explicit FakeCommandBuffer(std::weak_ptr<const Context> context)
|
||||
: CommandBuffer(std::move(context)) {}
|
||||
|
||||
~FakeCommandBuffer() {}
|
||||
|
||||
bool IsValid() const override { return true; }
|
||||
|
||||
void SetLabel(const std::string& label) const override {}
|
||||
|
||||
std::shared_ptr<RenderPass> OnCreateRenderPass(
|
||||
RenderTarget render_target) override {
|
||||
return std::make_shared<RecordingRenderPass>(nullptr, context_.lock(),
|
||||
render_target);
|
||||
}
|
||||
|
||||
std::shared_ptr<BlitPass> OnCreateBlitPass() override { FML_UNREACHABLE() }
|
||||
|
||||
virtual bool OnSubmitCommands(CompletionCallback callback) { return true; }
|
||||
|
||||
void OnWaitUntilScheduled() {}
|
||||
|
||||
std::shared_ptr<ComputePass> OnCreateComputePass() override {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
};
|
||||
|
||||
class FakeContext : public Context,
|
||||
public std::enable_shared_from_this<FakeContext> {
|
||||
public:
|
||||
explicit FakeContext(
|
||||
const std::string& gpu_model = "",
|
||||
PixelFormat default_color_format = PixelFormat::kR8G8B8A8UNormInt)
|
||||
: Context(),
|
||||
allocator_(std::make_shared<FakeAllocator>()),
|
||||
capabilities_(std::shared_ptr<Capabilities>(
|
||||
CapabilitiesBuilder()
|
||||
.SetDefaultColorFormat(default_color_format)
|
||||
.Build())),
|
||||
pipelines_(std::make_shared<FakePipelineLibrary>()),
|
||||
queue_(std::make_shared<CommandQueue>()),
|
||||
shader_library_(std::make_shared<FakeShaderLibrary>()),
|
||||
gpu_model_(gpu_model) {}
|
||||
|
||||
BackendType GetBackendType() const override { return BackendType::kVulkan; }
|
||||
std::string DescribeGpuModel() const override { return gpu_model_; }
|
||||
bool IsValid() const override { return true; }
|
||||
const std::shared_ptr<const Capabilities>& GetCapabilities() const override {
|
||||
return capabilities_;
|
||||
}
|
||||
std::shared_ptr<Allocator> GetResourceAllocator() const override {
|
||||
return allocator_;
|
||||
}
|
||||
std::shared_ptr<ShaderLibrary> GetShaderLibrary() const {
|
||||
return shader_library_;
|
||||
}
|
||||
std::shared_ptr<SamplerLibrary> GetSamplerLibrary() const { return nullptr; }
|
||||
std::shared_ptr<PipelineLibrary> GetPipelineLibrary() const {
|
||||
return pipelines_;
|
||||
}
|
||||
std::shared_ptr<CommandQueue> GetCommandQueue() const { return queue_; }
|
||||
std::shared_ptr<CommandBuffer> CreateCommandBuffer() const {
|
||||
return std::make_shared<FakeCommandBuffer>(shared_from_this());
|
||||
}
|
||||
void Shutdown() {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Allocator> allocator_;
|
||||
std::shared_ptr<const Capabilities> capabilities_;
|
||||
std::shared_ptr<FakePipelineLibrary> pipelines_;
|
||||
std::shared_ptr<CommandQueue> queue_;
|
||||
std::shared_ptr<ShaderLibrary> shader_library_;
|
||||
std::string gpu_model_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST(ContentContext, CachesPipelines) {
|
||||
auto context = std::make_shared<FakeContext>();
|
||||
|
||||
auto create_callback = [&]() {
|
||||
return std::make_shared<FakePipeline>(context->GetPipelineLibrary(),
|
||||
PipelineDescriptor{});
|
||||
};
|
||||
|
||||
ContentContext content_context(context, nullptr);
|
||||
ContentContextOptions optionsA{.blend_mode = BlendMode::kSourceOver};
|
||||
ContentContextOptions optionsB{.blend_mode = BlendMode::kSource};
|
||||
|
||||
auto pipelineA = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsA, create_callback);
|
||||
|
||||
auto pipelineA2 = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsA, create_callback);
|
||||
|
||||
auto pipelineA3 = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsB, create_callback);
|
||||
|
||||
auto pipelineB = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"B", optionsB, create_callback);
|
||||
|
||||
ASSERT_EQ(pipelineA.get(), pipelineA2.get());
|
||||
ASSERT_NE(pipelineA.get(), pipelineA3.get());
|
||||
ASSERT_NE(pipelineB.get(), pipelineA.get());
|
||||
}
|
||||
|
||||
TEST(ContentContext, InvalidatesAllPipelinesWithSameUniqueNameOnClear) {
|
||||
auto context = std::make_shared<FakeContext>();
|
||||
ContentContext content_context(context, nullptr);
|
||||
ContentContextOptions optionsA{.blend_mode = BlendMode::kSourceOver};
|
||||
ContentContextOptions optionsB{.blend_mode = BlendMode::kSource};
|
||||
|
||||
auto create_callback = [&]() {
|
||||
return std::make_shared<FakePipeline>(context->GetPipelineLibrary(),
|
||||
PipelineDescriptor{});
|
||||
};
|
||||
|
||||
auto pipelineA = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsA, create_callback);
|
||||
|
||||
auto pipelineA2 = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsB, create_callback);
|
||||
|
||||
auto pipelineB = content_context.GetCachedRuntimeEffectPipeline(
|
||||
"B", optionsB, create_callback);
|
||||
|
||||
ASSERT_TRUE(pipelineA);
|
||||
ASSERT_TRUE(pipelineA2);
|
||||
ASSERT_TRUE(pipelineB);
|
||||
|
||||
ASSERT_EQ(pipelineA, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsA, create_callback));
|
||||
ASSERT_EQ(pipelineA2, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsB, create_callback));
|
||||
ASSERT_EQ(pipelineB, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"B", optionsB, create_callback));
|
||||
|
||||
content_context.ClearCachedRuntimeEffectPipeline("A");
|
||||
|
||||
ASSERT_NE(pipelineA, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsA, create_callback));
|
||||
ASSERT_NE(pipelineA2, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"A", optionsB, create_callback));
|
||||
ASSERT_EQ(pipelineB, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"B", optionsB, create_callback));
|
||||
|
||||
content_context.ClearCachedRuntimeEffectPipeline("B");
|
||||
|
||||
ASSERT_NE(pipelineB, content_context.GetCachedRuntimeEffectPipeline(
|
||||
"B", optionsB, create_callback));
|
||||
}
|
||||
|
||||
TEST(ContentContext, InitializeCommonlyUsedShadersIfNeeded) {
|
||||
ScopedValidationFatal fatal_validations;
|
||||
// Set a pixel format that is larger than 32bpp.
|
||||
auto context = std::make_shared<FakeContext>("Mali G70",
|
||||
PixelFormat::kR16G16B16A16Float);
|
||||
ContentContext content_context(context, nullptr);
|
||||
|
||||
FakeAllocator& fake_allocator =
|
||||
FakeAllocator::Cast(*context->GetResourceAllocator());
|
||||
|
||||
#if IMPELLER_ENABLE_3D
|
||||
EXPECT_EQ(fake_allocator.textures.size(), 2u);
|
||||
#else
|
||||
EXPECT_EQ(fake_allocator.textures.size(), 1u);
|
||||
#endif // IMPELLER_ENABLE_3D
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
@@ -684,6 +684,8 @@ std::optional<Entity> BlendFilterContents::CreateFramebufferAdvancedBlend(
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> foreground_texture;
|
||||
|
||||
ContentContext::SubpassCallback subpass_callback = [&](const ContentContext&
|
||||
renderer,
|
||||
RenderPass& pass) {
|
||||
@@ -736,20 +738,7 @@ std::optional<Entity> BlendFilterContents::CreateFramebufferAdvancedBlend(
|
||||
// texture for the foreground color.
|
||||
std::shared_ptr<Texture> src_texture;
|
||||
if (foreground_color.has_value()) {
|
||||
TextureDescriptor desc;
|
||||
desc.size = {1, 1};
|
||||
desc.format = PixelFormat::kR8G8B8A8UNormInt;
|
||||
desc.storage_mode = StorageMode::kHostVisible;
|
||||
src_texture =
|
||||
renderer.GetContext()->GetResourceAllocator()->CreateTexture(desc);
|
||||
if (!src_texture) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!src_texture->SetContents(
|
||||
foreground_color->Premultiply().ToR8G8B8A8().data(), 4u)) {
|
||||
return false;
|
||||
}
|
||||
src_texture = foreground_texture;
|
||||
} else {
|
||||
auto src_snapshot =
|
||||
inputs[0]->GetSnapshot("ForegroundAdvancedBlend", renderer, entity);
|
||||
@@ -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()) {
|
||||
TextureDescriptor desc;
|
||||
desc.size = {1, 1};
|
||||
desc.format = PixelFormat::kR8G8B8A8UNormInt;
|
||||
desc.storage_mode = StorageMode::kDevicePrivate;
|
||||
foreground_texture =
|
||||
renderer.GetContext()->GetResourceAllocator()->CreateTexture(desc);
|
||||
if (!foreground_texture) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto blit_pass = cmd_buffer->CreateBlitPass();
|
||||
auto buffer_view = renderer.GetTransientsBuffer().Emplace(
|
||||
foreground_color->Premultiply().ToR8G8B8A8());
|
||||
|
||||
blit_pass->AddCopy(std::move(buffer_view), foreground_texture);
|
||||
if (!blit_pass->EncodeCommands(
|
||||
renderer.GetContext()->GetResourceAllocator())) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
auto render_target =
|
||||
renderer.MakeSubpass("FramebufferBlend", dst_snapshot->texture->GetSize(),
|
||||
cmd_buffer, subpass_callback);
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "impeller/entity/contents/gradient_generator.h"
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "impeller/base/strings.h"
|
||||
#include "impeller/core/device_buffer.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/core/texture.h"
|
||||
#include "impeller/entity/contents/content_context.h"
|
||||
#include "impeller/renderer/context.h"
|
||||
#include "impeller/renderer/render_pass.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
@@ -33,11 +32,20 @@ std::shared_ptr<Texture> CreateGradientTexture(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto mapping = std::make_shared<fml::DataMapping>(gradient_data.color_bytes);
|
||||
if (!texture->SetContents(mapping)) {
|
||||
FML_DLOG(ERROR) << "Could not copy contents into Impeller texture.";
|
||||
auto data_mapping =
|
||||
std::make_shared<fml::DataMapping>(gradient_data.color_bytes);
|
||||
auto buffer =
|
||||
context->GetResourceAllocator()->CreateBufferWithCopy(*data_mapping);
|
||||
|
||||
auto cmd_buffer = context->CreateCommandBuffer();
|
||||
auto blit_pass = cmd_buffer->CreateBlitPass();
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(buffer)), texture);
|
||||
|
||||
if (!blit_pass->EncodeCommands(context->GetResourceAllocator()) ||
|
||||
!context->GetCommandQueue()->Submit({std::move(cmd_buffer)}).ok()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
texture->SetLabel(impeller::SPrintF("Gradient(%p)", texture.get()).c_str());
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "flutter/display_list/testing/dl_test_snippets.h"
|
||||
#include "fml/logging.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "impeller/core/device_buffer.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/core/texture_descriptor.h"
|
||||
#include "impeller/entity/contents/atlas_contents.h"
|
||||
@@ -2070,6 +2071,9 @@ static std::vector<std::shared_ptr<Texture>> CreateTestYUVTextures(
|
||||
uv_data.push_back(j % 2 == 0 ? u : v);
|
||||
}
|
||||
}
|
||||
auto cmd_buffer = context->CreateCommandBuffer();
|
||||
auto blit_pass = cmd_buffer->CreateBlitPass();
|
||||
|
||||
impeller::TextureDescriptor y_texture_descriptor;
|
||||
y_texture_descriptor.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
y_texture_descriptor.format = PixelFormat::kR8UNormInt;
|
||||
@@ -2077,9 +2081,10 @@ static std::vector<std::shared_ptr<Texture>> CreateTestYUVTextures(
|
||||
auto y_texture =
|
||||
context->GetResourceAllocator()->CreateTexture(y_texture_descriptor);
|
||||
auto y_mapping = std::make_shared<fml::DataMapping>(y_data);
|
||||
if (!y_texture->SetContents(y_mapping)) {
|
||||
FML_DLOG(ERROR) << "Could not copy contents into Y texture.";
|
||||
}
|
||||
auto y_mapping_buffer =
|
||||
context->GetResourceAllocator()->CreateBufferWithCopy(*y_mapping);
|
||||
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(y_mapping_buffer), y_texture);
|
||||
|
||||
impeller::TextureDescriptor uv_texture_descriptor;
|
||||
uv_texture_descriptor.storage_mode = impeller::StorageMode::kHostVisible;
|
||||
@@ -2088,8 +2093,14 @@ static std::vector<std::shared_ptr<Texture>> CreateTestYUVTextures(
|
||||
auto uv_texture =
|
||||
context->GetResourceAllocator()->CreateTexture(uv_texture_descriptor);
|
||||
auto uv_mapping = std::make_shared<fml::DataMapping>(uv_data);
|
||||
if (!uv_texture->SetContents(uv_mapping)) {
|
||||
FML_DLOG(ERROR) << "Could not copy contents into UV texture.";
|
||||
auto uv_mapping_buffer =
|
||||
context->GetResourceAllocator()->CreateBufferWithCopy(*uv_mapping);
|
||||
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(uv_mapping_buffer), uv_texture);
|
||||
|
||||
if (!blit_pass->EncodeCommands(context->GetResourceAllocator()) ||
|
||||
!context->GetCommandQueue()->Submit({cmd_buffer}).ok()) {
|
||||
FML_DLOG(ERROR) << "Could not copy contents into Y/UV texture.";
|
||||
}
|
||||
|
||||
return {y_texture, uv_texture};
|
||||
|
||||
@@ -414,27 +414,26 @@ static std::shared_ptr<Texture> CreateTextureForDecompressedImage(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto uploaded = texture->SetContents(decompressed_image.GetAllocation());
|
||||
if (!uploaded) {
|
||||
VALIDATION_LOG << "Could not upload texture to device memory for fixture.";
|
||||
auto command_buffer = context->CreateCommandBuffer();
|
||||
if (!command_buffer) {
|
||||
FML_DLOG(ERROR) << "Could not create command buffer for mipmap generation.";
|
||||
return nullptr;
|
||||
}
|
||||
command_buffer->SetLabel("Mipmap Command Buffer");
|
||||
|
||||
auto blit_pass = command_buffer->CreateBlitPass();
|
||||
auto buffer_view = DeviceBuffer::AsBufferView(
|
||||
context->GetResourceAllocator()->CreateBufferWithCopy(
|
||||
*decompressed_image.GetAllocation()));
|
||||
blit_pass->AddCopy(buffer_view, texture);
|
||||
if (enable_mipmapping) {
|
||||
auto command_buffer = context->CreateCommandBuffer();
|
||||
if (!command_buffer) {
|
||||
FML_DLOG(ERROR)
|
||||
<< "Could not create command buffer for mipmap generation.";
|
||||
return nullptr;
|
||||
}
|
||||
command_buffer->SetLabel("Mipmap Command Buffer");
|
||||
auto blit_pass = command_buffer->CreateBlitPass();
|
||||
blit_pass->SetLabel("Mipmap Blit Pass");
|
||||
blit_pass->GenerateMipmap(texture);
|
||||
blit_pass->EncodeCommands(context->GetResourceAllocator());
|
||||
if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
|
||||
FML_DLOG(ERROR) << "Failed to submit blit pass command buffer.";
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
blit_pass->EncodeCommands(context->GetResourceAllocator());
|
||||
if (!context->GetCommandQueue()->Submit({command_buffer}).ok()) {
|
||||
FML_DLOG(ERROR) << "Failed to submit blit pass command buffer.";
|
||||
return nullptr;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
@@ -492,14 +491,24 @@ std::shared_ptr<Texture> Playground::CreateTextureCubeForFixture(
|
||||
}
|
||||
texture->SetLabel("Texture cube");
|
||||
|
||||
auto cmd_buffer = renderer_->GetContext()->CreateCommandBuffer();
|
||||
auto blit_pass = cmd_buffer->CreateBlitPass();
|
||||
for (size_t i = 0; i < fixture_names.size(); i++) {
|
||||
auto uploaded =
|
||||
texture->SetContents(images[i].GetAllocation()->GetMapping(),
|
||||
images[i].GetAllocation()->GetSize(), i);
|
||||
if (!uploaded) {
|
||||
VALIDATION_LOG << "Could not upload texture to device memory.";
|
||||
return nullptr;
|
||||
}
|
||||
auto device_buffer =
|
||||
renderer_->GetContext()->GetResourceAllocator()->CreateBufferWithCopy(
|
||||
*images[i].GetAllocation());
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture, {},
|
||||
"", /*slice=*/i);
|
||||
}
|
||||
|
||||
if (!blit_pass->EncodeCommands(
|
||||
renderer_->GetContext()->GetResourceAllocator()) ||
|
||||
!renderer_->GetContext()
|
||||
->GetCommandQueue()
|
||||
->Submit({std::move(cmd_buffer)})
|
||||
.ok()) {
|
||||
VALIDATION_LOG << "Could not upload texture to device memory.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return texture;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include "impeller/renderer/backend/gles/blit_command_gles.h"
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
#include "fml/trace_event.h"
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/geometry/point.h"
|
||||
#include "impeller/renderer/backend/gles/device_buffer_gles.h"
|
||||
#include "impeller/renderer/backend/gles/texture_gles.h"
|
||||
|
||||
@@ -117,6 +119,168 @@ bool BlitCopyTextureToTextureCommandGLES::Encode(
|
||||
return true;
|
||||
};
|
||||
|
||||
namespace {
|
||||
struct TexImage2DData {
|
||||
GLint internal_format = 0;
|
||||
GLenum external_format = GL_NONE;
|
||||
GLenum type = GL_NONE;
|
||||
BufferView buffer_view;
|
||||
|
||||
explicit TexImage2DData(PixelFormat pixel_format) {
|
||||
switch (pixel_format) {
|
||||
case PixelFormat::kA8UNormInt:
|
||||
internal_format = GL_ALPHA;
|
||||
external_format = GL_ALPHA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case PixelFormat::kR8UNormInt:
|
||||
internal_format = GL_RED;
|
||||
external_format = GL_RED;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case PixelFormat::kR8G8B8A8UNormInt:
|
||||
case PixelFormat::kB8G8R8A8UNormInt:
|
||||
case PixelFormat::kR8G8B8A8UNormIntSRGB:
|
||||
case PixelFormat::kB8G8R8A8UNormIntSRGB:
|
||||
internal_format = GL_RGBA;
|
||||
external_format = GL_RGBA;
|
||||
type = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case PixelFormat::kR32G32B32A32Float:
|
||||
internal_format = GL_RGBA;
|
||||
external_format = GL_RGBA;
|
||||
type = GL_FLOAT;
|
||||
break;
|
||||
case PixelFormat::kR16G16B16A16Float:
|
||||
internal_format = GL_RGBA;
|
||||
external_format = GL_RGBA;
|
||||
type = GL_HALF_FLOAT;
|
||||
break;
|
||||
case PixelFormat::kS8UInt:
|
||||
// Pure stencil textures are only available in OpenGL 4.4+, which is
|
||||
// ~0% of mobile devices. Instead, we use a depth-stencil texture and
|
||||
// only use the stencil component.
|
||||
//
|
||||
// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
internal_format = GL_DEPTH_STENCIL;
|
||||
external_format = GL_DEPTH_STENCIL;
|
||||
type = GL_UNSIGNED_INT_24_8;
|
||||
break;
|
||||
case PixelFormat::kUnknown:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
case PixelFormat::kR8G8UNormInt:
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
case PixelFormat::kB10G10R10XR:
|
||||
case PixelFormat::kB10G10R10A10XR:
|
||||
return;
|
||||
}
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
TexImage2DData(PixelFormat pixel_format, BufferView p_buffer_view)
|
||||
: TexImage2DData(pixel_format) {
|
||||
buffer_view = std::move(p_buffer_view);
|
||||
}
|
||||
|
||||
bool IsValid() const { return is_valid_; }
|
||||
|
||||
private:
|
||||
bool is_valid_ = false;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BlitCopyBufferToTextureCommandGLES::~BlitCopyBufferToTextureCommandGLES() =
|
||||
default;
|
||||
|
||||
std::string BlitCopyBufferToTextureCommandGLES::GetLabel() const {
|
||||
return label;
|
||||
}
|
||||
|
||||
bool BlitCopyBufferToTextureCommandGLES::Encode(
|
||||
const ReactorGLES& reactor) const {
|
||||
TextureGLES& texture_gles = TextureGLES::Cast(*destination);
|
||||
|
||||
if (texture_gles.GetType() != TextureGLES::Type::kTexture) {
|
||||
VALIDATION_LOG << "Incorrect texture usage flags for setting contents on "
|
||||
"this texture object.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (texture_gles.IsWrapped()) {
|
||||
VALIDATION_LOG << "Cannot set the contents of a wrapped texture.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& tex_descriptor = texture_gles.GetTextureDescriptor();
|
||||
|
||||
if (tex_descriptor.size.IsEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!tex_descriptor.IsValid() ||
|
||||
source.range.length < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
destination->SetCoordinateSystem(TextureCoordinateSystem::kUploadFromHost);
|
||||
|
||||
GLenum texture_type;
|
||||
GLenum texture_target;
|
||||
switch (tex_descriptor.type) {
|
||||
case TextureType::kTexture2D:
|
||||
texture_type = GL_TEXTURE_2D;
|
||||
texture_target = GL_TEXTURE_2D;
|
||||
break;
|
||||
case TextureType::kTexture2DMultisample:
|
||||
VALIDATION_LOG << "Multisample texture uploading is not supported for "
|
||||
"the OpenGLES backend.";
|
||||
return false;
|
||||
case TextureType::kTextureCube:
|
||||
texture_type = GL_TEXTURE_CUBE_MAP;
|
||||
texture_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
|
||||
break;
|
||||
case TextureType::kTextureExternalOES:
|
||||
texture_type = GL_TEXTURE_EXTERNAL_OES;
|
||||
texture_target = GL_TEXTURE_EXTERNAL_OES;
|
||||
break;
|
||||
}
|
||||
|
||||
TexImage2DData data = TexImage2DData(tex_descriptor.format, source);
|
||||
if (!data.IsValid()) {
|
||||
VALIDATION_LOG << "Invalid texture format.";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto gl_handle = texture_gles.GetGLHandle();
|
||||
if (!gl_handle.has_value()) {
|
||||
VALIDATION_LOG
|
||||
<< "Texture was collected before it could be uploaded to the GPU.";
|
||||
return false;
|
||||
}
|
||||
const auto& gl = reactor.GetProcTable();
|
||||
gl.BindTexture(texture_type, gl_handle.value());
|
||||
const GLvoid* tex_data =
|
||||
data.buffer_view.buffer->OnGetContents() + data.buffer_view.range.offset;
|
||||
|
||||
{
|
||||
TRACE_EVENT1("impeller", "TexImage2DUpload", "Bytes",
|
||||
std::to_string(data.buffer_view.range.length).c_str());
|
||||
gl.TexImage2D(texture_target, // target
|
||||
0u, // LOD level
|
||||
data.internal_format, // internal format
|
||||
tex_descriptor.size.width, // width
|
||||
tex_descriptor.size.height, // height
|
||||
0u, // border
|
||||
data.external_format, // external format
|
||||
data.type, // type
|
||||
tex_data // data
|
||||
);
|
||||
}
|
||||
texture_gles.MarkContentsInitialized();
|
||||
return true;
|
||||
}
|
||||
|
||||
BlitCopyTextureToBufferCommandGLES::~BlitCopyTextureToBufferCommandGLES() =
|
||||
default;
|
||||
|
||||
|
||||
@@ -20,6 +20,16 @@ struct BlitEncodeGLES : BackendCast<BlitEncodeGLES, BlitCommand> {
|
||||
[[nodiscard]] virtual bool Encode(const ReactorGLES& reactor) const = 0;
|
||||
};
|
||||
|
||||
struct BlitCopyBufferToTextureCommandGLES
|
||||
: public BlitEncodeGLES,
|
||||
public BlitCopyBufferToTextureCommand {
|
||||
~BlitCopyBufferToTextureCommandGLES() override;
|
||||
|
||||
std::string GetLabel() const override;
|
||||
|
||||
[[nodiscard]] bool Encode(const ReactorGLES& reactor) const override;
|
||||
};
|
||||
|
||||
struct BlitCopyTextureToTextureCommandGLES
|
||||
: public BlitEncodeGLES,
|
||||
public BlitCopyTextureToTextureCommand {
|
||||
|
||||
@@ -104,7 +104,7 @@ bool BlitPassGLES::OnCopyTextureToTextureCommand(
|
||||
command->source_region = source_region;
|
||||
command->destination_origin = destination_origin;
|
||||
|
||||
commands_.emplace_back(std::move(command));
|
||||
commands_.push_back(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,26 @@ bool BlitPassGLES::OnCopyTextureToBufferCommand(
|
||||
command->source_region = source_region;
|
||||
command->destination_offset = destination_offset;
|
||||
|
||||
commands_.emplace_back(std::move(command));
|
||||
commands_.push_back(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
// |BlitPass|
|
||||
bool BlitPassGLES::OnCopyBufferToTextureCommand(
|
||||
BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label,
|
||||
uint32_t slice) {
|
||||
auto command = std::make_unique<BlitCopyBufferToTextureCommandGLES>();
|
||||
command->label = label;
|
||||
command->source = std::move(source);
|
||||
command->destination = std::move(destination);
|
||||
command->destination_origin = destination_origin;
|
||||
command->label = label;
|
||||
command->slice = slice;
|
||||
|
||||
commands_.push_back(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -133,7 +152,7 @@ bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
|
||||
command->label = label;
|
||||
command->texture = std::move(texture);
|
||||
|
||||
commands_.emplace_back(std::move(command));
|
||||
commands_.push_back(std::move(command));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,9 @@ class BlitPassGLES final : public BlitPass,
|
||||
bool OnCopyBufferToTextureCommand(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) override {
|
||||
IMPELLER_UNIMPLEMENTED;
|
||||
return false;
|
||||
}
|
||||
std::string label,
|
||||
uint32_t slice) override;
|
||||
|
||||
// |BlitPass|
|
||||
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
|
||||
std::string label) override;
|
||||
|
||||
@@ -153,10 +153,6 @@ bool CapabilitiesGLES::SupportsSSBO() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CapabilitiesGLES::SupportsBufferToTextureBlits() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CapabilitiesGLES::SupportsTextureToTextureBlits() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -86,9 +86,6 @@ class CapabilitiesGLES final
|
||||
// |Capabilities|
|
||||
bool SupportsSSBO() const override;
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsBufferToTextureBlits() const override;
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsTextureToTextureBlits() const override;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ TEST(CapabilitiesGLES, CanInitializeWithDefaults) {
|
||||
|
||||
EXPECT_FALSE(capabilities->SupportsOffscreenMSAA());
|
||||
EXPECT_FALSE(capabilities->SupportsSSBO());
|
||||
EXPECT_FALSE(capabilities->SupportsBufferToTextureBlits());
|
||||
EXPECT_FALSE(capabilities->SupportsTextureToTextureBlits());
|
||||
EXPECT_FALSE(capabilities->SupportsFramebufferFetch());
|
||||
EXPECT_FALSE(capabilities->SupportsCompute());
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
namespace {
|
||||
static bool IsDepthStencilFormat(PixelFormat format) {
|
||||
switch (format) {
|
||||
case PixelFormat::kS8UInt:
|
||||
@@ -55,76 +56,6 @@ static TextureGLES::Type GetTextureTypeFromDescriptor(
|
||||
: TextureGLES::Type::kTexture;
|
||||
}
|
||||
|
||||
HandleType ToHandleType(TextureGLES::Type type) {
|
||||
switch (type) {
|
||||
case TextureGLES::Type::kTexture:
|
||||
case TextureGLES::Type::kTextureMultisampled:
|
||||
return HandleType::kTexture;
|
||||
case TextureGLES::Type::kRenderBuffer:
|
||||
case TextureGLES::Type::kRenderBufferMultisampled:
|
||||
return HandleType::kRenderBuffer;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
TextureGLES::TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
|
||||
: TextureGLES(std::move(reactor), desc, false, std::nullopt) {}
|
||||
|
||||
TextureGLES::TextureGLES(ReactorGLES::Ref reactor,
|
||||
TextureDescriptor desc,
|
||||
enum IsWrapped wrapped)
|
||||
: TextureGLES(std::move(reactor), desc, true, std::nullopt) {}
|
||||
|
||||
std::shared_ptr<TextureGLES> TextureGLES::WrapFBO(ReactorGLES::Ref reactor,
|
||||
TextureDescriptor desc,
|
||||
GLuint fbo) {
|
||||
return std::shared_ptr<TextureGLES>(
|
||||
new TextureGLES(std::move(reactor), desc, true, fbo));
|
||||
}
|
||||
|
||||
TextureGLES::TextureGLES(std::shared_ptr<ReactorGLES> reactor,
|
||||
TextureDescriptor desc,
|
||||
bool is_wrapped,
|
||||
std::optional<GLuint> fbo)
|
||||
: Texture(desc),
|
||||
reactor_(std::move(reactor)),
|
||||
type_(GetTextureTypeFromDescriptor(GetTextureDescriptor())),
|
||||
handle_(reactor_->CreateHandle(ToHandleType(type_))),
|
||||
is_wrapped_(is_wrapped),
|
||||
wrapped_fbo_(fbo) {
|
||||
// Ensure the texture descriptor itself is valid.
|
||||
if (!GetTextureDescriptor().IsValid()) {
|
||||
VALIDATION_LOG << "Invalid texture descriptor.";
|
||||
return;
|
||||
}
|
||||
// Ensure the texture doesn't exceed device capabilities.
|
||||
const auto tex_size = GetTextureDescriptor().size;
|
||||
const auto max_size =
|
||||
reactor_->GetProcTable().GetCapabilities()->max_texture_size;
|
||||
if (tex_size.Max(max_size) != max_size) {
|
||||
VALIDATION_LOG << "Texture of size " << tex_size
|
||||
<< " would exceed max supported size of " << max_size << ".";
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
TextureGLES::~TextureGLES() {
|
||||
reactor_->CollectHandle(handle_);
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
bool TextureGLES::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
void TextureGLES::SetLabel(std::string_view label) {
|
||||
reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
|
||||
}
|
||||
|
||||
struct TexImage2DData {
|
||||
GLint internal_format = 0;
|
||||
GLenum external_format = GL_NONE;
|
||||
@@ -194,6 +125,77 @@ struct TexImage2DData {
|
||||
private:
|
||||
bool is_valid_ = false;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
HandleType ToHandleType(TextureGLES::Type type) {
|
||||
switch (type) {
|
||||
case TextureGLES::Type::kTexture:
|
||||
case TextureGLES::Type::kTextureMultisampled:
|
||||
return HandleType::kTexture;
|
||||
case TextureGLES::Type::kRenderBuffer:
|
||||
case TextureGLES::Type::kRenderBufferMultisampled:
|
||||
return HandleType::kRenderBuffer;
|
||||
}
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
TextureGLES::TextureGLES(ReactorGLES::Ref reactor, TextureDescriptor desc)
|
||||
: TextureGLES(std::move(reactor), desc, false, std::nullopt) {}
|
||||
|
||||
TextureGLES::TextureGLES(ReactorGLES::Ref reactor,
|
||||
TextureDescriptor desc,
|
||||
enum IsWrapped wrapped)
|
||||
: TextureGLES(std::move(reactor), desc, true, std::nullopt) {}
|
||||
|
||||
std::shared_ptr<TextureGLES> TextureGLES::WrapFBO(ReactorGLES::Ref reactor,
|
||||
TextureDescriptor desc,
|
||||
GLuint fbo) {
|
||||
return std::shared_ptr<TextureGLES>(
|
||||
new TextureGLES(std::move(reactor), desc, true, fbo));
|
||||
}
|
||||
|
||||
TextureGLES::TextureGLES(std::shared_ptr<ReactorGLES> reactor,
|
||||
TextureDescriptor desc,
|
||||
bool is_wrapped,
|
||||
std::optional<GLuint> fbo)
|
||||
: Texture(desc),
|
||||
reactor_(std::move(reactor)),
|
||||
type_(GetTextureTypeFromDescriptor(GetTextureDescriptor())),
|
||||
handle_(reactor_->CreateHandle(ToHandleType(type_))),
|
||||
is_wrapped_(is_wrapped),
|
||||
wrapped_fbo_(fbo) {
|
||||
// Ensure the texture descriptor itself is valid.
|
||||
if (!GetTextureDescriptor().IsValid()) {
|
||||
VALIDATION_LOG << "Invalid texture descriptor.";
|
||||
return;
|
||||
}
|
||||
// Ensure the texture doesn't exceed device capabilities.
|
||||
const auto tex_size = GetTextureDescriptor().size;
|
||||
const auto max_size =
|
||||
reactor_->GetProcTable().GetCapabilities()->max_texture_size;
|
||||
if (tex_size.Max(max_size) != max_size) {
|
||||
VALIDATION_LOG << "Texture of size " << tex_size
|
||||
<< " would exceed max supported size of " << max_size << ".";
|
||||
return;
|
||||
}
|
||||
|
||||
is_valid_ = true;
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
TextureGLES::~TextureGLES() {
|
||||
reactor_->CollectHandle(handle_);
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
bool TextureGLES::IsValid() const {
|
||||
return is_valid_;
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
void TextureGLES::SetLabel(std::string_view label) {
|
||||
reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
bool TextureGLES::OnSetContents(const uint8_t* contents,
|
||||
@@ -234,11 +236,8 @@ bool TextureGLES::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!tex_descriptor.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
|
||||
if (!tex_descriptor.IsValid() ||
|
||||
mapping->GetSize() < tex_descriptor.GetByteSizeOfBaseMipLevel()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -456,6 +455,10 @@ bool TextureGLES::Bind() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextureGLES::MarkContentsInitialized() const {
|
||||
contents_initialized_ = true;
|
||||
}
|
||||
|
||||
bool TextureGLES::GenerateMipmap() {
|
||||
if (!IsValid()) {
|
||||
return false;
|
||||
|
||||
@@ -60,9 +60,9 @@ class TextureGLES final : public Texture,
|
||||
|
||||
std::optional<GLuint> GetFBO() const { return wrapped_fbo_; }
|
||||
|
||||
private:
|
||||
friend class AllocatorMTL;
|
||||
void MarkContentsInitialized() const;
|
||||
|
||||
private:
|
||||
ReactorGLES::Ref reactor_;
|
||||
const Type type_;
|
||||
HandleGLES handle_;
|
||||
|
||||
@@ -132,7 +132,7 @@ bool BlitCopyBufferToTextureCommandMTL::Encode(
|
||||
sourceBytesPerImage:destination_bytes_per_image
|
||||
sourceSize:source_size_mtl
|
||||
toTexture:destination_mtl
|
||||
destinationSlice:0
|
||||
destinationSlice:slice
|
||||
destinationLevel:0
|
||||
destinationOrigin:destination_origin_mtl];
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ class BlitPassMTL final : public BlitPass {
|
||||
bool OnCopyBufferToTextureCommand(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) override;
|
||||
std::string label,
|
||||
uint32_t slice) override;
|
||||
|
||||
// |BlitPass|
|
||||
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "impeller/renderer/backend/metal/blit_pass_mtl.h"
|
||||
#include <Metal/Metal.h>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
@@ -127,12 +128,14 @@ bool BlitPassMTL::OnCopyBufferToTextureCommand(
|
||||
BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) {
|
||||
std::string label,
|
||||
uint32_t slice) {
|
||||
auto command = std::make_unique<BlitCopyBufferToTextureCommandMTL>();
|
||||
command->label = label;
|
||||
command->label = std::move(label);
|
||||
command->source = std::move(source);
|
||||
command->destination = std::move(destination);
|
||||
command->destination_origin = destination_origin;
|
||||
command->slice = slice;
|
||||
|
||||
commands_.emplace_back(std::move(command));
|
||||
return true;
|
||||
|
||||
@@ -56,7 +56,6 @@ static std::unique_ptr<Capabilities> InferMetalCapabilities(
|
||||
return CapabilitiesBuilder()
|
||||
.SetSupportsOffscreenMSAA(true)
|
||||
.SetSupportsSSBO(true)
|
||||
.SetSupportsBufferToTextureBlits(true)
|
||||
.SetSupportsTextureToTextureBlits(true)
|
||||
.SetSupportsDecalSamplerAddressMode(true)
|
||||
.SetSupportsFramebufferFetch(DeviceSupportsFramebufferFetch(device))
|
||||
|
||||
@@ -36,11 +36,6 @@ class DeviceBufferMTL final
|
||||
// |DeviceBuffer|
|
||||
uint8_t* OnGetContents() const override;
|
||||
|
||||
// |DeviceBuffer|
|
||||
std::shared_ptr<Texture> AsTexture(Allocator& allocator,
|
||||
const TextureDescriptor& descriptor,
|
||||
uint16_t row_bytes) const override;
|
||||
|
||||
// |DeviceBuffer|
|
||||
bool OnCopyHostBuffer(const uint8_t* source,
|
||||
Range source_range,
|
||||
|
||||
@@ -29,30 +29,6 @@ uint8_t* DeviceBufferMTL::OnGetContents() const {
|
||||
return reinterpret_cast<uint8_t*>(buffer_.contents);
|
||||
}
|
||||
|
||||
std::shared_ptr<Texture> DeviceBufferMTL::AsTexture(
|
||||
Allocator& allocator,
|
||||
const TextureDescriptor& descriptor,
|
||||
uint16_t row_bytes) const {
|
||||
auto mtl_texture_desc = ToMTLTextureDescriptor(descriptor);
|
||||
|
||||
if (!mtl_texture_desc) {
|
||||
VALIDATION_LOG << "Texture descriptor was invalid.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (@available(iOS 13.0, macos 10.15, *)) {
|
||||
mtl_texture_desc.resourceOptions = buffer_.resourceOptions;
|
||||
}
|
||||
|
||||
auto texture = [buffer_ newTextureWithDescriptor:mtl_texture_desc
|
||||
offset:0
|
||||
bytesPerRow:row_bytes];
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
return TextureMTL::Create(descriptor, texture);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool DeviceBufferMTL::OnCopyHostBuffer(const uint8_t* source,
|
||||
Range source_range,
|
||||
size_t offset) {
|
||||
|
||||
@@ -262,6 +262,22 @@ bool BlitCopyBufferToTextureCommandVK::Encode(CommandEncoderVK& encoder) const {
|
||||
image_copy //
|
||||
);
|
||||
|
||||
// Transition to shader-read.
|
||||
{
|
||||
BarrierVK barrier;
|
||||
barrier.cmd_buffer = cmd_buffer;
|
||||
barrier.src_access = vk::AccessFlagBits::eTransferWrite;
|
||||
barrier.src_stage = vk::PipelineStageFlagBits::eTransfer;
|
||||
barrier.dst_access = vk::AccessFlagBits::eShaderRead;
|
||||
barrier.dst_stage = vk::PipelineStageFlagBits::eFragmentShader;
|
||||
|
||||
barrier.new_layout = vk::ImageLayout::eShaderReadOnlyOptimal;
|
||||
|
||||
if (!dst.SetLayout(barrier)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,13 +97,15 @@ bool BlitPassVK::OnCopyBufferToTextureCommand(
|
||||
BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) {
|
||||
std::string label,
|
||||
uint32_t slice) {
|
||||
auto command = std::make_unique<BlitCopyBufferToTextureCommandVK>();
|
||||
|
||||
command->source = std::move(source);
|
||||
command->destination = std::move(destination);
|
||||
command->destination_origin = destination_origin;
|
||||
command->label = std::move(label);
|
||||
command->slice = slice;
|
||||
|
||||
commands_.push_back(std::move(command));
|
||||
return true;
|
||||
|
||||
@@ -56,7 +56,8 @@ class BlitPassVK final : public BlitPass {
|
||||
bool OnCopyBufferToTextureCommand(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) override;
|
||||
std::string label,
|
||||
uint32_t slice) override;
|
||||
// |BlitPass|
|
||||
bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
|
||||
std::string label) override;
|
||||
|
||||
@@ -536,11 +536,6 @@ bool CapabilitiesVK::SupportsSSBO() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
// |Capabilities|
|
||||
bool CapabilitiesVK::SupportsBufferToTextureBlits() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
// |Capabilities|
|
||||
bool CapabilitiesVK::SupportsTextureToTextureBlits() const {
|
||||
return true;
|
||||
|
||||
@@ -186,9 +186,6 @@ class CapabilitiesVK final : public Capabilities,
|
||||
// |Capabilities|
|
||||
bool SupportsSSBO() const override;
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsBufferToTextureBlits() const override;
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsTextureToTextureBlits() const override;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ struct BlitCopyBufferToTextureCommand : public BlitCommand {
|
||||
BufferView source;
|
||||
std::shared_ptr<Texture> destination;
|
||||
IPoint destination_origin;
|
||||
uint32_t slice = 0;
|
||||
};
|
||||
|
||||
struct BlitGenerateMipmapCommand : public BlitCommand {
|
||||
|
||||
@@ -123,7 +123,8 @@ bool BlitPass::AddCopy(std::shared_ptr<Texture> source,
|
||||
bool BlitPass::AddCopy(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) {
|
||||
std::string label,
|
||||
uint32_t slice) {
|
||||
if (!destination) {
|
||||
VALIDATION_LOG << "Attempted to add a texture blit with no destination.";
|
||||
return false;
|
||||
@@ -141,7 +142,8 @@ bool BlitPass::AddCopy(BufferView source,
|
||||
}
|
||||
|
||||
return OnCopyBufferToTextureCommand(std::move(source), std::move(destination),
|
||||
destination_origin, std::move(label));
|
||||
destination_origin, std::move(label),
|
||||
slice);
|
||||
}
|
||||
|
||||
bool BlitPass::GenerateMipmap(std::shared_ptr<Texture> texture,
|
||||
|
||||
@@ -93,13 +93,16 @@ class BlitPass {
|
||||
/// destination buffer.
|
||||
/// @param[in] label The optional debug label to give the
|
||||
/// command.
|
||||
/// @param[in] slice For cubemap textures, the slice to write
|
||||
/// data to.
|
||||
///
|
||||
/// @return If the command was valid for subsequent commitment.
|
||||
///
|
||||
bool AddCopy(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin = {},
|
||||
std::string label = "");
|
||||
std::string label = "",
|
||||
uint32_t slice = 0);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @brief Record a command to generate all mip levels for a texture.
|
||||
@@ -146,7 +149,8 @@ class BlitPass {
|
||||
BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label) = 0;
|
||||
std::string label,
|
||||
uint32_t slice) = 0;
|
||||
|
||||
virtual bool OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
|
||||
std::string label) = 0;
|
||||
|
||||
@@ -27,11 +27,6 @@ class StandardCapabilities final : public Capabilities {
|
||||
// |Capabilities|
|
||||
bool SupportsSSBO() const override { return supports_ssbo_; }
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsBufferToTextureBlits() const override {
|
||||
return supports_buffer_to_texture_blits_;
|
||||
}
|
||||
|
||||
// |Capabilities|
|
||||
bool SupportsTextureToTextureBlits() const override {
|
||||
return supports_texture_to_texture_blits_;
|
||||
@@ -88,7 +83,6 @@ class StandardCapabilities final : public Capabilities {
|
||||
private:
|
||||
StandardCapabilities(bool supports_offscreen_msaa,
|
||||
bool supports_ssbo,
|
||||
bool supports_buffer_to_texture_blits,
|
||||
bool supports_texture_to_texture_blits,
|
||||
bool supports_framebuffer_fetch,
|
||||
bool supports_compute,
|
||||
@@ -102,7 +96,6 @@ class StandardCapabilities final : public Capabilities {
|
||||
PixelFormat default_glyph_atlas_format)
|
||||
: supports_offscreen_msaa_(supports_offscreen_msaa),
|
||||
supports_ssbo_(supports_ssbo),
|
||||
supports_buffer_to_texture_blits_(supports_buffer_to_texture_blits),
|
||||
supports_texture_to_texture_blits_(supports_texture_to_texture_blits),
|
||||
supports_framebuffer_fetch_(supports_framebuffer_fetch),
|
||||
supports_compute_(supports_compute),
|
||||
@@ -120,7 +113,6 @@ class StandardCapabilities final : public Capabilities {
|
||||
|
||||
bool supports_offscreen_msaa_ = false;
|
||||
bool supports_ssbo_ = false;
|
||||
bool supports_buffer_to_texture_blits_ = false;
|
||||
bool supports_texture_to_texture_blits_ = false;
|
||||
bool supports_framebuffer_fetch_ = false;
|
||||
bool supports_compute_ = false;
|
||||
@@ -152,12 +144,6 @@ CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsSSBO(bool value) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsBufferToTextureBlits(
|
||||
bool value) {
|
||||
supports_buffer_to_texture_blits_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsTextureToTextureBlits(
|
||||
bool value) {
|
||||
supports_texture_to_texture_blits_ = value;
|
||||
@@ -227,7 +213,6 @@ std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
|
||||
return std::unique_ptr<StandardCapabilities>(new StandardCapabilities( //
|
||||
supports_offscreen_msaa_, //
|
||||
supports_ssbo_, //
|
||||
supports_buffer_to_texture_blits_, //
|
||||
supports_texture_to_texture_blits_, //
|
||||
supports_framebuffer_fetch_, //
|
||||
supports_compute_, //
|
||||
|
||||
@@ -28,11 +28,6 @@ class Capabilities {
|
||||
/// Objects (SSBOs) to pipelines.
|
||||
virtual bool SupportsSSBO() const = 0;
|
||||
|
||||
/// @brief Whether the context backend supports blitting from a given
|
||||
/// `DeviceBuffer` view to a texture region (via the relevant
|
||||
/// `BlitPass::AddCopy` overloads).
|
||||
virtual bool SupportsBufferToTextureBlits() const = 0;
|
||||
|
||||
/// @brief Whether the context backend supports blitting from one texture
|
||||
/// region to another texture region (via the relevant
|
||||
/// `BlitPass::AddCopy` overloads).
|
||||
@@ -128,8 +123,6 @@ class CapabilitiesBuilder {
|
||||
|
||||
CapabilitiesBuilder& SetSupportsSSBO(bool value);
|
||||
|
||||
CapabilitiesBuilder& SetSupportsBufferToTextureBlits(bool value);
|
||||
|
||||
CapabilitiesBuilder& SetSupportsTextureToTextureBlits(bool value);
|
||||
|
||||
CapabilitiesBuilder& SetSupportsFramebufferFetch(bool value);
|
||||
@@ -157,7 +150,6 @@ class CapabilitiesBuilder {
|
||||
private:
|
||||
bool supports_offscreen_msaa_ = false;
|
||||
bool supports_ssbo_ = false;
|
||||
bool supports_buffer_to_texture_blits_ = false;
|
||||
bool supports_texture_to_texture_blits_ = false;
|
||||
bool supports_framebuffer_fetch_ = false;
|
||||
bool supports_compute_ = false;
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace testing {
|
||||
|
||||
CAPABILITY_TEST(SupportsOffscreenMSAA, false);
|
||||
CAPABILITY_TEST(SupportsSSBO, false);
|
||||
CAPABILITY_TEST(SupportsBufferToTextureBlits, false);
|
||||
CAPABILITY_TEST(SupportsTextureToTextureBlits, false);
|
||||
CAPABILITY_TEST(SupportsFramebufferFetch, false);
|
||||
CAPABILITY_TEST(SupportsCompute, false);
|
||||
|
||||
@@ -973,43 +973,6 @@ TEST_P(RendererTest, InactiveUniforms) {
|
||||
OpenPlaygroundHere(callback);
|
||||
}
|
||||
|
||||
TEST_P(RendererTest, CanCreateCPUBackedTexture) {
|
||||
if (GetParam() == PlaygroundBackend::kOpenGLES) {
|
||||
GTEST_SKIP_("CPU backed textures are not supported on OpenGLES.");
|
||||
}
|
||||
|
||||
auto context = GetContext();
|
||||
auto allocator = context->GetResourceAllocator();
|
||||
size_t dimension = 2;
|
||||
|
||||
do {
|
||||
ISize size(dimension, dimension);
|
||||
TextureDescriptor texture_descriptor;
|
||||
texture_descriptor.storage_mode = StorageMode::kHostVisible;
|
||||
texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
|
||||
texture_descriptor.size = size;
|
||||
auto row_bytes =
|
||||
std::max(static_cast<uint16_t>(size.width * 4),
|
||||
allocator->MinimumBytesPerRow(texture_descriptor.format));
|
||||
auto buffer_size = size.height * row_bytes;
|
||||
|
||||
DeviceBufferDescriptor buffer_descriptor;
|
||||
buffer_descriptor.storage_mode = StorageMode::kHostVisible;
|
||||
buffer_descriptor.size = buffer_size;
|
||||
|
||||
auto buffer = allocator->CreateBuffer(buffer_descriptor);
|
||||
|
||||
ASSERT_TRUE(buffer);
|
||||
|
||||
auto texture = buffer->AsTexture(*allocator, texture_descriptor, row_bytes);
|
||||
|
||||
ASSERT_TRUE(texture);
|
||||
ASSERT_TRUE(texture->IsValid());
|
||||
|
||||
dimension *= 2;
|
||||
} while (dimension <= 8192);
|
||||
}
|
||||
|
||||
TEST_P(RendererTest, DefaultIndexSize) {
|
||||
using VS = BoxFadeVertexShader;
|
||||
|
||||
|
||||
@@ -83,7 +83,8 @@ class MockBlitPass : public BlitPass {
|
||||
(BufferView source,
|
||||
std::shared_ptr<Texture> destination,
|
||||
IPoint destination_origin,
|
||||
std::string label),
|
||||
std::string label,
|
||||
uint32_t slice),
|
||||
(override));
|
||||
MOCK_METHOD(bool,
|
||||
OnGenerateMipmapCommand,
|
||||
@@ -193,7 +194,6 @@ class MockCapabilities : public Capabilities {
|
||||
MOCK_METHOD(bool, SupportsOffscreenMSAA, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsImplicitResolvingMSAA, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsSSBO, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsBufferToTextureBlits, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsTextureToTextureBlits, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsFramebufferFetch, (), (const, override));
|
||||
MOCK_METHOD(bool, SupportsCompute, (), (const, override));
|
||||
|
||||
@@ -9,10 +9,14 @@
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "fml/closure.h"
|
||||
#include "fml/mapping.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
#include "impeller/core/allocator.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
#include "impeller/typographer/backends/skia/glyph_atlas_context_skia.h"
|
||||
#include "impeller/typographer/backends/skia/typeface_skia.h"
|
||||
#include "impeller/typographer/glyph_atlas.h"
|
||||
#include "impeller/typographer/rectangle_packer.h"
|
||||
#include "impeller/typographer/typographer_context.h"
|
||||
#include "include/core/SkColor.h"
|
||||
@@ -257,8 +261,11 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
static bool UpdateGlyphTextureAtlas(std::shared_ptr<SkBitmap> bitmap,
|
||||
const std::shared_ptr<Texture>& texture) {
|
||||
static bool UpdateGlyphTextureAtlas(
|
||||
std::shared_ptr<SkBitmap> bitmap,
|
||||
const std::shared_ptr<Allocator>& allocator,
|
||||
const std::shared_ptr<Texture>& texture,
|
||||
const std::shared_ptr<BlitPass>& blit_pass) {
|
||||
TRACE_EVENT0("impeller", __FUNCTION__);
|
||||
|
||||
FML_DCHECK(bitmap != nullptr);
|
||||
@@ -270,12 +277,17 @@ static bool UpdateGlyphTextureAtlas(std::shared_ptr<SkBitmap> bitmap,
|
||||
[bitmap](auto, auto) mutable { bitmap.reset(); } // proc
|
||||
);
|
||||
|
||||
return texture->SetContents(mapping);
|
||||
std::shared_ptr<DeviceBuffer> device_buffer =
|
||||
allocator->CreateBufferWithCopy(*mapping);
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(device_buffer)),
|
||||
texture);
|
||||
return blit_pass->EncodeCommands(allocator);
|
||||
}
|
||||
|
||||
static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
const std::shared_ptr<Allocator>& allocator,
|
||||
std::shared_ptr<SkBitmap> bitmap,
|
||||
const std::shared_ptr<BlitPass>& blit_pass,
|
||||
const ISize& atlas_size,
|
||||
PixelFormat format) {
|
||||
TRACE_EVENT0("impeller", __FUNCTION__);
|
||||
@@ -287,7 +299,7 @@ static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
const auto& pixmap = bitmap->pixmap();
|
||||
|
||||
TextureDescriptor texture_descriptor;
|
||||
texture_descriptor.storage_mode = StorageMode::kHostVisible;
|
||||
texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
|
||||
texture_descriptor.format = format;
|
||||
texture_descriptor.size = atlas_size;
|
||||
|
||||
@@ -296,21 +308,25 @@ static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto texture = allocator->CreateTexture(texture_descriptor);
|
||||
std::shared_ptr<Texture> texture =
|
||||
allocator->CreateTexture(texture_descriptor);
|
||||
if (!texture || !texture->IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
texture->SetLabel("GlyphAtlas");
|
||||
|
||||
auto mapping = std::make_shared<fml::NonOwnedMapping>(
|
||||
reinterpret_cast<const uint8_t*>(bitmap->getAddr(0, 0)), // data
|
||||
texture_descriptor.GetByteSizeOfBaseMipLevel(), // size
|
||||
[bitmap](auto, auto) mutable { bitmap.reset(); } // proc
|
||||
);
|
||||
std::shared_ptr<fml::NonOwnedMapping> mapping =
|
||||
std::make_shared<fml::NonOwnedMapping>(
|
||||
reinterpret_cast<const uint8_t*>(bitmap->getAddr(0, 0)), // data
|
||||
texture_descriptor.GetByteSizeOfBaseMipLevel(), // size
|
||||
[bitmap](auto, auto) mutable { bitmap.reset(); } // proc
|
||||
);
|
||||
std::shared_ptr<DeviceBuffer> device_buffer =
|
||||
allocator->CreateBufferWithCopy(*mapping);
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(std::move(device_buffer)),
|
||||
texture);
|
||||
blit_pass->EncodeCommands(allocator);
|
||||
|
||||
if (!texture->SetContents(mapping)) {
|
||||
return nullptr;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -329,6 +345,12 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
|
||||
if (font_glyph_map.empty()) {
|
||||
return last_atlas;
|
||||
}
|
||||
std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
|
||||
std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
|
||||
|
||||
fml::ScopedCleanupClosure closure([&cmd_buffer, &context]() {
|
||||
context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Step 1: Determine if the atlas type and font glyph pairs are compatible
|
||||
@@ -387,7 +409,8 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
|
||||
// ---------------------------------------------------------------------------
|
||||
// Step 5a: Update the existing texture with the updated bitmap.
|
||||
// ---------------------------------------------------------------------------
|
||||
if (!UpdateGlyphTextureAtlas(bitmap, last_atlas->GetTexture())) {
|
||||
if (!UpdateGlyphTextureAtlas(bitmap, context.GetResourceAllocator(),
|
||||
last_atlas->GetTexture(), blit_pass)) {
|
||||
return nullptr;
|
||||
}
|
||||
return last_atlas;
|
||||
@@ -407,8 +430,8 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
|
||||
font_glyph_pairs.push_back({scaled_font, glyph});
|
||||
}
|
||||
}
|
||||
auto glyph_atlas = std::make_shared<GlyphAtlas>(type);
|
||||
auto atlas_size = OptimumAtlasSizeForFontGlyphPairs(
|
||||
std::shared_ptr<GlyphAtlas> glyph_atlas = std::make_shared<GlyphAtlas>(type);
|
||||
ISize atlas_size = OptimumAtlasSizeForFontGlyphPairs(
|
||||
font_glyph_pairs, //
|
||||
glyph_positions, //
|
||||
atlas_context, //
|
||||
@@ -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
|
||||
// texture and treat this as an updated that replaces all glyphs.
|
||||
if (last_atlas && last_atlas->GetTexture()) {
|
||||
std::shared_ptr<Texture> last_texture = last_atlas->GetTexture();
|
||||
if (atlas_size == last_texture->GetSize()) {
|
||||
if (!UpdateGlyphTextureAtlas(bitmap, context.GetResourceAllocator(),
|
||||
last_texture, blit_pass)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glyph_atlas->SetTexture(last_texture);
|
||||
return glyph_atlas;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Step 7b: Upload the atlas as a texture.
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -462,8 +500,8 @@ std::shared_ptr<GlyphAtlas> TypographerContextSkia::CreateGlyphAtlas(
|
||||
format = PixelFormat::kR8G8B8A8UNormInt;
|
||||
break;
|
||||
}
|
||||
auto texture = UploadGlyphTextureAtlas(context.GetResourceAllocator(), bitmap,
|
||||
atlas_size, format);
|
||||
std::shared_ptr<Texture> texture = UploadGlyphTextureAtlas(
|
||||
context.GetResourceAllocator(), bitmap, blit_pass, atlas_size, format);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,11 @@
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#include "flutter/fml/trace_event.h"
|
||||
#include "fml/closure.h"
|
||||
#include "fml/mapping.h"
|
||||
#include "impeller/base/allocation.h"
|
||||
#include "impeller/core/allocator.h"
|
||||
#include "impeller/core/device_buffer.h"
|
||||
#include "impeller/typographer/backends/stb/glyph_atlas_context_stb.h"
|
||||
#include "impeller/typographer/font_glyph_pair.h"
|
||||
#include "typeface_stb.h"
|
||||
@@ -309,6 +312,8 @@ static std::shared_ptr<BitmapSTB> CreateAtlasBitmap(const GlyphAtlas& atlas,
|
||||
|
||||
// static bool UpdateGlyphTextureAtlas(std::shared_ptr<SkBitmap> bitmap,
|
||||
static bool UpdateGlyphTextureAtlas(std::shared_ptr<BitmapSTB>& bitmap,
|
||||
const std::shared_ptr<Allocator>& allocator,
|
||||
std::shared_ptr<BlitPass>& blit_pass,
|
||||
const std::shared_ptr<Texture>& texture) {
|
||||
TRACE_EVENT0("impeller", __FUNCTION__);
|
||||
|
||||
@@ -323,11 +328,16 @@ static bool UpdateGlyphTextureAtlas(std::shared_ptr<BitmapSTB>& bitmap,
|
||||
// specify a release proc.
|
||||
);
|
||||
|
||||
return texture->SetContents(mapping);
|
||||
std::shared_ptr<DeviceBuffer> device_buffer =
|
||||
allocator->CreateBufferWithCopy(*mapping);
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture);
|
||||
|
||||
return blit_pass->EncodeCommands(allocator);
|
||||
}
|
||||
|
||||
static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
const std::shared_ptr<Allocator>& allocator,
|
||||
std::shared_ptr<BlitPass>& blit_pass,
|
||||
std::shared_ptr<BitmapSTB>& bitmap,
|
||||
const ISize& atlas_size,
|
||||
PixelFormat format) {
|
||||
@@ -339,7 +349,7 @@ static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
FML_DCHECK(bitmap != nullptr);
|
||||
|
||||
TextureDescriptor texture_descriptor;
|
||||
texture_descriptor.storage_mode = StorageMode::kHostVisible;
|
||||
texture_descriptor.storage_mode = StorageMode::kDevicePrivate;
|
||||
texture_descriptor.format = format;
|
||||
texture_descriptor.size = atlas_size;
|
||||
|
||||
@@ -354,16 +364,20 @@ static std::shared_ptr<Texture> UploadGlyphTextureAtlas(
|
||||
}
|
||||
texture->SetLabel("GlyphAtlas");
|
||||
|
||||
auto mapping = std::make_shared<fml::NonOwnedMapping>(
|
||||
reinterpret_cast<const uint8_t*>(bitmap->GetPixels()), // data
|
||||
texture_descriptor.GetByteSizeOfBaseMipLevel() // size
|
||||
// As the bitmap is static in this module I believe we don't need to
|
||||
// specify a release proc.
|
||||
);
|
||||
|
||||
if (!texture->SetContents(mapping)) {
|
||||
std::shared_ptr<fml::NonOwnedMapping> mapping =
|
||||
std::make_shared<fml::NonOwnedMapping>(
|
||||
reinterpret_cast<const uint8_t*>(bitmap->GetPixels()), // data
|
||||
texture_descriptor.GetByteSizeOfBaseMipLevel() // size
|
||||
// As the bitmap is static in this module I believe we don't need to
|
||||
// specify a release proc.
|
||||
);
|
||||
std::shared_ptr<DeviceBuffer> device_buffer =
|
||||
allocator->CreateBufferWithCopy(*mapping);
|
||||
blit_pass->AddCopy(DeviceBuffer::AsBufferView(device_buffer), texture);
|
||||
if (!blit_pass->EncodeCommands(allocator)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -383,6 +397,13 @@ std::shared_ptr<GlyphAtlas> TypographerContextSTB::CreateGlyphAtlas(
|
||||
return last_atlas;
|
||||
}
|
||||
|
||||
std::shared_ptr<CommandBuffer> cmd_buffer = context.CreateCommandBuffer();
|
||||
std::shared_ptr<BlitPass> blit_pass = cmd_buffer->CreateBlitPass();
|
||||
|
||||
fml::ScopedCleanupClosure closure([&cmd_buffer, &context]() {
|
||||
context.GetCommandQueue()->Submit({std::move(cmd_buffer)});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Step 1: Determine if the atlas type and font glyph pairs are compatible
|
||||
// with the current atlas and reuse if possible.
|
||||
@@ -441,7 +462,8 @@ std::shared_ptr<GlyphAtlas> TypographerContextSTB::CreateGlyphAtlas(
|
||||
// ---------------------------------------------------------------------------
|
||||
// Step 5a: Update the existing texture with the updated bitmap.
|
||||
// ---------------------------------------------------------------------------
|
||||
if (!UpdateGlyphTextureAtlas(bitmap, last_atlas->GetTexture())) {
|
||||
if (!UpdateGlyphTextureAtlas(bitmap, context.GetResourceAllocator(),
|
||||
blit_pass, last_atlas->GetTexture())) {
|
||||
return nullptr;
|
||||
}
|
||||
return last_atlas;
|
||||
@@ -519,8 +541,8 @@ std::shared_ptr<GlyphAtlas> TypographerContextSTB::CreateGlyphAtlas(
|
||||
: PixelFormat::kR8G8B8A8UNormInt;
|
||||
break;
|
||||
}
|
||||
auto texture = UploadGlyphTextureAtlas(context.GetResourceAllocator(), bitmap,
|
||||
atlas_size, format);
|
||||
auto texture = UploadGlyphTextureAtlas(context.GetResourceAllocator(),
|
||||
blit_pass, bitmap, atlas_size, format);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -338,8 +338,7 @@ TEST_P(TypographerTest, RectanglePackerAddsNonoverlapingRectangles) {
|
||||
ASSERT_EQ(packer->PercentFull(), 0);
|
||||
}
|
||||
|
||||
TEST_P(TypographerTest,
|
||||
GlyphAtlasTextureIsRecycledWhenContentsAreNotRecreated) {
|
||||
TEST_P(TypographerTest, GlyphAtlasTextureIsRecycledWhenContentsAreRecreated) {
|
||||
auto context = TypographerContextSkia::Make();
|
||||
auto atlas_context = context->CreateGlyphAtlasContext();
|
||||
ASSERT_TRUE(context && context->IsValid());
|
||||
@@ -371,7 +370,7 @@ TEST_P(TypographerTest,
|
||||
|
||||
auto new_packer = atlas_context->GetRectPacker();
|
||||
|
||||
ASSERT_NE(second_texture, first_texture);
|
||||
ASSERT_EQ(second_texture, first_texture);
|
||||
ASSERT_NE(old_packer, new_packer);
|
||||
}
|
||||
|
||||
|
||||
@@ -494,18 +494,10 @@ void ImageDecoderImpeller::Decode(fml::RefPtr<ImageDescriptor> descriptor,
|
||||
gpu_disabled_switch]() {
|
||||
sk_sp<DlImage> image;
|
||||
std::string decode_error;
|
||||
if (context->GetCapabilities()->SupportsBufferToTextureBlits()) {
|
||||
std::tie(image, decode_error) = UploadTextureToPrivate(
|
||||
context, bitmap_result.device_buffer, bitmap_result.image_info,
|
||||
bitmap_result.sk_bitmap, gpu_disabled_switch);
|
||||
result(image, decode_error);
|
||||
} else {
|
||||
std::tie(image, decode_error) = UploadTextureToStorage(
|
||||
context, bitmap_result.sk_bitmap, gpu_disabled_switch,
|
||||
impeller::StorageMode::kDevicePrivate,
|
||||
/*create_mips=*/true);
|
||||
result(image, decode_error);
|
||||
}
|
||||
std::tie(image, decode_error) = UploadTextureToPrivate(
|
||||
context, bitmap_result.device_buffer, bitmap_result.image_info,
|
||||
bitmap_result.sk_bitmap, gpu_disabled_switch);
|
||||
result(image, decode_error);
|
||||
};
|
||||
if (context->GetBackendType() ==
|
||||
impeller::Context::BackendType::kOpenGLES) {
|
||||
|
||||
@@ -44,12 +44,6 @@ class TestImpellerDeviceBuffer : public DeviceBuffer {
|
||||
~TestImpellerDeviceBuffer() { free(bytes_); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<Texture> AsTexture(Allocator& allocator,
|
||||
const TextureDescriptor& descriptor,
|
||||
uint16_t row_bytes) const override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool SetLabel(const std::string& label) override { return true; }
|
||||
|
||||
bool SetLabel(const std::string& label, Range range) override { return true; }
|
||||
|
||||
Reference in New Issue
Block a user