diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ce59b6aad..77cd1d5200 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: tags: [v0.*] pull_request: +env: + RUST_BACKTRACE: 1 + jobs: build: strategy: @@ -18,6 +21,13 @@ jobs: channel: stable target: x86_64-pc-windows-msvc kind: test + backends: dx12 # dx11 + + - name: Windows Nightly x86_64 + os: windows-2019 + channel: nightly + target: x86_64-pc-windows-msvc + kind: compile # MacOS @@ -42,7 +52,8 @@ jobs: os: ubuntu-20.04 channel: stable target: x86_64-unknown-linux-gnu - kind: test + kind: compile + backends: # vulkan gl - name: Linux Nightly x86_64 os: ubuntu-20.04 @@ -71,7 +82,7 @@ jobs: env: PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work - RUSTFLAGS: --cfg=web_sys_unstable_apis + RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings RUSTDOCFLAGS: -Dwarnings steps: @@ -87,6 +98,11 @@ jobs: profile: minimal components: clippy + - name: caching + uses: Swatinem/rust-cache@v1 + with: + key: ${{ matrix.target }}-a # suffix for cache busting + - name: add android apk to path if: matrix.os == 'ubuntu-20.04' && matrix.target == 'aarch64-linux-android' run: | @@ -95,73 +111,69 @@ jobs: - name: install llvmpipe and lavapipe if: matrix.os == 'ubuntu-20.04' && matrix.kind == 'test' run: | - echo "Installing Vulkan" sudo apt-get update -y -qq sudo add-apt-repository ppa:ubuntu-x-swat/updates -y sudo apt-get update sudo apt install -y libxcb-xfixes0-dev mesa-vulkan-drivers + # add libegl1-mesa libgl1-mesa-dri for egl + + # We enable line numbers for panics, but that's it + - name: disable debug + shell: bash + run: | + mkdir .cargo + echo """[profile.dev] + debug = 1" > .cargo/config.toml # This is separate for now because webgl isn't hooked up so we can't compile wgpu-core for wasm - name: check web if: matrix.kind == 'webgl' run: | - cargo clippy --target ${{ matrix.target }} -p wgpu -- -D warnings + cargo clippy --target ${{ matrix.target }} -p wgpu # build docs cargo doc --target ${{ matrix.target }} -p wgpu --no-deps - - name: check native stable (fatal warnings) - if: (matrix.kind == 'compile' || matrix.kind == 'test') && matrix.channel == 'stable' - run: | - # check with no features - cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player -- -D warnings - - # check with all features - # explicitly don't mention wgpu-hal so that --all-features don't apply to it - cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --examples --tests --all-features -- -D warnings - - # build docs - cargo doc --target ${{ matrix.target }} --no-deps - cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --all-features --no-deps - - - name: check native nightly (non-fatal warnings) - if: (matrix.kind == 'compile' || matrix.kind == 'test') && matrix.channel != 'stable' + - name: check native + if: matrix.kind == 'compile' || matrix.kind == 'test' run: | # check with no features cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player # check with all features # explicitly don't mention wgpu-hal so that --all-features don't apply to it - cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --examples --tests --all-features + cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --examples --tests --all-features - - name: build tests - if: matrix.kind == 'test' - run: | - cargo build --target ${{ matrix.target }} --bin wgpu-info - cargo build --target ${{ matrix.target }} --tests -p wgpu-types -p wgpu-hal -p wgpu-core - cargo build --target ${{ matrix.target }} --examples --tests -p wgpu + # build docs + cargo doc --target ${{ matrix.target }} --no-deps + cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --all-features --no-deps - name: tests - if: matrix.kind == 'test' && matrix.os == 'windows-2019' + if: matrix.kind == 'test' + shell: bash run: | # run wgpu-info cargo run --target ${{ matrix.target }} --bin wgpu-info - # run player tests - cargo test --target ${{ matrix.target }} -p wgpu-types -p wgpu-hal -p wgpu-core --no-fail-fast -- --nocapture - # run coretests - cargo run --target ${{ matrix.target }} --bin wgpu-info -- cargo test --target ${{ matrix.target }} -p wgpu --no-fail-fast -- --nocapture + for backend in ${{ matrix.backends }}; do + echo "======= NATIVE TESTS $backend ======"; + # run player tests + WGPU_BACKEND=$backend cargo test --target ${{ matrix.target }} -p wgpu-types -p wgpu-hal -p wgpu-core --no-fail-fast -- --nocapture --test-threads=1 + # run coretests + WGPU_BACKEND=$backend cargo test --target ${{ matrix.target }} -p wgpu --no-fail-fast -- --nocapture --test-threads=1 + done - test: + cts: strategy: fail-fast: false matrix: include: # Windows - name: Windows x86_64 - os: windows-latest + os: windows-2019 target: x86_64-pc-windows-msvc + backends: dx12 # dx11 - name: Test ${{ matrix.name }} + name: CTS ${{ matrix.name }} runs-on: ${{ matrix.os }} steps: @@ -169,6 +181,7 @@ jobs: uses: actions/checkout@v2 with: path: wgpu + - name: checkout cts uses: actions/checkout@v2 with: @@ -183,16 +196,36 @@ jobs: target: ${{ matrix.target }} profile: minimal + - name: caching + uses: Swatinem/rust-cache@v1 + with: + key: cts-a # suffix for cache busting + working-directory: wgpu/cts_runner + target-dir: wgpu/cts_runner/target + + # We enable line numbers for panics, but that's it + - name: disable debug + shell: bash + run: | + mkdir wgpu/.cargo + echo """[profile.dev] + debug = 1" > wgpu/.cargo/config.toml + - name: build CTS runner - run: cd wgpu/cts_runner && cargo build + run: | + cargo build --manifest-path wgpu/cts_runner/Cargo.toml - name: run CTS + if: ${{ matrix.os }} == 'windows-2019' shell: bash - run: >- + run: | cd cts; - grep -v '^//' ../wgpu/cts_runner/test.lst | while IFS=$' \t\r\n' read test; do - echo "=== Running $test ==="; - cargo run --manifest-path ../wgpu/cts_runner/Cargo.toml --frozen -- ./tools/run_deno --verbose "$test"; + for backend in ${{ matrix.backends }}; do + echo "======= CTS TESTS $backend ======"; + grep -v '^//' ../wgpu/cts_runner/test.lst | while IFS=$' \t\r\n' read test; do + echo "=== Running $test ==="; + DENO_WEBGPU_BACKEND=$backend cargo run --manifest-path ../wgpu/cts_runner/Cargo.toml --frozen -- ./tools/run_deno --verbose "$test"; + done done fmt: diff --git a/deno_webgpu/src/lib.rs b/deno_webgpu/src/lib.rs index 3e1f18b572..d8c8b67e98 100644 --- a/deno_webgpu/src/lib.rs +++ b/deno_webgpu/src/lib.rs @@ -242,13 +242,14 @@ pub async fn op_webgpu_request_adapter( ) -> Result { let mut state = state.borrow_mut(); check_unstable(&state, "navigator.gpu.requestAdapter"); + let backends = std::env::var("DENO_WEBGPU_BACKEND").ok().map_or_else(wgpu_types::Backends::all, |s| wgpu_core::instance::parse_backends_from_comma_list(&s)); let instance = if let Some(instance) = state.try_borrow::() { instance } else { state.put(wgpu_core::hub::Global::new( "webgpu", wgpu_core::hub::IdentityManagerFactory, - wgpu_types::Backends::PRIMARY, + backends, )); state.borrow::() }; @@ -263,7 +264,7 @@ pub async fn op_webgpu_request_adapter( }; let res = instance.request_adapter( &descriptor, - wgpu_core::instance::AdapterInputs::Mask(wgpu_types::Backends::PRIMARY, |_| { + wgpu_core::instance::AdapterInputs::Mask(backends, |_| { std::marker::PhantomData }), ); diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index e745374ffe..e2c7472c63 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -419,6 +419,7 @@ pub struct BindGroupLayout { pub(crate) device_id: Stored, pub(crate) multi_ref_count: MultiRefCount, pub(crate) entries: BindEntryMap, + #[allow(unused)] pub(crate) dynamic_count: usize, pub(crate) count_validator: BindingTypeMaxCountValidator, #[cfg(debug_assertions)] diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index bf04019aaf..277a28cc6c 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -4637,7 +4637,7 @@ impl Global { resource::BufferMapState::Waiting(resource::BufferPendingMapping { range, op, - parent_ref_count: buffer.life_guard.add_ref(), + _parent_ref_count: buffer.life_guard.add_ref(), }) } }; diff --git a/wgpu-core/src/hub.rs b/wgpu-core/src/hub.rs index 4240ecdee3..d43c68a7de 100644 --- a/wgpu-core/src/hub.rs +++ b/wgpu-core/src/hub.rs @@ -17,21 +17,12 @@ use std::cell::Cell; use std::{fmt::Debug, marker::PhantomData, mem, ops}; /// A simple structure to manage identities of objects. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct IdentityManager { free: Vec, epochs: Vec, } -impl Default for IdentityManager { - fn default() -> Self { - Self { - free: Default::default(), - epochs: Default::default(), - } - } -} - impl IdentityManager { pub fn from_index(min_index: u32) -> Self { Self { diff --git a/wgpu-core/src/instance.rs b/wgpu-core/src/instance.rs index 6407259a5a..7389a79b8e 100644 --- a/wgpu-core/src/instance.rs +++ b/wgpu-core/src/instance.rs @@ -876,3 +876,40 @@ impl Global { (id, Some(error)) } } + +/// Generates a set of backends from a comma separated list of case-insensitive backend names. +/// +/// Whitespace is stripped, so both 'gl, dx12' and 'gl,dx12' are valid. +/// +/// Always returns WEBGPU on wasm over webgpu. +/// +/// Names: +/// - vulkan = "vulkan" or "vk" +/// - dx12 = "dx12" or "d3d12" +/// - dx11 = "dx11" or "d3d11" +/// - metal = "metal" or "mtl" +/// - gles = "opengl" or "gles" or "gl" +/// - webgpu = "webgpu" +pub fn parse_backends_from_comma_list(string: &str) -> Backends { + let mut backends = Backends::empty(); + for backend in string.to_lowercase().split(',') { + backends |= match backend.trim() { + "vulkan" | "vk" => Backends::VULKAN, + "dx12" | "d3d12" => Backends::DX12, + "dx11" | "d3d11" => Backends::DX11, + "metal" | "mtl" => Backends::METAL, + "opengl" | "gles" | "gl" => Backends::GL, + "webgpu" => Backends::BROWSER_WEBGPU, + b => { + log::warn!("unknown backend string '{}'", b); + continue; + } + } + } + + if backends.is_empty() { + log::warn!("no valid backend strings found!"); + } + + backends +} diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index ab25b8afc2..9daecf326b 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -32,6 +32,7 @@ pub const DESIRED_NUM_FRAMES: u32 = 3; pub(crate) struct Presentation { pub(crate) device_id: Stored, pub(crate) config: wgt::SurfaceConfiguration, + #[allow(unused)] pub(crate) num_frames: u32, pub(crate) acquired_texture: Option>, } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 4e9d971e4c..9f990b995a 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -109,7 +109,7 @@ pub(crate) struct BufferPendingMapping { pub range: Range, pub op: BufferMapOperation, // hold the parent alive while the mapping is active - pub parent_ref_count: RefCount, + pub _parent_ref_count: RefCount, } pub type BufferDescriptor<'a> = wgt::BufferDescriptor>; diff --git a/wgpu-core/src/validation.rs b/wgpu-core/src/validation.rs index 43d000c0e4..e1e024b117 100644 --- a/wgpu-core/src/validation.rs +++ b/wgpu-core/src/validation.rs @@ -21,6 +21,7 @@ enum ResourceType { #[derive(Debug)] struct Resource { + #[allow(unused)] name: Option, bind: naga::ResourceBinding, ty: ResourceType, @@ -90,6 +91,7 @@ enum Varying { BuiltIn(naga::BuiltIn), } +#[allow(unused)] #[derive(Debug)] struct SpecializationConstant { id: u32, @@ -101,6 +103,7 @@ struct EntryPoint { inputs: Vec, outputs: Vec, resources: Vec<(naga::Handle, GlobalUse)>, + #[allow(unused)] spec_constants: Vec, sampling_pairs: FastHashSet<(naga::Handle, naga::Handle)>, } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 6e4a0b4cbe..886e3807f6 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -155,13 +155,17 @@ unsafe impl Sync for Surface {} #[derive(Debug, Clone, Copy)] enum MemoryArchitecture { - Unified { cache_coherent: bool }, + Unified { + #[allow(unused)] + cache_coherent: bool, + }, NonUnified, } #[derive(Debug, Clone, Copy)] struct PrivateCapabilities { instance_flags: crate::InstanceFlags, + #[allow(unused)] heterogeneous_resource_heaps: bool, memory_architecture: MemoryArchitecture, heap_create_not_zeroed: bool, diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 7badd3c6d0..c91c1a2d3d 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -317,6 +317,7 @@ impl AdapterContext { #[derive(Debug)] struct Inner { egl: Arc>, + #[allow(unused)] version: (i32, i32), supports_native_window: bool, display: egl::Display, @@ -721,6 +722,7 @@ pub struct Swapchain { extent: wgt::Extent3d, format: wgt::TextureFormat, format_desc: super::TextureFormatDesc, + #[allow(unused)] sample_type: wgt::TextureSampleType, } @@ -731,6 +733,7 @@ pub struct Surface { config: egl::Config, display: egl::Display, context: egl::Context, + #[allow(unused)] pbuffer: Option, pub(super) presentable: bool, raw_window_handle: RawWindowHandle, diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 5c4e752682..631d86eb4d 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -229,6 +229,7 @@ pub struct Texture { mip_level_count: u32, array_layer_count: u32, format: wgt::TextureFormat, + #[allow(unused)] format_desc: TextureFormatDesc, copy_size: crate::CopyExtent, } @@ -345,6 +346,7 @@ struct VertexBufferDesc { stride: u32, } +#[allow(unused)] #[derive(Clone)] struct UniformDesc { location: glow::UniformLocation, @@ -533,6 +535,7 @@ enum Command { dst_target: BindTarget, range: crate::MemoryRange, }, + #[allow(unused)] // yet unimplemented ClearTexture { dst: glow::Texture, dst_target: BindTarget, @@ -554,6 +557,7 @@ enum Command { }, CopyBufferToTexture { src: glow::Buffer, + #[allow(unused)] src_target: BindTarget, dst: glow::Texture, dst_target: BindTarget, @@ -565,6 +569,7 @@ enum Command { src_target: BindTarget, src_format: wgt::TextureFormat, dst: glow::Buffer, + #[allow(unused)] dst_target: BindTarget, copy: crate::BufferTextureCopy, }, diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index e59f9e67a2..efc8125e8d 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -3,11 +3,6 @@ */ #![allow( - // The intra doc links to the wgpu crate in this crate actually successfully link to the types in the wgpu crate, when built from the wgpu crate. - // However when building from both the wgpu crate or this crate cargo doc will claim all the links cannot be resolved - // despite the fact that it works fine when it needs to. - // So we just disable those warnings. - broken_intra_doc_links, // We don't use syntax sugar where it's not necessary. clippy::match_like_matches_macro, )] @@ -722,6 +717,8 @@ impl Limits { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DownlevelLimits {} +#[allow(unknown_lints)] // derivable_impls is nightly only currently +#[allow(clippy::derivable_impls)] impl Default for DownlevelLimits { fn default() -> Self { DownlevelLimits {} @@ -2776,7 +2773,7 @@ impl TextureDescriptor { /// # use wgpu_types as wgpu; /// let desc = wgpu::TextureDescriptor { /// label: (), - /// size: Extent3d { width: 100, height: 60, depth_or_array_layers: 2 }, + /// size: wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 }, /// mip_level_count: 7, /// sample_count: 1, /// dimension: wgpu::TextureDimension::D3, diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 4c5d6c3f70..32a0dd312a 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -2,23 +2,22 @@ use wgt::{Backends, PowerPreference, RequestAdapterOptions}; use crate::{Adapter, Instance, Surface}; +#[cfg(any(not(target_arch = "wasm32"), feature = "wgc"))] +pub use wgc::instance::parse_backends_from_comma_list; +/// Always returns WEBGPU on wasm over webgpu. +#[cfg(all(target_arch = "wasm32", not(feature = "wgc")))] +pub fn parse_backends_from_comma_list(_string: &str) -> Backends { + Backends::BROWSER_WEBGPU +} + /// Get a set of backend bits from the environment variable WGPU_BACKEND. pub fn backend_bits_from_env() -> Option { - Some( - match std::env::var("WGPU_BACKEND") - .as_deref() - .map(str::to_lowercase) - .as_deref() - { - Ok("vulkan") => Backends::VULKAN, - Ok("dx12") => Backends::DX12, - Ok("dx11") => Backends::DX11, - Ok("metal") => Backends::METAL, - Ok("gl") => Backends::GL, - Ok("webgpu") => Backends::BROWSER_WEBGPU, - _ => return None, - }, - ) + std::env::var("WGPU_BACKEND") + .as_deref() + .map(str::to_lowercase) + .ok() + .as_deref() + .map(parse_backends_from_comma_list) } /// Get a power preference from the environment variable WGPU_POWER_PREF @@ -79,8 +78,7 @@ pub async fn initialize_adapter_from_env_or_default( None => { instance .request_adapter(&RequestAdapterOptions { - power_preference: power_preference_from_env() - .unwrap_or_else(PowerPreference::default), + power_preference: power_preference_from_env().unwrap_or_default(), compatible_surface, }) .await diff --git a/wgpu/src/util/mod.rs b/wgpu/src/util/mod.rs index f0a115a7c2..d50ee9796c 100644 --- a/wgpu/src/util/mod.rs +++ b/wgpu/src/util/mod.rs @@ -15,10 +15,7 @@ use std::{ pub use belt::StagingBelt; pub use device::{BufferInitDescriptor, DeviceExt}; pub use encoder::RenderEncoder; -pub use init::{ - backend_bits_from_env, initialize_adapter_from_env, initialize_adapter_from_env_or_default, - power_preference_from_env, -}; +pub use init::*; /// Treat the given byte slice as a SPIR-V module. ///