Skip to content

infosia/wgpu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10,507 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

wgpu — Tiled Rendering Fork

A mobile-optimized fork of wgpu that adds tile-based deferred rendering (TBDR) support while keeping the upstream API intact.

What this fork adds

This is the feature/tiled branch: a port of the TBDR extension from the wgpu-tiled reference implementation onto upstream wgpu v29.0.1, deliberately reshaped to minimize divergence from upstream. It exposes the GPU features that mobile TBDR architectures (Apple GPU, Qualcomm Adreno, ARM Mali) need to keep intermediate rendering data in fast on-chip tile memory instead of round-tripping through DRAM:

  • Transient attachments — tile-memory-only textures with no DRAM backing (Vulkan LAZILY_ALLOCATED, Metal MTLStorageMode::Memoryless, GLES renderbuffer fallback).
  • Multi-subpass render passes — multiple rendering phases inside a single hardware pass, so G-buffer / depth / normal data stays in tile memory across subpasses.
  • Input attachments — read a previous subpass's output at the current fragment position directly from tile memory, with no texture sampling overhead.
  • Typed subpass_input WGSL typessubpass_input<T> and subpass_input_multisampled<T> plus the subpassLoad builtin, compiled by naga to SPIR-V SubpassData / MSL [[color(N)]] / GLSL framebuffer fetch.

Standard wgpu follows the WebGPU spec, which only supports flat single-pass rendering — forcing mobile GPUs to spill intermediate data to DRAM between passes and read it back. This fork eliminates that bottleneck.

Design principle: no breaking changes to upstream

Unlike a from-scratch divergence, this fork wraps rather than extends. New capability is delivered through additive, sidecar APIs so an upstream rebase stays trivial:

  • adapter.tiled_capabilities() — query subpass / input-attachment limits (separate from Limits, not an extension of it).
  • device.create_transient_attachment(&desc) — allocate a tile-memory attachment.
  • device.create_subpass_render_pipeline(&SubpassRenderPipelineDescriptor::new(..)) — a wrapper around RenderPipelineDescriptor, not a new field on it.
  • encoder.begin_subpass_render_pass(&SubpassRenderPassDescriptor { .. }) and pass.next_subpass() — a sibling entry point, not an expansion of begin_render_pass.
  • HAL backends opt in via TiledApi / TiledDevice / TiledCommandEncoder sub-traits rather than changes to the upstream Api / Device / CommandEncoder traits.

git grep "tiled-fork:" enumerates every divergence point in upstream-shared files; the bulk of the diff lives in fork-only new files.

Backend status

Backend Transient attachments Multi-subpass Status
Vulkan VkImage + LAZILY_ALLOCATED Native VkRenderPass subpasses + dependencies End-to-end; deferred_rendering runs at 60 FPS with zero validation messages
Metal MTLStorageMode::Memoryless Single-encoder subpass state machine End-to-end runtime (deferred_rendering / subpass_msaa)
GLES Renderbuffer fallback EXT_shader_framebuffer_fetch / multi-pass (Tier A/B) Real impl
DX12 Stub (regular texture) Stub (separate passes) Stub

WGSL example: typed subpass_input

// Lighting subpass — reads the G-Buffer from tile memory via input attachments
@group(0) @binding(0) var t_albedo: subpass_input<f32>;
@group(0) @binding(1) var t_normal: subpass_input<f32>;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    let albedo = subpassLoad(t_albedo).rgb;
    let normal = subpassLoad(t_normal).rgb;
    // ... lighting calculation ...
}

subpass_input* declarations identify the attachment through @binding only, and subpassLoad reads from the current fragment position. naga compiles this to SPIR-V OpTypeImage with Dim=SubpassData + InputAttachmentIndex, MSL [[color(N)]] fragment parameters, or a GLSL framebuffer-fetch / texelFetch fallback.

Examples

  • examples/features/src/deferred_rendering/ — 3-subpass G-buffer → lighting → composite pipeline. Runs end-to-end on Vulkan and Metal.
  • examples/features/src/subpass_msaa/ — 2-subpass MSAA line demo with a follow-up resolve pass; Left/Right arrow keys toggle 1× ↔ adapter-max MSAA.
  • examples/features/src/subpass_render_graph/ — headless 2-subpass smoke test built directly from the subpass descriptors.

Note: the wgpu-tiled reference repo ships a higher-level declarative RenderGraphBuilder. This fork intentionally does not port it — the render-graph example constructs subpasses directly from the lower-level descriptors to keep the upstream-divergence surface small.

This is a fork

This branch deliberately breaks WebGPU spec compliance to expose native TBDR capabilities. There are no plans to upstream these changes; the goal is a clean, rebaseable diff against upstream wgpu. The design plan and phase status live in TILED.md.


wgpu (upstream)

Build Status codecov.io

wgpu is a cross-platform, safe, pure-Rust graphics API. It runs natively on Vulkan, Metal, D3D12, and OpenGL; and on top of WebGL2 and WebGPU on wasm.

The API is based on the WebGPU standard, but is a fully native Rust library. It serves as the core of the WebGPU integration in Firefox, Servo, and Deno.

Getting Started

See our examples online at https://wgpu.rs/examples/. You can see the Rust sources at examples and run them directly with cargo run --bin wgpu-examples <example>.

Learning wgpu

If you are new to wgpu and graphics programming, we recommend starting with Learn Wgpu.

Additionally, WebGPU Fundamentals is a tutorial for WebGPU which is very similar to our API, minus differences between Rust and Javascript.

Wiki

We have a wiki which has information on useful architecture patterns, debugging tips, and more getting started information.

Need Help? Want to Contribute?

The wgpu community uses Matrix and Discord to discuss.

  • #wgpu:matrix.org - discussion of wgpu's development.
  • #wgpu-users:matrix.org - discussion of using the library and the surrounding ecosystem.
  • #wgpu on the Rust Gamedev Discord - Dedicated support channel on the Rust Gamedev Discord.

Other Languages

To use wgpu in C or dozens of other languages, look at wgpu-native. These are C bindings to wgpu and has an up-to-date list of libraries bringing support to other languages.

Learn WebGPU (for C++) is a good resource for learning how to use wgpu-native from C++.

Quick Links

Docs Examples Changelog
v29 v29 v29
trunk trunk trunk

Contributors are welcome! See CONTRIBUTING.md for more information.

Supported Platforms

API Windows Linux/Android macOS/iOS Web (wasm)
Vulkan 🌋
Metal
DX12
OpenGL 🆗 (GL 3.3+) 🆗 (GL ES 3.0+) 📐 🆗 (WebGL2)
WebGPU

✅ = First Class Support
🆗 = Downlevel/Best Effort Support
📐 = Requires the ANGLE translation layer (GL ES 3.0 only)
🌋 = Requires the MoltenVK translation layer
🛠️ = Unsupported, though open to contributions

Environment Variables

Testing, examples, and ::from_env() methods use a standardized set of environment variables to control wgpu's behavior.

  • WGPU_BACKEND with a comma-separated list of the backends you want to use (vulkan, metal, dx12, or gl).
  • WGPU_ADAPTER_NAME with a case-insensitive substring of the name of the adapter you want to use (ex. 1080 will match NVIDIA GeForce 1080ti).
  • WGPU_DX12_COMPILER with the DX12 shader compiler you wish to use (dxc, static-dxc, or fxc). Note that dxc requires dxcompiler.dll (min v1.8.2502) to be in the working directory, and static-dxc requires the static-dxc crate feature to be enabled. Otherwise, it will fall back to fxc.

See the documentation for more environment variables.

When running the CTS, use the variables DENO_WEBGPU_ADAPTER_NAME, DENO_WEBGPU_BACKEND, DENO_WEBGPU_POWER_PREFERENCE, and DENO_WEBGPU_DX12_COMPILER.

Repo Overview

For an overview of all the components in the gfx-rs ecosystem, see the big picture.

MSRV policy

TL;DR: If you're using wgpu, our MSRV is 1.87. If you're running our tests or examples, our MSRV is 1.93.

We will avoid bumping the MSRV of wgpu without good reason, and such a change is considered breaking.

Specific Details

Due to complex dependants, we have three MSRV policies:

  • wgpu's MSRV is 1.87
  • wgpu-core (and hence wgpu-hal, naga, and wgpu-types)'s MSRV is 1.87.
  • The rest of the workspace has an MSRV of 1.93.

It is enforced on CI (in "/.github/workflows/ci.yml") with the WGPU_MSRV, CORE_MSRV, and REPO_MSRV variables, respectively. This version can only be upgraded in breaking releases, though we release a breaking version every three months.

The following rules apply:

  • The wgpu-core crate should never require an MSRV ahead of Firefox's MSRV for nightly builds, as determined by the value of MINIMUM_RUST_VERSION in python/mozboot/mozboot/util.py.
  • The wgpu crate should never require an MSRV ahead of Servo's MSRV, as determined by the value of their rust-version declaration in Cargo.toml
  • The repository MSRV should never require an MSRV higher than stable - 3. For example, if stable is at 1.97, the repository MSRV should be no higher than 1.94. This is to allow people who are using a decently-updated OS-provided rust to be able to build our repository. Consider cross checking with NixOS, though this is not required.

Testing and Environment Variables

Information about testing, including where tests of various kinds live, and how to run the tests.

Tracking the WebGPU and WGSL draft specifications

The wgpu crate is meant to be an idiomatic Rust translation of the WebGPU API. That specification, along with its shading language, WGSL, are both still in the "Working Draft" phase, and while the general outlines are stable, details change frequently. Until the specification is stabilized, the wgpu crate and the version of WGSL it implements will likely differ from what is specified, as the implementation catches up.

Exactly which WGSL features wgpu supports depends on how you are using it:

  • When running as native code, wgpu uses Naga to translate WGSL code into the shading language of your platform's native GPU API. Naga is working on catching up to the WGSL specification, with bugs tracking various issues, but there is no concise summary of differences from the specification.

  • When running in a web browser (by compilation to WebAssembly) without the "webgl" feature enabled, wgpu relies on the browser's own WebGPU implementation. WGSL shaders are simply passed through to the browser, so that determines which WGSL features you can use.

  • When running in a web browser with wgpu's "webgl" feature enabled, wgpu uses Naga to translate WGSL programs into GLSL. This uses the same version of Naga as if you were running wgpu as native code.

About

wgpu-tiled - A mobile-optimized fork of wgpu with tile-based deferred rendering (TBDR) support

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE.APACHE
MIT
LICENSE.MIT

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors