From b8b7561796b7215e0953da12c76032b1d6fa9129 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 23 Aug 2020 23:54:58 -0400 Subject: [PATCH 1/2] Improve texture creation validation --- wgpu-core/src/command/transfer.rs | 9 +-------- wgpu-core/src/conv.rs | 17 +++++++++++++++-- wgpu-core/src/device/mod.rs | 2 +- wgpu-core/src/resource.rs | 11 +++++++++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 0a778f2e7..8ffc56bae 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -10,7 +10,7 @@ use crate::{ device::{all_buffer_stages, all_image_stages}, hub::{GfxBackend, Global, GlobalIdentityHandlerFactory, Storage, Token}, id::{BufferId, CommandEncoderId, TextureId}, - resource::{BufferUse, Texture, TextureUse}, + resource::{BufferUse, Texture, TextureErrorDimension, TextureUse}, span, track::TextureSelector, }; @@ -32,13 +32,6 @@ pub enum CopySide { Destination, } -#[derive(Clone, Debug)] -pub enum TextureErrorDimension { - X, - Y, - Z, -} - /// Error encountered while attempting a data transfer. #[derive(Clone, Debug, Error)] pub enum TransferError { diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index 9b58bb18f..9b0f5fda2 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -575,6 +575,19 @@ pub fn map_texture_dimension_size( use resource::TextureDimensionError as Tde; use wgt::TextureDimension::*; + let zero_dim = if width == 0 { + Some(resource::TextureErrorDimension::X) + } else if height == 0 { + Some(resource::TextureErrorDimension::Y) + } else if depth == 0 { + Some(resource::TextureErrorDimension::Z) + } else { + None + }; + if let Some(dim) = zero_dim { + return Err(resource::TextureDimensionError::Zero(dim)); + } + Ok(match dimension { D1 => { if height != 1 { @@ -583,14 +596,14 @@ pub fn map_texture_dimension_size( if sample_size != 1 { return Err(Tde::InvalidSampleCount(sample_size)); } - let layers = depth.try_into().or(Err(Tde::TooManyLayers(depth)))?; + let layers = depth.try_into().unwrap_or(!0); H::D1(width, layers) } D2 => { if sample_size > 32 || !is_power_of_two(sample_size) { return Err(Tde::InvalidSampleCount(sample_size)); } - let layers = depth.try_into().or(Err(Tde::TooManyLayers(depth)))?; + let layers = depth.try_into().unwrap_or(!0); H::D2(width, height, layers, sample_size as u8) } D3 => { diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 50b7c96d3..d7f142d20 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -482,7 +482,7 @@ impl Device { let usage = conv::map_texture_usage(desc.usage, aspects); let mip_level_count = desc.mip_level_count; - if mip_level_count >= MAX_MIP_LEVELS { + if mip_level_count == 0 && mip_level_count > kind.compute_num_levels() as u32 { return Err(resource::CreateTextureError::InvalidMipLevelCount( mip_level_count, )); diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index f0afbd7c4..9767046a7 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -213,10 +213,17 @@ pub struct Texture { pub(crate) life_guard: LifeGuard, } +#[derive(Clone, Debug)] +pub enum TextureErrorDimension { + X, + Y, + Z, +} + #[derive(Clone, Debug, Error)] pub enum TextureDimensionError { - #[error("too many layers ({0}) for texture array")] - TooManyLayers(u32), + #[error("Dimension {0:?} is zero")] + Zero(TextureErrorDimension), #[error("1D textures must have height set to 1")] InvalidHeight, #[error("sample count {0} is invalid")] From 0779a5ce2f83ee87664e08aade0300570ffb074a Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 24 Aug 2020 12:37:32 -0400 Subject: [PATCH 2/2] Allow CI fail on Windows Nightly, for now --- .github/workflows/ci.yml | 35 ++++++++++++++--------------------- bors.toml | 4 +--- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60cd72c44..a89b2fbfb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,48 +44,41 @@ jobs: strategy: fail-fast: false matrix: - name: - [ - MacOS Stable, - MacOS Nightly, - Ubuntu Stable, - Ubuntu Nightly, - Windows Stable, - Windows Nightly, - ] + os: [macos-10.15, ubuntu-18.04, windows-2019] + channel: [stable, nightly] include: - - os: macos-10.15 - name: MacOS Stable + - name: MacOS Stable channel: stable + os: macos-10.15 build_command: cargo clippy additional_core_features: trace additional_player_features: winit - - os: macos-10.15 - name: MacOS Nightly + - name: MacOS Nightly + os: macos-10.15 channel: nightly build_command: cargo test additional_core_features: additional_player_features: - - os: ubuntu-18.04 - name: Ubuntu Stable + - name: Ubuntu Stable + os: ubuntu-18.04 channel: stable build_command: cargo clippy additional_core_features: trace,replay additional_player_features: - - os: ubuntu-18.04 - name: Ubuntu Nightly + - name: Ubuntu Nightly + os: ubuntu-18.04 channel: nightly build_command: cargo test additional_core_features: serial-pass additional_player_features: winit - - os: windows-2019 - name: Windows Stable + - name: Windows Stable + os: windows-2019 channel: stable build_command: rustup default stable-msvc; cargo clippy additional_core_features: trace,serial-pass additional_player_features: renderdoc - - os: windows-2019 - name: Windows Nightly + - name: Windows Nightly + os: windows-2019 channel: nightly build_command: rustup default nightly-msvc; cargo test additional_core_features: diff --git a/bors.toml b/bors.toml index f83b5282a..38ac9b451 100644 --- a/bors.toml +++ b/bors.toml @@ -6,7 +6,5 @@ status = [ "Ubuntu Stable", "Ubuntu Nightly", "Windows Stable", - "Windows Nightly", + #"Windows Nightly", ] - -timeout_sec = 18000 # 5 hours