Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extensions: Add VK_KHR_maintenance4 #489

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions ash/src/extensions/khr/maintenance4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;

#[derive(Clone)]
pub struct Maintenance4 {
handle: vk::Device,
fns: vk::KhrMaintenance4Fn,
}

impl Maintenance4 {
pub fn new(instance: &Instance, device: &Device) -> Self {
let fns = vk::KhrMaintenance4Fn::load(|name| unsafe {
MarijnS95 marked this conversation as resolved.
Show resolved Hide resolved
mem::transmute(instance.get_device_proc_addr(device.handle(), name.as_ptr()))
});
Self {
handle: device.handle(),
fns,
}
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceBufferMemoryRequirementsKHR.html>"]
pub unsafe fn get_device_buffer_memory_requirements(
&self,
create_info: &vk::DeviceBufferMemoryRequirementsKHR,
out: &mut vk::MemoryRequirements2,
) {
self.fns
.get_device_buffer_memory_requirements_khr(self.handle, create_info, out)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceImageMemoryRequirementsKHR.html>"]
pub unsafe fn get_device_image_memory_requirements(
&self,
create_info: &vk::DeviceImageMemoryRequirementsKHR,
out: &mut vk::MemoryRequirements2,
) {
self.fns
.get_device_image_memory_requirements_khr(self.handle, create_info, out)
}

/// Retrieve the number of elements to pass to [`Self::get_device_image_sparse_memory_requirements()`]
pub unsafe fn get_device_image_sparse_memory_requirements_len(
&self,
create_info: &vk::DeviceImageMemoryRequirementsKHR,
) -> usize {
let mut count = 0;
self.fns.get_device_image_sparse_memory_requirements_khr(
self.handle,
create_info,
&mut count,
std::ptr::null_mut(),
);
count as usize
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDeviceImageSparseMemoryRequirementsKHR.html>"]
///
/// Call [`Self::get_device_image_sparse_memory_requirements_len()`] to query the number of elements to pass to `sparse_memory_requirements`.
/// Be sure to [`Default::default()`]-initialize these elements and optionally set their `p_next` pointer.
pub unsafe fn get_device_image_sparse_memory_requirements(
&self,
create_info: &vk::DeviceImageMemoryRequirementsKHR,
out: &mut [vk::SparseImageMemoryRequirements2],
) {
let mut count = out.len() as u32;
self.fns.get_device_image_sparse_memory_requirements_khr(
self.handle,
create_info,
&mut count,
out.as_mut_ptr(),
);
assert_eq!(count, out.len() as u32);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ralith I slipped in an assert_eq here without mentioning. I have a change locally to apply this to the other functions of this sort - do you think it's worth adding that everywhere consistently?

It seems very unlikely for this to ever change, hence an assert might be a good idea in the strange event that a driver happens to overwrite it after all (ie. playing around with beta drivers etc).

}

pub fn name() -> &'static CStr {
vk::KhrMaintenance4Fn::name()
}

pub fn fp(&self) -> &vk::KhrMaintenance4Fn {
&self.fns
}

pub fn device(&self) -> vk::Device {
self.handle
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/khr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use self::get_memory_requirements2::GetMemoryRequirements2;
pub use self::get_physical_device_properties2::GetPhysicalDeviceProperties2;
pub use self::maintenance1::Maintenance1;
pub use self::maintenance3::Maintenance3;
pub use self::maintenance4::Maintenance4;
pub use self::pipeline_executable_properties::PipelineExecutableProperties;
pub use self::push_descriptor::PushDescriptor;
pub use self::ray_tracing_pipeline::RayTracingPipeline;
Expand Down Expand Up @@ -42,6 +43,7 @@ mod get_memory_requirements2;
mod get_physical_device_properties2;
mod maintenance1;
mod maintenance3;
mod maintenance4;
mod pipeline_executable_properties;
mod push_descriptor;
mod ray_tracing_pipeline;
Expand Down