Data types

VkComputeUtils.ComputeShaderPipelineType
struct ComputeShaderPipeline{PushConstsT, NBuffers}

An overarching structure that holds everything needed to run a single compute-only pipeline: the shader, descriptor set and pipeline layouts, the pipeline, a single small descriptor pool, and the descriptor sets.

source

Facility discovery

VkComputeUtils.find_memory_type_idxMethod
find_memory_type_idx(physical_device; check::Function=(_,_)->true, score::Function=(_,_)->0)

Find a memory type index (numbered from 0) for a physical device that satisfies some given properties. The arguments check and score behave as with find_scored_idx, but take 2 arguments with types MemoryType and MemoryHeap.

Example

# Find a host visible and device local memory type with largest heap
find_memory_type_idx(physical_device,
    check=(mt, heap) -> hasbits(mt.property_flags, MEMORY_PROPERTY_HOST_VISIBLE_BIT|MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
    score=(mt, heap) -> heap.size,
)
source
VkComputeUtils.find_physical_deviceMethod
find_physical_device(instance; args...)

Find a physical device within the instance that satisfies some given properties; arguments are forwarded to find_scored_idx.

Example

physical_device = find_physical_device(instance, check=props->contains(props.device_name, "MyFavVendor"))
source
VkComputeUtils.find_queue_family_idxMethod
find_queue_family_idx(physical_device; args...)

Find a queue family index (numbered from 0) for a physical device that satisfies some given properties; arguments are forwarded to find_scored_idx.

Example

# Find a queue family with most queues that supports compute and transfer operations.
find_queue_family_idx(physical_device, 
    check=qfp->hasbits(qfp.queue_flags, QUEUE_TRANSFER_BIT | QUEUE_COMPUTE_BIT),
    score=qfp->qfp.queue_count,
)
source
VkComputeUtils.find_scored_idxMethod
find_scored_idx(collection, what::String; check::Function=_->true, score::Function=_->0)

A helper function that runs through a collection and select an item that satisfies the predicate check with best score computed by score. If no suitable item is found, an error is thrown referring to the item type as what.

source

Compute shader pipelines

VkComputeUtils.ComputeShaderPipelineMethod
ComputeShaderPipeline(device, shader_code, n_buffers, spec_consts, push_constant_type::Type)

Create a ComputeShaderPipeline wrapper around the required tooling around the shader on the device. shader_code is compiled to SPIR-V using glslang and specialized using spec_consts to make a pipeline with a prepared descriptor sets and layouts for n_buffers storage buffers, accepting push constants of push_constant_type.

source
VkComputeUtils.cmd_bind_dispatchMethod
function cmd_bind_dispatch(
    cmd_buffer,
    csp::ComputeShaderPipeline{PushConstsT,NBuffers},
    push_constants::PushConstantsHolder{PushConstsT},
    x::Int,
    y::Int,
    z::Int,
) where {PushConstsT,NBuffers}

Write commands that properly push the constants, bind the descriptor sets and dispatch the shader over the workgroup of dimensions (x,y,z) to the command buffer cmd_buffer.

source
VkComputeUtils.hold_push_constantsMethod
hold_push_constants(t::T, args...)
hold_push_constants(csp::ComputeShaderPipeline{PushConstsT, NBuffers}, args...) where{PushConstsT, NBuffers}

A simple helper to create a "holding" structure for the push constants.

source
VkComputeUtils.write_descriptor_set_buffersMethod
write_descriptor_set_buffers(device, csp::ComputeShaderPipeline{PushConstsT, NBuffers}, buffers::Vector{Buffer}) where {PushConstsT,NBuffers}

Write a set of Vulkan Buffers to the descriptor set stored in csp.

source

Utilities

VkComputeUtils.n_blocksFunction
n_blocks(x,bs)

How many blocks of size bs are needed to process x items? Shortcut for div with RoundUp aka cld.

source