Skip to content

Commit

Permalink
Omit wrapper functions on Fp structs
Browse files Browse the repository at this point in the history
These wrappers contributed thousands of lines of code but offered
insignificant ergonomic benefit as the same functions are also wrapped
at a higher level and, if necessary, wrapper functions can be called
directly.
  • Loading branch information
Ralith committed Mar 22, 2022
1 parent 79a2ef0 commit 6006a32
Show file tree
Hide file tree
Showing 58 changed files with 1,038 additions and 7,376 deletions.
885 changes: 407 additions & 478 deletions ash/src/device.rs

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ impl Entry {
/// Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`].
pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self {
let load_fn = |name: &std::ffi::CStr| {
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
mem::transmute((static_fn.get_instance_proc_addr)(
vk::Instance::null(),
name.as_ptr(),
))
};
let entry_fn_1_0 = vk::EntryFnV1_0::load(load_fn);
let entry_fn_1_1 = vk::EntryFnV1_1::load(load_fn);
Expand Down Expand Up @@ -192,10 +195,10 @@ impl Entry {
let mut api_version = 0;
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
let name = b"vkEnumerateInstanceVersion\0".as_ptr() as *const _;
mem::transmute(
self.static_fn
.get_instance_proc_addr(vk::Instance::null(), name),
)
mem::transmute((self.static_fn.get_instance_proc_addr)(
vk::Instance::null(),
name,
))
};
if let Some(enumerate_instance_version) = enumerate_instance_version {
(enumerate_instance_version)(&mut api_version)
Expand All @@ -218,22 +221,20 @@ impl Entry {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<Instance> {
let mut instance = mem::zeroed();
self.entry_fn_1_0
.create_instance(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
)
.result()?;
(self.entry_fn_1_0.create_instance)(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
)
.result()?;
Ok(Instance::load(&self.static_fn, instance))
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceLayerProperties.html>
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
unsafe {
read_into_uninitialized_vector(|count, data| {
self.entry_fn_1_0
.enumerate_instance_layer_properties(count, data)
(self.entry_fn_1_0.enumerate_instance_layer_properties)(count, data)
})
}
}
Expand All @@ -245,7 +246,7 @@ impl Entry {
) -> VkResult<Vec<vk::ExtensionProperties>> {
unsafe {
read_into_uninitialized_vector(|count, data| {
self.entry_fn_1_0.enumerate_instance_extension_properties(
(self.entry_fn_1_0.enumerate_instance_extension_properties)(
layer_name.map_or(ptr::null(), |str| str.as_ptr()),
count,
data,
Expand All @@ -260,7 +261,7 @@ impl Entry {
instance: vk::Instance,
p_name: *const c_char,
) -> vk::PFN_vkVoidFunction {
self.static_fn.get_instance_proc_addr(instance, p_name)
(self.static_fn.get_instance_proc_addr)(instance, p_name)
}
}

Expand All @@ -278,8 +279,7 @@ impl Entry {
pub fn enumerate_instance_version(&self) -> VkResult<u32> {
unsafe {
let mut api_version = 0;
self.entry_fn_1_1
.enumerate_instance_version(&mut api_version)
(self.entry_fn_1_1.enumerate_instance_version)(&mut api_version)
.result_with_success(api_version)
}
}
Expand Down
2 changes: 1 addition & 1 deletion ash/src/extensions/ext/buffer_device_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl BufferDeviceAddress {
&self,
info: &vk::BufferDeviceAddressInfoEXT,
) -> vk::DeviceAddress {
self.fp.get_buffer_device_address_ext(self.handle, info)
(self.fp.get_buffer_device_address_ext)(self.handle, info)
}

pub fn name() -> &'static CStr {
Expand Down
24 changes: 13 additions & 11 deletions ash/src/extensions/ext/calibrated_timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ impl CalibratedTimestamps {
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::TimeDomainEXT>> {
read_into_uninitialized_vector(|count, data| {
self.fp
.get_physical_device_calibrateable_time_domains_ext(physical_device, count, data)
(self.fp.get_physical_device_calibrateable_time_domains_ext)(
physical_device,
count,
data,
)
})
}

Expand All @@ -40,15 +43,14 @@ impl CalibratedTimestamps {
) -> VkResult<(Vec<u64>, Vec<u64>)> {
let mut timestamps = vec![0u64; info.len()];
let mut max_deviation = vec![0u64; info.len()];
self.fp
.get_calibrated_timestamps_ext(
device,
info.len() as u32,
info.as_ptr(),
timestamps.as_mut_ptr(),
max_deviation.as_mut_ptr(),
)
.result_with_success((timestamps, max_deviation))
(self.fp.get_calibrated_timestamps_ext)(
device,
info.len() as u32,
info.as_ptr(),
timestamps.as_mut_ptr(),
max_deviation.as_mut_ptr(),
)
.result_with_success((timestamps, max_deviation))
}

pub fn name() -> &'static CStr {
Expand Down
12 changes: 4 additions & 8 deletions ash/src/extensions/ext/debug_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ impl DebugMarker {
&self,
name_info: &vk::DebugMarkerObjectNameInfoEXT,
) -> VkResult<()> {
self.fp
.debug_marker_set_object_name_ext(self.handle, name_info)
.result()
(self.fp.debug_marker_set_object_name_ext)(self.handle, name_info).result()
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdDebugMarkerBeginEXT.html>
Expand All @@ -35,13 +33,12 @@ impl DebugMarker {
command_buffer: vk::CommandBuffer,
marker_info: &vk::DebugMarkerMarkerInfoEXT,
) {
self.fp
.cmd_debug_marker_begin_ext(command_buffer, marker_info);
(self.fp.cmd_debug_marker_begin_ext)(command_buffer, marker_info);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdDebugMarkerEndEXT.html>
pub unsafe fn cmd_debug_marker_end(&self, command_buffer: vk::CommandBuffer) {
self.fp.cmd_debug_marker_end_ext(command_buffer);
(self.fp.cmd_debug_marker_end_ext)(command_buffer);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdDebugMarkerInsertEXT.html>
Expand All @@ -50,8 +47,7 @@ impl DebugMarker {
command_buffer: vk::CommandBuffer,
marker_info: &vk::DebugMarkerMarkerInfoEXT,
) {
self.fp
.cmd_debug_marker_insert_ext(command_buffer, marker_info);
(self.fp.cmd_debug_marker_insert_ext)(command_buffer, marker_info);
}

pub fn name() -> &'static CStr {
Expand Down
17 changes: 8 additions & 9 deletions ash/src/extensions/ext/debug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl DebugReport {
debug: vk::DebugReportCallbackEXT,
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) {
self.fp.destroy_debug_report_callback_ext(
(self.fp.destroy_debug_report_callback_ext)(
self.handle,
debug,
allocation_callbacks.as_raw_ptr(),
Expand All @@ -40,14 +40,13 @@ impl DebugReport {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::DebugReportCallbackEXT> {
let mut debug_cb = mem::zeroed();
self.fp
.create_debug_report_callback_ext(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut debug_cb,
)
.result_with_success(debug_cb)
(self.fp.create_debug_report_callback_ext)(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut debug_cb,
)
.result_with_success(debug_cb)
}

pub fn name() -> &'static CStr {
Expand Down
42 changes: 17 additions & 25 deletions ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ impl DebugUtils {
device: vk::Device,
name_info: &vk::DebugUtilsObjectNameInfoEXT,
) -> VkResult<()> {
self.fp
.set_debug_utils_object_name_ext(device, name_info)
.result()
(self.fp.set_debug_utils_object_name_ext)(device, name_info).result()
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkSetDebugUtilsObjectTagEXT.html>
Expand All @@ -36,9 +34,7 @@ impl DebugUtils {
device: vk::Device,
tag_info: &vk::DebugUtilsObjectTagInfoEXT,
) -> VkResult<()> {
self.fp
.set_debug_utils_object_tag_ext(device, tag_info)
.result()
(self.fp.set_debug_utils_object_tag_ext)(device, tag_info).result()
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBeginDebugUtilsLabelEXT.html>
Expand All @@ -47,13 +43,12 @@ impl DebugUtils {
command_buffer: vk::CommandBuffer,
label: &vk::DebugUtilsLabelEXT,
) {
self.fp
.cmd_begin_debug_utils_label_ext(command_buffer, label);
(self.fp.cmd_begin_debug_utils_label_ext)(command_buffer, label);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdEndDebugUtilsLabelEXT.html>
pub unsafe fn cmd_end_debug_utils_label(&self, command_buffer: vk::CommandBuffer) {
self.fp.cmd_end_debug_utils_label_ext(command_buffer);
(self.fp.cmd_end_debug_utils_label_ext)(command_buffer);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdInsertDebugUtilsLabelEXT.html>
Expand All @@ -62,8 +57,7 @@ impl DebugUtils {
command_buffer: vk::CommandBuffer,
label: &vk::DebugUtilsLabelEXT,
) {
self.fp
.cmd_insert_debug_utils_label_ext(command_buffer, label);
(self.fp.cmd_insert_debug_utils_label_ext)(command_buffer, label);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkQueueBeginDebugUtilsLabelEXT.html>
Expand All @@ -72,12 +66,12 @@ impl DebugUtils {
queue: vk::Queue,
label: &vk::DebugUtilsLabelEXT,
) {
self.fp.queue_begin_debug_utils_label_ext(queue, label);
(self.fp.queue_begin_debug_utils_label_ext)(queue, label);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkQueueEndDebugUtilsLabelEXT.html>
pub unsafe fn queue_end_debug_utils_label(&self, queue: vk::Queue) {
self.fp.queue_end_debug_utils_label_ext(queue);
(self.fp.queue_end_debug_utils_label_ext)(queue);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkQueueInsertDebugUtilsLabelEXT.html>
Expand All @@ -86,7 +80,7 @@ impl DebugUtils {
queue: vk::Queue,
label: &vk::DebugUtilsLabelEXT,
) {
self.fp.queue_insert_debug_utils_label_ext(queue, label);
(self.fp.queue_insert_debug_utils_label_ext)(queue, label);
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDebugUtilsMessengerEXT.html>
Expand All @@ -96,14 +90,13 @@ impl DebugUtils {
allocator: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::DebugUtilsMessengerEXT> {
let mut messenger = mem::zeroed();
self.fp
.create_debug_utils_messenger_ext(
self.handle,
create_info,
allocator.as_raw_ptr(),
&mut messenger,
)
.result_with_success(messenger)
(self.fp.create_debug_utils_messenger_ext)(
self.handle,
create_info,
allocator.as_raw_ptr(),
&mut messenger,
)
.result_with_success(messenger)
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkDestroyDebugUtilsMessengerEXT.html>
Expand All @@ -112,8 +105,7 @@ impl DebugUtils {
messenger: vk::DebugUtilsMessengerEXT,
allocator: Option<&vk::AllocationCallbacks>,
) {
self.fp
.destroy_debug_utils_messenger_ext(self.handle, messenger, allocator.as_raw_ptr());
(self.fp.destroy_debug_utils_messenger_ext)(self.handle, messenger, allocator.as_raw_ptr());
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkSubmitDebugUtilsMessageEXT.html>
Expand All @@ -123,7 +115,7 @@ impl DebugUtils {
message_types: vk::DebugUtilsMessageTypeFlagsEXT,
callback_data: &vk::DebugUtilsMessengerCallbackDataEXT,
) {
self.fp.submit_debug_utils_message_ext(
(self.fp.submit_debug_utils_message_ext)(
self.handle,
message_severity,
message_types,
Expand Down
Loading

0 comments on commit 6006a32

Please sign in to comment.