From 34fd11cf54bb6f643c31c2943557104fcf23a141 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Thu, 2 Nov 2023 13:17:49 -0700 Subject: [PATCH] [Impeller] one blur shader. --- ci/licenses_golden/licenses_flutter | 8 ++------ impeller/entity/BUILD.gn | 3 +-- impeller/entity/contents/content_context.cc | 8 ++++---- impeller/entity/contents/content_context.h | 9 +++------ impeller/entity/entity_unittests.cc | 13 +++++++++++++ .../{gaussian_blur.glsl => gaussian_blur.frag} | 9 +++++---- .../gaussian_blur/gaussian_blur_noalpha_decal.frag | 9 --------- .../gaussian_blur_noalpha_nodecal.frag | 9 --------- 8 files changed, 28 insertions(+), 40 deletions(-) rename impeller/entity/shaders/gaussian_blur/{gaussian_blur.glsl => gaussian_blur.frag} (94%) delete mode 100644 impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag delete mode 100644 impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 87d04a2a82b0d..a5338d8ac80e9 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -3153,10 +3153,8 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/conical_gradient_fill.frag + .. ORIGIN: ../../../flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag + ../../../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/gaussian_blur/gaussian_blur.glsl + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.vert + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/points.comp + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/geometry/uv.comp + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE @@ -5907,10 +5905,8 @@ FILE: ../../../flutter/impeller/entity/shaders/conical_gradient_fill.frag FILE: ../../../flutter/impeller/entity/shaders/conical_gradient_ssbo_fill.frag FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.frag FILE: ../../../flutter/impeller/entity/shaders/debug/checkerboard.vert -FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl +FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.frag FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur.vert -FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag -FILE: ../../../flutter/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag FILE: ../../../flutter/impeller/entity/shaders/geometry/points.comp FILE: ../../../flutter/impeller/entity/shaders/geometry/uv.comp FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag diff --git a/impeller/entity/BUILD.gn b/impeller/entity/BUILD.gn index 4e1ce88280d4a..1aeb0ddda6eb0 100644 --- a/impeller/entity/BUILD.gn +++ b/impeller/entity/BUILD.gn @@ -26,8 +26,7 @@ impeller_shaders("entity_shaders") { "shaders/color_matrix_color_filter.vert", "shaders/conical_gradient_fill.frag", "shaders/gaussian_blur/gaussian_blur.vert", - "shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag", - "shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag", + "shaders/gaussian_blur/gaussian_blur.frag", "shaders/glyph_atlas.frag", "shaders/glyph_atlas_color.frag", "shaders/glyph_atlas.vert", diff --git a/impeller/entity/contents/content_context.cc b/impeller/entity/contents/content_context.cc index ec4725795eb31..e8e947d7916fd 100644 --- a/impeller/entity/contents/content_context.cc +++ b/impeller/entity/contents/content_context.cc @@ -317,10 +317,10 @@ ContentContext::ContentContext( texture_pipelines_.CreateDefault(*context_, options); position_uv_pipelines_.CreateDefault(*context_, options); tiled_texture_pipelines_.CreateDefault(*context_, options); - gaussian_blur_noalpha_decal_pipelines_.CreateDefault(*context_, - options_trianglestrip); - gaussian_blur_noalpha_nodecal_pipelines_.CreateDefault(*context_, - options_trianglestrip); + gaussian_blur_noalpha_decal_pipelines_.CreateDefault( + *context_, options_trianglestrip, {/*decal_specialization=*/1}); + gaussian_blur_noalpha_nodecal_pipelines_.CreateDefault( + *context_, options_trianglestrip, {/*decal_specialization=*/0}); border_mask_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); morphology_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); color_matrix_color_filter_pipelines_.CreateDefault(*context_, diff --git a/impeller/entity/contents/content_context.h b/impeller/entity/contents/content_context.h index 7fdcc6cbc74e8..5931abc1abd5c 100644 --- a/impeller/entity/contents/content_context.h +++ b/impeller/entity/contents/content_context.h @@ -63,9 +63,8 @@ #include "impeller/entity/yuv_to_rgb_filter.frag.h" #include "impeller/entity/yuv_to_rgb_filter.vert.h" +#include "impeller/entity/gaussian_blur.frag.h" #include "impeller/entity/gaussian_blur.vert.h" -#include "impeller/entity/gaussian_blur_noalpha_decal.frag.h" -#include "impeller/entity/gaussian_blur_noalpha_nodecal.frag.h" #include "impeller/entity/position_color.vert.h" @@ -130,11 +129,9 @@ using PositionUVPipeline = using TiledTexturePipeline = RenderPipelineT; using GaussianBlurDecalPipeline = - RenderPipelineT; + RenderPipelineT; using GaussianBlurPipeline = - RenderPipelineT; + RenderPipelineT; using BorderMaskBlurPipeline = RenderPipelineT; using MorphologyFilterPipeline = diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 1eb9cf149ad77..ca1604ab3d6f7 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -2556,6 +2556,19 @@ TEST_P(EntityTest, SpecializationConstantsAreAppliedToVariants) { expected_constants); } +TEST_P(EntityTest, BlurSpecializationConstantValuesAreExpected) { + auto content_context = + ContentContext(GetContext(), TypographerContextSkia::Make()); + + auto decal_pipeline = content_context.GetGaussianBlurDecalPipeline({}); + auto nodecal_pipeline = content_context.GetGaussianBlurPipeline({}); + + ASSERT_EQ(decal_pipeline->GetDescriptor().GetSpecializationConstants()[0], + /*decal_specialization*/ 1); + ASSERT_EQ(nodecal_pipeline->GetDescriptor().GetSpecializationConstants()[0], + /*decal_specialization*/ 0); +} + } // namespace testing } // namespace impeller diff --git a/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl b/impeller/entity/shaders/gaussian_blur/gaussian_blur.frag similarity index 94% rename from impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl rename to impeller/entity/shaders/gaussian_blur/gaussian_blur.frag index a40797aec125d..5e19d71fbf86e 100644 --- a/impeller/entity/shaders/gaussian_blur/gaussian_blur.glsl +++ b/impeller/entity/shaders/gaussian_blur/gaussian_blur.frag @@ -18,6 +18,8 @@ #include #include +layout(constant_id = 0) const int decal_specialization = 0; + uniform f16sampler2D texture_sampler; uniform BlurInfo { @@ -33,11 +35,10 @@ uniform BlurInfo { blur_info; f16vec4 Sample(f16sampler2D tex, vec2 coords) { -#if ENABLE_DECAL_SPECIALIZATION - return IPHalfSampleDecal(tex, coords); -#else + if (decal_specialization == 1) { + return IPHalfSampleDecal(tex, coords); + } return texture(tex, coords); -#endif } in vec2 v_texture_coords; diff --git a/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag b/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag deleted file mode 100644 index 7bb1045e19dbc..0000000000000 --- a/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_decal.frag +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -precision mediump float; - -#define ENABLE_DECAL_SPECIALIZATION 1 - -#include "gaussian_blur.glsl" diff --git a/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag b/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag deleted file mode 100644 index 79d708e1dae36..0000000000000 --- a/impeller/entity/shaders/gaussian_blur/gaussian_blur_noalpha_nodecal.frag +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -precision mediump float; - -#define ENABLE_DECAL_SPECIALIZATION 0 - -#include "gaussian_blur.glsl"