mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 14:55:05 +00:00
Improve texture creation validation
This commit is contained in:
parent
0bb6bb8647
commit
b8b7561796
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user