ITADN
linebender/vello · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

Vello

以 GPU 计算为核心的 2D 渲染器

Linebender Zulip dependency status Apache 2.0 or MIT license. wgpu version

Crates.io Docs Build status

Vello 是一个用 Rust 编写的 2D 图形渲染引擎,专注于 GPU 计算。 它可以使用 wgpu 进行 GPU 访问,以交互式或接近交互式的性能绘制大型 2D 场景。

运行示例程序的快速入门:

cargo run -p with_winit

image

它被用作 Xilem(一个 Rust GUI 工具包)的渲染后端。

[!WARNING] Vello 目前可被视为处于 alpha 阶段。特别是,我们仍在处理以下事项:

重大更改记录在 the changelog 中。

动机

Vello 旨在在图形栈中占据与其他矢量图形渲染器(如 SkiaCairo 及其前身项目 Piet)相同的位置。 从基本层面来说,这意味着它提供使用 PostScript 风格 API 来渲染形状、图像、渐变、文本等工具,该 API 同样驱动着 SVG 文件和 the browser <canvas> 元素

Vello 的卖点是,通过更好地利用 GPU,它比其他渲染器获得更好的性能。 在传统 PostScript 风格的渲染器中,渲染过程的某些步骤(如排序和裁剪)要么需要在 CPU 上处理,要么通过使用中间纹理来完成。 Vello 通过使用前缀和算法来并行化通常需要顺序执行的工作,从而避免了这一点,以便将工作卸载到 GPU,同时最大限度地减少临时缓冲区的使用。

这意味着 Vello 需要支持计算着色器的 GPU 才能运行。

入门

Vello 旨在深度集成到 UI 渲染栈中。 虽然在 Vello 场景中绘制很简单,但将该场景实际渲染到表面需要设置 wgpu 上下文,这是一项非平凡的任务。

要将 Vello 用作您的 PDF 阅读器 / GUI 工具包 / 等的渲染器,您的代码大致需要如下所示:

use vello::{
    kurbo::{Affine, Circle},
    peniko::{Color, Fill},
    *,
};

// Initialize wgpu and get handles
let (width, height) = ...;
let device: wgpu::Device = ...;
let queue: wgpu::Queue = ...;
let mut renderer = Renderer::new(
   &device,
   RendererOptions::default()
).expect("Failed to create renderer");
// Create scene and draw stuff in it
let mut scene = vello::Scene::new();
scene.fill(
   vello::peniko::Fill::NonZero,
   vello::Affine::IDENTITY,
   vello::Color::from_rgb8(242, 140, 168),
   None,
   &vello::Circle::new((420.0, 200.0), 120.0),
);
// Draw more stuff
scene.push_layer(...);
scene.fill(...);
scene.stroke(...);
scene.pop_layer(...);
let texture = device.create_texture(&...);

// Render to a wgpu Texture
renderer
   .render_to_texture(
      &device,
      &queue,
      &scene,
      &texture,
      &vello::RenderParams {
         base_color: palette::css::BLACK, // Background color
         width,
         height,
         antialiasing_method: AaConfig::Msaa16,
      },
   )
   .expect("Failed to render to a texture");
// Do things with `texture`, such as blitting it to the Surface using
// wgpu::util::TextureBlitter

请参阅 examples 目录,其中包含与 winit 等框架集成的代码。

Performance

我们在 M1 Max 上以 1600 像素见方的分辨率运行 paris-30k 测试场景时,观察到 177 fps,这是出色的性能,代表了该引擎的某种最佳情况。

更正式的基准测试即将到来。

Integrations

SVG

一个用于渲染 SVG 文件的独立 Linebender 集成可通过 vello_svg 获取。

Lottie

一个用于播放 Lottie 动画的独立 Linebender 集成可通过 velato 获取。

Bevy

一个用于在 Bevy 中通过 bevy_vello 渲染原始场景或 Lottie 和 SVG 文件的独立 Linebender 集成。

Examples

我们的示例以独立包的形式提供在 examples 目录中。 这使它们能够拥有独立的依赖项和更快的构建速度。 必须使用 --package(或 -p)Cargo 标志来选择示例。

Winit

我们的 winit 示例(examples/with_winit)演示了如何渲染到 winit 窗口。 默认情况下,它会渲染 GhostScript Tiger 以及您在 examples/assets/downloads 目录中添加的所有 SVG 文件。 也可以提供自定义的 SVG 文件路径列表(以及要渲染其中所有 SVG 文件的目录)作为参数。 它还包含一组展示 vello 功能的测试场景,可以通过 --test-scenes 显示。

cargo run -p with_winit

平台

我们旨在支持所有能够运行 WebGPU 的环境,并采用默认限制。 对于此支持,我们参考 wgpu。 其他平台更为复杂,可能需要特殊的构建/运行流程。

Web

由于 Vello 严重依赖计算着色器,我们依赖新兴的 WebGPU 标准以在 Web 上运行。 浏览器对 WebGPU 的支持仍在发展中。 Vello 已在 Chrome 的生产版本中进行了测试,但 Firefox 和 Safari 中的 WebGPU 支持仍处于实验阶段。 可能需要使用开发版浏览器并显式启用 WebGPU。

以下命令构建并运行 winit 演示 的 Web 版本。 这使用 cargo-run-wasm 为 Web 构建示例,并为其托管一个本地服务器

# Make sure the Rust toolchain supports the wasm32 target
rustup target add wasm32-unknown-unknown

# The binary name must also be explicitly provided as it differs from the package name
cargo run_wasm -p with_winit --bin with_winit_bin

这里还有一个网络演示,可在此处 在支持的 Web 浏览器上访问。

[!WARNING] 目前 Web 并非 Vello 的主要目标平台,且 WebGPU 实现尚不完整,因此运行此示例时可能会遇到问题。

Android

with_winit 示例支持在 Android 上运行,使用 cargo apk

cargo apk run -p with_winit --lib

[!TIP] cargo apk 不支持在未配置的情况下以 release 模式运行。 请参阅 其 crates 页面文档(约在 package.metadata.android.signing.<profile> 处)。

另请参阅 cargo-apk#16。 要以 release 模式运行,您必须将以下内容添加到 examples/with_winit/Cargo.toml(将 $HOME 更改为您的主目录):

[package.metadata.android.signing.release]
path = "$HOME/.android/debug.keystore"
keystore_password = "android"

[!NOTE] 由于 cargo apk 不允许在运行时向应用程序传递命令行参数或环境变量,因此可以在编译时将这些内容嵌入到 程序中(目前仅支持 Android) with_winit 目前支持以下环境变量:

  • VELLO_STATIC_LOG,其等效于 RUST_LOG
  • VELLO_STATIC_ARGS,其等效于传入命令行参数

例如(使用 unix shell 环境变量语法):

VELLO_STATIC_LOG="vello=trace" VELLO_STATIC_ARGS="--test-scenes" cargo apk run -p with_winit --lib

最低支持的 Rust 版本 (MSRV)

此版本的 Vello 已验证可在 Rust 1.88 及更高版本上编译。

Vello 的未来版本可能会提高 Rust 版本要求。 这不会被视为破坏性变更,因此甚至可能在小版本补丁发布中发生。

如果编译失败,请单击此处。

随着时间推移,Vello 的某些依赖项可能已发布了具有更高 Rust 要求的版本。 如果您遇到因依赖项导致的编译问题,并且不想升级您的 Rust 工具链,则可以降级该依赖项。

# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1

社区

Vello 的开发讨论在 Linebender Zulip 中进行,具体在 #vello 频道。 所有公开内容无需登录即可阅读。

欢迎通过拉取请求(pull request)做出贡献。 [Rust 行为准则] 适用。

除非您明确另有说明,否则您有意提交以纳入本作品的任何贡献,如 Apache 2.0 许可证所定义,将按照 License 章节中注明的许可进行授权,不附加任何额外条款或条件。

历史

Vello 此前被称为 piet-gpu。 该前身版本使用了名为 piet-gpu-hal 的自定义跨 API 硬件抽象层,而非 wgpu

该版本的存档可在分支 custom-hal-archive-with-shaderscustom-hal-archive 中找到。 它取代了之前的原型 piet-metal,并包含了改编自 piet-dx12 的工作。

关于放弃 piet-gpu-hal 转而采用 WebGPU 的决定,在博客文章 Requiem for piet-gpu-hal 中有详细讨论。

一份日期为 2020 年 12 月的 vision 文档阐述了项目的长期目标,以及我们可能如何达成这些目标。 其中许多条目已过时或已完成,但它仍可能提供一些有用的背景信息。

相关项目

Vello 从许多其他渲染项目中汲取灵感,包括:

许可证

根据以下任一许可证授权

at your option.

In addition, all files in the vello_shaders/shader and vello_shaders/src/cpu directories and subdirectories thereof are alternatively licensed under the Unlicense (vello_shaders/shader/UNLICENSE or http://unlicense.org/). For clarity, these files are also licensed under either of the above licenses. The intent is for this research to be used in as broad a context as possible.

The files in subdirectories of the examples/assets directory are licensed solely under their respective licenses, available in the LICENSE file in their directories.