Skip to content

Commit 37f6113

Browse files
authored
Add --shader-report and --fail-on-unused-shaders option to impeller_golden_tests (flutter#193319)
Fixes flutter#193318 Adds a --shader-report option to impeller_golden_tests. When running with this option, the test suite will spit out a report on which shaders were prewarmed, but never used. Adds a --fail-on-unused-shaders option to impeller_golden_tests. When running with this option, the goldens will fail if there are any shaders that are completely unused in the golden tests. Everything is only run in debug builds inside of impeller_golden_tests, so no production impact. --fail-on-unused-shaders is not hooked up to CI yet. Example output for --shader-report: ``` ================================================================================ Impeller pipeline variant usage ================================================================================ 2948 tests run, 55 skipped, 0 failed, filter '*' Legend: SC = specialization constants, +flag = option enabled, "drawn as" = how the same pipeline was actually drawn. -------------------------------------------------------------------------------- Metal 276 variants: 137 warmed (0 drawn) | 0 created lazily, never drawn Draws covered by warmed variants: 0 of 620,223 (0.0%) WARMED BUT NEVER DRAWN (137) - candidates to stop warming Likely cause: 111 of 137 were drawn, but only with other options: 111 depth Always -> GreaterEqual 48 blend SrcOver -> Src 45 format B10G10R10A10XR -> B8G8R8A8UNormInt 26 prim Triangle -> TriangleStrip 16 depth_stencil on -> off 16 msaa 4x -> 1x 4 prim TriangleStrip -> Triangle 2 blend SrcOver -> Dst ... 3 other changes 26 of 137 were never drawn with any options. msaa=1x blend=SrcOver depth=Always stencil=Ignore prim=TriangleStrip format=B8G8R8A8UNormInt Gaussian Pipeline SC=[1] drawn as: depth Always -> GreaterEqual (2,248 draws) TextureDownsample Pipeline drawn as: depth Always -> GreaterEqual (866 draws) TextureDownsampleBounded Pipeline drawn as: depth Always -> GreaterEqual (18 draws) msaa=1x blend=SrcOver depth=Always stencil=Ignore prim=TriangleStrip format=B10G10R10A10XR Gaussian Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (2,248 draws) TextureDownsample Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (866 draws) TextureDownsampleBounded Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (18 draws) msaa=4x blend=SrcOver depth=Always stencil=Ignore prim=Triangle format=B8G8R8A8UNormInt +depth_stencil Circle Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (2,949 draws) Clip Pipeline drawn as: blend SrcOver -> Dst, depth Always -> GreaterEqual, stencil Ignore -> StencilIncrementAll, prim Triangle -> TriangleStrip (390 draws) ComplexRse Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (8 draws) ConicalGradientSsboFill Pipeline SC=[0] never drawn with any options ConicalGradientSsboFill Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (8 draws) ConicalGradientSsboFill Pipeline SC=[2] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (4 draws) ConicalGradientSsboFill Pipeline SC=[3] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (41 draws) FastGradient Pipeline drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, depth_write off -> on (8 draws) GlyphAtlas Pipeline SC=[1] drawn as: depth Always -> GreaterEqual (690 draws) LinearGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (86 draws) RadialGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (96 draws) ShadowVertices Pipeline drawn as: depth Always -> GreaterEqual (660 draws) SolidFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (2,400 draws) SweepGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (36 draws) TextureFill Pipeline drawn as: depth Always -> GreaterEqual (16 draws) TextureFillStrictSrc Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (60 draws) TiledTextureFill Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (418 draws) UberSdf Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (295,723 draws) VerticesUber1 Pipeline SC=[1] drawn as: depth Always -> GreaterEqual (8 draws) VerticesUber2 Pipeline SC=[1] never drawn with any options msaa=4x blend=SrcOver depth=Always stencil=Ignore prim=Triangle format=B10G10R10A10XR +depth_stencil Circle Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (2,949 draws) Clip Pipeline drawn as: blend SrcOver -> Dst, depth Always -> GreaterEqual, stencil Ignore -> StencilIncrementAll, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (390 draws) ComplexRse Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) ConicalGradientSsboFill Pipeline SC=[0] never drawn with any options ConicalGradientSsboFill Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) ConicalGradientSsboFill Pipeline SC=[2] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (4 draws) ConicalGradientSsboFill Pipeline SC=[3] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (41 draws) FastGradient Pipeline drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt, depth_write off -> on (8 draws) GlyphAtlas Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (690 draws) LinearGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (86 draws) RadialGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (96 draws) ShadowVertices Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (660 draws) SolidFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (2,400 draws) SweepGradientSsboFill Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (36 draws) TextureFill Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (16 draws) TextureFillStrictSrc Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (60 draws) TiledTextureFill Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip, format B10G10R10A10XR -> B8G8R8A8UNormInt (418 draws) UberSdf Pipeline drawn as: depth Always -> GreaterEqual, prim Triangle -> TriangleStrip (2 draws) VerticesUber1 Pipeline SC=[1] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) VerticesUber2 Pipeline SC=[1] never drawn with any options msaa=4x blend=SrcOver depth=Always stencil=Ignore prim=TriangleStrip format=B8G8R8A8UNormInt +depth_stencil AdvancedBlend Pipeline SC=[0,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[1,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[2,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[3,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[4,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[5,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[6,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[7,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[8,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[9,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[10,1] drawn as: depth Always -> GreaterEqual (30 draws) AdvancedBlend Pipeline SC=[11,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[12,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[13,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) AdvancedBlend Pipeline SC=[14,1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (2 draws) BorderMaskBlur Pipeline never drawn with any options ColorMatrixColorFilter Pipeline drawn as: depth Always -> GreaterEqual (68 draws) FramebufferBlend Pipeline SC=[0,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (52 draws) FramebufferBlend Pipeline SC=[1,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[2,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[3,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (52 draws) FramebufferBlend Pipeline SC=[4,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (52 draws) FramebufferBlend Pipeline SC=[5,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[6,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[7,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[8,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (56 draws) FramebufferBlend Pipeline SC=[9,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (76 draws) FramebufferBlend Pipeline SC=[10,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (56 draws) FramebufferBlend Pipeline SC=[11,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[12,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (48 draws) FramebufferBlend Pipeline SC=[13,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) FramebufferBlend Pipeline SC=[14,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual (44 draws) LinearToSrgbFilter Pipeline drawn as: depth Always -> GreaterEqual (8 draws) MorphologyFilter Pipeline SC=[1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, depth_stencil on -> off (48 draws) PorterDuffBlend Pipeline SC=[1,0,0,0,0,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,0,0,1] drawn as: depth Always -> GreaterEqual (4 draws) PorterDuffBlend Pipeline SC=[1,0,0,0,1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,0,-1] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,0,0] drawn as: depth Always -> GreaterEqual (20 draws) PorterDuffBlend Pipeline SC=[1,0,1,0,0,0] drawn as: depth Always -> GreaterEqual, prim TriangleStrip -> Triangle (86 draws) PorterDuffBlend Pipeline SC=[1,0,1,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,0,0,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,0,1,0] drawn as: depth Always -> GreaterEqual, prim TriangleStrip -> Triangle (4 draws) PorterDuffBlend Pipeline SC=[1,1,-1,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,1,0,0] drawn as: depth Always -> GreaterEqual (8 draws) PorterDuffBlend Pipeline SC=[1,1,0,0,0,0] drawn as: depth Always -> GreaterEqual (8 draws) PorterDuffBlend Pipeline SC=[1,1,0,1,-1,0] drawn as: depth Always -> GreaterEqual (6 draws) PorterDuffBlend Pipeline SC=[1,1,0,1,0,0] drawn as: depth Always -> GreaterEqual, format B8G8R8A8UNormInt -> B10G10R10A10XR (4 draws) RrectBlur Pipeline drawn as: depth Always -> GreaterEqual (454 draws) RsuperellipseBlur Pipeline never drawn with any options SrgbToLinearFilter Pipeline never drawn with any options YuvToRgbFilter Pipeline never drawn with any options msaa=4x blend=SrcOver depth=Always stencil=Ignore prim=TriangleStrip format=B10G10R10A10XR +depth_stencil BorderMaskBlur Pipeline never drawn with any options ColorMatrixColorFilter Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (68 draws) FramebufferBlend Pipeline SC=[0,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (52 draws) FramebufferBlend Pipeline SC=[1,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[2,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[3,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (52 draws) FramebufferBlend Pipeline SC=[4,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (52 draws) FramebufferBlend Pipeline SC=[5,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[6,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[7,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[8,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (56 draws) FramebufferBlend Pipeline SC=[9,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (76 draws) FramebufferBlend Pipeline SC=[10,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (56 draws) FramebufferBlend Pipeline SC=[11,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[12,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (48 draws) FramebufferBlend Pipeline SC=[13,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) FramebufferBlend Pipeline SC=[14,1] drawn as: blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (44 draws) LinearToSrgbFilter Pipeline drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) MorphologyFilter Pipeline SC=[1] drawn as: msaa 4x -> 1x, blend SrcOver -> Src, depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt, depth_stencil on -> off (48 draws) PorterDuffBlend Pipeline SC=[1,0,0,0,0,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,0,0,1] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (4 draws) PorterDuffBlend Pipeline SC=[1,0,0,0,1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,0,-1] never drawn with any options PorterDuffBlend Pipeline SC=[1,0,0,1,0,0] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (20 draws) PorterDuffBlend Pipeline SC=[1,0,1,0,0,0] drawn as: depth Always -> GreaterEqual, prim TriangleStrip -> Triangle, format B10G10R10A10XR -> B8G8R8A8UNormInt (86 draws) PorterDuffBlend Pipeline SC=[1,0,1,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,0,0,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,0,1,0] drawn as: depth Always -> GreaterEqual, prim TriangleStrip -> Triangle, format B10G10R10A10XR -> B8G8R8A8UNormInt (4 draws) PorterDuffBlend Pipeline SC=[1,1,-1,1,-1,0] never drawn with any options PorterDuffBlend Pipeline SC=[1,1,-1,1,0,0] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) PorterDuffBlend Pipeline SC=[1,1,0,0,0,0] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (8 draws) PorterDuffBlend Pipeline SC=[1,1,0,1,-1,0] drawn as: depth Always -> GreaterEqual, format B10G10R10A10XR -> B8G8R8A8UNormInt (6 draws) PorterDuffBlend Pipeline SC=[1,1,0,1,0,0] drawn as: depth Always -> GreaterEqual (4 draws) RrectBlur Pipeline drawn as: depth Always -> GreaterEqual (4 draws) RsuperellipseBlur Pipeline never drawn with any options SrgbToLinearFilter Pipeline never drawn with any options YuvToRgbFilter Pipeline never drawn with any options ``` Example output for --fail-on-unused-shaders: ``` ================================================================================ Unused Impeller shaders ================================================================================ 13 shaders were created by a ContentContext but never drawn with, with any options, on any backend: BorderMaskBlur Pipeline [Metal] ConicalGradientSsboFill Pipeline spec=[0] [Metal] PorterDuffBlend Pipeline spec=[1,0,0,0,0,0] [Metal] PorterDuffBlend Pipeline spec=[1,0,0,0,1,0] [Metal] PorterDuffBlend Pipeline spec=[1,0,0,1,-1,0] [Metal] PorterDuffBlend Pipeline spec=[1,0,0,1,0,-1] [Metal] PorterDuffBlend Pipeline spec=[1,0,1,1,-1,0] [Metal] PorterDuffBlend Pipeline spec=[1,1,-1,0,0,0] [Metal] PorterDuffBlend Pipeline spec=[1,1,-1,1,-1,0] [Metal] RsuperellipseBlur Pipeline [Metal] SrgbToLinearFilter Pipeline [Metal] VerticesUber2 Pipeline spec=[1] [Metal] YuvToRgbFilter Pipeline [Metal] Add a golden test that draws with each of them, or stop creating them. ``` ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord].
1 parent ea4ba77 commit 37f6113

13 files changed

Lines changed: 2264 additions & 2 deletions

‎engine/src/flutter/impeller/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impeller_component("impeller_unittests") {
9090
"fixtures",
9191
"geometry:geometry_unittests",
9292
"playground",
93+
"playground:pipeline_variant_recorder_unittests",
9394
"renderer:renderer_unittests",
9495
"typographer:typographer_unittests",
9596
]

‎engine/src/flutter/impeller/entity/BUILD.gn‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ impeller_component("entity") {
176176
"contents/gradient_generator.h",
177177
"contents/linear_gradient_contents.cc",
178178
"contents/linear_gradient_contents.h",
179+
"contents/pipeline_variant_recording.cc",
180+
"contents/pipeline_variant_recording.h",
179181
"contents/pipelines.h",
180182
"contents/radial_gradient_contents.cc",
181183
"contents/radial_gradient_contents.h",
@@ -292,6 +294,7 @@ impeller_component("entity_unittests") {
292294
"contents/filters/matrix_filter_contents_unittests.cc",
293295
"contents/filters/morphology_filter_contents_unittests.cc",
294296
"contents/host_buffer_unittests.cc",
297+
"contents/pipeline_variant_recording_unittests.cc",
295298
"contents/text_contents_unittests.cc",
296299
"contents/tiled_texture_contents_unittests.cc",
297300
"contents/uber_sdf_contents_unittests.cc",

‎engine/src/flutter/impeller/entity/contents/content_context.cc‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "impeller/core/formats.h"
1515
#include "impeller/core/texture_descriptor.h"
1616
#include "impeller/entity/contents/framebuffer_blend_contents.h"
17+
#include "impeller/entity/contents/pipeline_variant_recording.h"
1718
#include "impeller/entity/contents/pipelines.h"
1819
#include "impeller/entity/contents/text_shadow_cache.h"
1920
#include "impeller/entity/entity.h"
@@ -42,6 +43,7 @@ class GenericVariants {
4243
return;
4344
}
4445
}
46+
IMPELLER_RECORD_PIPELINE_VARIANT(options, pipeline.get());
4547
pipelines_.push_back(std::make_pair(p_key, std::move(pipeline)));
4648
}
4749

@@ -171,6 +173,8 @@ RenderPipelineHandleT* CreateIfNeeded(
171173
return found;
172174
}
173175

176+
IMPELLER_PIPELINE_VARIANT_LAZY_SCOPE(context);
177+
174178
RenderPipelineHandleT* default_handle =
175179
container.GetDefault(*context->GetContext());
176180
if (container.IsDefault(opts)) {
@@ -573,6 +577,8 @@ ContentContext::ContentContext(
573577
return;
574578
}
575579

580+
IMPELLER_PIPELINE_VARIANT_WARMING_SCOPE(this);
581+
576582
// On most backends, indexes and other data can be allocated into the same
577583
// buffers. However, some backends (namely WebGL) require indexes used in
578584
// indexed draws to be allocated separately from other data. For those
@@ -883,7 +889,9 @@ ContentContext::ContentContext(
883889
InitializeCommonlyUsedShadersIfNeeded();
884890
}
885891

886-
ContentContext::~ContentContext() = default;
892+
ContentContext::~ContentContext() {
893+
IMPELLER_REPORT_PIPELINE_VARIANTS(this, context_);
894+
}
887895

888896
bool ContentContext::IsValid() const {
889897
return is_valid_;
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "impeller/entity/contents/pipeline_variant_recording.h"
6+
7+
// Everything in this file is a test diagnostic that is compiled out of
8+
// everything but debug builds.
9+
#if IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
10+
11+
#include <atomic>
12+
#include <optional>
13+
#include <unordered_map>
14+
#include <utility>
15+
16+
#include "impeller/base/thread.h"
17+
#include "impeller/base/thread_safety.h"
18+
#include "impeller/renderer/pipeline.h"
19+
20+
namespace impeller {
21+
22+
namespace {
23+
24+
struct Registry {
25+
Mutex mutex;
26+
PipelineVariantObserver observer IPLR_GUARDED_BY(mutex);
27+
/// The variants recorded so far for every `ContentContext` that was created
28+
/// while an observer was set and has not been destroyed yet.
29+
std::unordered_map<const ContentContext*,
30+
std::vector<RecordedPipelineVariant>>
31+
variants IPLR_GUARDED_BY(mutex);
32+
};
33+
34+
Registry& GetRegistry() {
35+
static Registry* registry = new Registry();
36+
return *registry;
37+
}
38+
39+
/// The size of `Registry::variants`, so that recording and reporting can skip
40+
/// taking the lock when nothing is being recorded, which is almost always.
41+
std::atomic<size_t> gRegisteredCount = 0;
42+
43+
/// Set by the innermost `Scope` on this thread.
44+
thread_local const ContentContext* tContentContext = nullptr;
45+
thread_local bool tWarmed = false;
46+
47+
} // namespace
48+
49+
void SetPipelineVariantObserver(PipelineVariantObserver observer) {
50+
Registry& registry = GetRegistry();
51+
Lock lock(registry.mutex);
52+
registry.observer = std::move(observer);
53+
}
54+
55+
namespace pipeline_variant_recording {
56+
57+
const ContentContext* Register(const ContentContext* content_context) {
58+
Registry& registry = GetRegistry();
59+
Lock lock(registry.mutex);
60+
if (!registry.observer) {
61+
return nullptr;
62+
}
63+
// Replaces anything left behind at this address, although `Report` should
64+
// always have removed it.
65+
registry.variants[content_context].clear();
66+
gRegisteredCount = registry.variants.size();
67+
return content_context;
68+
}
69+
70+
void Record(const ContentContextOptions& options,
71+
const GenericRenderPipelineHandle* pipeline) {
72+
if (tContentContext == nullptr || pipeline == nullptr ||
73+
gRegisteredCount == 0u) {
74+
return;
75+
}
76+
std::optional<PipelineDescriptor> descriptor = pipeline->GetDescriptor();
77+
if (!descriptor.has_value()) {
78+
return;
79+
}
80+
Registry& registry = GetRegistry();
81+
Lock lock(registry.mutex);
82+
auto found = registry.variants.find(tContentContext);
83+
if (found == registry.variants.end()) {
84+
return;
85+
}
86+
found->second.push_back(RecordedPipelineVariant{
87+
.descriptor = descriptor.value(), .options = options, .warmed = tWarmed});
88+
}
89+
90+
void Report(const ContentContext* content_context,
91+
const std::shared_ptr<Context>& context) {
92+
if (gRegisteredCount == 0u) {
93+
return;
94+
}
95+
std::vector<RecordedPipelineVariant> variants;
96+
PipelineVariantObserver observer;
97+
{
98+
Registry& registry = GetRegistry();
99+
Lock lock(registry.mutex);
100+
auto found = registry.variants.find(content_context);
101+
if (found == registry.variants.end()) {
102+
return;
103+
}
104+
// Removed even if there is nothing to report, so that a `ContentContext`
105+
// later created at the same address starts from scratch.
106+
variants = std::move(found->second);
107+
registry.variants.erase(found);
108+
gRegisteredCount = registry.variants.size();
109+
observer = registry.observer;
110+
}
111+
// Called without the lock held so that the observer is free to do anything.
112+
if (observer && context && !variants.empty()) {
113+
observer(*context, variants);
114+
}
115+
}
116+
117+
Scope::Scope(const ContentContext* content_context, bool warmed)
118+
: previous_content_context_(tContentContext), previous_warmed_(tWarmed) {
119+
tContentContext = content_context;
120+
tWarmed = warmed;
121+
}
122+
123+
Scope::~Scope() {
124+
tContentContext = previous_content_context_;
125+
tWarmed = previous_warmed_;
126+
}
127+
128+
} // namespace pipeline_variant_recording
129+
130+
} // namespace impeller
131+
132+
#endif // IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_IMPELLER_ENTITY_CONTENTS_PIPELINE_VARIANT_RECORDING_H_
6+
#define FLUTTER_IMPELLER_ENTITY_CONTENTS_PIPELINE_VARIANT_RECORDING_H_
7+
8+
#include <functional>
9+
#include <memory>
10+
#include <vector>
11+
12+
#include "flutter/fml/logging.h"
13+
#include "impeller/entity/contents/content_context.h"
14+
#include "impeller/renderer/pipeline_descriptor.h"
15+
16+
//------------------------------------------------------------------------------
17+
/// Recording of the pipeline variants that each `ContentContext` creates, so
18+
/// that test diagnostics can tell which of them were never drawn with. See
19+
/// `SetPipelineVariantObserver`.
20+
///
21+
/// This is a test diagnostic, so it is compiled out of everything but debug
22+
/// builds. Outside of them every macro below expands to nothing, without
23+
/// evaluating its arguments, and the implementation file is empty.
24+
///
25+
/// `ContentContext` only interacts with this through the macros below.
26+
///
27+
28+
/// Whether pipeline variant recording is compiled into this build. Can be used
29+
/// both in `#if` directives and in expressions.
30+
#if defined(FLUTTER_RUNTIME_MODE) && \
31+
FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
32+
#define IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED() 1
33+
#else
34+
#define IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED() 0
35+
#endif
36+
37+
namespace impeller {
38+
39+
class Context;
40+
class GenericRenderPipelineHandle;
41+
42+
//------------------------------------------------------------------------------
43+
/// @brief A pipeline variant created by a `ContentContext`.
44+
///
45+
struct RecordedPipelineVariant {
46+
/// The descriptor the variant's pipeline was created with. This is what
47+
/// `PipelineLibrary::GetPipelineUseCounts` is keyed by.
48+
PipelineDescriptor descriptor;
49+
ContentContextOptions options;
50+
/// True if the variant was created ahead of time (warmed) by the
51+
/// `ContentContext` constructor, false if it was created lazily on first
52+
/// request.
53+
bool warmed = false;
54+
};
55+
56+
using PipelineVariantObserver =
57+
std::function<void(const Context& context,
58+
const std::vector<RecordedPipelineVariant>& variants)>;
59+
60+
//------------------------------------------------------------------------------
61+
/// @brief Sets a process-wide observer that each `ContentContext` calls
62+
/// from its destructor with every pipeline variant it created.
63+
/// Pass an empty function to remove it.
64+
///
65+
/// Only `ContentContext`s created while an observer is set record
66+
/// their variants. Intended for test diagnostics, see
67+
/// `PipelineVariantRecorder` and the `--shader-report` and
68+
/// `--fail-on-unused-shaders` flags of `impeller_golden_tests`.
69+
///
70+
/// Outside of debug builds (see
71+
/// `IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED`) this logs an
72+
/// error and the observer is never called.
73+
///
74+
#if IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
75+
void SetPipelineVariantObserver(PipelineVariantObserver observer);
76+
#else
77+
inline void SetPipelineVariantObserver(
78+
const PipelineVariantObserver& observer) {
79+
if (observer) {
80+
FML_LOG(ERROR) << "Pipeline variant recording is only available in debug "
81+
"builds. The observer will never be called.";
82+
}
83+
}
84+
#endif // IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
85+
86+
#if IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
87+
/// Implementation details of the macros below. Use the macros instead.
88+
namespace pipeline_variant_recording {
89+
90+
/// Starts recording the variants of `content_context` if an observer is set.
91+
///
92+
/// @return `content_context` if its variants are being recorded, nullptr
93+
/// otherwise.
94+
const ContentContext* Register(const ContentContext* content_context);
95+
96+
/// Records the variant `pipeline` was created for if it was created inside a
97+
/// `Scope` of a registered `ContentContext`.
98+
void Record(const ContentContextOptions& options,
99+
const GenericRenderPipelineHandle* pipeline);
100+
101+
/// Stops recording the variants of `content_context` and hands them to the
102+
/// observer.
103+
void Report(const ContentContext* content_context,
104+
const std::shared_ptr<Context>& context);
105+
106+
/// Attributes the variants created on this thread while it is alive to
107+
/// `content_context`. Scopes nest.
108+
class Scope {
109+
public:
110+
Scope(const ContentContext* content_context, bool warmed);
111+
112+
~Scope();
113+
114+
private:
115+
const ContentContext* previous_content_context_;
116+
bool previous_warmed_;
117+
118+
Scope(const Scope&) = delete;
119+
120+
Scope& operator=(const Scope&) = delete;
121+
};
122+
123+
} // namespace pipeline_variant_recording
124+
#endif // IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
125+
126+
} // namespace impeller
127+
128+
#if IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
129+
130+
/// For the `ContentContext` constructor: records the variants created for
131+
/// `content_context` until the end of the enclosing scope as warmed, and every
132+
/// variant created for it later on as lazily created. Does nothing unless an
133+
/// observer is set.
134+
#define IMPELLER_PIPELINE_VARIANT_WARMING_SCOPE(content_context) \
135+
::impeller::pipeline_variant_recording::Scope \
136+
impeller_pipeline_variant_warming_scope( \
137+
::impeller::pipeline_variant_recording::Register(content_context), \
138+
/*warmed=*/true)
139+
140+
/// For code that creates variants on demand: attributes the variants created
141+
/// until the end of the enclosing scope to `content_context`, as lazily
142+
/// created.
143+
#define IMPELLER_PIPELINE_VARIANT_LAZY_SCOPE(content_context) \
144+
::impeller::pipeline_variant_recording::Scope \
145+
impeller_pipeline_variant_lazy_scope(content_context, /*warmed=*/false)
146+
147+
/// For wherever a variant is added to its container: records the variant that
148+
/// `pipeline`, a `GenericRenderPipelineHandle*`, was created for with
149+
/// `options`.
150+
#define IMPELLER_RECORD_PIPELINE_VARIANT(options, pipeline) \
151+
::impeller::pipeline_variant_recording::Record(options, pipeline)
152+
153+
/// For the `ContentContext` destructor: hands every variant recorded for
154+
/// `content_context` to the observer, along with `context`, the
155+
/// `std::shared_ptr<Context>` it rendered with.
156+
#define IMPELLER_REPORT_PIPELINE_VARIANTS(content_context, context) \
157+
::impeller::pipeline_variant_recording::Report(content_context, context)
158+
159+
#else
160+
161+
#define IMPELLER_PIPELINE_VARIANT_WARMING_SCOPE(content_context)
162+
#define IMPELLER_PIPELINE_VARIANT_LAZY_SCOPE(content_context)
163+
#define IMPELLER_RECORD_PIPELINE_VARIANT(options, pipeline)
164+
#define IMPELLER_REPORT_PIPELINE_VARIANTS(content_context, context)
165+
166+
#endif // IMPELLER_PIPELINE_VARIANT_RECORDER_IS_SUPPORTED()
167+
168+
#endif // FLUTTER_IMPELLER_ENTITY_CONTENTS_PIPELINE_VARIANT_RECORDING_H_

0 commit comments

Comments
 (0)