跳转至正文

Impeller 渲染引擎

什么是 Impeller,如何启用?

什么是 Impeller?

#

Impeller 为 Flutter 提供新的渲染运行时。Impeller 在引擎构建时预编译 smaller, simpler set of shaders(更小、更简单的着色器集),避免在运行时编译。

要了解 Impeller 的视频介绍,可观看 Google I/O 2023 的以下演讲。

Watch on YouTube in a new tab: "Introducing Impeller, Flutter's new rendering engine"

Impeller 的目标包括:

  • Predictable performance: Impeller compiles all shaders and reflection offline at build time. It builds all pipeline state objects upfront. The engine controls caching and caches explicitly.

  • 可预测的性能:Impeller 在构建时离线编译所有着色器与反射,预先构建所有管线状态对象,由引擎显式控制缓存。

  • Instrumentable: Impeller tags and labels all graphics resources, such as textures and buffers. It can capture and persist animations to disk without affecting per-frame rendering performance.

  • 可观测:Impeller 为纹理、缓冲区等图形资源打标签,可在不影响每帧渲染性能的情况下捕获动画并持久化到磁盘。

  • Portable: Flutter doesn't tie Impeller to a specific client-rendering API. You can author shaders once and convert them to backend-specific formats, as necessary.

  • 可移植:Flutter 不将 Impeller 绑定到特定客户端渲染 API,可一次编写着色器并按需转换为后端格式。

  • Leverages modern graphics APIs: Impeller uses, but doesn't depend on, features available in modern APIs like Metal and Vulkan.

  • 利用现代图形 API:Impeller 使用 Metal、Vulkan 等现代 API 的特性,但不依赖它们。

  • Leverages concurrency: Impeller can distribute single-frame workloads across multiple threads, if necessary.

  • 利用并发:必要时 Impeller 可将单帧工作负载分布到多个线程。

可用性

#

在哪里可以使用 Impeller?详细 信息请参阅 Can I use Impeller? 页面。

iOS

#

iOS

#

Impeller 是 iOS 上 唯一支持 的渲染引擎,无法切换回 Skia。

Android

#

Android

#

Impeller 在 Android API 29+ 上默认可用并已启用。在较低 Android 版本或不支持 Vulkan 的设备上,Impeller 会回退到旧版 OpenGL 渲染器。你无需为此回退行为做任何操作。

  • To disable Impeller when debugging, pass --no-enable-impeller to the flutter run command.

  • 调试时 禁用 Impeller,向 flutter run 传入 --no-enable-impeller

    flutter run --no-enable-impeller
    
  • To disable Impeller when deploying your app, add the following setting to your project's AndroidManifest.xml file under the <application> tag:

  • 部署应用时 禁用 Impeller,在项目的 AndroidManifest.xml<application> 标签下添加以下设置:

xml
<meta-data
    android:name="io.flutter.embedding.android.EnableImpeller"
    android:value="false" />

Web

#

Web

#

Flutter Web 提供 two renderers(两种渲染器)——canvaskitskwasm——目前均使用 Skia,未来可能使用 Impeller。

macOS

#

macOS

#

可通过标志在 macOS 上试用 Impeller。未来版本将移除选择不使用 Impeller 的选项。

macOS 调试时启用 Impeller,向 flutter run 传入 --enable-impeller

flutter run --enable-impeller

macOS 部署时启用 Impeller,在应用 Info.plist 顶层 <dict> 标签下添加以下内容:

xml
  <key>FLTEnableImpeller</key>
  <true />

Bug 与 issue

#

团队持续改进 Impeller 支持。若在任何平台上遇到 Impeller 的性能或保真度问题,请在 GitHub tracker 提交 issue,标题以 [Impeller] 为前缀,并附上可复现的小型测试用例。

提交 Impeller 相关 issue 时请包含以下信息:

  • The device you are running on, including the chip information.

  • 运行设备,包括芯片信息。

  • Screenshots or recordings of any visible issues.

  • 任何可见问题的截图或录屏。

  • An export of the performance trace. Zip the file and attach it to the GitHub issue.

  • export of the performance trace(性能跟踪导出)。将文件 zip 后附在 GitHub issue 中。

架构

#

要了解 Impeller 设计与架构的更多细节,请参阅源码树中的 README.md 文件。

更多信息

#