Skip to content

Commit 58ac1da

Browse files
author
Jonah Williams
authored
[Impeller] split downsample shader into GLES variant. (#56376)
This fixes a crash reported on a moto g4 where the on device shader compiler fails to process the ifdef.
1 parent 371c8fe commit 58ac1da

9 files changed

Lines changed: 279 additions & 50 deletions

File tree

‎ci/licenses_golden/licenses_flutter‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43065,6 +43065,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert
4306543065
ORIGIN: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag + ../../../flutter/LICENSE
4306643066
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.frag + ../../../flutter/LICENSE
4306743067
ORIGIN: ../../../flutter/impeller/entity/shaders/clip.vert + ../../../flutter/LICENSE
43068+
ORIGIN: ../../../flutter/impeller/entity/shaders/downsample.glsl + ../../../flutter/LICENSE
4306843069
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/border_mask_blur.frag + ../../../flutter/LICENSE
4306943070
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/color_matrix_color_filter.frag + ../../../flutter/LICENSE
4307043071
ORIGIN: ../../../flutter/impeller/entity/shaders/filters/filter_position.vert + ../../../flutter/LICENSE
@@ -43093,6 +43094,7 @@ ORIGIN: ../../../flutter/impeller/entity/shaders/runtime_effect.vert + ../../../
4309343094
ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.frag + ../../../flutter/LICENSE
4309443095
ORIGIN: ../../../flutter/impeller/entity/shaders/solid_fill.vert + ../../../flutter/LICENSE
4309543096
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_downsample.frag + ../../../flutter/LICENSE
43097+
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_downsample_gles.frag + ../../../flutter/LICENSE
4309643098
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.frag + ../../../flutter/LICENSE
4309743099
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill.vert + ../../../flutter/LICENSE
4309843100
ORIGIN: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag + ../../../flutter/LICENSE
@@ -45925,6 +45927,7 @@ FILE: ../../../flutter/impeller/entity/shaders/blending/porter_duff_blend.vert
4592545927
FILE: ../../../flutter/impeller/entity/shaders/blending/vertices_uber.frag
4592645928
FILE: ../../../flutter/impeller/entity/shaders/clip.frag
4592745929
FILE: ../../../flutter/impeller/entity/shaders/clip.vert
45930+
FILE: ../../../flutter/impeller/entity/shaders/downsample.glsl
4592845931
FILE: ../../../flutter/impeller/entity/shaders/filters/border_mask_blur.frag
4592945932
FILE: ../../../flutter/impeller/entity/shaders/filters/color_matrix_color_filter.frag
4593045933
FILE: ../../../flutter/impeller/entity/shaders/filters/filter_position.vert
@@ -45953,6 +45956,7 @@ FILE: ../../../flutter/impeller/entity/shaders/runtime_effect.vert
4595345956
FILE: ../../../flutter/impeller/entity/shaders/solid_fill.frag
4595445957
FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
4595545958
FILE: ../../../flutter/impeller/entity/shaders/texture_downsample.frag
45959+
FILE: ../../../flutter/impeller/entity/shaders/texture_downsample_gles.frag
4595645960
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
4595745961
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
4595845962
FILE: ../../../flutter/impeller/entity/shaders/texture_fill_strict_src.frag

‎impeller/entity/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impeller_shaders("entity_shaders") {
5151
"shaders/gradients/fast_gradient.vert",
5252
"shaders/gradients/fast_gradient.frag",
5353
"shaders/texture_downsample.frag",
54+
"shaders/texture_downsample_gles.frag",
5455
]
5556
}
5657

‎impeller/entity/contents/content_context.cc‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ ContentContext::ContentContext(
336336
clip_pipelines_.SetDefault(
337337
options,
338338
std::make_unique<ClipPipeline>(*context_, clip_pipeline_descriptor));
339-
texture_downsample_pipelines_.CreateDefault(
340-
*context_, options_trianglestrip, {supports_decal});
339+
texture_downsample_pipelines_.CreateDefault(*context_,
340+
options_trianglestrip);
341341
rrect_blur_pipelines_.CreateDefault(*context_, options_trianglestrip);
342342
texture_strict_src_pipelines_.CreateDefault(*context_, options);
343343
tiled_texture_pipelines_.CreateDefault(*context_, options,
@@ -454,10 +454,14 @@ ContentContext::ContentContext(
454454
options_trianglestrip);
455455
yuv_to_rgb_filter_pipelines_.CreateDefault(*context_, options_trianglestrip);
456456

457-
// GLES only shader that is unsupported on macOS.
458-
#if defined(IMPELLER_ENABLE_OPENGLES) && !defined(FML_OS_MACOSX)
457+
#if defined(IMPELLER_ENABLE_OPENGLES)
459458
if (GetContext()->GetBackendType() == Context::BackendType::kOpenGLES) {
459+
#if !defined(FML_OS_MACOSX)
460+
// GLES only shader that is unsupported on macOS.
460461
tiled_texture_external_pipelines_.CreateDefault(*context_, options);
462+
#endif // !defined(FML_OS_MACOSX)
463+
texture_downsample_gles_pipelines_.CreateDefault(*context_,
464+
options_trianglestrip);
461465
}
462466
#endif // IMPELLER_ENABLE_OPENGLES
463467

‎impeller/entity/contents/content_context.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "impeller/entity/vertices_uber.frag.h"
7171

7272
#ifdef IMPELLER_ENABLE_OPENGLES
73+
#include "impeller/entity/texture_downsample_gles.frag.h"
7374
#include "impeller/entity/tiled_texture_fill_external.frag.h"
7475
#endif // IMPELLER_ENABLE_OPENGLES
7576

@@ -239,6 +240,9 @@ using VerticesUberShader = RenderPipelineHandle<PorterDuffBlendVertexShader,
239240
using TiledTextureExternalPipeline =
240241
RenderPipelineHandle<TextureFillVertexShader,
241242
TiledTextureFillExternalFragmentShader>;
243+
using TextureDownsampleGlesPipeline =
244+
RenderPipelineHandle<TextureFillVertexShader,
245+
TextureDownsampleGlesFragmentShader>;
242246
#endif // IMPELLER_ENABLE_OPENGLES
243247

244248
/// Pipeline state configuration.
@@ -426,6 +430,11 @@ class ContentContext {
426430
}
427431

428432
#ifdef IMPELLER_ENABLE_OPENGLES
433+
std::shared_ptr<Pipeline<PipelineDescriptor>>
434+
GetDownsampleTextureGlesPipeline(ContentContextOptions opts) const {
435+
return GetPipeline(texture_downsample_gles_pipelines_, opts);
436+
}
437+
429438
std::shared_ptr<Pipeline<PipelineDescriptor>> GetTiledTextureExternalPipeline(
430439
ContentContextOptions opts) const {
431440
FML_DCHECK(GetContext()->GetBackendType() ==
@@ -873,6 +882,8 @@ class ContentContext {
873882
#ifdef IMPELLER_ENABLE_OPENGLES
874883
mutable Variants<TiledTextureExternalPipeline>
875884
tiled_texture_external_pipelines_;
885+
mutable Variants<TextureDownsampleGlesPipeline>
886+
texture_downsample_gles_pipelines_;
876887
#endif // IMPELLER_ENABLE_OPENGLES
877888
mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
878889
mutable Variants<GaussianBlurPipeline> gaussian_blur_pipelines_;

‎impeller/entity/contents/filters/gaussian_blur_filter_contents.cc‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,20 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass(
396396
pass.SetCommandLabel("Gaussian blur downsample");
397397
auto pipeline_options = OptionsFromPass(pass);
398398
pipeline_options.primitive_type = PrimitiveType::kTriangleStrip;
399+
#ifdef IMPELLER_ENABLE_OPENGLES
400+
// The GLES backend conditionally supports decal tile mode, while
401+
// decal is always supported for Vulkan and Metal.
402+
if (renderer.GetDeviceCapabilities()
403+
.SupportsDecalSamplerAddressMode() ||
404+
tile_mode != Entity::TileMode::kDecal) {
405+
pass.SetPipeline(renderer.GetDownsamplePipeline(pipeline_options));
406+
} else {
407+
pass.SetPipeline(
408+
renderer.GetDownsampleTextureGlesPipeline(pipeline_options));
409+
}
410+
#else
399411
pass.SetPipeline(renderer.GetDownsamplePipeline(pipeline_options));
412+
#endif // IMPELLER_ENABLE_OPENGLES
400413

401414
TextureFillVertexShader::FrameInfo frame_info;
402415
frame_info.mvp = Matrix::MakeOrthographic(ISize(1, 1));
@@ -407,8 +420,6 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass(
407420
frag_info.edge = edge;
408421
frag_info.ratio = ratio;
409422
frag_info.pixel_size = Vector2(1.0f / Size(input_texture->GetSize()));
410-
frag_info.use_decal =
411-
(tile_mode == Entity::TileMode::kDecal) ? 1.0 : 0.0;
412423

413424
const Quad& uvs = pass_args.uvs;
414425
std::array<VS::PerVertexData, 4> vertices = {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
precision mediump float;
6+
7+
#include <impeller/constants.glsl>
8+
#include <impeller/types.glsl>
9+
10+
uniform f16sampler2D texture_sampler;
11+
12+
uniform FragInfo {
13+
float edge;
14+
float ratio;
15+
vec2 pixel_size;
16+
}
17+
frag_info;
18+
19+
in highp vec2 v_texture_coords;
20+
21+
out vec4 frag_color;
22+
23+
vec4 Sample(vec2 uv) {
24+
#ifdef SUPPORTS_DECAL
25+
return texture(texture_sampler, uv, float16_t(kDefaultMipBias));
26+
#else
27+
if ((uv.x < 0 || uv.y < 0 || uv.x > 1 || uv.y > 1)) {
28+
return vec4(0);
29+
} else {
30+
return texture(texture_sampler, uv, float16_t(kDefaultMipBias));
31+
}
32+
#endif
33+
}
34+
35+
void main() {
36+
vec4 total = vec4(0.0);
37+
for (float i = -frag_info.edge; i <= frag_info.edge; i += 2) {
38+
for (float j = -frag_info.edge; j <= frag_info.edge; j += 2) {
39+
total += (Sample(v_texture_coords + frag_info.pixel_size * vec2(i, j)) *
40+
frag_info.ratio);
41+
}
42+
}
43+
frag_color = total;
44+
}

‎impeller/entity/shaders/texture_downsample.frag‎

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
precision mediump float;
5+
#define SUPPORTS_DECAL 1
66

7-
#include <impeller/constants.glsl>
8-
#include <impeller/types.glsl>
9-
10-
layout(constant_id = 0) const float supports_decal = 1.0;
11-
12-
uniform f16sampler2D texture_sampler;
13-
14-
uniform FragInfo {
15-
float edge;
16-
float ratio;
17-
float use_decal;
18-
vec2 pixel_size;
19-
}
20-
frag_info;
21-
22-
in highp vec2 v_texture_coords;
23-
24-
out vec4 frag_color;
25-
26-
vec4 Sample(vec2 uv) {
27-
if (supports_decal == 1.0) {
28-
return texture(texture_sampler, uv, float16_t(kDefaultMipBias));
29-
} else {
30-
if (frag_info.use_decal == 1.0 &&
31-
(uv.x < 0 || uv.y < 0 || uv.x > 1 || uv.y > 1)) {
32-
return vec4(0);
33-
} else {
34-
return texture(texture_sampler, uv, float16_t(kDefaultMipBias));
35-
}
36-
}
37-
}
38-
39-
void main() {
40-
vec4 total = vec4(0.0);
41-
for (float i = -frag_info.edge; i <= frag_info.edge; i += 2) {
42-
for (float j = -frag_info.edge; j <= frag_info.edge; j += 2) {
43-
total += (Sample(v_texture_coords + frag_info.pixel_size * vec2(i, j)) *
44-
frag_info.ratio);
45-
}
46-
}
47-
frag_color = total;
48-
}
7+
#include <downsample.glsl>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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 <downsample.glsl>

0 commit comments

Comments
 (0)