Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,7 @@ FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/branching.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/color.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/constants.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gaussian.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/gradient.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/texture.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/transform.glsl
FILE: ../../../flutter/impeller/compiler/shader_lib/impeller/types.glsl
Expand Down Expand Up @@ -1285,6 +1286,7 @@ FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.frag
FILE: ../../../flutter/impeller/entity/shaders/glyph_atlas_sdf.vert
FILE: ../../../flutter/impeller/entity/shaders/gradient_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/linear_gradient_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/linear_gradient_fixed_fill.frag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets call this ssbo_fill perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

FILE: ../../../flutter/impeller/entity/shaders/linear_to_srgb_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/linear_to_srgb_filter.vert
FILE: ../../../flutter/impeller/entity/shaders/morphology_filter.frag
Expand All @@ -1293,6 +1295,7 @@ FILE: ../../../flutter/impeller/entity/shaders/position.vert
FILE: ../../../flutter/impeller/entity/shaders/position_color.vert
FILE: ../../../flutter/impeller/entity/shaders/position_uv.vert
FILE: ../../../flutter/impeller/entity/shaders/radial_gradient_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/radial_gradient_fixed_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/rrect_blur.frag
FILE: ../../../flutter/impeller/entity/shaders/rrect_blur.vert
FILE: ../../../flutter/impeller/entity/shaders/runtime_effect.vert
Expand All @@ -1301,6 +1304,7 @@ FILE: ../../../flutter/impeller/entity/shaders/solid_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/srgb_to_linear_filter.frag
FILE: ../../../flutter/impeller/entity/shaders/srgb_to_linear_filter.vert
FILE: ../../../flutter/impeller/entity/shaders/sweep_gradient_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/sweep_gradient_fixed_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.frag
FILE: ../../../flutter/impeller/entity/shaders/texture_fill.vert
FILE: ../../../flutter/impeller/entity/shaders/tiled_texture_fill.frag
Expand Down
8 changes: 6 additions & 2 deletions impeller/compiler/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ static CompilerBackend CreateGLSLCompiler(const spirv_cross::ParsedIR& ir,
sl_options.force_zero_initialized_variables = true;
sl_options.vertex.fixup_clipspace = true;
if (source_options.target_platform == TargetPlatform::kOpenGLES) {
sl_options.version = 100;
sl_options.version = source_options.gles_language_version > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should do source language selection based on #version directives now instead of applying command line options. Omitting them was fine when we only had a single version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that sounds reasonable, but I'm not quite sure how to make make shaderc and spirvcross work together on this. I'll file a bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? source_options.gles_language_version
: 100;
sl_options.es = true;
} else {
sl_options.version = 120;
sl_options.version = source_options.gles_language_version > 0
? source_options.gles_language_version
: 120;
sl_options.es = false;
}
gl_compiler->set_common_options(sl_options);
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/impellerc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ bool Main(const fml::CommandLine& command_line) {
options.entry_point_name = EntryPointFunctionNameFromSourceName(
switches.source_file_name, options.type, options.source_language);
options.json_format = switches.json_format;
options.gles_language_version = switches.gles_language_version;

Reflector::Options reflector_options;
reflector_options.target_platform = switches.target_platform;
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/shader_lib/impeller/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ copy("impeller") {
"color.glsl",
"constants.glsl",
"gaussian.glsl",
"gradient.glsl",
"texture.glsl",
"transform.glsl",
"types.glsl",
Expand Down
28 changes: 28 additions & 0 deletions impeller/compiler/shader_lib/impeller/gradient.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

#ifndef GRADIENT_GLSL_
#define GRADIENT_GLSL_

#include <impeller/texture.glsl>

/// Compute the indexes and mix coefficient used to mix colors for an
/// arbitrarily sized color gradient.
///
/// The returned values are the lower index, upper index, and mix
/// coefficient.
vec3 IPComputeFixedGradientValues(float t, float colors_length) {
if (colors_length == 2) {
return vec3(0, 1, t);
}

float rough_index = colors_length * t;
float lower_index = floor(rough_index);
float upper_index = ceil(rough_index);
float scale = rough_index - lower_index;

return vec3(lower_index, upper_index, scale);
}

#endif
1 change: 1 addition & 0 deletions impeller/compiler/source_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct SourceOptions {
std::vector<IncludeDir> include_dirs;
std::string file_name = "main.glsl";
std::string entry_point_name = "main";
uint32_t gles_language_version = 100;
std::vector<std::string> defines;
bool json_format = false;

Expand Down
6 changes: 5 additions & 1 deletion impeller/compiler/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void Switches::PrintHelp(std::ostream& stream) {
stream << "[optional,multiple] --include=<include_directory>" << std::endl;
stream << "[optional,multiple] --define=<define>" << std::endl;
stream << "[optional] --depfile=<depfile_path>" << std::endl;
stream << "[optional] --gles-language-verision=<number>" << std::endl;
stream << "[optional] --json" << std::endl;
}

Expand Down Expand Up @@ -120,7 +121,10 @@ Switches::Switches(const fml::CommandLine& command_line)
reflection_cc_name(
command_line.GetOptionValueWithDefault("reflection-cc", "")),
depfile_path(command_line.GetOptionValueWithDefault("depfile", "")),
json_format(command_line.HasOption("json")) {
json_format(command_line.HasOption("json")),
gles_language_version(
stoi(command_line.GetOptionValueWithDefault("gles-language-version",
"0"))) {
if (!working_directory || !working_directory->is_valid()) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions impeller/compiler/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Switches {
std::vector<std::string> defines;
bool json_format;
SourceLanguage source_language = SourceLanguage::kUnknown;
uint32_t gles_language_version;

Switches();

Expand Down
15 changes: 15 additions & 0 deletions impeller/entity/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ impeller_shaders("entity_shaders") {
]
}

impeller_shaders("modern_entity_shaders") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost works, except that I fail to load the fixed_fill shaders at runtime. I suspect something somewhere is hard coded but I haven't found it. If I place these shaders in the entity shaders set (and force the gles_language version to 460 everywhere) it works as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

name = "modern"

if (impeller_enable_opengles) {
gles_language_version = "460"
}

shaders = [
"shaders/linear_gradient_fixed_fill.frag",
"shaders/radial_gradient_fixed_fill.frag",
"shaders/sweep_gradient_fixed_fill.frag",
]
}

impeller_component("entity") {
sources = [
"contents/atlas_contents.cc",
Expand Down Expand Up @@ -146,6 +160,7 @@ impeller_component("entity") {

public_deps = [
":entity_shaders",
":modern_entity_shaders",
"../archivist",
"../image",
"../renderer",
Expand Down
21 changes: 21 additions & 0 deletions impeller/entity/contents/backend_features.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

#pragma once

namespace impeller {

/// @brief A struct for describing available backend features for runtime
/// selection.
struct BackendFeatures {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was thinking of this being an enum with the modern stuff implying SSBO support. But this is way better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bool ssbo_support;
};

/// @brief feature sets available on most but not all modern hardware.
constexpr BackendFeatures kModernBackendFeatures = {.ssbo_support = true};

/// @brief Lowest common denominator feature sets.
constexpr BackendFeatures kLegacyBackendFeatures = {.ssbo_support = false};

} // namespace impeller
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline at EOF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

17 changes: 17 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,26 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
if (!context_ || !context_->IsValid()) {
return;
}
#ifdef FML_OS_ANDROID
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBD: actual feature selection when we have vulkan support

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider having a define for IMPELLER_SUPPORT_SSBO that's just IMPELLER_ENABLE_METAL || IMPELLER_ENABLE_VULKAN. Or just use the more verbose one here. You'll need some runtime detection, so an update to the Context object to have some method or struct or something that says whether SSBOs are allowed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see some of the runtime stuff is started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to leave this as runtime support as far as I can tell, once Vulkan is on by default. Avoids literring the code base with ifdefs too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have this on on impeller::Context instead? You can ask the context for its feature set. That way, only ES will return the legacy stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

backend_features_ = kLegacyBackendFeatures;
#else
backend_features_ = kModernBackendFeatures;
#endif // FML_OS_ANDROID

solid_fill_pipelines_[{}] =
CreateDefaultPipeline<SolidFillPipeline>(*context_);
linear_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<LinearGradientFillPipeline>(*context_);
radial_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<RadialGradientFillPipeline>(*context_);
if (backend_features_.ssbo_support) {
linear_gradient_fixed_fill_pipelines_[{}] =
CreateDefaultPipeline<LinearGradientFixedFillPipeline>(*context_);
radial_gradient_fixed_fill_pipelines_[{}] =
CreateDefaultPipeline<RadialGradientFixedFillPipeline>(*context_);
sweep_gradient_fixed_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientFixedFillPipeline>(*context_);
}
sweep_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientFillPipeline>(*context_);
rrect_blur_pipelines_[{}] =
Expand Down Expand Up @@ -303,4 +316,8 @@ std::shared_ptr<Context> ContentContext::GetContext() const {
return context_;
}

const BackendFeatures& ContentContext::GetBackendFeatures() const {
return backend_features_;
}

} // namespace impeller
42 changes: 42 additions & 0 deletions impeller/entity/contents/content_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@

#include "impeller/typographer/glyph_atlas.h"

#include "impeller/entity/linear_gradient_fixed_fill.frag.h"
#include "impeller/entity/radial_gradient_fixed_fill.frag.h"
#include "impeller/entity/sweep_gradient_fixed_fill.frag.h"

#include "impeller/entity/contents/backend_features.h"

namespace impeller {

using LinearGradientFillPipeline =
Expand All @@ -82,6 +88,15 @@ using RadialGradientFillPipeline =
RenderPipelineT<GradientFillVertexShader, RadialGradientFillFragmentShader>;
using SweepGradientFillPipeline =
RenderPipelineT<GradientFillVertexShader, SweepGradientFillFragmentShader>;
using LinearGradientFixedFillPipeline =
RenderPipelineT<GradientFillVertexShader,
LinearGradientFixedFillFragmentShader>;
using RadialGradientFixedFillPipeline =
RenderPipelineT<GradientFillVertexShader,
RadialGradientFixedFillFragmentShader>;
using SweepGradientFixedFillPipeline =
RenderPipelineT<GradientFillVertexShader,
SweepGradientFixedFillFragmentShader>;
using BlendPipeline = RenderPipelineT<BlendVertexShader, BlendFragmentShader>;
using RRectBlurPipeline =
RenderPipelineT<RrectBlurVertexShader, RrectBlurFragmentShader>;
Expand Down Expand Up @@ -210,6 +225,24 @@ class ContentContext {
return GetPipeline(linear_gradient_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetLinearGradientFixedFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(backend_features_.ssbo_support);
return GetPipeline(linear_gradient_fixed_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetRadialGradientFixedFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(backend_features_.ssbo_support);
return GetPipeline(radial_gradient_fixed_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetSweepGradientFixedFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(backend_features_.ssbo_support);
return GetPipeline(sweep_gradient_fixed_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>> GetRadialGradientFillPipeline(
ContentContextOptions opts) const {
return GetPipeline(radial_gradient_fill_pipelines_, opts);
Expand Down Expand Up @@ -391,6 +424,8 @@ class ContentContext {

std::shared_ptr<GlyphAtlasContext> GetGlyphAtlasContext() const;

const BackendFeatures& GetBackendFeatures() const;

using SubpassCallback =
std::function<bool(const ContentContext&, RenderPass&)>;

Expand All @@ -416,6 +451,12 @@ class ContentContext {
mutable Variants<LinearGradientFillPipeline> linear_gradient_fill_pipelines_;
mutable Variants<RadialGradientFillPipeline> radial_gradient_fill_pipelines_;
mutable Variants<SweepGradientFillPipeline> sweep_gradient_fill_pipelines_;
mutable Variants<LinearGradientFixedFillPipeline>
linear_gradient_fixed_fill_pipelines_;
mutable Variants<RadialGradientFixedFillPipeline>
radial_gradient_fixed_fill_pipelines_;
mutable Variants<SweepGradientFixedFillPipeline>
sweep_gradient_fixed_fill_pipelines_;
mutable Variants<RRectBlurPipeline> rrect_blur_pipelines_;
mutable Variants<BlendPipeline> texture_blend_pipelines_;
mutable Variants<TexturePipeline> texture_pipelines_;
Expand Down Expand Up @@ -483,6 +524,7 @@ class ContentContext {
bool is_valid_ = false;
std::shared_ptr<Tessellator> tessellator_;
std::shared_ptr<GlyphAtlasContext> glyph_atlas_context_;
BackendFeatures backend_features_;

FML_DISALLOW_COPY_AND_ASSIGN(ContentContext);
};
Expand Down
5 changes: 1 addition & 4 deletions impeller/entity/contents/gradient_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@

#include "flutter/fml/logging.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/geometry/gradient.h"
#include "impeller/renderer/context.h"
#include "impeller/renderer/render_pass.h"
#include "impeller/renderer/texture.h"

namespace impeller {

std::shared_ptr<Texture> CreateGradientTexture(
const std::vector<Color>& colors,
const std::vector<Scalar>& stops,
const GradientData& gradient_data,
const std::shared_ptr<impeller::Context>& context) {
auto gradient_data = CreateGradientBuffer(colors, stops);
if (gradient_data.texture_size == 0) {
FML_DLOG(ERROR) << "Invalid gradient data.";
return nullptr;
Expand Down
6 changes: 3 additions & 3 deletions impeller/entity/contents/gradient_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "flutter/fml/macros.h"
#include "flutter/impeller/renderer/texture.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/gradient.h"
#include "impeller/geometry/path.h"
#include "impeller/geometry/point.h"

Expand All @@ -20,11 +21,10 @@ class Context;

/**
* @brief Create a host visible texture that contains the gradient defined
* by the provided colors and stops.
* by the provided gradient data.
*/
std::shared_ptr<Texture> CreateGradientTexture(
const std::vector<Color>& colors,
const std::vector<Scalar>& stops,
const GradientData& gradient_data,
const std::shared_ptr<impeller::Context>& context);

} // namespace impeller
Loading