Add extension wrapper for VK_KHR_synchronization2 (#403)

* Add extension wrapper for VK_KHR_synchronization2

* synchronization2: Add missing slice length assert

* fmt

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
This commit is contained in:
Jakob Loth 2021-05-08 12:54:43 +02:00 committed by GitHub
parent bc510f017d
commit c7216f1c1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 0 deletions

View file

@ -18,6 +18,7 @@ pub use self::push_descriptor::PushDescriptor;
pub use self::ray_tracing_pipeline::RayTracingPipeline;
pub use self::surface::Surface;
pub use self::swapchain::Swapchain;
pub use self::synchronization2::Synchronization2;
pub use self::timeline_semaphore::TimelineSemaphore;
pub use self::wayland_surface::WaylandSurface;
pub use self::win32_surface::Win32Surface;
@ -44,6 +45,7 @@ mod push_descriptor;
mod ray_tracing_pipeline;
mod surface;
mod swapchain;
mod synchronization2;
mod timeline_semaphore;
mod wayland_surface;
mod win32_surface;

View file

@ -0,0 +1,107 @@
use crate::prelude::*;
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
#[derive(Clone)]
pub struct Synchronization2 {
handle: vk::Device,
synchronization2_fn: vk::KhrSynchronization2Fn,
}
impl Synchronization2 {
pub fn new(instance: &Instance, device: &Device) -> Self {
let synchronization2_fn = vk::KhrSynchronization2Fn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});
Self {
handle: device.handle(),
synchronization2_fn,
}
}
pub fn name() -> &'static CStr {
vk::KhrSynchronization2Fn::name()
}
pub fn fp(&self) -> &vk::KhrSynchronization2Fn {
&self.synchronization2_fn
}
pub fn device(&self) -> vk::Device {
self.handle
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdPipelineBarrier2KHR.html>"]
pub unsafe fn cmd_pipeline_barrier2(
&self,
command_buffer: vk::CommandBuffer,
dependency_info: &vk::DependencyInfoKHR,
) {
self.synchronization2_fn
.cmd_pipeline_barrier2_khr(command_buffer, dependency_info)
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdResetEvent2KHR.html>"]
pub unsafe fn cmd_reset_event2(
&self,
command_buffer: vk::CommandBuffer,
event: vk::Event,
stage_mask: vk::PipelineStageFlags2KHR,
) {
self.synchronization2_fn
.cmd_reset_event2_khr(command_buffer, event, stage_mask)
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdSetEvent2KHR.html>"]
pub unsafe fn cmd_set_event2(
&self,
command_buffer: vk::CommandBuffer,
event: vk::Event,
dependency_info: &vk::DependencyInfoKHR,
) {
self.synchronization2_fn
.cmd_set_event2_khr(command_buffer, event, dependency_info)
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdWaitEvents2KHR.html>"]
pub unsafe fn cmd_wait_events2(
&self,
command_buffer: vk::CommandBuffer,
events: &[vk::Event],
dependency_infos: &[vk::DependencyInfoKHR],
) {
assert_eq!(events.len(), dependency_infos.len());
self.synchronization2_fn.cmd_wait_events2_khr(
command_buffer,
events.len() as u32,
events.as_ptr(),
dependency_infos.as_ptr(),
)
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdWriteTimestamp2KHR.html>"]
pub unsafe fn cmd_write_timestamp2(
&self,
command_buffer: vk::CommandBuffer,
stage: vk::PipelineStageFlags2KHR,
query_pool: vk::QueryPool,
query: u32,
) {
self.synchronization2_fn
.cmd_write_timestamp2_khr(command_buffer, stage, query_pool, query)
}
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkQueueSubmit2KHR.html>"]
pub unsafe fn queue_submit2(
&self,
queue: vk::Queue,
submits: &[vk::SubmitInfo2KHR],
fence: vk::Fence,
) -> VkResult<()> {
self.synchronization2_fn
.queue_submit2_khr(queue, submits.len() as u32, submits.as_ptr(), fence)
.result()
}
}