Skip to content

Commit

Permalink
Box ValidationError (#2253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua authored Jul 6, 2023
1 parent 622ec47 commit b74ce40
Show file tree
Hide file tree
Showing 70 changed files with 2,892 additions and 2,759 deletions.
6 changes: 3 additions & 3 deletions vulkano-win/src/raw_window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use raw_window_handle::{
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
};
use std::{any::Any, sync::Arc};
use vulkano::{instance::Instance, swapchain::Surface, VulkanError};
use vulkano::{instance::Instance, swapchain::Surface, Validated, VulkanError};

/// Creates a Vulkan surface from a generic window which implements `HasRawWindowHandle` and thus
/// can reveal the OS-dependent handle.
pub fn create_surface_from_handle(
window: Arc<impl Any + Send + Sync + HasRawWindowHandle + HasRawDisplayHandle>,
instance: Arc<Instance>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
unsafe {
match window.raw_window_handle() {
RawWindowHandle::AndroidNdk(h) => {
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn create_surface_from_handle(
pub unsafe fn create_surface_from_handle_ref(
window: &(impl HasRawWindowHandle + HasRawDisplayHandle),
instance: Arc<Instance>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
unsafe {
match window.raw_window_handle() {
RawWindowHandle::AndroidNdk(h) => {
Expand Down
34 changes: 17 additions & 17 deletions vulkano-win/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use vulkano::{
instance::{Instance, InstanceExtensions},
swapchain::Surface,
VulkanError, VulkanLibrary,
Validated, VulkanError, VulkanLibrary,
};
use winit::{
error::OsError as WindowCreationError,
Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn required_extensions(library: &VulkanLibrary) -> InstanceExtensions {
pub fn create_surface_from_winit(
window: Arc<Window>,
instance: Arc<Instance>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
unsafe { winit_to_surface(instance, window) }
}

Expand Down Expand Up @@ -65,17 +65,17 @@ impl<E> VkSurfaceBuild<E> for WindowBuilder {
#[derive(Debug)]
pub enum CreationError {
/// Error when creating the surface.
VulkanError(VulkanError),
Surface(Validated<VulkanError>),

/// Error when creating the window.
WindowCreationError(WindowCreationError),
Window(WindowCreationError),
}

impl Error for CreationError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
CreationError::VulkanError(err) => Some(err),
CreationError::WindowCreationError(err) => Some(err),
CreationError::Surface(err) => Some(err),
CreationError::Window(err) => Some(err),
}
}
}
Expand All @@ -86,30 +86,30 @@ impl Display for CreationError {
f,
"{}",
match self {
CreationError::VulkanError(_) => "error while creating the surface",
CreationError::WindowCreationError(_) => "error while creating the window",
CreationError::Surface(_) => "error while creating the surface",
CreationError::Window(_) => "error while creating the window",
}
)
}
}

impl From<VulkanError> for CreationError {
fn from(err: VulkanError) -> CreationError {
CreationError::VulkanError(err)
impl From<Validated<VulkanError>> for CreationError {
fn from(err: Validated<VulkanError>) -> CreationError {
CreationError::Surface(err)
}
}

impl From<WindowCreationError> for CreationError {
fn from(err: WindowCreationError) -> CreationError {
CreationError::WindowCreationError(err)
CreationError::Window(err)
}
}

#[cfg(target_os = "android")]
unsafe fn winit_to_surface(
instance: Arc<Instance>,
window: Arc<Window>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
use raw_window_handle::HasRawWindowHandle;
use raw_window_handle::RawWindowHandle::AndroidNdk;
if let AndroidNdk(handle) = window.raw_window_handle() {
Expand All @@ -128,7 +128,7 @@ unsafe fn winit_to_surface(
unsafe fn winit_to_surface(
instance: Arc<Instance>,
window: Arc<Window>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
use winit::platform::{wayland::WindowExtWayland, x11::WindowExtX11};

match (window.wayland_display(), window.wayland_surface()) {
Expand Down Expand Up @@ -194,7 +194,7 @@ pub(crate) unsafe fn get_metal_layer_macos(view: *mut std::ffi::c_void) -> *mut
unsafe fn winit_to_surface(
instance: Arc<Instance>,
window: Arc<Window>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
use winit::platform::macos::WindowExtMacOS;
let layer = get_metal_layer_macos(window.ns_view());
Surface::from_mac_os(instance, layer as *const (), Some(window))
Expand Down Expand Up @@ -225,7 +225,7 @@ pub(crate) unsafe fn get_metal_layer_ios(view: *mut std::ffi::c_void) -> IOSMeta
unsafe fn winit_to_surface(
instance: Arc<Instance>,
window: Arc<Window>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
use winit::platform::ios::WindowExtIOS;
let layer = get_metal_layer_ios(window.ui_view());
Surface::from_ios(instance, layer, Some(window))
Expand All @@ -235,7 +235,7 @@ unsafe fn winit_to_surface(
unsafe fn winit_to_surface(
instance: Arc<Instance>,
window: Arc<Window>,
) -> Result<Arc<Surface>, VulkanError> {
) -> Result<Arc<Surface>, Validated<VulkanError>> {
use winit::platform::windows::WindowExtWindows;

Surface::from_win32(
Expand Down
6 changes: 3 additions & 3 deletions vulkano/autogen/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ fn errors_output(members: &[ErrorsMember]) -> TokenStream {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(i32)]
#[non_exhaustive]
pub enum RuntimeError {
pub enum VulkanError {
#(#enum_items)*
Unnamed(ash::vk::Result),
}

impl From<ash::vk::Result> for RuntimeError {
fn from(val: ash::vk::Result) -> RuntimeError {
impl From<ash::vk::Result> for VulkanError {
fn from(val: ash::vk::Result) -> VulkanError {
match val {
#(#try_from_items)*
x => Self::Unnamed(x),
Expand Down
20 changes: 10 additions & 10 deletions vulkano/autogen/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {

quote! {
if !(#(#condition_items)||*) {
return Err(crate::ValidationError {
return Err(Box::new(crate::ValidationError {
problem: #problem.into(),
requires_one_of: crate::RequiresOneOf(&[
#(#requires_one_of_items)*
]),
..Default::default()
});
}));
}
}
})
Expand All @@ -180,10 +180,10 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
quote! {
if self.#name {
if !supported.#name {
return Err(crate::ValidationError {
return Err(Box::new(crate::ValidationError {
problem: #problem.into(),
..Default::default()
});
}));
}

#(#dependency_check_items)*
Expand Down Expand Up @@ -277,7 +277,7 @@ fn device_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
supported: &DeviceExtensions,
api_version: crate::Version,
instance_extensions: &crate::instance::InstanceExtensions,
) -> Result<(), crate::ValidationError> {
) -> Result<(), Box<crate::ValidationError>> {
#(#check_requirements_items)*
Ok(())
}
Expand Down Expand Up @@ -317,15 +317,15 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {

quote! {
if !(api_version >= crate::Version::#version) {
return Err(crate::ValidationError {
return Err(Box::new(crate::ValidationError {
problem: #problem.into(),
requires_one_of: crate::RequiresOneOf(&[
crate::RequiresAllOf(&[
crate::Requires::APIVersion(crate::Version::#version),
]),
]),
..Default::default()
});
}));
}
}
})
Expand All @@ -339,10 +339,10 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
quote! {
if self.#name {
if !supported.#name {
return Err(crate::ValidationError {
return Err(Box::new(crate::ValidationError {
problem: #problem.into(),
..Default::default()
});
}));
}

#(#dependency_check_items)*
Expand Down Expand Up @@ -435,7 +435,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream {
&self,
supported: &InstanceExtensions,
api_version: crate::Version,
) -> Result<(), crate::ValidationError> {
) -> Result<(), Box<crate::ValidationError>> {
#(#check_requirements_items)*
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions vulkano/autogen/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream {
let name_string = name.to_string();
quote! {
if self.#name && !supported.#name {
return Err(crate::ValidationError {
return Err(Box::new(crate::ValidationError {
problem: format!(
"contains `{}`, but this feature is not supported \
by the physical device",
#name_string,
)
.into(),
..Default::default()
});
}));
}
}
});
Expand Down Expand Up @@ -291,7 +291,7 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream {
pub(super) fn check_requirements(
&self,
supported: &Features,
) -> Result<(), crate::ValidationError> {
) -> Result<(), Box<crate::ValidationError>> {
#(#check_requirements_items)*
Ok(())
}
Expand Down
Loading

0 comments on commit b74ce40

Please sign in to comment.