Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preliminary cleanup pass #339

Merged
merged 29 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3011d24
Fix clippy::manual_strip
MarijnS95 Nov 9, 2020
d035f82
Fix clippy::comparison_to_empty
MarijnS95 Nov 9, 2020
f7c9451
Fix clippy::needless_lifetimes
MarijnS95 Nov 9, 2020
f078547
generator: Drop unnecessary edgecase for charptr array in builder
MarijnS95 Aug 24, 2020
abd3052
generator: Make array type handling more linear
MarijnS95 Aug 24, 2020
8803570
prelude: Provide Result -> VkResult<()> conversion
MarijnS95 Aug 24, 2020
6110c23
Add #[must_use] to Result type
MarijnS95 Aug 24, 2020
7e2e938
Fix all unchecked vk::Result cases
MarijnS95 Aug 25, 2020
5a98daa
generator: Fix typos
MarijnS95 Aug 24, 2020
f0f012d
generator: Assert char ptrs have `"null-terminated"` len attribute
MarijnS95 Aug 24, 2020
e8305d4
prelude: Provide result_with_success helper for Result -> VKresult
MarijnS95 Nov 16, 2020
62961b4
Cleanup match{success} blocks with SSR
MarijnS95 Nov 16, 2020
d619ecb
Simplify matching on Result::SUCCESS
MarijnS95 Nov 20, 2020
e3f9aaa
Simplify intermediate error return
MarijnS95 Nov 20, 2020
e23e496
Simplify error checking with .result()? and .result_with_success()
MarijnS95 Nov 20, 2020
d64286e
generator: Ignore empty basetype in typedef (forward declaration)
MarijnS95 Aug 24, 2020
7e1a601
Suggestion: Allocate data in get_ray_tracing_shader_group_handles
MarijnS95 Aug 28, 2020
05dcdbf
generator: Update nom to 6.0
MarijnS95 Nov 16, 2020
79be32d
generator: Generalize C expression conversion to TokenStream
MarijnS95 Nov 20, 2020
76a19df
generator: Simplify ReferenceType::to_tokens with quote!
MarijnS95 Nov 16, 2020
17f3010
generator: Refactor to not parse our own stringified token stream
MarijnS95 Nov 23, 2020
392f943
generator: Deal with pointers to static-sized arrays
MarijnS95 Aug 24, 2020
f4adefc
generator: Apply static-sized array pointer to size containing `*`
MarijnS95 Nov 23, 2020
18fce5b
generator: setter: Interpret all references as ptr, not just p_/pp_
MarijnS95 Nov 23, 2020
6d04568
generator: quote::* is already imported
MarijnS95 Nov 24, 2020
162c861
generator: Replace manual fn to_tokens with quote::ToTokens trait impl
MarijnS95 Nov 24, 2020
d366983
generator: Return str reference from constant_name
MarijnS95 Nov 24, 2020
a83882f
generator: Replace unused to_type_tokens with name_to_tokens
MarijnS95 Dec 6, 2020
5ae5c17
generator: setters: Use safe mutable references instead of raw ptrs
MarijnS95 Nov 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
668 changes: 262 additions & 406 deletions ash/src/device.rs

Large diffs are not rendered by default.

53 changes: 20 additions & 33 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,32 @@ pub trait EntryV1_0 {
unsafe {
let mut num = 0;
self.fp_v1_0()
.enumerate_instance_layer_properties(&mut num, ptr::null_mut());

.enumerate_instance_layer_properties(&mut num, ptr::null_mut())
.result()?;
let mut v = Vec::with_capacity(num as usize);
let err_code = self
.fp_v1_0()
.enumerate_instance_layer_properties(&mut num, v.as_mut_ptr());
v.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
err_code.result_with_success(v)
}
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkEnumerateInstanceExtensionProperties.html>"]
fn enumerate_instance_extension_properties(&self) -> VkResult<Vec<vk::ExtensionProperties>> {
unsafe {
let mut num = 0;
self.fp_v1_0().enumerate_instance_extension_properties(
ptr::null(),
&mut num,
ptr::null_mut(),
);
self.fp_v1_0()
.enumerate_instance_extension_properties(ptr::null(), &mut num, ptr::null_mut())
.result()?;
let mut data = Vec::with_capacity(num as usize);
let err_code = self.fp_v1_0().enumerate_instance_extension_properties(
ptr::null(),
&mut num,
data.as_mut_ptr(),
);
data.set_len(num as usize);
match err_code {
vk::Result::SUCCESS => Ok(data),
_ => Err(err_code),
}
err_code.result_with_success(data)
}
}

Expand Down Expand Up @@ -119,14 +111,14 @@ impl<L> EntryV1_0 for EntryCustom<L> {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> Result<Self::Instance, InstanceError> {
let mut instance: vk::Instance = mem::zeroed();
let err_code = self.fp_v1_0().create_instance(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
);
if err_code != vk::Result::SUCCESS {
return Err(InstanceError::VkError(err_code));
}
self.fp_v1_0()
.create_instance(
create_info,
allocation_callbacks.as_raw_ptr(),
&mut instance,
)
.result()
.map_err(InstanceError::VkError)?;
Ok(Instance::load(&self.static_fn, instance))
}
fn fp_v1_0(&self) -> &vk::EntryFnV1_0 {
Expand All @@ -146,11 +138,9 @@ pub trait EntryV1_1: EntryV1_0 {
fn enumerate_instance_version(&self) -> VkResult<u32> {
unsafe {
let mut api_version = 0;
let err_code = self.fp_v1_1().enumerate_instance_version(&mut api_version);
match err_code {
vk::Result::SUCCESS => Ok(api_version),
_ => Err(err_code),
}
self.fp_v1_1()
.enumerate_instance_version(&mut api_version)
.result_with_success(api_version)
}
}
}
Expand Down Expand Up @@ -228,11 +218,8 @@ impl<L> EntryCustom<L> {
)
};
if let Some(enumerate_instance_version) = enumerate_instance_version {
let err_code = (enumerate_instance_version)(&mut api_version);
match err_code {
vk::Result::SUCCESS => Ok(Some(api_version)),
_ => Err(err_code),
}
(enumerate_instance_version)(&mut api_version)
.result_with_success(Some(api_version))
} else {
Ok(None)
}
Expand Down
10 changes: 3 additions & 7 deletions ash/src/extensions/ext/debug_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ impl DebugMarker {
device: vk::Device,
name_info: &vk::DebugMarkerObjectNameInfoEXT,
) -> VkResult<()> {
let err_code = self
.debug_marker_fn
.debug_marker_set_object_name_ext(device, name_info);
match err_code {
vk::Result::SUCCESS => Ok(()),
_ => Err(err_code),
}
self.debug_marker_fn
.debug_marker_set_object_name_ext(device, name_info)
.into()
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdDebugMarkerBeginEXT.html>"]
Expand Down
18 changes: 8 additions & 10 deletions ash/src/extensions/ext/debug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ impl DebugReport {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::DebugReportCallbackEXT> {
let mut debug_cb = mem::zeroed();
let err_code = self.debug_report_fn.create_debug_report_callback_ext(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut debug_cb,
);
match err_code {
vk::Result::SUCCESS => Ok(debug_cb),
_ => Err(err_code),
}
self.debug_report_fn
.create_debug_report_callback_ext(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut debug_cb,
)
.result_with_success(debug_cb)
}

pub fn fp(&self) -> &vk::ExtDebugReportFn {
Expand Down
38 changes: 14 additions & 24 deletions ash/src/extensions/ext/debug_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ impl DebugUtils {
device: vk::Device,
name_info: &vk::DebugUtilsObjectNameInfoEXT,
) -> VkResult<()> {
let err_code = self
.debug_utils_fn
.set_debug_utils_object_name_ext(device, name_info);
match err_code {
vk::Result::SUCCESS => Ok(()),
_ => Err(err_code),
}
self.debug_utils_fn
.set_debug_utils_object_name_ext(device, name_info)
.into()
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkSetDebugUtilsObjectTagEXT.html>"]
Expand All @@ -47,13 +43,9 @@ impl DebugUtils {
device: vk::Device,
tag_info: &vk::DebugUtilsObjectTagInfoEXT,
) -> VkResult<()> {
let err_code = self
.debug_utils_fn
.set_debug_utils_object_tag_ext(device, tag_info);
match err_code {
vk::Result::SUCCESS => Ok(()),
_ => Err(err_code),
}
self.debug_utils_fn
.set_debug_utils_object_tag_ext(device, tag_info)
.into()
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdBeginDebugUtilsLabelEXT.html>"]
Expand Down Expand Up @@ -114,16 +106,14 @@ impl DebugUtils {
allocator: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::DebugUtilsMessengerEXT> {
let mut messenger = mem::zeroed();
let err_code = self.debug_utils_fn.create_debug_utils_messenger_ext(
self.handle,
create_info,
allocator.as_raw_ptr(),
&mut messenger,
);
match err_code {
vk::Result::SUCCESS => Ok(messenger),
_ => Err(err_code),
}
self.debug_utils_fn
.create_debug_utils_messenger_ext(
self.handle,
create_info,
allocator.as_raw_ptr(),
&mut messenger,
)
.result_with_success(messenger)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroyDebugUtilsMessengerEXT.html>"]
Expand Down
18 changes: 8 additions & 10 deletions ash/src/extensions/ext/metal_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ impl MetalSurface {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::zeroed();
let err_code = self.metal_surface_fn.create_metal_surface_ext(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut surface,
);
match err_code {
vk::Result::SUCCESS => Ok(surface),
_ => Err(err_code),
}
self.metal_surface_fn
.create_metal_surface_ext(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut surface,
)
.result_with_success(surface)
}

pub fn fp(&self) -> &vk::ExtMetalSurfaceFn {
Expand Down
8 changes: 3 additions & 5 deletions ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ impl ToolingInfo {
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT>> {
let mut count = 0;
self.tooling_info_fn
.get_physical_device_tool_properties_ext(physical_device, &mut count, ptr::null_mut());
.get_physical_device_tool_properties_ext(physical_device, &mut count, ptr::null_mut())
.result()?;
let mut v = Vec::with_capacity(count as usize);
let err_code = self
.tooling_info_fn
.get_physical_device_tool_properties_ext(physical_device, &mut count, v.as_mut_ptr());
v.set_len(count as usize);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
err_code.result_with_success(v)
}

pub fn fp(&self) -> &vk::ExtToolingInfoFn {
Expand Down
18 changes: 8 additions & 10 deletions ash/src/extensions/khr/android_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ impl AndroidSurface {
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
let mut surface = mem::zeroed();
let err_code = self.android_surface_fn.create_android_surface_khr(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut surface,
);
match err_code {
vk::Result::SUCCESS => Ok(surface),
_ => Err(err_code),
}
self.android_surface_fn
.create_android_surface_khr(
self.handle,
create_info,
allocation_callbacks.as_raw_ptr(),
&mut surface,
)
.result_with_success(surface)
}

pub fn fp(&self) -> &vk::KhrAndroidSurfaceFn {
Expand Down
Loading