From 0b689273c635edac14e566092a5d4a6ca3c70e18 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Sun, 1 Dec 2019 02:09:21 -0800 Subject: [PATCH] Support VK_KHR_push_descriptor (#241) * Support VK_KHR_push_descriptor * Accept slice in cmd_push_descriptor_set --- ash/src/extensions/khr/mod.rs | 2 + ash/src/extensions/khr/push_descriptor.rs | 75 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 ash/src/extensions/khr/push_descriptor.rs diff --git a/ash/src/extensions/khr/mod.rs b/ash/src/extensions/khr/mod.rs index c27beef..b81292c 100644 --- a/ash/src/extensions/khr/mod.rs +++ b/ash/src/extensions/khr/mod.rs @@ -1,6 +1,7 @@ pub use self::android_surface::AndroidSurface; pub use self::display::Display; pub use self::display_swapchain::DisplaySwapchain; +pub use self::push_descriptor::PushDescriptor; pub use self::surface::Surface; pub use self::swapchain::Swapchain; pub use self::wayland_surface::WaylandSurface; @@ -11,6 +12,7 @@ pub use self::xlib_surface::XlibSurface; mod android_surface; mod display; mod display_swapchain; +mod push_descriptor; mod surface; mod swapchain; mod wayland_surface; diff --git a/ash/src/extensions/khr/push_descriptor.rs b/ash/src/extensions/khr/push_descriptor.rs new file mode 100644 index 0000000..89103e3 --- /dev/null +++ b/ash/src/extensions/khr/push_descriptor.rs @@ -0,0 +1,75 @@ +#![allow(dead_code)] +use crate::version::{DeviceV1_0, InstanceV1_0}; +use crate::vk; +use std::ffi::c_void; +use std::ffi::CStr; +use std::mem; + +#[derive(Clone)] +pub struct PushDescriptor { + handle: vk::Instance, + push_descriptors_fn: vk::KhrPushDescriptorFn, +} + +impl PushDescriptor { + pub fn new(instance: &I, device: &D) -> PushDescriptor { + let push_descriptors_fn = vk::KhrPushDescriptorFn::load(|name| unsafe { + mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr())) + }); + + PushDescriptor { + handle: instance.handle(), + push_descriptors_fn, + } + } + + pub fn name() -> &'static CStr { + vk::KhrPushDescriptorFn::name() + } + + #[doc = ""] + pub unsafe fn cmd_push_descriptor_set( + &self, + command_buffer: vk::CommandBuffer, + pipeline_bind_point: vk::PipelineBindPoint, + layout: vk::PipelineLayout, + set: u32, + descriptor_writes: &[vk::WriteDescriptorSet], + ) { + self.push_descriptors_fn.cmd_push_descriptor_set_khr( + command_buffer, + pipeline_bind_point, + layout, + set, + descriptor_writes.len() as u32, + descriptor_writes.as_ptr(), + ); + } + + #[doc = ""] + pub unsafe fn cmd_push_descriptor_set_with_template( + &self, + command_buffer: vk::CommandBuffer, + descriptor_update_template: vk::DescriptorUpdateTemplate, + layout: vk::PipelineLayout, + set: u32, + p_data: *const c_void, + ) { + self.push_descriptors_fn + .cmd_push_descriptor_set_with_template_khr( + command_buffer, + descriptor_update_template, + layout, + set, + p_data, + ); + } + + pub fn fp(&self) -> &vk::KhrPushDescriptorFn { + &self.push_descriptors_fn + } + + pub fn instance(&self) -> vk::Instance { + self.handle + } +}