[Impeller] clamp render target size at max texture size. (flutter/engine#55628)
Part of https://github.com/flutter/flutter/issues/128912 If an intermediate render target would be larger than the max texture size, then clamp the texture.
This commit is contained in:
@@ -1509,5 +1509,30 @@ TEST_P(AiksTest, PipelineBlendSingleParameter) {
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
// Creates an image matrix filter that scales large content such that it would
|
||||
// exceed the max texture size. See
|
||||
// https://github.com/flutter/flutter/issues/128912
|
||||
TEST_P(AiksTest, MassiveScalingMatrixImageFilter) {
|
||||
if (GetBackend() == PlaygroundBackend::kVulkan) {
|
||||
GTEST_SKIP() << "Swiftshader is running out of memory on this example.";
|
||||
}
|
||||
DisplayListBuilder builder(SkRect::MakeSize(SkSize::Make(1000, 1000)));
|
||||
|
||||
auto filter = DlMatrixImageFilter::Make(SkMatrix::Scale(0.001, 0.001),
|
||||
DlImageSampling::kLinear);
|
||||
|
||||
DlPaint paint;
|
||||
paint.setImageFilter(filter);
|
||||
builder.SaveLayer(nullptr, &paint);
|
||||
{
|
||||
DlPaint paint;
|
||||
paint.setColor(DlColor::kRed());
|
||||
builder.DrawRect(SkRect::MakeLTRB(0, 0, 100000, 100000), paint);
|
||||
}
|
||||
builder.Restore();
|
||||
|
||||
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -1107,6 +1107,13 @@ void Canvas::SaveLayer(const Paint& paint,
|
||||
return SkipUntilMatchingRestore(total_content_depth);
|
||||
}
|
||||
|
||||
// When there are scaling filters present, these contents may exceed the
|
||||
// maximum texture size. Perform a clamp here, which may cause rendering
|
||||
// artifacts.
|
||||
subpass_size = subpass_size.Min(renderer_.GetContext()
|
||||
->GetCapabilities()
|
||||
->GetMaximumRenderPassAttachmentSize());
|
||||
|
||||
// Backdrop filter state, ignored if there is no BDF.
|
||||
std::shared_ptr<FilterContents> backdrop_filter_contents;
|
||||
Point local_position = {0, 0};
|
||||
|
||||
@@ -205,4 +205,8 @@ PixelFormat CapabilitiesGLES::GetDefaultGlyphAtlasFormat() const {
|
||||
return default_glyph_atlas_format_;
|
||||
}
|
||||
|
||||
ISize CapabilitiesGLES::GetMaximumRenderPassAttachmentSize() const {
|
||||
return max_texture_size;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -122,6 +122,8 @@ class CapabilitiesGLES final
|
||||
// |Capabilities|
|
||||
PixelFormat GetDefaultGlyphAtlasFormat() const override;
|
||||
|
||||
ISize GetMaximumRenderPassAttachmentSize() const override;
|
||||
|
||||
private:
|
||||
bool supports_framebuffer_fetch_ = false;
|
||||
bool supports_decal_sampler_address_mode_ = false;
|
||||
|
||||
@@ -32,6 +32,8 @@ class DebugAllocatorStats {
|
||||
std::atomic<size_t> size_ = 0;
|
||||
};
|
||||
|
||||
ISize DeviceMaxTextureSizeSupported(id<MTLDevice> device);
|
||||
|
||||
class AllocatorMTL final : public Allocator {
|
||||
public:
|
||||
AllocatorMTL();
|
||||
|
||||
@@ -52,7 +52,7 @@ static bool DeviceHasUnifiedMemoryArchitecture(id<MTLDevice> device) {
|
||||
FML_UNREACHABLE();
|
||||
}
|
||||
|
||||
static ISize DeviceMaxTextureSizeSupported(id<MTLDevice> device) {
|
||||
ISize DeviceMaxTextureSizeSupported(id<MTLDevice> device) {
|
||||
// Since Apple didn't expose API for us to get the max texture size, we have
|
||||
// to use hardcoded data from
|
||||
// https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf
|
||||
|
||||
@@ -69,6 +69,7 @@ static std::unique_ptr<Capabilities> InferMetalCapabilities(
|
||||
.SetSupportsDeviceTransientTextures(true)
|
||||
.SetDefaultGlyphAtlasFormat(PixelFormat::kA8UNormInt)
|
||||
.SetSupportsTriangleFan(false)
|
||||
.SetMaximumRenderPassAttachmentSize(DeviceMaxTextureSizeSupported(device))
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -558,6 +558,10 @@ bool CapabilitiesVK::SetPhysicalDevice(
|
||||
.get<vk::PhysicalDeviceImageCompressionControlFeaturesEXT>()
|
||||
.imageCompressionControl;
|
||||
|
||||
max_render_pass_attachment_size_ =
|
||||
ISize{device_properties_.limits.maxFramebufferWidth,
|
||||
device_properties_.limits.maxFramebufferHeight};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -712,4 +716,8 @@ bool CapabilitiesVK::SupportsTriangleFan() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
ISize CapabilitiesVK::GetMaximumRenderPassAttachmentSize() const {
|
||||
return max_render_pass_attachment_size_;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
@@ -253,6 +253,9 @@ class CapabilitiesVK final : public Capabilities,
|
||||
// |Capabilities|
|
||||
PixelFormat GetDefaultGlyphAtlasFormat() const override;
|
||||
|
||||
// |Capabilities|
|
||||
ISize GetMaximumRenderPassAttachmentSize() const override;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/// @return If fixed-rate compression for non-onscreen surfaces is
|
||||
/// supported.
|
||||
@@ -287,6 +290,7 @@ class CapabilitiesVK final : public Capabilities,
|
||||
bool supports_compute_subgroups_ = false;
|
||||
bool supports_device_transient_textures_ = false;
|
||||
bool supports_texture_fixed_rate_compression_ = false;
|
||||
ISize max_render_pass_attachment_size_ = ISize{0, 0};
|
||||
bool is_valid_ = false;
|
||||
|
||||
bool HasExtension(const std::string& ext) const;
|
||||
|
||||
@@ -83,6 +83,11 @@ class StandardCapabilities final : public Capabilities {
|
||||
return default_glyph_atlas_format_;
|
||||
}
|
||||
|
||||
// |Capabilities|
|
||||
ISize GetMaximumRenderPassAttachmentSize() const override {
|
||||
return default_maximum_render_pass_attachment_size_;
|
||||
}
|
||||
|
||||
private:
|
||||
StandardCapabilities(bool supports_offscreen_msaa,
|
||||
bool supports_ssbo,
|
||||
@@ -97,7 +102,8 @@ class StandardCapabilities final : public Capabilities {
|
||||
PixelFormat default_color_format,
|
||||
PixelFormat default_stencil_format,
|
||||
PixelFormat default_depth_stencil_format,
|
||||
PixelFormat default_glyph_atlas_format)
|
||||
PixelFormat default_glyph_atlas_format,
|
||||
ISize default_maximum_render_pass_attachment_size)
|
||||
: supports_offscreen_msaa_(supports_offscreen_msaa),
|
||||
supports_ssbo_(supports_ssbo),
|
||||
supports_texture_to_texture_blits_(supports_texture_to_texture_blits),
|
||||
@@ -112,7 +118,9 @@ class StandardCapabilities final : public Capabilities {
|
||||
default_color_format_(default_color_format),
|
||||
default_stencil_format_(default_stencil_format),
|
||||
default_depth_stencil_format_(default_depth_stencil_format),
|
||||
default_glyph_atlas_format_(default_glyph_atlas_format) {}
|
||||
default_glyph_atlas_format_(default_glyph_atlas_format),
|
||||
default_maximum_render_pass_attachment_size_(
|
||||
default_maximum_render_pass_attachment_size) {}
|
||||
|
||||
friend class CapabilitiesBuilder;
|
||||
|
||||
@@ -130,6 +138,7 @@ class StandardCapabilities final : public Capabilities {
|
||||
PixelFormat default_stencil_format_ = PixelFormat::kUnknown;
|
||||
PixelFormat default_depth_stencil_format_ = PixelFormat::kUnknown;
|
||||
PixelFormat default_glyph_atlas_format_ = PixelFormat::kUnknown;
|
||||
ISize default_maximum_render_pass_attachment_size_ = ISize(1, 1);
|
||||
|
||||
StandardCapabilities(const StandardCapabilities&) = delete;
|
||||
|
||||
@@ -220,6 +229,12 @@ CapabilitiesBuilder& CapabilitiesBuilder::SetSupportsTriangleFan(bool value) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
CapabilitiesBuilder& CapabilitiesBuilder::SetMaximumRenderPassAttachmentSize(
|
||||
ISize size) {
|
||||
default_maximum_render_pass_attachment_size_ = size;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
|
||||
return std::unique_ptr<StandardCapabilities>(new StandardCapabilities( //
|
||||
supports_offscreen_msaa_, //
|
||||
@@ -235,7 +250,8 @@ std::unique_ptr<Capabilities> CapabilitiesBuilder::Build() {
|
||||
default_color_format_.value_or(PixelFormat::kUnknown), //
|
||||
default_stencil_format_.value_or(PixelFormat::kUnknown), //
|
||||
default_depth_stencil_format_.value_or(PixelFormat::kUnknown), //
|
||||
default_glyph_atlas_format_.value_or(PixelFormat::kUnknown) //
|
||||
default_glyph_atlas_format_.value_or(PixelFormat::kUnknown), //
|
||||
default_maximum_render_pass_attachment_size_.value_or(ISize{1, 1}) //
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,11 @@ class Capabilities {
|
||||
/// should not have any impact
|
||||
virtual PixelFormat GetDefaultGlyphAtlasFormat() const = 0;
|
||||
|
||||
/// @brief Return the maximum size of a render pass attachment.
|
||||
///
|
||||
/// Note that this may be smaller than the maximum allocatable texture size.
|
||||
virtual ISize GetMaximumRenderPassAttachmentSize() const = 0;
|
||||
|
||||
protected:
|
||||
Capabilities();
|
||||
|
||||
@@ -150,6 +155,8 @@ class CapabilitiesBuilder {
|
||||
|
||||
CapabilitiesBuilder& SetSupportsTriangleFan(bool value);
|
||||
|
||||
CapabilitiesBuilder& SetMaximumRenderPassAttachmentSize(ISize size);
|
||||
|
||||
std::unique_ptr<Capabilities> Build();
|
||||
|
||||
private:
|
||||
@@ -167,6 +174,8 @@ class CapabilitiesBuilder {
|
||||
std::optional<PixelFormat> default_stencil_format_ = std::nullopt;
|
||||
std::optional<PixelFormat> default_depth_stencil_format_ = std::nullopt;
|
||||
std::optional<PixelFormat> default_glyph_atlas_format_ = std::nullopt;
|
||||
std::optional<ISize> default_maximum_render_pass_attachment_size_ =
|
||||
std::nullopt;
|
||||
|
||||
CapabilitiesBuilder(const CapabilitiesBuilder&) = delete;
|
||||
|
||||
|
||||
@@ -66,5 +66,14 @@ TEST(CapabilitiesTest, DefaultGlyphAtlasFormat) {
|
||||
EXPECT_EQ(mutated->GetDefaultGlyphAtlasFormat(), PixelFormat::kA8UNormInt);
|
||||
}
|
||||
|
||||
TEST(CapabilitiesTest, MaxRenderPassAttachmentSize) {
|
||||
auto defaults = CapabilitiesBuilder().Build();
|
||||
EXPECT_EQ(defaults->GetMaximumRenderPassAttachmentSize(), ISize(1, 1));
|
||||
auto mutated = CapabilitiesBuilder()
|
||||
.SetMaximumRenderPassAttachmentSize({100, 100})
|
||||
.Build();
|
||||
EXPECT_EQ(mutated->GetMaximumRenderPassAttachmentSize(), ISize(100, 100));
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace impeller
|
||||
|
||||
@@ -217,6 +217,7 @@ class MockCapabilities : public Capabilities {
|
||||
MOCK_METHOD(PixelFormat, GetDefaultStencilFormat, (), (const, override));
|
||||
MOCK_METHOD(PixelFormat, GetDefaultDepthStencilFormat, (), (const, override));
|
||||
MOCK_METHOD(PixelFormat, GetDefaultGlyphAtlasFormat, (), (const, override));
|
||||
MOCK_METHOD(ISize, GetMaximumRenderPassAttachmentSize, (), (const override));
|
||||
};
|
||||
|
||||
class MockCommandQueue : public CommandQueue {
|
||||
|
||||
@@ -769,6 +769,8 @@ impeller_Play_AiksTest_MaskBlurVariantTestSolidTranslucent_Vulkan.png
|
||||
impeller_Play_AiksTest_MaskBlurWithZeroSigmaIsSkipped_Metal.png
|
||||
impeller_Play_AiksTest_MaskBlurWithZeroSigmaIsSkipped_OpenGLES.png
|
||||
impeller_Play_AiksTest_MaskBlurWithZeroSigmaIsSkipped_Vulkan.png
|
||||
impeller_Play_AiksTest_MassiveScalingMatrixImageFilter_Metal.png
|
||||
impeller_Play_AiksTest_MassiveScalingMatrixImageFilter_OpenGLES.png
|
||||
impeller_Play_AiksTest_MatrixBackdropFilter_Metal.png
|
||||
impeller_Play_AiksTest_MatrixBackdropFilter_OpenGLES.png
|
||||
impeller_Play_AiksTest_MatrixBackdropFilter_Vulkan.png
|
||||
|
||||
Reference in New Issue
Block a user