Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] skip mip generation if blur downsample is factor is 0.5 or greater #53635

Closed
wants to merge 2 commits into from

Conversation

jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jun 28, 2024

THe downsample uses bilinear filtering to read from the input texture. To avoid dropping data, we generate mipmaps. However if the downscale factor is 0.5 or 1.0, then we don't need to read from any of the mip levels besides the base. Skip mip generation in this case, since its very expensive.

Additionally, mip generation is moved into the blur, rather than checking for mips and erroring - we generate mips if needed - removing an error condition.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

@jonahwilliams jonahwilliams requested a review from gaaclarke June 28, 2024 17:51
@jonahwilliams
Copy link
Member Author

It looks like this causes a validation failure on metal, even if we won't end up reading from a higher mip level. Potentially more fuel for separating out bdfs and image filter blurs, since at least in the later case we can compute exactly how many mip levels (if any) we need.

@jonahwilliams jonahwilliams marked this pull request as draft June 28, 2024 19:19
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

I don't know if we have a test that will hit this. I think adding a golden test that sets the sigma values to something really small would be prudent.

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool min_lod_clamp) {
bool use_base_mip) {

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool generated_mips = false;
bool use_base_mip = true;

@jonahwilliams
Copy link
Member Author

Tests did hit this, hence the failure and my comment :)

@jonahwilliams
Copy link
Member Author

Closing in favor of #53760

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants