This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] skip mip generation if blur downsample is factor is 0.5 or greater #53635
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,13 +5,16 @@ | |||||
#include "impeller/entity/contents/filters/gaussian_blur_filter_contents.h" | ||||||
|
||||||
#include <cmath> | ||||||
#include <optional> | ||||||
|
||||||
#include "flutter/fml/make_copyable.h" | ||||||
#include "impeller/core/formats.h" | ||||||
#include "impeller/entity/contents/clip_contents.h" | ||||||
#include "impeller/entity/contents/content_context.h" | ||||||
#include "impeller/entity/texture_fill.frag.h" | ||||||
#include "impeller/entity/texture_fill.vert.h" | ||||||
#include "impeller/renderer/render_pass.h" | ||||||
#include "impeller/renderer/texture_mipmap.h" | ||||||
#include "impeller/renderer/vertex_buffer_builder.h" | ||||||
|
||||||
namespace impeller { | ||||||
|
@@ -147,12 +150,6 @@ std::optional<Snapshot> GetSnapshot(const std::shared_ptr<FilterInput>& input, | |||||
return std::nullopt; | ||||||
} | ||||||
|
||||||
// In order to avoid shimmering in downsampling step, we should have mips. | ||||||
if (input_snapshot->texture->GetMipCount() <= 1) { | ||||||
FML_DLOG(ERROR) << GaussianBlurFilterContents::kNoMipsError; | ||||||
} | ||||||
FML_DCHECK(!input_snapshot->texture->NeedsMipmapGeneration()); | ||||||
|
||||||
return input_snapshot; | ||||||
} | ||||||
|
||||||
|
@@ -242,9 +239,6 @@ DownsamplePassArgs CalculateDownsamplePassArgs( | |||||
Scalar desired_scalar = | ||||||
std::min(GaussianBlurFilterContents::CalculateScale(scaled_sigma.x), | ||||||
GaussianBlurFilterContents::CalculateScale(scaled_sigma.y)); | ||||||
// TODO(jonahwilliams): If desired_scalar is 1.0 and we fully acquired the | ||||||
// gutter from the expanded_coverage_hint, we can skip the downsample pass. | ||||||
// pass. | ||||||
Vector2 downsample_scalar(desired_scalar, desired_scalar); | ||||||
// TODO(gaaclarke): The padding could be removed if we know it's not needed or | ||||||
// resized to account for the expanded_clip_coverage. There doesn't appear | ||||||
|
@@ -326,7 +320,8 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass( | |||||
std::shared_ptr<Texture> input_texture, | ||||||
const SamplerDescriptor& sampler_descriptor, | ||||||
const DownsamplePassArgs& pass_args, | ||||||
Entity::TileMode tile_mode) { | ||||||
Entity::TileMode tile_mode, | ||||||
bool min_lod_clamp) { | ||||||
ContentContext::SubpassCallback subpass_callback = | ||||||
[&](const ContentContext& renderer, RenderPass& pass) { | ||||||
HostBuffer& host_buffer = renderer.GetTransientsBuffer(); | ||||||
|
@@ -356,6 +351,9 @@ fml::StatusOr<RenderTarget> MakeDownsampleSubpass( | |||||
SetTileMode(&linear_sampler_descriptor, renderer, tile_mode); | ||||||
linear_sampler_descriptor.mag_filter = MinMagFilter::kLinear; | ||||||
linear_sampler_descriptor.min_filter = MinMagFilter::kLinear; | ||||||
if (min_lod_clamp) { | ||||||
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. With a downsample factor of 0.5, by default we will try to sample from mip level 1 instead of 0. But forcing 0 and using linear filtering is sufficient to not lose quality. |
||||||
linear_sampler_descriptor.mip_filter = MipFilter::kBase; | ||||||
} | ||||||
TextureFillVertexShader::BindFrameInfo( | ||||||
pass, host_buffer.EmplaceUniform(frame_info)); | ||||||
TextureFillFragmentShader::BindFragInfo( | ||||||
|
@@ -537,9 +535,6 @@ Entity ApplyBlurStyle(FilterContents::BlurStyle blur_style, | |||||
} | ||||||
} // namespace | ||||||
|
||||||
std::string_view GaussianBlurFilterContents::kNoMipsError = | ||||||
"Applying gaussian blur without mipmap."; | ||||||
|
||||||
GaussianBlurFilterContents::GaussianBlurFilterContents( | ||||||
Scalar sigma_x, | ||||||
Scalar sigma_y, | ||||||
|
@@ -679,9 +674,23 @@ std::optional<Entity> GaussianBlurFilterContents::RenderFilter( | |||||
blur_info.scaled_sigma, blur_info.padding, input_snapshot.value(), | ||||||
source_expanded_coverage_hint, inputs[0], snapshot_entity); | ||||||
|
||||||
fml::StatusOr<RenderTarget> pass1_out = MakeDownsampleSubpass( | ||||||
renderer, command_buffer, input_snapshot->texture, | ||||||
input_snapshot->sampler_descriptor, downsample_pass_args, tile_mode_); | ||||||
// If a blur scalar is less than 0.5, generate mipmaps. Otherwise, the | ||||||
// bilinear filtering of the base mip level is sufficient to preserve quality. | ||||||
bool generated_mips = false; | ||||||
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.
Suggested change
|
||||||
if (downsample_pass_args.effective_scalar.x < 0.5 || | ||||||
downsample_pass_args.effective_scalar.y < 0.5) { | ||||||
if (!AddMipmapGeneration(command_buffer, renderer.GetContext(), | ||||||
input_snapshot->texture) | ||||||
.ok()) { | ||||||
return std::nullopt; | ||||||
} | ||||||
generated_mips = true; | ||||||
} | ||||||
|
||||||
fml::StatusOr<RenderTarget> pass1_out = | ||||||
MakeDownsampleSubpass(renderer, command_buffer, input_snapshot->texture, | ||||||
input_snapshot->sampler_descriptor, | ||||||
downsample_pass_args, tile_mode_, !generated_mips); | ||||||
|
||||||
if (!pass1_out.ok()) { | ||||||
return std::nullopt; | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.