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 all 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
5 changes: 5 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,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 @@ -1291,6 +1292,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_ssbo_fill.frag
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 @@ -1299,6 +1301,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_ssbo_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 @@ -1307,6 +1310,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_ssbo_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 Expand Up @@ -1490,6 +1494,7 @@ FILE: ../../../flutter/impeller/renderer/backend/vulkan/texture_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/vertex_descriptor_vk.cc
FILE: ../../../flutter/impeller/renderer/backend/vulkan/vertex_descriptor_vk.h
FILE: ../../../flutter/impeller/renderer/backend/vulkan/vk.h
FILE: ../../../flutter/impeller/renderer/backend_features.h
FILE: ../../../flutter/impeller/renderer/blit_command.cc
FILE: ../../../flutter/impeller/renderer/blit_command.h
FILE: ../../../flutter/impeller/renderer/blit_pass.cc
Expand Down
1 change: 0 additions & 1 deletion impeller/compiler/code_gen_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ using Shader = {{camel_case(shader_name)}}{{camel_case(shader_stage)}}Shader;
// Sanity checks for {{def.name}}
{% if last(def.members).array_elements == 0 %}
static_assert(std::is_standard_layout_v<Shader::{{def.name}}<0>>);
static_assert(sizeof(Shader::{{def.name}}<0>) == {{def.byte_length}});
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 assert appears to be invalid on windows hosts, which claim this always has a sizeof 4.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I suppose having platform specific differences here is possible. Was the shader name in the generated shaders correct though?

{% for member in def.members %}
static_assert(offsetof(Shader::{{def.name}}<0>, {{member.name}}) == {{member.offset}});
{% endfor %}
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 @@ -73,6 +73,7 @@ bool Main(const fml::CommandLine& command_line) {
switches.source_file_name, options.type, options.source_language,
switches.entry_point);
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
24 changes: 24 additions & 0 deletions impeller/compiler/shader_lib/impeller/gradient.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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) {
float rough_index = (colors_length - 1) * 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
4 changes: 4 additions & 0 deletions impeller/compiler/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 @@ -124,6 +125,9 @@ Switches::Switches(const fml::CommandLine& command_line)
command_line.GetOptionValueWithDefault("reflection-cc", "")),
depfile_path(command_line.GetOptionValueWithDefault("depfile", "")),
json_format(command_line.HasOption("json")),
gles_language_version(
stoi(command_line.GetOptionValueWithDefault("gles-language-version",
"0"))),
entry_point(
command_line.GetOptionValueWithDefault("entry-point", "main")) {
if (!working_directory || !working_directory->is_valid()) {
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;
std::string entry_point;

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_ssbo_fill.frag",
"shaders/radial_gradient_ssbo_fill.frag",
"shaders/sweep_gradient_ssbo_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
12 changes: 12 additions & 0 deletions impeller/entity/contents/content_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
CreateDefaultPipeline<LinearGradientFillPipeline>(*context_);
radial_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<RadialGradientFillPipeline>(*context_);
if (context_->GetBackendFeatures().ssbo_support) {
linear_gradient_ssbo_fill_pipelines_[{}] =
CreateDefaultPipeline<LinearGradientSSBOFillPipeline>(*context_);
radial_gradient_ssbo_fill_pipelines_[{}] =
CreateDefaultPipeline<RadialGradientSSBOFillPipeline>(*context_);
sweep_gradient_ssbo_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientSSBOFillPipeline>(*context_);
}
sweep_gradient_fill_pipelines_[{}] =
CreateDefaultPipeline<SweepGradientFillPipeline>(*context_);
rrect_blur_pipelines_[{}] =
Expand Down Expand Up @@ -303,4 +311,8 @@ std::shared_ptr<Context> ContentContext::GetContext() const {
return context_;
}

const BackendFeatures& ContentContext::GetBackendFeatures() const {
return context_->GetBackendFeatures();
}

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

#include "impeller/typographer/glyph_atlas.h"

#include "impeller/entity/linear_gradient_ssbo_fill.frag.h"
#include "impeller/entity/radial_gradient_ssbo_fill.frag.h"
#include "impeller/entity/sweep_gradient_ssbo_fill.frag.h"

namespace impeller {

using LinearGradientFillPipeline =
Expand All @@ -82,6 +86,15 @@ using RadialGradientFillPipeline =
RenderPipelineT<GradientFillVertexShader, RadialGradientFillFragmentShader>;
using SweepGradientFillPipeline =
RenderPipelineT<GradientFillVertexShader, SweepGradientFillFragmentShader>;
using LinearGradientSSBOFillPipeline =
RenderPipelineT<GradientFillVertexShader,
LinearGradientSsboFillFragmentShader>;
using RadialGradientSSBOFillPipeline =
RenderPipelineT<GradientFillVertexShader,
RadialGradientSsboFillFragmentShader>;
using SweepGradientSSBOFillPipeline =
RenderPipelineT<GradientFillVertexShader,
SweepGradientSsboFillFragmentShader>;
using BlendPipeline = RenderPipelineT<BlendVertexShader, BlendFragmentShader>;
using RRectBlurPipeline =
RenderPipelineT<RrectBlurVertexShader, RrectBlurFragmentShader>;
Expand Down Expand Up @@ -210,6 +223,24 @@ class ContentContext {
return GetPipeline(linear_gradient_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetLinearGradientSSBOFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(GetBackendFeatures().ssbo_support);
return GetPipeline(linear_gradient_ssbo_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetRadialGradientSSBOFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(GetBackendFeatures().ssbo_support);
return GetPipeline(radial_gradient_ssbo_fill_pipelines_, opts);
}

std::shared_ptr<Pipeline<PipelineDescriptor>>
GetSweepGradientSSBOFillPipeline(ContentContextOptions opts) const {
FML_DCHECK(GetBackendFeatures().ssbo_support);
return GetPipeline(sweep_gradient_ssbo_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 +422,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 +449,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<LinearGradientSSBOFillPipeline>
linear_gradient_ssbo_fill_pipelines_;
mutable Variants<RadialGradientSSBOFillPipeline>
radial_gradient_ssbo_fill_pipelines_;
mutable Variants<SweepGradientSSBOFillPipeline>
sweep_gradient_ssbo_fill_pipelines_;
mutable Variants<RRectBlurPipeline> rrect_blur_pipelines_;
mutable Variants<BlendPipeline> texture_blend_pipelines_;
mutable Variants<TexturePipeline> texture_pipelines_;
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
66 changes: 65 additions & 1 deletion impeller/entity/contents/linear_gradient_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ void LinearGradientContents::SetTileMode(Entity::TileMode tile_mode) {
bool LinearGradientContents::Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
if (renderer.GetBackendFeatures().ssbo_support) {
return RenderSSBO(renderer, entity, pass);
}
return RenderTexture(renderer, entity, pass);
}

bool LinearGradientContents::RenderTexture(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = LinearGradientFillPipeline::VertexShader;
using FS = LinearGradientFillPipeline::FragmentShader;

auto gradient_data = CreateGradientBuffer(colors_, stops_);
auto gradient_texture =
CreateGradientTexture(colors_, stops_, renderer.GetContext());
CreateGradientTexture(gradient_data, renderer.GetContext());
if (gradient_texture == nullptr) {
return false;
}
Expand Down Expand Up @@ -106,4 +116,58 @@ bool LinearGradientContents::Render(const ContentContext& renderer,
return true;
}

bool LinearGradientContents::RenderSSBO(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const {
using VS = LinearGradientSSBOFillPipeline::VertexShader;
using FS = LinearGradientSSBOFillPipeline::FragmentShader;

FS::GradientInfo gradient_info;
gradient_info.start_point = start_point_;
gradient_info.end_point = end_point_;
gradient_info.tile_mode = static_cast<Scalar>(tile_mode_);
gradient_info.alpha = GetAlpha();

auto& host_buffer = pass.GetTransientsBuffer();
auto colors = CreateGradientColors(colors_, stops_).value_or(colors_);

gradient_info.colors_length = colors.size();
auto color_buffer = host_buffer.Emplace(
colors.data(), colors.size() * sizeof(Color), alignof(Color));

VS::FrameInfo frame_info;
frame_info.mvp = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) *
entity.GetTransformation();
frame_info.matrix = GetInverseMatrix();

Command cmd;
cmd.label = "LinearGradientSSBOFill";
cmd.stencil_reference = entity.GetStencilDepth();

auto geometry_result =
GetGeometry()->GetPositionBuffer(renderer, entity, pass);
auto options = OptionsFromPassAndEntity(pass, entity);
if (geometry_result.prevent_overdraw) {
options.stencil_compare = CompareFunction::kEqual;
options.stencil_operation = StencilOperation::kIncrementClamp;
}
options.primitive_type = geometry_result.type;
cmd.pipeline = renderer.GetLinearGradientSSBOFillPipeline(options);

cmd.BindVertices(geometry_result.vertex_buffer);
FS::BindGradientInfo(
cmd, pass.GetTransientsBuffer().EmplaceUniform(gradient_info));
FS::BindColorData(cmd, color_buffer);
VS::BindFrameInfo(cmd, pass.GetTransientsBuffer().EmplaceUniform(frame_info));

if (!pass.AddCommand(std::move(cmd))) {
return false;
}

if (geometry_result.prevent_overdraw) {
return ClipRestoreContents().Render(renderer, entity, pass);
}
return true;
}

} // namespace impeller
Loading