Skip to content

Commit 84cddb7

Browse files
authored
Omit wrapper functions on Fp structs (#599)
* Omit wrapper functions on Fp structs 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. * Standardize on direct fp table access in wrapper functions
1 parent 1cd8106 commit 84cddb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1045
-7400
lines changed

Changelog.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## Unreleased
88

9+
- Dropped auto-generated wrapper methods from function pointer structs
10+
in favor of direct invocation of function pointers (#599)
11+
912
### Added
1013

1114
- Update Vulkan-Headers to 1.3.208 (#597)

ash/src/device.rs

+411-478
Large diffs are not rendered by default.

ash/src/entry.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ impl Entry {
144144
/// Vulkan 1.0, which must remain valid for at least the lifetime of the returned [`Entry`].
145145
pub unsafe fn from_static_fn(static_fn: vk::StaticFn) -> Self {
146146
let load_fn = |name: &std::ffi::CStr| {
147-
mem::transmute(static_fn.get_instance_proc_addr(vk::Instance::null(), name.as_ptr()))
147+
mem::transmute((static_fn.get_instance_proc_addr)(
148+
vk::Instance::null(),
149+
name.as_ptr(),
150+
))
148151
};
149152
let entry_fn_1_0 = vk::EntryFnV1_0::load(load_fn);
150153
let entry_fn_1_1 = vk::EntryFnV1_1::load(load_fn);
@@ -192,10 +195,10 @@ impl Entry {
192195
let mut api_version = 0;
193196
let enumerate_instance_version: Option<vk::PFN_vkEnumerateInstanceVersion> = {
194197
let name = b"vkEnumerateInstanceVersion\0".as_ptr() as *const _;
195-
mem::transmute(
196-
self.static_fn
197-
.get_instance_proc_addr(vk::Instance::null(), name),
198-
)
198+
mem::transmute((self.static_fn.get_instance_proc_addr)(
199+
vk::Instance::null(),
200+
name,
201+
))
199202
};
200203
if let Some(enumerate_instance_version) = enumerate_instance_version {
201204
(enumerate_instance_version)(&mut api_version)
@@ -218,22 +221,20 @@ impl Entry {
218221
allocation_callbacks: Option<&vk::AllocationCallbacks>,
219222
) -> VkResult<Instance> {
220223
let mut instance = mem::zeroed();
221-
self.entry_fn_1_0
222-
.create_instance(
223-
create_info,
224-
allocation_callbacks.as_raw_ptr(),
225-
&mut instance,
226-
)
227-
.result()?;
224+
(self.entry_fn_1_0.create_instance)(
225+
create_info,
226+
allocation_callbacks.as_raw_ptr(),
227+
&mut instance,
228+
)
229+
.result()?;
228230
Ok(Instance::load(&self.static_fn, instance))
229231
}
230232

231233
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkEnumerateInstanceLayerProperties.html>
232234
pub fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
233235
unsafe {
234236
read_into_uninitialized_vector(|count, data| {
235-
self.entry_fn_1_0
236-
.enumerate_instance_layer_properties(count, data)
237+
(self.entry_fn_1_0.enumerate_instance_layer_properties)(count, data)
237238
})
238239
}
239240
}
@@ -245,7 +246,7 @@ impl Entry {
245246
) -> VkResult<Vec<vk::ExtensionProperties>> {
246247
unsafe {
247248
read_into_uninitialized_vector(|count, data| {
248-
self.entry_fn_1_0.enumerate_instance_extension_properties(
249+
(self.entry_fn_1_0.enumerate_instance_extension_properties)(
249250
layer_name.map_or(ptr::null(), |str| str.as_ptr()),
250251
count,
251252
data,
@@ -260,7 +261,7 @@ impl Entry {
260261
instance: vk::Instance,
261262
p_name: *const c_char,
262263
) -> vk::PFN_vkVoidFunction {
263-
self.static_fn.get_instance_proc_addr(instance, p_name)
264+
(self.static_fn.get_instance_proc_addr)(instance, p_name)
264265
}
265266
}
266267

@@ -278,8 +279,7 @@ impl Entry {
278279
pub fn enumerate_instance_version(&self) -> VkResult<u32> {
279280
unsafe {
280281
let mut api_version = 0;
281-
self.entry_fn_1_1
282-
.enumerate_instance_version(&mut api_version)
282+
(self.entry_fn_1_1.enumerate_instance_version)(&mut api_version)
283283
.result_with_success(api_version)
284284
}
285285
}

ash/src/extensions/ext/buffer_device_address.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl BufferDeviceAddress {
2323
&self,
2424
info: &vk::BufferDeviceAddressInfoEXT,
2525
) -> vk::DeviceAddress {
26-
self.fp.get_buffer_device_address_ext(self.handle, info)
26+
(self.fp.get_buffer_device_address_ext)(self.handle, info)
2727
}
2828

2929
pub const fn name() -> &'static CStr {

ash/src/extensions/ext/calibrated_timestamps.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ impl CalibratedTimestamps {
2525
physical_device: vk::PhysicalDevice,
2626
) -> VkResult<Vec<vk::TimeDomainEXT>> {
2727
read_into_uninitialized_vector(|count, data| {
28-
self.fp
29-
.get_physical_device_calibrateable_time_domains_ext(physical_device, count, data)
28+
(self.fp.get_physical_device_calibrateable_time_domains_ext)(
29+
physical_device,
30+
count,
31+
data,
32+
)
3033
})
3134
}
3235

@@ -40,15 +43,14 @@ impl CalibratedTimestamps {
4043
) -> VkResult<(Vec<u64>, Vec<u64>)> {
4144
let mut timestamps = vec![0u64; info.len()];
4245
let mut max_deviation = vec![0u64; info.len()];
43-
self.fp
44-
.get_calibrated_timestamps_ext(
45-
device,
46-
info.len() as u32,
47-
info.as_ptr(),
48-
timestamps.as_mut_ptr(),
49-
max_deviation.as_mut_ptr(),
50-
)
51-
.result_with_success((timestamps, max_deviation))
46+
(self.fp.get_calibrated_timestamps_ext)(
47+
device,
48+
info.len() as u32,
49+
info.as_ptr(),
50+
timestamps.as_mut_ptr(),
51+
max_deviation.as_mut_ptr(),
52+
)
53+
.result_with_success((timestamps, max_deviation))
5254
}
5355

5456
pub const fn name() -> &'static CStr {

ash/src/extensions/ext/debug_marker.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ impl DebugMarker {
2424
&self,
2525
name_info: &vk::DebugMarkerObjectNameInfoEXT,
2626
) -> VkResult<()> {
27-
self.fp
28-
.debug_marker_set_object_name_ext(self.handle, name_info)
29-
.result()
27+
(self.fp.debug_marker_set_object_name_ext)(self.handle, name_info).result()
3028
}
3129

3230
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdDebugMarkerBeginEXT.html>
@@ -35,13 +33,12 @@ impl DebugMarker {
3533
command_buffer: vk::CommandBuffer,
3634
marker_info: &vk::DebugMarkerMarkerInfoEXT,
3735
) {
38-
self.fp
39-
.cmd_debug_marker_begin_ext(command_buffer, marker_info);
36+
(self.fp.cmd_debug_marker_begin_ext)(command_buffer, marker_info);
4037
}
4138

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

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

5753
pub const fn name() -> &'static CStr {

ash/src/extensions/ext/debug_report.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl DebugReport {
2626
debug: vk::DebugReportCallbackEXT,
2727
allocation_callbacks: Option<&vk::AllocationCallbacks>,
2828
) {
29-
self.fp.destroy_debug_report_callback_ext(
29+
(self.fp.destroy_debug_report_callback_ext)(
3030
self.handle,
3131
debug,
3232
allocation_callbacks.as_raw_ptr(),
@@ -40,14 +40,13 @@ impl DebugReport {
4040
allocation_callbacks: Option<&vk::AllocationCallbacks>,
4141
) -> VkResult<vk::DebugReportCallbackEXT> {
4242
let mut debug_cb = mem::zeroed();
43-
self.fp
44-
.create_debug_report_callback_ext(
45-
self.handle,
46-
create_info,
47-
allocation_callbacks.as_raw_ptr(),
48-
&mut debug_cb,
49-
)
50-
.result_with_success(debug_cb)
43+
(self.fp.create_debug_report_callback_ext)(
44+
self.handle,
45+
create_info,
46+
allocation_callbacks.as_raw_ptr(),
47+
&mut debug_cb,
48+
)
49+
.result_with_success(debug_cb)
5150
}
5251

5352
pub const fn name() -> &'static CStr {

ash/src/extensions/ext/debug_utils.rs

+17-25
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ impl DebugUtils {
2525
device: vk::Device,
2626
name_info: &vk::DebugUtilsObjectNameInfoEXT,
2727
) -> VkResult<()> {
28-
self.fp
29-
.set_debug_utils_object_name_ext(device, name_info)
30-
.result()
28+
(self.fp.set_debug_utils_object_name_ext)(device, name_info).result()
3129
}
3230

3331
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkSetDebugUtilsObjectTagEXT.html>
@@ -36,9 +34,7 @@ impl DebugUtils {
3634
device: vk::Device,
3735
tag_info: &vk::DebugUtilsObjectTagInfoEXT,
3836
) -> VkResult<()> {
39-
self.fp
40-
.set_debug_utils_object_tag_ext(device, tag_info)
41-
.result()
37+
(self.fp.set_debug_utils_object_tag_ext)(device, tag_info).result()
4238
}
4339

4440
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdBeginDebugUtilsLabelEXT.html>
@@ -47,13 +43,12 @@ impl DebugUtils {
4743
command_buffer: vk::CommandBuffer,
4844
label: &vk::DebugUtilsLabelEXT,
4945
) {
50-
self.fp
51-
.cmd_begin_debug_utils_label_ext(command_buffer, label);
46+
(self.fp.cmd_begin_debug_utils_label_ext)(command_buffer, label);
5247
}
5348

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

5954
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCmdInsertDebugUtilsLabelEXT.html>
@@ -62,8 +57,7 @@ impl DebugUtils {
6257
command_buffer: vk::CommandBuffer,
6358
label: &vk::DebugUtilsLabelEXT,
6459
) {
65-
self.fp
66-
.cmd_insert_debug_utils_label_ext(command_buffer, label);
60+
(self.fp.cmd_insert_debug_utils_label_ext)(command_buffer, label);
6761
}
6862

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

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

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

9286
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateDebugUtilsMessengerEXT.html>
@@ -96,14 +90,13 @@ impl DebugUtils {
9690
allocator: Option<&vk::AllocationCallbacks>,
9791
) -> VkResult<vk::DebugUtilsMessengerEXT> {
9892
let mut messenger = mem::zeroed();
99-
self.fp
100-
.create_debug_utils_messenger_ext(
101-
self.handle,
102-
create_info,
103-
allocator.as_raw_ptr(),
104-
&mut messenger,
105-
)
106-
.result_with_success(messenger)
93+
(self.fp.create_debug_utils_messenger_ext)(
94+
self.handle,
95+
create_info,
96+
allocator.as_raw_ptr(),
97+
&mut messenger,
98+
)
99+
.result_with_success(messenger)
107100
}
108101

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

119111
/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkSubmitDebugUtilsMessageEXT.html>
@@ -123,7 +115,7 @@ impl DebugUtils {
123115
message_types: vk::DebugUtilsMessageTypeFlagsEXT,
124116
callback_data: &vk::DebugUtilsMessengerCallbackDataEXT,
125117
) {
126-
self.fp.submit_debug_utils_message_ext(
118+
(self.fp.submit_debug_utils_message_ext)(
127119
self.handle,
128120
message_severity,
129121
message_types,

0 commit comments

Comments
 (0)