Skip to content

Commit 6e19a1a

Browse files
committed
feat(core): Expose descriptor validation separately from create_texture
1 parent 7a65558 commit 6e19a1a

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Bottom level categories:
4747
#### General
4848

4949
- Support the `wasm64-unknown-unknown` target for the web backend. Building for wasm64 requires a nightly toolchain with `-Z build-std=std,panic_abort`. By @nickbabcock in [#9836](https://github.com/gfx-rs/wgpu/pull/9836).
50-
- `wgpu-core` now exposes a `validate_device_descriptor` function that validates a device descriptor as `request_device` would. This may be useful in conjunction with `create_device_from_hal`. By @andyleiserson in [#9967](https://github.com/gfx-rs/wgpu/pull/9967).
50+
- `wgpu-core` now exposes `validate_device_descriptor` and `validate_texture_descriptor` functions that perform the same descriptor validation the corresponding resource creation APIs would, without actually creating a resource. This may be useful in conjunction with hal raw APIs. By @andyleiserson in [#9967](https://github.com/gfx-rs/wgpu/pull/9967) and TBD.
5151

5252
#### Hal
5353

wgpu-core/src/device/global.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ impl Global {
254254
(id, error)
255255
}
256256

257+
pub fn device_validate_texture_descriptor(
258+
&self,
259+
device_id: DeviceId,
260+
desc: &resource::TextureDescriptor,
261+
) -> Option<resource::CreateTextureError> {
262+
self.hub
263+
.devices
264+
.get(device_id)
265+
.validate_texture_descriptor(desc)
266+
.err()
267+
}
268+
257269
/// # Safety
258270
///
259271
/// - `hal_texture` must be created from `device_id` corresponding raw handle.

wgpu-core/src/device/resource.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,13 +1662,20 @@ impl Device {
16621662
}
16631663
}
16641664

1665-
fn create_texture_inner(
1665+
pub fn validate_texture_descriptor(
16661666
self: &Arc<Self>,
16671667
desc: &resource::TextureDescriptor,
1668-
) -> Result<Arc<Texture>, resource::CreateTextureError> {
1669-
use resource::{CreateTextureError, TextureDimensionError};
1668+
) -> Result<(), resource::CreateTextureError> {
1669+
self.validate_texture_descriptor_inner(desc)?;
1670+
Ok(())
1671+
}
16701672

1671-
self.check_is_valid()?;
1673+
fn validate_texture_descriptor_inner(
1674+
self: &Arc<Self>,
1675+
desc: &resource::TextureDescriptor,
1676+
) -> Result<(wgt::TextureFormatFeatures, Vec<TextureFormat>), resource::CreateTextureError>
1677+
{
1678+
use resource::{CreateTextureError, TextureDimensionError};
16721679

16731680
if desc.usage.is_empty() || desc.usage.contains_unknown_bits() {
16741681
return Err(CreateTextureError::InvalidUsage(desc.usage));
@@ -1939,6 +1946,17 @@ impl Device {
19391946
self.require_downlevel_flags(wgt::DownlevelFlags::VIEW_FORMATS)?;
19401947
}
19411948

1949+
Ok((format_features, hal_view_formats))
1950+
}
1951+
1952+
fn create_texture_inner(
1953+
self: &Arc<Self>,
1954+
desc: &resource::TextureDescriptor,
1955+
) -> Result<Arc<Texture>, resource::CreateTextureError> {
1956+
self.check_is_valid()?;
1957+
1958+
let (format_features, hal_view_formats) = self.validate_texture_descriptor_inner(desc)?;
1959+
19421960
let hal_usage = conv::map_texture_usage_for_texture(desc, &format_features);
19431961

19441962
let hal_desc = hal::TextureDescriptor {

0 commit comments

Comments
 (0)