Skip to content

Commit

Permalink
extensions/amdx: Add VK_AMDX_shader_enqueue
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jul 28, 2023
1 parent a5dfebd commit 780d7fb
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VK_NV_memory_decompression` device extension (#761)
- Added `VK_GOOGLE_display_timing` device extension (#765)
- Added `VK_ANDROID_external_memory_android_hardware_buffer` device extension (#769)
- Added `VK_AMDX_shader_enqueue` device extension (#TODO)

### Changed

Expand Down
3 changes: 3 additions & 0 deletions ash/src/extensions/amdx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub use self::shader_enqueue::ShaderEnqueue;

mod shader_enqueue;
123 changes: 123 additions & 0 deletions ash/src/extensions/amdx/shader_enqueue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use crate::prelude::*;
use crate::vk;
use crate::RawPtr;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;

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

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

#[inline]
pub unsafe fn create_execution_graph_pipelines(
&self,
pipeline_cache: vk::PipelineCache,
create_infos: &[vk::ExecutionGraphPipelineCreateInfoAMDX],
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<Vec<vk::Pipeline>> {
let mut pipelines = vec![mem::zeroed(); create_infos.len()];
(self.fp.create_execution_graph_pipelines_amdx)(
self.handle,
pipeline_cache,
create_infos.len() as u32,
create_infos.as_ptr(),
allocation_callbacks.as_raw_ptr(),
pipelines.as_mut_ptr(),
)
.result_with_success(pipelines)
}

#[inline]
pub unsafe fn get_execution_graph_pipeline_scratch_size(
&self,
execution_graph: vk::Pipeline,
size_info: &mut vk::ExecutionGraphPipelineScratchSizeAMDX,
) -> VkResult<()> {
(self.fp.get_execution_graph_pipeline_scratch_size_amdx)(
self.handle,
execution_graph,
size_info,
)
.result()
}

#[inline]
pub unsafe fn get_execution_graph_pipeline_node_index(
&self,
execution_graph: vk::Pipeline,
node_info: &vk::PipelineShaderStageNodeCreateInfoAMDX,
) -> VkResult<u32> {
let mut node_index = 0;
(self.fp.get_execution_graph_pipeline_node_index_amdx)(
self.handle,
execution_graph,
node_info,
&mut node_index,
)
.result_with_success(node_index)
}

#[inline]
pub unsafe fn cmd_initialize_graph_scratch_memory(
&self,
command_buffer: vk::CommandBuffer,
scratch: vk::DeviceAddress,
) {
(self.fp.cmd_initialize_graph_scratch_memory_amdx)(command_buffer, scratch)
}

#[inline]
pub unsafe fn cmd_dispatch_graph(
&self,
command_buffer: vk::CommandBuffer,
scratch: vk::DeviceAddress,
count_info: &vk::DispatchGraphCountInfoAMDX,
) {
(self.fp.cmd_dispatch_graph_amdx)(command_buffer, scratch, count_info)
}

#[inline]
pub unsafe fn cmd_dispatch_graph_indirect(
&self,
command_buffer: vk::CommandBuffer,
scratch: vk::DeviceAddress,
count_info: &vk::DispatchGraphCountInfoAMDX,
) {
(self.fp.cmd_dispatch_graph_indirect_amdx)(command_buffer, scratch, count_info)
}

#[inline]
pub unsafe fn cmd_dispatch_graph_indirect_count(
&self,
command_buffer: vk::CommandBuffer,
scratch: vk::DeviceAddress,
count_info: vk::DeviceAddress,
) {
(self.fp.cmd_dispatch_graph_indirect_count_amdx)(command_buffer, scratch, count_info)
}

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

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

#[inline]
pub fn device(&self) -> vk::Device {
self.handle
}
}
1 change: 1 addition & 0 deletions ash/src/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pub mod khr;
pub mod mvk;
pub mod nn;
pub mod nv;
pub mod amdx;

0 comments on commit 780d7fb

Please sign in to comment.