diff --git a/deno_webgpu/device.rs b/deno_webgpu/device.rs index 5416f5379..211cdc513 100644 --- a/deno_webgpu/device.rs +++ b/deno_webgpu/device.rs @@ -680,29 +680,26 @@ impl GPUDevice { .buffers .into_iter() .map(|b| { - let layout = b.into_option().ok_or_else(|| { - JsErrorBox::type_error( - "Nullable GPUVertexBufferLayouts are currently not supported", - ) - })?; - - Ok(wgpu_core::pipeline::VertexBufferLayout { - array_stride: layout.array_stride, - step_mode: layout.step_mode.into(), - attributes: Cow::Owned( - layout - .attributes - .into_iter() - .map(|attr| wgpu_types::VertexAttribute { - format: attr.format.into(), - offset: attr.offset, - shader_location: attr.shader_location, - }) - .collect(), - ), - }) + b.into_option().map_or_else( + wgpu_core::pipeline::VertexBufferLayout::default, + |layout| wgpu_core::pipeline::VertexBufferLayout { + array_stride: layout.array_stride, + step_mode: layout.step_mode.into(), + attributes: Cow::Owned( + layout + .attributes + .into_iter() + .map(|attr| wgpu_types::VertexAttribute { + format: attr.format.into(), + offset: attr.offset, + shader_location: attr.shader_location, + }) + .collect(), + ), + }, + ) }) - .collect::>()?, + .collect(), ), }; diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index 3c4b52cc7..3bc3f7f6d 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -371,6 +371,17 @@ pub struct VertexBufferLayout<'a> { pub attributes: Cow<'a, [wgt::VertexAttribute]>, } +/// A null vertex buffer layout that may be placed in unused slots. +impl Default for VertexBufferLayout<'_> { + fn default() -> Self { + Self { + array_stride: Default::default(), + step_mode: Default::default(), + attributes: Cow::Borrowed(&[]), + } + } +} + /// Describes the vertex process in a render pipeline. #[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]