Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2263,5 +2263,39 @@ TEST_P(AiksTest, CanRenderBackdropBlur) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

// Regression test for https://github.com/flutter/flutter/issues/126701 .
TEST_P(AiksTest, CanRenderClippedRuntimeEffects) {
if (GetParam() != PlaygroundBackend::kMetal) {
GTEST_SKIP_("This backend doesn't support runtime effects.");
}

auto runtime_stage =
OpenAssetAsRuntimeStage("runtime_stage_example.frag.iplr");
ASSERT_TRUE(runtime_stage->IsDirty());

struct FragUniforms {
Vector2 iResolution;
Scalar iTime;
} frag_uniforms = {.iResolution = Vector2(400, 400), .iTime = 100.0};
auto uniform_data = std::make_shared<std::vector<uint8_t>>();
uniform_data->resize(sizeof(FragUniforms));
memcpy(uniform_data->data(), &frag_uniforms, sizeof(FragUniforms));

std::vector<RuntimeEffectContents::TextureInput> texture_inputs;

Paint paint;
paint.color_source = ColorSource::MakeRuntimeEffect(
runtime_stage, uniform_data, texture_inputs);

Canvas canvas;
canvas.Save();
canvas.ClipRRect(Rect{0, 0, 400, 400}, 10.0,
Entity::ClipOperation::kIntersect);
canvas.DrawRect(Rect{0, 0, 400, 400}, paint);
canvas.Restore();

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

} // namespace testing
} // namespace impeller
5 changes: 4 additions & 1 deletion impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
desc.SetVertexDescriptor(std::move(vertex_descriptor));
desc.SetColorAttachmentDescriptor(
0u, {.format = color_attachment_format, .blending_enabled = true});
desc.SetStencilAttachmentDescriptors({});

StencilAttachmentDescriptor stencil0;
stencil0.stencil_compare = CompareFunction::kEqual;
Copy link
Member

Choose a reason for hiding this comment

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

The stencil depth (you can get this from the Entity) should also be set here, otherwise any clips will cause the output to get discarded.

Copy link
Member

Choose a reason for hiding this comment

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

Specifically, the "stencil_reference" field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also set this on the command below. its a bit hard to track though, I think ultimately all of this information needs to end up on the descriptor right?

Copy link
Member

Choose a reason for hiding this comment

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

Ah whoops, I missed that we're already setting it.

The reason we have the stencil ref on the command and not the pipeline descriptor is that it's a pipeline input, not a property that we need to hash and build new pipelines for.

desc.SetStencilAttachmentDescriptors(stencil0);
desc.SetStencilPixelFormat(stencil_attachment_format);

auto options = OptionsFromPassAndEntity(pass, entity);
Expand Down
3 changes: 3 additions & 0 deletions impeller/golden_tests/golden_playground_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class GoldenPlaygroundTest
const char* fixture_name,
bool enable_mipmapping = false) const;

std::shared_ptr<RuntimeStage> OpenAssetAsRuntimeStage(
const char* asset_name) const;

std::shared_ptr<Context> GetContext() const;

Point GetContentScale() const;
Expand Down
13 changes: 13 additions & 0 deletions impeller/golden_tests/golden_playground_test_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
return result;
}

std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
auto fixture = flutter::testing::OpenFixtureAsMapping(asset_name);
if (!fixture || fixture->GetSize() == 0) {
return nullptr;
}
auto stage = std::make_unique<RuntimeStage>(std::move(fixture));
if (!stage->IsValid()) {
return nullptr;
}
return stage;
}

std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
return pimpl_->screenshoter->GetContext().GetContext();
}
Expand Down
5 changes: 5 additions & 0 deletions impeller/golden_tests/golden_playground_test_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ std::shared_ptr<Texture> GoldenPlaygroundTest::CreateTextureForFixture(
return nullptr;
}

std::shared_ptr<RuntimeStage> GoldenPlaygroundTest::OpenAssetAsRuntimeStage(
const char* asset_name) const {
return nullptr;
}

std::shared_ptr<Context> GoldenPlaygroundTest::GetContext() const {
return nullptr;
}
Expand Down