diff --git a/wgpu-core-remote-types/src/lib.rs b/wgpu-core-remote-types/src/lib.rs index fa4e5ca82..f120db261 100644 --- a/wgpu-core-remote-types/src/lib.rs +++ b/wgpu-core-remote-types/src/lib.rs @@ -53,3 +53,31 @@ pub type QueueDescriptor<'a> = wgt::QueueDescriptor>; pub type BufferDescriptor<'a> = wgt::BufferDescriptor>; pub type TextureDescriptor<'a> = wgt::TextureDescriptor, Vec>; pub type ExternalTextureDescriptor<'a> = wgt::ExternalTextureDescriptor>; + +/// Describes a `TextureView`. +/// +/// Corresponds to [WebGPU `GPUTextureViewDescriptor`](https://gpuweb.github.io/gpuweb/#dictdef-gputextureviewdescriptor). +#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)] +#[serde(default)] +pub struct TextureViewDescriptor<'a> { + /// Debug label of the texture view. + /// + /// This will show up in graphics debuggers for easy identification. + pub label: Label<'a>, + /// Format of the texture view, or `None` for the same format as the texture + /// itself. + /// + /// At this time, it must be the same the underlying format of the texture. + pub format: Option, + /// The dimension of the texture view. + /// + /// - For 1D textures, this must be `D1`. + /// - For 2D textures it must be one of `D2`, `D2Array`, `Cube`, or `CubeArray`. + /// - For 3D textures it must be `D3`. + pub dimension: Option, + /// The allowed usage(s) for the texture view. Must be a subset of the usage flags of the texture. + /// If not provided, defaults to the full set of usage flags of the texture. + pub usage: Option, + /// Range within the texture that is accessible via this view. + pub range: wgt::ImageSubresourceRange, +} diff --git a/wgpu-core-remote/src/global/device.rs b/wgpu-core-remote/src/global/device.rs index d22d1e14b..b97cd85c6 100644 --- a/wgpu-core-remote/src/global/device.rs +++ b/wgpu-core-remote/src/global/device.rs @@ -1,9 +1,10 @@ use alloc::{borrow::Cow, boxed::Box, sync::Arc, vec::Vec}; +use core::ops::Deref; use core::ptr::NonNull; use wgpu_core_remote_types::{ encoders::RenderBundleDescriptor, pipelines::{ComputePipelineDescriptor, RenderPipelineDescriptor}, - BufferDescriptor, ExternalTextureDescriptor, TextureDescriptor, + BufferDescriptor, ExternalTextureDescriptor, TextureDescriptor, TextureViewDescriptor, }; use wgpu_core::{ @@ -322,7 +323,7 @@ impl Global { pub fn texture_create_view( &self, texture_id: id::TextureId, - desc: &resource::TextureViewDescriptor, + desc: &TextureViewDescriptor, id_in: id::TextureViewId, ) -> (id::TextureViewId, Option) { let mut hub = self.hub.borrow_mut(); @@ -334,7 +335,15 @@ impl Global { let texture = textures.get(texture_id); - let (view, error) = texture.create_view(desc); + let desc = resource::TextureViewDescriptor { + label: desc.label.as_ref().map(|s| Cow::Borrowed(s.deref())), + format: desc.format, + dimension: desc.dimension, + usage: desc.usage, + range: desc.range, + }; + + let (view, error) = texture.create_view(&desc); let id = texture_views.assign(id_in, view);