[Impeller] combine text shaders. (flutter/engine#52392)

Combine both text shaders into one. One more down!

https://github.com/flutter/flutter/issues/143540
This commit is contained in:
Jonah Williams
2024-04-25 13:18:13 -07:00
committed by GitHub
parent 8e9dd76646
commit b14463a57b
9 changed files with 85 additions and 303 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -438,7 +438,6 @@ ContentContext::ContentContext(
{static_cast<Scalar>(
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});

View File

@@ -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<GlyphAtlasVertexShader, GlyphAtlasFragmentShader>;
using GlyphAtlasColorPipeline =
RenderPipelineHandle<GlyphAtlasVertexShader, GlyphAtlasColorFragmentShader>;
using PorterDuffBlendPipeline =
RenderPipelineHandle<PorterDuffBlendVertexShader,
PorterDuffBlendFragmentShader>;
@@ -516,11 +514,6 @@ class ContentContext {
return GetPipeline(glyph_atlas_pipelines_, opts);
}
std::shared_ptr<Pipeline<PipelineDescriptor>> GetGlyphAtlasColorPipeline(
ContentContextOptions opts) const {
return GetPipeline(glyph_atlas_color_pipelines_, opts);
}
std::shared_ptr<Pipeline<PipelineDescriptor>> GetYUVToRGBFilterPipeline(
ContentContextOptions opts) const {
return GetPipeline(yuv_to_rgb_filter_pipelines_, opts);
@@ -917,7 +910,6 @@ class ContentContext {
mutable Variants<SrgbToLinearFilterPipeline> srgb_to_linear_filter_pipelines_;
mutable Variants<ClipPipeline> clip_pipelines_;
mutable Variants<GlyphAtlasPipeline> glyph_atlas_pipelines_;
mutable Variants<GlyphAtlasColorPipeline> glyph_atlas_color_pipelines_;
mutable Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter_pipelines_;
mutable Variants<PorterDuffBlendPipeline> porter_duff_blend_pipelines_;
// Advanced blends.

View File

@@ -8,6 +8,7 @@
#include <optional>
#include <utility>
#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<VS::PerVertexData*>(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;
}
}
}

View File

@@ -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;
}
}
}

View File

@@ -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;
}

View File

@@ -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 <impeller/types.glsl>
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;
}
}

View File

@@ -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",