Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve detection and validation of cubemap views #2331

Merged
merged 1 commit into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,14 @@ impl<A: HalApi> Device<A> {
) -> Result<resource::Texture<A>, resource::CreateTextureError> {
let format_desc = desc.format.describe();

// Depth volume textures can't be written to - depth forbids COPY_DST and volume textures can't be rendered to - therefore they aren't allowed.
// Depth textures can only be 2D
if format_desc.sample_type == wgt::TextureSampleType::Depth
&& desc.dimension == wgt::TextureDimension::D3
&& desc.dimension != wgt::TextureDimension::D2
{
return Err(resource::CreateTextureError::CannotCreateDepthVolumeTexture(desc.format));
return Err(resource::CreateTextureError::InvalidDepthKind(
desc.dimension,
desc.format,
));
}

let format_features = self
Expand Down Expand Up @@ -779,6 +782,7 @@ impl<A: HalApi> Device<A> {

let view_dim = match desc.dimension {
Some(dim) => {
// check if the dimension is compatible with the texture
if texture.desc.dimension != dim.compatible_texture_dimension() {
return Err(
resource::CreateTextureViewError::InvalidTextureViewDimension {
Expand All @@ -787,6 +791,14 @@ impl<A: HalApi> Device<A> {
},
);
}
// check if multisampled texture is seen as anything but 2D
match dim {
wgt::TextureViewDimension::D2 | wgt::TextureViewDimension::D2Array => {}
_ if texture.desc.sample_count > 1 => {
return Err(resource::CreateTextureViewError::InvalidMultisampledTextureViewDimension(dim));
}
_ => {}
}
dim
}
None => match texture.desc.dimension {
Expand Down
6 changes: 4 additions & 2 deletions wgpu-core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ pub enum TextureDimensionError {
pub enum CreateTextureError {
#[error(transparent)]
Device(#[from] DeviceError),
#[error("Depth Texture format {0:?} can't be used for volume textures")]
CannotCreateDepthVolumeTexture(wgt::TextureFormat),
#[error("Textures cannot have empty usage flags")]
EmptyUsage,
#[error(transparent)]
InvalidDimension(#[from] TextureDimensionError),
#[error("Depth texture kind {0:?} of format {0:?} can't be created")]
InvalidDepthKind(wgt::TextureDimension, wgt::TextureFormat),
#[error("texture descriptor mip level count ({0}) is invalid")]
InvalidMipLevelCount(u32),
#[error("The texture usages {0:?} are not allowed on a texture of type {1:?}")]
Expand Down Expand Up @@ -382,6 +382,8 @@ pub enum CreateTextureViewError {
view: wgt::TextureViewDimension,
texture: wgt::TextureDimension,
},
#[error("Invalid texture view dimension `{0:?}` of a multisampled texture")]
InvalidMultisampledTextureViewDimension(wgt::TextureViewDimension),
#[error("Invalid texture depth `{depth}` for texture view of dimension `Cubemap`. Cubemap views must use images of size 6.")]
InvalidCubemapTextureDepth { depth: u32 },
#[error("Invalid texture depth `{depth}` for texture view of dimension `CubemapArray`. Cubemap views must use images with sizes which are a multiple of 6.")]
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ impl crate::Device<super::Api> for super::Device {
//HACK: detect a cube map
let cube_count = if desc.size.width == desc.size.height
&& desc.size.depth_or_array_layers % 6 == 0
&& desc.sample_count == 1
{
Some(desc.size.depth_or_array_layers / 6)
} else {
Expand Down
6 changes: 5 additions & 1 deletion wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,11 @@ impl crate::Device<super::Api> for super::Device {
let copy_size = conv::map_extent_to_copy_size(&desc.size, desc.dimension);

let mut raw_flags = vk::ImageCreateFlags::empty();
if desc.dimension == wgt::TextureDimension::D2 && desc.size.depth_or_array_layers % 6 == 0 {
if desc.dimension == wgt::TextureDimension::D2
&& desc.size.depth_or_array_layers % 6 == 0
&& desc.sample_count == 1
&& desc.size.width == desc.size.height
{
raw_flags |= vk::ImageCreateFlags::CUBE_COMPATIBLE;
}

Expand Down