From e0547227711e9c40c0c83db3ecb6a4fc76d744e6 Mon Sep 17 00:00:00 2001 From: Joshua Simmons Date: Wed, 2 Nov 2022 22:15:47 +0100 Subject: [PATCH] Add vk descriptor management functions --- ffi/vulkan-sys/src/handles.rs | 2 +- ffi/vulkan-sys/src/lib.rs | 103 ++++++++++++++++++++++++++++++++++ ffi/vulkan-sys/src/structs.rs | 12 ++-- 3 files changed, 110 insertions(+), 7 deletions(-) diff --git a/ffi/vulkan-sys/src/handles.rs b/ffi/vulkan-sys/src/handles.rs index 478d7d4..ebf32d1 100644 --- a/ffi/vulkan-sys/src/handles.rs +++ b/ffi/vulkan-sys/src/handles.rs @@ -20,7 +20,7 @@ pub struct CommandBuffer(u64); #[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, Default, Debug)] -pub struct DeviceMemory(u64); +pub struct DeviceMemory(pub u64); #[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, Default, Debug)] diff --git a/ffi/vulkan-sys/src/lib.rs b/ffi/vulkan-sys/src/lib.rs index 7bf66b5..7eeba0c 100644 --- a/ffi/vulkan-sys/src/lib.rs +++ b/ffi/vulkan-sys/src/lib.rs @@ -537,6 +537,12 @@ pub struct DeviceFunctions { destroy_sampler: FnDestroySampler, create_descriptor_set_layout: FnCreateDescriptorSetLayout, destroy_descriptor_set_layout: FnDestroyDescriptorSetLayout, + create_descriptor_pool: FnCreateDescriptorPool, + destroy_descriptor_pool: FnDestroyDescriptorPool, + reset_descriptor_pool: FnResetDescriptorPool, + allocate_descriptor_sets: FnAllocateDescriptorSets, + free_descriptor_sets: FnFreeDescriptorSets, + update_descriptor_sets: FnUpdateDescriptorSets, create_pipeline_layout: FnCreatePipelineLayout, destroy_pipeline_layout: FnDestroyPipelineLayout, create_graphics_pipelines: FnCreateGraphicsPipelines, @@ -734,6 +740,30 @@ impl DeviceFunctions { cstr!("vkDestroyDescriptorSetLayout"), VERSION_1_0, )), + create_descriptor_pool: transmute::<_, _>(load( + cstr!("vkCreateDescriptorPool"), + VERSION_1_0, + )), + destroy_descriptor_pool: transmute::<_, _>(load( + cstr!("vkDestroyDescriptorPool"), + VERSION_1_0, + )), + reset_descriptor_pool: transmute::<_, _>(load( + cstr!("vkResetDescriptorPool"), + VERSION_1_0, + )), + allocate_descriptor_sets: transmute::<_, _>(load( + cstr!("vkAllocateDescriptorSets"), + VERSION_1_0, + )), + free_descriptor_sets: transmute::<_, _>(load( + cstr!("vkFreeDescriptorSets"), + VERSION_1_0, + )), + update_descriptor_sets: transmute::<_, _>(load( + cstr!("vkUpdateDescriptorSets"), + VERSION_1_0, + )), create_pipeline_layout: transmute::<_, _>(load( cstr!("vkCreatePipelineLayout"), VERSION_1_0, @@ -1381,6 +1411,79 @@ impl DeviceFunctions { (self.destroy_descriptor_set_layout)(device, descriptor_set_layout, allocator) } + #[inline] + pub unsafe fn create_descriptor_pool( + &self, + device: Device, + create_info: &DescriptorPoolCreateInfo, + allocator: Option<&AllocationCallbacks>, + descriptor_pool: &mut DescriptorPool, + ) -> Result { + (self.create_descriptor_pool)(device, create_info, allocator, descriptor_pool) + } + + #[inline] + pub unsafe fn destroy_descriptor_pool( + &self, + device: Device, + descriptor_pool: DescriptorPool, + allocator: Option<&AllocationCallbacks>, + ) { + (self.destroy_descriptor_pool)(device, descriptor_pool, allocator) + } + + #[inline] + pub unsafe fn reset_descriptor_pool( + &self, + device: Device, + descriptor_pool: DescriptorPool, + flags: DescriptorPoolResetFlags, + ) -> Result { + (self.reset_descriptor_pool)(device, descriptor_pool, flags) + } + + #[inline] + pub unsafe fn allocate_descriptor_sets( + &self, + device: Device, + allocate_info: &DescriptorSetAllocateInfo, + descriptor_sets: *mut DescriptorSet, + ) -> Result { + (self.allocate_descriptor_sets)(device, allocate_info, descriptor_sets) + } + + #[inline] + pub unsafe fn free_descriptor_sets( + &self, + device: Device, + descriptor_pool: DescriptorPool, + descriptor_set_count: u32, + descriptor_sets: *const DescriptorSet, + ) -> Result { + (self.free_descriptor_sets)( + device, + descriptor_pool, + descriptor_set_count, + descriptor_sets, + ) + } + + #[inline] + pub unsafe fn update_descriptor_sets( + &self, + device: Device, + descriptor_writes: &[WriteDescriptorSet], + descriptor_copies: &[CopyDescriptorSet], + ) { + (self.update_descriptor_sets)( + device, + descriptor_writes.len() as u32, + descriptor_writes.as_ptr(), + descriptor_copies.len() as u32, + descriptor_copies.as_ptr(), + ) + } + #[inline] pub unsafe fn create_pipeline_layout( &self, diff --git a/ffi/vulkan-sys/src/structs.rs b/ffi/vulkan-sys/src/structs.rs index a704ec5..0c0a1e4 100644 --- a/ffi/vulkan-sys/src/structs.rs +++ b/ffi/vulkan-sys/src/structs.rs @@ -1062,7 +1062,7 @@ impl<'a> Default for DescriptorSetLayoutCreateInfo<'a> { #[repr(C)] #[derive(Copy, Clone)] pub struct DescriptorPoolSize { - pub r#type: DescriptorType, + pub descriptor_type: DescriptorType, pub descriptor_count: u32, } @@ -1536,7 +1536,7 @@ pub struct DescriptorImageInfo { #[repr(C)] #[derive(Copy, Clone)] -pub struct WriteDescriptorSet<'a> { +pub struct WriteDescriptorSet { pub _type: StructureType, pub _next: *const c_void, /// Destination descriptor set @@ -1550,14 +1550,14 @@ pub struct WriteDescriptorSet<'a> { /// Descriptor type to write (determines which members of the array pointed by pDescriptors are going to be used) pub descriptor_type: DescriptorType, /// Sampler, image view, and layout for SAMPLER, COMBINED_IMAGE_SAMPLER, {SAMPLED,STORAGE}_IMAGE, and INPUT_ATTACHMENT descriptor types. - pub image_info: Option<&'a DescriptorImageInfo>, + pub image_info: *const DescriptorImageInfo, /// Raw buffer, size, and offset for {UNIFORM,STORAGE}_BUFFER\[_DYNAMIC\] descriptor types. - pub buffer_info: Option<&'a DescriptorBufferInfo>, + pub buffer_info: *const DescriptorBufferInfo, /// Buffer view to write to the descriptor for {UNIFORM,STORAGE}_TEXEL_BUFFER descriptor types. - pub texel_buffer_view: Option<&'a BufferView>, + pub texel_buffer_view: *const BufferView, } -impl<'a> Default for WriteDescriptorSet<'a> { +impl Default for WriteDescriptorSet { fn default() -> Self { let mut x = unsafe { MaybeUninit::::zeroed().assume_init() }; x._type = StructureType::WriteDescriptorSet; -- 2.49.0