-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] use SSBOs for gradients where supported (metal/vulkan) #37654
Changes from 8 commits
ac5289a
a993117
1e0b407
6464e63
c6764e1
ad2913d
6205d78
0693dbd
da02aea
377b3e5
8428aea
b843436
652553e
21cc74a
283957a
642a3e9
ace492f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,20 @@ impeller_shaders("entity_shaders") { | |
| ] | ||
| } | ||
|
|
||
| impeller_shaders("modern_entity_shaders") { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
|
@@ -146,6 +160,7 @@ impeller_component("entity") { | |
|
|
||
| public_deps = [ | ||
| ":entity_shaders", | ||
| ":modern_entity_shaders", | ||
| "../archivist", | ||
| "../image", | ||
| "../renderer", | ||
|
|
||
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,13 +150,26 @@ ContentContext::ContentContext(std::shared_ptr<Context> context) | |
| if (!context_ || !context_->IsValid()) { | ||
| return; | ||
| } | ||
| #ifdef FML_OS_ANDROID | ||
|
||
| 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_[{}] = | ||
|
|
@@ -303,4 +316,8 @@ std::shared_ptr<Context> ContentContext::GetContext() const { | |
| return context_; | ||
| } | ||
|
|
||
| const BackendFeatures& ContentContext::GetBackendFeatures() const { | ||
| return backend_features_; | ||
| } | ||
|
|
||
| } // namespace impeller | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done