Data types
VkComputeUtils.ComputeShaderPipeline
— Typestruct 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.
VkComputeUtils.PushConstantsHolder
— Typestruct PushConstantsHolder{PushConstsT}
A holder for the push-constants value that holds it static while being pointed to by command buffer functions.
Facility discovery
VkComputeUtils.find_memory_type_idx
— Methodfind_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,
)
VkComputeUtils.find_physical_device
— Methodfind_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"))
VkComputeUtils.find_queue_family_idx
— Methodfind_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,
)
VkComputeUtils.find_scored_idx
— Methodfind_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
.
Compute shader pipelines
VkComputeUtils.ComputeShaderPipeline
— MethodComputeShaderPipeline(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
.
VkComputeUtils.cmd_bind_dispatch
— Methodfunction 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
.
VkComputeUtils.hold_push_constants
— Methodhold_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.
VkComputeUtils.write_descriptor_set_buffers
— Methodwrite_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
.
Utilities
VkComputeUtils.hasbits
— Methodhasbits(flags, required)
Check that all required
bits are present in flags
. Non-shortcut for in
.
VkComputeUtils.hasbits
— Methodhasbits(required)
Convenience function that checks if something has the required
bits. Uses the other methods of hasbits
.
VkComputeUtils.n_blocks
— Functionn_blocks(x,bs)
How many blocks of size bs
are needed to process x
items? Shortcut for div
with RoundUp
aka cld
.