mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-19 05:51:03 +01:00
[wgpu] make vertex buffer slots optional
This commit is contained in:
1 parent
35fd939877
commit
67b4f3c7e5
28 files changed
+143
-126
No files matched your search
@@ -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 =
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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: &[
|
||||
@@ -233,7 +233,7 @@ impl crate::framework::Example for Example {
|
||||
shader_location: 1,
|
||||
},
|
||||
],
|
||||
}];
|
||||
})];
|
||||
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: None,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: &[
|
||||
@@ -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,
|
||||
|
||||
@@ -53,7 +53,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: &[wgpu::VertexAttribute {
|
||||
@@ -61,7 +61,7 @@ impl crate::framework::Example for Example {
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
}],
|
||||
}];
|
||||
})];
|
||||
|
||||
let mask_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: None,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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), &[]);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -107,13 +107,21 @@ impl<'a> RenderBundleEncoder<'a> {
|
||||
///
|
||||
/// [`draw`]: RenderBundleEncoder::draw
|
||||
/// [`draw_indexed`]: RenderBundleEncoder::draw_indexed
|
||||
pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) {
|
||||
self.inner.set_vertex_buffer(
|
||||
slot,
|
||||
&buffer_slice.buffer.inner,
|
||||
buffer_slice.offset,
|
||||
Some(buffer_slice.size),
|
||||
);
|
||||
pub fn set_vertex_buffer<'b, B>(&mut self, slot: u32, buffer_slice: B)
|
||||
where
|
||||
Option<BufferSlice<'b>>: From<B>,
|
||||
{
|
||||
let buffer_slice: Option<BufferSlice<'b>> = buffer_slice.into();
|
||||
if let Some(buffer_slice) = buffer_slice {
|
||||
self.inner.set_vertex_buffer(
|
||||
slot,
|
||||
Some(&buffer_slice.buffer.inner),
|
||||
buffer_slice.offset,
|
||||
Some(buffer_slice.size),
|
||||
);
|
||||
} else {
|
||||
self.inner.set_vertex_buffer(slot, None, 0, None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Draws primitives from the active vertex buffer(s).
|
||||
|
||||
@@ -121,13 +121,21 @@ impl RenderPass<'_> {
|
||||
///
|
||||
/// [`draw`]: RenderPass::draw
|
||||
/// [`draw_indexed`]: RenderPass::draw_indexed
|
||||
pub fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'_>) {
|
||||
self.inner.set_vertex_buffer(
|
||||
slot,
|
||||
&buffer_slice.buffer.inner,
|
||||
buffer_slice.offset,
|
||||
Some(buffer_slice.size),
|
||||
);
|
||||
pub fn set_vertex_buffer<'b, B>(&mut self, slot: u32, buffer_slice: B)
|
||||
where
|
||||
Option<BufferSlice<'b>>: From<B>,
|
||||
{
|
||||
let buffer_slice: Option<BufferSlice<'b>> = buffer_slice.into();
|
||||
if let Some(buffer_slice) = buffer_slice {
|
||||
self.inner.set_vertex_buffer(
|
||||
slot,
|
||||
Some(&buffer_slice.buffer.inner),
|
||||
buffer_slice.offset,
|
||||
Some(buffer_slice.size),
|
||||
);
|
||||
} else {
|
||||
self.inner.set_vertex_buffer(slot, None, 0, None);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the scissor rectangle used during the rasterization stage.
|
||||
|
||||
@@ -112,7 +112,7 @@ pub struct VertexState<'a> {
|
||||
///
|
||||
/// The attribute locations and types specified in this layout must match the
|
||||
/// locations and types of the inputs to the `entry_point` function.
|
||||
pub buffers: &'a [VertexBufferLayout<'a>],
|
||||
pub buffers: &'a [Option<VertexBufferLayout<'a>>],
|
||||
}
|
||||
#[cfg(send_sync)]
|
||||
static_assertions::assert_impl_all!(VertexState<'_>: Send, Sync);
|
||||
|
||||
+29
-26
@@ -2215,25 +2215,28 @@ impl dispatch::DeviceInterface for WebDevice {
|
||||
.vertex
|
||||
.buffers
|
||||
.iter()
|
||||
.map(|vbuf| {
|
||||
let mapped_attributes = vbuf
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
webgpu_sys::GpuVertexAttribute::new_with_f64(
|
||||
map_vertex_format(attr.format),
|
||||
attr.offset as f64,
|
||||
attr.shader_location,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<webgpu_sys::GpuVertexAttribute>>();
|
||||
.map(|vbuf| match vbuf {
|
||||
Some(vbuf) => {
|
||||
let mapped_attributes = vbuf
|
||||
.attributes
|
||||
.iter()
|
||||
.map(|attr| {
|
||||
webgpu_sys::GpuVertexAttribute::new_with_f64(
|
||||
map_vertex_format(attr.format),
|
||||
attr.offset as f64,
|
||||
attr.shader_location,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<webgpu_sys::GpuVertexAttribute>>();
|
||||
|
||||
let mapped_vbuf = webgpu_sys::GpuVertexBufferLayout::new_with_f64(
|
||||
vbuf.array_stride as f64,
|
||||
&mapped_attributes,
|
||||
);
|
||||
mapped_vbuf.set_step_mode(map_vertex_step_mode(vbuf.step_mode));
|
||||
js_sys::JsOption::wrap(mapped_vbuf)
|
||||
let mapped_vbuf = webgpu_sys::GpuVertexBufferLayout::new_with_f64(
|
||||
vbuf.array_stride as f64,
|
||||
&mapped_attributes,
|
||||
);
|
||||
mapped_vbuf.set_step_mode(map_vertex_step_mode(vbuf.step_mode));
|
||||
js_sys::JsOption::wrap(mapped_vbuf)
|
||||
}
|
||||
None => js_sys::JsOption::new(),
|
||||
})
|
||||
.collect::<Vec<js_sys::JsOption<webgpu_sys::GpuVertexBufferLayout>>>();
|
||||
|
||||
@@ -3517,22 +3520,22 @@ impl dispatch::RenderPassInterface for WebRenderPassEncoder {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &dispatch::DispatchBuffer,
|
||||
buffer: Option<&dispatch::DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
) {
|
||||
let buffer = buffer.as_webgpu();
|
||||
let buffer = buffer.map(|buffer| &buffer.as_webgpu().inner);
|
||||
|
||||
if let Some(size) = size {
|
||||
self.inner.set_vertex_buffer_with_f64_and_f64(
|
||||
slot,
|
||||
Some(&buffer.inner),
|
||||
buffer,
|
||||
offset as f64,
|
||||
size.get() as f64,
|
||||
);
|
||||
} else {
|
||||
self.inner
|
||||
.set_vertex_buffer_with_f64(slot, Some(&buffer.inner), offset as f64);
|
||||
.set_vertex_buffer_with_f64(slot, buffer, offset as f64);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3808,22 +3811,22 @@ impl dispatch::RenderBundleEncoderInterface for WebRenderBundleEncoder {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &dispatch::DispatchBuffer,
|
||||
buffer: Option<&dispatch::DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
) {
|
||||
let buffer = buffer.as_webgpu();
|
||||
let buffer = buffer.map(|buffer| &buffer.as_webgpu().inner);
|
||||
|
||||
if let Some(size) = size {
|
||||
self.inner.set_vertex_buffer_with_f64_and_f64(
|
||||
slot,
|
||||
Some(&buffer.inner),
|
||||
buffer,
|
||||
offset as f64,
|
||||
size.get() as f64,
|
||||
);
|
||||
} else {
|
||||
self.inner
|
||||
.set_vertex_buffer_with_f64(slot, Some(&buffer.inner), offset as f64);
|
||||
.set_vertex_buffer_with_f64(slot, buffer, offset as f64);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1339,7 +1339,7 @@ impl dispatch::DeviceInterface for CoreDevice {
|
||||
.buffers
|
||||
.iter()
|
||||
.map(|vbuf| {
|
||||
Some(pipe::VertexBufferLayout {
|
||||
vbuf.as_ref().map(|vbuf| pipe::VertexBufferLayout {
|
||||
array_stride: vbuf.array_stride,
|
||||
step_mode: vbuf.step_mode,
|
||||
attributes: Borrowed(vbuf.attributes),
|
||||
@@ -3240,19 +3240,17 @@ impl dispatch::RenderPassInterface for CoreRenderPass {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &dispatch::DispatchBuffer,
|
||||
buffer: Option<&dispatch::DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
) {
|
||||
let buffer = buffer.as_core();
|
||||
let buffer = buffer.map(|buffer| buffer.as_core().id);
|
||||
|
||||
if let Err(cause) = self.context.0.render_pass_set_vertex_buffer(
|
||||
&mut self.pass,
|
||||
slot,
|
||||
Some(buffer.id),
|
||||
offset,
|
||||
size,
|
||||
) {
|
||||
if let Err(cause) =
|
||||
self.context
|
||||
.0
|
||||
.render_pass_set_vertex_buffer(&mut self.pass, slot, buffer, offset, size)
|
||||
{
|
||||
self.context.handle_error(
|
||||
&self.error_sink,
|
||||
cause,
|
||||
@@ -3825,13 +3823,13 @@ impl dispatch::RenderBundleEncoderInterface for CoreRenderBundleEncoder {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &dispatch::DispatchBuffer,
|
||||
buffer: Option<&dispatch::DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
) {
|
||||
let buffer = buffer.as_core();
|
||||
let buffer = buffer.map(|buffer| buffer.as_core().id);
|
||||
|
||||
wgpu_render_bundle_set_vertex_buffer(&mut self.encoder, slot, Some(buffer.id), offset, size)
|
||||
wgpu_render_bundle_set_vertex_buffer(&mut self.encoder, slot, buffer, offset, size)
|
||||
}
|
||||
|
||||
fn set_immediates(&mut self, offset: u32, data: &[u8]) {
|
||||
|
||||
@@ -438,7 +438,7 @@ pub trait RenderPassInterface: CommonTraits + Drop {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &DispatchBuffer,
|
||||
buffer: Option<&DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
);
|
||||
@@ -549,7 +549,7 @@ pub trait RenderBundleEncoderInterface: CommonTraits {
|
||||
fn set_vertex_buffer(
|
||||
&mut self,
|
||||
slot: u32,
|
||||
buffer: &DispatchBuffer,
|
||||
buffer: Option<&DispatchBuffer>,
|
||||
offset: crate::BufferAddress,
|
||||
size: Option<crate::BufferSize>,
|
||||
);
|
||||
|
||||
@@ -38,7 +38,7 @@ pub trait RenderEncoder<'a> {
|
||||
///
|
||||
/// [`draw`]: RenderEncoder::draw
|
||||
/// [`draw_indexed`]: RenderEncoder::draw_indexed
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>);
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: Option<BufferSlice<'a>>);
|
||||
|
||||
/// Draws primitives from the active vertex buffer(s).
|
||||
///
|
||||
@@ -106,7 +106,7 @@ impl<'a> RenderEncoder<'a> for RenderPass<'a> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) {
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: Option<BufferSlice<'a>>) {
|
||||
Self::set_vertex_buffer(self, slot, buffer_slice);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ impl<'a> RenderEncoder<'a> for RenderBundleEncoder<'a> {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: BufferSlice<'a>) {
|
||||
fn set_vertex_buffer(&mut self, slot: u32, buffer_slice: Option<BufferSlice<'a>>) {
|
||||
Self::set_vertex_buffer(self, slot, buffer_slice);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user