pipeline types
This commit is contained in:
parent
6c18ddfa16
commit
c73457b913
|
|
@ -217,15 +217,19 @@ pub struct DescriptorSetAllocDesc<'a> {
|
||||||
pub layout: &'a DescriptorSetLayout,
|
pub layout: &'a DescriptorSetLayout,
|
||||||
}
|
}
|
||||||
|
|
||||||
define_device_owned_handle! {
|
impl DeviceHandle for vk::DescriptorPool {
|
||||||
#[derive(Debug)]
|
unsafe fn destroy(&mut self, device: &Device) {
|
||||||
pub DescriptorPool(vk::DescriptorPool) {} => |this| unsafe {
|
unsafe { device.dev().destroy_descriptor_pool(*self, None) };
|
||||||
this.device().dev().destroy_descriptor_pool(this.handle(), None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DescriptorPool {
|
||||||
|
pool: DeviceObject<vk::DescriptorPool>,
|
||||||
|
}
|
||||||
|
|
||||||
impl DescriptorPool {
|
impl DescriptorPool {
|
||||||
pub fn new(device: Device, desc: DescriptorPoolDesc) -> VkResult<Self> {
|
pub fn new(device: Device, desc: DescriptorPoolDesc) -> crate::Result<Self> {
|
||||||
let info = &vk::DescriptorPoolCreateInfo::default()
|
let info = &vk::DescriptorPoolCreateInfo::default()
|
||||||
.flags(desc.flags)
|
.flags(desc.flags)
|
||||||
.max_sets(desc.max_sets)
|
.max_sets(desc.max_sets)
|
||||||
|
|
@ -233,7 +237,9 @@ impl DescriptorPool {
|
||||||
|
|
||||||
let handle = unsafe { device.dev().create_descriptor_pool(info, None)? };
|
let handle = unsafe { device.dev().create_descriptor_pool(info, None)? };
|
||||||
|
|
||||||
Self::construct(device, handle, desc.name)
|
Ok(Self {
|
||||||
|
pool: DeviceObject::new(handle, device, desc.name),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocate(&self, descs: &[DescriptorSetAllocDesc]) -> VkResult<Vec<vk::DescriptorSet>> {
|
pub fn allocate(&self, descs: &[DescriptorSetAllocDesc]) -> VkResult<Vec<vk::DescriptorSet>> {
|
||||||
|
|
@ -243,13 +249,13 @@ impl DescriptorPool {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let info = &vk::DescriptorSetAllocateInfo::default()
|
let info = &vk::DescriptorSetAllocateInfo::default()
|
||||||
.descriptor_pool(self.handle())
|
.descriptor_pool(*self.pool)
|
||||||
.set_layouts(&layouts);
|
.set_layouts(&layouts);
|
||||||
let sets = unsafe { self.device().dev().allocate_descriptor_sets(info)? };
|
let sets = unsafe { self.pool.device().raw.allocate_descriptor_sets(info)? };
|
||||||
|
|
||||||
for (&set, desc) in sets.iter().zip(descs) {
|
for (&set, desc) in sets.iter().zip(descs) {
|
||||||
if let Some(name) = desc.name.as_ref() {
|
if let Some(name) = desc.name.as_ref() {
|
||||||
unsafe { self.device().debug_name_object(set, name) };
|
unsafe { self.pool.device().debug_name_object(set, name) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -259,22 +265,27 @@ impl DescriptorPool {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn reset(&self) -> VkResult<()> {
|
pub fn reset(&self) -> VkResult<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.device()
|
self.pool
|
||||||
.dev()
|
.device()
|
||||||
.reset_descriptor_pool(self.handle(), vk::DescriptorPoolResetFlags::empty())
|
.raw
|
||||||
|
.reset_descriptor_pool(*self.pool, vk::DescriptorPoolResetFlags::empty())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define_device_owned_handle! {
|
impl DeviceHandle for vk::DescriptorSetLayout {
|
||||||
#[derive(Debug)]
|
unsafe fn destroy(&mut self, device: &Device) {
|
||||||
pub DescriptorSetLayout(vk::DescriptorSetLayout) {} => |this| unsafe {
|
unsafe { device.raw.destroy_descriptor_set_layout(*self, None) };
|
||||||
this.device().dev().destroy_descriptor_set_layout(this.handle(), None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct DescriptorSetLayout {
|
||||||
|
layout: DeviceObject<vk::DescriptorSetLayout>,
|
||||||
|
}
|
||||||
|
|
||||||
impl DescriptorSetLayout {
|
impl DescriptorSetLayout {
|
||||||
pub fn new(device: Device, desc: DescriptorSetLayoutDesc) -> VkResult<Self> {
|
pub fn new(device: Device, desc: DescriptorSetLayoutDesc) -> crate::Result<Self> {
|
||||||
let (flags, bindings): (Vec<_>, Vec<_>) = desc
|
let (flags, bindings): (Vec<_>, Vec<_>) = desc
|
||||||
.bindings
|
.bindings
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -305,34 +316,50 @@ impl DescriptorSetLayout {
|
||||||
info = info.push_next(flags);
|
info = info.push_next(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
let layout = unsafe { device.dev().create_descriptor_set_layout(&info, None)? };
|
let layout = unsafe { device.raw.create_descriptor_set_layout(&info, None)? };
|
||||||
|
|
||||||
Self::construct(device, layout, desc.name)
|
Ok(Self {
|
||||||
|
layout: DeviceObject::new(layout, device, desc.name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn raw(&self) -> vk::DescriptorSetLayout {
|
||||||
|
*self.layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::device::DeviceOwned;
|
use crate::device::DeviceOwned;
|
||||||
|
|
||||||
define_device_owned_handle! {
|
impl DeviceHandle for vk::PipelineLayout {
|
||||||
#[derive(Debug)]
|
unsafe fn destroy(&mut self, device: &Device) {
|
||||||
pub PipelineLayout(vk::PipelineLayout) {} => |this| unsafe {
|
unsafe { device.raw.destroy_pipeline_layout(*self, None) };
|
||||||
this.device().dev().destroy_pipeline_layout(this.handle(), None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct PipelineLayout {
|
||||||
|
layout: DeviceObject<vk::PipelineLayout>,
|
||||||
|
}
|
||||||
|
|
||||||
impl PipelineLayout {
|
impl PipelineLayout {
|
||||||
pub fn new(device: Device, desc: PipelineLayoutDesc) -> VkResult<Self> {
|
pub fn new(device: Device, desc: PipelineLayoutDesc) -> crate::Result<Self> {
|
||||||
let set_layouts = desc
|
let set_layouts = desc
|
||||||
.descriptor_set_layouts
|
.descriptor_set_layouts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|desc| desc.handle())
|
.map(|desc| desc.raw())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let info = &vk::PipelineLayoutCreateInfo::default()
|
let info = &vk::PipelineLayoutCreateInfo::default()
|
||||||
.set_layouts(&set_layouts)
|
.set_layouts(&set_layouts)
|
||||||
.push_constant_ranges(desc.push_constant_ranges);
|
.push_constant_ranges(desc.push_constant_ranges);
|
||||||
let layout = unsafe { device.dev().create_pipeline_layout(info, None)? };
|
let layout = unsafe { device.raw.create_pipeline_layout(info, None)? };
|
||||||
|
|
||||||
Self::construct(device, layout, desc.name)
|
Ok(Self {
|
||||||
|
layout: DeviceObject::new(layout, device, desc.name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn raw(&self) -> vk::PipelineLayout {
|
||||||
|
*self.layout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -431,14 +458,21 @@ impl Sampler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
define_device_owned_handle! {
|
impl DeviceHandle for vk::ShaderModule {
|
||||||
#[derive(Debug)]
|
unsafe fn destroy(&mut self, device: &Device) {
|
||||||
pub ShaderModule(vk::ShaderModule) {} => |this| unsafe {
|
unsafe { device.raw.destroy_shader_module(*self, None) };
|
||||||
this.device().dev().destroy_shader_module(this.handle(), None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ShaderModule {
|
||||||
|
module: DeviceObject<vk::ShaderModule>,
|
||||||
|
}
|
||||||
|
|
||||||
impl ShaderModule {
|
impl ShaderModule {
|
||||||
|
pub fn raw(&self) -> vk::ShaderModule {
|
||||||
|
*self.module
|
||||||
|
}
|
||||||
pub fn new_from_path<P: AsRef<Path>>(device: Device, path: P) -> crate::Result<Self> {
|
pub fn new_from_path<P: AsRef<Path>>(device: Device, path: P) -> crate::Result<Self> {
|
||||||
use std::io::{BufReader, Read, Seek};
|
use std::io::{BufReader, Read, Seek};
|
||||||
|
|
||||||
|
|
@ -456,12 +490,14 @@ impl ShaderModule {
|
||||||
Ok(Self::new_from_memory(device, &buffer)?)
|
Ok(Self::new_from_memory(device, &buffer)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_memory(device: Device, buffer: &[u32]) -> VkResult<Self> {
|
pub fn new_from_memory(device: Device, buffer: &[u32]) -> crate::Result<Self> {
|
||||||
let info = &vk::ShaderModuleCreateInfo::default().code(buffer);
|
let info = &vk::ShaderModuleCreateInfo::default().code(buffer);
|
||||||
|
|
||||||
let module = unsafe { device.dev().create_shader_module(info, None)? };
|
let module = unsafe { device.dev().create_shader_module(info, None)? };
|
||||||
|
|
||||||
Self::construct(device, module, None)
|
Ok(Self {
|
||||||
|
module: DeviceObject::new(module, device, None),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -480,7 +516,7 @@ impl DeviceHandle for vk::Pipeline {
|
||||||
impl ShaderStageDesc<'_> {
|
impl ShaderStageDesc<'_> {
|
||||||
fn as_create_info(&'_ self) -> vk::PipelineShaderStageCreateInfo<'_> {
|
fn as_create_info(&'_ self) -> vk::PipelineShaderStageCreateInfo<'_> {
|
||||||
vk::PipelineShaderStageCreateInfo::default()
|
vk::PipelineShaderStageCreateInfo::default()
|
||||||
.module(self.module.handle())
|
.module(self.module.raw())
|
||||||
.flags(self.flags)
|
.flags(self.flags)
|
||||||
.stage(self.stage)
|
.stage(self.stage)
|
||||||
.name(&self.entry)
|
.name(&self.entry)
|
||||||
|
|
@ -491,7 +527,7 @@ impl Pipeline {
|
||||||
pub fn new_compute(device: Device, desc: ComputePipelineDesc) -> crate::Result<Self> {
|
pub fn new_compute(device: Device, desc: ComputePipelineDesc) -> crate::Result<Self> {
|
||||||
let info = &vk::ComputePipelineCreateInfo::default()
|
let info = &vk::ComputePipelineCreateInfo::default()
|
||||||
.flags(desc.flags)
|
.flags(desc.flags)
|
||||||
.layout(desc.layout.handle())
|
.layout(desc.layout.raw())
|
||||||
.base_pipeline_handle(
|
.base_pipeline_handle(
|
||||||
desc.base_pipeline
|
desc.base_pipeline
|
||||||
.map(|p| p.raw())
|
.map(|p| p.raw())
|
||||||
|
|
@ -653,7 +689,7 @@ impl Pipeline {
|
||||||
p_depth_stencil_state: option_to_ptr(&depth_stencil),
|
p_depth_stencil_state: option_to_ptr(&depth_stencil),
|
||||||
p_color_blend_state: option_to_ptr(&color_blend),
|
p_color_blend_state: option_to_ptr(&color_blend),
|
||||||
p_dynamic_state: option_to_ptr(&dynamic),
|
p_dynamic_state: option_to_ptr(&dynamic),
|
||||||
layout: desc.layout.handle(),
|
layout: desc.layout.raw(),
|
||||||
render_pass: desc.render_pass.unwrap_or(vk::RenderPass::null()),
|
render_pass: desc.render_pass.unwrap_or(vk::RenderPass::null()),
|
||||||
subpass: desc.subpass.unwrap_or(0),
|
subpass: desc.subpass.unwrap_or(0),
|
||||||
base_pipeline_handle: desc
|
base_pipeline_handle: desc
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue