Skip to content

Commit 7bbcfe0

Browse files
author
Jonah Williams
authored
[Impeller] split vertices uber into 2 shaders. (#165938)
Works around compilation error on newer phone (ask me offline). Required for flutter/flutter#162033
1 parent ffcc383 commit 7bbcfe0

File tree

12 files changed

+335
-52
lines changed

12 files changed

+335
-52
lines changed

engine/src/flutter/ci/licenses_golden/licenses_flutter

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51303,7 +51303,9 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag
5130351303
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert + ../../../flutter/LICENSE
5130451304
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.frag + ../../../flutter/LICENSE
5130551305
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert + ../../../flutter/LICENSE
51306-
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag + ../../../flutter/LICENSE
51306+
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.glsl + ../../../flutter/LICENSE
51307+
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_1.frag + ../../../flutter/LICENSE
51308+
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_2.frag + ../../../flutter/LICENSE
5130751309
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.frag + ../../../flutter/LICENSE
5130851310
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.vert + ../../../flutter/LICENSE
5130951311
ORIGIN: ../../../flutter/impeller/entity/shaders/downsample.glsl + ../../../flutter/LICENSE
@@ -54287,7 +54289,9 @@ FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.frag
5428754289
FILE: ../../../flutter/impeller/entity/shaders/blending/framebuffer_blend.vert
5428854290
FILE: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.frag
5428954291
FILE: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert
54290-
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag
54292+
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.glsl
54293+
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_1.frag
54294+
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber_2.frag
5429154295
FILE: ../../../flutter/impeller/entity/shaders/clip.frag
5429254296
FILE: ../../../flutter/impeller/entity/shaders/clip.vert
5429354297
FILE: ../../../flutter/impeller/entity/shaders/downsample.glsl

engine/src/flutter/impeller/entity/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ impeller_shaders("entity_shaders") {
5959
"shaders/filters/srgb_to_linear_filter.frag",
6060
"shaders/filters/linear_to_srgb_filter.frag",
6161
"shaders/filters/morphology_filter.frag",
62-
"shaders/blending/vertices_uber.frag",
62+
"shaders/blending/vertices_uber_1.frag",
63+
"shaders/blending/vertices_uber_2.frag",
6364
"shaders/gradients/fast_gradient.vert",
6465
"shaders/gradients/fast_gradient.frag",
6566
"shaders/texture_downsample.frag",

engine/src/flutter/impeller/entity/contents/atlas_contents.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ bool AtlasContents::Render(const ContentContext& renderer,
126126
return pass.Draw().ok();
127127
}
128128

129-
using VUS = VerticesUberShader::VertexShader;
130-
using FS = VerticesUberShader::FragmentShader;
129+
using VUS = VerticesUber1Shader::VertexShader;
130+
using FS = VerticesUber1Shader::FragmentShader;
131131

132132
#ifdef IMPELLER_DEBUG
133133
pass.SetCommandLabel("DrawAtlas Advanced Blend");
134134
#endif // IMPELLER_DEBUG
135135
pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
136136

137-
pass.SetPipeline(renderer.GetDrawVerticesUberShader(OptionsFromPass(pass)));
137+
renderer.GetDrawVerticesUberPipeline(blend_mode, OptionsFromPass(pass));
138138
FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
139139

140140
VUS::FrameInfo frame_info;

engine/src/flutter/impeller/entity/contents/content_context.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ struct ContentContext::Pipelines {
272272
Variants<TexturePipeline> texture;
273273
Variants<TextureStrictSrcPipeline> texture_strict_src;
274274
Variants<TiledTexturePipeline> tiled_texture;
275-
Variants<VerticesUberShader> vertices_uber_shader_;
275+
Variants<VerticesUber1Shader> vertices_uber_1_;
276+
Variants<VerticesUber2Shader> vertices_uber_2_;
276277
Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter;
277278

278279
#ifdef IMPELLER_ENABLE_OPENGLES
@@ -668,8 +669,10 @@ ContentContext::ContentContext(
668669
options_trianglestrip);
669670
pipelines_->color_matrix_color_filter.CreateDefault(*context_,
670671
options_trianglestrip);
671-
pipelines_->vertices_uber_shader_.CreateDefault(*context_, options,
672-
{supports_decal});
672+
pipelines_->vertices_uber_1_.CreateDefault(*context_, options,
673+
{supports_decal});
674+
pipelines_->vertices_uber_2_.CreateDefault(*context_, options,
675+
{supports_decal});
673676

674677
const std::array<std::vector<Scalar>, 15> porter_duff_constants =
675678
GetPorterDuffSpecConstants(supports_decal);
@@ -1421,9 +1424,14 @@ PipelineRef ContentContext::GetFramebufferBlendSoftLightPipeline(
14211424
return GetPipeline(this, pipelines_->framebuffer_blend_softlight, opts);
14221425
}
14231426

1424-
PipelineRef ContentContext::GetDrawVerticesUberShader(
1427+
PipelineRef ContentContext::GetDrawVerticesUberPipeline(
1428+
BlendMode blend_mode,
14251429
ContentContextOptions opts) const {
1426-
return GetPipeline(this, pipelines_->vertices_uber_shader_, opts);
1430+
if (blend_mode <= BlendMode::kSoftLight) {
1431+
return GetPipeline(this, pipelines_->vertices_uber_1_, opts);
1432+
} else {
1433+
return GetPipeline(this, pipelines_->vertices_uber_2_, opts);
1434+
}
14271435
}
14281436

14291437
PipelineRef ContentContext::GetLinePipeline(ContentContextOptions opts) const {

engine/src/flutter/impeller/entity/contents/content_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class ContentContext {
176176
PipelineRef GetDestinationOutBlendPipeline(ContentContextOptions opts) const;
177177
PipelineRef GetDestinationOverBlendPipeline(ContentContextOptions opts) const;
178178
PipelineRef GetDownsamplePipeline(ContentContextOptions opts) const;
179-
PipelineRef GetDrawVerticesUberShader(ContentContextOptions opts) const;
179+
PipelineRef GetDrawVerticesUberPipeline(BlendMode blend_mode, ContentContextOptions opts) const;
180180
PipelineRef GetFastGradientPipeline(ContentContextOptions opts) const;
181181
PipelineRef GetFramebufferBlendColorBurnPipeline(ContentContextOptions opts) const;
182182
PipelineRef GetFramebufferBlendColorDodgePipeline(ContentContextOptions opts) const;

engine/src/flutter/impeller/entity/contents/pipelines.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
#include "impeller/entity/texture_fill_strict_src.frag.h"
5757
#include "impeller/entity/texture_uv_fill.vert.h"
5858
#include "impeller/entity/tiled_texture_fill.frag.h"
59-
#include "impeller/entity/vertices_uber.frag.h"
59+
#include "impeller/entity/vertices_uber_1.frag.h"
60+
#include "impeller/entity/vertices_uber_2.frag.h"
6061
#include "impeller/entity/yuv_to_rgb_filter.frag.h"
6162
#include "impeller/renderer/pipeline.h"
6263

@@ -146,7 +147,8 @@ using TextureDownsamplePipeline = RenderPipelineHandle<TextureFillVertexShader,
146147
using TexturePipeline = RenderPipelineHandle<TextureFillVertexShader, TextureFillFragmentShader>;
147148
using TextureStrictSrcPipeline = RenderPipelineHandle<TextureFillVertexShader, TextureFillStrictSrcFragmentShader>;
148149
using TiledTexturePipeline = RenderPipelineHandle<TextureUvFillVertexShader, TiledTextureFillFragmentShader>;
149-
using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUberFragmentShader>;
150+
using VerticesUber1Shader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUber1FragmentShader>;
151+
using VerticesUber2Shader = RenderPipelineHandle<PorterDuffBlendVertexShader, VerticesUber2FragmentShader>;
150152
using YUVToRGBFilterPipeline = RenderPipelineHandle<FilterPositionVertexShader, YuvToRgbFilterFragmentShader>;
151153
// clang-format on
152154

engine/src/flutter/impeller/entity/contents/vertices_contents.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "impeller/entity/contents/content_context.h"
1111
#include "impeller/entity/contents/contents.h"
1212
#include "impeller/entity/contents/filters/blend_filter_contents.h"
13+
#include "impeller/entity/contents/pipelines.h"
1314
#include "impeller/entity/geometry/geometry.h"
1415
#include "impeller/entity/geometry/vertices_geometry.h"
1516
#include "impeller/geometry/color.h"
@@ -177,8 +178,8 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
177178
return pass.Draw().ok();
178179
}
179180

180-
using VS = VerticesUberShader::VertexShader;
181-
using FS = VerticesUberShader::FragmentShader;
181+
using VS = VerticesUber1Shader::VertexShader;
182+
using FS = VerticesUber1Shader::FragmentShader;
182183

183184
#ifdef IMPELLER_DEBUG
184185
pass.SetCommandLabel(SPrintF("DrawVertices Advanced Blend (%s)",
@@ -188,7 +189,7 @@ bool VerticesSimpleBlendContents::Render(const ContentContext& renderer,
188189

189190
auto options = OptionsFromPassAndEntity(pass, entity);
190191
options.primitive_type = geometry_result.type;
191-
pass.SetPipeline(renderer.GetDrawVerticesUberShader(options));
192+
pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(blend_mode, options));
192193

193194
FS::BindTextureSampler(pass, texture, dst_sampler);
194195

engine/src/flutter/impeller/entity/shaders/blending/blend_select.glsl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,56 @@ f16vec3 AdvancedBlend(f16vec3 dst, f16vec3 src, int blend_type) {
7070
}
7171
return f16vec3(0.0hf);
7272
}
73+
74+
f16vec3 AdvancedBlendHalf1(f16vec3 dst, f16vec3 src, int blend_type) {
75+
if (blend_type == 0) {
76+
return IPBlendScreen(dst, src);
77+
}
78+
if (blend_type == 1) {
79+
return IPBlendOverlay(dst, src);
80+
}
81+
if (blend_type == 2) {
82+
return IPBlendDarken(dst, src);
83+
}
84+
if (blend_type == 3) {
85+
return IPBlendLighten(dst, src);
86+
}
87+
if (blend_type == 4) {
88+
return IPBlendColorDodge(dst, src);
89+
}
90+
if (blend_type == 5) {
91+
return IPBlendColorBurn(dst, src);
92+
}
93+
if (blend_type == 6) {
94+
return IPBlendHardLight(dst, src);
95+
}
96+
if (blend_type == 7) {
97+
return IPBlendSoftLight(dst, src);
98+
}
99+
return f16vec3(0.0hf);
100+
}
101+
102+
f16vec3 AdvancedBlendHalf2(f16vec3 dst, f16vec3 src, int blend_type) {
103+
if (blend_type == 8) {
104+
return IPBlendDifference(dst, src);
105+
}
106+
if (blend_type == 9) {
107+
return IPBlendExclusion(dst, src);
108+
}
109+
if (blend_type == 10) {
110+
return IPBlendMultiply(dst, src);
111+
}
112+
if (blend_type == 11) {
113+
return IPBlendHue(dst, src);
114+
}
115+
if (blend_type == 12) {
116+
return IPBlendSaturation(dst, src);
117+
}
118+
if (blend_type == 13) {
119+
return IPBlendColor(dst, src);
120+
}
121+
if (blend_type == 14) {
122+
return IPBlendLuminosity(dst, src);
123+
}
124+
return f16vec3(0.0hf);
125+
}

engine/src/flutter/impeller/entity/shaders/blending/vertices_uber.frag renamed to engine/src/flutter/impeller/entity/shaders/blending/vertices_uber.glsl

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,3 @@ f16vec4 Sample(f16sampler2D texture_sampler,
3333
}
3434
return IPHalfSampleWithTileMode(texture_sampler, texture_coords, tmx, tmy);
3535
}
36-
37-
// A shader that implements the required src/dst blending for drawVertices and
38-
// drawAtlas advanced blends without requiring an offscreen render pass. This is
39-
// done in a single shader to reduce the permutations of PSO needed at runtime
40-
// for rarely used features.
41-
void main() {
42-
f16vec4 dst = IPHalfUnpremultiply(v_color);
43-
f16vec4 src = IPHalfUnpremultiply(
44-
Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy));
45-
f16vec3 blend_result =
46-
AdvancedBlend(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0));
47-
frag_color = IPApplyBlendedColor(dst, src, blend_result);
48-
frag_color *= frag_info.alpha;
49-
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "vertices_uber.glsl"
6+
7+
// A shader that implements the required src/dst blending for drawVertices and
8+
// drawAtlas advanced blends without requiring an offscreen render pass. This is
9+
// done in a single shader to reduce the permutations of PSO needed at runtime
10+
// for rarely used features.
11+
void main() {
12+
f16vec4 dst = IPHalfUnpremultiply(v_color);
13+
f16vec4 src = IPHalfUnpremultiply(
14+
Sample(texture_sampler, v_texture_coords, frag_info.tmx, frag_info.tmy));
15+
f16vec3 blend_result =
16+
AdvancedBlendHalf1(dst.rgb, src.rgb, int(frag_info.blend_mode - 14.0));
17+
frag_color = IPApplyBlendedColor(dst, src, blend_result);
18+
frag_color *= frag_info.alpha;
19+
}

0 commit comments

Comments
 (0)