From b14463a57b1c1410f5556807fd376823330f1be9 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 25 Apr 2024 13:18:13 -0700 Subject: [PATCH] [Impeller] combine text shaders. (flutter/engine#52392) Combine both text shaders into one. One more down! https://github.com/flutter/flutter/issues/143540 --- .../ci/licenses_golden/licenses_flutter | 2 - engine/src/flutter/impeller/entity/BUILD.gn | 1 - .../entity/contents/content_context.cc | 1 - .../entity/contents/content_context.h | 10 +- .../impeller/entity/contents/text_contents.cc | 27 +- .../impeller/entity/shaders/glyph_atlas.frag | 24 +- .../impeller/entity/shaders/glyph_atlas.vert | 4 - .../entity/shaders/glyph_atlas_color.frag | 29 -- engine/src/flutter/impeller/tools/malioc.json | 290 ++++-------------- 9 files changed, 85 insertions(+), 303 deletions(-) delete mode 100644 engine/src/flutter/impeller/entity/shaders/glyph_atlas_color.frag diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index 614641afcc..45ac54a3bb 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -40491,7 +40491,6 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/filters/srgb_to_linear_filter.f ORIGIN: ../../../flutter/impeller/entity/shaders/filters/yuv_to_rgb_filter.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert + ../../../flutter/LICENSE -ORIGIN: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/gradients/conical_gradient_fill.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/gradients/conical_gradient_ssbo_fill.frag + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/entity/shaders/gradients/gradient_fill.vert + ../../../flutter/LICENSE @@ -43367,7 +43366,6 @@ FILE: ../../../flutter/impeller/entity/shaders/filters/srgb_to_linear_filter.fra FILE: ../../../flutter/impeller/entity/shaders/filters/yuv_to_rgb_filter.frag FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.frag FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas.vert -FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_color.frag FILE: ../../../flutter/impeller/entity/shaders/gradients/conical_gradient_fill.frag FILE: ../../../flutter/impeller/entity/shaders/gradients/conical_gradient_ssbo_fill.frag FILE: ../../../flutter/impeller/entity/shaders/gradients/gradient_fill.vert diff --git a/engine/src/flutter/impeller/entity/BUILD.gn b/engine/src/flutter/impeller/entity/BUILD.gn index c4c52d244c..2038888652 100644 --- a/engine/src/flutter/impeller/entity/BUILD.gn +++ b/engine/src/flutter/impeller/entity/BUILD.gn @@ -20,7 +20,6 @@ impeller_shaders("entity_shaders") { "shaders/clip.vert", "shaders/gradients/conical_gradient_fill.frag", "shaders/glyph_atlas.frag", - "shaders/glyph_atlas_color.frag", "shaders/glyph_atlas.vert", "shaders/gradients/gradient_fill.vert", "shaders/gradients/linear_gradient_fill.frag", diff --git a/engine/src/flutter/impeller/entity/contents/content_context.cc b/engine/src/flutter/impeller/entity/contents/content_context.cc index 7d0e6d9040..31d9d6c6b6 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.cc +++ b/engine/src/flutter/impeller/entity/contents/content_context.cc @@ -438,7 +438,6 @@ ContentContext::ContentContext( {static_cast( GetContext()->GetCapabilities()->GetDefaultGlyphAtlasFormat() == PixelFormat::kA8UNormInt)}); - glyph_atlas_color_pipelines_.CreateDefault(*context_, options); yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip); porter_duff_blend_pipelines_.CreateDefault(*context_, options_trianglestrip, {supports_decal}); diff --git a/engine/src/flutter/impeller/entity/contents/content_context.h b/engine/src/flutter/impeller/entity/contents/content_context.h index a21e110c51..9face9f8d1 100644 --- a/engine/src/flutter/impeller/entity/contents/content_context.h +++ b/engine/src/flutter/impeller/entity/contents/content_context.h @@ -39,7 +39,6 @@ #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" @@ -149,8 +148,7 @@ using YUVToRGBFilterPipeline = using GlyphAtlasPipeline = RenderPipelineHandle; -using GlyphAtlasColorPipeline = - RenderPipelineHandle; + using PorterDuffBlendPipeline = RenderPipelineHandle; @@ -516,11 +514,6 @@ class ContentContext { return GetPipeline(glyph_atlas_pipelines_, opts); } - std::shared_ptr> GetGlyphAtlasColorPipeline( - ContentContextOptions opts) const { - return GetPipeline(glyph_atlas_color_pipelines_, opts); - } - std::shared_ptr> GetYUVToRGBFilterPipeline( ContentContextOptions opts) const { return GetPipeline(yuv_to_rgb_filter_pipelines_, opts); @@ -917,7 +910,6 @@ class ContentContext { mutable Variants srgb_to_linear_filter_pipelines_; mutable Variants clip_pipelines_; mutable Variants glyph_atlas_pipelines_; - mutable Variants glyph_atlas_color_pipelines_; mutable Variants yuv_to_rgb_filter_pipelines_; mutable Variants porter_duff_blend_pipelines_; // Advanced blends. diff --git a/engine/src/flutter/impeller/entity/contents/text_contents.cc b/engine/src/flutter/impeller/entity/contents/text_contents.cc index 3bcb882e2c..96cbfd7935 100644 --- a/engine/src/flutter/impeller/entity/contents/text_contents.cc +++ b/engine/src/flutter/impeller/entity/contents/text_contents.cc @@ -8,6 +8,7 @@ #include #include +#include "impeller/core/buffer_view.h" #include "impeller/core/formats.h" #include "impeller/core/sampler_descriptor.h" #include "impeller/entity/contents/content_context.h" @@ -83,11 +84,7 @@ bool TextContents::Render(const ContentContext& renderer, pass.SetCommandLabel("TextFrame"); auto opts = OptionsFromPassAndEntity(pass, entity); opts.primitive_type = PrimitiveType::kTriangle; - if (type == GlyphAtlas::Type::kAlphaBitmap) { - pass.SetPipeline(renderer.GetGlyphAtlasPipeline(opts)); - } else { - pass.SetPipeline(renderer.GetGlyphAtlasColorPipeline(opts)); - } + pass.SetPipeline(renderer.GetGlyphAtlasPipeline(opts)); using VS = GlyphAtlasPipeline::VertexShader; using FS = GlyphAtlasPipeline::FragmentShader; @@ -103,18 +100,17 @@ bool TextContents::Render(const ContentContext& renderer, frame_info.is_translation_scale = entity.GetTransform().IsTranslationScaleOnly(); frame_info.entity_transform = entity.GetTransform(); - frame_info.text_color = ToVector(color.Premultiply()); VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(frame_info)); - if (type == GlyphAtlas::Type::kColorBitmap) { - using FSS = GlyphAtlasColorPipeline::FragmentShader; - FSS::FragInfo frag_info; - frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0; - FSS::BindFragInfo(pass, - renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); - } + FS::FragInfo frag_info; + frag_info.use_text_color = force_text_color_ ? 1.0 : 0.0; + frag_info.text_color = ToVector(color.Premultiply()); + frag_info.is_color_glyph = type == GlyphAtlas::Type::kColorBitmap; + + FS::BindFragInfo(pass, + renderer.GetTransientsBuffer().EmplaceUniform(frag_info)); SamplerDescriptor sampler_desc; if (frame_info.is_translation_scale) { @@ -156,12 +152,13 @@ bool TextContents::Render(const ContentContext& renderer, } vertex_count *= 6; - auto buffer_view = host_buffer.Emplace( + BufferView buffer_view = host_buffer.Emplace( vertex_count * sizeof(VS::PerVertexData), alignof(VS::PerVertexData), [&](uint8_t* contents) { VS::PerVertexData vtx; VS::PerVertexData* vtx_contents = reinterpret_cast(contents); + size_t offset = 0u; for (const TextRun& run : frame_->GetRuns()) { const Font& font = run.GetFont(); Scalar rounded_scale = TextFrame::RoundScaledFontSize( @@ -188,7 +185,7 @@ bool TextContents::Render(const ContentContext& renderer, for (const Point& point : unit_points) { vtx.unit_position = point; - std::memcpy(vtx_contents++, &vtx, sizeof(VS::PerVertexData)); + vtx_contents[offset++] = vtx; } } } diff --git a/engine/src/flutter/impeller/entity/shaders/glyph_atlas.frag b/engine/src/flutter/impeller/entity/shaders/glyph_atlas.frag index 8db425d0e9..6d985c7889 100644 --- a/engine/src/flutter/impeller/entity/shaders/glyph_atlas.frag +++ b/engine/src/flutter/impeller/entity/shaders/glyph_atlas.frag @@ -10,17 +10,31 @@ uniform f16sampler2D glyph_atlas_sampler; layout(constant_id = 0) const float use_alpha_color_channel = 1.0; -in highp vec2 v_uv; +uniform FragInfo { + float is_color_glyph; + float use_text_color; + f16vec4 text_color; +} +frag_info; -IMPELLER_MAYBE_FLAT in f16vec4 v_text_color; +in highp vec2 v_uv; out f16vec4 frag_color; void main() { f16vec4 value = texture(glyph_atlas_sampler, v_uv); - if (use_alpha_color_channel == 1.0) { - frag_color = value.aaaa * v_text_color; + + if (frag_info.is_color_glyph == 1.0) { + if (frag_info.use_text_color == 1.0) { + frag_color = value.aaaa * frag_info.text_color; + } else { + frag_color = value * frag_info.text_color.aaaa; + } } else { - frag_color = value.rrrr * v_text_color; + if (use_alpha_color_channel == 1.0) { + frag_color = value.aaaa * frag_info.text_color; + } else { + frag_color = value.rrrr * frag_info.text_color; + } } } diff --git a/engine/src/flutter/impeller/entity/shaders/glyph_atlas.vert b/engine/src/flutter/impeller/entity/shaders/glyph_atlas.vert index ae4ff68844..e2a7e04e26 100644 --- a/engine/src/flutter/impeller/entity/shaders/glyph_atlas.vert +++ b/engine/src/flutter/impeller/entity/shaders/glyph_atlas.vert @@ -10,7 +10,6 @@ uniform FrameInfo { mat4 entity_transform; vec2 atlas_size; vec2 offset; - f16vec4 text_color; float is_translation_scale; } frame_info; @@ -25,8 +24,6 @@ in vec2 glyph_position; out vec2 v_uv; -IMPELLER_MAYBE_FLAT out mediump f16vec4 v_text_color; - mat4 basis(mat4 m) { return mat4(m[0][0], m[0][1], m[0][2], 0.0, // m[1][0], m[1][1], m[1][2], 0.0, // @@ -81,5 +78,4 @@ void main() { gl_Position = frame_info.mvp * position; v_uv = uv_origin + unit_position * uv_size; - v_text_color = frame_info.text_color; } diff --git a/engine/src/flutter/impeller/entity/shaders/glyph_atlas_color.frag b/engine/src/flutter/impeller/entity/shaders/glyph_atlas_color.frag deleted file mode 100644 index 5b8ecc2520..0000000000 --- a/engine/src/flutter/impeller/entity/shaders/glyph_atlas_color.frag +++ /dev/null @@ -1,29 +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; - -#include - -uniform f16sampler2D glyph_atlas_sampler; - -uniform FragInfo { - float use_text_color; -} -frag_info; - -in highp vec2 v_uv; - -IMPELLER_MAYBE_FLAT in f16vec4 v_text_color; - -out f16vec4 frag_color; - -void main() { - f16vec4 value = texture(glyph_atlas_sampler, v_uv); - if (frag_info.use_text_color == 1.0f) { - frag_color = value.aaaa * v_text_color; - } else { - frag_color = value * v_text_color.aaaa; - } -} diff --git a/engine/src/flutter/impeller/tools/malioc.json b/engine/src/flutter/impeller/tools/malioc.json index abff6dc3ba..b3deba04be 100644 --- a/engine/src/flutter/impeller/tools/malioc.json +++ b/engine/src/flutter/impeller/tools/malioc.json @@ -2554,7 +2554,7 @@ "core": "Mali-G78", "filename": "flutter/impeller/entity/gles/glyph_atlas.frag.gles", "has_side_effects": false, - "has_uniform_computation": false, + "has_uniform_computation": true, "modifies_coverage": false, "reads_color_buffer": false, "type": "Fragment", @@ -2566,15 +2566,16 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "varying" + "varying", + "texture" ], "longest_path_cycles": [ + 0.109375, 0.03125, - 0.03125, - 0.03125, + 0.109375, 0.0, 0.0, - 0.5, + 0.25, 0.25 ], "pipelines": [ @@ -2587,33 +2588,35 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "varying", + "texture" ], "shortest_path_cycles": [ + 0.0625, 0.03125, - 0.03125, + 0.0625, 0.0, 0.0, - 0.0, - 0.5, + 0.25, 0.25 ], "total_bound_pipelines": [ - "varying" + "varying", + "texture" ], "total_cycles": [ - 0.03125, - 0.03125, - 0.03125, + 0.125, + 0.0625, + 0.125, 0.0, 0.0, - 0.5, + 0.25, 0.25 ] }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 4, + "uniform_registers_used": 6, "work_registers_used": 19 } } @@ -2653,17 +2656,16 @@ 1.0 ], "total_bound_pipelines": [ - "load_store", - "texture" + "arithmetic" ], "total_cycles": [ - 0.6666666865348816, + 2.6666667461395264, 1.0, 1.0 ] }, "thread_occupancy": 100, - "uniform_registers_used": 0, + "uniform_registers_used": 1, "work_registers_used": 2 } } @@ -2724,7 +2726,7 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 46, + "uniform_registers_used": 44, "work_registers_used": 32 }, "Varying": { @@ -2737,7 +2739,7 @@ "longest_path_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -2756,7 +2758,7 @@ "shortest_path_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -2767,7 +2769,7 @@ "total_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -2775,7 +2777,7 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 16, + "uniform_registers_used": 14, "work_registers_used": 11 } } @@ -2794,7 +2796,7 @@ ], "longest_path_cycles": [ 6.929999828338623, - 8.0, + 7.0, 0.0 ], "pipelines": [ @@ -2807,7 +2809,7 @@ ], "shortest_path_cycles": [ 5.940000057220459, - 8.0, + 7.0, 0.0 ], "total_bound_pipelines": [ @@ -2815,136 +2817,17 @@ ], "total_cycles": [ 9.0, - 8.0, + 7.0, 0.0 ] }, "thread_occupancy": 100, - "uniform_registers_used": 12, + "uniform_registers_used": 11, "work_registers_used": 3 } } } }, - "flutter/impeller/entity/gles/glyph_atlas_color.frag.gles": { - "Mali-G78": { - "core": "Mali-G78", - "filename": "flutter/impeller/entity/gles/glyph_atlas_color.frag.gles", - "has_side_effects": false, - "has_uniform_computation": true, - "modifies_coverage": false, - "reads_color_buffer": false, - "type": "Fragment", - "uses_late_zs_test": false, - "uses_late_zs_update": false, - "variants": { - "Main": { - "fp16_arithmetic": 100, - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "varying" - ], - "longest_path_cycles": [ - 0.0625, - 0.0625, - 0.0625, - 0.0, - 0.0, - 0.5, - 0.25 - ], - "pipelines": [ - "arith_total", - "arith_fma", - "arith_cvt", - "arith_sfu", - "load_store", - "varying", - "texture" - ], - "shortest_path_bound_pipelines": [ - "varying" - ], - "shortest_path_cycles": [ - 0.0625, - 0.0625, - 0.03125, - 0.0, - 0.0, - 0.5, - 0.25 - ], - "total_bound_pipelines": [ - "varying" - ], - "total_cycles": [ - 0.0625, - 0.0625, - 0.0625, - 0.0, - 0.0, - 0.5, - 0.25 - ] - }, - "stack_spill_bytes": 0, - "thread_occupancy": 100, - "uniform_registers_used": 4, - "work_registers_used": 19 - } - } - }, - "Mali-T880": { - "core": "Mali-T880", - "filename": "flutter/impeller/entity/gles/glyph_atlas_color.frag.gles", - "has_uniform_computation": false, - "type": "Fragment", - "variants": { - "Main": { - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "arithmetic", - "load_store", - "texture" - ], - "longest_path_cycles": [ - 1.0, - 1.0, - 1.0 - ], - "pipelines": [ - "arithmetic", - "load_store", - "texture" - ], - "shortest_path_bound_pipelines": [ - "arithmetic", - "load_store", - "texture" - ], - "shortest_path_cycles": [ - 1.0, - 1.0, - 1.0 - ], - "total_bound_pipelines": [ - "arithmetic" - ], - "total_cycles": [ - 1.3333333730697632, - 1.0, - 1.0 - ] - }, - "thread_occupancy": 100, - "uniform_registers_used": 1, - "work_registers_used": 2 - } - } - } - }, "flutter/impeller/entity/gles/gradient_fill.vert.gles": { "Mali-G78": { "core": "Mali-G78", @@ -5827,7 +5710,7 @@ "core": "Mali-G78", "filename": "flutter/impeller/entity/glyph_atlas.frag.vkspv", "has_side_effects": false, - "has_uniform_computation": false, + "has_uniform_computation": true, "modifies_coverage": false, "reads_color_buffer": false, "type": "Fragment", @@ -5839,15 +5722,16 @@ "has_stack_spilling": false, "performance": { "longest_path_bound_pipelines": [ - "varying" + "varying", + "texture" ], "longest_path_cycles": [ + 0.078125, 0.03125, - 0.03125, + 0.078125, 0.0, 0.0, - 0.0, - 0.5, + 0.25, 0.25 ], "pipelines": [ @@ -5860,33 +5744,35 @@ "texture" ], "shortest_path_bound_pipelines": [ - "varying" + "varying", + "texture" ], "shortest_path_cycles": [ + 0.0625, 0.03125, - 0.03125, + 0.0625, 0.0, 0.0, - 0.0, - 0.5, + 0.25, 0.25 ], "total_bound_pipelines": [ - "varying" + "varying", + "texture" ], "total_cycles": [ - 0.03125, - 0.03125, + 0.09375, + 0.0625, + 0.09375, 0.0, 0.0, - 0.0, - 0.5, + 0.25, 0.25 ] }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 4, + "uniform_registers_used": 8, "work_registers_used": 6 } } @@ -5947,7 +5833,7 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 54, + "uniform_registers_used": 52, "work_registers_used": 32 }, "Varying": { @@ -5960,7 +5846,7 @@ "longest_path_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -5979,7 +5865,7 @@ "shortest_path_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -5990,7 +5876,7 @@ "total_cycles": [ 0.15625, 0.15625, - 0.03125, + 0.0, 0.0, 4.0, 0.0 @@ -5998,82 +5884,12 @@ }, "stack_spill_bytes": 0, "thread_occupancy": 100, - "uniform_registers_used": 46, + "uniform_registers_used": 44, "work_registers_used": 11 } } } }, - "flutter/impeller/entity/glyph_atlas_color.frag.vkspv": { - "Mali-G78": { - "core": "Mali-G78", - "filename": "flutter/impeller/entity/glyph_atlas_color.frag.vkspv", - "has_side_effects": false, - "has_uniform_computation": true, - "modifies_coverage": false, - "reads_color_buffer": false, - "type": "Fragment", - "uses_late_zs_test": false, - "uses_late_zs_update": false, - "variants": { - "Main": { - "fp16_arithmetic": 100, - "has_stack_spilling": false, - "performance": { - "longest_path_bound_pipelines": [ - "varying" - ], - "longest_path_cycles": [ - 0.0625, - 0.0625, - 0.03125, - 0.0, - 0.0, - 0.5, - 0.25 - ], - "pipelines": [ - "arith_total", - "arith_fma", - "arith_cvt", - "arith_sfu", - "load_store", - "varying", - "texture" - ], - "shortest_path_bound_pipelines": [ - "varying" - ], - "shortest_path_cycles": [ - 0.0625, - 0.0625, - 0.03125, - 0.0, - 0.0, - 0.5, - 0.25 - ], - "total_bound_pipelines": [ - "varying" - ], - "total_cycles": [ - 0.0625, - 0.0625, - 0.03125, - 0.0, - 0.0, - 0.5, - 0.25 - ] - }, - "stack_spill_bytes": 0, - "thread_occupancy": 100, - "uniform_registers_used": 4, - "work_registers_used": 8 - } - } - } - }, "flutter/impeller/entity/gradient_fill.vert.vkspv": { "Mali-G78": { "core": "Mali-G78",