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 1 commit
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
Prev Previous commit
Next Next commit
Simplify error checking with .result()? and .result_with_success()
  • Loading branch information
MarijnS95 committed Nov 24, 2020
commit e23e4967456f81202ad5d96deef5bb8c3a18b66a
15 changes: 3 additions & 12 deletions ash/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,7 @@ pub trait DeviceV1_0 {
);

desc_set.set_len(create_info.descriptor_set_count as usize);
match err_code {
vk::Result::SUCCESS => Ok(desc_set),
_ => Err(err_code),
}
err_code.result_with_success(desc_set)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDescriptorSetLayout.html>"]
Expand Down Expand Up @@ -1597,10 +1594,7 @@ pub trait DeviceV1_0 {
data.as_mut_ptr() as _,
);
data.set_len(data_size);
match err_code {
vk::Result::SUCCESS => Ok(data),
_ => Err(err_code),
}
err_code.result_with_success(data)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkMapMemory.html>"]
Expand Down Expand Up @@ -1826,10 +1820,7 @@ pub trait DeviceV1_0 {
buffers.as_mut_ptr(),
);
buffers.set_len(create_info.command_buffer_count as usize);
match err_code {
vk::Result::SUCCESS => Ok(buffers),
_ => Err(err_code),
}
err_code.result_with_success(buffers)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateCommandPool.html>"]
Expand Down
35 changes: 13 additions & 22 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,15 @@ pub trait EntryV1_0 {
fn enumerate_instance_layer_properties(&self) -> VkResult<Vec<vk::LayerProperties>> {
unsafe {
let mut num = 0;
let err_code = self
.fp_v1_0()
.enumerate_instance_layer_properties(&mut num, ptr::null_mut());
if err_code != vk::Result::SUCCESS {
return Err(err_code);
}
self.fp_v1_0()
.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)
}
}

Expand All @@ -89,10 +83,7 @@ pub trait EntryV1_0 {
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 @@ -120,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 Down
14 changes: 4 additions & 10 deletions ash/src/extensions/ext/tooling_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ impl ToolingInfo {
physical_device: vk::PhysicalDevice,
) -> VkResult<Vec<vk::PhysicalDeviceToolPropertiesEXT>> {
let mut count = 0;
let err_code = self
.tooling_info_fn
.get_physical_device_tool_properties_ext(physical_device, &mut count, ptr::null_mut());
if err_code != vk::Result::SUCCESS {
return Err(err_code);
}
self.tooling_info_fn
.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
20 changes: 4 additions & 16 deletions ash/src/extensions/khr/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ impl Display {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceDisplayPlanePropertiesKHR.html>"]
Expand Down Expand Up @@ -78,10 +75,7 @@ impl Display {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayPlaneSupportedDisplaysKHR.html>"]
Expand All @@ -107,10 +101,7 @@ impl Display {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetDisplayModePropertiesKHR.html>"]
Expand All @@ -131,10 +122,7 @@ impl Display {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCreateDisplayModeKHR.html>"]
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/display_swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ impl DisplaySwapchain {
swapchains.as_mut_ptr(),
);
swapchains.set_len(create_infos.len());
match err_code {
vk::Result::SUCCESS => Ok(swapchains),
_ => Err(err_code),
}
err_code.result_with_success(swapchains)
}

pub fn fp(&self) -> &vk::KhrDisplaySwapchainFn {
Expand Down
11 changes: 4 additions & 7 deletions ash/src/extensions/khr/external_memory_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ impl ExternalMemoryFd {
#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdKHR.html>"]
pub unsafe fn get_memory_fd(&self, create_info: &vk::MemoryGetFdInfoKHR) -> VkResult<i32> {
let mut fd = -1;
let err_code =
self.external_memory_fd_fn
.get_memory_fd_khr(self.handle, create_info, &mut fd);
match err_code {
vk::Result::SUCCESS => Ok(fd),
_ => Err(err_code),
}

self.external_memory_fd_fn
.get_memory_fd_khr(self.handle, create_info, &mut fd)
.result_with_success(fd)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetMemoryFdPropertiesKHR.html>"]
Expand Down
30 changes: 9 additions & 21 deletions ash/src/extensions/khr/pipeline_executable_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ impl PipelineExecutableProperties {
return Err(err_code);
}
let mut v: Vec<_> = vec![Default::default(); count as usize];
let err_code = self
.pipeline_executable_properties_fn
self.pipeline_executable_properties_fn
.get_pipeline_executable_internal_representations_khr(
device,
executable_info,
&mut count,
v.as_mut_ptr(),
);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
)
.result_with_success(v)
}

#[doc = "https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutablePropertiesKHR.html"]
Expand All @@ -84,18 +80,14 @@ impl PipelineExecutableProperties {
return Err(err_code);
}
let mut v: Vec<_> = vec![Default::default(); count as usize];
let err_code = self
.pipeline_executable_properties_fn
self.pipeline_executable_properties_fn
.get_pipeline_executable_properties_khr(
device,
pipeline_info,
&mut count,
v.as_mut_ptr(),
);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
)
.result_with_success(v)
}

#[doc = "https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPipelineExecutableStatisticsKHR.html"]
Expand All @@ -117,18 +109,14 @@ impl PipelineExecutableProperties {
return Err(err_code);
}
let mut v: Vec<_> = vec![Default::default(); count as usize];
let err_code = self
.pipeline_executable_properties_fn
self.pipeline_executable_properties_fn
.get_pipeline_executable_statistics_khr(
device,
executable_info,
&mut count,
v.as_mut_ptr(),
);
match err_code {
vk::Result::SUCCESS => Ok(v),
_ => Err(err_code),
}
)
.result_with_success(v)
}

pub fn fp(&self) -> &vk::KhrPipelineExecutablePropertiesFn {
Expand Down
11 changes: 3 additions & 8 deletions ash/src/extensions/khr/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,21 +283,16 @@ impl RayTracing {
) -> VkResult<Vec<u8>> {
let mut data: Vec<u8> = Vec::with_capacity(data_size);

let err_code = self
.ray_tracing_fn
self.ray_tracing_fn
.get_ray_tracing_capture_replay_shader_group_handles_khr(
device,
pipeline,
first_group,
group_count,
data_size,
data.as_mut_ptr() as *mut _,
);

match err_code {
vk::Result::SUCCESS => Ok(data),
_ => Err(err_code),
}
)
.result_with_success(data)
}

pub unsafe fn cmd_trace_rays_indirect(
Expand Down
29 changes: 8 additions & 21 deletions ash/src/extensions/khr/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ impl Surface {
surface: vk::SurfaceKHR,
) -> VkResult<Vec<vk::PresentModeKHR>> {
let mut count = 0;
let err_code = self
.surface_fn
self.surface_fn
.get_physical_device_surface_present_modes_khr(
physical_device,
surface,
&mut count,
ptr::null_mut(),
);
if err_code != vk::Result::SUCCESS {
return Err(err_code);
}
)
.result()?;
let mut v = Vec::with_capacity(count as usize);
let err_code = self
.surface_fn
Expand All @@ -69,10 +66,7 @@ impl Surface {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceCapabilitiesKHR.html>"]
Expand All @@ -82,17 +76,13 @@ impl Surface {
surface: vk::SurfaceKHR,
) -> VkResult<vk::SurfaceCapabilitiesKHR> {
let mut surface_capabilities = mem::zeroed();
let err_code = self
.surface_fn
self.surface_fn
.get_physical_device_surface_capabilities_khr(
physical_device,
surface,
&mut surface_capabilities,
);
match err_code {
vk::Result::SUCCESS => Ok(surface_capabilities),
_ => Err(err_code),
}
)
.result_with_success(surface_capabilities)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkGetPhysicalDeviceSurfaceFormatsKHR.html>"]
Expand All @@ -118,10 +108,7 @@ impl Surface {
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)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkDestroySurfaceKHR.html>"]
Expand Down
5 changes: 1 addition & 4 deletions ash/src/extensions/khr/swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ impl Swapchain {
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::KhrSwapchainFn {
Expand Down
11 changes: 3 additions & 8 deletions ash/src/extensions/khr/timeline_semaphore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ impl TimelineSemaphore {
semaphore: vk::Semaphore,
) -> VkResult<u64> {
let mut value = 0;
let err_code = self
.timeline_semaphore_fn
.get_semaphore_counter_value_khr(device, semaphore, &mut value);

match err_code {
vk::Result::SUCCESS => Ok(value),
_ => Err(err_code),
}
self.timeline_semaphore_fn
.get_semaphore_counter_value_khr(device, semaphore, &mut value)
.result_with_success(value)
}

#[doc = "<https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkWaitSemaphores.html>"]
Expand Down
Loading