diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6712b033912..cfd6ad3c84e 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 default features + cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu --no-default-features + # build examples cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu --examples @@ -202,6 +205,9 @@ jobs: - name: check native if: matrix.kind == 'local' || matrix.kind == 'other' run: | + # check with no default features + cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --no-default-features + # check with no features cargo ${{matrix.tool}} --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player diff --git a/README.md b/README.md index 860454c59fc..0f56f20579f 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 1fef8c94514..96b86d97b37 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" [lib] [features] -default = [] +default = ["wgsl"] # Apply run-time checks, even in release builds. These are in addition # to the validation carried out at public APIs in all builds. strict_asserts = [] @@ -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] @@ -47,7 +49,7 @@ thiserror = "1" git = "https://github.com/gfx-rs/naga" rev = "b209d911" version = "0.9" -features = ["span", "validate", "wgsl-in"] +features = ["span", "validate"] [dependencies.wgt] path = "../wgpu-types" diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index a5c5cbe51ca..fa66b44954c 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1189,9 +1189,11 @@ impl Device { &self, self_id: id::DeviceId, desc: &pipeline::ShaderModuleDescriptor<'a>, - source: pipeline::ShaderModuleSource<'a>, + #[cfg(feature = "wgsl")] source: pipeline::ShaderModuleSource<'a>, + #[cfg(not(feature = "wgsl"))] source: pipeline::ShaderModuleSource, ) -> 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| { diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index f9d500178d0..85e865eb232 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -19,7 +19,8 @@ pub(crate) struct LateSizedBufferGroup { } #[allow(clippy::large_enum_variant)] -pub enum ShaderModuleSource<'a> { +pub enum ShaderModuleSource<#[cfg(feature = "wgsl")] 'a> { + #[cfg(feature = "wgsl")] Wgsl(Cow<'a, str>), Naga(naga::Module), } @@ -63,6 +64,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 +116,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 +140,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/Cargo.toml b/wgpu/Cargo.toml index e0040dfb16c..320c7542218 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"] @@ -90,6 +91,7 @@ vulkan-portability = ["wgc/vulkan-portability"] package = "wgpu-core" path = "../wgpu-core" version = "0.13" +default-features = false features = ["raw-window-handle"] [target.'cfg(target_arch = "wasm32")'.dependencies.wgc] diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 669ba456de7..0e55257d9bf 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, }; use arrayvec::ArrayVec; @@ -1075,6 +1075,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, @@ -1088,7 +1097,7 @@ impl crate::Context for Context { }; let source = match desc.source { #[cfg(feature = "spirv")] - ShaderSource::SpirV(ref spv) => { + crate::ShaderSource::SpirV(ref spv) => { // Parse the given shader code and store its representation. let options = naga::front::spv::Options { adjust_coordinate_space: false, // we require NDC_Y_UP feature @@ -1100,7 +1109,7 @@ impl crate::Context for Context { wgc::pipeline::ShaderModuleSource::Naga(module) } #[cfg(feature = "glsl")] - ShaderSource::Glsl { + crate::ShaderSource::Glsl { ref shader, stage, ref defines, @@ -1115,9 +1124,12 @@ impl crate::Context for Context { wgc::pipeline::ShaderModuleSource::Naga(module) } - ShaderSource::Wgsl(ref code) => wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)), + #[cfg(feature = "wgsl")] + crate::ShaderSource::Wgsl(ref code) => { + wgc::pipeline::ShaderModuleSource::Wgsl(Borrowed(code)) + } #[cfg(feature = "naga")] - ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module), + crate::ShaderSource::Naga(module) => wgc::pipeline::ShaderModuleSource::Naga(module), }; 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 f8161251481..1bacf2a4306 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1278,13 +1278,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}; @@ -1336,6 +1345,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) => { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 541fa3566eb..3aebd7d8f99 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -816,7 +816,7 @@ impl Drop for ShaderModule { /// Any necessary shader translation (e.g. from WGSL to SPIR-V or vice versa) /// will be done internally by wgpu. #[non_exhaustive] -pub enum ShaderSource<'a> { +pub enum ShaderSource<#[cfg(any(feature = "spirv", feature = "glsl", feature = "wgsl"))] 'a> { /// SPIR-V module represented as a slice of words. /// /// See also: [`util::make_spirv`], [`include_spirv`] @@ -837,6 +837,8 @@ 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")] @@ -852,7 +854,11 @@ pub struct ShaderModuleDescriptor<'a> { /// Debug label of the shader module. This will show up in graphics debuggers for easy identification. pub label: Label<'a>, /// Source code for the shader. + #[cfg(any(feature = "spirv", feature = "glsl", feature = "wgsl"))] pub source: ShaderSource<'a>, + /// Source code for the shader. + #[cfg(not(any(feature = "spirv", feature = "glsl", feature = "wgsl")))] + pub source: ShaderSource, } /// Descriptor for a shader module given by SPIR-V binary.