Skip to content

Commit

Permalink
extensions/nv: Add VK_NV_cuda_kernel_launch extension
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Oct 25, 2023
1 parent 8f81f7d commit cbc32ab
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 2 deletions.
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 @@ -2232,12 +2232,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

0 comments on commit cbc32ab

Please sign in to comment.