pub struct Compute<'a> { /* private fields */ }
Expand description
Recording interface for computing commands.
This structure provides a strongly-typed set of methods which allow compute shader code to be
executed. An instance of Compute
is provided to the closure parameter of
PipelinePassRef::record_compute
which may be accessed by binding a ComputePipeline
to a
render pass.
§Examples
Basic usage:
my_graph.begin_pass("my compute pass")
.bind_pipeline(&my_compute_pipeline)
.record_compute(move |compute, bindings| {
// During this closure we have access to the compute methods!
});
Implementations§
source§impl<'a> Compute<'a>
impl<'a> Compute<'a>
sourcepub fn dispatch(
&self,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32
) -> &Self
pub fn dispatch( &self, group_count_x: u32, group_count_y: u32, group_count_z: u32 ) -> &Self
Dispatch compute work items.
When the command is executed, a global workgroup consisting of
group_count_x × group_count_y × group_count_z
local workgroups is assembled.
§Examples
Basic usage:
#version 450
layout(set = 0, binding = 0, std430) restrict writeonly buffer MyBufer {
uint my_buf[];
};
void main()
{
// TODO
}
my_graph.begin_pass("fill my_buf_node with data")
.bind_pipeline(&my_compute_pipeline)
.write_descriptor(0, my_buf_node)
.record_compute(move |compute, bindings| {
compute.dispatch(128, 64, 32);
});
sourcepub fn dispatch_base(
&self,
base_group_x: u32,
base_group_y: u32,
base_group_z: u32,
group_count_x: u32,
group_count_y: u32,
group_count_z: u32
) -> &Self
pub fn dispatch_base( &self, base_group_x: u32, base_group_y: u32, base_group_z: u32, group_count_x: u32, group_count_y: u32, group_count_z: u32 ) -> &Self
Dispatch compute work items with non-zero base values for the workgroup IDs.
When the command is executed, a global workgroup consisting of
group_count_x × group_count_y × group_count_z
local workgroups is assembled, with
WorkgroupId values ranging from [base_group*, base_group* + group_count*)
in each
component.
Compute::dispatch
is equivalent to
dispatch_base(0, 0, 0, group_count_x, group_count_y, group_count_z)
.
sourcepub fn dispatch_indirect(
&self,
args_buf: impl Into<AnyBufferNode>,
args_offset: DeviceSize
) -> &Self
pub fn dispatch_indirect( &self, args_buf: impl Into<AnyBufferNode>, args_offset: DeviceSize ) -> &Self
Dispatch compute work items with indirect parameters.
dispatch_indirect
behaves similarly to Compute::dispatch
except that the parameters
are read by the device from args_buf
during execution. The parameters of the dispatch are
encoded in a vk::DispatchIndirectCommand
structure taken from args_buf
starting at
args_offset
.
§Examples
Basic usage:
const CMD_SIZE: usize = size_of::<vk::DispatchIndirectCommand>();
let cmd = vk::DispatchIndirectCommand {
x: 1,
y: 2,
z: 3,
};
let cmd_data = unsafe {
std::slice::from_raw_parts(&cmd as *const _ as *const _, CMD_SIZE)
};
let args_buf_flags = vk::BufferUsageFlags::STORAGE_BUFFER;
let args_buf = Buffer::create_from_slice(&device, args_buf_flags, cmd_data)?;
let args_buf_node = my_graph.bind_node(args_buf);
my_graph.begin_pass("fill my_buf_node with data")
.bind_pipeline(&my_compute_pipeline)
.read_node(args_buf_node)
.write_descriptor(0, my_buf_node)
.record_compute(move |compute, bindings| {
compute.dispatch_indirect(args_buf_node, 0);
});
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 bindings to read/write things!
}
my_graph.begin_pass("compute the ultimate question")
.bind_pipeline(&my_compute_pipeline)
.record_compute(move |compute, bindings| {
compute.push_constants(&[42])
.dispatch(1, 1, 1);
});
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 Compute::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 bindings to read/write things!
}
my_graph.begin_pass("calculate the wow factor")
.bind_pipeline(&my_compute_pipeline)
.record_compute(move |compute, bindings| {
compute.push_constants(&[0x00, 0x00])
.dispatch(1, 1, 1)
.push_constants_offset(4, &[0xff])
.dispatch(1, 1, 1);
});
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Compute<'a>
impl<'a> !Send for Compute<'a>
impl<'a> !Sync for Compute<'a>
impl<'a> Unpin for Compute<'a>
impl<'a> !UnwindSafe for Compute<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.