gfx-rs/wgpu
wgpu-naga-bridge
wgpu-naga-bridge (wgpu-naga-bridge/) is a small crate that mediates between wgpu-core and naga. It was extracted from wgpu-core on 2026-03-13 to give the project room to swap or version-pin naga independently.
Purpose
- Translate user-supplied shader source (WGSL, GLSL, SPIR-V) into a validated
naga::Module. - Run
naga::valid::Validatorwith the rightCapabilitiesfor the active device. - Hand the validated module to whichever
nagabackend matches the activewgpu-halbackend (SPIR-V for Vulkan, MSL for Metal, HLSL for DX12, GLSL for GLES). - Decouple
wgpu-corefrom naga's API surface so naga can move at its own pace.
Directory layout
wgpu-naga-bridge/
├── Cargo.toml
└── src/ # small, single-purpose crateHow it works
graph LR
UserSource["User shader<br/>(WGSL / GLSL / SPIR-V)"] --> Front[naga::front::*]
Front --> Module[naga::Module]
Module --> Validator[naga::valid::Validator]
Validator --> ValidatedModule[ModuleInfo + Module]
ValidatedModule --> Back[naga::back::*]
Back -->|SPIR-V| Vk[Vulkan backend]
Back -->|MSL| Mt[Metal backend]
Back -->|HLSL| Dx[DX12 backend]
Back -->|GLSL| Gl[GLES backend]wgpu-core::pipeline::ShaderModule::create calls into wgpu-naga-bridge to run the front-validate-back pipeline. The bridge exposes the result in a form wgpu-core can store and later use to build RenderPipeline / ComputePipeline objects without touching naga's types directly.
Capabilities mapping
naga::valid::Capabilities is computed from the active wgt::Features. For example, Features::SHADER_F64 enables Capabilities::FLOAT64, Features::SUBGROUP* unlocks subgroup operations, and Features::SHADER_INT64 unlocks 64-bit integer support. The mapping lives in this crate; before March 2026 it was inside wgpu-core/src/validation.rs.
Why a separate crate
Three motivations:
- API decoupling — naga's public types (
naga::Module,naga::valid::ModuleInfo) are not part of wgpu's stable surface. Putting the integration in a separate crate lets wgpu-core consume only whatwgpu-naga-bridgere-exports. - Version pinning — A future plan involves letting downstream embedders bring their own naga version. The bridge crate can implement the feature-detection logic against multiple naga versions.
- Build time — naga's
default-features = falseplus selective feature enables are clearer when concentrated in one crate.
Integration points
- Above:
wgpu-core::pipeline,wgpu-core::validation. - Below:
naga(with the relevantwgsl-in,glsl-in,spv-in,wgsl-out,spv-out,msl-out,hlsl-out,glsl-outfeatures enabled). - Adjacent:
wgpu-typesforFeatures/Limitsto drive capability mapping.
Entry points for modification
- A new shader frontend — wire it through here so all of
wgpu-corecan use it without depending on the new naga module directly. - A new feature → capability mapping — when adding a new
Features::SHADER_*bit, add the correspondingCapabilitiesmapping in this crate, not inwgpu-core. - A naga API change — adapt the bridge first; then bump the version in
[workspace.dependencies].
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.