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>

source

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);
        });
source

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).

source

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);
        });
source

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);
        });
source

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more