mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Merge #893
893: Improve texture creation validation r=cwfitzgerald a=kvark **Connections** Fixes https://github.com/gfx-rs/wgpu-rs/issues/528#issuecomment-678853886 **Description** Improves the mipmap levels check. Note that it also removes the `TooManyLayers` error, and instead produces max `u16` value. This is to be followed up with a check for *real* limits, which has to happen regardless, and trying to catch it on the number conversion step seems wasteful. **Testing** Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
35
.github/workflows/ci.yml
vendored
35
.github/workflows/ci.yml
vendored
@@ -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:
|
||||
|
||||
@@ -6,7 +6,5 @@ status = [
|
||||
"Ubuntu Stable",
|
||||
"Ubuntu Nightly",
|
||||
"Windows Stable",
|
||||
"Windows Nightly",
|
||||
#"Windows Nightly",
|
||||
]
|
||||
|
||||
timeout_sec = 18000 # 5 hours
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -482,7 +482,7 @@ impl<B: GfxBackend> Device<B> {
|
||||
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,
|
||||
));
|
||||
|
||||
@@ -213,10 +213,17 @@ pub struct Texture<B: hal::Backend> {
|
||||
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")]
|
||||
|
||||
Reference in New Issue
Block a user