Add missing map_label and ser/de to wgpu-types/texture#9480
Add missing map_label and ser/de to wgpu-types/texture#9480andyleiserson merged 1 commit intogfx-rs:trunkfrom
map_label and ser/de to wgpu-types/texture#9480Conversation
| 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, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I just don't understand why this has to live in wgpu? Can't bevy take this code themself?
There was a problem hiding this comment.
It's not really necessary. I added it only because other types have this function.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
But users would need to map TextureViewDescriptor and SamplerDescriptor to references when creating TextureView/Sampler, too.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I think this is a reasonable helper to provide. We already have it for quite a few of the descriptor types.
| 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, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I think this is a reasonable helper to provide. We already have it for quite a few of the descriptor types.
Description
TextureViewDescriptorandTextureDataOrdershould derive Serialize and Deserialize withserdefeature. Bevy currently uses wrappers to ser/de them https://github.com/bevyengine/bevy/blob/638c5dd29778c9ea718d44996b4832ed600c0169/crates/bevy_image/src/serialized_image.rs#L35-L99TextureViewDescriptorandSamplerDescriptorare missingmap_labelmethod, which is inconvenient to create them when the labels aren'tOption<&str>.Testing
CI
Squash or Rebase?
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.