2023-01-14 12:03:01 +00:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct PipelineLayoutBuilder {
|
|
|
|
descriptor_set_layouts: Vec<VkDescriptorSetLayout>,
|
|
|
|
push_constant_ranges: Vec<VkPushConstantRange>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PipelineLayoutBuilder {
|
|
|
|
pub fn add_descriptor_set_layout(
|
|
|
|
mut self,
|
|
|
|
descriptor_set_layout: &dyn VkHandle<VkDescriptorSetLayout>,
|
|
|
|
) -> Self {
|
|
|
|
self.descriptor_set_layouts
|
|
|
|
.push(descriptor_set_layout.vk_handle());
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add_push_constant(mut self, push_constant: VkPushConstantRange) -> Self {
|
|
|
|
self.push_constant_ranges.push(push_constant);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build(self, device: Arc<Device>) -> Result<Arc<PipelineLayout>> {
|
|
|
|
let pipeline_layout_ci = VkPipelineLayoutCreateInfo::new(
|
|
|
|
VK_PIPELINE_LAYOUT_CREATE_NULL_BIT,
|
|
|
|
&self.descriptor_set_layouts,
|
|
|
|
&self.push_constant_ranges,
|
|
|
|
);
|
|
|
|
|
|
|
|
let pipeline_layout = device.create_pipeline_layout(&pipeline_layout_ci)?;
|
|
|
|
|
|
|
|
Ok(Arc::new(PipelineLayout {
|
|
|
|
device,
|
|
|
|
pipeline_layout,
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct PipelineLayout {
|
|
|
|
device: Arc<Device>,
|
|
|
|
pipeline_layout: VkPipelineLayout,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PipelineLayout {
|
|
|
|
pub fn builder() -> PipelineLayoutBuilder {
|
|
|
|
PipelineLayoutBuilder {
|
|
|
|
descriptor_set_layouts: Vec::new(),
|
|
|
|
push_constant_ranges: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VulkanDevice for PipelineLayout {
|
2024-03-28 17:28:52 +00:00
|
|
|
fn device(&self) -> &Device {
|
2023-01-14 12:03:01 +00:00
|
|
|
&self.device
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_vk_handle!(PipelineLayout, VkPipelineLayout, pipeline_layout);
|
|
|
|
|
|
|
|
impl Drop for PipelineLayout {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.device.destroy_pipeline_layout(self.pipeline_layout);
|
|
|
|
}
|
|
|
|
}
|