pub struct Draw<'a> { /* private fields */ }Expand description
Recording interface for drawing commands.
This structure provides a strongly-typed set of methods which allow rasterization shader code to
be executed. An instance of Draw is provided to the closure parameter of
PipelinePassRef::record_subpass which may be accessed by binding a GraphicPipeline to a
render pass.
§Examples
Basic usage:
my_graph.begin_pass("my draw pass")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.record_subpass(move |subpass, bindings| {
// During this closure we have access to the draw methods!
});Implementations§
Source§impl Draw<'_>
impl Draw<'_>
Sourcepub fn bind_index_buffer(
&self,
buffer: impl Into<AnyBufferNode>,
index_ty: IndexType,
) -> &Self
pub fn bind_index_buffer( &self, buffer: impl Into<AnyBufferNode>, index_ty: IndexType, ) -> &Self
Bind an index buffer to the current pass.
§Examples
Basic usage:
my_graph.begin_pass("my indexed geometry draw pass")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.read_node(my_idx_buf)
.read_node(my_vtx_buf)
.record_subpass(move |subpass, bindings| {
subpass.bind_index_buffer(my_idx_buf, vk::IndexType::UINT16)
.bind_vertex_buffer(my_vtx_buf)
.draw_indexed(42, 1, 0, 0, 0);
});Sourcepub fn bind_index_buffer_offset(
&self,
buffer: impl Into<AnyBufferNode>,
index_ty: IndexType,
offset: DeviceSize,
) -> &Self
pub fn bind_index_buffer_offset( &self, buffer: impl Into<AnyBufferNode>, index_ty: IndexType, offset: DeviceSize, ) -> &Self
Bind an index buffer to the current pass.
Behaves similarly to bind_index_buffer except that offset is the starting offset in
bytes within buffer used in index buffer address calculations.
Sourcepub fn bind_vertex_buffer(&self, buffer: impl Into<AnyBufferNode>) -> &Self
pub fn bind_vertex_buffer(&self, buffer: impl Into<AnyBufferNode>) -> &Self
Bind a vertex buffer to the current pass.
§Examples
Basic usage:
my_graph.begin_pass("my unindexed geometry draw pass")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.read_node(my_vtx_buf)
.record_subpass(move |subpass, bindings| {
subpass.bind_vertex_buffer(my_vtx_buf)
.draw(42, 1, 0, 0);
});Sourcepub fn bind_vertex_buffer_offset(
&self,
buffer: impl Into<AnyBufferNode>,
offset: DeviceSize,
) -> &Self
pub fn bind_vertex_buffer_offset( &self, buffer: impl Into<AnyBufferNode>, offset: DeviceSize, ) -> &Self
Bind a vertex buffer to the current pass.
Behaves similarly to bind_vertex_buffer except the vertex input binding is updated to
start at offset from the start of buffer.
Sourcepub fn bind_vertex_buffers<B>(
&self,
first_binding: u32,
buffer_offsets: impl IntoIterator<Item = (B, DeviceSize)>,
) -> &Selfwhere
B: Into<AnyBufferNode>,
pub fn bind_vertex_buffers<B>(
&self,
first_binding: u32,
buffer_offsets: impl IntoIterator<Item = (B, DeviceSize)>,
) -> &Selfwhere
B: Into<AnyBufferNode>,
Binds multiple vertex buffers to the current pass, starting at the given first_binding.
Each vertex input binding in buffers specifies an offset from the start of the
corresponding buffer.
The vertex input attributes that use each of these bindings will use these updated addresses in their address calculations for subsequent drawing commands.
Sourcepub fn draw(
&self,
vertex_count: u32,
instance_count: u32,
first_vertex: u32,
first_instance: u32,
) -> &Self
pub fn draw( &self, vertex_count: u32, instance_count: u32, first_vertex: u32, first_instance: u32, ) -> &Self
Draw unindexed primitives.
When the command is executed, primitives are assembled using the current primitive topology
and vertex_count consecutive vertex indices with the first vertex_index value equal to
first_vertex. The primitives are drawn instance_count times with instance_index
starting with first_instance and increasing sequentially for each instance.
Sourcepub fn draw_indexed(
&self,
index_count: u32,
instance_count: u32,
first_index: u32,
vertex_offset: i32,
first_instance: u32,
) -> &Self
pub fn draw_indexed( &self, index_count: u32, instance_count: u32, first_index: u32, vertex_offset: i32, first_instance: u32, ) -> &Self
Draw indexed primitives.
When the command is executed, primitives are assembled using the current primitive topology
and index_count vertices whose indices are retrieved from the index buffer. The index
buffer is treated as an array of tightly packed unsigned integers of size defined by the
index_ty parameter with which the buffer was bound.
Sourcepub fn draw_indexed_indirect(
&self,
buffer: impl Into<AnyBufferNode>,
offset: DeviceSize,
draw_count: u32,
stride: u32,
) -> &Self
pub fn draw_indexed_indirect( &self, buffer: impl Into<AnyBufferNode>, offset: DeviceSize, draw_count: u32, stride: u32, ) -> &Self
Draw primitives with indirect parameters and indexed vertices.
draw_indexed_indirect behaves similarly to draw_indexed except that the parameters are
read by the device from buffer during execution. draw_count draws are executed by the
command, with parameters taken from buffer starting at offset and increasing by stride
bytes for each successive draw. The parameters of each draw are encoded in an array of
vk::DrawIndexedIndirectCommand structures.
If draw_count is less than or equal to one, stride is ignored.
§Examples
Basic usage:
const CMD_SIZE: usize = size_of::<vk::DrawIndexedIndirectCommand>();
let cmd = vk::DrawIndexedIndirectCommand {
index_count: 3,
instance_count: 1,
first_index: 0,
vertex_offset: 0,
first_instance: 0,
};
let cmd_data = unsafe {
std::slice::from_raw_parts(&cmd as *const _ as *const _, CMD_SIZE)
};
let buf_flags = vk::BufferUsageFlags::STORAGE_BUFFER;
let buf = Buffer::create_from_slice(&device, buf_flags, cmd_data)?;
let buf_node = my_graph.bind_node(buf);
my_graph.begin_pass("draw a single triangle")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.read_node(my_idx_buf)
.read_node(my_vtx_buf)
.read_node(buf_node)
.record_subpass(move |subpass, bindings| {
subpass.bind_index_buffer(my_idx_buf, vk::IndexType::UINT16)
.bind_vertex_buffer(my_vtx_buf)
.draw_indexed_indirect(buf_node, 0, 1, 0);
});Sourcepub fn draw_indexed_indirect_count(
&self,
buffer: impl Into<AnyBufferNode>,
offset: DeviceSize,
count_buf: impl Into<AnyBufferNode>,
count_buf_offset: DeviceSize,
max_draw_count: u32,
stride: u32,
) -> &Self
pub fn draw_indexed_indirect_count( &self, buffer: impl Into<AnyBufferNode>, offset: DeviceSize, count_buf: impl Into<AnyBufferNode>, count_buf_offset: DeviceSize, max_draw_count: u32, stride: u32, ) -> &Self
Draw primitives with indirect parameters, indexed vertices, and draw count.
draw_indexed_indirect_count behaves similarly to draw_indexed_indirect except that the
draw count is read by the device from buffer during execution. The command will read an
unsigned 32-bit integer from count_buf located at count_buf_offset and use this as the
draw count.
max_draw_count specifies the maximum number of draws that will be executed. The actual
number of executed draw calls is the minimum of the count specified in count_buf and
max_draw_count.
stride is the byte stride between successive sets of draw parameters.
Sourcepub fn draw_indirect(
&self,
buffer: impl Into<AnyBufferNode>,
offset: DeviceSize,
draw_count: u32,
stride: u32,
) -> &Self
pub fn draw_indirect( &self, buffer: impl Into<AnyBufferNode>, offset: DeviceSize, draw_count: u32, stride: u32, ) -> &Self
Draw primitives with indirect parameters and unindexed vertices.
Behaves otherwise similar to Draw::draw_indexed_indirect.
Sourcepub fn draw_indirect_count(
&self,
buffer: impl Into<AnyBufferNode>,
offset: DeviceSize,
count_buf: impl Into<AnyBufferNode>,
count_buf_offset: DeviceSize,
max_draw_count: u32,
stride: u32,
) -> &Self
pub fn draw_indirect_count( &self, buffer: impl Into<AnyBufferNode>, offset: DeviceSize, count_buf: impl Into<AnyBufferNode>, count_buf_offset: DeviceSize, max_draw_count: u32, stride: u32, ) -> &Self
Draw primitives with indirect parameters, unindexed vertices, and draw count.
Behaves otherwise similar to Draw::draw_indexed_indirect_count.
Sourcepub fn push_constants(&self, data: &[u8]) -> &Self
pub fn push_constants(&self, data: &[u8]) -> &Self
Updates push constants.
Push constants represent a high speed path to modify constant data in pipelines that is expected to outperform memory-backed resource updates.
Push constant values can be updated incrementally, causing shader stages to read the new data for push constants modified by this command, while still reading the previous data for push constants not modified by this command.
§Device limitations
See
device.physical_device.props.limits.max_push_constants_size
for the limits of the current device. You may also check gpuinfo.org for a listing of
reported limits on other devices.
§Examples
Basic usage:
#version 450
layout(push_constant) uniform PushConstants {
layout(offset = 0) uint the_answer;
} push_constants;
void main()
{
// TODO: Add code!
}my_graph.begin_pass("draw a quad")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.record_subpass(move |subpass, bindings| {
subpass.push_constants(&[42])
.draw(6, 1, 0, 0);
});Sourcepub fn push_constants_offset(&self, offset: u32, data: &[u8]) -> &Self
pub fn push_constants_offset(&self, offset: u32, data: &[u8]) -> &Self
Updates push constants starting at the given offset.
Behaves similary to Draw::push_constants except that offset describes the position at
which data updates the push constants of the currently bound pipeline. This may be used to
update a subset or single field of previously set push constant data.
§Device limitations
See
device.physical_device.props.limits.max_push_constants_size
for the limits of the current device. You may also check gpuinfo.org for a listing of
reported limits on other devices.
§Examples
Basic usage:
#version 450
layout(push_constant) uniform PushConstants {
layout(offset = 0) uint some_val1;
layout(offset = 4) uint some_val2;
} push_constants;
void main()
{
// TODO: Add code!
}my_graph.begin_pass("draw a quad")
.bind_pipeline(&my_graphic_pipeline)
.store_color(0, swapchain_image)
.record_subpass(move |subpass, bindings| {
subpass.push_constants(&[0x00, 0x00])
.draw(6, 1, 0, 0)
.push_constants_offset(4, &[0xff])
.draw(6, 1, 0, 0);
});Sourcepub fn set_scissor(&self, x: i32, y: i32, width: u32, height: u32) -> &Self
pub fn set_scissor(&self, x: i32, y: i32, width: u32, height: u32) -> &Self
Set scissor rectangle dynamically for a pass.
Sourcepub fn set_scissors<S>(
&self,
first_scissor: u32,
scissors: impl IntoIterator<Item = S>,
) -> &Self
pub fn set_scissors<S>( &self, first_scissor: u32, scissors: impl IntoIterator<Item = S>, ) -> &Self
Set scissor rectangles dynamically for a pass.
Sourcepub fn set_viewport(
&self,
x: f32,
y: f32,
width: f32,
height: f32,
depth: Range<f32>,
) -> &Self
pub fn set_viewport( &self, x: f32, y: f32, width: f32, height: f32, depth: Range<f32>, ) -> &Self
Set the viewport dynamically for a pass.
Sourcepub fn set_viewports<V>(
&self,
first_viewport: u32,
viewports: impl IntoIterator<Item = V>,
) -> &Self
pub fn set_viewports<V>( &self, first_viewport: u32, viewports: impl IntoIterator<Item = V>, ) -> &Self
Set the viewports dynamically for a pass.