Skip to content

Commit

Permalink
[Impeller] Replace FML_OS_PHYSICAL_IOS compile check with runtime cap…
Browse files Browse the repository at this point in the history
…abilties check based on metal GPU family. (flutter#40124)

[Impeller] Replace FML_OS_PHYSICAL_IOS compile check with runtime capabilties check based on metal GPU family.
  • Loading branch information
jonahwilliams authored Mar 8, 2023
1 parent 694a14c commit e763087
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 166 deletions.
6 changes: 0 additions & 6 deletions fml/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,4 @@
#error Please add support for your architecture in flutter/fml/build_config.h
#endif

#if defined(FML_OS_IOS)
#if !defined(FML_OS_IOS_SIMULATOR)
#define FML_OS_PHYSICAL_IOS 1
#endif
#endif

#endif // FLUTTER_FML_BUILD_CONFIG_H_
2 changes: 1 addition & 1 deletion impeller/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static uint32_t ParseMSLVersion(const std::string& msl_version) {
}
}
}
if (major < 1 || minor < 2) {
if (major < 1 || (major == 1 && minor < 2)) {
std::cerr << "--metal-version version must be at least 1.2. Have "
<< msl_version << std::endl;
}
Expand Down
62 changes: 36 additions & 26 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,40 @@ impeller_shaders("modern_entity_shaders") {
"shaders/radial_gradient_ssbo_fill.frag",
"shaders/sweep_gradient_ssbo_fill.frag",
]
if (is_ios && !use_ios_simulator) {
shaders += [
"shaders/blending/ios/framebuffer_blend.vert",
"shaders/blending/ios/framebuffer_blend_color.frag",
"shaders/blending/ios/framebuffer_blend_colorburn.frag",
"shaders/blending/ios/framebuffer_blend_colordodge.frag",
"shaders/blending/ios/framebuffer_blend_darken.frag",
"shaders/blending/ios/framebuffer_blend_difference.frag",
"shaders/blending/ios/framebuffer_blend_exclusion.frag",
"shaders/blending/ios/framebuffer_blend_hardlight.frag",
"shaders/blending/ios/framebuffer_blend_hue.frag",
"shaders/blending/ios/framebuffer_blend_lighten.frag",
"shaders/blending/ios/framebuffer_blend_luminosity.frag",
"shaders/blending/ios/framebuffer_blend_multiply.frag",
"shaders/blending/ios/framebuffer_blend_overlay.frag",
"shaders/blending/ios/framebuffer_blend_saturation.frag",
"shaders/blending/ios/framebuffer_blend_screen.frag",
"shaders/blending/ios/framebuffer_blend_softlight.frag",
]
}

impeller_shaders("framebuffer_blend_entity_shaders") {
name = "framebuffer_blend"

if (is_mac && !is_ios) {
# Note: this needs to correspond to the Apple7 Support family
# for M1 and M2.
metal_version = "2.3"
}

# This version is to disable malioc checks.
if (impeller_enable_opengles) {
gles_language_version = "460"
}

shaders = [
"shaders/blending/ios/framebuffer_blend.vert",
"shaders/blending/ios/framebuffer_blend_color.frag",
"shaders/blending/ios/framebuffer_blend_colorburn.frag",
"shaders/blending/ios/framebuffer_blend_colordodge.frag",
"shaders/blending/ios/framebuffer_blend_darken.frag",
"shaders/blending/ios/framebuffer_blend_difference.frag",
"shaders/blending/ios/framebuffer_blend_exclusion.frag",
"shaders/blending/ios/framebuffer_blend_hardlight.frag",
"shaders/blending/ios/framebuffer_blend_hue.frag",
"shaders/blending/ios/framebuffer_blend_lighten.frag",
"shaders/blending/ios/framebuffer_blend_luminosity.frag",
"shaders/blending/ios/framebuffer_blend_multiply.frag",
"shaders/blending/ios/framebuffer_blend_overlay.frag",
"shaders/blending/ios/framebuffer_blend_saturation.frag",
"shaders/blending/ios/framebuffer_blend_screen.frag",
"shaders/blending/ios/framebuffer_blend_softlight.frag",
]
}

impeller_component("entity") {
Expand Down Expand Up @@ -143,6 +157,8 @@ impeller_component("entity") {
"contents/filters/srgb_to_linear_filter_contents.h",
"contents/filters/yuv_to_rgb_filter_contents.cc",
"contents/filters/yuv_to_rgb_filter_contents.h",
"contents/framebuffer_blend_contents.cc",
"contents/framebuffer_blend_contents.h",
"contents/gradient_generator.cc",
"contents/gradient_generator.h",
"contents/linear_gradient_contents.cc",
Expand Down Expand Up @@ -179,15 +195,9 @@ impeller_component("entity") {
"inline_pass_context.h",
]

if (is_ios && !use_ios_simulator) {
sources += [
"contents/framebuffer_blend_contents.cc",
"contents/framebuffer_blend_contents.h",
]
}

public_deps = [
":entity_shaders",
":framebuffer_blend_entity_shaders",
":modern_entity_shaders",
"../archivist",
"../image",
Expand Down
64 changes: 31 additions & 33 deletions impeller/entity/contents/atlas_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/framebuffer_blend_contents.h"
#include "impeller/entity/contents/texture_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry.h"
Expand All @@ -22,10 +23,6 @@
#include "impeller/renderer/sampler_library.h"
#include "impeller/renderer/vertex_buffer_builder.h"

#ifdef FML_OS_PHYSICAL_IOS
#include "impeller/entity/contents/framebuffer_blend_contents.h"
#endif

namespace impeller {

AtlasContents::AtlasContents() = default;
Expand Down Expand Up @@ -224,38 +221,39 @@ bool AtlasContents::Render(const ContentContext& renderer,
dst_contents->SetSubAtlas(sub_atlas);
dst_contents->SetCoverage(sub_coverage);

#ifdef FML_OS_PHYSICAL_IOS
auto new_texture = renderer.MakeSubpass(
"Atlas Blend", sub_atlas->size,
[&](const ContentContext& context, RenderPass& pass) {
Entity entity;
entity.SetContents(dst_contents);
entity.SetBlendMode(BlendMode::kSource);
if (!entity.Render(context, pass)) {
return false;
}
if (blend_mode_ >= Entity::kLastPipelineBlendMode) {
auto contents = std::make_shared<FramebufferBlendContents>();
contents->SetBlendMode(blend_mode_);
contents->SetChildContents(src_contents);
entity.SetContents(std::move(contents));
std::shared_ptr<Texture> new_texture;
if (renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
new_texture = renderer.MakeSubpass(
"Atlas Blend", sub_atlas->size,
[&](const ContentContext& context, RenderPass& pass) {
Entity entity;
entity.SetContents(dst_contents);
entity.SetBlendMode(BlendMode::kSource);
if (!entity.Render(context, pass)) {
return false;
}
if (blend_mode_ >= Entity::kLastPipelineBlendMode) {
auto contents = std::make_shared<FramebufferBlendContents>();
contents->SetBlendMode(blend_mode_);
contents->SetChildContents(src_contents);
entity.SetContents(std::move(contents));
entity.SetBlendMode(BlendMode::kSource);
return entity.Render(context, pass);
}
entity.SetContents(src_contents);
entity.SetBlendMode(blend_mode_);
return entity.Render(context, pass);
}
entity.SetContents(src_contents);
entity.SetBlendMode(blend_mode_);
return entity.Render(context, pass);
});
#else
auto contents = ColorFilterContents::MakeBlend(
blend_mode_,
{FilterInput::Make(dst_contents), FilterInput::Make(src_contents)});
auto snapshot = contents->RenderToSnapshot(renderer, entity);
if (!snapshot.has_value()) {
return false;
});
} else {
auto contents = ColorFilterContents::MakeBlend(
blend_mode_,
{FilterInput::Make(dst_contents), FilterInput::Make(src_contents)});
auto snapshot = contents->RenderToSnapshot(renderer, entity);
if (!snapshot.has_value()) {
return false;
}
new_texture = snapshot.value().texture;
}
auto new_texture = snapshot.value().texture;
#endif

auto child_contents = AtlasTextureContents(*this);
child_contents.SetAlpha(alpha_);
Expand Down
65 changes: 32 additions & 33 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,38 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
sweep_gradient_ssbo_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientSSBOFillPipeline>(*context_);
}
if (context_->GetDeviceCapabilities().SupportsFramebufferFetch()) {
framebuffer_blend_color_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorPipeline>(*context_);
framebuffer_blend_colorburn_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorBurnPipeline>(*context_);
framebuffer_blend_colordodge_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorDodgePipeline>(*context_);
framebuffer_blend_darken_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendDarkenPipeline>(*context_);
framebuffer_blend_difference_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendDifferencePipeline>(*context_);
framebuffer_blend_exclusion_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendExclusionPipeline>(*context_);
framebuffer_blend_hardlight_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendHardLightPipeline>(*context_);
framebuffer_blend_hue_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendHuePipeline>(*context_);
framebuffer_blend_lighten_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendLightenPipeline>(*context_);
framebuffer_blend_luminosity_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendLuminosityPipeline>(*context_);
framebuffer_blend_multiply_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendMultiplyPipeline>(*context_);
framebuffer_blend_overlay_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendOverlayPipeline>(*context_);
framebuffer_blend_saturation_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendSaturationPipeline>(*context_);
framebuffer_blend_screen_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendScreenPipeline>(*context_);
framebuffer_blend_softlight_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendSoftLightPipeline>(*context_);
}

blend_color_pipelines_[{}] =
CreateDefaultPipeline<BlendColorPipeline>(*context_);
Expand Down Expand Up @@ -213,39 +245,6 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
CreateDefaultPipeline<BlendScreenPipeline>(*context_);
blend_softlight_pipelines_[{}] =
CreateDefaultPipeline<BlendSoftLightPipeline>(*context_);
#if FML_OS_PHYSICAL_IOS
framebuffer_blend_color_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorPipeline>(*context_);
framebuffer_blend_colorburn_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorBurnPipeline>(*context_);
framebuffer_blend_colordodge_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendColorDodgePipeline>(*context_);
framebuffer_blend_darken_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendDarkenPipeline>(*context_);
framebuffer_blend_difference_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendDifferencePipeline>(*context_);
framebuffer_blend_exclusion_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendExclusionPipeline>(*context_);
framebuffer_blend_hardlight_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendHardLightPipeline>(*context_);
framebuffer_blend_hue_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendHuePipeline>(*context_);
framebuffer_blend_lighten_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendLightenPipeline>(*context_);
framebuffer_blend_luminosity_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendLuminosityPipeline>(*context_);
framebuffer_blend_multiply_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendMultiplyPipeline>(*context_);
framebuffer_blend_overlay_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendOverlayPipeline>(*context_);
framebuffer_blend_saturation_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendSaturationPipeline>(*context_);
framebuffer_blend_screen_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendScreenPipeline>(*context_);
framebuffer_blend_softlight_pipelines_[{}] =
CreateDefaultPipeline<FramebufferBlendSoftLightPipeline>(*context_);
#endif // FML_OS_PHYSICAL_IOS

sweep_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientFillPipeline>(*context_);
rrect_blur_pipelines_[{}] =
Expand Down
Loading

0 comments on commit e763087

Please sign in to comment.