Skip to content

Add missing map_label and ser/de to wgpu-types/texture#9480

Merged
andyleiserson merged 1 commit intogfx-rs:trunkfrom
beicause:wgpu-types-texture-serde-map-label
May 7, 2026
Merged

Add missing map_label and ser/de to wgpu-types/texture#9480
andyleiserson merged 1 commit intogfx-rs:trunkfrom
beicause:wgpu-types-texture-serde-map-label

Conversation

@beicause
Copy link
Copy Markdown
Contributor

@beicause beicause commented May 1, 2026

Description
TextureViewDescriptor and TextureDataOrder should derive Serialize and Deserialize with serde feature. Bevy currently uses wrappers to ser/de them https://github.com/bevyengine/bevy/blob/638c5dd29778c9ea718d44996b4832ed600c0169/crates/bevy_image/src/serialized_image.rs#L35-L99

TextureViewDescriptor and SamplerDescriptor are missing map_label method, which is inconvenient to create them when the labels aren't Option<&str>.

Testing
CI

Squash or Rebase?
Squash

Checklist

  • I self-reviewed and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

Comment thread wgpu-types/src/texture.rs
Comment on lines +480 to +496
impl<L> TextureViewDescriptor<L> {
/// Takes a closure and maps the label of the texture view descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
TextureViewDescriptor {
label: fun(&self.label),
format: self.format,
dimension: self.dimension,
usage: self.usage,
aspect: self.aspect,
base_mip_level: self.base_mip_level,
mip_level_count: self.mip_level_count,
base_array_layer: self.base_array_layer,
array_layer_count: self.array_layer_count,
}
}
}
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.

I just don't understand why this has to live in wgpu? Can't bevy take this code themself?

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.

It's not really necessary. I added it only because other types have this function.

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.

@beicause Other types have this usually because it is used in wgpu code. For example I believe on the texture descriptor, the wgpu public API maps it to a wgpu-core-friendly generic.

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.

But users would need to map TextureViewDescriptor and SamplerDescriptor to references when creating TextureView/Sampler, too.

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.

I'm sorta of the opinion that wgpu itself doesn't need this, since its a minor helper function that likely only bevy would use and it wouldn't hurt to have it live in bevy. But I also don't really care

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a reasonable helper to provide. We already have it for quite a few of the descriptor types.

Comment thread wgpu-types/src/texture.rs
Comment on lines +480 to +496
impl<L> TextureViewDescriptor<L> {
/// Takes a closure and maps the label of the texture view descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
TextureViewDescriptor {
label: fun(&self.label),
format: self.format,
dimension: self.dimension,
usage: self.usage,
aspect: self.aspect,
base_mip_level: self.base_mip_level,
mip_level_count: self.mip_level_count,
base_array_layer: self.base_array_layer,
array_layer_count: self.array_layer_count,
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a reasonable helper to provide. We already have it for quite a few of the descriptor types.

@andyleiserson andyleiserson merged commit 4448bc7 into gfx-rs:trunk May 7, 2026
93 of 94 checks passed
@andyleiserson andyleiserson mentioned this pull request May 7, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants