40 std::shared_ptr<VKShaderModule>
shader;
44 vk::PipelineCache
cache =
nullptr;
125 void cleanup(vk::Device device);
152 void bind(vk::CommandBuffer cmd)
const;
172 vk::CommandBuffer cmd,
173 const std::vector<vk::DescriptorSet>& descriptor_sets,
174 uint32_t first_set = 0,
175 const std::vector<uint32_t>& dynamic_offsets = {})
const;
195 vk::CommandBuffer cmd,
196 vk::ShaderStageFlags stage_flags,
199 const void* data)
const;
219 vk::CommandBuffer cmd,
220 uint32_t group_count_x,
221 uint32_t group_count_y,
222 uint32_t group_count_z)
const;
239 vk::CommandBuffer cmd,
240 uint32_t element_count,
241 uint32_t local_size_x)
const;
258 vk::CommandBuffer cmd,
259 uint32_t width_elements,
260 uint32_t height_elements,
261 uint32_t local_size_x,
262 uint32_t local_size_y)
const;
275 vk::CommandBuffer cmd,
276 uint32_t width_elements,
277 uint32_t height_elements,
278 uint32_t depth_elements,
279 uint32_t local_size_x,
280 uint32_t local_size_y,
281 uint32_t local_size_z)
const;
310 const ComputePipelineConfig& config,
311 const std::unordered_map<uint32_t, uint32_t>& specialization_data);
323 uint32_t element_count,
324 uint32_t workgroup_size);
330 uint32_t width, uint32_t height,
331 uint32_t workgroup_x, uint32_t workgroup_y);
337 uint32_t width, uint32_t height, uint32_t depth,
338 uint32_t workgroup_x, uint32_t workgroup_y, uint32_t workgroup_z);
346 template <
typename T>
349 static_assert(
sizeof(T) <= 128,
"Push constants typically limited to 128 bytes");
350 cmd.pushConstants(
m_layout, vk::ShaderStageFlagBits::eCompute,
351 0,
sizeof(T), &data);
365 vk::DeviceSize offset = 0);
bool create_specialized(vk::Device device, const ComputePipelineConfig &config, const std::unordered_map< uint32_t, uint32_t > &specialization_data)
Create pipeline with specialization constants.
void dispatch_1d(vk::CommandBuffer cmd, uint32_t element_count, uint32_t local_size_x) const
Dispatch compute workgroups with automatic calculation.
void bind(vk::CommandBuffer cmd) const
Bind pipeline to command buffer.
VKComputePipeline()=default
std::optional< std::array< uint32_t, 3 > > m_workgroup_size
void cleanup(vk::Device device)
Cleanup pipeline resources.
const ShaderReflection & get_shader_reflection() const
Get shader module reflection data.
void dispatch_indirect(vk::CommandBuffer cmd, vk::Buffer buffer, vk::DeviceSize offset=0)
Dispatch compute shader indirectly from GPU buffer.
VKComputePipeline(const VKComputePipeline &)=delete
static std::array< uint32_t, 3 > calculate_dispatch_2d(uint32_t width, uint32_t height, uint32_t workgroup_x, uint32_t workgroup_y)
Calculate 2D dispatch size.
static uint32_t calculate_workgroups(uint32_t element_count, uint32_t workgroup_size)
Calculate number of workgroups needed.
void dispatch(vk::CommandBuffer cmd, uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) const
Dispatch compute workgroups.
vk::Pipeline get() const
Get raw Vulkan pipeline handle.
std::shared_ptr< VKShaderModule > m_shader
void dispatch_2d(vk::CommandBuffer cmd, uint32_t width_elements, uint32_t height_elements, uint32_t local_size_x, uint32_t local_size_y) const
Dispatch compute workgroups in 2D with automatic calculation.
static std::array< uint32_t, 3 > calculate_dispatch_1d(uint32_t element_count, uint32_t workgroup_size)
Calculate dispatch size from element count.
std::optional< std::array< uint32_t, 3 > > get_workgroup_size() const
Get shader workgroup size from reflection.
void bind_descriptor_sets(vk::CommandBuffer cmd, const std::vector< vk::DescriptorSet > &descriptor_sets, uint32_t first_set=0, const std::vector< uint32_t > &dynamic_offsets={}) const
Bind descriptor sets to pipeline.
bool create(vk::Device device, const ComputePipelineConfig &config)
Create compute pipeline from configuration.
VKComputePipeline & operator=(const VKComputePipeline &)=delete
vk::PipelineLayout get_layout() const
Get pipeline layout handle.
void push_constants(vk::CommandBuffer cmd, vk::ShaderStageFlags stage_flags, uint32_t offset, uint32_t size, const void *data) const
Update push constants.
bool is_valid() const
Get pipeline statistics (if available)
void dispatch_3d(vk::CommandBuffer cmd, uint32_t width_elements, uint32_t height_elements, uint32_t depth_elements, uint32_t local_size_x, uint32_t local_size_y, uint32_t local_size_z) const
Dispatch compute workgroups in 3D with automatic calculation.
static std::array< uint32_t, 3 > calculate_dispatch_3d(uint32_t width, uint32_t height, uint32_t depth, uint32_t workgroup_x, uint32_t workgroup_y, uint32_t workgroup_z)
Calculate 3D dispatch size.
void push_constants_typed(vk::CommandBuffer cmd, const T &data)
Push constants with type safety.
vk::PipelineLayout m_layout
vk::PipelineLayout create_pipeline_layout(vk::Device device, const ComputePipelineConfig &config)
Create pipeline layout from configuration.
Wrapper for Vulkan compute pipeline with simplified interface.
std::vector< vk::DescriptorSetLayout > set_layouts
Descriptor layouts.
void add_descriptor_set_layout(vk::DescriptorSetLayout layout)
std::shared_ptr< VKShaderModule > shader
Compute shader.
void add_push_constant(vk::ShaderStageFlags stages, uint32_t size, uint32_t offset=0)
std::vector< PushConstantRange > push_constants
Push constant ranges.
Configuration for creating a compute pipeline.
vk::ShaderStageFlags stage_flags
Which shader stages access this.
PushConstantRange(vk::ShaderStageFlags stages, uint32_t offset_, uint32_t size_)
uint32_t size
Size of push constant data (bytes)
uint32_t offset
Offset in push constant block (bytes)
Defines a push constant range for pipeline creation.
Metadata extracted from shader module.