Skip to content

[Impeller] Add anisotropic filtering support to samplers#188056

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bdero:bdero/impeller-anisotropic-filtering
Jun 25, 2026
Merged

[Impeller] Add anisotropic filtering support to samplers#188056
auto-submit[bot] merged 5 commits into
flutter:masterfrom
bdero:bdero/impeller-anisotropic-filtering

Conversation

@bdero

@bdero bdero commented Jun 16, 2026

Copy link
Copy Markdown
Member

Adds anisotropic texture filtering to Impeller and surfaces it through Flutter GPU. Anisotropic filtering is a sampler read-time setting, so this needs no changes to attachments or texture upload.

A new max_anisotropy field on SamplerDescriptor sets the maximum anisotropy clamp, where 1 disables anisotropic filtering (matching WebGPU). It is implemented across all three backends.

  • Metal sets maxAnisotropy on MTLSamplerDescriptor, which every device supports.
  • Vulkan enables the samplerAnisotropy device feature when available and clamps to maxSamplerAnisotropy in SamplerLibraryVK.
  • OpenGL ES applies GL_TEXTURE_MAX_ANISOTROPY_EXT when GL_EXT_texture_filter_anisotropic is present, using only core ES 2.0 entry points (GetFloatv and TexParameterfv).

The device limit is reported by Capabilities::GetMaxSamplerAnisotropy, where 1 means anisotropic filtering is unsupported. Flutter GPU adds SamplerOptions.maxAnisotropy and GpuContext.maxSamplerAnisotropy, and requires all filters to be linear when anisotropy is enabled.

Anisotropic minification reads across the mip chain... so callers populate mips with Texture.overwrite or by rendering into them, consistent with the existing mip and slice support.

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 16, 2026
@bdero bdero added e: impeller Impeller rendering backend issues and features requests flutter-gpu labels Jun 16, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests flutter-gpu team-fluttergpu Owned by Flutter GPU team labels Jun 16, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU Jun 16, 2026
@bdero
bdero force-pushed the bdero/impeller-anisotropic-filtering branch from 7e2f369 to da3c015 Compare June 16, 2026 05:09
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 16, 2026
@bdero bdero added the CICD Run CI/CD label Jun 19, 2026
@bdero
bdero marked this pull request as ready for review June 19, 2026 04:03

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for anisotropic filtering across the GLES, Metal, and Vulkan backends in Impeller, exposing the capability to the Flutter GPU Dart API. It introduces max_anisotropy to SamplerDescriptor, implements device capability queries, and adds validation to ensure anisotropic filtering is only configured when linear filtering is active. Feedback points out a potential undefined behavior issue in the Vulkan backend where std::clamp could be invoked with a lower bound greater than the upper bound if the device's reported maximum anisotropy is less than 1.0.

Comment thread engine/src/flutter/impeller/renderer/backend/vulkan/sampler_library_vk.cc Outdated
Adds a max_anisotropy field to SamplerDescriptor (1 disables anisotropic
filtering, matching WebGPU) and implements it on all three backends.

- Metal sets maxAnisotropy on MTLSamplerDescriptor, always supported.
- Vulkan enables the samplerAnisotropy device feature when available and
  clamps to maxSamplerAnisotropy in SamplerLibraryVK.
- GLES applies GL_TEXTURE_MAX_ANISOTROPY_EXT when
  GL_EXT_texture_filter_anisotropic is present, using only core ES 2.0
  entry points (GetFloatv/TexParameterfv).

The device limit is exposed via Capabilities::GetMaxSamplerAnisotropy
(1 means unsupported). Flutter GPU exposes SamplerOptions.maxAnisotropy
and GpuContext.maxSamplerAnisotropy, requiring all filters to be linear
when anisotropy is enabled.
@bdero
bdero force-pushed the bdero/impeller-anisotropic-filtering branch from da3c015 to a5c1419 Compare June 19, 2026 04:13
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 19, 2026
@bdero bdero added the CICD Run CI/CD label Jun 19, 2026
@gaaclarke
gaaclarke requested a review from b-luk June 22, 2026 18:11
@gaaclarke

Copy link
Copy Markdown
Member

@bdero heads up, those test failures look like they may be apropos

@b-luk can you help brandon by reviewing this (once the tests are green)?

bdero added 2 commits June 22, 2026 16:04
Guards against std::clamp seeing an inverted range if a driver reports a
max anisotropy below 1. The real path always reports at least 1, so this
is defensive.
The success-path assertion bound a sampler to a non-texture uniform slot,
which fails at the FFI with "Failed to bind texture". The two validation
throw assertions cover the test's purpose.
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 22, 2026
@bdero bdero added the CICD Run CI/CD label Jun 22, 2026
b-luk
b-luk previously approved these changes Jun 23, 2026

@b-luk b-luk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

gaaclarke
gaaclarke previously approved these changes Jun 23, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm, one question about types since we sometimes use float, sometimes double, sometimes int. Often times we opt for "Scalar"for floating point values, I'm not sure if that makes sense here though.

return max_texture_size;
}

float CapabilitiesGLES::GetMaxSamplerAnisotropy() const {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is float the right type for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah we should change it to int. GL/VK use floats, but it's actually an int ceiling. Metal uses ints. Done.

/// Anisotropic filtering samples across the mip chain, so populate mip
/// levels (via [Texture.overwrite] or by rendering into them) to get the
/// full quality benefit.
int maxAnisotropy;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here it is an integer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Switched to int everywhere

The device max anisotropy was a float mirroring the Vulkan and GL source,
but it is only ever used as an integer ceiling and the public value is an
integer. Return uint32_t from the capability and int from the Dart getter
so the value and the limit are consistent.
@bdero
bdero dismissed stale reviews from gaaclarke and b-luk via 905a17b June 24, 2026 03:14
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 24, 2026
@bdero bdero added the CICD Run CI/CD label Jun 24, 2026
@bdero
bdero requested review from b-luk and gaaclarke June 24, 2026 22:33

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 25, 2026
@bdero bdero added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Jun 25, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jun 25, 2026
Merged via the queue into flutter:master with commit a97fc48 Jun 25, 2026
208 checks passed
@github-project-automation github-project-automation Bot moved this from 🤔 Needs Triage to ✅ Done in Flutter GPU Jun 25, 2026
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants