[wgpu] make vertex buffer slots optional

This commit is contained in:
teoxoy authored and Andy Leiserson committed 2026-04-14 17:20:15 -07:00
1 parent 35fd939877
commit 67b4f3c7e5
28 files changed
+143 -126

No files matched your search

+8 -8
View File
@@ -127,11 +127,11 @@ async fn run_test_inner(
use_multi_draw: bool,
) {
let mut vertex_buffer_layouts = Vec::new();
vertex_buffer_layouts.push(wgpu::VertexBufferLayout {
vertex_buffer_layouts.push(Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x2],
});
}));
let vertex_buffer = ctx.device.create_buffer_init(&BufferInitDescriptor {
label: None,
contents: bytemuck::cast_slice(test_data.vertex_buffer_content()),
@@ -151,11 +151,11 @@ async fn run_test_inner(
};
let instance_buffer = test_data.instanced.as_ref().map(|instanced| {
vertex_buffer_layouts.push(wgpu::VertexBufferLayout {
vertex_buffer_layouts.push(Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &vertex_attr_array![1 => Float32x2],
});
}));
ctx.device.create_buffer_init(&BufferInitDescriptor {
label: None,
contents: bytemuck::cast_slice(instanced.instance_buffer_content),
@@ -689,16 +689,16 @@ async fn indirect_buffer_offsets(ctx: TestingContext) {
layout: None,
vertex: wgpu::VertexState {
buffers: &[
wgpu::VertexBufferLayout {
Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x2],
},
wgpu::VertexBufferLayout {
}),
Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &vertex_attr_array![1 => Float32x2],
},
}),
],
module: &shader,
entry_point: Some("vs_main"),
+2 -2
View File
@@ -83,7 +83,7 @@ async fn per_vertex(ctx: TestingContext) {
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 12,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
@@ -91,7 +91,7 @@ async fn per_vertex(ctx: TestingContext) {
offset: 0,
shader_location: 0,
}],
}],
})],
},
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
@@ -59,16 +59,16 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = GpuTestConfiguration::ne
entry_point: Some("double_buffer_vert"),
compilation_options: Default::default(),
buffers: &[
VertexBufferLayout {
Some(VertexBufferLayout {
array_stride: 16,
step_mode: VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x4],
},
VertexBufferLayout {
}),
Some(VertexBufferLayout {
array_stride: 4,
step_mode: VertexStepMode::Vertex,
attributes: &vertex_attr_array![5 => Float32],
},
}),
],
},
primitive: PrimitiveState::default(),
@@ -97,11 +97,11 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = GpuTestConfiguration::ne
module: &module,
entry_point: Some("single_buffer_vert"),
compilation_options: Default::default(),
buffers: &[VertexBufferLayout {
buffers: &[Some(VertexBufferLayout {
array_stride: 16,
step_mode: VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x4],
}],
})],
},
primitive: PrimitiveState::default(),
depth_stencil: None,
@@ -520,11 +520,11 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
module: &sm,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 4,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Uint32],
}],
})],
},
fragment: Some(wgpu::FragmentState {
module: &sm,
+4 -4
View File
@@ -80,11 +80,11 @@ async fn run_test(
label: None,
layout: None,
vertex: wgpu::VertexState {
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x2],
}],
})],
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
@@ -305,11 +305,11 @@ async fn run_test_3d(ctx: TestingContext) {
label: None,
layout: None,
vertex: wgpu::VertexState {
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x2],
}],
})],
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
@@ -82,7 +82,7 @@ async fn barycentric(ctx: TestingContext, no_perspective: bool) {
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
@@ -90,7 +90,7 @@ async fn barycentric(ctx: TestingContext, no_perspective: bool) {
offset: 0,
shader_location: 0,
}],
}],
})],
},
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
@@ -127,7 +127,7 @@ async fn pulling_common(
module: &shader,
entry_point: Some("vs_main"),
compilation_options: Default::default(),
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
@@ -135,7 +135,7 @@ async fn pulling_common(
offset: 0,
shader_location: 0,
}],
}],
})],
},
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
+2 -2
View File
@@ -292,11 +292,11 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) {
label: None,
layout: Some(&ppl),
vertex: wgpu::VertexState {
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
array_stride: 0, // Calculate, please!
step_mode: wgpu::VertexStepMode::Vertex,
attributes: test.attributes,
}],
})],
module: &shader,
entry_point: Some(test.entry_point),
compilation_options: Default::default(),
+6 -6
View File
@@ -266,16 +266,16 @@ async fn vertex_index_common(ctx: TestingContext) {
pipeline_desc.vertex.entry_point = Some("vs_main_buffers");
pipeline_desc.vertex.buffers = &[
wgpu::VertexBufferLayout {
Some(wgpu::VertexBufferLayout {
array_stride: 4,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &wgpu::vertex_attr_array![0 => Uint32],
},
wgpu::VertexBufferLayout {
}),
Some(wgpu::VertexBufferLayout {
array_stride: 4,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![1 => Uint32],
},
}),
];
let buffer_pipeline = ctx.device.create_render_pipeline(&pipeline_desc);
@@ -391,8 +391,8 @@ async fn vertex_index_common(ctx: TestingContext) {
.map(|r| r as &mut dyn RenderEncoder)
.unwrap_or(&mut rpass);
render_encoder.set_vertex_buffer(0, identity_buffer.slice(..));
render_encoder.set_vertex_buffer(1, identity_buffer.slice(..));
render_encoder.set_vertex_buffer(0, Some(identity_buffer.slice(..)));
render_encoder.set_vertex_buffer(1, Some(identity_buffer.slice(..)));
render_encoder.set_index_buffer(identity_buffer.slice(..), wgpu::IndexFormat::Uint32);
render_encoder.set_pipeline(pipeline);
render_encoder.set_bind_group(0, Some(&bg), &[]);
+5 -5
View File
@@ -74,16 +74,16 @@ async fn set_array_stride_to_0(ctx: TestingContext) {
});
let vbl = [
wgpu::VertexBufferLayout {
Some(wgpu::VertexBufferLayout {
array_stride: 8,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![0 => Float32x2],
},
wgpu::VertexBufferLayout {
}),
Some(wgpu::VertexBufferLayout {
array_stride: 0,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &vertex_attr_array![1 => Float32x4],
},
}),
];
let pipeline_desc = wgpu::RenderPipelineDescriptor {
label: None,
@@ -112,7 +112,7 @@ async fn set_array_stride_to_0(ctx: TestingContext) {
};
let mut first_pipeline_desc = pipeline_desc.clone();
let mut first_vbl = vbl.clone();
first_vbl[1].array_stride = 16;
first_vbl[1].as_mut().unwrap().array_stride = 16;
first_pipeline_desc.vertex.buffers = &first_vbl;
let pipeline = ctx.device.create_render_pipeline(&pipeline_desc);
let first_pipeline = ctx.device.create_render_pipeline(&first_pipeline_desc);