Skip to content

Commit 7fdc5f1

Browse files
authored
Improve various TextureView error messages (#8323)
1 parent e2f70c2 commit 7fdc5f1

File tree

3 files changed

+54
-43
lines changed

3 files changed

+54
-43
lines changed

tests/tests/wgpu-validation/api/texture.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn non_planar_texture_view_plane() {
145145
..Default::default()
146146
});
147147
},
148-
Some("Aspect Plane0 is not in the source texture format R8Unorm"),
148+
Some("Aspect Plane0 is not a valid aspect of the source texture format R8Unorm"),
149149
);
150150
}
151151

@@ -199,7 +199,7 @@ fn planar_texture_view_plane_out_of_bounds() {
199199
});
200200
},
201201
Some(&format!(
202-
"Aspect {view_aspect:?} is not in the source texture format {tex_format:?}"
202+
"Aspect {view_aspect:?} is not a valid aspect of the source texture format {tex_format:?}"
203203
)),
204204
);
205205
}
@@ -208,7 +208,7 @@ fn planar_texture_view_plane_out_of_bounds() {
208208
/// Ensures that attempting to create a texture view from a specific plane of a
209209
/// planar texture with an invalid format fails validation.
210210
#[test]
211-
fn planar_texture_view_plane_bad_format() {
211+
fn planar_texture_bad_view_format() {
212212
let required_features = wgpu::Features::TEXTURE_FORMAT_NV12
213213
| wgpu::Features::TEXTURE_FORMAT_P010
214214
| wgpu::Features::TEXTURE_FORMAT_16BIT_NORM;
@@ -222,39 +222,27 @@ fn planar_texture_view_plane_bad_format() {
222222
height: 256,
223223
depth_or_array_layers: 1,
224224
};
225-
for (tex_format, view_format, view_aspect) in [
226-
(
227-
wgpu::TextureFormat::NV12,
228-
wgpu::TextureFormat::Rg8Unorm,
229-
wgpu::TextureAspect::Plane0,
230-
),
231-
(
232-
wgpu::TextureFormat::P010,
233-
wgpu::TextureFormat::Rg16Unorm,
234-
wgpu::TextureAspect::Plane0,
235-
),
225+
for (tex_format, view_format) in [
226+
(wgpu::TextureFormat::NV12, wgpu::TextureFormat::Rg8Unorm),
227+
(wgpu::TextureFormat::P010, wgpu::TextureFormat::Rg16Unorm),
236228
] {
237-
let tex = device.create_texture(&wgpu::TextureDescriptor {
238-
label: None,
239-
dimension: wgpu::TextureDimension::D2,
240-
size,
241-
format: tex_format,
242-
usage: wgpu::TextureUsages::TEXTURE_BINDING,
243-
mip_level_count: 1,
244-
sample_count: 1,
245-
view_formats: &[],
246-
});
247229
fail(
248230
&device,
249231
|| {
250-
let _ = tex.create_view(&wgpu::TextureViewDescriptor {
251-
format: Some(view_format),
252-
aspect: view_aspect,
253-
..Default::default()
232+
let _ = device.create_texture(&wgpu::TextureDescriptor {
233+
label: None,
234+
dimension: wgpu::TextureDimension::D2,
235+
size,
236+
format: tex_format,
237+
usage: wgpu::TextureUsages::TEXTURE_BINDING,
238+
mip_level_count: 1,
239+
sample_count: 1,
240+
view_formats: &[view_format],
254241
});
255242
},
256243
Some(&format!(
257-
"unable to view texture {tex_format:?} as {view_format:?}"
244+
"The view format {view_format:?} is not compatible with texture \
245+
format {tex_format:?}, only changing srgb-ness is allowed."
258246
)),
259247
);
260248
}

wgpu-core/src/device/resource.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,8 @@ impl Device {
16511651
let level_end = texture.desc.mip_level_count;
16521652
if mip_level_end > level_end {
16531653
return Err(resource::CreateTextureViewError::TooManyMipLevels {
1654-
requested: mip_level_end,
1654+
base_mip_level: desc.range.base_mip_level,
1655+
mip_level_count: resolved_mip_level_count,
16551656
total: level_end,
16561657
});
16571658
}
@@ -1668,7 +1669,8 @@ impl Device {
16681669
let layer_end = texture.desc.array_layer_count();
16691670
if array_layer_end > layer_end {
16701671
return Err(resource::CreateTextureViewError::TooManyArrayLayers {
1671-
requested: array_layer_end,
1672+
base_array_layer: desc.range.base_array_layer,
1673+
array_layer_count: resolved_array_layer_count,
16721674
total: layer_end,
16731675
});
16741676
};

wgpu-core/src/resource.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,20 +1714,22 @@ pub enum CreateTextureViewError {
17141714
view: wgt::TextureViewDimension,
17151715
texture: wgt::TextureDimension,
17161716
},
1717-
#[error("Texture view format `{0:?}` is not renderable")]
1717+
#[error("Texture view format `{0:?}` cannot be used as a render attachment. Make sure the format supports RENDER_ATTACHMENT usage and required device features are enabled.")]
17181718
TextureViewFormatNotRenderable(wgt::TextureFormat),
1719-
#[error("Texture view format `{0:?}` is not storage bindable")]
1719+
#[error("Texture view format `{0:?}` cannot be used as a storage binding. Make sure the format supports STORAGE usage and required device features are enabled.")]
17201720
TextureViewFormatNotStorage(wgt::TextureFormat),
1721-
#[error("Invalid texture view usage `{view:?}` with texture of usage `{texture:?}`")]
1721+
#[error("Texture view usages (`{view:?}`) must be a subset of the texture's original usages (`{texture:?}`)")]
17221722
InvalidTextureViewUsage {
17231723
view: wgt::TextureUsages,
17241724
texture: wgt::TextureUsages,
17251725
},
1726-
#[error("Invalid texture view dimension `{0:?}` of a multisampled texture")]
1726+
#[error("Texture view dimension `{0:?}` cannot be used with a multisampled texture")]
17271727
InvalidMultisampledTextureViewDimension(wgt::TextureViewDimension),
1728-
#[error("Invalid texture depth `{depth}` for texture view of dimension `Cubemap`. Cubemap views must use images of size 6.")]
1728+
#[error(
1729+
"TextureView has an arrayLayerCount of {depth}. Views of type `Cube` must have arrayLayerCount of 6."
1730+
)]
17291731
InvalidCubemapTextureDepth { depth: u32 },
1730-
#[error("Invalid texture depth `{depth}` for texture view of dimension `CubemapArray`. Cubemap views must use images with sizes which are a multiple of 6.")]
1732+
#[error("TextureView has an arrayLayerCount of {depth}. Views of type `CubeArray` must have an arrayLayerCount that is a multiple of 6.")]
17311733
InvalidCubemapArrayTextureDepth { depth: u32 },
17321734
#[error("Source texture width and height must be equal for a texture view of dimension `Cube`/`CubeArray`")]
17331735
InvalidCubeTextureViewSize,
@@ -1736,22 +1738,41 @@ pub enum CreateTextureViewError {
17361738
#[error("Array layer count is 0")]
17371739
ZeroArrayLayerCount,
17381740
#[error(
1739-
"TextureView mip level count + base mip level {requested} must be <= Texture mip level count {total}"
1741+
"TextureView spans mip levels [{base_mip_level}, {end_mip_level}) \
1742+
(mipLevelCount {mip_level_count}) but the texture view only has {total} total mip levels",
1743+
end_mip_level = base_mip_level + mip_level_count
1744+
)]
1745+
TooManyMipLevels {
1746+
base_mip_level: u32,
1747+
mip_level_count: u32,
1748+
total: u32,
1749+
},
1750+
#[error(
1751+
"TextureView spans array layers [{base_array_layer}, {end_array_layer}) \
1752+
(arrayLayerCount {array_layer_count}) but the texture view only has {total} total layers",
1753+
end_array_layer = base_array_layer + array_layer_count
17401754
)]
1741-
TooManyMipLevels { requested: u32, total: u32 },
1742-
#[error("TextureView array layer count + base array layer {requested} must be <= Texture depth/array layer count {total}")]
1743-
TooManyArrayLayers { requested: u32, total: u32 },
1755+
TooManyArrayLayers {
1756+
base_array_layer: u32,
1757+
array_layer_count: u32,
1758+
total: u32,
1759+
},
17441760
#[error("Requested array layer count {requested} is not valid for the target view dimension {dim:?}")]
17451761
InvalidArrayLayerCount {
17461762
requested: u32,
17471763
dim: wgt::TextureViewDimension,
17481764
},
1749-
#[error("Aspect {requested_aspect:?} is not in the source texture format {texture_format:?}")]
1765+
#[error(
1766+
"Aspect {requested_aspect:?} is not a valid aspect of the source texture format {texture_format:?}"
1767+
)]
17501768
InvalidAspect {
17511769
texture_format: wgt::TextureFormat,
17521770
requested_aspect: wgt::TextureAspect,
17531771
},
1754-
#[error("Unable to view texture {texture:?} as {view:?}")]
1772+
#[error(
1773+
"Trying to create a view of format {view:?} of a texture with format {texture:?}, \
1774+
but this view format is not present in the texture's viewFormat array"
1775+
)]
17551776
FormatReinterpretation {
17561777
texture: wgt::TextureFormat,
17571778
view: wgt::TextureFormat,

0 commit comments

Comments
 (0)