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/nv: Add VK_NV_cuda_kernel_launch extension #805

Merged
merged 1 commit into from
Oct 26, 2023
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
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_EXT_swapchain_maintenance1` device extension (#786)
- Added `VK_NV_low_latency2` device extension (#802)
- Added `VK_EXT_hdr_metadata` device extension (#804)
- Added `VK_NV_cuda_kernel_launch` device extension (#805)

### Changed

Expand Down
4 changes: 2 additions & 2 deletions ash/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2238,12 +2238,12 @@ impl Device {
&self,
pipeline_cache: vk::PipelineCache,
) -> VkResult<Vec<u8>> {
read_into_uninitialized_vector(|count, data| {
read_into_uninitialized_vector(|count, data: *mut u8| {
(self.device_fn_1_0.get_pipeline_cache_data)(
self.handle(),
pipeline_cache,
count,
data as _,
data.cast(),
)
})
}
Expand Down
107 changes: 107 additions & 0 deletions ash/src/extensions/nv/cuda_kernel_launch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use crate::prelude::*;
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_NV_cuda_kernel_launch.html>
#[derive(Clone)]
pub struct CudaKernelLaunch {
handle: vk::Device,
fp: vk::NvCudaKernelLaunchFn,
}

impl CudaKernelLaunch {
pub fn new(instance: &Instance, device: &Device) -> Self {
let handle = device.handle();
let fp = vk::NvCudaKernelLaunchFn::load(|name| unsafe {
mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
});
Self { handle, fp }
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateCudaModuleNV.html>
#[inline]
pub unsafe fn create_cuda_module(
&self,
create_info: &vk::CudaModuleCreateInfoNV<'_>,
allocator: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::CudaModuleNV> {
let mut module = mem::MaybeUninit::uninit();
(self.fp.create_cuda_module_nv)(
self.handle,
create_info,
allocator.as_raw_ptr(),
module.as_mut_ptr(),
)
.assume_init_on_success(module)
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkGetCudaModuleCacheNV.html>
#[inline]
pub unsafe fn get_cuda_module_cache(&self, module: vk::CudaModuleNV) -> VkResult<Vec<u8>> {
read_into_uninitialized_vector(|cache_size, cache_data: *mut u8| {
(self.fp.get_cuda_module_cache_nv)(self.handle, module, cache_size, cache_data.cast())
})
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCreateCudaFunctionNV.html>
#[inline]
pub unsafe fn create_cuda_function(
&self,
create_info: &vk::CudaFunctionCreateInfoNV<'_>,
allocator: Option<&vk::AllocationCallbacks<'_>>,
) -> VkResult<vk::CudaFunctionNV> {
let mut function = mem::MaybeUninit::uninit();
(self.fp.create_cuda_function_nv)(
self.handle,
create_info,
allocator.as_raw_ptr(),
function.as_mut_ptr(),
)
.assume_init_on_success(function)
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyCudaModuleNV.html>
#[inline]
pub unsafe fn destroy_cuda_module(
&self,
module: vk::CudaModuleNV,
allocator: Option<&vk::AllocationCallbacks<'_>>,
) {
(self.fp.destroy_cuda_module_nv)(self.handle, module, allocator.as_raw_ptr())
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkDestroyCudaFunctionNV.html>
#[inline]
pub unsafe fn destroy_cuda_function(
&self,
function: vk::CudaFunctionNV,
allocator: Option<&vk::AllocationCallbacks<'_>>,
) {
(self.fp.destroy_cuda_function_nv)(self.handle, function, allocator.as_raw_ptr())
}

/// <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/vkCmdCudaLaunchKernelNV.html>
#[inline]
pub unsafe fn cmd_cuda_launch_kernel(
&self,
command_buffer: vk::CommandBuffer,
launch_info: &vk::CudaLaunchInfoNV<'_>,
) {
(self.fp.cmd_cuda_launch_kernel_nv)(command_buffer, launch_info)
}

pub const NAME: &'static CStr = vk::NvCudaKernelLaunchFn::NAME;

#[inline]
pub fn fp(&self) -> &vk::NvCudaKernelLaunchFn {
&self.fp
}

#[inline]
pub fn device(&self) -> vk::Device {
self.handle
}
}
2 changes: 2 additions & 0 deletions ash/src/extensions/nv/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use self::coverage_reduction_mode::CoverageReductionMode;
pub use self::cuda_kernel_launch::CudaKernelLaunch;
pub use self::device_diagnostic_checkpoints::DeviceDiagnosticCheckpoints;
pub use self::device_generated_commands_compute::DeviceGeneratedCommandsCompute;
pub use self::low_latency2::LowLatency2;
Expand All @@ -7,6 +8,7 @@ pub use self::mesh_shader::MeshShader;
pub use self::ray_tracing::RayTracing;

mod coverage_reduction_mode;
mod cuda_kernel_launch;
mod device_diagnostic_checkpoints;
mod device_generated_commands_compute;
mod low_latency2;
Expand Down
Loading