[Impeller] split vertices uber into 2 shaders. (#165938)

Works around compilation error on newer phone (ask me offline). Required
for https://github.com/flutter/flutter/issues/162033
This commit is contained in:
Jonah Williams
2025-03-28 09:36:59 -07:00
committed by GitHub
parent ffcc383848
commit 7bbcfe08d3
12 changed files with 335 additions and 52 deletions

View File

@@ -51303,7 +51303,9 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert + ../../../flutter/LICENSE
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.glsl + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_1.frag + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_2.frag + ../../../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/downsample.glsl + ../../../flutter/LICENSE
@@ -54287,7 +54289,9 @@ FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag
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.glsl
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_1.frag
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_2.frag
FILE: ../../../flutter/impeller/entity/shaders/clip.frag
FILE: ../../../flutter/impeller/entity/shaders/clip.vert
FILE: ../../../flutter/impeller/entity/shaders/downsample.glsl

View File

@@ -59,7 +59,8 @@ impeller_shaders("entity_shaders") {
"shaders/filters/srgb_to_linear_filter.frag",
"shaders/filters/linear_to_srgb_filter.frag",
"shaders/filters/morphology_filter.frag",
"shaders/blending/vertices_uber.frag",
"shaders/blending/vertices_uber_1.frag",
"shaders/blending/vertices_uber_2.frag",
"shaders/gradients/fast_gradient.vert",
"shaders/gradients/fast_gradient.frag",
"shaders/texture_downsample.frag",

View File

@@ -126,15 +126,15 @@ bool AtlasContents::Render(const ContentContext& renderer,
return pass.Draw().ok();
}
using VUS = VerticesUberShader::VertexShader;
using FS = VerticesUberShader::FragmentShader;
using VUS = VerticesUber1Shader::VertexShader;
using FS = VerticesUber1Shader::FragmentShader;
#ifdef IMPELLER_DEBUG
pass.SetCommandLabel("DrawAtlas Advanced Blend");
#endif // IMPELLER_DEBUG
pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
pass.SetPipeline(renderer.GetDrawVerticesUberShader(OptionsFromPass(pass)));
renderer.GetDrawVerticesUberPipeline(blend_mode, OptionsFromPass(pass));
FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
VUS::FrameInfo frame_info;

View File

@@ -272,7 +272,8 @@ struct ContentContext::Pipelines {
Variants<TexturePipeline> texture;
Variants<TextureStrictSrcPipeline> texture_strict_src;
Variants<TiledTexturePipeline> tiled_texture;
Variants<VerticesUberShader> vertices_uber_shader_;
Variants<VerticesUber1Shader> vertices_uber_1_;
Variants<VerticesUber2Shader> vertices_uber_2_;
Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter;
#ifdef IMPELLER_ENABLE_OPENGLES
@@ -668,8 +669,10 @@ ContentContext::ContentContext(
options_trianglestrip);
pipelines_->color_matrix_color_filter.CreateDefault(*context_,
options_trianglestrip);
pipelines_->vertices_uber_shader_.CreateDefault(*context_, options,
{supports_decal});
pipelines_->vertices_uber_1_.CreateDefault(*context_, options,
{supports_decal});
pipelines_->vertices_uber_2_.CreateDefault(*context_, options,
{supports_decal});
const std::array<std::vector<Scalar>, 15> porter_duff_constants =
GetPorterDuffSpecConstants(supports_decal);
@@ -1421,9 +1424,14 @@ PipelineRef ContentContext::GetFramebufferBlendSoftLightPipeline(
return GetPipeline(this, pipelines_->framebuffer_blend_softlight, opts);
}
PipelineRef ContentContext::GetDrawVerticesUberShader(
PipelineRef ContentContext::GetDrawVerticesUberPipeline(
BlendMode blend_mode,
ContentContextOptions opts) const {
return GetPipeline(this, pipelines_->vertices_uber_shader_, opts);
if (blend_mode <= BlendMode::kSoftLight) {
return GetPipeline(this, pipelines_->vertices_uber_1_, opts);
} else {
return GetPipeline(this, pipelines_->vertices_uber_2_, opts);
}
}
PipelineRef ContentContext::GetLinePipeline(ContentContextOptions opts) const {

View File

@@ -176,7 +176,7 @@ class ContentContext {
PipelineRef GetDestinationOutBlendPipeline(ContentContextOptions opts) const;
PipelineRef GetDestinationOverBlendPipeline(ContentContextOptions opts) const;
PipelineRef GetDownsamplePipeline(ContentContextOptions opts) const;
PipelineRef GetDrawVerticesUberShader(ContentContextOptions opts) const;
PipelineRef GetDrawVerticesUberPipeline(BlendMode blend_mode, ContentContextOptions opts) const;
PipelineRef GetFastGradientPipeline(ContentContextOptions opts) const;
PipelineRef GetFramebufferBlendColorBurnPipeline(ContentContextOptions opts) const;
PipelineRef GetFramebufferBlendColorDodgePipeline(ContentContextOptions opts) const;

View File

@@ -56,7 +56,8 @@
#include "impeller/entity/texture_fill_strict_src.frag.h"
#include "impeller/entity/texture_uv_fill.vert.h"
#include "impeller/entity/tiled_texture_fill.frag.h"
#include "impeller/entity/vertices_uber.frag.h"
#include "impeller/entity/vertices_uber_1.frag.h"
#include "impeller/entity/vertices_uber_2.frag.h"
#include "impeller/entity/yuv_to_rgb_filter.frag.h"
#include "impeller/renderer/pipeline.h"
@@ -146,7 +147,8 @@ using TextureDownsamplePipeline = RenderPipelineHandle<TextureFillVertexShader,
using TexturePipeline = RenderPipelineHandle<TextureFillVertexShader, TextureFillFragmentShader>;
using TextureStrictSrcPipeline = RenderPipelineHandle<TextureFillVertexShader, TextureFillStrictSrcFragmentShader>;
using TiledTexturePipeline = RenderPipelineHandle<TextureUvFillVertexShader, TiledTextureFillFragmentShader>;
using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUberFragmentShader>;
using VerticesUber1Shader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUber1FragmentShader>;
using VerticesUber2Shader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUber2FragmentShader>;
using YUVToRGBFilterPipeline = RenderPipelineHandle<FilterPositionVertexShader, YuvToRgbFilterFragmentShader>;
// clang-format on

View File

@@ -10,6 +10,7 @@
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/contents/filters/blend_filter_contents.h"
#include "impeller/entity/contents/pipelines.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/entity/geometry/vertices_geometry.h"
#include "impeller/geometry/color.h"
@@ -177,8 +178,8 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
return pass.Draw().ok();
}
using VS = VerticesUberShader::VertexShader;
using FS = VerticesUberShader::FragmentShader;
using VS = VerticesUber1Shader::VertexShader;
using FS = VerticesUber1Shader::FragmentShader;
#ifdef IMPELLER_DEBUG
pass.SetCommandLabel(SPrintF("DrawVertices Advanced Blend (%s)",
@@ -188,7 +189,7 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
auto options = OptionsFromPassAndEntity(pass, entity);
options.primitive_type = geometry_result.type;
pass.SetPipeline(renderer.GetDrawVerticesUberShader(options));
pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(blend_mode, options));
FS::BindTextureSampler(pass, texture, dst_sampler);

View File

@@ -70,3 +70,56 @@ f16vec3 AdvancedBlend(f16vec3 dst, f16vec3 src, int blend_type) {
}
return f16vec3(0.0hf);
}
f16vec3 AdvancedBlendHalf1(f16vec3 dst, f16vec3 src, int blend_type) {
if (blend_type == 0) {
return IPBlendScreen(dst, src);
}
if (blend_type == 1) {
return IPBlendOverlay(dst, src);
}
if (blend_type == 2) {
return IPBlendDarken(dst, src);
}
if (blend_type == 3) {
return IPBlendLighten(dst, src);
}
if (blend_type == 4) {
return IPBlendColorDodge(dst, src);
}
if (blend_type == 5) {
return IPBlendColorBurn(dst, src);
}
if (blend_type == 6) {
return IPBlendHardLight(dst, src);
}
if (blend_type == 7) {
return IPBlendSoftLight(dst, src);
}
return f16vec3(0.0hf);
}
f16vec3 AdvancedBlendHalf2(f16vec3 dst, f16vec3 src, int blend_type) {
if (blend_type == 8) {
return IPBlendDifference(dst, src);
}
if (blend_type == 9) {
return IPBlendExclusion(dst, src);
}
if (blend_type == 10) {
return IPBlendMultiply(dst, src);
}
if (blend_type == 11) {
return IPBlendHue(dst, src);
}
if (blend_type == 12) {
return IPBlendSaturation(dst, src);
}
if (blend_type == 13) {
return IPBlendColor(dst, src);
}
if (blend_type == 14) {
return IPBlendLuminosity(dst, src);
}
return f16vec3(0.0hf);
}

View File

@@ -33,17 +33,3 @@ f16vec4 Sample(f16sampler2D texture_sampler,
}
return IPHalfSampleWithTileMode(texture_sampler, texture_coords, tmx, tmy);
}
// A shader that implements the required src/dst blending for drawVertices and
// drawAtlas advanced blends without requiring an offscreen render pass. This is
// done in a single shader to reduce the permutations of PSO needed at runtime
// for rarely used features.
void main() {
f16vec4 dst = IPHalfUnpremultiply(v_color);
f16vec4 src = IPHalfUnpremultiply(
Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy));
f16vec3 blend_result =
AdvancedBlend(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0));
frag_color = IPApplyBlendedColor(dst, src, blend_result);
frag_color *= frag_info.alpha;
}

View File

@@ -0,0 +1,19 @@
// 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.
#include "vertices_uber.glsl"
// A shader that implements the required src/dst blending for drawVertices and
// drawAtlas advanced blends without requiring an offscreen render pass. This is
// done in a single shader to reduce the permutations of PSO needed at runtime
// for rarely used features.
void main() {
f16vec4 dst = IPHalfUnpremultiply(v_color);
f16vec4 src = IPHalfUnpremultiply(
Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy));
f16vec3 blend_result =
AdvancedBlendHalf1(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0));
frag_color = IPApplyBlendedColor(dst, src, blend_result);
frag_color *= frag_info.alpha;
}

View File

@@ -0,0 +1,19 @@
// 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.
#include "vertices_uber.glsl"
// A shader that implements the required src/dst blending for drawVertices and
// drawAtlas advanced blends without requiring an offscreen render pass. This is
// done in a single shader to reduce the permutations of PSO needed at runtime
// for rarely used features.
void main() {
f16vec4 dst = IPHalfUnpremultiply(v_color);
f16vec4 src = IPHalfUnpremultiply(
Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy));
f16vec3 blend_result =
AdvancedBlendHalf2(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0));
frag_color = IPApplyBlendedColor(dst, src, blend_result);
frag_color *= frag_info.alpha;
}

View File

@@ -7709,10 +7709,10 @@
}
}
},
"flutter/impeller/entity/gles/vertices_uber.frag.gles": {
"flutter/impeller/entity/gles/vertices_uber_1.frag.gles": {
"Mali-G78": {
"core": "Mali-G78",
"filename": "flutter/impeller/entity/gles/vertices_uber.frag.gles",
"filename": "flutter/impeller/entity/gles/vertices_uber_1.frag.gles",
"has_side_effects": false,
"has_uniform_computation": true,
"modifies_coverage": false,
@@ -7732,7 +7732,7 @@
"longest_path_cycles": [
1.2625000476837158,
1.2625000476837158,
0.675000011920929,
0.737500011920929,
0.3125,
0.0,
0.5,
@@ -7764,10 +7764,10 @@
"arith_fma"
],
"total_cycles": [
3.862499952316284,
3.862499952316284,
2.799999952316284,
0.9375,
2.40625,
2.40625,
1.75,
0.6875,
0.0,
0.5,
0.25
@@ -7775,14 +7775,14 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 14,
"uniform_registers_used": 10,
"work_registers_used": 32
}
}
},
"Mali-T880": {
"core": "Mali-T880",
"filename": "flutter/impeller/entity/gles/vertices_uber.frag.gles",
"filename": "flutter/impeller/entity/gles/vertices_uber_1.frag.gles",
"has_uniform_computation": false,
"type": "Fragment",
"variants": {
@@ -7793,7 +7793,7 @@
"arithmetic"
],
"longest_path_cycles": [
14.1899995803833,
11.880000114440918,
5.0,
1.0
],
@@ -7814,7 +7814,7 @@
"arithmetic"
],
"total_cycles": [
47.33333206176758,
23.0,
6.0,
1.0
]
@@ -7826,6 +7826,123 @@
}
}
},
"flutter/impeller/entity/gles/vertices_uber_2.frag.gles": {
"Mali-G78": {
"core": "Mali-G78",
"filename": "flutter/impeller/entity/gles/vertices_uber_2.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": 0,
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma"
],
"longest_path_cycles": [
1.1124999523162842,
1.1124999523162842,
0.800000011920929,
0.3125,
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.421875,
0.421875,
0.359375,
0.0625,
0.0,
0.5,
0.25
],
"total_bound_pipelines": [
"arith_total",
"arith_fma"
],
"total_cycles": [
1.8875000476837158,
1.8875000476837158,
1.28125,
0.375,
0.0,
0.5,
0.25
]
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 24
}
}
},
"Mali-T880": {
"core": "Mali-T880",
"filename": "flutter/impeller/entity/gles/vertices_uber_2.frag.gles",
"has_uniform_computation": false,
"type": "Fragment",
"variants": {
"Main": {
"has_stack_spilling": true,
"performance": {
"longest_path_bound_pipelines": [
"arithmetic"
],
"longest_path_cycles": [
11.220000267028809,
9.0,
1.0
],
"pipelines": [
"arithmetic",
"load_store",
"texture"
],
"shortest_path_bound_pipelines": [
"load_store"
],
"shortest_path_cycles": [
3.630000114440918,
5.0,
1.0
],
"total_bound_pipelines": [
"arithmetic"
],
"total_cycles": [
27.66666603088379,
14.0,
1.0
]
},
"thread_occupancy": 100,
"uniform_registers_used": 1,
"work_registers_used": 4
}
}
}
},
"flutter/impeller/entity/gles/yuv_to_rgb_filter.frag.gles": {
"Mali-G78": {
"core": "Mali-G78",
@@ -10552,10 +10669,10 @@
}
}
},
"flutter/impeller/entity/vertices_uber.frag.vkspv": {
"flutter/impeller/entity/vertices_uber_1.frag.vkspv": {
"Mali-G78": {
"core": "Mali-G78",
"filename": "flutter/impeller/entity/vertices_uber.frag.vkspv",
"filename": "flutter/impeller/entity/vertices_uber_1.frag.vkspv",
"has_side_effects": false,
"has_uniform_computation": true,
"modifies_coverage": false,
@@ -10573,9 +10690,9 @@
"arith_fma"
],
"longest_path_cycles": [
1.1124999523162842,
1.1124999523162842,
0.84375,
1.2625000476837158,
1.2625000476837158,
0.6875,
0.3125,
0.0,
0.5,
@@ -10608,10 +10725,10 @@
"arith_fma"
],
"total_cycles": [
3.875,
3.875,
2.40625,
0.9375,
2.4375,
2.4375,
1.5,
0.6875,
0.0,
0.5,
0.25
@@ -10619,12 +10736,85 @@
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 14,
"uniform_registers_used": 12,
"work_registers_used": 32
}
}
}
},
"flutter/impeller/entity/vertices_uber_2.frag.vkspv": {
"Mali-G78": {
"core": "Mali-G78",
"filename": "flutter/impeller/entity/vertices_uber_2.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": 0,
"has_stack_spilling": false,
"performance": {
"longest_path_bound_pipelines": [
"arith_total",
"arith_fma"
],
"longest_path_cycles": [
1.1124999523162842,
1.1124999523162842,
0.699999988079071,
0.3125,
0.0,
0.5,
0.25
],
"pipelines": [
"arith_total",
"arith_fma",
"arith_cvt",
"arith_sfu",
"load_store",
"varying",
"texture"
],
"shortest_path_bound_pipelines": [
"arith_total",
"arith_fma"
],
"shortest_path_cycles": [
0.5625,
0.5625,
0.234375,
0.125,
0.0,
0.5,
0.25
],
"total_bound_pipelines": [
"arith_total",
"arith_fma"
],
"total_cycles": [
1.90625,
1.90625,
1.09375,
0.375,
0.0,
0.5,
0.25
]
},
"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 8,
"work_registers_used": 23
}
}
}
},
"flutter/impeller/entity/yuv_to_rgb_filter.frag.vkspv": {
"Mali-G78": {
"core": "Mali-G78",