Skip to content

Commit

Permalink
Re-export public dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Jan 15, 2024
1 parent c5a0b0b commit a3dfbe3
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ mod track;
pub mod validation;

pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_ATTACHMENTS, MAX_VERTEX_BUFFERS};
pub use naga;

use std::{borrow::Cow, os::raw::c_char};

Expand Down
9 changes: 4 additions & 5 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ angle = ["wgc?/gles"]
vulkan-portability = ["wgc?/vulkan"]

## Enables the WebGPU backend on Wasm. Disabled when targeting `emscripten`.
webgpu = []
webgpu = ["naga?/wgsl-out"]

## Enables the GLES backend on Wasm
##
Expand All @@ -64,6 +64,9 @@ glsl = ["naga/glsl-in"]
## Enable accepting WGSL shaders as input.
wgsl = ["wgc?/wgsl"]

## Enable accepting naga IR shaders as input.
naga-ir = ["naga"]

#! ### Logging & Tracing
# --------------------------------------------------------------------
#! The following features do not have any effect on the WebGPU backend.
Expand Down Expand Up @@ -178,10 +181,6 @@ cfg_aliases.workspace = true
workspace = true
features = ["wgsl-in"]

[target.'cfg(target_arch = "wasm32")'.dependencies.naga]
workspace = true
features = ["wgsl-out"]

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { workspace = true, features = [
"Document",
Expand Down
5 changes: 4 additions & 1 deletion wgpu/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fn main() {
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
) },
dx12: { all(target_os = "windows", feature = "dx12") },
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") }
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
// This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides
// its own re-export of naga, which can be used in other situations
naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") },
}
}
6 changes: 3 additions & 3 deletions wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ impl crate::context::Context for ContextWebGpu {
feature = "spirv",
feature = "glsl",
feature = "wgsl",
feature = "naga"
feature = "naga-ir"
)),
allow(unreachable_code, unused_variables)
)]
Expand All @@ -1411,7 +1411,7 @@ impl crate::context::Context for ContextWebGpu {
desc: crate::ShaderModuleDescriptor<'_>,
_shader_bound_checks: wgt::ShaderBoundChecks,
) -> (Self::ShaderModuleId, Self::ShaderModuleData) {
let mut descriptor = match desc.source {
let mut descriptor: web_sys::GpuShaderModuleDescriptor = match desc.source {
#[cfg(feature = "spirv")]
crate::ShaderSource::SpirV(ref spv) => {
use naga::{back, front, valid};
Expand Down Expand Up @@ -1465,7 +1465,7 @@ impl crate::context::Context for ContextWebGpu {
}
#[cfg(feature = "wgsl")]
crate::ShaderSource::Wgsl(ref code) => web_sys::GpuShaderModuleDescriptor::new(code),
#[cfg(feature = "naga")]
#[cfg(feature = "naga-ir")]
crate::ShaderSource::Naga(module) => {
use naga::{back, valid};

Expand Down
4 changes: 2 additions & 2 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ impl crate::Context for ContextWgpuCore {
feature = "spirv",
feature = "glsl",
feature = "wgsl",
feature = "naga"
feature = "naga-ir"
)),
allow(unreachable_code, unused_variables)
)]
Expand Down Expand Up @@ -885,7 +885,7 @@ impl crate::Context for ContextWgpuCore {
}
#[cfg(feature = "wgsl")]
ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)),
#[cfg(feature = "naga")]
#[cfg(feature = "naga-ir")]
ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module),
ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"),
};
Expand Down
55 changes: 46 additions & 9 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! - **`spirv`** --- Enable accepting SPIR-V shaders as input.
//! - **`glsl`** --- Enable accepting GLSL shaders as input.
//! - **`wgsl`** _(enabled by default)_ --- Enable accepting WGSL shaders as input.
//! - **`naga-ir`** --- Enable accepting Naga IR shaders as input.
//!
//! ### Logging & Tracing
//!
Expand Down Expand Up @@ -100,15 +101,51 @@ pub use wgt::{
QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT,
};

#[cfg(not(webgpu))]
#[doc(hidden)]
pub use ::hal;
#[cfg(feature = "naga")]
pub use ::naga;
#[cfg(not(webgpu))]
#[doc(hidden)]
/// Re-export of our `wgpu-core` dependency.
///
#[cfg(wgpu_core)]
#[doc(inline)]
pub use ::wgc as core;

/// Re-export of our `wgpu-hal` dependency.
///
///
#[cfg(wgpu_core)]
#[doc(inline)]
pub use ::hal;

/// Re-export of our `naga` dependency.
///
#[cfg(wgpu_core)]
#[cfg_attr(
docsrs,
doc(cfg(any(wgpu_core, feature = "glsl", feature = "spirv", feature = "naga-ir",)))
)]
#[doc(inline)]
// We re-export wgpu-core's re-export of naga, as we may not have direct access to it.
pub use ::wgc::naga;
/// Re-export of our `naga` dependency.
///
#[cfg(all(not(wgpu_core), naga))]
#[cfg_attr(
docsrs,
doc(cfg(wgpu_core, feature = "glsl", feature = "spirv", feature = "naga-ir"))
)]
#[doc(inline)]
// If that's not available, we re-export our own.
pub use naga;

#[doc(inline)]
/// Re-export of our `raw-window-handle` dependency.
///
pub use raw_window_handle as rwh;

/// Re-export of our `web-sys` dependency.
///
#[cfg(any(webgl, webgpu))]
#[doc(inline)]
pub use web_sys;

// wasm-only types, we try to keep as many types non-platform
// specific, but these need to depend on web-sys.
#[cfg(any(webgpu, webgl))]
Expand Down Expand Up @@ -644,7 +681,7 @@ impl Drop for ShaderModule {
///
/// This type is unique to the Rust API of `wgpu`. In the WebGPU specification,
/// only WGSL source code strings are accepted.
#[cfg_attr(feature = "naga", allow(clippy::large_enum_variant))]
#[cfg_attr(feature = "naga-ir", allow(clippy::large_enum_variant))]
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum ShaderSource<'a> {
Expand All @@ -669,7 +706,7 @@ pub enum ShaderSource<'a> {
#[cfg(feature = "wgsl")]
Wgsl(Cow<'a, str>),
/// Naga module.
#[cfg(feature = "naga")]
#[cfg(feature = "naga-ir")]
Naga(Cow<'static, naga::Module>),
/// Dummy variant because `Naga` doesn't have a lifetime and without enough active features it
/// could be the last one active.
Expand Down
8 changes: 4 additions & 4 deletions wgpu/src/util/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use wgt::{Backends, PowerPreference, RequestAdapterOptions};

use crate::{Adapter, Instance, Surface};

#[cfg(not(webgpu))]
#[cfg(wgpu_core)]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub use wgc::instance::parse_backends_from_comma_list;
/// Always returns WEBGPU on wasm over webgpu.
#[cfg(webgpu)]
/// Just return ALL, if wgpu_core is not enabled.
#[cfg(not(wgpu_core))]
pub fn parse_backends_from_comma_list(_string: &str) -> Backends {
Backends::BROWSER_WEBGPU
Backends::all()
}

/// Get a set of backend bits from the environment variable WGPU_BACKEND.
Expand Down

0 comments on commit a3dfbe3

Please sign in to comment.