mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 01:54:31 +01:00
Add util::indirect helper structs
This commit is contained in:
1 parent
10a07e4807
commit
e924aa1a05
4 files changed
+94
-127
No files matched your search
+9
-104
@@ -2605,18 +2605,7 @@ impl<'a> RenderPass<'a> {
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// first_vertex: u32, // The Index of the first vertex to draw.
|
||||
/// first_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// // has to be 0, unless [`Features::INDIRECT_FIRST_INSTANCE`] is enabled.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndirect`](crate::util::DrawIndirect).
|
||||
pub fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) {
|
||||
self.id.draw_indirect(&indirect_buffer.id, indirect_offset);
|
||||
}
|
||||
@@ -2627,19 +2616,7 @@ impl<'a> RenderPass<'a> {
|
||||
/// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndexedIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// first_index: u32, // The base index within the index buffer.
|
||||
/// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer.
|
||||
/// first_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// // has to be 0, unless [`Features::INDIRECT_FIRST_INSTANCE`] is enabled.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndexedIndirect`](crate::util::DrawIndexedIndirect).
|
||||
pub fn draw_indexed_indirect(
|
||||
&mut self,
|
||||
indirect_buffer: &'a Buffer,
|
||||
@@ -2664,17 +2641,7 @@ impl<'a> RenderPass<'a> {
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_vertex: u32, // The Index of the first vertex to draw.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndirect`](crate::util::DrawIndirect).
|
||||
///
|
||||
/// These draw structures are expected to be tightly packed.
|
||||
pub fn multi_draw_indirect(
|
||||
@@ -2693,18 +2660,7 @@ impl<'a> RenderPass<'a> {
|
||||
/// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndexedIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_index: u32, // The base index within the index buffer.
|
||||
/// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndexedIndirect`](crate::util::DrawIndexedIndirect).
|
||||
///
|
||||
/// These draw structures are expected to be tightly packed.
|
||||
pub fn multi_draw_indexed_indirect(
|
||||
@@ -2728,17 +2684,7 @@ impl<'a> RenderPass<'a> {
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_vertex: u32, // The Index of the first vertex to draw.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndirect`](crate::util::DrawIndirect).
|
||||
///
|
||||
/// These draw structures are expected to be tightly packed.
|
||||
///
|
||||
@@ -2776,18 +2722,8 @@ impl<'a> RenderPass<'a> {
|
||||
/// The active index buffer can be set with [`RenderPass::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderPass::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndexedIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_index: u32, // The base index within the index buffer.
|
||||
/// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndexedIndirect`](crate::util::DrawIndexedIndirect).
|
||||
///
|
||||
/// These draw structures are expected to be tightly packed.
|
||||
///
|
||||
@@ -2938,17 +2874,7 @@ impl<'a> ComputePass<'a> {
|
||||
|
||||
/// Dispatches compute work operations, based on the contents of the `indirect_buffer`.
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// // x, y and z denote the number of work groups to dispatch in each dimension.
|
||||
/// #[repr(C)]
|
||||
/// struct DispatchIndirect {
|
||||
/// x: u32,
|
||||
/// y: u32,
|
||||
/// z: u32,
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DispatchIndirect`](crate::util::DispatchIndirect).
|
||||
pub fn dispatch_indirect(
|
||||
&mut self,
|
||||
indirect_buffer: &'a Buffer,
|
||||
@@ -3094,17 +3020,7 @@ impl<'a> RenderBundleEncoder<'a> {
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_vertex: u32, // The Index of the first vertex to draw.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndirect`](crate::util::DrawIndirect).
|
||||
pub fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress) {
|
||||
self.id.draw_indirect(&indirect_buffer.id, indirect_offset);
|
||||
}
|
||||
@@ -3115,18 +3031,7 @@ impl<'a> RenderBundleEncoder<'a> {
|
||||
/// The active index buffer can be set with [`RenderBundleEncoder::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderBundleEncoder::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndexedIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_index: u32, // The base index within the index buffer.
|
||||
/// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndexedIndirect`](crate::util::DrawIndexedIndirect).
|
||||
pub fn draw_indexed_indirect(
|
||||
&mut self,
|
||||
indirect_buffer: &'a Buffer,
|
||||
|
||||
@@ -50,17 +50,7 @@ pub trait RenderEncoder<'a> {
|
||||
///
|
||||
/// The active vertex buffers can be set with [`RenderEncoder::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_vertex: u32, // The Index of the first vertex to draw.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndirect`](crate::util::DrawIndirect).
|
||||
fn draw_indirect(&mut self, indirect_buffer: &'a Buffer, indirect_offset: BufferAddress);
|
||||
|
||||
/// Draws indexed primitives using the active index buffer and the active vertex buffers,
|
||||
@@ -69,18 +59,7 @@ pub trait RenderEncoder<'a> {
|
||||
/// The active index buffer can be set with [`RenderEncoder::set_index_buffer`], while the active
|
||||
/// vertex buffers can be set with [`RenderEncoder::set_vertex_buffer`].
|
||||
///
|
||||
/// The structure expected in `indirect_buffer` is the following:
|
||||
///
|
||||
/// ```rust
|
||||
/// #[repr(C)]
|
||||
/// struct DrawIndexedIndirect {
|
||||
/// vertex_count: u32, // The number of vertices to draw.
|
||||
/// instance_count: u32, // The number of instances to draw.
|
||||
/// base_index: u32, // The base index within the index buffer.
|
||||
/// vertex_offset: i32, // The value added to the vertex index before indexing into the vertex buffer.
|
||||
/// base_instance: u32, // The instance ID of the first instance to draw.
|
||||
/// }
|
||||
/// ```
|
||||
/// The structure expected in `indirect_buffer` must conform to [`DrawIndexedIndirect`](crate::util::DrawIndexedIndirect).
|
||||
fn draw_indexed_indirect(
|
||||
&mut self,
|
||||
indirect_buffer: &'a Buffer,
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/// The structure expected in `indirect_buffer` for [`RenderEncoder::draw_indirect`](crate::util::RenderEncoder::draw_indirect).
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct DrawIndirect {
|
||||
/// The number of vertices to draw.
|
||||
pub vertex_count: u32,
|
||||
/// The number of instances to draw.
|
||||
pub instance_count: u32,
|
||||
/// The Index of the first vertex to draw.
|
||||
pub base_vertex: u32,
|
||||
/// The instance ID of the first instance to draw.
|
||||
/// Has to be 0, unless [`Features::INDIRECT_FIRST_INSTANCE`](crate::Features::INDIRECT_FIRST_INSTANCE) is enabled.
|
||||
pub base_instance: u32,
|
||||
}
|
||||
|
||||
impl DrawIndirect {
|
||||
/// Returns the bytes representation of the struct, ready to be written in a [`Buffer`](crate::Buffer).
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
std::mem::transmute(std::slice::from_raw_parts(
|
||||
self as *const _ as *const u8,
|
||||
std::mem::size_of::<Self>(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The structure expected in `indirect_buffer` for [`RenderEncoder::draw_indexed_indirect`](crate::util::RenderEncoder::draw_indexed_indirect).
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct DrawIndexedIndirect {
|
||||
/// The number of vertices to draw.
|
||||
pub vertex_count: u32,
|
||||
/// The number of instances to draw.
|
||||
pub instance_count: u32,
|
||||
/// The base index within the index buffer.
|
||||
pub base_index: u32,
|
||||
/// The value added to the vertex index before indexing into the vertex buffer.
|
||||
pub vertex_offset: i32,
|
||||
/// The instance ID of the first instance to draw.
|
||||
/// Has to be 0, unless [`Features::INDIRECT_FIRST_INSTANCE`](crate::Features::INDIRECT_FIRST_INSTANCE) is enabled.
|
||||
pub base_instance: u32,
|
||||
}
|
||||
|
||||
impl DrawIndexedIndirect {
|
||||
/// Returns the bytes representation of the struct, ready to be written in a [`Buffer`](crate::Buffer).
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
std::mem::transmute(std::slice::from_raw_parts(
|
||||
self as *const _ as *const u8,
|
||||
std::mem::size_of::<Self>(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The structure expected in `indirect_buffer` for [`ComputePass::dispatch_indirect`](crate::ComputePass::dispatch_indirect).
|
||||
///
|
||||
/// x, y and z denote the number of work groups to dispatch in each dimension.
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct DispatchIndirect {
|
||||
/// The number of work groups in X dimension.
|
||||
pub x: u32,
|
||||
/// The number of work groups in Y dimension.
|
||||
pub y: u32,
|
||||
/// The number of work groups in Z dimension.
|
||||
pub z: u32,
|
||||
}
|
||||
|
||||
impl DispatchIndirect {
|
||||
/// Returns the bytes representation of the struct, ready to be written in a [`Buffer`](crate::Buffer).
|
||||
pub fn as_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
std::mem::transmute(std::slice::from_raw_parts(
|
||||
self as *const _ as *const u8,
|
||||
std::mem::size_of::<Self>(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
mod belt;
|
||||
mod device;
|
||||
mod encoder;
|
||||
mod indirect;
|
||||
mod init;
|
||||
|
||||
use std::future::Future;
|
||||
@@ -15,6 +16,7 @@ use std::{
|
||||
pub use belt::StagingBelt;
|
||||
pub use device::{BufferInitDescriptor, DeviceExt};
|
||||
pub use encoder::RenderEncoder;
|
||||
pub use indirect::*;
|
||||
pub use init::*;
|
||||
|
||||
/// Treat the given byte slice as a SPIR-V module.
|
||||
|
||||
Reference in new issue
Block a user