Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ Bottom level categories:

## Unreleased

### Major changes

#### Optional vertex buffer slots

This allows gaps in `VertexState`'s `buffers` and adds support for unbinding vertex buffers, bringing us in compliance with the WebGPU spec. As a result of this, `VertexState`'s `buffers` field now has type of `&[Option<VertexBufferLayout>]`. To migrate, wrap vertex buffer layouts in `Some`:

```diff
let vertex_state = wgpu::VertexState {
module: &vs_module,
entry_point: Some("vs_main"),
compilation_options: wgpu::PipelineCompilationOptions::default(),
buffers: &[
- &vertex_buffer_layout
+ Some(&vertex_buffer_layout)
],
};
```

By @teoxoy in [#9351](https://github.com/gfx-rs/wgpu/pull/9351).

### Added/New Features

#### General
Expand Down
4 changes: 2 additions & 2 deletions benches/benches/wgpu-benchmark/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ impl RenderpassState {

let mut vertex_buffer_layouts = Vec::with_capacity(VERTEX_BUFFERS_PER_DRAW as usize);
for attributes in &vertex_buffer_attributes {
vertex_buffer_layouts.push(wgpu::VertexBufferLayout {
vertex_buffer_layouts.push(Some(wgpu::VertexBufferLayout {
array_stride: 16,
step_mode: wgpu::VertexStepMode::Vertex,
attributes,
});
}));
}

let pipeline =
Expand Down
6 changes: 3 additions & 3 deletions cts_runner/fail.lst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ webgpu:api,validation,createBindGroup:texture,resource_state:* // crash, https:/
webgpu:api,validation,createView:texture_state:* // 0%, https://github.com/gfx-rs/wgpu/issues/7881
webgpu:api,validation,encoding,cmds,copyTextureToTexture:copy_ranges:* // ***, https://github.com/gfx-rs/wgpu/issues/8118
webgpu:api,validation,encoding,cmds,debug:* // 92%, https://github.com/gfx-rs/wgpu/issues/8039
webgpu:api,validation,encoding,cmds,render,* // https://github.com/gfx-rs/wgpu/issues/7912
webgpu:api,validation,encoding,cmds,render,draw:max_draw_count:* // https://github.com/gfx-rs/wgpu/issues/8737
webgpu:api,validation,encoding,cmds,render,indirect_draw:indirect_offset_alignment:* // render bundle
webgpu:api,validation,encoding,cmds,render,indirect_draw:indirect_offset_oob:* // unwrap on None in wgpu-core/src/indirect_validation/draw.rs:432:18
webgpu:api,validation,encoding,cmds,setBindGroup:dynamic_offsets_match_expectations_in_pass_encoder:* // deno unwrap
webgpu:api,validation,encoding,cmds,setBindGroup:state_and_binding_index:encoderType="compute%20pass";state="destroyed";* // https://github.com/gfx-rs/wgpu/issues/7881
webgpu:api,validation,encoding,cmds,setBindGroup:state_and_binding_index:encoderType="render%20bundle";state="destroyed";* // https://github.com/gfx-rs/wgpu/issues/7881
Expand All @@ -48,8 +50,6 @@ webgpu:api,validation,render_pipeline,inter_stage:* // 15%, inter-stage type val
webgpu:api,validation,render_pipeline,misc:external_texture:* // 0%, no external texture in deno
webgpu:api,validation,render_pipeline,multisample_state:* // 60%, https://github.com/gfx-rs/wgpu/issues/8779
webgpu:api,validation,render_pipeline,overrides:* // 17%, missing validation: invalid pipeline constant identifiers silently ignored
webgpu:api,validation,render_pipeline,vertex_state:max_vertex_attribute_limit:* // 0%, empty vertex buffers not counted, GPUInternalError no message
webgpu:api,validation,render_pipeline,vertex_state:max_vertex_buffer_limit:* // 0%, empty vertex buffers not counted toward limit
webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_contained_in_stride:* // fails on metal in CI https://github.com/gfx-rs/wgpu/issues/8312
webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_offset_alignment:* // fails on metal in CI
webgpu:api,validation,resource_usages,texture,in_pass_encoder:subresources_and_binding_types_combination_for_color:* // 92%, https://github.com/gfx-rs/wgpu/issues/3126
Expand Down
5 changes: 5 additions & 0 deletions cts_runner/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ webgpu:api,validation,encoding,cmds,debug:debug_group_balanced:encoderType="rend
webgpu:api,validation,encoding,cmds,debug:debug_group:*
webgpu:api,validation,encoding,cmds,debug:debug_marker:*
webgpu:api,validation,encoding,cmds,index_access:*
webgpu:api,validation,encoding,cmds,render,draw:buffer_binding_overlap:*
webgpu:api,validation,encoding,cmds,render,draw:index_buffer_OOB:*
webgpu:api,validation,encoding,cmds,render,draw:unused_buffer_bound:*
webgpu:api,validation,encoding,cmds,render,draw:vertex_buffer_OOB:*
webgpu:api,validation,encoding,cmds,render,dynamic_state:*
webgpu:api,validation,encoding,cmds,render,indirect_draw:indirect_buffer_state:*
webgpu:api,validation,encoding,cmds,render,indirect_draw:indirect_buffer_usage:*
webgpu:api,validation,encoding,cmds,render,indirect_draw:indirect_buffer,device_mismatch:*
webgpu:api,validation,encoding,cmds,render,setIndexBuffer:*
Expand Down Expand Up @@ -271,7 +274,9 @@ webgpu:api,validation,render_pipeline,primitive_state:*
webgpu:api,validation,render_pipeline,resource_compatibility:*
webgpu:api,validation,render_pipeline,shader_module:*
webgpu:api,validation,render_pipeline,vertex_state:many_attributes_overlapping:*
webgpu:api,validation,render_pipeline,vertex_state:max_vertex_attribute_limit:*
webgpu:api,validation,render_pipeline,vertex_state:max_vertex_buffer_array_stride_limit:*
webgpu:api,validation,render_pipeline,vertex_state:max_vertex_buffer_limit:*
fails-if(metal) webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_contained_in_stride:*
fails-if(metal) webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_offset_alignment:*
webgpu:api,validation,render_pipeline,vertex_state:vertex_attribute_shaderLocation_limit:*
Expand Down
3 changes: 1 addition & 2 deletions deno_webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ ObjectDefineProperty(GPUSupportedLimitsPrototype, privateCustomInspect, {
"maxTextureDimension3D",
"maxTextureArrayLayers",
"maxBindGroups",
// TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
// "maxBindGroupsPlusVertexBuffers",
"maxBindGroupsPlusVertexBuffers",
"maxBindingsPerBindGroup",
"maxDynamicUniformBuffersPerPipelineLayout",
"maxDynamicStorageBuffersPerPipelineLayout",
Expand Down
5 changes: 4 additions & 1 deletion deno_webgpu/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ impl GPUSupportedLimits {
self.0.max_bind_groups
}

// TODO(@crowlKats): support max_bind_groups_plus_vertex_buffers
#[getter]
fn maxBindGroupsPlusVertexBuffers(&self) -> u32 {
self.0.max_bind_groups_plus_vertex_buffers
}

#[getter]
fn maxBindingsPerBindGroup(&self) -> u32 {
Expand Down
9 changes: 4 additions & 5 deletions deno_webgpu/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,8 @@ impl GPUDevice {
.buffers
.into_iter()
.map(|b| {
b.into_option().map_or_else(
wgpu_core::pipeline::VertexBufferLayout::default,
|layout| wgpu_core::pipeline::VertexBufferLayout {
b.into_option().map(|layout| {
wgpu_core::pipeline::VertexBufferLayout {
array_stride: layout.array_stride,
step_mode: layout.step_mode.into(),
attributes: Cow::Owned(
Expand All @@ -850,8 +849,8 @@ impl GPUDevice {
})
.collect(),
),
},
)
}
})
})
.collect(),
),
Expand Down
4 changes: 2 additions & 2 deletions deno_webgpu/render_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl GPURenderBundleEncoder {
fn set_vertex_buffer(
&self,
#[webidl(options(enforce_range = true))] slot: u32,
#[webidl] buffer: Ptr<GPUBuffer>, // TODO(wgpu): support nullable buffer
#[webidl] buffer: Nullable<Ptr<GPUBuffer>>,
#[webidl(default = 0, options(enforce_range = true))] offset: u64,
#[webidl(options(enforce_range = true))] size: Option<u64>,
) -> Result<(), JsErrorBox> {
Expand All @@ -287,7 +287,7 @@ impl GPURenderBundleEncoder {
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
encoder,
slot,
buffer.id,
buffer.into_option().map(|buffer| buffer.id),
offset,
size.and_then(NonZeroU64::new),
);
Expand Down
4 changes: 2 additions & 2 deletions deno_webgpu/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl GPURenderPassEncoder {
fn set_vertex_buffer(
&self,
#[webidl(options(enforce_range = true))] slot: u32,
#[webidl] buffer: Ptr<GPUBuffer>, // TODO(wgpu): support nullable buffer
#[webidl] buffer: Nullable<Ptr<GPUBuffer>>,
#[webidl(default = 0, options(enforce_range = true))] offset: u64,
#[webidl(options(enforce_range = true))] size: Option<u64>,
) {
Expand All @@ -356,7 +356,7 @@ impl GPURenderPassEncoder {
.render_pass_set_vertex_buffer(
&mut self.render_pass.borrow_mut(),
slot,
buffer.id,
buffer.into_option().map(|buffer| buffer.id),
offset,
size.and_then(NonZeroU64::new),
)
Expand Down
8 changes: 4 additions & 4 deletions examples/features/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ impl crate::framework::Example for Example {
entry_point: Some("main_vs"),
compilation_options: Default::default(),
buffers: &[
wgpu::VertexBufferLayout {
Some(wgpu::VertexBufferLayout {
array_stride: 4 * 4,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2],
},
wgpu::VertexBufferLayout {
}),
Some(wgpu::VertexBufferLayout {
array_stride: 2 * 4,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![2 => Float32x2],
},
}),
],
},
fragment: Some(wgpu::FragmentState {
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/cube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl crate::framework::Example for Example {

let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
let vertex_buffers = [Some(wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
Expand All @@ -233,7 +233,7 @@ impl crate::framework::Example for Example {
shader_location: 1,
},
],
}];
})];

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl Example {
module: shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: shader,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/ray_shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ impl crate::framework::Example for Example {
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[VertexBufferLayout {
buffers: &[Some(VertexBufferLayout {
array_stride: mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: Default::default(),
attributes: &vertex_attr_array![0 => Float32x3, 1 => Float32x3],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
Expand Down
8 changes: 4 additions & 4 deletions examples/features/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ impl crate::framework::Example for Example {
});

let vertex_attr = wgpu::vertex_attr_array![0 => Sint8x4, 1 => Sint8x4];
let vb_desc = wgpu::VertexBufferLayout {
let vertex_buffers = [Some(wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr,
};
})];

let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

Expand Down Expand Up @@ -494,7 +494,7 @@ impl crate::framework::Example for Example {
module: &shader,
entry_point: Some("vs_bake"),
compilation_options: Default::default(),
buffers: std::slice::from_ref(&vb_desc),
buffers: &vertex_buffers,
},
fragment: None,
primitive: wgpu::PrimitiveState {
Expand Down Expand Up @@ -628,7 +628,7 @@ impl crate::framework::Example for Example {
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[vb_desc],
buffers: &vertex_buffers,
},
fragment: Some(wgpu::FragmentState {
module: &shader,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ impl crate::framework::Example for Example {
module: &shader,
entry_point: Some("vs_entity"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {

let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
let vertex_buffers = [Some(wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
Expand All @@ -119,7 +119,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
shader_location: 1,
},
],
}];
})];

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ impl crate::framework::Example for Example {

let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl"));

let vertex_buffers = [wgpu::VertexBufferLayout {
let vertex_buffers = [Some(wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
format: wgpu::VertexFormat::Float32x4,
offset: 0,
shader_location: 0,
}],
}];
})];

let mask_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
Expand Down
4 changes: 2 additions & 2 deletions examples/features/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ impl crate::framework::Example for Example {
module: &base_shader_module,
entry_point: Some("vert_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: fragment_shader_module,
Expand Down
8 changes: 4 additions & 4 deletions examples/features/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ impl crate::framework::Example for Example {
// ensured by tagging on either a `#[repr(C)]` onto a
// struct, or a `#[repr(transparent)]` if it only contains
// one item, which is itself `repr(C)`.
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: water_vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4],
}],
})],
},
// Fragment shader and output targets
fragment: Some(wgpu::FragmentState {
Expand Down Expand Up @@ -579,11 +579,11 @@ impl crate::framework::Example for Example {
module: &terrain_module,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: terrain_vertex_size as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: &terrain_module,
Expand Down
2 changes: 1 addition & 1 deletion player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ impl Player {
size,
} => C::SetVertexBuffer {
slot,
buffer: self.resolve_buffer_id(buffer),
buffer: buffer.map(|buffer| self.resolve_buffer_id(buffer)),
offset,
size,
},
Expand Down
Loading