Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] use spec constant for gaussian shader, rename, and reuse vertex sources. #52361

Merged
merged 4 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 8 additions & 18 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -40378,24 +40378,19 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/border_mask_blur.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/border_mask_blur.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/debug/checkerboard.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/debug/checkerboard.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/border_mask_blur.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/color_matrix_color_filter.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/filter.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/filter_position.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/filter_position_uv.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/gaussian.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/linear_to_srgb_filter.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/morphology_filter.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/morphology_filter.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/srgb_to_linear_filter.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/yuv_to_rgb_filter.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE
Expand Down Expand Up @@ -43260,24 +43255,19 @@ FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert
FILE: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.vert
FILE: ../../../flutter/impeller/entity/shaders/border_mask_blur.frag
FILE: ../../../flutter/impeller/entity/shaders/border_mask_blur.vert
FILE: ../../../flutter/impeller/entity/shaders/clip.frag
FILE: ../../../flutter/impeller/entity/shaders/clip.vert
FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.frag
FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.vert
FILE: ../../../flutter/impeller/entity/shaders/filters/border_mask_blur.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/color_matrix_color_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/filter.vert
FILE: ../../../flutter/impeller/entity/shaders/filters/filter_position.vert
FILE: ../../../flutter/impeller/entity/shaders/filters/filter_position_uv.vert
FILE: ../../../flutter/impeller/entity/shaders/filters/gaussian.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/linear_to_srgb_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/morphology_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/morphology_filter.vert
FILE: ../../../flutter/impeller/entity/shaders/filters/srgb_to_linear_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/filters/yuv_to_rgb_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.glsl
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel.vert
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_decal.frag
FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/kernel_nodecal.frag
FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert
Expand Down
12 changes: 4 additions & 8 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ impeller_shaders("entity_shaders") {
shaders = [
"shaders/blending/advanced_blend.vert",
"shaders/blending/advanced_blend.frag",
"shaders/border_mask_blur.frag",
"shaders/border_mask_blur.vert",
"shaders/clip.frag",
"shaders/clip.vert",
"shaders/gradients/conical_gradient_fill.frag",
"shaders/gaussian_blur/kernel_decal.frag",
"shaders/gaussian_blur/kernel_nodecal.frag",
"shaders/gaussian_blur/kernel.vert",
"shaders/glyph_atlas.frag",
"shaders/glyph_atlas_color.frag",
"shaders/glyph_atlas.vert",
Expand All @@ -46,15 +41,16 @@ impeller_shaders("entity_shaders") {
"shaders/vertices.frag",
"shaders/blending/porter_duff_blend.frag",
"shaders/blending/porter_duff_blend.vert",
"shaders/filters/border_mask_blur.frag",
"shaders/filters/color_matrix_color_filter.frag",
"shaders/filters/filter.vert",
"shaders/filters/filter_position.vert",
"shaders/filters/filter_position_uv.vert",
"shaders/filters/gaussian.frag",
"shaders/filters/yuv_to_rgb_filter.frag",
"shaders/filters/srgb_to_linear_filter.frag",
"shaders/filters/linear_to_srgb_filter.frag",
"shaders/filters/morphology_filter.frag",
"shaders/filters/morphology_filter.vert",
"shaders/blending/vertices_uber.frag",
"shaders/blending/vertices_uber.vert",
]

if (impeller_debug) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ ContentContext::ContentContext(
rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
texture_strict_src_pipelines_.CreateDefault(*context_, options);
tiled_texture_pipelines_.CreateDefault(*context_, options, {supports_decal});
kernel_decal_pipelines_.CreateDefault(*context_, options_trianglestrip);
kernel_nodecal_pipelines_.CreateDefault(*context_, options_trianglestrip);
gaussian_blur_pipelines_.CreateDefault(*context_, options_trianglestrip,
{supports_decal});
border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip,
{supports_decal});
Expand Down
54 changes: 22 additions & 32 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@
#endif // IMPELLER_DEBUG

#include "impeller/entity/border_mask_blur.frag.h"
#include "impeller/entity/border_mask_blur.vert.h"
#include "impeller/entity/clip.frag.h"
#include "impeller/entity/clip.vert.h"
#include "impeller/entity/color_matrix_color_filter.frag.h"
#include "impeller/entity/conical_gradient_fill.frag.h"
#include "impeller/entity/filter.vert.h"
#include "impeller/entity/filter_position.vert.h"
#include "impeller/entity/filter_position_uv.vert.h"
#include "impeller/entity/gaussian.frag.h"
#include "impeller/entity/glyph_atlas.frag.h"
#include "impeller/entity/glyph_atlas.vert.h"
#include "impeller/entity/glyph_atlas_color.frag.h"
#include "impeller/entity/gradient_fill.vert.h"
#include "impeller/entity/linear_gradient_fill.frag.h"
#include "impeller/entity/linear_to_srgb_filter.frag.h"
#include "impeller/entity/morphology_filter.frag.h"
#include "impeller/entity/morphology_filter.vert.h"
#include "impeller/entity/points.comp.h"
#include "impeller/entity/porter_duff_blend.frag.h"
#include "impeller/entity/porter_duff_blend.vert.h"
#include "impeller/entity/position_color.vert.h"
#include "impeller/entity/radial_gradient_fill.frag.h"
#include "impeller/entity/rrect_blur.frag.h"
#include "impeller/entity/rrect_blur.vert.h"
Expand All @@ -62,12 +63,6 @@
#include "impeller/entity/vertices.frag.h"
#include "impeller/entity/yuv_to_rgb_filter.frag.h"

#include "impeller/entity/kernel.vert.h"
#include "impeller/entity/kernel_decal.frag.h"
#include "impeller/entity/kernel_nodecal.frag.h"

#include "impeller/entity/position_color.vert.h"

#include "impeller/typographer/glyph_atlas.h"

#include "impeller/entity/conical_gradient_ssbo_fill.frag.h"
Expand All @@ -82,7 +77,6 @@
#include "impeller/entity/framebuffer_blend.vert.h"

#include "impeller/entity/vertices_uber.frag.h"
#include "impeller/entity/vertices_uber.vert.h"

#ifdef IMPELLER_ENABLE_OPENGLES
#include "impeller/entity/tiled_texture_fill_external.frag.h"
Expand Down Expand Up @@ -135,23 +129,27 @@ using TextureStrictSrcPipeline =
using TiledTexturePipeline =
RenderPipelineHandle<TextureUvFillVertexShader,
TiledTextureFillFragmentShader>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes here is the gaussian, morph, and border mask filters all have identical vertex stages so they can share them now.

Likewise, vertices_uber and porter duff have identical vertex stages.

Also we don't need two gaussians, only ever need one.

using KernelDecalPipeline =
RenderPipelineHandle<KernelVertexShader, KernelDecalFragmentShader>;
using KernelPipeline =
RenderPipelineHandle<KernelVertexShader, KernelNodecalFragmentShader>;
using GaussianBlurPipeline =
RenderPipelineHandle<FilterPositionUvVertexShader, GaussianFragmentShader>;
using BorderMaskBlurPipeline =
RenderPipelineHandle<BorderMaskBlurVertexShader,
RenderPipelineHandle<FilterPositionUvVertexShader,
BorderMaskBlurFragmentShader>;
using MorphologyFilterPipeline =
RenderPipelineHandle<MorphologyFilterVertexShader,
RenderPipelineHandle<FilterPositionUvVertexShader,
MorphologyFilterFragmentShader>;
using ColorMatrixColorFilterPipeline =
RenderPipelineHandle<FilterVertexShader,
RenderPipelineHandle<FilterPositionVertexShader,
ColorMatrixColorFilterFragmentShader>;
using LinearToSrgbFilterPipeline =
RenderPipelineHandle<FilterVertexShader, LinearToSrgbFilterFragmentShader>;
RenderPipelineHandle<FilterPositionVertexShader,
LinearToSrgbFilterFragmentShader>;
using SrgbToLinearFilterPipeline =
RenderPipelineHandle<FilterVertexShader, SrgbToLinearFilterFragmentShader>;
RenderPipelineHandle<FilterPositionVertexShader,
SrgbToLinearFilterFragmentShader>;
using YUVToRGBFilterPipeline =
RenderPipelineHandle<FilterPositionVertexShader,
YuvToRgbFilterFragmentShader>;

using GlyphAtlasPipeline =
RenderPipelineHandle<GlyphAtlasVertexShader, GlyphAtlasFragmentShader>;
using GlyphAtlasColorPipeline =
Expand All @@ -163,8 +161,6 @@ using ClipPipeline = RenderPipelineHandle<ClipVertexShader, ClipFragmentShader>;

using GeometryColorPipeline =
RenderPipelineHandle<PositionColorVertexShader, VerticesFragmentShader>;
using YUVToRGBFilterPipeline =
RenderPipelineHandle<FilterVertexShader, YuvToRgbFilterFragmentShader>;

// Advanced blends
using BlendColorPipeline = RenderPipelineHandle<AdvancedBlendVertexShader,
Expand Down Expand Up @@ -253,8 +249,8 @@ using FramebufferBlendSoftLightPipeline =
FramebufferBlendFragmentShader>;

/// Draw Vertices/Atlas Uber Shader
using VerticesUberShader =
RenderPipelineHandle<VerticesUberVertexShader, VerticesUberFragmentShader>;
using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader,
VerticesUberFragmentShader>;

/// Geometry Pipelines
using PointsComputeShaderPipeline = ComputePipelineBuilder<PointsComputeShader>;
Expand Down Expand Up @@ -481,14 +477,9 @@ class ContentContext {
return GetPipeline(tiled_texture_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetKernelDecalPipeline(
ContentContextOptions opts) const {
return GetPipeline(kernel_decal_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetKernelPipeline(
std::shared_ptr<Pipeline<PipelineDescriptor>> GetGaussianBlurPipeline(
ContentContextOptions opts) const {
return GetPipeline(kernel_nodecal_pipelines_, opts);
return GetPipeline(gaussian_blur_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetBorderMaskBlurPipeline(
Expand Down Expand Up @@ -925,8 +916,7 @@ class ContentContext {
tiled_texture_external_pipelines_;
#endif // IMPELLER_ENABLE_OPENGLES
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
mutable Variants<KernelDecalPipeline> kernel_decal_pipelines_;
mutable Variants<KernelPipeline> kernel_nodecal_pipelines_;
mutable Variants<GaussianBlurPipeline> gaussian_blur_pipelines_;
mutable Variants<BorderMaskBlurPipeline> border_mask_blur_pipelines_;
mutable Variants<MorphologyFilterPipeline> morphology_filter_pipelines_;
mutable Variants<ColorMatrixColorFilterPipeline>
Expand Down
39 changes: 15 additions & 24 deletions impeller/entity/contents/filters/gaussian_blur_filter_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,22 @@

#include "flutter/fml/make_copyable.h"
#include "impeller/entity/contents/clip_contents.h"
#include "impeller/entity/contents/color_source_contents.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/texture_fill.frag.h"
#include "impeller/entity/texture_fill.vert.h"
#include "impeller/renderer/command.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/texture_mipmap.h"
#include "impeller/renderer/vertex_buffer_builder.h"

namespace impeller {

using GaussianBlurVertexShader = KernelPipeline::VertexShader;
using GaussianBlurFragmentShader = KernelPipeline::FragmentShader;
using GaussianBlurVertexShader = GaussianBlurPipeline::VertexShader;
using GaussianBlurFragmentShader = GaussianBlurPipeline::FragmentShader;

const int32_t GaussianBlurFilterContents::kBlurFilterRequiredMipCount = 4;

namespace {

// 48 comes from kernel.glsl.
// 48 comes from gaussian.frag.
const int32_t kMaxKernelSize = 48;

SamplerDescriptor MakeSamplerDescriptor(MinMagFilter filter,
Expand Down Expand Up @@ -155,14 +152,7 @@ fml::StatusOr<RenderTarget> MakeBlurSubpass(

ContentContextOptions options = OptionsFromPass(pass);
options.primitive_type = PrimitiveType::kTriangleStrip;

if (tile_mode == Entity::TileMode::kDecal &&
!renderer.GetDeviceCapabilities()
.SupportsDecalSamplerAddressMode()) {
pass.SetPipeline(renderer.GetKernelDecalPipeline(options));
} else {
pass.SetPipeline(renderer.GetKernelPipeline(options));
}
pass.SetPipeline(renderer.GetGaussianBlurPipeline(options));

BindVertices<GaussianBlurVertexShader>(pass, host_buffer,
{
Expand All @@ -181,7 +171,7 @@ fml::StatusOr<RenderTarget> MakeBlurSubpass(
linear_sampler_descriptor));
GaussianBlurVertexShader::BindFrameInfo(
pass, host_buffer.EmplaceUniform(frame_info));
KernelPipeline::FragmentShader::KernelSamples kernel_samples =
GaussianBlurPipeline::FragmentShader::KernelSamples kernel_samples =
LerpHackKernelSamples(GenerateBlurInfo(blur_info));
FML_CHECK(kernel_samples.sample_count < kMaxKernelSize);
GaussianBlurFragmentShader::BindKernelSamples(
Expand Down Expand Up @@ -600,9 +590,9 @@ Scalar GaussianBlurFilterContents::ScaleSigma(Scalar sigma) {
return clamped * scalar;
}

KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
BlurParameters parameters) {
KernelPipeline::FragmentShader::KernelSamples result;
GaussianBlurPipeline::FragmentShader::KernelSamples result;
result.sample_count =
((2 * parameters.blur_radius) / parameters.step_size) + 1;

Expand All @@ -617,7 +607,7 @@ KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
Scalar tally = 0.0f;
for (int i = 0; i < result.sample_count; ++i) {
int x = x_offset + (i * parameters.step_size) - parameters.blur_radius;
result.samples[i] = KernelPipeline::FragmentShader::KernelSample{
result.samples[i] = GaussianBlurPipeline::FragmentShader::KernelSample{
.uv_offset = parameters.blur_uv_offset * x,
.coefficient = expf(-0.5f * (x * x) /
(parameters.blur_sigma * parameters.blur_sigma)) /
Expand All @@ -636,20 +626,21 @@ KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(

// This works by shrinking the kernel size by 2 and relying on lerp to read
// between the samples.
KernelPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(
KernelPipeline::FragmentShader::KernelSamples parameters) {
KernelPipeline::FragmentShader::KernelSamples result;
GaussianBlurPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(
GaussianBlurPipeline::FragmentShader::KernelSamples parameters) {
GaussianBlurPipeline::FragmentShader::KernelSamples result;
result.sample_count = ((parameters.sample_count - 1) / 2) + 1;
int32_t middle = result.sample_count / 2;
int32_t j = 0;
for (int i = 0; i < result.sample_count; i++) {
if (i == middle) {
result.samples[i] = parameters.samples[j++];
} else {
KernelPipeline::FragmentShader::KernelSample left = parameters.samples[j];
KernelPipeline::FragmentShader::KernelSample right =
GaussianBlurPipeline::FragmentShader::KernelSample left =
parameters.samples[j];
GaussianBlurPipeline::FragmentShader::KernelSample right =
parameters.samples[j + 1];
result.samples[i] = KernelPipeline::FragmentShader::KernelSample{
result.samples[i] = GaussianBlurPipeline::FragmentShader::KernelSample{
.uv_offset = (left.uv_offset * left.coefficient +
right.uv_offset * right.coefficient) /
(left.coefficient + right.coefficient),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ struct BlurParameters {
int step_size;
};

KernelPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
GaussianBlurPipeline::FragmentShader::KernelSamples GenerateBlurInfo(
BlurParameters parameters);

/// This will shrink the size of a kernel by roughly half by sampling between
/// samples and relying on linear interpolation between the samples.
KernelPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(
KernelPipeline::FragmentShader::KernelSamples samples);
GaussianBlurPipeline::FragmentShader::KernelSamples LerpHackKernelSamples(
GaussianBlurPipeline::FragmentShader::KernelSamples samples);

/// Performs a bidirectional Gaussian blur.
///
Expand Down
Loading