diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6712b033912..f8564bcd1a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ on: env: RUST_BACKTRACE: 1 - RUST_VERSION: 1.59 + RUST_VERSION: '1.60' # We distinguish the following kinds of builds: # - local: build for the same target as we compile on, and do local tests @@ -178,6 +178,9 @@ jobs: - name: check web if: matrix.kind == 'web' run: | + # build with no features + cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu --no-default-features + # build examples cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu --examples @@ -194,7 +197,7 @@ jobs: if: matrix.kind == 'em' run: | # build for Emscripten/WebGL - cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-hal --features webgl,emscripten + cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-hal -no-default-features --features webgl,emscripten # build raw-gles example cargo ${{matrix.tool}} --target ${{ matrix.target }} --example raw-gles --features webgl,emscripten @@ -203,7 +206,7 @@ jobs: if: matrix.kind == 'local' || matrix.kind == 'other' run: | # check with no features - cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player + cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --no-default-features # check with all features # explicitly don't mention wgpu-hal so that --all-features don't apply to it diff --git a/README.md b/README.md index d6fea339496..25e28ba8606 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ For an overview of all the components in the gfx-rs ecosystem, see [the big pict ### MSRV policy -Minimum Supported Rust Version is **1.59**. +Minimum Supported Rust Version is **1.60**. It is enforced on CI (in "/.github/workflows/ci.yml") with `RUST_VERSION` variable. This version can only be upgraded in breaking releases. diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 73792f79800..8dd0632121c 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -24,6 +24,8 @@ replay = ["serde", "wgt/replay", "arrayvec/serde", "naga/deserialize"] # Enable serializable compute/render passes, and bundle encoders. serial-pass = ["serde", "wgt/serde", "arrayvec/serde"] id32 = [] +# Enable `ShaderModuleSource::Wgsl` +wgsl = ["naga/wgsl-in"] vulkan-portability = ["hal/vulkan"] [dependencies] @@ -46,7 +48,7 @@ thiserror = "1" git = "https://github.com/gfx-rs/naga" rev = "c52d9102" version = "0.10" -features = ["clone", "span", "validate", "wgsl-in"] +features = ["clone", "span", "validate"] [dependencies.wgt] path = "../wgpu-types" diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index a88d99cbca7..48786b68594 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1206,6 +1206,7 @@ impl Device { source: pipeline::ShaderModuleSource<'a>, ) -> Result, pipeline::CreateShaderModuleError> { let (module, source) = match source { + #[cfg(feature = "wgsl")] pipeline::ShaderModuleSource::Wgsl(code) => { profiling::scope!("naga::wgsl::parse_str"); let module = naga::front::wgsl::parse_str(&code).map_err(|inner| { @@ -1218,6 +1219,7 @@ impl Device { (Cow::Owned(module), code.into_owned()) } pipeline::ShaderModuleSource::Naga(module) => (module, String::new()), + pipeline::ShaderModuleSource::Dummy(_) => panic!("found `ShaderModuleSource::Dummy`"), }; for (_, var) in module.global_variables.iter() { match var.binding { @@ -4400,6 +4402,7 @@ impl Global { if let Some(ref trace) = device.trace { let mut trace = trace.lock(); let data = match source { + #[cfg(feature = "wgsl")] pipeline::ShaderModuleSource::Wgsl(ref code) => { trace.make_binary("wgsl", code.as_bytes()) } @@ -4409,6 +4412,9 @@ impl Global { .unwrap(); trace.make_binary("ron", string.as_bytes()) } + pipeline::ShaderModuleSource::Dummy(_) => { + panic!("found `ShaderModuleSource::Dummy`") + } }; trace.add(trace::Action::CreateShaderModule { id: fid.id(), diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 2b0e0804a62..667b8b96ed2 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -6,7 +6,7 @@ use crate::{ validation, Label, LifeGuard, Stored, }; use arrayvec::ArrayVec; -use std::{borrow::Cow, error::Error, fmt, num::NonZeroU32}; +use std::{borrow::Cow, error::Error, fmt, marker::PhantomData, num::NonZeroU32}; use thiserror::Error; /// Information about buffer bindings, which @@ -20,8 +20,13 @@ pub(crate) struct LateSizedBufferGroup { #[allow(clippy::large_enum_variant)] pub enum ShaderModuleSource<'a> { + #[cfg(feature = "wgsl")] Wgsl(Cow<'a, str>), 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. + #[doc(hidden)] + Dummy(PhantomData<&'a ()>), } #[derive(Clone, Debug)] @@ -63,6 +68,7 @@ pub struct ShaderError { pub label: Option, pub inner: E, } +#[cfg(feature = "wgsl")] impl fmt::Display for ShaderError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let label = self.label.as_deref().unwrap_or_default(); @@ -114,6 +120,7 @@ where //Note: `Clone` would require `WithSpan: Clone`. #[derive(Debug, Error)] pub enum CreateShaderModuleError { + #[cfg(feature = "wgsl")] #[error(transparent)] Parsing(#[from] ShaderError), #[error("Failed to generate the backend-specific code")] @@ -137,6 +144,7 @@ pub enum CreateShaderModuleError { impl CreateShaderModuleError { pub fn location(&self, source: &str) -> Option { match *self { + #[cfg(feature = "wgsl")] CreateShaderModuleError::Parsing(ref err) => err.inner.location(source), CreateShaderModuleError::Validation(ref err) => err.inner.location(source), _ => None, diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index fae8e8f6486..55c9d82e94f 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -8,7 +8,7 @@ homepage = "https://github.com/gfx-rs/wgpu" repository = "https://github.com/gfx-rs/wgpu" keywords = ["graphics"] license = "MIT OR Apache-2.0" -rust-version = "1.59" +rust-version = "1.60" [lib] diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 50dc584f16b..1d9909c4346 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -76,9 +76,10 @@ name = "water" test = true [features] -default = [] +default = ["wgsl"] spirv = ["naga/spv-in"] glsl = ["naga/glsl-in"] +wgsl = ["wgc?/wgsl"] trace = ["serde", "wgc/trace"] replay = ["serde", "wgc/replay"] angle = ["wgc/angle"] diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 8b4e3e8b765..fbf549c7ef1 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -3,8 +3,8 @@ use crate::{ CommandEncoderDescriptor, ComputePassDescriptor, ComputePipelineDescriptor, DownlevelCapabilities, Features, Label, Limits, LoadOp, MapMode, Operations, PipelineLayoutDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor, - SamplerDescriptor, ShaderModuleDescriptor, ShaderModuleDescriptorSpirV, ShaderSource, - SurfaceStatus, TextureDescriptor, TextureFormat, TextureViewDescriptor, + SamplerDescriptor, ShaderModuleDescriptor, ShaderModuleDescriptorSpirV, SurfaceStatus, + TextureDescriptor, TextureFormat, TextureViewDescriptor, ShaderSource, }; use arrayvec::ArrayVec; @@ -1094,6 +1094,15 @@ impl crate::Context for Context { } } + #[cfg_attr( + not(any( + feature = "spirv", + feature = "glsl", + feature = "wgsl", + feature = "naga" + )), + allow(unreachable_code, unused_variables) + )] fn device_create_shader_module( &self, device: &Self::DeviceId, @@ -1134,9 +1143,13 @@ impl crate::Context for Context { wgc::pipeline::ShaderModuleSource::Naga(std::borrow::Cow::Owned(module)) } - ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)), + #[cfg(feature = "wgsl")] + ShaderSource::Wgsl(ref code) => { + wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)) + } #[cfg(feature = "naga")] ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module), + ShaderSource::Dummy(_) => panic!("found `ShaderSource::Dummy`"), }; let (id, error) = wgc::gfx_select!( device.id => global.device_create_shader_module(device.id, &descriptor, source, ()) diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index ec3d3f322f4..19f208c4678 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1334,13 +1334,22 @@ impl crate::Context for Context { wgt::DownlevelCapabilities::default() } + #[cfg_attr( + not(any( + feature = "spirv", + feature = "glsl", + feature = "wgsl", + feature = "naga" + )), + allow(unreachable_code, unused_variables) + )] fn device_create_shader_module( &self, device: &Self::DeviceId, desc: crate::ShaderModuleDescriptor, _shader_bound_checks: wgt::ShaderBoundChecks, ) -> Self::ShaderModuleId { - 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}; @@ -1392,6 +1401,7 @@ impl crate::Context for Context { .unwrap(); web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str()) } + #[cfg(feature = "wgsl")] crate::ShaderSource::Wgsl(ref code) => web_sys::GpuShaderModuleDescriptor::new(code), #[cfg(feature = "naga")] crate::ShaderSource::Naga(module) => { @@ -1408,6 +1418,9 @@ impl crate::Context for Context { back::wgsl::write_string(&module, &module_info, writer_flags).unwrap(); web_sys::GpuShaderModuleDescriptor::new(wgsl_text.as_str()) } + crate::ShaderSource::Dummy(_) => { + panic!("found `ShaderSource::Dummy`") + } }; if let Some(label) = desc.label { descriptor.label(label); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 912989572f2..9ee5c370a08 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -858,11 +858,17 @@ pub enum ShaderSource<'a> { defines: naga::FastHashMap, }, /// WGSL module as a string slice. + #[cfg(feature = "wgsl")] + #[cfg_attr(docsrs, doc(cfg(feature = "wgsl")))] Wgsl(Cow<'a, str>), /// Naga module. #[cfg(feature = "naga")] #[cfg_attr(docsrs, doc(cfg(feature = "naga")))] 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. + #[doc(hidden)] + Dummy(PhantomData<&'a ()>), } static_assertions::assert_impl_all!(ShaderSource: Send, Sync);