vulkan_lib/vulkan-rs/src/pipeline.rs

98 lines
2 KiB
Rust

use crate::prelude::*;
use anyhow::Result;
use std::sync::Arc;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum PipelineType {
Graphics,
Compute,
RayTracing,
}
#[derive(Debug)]
pub struct Pipeline {
device: Arc<Device>,
pipeline_layout: Arc<PipelineLayout>,
pipeline_type: PipelineType,
pipeline: VkPipeline,
sub_pass: u32,
}
impl Pipeline {
pub(crate) fn new(
device: Arc<Device>,
pipeline_layout: Arc<PipelineLayout>,
pipeline_type: PipelineType,
pipeline: VkPipeline,
) -> Self {
Pipeline {
device,
pipeline_layout,
pipeline_type,
pipeline,
sub_pass: u32::MAX,
}
}
pub(crate) fn set_sub_pass(mut self, subpass: u32) -> Self {
self.sub_pass = subpass;
self
}
pub(crate) fn sub_pass(&self) -> u32 {
self.sub_pass
}
pub fn new_graphics() -> GraphicsPipelineBuilder {
GraphicsPipelineBuilder::default()
}
pub fn new_compute<'a>() -> ComputePipelineBuilder<'a> {
ComputePipelineBuilder::default()
}
pub fn new_ray_tracing<'a>() -> RayTracingPipelineBuilder<'a> {
RayTracingPipelineBuilder::default()
}
pub(crate) fn ray_tracing_shader_group_handles(
&self,
group_count: u32,
handle_size: u32,
) -> Result<Vec<u8>> {
if self.pipeline_type != PipelineType::RayTracing {
panic!("wrong pipeline type");
}
self.device
.get_ray_tracing_shader_group_handles(self.pipeline, 0, group_count, handle_size)
}
pub fn pipeline_layout(&self) -> &Arc<PipelineLayout> {
&self.pipeline_layout
}
pub fn pipeline_type(&self) -> PipelineType {
self.pipeline_type
}
}
impl VulkanDevice for Pipeline {
fn device(&self) -> &Arc<Device> {
&self.device
}
}
impl_vk_handle!(Pipeline, VkPipeline, pipeline);
impl Drop for Pipeline {
fn drop(&mut self) {
self.device.destroy_pipeline(self.pipeline);
}
}