1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use utils::c_bindings::*;
use utils::vk_traits::*;
use utils::vk_ptr::*;
use utils::vk_convert::*;
use std::os::raw::c_char;
use std::ops::Drop;
use std::ptr;
use std::mem;
use std::cmp;
use std::slice;
use vulkan::*;
use vulkan::vk::*;
#[doc(hidden)]
pub type RawVkPipeline = u64;
#[derive(Debug, Clone)]
pub struct VkPipeline {
_handle: RawVkPipeline,
_parent_instance: RawVkInstance,
_parent_device: RawVkDevice,
_fn_table: *mut VkInstanceFunctionTable
}
impl VkRawType<VkPipeline> for RawVkPipeline {
fn vk_to_wrapped(src: &RawVkPipeline) -> VkPipeline {
VkPipeline {
_handle: *src,
_parent_instance: 0,
_parent_device: 0,
_fn_table: ptr::null_mut()
}
}
}
impl VkWrappedType<RawVkPipeline> for VkPipeline {
fn vk_to_raw(src: &VkPipeline, dst: &mut RawVkPipeline) {
*dst = src._handle
}
}
impl Default for VkPipeline {
fn default() -> VkPipeline {
VkPipeline {
_handle: 0,
_parent_instance: 0,
_parent_device: 0,
_fn_table: ptr::null_mut()
}
}
}
impl PartialEq for VkPipeline {
fn eq(&self, other: &VkPipeline) -> bool {
self._handle == other._handle
}
}
impl VkSetup for VkPipeline {
fn vk_setup(&mut self, fn_table: *mut VkInstanceFunctionTable, instance: RawVkInstance, device: RawVkDevice) {
self._parent_instance = instance;
self._parent_device = device;
self._fn_table = fn_table;
}
}
impl VkPipeline {
pub fn vk_handle(&self) -> u64 {
self._handle
}
pub fn destroy(&self) {
unsafe {
((&*self._fn_table).vkDestroyPipeline)(self._parent_device, self._handle, ptr::null());
}
}
pub fn get_shader_info(&self, shader_stage: VkShaderStageFlags, info_type: amd::VkShaderInfoType) -> Result<Vec<c_void>, (VkResult, Vec<c_void>)> {
unsafe {
let raw_shader_stage = vk_to_raw_value(&shader_stage);
let raw_info_type = vk_to_raw_value(&info_type);
let mut vk_result = 0;
let mut raw_info : *mut c_void = ptr::null_mut();
let raw_info_size = &mut mem::zeroed() as *mut usize;
vk_result = ((&*self._fn_table).vkGetShaderInfoAMD)(self._parent_device, self._handle, raw_shader_stage, raw_info_type, raw_info_size, raw_info);
raw_info = calloc(*raw_info_size as usize, mem::size_of::<c_void>()) as *mut c_void;
vk_result = ((&*self._fn_table).vkGetShaderInfoAMD)(self._parent_device, self._handle, raw_shader_stage, raw_info_type, raw_info_size, raw_info);
let info = Vec::from_raw_parts(raw_info, *raw_info_size, *raw_info_size);
if vk_result == 0 { Ok(info) } else { Err((RawVkResult::vk_to_wrapped(&vk_result), info)) }
}
}
pub fn get_ray_tracing_shader_group_handles(&self, first_group: usize, group_count: usize, data: &mut [c_void]) -> Result<(), VkResult> {
unsafe {
let raw_first_group = vk_to_raw_value(&first_group);
let raw_group_count = vk_to_raw_value(&group_count);
let raw_data_size = data.len();
let raw_data = data.as_mut_ptr();
let vk_result = ((&*self._fn_table).vkGetRayTracingShaderGroupHandlesNV)(self._parent_device, self._handle, raw_first_group, raw_group_count, raw_data_size, raw_data);
if vk_result == 0 { Ok(()) } else { Err(RawVkResult::vk_to_wrapped(&vk_result)) }
}
}
pub fn compile_deferred(&self, shader: usize) -> Result<(), VkResult> {
unsafe {
let raw_shader = vk_to_raw_value(&shader);
let vk_result = ((&*self._fn_table).vkCompileDeferredNV)(self._parent_device, self._handle, raw_shader);
if vk_result == 0 { Ok(()) } else { Err(RawVkResult::vk_to_wrapped(&vk_result)) }
}
}
}