[Impeller] Made the new blur work on devices without the decal address mode (flutter/engine#48899)
This also adds a new mechanism of override the device capabilities. fixes https://github.com/flutter/flutter/issues/139773 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "impeller/playground/widgets.h"
|
||||
#include "impeller/renderer/command_buffer.h"
|
||||
#include "impeller/renderer/snapshot.h"
|
||||
#include "impeller/renderer/testing/mocks.h"
|
||||
#include "impeller/scene/material.h"
|
||||
#include "impeller/scene/node.h"
|
||||
#include "impeller/typographer/backends/skia/text_frame_skia.h"
|
||||
@@ -4504,5 +4505,55 @@ TEST_P(AiksTest, GaussianBlurAtPeripheryHorizontal) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
#define FLT_FORWARD(mock, real, method) \
|
||||
EXPECT_CALL(*mock, method()) \
|
||||
.WillRepeatedly(::testing::Return(real->method()));
|
||||
|
||||
TEST_P(AiksTest, GaussianBlurWithoutDecalSupport) {
|
||||
if (GetParam() != PlaygroundBackend::kMetal) {
|
||||
GTEST_SKIP_(
|
||||
"This backend doesn't yet support setting device capabilities.");
|
||||
}
|
||||
if (!WillRenderSomething()) {
|
||||
// Sometimes these tests are run without playgrounds enabled which is
|
||||
// pointless for this test since we are asserting that
|
||||
// `SupportsDecalSamplerAddressMode` is called.
|
||||
GTEST_SKIP_("This test requires playgrounds.");
|
||||
}
|
||||
|
||||
std::shared_ptr<const Capabilities> old_capabilities =
|
||||
GetContext()->GetCapabilities();
|
||||
auto mock_capabilities = std::make_shared<MockCapabilities>();
|
||||
EXPECT_CALL(*mock_capabilities, SupportsDecalSamplerAddressMode())
|
||||
.Times(::testing::AtLeast(1))
|
||||
.WillRepeatedly(::testing::Return(false));
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultColorFormat);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, GetDefaultStencilFormat);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, SupportsOffscreenMSAA);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities,
|
||||
SupportsImplicitResolvingMSAA);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, SupportsReadFromResolve);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, SupportsFramebufferFetch);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, SupportsSSBO);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities, SupportsCompute);
|
||||
FLT_FORWARD(mock_capabilities, old_capabilities,
|
||||
SupportsTextureToTextureBlits);
|
||||
ASSERT_TRUE(SetCapabilities(mock_capabilities).ok());
|
||||
|
||||
auto texture = std::make_shared<Image>(CreateTextureForFixture("boston.jpg"));
|
||||
Canvas canvas;
|
||||
canvas.Scale(GetContentScale() * 0.5);
|
||||
canvas.DrawPaint({.color = Color::Black()});
|
||||
canvas.DrawImage(
|
||||
texture, Point(200, 200),
|
||||
{
|
||||
.image_filter = ImageFilter::MakeBlur(
|
||||
Sigma(20.0), Sigma(20.0), FilterContents::BlurStyle::kNormal,
|
||||
Entity::TileMode::kDecal),
|
||||
});
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -146,6 +146,7 @@ std::shared_ptr<Texture> MakeBlurSubpass(
|
||||
const ContentContext& renderer,
|
||||
std::shared_ptr<Texture> input_texture,
|
||||
const SamplerDescriptor& sampler_descriptor,
|
||||
Entity::TileMode tile_mode,
|
||||
const GaussianBlurFragmentShader::BlurInfo& blur_info) {
|
||||
// TODO(gaaclarke): This blurs the whole image, but because we know the clip
|
||||
// region we could focus on just blurring that.
|
||||
@@ -161,7 +162,15 @@ std::shared_ptr<Texture> MakeBlurSubpass(
|
||||
Command cmd;
|
||||
ContentContextOptions options = OptionsFromPass(pass);
|
||||
options.primitive_type = PrimitiveType::kTriangleStrip;
|
||||
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
|
||||
|
||||
if (tile_mode == Entity::TileMode::kDecal &&
|
||||
!renderer.GetDeviceCapabilities()
|
||||
.SupportsDecalSamplerAddressMode()) {
|
||||
cmd.pipeline = renderer.GetGaussianBlurDecalPipeline(options);
|
||||
} else {
|
||||
cmd.pipeline = renderer.GetGaussianBlurPipeline(options);
|
||||
}
|
||||
|
||||
BindVertices<GaussianBlurVertexShader>(cmd, host_buffer,
|
||||
{
|
||||
{Point(0, 0), Point(0, 0)},
|
||||
@@ -300,24 +309,26 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter(
|
||||
|
||||
Vector2 pass1_pixel_size = 1.0 / Vector2(pass1_out_texture->GetSize());
|
||||
|
||||
std::shared_ptr<Texture> pass2_out_texture = MakeBlurSubpass(
|
||||
renderer, pass1_out_texture, input_snapshot->sampler_descriptor,
|
||||
GaussianBlurFragmentShader::BlurInfo{
|
||||
.blur_uv_offset = Point(0.0, pass1_pixel_size.y),
|
||||
.blur_sigma = scaled_sigma * effective_scalar.y,
|
||||
.blur_radius = blur_radius * effective_scalar.y,
|
||||
.step_size = 1.0,
|
||||
});
|
||||
std::shared_ptr<Texture> pass2_out_texture =
|
||||
MakeBlurSubpass(renderer, pass1_out_texture,
|
||||
input_snapshot->sampler_descriptor, tile_mode_,
|
||||
GaussianBlurFragmentShader::BlurInfo{
|
||||
.blur_uv_offset = Point(0.0, pass1_pixel_size.y),
|
||||
.blur_sigma = scaled_sigma * effective_scalar.y,
|
||||
.blur_radius = blur_radius * effective_scalar.y,
|
||||
.step_size = 1.0,
|
||||
});
|
||||
|
||||
// TODO(gaaclarke): Make this pass reuse the texture from pass1.
|
||||
std::shared_ptr<Texture> pass3_out_texture = MakeBlurSubpass(
|
||||
renderer, pass2_out_texture, input_snapshot->sampler_descriptor,
|
||||
GaussianBlurFragmentShader::BlurInfo{
|
||||
.blur_uv_offset = Point(pass1_pixel_size.x, 0.0),
|
||||
.blur_sigma = scaled_sigma * effective_scalar.x,
|
||||
.blur_radius = blur_radius * effective_scalar.x,
|
||||
.step_size = 1.0,
|
||||
});
|
||||
std::shared_ptr<Texture> pass3_out_texture =
|
||||
MakeBlurSubpass(renderer, pass2_out_texture,
|
||||
input_snapshot->sampler_descriptor, tile_mode_,
|
||||
GaussianBlurFragmentShader::BlurInfo{
|
||||
.blur_uv_offset = Point(pass1_pixel_size.x, 0.0),
|
||||
.blur_sigma = scaled_sigma * effective_scalar.x,
|
||||
.blur_radius = blur_radius * effective_scalar.x,
|
||||
.step_size = 1.0,
|
||||
});
|
||||
|
||||
SamplerDescriptor sampler_desc = MakeSamplerDescriptor(
|
||||
MinMagFilter::kLinear, SamplerAddressMode::kClampToEdge);
|
||||
|
||||
@@ -58,6 +58,13 @@ class GoldenPlaygroundTest
|
||||
|
||||
ISize GetWindowSize() const;
|
||||
|
||||
[[nodiscard]] fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities);
|
||||
|
||||
/// TODO(https://github.com/flutter/flutter/issues/139950): Remove this.
|
||||
/// Returns true if `OpenPlaygroundHere` will actually render anything.
|
||||
bool WillRenderSomething() const { return true; }
|
||||
|
||||
protected:
|
||||
void SetWindowSize(ISize size);
|
||||
|
||||
|
||||
@@ -198,4 +198,9 @@ void GoldenPlaygroundTest::GoldenPlaygroundTest::SetWindowSize(ISize size) {
|
||||
pimpl_->window_size = size;
|
||||
}
|
||||
|
||||
fml::Status GoldenPlaygroundTest::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
return pimpl_->screenshotter->GetPlayground().SetCapabilities(capabilities);
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -66,4 +66,11 @@ ISize GoldenPlaygroundTest::GetWindowSize() const {
|
||||
|
||||
void GoldenPlaygroundTest::SetWindowSize(ISize size) {}
|
||||
|
||||
fml::Status GoldenPlaygroundTest::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
return fml::Status(
|
||||
fml::StatusCode::kUnimplemented,
|
||||
"GoldenPlaygroundTest-Stub doesn't support SetCapabilities.");
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -25,7 +25,7 @@ class MetalScreenshotter {
|
||||
300},
|
||||
bool scale_content = true);
|
||||
|
||||
const PlaygroundImpl& GetPlayground() const { return *playground_; }
|
||||
PlaygroundImpl& GetPlayground() { return *playground_; }
|
||||
|
||||
private:
|
||||
std::unique_ptr<PlaygroundImpl> playground_;
|
||||
|
||||
@@ -156,4 +156,11 @@ std::unique_ptr<Surface> PlaygroundImplGLES::AcquireSurfaceFrame(
|
||||
);
|
||||
}
|
||||
|
||||
fml::Status PlaygroundImplGLES::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
return fml::Status(
|
||||
fml::StatusCode::kUnimplemented,
|
||||
"PlaygroundImplGLES doesn't support setting the capabilities.");
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -16,6 +16,9 @@ class PlaygroundImplGLES final : public PlaygroundImpl {
|
||||
|
||||
~PlaygroundImplGLES();
|
||||
|
||||
fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) override;
|
||||
|
||||
private:
|
||||
class ReactorWorker;
|
||||
|
||||
|
||||
@@ -14,12 +14,18 @@
|
||||
|
||||
namespace impeller {
|
||||
|
||||
// Forward declared to avoid objc in a C++ header.
|
||||
class ContextMTL;
|
||||
|
||||
class PlaygroundImplMTL final : public PlaygroundImpl {
|
||||
public:
|
||||
explicit PlaygroundImplMTL(PlaygroundSwitches switches);
|
||||
|
||||
~PlaygroundImplMTL();
|
||||
|
||||
fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) override;
|
||||
|
||||
private:
|
||||
struct Data;
|
||||
|
||||
@@ -29,7 +35,7 @@ class PlaygroundImplMTL final : public PlaygroundImpl {
|
||||
|
||||
// To ensure that ObjC stuff doesn't leak into C++ TUs.
|
||||
std::unique_ptr<Data> data_;
|
||||
std::shared_ptr<Context> context_;
|
||||
std::shared_ptr<ContextMTL> context_;
|
||||
std::shared_ptr<fml::ConcurrentMessageLoop> concurrent_loop_;
|
||||
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
|
||||
|
||||
|
||||
@@ -123,4 +123,10 @@ std::unique_ptr<Surface> PlaygroundImplMTL::AcquireSurfaceFrame(
|
||||
return SurfaceMTL::MakeFromMetalLayerDrawable(context, drawable);
|
||||
}
|
||||
|
||||
fml::Status PlaygroundImplMTL::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
context_->SetCapabilities(capabilities);
|
||||
return fml::Status();
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -182,4 +182,11 @@ void PlaygroundImplVK::InitGlobalVulkanInstance() {
|
||||
global_instance_ = std::move(instance_result.value);
|
||||
}
|
||||
|
||||
fml::Status PlaygroundImplVK::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
return fml::Status(
|
||||
fml::StatusCode::kUnimplemented,
|
||||
"PlaygroundImplVK doesn't support setting the capabilities.");
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -17,6 +17,9 @@ class PlaygroundImplVK final : public PlaygroundImpl {
|
||||
|
||||
~PlaygroundImplVK();
|
||||
|
||||
fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Context> context_;
|
||||
|
||||
|
||||
@@ -532,4 +532,13 @@ bool Playground::ShouldKeepRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
fml::Status Playground::SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) {
|
||||
return impl_->SetCapabilities(capabilities);
|
||||
}
|
||||
|
||||
bool Playground::WillRenderSomething() const {
|
||||
return switches_.enable_playground;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "flutter/fml/closure.h"
|
||||
#include "flutter/fml/macros.h"
|
||||
#include "flutter/fml/status.h"
|
||||
#include "flutter/fml/time/time_delta.h"
|
||||
#include "impeller/core/texture.h"
|
||||
#include "impeller/geometry/point.h"
|
||||
@@ -88,6 +89,13 @@ class Playground {
|
||||
|
||||
virtual std::string GetWindowTitle() const = 0;
|
||||
|
||||
[[nodiscard]] fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities);
|
||||
|
||||
/// TODO(https://github.com/flutter/flutter/issues/139950): Remove this.
|
||||
/// Returns true if `OpenPlaygroundHere` will actually render anything.
|
||||
bool WillRenderSomething() const;
|
||||
|
||||
protected:
|
||||
const PlaygroundSwitches switches_;
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ class PlaygroundImpl {
|
||||
|
||||
Vector2 GetContentScale() const;
|
||||
|
||||
virtual fml::Status SetCapabilities(
|
||||
const std::shared_ptr<Capabilities>& capabilities) = 0;
|
||||
|
||||
protected:
|
||||
const PlaygroundSwitches switches_;
|
||||
|
||||
|
||||
@@ -83,6 +83,8 @@ class ContextMTL final : public Context,
|
||||
// |Context|
|
||||
const std::shared_ptr<const Capabilities>& GetCapabilities() const override;
|
||||
|
||||
void SetCapabilities(const std::shared_ptr<const Capabilities>& capabilities);
|
||||
|
||||
// |Context|
|
||||
bool UpdateOffscreenLayerPixelFormat(PixelFormat format) override;
|
||||
|
||||
|
||||
@@ -376,6 +376,11 @@ const std::shared_ptr<const Capabilities>& ContextMTL::GetCapabilities() const {
|
||||
return device_capabilities_;
|
||||
}
|
||||
|
||||
void ContextMTL::SetCapabilities(
|
||||
const std::shared_ptr<const Capabilities>& capabilities) {
|
||||
device_capabilities_ = capabilities;
|
||||
}
|
||||
|
||||
// |Context|
|
||||
bool ContextMTL::UpdateOffscreenLayerPixelFormat(PixelFormat format) {
|
||||
device_capabilities_ = InferMetalCapabilities(device_, format);
|
||||
|
||||
Reference in New Issue
Block a user