From 57c3c6af5d836235edc03f2589156fe7296db846 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Fri, 1 Nov 2024 15:45:14 -0700 Subject: [PATCH] [Impeller] fix downsample with decal tile mode. (flutter/engine#56316) Fixes https://github.com/flutter/flutter/issues/157956 Fixes https://github.com/flutter/flutter/issues/157959 Decal tile mode needs to be emulated on platforms that don't support it. --- .../entity/contents/content_context.cc | 4 ++-- .../filters/gaussian_blur_filter_contents.cc | 3 +++ .../entity/shaders/texture_downsample.frag | 20 ++++++++++++++++--- engine/src/flutter/impeller/tools/malioc.json | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/impeller/entity/contents/content_context.cc b/engine/src/flutter/impeller/entity/contents/content_context.cc index 92c854f41d..4cb2ab6371 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.cc +++ b/engine/src/flutter/impeller/entity/contents/content_context.cc @@ -337,8 +337,8 @@ ContentContext::ContentContext( clip_pipelines_.SetDefault( options, std::make_unique(*context_, clip_pipeline_descriptor)); - texture_downsample_pipelines_.CreateDefault(*context_, - options_trianglestrip); + texture_downsample_pipelines_.CreateDefault( + *context_, options_trianglestrip, {supports_decal}); rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip); texture_strict_src_pipelines_.CreateDefault(*context_, options); tiled_texture_pipelines_.CreateDefault(*context_, options, diff --git a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc index e66c830ac7..17017b1f9e 100644 --- a/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/filters/gaussian_blur_filter_contents.cc @@ -9,6 +9,7 @@ #include "flutter/fml/make_copyable.h" #include "impeller/entity/contents/clip_contents.h" #include "impeller/entity/contents/content_context.h" +#include "impeller/entity/entity.h" #include "impeller/entity/texture_downsample.frag.h" #include "impeller/entity/texture_fill.frag.h" #include "impeller/entity/texture_fill.vert.h" @@ -406,6 +407,8 @@ fml::StatusOr MakeDownsampleSubpass( frag_info.edge = edge; frag_info.ratio = ratio; frag_info.pixel_size = Vector2(1.0f / Size(input_texture->GetSize())); + frag_info.use_decal = + (tile_mode == Entity::TileMode::kDecal) ? 1.0 : 0.0; const Quad& uvs = pass_args.uvs; std::array vertices = { diff --git a/engine/src/flutter/impeller/entity/shaders/texture_downsample.frag b/engine/src/flutter/impeller/entity/shaders/texture_downsample.frag index 8b512fe29a..487422f66b 100644 --- a/engine/src/flutter/impeller/entity/shaders/texture_downsample.frag +++ b/engine/src/flutter/impeller/entity/shaders/texture_downsample.frag @@ -7,11 +7,14 @@ precision mediump float; #include #include +layout(constant_id = 0) const float supports_decal = 1.0; + uniform f16sampler2D texture_sampler; uniform FragInfo { float edge; float ratio; + float use_decal; vec2 pixel_size; } frag_info; @@ -20,13 +23,24 @@ in highp vec2 v_texture_coords; out vec4 frag_color; +vec4 Sample(vec2 uv) { + if (supports_decal == 1.0) { + return texture(texture_sampler, uv, float16_t(kDefaultMipBias)); + } else { + if (frag_info.use_decal == 1.0 && + (uv.x < 0 || uv.y < 0 || uv.x > 1 || uv.y > 1)) { + return vec4(0); + } else { + return texture(texture_sampler, uv, float16_t(kDefaultMipBias)); + } + } +} + void main() { vec4 total = vec4(0.0); for (float i = -frag_info.edge; i <= frag_info.edge; i += 2) { for (float j = -frag_info.edge; j <= frag_info.edge; j += 2) { - total += (texture(texture_sampler, - v_texture_coords + frag_info.pixel_size * vec2(i, j), - float16_t(kDefaultMipBias)) * + total += (Sample(v_texture_coords + frag_info.pixel_size * vec2(i, j)) * frag_info.ratio); } } diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index 8dacf095ca..1204c35fa3 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -4845,7 +4845,7 @@ }, "thread_occupancy": 100, "uniform_registers_used": 1, - "work_registers_used": 4 + "work_registers_used": 3 } } }