Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Bottom level categories:
#### General

- 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).
- `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).
- Many types now offer `pub const fn default()` in addition to implementing the `Default` trait, allowing constants to make use of default values. By @kpreid in [#9929](https://github.com/gfx-rs/wgpu/pull/9929).
- `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 [#9979](https://github.com/gfx-rs/wgpu/pull/9979).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: We intend to expand this list to other resources, too, right? Sounds like a multi-line list would be easier to review than an inline comma-separated list in prose going forward.


#### Hal

Expand Down
12 changes: 12 additions & 0 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ impl Global {
(id, error)
}

pub fn device_validate_texture_descriptor(
&self,
device_id: DeviceId,
desc: &resource::TextureDescriptor,
) -> Option<resource::CreateTextureError> {
self.hub
.devices
.get(device_id)
.validate_texture_descriptor(desc)
.err()
}

/// # Safety
///
/// - `hal_texture` must be created from `device_id` corresponding raw handle.
Expand Down
34 changes: 32 additions & 2 deletions wgpu-core/src/device/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,8 @@ impl Device {
desc: &resource::TextureDescriptor,
initial_state: wgt::TextureUses,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
self.check_is_valid()?;

let format_features = self
.describe_format_features(desc.format)
.map_err(|error| resource::CreateTextureError::MissingFeatures(desc.format, error))?;
Expand Down Expand Up @@ -1662,10 +1664,29 @@ impl Device {
}
}

fn create_texture_inner(
/// Validate a texture descriptor.
///
/// This applies the same validation as [`Self::create_texture`], without
/// actually creating a texture.
pub fn validate_texture_descriptor(
self: &Arc<Self>,
desc: &resource::TextureDescriptor,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
) -> Result<(), resource::CreateTextureError> {
self.validate_texture_descriptor_inner(desc)?;
Ok(())
}

/// Validate a texture descriptor.
///
/// Implements the [validating GPUTextureDescriptor] algorithm, with some
/// `wgpu` extensions.
///
/// [validating GPUTextureDescriptor]: https://www.w3.org/TR/webgpu/#abstract-opdef-validating-gputexturedescriptor
fn validate_texture_descriptor_inner(
Comment thread
andyleiserson marked this conversation as resolved.
self: &Arc<Self>,
desc: &resource::TextureDescriptor,
) -> Result<(wgt::TextureFormatFeatures, Vec<TextureFormat>), resource::CreateTextureError>
{
use resource::{CreateTextureError, TextureDimensionError};

self.check_is_valid()?;
Expand Down Expand Up @@ -1939,6 +1960,15 @@ impl Device {
self.require_downlevel_flags(wgt::DownlevelFlags::VIEW_FORMATS)?;
}

Ok((format_features, hal_view_formats))
}

fn create_texture_inner(
self: &Arc<Self>,
desc: &resource::TextureDescriptor,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
let (format_features, hal_view_formats) = self.validate_texture_descriptor_inner(desc)?;

let hal_usage = conv::map_texture_usage_for_texture(desc, &format_features);

let hal_desc = hal::TextureDescriptor {
Expand Down