Skip to content

Commit 6658986

Browse files
author
Jonah Williams
authored
[Impeller] set stencil attachment descriptor for runtime effect. (flutter#42054)
This fixes the correctness issues observed in flutter#126701 . The missing stencil descriptor meant that the clips were always ignored. Have not yet investigated the reported debug performance issues.
1 parent 4c46228 commit 6658986

5 files changed

Lines changed: 59 additions & 1 deletion

File tree

impeller/aiks/aiks_unittests.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,5 +2263,39 @@ TEST_P(AiksTest, CanRenderBackdropBlur) {
22632263
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
22642264
}
22652265

2266+
// Regression test for https://github.com/flutter/flutter/issues/126701 .
2267+
TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
2268+
if (GetParam() != PlaygroundBackend::kMetal) {
2269+
GTEST_SKIP_("This backend doesn't support runtime effects.");
2270+
}
2271+
2272+
auto runtime_stage =
2273+
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
2274+
ASSERT_TRUE(runtime_stage->IsDirty());
2275+
2276+
struct FragUniforms {
2277+
Vector2 iResolution;
2278+
Scalar iTime;
2279+
} frag_uniforms = {.iResolution = Vector2(400, 400), .iTime = 100.0};
2280+
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
2281+
uniform_data->resize(sizeof(FragUniforms));
2282+
memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));
2283+
2284+
std::vector<RuntimeEffectContents::TextureInput> texture_inputs;
2285+
2286+
Paint paint;
2287+
paint.color_source = ColorSource::MakeRuntimeEffect(
2288+
runtime_stage, uniform_data, texture_inputs);
2289+
2290+
Canvas canvas;
2291+
canvas.Save();
2292+
canvas.ClipRRect(Rect{0, 0, 400, 400}, 10.0,
2293+
Entity::ClipOperation::kIntersect);
2294+
canvas.DrawRect(Rect{0, 0, 400, 400}, paint);
2295+
canvas.Restore();
2296+
2297+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2298+
}
2299+
22662300
} // namespace testing
22672301
} // namespace impeller

impeller/entity/contents/runtime_effect_contents.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
124124
desc.SetVertexDescriptor(std::move(vertex_descriptor));
125125
desc.SetColorAttachmentDescriptor(
126126
0u, {.format = color_attachment_format, .blending_enabled = true});
127-
desc.SetStencilAttachmentDescriptors({});
127+
128+
StencilAttachmentDescriptor stencil0;
129+
stencil0.stencil_compare = CompareFunction::kEqual;
130+
desc.SetStencilAttachmentDescriptors(stencil0);
128131
desc.SetStencilPixelFormat(stencil_attachment_format);
129132

130133
auto options = OptionsFromPassAndEntity(pass, entity);

impeller/golden_tests/golden_playground_test.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class GoldenPlaygroundTest
3636
const char* fixture_name,
3737
bool enable_mipmapping = false) const;
3838

39+
std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage(
40+
const char* asset_name) const;
41+
3942
std::shared_ptr<Context> GetContext() const;
4043

4144
Point GetContentScale() const;

impeller/golden_tests/golden_playground_test_mac.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,19 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
147147
return result;
148148
}
149149

150+
std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
151+
const char* asset_name) const {
152+
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
153+
if (!fixture || fixture->GetSize() == 0) {
154+
return nullptr;
155+
}
156+
auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
157+
if (!stage->IsValid()) {
158+
return nullptr;
159+
}
160+
return stage;
161+
}
162+
150163
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
151164
return pimpl_->screenshoter->GetContext().GetContext();
152165
}

impeller/golden_tests/golden_playground_test_stub.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
3333
return nullptr;
3434
}
3535

36+
std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
37+
const char* asset_name) const {
38+
return nullptr;
39+
}
40+
3641
std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
3742
return nullptr;
3843
}

0 commit comments

Comments
 (0)