Skip to content

feat(core): Expose descriptor validation separately from create_texture - #9979

Merged
andyleiserson merged 3 commits into
gfx-rs:trunkfrom
andyleiserson:jj-push-nswk
Aug 3, 2026
Merged

feat(core): Expose descriptor validation separately from create_texture#9979
andyleiserson merged 3 commits into
gfx-rs:trunkfrom
andyleiserson:jj-push-nswk

Conversation

@andyleiserson

@andyleiserson andyleiserson commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Similar to #9967, but for textures this time.

Testing
Simple refactor.

Squash or Rebase? Squash

Checklist

  • CHANGELOG.md entries for the user-facing effects of this change are present.

@sagudev sagudev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread wgpu-core/src/device/resource.rs
Comment thread wgpu-core/src/device/resource.rs Outdated
self: &Arc<Self>,
desc: &resource::TextureDescriptor,
) -> Result<Arc<Texture>, resource::CreateTextureError> {
self.check_is_valid()?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this not done in validate_texture_descriptor_inner?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I considered it, but decided that the device not being valid is independent of validating the texture descriptor. (I didn't see any use of the device by validate_texture_descriptor other than immutable capability lookup.) Although I also don't see check_is_valid in create_texture_from_hal_inner, we should probably add that. And I'm not opposed to adding the device validity check to the descriptor validation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We would need check_is_valid in validate_texture_descriptor for servo and I think this also makes more sense conceptually as device.validate_texture_descriptor actually validates tex desc against device.

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.

I would tend to agree with @sagudev, because the validation asks, "If I create a texture at this point in time, is this valid?" If the device is invalid, then the answer is, "Definitely." forever onward.

If device validity were intermittent, I could see an argument for keeping these separate, but a device never becomes valid again, so it doesn't seem harmful to report that issue earlier than when creation may actually happen.

Although I also don't see check_is_valid in create_texture_from_hal_inner, we should probably add that. And I'm not opposed to adding the device validity check to the descriptor validation.

Yes please!

@ErichDonGubler ErichDonGubler left a comment

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.

LGTM, modulo resolution @sagudev's point about device validity (which I'm trusting you to resolve before merging).

Comment thread CHANGELOG.md

- 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).
- `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.

@ErichDonGubler ErichDonGubler added area: validation Issues related to validation, diagnostics, and error handling area: api Issues related to API surface kind: refactor Making existing function faster or nicer type: enhancement New feature or request and removed kind: refactor Making existing function faster or nicer labels Aug 3, 2026
- Move from `create_texture_inner` to `validate_texture_descriptor_inner`
- Add check in `create_texture_from_hal_inner`
@andyleiserson
andyleiserson merged commit d5d8ed8 into gfx-rs:trunk Aug 3, 2026
60 checks passed
@andyleiserson
andyleiserson deleted the jj-push-nswk branch August 3, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: api Issues related to API surface area: validation Issues related to validation, diagnostics, and error handling type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants