From b74ce40b2c0633514768af923f961b62fb0aa808 Mon Sep 17 00:00:00 2001 From: Rua Date: Thu, 6 Jul 2023 12:43:45 +0200 Subject: [PATCH] Box `ValidationError` (#2253) --- vulkano-win/src/raw_window_handle.rs | 6 +- vulkano-win/src/winit.rs | 34 +- vulkano/autogen/errors.rs | 6 +- vulkano/autogen/extensions.rs | 20 +- vulkano/autogen/features.rs | 6 +- vulkano/src/acceleration_structure.rs | 88 ++-- vulkano/src/buffer/allocator.rs | 4 +- vulkano/src/buffer/mod.rs | 78 +-- vulkano/src/buffer/subbuffer.rs | 2 +- vulkano/src/buffer/sys.rs | 99 ++-- vulkano/src/buffer/view.rs | 52 +- .../commands/acceleration_structure.rs | 324 ++++++------ .../src/command_buffer/commands/bind_push.rs | 22 +- .../src/command_buffer/commands/pipeline.rs | 2 +- vulkano/src/command_buffer/pool.rs | 18 +- vulkano/src/command_buffer/sys.rs | 6 +- vulkano/src/deferred.rs | 28 +- vulkano/src/descriptor_set/allocator.rs | 36 +- vulkano/src/descriptor_set/layout.rs | 86 ++-- vulkano/src/descriptor_set/mod.rs | 2 +- vulkano/src/descriptor_set/persistent.rs | 6 +- vulkano/src/descriptor_set/pool.rs | 52 +- vulkano/src/descriptor_set/update.rs | 250 +++++----- vulkano/src/device/mod.rs | 178 +++---- vulkano/src/device/physical.rs | 250 +++++----- vulkano/src/device/queue.rs | 50 +- vulkano/src/image/mod.rs | 140 +++--- vulkano/src/image/sampler/mod.rs | 200 ++++---- vulkano/src/image/sampler/ycbcr.rs | 125 ++--- vulkano/src/image/sys.rs | 440 +++++++++-------- vulkano/src/image/view.rs | 160 +++--- vulkano/src/instance/debug.rs | 26 +- vulkano/src/instance/mod.rs | 63 +-- vulkano/src/lib.rs | 331 ++++++------- vulkano/src/library.rs | 36 +- vulkano/src/memory/allocator/mod.rs | 34 +- vulkano/src/memory/allocator/suballocator.rs | 12 +- vulkano/src/memory/device_memory.rs | 163 +++--- vulkano/src/pipeline/cache.rs | 30 +- vulkano/src/pipeline/compute.rs | 16 +- vulkano/src/pipeline/graphics/color_blend.rs | 50 +- .../src/pipeline/graphics/depth_stencil.rs | 62 +-- .../pipeline/graphics/discard_rectangle.rs | 6 +- .../src/pipeline/graphics/input_assembly.rs | 30 +- vulkano/src/pipeline/graphics/mod.rs | 209 ++++---- vulkano/src/pipeline/graphics/multisample.rs | 14 +- .../src/pipeline/graphics/rasterization.rs | 82 ++-- vulkano/src/pipeline/graphics/subpass.rs | 34 +- vulkano/src/pipeline/graphics/tessellation.rs | 18 +- .../pipeline/graphics/vertex_input/buffers.rs | 5 +- .../graphics/vertex_input/definition.rs | 45 +- .../src/pipeline/graphics/vertex_input/mod.rs | 58 +-- vulkano/src/pipeline/graphics/viewport.rs | 96 ++-- vulkano/src/pipeline/layout.rs | 76 +-- vulkano/src/pipeline/mod.rs | 22 +- vulkano/src/query.rs | 22 +- vulkano/src/render_pass/create.rs | 10 +- vulkano/src/render_pass/framebuffer.rs | 92 ++-- vulkano/src/render_pass/mod.rs | 464 +++++++++--------- vulkano/src/shader/mod.rs | 8 +- vulkano/src/swapchain/acquire_present.rs | 38 +- vulkano/src/swapchain/display.rs | 18 +- vulkano/src/swapchain/mod.rs | 182 +++---- vulkano/src/swapchain/surface.rs | 281 ++++++----- vulkano/src/sync/event.rs | 18 +- vulkano/src/sync/fence.rs | 65 +-- vulkano/src/sync/future/mod.rs | 16 +- vulkano/src/sync/mod.rs | 4 +- vulkano/src/sync/pipeline.rs | 114 ++--- vulkano/src/sync/semaphore.rs | 55 ++- 70 files changed, 2904 insertions(+), 2771 deletions(-) diff --git a/vulkano-win/src/raw_window_handle.rs b/vulkano-win/src/raw_window_handle.rs index 396b49ee..7412ad5e 100644 --- a/vulkano-win/src/raw_window_handle.rs +++ b/vulkano-win/src/raw_window_handle.rs @@ -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, instance: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { unsafe { match window.raw_window_handle() { RawWindowHandle::AndroidNdk(h) => { @@ -82,7 +82,7 @@ pub fn create_surface_from_handle( pub unsafe fn create_surface_from_handle_ref( window: &(impl HasRawWindowHandle + HasRawDisplayHandle), instance: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { unsafe { match window.raw_window_handle() { RawWindowHandle::AndroidNdk(h) => { diff --git a/vulkano-win/src/winit.rs b/vulkano-win/src/winit.rs index 20ffb45f..ef8e180a 100644 --- a/vulkano-win/src/winit.rs +++ b/vulkano-win/src/winit.rs @@ -6,7 +6,7 @@ use std::{ use vulkano::{ instance::{Instance, InstanceExtensions}, swapchain::Surface, - VulkanError, VulkanLibrary, + Validated, VulkanError, VulkanLibrary, }; use winit::{ error::OsError as WindowCreationError, @@ -37,7 +37,7 @@ pub fn required_extensions(library: &VulkanLibrary) -> InstanceExtensions { pub fn create_surface_from_winit( window: Arc, instance: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { unsafe { winit_to_surface(instance, window) } } @@ -65,17 +65,17 @@ impl VkSurfaceBuild for WindowBuilder { #[derive(Debug)] pub enum CreationError { /// Error when creating the surface. - VulkanError(VulkanError), + Surface(Validated), /// 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), } } } @@ -86,22 +86,22 @@ 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 for CreationError { - fn from(err: VulkanError) -> CreationError { - CreationError::VulkanError(err) +impl From> for CreationError { + fn from(err: Validated) -> CreationError { + CreationError::Surface(err) } } impl From for CreationError { fn from(err: WindowCreationError) -> CreationError { - CreationError::WindowCreationError(err) + CreationError::Window(err) } } @@ -109,7 +109,7 @@ impl From for CreationError { unsafe fn winit_to_surface( instance: Arc, window: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { use raw_window_handle::HasRawWindowHandle; use raw_window_handle::RawWindowHandle::AndroidNdk; if let AndroidNdk(handle) = window.raw_window_handle() { @@ -128,7 +128,7 @@ unsafe fn winit_to_surface( unsafe fn winit_to_surface( instance: Arc, window: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { use winit::platform::{wayland::WindowExtWayland, x11::WindowExtX11}; match (window.wayland_display(), window.wayland_surface()) { @@ -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, window: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { use winit::platform::macos::WindowExtMacOS; let layer = get_metal_layer_macos(window.ns_view()); Surface::from_mac_os(instance, layer as *const (), Some(window)) @@ -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, window: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { use winit::platform::ios::WindowExtIOS; let layer = get_metal_layer_ios(window.ui_view()); Surface::from_ios(instance, layer, Some(window)) @@ -235,7 +235,7 @@ unsafe fn winit_to_surface( unsafe fn winit_to_surface( instance: Arc, window: Arc, -) -> Result, VulkanError> { +) -> Result, Validated> { use winit::platform::windows::WindowExtWindows; Surface::from_win32( diff --git a/vulkano/autogen/errors.rs b/vulkano/autogen/errors.rs index a5d9fb71..920b9b3c 100644 --- a/vulkano/autogen/errors.rs +++ b/vulkano/autogen/errors.rs @@ -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 for RuntimeError { - fn from(val: ash::vk::Result) -> RuntimeError { + impl From for VulkanError { + fn from(val: ash::vk::Result) -> VulkanError { match val { #(#try_from_items)* x => Self::Unnamed(x), diff --git a/vulkano/autogen/extensions.rs b/vulkano/autogen/extensions.rs index 55b0bb9e..31630571 100644 --- a/vulkano/autogen/extensions.rs +++ b/vulkano/autogen/extensions.rs @@ -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() - }); + })); } } }) @@ -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)* @@ -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> { #(#check_requirements_items)* Ok(()) } @@ -317,7 +317,7 @@ 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(&[ @@ -325,7 +325,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream { ]), ]), ..Default::default() - }); + })); } } }) @@ -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)* @@ -435,7 +435,7 @@ fn instance_extensions_output(members: &[ExtensionsMember]) -> TokenStream { &self, supported: &InstanceExtensions, api_version: crate::Version, - ) -> Result<(), crate::ValidationError> { + ) -> Result<(), Box> { #(#check_requirements_items)* Ok(()) } diff --git a/vulkano/autogen/features.rs b/vulkano/autogen/features.rs index dde2ef44..2fe39cca 100644 --- a/vulkano/autogen/features.rs +++ b/vulkano/autogen/features.rs @@ -101,7 +101,7 @@ 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", @@ -109,7 +109,7 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream { ) .into(), ..Default::default() - }); + })); } } }); @@ -291,7 +291,7 @@ fn features_output(members: &[FeaturesMember]) -> TokenStream { pub(super) fn check_requirements( &self, supported: &Features, - ) -> Result<(), crate::ValidationError> { + ) -> Result<(), Box> { #(#check_requirements_items)* Ok(()) } diff --git a/vulkano/src/acceleration_structure.rs b/vulkano/src/acceleration_structure.rs index 8b70cf66..bc60d9ae 100644 --- a/vulkano/src/acceleration_structure.rs +++ b/vulkano/src/acceleration_structure.rs @@ -97,8 +97,8 @@ use crate::{ format::{Format, FormatFeatures}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_enum}, - DeviceSize, NonZeroDeviceSize, Packed24_8, Requires, RequiresAllOf, RequiresOneOf, - RuntimeError, ValidationError, VulkanError, VulkanObject, + DeviceSize, NonZeroDeviceSize, Packed24_8, Requires, RequiresAllOf, RequiresOneOf, Validated, + ValidationError, VulkanError, VulkanObject, }; use bytemuck::{Pod, Zeroable}; use std::{fmt::Debug, hash::Hash, mem::MaybeUninit, num::NonZeroU64, ptr, sync::Arc}; @@ -130,7 +130,7 @@ impl AccelerationStructure { pub unsafe fn new( device: Arc, create_info: AccelerationStructureCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; Ok(Self::new_unchecked(device, create_info)?) @@ -139,24 +139,24 @@ impl AccelerationStructure { fn validate_new( device: &Device, create_info: &AccelerationStructureCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !device.enabled_extensions().khr_acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_acceleration_structure", )])]), ..Default::default() - }); + })); } if !device.enabled_features().acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "acceleration_structure", )])]), vuids: &["VUID-vkCreateAccelerationStructureKHR-accelerationStructure-03611"], ..Default::default() - }); + })); } // VUID-vkCreateAccelerationStructureKHR-pCreateInfo-parameter @@ -171,7 +171,7 @@ impl AccelerationStructure { pub unsafe fn new_unchecked( device: Arc, create_info: AccelerationStructureCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &AccelerationStructureCreateInfo { create_flags, ref buffer, @@ -200,7 +200,7 @@ impl AccelerationStructure { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -370,7 +370,7 @@ impl AccelerationStructureCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { create_flags, ref buffer, @@ -397,26 +397,26 @@ impl AccelerationStructureCreateInfo { .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_STORAGE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "buffer".into(), problem: "the buffer was not created with the `ACCELERATION_STRUCTURE_STORAGE` \ usage" .into(), vuids: &["VUID-VkAccelerationStructureCreateInfoKHR-buffer-03614"], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureCreateInfoKHR-offset-03616 // Ensured by the definition of `Subbuffer`. if buffer.offset() % 256 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "buffer".into(), problem: "the offset of the buffer is not a multiple of 256".into(), vuids: &["VUID-VkAccelerationStructureCreateInfoKHR-offset-03734"], ..Default::default() - }); + })); } Ok(()) @@ -503,7 +503,7 @@ impl AccelerationStructureBuildGeometryInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref mode, @@ -537,12 +537,12 @@ impl AccelerationStructureBuildGeometryInfo { } if geometries.len() as u64 > max_geometry_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "geometries".into(), problem: "the length exceeds the `max_geometry_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03793"], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03795 @@ -558,12 +558,12 @@ impl AccelerationStructureBuildGeometryInfo { } if geometries.len() as u64 > max_geometry_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "geometries".into(), problem: "the length exceeds the `max_geometry_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03793"], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03794 @@ -589,14 +589,14 @@ impl AccelerationStructureBuildGeometryInfo { BuildAccelerationStructureFlags::PREFER_FAST_TRACE | BuildAccelerationStructureFlags::PREFER_FAST_BUILD, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "flags".into(), problem: "contains both `BuildAccelerationStructureFlags::PREFER_FAST_TRACE` and \ `BuildAccelerationStructureFlags::PREFER_FAST_BUILD`" .into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-03796"], ..Default::default() - }); + })); } Ok(()) @@ -997,7 +997,7 @@ impl AccelerationStructureGeometryTrianglesData { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, vertex_format, @@ -1034,14 +1034,14 @@ impl AccelerationStructureGeometryTrianglesData { .buffer_features .intersects(FormatFeatures::ACCELERATION_STRUCTURE_VERTEX_BUFFER) } { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "vertex_format".into(), problem: "format features do not contain \ `FormatFeature::ACCELERATION_STRUCTURE_VERTEX_BUFFER`" .into(), vuids: &["VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexFormat-03797"], ..Default::default() - }); + })); } let smallest_component_bits = vertex_format @@ -1053,25 +1053,25 @@ impl AccelerationStructureGeometryTrianglesData { let smallest_component_bytes = (smallest_component_bits + 7) & !7; if vertex_stride % smallest_component_bytes != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`vertex_stride` is not a multiple of the byte size of the \ smallest component of `vertex_format`" .into(), vuids: &["VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexStride-03735"], ..Default::default() - }); + })); } if let Some(index_data) = index_data.as_ref() { if !matches!(index_data, IndexBuffer::U16(_) | IndexBuffer::U32(_)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "index_data".into(), problem: "is not `IndexBuffer::U16` or `IndexBuffer::U32`".into(), vuids: &[ "VUID-VkAccelerationStructureGeometryTrianglesDataKHR-indexType-03798", ], ..Default::default() - }); + })); } } @@ -1119,7 +1119,7 @@ impl AccelerationStructureGeometryAabbsData { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, data: _, @@ -1136,12 +1136,12 @@ impl AccelerationStructureGeometryAabbsData { })?; if stride % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stride".into(), problem: "is not a multiple of 8".into(), vuids: &["VUID-VkAccelerationStructureGeometryAabbsDataKHR-stride-03545"], ..Default::default() - }); + })); } Ok(()) @@ -1192,7 +1192,7 @@ impl AccelerationStructureGeometryInstancesData { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, data: _, @@ -1390,7 +1390,7 @@ impl CopyAccelerationStructureInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { ref src, ref dst, @@ -1413,22 +1413,22 @@ impl CopyAccelerationStructureInfo { mode, CopyAccelerationStructureMode::Compact | CopyAccelerationStructureMode::Clone ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mode".into(), problem: "is not `CopyAccelerationStructureMode::Compact` or \ `CopyAccelerationStructureMode::Clone`" .into(), vuids: &["VUID-VkCopyAccelerationStructureInfoKHR-mode-03410"], ..Default::default() - }); + })); } if src.buffer() == dst.buffer() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src` and `dst` share the same buffer".into(), vuids: &["VUID-VkCopyAccelerationStructureInfoKHR-dst-07791"], ..Default::default() - }); + })); } // VUID-VkCopyAccelerationStructureInfoKHR-src-04963 @@ -1474,7 +1474,7 @@ impl CopyAccelerationStructureToMemoryInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { ref src, ref dst, @@ -1493,12 +1493,12 @@ impl CopyAccelerationStructureToMemoryInfo { })?; if !matches!(mode, CopyAccelerationStructureMode::Serialize) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mode".into(), problem: "is not `CopyAccelerationStructureMode::Serialize`".into(), vuids: &["VUID-VkCopyAccelerationStructureToMemoryInfoKHR-mode-03412"], ..Default::default() - }); + })); } // VUID-VkCopyAccelerationStructureToMemoryInfoKHR-src-04959 @@ -1544,7 +1544,7 @@ impl CopyMemoryToAccelerationStructureInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { ref src, ref dst, @@ -1563,12 +1563,12 @@ impl CopyMemoryToAccelerationStructureInfo { })?; if !matches!(mode, CopyAccelerationStructureMode::Deserialize) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mode".into(), problem: "is not `CopyAccelerationStructureMode::Deserialize`".into(), vuids: &["VUID-VkCopyMemoryToAccelerationStructureInfoKHR-mode-03413"], ..Default::default() - }); + })); } // VUID-VkCopyMemoryToAccelerationStructureInfoKHR-src-04960 diff --git a/vulkano/src/buffer/allocator.rs b/vulkano/src/buffer/allocator.rs index 3c3fca02..be5fe87a 100644 --- a/vulkano/src/buffer/allocator.rs +++ b/vulkano/src/buffer/allocator.rs @@ -22,7 +22,7 @@ use crate::{ }, DeviceAlignment, }, - DeviceSize, NonZeroDeviceSize, + DeviceSize, NonZeroDeviceSize, Validated, }; use crossbeam_queue::ArrayQueue; use std::{ @@ -355,7 +355,7 @@ where DeviceLayout::from_size_alignment(self.arena_size, 1).unwrap(), ) .map_err(|err| match err { - BufferAllocateError::AllocateMemory(err) => err, + Validated::Error(BufferAllocateError::AllocateMemory(err)) => err, // We don't use sparse-binding, concurrent sharing or external memory, therefore the // other errors can't happen. _ => unreachable!(), diff --git a/vulkano/src/buffer/mod.rs b/vulkano/src/buffer/mod.rs index 58beb06d..8fca0554 100644 --- a/vulkano/src/buffer/mod.rs +++ b/vulkano/src/buffer/mod.rs @@ -116,7 +116,7 @@ use crate::{ }, range_map::RangeMap, sync::{future::AccessError, AccessConflict, CurrentAccess, Sharing}, - DeviceSize, NonZeroDeviceSize, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, + DeviceSize, NonZeroDeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use parking_lot::{Mutex, MutexGuard}; @@ -262,14 +262,14 @@ impl Buffer { /// - Panics if the chosen memory type is not host-visible. pub fn from_data( allocator: &(impl MemoryAllocator + ?Sized), - buffer_info: BufferCreateInfo, + create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, data: T, - ) -> Result, BufferAllocateError> + ) -> Result, Validated> where T: BufferContents, { - let buffer = Buffer::new_sized(allocator, buffer_info, allocation_info)?; + let buffer = Buffer::new_sized(allocator, create_info, allocation_info)?; { let mut write_guard = buffer @@ -295,10 +295,10 @@ impl Buffer { /// - Panics if `iter` is empty. pub fn from_iter( allocator: &(impl MemoryAllocator + ?Sized), - buffer_info: BufferCreateInfo, + create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, iter: I, - ) -> Result, BufferAllocateError> + ) -> Result, Validated> where T: BufferContents, I: IntoIterator, @@ -307,7 +307,7 @@ impl Buffer { let iter = iter.into_iter(); let buffer = Buffer::new_slice( allocator, - buffer_info, + create_info, allocation_info, iter.len().try_into().unwrap(), )?; @@ -333,16 +333,16 @@ impl Buffer { /// - Panics if `buffer_info.size` is not zero. pub fn new_sized( allocator: &(impl MemoryAllocator + ?Sized), - buffer_info: BufferCreateInfo, + create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, - ) -> Result, BufferAllocateError> + ) -> Result, Validated> where T: BufferContents, { let layout = T::LAYOUT.unwrap_sized(); let buffer = Subbuffer::new(Buffer::new( allocator, - buffer_info, + create_info, allocation_info, layout, )?); @@ -359,14 +359,14 @@ impl Buffer { /// - Panics if `len` is zero. pub fn new_slice( allocator: &(impl MemoryAllocator + ?Sized), - buffer_info: BufferCreateInfo, + create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, len: DeviceSize, - ) -> Result, BufferAllocateError> + ) -> Result, Validated> where T: BufferContents, { - Buffer::new_unsized(allocator, buffer_info, allocation_info, len) + Buffer::new_unsized(allocator, create_info, allocation_info, len) } /// Creates a new uninitialized `Buffer` for unsized data. Returns a [`Subbuffer`] spanning the @@ -378,10 +378,10 @@ impl Buffer { /// - Panics if `len` is zero. pub fn new_unsized( allocator: &(impl MemoryAllocator + ?Sized), - buffer_info: BufferCreateInfo, + create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, len: DeviceSize, - ) -> Result, BufferAllocateError> + ) -> Result, Validated> where T: BufferContents + ?Sized, { @@ -389,7 +389,7 @@ impl Buffer { let layout = T::LAYOUT.layout_for_len(len).unwrap(); let buffer = Subbuffer::new(Buffer::new( allocator, - buffer_info, + create_info, allocation_info, layout, )?); @@ -405,24 +405,27 @@ impl Buffer { /// - Panics if `layout.alignment()` is greater than 64. pub fn new( allocator: &(impl MemoryAllocator + ?Sized), - mut buffer_info: BufferCreateInfo, + mut create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, layout: DeviceLayout, - ) -> Result, BufferAllocateError> { + ) -> Result, Validated> { assert!(layout.alignment().as_devicesize() <= 64); // TODO: Enable once sparse binding materializes // assert!(!allocate_info.flags.contains(BufferCreateFlags::SPARSE_BINDING)); assert!( - buffer_info.size == 0, + create_info.size == 0, "`Buffer::new*` functions set the `buffer_info.size` field themselves, you should not \ set it yourself", ); - buffer_info.size = layout.size(); + create_info.size = layout.size(); - let raw_buffer = RawBuffer::new(allocator.device().clone(), buffer_info) - .map_err(BufferAllocateError::CreateBuffer)?; + let raw_buffer = + RawBuffer::new(allocator.device().clone(), create_info).map_err(|err| match err { + Validated::Error(err) => Validated::Error(BufferAllocateError::CreateBuffer(err)), + Validated::ValidationError(err) => err.into(), + })?; let mut requirements = *raw_buffer.memory_requirements(); requirements.layout = requirements.layout.align_to(layout.alignment()).unwrap(); @@ -448,7 +451,7 @@ impl Buffer { unsafe { raw_buffer.bind_memory_unchecked(allocation) } .map(Arc::new) - .map_err(|(err, _, _)| BufferAllocateError::BindMemory(err)) + .map_err(|(err, _, _)| BufferAllocateError::BindMemory(err).into()) } fn from_raw(inner: RawBuffer, memory: BufferMemory) -> Self { @@ -505,32 +508,32 @@ impl Buffer { /// Returns the device address for this buffer. // TODO: Caching? - pub fn device_address(&self) -> Result { + pub fn device_address(&self) -> Result> { self.validate_device_address()?; unsafe { Ok(self.device_address_unchecked()) } } - fn validate_device_address(&self) -> Result<(), ValidationError> { + fn validate_device_address(&self) -> Result<(), Box> { let device = self.device(); if !device.enabled_features().buffer_device_address { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "buffer_device_address", )])]), vuids: &["VUID-vkGetBufferDeviceAddress-bufferDeviceAddress-03324"], ..Default::default() - }); + })); } if !self.usage().intersects(BufferUsage::SHADER_DEVICE_ADDRESS) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self.usage()".into(), problem: "does not contain `BufferUsage::SHADER_DEVICE_ADDRESS`".into(), vuids: &["VUID-VkBufferDeviceAddressInfo-buffer-02601"], ..Default::default() - }); + })); } Ok(()) @@ -601,7 +604,7 @@ impl Hash for Buffer { pub enum BufferAllocateError { CreateBuffer(VulkanError), AllocateMemory(MemoryAllocatorError), - BindMemory(RuntimeError), + BindMemory(VulkanError), } impl Error for BufferAllocateError { @@ -624,6 +627,12 @@ impl Display for BufferAllocateError { } } +impl From for Validated { + fn from(err: BufferAllocateError) -> Self { + Self::Error(err) + } +} + /// The current state of a buffer. #[derive(Debug)] pub(crate) struct BufferState { @@ -915,7 +924,10 @@ impl ExternalBufferInfo { } } - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { handle_type, usage, @@ -932,12 +944,12 @@ impl ExternalBufferInfo { })?; if usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "is empty".into(), vuids: &["VUID-VkPhysicalDeviceExternalBufferInfo-usage-requiredbitmask"], ..Default::default() - }); + })); } handle_type diff --git a/vulkano/src/buffer/subbuffer.rs b/vulkano/src/buffer/subbuffer.rs index 436bb9ec..00224f86 100644 --- a/vulkano/src/buffer/subbuffer.rs +++ b/vulkano/src/buffer/subbuffer.rs @@ -134,7 +134,7 @@ impl Subbuffer { } /// Returns the device address for this subbuffer. - pub fn device_address(&self) -> Result { + pub fn device_address(&self) -> Result> { self.buffer().device_address().map(|ptr| { // SAFETY: The original address came from the Vulkan implementation, and allocation // sizes are guaranteed to not exceed `DeviceLayout::MAX_SIZE`, so the offset better be diff --git a/vulkano/src/buffer/sys.rs b/vulkano/src/buffer/sys.rs index 89d600c5..c5482fde 100644 --- a/vulkano/src/buffer/sys.rs +++ b/vulkano/src/buffer/sys.rs @@ -24,7 +24,7 @@ use crate::{ MemoryPropertyFlags, MemoryRequirements, }, sync::Sharing, - DeviceSize, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + DeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use smallvec::SmallVec; @@ -60,7 +60,10 @@ impl RawBuffer { /// - Panics if `create_info.size` is zero. /// - Panics if `create_info.usage` is empty. #[inline] - pub fn new(device: Arc, create_info: BufferCreateInfo) -> Result { + pub fn new( + device: Arc, + create_info: BufferCreateInfo, + ) -> Result> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -69,7 +72,7 @@ impl RawBuffer { fn validate_new( device: &Device, create_info: &BufferCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { create_info .validate(device) .map_err(|err| err.add_context("create_info"))?; @@ -81,7 +84,7 @@ impl RawBuffer { pub unsafe fn new_unchecked( device: Arc, create_info: BufferCreateInfo, - ) -> Result { + ) -> Result { let &BufferCreateInfo { flags, ref sharing, @@ -133,7 +136,7 @@ impl RawBuffer { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -274,7 +277,7 @@ impl RawBuffer { pub fn bind_memory( self, allocation: MemoryAlloc, - ) -> Result { + ) -> Result, RawBuffer, MemoryAlloc)> { if let Err(err) = self.validate_bind_memory(&allocation) { return Err((err.into(), self, allocation)); } @@ -283,7 +286,7 @@ impl RawBuffer { .map_err(|(err, buffer, allocation)| (err.into(), buffer, allocation)) } - fn validate_bind_memory(&self, allocation: &MemoryAlloc) -> Result<(), ValidationError> { + fn validate_bind_memory(&self, allocation: &MemoryAlloc) -> Result<(), Box> { assert_ne!(allocation.allocation_type(), AllocationType::NonLinear); let memory_requirements = &self.memory_requirements; @@ -309,58 +312,58 @@ impl RawBuffer { // Assume that `allocation` was created correctly. if memory_requirements.memory_type_bits & (1 << memory.memory_type_index()) == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.device_memory().memory_type_index()` is not a bit set in \ `self.memory_requirements().memory_type_bits`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-memory-01035"], ..Default::default() - }); + })); } if !is_aligned(memory_offset, memory_requirements.layout.alignment()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.offset()` is not aligned according to \ `self.memory_requirements().layout.alignment()`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-memoryOffset-01036"], ..Default::default() - }); + })); } if allocation.size() < memory_requirements.layout.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.size()` is less than \ `self.memory_requirements().layout.size()`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-size-01037"], ..Default::default() - }); + })); } if let Some(dedicated_to) = memory.dedicated_to() { match dedicated_to { DedicatedTo::Buffer(id) if id == self.id => {} _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.device_memory()` is a dedicated allocation, but \ it is not dedicated to this buffer" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-memory-01508"], ..Default::default() - }); + })); } } debug_assert!(memory_offset == 0); // This should be ensured by the allocator } else { if memory_requirements.requires_dedicated_allocation { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.memory_requirements().requires_dedicated_allocation` is \ `true`, but `allocation.device_memory()` is not a dedicated allocation" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-buffer-01444"], ..Default::default() - }); + })); } } @@ -368,13 +371,13 @@ impl RawBuffer { .property_flags .intersects(MemoryPropertyFlags::PROTECTED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the `property_flags` of the memory type of \ `allocation.device_memory()` contains `MemoryPropertyFlags::PROTECTED`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-None-01899"], ..Default::default() - }); + })); } if !memory.export_handle_types().is_empty() @@ -382,26 +385,26 @@ impl RawBuffer { .external_memory_handle_types .intersects(memory.export_handle_types()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.device_memory().export_handle_types()` is not empty, but \ it does not share at least one memory type with \ `self.external_memory_handle_types()`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-memory-02726"], ..Default::default() - }); + })); } if let Some(handle_type) = memory.imported_handle_type() { if !self.external_memory_handle_types.contains_enum(handle_type) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation.device_memory()` is imported, but \ `self.external_memory_handle_types()` does not contain the imported \ handle type" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-memory-02985"], ..Default::default() - }); + })); } } @@ -411,14 +414,14 @@ impl RawBuffer { .flags() .intersects(MemoryAllocateFlags::DEVICE_ADDRESS) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.usage()` contains `BufferUsage::SHADER_DEVICE_ADDRESS`, but \ `allocation.device_memory().flags()` does not contain \ `MemoryAllocateFlags::DEVICE_ADDRESS`" .into(), vuids: &["VUID-VkBindBufferMemoryInfo-bufferDeviceAddress-03339"], ..Default::default() - }); + })); } Ok(()) @@ -428,7 +431,7 @@ impl RawBuffer { pub unsafe fn bind_memory_unchecked( self, allocation: MemoryAlloc, - ) -> Result { + ) -> Result { let memory = allocation.device_memory(); let memory_offset = allocation.offset(); @@ -468,7 +471,7 @@ impl RawBuffer { .result(); if let Err(err) = result { - return Err((RuntimeError::from(err), self, allocation)); + return Err((VulkanError::from(err), self, allocation)); } Ok(Buffer::from_raw(self, BufferMemory::Normal(allocation))) @@ -594,7 +597,7 @@ impl Default for BufferCreateInfo { } impl BufferCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref sharing, @@ -621,56 +624,56 @@ impl BufferCreateInfo { })?; if usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "is empty".into(), vuids: &["VUID-VkBufferCreateInfo-usage-requiredbitmask"], ..Default::default() - }); + })); } if size == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "size".into(), problem: "is zero".into(), vuids: &["VUID-VkBufferCreateInfo-size-00912"], ..Default::default() - }); + })); } /* Enable when sparse binding is properly handled if let Some(sparse_level) = sparse { if !device.enabled_features().sparse_binding { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sparse".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sparse_binding", )])]), vuids: &["VUID-VkBufferCreateInfo-flags-00915"], - }); + })); } if sparse_level.sparse_residency && !device.enabled_features().sparse_residency_buffer { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sparse".into(), problem: "contains `BufferCreateFlags::SPARSE_RESIDENCY`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sparse_residency_buffer", )])]), vuids: &["VUID-VkBufferCreateInfo-flags-00916"], - }); + })); } if sparse_level.sparse_aliased && !device.enabled_features().sparse_residency_aliased { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sparse".into(), problem: "contains `BufferCreateFlags::SPARSE_ALIASED`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sparse_residency_aliased", )])]), vuids: &["VUID-VkBufferCreateInfo-flags-00917"], - }); + })); } // TODO: @@ -681,13 +684,13 @@ impl BufferCreateInfo { Sharing::Exclusive => (), Sharing::Concurrent(queue_family_indices) => { if queue_family_indices.len() < 2 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sharing".into(), problem: "is `Sharing::Concurrent`, but contains less than 2 elements" .into(), vuids: &["VUID-VkBufferCreateInfo-sharingMode-00914"], ..Default::default() - }); + })); } let queue_family_count = @@ -695,7 +698,7 @@ impl BufferCreateInfo { for (index, &queue_family_index) in queue_family_indices.iter().enumerate() { if queue_family_indices[..index].contains(&queue_family_index) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_indices".into(), problem: format!( "the queue family index in the list at index {} is contained in \ @@ -705,17 +708,17 @@ impl BufferCreateInfo { .into(), vuids: &["VUID-VkBufferCreateInfo-sharingMode-01419"], ..Default::default() - }); + })); } if queue_family_index >= queue_family_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("sharing[{}]", index).into(), problem: "is not less than the number of queue families in the device" .into(), vuids: &["VUID-VkBufferCreateInfo-sharingMode-01419"], ..Default::default() - }); + })); } } } @@ -723,12 +726,12 @@ impl BufferCreateInfo { if let Some(max_buffer_size) = device.physical_device().properties().max_buffer_size { if size > max_buffer_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "size".into(), problem: "exceeds the `max_buffer_size` limit".into(), vuids: &["VUID-VkBufferCreateInfo-size-06409"], ..Default::default() - }); + })); } } @@ -736,7 +739,7 @@ impl BufferCreateInfo { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_external_memory) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "external_memory_handle_types".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[ @@ -744,7 +747,7 @@ impl BufferCreateInfo { RequiresAllOf(&[Requires::DeviceExtension("khr_external_memory")]), ]), ..Default::default() - }); + })); } external_memory_handle_types diff --git a/vulkano/src/buffer/view.rs b/vulkano/src/buffer/view.rs index 83505eca..deea081a 100644 --- a/vulkano/src/buffer/view.rs +++ b/vulkano/src/buffer/view.rs @@ -53,7 +53,7 @@ use crate::{ format::{Format, FormatFeatures}, macros::impl_id_counter, memory::{is_aligned, DeviceAlignment}, - DeviceSize, RuntimeError, ValidationError, Version, VulkanError, VulkanObject, + DeviceSize, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use std::{mem::MaybeUninit, num::NonZeroU64, ops::Range, ptr, sync::Arc}; @@ -76,7 +76,7 @@ impl BufferView { pub fn new( subbuffer: Subbuffer, create_info: BufferViewCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { let subbuffer = subbuffer.into_bytes(); Self::validate_new(&subbuffer, &create_info)?; @@ -86,7 +86,7 @@ impl BufferView { fn validate_new( subbuffer: &Subbuffer<[u8]>, create_info: &BufferViewCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let device = subbuffer.device(); create_info @@ -110,66 +110,66 @@ impl BufferView { .usage() .intersects(BufferUsage::UNIFORM_TEXEL_BUFFER | BufferUsage::STORAGE_TEXEL_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "subbuffer".into(), problem: "was not created with the `BufferUsage::UNIFORM_TEXEL_BUFFER` \ or `BufferUsage::STORAGE_TEXEL_BUFFER` usage" .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-00932"], ..Default::default() - }); + })); } if buffer.usage().intersects(BufferUsage::UNIFORM_TEXEL_BUFFER) && !format_features.intersects(FormatFeatures::UNIFORM_TEXEL_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the `BufferUsage::UNIFORM_TEXEL_BUFFER` \ usage, but the format features of `create_info.format` do not include \ `FormatFeatures::UNIFORM_TEXEL_BUFFER`" .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-00933"], ..Default::default() - }); + })); } if buffer.usage().intersects(BufferUsage::STORAGE_TEXEL_BUFFER) && !format_features.intersects(FormatFeatures::STORAGE_TEXEL_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the `BufferUsage::STORAGE_TEXEL_BUFFER` \ usage, but the format features of `create_info.format` do not include \ `FormatFeatures::STORAGE_TEXEL_BUFFER`" .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-00934"], ..Default::default() - }); + })); } let block_size = format.block_size().unwrap(); let texels_per_block = format.texels_per_block(); if subbuffer.size() % block_size != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer.size()` is not a multiple of \ `create_info.format.block_size()`" .into(), vuids: &["VUID-VkBufferViewCreateInfo-range-00929"], ..Default::default() - }); + })); } if ((subbuffer.size() / block_size) * texels_per_block as DeviceSize) as u32 > properties.max_texel_buffer_elements { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer.size() / create_info.format.block_size() * \ create_info.format.texels_per_block()` is greater than the \ `max_texel_buffer_elements` limit" .into(), vuids: &["VUID-VkBufferViewCreateInfo-range-00930"], ..Default::default() - }); + })); } if device.api_version() >= Version::V1_3 || device.enabled_features().texel_buffer_alignment @@ -193,7 +193,7 @@ impl BufferView { .unwrap() .min(element_size), ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the \ `BufferUsage::STORAGE_TEXEL_BUFFER` usage, and the \ `storage_texel_buffer_offset_single_texel_alignment` \ @@ -204,7 +204,7 @@ impl BufferView { .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-02750"], ..Default::default() - }); + })); } } else { if !is_aligned( @@ -213,7 +213,7 @@ impl BufferView { .storage_texel_buffer_offset_alignment_bytes .unwrap(), ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the \ `BufferUsage::STORAGE_TEXEL_BUFFER` usage, and the \ `storage_texel_buffer_offset_single_texel_alignment` \ @@ -223,7 +223,7 @@ impl BufferView { .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-02750"], ..Default::default() - }); + })); } } } @@ -240,7 +240,7 @@ impl BufferView { .unwrap() .min(element_size), ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the \ `BufferUsage::UNIFORM_TEXEL_BUFFER` usage, and the \ `uniform_texel_buffer_offset_single_texel_alignment` \ @@ -251,7 +251,7 @@ impl BufferView { .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-02751"], ..Default::default() - }); + })); } } else { if !is_aligned( @@ -260,7 +260,7 @@ impl BufferView { .uniform_texel_buffer_offset_alignment_bytes .unwrap(), ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer` was created with the \ `BufferUsage::UNIFORM_TEXEL_BUFFER` usage, and the \ `uniform_texel_buffer_offset_single_texel_alignment` \ @@ -270,7 +270,7 @@ impl BufferView { .into(), vuids: &["VUID-VkBufferViewCreateInfo-buffer-02751"], ..Default::default() - }); + })); } } } @@ -279,13 +279,13 @@ impl BufferView { subbuffer.offset(), properties.min_texel_buffer_offset_alignment, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subbuffer.offset()` is not a multiple of the \ `min_texel_buffer_offset_alignment` limit" .into(), vuids: &["VUID-VkBufferViewCreateInfo-offset-02749"], ..Default::default() - }); + })); } } @@ -296,7 +296,7 @@ impl BufferView { pub unsafe fn new_unchecked( subbuffer: Subbuffer, create_info: BufferViewCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &BufferViewCreateInfo { format, _ne: _ } = &create_info; let device = subbuffer.device(); @@ -320,7 +320,7 @@ impl BufferView { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -438,7 +438,7 @@ impl Default for BufferViewCreateInfo { } impl BufferViewCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let Self { format, _ne: _ } = self; let format = format.ok_or(ValidationError { diff --git a/vulkano/src/command_buffer/commands/acceleration_structure.rs b/vulkano/src/command_buffer/commands/acceleration_structure.rs index 097859e6..c96eafaa 100644 --- a/vulkano/src/command_buffer/commands/acceleration_structure.rs +++ b/vulkano/src/command_buffer/commands/acceleration_structure.rs @@ -94,7 +94,7 @@ where &mut self, info: AccelerationStructureBuildGeometryInfo, build_range_infos: SmallVec<[AccelerationStructureBuildRangeInfo; 8]>, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_build_acceleration_structure(&info, &build_range_infos)?; Ok(self.build_acceleration_structure_unchecked(info, build_range_infos)) @@ -104,27 +104,27 @@ where &self, info: &AccelerationStructureBuildGeometryInfo, build_range_infos: &[AccelerationStructureBuildRangeInfo], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue_family_properties() .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-commandBuffer-cmdpool"], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-renderpass"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-parameter @@ -165,13 +165,13 @@ where .usage() .intersects(BufferUsage::STORAGE_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "the buffer was not created with the `BufferUsage::STORAGE_BUFFER` usage" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03674"], ..Default::default() - }); + })); } let min_acceleration_structure_scratch_offset_alignment = self @@ -185,20 +185,20 @@ where % min_acceleration_structure_scratch_offset_alignment as u64 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "the device address of the buffer is not a multiple of the \ `min_acceleration_structure_scratch_offset_alignment` device property" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03710"], ..Default::default() - }); + })); } match dst_acceleration_structure.ty() { AccelerationStructureType::TopLevel => { if !matches!(geometries, AccelerationStructureGeometries::Instances(_)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info".into(), problem: "`dst_acceleration_structure` is a top-level \ acceleration structure, but `geometries` is not \ @@ -209,12 +209,12 @@ where "VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03699", ], ..Default::default() - }); + })); } } AccelerationStructureType::BottomLevel => { if matches!(geometries, AccelerationStructureGeometries::Instances(_)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info".into(), problem: "`dst_acceleration_structure` is a bottom-level \ acceleration structure, but `geometries` is \ @@ -225,19 +225,19 @@ where "VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03700", ], ..Default::default() - }); + })); } } AccelerationStructureType::Generic => (), } if geometries.len() != build_range_infos.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`info.geometries` and `build_range_infos` do not have the same length" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-ppBuildRangeInfos-03676"], ..Default::default() - }); + })); } let max_primitive_count = self @@ -277,7 +277,7 @@ where } = build_range_info; if primitive_count as u64 > max_primitive_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "build_range_infos[{}].primitive_count", geometry_index @@ -286,7 +286,7 @@ where problem: "exceeds the `max_primitive_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03795"], ..Default::default() - }); + })); } if !vertex_data @@ -294,7 +294,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].vertex_data", geometry_index) .into(), problem: "the buffer was not created with the \ @@ -302,7 +302,7 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } let smallest_component_bits = vertex_format @@ -316,7 +316,7 @@ where if vertex_data.device_address().unwrap().get() % smallest_component_bytes as u64 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].vertex_data", geometry_index) .into(), problem: "the buffer's device address is not a multiple of the byte \ @@ -324,7 +324,7 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03711"], ..Default::default() - }); + })); } if let Some(index_data) = index_data { @@ -334,7 +334,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].index_data", geometry_index) .into(), problem: "the buffer was not created with the \ @@ -343,14 +343,14 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } if index_data.as_bytes().device_address().unwrap().get() % index_data.index_type().size() != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].index_data", geometry_index) .into(), problem: "the buffer's device address is not a multiple \ @@ -358,11 +358,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03712"], ..Default::default() - }); + })); } if primitive_offset as u64 % index_data.index_type().size() != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`info.geometries` is \ `AccelerationStructureGeometries::Triangles`, and \ @@ -374,7 +374,7 @@ where .into(), vuids: &["VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03656"], ..Default::default() - }); + })); } if primitive_offset as DeviceSize @@ -382,7 +382,7 @@ where * index_data.index_type().size() as DeviceSize > vertex_data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`infos.geometries` is \ `AccelerationStructureGeometries::Triangles`, \ @@ -395,11 +395,11 @@ where ) .into(), ..Default::default() - }); + })); } } else { if primitive_offset % smallest_component_bytes != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`info.geometries` is \ `AccelerationStructureGeometries::Triangles`, and @@ -411,7 +411,7 @@ where .into(), vuids: &["VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03657"], ..Default::default() - }); + })); } if primitive_offset as DeviceSize @@ -419,7 +419,7 @@ where * vertex_stride as DeviceSize > vertex_data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`infos.geometries` is \ `AccelerationStructureGeometries::Triangles`, \ @@ -433,7 +433,7 @@ where ) .into(), ..Default::default() - }); + })); } } @@ -443,7 +443,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "info.geometries[{}].transform_data", geometry_index @@ -455,11 +455,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } if transform_data.device_address().unwrap().get() % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "info.geometries[{}].transform_data", geometry_index @@ -469,11 +469,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03810"], ..Default::default() - }); + })); } if transform_offset % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`info.geometries` is \ `AccelerationStructureGeometries::Triangles`, and \ @@ -484,14 +484,14 @@ where .into(), vuids: &["VUID-VkAccelerationStructureBuildRangeInfoKHR-transformOffset-03658"], ..Default::default() - }); + })); } if transform_offset as DeviceSize + size_of::() as DeviceSize > transform_data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`infos.geometries` is \ `AccelerationStructureGeometries::Triangles`, and \ @@ -502,7 +502,7 @@ where ) .into(), ..Default::default() - }); + })); } } } @@ -526,12 +526,12 @@ where } = build_range_info; if primitive_count as u64 > max_primitive_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("build_range_infos[{}]", geometry_index).into(), problem: "exceeds the `max_primitive_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03794"], ..Default::default() - }); + })); } if !data @@ -539,7 +539,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].data", geometry_index).into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` \ @@ -547,20 +547,20 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } if data.device_address().unwrap().get() % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].data", geometry_index).into(), problem: "the buffer's device address is not a multiple of 8".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03714"], ..Default::default() - }); + })); } if primitive_offset % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`info.geometries` is \ `AccelerationStructureGeometries::Aabbs`, and \ @@ -570,14 +570,14 @@ where .into(), vuids: &["VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03659"], ..Default::default() - }); + })); } if primitive_offset as DeviceSize + primitive_count as DeviceSize * stride as DeviceSize > data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`infos.geometries` is `AccelerationStructureGeometries::Aabbs`, and `build_range_infos[{0}].primitive_offset` + \ @@ -588,7 +588,7 @@ where ) .into(), ..Default::default() - }); + })); } } } @@ -607,16 +607,16 @@ where } = &build_range_infos[0]; if primitive_count as u64 > max_instance_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "build_range_infos[0]".into(), problem: "exceeds the the `max_instance_count` limit".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03801"], ..Default::default() - }); + })); } if primitive_offset % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`info.geometries is` \ `AccelerationStructureGeometries::Instances`, and \ `build_range_infos[0].primitive_offset` is not a multiple of 16" @@ -625,13 +625,13 @@ where "VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03660", ], ..Default::default() - }); + })); } let data_buffer = match data { AccelerationStructureGeometryInstancesDataType::Values(data) => { if data.device_address().unwrap().get() % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "is `AccelerationStructureGeometryInstancesDataType::\ Values`, and the buffer's device address is not a multiple of \ @@ -639,7 +639,7 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03715"], ..Default::default() - }); + })); } if primitive_offset as DeviceSize @@ -647,7 +647,7 @@ where * size_of::() as DeviceSize > data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`infos.geometries` is \ `AccelerationStructureGeometries::Instances`, \ `infos.geometries.data` is \ @@ -658,7 +658,7 @@ where the size of `infos.geometries.data`" .into(), ..Default::default() - }); + })); } data.buffer() @@ -669,7 +669,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` \ @@ -677,11 +677,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } if data.device_address().unwrap().get() % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "is `AccelerationStructureGeometryInstancesDataType::\ Pointers` and the buffer's device address is not a multiple \ @@ -689,14 +689,14 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03716"], ..Default::default() - }); + })); } if primitive_offset as DeviceSize + primitive_count as DeviceSize * size_of::() as DeviceSize > data.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`infos.geometries` is \ `AccelerationStructureGeometries::Instances`, \ `infos.geometries.data` is \ @@ -707,7 +707,7 @@ where size of `infos.geometries.data`" .into(), ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03717 @@ -721,14 +721,14 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` usage" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-geometry-03673"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-06707 @@ -748,34 +748,34 @@ where }; if dst_acceleration_structure.size() < build_size_info.acceleration_structure_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.dst_acceleration_structure".into(), problem: "size is too small to hold the resulting acceleration structure data" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03675"], ..Default::default() - }); + })); } match mode { BuildAccelerationStructureMode::Build => { if scratch_data.size() < build_size_info.build_scratch_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "size is too small for the build operation".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03671"], ..Default::default() - }); + })); } } BuildAccelerationStructureMode::Update(_src_acceleration_structure) => { if scratch_data.size() < build_size_info.update_scratch_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "size is too small for the update operation".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03672"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-03667 @@ -873,7 +873,7 @@ where indirect_buffer: Subbuffer<[u8]>, stride: u32, max_primitive_counts: SmallVec<[u32; 8]>, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_build_acceleration_structure_indirect( &info, &indirect_buffer, @@ -895,17 +895,17 @@ where indirect_buffer: &Subbuffer<[u8]>, stride: u32, max_primitive_counts: &[u32], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .device() .enabled_features() .acceleration_structure_indirect_build { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature("acceleration_structure_indirect_build")])]), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-accelerationStructureIndirectBuild-03650"], ..Default::default() - }); + })); } if !self @@ -913,21 +913,21 @@ where .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-commandBuffer-cmdpool"], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-renderpass"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-parameter @@ -968,13 +968,13 @@ where .usage() .intersects(BufferUsage::STORAGE_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "the buffer was not created with the `BufferUsage::STORAGE_BUFFER` usage" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03674"], ..Default::default() - }); + })); } let min_acceleration_structure_scratch_offset_alignment = self @@ -988,20 +988,20 @@ where % min_acceleration_structure_scratch_offset_alignment as u64 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "the device address of the buffer is not a multiple of the \ `min_acceleration_structure_scratch_offset_alignment` device property" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03710"], ..Default::default() - }); + })); } match dst_acceleration_structure.ty() { AccelerationStructureType::TopLevel => { if !matches!(geometries, AccelerationStructureGeometries::Instances(_)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info".into(), problem: "`dst_acceleration_structure` is a top-level \ acceleration structure, but `geometries` is not \ @@ -1012,12 +1012,12 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03699", ], ..Default::default() - }); + })); } } AccelerationStructureType::BottomLevel => { if matches!(geometries, AccelerationStructureGeometries::Instances(_)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info".into(), problem: "`dst_acceleration_structure` is a bottom-level \ acceleration structure, but `geometries` is \ @@ -1028,21 +1028,21 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03700", ], ..Default::default() - }); + })); } } AccelerationStructureType::Generic => (), } if geometries.len() != max_primitive_counts.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`info.geometries` and `max_primitive_counts` do not have the same length" .into(), vuids: &[ "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-ppMaxPrimitiveCounts-parameter", ], ..Default::default() - }); + })); } match geometries { @@ -1067,7 +1067,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].vertex_data", geometry_index) .into(), problem: "the buffer was not created with the \ @@ -1077,7 +1077,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673", ], ..Default::default() - }); + })); } let smallest_component_bits = vertex_format @@ -1091,7 +1091,7 @@ where if vertex_data.device_address().unwrap().get() % smallest_component_bytes as u64 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].vertex_data", geometry_index) .into(), problem: "the buffer's device address is not a multiple of the byte \ @@ -1101,7 +1101,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03711", ], ..Default::default() - }); + })); } if let Some(index_data) = index_data { @@ -1111,7 +1111,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].index_data", geometry_index) .into(), problem: "the buffer was not created with the \ @@ -1120,14 +1120,14 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673"], ..Default::default() - }); + })); } if index_data.as_bytes().device_address().unwrap().get() % index_data.index_type().size() != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].index_data", geometry_index) .into(), problem: "the buffer's device address is not a multiple \ @@ -1137,7 +1137,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03712", ], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03656 @@ -1153,7 +1153,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "info.geometries[{}].transform_data", geometry_index @@ -1165,11 +1165,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673"], ..Default::default() - }); + })); } if transform_data.device_address().unwrap().get() % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "info.geometries[{}].transform_data", geometry_index @@ -1181,7 +1181,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03810", ], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildRangeInfoKHR-transformOffset-03658 @@ -1206,7 +1206,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].data", geometry_index).into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` usage" @@ -1215,18 +1215,18 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673", ], ..Default::default() - }); + })); } if data.device_address().unwrap().get() % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("info.geometries[{}].data", geometry_index).into(), problem: "the buffer's device address is not a multiple of 8".into(), vuids: &[ "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03714", ], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03659 @@ -1246,7 +1246,7 @@ where let data_buffer = match data { AccelerationStructureGeometryInstancesDataType::Values(data) => { if data.device_address().unwrap().get() % 16 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "is `AccelerationStructureGeometryInstancesDataType::\ Values` and the buffer's device address is not a multiple of \ @@ -1256,7 +1256,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03715", ], ..Default::default() - }); + })); } data.buffer() @@ -1267,7 +1267,7 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` \ @@ -1275,11 +1275,11 @@ where .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673"], ..Default::default() - }); + })); } if data.device_address().unwrap().get() % 8 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "is `AccelerationStructureGeometryInstancesDataType::\ Pointers` and the buffer's device address is not a multiple \ @@ -1289,7 +1289,7 @@ where "VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03716", ], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03717 @@ -1303,14 +1303,14 @@ where .usage() .intersects(BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.geometries.data".into(), problem: "the buffer was not created with the \ `BufferUsage::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY` usage" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-geometry-03673"], ..Default::default() - }); + })); } // VUID-VkAccelerationStructureBuildRangeInfoKHR-primitiveOffset-03660 @@ -1330,34 +1330,34 @@ where }; if dst_acceleration_structure.size() < build_size_info.acceleration_structure_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.dst_acceleration_structure".into(), problem: "size is too small to hold the resulting acceleration structure data" .into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03652"], ..Default::default() - }); + })); } match mode { BuildAccelerationStructureMode::Build => { if scratch_data.size() < build_size_info.build_scratch_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "size is too small for the build operation".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03671"], ..Default::default() - }); + })); } } BuildAccelerationStructureMode::Update(_src_acceleration_structure) => { if scratch_data.size() < build_size_info.update_scratch_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.scratch_data".into(), problem: "size is too small for the update operation".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03672"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pInfos-03667 @@ -1366,12 +1366,12 @@ where } if geometries.len() as DeviceSize * stride as DeviceSize > indirect_buffer.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`info.geometries.len()` * `stride` is greater than the size of \ `indirect_buffer`".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pIndirectDeviceAddresses-03646"], ..Default::default() - }); + })); } if !indirect_buffer @@ -1379,30 +1379,30 @@ where .usage() .intersects(BufferUsage::INDIRECT_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "indirect_buffer".into(), problem: "the buffer was not created with the `BufferUsage::INDIRECT_BUFFER` usage".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pIndirectDeviceAddresses-03647"], ..Default::default() - }); + })); } if indirect_buffer.device_address().unwrap().get() % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "indirect_buffer".into(), problem: "the buffer's device address is not a multiple of 4".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pIndirectDeviceAddresses-03648"], ..Default::default() - }); + })); } if stride % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stride".into(), problem: "is not a multiple of 4".into(), vuids: &["VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pIndirectStrides-03787"], ..Default::default() - }); + })); } // VUID-vkCmdBuildAccelerationStructuresIndirectKHR-pIndirectDeviceAddresses-03651 @@ -1456,7 +1456,7 @@ where pub unsafe fn copy_acceleration_structure( &mut self, info: CopyAccelerationStructureInfo, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_copy_acceleration_structure(&info)?; Ok(self.copy_acceleration_structure_unchecked(info)) @@ -1465,27 +1465,27 @@ where fn validate_copy_acceleration_structure( &self, info: &CopyAccelerationStructureInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue_family_properties() .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &["VUID-vkCmdCopyAccelerationStructureKHR-commandBuffer-cmdpool"], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdCopyAccelerationStructureKHR-renderpass"], ..Default::default() - }); + })); } // VUID-vkCmdCopyAccelerationStructureKHR-pInfo-parameter @@ -1555,7 +1555,7 @@ where pub unsafe fn copy_acceleration_structure_to_memory( &mut self, info: CopyAccelerationStructureToMemoryInfo, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_copy_acceleration_structure_to_memory(&info)?; Ok(self.copy_acceleration_structure_to_memory_unchecked(info)) @@ -1564,36 +1564,36 @@ where fn validate_copy_acceleration_structure_to_memory( &self, info: &CopyAccelerationStructureToMemoryInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue_family_properties() .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &["VUID-vkCmdCopyAccelerationStructureToMemoryKHR-commandBuffer-cmdpool"], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdCopyAccelerationStructureToMemoryKHR-renderpass"], ..Default::default() - }); + })); } if info.dst.device_address().unwrap().get() % 256 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.dst".into(), problem: "the device address of the buffer is not a multiple of 256".into(), vuids: &["VUID-vkCmdCopyAccelerationStructureToMemoryKHR-pInfo-03740"], ..Default::default() - }); + })); } // VUID-vkCmdCopyAccelerationStructureToMemoryKHR-pInfo-parameter @@ -1665,7 +1665,7 @@ where pub unsafe fn copy_memory_to_acceleration_structure( &mut self, info: CopyMemoryToAccelerationStructureInfo, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_copy_memory_to_acceleration_structure(&info)?; Ok(self.copy_memory_to_acceleration_structure_unchecked(info)) @@ -1674,36 +1674,36 @@ where fn validate_copy_memory_to_acceleration_structure( &self, info: &CopyMemoryToAccelerationStructureInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue_family_properties() .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &["VUID-vkCmdCopyMemoryToAccelerationStructureKHR-commandBuffer-cmdpool"], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdCopyMemoryToAccelerationStructureKHR-renderpass"], ..Default::default() - }); + })); } if info.src.device_address().unwrap().get() % 256 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "info.src".into(), problem: "the device address of the buffer is not a multiple of 256".into(), vuids: &["VUID-vkCmdCopyMemoryToAccelerationStructureKHR-pInfo-03743"], ..Default::default() - }); + })); } // VUID-vkCmdCopyMemoryToAccelerationStructureKHR-pInfo-parameter @@ -1780,7 +1780,7 @@ where acceleration_structures: SmallVec<[Arc; 4]>, query_pool: Arc, first_query: u32, - ) -> Result<&mut Self, ValidationError> { + ) -> Result<&mut Self, Box> { self.validate_write_acceleration_structures_properties( &acceleration_structures, &query_pool, @@ -1799,7 +1799,7 @@ where acceleration_structures: &[Arc], query_pool: &QueryPool, first_query: u32, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if acceleration_structures.is_empty() { return Ok(()); } @@ -1809,23 +1809,23 @@ where .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "queue family does not support compute operations".into(), vuids: &[ "VUID-vkCmdWriteAccelerationStructuresPropertiesKHR-commandBuffer-cmdpool", ], ..Default::default() - }); + })); } if self.builder_state.render_pass.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "a render pass instance is active".into(), vuids: &["VUID-vkCmdWriteAccelerationStructuresPropertiesKHR-renderpass"], ..Default::default() - }); + })); } for acs in acceleration_structures { @@ -1847,13 +1847,13 @@ where if first_query as usize + acceleration_structures.len() > query_pool.query_count() as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`first_query` + `acceleration_structures.len()` is greater than \ `query_pool.query_count`" .into(), vuids: &["VUID-vkCmdWriteAccelerationStructuresPropertiesKHR-query-04880"], ..Default::default() - }); + })); } if !matches!( @@ -1863,12 +1863,12 @@ where | QueryType::AccelerationStructureCompactedSize | QueryType::AccelerationStructureSerializationSize, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "query_pool.query_type()".into(), problem: "is not an acceleration structure query".into(), vuids: &["VUID-vkCmdWriteAccelerationStructuresPropertiesKHR-queryType-06742"], ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/command_buffer/commands/bind_push.rs b/vulkano/src/command_buffer/commands/bind_push.rs index 2e6061c9..74bd9626 100644 --- a/vulkano/src/command_buffer/commands/bind_push.rs +++ b/vulkano/src/command_buffer/commands/bind_push.rs @@ -766,14 +766,14 @@ where pipeline_layout: &PipelineLayout, set_num: u32, descriptor_writes: &[WriteDescriptorSet], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.device().enabled_extensions().khr_push_descriptor { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_push_descriptor", )])]), ..Default::default() - }); + })); } pipeline_bind_point @@ -792,7 +792,7 @@ where .queue_flags .intersects(QueueFlags::COMPUTE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "`pipeline_bind_point` is `PipelineBindPoint::Compute`, and the \ queue family does not support compute operations" @@ -802,7 +802,7 @@ where "VUID-vkCmdPushDescriptorSetKHR-commandBuffer-cmdpool", ], ..Default::default() - }); + })); } } PipelineBindPoint::Graphics => { @@ -810,7 +810,7 @@ where .queue_flags .intersects(QueueFlags::GRAPHICS) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "`pipeline_bind_point` is `PipelineBindPoint::Graphics`, and the \ queue family does not support graphics operations" @@ -820,7 +820,7 @@ where "VUID-vkCmdPushDescriptorSetKHR-commandBuffer-cmdpool", ], ..Default::default() - }); + })); } } } @@ -829,13 +829,13 @@ where assert_eq!(self.device(), pipeline_layout.device()); if set_num as usize > pipeline_layout.set_layouts().len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`set_num` is greater than the number of descriptor set layouts in \ `pipeline_layout`" .into(), vuids: &["VUID-vkCmdPushDescriptorSetKHR-set-00364"], ..Default::default() - }); + })); } let descriptor_set_layout = &pipeline_layout.set_layouts()[set_num as usize]; @@ -844,14 +844,14 @@ where .flags() .intersects(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor set layout with the number `set_num` in \ `pipeline_layout` was not created with the \ `DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR` flag" .into(), vuids: &["VUID-vkCmdPushDescriptorSetKHR-set-00365"], ..Default::default() - }); + })); } for (index, write) in descriptor_writes.iter().enumerate() { diff --git a/vulkano/src/command_buffer/commands/pipeline.rs b/vulkano/src/command_buffer/commands/pipeline.rs index 3fb6c4c8..a7967e3a 100644 --- a/vulkano/src/command_buffer/commands/pipeline.rs +++ b/vulkano/src/command_buffer/commands/pipeline.rs @@ -2675,7 +2675,7 @@ pub enum DescriptorResourceInvalidError { image_view_set_num: u32, image_view_binding_num: u32, image_view_index: u32, - error: ValidationError, + error: Box, }, SamplerUnnormalizedCoordinatesNotAllowed, SamplerYcbcrConversionNotAllowed, diff --git a/vulkano/src/command_buffer/pool.rs b/vulkano/src/command_buffer/pool.rs index 900a18b2..eab87076 100644 --- a/vulkano/src/command_buffer/pool.rs +++ b/vulkano/src/command_buffer/pool.rs @@ -20,7 +20,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, macros::impl_id_counter, - OomError, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, Version, VulkanObject, + OomError, Requires, RequiresAllOf, RequiresOneOf, Version, VulkanError, VulkanObject, }; use smallvec::SmallVec; use std::{ @@ -170,7 +170,7 @@ impl CommandPool { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -196,7 +196,7 @@ impl CommandPool { let fns = self.device.fns(); (fns.v1_0.reset_command_pool)(self.device.handle(), self.handle, flags) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -233,7 +233,7 @@ impl CommandPool { out.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; out.set_len(command_buffer_count as usize); out } @@ -390,10 +390,10 @@ impl Display for CommandPoolCreationError { } } -impl From for CommandPoolCreationError { - fn from(err: RuntimeError) -> Self { +impl From for CommandPoolCreationError { + fn from(err: VulkanError) -> Self { match err { - err @ RuntimeError::OutOfHostMemory => Self::OomError(OomError::from(err)), + err @ VulkanError::OutOfHostMemory => Self::OomError(OomError::from(err)), _ => panic!("unexpected error: {:?}", err), } } @@ -522,8 +522,8 @@ impl Display for CommandPoolTrimError { } } -impl From for CommandPoolTrimError { - fn from(err: RuntimeError) -> CommandPoolTrimError { +impl From for CommandPoolTrimError { + fn from(err: VulkanError) -> CommandPoolTrimError { panic!("unexpected error: {:?}", err) } } diff --git a/vulkano/src/command_buffer/sys.rs b/vulkano/src/command_buffer/sys.rs index 77bd555e..7c112215 100644 --- a/vulkano/src/command_buffer/sys.rs +++ b/vulkano/src/command_buffer/sys.rs @@ -21,7 +21,7 @@ use crate::{ }, device::{Device, DeviceOwned}, query::QueryControlFlags, - OomError, RuntimeError, VulkanObject, + OomError, VulkanError, VulkanObject, }; use smallvec::SmallVec; use std::{fmt::Debug, ptr, sync::Arc}; @@ -173,7 +173,7 @@ where let fns = builder_alloc.device().fns(); (fns.v1_0.begin_command_buffer)(builder_alloc.inner().handle(), &begin_info_vk) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Ok(UnsafeCommandBufferBuilder { @@ -191,7 +191,7 @@ where let fns = self.device().fns(); (fns.v1_0.end_command_buffer)(self.handle()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(UnsafeCommandBuffer { alloc: self.builder_alloc.into_alloc(), diff --git a/vulkano/src/deferred.rs b/vulkano/src/deferred.rs index b1be042f..4b0e20a4 100644 --- a/vulkano/src/deferred.rs +++ b/vulkano/src/deferred.rs @@ -19,7 +19,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, VulkanObject, + Requires, RequiresAllOf, RequiresOneOf, VulkanError, VulkanObject, }; use std::{ error::Error, @@ -66,7 +66,7 @@ impl DeferredOperation { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn new_unchecked(device: Arc) -> Result, RuntimeError> { + pub unsafe fn new_unchecked(device: Arc) -> Result, VulkanError> { let handle = { let fns = device.fns(); let mut output = MaybeUninit::uninit(); @@ -75,7 +75,7 @@ impl DeferredOperation { device.handle(), ptr::null(), output.as_mut_ptr() ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -99,7 +99,7 @@ impl DeferredOperation { } /// Executes a portion of the operation on the current thread. - pub fn join(&self) -> Result { + pub fn join(&self) -> Result { let result = unsafe { let fns = self.device.fns(); (fns.khr_deferred_host_operations.deferred_operation_join_khr)( @@ -112,12 +112,12 @@ impl DeferredOperation { ash::vk::Result::SUCCESS => Ok(DeferredOperationJoinStatus::Complete), ash::vk::Result::THREAD_DONE_KHR => Ok(DeferredOperationJoinStatus::ThreadDone), ash::vk::Result::THREAD_IDLE_KHR => Ok(DeferredOperationJoinStatus::ThreadIdle), - err => Err(RuntimeError::from(err)), + err => Err(VulkanError::from(err)), } } /// Returns the result of the operation, or `None` if the operation is not yet complete. - pub fn result(&self) -> Option> { + pub fn result(&self) -> Option> { let result = unsafe { let fns = self.device.fns(); (fns.khr_deferred_host_operations @@ -127,12 +127,12 @@ impl DeferredOperation { match result { ash::vk::Result::NOT_READY => None, ash::vk::Result::SUCCESS => Some(Ok(())), - err => Some(Err(RuntimeError::from(err))), + err => Some(Err(VulkanError::from(err))), } } /// Waits for the operation to complete, then returns its result. - pub fn wait(&self) -> Result, RuntimeError> { + pub fn wait(&self) -> Result, VulkanError> { // Based on example code on the extension's spec page. // Call `join` until we get `Complete` or `ThreadDone`. @@ -210,7 +210,7 @@ unsafe impl DeviceOwned for DeferredOperation { /// Error that can happen when creating a `DeferredOperation`. #[derive(Clone, Debug)] pub enum DeferredOperationCreateError { - RuntimeError(RuntimeError), + VulkanError(VulkanError), RequirementNotMet { required_for: &'static str, @@ -221,7 +221,7 @@ pub enum DeferredOperationCreateError { impl Display for DeferredOperationCreateError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - Self::RuntimeError(_) => write!(f, "a runtime error occurred"), + Self::VulkanError(_) => write!(f, "a runtime error occurred"), Self::RequirementNotMet { required_for, requires_one_of, @@ -237,15 +237,15 @@ impl Display for DeferredOperationCreateError { impl Error for DeferredOperationCreateError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - Self::RuntimeError(err) => Some(err), + Self::VulkanError(err) => Some(err), _ => None, } } } -impl From for DeferredOperationCreateError { - fn from(err: RuntimeError) -> Self { - Self::RuntimeError(err) +impl From for DeferredOperationCreateError { + fn from(err: VulkanError) -> Self { + Self::VulkanError(err) } } diff --git a/vulkano/src/descriptor_set/allocator.rs b/vulkano/src/descriptor_set/allocator.rs index 73e1bbc7..719f7a8a 100644 --- a/vulkano/src/descriptor_set/allocator.rs +++ b/vulkano/src/descriptor_set/allocator.rs @@ -26,7 +26,7 @@ use crate::{ descriptor_set::layout::{DescriptorSetLayoutCreateFlags, DescriptorType}, device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, - RuntimeError, VulkanError, + Validated, VulkanError, }; use crossbeam_queue::ArrayQueue; use std::{cell::UnsafeCell, mem::ManuallyDrop, num::NonZeroU64, sync::Arc, thread}; @@ -60,7 +60,7 @@ pub unsafe trait DescriptorSetAllocator: DeviceOwned { &self, layout: &Arc, variable_descriptor_count: u32, - ) -> Result; + ) -> Result; } /// An allocated descriptor set. @@ -154,7 +154,7 @@ unsafe impl DescriptorSetAllocator for StandardDescriptorSetAllocator { &self, layout: &Arc, variable_descriptor_count: u32, - ) -> Result { + ) -> Result { assert!( !layout .flags() @@ -197,7 +197,7 @@ unsafe impl DescriptorSetAllocator for Arc { &self, layout: &Arc, variable_descriptor_count: u32, - ) -> Result { + ) -> Result { (**self).allocate(layout, variable_descriptor_count) } } @@ -221,7 +221,7 @@ struct FixedEntry { } impl FixedEntry { - fn new(layout: Arc) -> Result { + fn new(layout: Arc) -> Result { Ok(FixedEntry { pool: FixedPool::new(&layout, MAX_SETS)?, set_count: MAX_SETS, @@ -229,7 +229,7 @@ impl FixedEntry { }) } - fn allocate(&mut self) -> Result { + fn allocate(&mut self) -> Result { let inner = if let Some(inner) = self.pool.reserve.pop() { inner } else { @@ -257,7 +257,7 @@ struct FixedPool { } impl FixedPool { - fn new(layout: &Arc, set_count: usize) -> Result, RuntimeError> { + fn new(layout: &Arc, set_count: usize) -> Result, VulkanError> { let inner = DescriptorPool::new( layout.device().clone(), DescriptorPoolCreateInfo { @@ -273,7 +273,7 @@ impl FixedPool { ..Default::default() }, ) - .map_err(VulkanError::unwrap_runtime)?; + .map_err(Validated::unwrap)?; let allocate_infos = (0..set_count).map(|_| DescriptorSetAllocateInfo { layout, @@ -284,12 +284,12 @@ impl FixedPool { inner .allocate_descriptor_sets(allocate_infos) .map_err(|err| match err { - RuntimeError::OutOfHostMemory | RuntimeError::OutOfDeviceMemory => err, - RuntimeError::FragmentedPool => { + VulkanError::OutOfHostMemory | VulkanError::OutOfDeviceMemory => err, + VulkanError::FragmentedPool => { // This can't happen as we don't free individual sets. unreachable!(); } - RuntimeError::OutOfPoolMemory => { + VulkanError::OutOfPoolMemory => { // We created the pool with an exact size. unreachable!(); } @@ -326,7 +326,7 @@ struct VariableEntry { } impl VariableEntry { - fn new(layout: Arc) -> Result { + fn new(layout: Arc) -> Result { let reserve = Arc::new(ArrayQueue::new(MAX_POOLS)); Ok(VariableEntry { @@ -340,7 +340,7 @@ impl VariableEntry { fn allocate( &mut self, variable_descriptor_count: u32, - ) -> Result { + ) -> Result { if self.allocations >= MAX_SETS { self.pool = if let Some(inner) = self.reserve.pop() { Arc::new(VariablePool { @@ -363,12 +363,12 @@ impl VariableEntry { .inner .allocate_descriptor_sets([allocate_info]) .map_err(|err| match err { - RuntimeError::OutOfHostMemory | RuntimeError::OutOfDeviceMemory => err, - RuntimeError::FragmentedPool => { + VulkanError::OutOfHostMemory | VulkanError::OutOfDeviceMemory => err, + VulkanError::FragmentedPool => { // This can't happen as we don't free individual sets. unreachable!(); } - RuntimeError::OutOfPoolMemory => { + VulkanError::OutOfPoolMemory => { // We created the pool to fit the maximum variable descriptor count. unreachable!(); } @@ -399,7 +399,7 @@ impl VariablePool { fn new( layout: &Arc, reserve: Arc>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { DescriptorPool::new( layout.device().clone(), DescriptorPoolCreateInfo { @@ -421,7 +421,7 @@ impl VariablePool { reserve, }) }) - .map_err(VulkanError::unwrap_runtime) + .map_err(Validated::unwrap) } } diff --git a/vulkano/src/descriptor_set/layout.rs b/vulkano/src/descriptor_set/layout.rs index 82b71ec3..87968e73 100644 --- a/vulkano/src/descriptor_set/layout.rs +++ b/vulkano/src/descriptor_set/layout.rs @@ -17,7 +17,7 @@ use crate::{ instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_enum}, shader::{DescriptorBindingRequirements, ShaderStages}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use ahash::HashMap; @@ -42,7 +42,7 @@ impl DescriptorSetLayout { pub fn new( device: Arc, create_info: DescriptorSetLayoutCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -51,7 +51,7 @@ impl DescriptorSetLayout { fn validate_new( device: &Device, create_info: &DescriptorSetLayoutCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateDescriptorSetLayout-pCreateInfo-parameter create_info .validate(device) @@ -77,13 +77,13 @@ impl DescriptorSetLayout { .is_none() } { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the total number of descriptors across all bindings is greater than \ the `max_per_set_descriptors` limit, and \ `device.descriptor_set_layout_support` returned `None`" .into(), ..Default::default() - }); + })); } } @@ -94,7 +94,7 @@ impl DescriptorSetLayout { pub unsafe fn new_unchecked( device: Arc, create_info: DescriptorSetLayoutCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &DescriptorSetLayoutCreateInfo { flags, ref bindings, @@ -177,7 +177,7 @@ impl DescriptorSetLayout { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -322,7 +322,7 @@ pub struct DescriptorSetLayoutCreateInfo { } impl DescriptorSetLayoutCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref bindings, @@ -366,7 +366,7 @@ impl DescriptorSetLayoutCreateInfo { | DescriptorType::StorageBufferDynamic | DescriptorType::InlineUniformBlock ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`flags` contains `DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR`, \ and `bindings[{}].descriptor_type` is @@ -381,11 +381,11 @@ impl DescriptorSetLayoutCreateInfo { "VUID-VkDescriptorSetLayoutCreateInfo-flags-02208", ], ..Default::default() - }); + })); } if binding_flags.intersects(DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`flags` contains `DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR`, \ and `bindings[{}].flags` contains \ @@ -395,14 +395,14 @@ impl DescriptorSetLayoutCreateInfo { .into(), vuids: &["VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-flags-03003"], ..Default::default() - }); + })); } } if binding_flags.intersects(DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT) && Some(binding_num) != highest_binding_num { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`bindings[{}].flags` contains \ `DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT`, but {0} is not the @@ -414,7 +414,7 @@ impl DescriptorSetLayoutCreateInfo { "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03004", ], ..Default::default() - }); + })); } } @@ -427,14 +427,14 @@ impl DescriptorSetLayoutCreateInfo { if flags.intersects(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR) && total_descriptor_count > max_push_descriptors { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR`, and \ the total number of descriptors in `bindings` exceeds the \ `max_push_descriptors` limit" .into(), vuids: &["VUID-VkDescriptorSetLayoutCreateInfo-flags-00281"], ..Default::default() - }); + })); } Ok(()) @@ -563,10 +563,10 @@ impl DescriptorSetLayoutBinding { /// Checks whether the descriptor of a pipeline layout `self` is compatible with the /// requirements of a shader `other`. #[inline] - pub fn ensure_compatible_with_shader( + pub(crate) fn ensure_compatible_with_shader( &self, binding_requirements: &DescriptorBindingRequirements, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let &DescriptorBindingRequirements { ref descriptor_types, descriptor_count, @@ -579,38 +579,38 @@ impl DescriptorSetLayoutBinding { } = binding_requirements; if !descriptor_types.contains(&self.descriptor_type) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type is not one of the types allowed by the \ descriptor binding requirements" .into(), ..Default::default() - }); + })); } if let Some(required) = descriptor_count { if self.descriptor_count < required { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor count is less than the count required by the \ descriptor binding requirements" .into(), ..Default::default() - }); + })); } } if !self.stages.contains(stages) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the stages are not a superset of the stages required by the \ descriptor binding requirements" .into(), ..Default::default() - }); + })); } Ok(()) } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { binding_flags, descriptor_type, @@ -640,24 +640,24 @@ impl DescriptorSetLayoutBinding { if descriptor_type == DescriptorType::InlineUniformBlock { if !device.enabled_features().inline_uniform_block { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "descriptor_type".into(), problem: "`DescriptorType::InlineUniformBlock`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "inline_uniform_block", )])]), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-04604"], - }); + })); } if descriptor_count % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`descriptor_type` is `DescriptorType::InlineUniformBlock`, and \ `descriptor_count` is not a multiple of 4" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-02209"], ..Default::default() - }); + })); } if descriptor_count @@ -667,14 +667,14 @@ impl DescriptorSetLayoutBinding { .max_inline_uniform_block_size .unwrap_or(0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`descriptor_type` is `DescriptorType::InlineUniformBlock`, and \ `descriptor_count` is greater than the `max_inline_uniform_block_size` \ limit" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-08004"], ..Default::default() - }); + })); } } @@ -690,25 +690,25 @@ impl DescriptorSetLayoutBinding { if descriptor_type == DescriptorType::InputAttachment && !(stages.is_empty() || stages == ShaderStages::FRAGMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`descriptor_type` is `DescriptorType::InputAttachment`, but \ `stages` is not either empty or equal to `ShaderStages::FRAGMENT`" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-01510"], ..Default::default() - }); + })); } } if !immutable_samplers.is_empty() { if descriptor_count != immutable_samplers.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`immutable_samplers` is not empty, but its length does not equal \ `descriptor_count`" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-00282"], ..Default::default() - }); + })); } let mut has_sampler_ycbcr_conversion = false; @@ -721,27 +721,27 @@ impl DescriptorSetLayoutBinding { if has_sampler_ycbcr_conversion { if !matches!(descriptor_type, DescriptorType::CombinedImageSampler) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`immutable_samplers` contains a sampler with a \ sampler YCbCr conversion, but `descriptor_type` is not \ `DescriptorType::CombinedImageSampler`" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-00282"], ..Default::default() - }); + })); } } else { if !matches!( descriptor_type, DescriptorType::Sampler | DescriptorType::CombinedImageSampler ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`immutable_samplers` is not empty, but `descriptor_type` is not \ `DescriptorType::Sampler` or `DescriptorType::CombinedImageSampler`" .into(), vuids: &["VUID-VkDescriptorSetLayoutBinding-descriptorType-00282"], ..Default::default() - }); + })); } } } @@ -751,21 +751,21 @@ impl DescriptorSetLayoutBinding { .enabled_features() .descriptor_binding_variable_descriptor_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "binding_flags".into(), problem: "contains `DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT`".into(), requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::Feature("descriptor_binding_variable_descriptor_count")]) ]), vuids: &["VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-descriptorBindingVariableDescriptorCount-03014"], - }); + })); } if matches!( descriptor_type, DescriptorType::UniformBufferDynamic | DescriptorType::StorageBufferDynamic ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`binding_flags` contains \ `DescriptorBindingFlags::VARIABLE_DESCRIPTOR_COUNT`, and \ `descriptor_type` is `DescriptorType::UniformBufferDynamic` or \ @@ -775,7 +775,7 @@ impl DescriptorSetLayoutBinding { "VUID-VkDescriptorSetLayoutBindingFlagsCreateInfo-pBindingFlags-03015", ], ..Default::default() - }); + })); } } diff --git a/vulkano/src/descriptor_set/mod.rs b/vulkano/src/descriptor_set/mod.rs index b1ffca12..a99977b4 100644 --- a/vulkano/src/descriptor_set/mod.rs +++ b/vulkano/src/descriptor_set/mod.rs @@ -169,7 +169,7 @@ impl DescriptorSetInner { variable_descriptor_count: u32, descriptor_writes: impl IntoIterator, descriptor_copies: impl IntoIterator, - ) -> Result { + ) -> Result> { assert!( !layout .flags() diff --git a/vulkano/src/descriptor_set/persistent.rs b/vulkano/src/descriptor_set/persistent.rs index 137fb799..3444a8ff 100644 --- a/vulkano/src/descriptor_set/persistent.rs +++ b/vulkano/src/descriptor_set/persistent.rs @@ -31,7 +31,7 @@ use crate::{ UnsafeDescriptorSet, }, device::{Device, DeviceOwned}, - VulkanError, VulkanObject, + Validated, VulkanError, VulkanObject, }; use std::{ hash::{Hash, Hasher}, @@ -54,7 +54,7 @@ impl PersistentDescriptorSet { layout: Arc, descriptor_writes: impl IntoIterator, descriptor_copies: impl IntoIterator, - ) -> Result>, VulkanError> + ) -> Result>, Validated> where A: DescriptorSetAllocator + ?Sized, { @@ -74,7 +74,7 @@ impl PersistentDescriptorSet { variable_descriptor_count: u32, descriptor_writes: impl IntoIterator, descriptor_copies: impl IntoIterator, - ) -> Result>, VulkanError> + ) -> Result>, Validated> where A: DescriptorSetAllocator + ?Sized, { diff --git a/vulkano/src/descriptor_set/pool.rs b/vulkano/src/descriptor_set/pool.rs index 3f926669..b1e13c45 100644 --- a/vulkano/src/descriptor_set/pool.rs +++ b/vulkano/src/descriptor_set/pool.rs @@ -15,7 +15,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use ahash::HashMap; @@ -47,7 +47,7 @@ impl DescriptorPool { pub fn new( device: Arc, create_info: DescriptorPoolCreateInfo, - ) -> Result { + ) -> Result> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -57,7 +57,7 @@ impl DescriptorPool { pub unsafe fn new_unchecked( device: Arc, create_info: DescriptorPoolCreateInfo, - ) -> Result { + ) -> Result { let &DescriptorPoolCreateInfo { flags, max_sets, @@ -106,7 +106,7 @@ impl DescriptorPool { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -116,7 +116,7 @@ impl DescriptorPool { fn validate_new( device: &Device, create_info: &DescriptorPoolCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateDescriptorPool-pCreateInfo-parameter create_info .validate(device) @@ -205,7 +205,7 @@ impl DescriptorPool { pub unsafe fn allocate_descriptor_sets<'a>( &self, allocate_info: impl IntoIterator>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let (layouts, variable_descriptor_counts): (SmallVec<[_; 1]>, SmallVec<[_; 1]>) = allocate_info .into_iter() @@ -256,15 +256,15 @@ impl DescriptorPool { let fns = self.device.fns(); (fns.v1_0.allocate_descriptor_sets)(self.device.handle(), &infos, output.as_mut_ptr()) .result() - .map_err(RuntimeError::from) + .map_err(VulkanError::from) .map_err(|err| match err { - RuntimeError::OutOfHostMemory - | RuntimeError::OutOfDeviceMemory - | RuntimeError::OutOfPoolMemory => err, + VulkanError::OutOfHostMemory + | VulkanError::OutOfDeviceMemory + | VulkanError::OutOfPoolMemory => err, // According to the specs, because `VK_ERROR_FRAGMENTED_POOL` was added after // version 1.0 of Vulkan, any negative return value except out-of-memory errors // must be considered as a fragmented pool error. - _ => RuntimeError::FragmentedPool, + _ => VulkanError::FragmentedPool, })?; output.set_len(layouts.len()); @@ -288,7 +288,7 @@ impl DescriptorPool { pub unsafe fn free_descriptor_sets( &self, descriptor_sets: impl IntoIterator, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let sets: SmallVec<[_; 8]> = descriptor_sets.into_iter().map(|s| s.handle()).collect(); if !sets.is_empty() { let fns = self.device.fns(); @@ -299,7 +299,7 @@ impl DescriptorPool { sets.as_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Ok(()) @@ -309,7 +309,7 @@ impl DescriptorPool { /// /// This destroys all descriptor sets and empties the pool. #[inline] - pub unsafe fn reset(&self) -> Result<(), RuntimeError> { + pub unsafe fn reset(&self) -> Result<(), VulkanError> { let fns = self.device.fns(); (fns.v1_0.reset_descriptor_pool)( self.device.handle(), @@ -317,7 +317,7 @@ impl DescriptorPool { ash::vk::DescriptorPoolResetFlags::empty(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -399,7 +399,7 @@ impl Default for DescriptorPoolCreateInfo { } impl DescriptorPoolCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, max_sets, @@ -417,21 +417,21 @@ impl DescriptorPoolCreateInfo { })?; if max_sets == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "max_sets".into(), problem: "is zero".into(), vuids: &["VUID-VkDescriptorPoolCreateInfo-maxSets-00301"], ..Default::default() - }); + })); } if pool_sizes.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "pool_sizes".into(), problem: "is empty".into(), // vuids? ..Default::default() - }); + })); } // VUID-VkDescriptorPoolCreateInfo-pPoolSizes-parameter @@ -445,21 +445,21 @@ impl DescriptorPoolCreateInfo { })?; if pool_size == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("pool_sizes[DescriptorType::{:?}]", descriptor_type).into(), problem: "is zero".into(), vuids: &["VUID-VkDescriptorPoolSize-descriptorCount-00302"], ..Default::default() - }); + })); } if descriptor_type == DescriptorType::InlineUniformBlock { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "pool_sizes[DescriptorType::InlineUniformBlock]".into(), problem: "is not a multiple of 4".into(), vuids: &["VUID-VkDescriptorPoolSize-type-02218"], ..Default::default() - }); + })); } } @@ -467,7 +467,7 @@ impl DescriptorPoolCreateInfo { && !(device.api_version() >= Version::V1_3 || device.enabled_extensions().ext_inline_uniform_block) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "max_inline_uniform_block_bindings".into(), problem: "is not zero".into(), requires_one_of: RequiresOneOf(&[ @@ -476,7 +476,7 @@ impl DescriptorPoolCreateInfo { ]), // vuids? ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/descriptor_set/update.rs b/vulkano/src/descriptor_set/update.rs index 7a6cf3ed..8838f138 100644 --- a/vulkano/src/descriptor_set/update.rs +++ b/vulkano/src/descriptor_set/update.rs @@ -367,7 +367,7 @@ impl WriteDescriptorSet { &self, layout: &DescriptorSetLayout, variable_descriptor_count: u32, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { fn provided_element_type(elements: &WriteDescriptorSetElements) -> &'static str { match elements { WriteDescriptorSetElements::None(_) => "none", @@ -392,12 +392,12 @@ impl WriteDescriptorSet { let layout_binding = match layout.bindings().get(&binding) { Some(layout_binding) => layout_binding, None => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "binding".into(), problem: "does not exist in the descriptor set layout".into(), vuids: &["VUID-VkWriteDescriptorSet-dstBinding-00315"], ..Default::default() - }); + })); } }; @@ -415,34 +415,34 @@ impl WriteDescriptorSet { // VUID-VkWriteDescriptorSet-dstArrayElement-00321 if first_array_element + array_element_count > max_descriptor_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`first_array_element` + the number of provided elements is greater than \ the number of descriptors in the descriptor set binding" .into(), vuids: &["VUID-VkWriteDescriptorSet-dstArrayElement-00321"], ..Default::default() - }); + })); } let validate_image_view = - |image_view: &ImageView, index: usize| -> Result<(), ValidationError> { + |image_view: &ImageView, index: usize| -> Result<(), Box> { if image_view.image().image_type() == ImageType::Dim3d { if image_view.view_type() == ImageViewType::Dim2dArray { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the image view's type is `ImageViewType::Dim2dArray`, and \ was created from a 3D image" .into(), vuids: &["VUID-VkDescriptorImageInfo-imageView-00343"], ..Default::default() - }); + })); } else if image_view.view_type() == ImageViewType::Dim2d { if !image_view .image() .flags() .intersects(ImageCreateFlags::DIM2D_VIEW_COMPATIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the image view's type is `ImageViewType::Dim2d`, and \ was created from a 3D image, but the image's flags do not \ @@ -450,13 +450,13 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkDescriptorImageInfo-imageView-07796"], ..Default::default() - }); + })); } match layout_binding.descriptor_type { DescriptorType::StorageImage => { if !device.enabled_features().image2_d_view_of3_d { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: format!( "the descriptor type is `DescriptorType::{:?}`, and \ @@ -469,12 +469,12 @@ impl WriteDescriptorSet { Requires::Feature("image2_d_view_of3_d"), ])]), vuids: &["VUID-VkDescriptorImageInfo-descriptorType-06713"], - }); + })); } } DescriptorType::SampledImage | DescriptorType::CombinedImageSampler => { if !device.enabled_features().sampler2_d_view_of3_d { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: format!( "the descriptor type is `DescriptorType::{:?}`, and \ @@ -487,11 +487,11 @@ impl WriteDescriptorSet { Requires::Feature("sampler2_d_view_of3_d"), ])]), vuids: &["VUID-VkDescriptorImageInfo-descriptorType-06714"], - }); + })); } } _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is not \ `DescriptorType::StorageImage`, \ @@ -502,7 +502,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkDescriptorImageInfo-imageView-07795"], ..Default::default() - }); + })); } } } @@ -513,14 +513,14 @@ impl WriteDescriptorSet { .aspects .contains(ImageAspects::DEPTH | ImageAspects::STENCIL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the image view's aspects include both a depth and a \ stencil component" .into(), vuids: &["VUID-VkDescriptorImageInfo-imageView-01976"], ..Default::default() - }); + })); } Ok(()) @@ -539,7 +539,7 @@ impl WriteDescriptorSet { if let WriteDescriptorSetElements::None(_) = elements { // Do nothing } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -549,25 +549,25 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); } } else { // For regular descriptors, no element must be written. - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "binding".into(), problem: "no descriptors must be written to this \ descriptor set binding" .into(), // vuids? ..Default::default() - }); + })); } } let elements = if let WriteDescriptorSetElements::Sampler(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -577,14 +577,14 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, sampler) in elements.iter().enumerate() { assert_eq!(device, sampler.device()); if sampler.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is not \ `DescriptorType::CombinedImageSampler`, and the sampler has a \ @@ -592,14 +592,14 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().mutable_comparison_samplers && sampler.compare().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "this device is a portability subset device, and \ the sampler has depth comparison enabled" @@ -608,7 +608,7 @@ impl WriteDescriptorSet { "mutable_comparison_samplers", )])]), vuids: &["VUID-VkDescriptorImageInfo-mutableComparisonSamplers-04450"], - }); + })); } } } @@ -619,7 +619,7 @@ impl WriteDescriptorSet { if let WriteDescriptorSetElements::ImageViewSampler(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -629,7 +629,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, (image_view_info, sampler)) in elements.iter().enumerate() { @@ -648,7 +648,7 @@ impl WriteDescriptorSet { validate_image_view(image_view.as_ref(), index)?; if !image_view.usage().intersects(ImageUsage::SAMPLED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::SampledImage` or \ @@ -657,7 +657,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00337"], ..Default::default() - }); + })); } if !matches!( @@ -670,7 +670,7 @@ impl WriteDescriptorSet { | ImageLayout::DepthReadOnlyOptimal | ImageLayout::StencilReadOnlyOptimal, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::CombinedImageSampler`, and the image layout \ @@ -678,14 +678,14 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-04150"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().mutable_comparison_samplers && sampler.compare().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "this device is a portability subset device, and \ the sampler has depth comparison enabled" @@ -696,27 +696,27 @@ impl WriteDescriptorSet { vuids: &[ "VUID-VkDescriptorImageInfo-mutableComparisonSamplers-04450", ], - }); + })); } if image_view.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the image view has a sampler YCbCr conversion, and the \ descriptor set layout was not created with immutable samplers" .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-02738"], ..Default::default() - }); + })); } if sampler.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the sampler has a sampler YCbCr conversion".into(), // vuids? ..Default::default() - }); + })); } sampler @@ -728,7 +728,7 @@ impl WriteDescriptorSet { { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -737,7 +737,7 @@ impl WriteDescriptorSet { ) .into(), ..Default::default() - }); + })); }; let immutable_samplers = &layout_binding.immutable_samplers @@ -760,7 +760,7 @@ impl WriteDescriptorSet { validate_image_view(image_view.as_ref(), index)?; if !image_view.usage().intersects(ImageUsage::SAMPLED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::SampledImage` or \ @@ -769,7 +769,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00337"], ..Default::default() - }); + })); } if !matches!( @@ -782,7 +782,7 @@ impl WriteDescriptorSet { | ImageLayout::DepthReadOnlyOptimal | ImageLayout::StencilReadOnlyOptimal, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::CombinedImageSampler`, and the image layout \ @@ -790,7 +790,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-04150"], ..Default::default() - }); + })); } sampler @@ -804,7 +804,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::ImageView(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -814,7 +814,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, image_view_info) in elements.iter().enumerate() { @@ -832,7 +832,7 @@ impl WriteDescriptorSet { validate_image_view(image_view.as_ref(), index)?; if !image_view.usage().intersects(ImageUsage::SAMPLED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::SampledImage` or \ @@ -841,7 +841,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00337"], ..Default::default() - }); + })); } if !matches!( @@ -854,7 +854,7 @@ impl WriteDescriptorSet { | ImageLayout::DepthReadOnlyOptimal | ImageLayout::StencilReadOnlyOptimal, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::SampledImage`, and the image layout is \ @@ -862,18 +862,18 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-04149"], ..Default::default() - }); + })); } if image_view.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::SampledImage`, and \ the image view has a sampler YCbCr conversion" .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-01946"], ..Default::default() - }); + })); } } } @@ -882,7 +882,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::ImageView(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -892,7 +892,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, image_view_info) in elements.iter().enumerate() { @@ -910,7 +910,7 @@ impl WriteDescriptorSet { validate_image_view(image_view.as_ref(), index)?; if !image_view.usage().intersects(ImageUsage::STORAGE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::StorageImage`, and the image was not \ @@ -918,11 +918,11 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00339"], ..Default::default() - }); + })); } if !matches!(image_layout, ImageLayout::General) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::StorageImage`, and the image layout is \ @@ -930,11 +930,11 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-04152"], ..Default::default() - }); + })); } if !image_view.component_mapping().is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::StorageImage` or \ `DescriptorType::InputAttachment`, and the image view is not \ @@ -942,16 +942,16 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00336"], ..Default::default() - }); + })); } if image_view.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the image view has a sampler YCbCr conversion".into(), // vuids? ..Default::default() - }); + })); } } } @@ -960,7 +960,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::BufferView(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -970,7 +970,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, buffer_view) in elements.iter().enumerate() { @@ -982,7 +982,7 @@ impl WriteDescriptorSet { .usage() .intersects(BufferUsage::UNIFORM_TEXEL_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::UniformTexelBuffer`, and the buffer was not \ @@ -990,7 +990,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00334"], ..Default::default() - }); + })); } } } @@ -999,7 +999,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::BufferView(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1009,7 +1009,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, buffer_view) in elements.iter().enumerate() { @@ -1022,7 +1022,7 @@ impl WriteDescriptorSet { .usage() .intersects(BufferUsage::STORAGE_TEXEL_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::StorageTexelBuffer`, and the buffer was not \ @@ -1030,7 +1030,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00335"], ..Default::default() - }); + })); } } } @@ -1039,7 +1039,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::Buffer(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1049,7 +1049,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, buffer_info) in elements.iter().enumerate() { @@ -1062,7 +1062,7 @@ impl WriteDescriptorSet { .usage() .intersects(BufferUsage::UNIFORM_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::UniformBuffer` or \ `DescriptorType::UniformBufferDynamic`, and the buffer was not \ @@ -1070,19 +1070,19 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00330"], ..Default::default() - }); + })); } assert!(!range.is_empty()); if range.end > buffer.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the end of the range is greater than the size of the buffer" .into(), vuids: &["VUID-VkDescriptorBufferInfo-range-00342"], ..Default::default() - }); + })); } } } @@ -1091,7 +1091,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::Buffer(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1101,7 +1101,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, buffer_info) in elements.iter().enumerate() { @@ -1114,7 +1114,7 @@ impl WriteDescriptorSet { .usage() .intersects(BufferUsage::STORAGE_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::StorageBuffer` or \ `DescriptorType::StorageBufferDynamic`, and the buffer was not \ @@ -1122,19 +1122,19 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00331"], ..Default::default() - }); + })); } assert!(!range.is_empty()); if range.end > buffer.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the end of the range is greater than the size of the buffer" .into(), vuids: &["VUID-VkDescriptorBufferInfo-range-00342"], ..Default::default() - }); + })); } } } @@ -1143,7 +1143,7 @@ impl WriteDescriptorSet { let elements = if let WriteDescriptorSetElements::ImageView(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1153,7 +1153,7 @@ impl WriteDescriptorSet { .into(), // vuids? ..Default::default() - }); + })); }; for (index, image_view_info) in elements.iter().enumerate() { @@ -1171,7 +1171,7 @@ impl WriteDescriptorSet { validate_image_view(image_view.as_ref(), index)?; if !image_view.usage().intersects(ImageUsage::INPUT_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::InputAttachment`, and the image was not \ @@ -1179,7 +1179,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00338"], ..Default::default() - }); + })); } if !matches!( @@ -1192,7 +1192,7 @@ impl WriteDescriptorSet { | ImageLayout::DepthReadOnlyOptimal | ImageLayout::StencilReadOnlyOptimal, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is \ `DescriptorType::InputAttachment`, and the image layout is \ @@ -1200,11 +1200,11 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-04151"], ..Default::default() - }); + })); } if !image_view.component_mapping().is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::StorageImage` or \ `DescriptorType::InputAttachment`, and the image view is not \ @@ -1212,18 +1212,18 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-00336"], ..Default::default() - }); + })); } if image_view.sampler_ycbcr_conversion().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the descriptor type is `DescriptorType::InputAttachment`, \ and the image view has a sampler YCbCr conversion" .into(), // vuids? ..Default::default() - }); + })); } } } @@ -1232,7 +1232,7 @@ impl WriteDescriptorSet { let data = if let WriteDescriptorSetElements::InlineUniformBlock(data) = elements { data } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1241,11 +1241,11 @@ impl WriteDescriptorSet { ) .into(), ..Default::default() - }); + })); }; if data.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "data".into(), problem: "is empty".into(), vuids: &[ @@ -1253,11 +1253,11 @@ impl WriteDescriptorSet { "VUID-VkWriteDescriptorSet-descriptorCount-arraylength", ], ..Default::default() - }); + })); } if data.len() % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "data".into(), problem: "the length is not a multiple of 4".into(), vuids: &[ @@ -1265,16 +1265,16 @@ impl WriteDescriptorSet { "VUID-VkWriteDescriptorSet-descriptorType-02220", ], ..Default::default() - }); + })); } if first_array_element % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "offset".into(), problem: "is not a multiple of 4".into(), vuids: &["VUID-VkWriteDescriptorSet-descriptorType-02219"], ..Default::default() - }); + })); } } @@ -1283,7 +1283,7 @@ impl WriteDescriptorSet { if let WriteDescriptorSetElements::AccelerationStructure(elements) = elements { elements } else { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "elements".into(), problem: format!( "contains `{}` elements, but the descriptor set \ @@ -1292,7 +1292,7 @@ impl WriteDescriptorSet { ) .into(), ..Default::default() - }); + })); }; for (index, acceleration_structure) in elements.iter().enumerate() { @@ -1302,7 +1302,7 @@ impl WriteDescriptorSet { acceleration_structure.ty(), AccelerationStructureType::TopLevel | AccelerationStructureType::Generic ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("elements[{}]", index).into(), problem: "the acceleration structure's type is not \ `AccelerationStructureType::TopLevel` or \ @@ -1310,7 +1310,7 @@ impl WriteDescriptorSet { .into(), vuids: &["VUID-VkWriteDescriptorSetAccelerationStructureKHR-pAccelerationStructures-03579"], ..Default::default() - }); + })); } } } @@ -1620,7 +1620,7 @@ impl CopyDescriptorSet { &self, dst_set_layout: &DescriptorSetLayout, dst_set_variable_descriptor_count: u32, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let &Self { ref src_set, src_binding, @@ -1637,13 +1637,13 @@ impl CopyDescriptorSet { let src_layout_binding = match src_set.layout().bindings().get(&src_binding) { Some(layout_binding) => layout_binding, None => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_binding` does not exist in the descriptor set layout of \ `src_set`" .into(), vuids: &["VUID-VkCopyDescriptorSet-srcBinding-00345"], ..Default::default() - }); + })); } }; @@ -1657,25 +1657,25 @@ impl CopyDescriptorSet { }; if src_first_array_element + descriptor_count > src_max_descriptor_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_first_array_element` + `descriptor_count` is greater than \ the number of descriptors in `src_set`'s descriptor set binding" .into(), vuids: &["VUID-VkCopyDescriptorSet-srcArrayElement-00346"], ..Default::default() - }); + })); } let dst_layout_binding = match dst_set_layout.bindings().get(&dst_binding) { Some(layout_binding) => layout_binding, None => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dst_binding` does not exist in the descriptor set layout of \ `dst_set`" .into(), vuids: &["VUID-VkCopyDescriptorSet-dstBinding-00347"], ..Default::default() - }); + })); } }; @@ -1689,70 +1689,70 @@ impl CopyDescriptorSet { }; if dst_first_array_element + descriptor_count > dst_max_descriptor_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dst_first_array_element` + `descriptor_count` is greater than \ the number of descriptors in `dst_set`'s descriptor set binding" .into(), vuids: &["VUID-VkCopyDescriptorSet-dstArrayElement-00348"], ..Default::default() - }); + })); } if src_layout_binding.descriptor_type != dst_layout_binding.descriptor_type { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type of `src_binding` within `src_set` does not equal \ the descriptor type of `dst_binding` within `dst_set`" .into(), vuids: &["VUID-VkCopyDescriptorSet-dstBinding-02632"], ..Default::default() - }); + })); } if dst_layout_binding.descriptor_type == DescriptorType::Sampler && !dst_layout_binding.immutable_samplers.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type of `dst_binding` within `dst_set` is \ `DescriptorType::Sampler`, and the layout was created with immutable samplers \ for `dst_binding`" .into(), vuids: &["VUID-VkCopyDescriptorSet-dstBinding-02753"], ..Default::default() - }); + })); } if dst_layout_binding.descriptor_type == DescriptorType::InlineUniformBlock { if src_first_array_element % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type of `src_binding` within `src_set` is \ `DescriptorType::InlineUniformBlock`, and `src_first_array_element` is \ not a multiple of 4" .into(), vuids: &["VUID-VkCopyDescriptorSet-srcBinding-02223"], ..Default::default() - }); + })); } if dst_first_array_element % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type of `dst_binding` within `dst_set` is \ `DescriptorType::InlineUniformBlock`, and `dst_first_array_element` is \ not a multiple of 4" .into(), vuids: &["VUID-VkCopyDescriptorSet-dstBinding-02224"], ..Default::default() - }); + })); } if descriptor_count % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the descriptor type of `dst_binding` within `dst_set` is \ `DescriptorType::InlineUniformBlock`, and `descriptor_count` is \ not a multiple of 4" .into(), vuids: &["VUID-VkCopyDescriptorSet-srcBinding-02225"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/device/mod.rs b/vulkano/src/device/mod.rs index 3be32e9a..a86f96cb 100644 --- a/vulkano/src/device/mod.rs +++ b/vulkano/src/device/mod.rs @@ -119,7 +119,7 @@ use crate::{ instance::{Instance, InstanceOwned, InstanceOwnedDebugWrapper}, macros::{impl_id_counter, vulkan_bitflags}, memory::ExternalMemoryHandleType, - OomError, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + OomError, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use ash::vk::Handle; @@ -178,7 +178,8 @@ impl Device { pub fn new( physical_device: Arc, create_info: DeviceCreateInfo, - ) -> Result<(Arc, impl ExactSizeIterator>), VulkanError> { + ) -> Result<(Arc, impl ExactSizeIterator>), Validated> + { Self::validate_new(&physical_device, &create_info)?; unsafe { Ok(Self::new_unchecked(physical_device, create_info)?) } @@ -187,7 +188,7 @@ impl Device { fn validate_new( physical_device: &PhysicalDevice, create_info: &DeviceCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { create_info .validate(physical_device) .map_err(|err| err.add_context("create_info"))?; @@ -205,13 +206,13 @@ impl Device { .iter() .any(|p| p.as_ref() == physical_device) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.physical_devices` is not empty, but does not contain \ `physical_device`" .into(), vuids: &["VUID-VkDeviceGroupDeviceCreateInfo-physicalDeviceCount-00377"], ..Default::default() - }); + })); } Ok(()) @@ -221,7 +222,7 @@ impl Device { pub unsafe fn new_unchecked( physical_device: Arc, mut create_info: DeviceCreateInfo, - ) -> Result<(Arc, impl ExactSizeIterator>), RuntimeError> { + ) -> Result<(Arc, impl ExactSizeIterator>), VulkanError> { // VUID-vkCreateDevice-ppEnabledExtensionNames-01387 create_info.enabled_extensions.enable_dependencies( physical_device.api_version(), @@ -377,7 +378,7 @@ impl Device { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -574,7 +575,7 @@ impl Device { build_type: AccelerationStructureBuildType, build_info: &AccelerationStructureBuildGeometryInfo, max_primitive_counts: &[u32], - ) -> Result { + ) -> Result> { self.validate_acceleration_structure_build_sizes( build_type, build_info, @@ -595,18 +596,18 @@ impl Device { build_type: AccelerationStructureBuildType, build_info: &AccelerationStructureBuildGeometryInfo, max_primitive_counts: &[u32], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.enabled_extensions().khr_acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_acceleration_structure", )])]), ..Default::default() - }); + })); } if !self.enabled_features().acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "acceleration_structure", )])]), @@ -614,7 +615,7 @@ impl Device { "VUID-vkGetAccelerationStructureBuildSizesKHR-accelerationStructure-08933", ], ..Default::default() - }); + })); } build_type @@ -645,12 +646,12 @@ impl Device { AccelerationStructureGeometries::Triangles(geometries) => { for (index, &primitive_count) in max_primitive_counts.iter().enumerate() { if primitive_count as u64 > max_primitive_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("max_primitive_counts[{}]", index).into(), problem: "exceeds the `max_primitive_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03795"], ..Default::default() - }); + })); } } @@ -659,12 +660,12 @@ impl Device { AccelerationStructureGeometries::Aabbs(geometries) => { for (index, &primitive_count) in max_primitive_counts.iter().enumerate() { if primitive_count as u64 > max_primitive_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("max_primitive_counts[{}]", index).into(), problem: "exceeds the `max_primitive_count` limit".into(), vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-type-03794"], ..Default::default() - }); + })); } } @@ -673,14 +674,14 @@ impl Device { AccelerationStructureGeometries::Instances(_) => { for (index, &instance_count) in max_primitive_counts.iter().enumerate() { if instance_count as u64 > max_instance_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("max_primitive_counts[{}]", index).into(), problem: "exceeds the `max_instance_count` limit".into(), vuids: &[ "VUID-vkGetAccelerationStructureBuildSizesKHR-pBuildInfo-03785", ], ..Default::default() - }); + })); } } @@ -689,13 +690,13 @@ impl Device { }; if max_primitive_counts.len() != geometry_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`build_info.geometries` and `max_primitive_counts` \ do not have the same length" .into(), vuids: &["VUID-vkGetAccelerationStructureBuildSizesKHR-pBuildInfo-03619"], ..Default::default() - }); + })); } Ok(()) @@ -741,7 +742,7 @@ impl Device { pub fn acceleration_structure_is_compatible( &self, version_data: &[u8; 2 * ash::vk::UUID_SIZE], - ) -> Result { + ) -> Result> { self.validate_acceleration_structure_is_compatible(version_data)?; unsafe { Ok(self.acceleration_structure_is_compatible_unchecked(version_data)) } @@ -750,24 +751,24 @@ impl Device { fn validate_acceleration_structure_is_compatible( &self, _version_data: &[u8; 2 * ash::vk::UUID_SIZE], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.enabled_extensions().khr_acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_acceleration_structure", )])]), ..Default::default() - }); + })); } if !self.enabled_features().acceleration_structure { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::Feature("acceleration_structure")]), ]), vuids: &["VUID-vkGetDeviceAccelerationStructureCompatibilityKHR-accelerationStructure-08928"], ..Default::default() - }); + })); } Ok(()) @@ -812,7 +813,7 @@ impl Device { pub fn descriptor_set_layout_support( &self, create_info: &DescriptorSetLayoutCreateInfo, - ) -> Result, ValidationError> { + ) -> Result, Box> { self.validate_descriptor_set_layout_support(create_info)?; unsafe { Ok(self.descriptor_set_layout_support_unchecked(create_info)) } @@ -821,15 +822,15 @@ impl Device { fn validate_descriptor_set_layout_support( &self, create_info: &DescriptorSetLayoutCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self.api_version() >= Version::V1_1 || self.enabled_extensions().khr_maintenance3) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), RequiresAllOf(&[Requires::DeviceExtension("khr_maintenance3")]), ]), ..Default::default() - }); + })); } // VUID-vkGetDescriptorSetLayoutSupport-pCreateInfo-parameter @@ -957,7 +958,7 @@ impl Device { &self, handle_type: ExternalMemoryHandleType, file: File, - ) -> Result { + ) -> Result> { self.validate_memory_fd_properties(handle_type, &file)?; Ok(self.memory_fd_properties_unchecked(handle_type, file)?) @@ -967,14 +968,14 @@ impl Device { &self, handle_type: ExternalMemoryHandleType, _file: &File, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.enabled_extensions().khr_external_memory_fd { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_external_memory_fd", )])]), ..Default::default() - }); + })); } handle_type @@ -986,12 +987,12 @@ impl Device { })?; if handle_type == ExternalMemoryHandleType::OpaqueFd { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "handle_type".into(), problem: "is `ExternalMemoryHandleType::OpaqueFd`".into(), vuids: &["VUID-vkGetMemoryFdPropertiesKHR-handleType-00674"], ..Default::default() - }); + })); } Ok(()) @@ -1003,7 +1004,7 @@ impl Device { &self, handle_type: ExternalMemoryHandleType, file: File, - ) -> Result { + ) -> Result { #[cfg(not(unix))] unreachable!("`khr_external_memory_fd` was somehow enabled on a non-Unix system"); @@ -1021,7 +1022,7 @@ impl Device { &mut memory_fd_properties, ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(MemoryFdProperties { memory_type_bits: memory_fd_properties.memory_type_bits, @@ -1056,7 +1057,7 @@ impl Device { let fns = self.instance().fns(); (fns.ext_debug_utils.set_debug_utils_object_name_ext)(self.handle, &info) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Ok(()) @@ -1077,7 +1078,7 @@ impl Device { let fns = self.fns(); (fns.v1_0.device_wait_idle)(self.handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -1230,7 +1231,10 @@ impl Default for DeviceCreateInfo { } impl DeviceCreateInfo { - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { ref queue_create_infos, ref enabled_extensions, @@ -1240,12 +1244,12 @@ impl DeviceCreateInfo { } = self; if queue_create_infos.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_create_infos".into(), problem: "is empty".into(), vuids: &["VUID-VkDeviceCreateInfo-queueCreateInfoCount-arraylength"], ..Default::default() - }); + })); } for (index, queue_create_info) in queue_create_infos.iter().enumerate() { @@ -1266,7 +1270,7 @@ impl DeviceCreateInfo { .count() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`queue_create_infos[{}].queue_family_index` occurs more than once in \ `queue_create_infos`", @@ -1275,7 +1279,7 @@ impl DeviceCreateInfo { .into(), vuids: &["VUID-VkDeviceCreateInfo-queueFamilyIndex-02802"], ..Default::default() - }); + })); } } @@ -1312,175 +1316,175 @@ impl DeviceCreateInfo { if enabled_extensions.ext_buffer_device_address { if enabled_extensions.khr_buffer_device_address { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_extensions".into(), problem: "contains `khr_buffer_device_address`, \ but also contains `ext_buffer_device_address`" .into(), vuids: &["VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-03328"], ..Default::default() - }); + })); } else if dependency_extensions.khr_buffer_device_address { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_extensions".into(), problem: "contains an extension that requires `khr_buffer_device_address`, \ but also contains `ext_buffer_device_address`" .into(), vuids: &["VUID-VkDeviceCreateInfo-ppEnabledExtensionNames-03328"], ..Default::default() - }); + })); } if physical_device.api_version() >= Version::V1_2 && enabled_features.buffer_device_address { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the physical device API version is at least 1.2, \ `enabled_features` contains `buffer_device_address`, and \ `enabled_extensions` contains `ext_buffer_device_address`" .into(), vuids: &["VUID-VkDeviceCreateInfo-pNext-04748"], ..Default::default() - }); + })); } } if enabled_features.shading_rate_image { if enabled_features.pipeline_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `shading_rate_image` and \ `pipeline_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04478"], ..Default::default() - }); + })); } if enabled_features.primitive_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `shading_rate_image` and \ `primitive_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04479"], ..Default::default() - }); + })); } if enabled_features.attachment_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `shading_rate_image` and \ `attachment_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04480"], ..Default::default() - }); + })); } } if enabled_features.fragment_density_map { if enabled_features.pipeline_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `fragment_density_map` and \ `pipeline_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04481"], ..Default::default() - }); + })); } if enabled_features.primitive_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `fragment_density_map` and \ `primitive_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04482"], ..Default::default() - }); + })); } if enabled_features.attachment_fragment_shading_rate { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains both `fragment_density_map` and \ `attachment_fragment_shading_rate`" .into(), vuids: &["VUID-VkDeviceCreateInfo-shadingRateImage-04483"], ..Default::default() - }); + })); } } if enabled_features.sparse_image_int64_atomics && !enabled_features.shader_image_int64_atomics { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains `sparse_image_int64_atomics`, but does not contain \ `shader_image_int64_atomics`" .into(), vuids: &["VUID-VkDeviceCreateInfo-None-04896"], ..Default::default() - }); + })); } if enabled_features.sparse_image_float32_atomics && !enabled_features.shader_image_float32_atomics { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains `sparse_image_float32_atomics`, but does not contain \ `shader_image_float32_atomics`" .into(), vuids: &["VUID-VkDeviceCreateInfo-None-04897"], ..Default::default() - }); + })); } if enabled_features.sparse_image_float32_atomic_add && !enabled_features.shader_image_float32_atomic_add { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains `sparse_image_float32_atomic_add`, but does not contain \ `shader_image_float32_atomic_add`" .into(), vuids: &["VUID-VkDeviceCreateInfo-None-04898"], ..Default::default() - }); + })); } if enabled_features.sparse_image_float32_atomic_min_max && !enabled_features.shader_image_float32_atomic_min_max { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_features".into(), problem: "contains `sparse_image_float32_atomic_min_max`, but does not contain \ `shader_image_float32_atomic_min_max`" .into(), vuids: &["VUID-VkDeviceCreateInfo-sparseImageFloat32AtomicMinMax-04975"], ..Default::default() - }); + })); } if enabled_features.descriptor_buffer && enabled_extensions.amd_shader_fragment_mask { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`enabled_features` contains `descriptor_buffer`, and \ `enabled_extensions` contains `amd_shader_fragment_mask`" .into(), vuids: &["VUID-VkDeviceCreateInfo-None-08095"], ..Default::default() - }); + })); } if physical_devices.len() > 1 { for (index, group_physical_device) in physical_devices.iter().enumerate() { if physical_devices[..index].contains(group_physical_device) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "physical_devices".into(), problem: format!( "the physical device at index {} is contained in the list more than \ @@ -1490,7 +1494,7 @@ impl DeviceCreateInfo { .into(), vuids: &["VUID-VkDeviceGroupDeviceCreateInfo-pPhysicalDevices-00375"], ..Default::default() - }); + })); } } @@ -1500,7 +1504,7 @@ impl DeviceCreateInfo { .enabled_extensions() .khr_device_group_creation) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "physical_devices".into(), problem: "the length is greater than 1".into(), requires_one_of: RequiresOneOf(&[ @@ -1508,20 +1512,20 @@ impl DeviceCreateInfo { RequiresAllOf(&[Requires::InstanceExtension("khr_device_group_creation")]), ]), ..Default::default() - }); + })); } if !physical_device .instance() .is_same_device_group(physical_devices.iter().map(AsRef::as_ref)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "physical_devices".into(), problem: "the physical devices do not all belong to the same device group" .into(), vuids: &["VUID-VkDeviceGroupDeviceCreateInfo-pPhysicalDevices-00376"], ..Default::default() - }); + })); } } @@ -1573,7 +1577,7 @@ impl QueueCreateInfo { physical_device: &PhysicalDevice, device_extensions: &DeviceExtensions, device_features: &Features, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let &Self { flags, queue_family_index, @@ -1606,32 +1610,32 @@ impl QueueCreateInfo { })?; if queues.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queues".into(), problem: "is empty".into(), vuids: &["VUID-VkDeviceQueueCreateInfo-queueCount-arraylength"], ..Default::default() - }); + })); } if queues.len() > queue_family_properties.queue_count as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the length of `queues` is greater than the number of queues in the queue family indicated by `queue_family_index`" .into(), vuids: &["VUID-VkDeviceQueueCreateInfo-queueCount-00382"], ..Default::default() - }); + })); } for (index, &priority) in queues.iter().enumerate() { if !(0.0..=1.0).contains(&priority) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("queues[{}]", index).into(), problem: "is not between 0.0 and 1.0 inclusive".into(), vuids: &["VUID-VkDeviceQueueCreateInfo-pQueuePriorities-00383"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/device/physical.rs b/vulkano/src/device/physical.rs index 56f8ebbf..df1039b9 100644 --- a/vulkano/src/device/physical.rs +++ b/vulkano/src/device/physical.rs @@ -29,7 +29,7 @@ use crate::{ semaphore::{ExternalSemaphoreInfo, ExternalSemaphoreProperties}, Sharing, }, - DebugWrapper, ExtensionProperties, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, + DebugWrapper, ExtensionProperties, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use bytemuck::cast_slice; @@ -95,7 +95,7 @@ impl PhysicalDevice { pub unsafe fn from_handle( instance: Arc, handle: ash::vk::PhysicalDevice, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let api_version = Self::get_api_version(handle, &instance); let extension_properties = Self::get_extension_properties(handle, &instance)?; let supported_extensions: DeviceExtensions = extension_properties @@ -160,7 +160,7 @@ impl PhysicalDevice { unsafe fn get_extension_properties( handle: ash::vk::PhysicalDevice, instance: &Instance, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let fns = instance.fns(); loop { @@ -172,7 +172,7 @@ impl PhysicalDevice { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut output = Vec::with_capacity(count as usize); let result = (fns.v1_0.enumerate_device_extension_properties)( @@ -188,7 +188,7 @@ impl PhysicalDevice { return Ok(output.into_iter().map(Into::into).collect()); } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } } } @@ -429,7 +429,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, dfb: *const D, - ) -> Result { + ) -> Result> { self.validate_directfb_presentation_support(queue_family_index, dfb)?; Ok(self.directfb_presentation_support_unchecked(queue_family_index, dfb)) @@ -439,18 +439,18 @@ impl PhysicalDevice { &self, queue_family_index: u32, _dfb: *const D, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().ext_directfb_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_directfb_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -458,7 +458,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-queueFamilyIndex-04119", ], ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceDirectFBPresentationSupportEXT-dfb-parameter @@ -496,7 +496,7 @@ impl PhysicalDevice { pub fn external_buffer_properties( &self, info: ExternalBufferInfo, - ) -> Result { + ) -> Result> { self.validate_external_buffer_properties(&info)?; unsafe { Ok(self.external_buffer_properties_unchecked(info)) } @@ -505,14 +505,14 @@ impl PhysicalDevice { fn validate_external_buffer_properties( &self, info: &ExternalBufferInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self.instance.api_version() >= Version::V1_1 || self .instance .enabled_extensions() .khr_external_memory_capabilities) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), RequiresAllOf(&[Requires::InstanceExtension( @@ -520,7 +520,7 @@ impl PhysicalDevice { )]), ]), ..Default::default() - }); + })); } info.validate(self).map_err(|err| err.add_context("info"))?; @@ -596,7 +596,7 @@ impl PhysicalDevice { pub fn external_fence_properties( &self, info: ExternalFenceInfo, - ) -> Result { + ) -> Result> { self.validate_external_fence_properties(&info)?; unsafe { Ok(self.external_fence_properties_unchecked(info)) } @@ -605,14 +605,14 @@ impl PhysicalDevice { fn validate_external_fence_properties( &self, info: &ExternalFenceInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self.instance.api_version() >= Version::V1_1 || self .instance .enabled_extensions() .khr_external_fence_capabilities) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), RequiresAllOf(&[Requires::InstanceExtension( @@ -620,7 +620,7 @@ impl PhysicalDevice { )]), ]), ..Default::default() - }); + })); } info.validate(self).map_err(|err| err.add_context("info"))?; @@ -699,7 +699,7 @@ impl PhysicalDevice { pub fn external_semaphore_properties( &self, info: ExternalSemaphoreInfo, - ) -> Result { + ) -> Result> { self.validate_external_semaphore_properties(&info)?; unsafe { Ok(self.external_semaphore_properties_unchecked(info)) } @@ -708,14 +708,14 @@ impl PhysicalDevice { fn validate_external_semaphore_properties( &self, info: &ExternalSemaphoreInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self.instance.api_version() >= Version::V1_1 || self .instance .enabled_extensions() .khr_external_semaphore_capabilities) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), RequiresAllOf(&[Requires::InstanceExtension( @@ -723,7 +723,7 @@ impl PhysicalDevice { )]), ]), ..Default::default() - }); + })); } info.validate(self).map_err(|err| err.add_context("info"))?; @@ -797,13 +797,16 @@ impl PhysicalDevice { /// The results of this function are cached, so that future calls with the same arguments /// do not need to make a call to the Vulkan API again. #[inline] - pub fn format_properties(&self, format: Format) -> Result { + pub fn format_properties( + &self, + format: Format, + ) -> Result> { self.validate_format_properties(format)?; unsafe { Ok(self.format_properties_unchecked(format)) } } - fn validate_format_properties(&self, format: Format) -> Result<(), ValidationError> { + fn validate_format_properties(&self, format: Format) -> Result<(), Box> { format .validate_physical_device(self) .map_err(|err| ValidationError { @@ -993,7 +996,7 @@ impl PhysicalDevice { pub fn image_format_properties( &self, image_format_info: ImageFormatInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { self.validate_image_format_properties(&image_format_info)?; unsafe { Ok(self.image_format_properties_unchecked(image_format_info)?) } @@ -1002,7 +1005,7 @@ impl PhysicalDevice { fn validate_image_format_properties( &self, image_format_info: &ImageFormatInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { image_format_info .validate(self) .map_err(|err| err.add_context("image_format_info"))?; @@ -1015,7 +1018,7 @@ impl PhysicalDevice { pub unsafe fn image_format_properties_unchecked( &self, mut image_format_info: ImageFormatInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { { let ImageFormatInfo { format, @@ -1193,7 +1196,7 @@ impl PhysicalDevice { ) } .result() - .map_err(RuntimeError::from) + .map_err(VulkanError::from) }; Ok(match result { @@ -1211,7 +1214,7 @@ impl PhysicalDevice { }), ..properties2_vk.image_format_properties.into() }), - Err(RuntimeError::FormatNotSupported) => None, + Err(VulkanError::FormatNotSupported) => None, Err(err) => return Err(err), }) }) @@ -1227,7 +1230,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, window: *const W, - ) -> Result { + ) -> Result> { self.validate_qnx_screen_presentation_support(queue_family_index, window)?; Ok(self.qnx_screen_presentation_support_unchecked(queue_family_index, window)) @@ -1237,18 +1240,18 @@ impl PhysicalDevice { &self, queue_family_index: u32, _window: *const W, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().qnx_screen_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "qnx_screen_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -1256,7 +1259,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-queueFamilyIndex-04743", ], ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceScreenPresentationSupportQNX-window-parameter @@ -1292,7 +1295,7 @@ impl PhysicalDevice { pub fn sparse_image_format_properties( &self, format_info: SparseImageFormatInfo, - ) -> Result, ValidationError> { + ) -> Result, Box> { self.validate_sparse_image_format_properties(&format_info)?; unsafe { Ok(self.sparse_image_format_properties_unchecked(format_info)) } @@ -1301,7 +1304,7 @@ impl PhysicalDevice { fn validate_sparse_image_format_properties( &self, format_info: &SparseImageFormatInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { format_info .validate(self) .map_err(|err| err.add_context("format_info"))?; @@ -1470,7 +1473,7 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result { + ) -> Result> { self.validate_surface_capabilities(surface, &surface_info)?; unsafe { Ok(self.surface_capabilities_unchecked(surface, surface_info)?) } @@ -1480,20 +1483,20 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: &SurfaceInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self .instance .enabled_extensions() .khr_get_surface_capabilities2 || self.instance.enabled_extensions().khr_surface) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::InstanceExtension("khr_get_surface_capabilities2")]), RequiresAllOf(&[Requires::InstanceExtension("khr_surface")]), ]), ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceSurfaceCapabilities2KHR-commonparent @@ -1503,12 +1506,12 @@ impl PhysicalDevice { self.surface_support_unchecked(index, surface) .unwrap_or_default() }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface".into(), problem: "is not supported by the physical device".into(), vuids: &["VUID-vkGetPhysicalDeviceSurfaceCapabilities2KHR-pSurfaceInfo-06210"], ..Default::default() - }); + })); } surface_info @@ -1533,11 +1536,11 @@ impl PhysicalDevice { }; if !present_modes.any(|mode| mode == present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface_info.present_mode` is not supported for `surface`".into(), vuids: &["VUID-VkSurfacePresentModeEXT-presentMode-07780"], ..Default::default() - }); + })); } } @@ -1547,7 +1550,7 @@ impl PhysicalDevice { win32_monitor.is_some(), ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is a Win32 surface, and \ `surface_info.full_screen_exclusive` is \ `FullScreenExclusive::ApplicationControlled`, but \ @@ -1555,17 +1558,17 @@ impl PhysicalDevice { .into(), vuids: &["VUID-VkPhysicalDeviceSurfaceInfo2KHR-pNext-02672"], ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is not a Win32 surface, or \ `surface_info.full_screen_exclusive` is not \ `FullScreenExclusive::ApplicationControlled`, but \ `surface_info.win32_monitor` is `Some`" .into(), ..Default::default() - }); + })); } (true, true) | (false, false) => (), } @@ -1578,7 +1581,7 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result { + ) -> Result { /* Input */ let SurfaceInfo { @@ -1696,7 +1699,7 @@ impl PhysicalDevice { &mut capabilities_vk, ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } else { (fns.khr_surface.get_physical_device_surface_capabilities_khr)( self.handle(), @@ -1704,7 +1707,7 @@ impl PhysicalDevice { &mut capabilities_vk.surface_capabilities, ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; }; Ok(SurfaceCapabilities { @@ -1835,7 +1838,7 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { self.validate_surface_formats(surface, &surface_info)?; unsafe { Ok(self.surface_formats_unchecked(surface, surface_info)?) } @@ -1845,20 +1848,20 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: &SurfaceInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !(self .instance .enabled_extensions() .khr_get_surface_capabilities2 || self.instance.enabled_extensions().khr_surface) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::InstanceExtension("khr_get_surface_capabilities2")]), RequiresAllOf(&[Requires::InstanceExtension("khr_surface")]), ]), ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceSurfaceFormats2KHR-commonparent @@ -1868,12 +1871,12 @@ impl PhysicalDevice { self.surface_support_unchecked(index, surface) .unwrap_or_default() }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface".into(), problem: "is not supported by the physical device".into(), vuids: &["VUID-vkGetPhysicalDeviceSurfaceFormats2KHR-pSurfaceInfo-06522"], ..Default::default() - }); + })); } surface_info @@ -1898,11 +1901,11 @@ impl PhysicalDevice { }; if !present_modes.any(|mode| mode == present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface_info.present_mode` is not supported for `surface`".into(), vuids: &["VUID-VkSurfacePresentModeEXT-presentMode-07780"], ..Default::default() - }); + })); } } @@ -1912,25 +1915,25 @@ impl PhysicalDevice { .khr_get_surface_capabilities2 { if full_screen_exclusive != FullScreenExclusive::Default { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface_info.full_screen_exclusive".into(), problem: "is not `FullScreenExclusive::Default`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("khr_get_surface_capabilities2"), ])]), ..Default::default() - }); + })); } if win32_monitor.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface_info.win32_monitor".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("khr_get_surface_capabilities2"), ])]), ..Default::default() - }); + })); } } @@ -1940,7 +1943,7 @@ impl PhysicalDevice { win32_monitor.is_some(), ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is a Win32 surface, and \ `surface_info.full_screen_exclusive` is \ `FullScreenExclusive::ApplicationControlled`, but \ @@ -1948,17 +1951,17 @@ impl PhysicalDevice { .into(), vuids: &["VUID-VkPhysicalDeviceSurfaceInfo2KHR-pNext-02672"], ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is not a Win32 surface, or \ `surface_info.full_screen_exclusive` is not \ `FullScreenExclusive::ApplicationControlled`, but \ `surface_info.win32_monitor` is `Some`" .into(), ..Default::default() - }); + })); } (true, true) | (false, false) => (), } @@ -1971,7 +1974,7 @@ impl PhysicalDevice { &self, surface: &Surface, surface_info: SurfaceInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { surface.surface_formats.get_or_try_insert( (self.handle, surface_info), |(_, surface_info)| { @@ -2041,7 +2044,7 @@ impl PhysicalDevice { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut surface_format2s_vk = vec![ash::vk::SurfaceFormat2KHR::default(); count as usize]; @@ -2060,7 +2063,7 @@ impl PhysicalDevice { break surface_format2s_vk; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -2081,7 +2084,7 @@ impl PhysicalDevice { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut surface_formats = Vec::with_capacity(count as usize); let result = (fns.khr_surface.get_physical_device_surface_formats_khr)( @@ -2097,7 +2100,7 @@ impl PhysicalDevice { break surface_formats; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -2124,20 +2127,23 @@ impl PhysicalDevice { pub fn surface_present_modes( &self, surface: &Surface, - ) -> Result, VulkanError> { + ) -> Result, Validated> { self.validate_surface_present_modes(surface)?; unsafe { Ok(self.surface_present_modes_unchecked(surface)?) } } - fn validate_surface_present_modes(&self, surface: &Surface) -> Result<(), ValidationError> { + fn validate_surface_present_modes( + &self, + surface: &Surface, + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_surface", )])]), ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceSurfacePresentModesKHR-commonparent @@ -2147,12 +2153,12 @@ impl PhysicalDevice { self.surface_support_unchecked(index, surface) .unwrap_or_default() }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface".into(), problem: "is not supported by the physical device".into(), vuids: &["VUID-vkGetPhysicalDeviceSurfacePresentModesKHR-surface-06525"], ..Default::default() - }); + })); } Ok(()) @@ -2162,7 +2168,7 @@ impl PhysicalDevice { pub unsafe fn surface_present_modes_unchecked( &self, surface: &Surface, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { surface .surface_present_modes .get_or_try_insert(self.handle, |_| { @@ -2178,7 +2184,7 @@ impl PhysicalDevice { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut modes = Vec::with_capacity(count as usize); let result = (fns @@ -2196,7 +2202,7 @@ impl PhysicalDevice { break modes; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -2217,7 +2223,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, surface: &Surface, - ) -> Result { + ) -> Result> { self.validate_surface_support(queue_family_index, surface)?; unsafe { Ok(self.surface_support_unchecked(queue_family_index, surface)?) } @@ -2227,24 +2233,24 @@ impl PhysicalDevice { &self, queue_family_index: u32, _surface: &Surface, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), vuids: &["VUID-vkGetPhysicalDeviceSurfaceSupportKHR-queueFamilyIndex-01269"], ..Default::default() - }); + })); } Ok(()) @@ -2255,7 +2261,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, surface: &Surface, - ) -> Result { + ) -> Result { surface .surface_support .get_or_try_insert((self.handle, queue_family_index), |_| { @@ -2269,7 +2275,7 @@ impl PhysicalDevice { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(output.assume_init() != 0) }) @@ -2284,21 +2290,21 @@ impl PhysicalDevice { /// [`ext_tooling_info`](crate::device::DeviceExtensions::ext_tooling_info) /// extension must be supported by the physical device. #[inline] - pub fn tool_properties(&self) -> Result, VulkanError> { + pub fn tool_properties(&self) -> Result, Validated> { self.validate_tool_properties()?; unsafe { Ok(self.tool_properties_unchecked()?) } } - fn validate_tool_properties(&self) -> Result<(), ValidationError> { + fn validate_tool_properties(&self) -> Result<(), Box> { if !(self.api_version() >= Version::V1_3 || self.supported_extensions().ext_tooling_info) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_3)]), RequiresAllOf(&[Requires::DeviceExtension("ext_tooling_info")]), ]), ..Default::default() - }); + })); } Ok(()) @@ -2306,7 +2312,7 @@ impl PhysicalDevice { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] #[inline] - pub unsafe fn tool_properties_unchecked(&self) -> Result, RuntimeError> { + pub unsafe fn tool_properties_unchecked(&self) -> Result, VulkanError> { let fns = self.instance.fns(); loop { @@ -2326,7 +2332,7 @@ impl PhysicalDevice { ) } .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut tool_properties = Vec::with_capacity(count as usize); let result = if self.api_version() >= Version::V1_3 { @@ -2375,7 +2381,7 @@ impl PhysicalDevice { }) .collect()); } - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } } } @@ -2390,7 +2396,7 @@ impl PhysicalDevice { &self, queue_family_index: u32, display: *const D, - ) -> Result { + ) -> Result> { self.validate_wayland_presentation_support(queue_family_index, display)?; Ok(self.wayland_presentation_support_unchecked(queue_family_index, display)) @@ -2400,18 +2406,18 @@ impl PhysicalDevice { &self, queue_family_index: u32, _display: *const D, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_wayland_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_wayland_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -2419,7 +2425,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceWaylandPresentationSupportKHR-queueFamilyIndex-01306", ], ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceWaylandPresentationSupportKHR-display-parameter @@ -2449,7 +2455,7 @@ impl PhysicalDevice { pub fn win32_presentation_support( &self, queue_family_index: u32, - ) -> Result { + ) -> Result> { self.validate_win32_presentation_support(queue_family_index)?; unsafe { Ok(self.win32_presentation_support_unchecked(queue_family_index)) } @@ -2458,18 +2464,18 @@ impl PhysicalDevice { fn validate_win32_presentation_support( &self, queue_family_index: u32, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_win32_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_win32_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -2477,7 +2483,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceWin32PresentationSupportKHR-queueFamilyIndex-01309", ], ..Default::default() - }); + })); } Ok(()) @@ -2504,7 +2510,7 @@ impl PhysicalDevice { queue_family_index: u32, connection: *const C, visual_id: ash::vk::xcb_visualid_t, - ) -> Result { + ) -> Result> { self.validate_xcb_presentation_support(queue_family_index, connection, visual_id)?; Ok(self.xcb_presentation_support_unchecked(queue_family_index, connection, visual_id)) @@ -2515,18 +2521,18 @@ impl PhysicalDevice { queue_family_index: u32, _connection: *const C, _visual_id: ash::vk::xcb_visualid_t, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_xcb_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_xcb_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -2534,7 +2540,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceXcbPresentationSupportKHR-queueFamilyIndex-01312", ], ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceXcbPresentationSupportKHR-connection-parameter @@ -2571,7 +2577,7 @@ impl PhysicalDevice { queue_family_index: u32, display: *const D, visual_id: ash::vk::VisualID, - ) -> Result { + ) -> Result> { self.validate_xlib_presentation_support(queue_family_index, display, visual_id)?; Ok(self.xlib_presentation_support_unchecked(queue_family_index, display, visual_id)) @@ -2582,18 +2588,18 @@ impl PhysicalDevice { queue_family_index: u32, _display: *const D, _visual_id: ash::vk::VisualID, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_xlib_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_xlib_surface", )])]), ..Default::default() - }); + })); } if queue_family_index >= self.queue_family_properties.len() as u32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_index".into(), problem: "is not less than the number of queue families in the physical device" .into(), @@ -2601,7 +2607,7 @@ impl PhysicalDevice { "VUID-vkGetPhysicalDeviceXlibPresentationSupportKHR-queueFamilyIndex-01315", ], ..Default::default() - }); + })); } // VUID-vkGetPhysicalDeviceXlibPresentationSupportKHR-dpy-parameter diff --git a/vulkano/src/device/queue.rs b/vulkano/src/device/queue.rs index b19d2879..e9677960 100644 --- a/vulkano/src/device/queue.rs +++ b/vulkano/src/device/queue.rs @@ -26,7 +26,7 @@ use crate::{ future::{AccessCheckError, FlushError, GpuFuture}, semaphore::SemaphoreState, }, - OomError, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + OomError, Requires, RequiresAllOf, RequiresOneOf, ValidationError, Version, VulkanError, VulkanObject, }; use ahash::HashMap; @@ -202,7 +202,7 @@ impl<'a> QueueGuard<'a> { &mut self, bind_infos: impl IntoIterator, fence: Option>, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let bind_infos: SmallVec<[_; 4]> = bind_infos.into_iter().collect(); let mut states = States::from_bind_infos(&bind_infos); @@ -221,7 +221,7 @@ impl<'a> QueueGuard<'a> { bind_infos: &SmallVec<[BindSparseInfo; 4]>, fence: Option<(&Arc, MutexGuard<'_, FenceState>)>, states: &mut States<'_>, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { struct PerBindSparseInfo { wait_semaphores_vk: SmallVec<[ash::vk::Semaphore; 4]>, buffer_bind_infos_vk: SmallVec<[ash::vk::SparseBufferMemoryBindInfo; 4]>, @@ -478,7 +478,7 @@ impl<'a> QueueGuard<'a> { .map_or_else(Default::default, |(fence, _)| fence.handle()), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; for bind_info in bind_infos { let BindSparseInfo { @@ -518,7 +518,7 @@ impl<'a> QueueGuard<'a> { pub unsafe fn present_unchecked( &mut self, present_info: PresentInfo, - ) -> Result>, RuntimeError> { + ) -> Result>, VulkanError> { let mut states = States::from_present_info(&present_info); self.present_unchecked_locked(&present_info, &mut states) } @@ -527,7 +527,7 @@ impl<'a> QueueGuard<'a> { &mut self, present_info: &PresentInfo, states: &mut States<'_>, - ) -> Result>, RuntimeError> { + ) -> Result>, VulkanError> { let PresentInfo { wait_semaphores, swapchain_infos, @@ -657,7 +657,7 @@ impl<'a> QueueGuard<'a> { | ash::vk::Result::ERROR_SURFACE_LOST_KHR | ash::vk::Result::ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT, ) { - return Err(RuntimeError::from(result)); + return Err(VulkanError::from(result)); } for semaphore in wait_semaphores { @@ -683,7 +683,7 @@ impl<'a> QueueGuard<'a> { Ok(results.into_iter().map(|result| match result { ash::vk::Result::SUCCESS => Ok(false), ash::vk::Result::SUBOPTIMAL_KHR => Ok(true), - err => Err(RuntimeError::from(err)), + err => Err(VulkanError::from(err)), })) } @@ -817,7 +817,7 @@ impl<'a> QueueGuard<'a> { &mut self, submit_infos: impl IntoIterator, fence: Option>, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let submit_infos: SmallVec<[_; 4]> = submit_infos.into_iter().collect(); let mut states = States::from_submit_infos(&submit_infos); @@ -836,7 +836,7 @@ impl<'a> QueueGuard<'a> { submit_infos: &SmallVec<[SubmitInfo; 4]>, fence: Option<(&Arc, MutexGuard<'_, FenceState>)>, states: &mut States<'_>, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { if self.queue.device.enabled_features().synchronization2 { struct PerSubmitInfo { wait_semaphore_infos_vk: SmallVec<[ash::vk::SemaphoreSubmitInfo; 4]>, @@ -965,7 +965,7 @@ impl<'a> QueueGuard<'a> { ) } .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } else { struct PerSubmitInfo { wait_semaphores_vk: SmallVec<[ash::vk::Semaphore; 4]>, @@ -1067,7 +1067,7 @@ impl<'a> QueueGuard<'a> { .map_or_else(Default::default, |(fence, _)| fence.handle()), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } for submit_info in submit_infos { @@ -1155,7 +1155,7 @@ impl<'a> QueueGuard<'a> { pub fn begin_debug_utils_label( &mut self, label_info: DebugUtilsLabel, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { self.validate_begin_debug_utils_label(&label_info)?; unsafe { @@ -1167,7 +1167,7 @@ impl<'a> QueueGuard<'a> { fn validate_begin_debug_utils_label( &self, _label_info: &DebugUtilsLabel, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue .device @@ -1175,12 +1175,12 @@ impl<'a> QueueGuard<'a> { .enabled_extensions() .ext_debug_utils { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_debug_utils", )])]), ..Default::default() - }); + })); } Ok(()) @@ -1216,14 +1216,14 @@ impl<'a> QueueGuard<'a> { /// - There must be an outstanding queue label region begun with `begin_debug_utils_label` in /// the queue. #[inline] - pub unsafe fn end_debug_utils_label(&mut self) -> Result<(), ValidationError> { + pub unsafe fn end_debug_utils_label(&mut self) -> Result<(), Box> { self.validate_end_debug_utils_label()?; self.end_debug_utils_label_unchecked(); Ok(()) } - fn validate_end_debug_utils_label(&self) -> Result<(), ValidationError> { + fn validate_end_debug_utils_label(&self) -> Result<(), Box> { if !self .queue .device @@ -1231,12 +1231,12 @@ impl<'a> QueueGuard<'a> { .enabled_extensions() .ext_debug_utils { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_debug_utils", )])]), ..Default::default() - }); + })); } // VUID-vkQueueEndDebugUtilsLabelEXT-None-01911 @@ -1260,7 +1260,7 @@ impl<'a> QueueGuard<'a> { pub fn insert_debug_utils_label( &mut self, label_info: DebugUtilsLabel, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { self.validate_insert_debug_utils_label(&label_info)?; unsafe { @@ -1272,7 +1272,7 @@ impl<'a> QueueGuard<'a> { fn validate_insert_debug_utils_label( &self, _label_info: &DebugUtilsLabel, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !self .queue .device @@ -1280,12 +1280,12 @@ impl<'a> QueueGuard<'a> { .enabled_extensions() .ext_debug_utils { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_debug_utils", )])]), ..Default::default() - }); + })); } Ok(()) @@ -1323,7 +1323,7 @@ impl QueueState { let fns = device.fns(); (fns.v1_0.queue_wait_idle)(handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; // Since we now know that the queue is finished with all work, // we can safely release all resources. diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index acc79fba..d117cf21 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -75,7 +75,7 @@ use crate::{ range_map::RangeMap, swapchain::Swapchain, sync::{future::AccessError, AccessConflict, CurrentAccess, Sharing}, - DeviceSize, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + DeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use parking_lot::{Mutex, MutexGuard}; @@ -146,15 +146,18 @@ impl Image { /// Creates a new uninitialized `Image`. pub fn new( allocator: &(impl MemoryAllocator + ?Sized), - image_info: ImageCreateInfo, + create_info: ImageCreateInfo, allocation_info: AllocationCreateInfo, - ) -> Result, ImageAllocateError> { + ) -> Result, Validated> { // TODO: adjust the code below to make this safe - assert!(!image_info.flags.intersects(ImageCreateFlags::DISJOINT)); + assert!(!create_info.flags.intersects(ImageCreateFlags::DISJOINT)); - let allocation_type = image_info.tiling.into(); - let raw_image = RawImage::new(allocator.device().clone(), image_info) - .map_err(ImageAllocateError::CreateImage)?; + let allocation_type = create_info.tiling.into(); + let raw_image = + RawImage::new(allocator.device().clone(), create_info).map_err(|err| match err { + Validated::Error(err) => Validated::Error(ImageAllocateError::CreateImage(err)), + Validated::ValidationError(err) => err.into(), + })?; let requirements = raw_image.memory_requirements()[0]; let allocation = unsafe { @@ -207,7 +210,7 @@ impl Image { handle: ash::vk::Image, swapchain: Arc, image_index: u32, - ) -> Result { + ) -> Result { let create_info = ImageCreateInfo { flags: ImageCreateFlags::empty(), image_type: ImageType::Dim2d, @@ -381,7 +384,7 @@ impl Image { aspect: ImageAspect, mip_level: u32, array_layer: u32, - ) -> Result { + ) -> Result> { self.inner .subresource_layout(aspect, mip_level, array_layer) } @@ -570,7 +573,7 @@ impl Hash for Image { pub enum ImageAllocateError { CreateImage(VulkanError), AllocateMemory(MemoryAllocatorError), - BindMemory(RuntimeError), + BindMemory(VulkanError), } impl Error for ImageAllocateError { @@ -593,6 +596,12 @@ impl Display for ImageAllocateError { } } +impl From for Validated { + fn from(err: ImageAllocateError) -> Self { + Self::Error(err) + } +} + /// The current state of an image. #[derive(Debug)] pub(crate) struct ImageState { @@ -1378,7 +1387,7 @@ impl ImageSubresourceLayers { } impl ImageSubresourceLayers { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { aspects, mip_level: _, @@ -1394,34 +1403,34 @@ impl ImageSubresourceLayers { })?; if aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "is empty".into(), vuids: &["VUID-VkImageSubresourceLayers-aspectMask-requiredbitmask"], ..Default::default() - }); + })); } if aspects.intersects(ImageAspects::COLOR) && aspects.intersects(ImageAspects::DEPTH | ImageAspects::STENCIL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "contains both `ImageAspects::COLOR`, and either `ImageAspects::DEPTH` \ or `ImageAspects::STENCIL`" .into(), vuids: &["VUID-VkImageSubresourceLayers-aspectMask-00167"], ..Default::default() - }); + })); } if aspects.intersects(ImageAspects::METADATA) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "contains `ImageAspects::METADATA`".into(), vuids: &["VUID-VkImageSubresourceLayers-aspectMask-00168"], ..Default::default() - }); + })); } if aspects.intersects( @@ -1430,7 +1439,7 @@ impl ImageSubresourceLayers { | ImageAspects::MEMORY_PLANE_2 | ImageAspects::MEMORY_PLANE_3, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "contains `ImageAspects::MEMORY_PLANE_0`, \ `ImageAspects::MEMORY_PLANE_1`, `ImageAspects::MEMORY_PLANE_2` or \ @@ -1438,16 +1447,16 @@ impl ImageSubresourceLayers { .into(), vuids: &["VUID-VkImageSubresourceLayers-aspectMask-02247"], ..Default::default() - }); + })); } if array_layers.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "array_layers".into(), problem: "is empty".into(), vuids: &["VUID-VkImageSubresourceLayers-layerCount-01700"], ..Default::default() - }); + })); } Ok(()) @@ -1511,7 +1520,7 @@ impl ImageSubresourceRange { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { aspects, ref mip_levels, @@ -1527,44 +1536,44 @@ impl ImageSubresourceRange { })?; if aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "is empty".into(), vuids: &["VUID-VkImageSubresourceRange-aspectMask-requiredbitmask"], ..Default::default() - }); + })); } if mip_levels.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mip_levels".into(), problem: "is empty".into(), vuids: &["VUID-VkImageSubresourceRange-levelCount-01720"], ..Default::default() - }); + })); } if array_layers.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "array_layers".into(), problem: "is empty".into(), vuids: &["VUID-VkImageSubresourceRange-layerCount-01721"], ..Default::default() - }); + })); } if aspects.intersects(ImageAspects::COLOR) && aspects .intersects(ImageAspects::PLANE_0 | ImageAspects::PLANE_1 | ImageAspects::PLANE_2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "contains both `ImageAspects::COLOR`, and one of \ `ImageAspects::PLANE_0`, `ImageAspects::PLANE_1` or `ImageAspects::PLANE_2`" .into(), vuids: &["VUID-VkImageSubresourceRange-aspectMask-01670"], ..Default::default() - }); + })); } if aspects.intersects( @@ -1573,7 +1582,7 @@ impl ImageSubresourceRange { | ImageAspects::MEMORY_PLANE_2 | ImageAspects::MEMORY_PLANE_3, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "aspects".into(), problem: "contains `ImageAspects::MEMORY_PLANE_0`, \ `ImageAspects::MEMORY_PLANE_1`, `ImageAspects::MEMORY_PLANE_2` or \ @@ -1581,7 +1590,7 @@ impl ImageSubresourceRange { .into(), vuids: &["VUID-VkImageSubresourceLayers-aspectMask-02247"], ..Default::default() - }); + })); } Ok(()) @@ -1733,7 +1742,10 @@ impl Default for ImageFormatInfo { } impl ImageFormatInfo { - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { flags, format, @@ -1796,12 +1808,12 @@ impl ImageFormatInfo { })?; if usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "is empty".into(), vuids: &["VUID-VkPhysicalDeviceImageFormatInfo2-usage-requiredbitmask"], ..Default::default() - }); + })); } let has_separate_stencil_usage = if aspects @@ -1820,7 +1832,7 @@ impl ImageFormatInfo { .supported_extensions() .ext_separate_stencil_usage) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stencil_usage` is `Some`, and `format` has both a depth and a \ stencil aspect" .into(), @@ -1829,7 +1841,7 @@ impl ImageFormatInfo { RequiresAllOf(&[Requires::DeviceExtension("ext_separate_stencil_usage")]), ]), ..Default::default() - }); + })); } stencil_usage @@ -1841,12 +1853,12 @@ impl ImageFormatInfo { })?; if stencil_usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_usage".into(), problem: "is empty".into(), vuids: &["VUID-VkImageStencilUsageCreateInfo-usage-requiredbitmask"], ..Default::default() - }); + })); } } @@ -1857,7 +1869,7 @@ impl ImageFormatInfo { .enabled_extensions() .khr_external_memory_capabilities) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`external_memory_handle_type` is `Some`".into(), requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), @@ -1866,7 +1878,7 @@ impl ImageFormatInfo { )]), ]), ..Default::default() - }); + })); } handle_type @@ -1880,13 +1892,13 @@ impl ImageFormatInfo { if let Some(image_view_type) = image_view_type { if !physical_device.supported_extensions().ext_filter_cubic { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image_view_type` is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_filter_cubic", )])]), ..Default::default() - }); + })); } image_view_type @@ -1905,14 +1917,14 @@ impl ImageFormatInfo { .supported_extensions() .ext_image_drm_format_modifier { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "drm_format_modifier_info".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_image_drm_format_modifier", )])]), ..Default::default() - }); + })); } drm_format_modifier_info @@ -1920,32 +1932,32 @@ impl ImageFormatInfo { .map_err(|err| err.add_context("drm_format_modifier_info"))?; if tiling != ImageTiling::DrmFormatModifier { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`drm_format_modifier_info` is `Some` but \ `tiling` is not `ImageTiling::DrmFormatModifier`" .into(), vuids: &[" VUID-VkPhysicalDeviceImageFormatInfo2-tiling-02249"], ..Default::default() - }); + })); } if flags.intersects(ImageCreateFlags::MUTABLE_FORMAT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`tiling` is `ImageTiling::DrmFormatModifier`, but \ `flags` contains `ImageCreateFlags::MUTABLE_FORMAT`" .into(), vuids: &["VUID-VkPhysicalDeviceImageFormatInfo2-tiling-02313"], ..Default::default() - }); + })); } } else if tiling == ImageTiling::DrmFormatModifier { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`tiling` is `ImageTiling::DrmFormatModifier`, but \ `drm_format_modifier_info` is `None`" .into(), vuids: &[" VUID-VkPhysicalDeviceImageFormatInfo2-tiling-02249"], ..Default::default() - }); + })); } Ok(()) @@ -1981,7 +1993,10 @@ impl Default for ImageDrmFormatModifierInfo { } impl ImageDrmFormatModifierInfo { - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { drm_format_modifier: _, ref sharing, @@ -1992,7 +2007,7 @@ impl ImageDrmFormatModifierInfo { Sharing::Exclusive => (), Sharing::Concurrent(queue_family_indices) => { if queue_family_indices.len() < 2 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sharing".into(), problem: "is `Sharing::Concurrent`, but contains less than 2 elements" .into(), @@ -2000,14 +2015,14 @@ impl ImageDrmFormatModifierInfo { "VUID-VkPhysicalDeviceImageDrmFormatModifierInfoEXT-sharingMode-02315", ], ..Default::default() - }); + })); } let queue_family_count = physical_device.queue_family_properties().len() as u32; for (index, &queue_family_index) in queue_family_indices.iter().enumerate() { if queue_family_indices[..index].contains(&queue_family_index) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_indices".into(), problem: format!( "the queue family index in the list at index {} is contained in \ @@ -2017,17 +2032,17 @@ impl ImageDrmFormatModifierInfo { .into(), vuids: &[" VUID-VkPhysicalDeviceImageDrmFormatModifierInfoEXT-sharingMode-02316"], ..Default::default() - }); + })); } if queue_family_index >= queue_family_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("sharing[{}]", index).into(), problem: "is not less than the number of queue families in the device" .into(), vuids: &[" VUID-VkPhysicalDeviceImageDrmFormatModifierInfoEXT-sharingMode-02316"], ..Default::default() - }); + })); } } } @@ -2139,7 +2154,10 @@ impl Default for SparseImageFormatInfo { } impl SparseImageFormatInfo { - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { format, image_type, @@ -2189,12 +2207,12 @@ impl SparseImageFormatInfo { })?; if usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "is empty".into(), vuids: &["VUID-VkPhysicalDeviceSparseImageFormatInfo2-usage-requiredbitmask"], ..Default::default() - }); + })); } tiling diff --git a/vulkano/src/image/sampler/mod.rs b/vulkano/src/image/sampler/mod.rs index f30571b9..966d20b7 100644 --- a/vulkano/src/image/sampler/mod.rs +++ b/vulkano/src/image/sampler/mod.rs @@ -58,8 +58,7 @@ use crate::{ macros::{impl_id_counter, vulkan_enum}, pipeline::graphics::depth_stencil::CompareOp, shader::ShaderScalarType, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, VulkanError, - VulkanObject, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, VulkanError, VulkanObject, }; use std::{mem::MaybeUninit, num::NonZeroU64, ops::RangeInclusive, ptr, sync::Arc}; @@ -118,7 +117,7 @@ impl Sampler { pub fn new( device: Arc, create_info: SamplerCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -127,7 +126,7 @@ impl Sampler { fn validate_new( device: &Device, create_info: &SamplerCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { create_info .validate(device) .map_err(|err| err.add_context("create_info"))?; @@ -139,7 +138,7 @@ impl Sampler { pub unsafe fn new_unchecked( device: Arc, create_info: SamplerCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &SamplerCreateInfo { mag_filter, min_filter, @@ -223,7 +222,7 @@ impl Sampler { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -281,7 +280,10 @@ impl Sampler { } /// Checks whether this sampler is compatible with `image_view`. - pub fn check_can_sample(&self, image_view: &ImageView) -> Result<(), ValidationError> { + pub(crate) fn check_can_sample( + &self, + image_view: &ImageView, + ) -> Result<(), Box> { /* NOTE: Most of these checks come from the Instruction/Sampler/Image View Validation section, and are not strictly VUIDs. @@ -294,13 +296,13 @@ impl Sampler { .format_features() .intersects(FormatFeatures::SAMPLED_IMAGE_DEPTH_COMPARISON) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler has depth comparison enabled, and \ the image view's format features do not include \ `FormatFeatures::SAMPLED_IMAGE_DEPTH_COMPARISON`" .into(), ..Default::default() - }); + })); } // The SPIR-V instruction is one of the OpImage*Dref* instructions, the image @@ -311,12 +313,12 @@ impl Sampler { .aspects .intersects(ImageAspects::DEPTH) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler has depth comparison enabled, and \ the image view's aspects do not include `ImageAspects::DEPTH`" .into(), ..Default::default() - }); + })); } } else { if !image_view @@ -325,24 +327,24 @@ impl Sampler { { // VUID-vkCmdDispatch-magFilter-04553 if self.mag_filter == Filter::Linear || self.min_filter == Filter::Linear { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler's `mag_filter` or `min_filter` is `Filter::Linear`, \ and the image view's format features do not include \ `FormatFeatures::SAMPLED_IMAGE_FILTER_LINEAR`" .into(), ..Default::default() - }); + })); } // VUID-vkCmdDispatch-mipmapMode-04770 if self.mipmap_mode == SamplerMipmapMode::Linear { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler's `mipmap_mode` is `SamplerMipmapMpde::Linear`, and \ the image view's format features do not include \ `FormatFeatures::SAMPLED_IMAGE_FILTER_LINEAR`" .into(), ..Default::default() - }); + })); } } } @@ -353,24 +355,24 @@ impl Sampler { .format_features() .intersects(FormatFeatures::SAMPLED_IMAGE_FILTER_CUBIC) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler's `mag_filter` or `min_filter` is `Filter::Cubic`, and \ the image view's format features do not include \ `FormatFeatures::SAMPLED_IMAGE_FILTER_CUBIC`" .into(), ..Default::default() - }); + })); } // VUID-vkCmdDispatch-filterCubic-02694 if !image_view.filter_cubic() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler's `mag_filter` or `min_filter` is Filter::Cubic, and \ the image view does not support this, as returned by \ `PhysicalDevice::image_format_properties`" .into(), ..Default::default() - }); + })); } // VUID-vkCmdDispatch-filterCubicMinmax-02695 @@ -379,7 +381,7 @@ impl Sampler { SamplerReductionMode::Min | SamplerReductionMode::Max ) && !image_view.filter_cubic_minmax() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler's `mag_filter` or `min_filter` is `Filter::Cubic`, and \ the its `reduction_mode` is `SamplerReductionMode::Min` or \ `SamplerReductionMode::Max`, and \ @@ -387,7 +389,7 @@ impl Sampler { `PhysicalDevice::image_format_properties`" .into(), ..Default::default() - }); + })); } } @@ -423,12 +425,12 @@ impl Sampler { view_scalar_type, ShaderScalarType::Sint | ShaderScalarType::Uint ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler has an integer border color, and \ the image view does not have an integer format" .into(), ..Default::default() - }); + })); } } BorderColor::FloatTransparentBlack @@ -438,12 +440,12 @@ impl Sampler { // format is not one of the VkFormat float types or a depth // component of a depth/stencil format. if !matches!(view_scalar_type, ShaderScalarType::Float) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler has an floating-point border color, and \ the image view does not have a floating-point format" .into(), ..Default::default() - }); + })); } } } @@ -460,12 +462,12 @@ impl Sampler { BorderColor::FloatOpaqueBlack | BorderColor::IntOpaqueBlack ) && !image_view.component_mapping().is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler has an opaque black border color, and \ the image view is not identity swizzled" .into(), ..Default::default() - }); + })); } } @@ -480,13 +482,13 @@ impl Sampler { image_view.view_type(), ImageViewType::Dim1d | ImageViewType::Dim2d ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler uses unnormalized coordinates, and \ the image view's type is not `ImageViewtype::Dim1d` or \ `ImageViewType::Dim2d`" .into(), ..Default::default() - }); + })); } // The image view must have a single layer and a single mip level. @@ -494,12 +496,12 @@ impl Sampler { - image_view.subresource_range().mip_levels.start != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the sampler uses unnormalized coordinates, and \ the image view has more than one mip level" .into(), ..Default::default() - }); + })); } } @@ -797,7 +799,7 @@ impl SamplerCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { mag_filter, min_filter, @@ -875,7 +877,7 @@ impl SamplerCreateInfo { if !(device.enabled_features().sampler_mirror_clamp_to_edge || device.enabled_extensions().khr_sampler_mirror_clamp_to_edge) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "address_mode".into(), problem: "contains `SamplerAddressMode::MirrorClampToEdge`".into(), requires_one_of: RequiresOneOf(&[ @@ -885,34 +887,34 @@ impl SamplerCreateInfo { )]), ]), ..Default::default() - }); + })); } } if lod.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "lod".into(), problem: "is empty".into(), vuids: &["VUID-VkSamplerCreateInfo-maxLod-01973"], ..Default::default() - }); + })); } if mip_lod_bias.abs() > properties.max_sampler_lod_bias { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "lod".into(), problem: "the absolute value is greater than the `max_sampler_lod_bias` limit" .into(), vuids: &["VUID-VkSamplerCreateInfo-mipLodBias-01069"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().sampler_mip_lod_bias && mip_lod_bias != 0.0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `mip_lod_bias` is not zero" .into(), @@ -921,47 +923,47 @@ impl SamplerCreateInfo { )])]), vuids: &["VUID-VkSamplerCreateInfo-samplerMipLodBias-04467"], ..Default::default() - }); + })); } if let Some(max_anisotropy) = anisotropy { if !device.enabled_features().sampler_anisotropy { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "anisotropy".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sampler_anisotropy", )])]), vuids: &["VUID-VkSamplerCreateInfo-anisotropyEnable-01070"], - }); + })); } if max_anisotropy < 1.0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "anisotropy".into(), problem: "is less than 1.0".into(), vuids: &["VUID-VkSamplerCreateInfo-anisotropyEnable-01071"], ..Default::default() - }); + })); } if max_anisotropy > properties.max_sampler_anisotropy { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "anisotropy".into(), problem: "is greater than the `max_sampler_anisotropy` limit".into(), vuids: &["VUID-VkSamplerCreateInfo-anisotropyEnable-01071"], ..Default::default() - }); + })); } if [mag_filter, min_filter].contains(&Filter::Cubic) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`anisotropy` is `Some`, but `mag_filter` or `min_filter` is \ `Filter::Cubic`" .into(), vuids: &["VUID-VkSamplerCreateInfo-magFilter-01081"], ..Default::default() - }); + })); } } @@ -975,45 +977,45 @@ impl SamplerCreateInfo { })?; if reduction_mode != SamplerReductionMode::WeightedAverage { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`compare` is `Some`, but `reduction_mode` is not \ `SamplerReductionMode::WeightedAverage`" .into(), vuids: &["VUID-VkSamplerCreateInfo-compareEnable-01423"], ..Default::default() - }); + })); } } if unnormalized_coordinates { if min_filter != mag_filter { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but \ `min_filter` and `mag_filter` are not equal" .into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01072"], ..Default::default() - }); + })); } if mipmap_mode != SamplerMipmapMode::Nearest { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but \ `mipmap_mode` is not `SamplerMipmapMode::Nearest`" .into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01073"], ..Default::default() - }); + })); } if *lod != (0.0..=0.0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but \ `lod` is not `0.0..=1.0`" .into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074"], ..Default::default() - }); + })); } if address_mode[0..2].iter().any(|mode| { @@ -1022,31 +1024,31 @@ impl SamplerCreateInfo { SamplerAddressMode::ClampToEdge | SamplerAddressMode::ClampToBorder ) }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but \ `address_mode[0]` or `address_mode[1]` are not \ `SamplerAddressMode::ClampToEdge` or `SamplerAddressMode::ClampToBorder`" .into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01075"], ..Default::default() - }); + })); } if anisotropy.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but `anisotropy` is `Some`" .into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01076"], ..Default::default() - }); + })); } if compare.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`unnormalized_coordinates` is `true`, but `compare` is `Some`".into(), vuids: &["VUID-VkSamplerCreateInfo-unnormalizedCoordinates-0107"], ..Default::default() - }); + })); } } @@ -1054,7 +1056,7 @@ impl SamplerCreateInfo { if !(device.enabled_features().sampler_filter_minmax || device.enabled_extensions().ext_sampler_filter_minmax) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "reduction_mode".into(), problem: "is not `SamplerReductionMode::WeightedAverage`".into(), requires_one_of: RequiresOneOf(&[ @@ -1062,7 +1064,7 @@ impl SamplerCreateInfo { RequiresAllOf(&[Requires::DeviceExtension("ext_sampler_filter_minmax")]), ]), ..Default::default() - }); + })); } } @@ -1084,7 +1086,7 @@ impl SamplerCreateInfo { ) && !(mag_filter == sampler_ycbcr_conversion.chroma_filter() && min_filter == sampler_ycbcr_conversion.chroma_filter()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, and \ the potential format features of `sampler_ycbcr_conversion.format()` \ do not include `FormatFeatures::\ @@ -1094,51 +1096,51 @@ impl SamplerCreateInfo { .into(), vuids: &["VUID-VkSamplerCreateInfo-minFilter-01645"], ..Default::default() - }); + })); } if address_mode .into_iter() .any(|mode| !matches!(mode, SamplerAddressMode::ClampToEdge)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, but \ not all elements of `address_mode` are \ `SamplerAddressMode::ClampToEdge`" .into(), vuids: &["VUID-VkSamplerCreateInfo-addressModeU-01646"], ..Default::default() - }); + })); } if anisotropy.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, but \ `anisotropy` is `Some`" .into(), vuids: &["VUID-VkSamplerCreateInfo-addressModeU-01646"], ..Default::default() - }); + })); } if unnormalized_coordinates { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, but \ `unnormalized_coordinates` is `true`" .into(), vuids: &["VUID-VkSamplerCreateInfo-addressModeU-01646"], ..Default::default() - }); + })); } if reduction_mode != SamplerReductionMode::WeightedAverage { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, but \ `reduction_mode` is not `SamplerReductionMode::WeightedAverage`" .into(), vuids: &["VUID-VkSamplerCreateInfo-None-01647"], ..Default::default() - }); + })); } } @@ -1248,7 +1250,7 @@ impl ComponentMapping { ] } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { r, g, b, a } = self; r.validate_device(device).map_err(|err| ValidationError { @@ -1493,7 +1495,7 @@ mod tests { Filter, Sampler, SamplerAddressMode, SamplerCreateInfo, SamplerReductionMode, }, pipeline::graphics::depth_stencil::CompareOp, - Requires, RequiresAllOf, RequiresOneOf, ValidationError, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, }; #[test] @@ -1628,7 +1630,7 @@ mod tests { ); match r { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), } } @@ -1651,7 +1653,7 @@ mod tests { ); match r { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), } } @@ -1673,7 +1675,7 @@ mod tests { ); match r { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), } } @@ -1695,15 +1697,19 @@ mod tests { ); match r { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf( - [RequiresAllOf([Requires::Feature("sampler_mirror_clamp_to_edge")]), RequiresAllOf( - [Requires::DeviceExtension("khr_sampler_mirror_clamp_to_edge")], - )], - ), - .. - })) => {} + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([ + RequiresAllOf([Requires::Feature("sampler_mirror_clamp_to_edge")]), + RequiresAllOf([Requires::DeviceExtension( + "khr_sampler_mirror_clamp_to_edge" + )],) + ],), + .. + } + ) => {} _ => panic!(), } } @@ -1723,13 +1729,17 @@ mod tests { ); match r { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf( - [RequiresAllOf([Requires::Feature("sampler_filter_minmax")]), RequiresAllOf([Requires::DeviceExtension("ext_sampler_filter_minmax")])], - ), - .. - })) => {} + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([ + RequiresAllOf([Requires::Feature("sampler_filter_minmax")]), + RequiresAllOf([Requires::DeviceExtension("ext_sampler_filter_minmax")]) + ],), + .. + } + ) => {} _ => panic!(), } } diff --git a/vulkano/src/image/sampler/ycbcr.rs b/vulkano/src/image/sampler/ycbcr.rs index 6f641b91..b4242995 100644 --- a/vulkano/src/image/sampler/ycbcr.rs +++ b/vulkano/src/image/sampler/ycbcr.rs @@ -115,7 +115,7 @@ use crate::{ image::sampler::{ComponentMapping, ComponentSwizzle, Filter}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_enum}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use std::{mem::MaybeUninit, num::NonZeroU64, ptr, sync::Arc}; @@ -145,7 +145,7 @@ impl SamplerYcbcrConversion { pub fn new( device: Arc, create_info: SamplerYcbcrConversionCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -154,15 +154,15 @@ impl SamplerYcbcrConversion { fn validate_new( device: &Device, create_info: &SamplerYcbcrConversionCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !device.enabled_features().sampler_ycbcr_conversion { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sampler_ycbcr_conversion", )])]), vuids: &["VUID-vkCreateSamplerYcbcrConversion-None-01648"], ..Default::default() - }); + })); } create_info @@ -176,7 +176,7 @@ impl SamplerYcbcrConversion { pub unsafe fn new_unchecked( device: Arc, create_info: SamplerYcbcrConversionCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &SamplerYcbcrConversionCreateInfo { format, ycbcr_model, @@ -217,7 +217,7 @@ impl SamplerYcbcrConversion { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -456,7 +456,7 @@ impl Default for SamplerYcbcrConversionCreateInfo { } impl SamplerYcbcrConversionCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { format, ycbcr_model, @@ -527,12 +527,12 @@ impl SamplerYcbcrConversionCreateInfo { .type_color() .map_or(false, |ty| ty == NumericType::UNORM) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "format".into(), problem: "the numeric type is not `UNORM`".into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-format-04061"], ..Default::default() - }); + })); } // Use unchecked, because all validation has been done above. @@ -546,7 +546,7 @@ impl SamplerYcbcrConversionCreateInfo { if !potential_format_features.intersects( FormatFeatures::MIDPOINT_CHROMA_SAMPLES | FormatFeatures::COSITED_CHROMA_SAMPLES, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "format".into(), problem: "the potential format features do not contain \ `FormatFeatures::MIDPOINT_CHROMA_SAMPLES` or \ @@ -554,7 +554,7 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-format-01650"], ..Default::default() - }); + })); } if let Some(chroma_sampling @ (ChromaSampling::Mode422 | ChromaSampling::Mode420)) = @@ -566,7 +566,7 @@ impl SamplerYcbcrConversionCreateInfo { && !potential_format_features .intersects(FormatFeatures::COSITED_CHROMA_SAMPLES) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both horizontal and vertical chroma \ subsampling, and \ its potential format features do not \ @@ -576,14 +576,14 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01651"], ..Default::default() - }); + })); } if chroma_offset.contains(&ChromaLocation::Midpoint) && !potential_format_features .intersects(FormatFeatures::MIDPOINT_CHROMA_SAMPLES) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both horizontal and vertical chroma \ subsampling, and \ its potential format features do not \ @@ -593,7 +593,7 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01652"], ..Default::default() - }); + })); } } ChromaSampling::Mode422 => { @@ -601,7 +601,7 @@ impl SamplerYcbcrConversionCreateInfo { && !potential_format_features .intersects(FormatFeatures::COSITED_CHROMA_SAMPLES) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has horizontal chroma subsampling, and \ its potential format features do not \ contain `FormatFeatures::COSITED_CHROMA_SAMPLES`, but \ @@ -610,14 +610,14 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01651"], ..Default::default() - }); + })); } if chroma_offset[0] == ChromaLocation::Midpoint && !potential_format_features .intersects(FormatFeatures::MIDPOINT_CHROMA_SAMPLES) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has horizontal chroma subsampling, and \ its potential format features do not \ contain `FormatFeatures::MIDPOINT_CHROMA_SAMPLES`, but \ @@ -626,20 +626,20 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-xChromaOffset-01652"], ..Default::default() - }); + })); } } _ => unreachable!(), } if !component_mapping.g_is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has chroma subsampling, but \ `component_mapping.g` is not identity swizzled" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02581"], ..Default::default() - }); + })); } if !(component_mapping.a_is_identity() @@ -648,7 +648,7 @@ impl SamplerYcbcrConversionCreateInfo { ComponentSwizzle::One | ComponentSwizzle::Zero )) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "component_mapping.a".into(), problem: "`format` has chroma subsampling, but \ `component_mapping.a` is not identity swizzled, or \ @@ -656,33 +656,33 @@ impl SamplerYcbcrConversionCreateInfo { .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02582"], ..Default::default() - }); + })); } if !(component_mapping.r_is_identity() || matches!(component_mapping.r, ComponentSwizzle::Blue)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has chroma subsampling, but \ `component_mapping.r` is not identity swizzled, or \ `ComponentSwizzle::Blue`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02583"], ..Default::default() - }); + })); } if !(component_mapping.b_is_identity() || matches!(component_mapping.b, ComponentSwizzle::Red)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has chroma subsampling, but \ `component_mapping.b` is not identity swizzled, or \ `ComponentSwizzle::Red`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02584"], ..Default::default() - }); + })); } match ( @@ -690,24 +690,24 @@ impl SamplerYcbcrConversionCreateInfo { component_mapping.b_is_identity(), ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has chroma subsampling, and \ `component_mapping.r` is identity swizzled, but \ `component_mapping.b` is not identity swizzled" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has chroma subsampling, and \ `component_mapping.b` is identity swizzled, but \ `component_mapping.r` is not identity swizzled" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } _ => (), } @@ -723,47 +723,47 @@ impl SamplerYcbcrConversionCreateInfo { // VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrModel-01655 if ycbcr_model != SamplerYcbcrModelConversion::RgbIdentity { if components_bits[0].map_or(true, |bits| bits == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_model` is not `SamplerYcbcrModelConversion::RgbIdentity`, \ and `component_mapping.r` does not map to a component that exists in \ `format`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } if components_bits[1].map_or(true, |bits| bits == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_model` is not `SamplerYcbcrModelConversion::RgbIdentity`, \ and `component_mapping.g` does not map to a component that exists in \ `format`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } if components_bits[2].map_or(true, |bits| bits == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_model` is not `SamplerYcbcrModelConversion::RgbIdentity`, \ and `component_mapping.b` does not map to a component that exists in \ `format`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } if components_bits[3].map_or(true, |bits| bits == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_model` is not `SamplerYcbcrModelConversion::RgbIdentity`, \ and `component_mapping.a` does not map to a component that exists in \ `format`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-components-02585"], ..Default::default() - }); + })); } } @@ -772,47 +772,47 @@ impl SamplerYcbcrConversionCreateInfo { // just skip them for now. if components_bits[0].map_or(false, |bits| bits < 8) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_range` is `SamplerYcbcrRange::ItuNarrow`, and \ `component_mapping.r` maps to a component in `format` with less than \ 8 bits" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrRange-02748"], ..Default::default() - }); + })); } if components_bits[1].map_or(false, |bits| bits < 8) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_range` is `SamplerYcbcrRange::ItuNarrow`, and \ `component_mapping.g` maps to a component in `format` with less than \ 8 bits" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrRange-02748"], ..Default::default() - }); + })); } if components_bits[2].map_or(false, |bits| bits < 8) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_range` is `SamplerYcbcrRange::ItuNarrow`, and \ `component_mapping.b` maps to a component in `format` with less than \ 8 bits" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrRange-02748"], ..Default::default() - }); + })); } if components_bits[3].map_or(false, |bits| bits < 8) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`ycbcr_range` is `SamplerYcbcrRange::ItuNarrow`, and \ `component_mapping.a` maps to a component in `format` with less than \ 8 bits" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-ycbcrRange-02748"], ..Default::default() - }); + })); } } @@ -820,14 +820,14 @@ impl SamplerYcbcrConversionCreateInfo { && !potential_format_features.intersects(FormatFeatures:: SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`force_explicit_reconstruction` is `true`, but the \ potential format features of `format` do not include `FormatFeatures::\ SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-forceExplicitReconstruction-01656"], ..Default::default() - }); + })); } match chroma_filter { @@ -836,23 +836,23 @@ impl SamplerYcbcrConversionCreateInfo { if !potential_format_features .intersects(FormatFeatures::SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`chroma_filter` is `Filter::Linear`, but the \ potential format features of `format` do not include `FormatFeatures::\ SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER`" .into(), vuids: &["VUID-VkSamplerYcbcrConversionCreateInfo-chromaFilter-01657"], ..Default::default() - }); + })); } } Filter::Cubic => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "chroma_filter".into(), problem: "is `Filter::Cubic`".into(), // vuids? ..Default::default() - }); + })); } } @@ -918,7 +918,7 @@ vulkan_enum! { #[cfg(test)] mod tests { use super::SamplerYcbcrConversion; - use crate::{Requires, RequiresAllOf, RequiresOneOf, ValidationError, VulkanError}; + use crate::{Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError}; #[test] fn feature_not_enabled() { @@ -927,11 +927,16 @@ mod tests { let r = SamplerYcbcrConversion::new(device, Default::default()); match r { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::Feature("sampler_ycbcr_conversion")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([Requires::Feature( + "sampler_ycbcr_conversion" + )])]), + .. + } + ) => {} _ => panic!(), } } diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index 1b9407cb..5c78575a 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -38,7 +38,7 @@ use crate::{ MemoryRequirements, }, sync::Sharing, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use smallvec::{smallvec, SmallVec}; @@ -83,13 +83,19 @@ pub struct RawImage { impl RawImage { /// Creates a new `RawImage`. #[inline] - pub fn new(device: Arc, create_info: ImageCreateInfo) -> Result { + pub fn new( + device: Arc, + create_info: ImageCreateInfo, + ) -> Result> { Self::validate_new(&device, &create_info)?; unsafe { Ok(RawImage::new_unchecked(device, create_info)?) } } - fn validate_new(device: &Device, create_info: &ImageCreateInfo) -> Result<(), ValidationError> { + fn validate_new( + device: &Device, + create_info: &ImageCreateInfo, + ) -> Result<(), Box> { create_info .validate(device) .map_err(|err| err.add_context("create_info"))?; @@ -102,7 +108,7 @@ impl RawImage { pub unsafe fn new_unchecked( device: Arc, create_info: ImageCreateInfo, - ) -> Result { + ) -> Result { let &ImageCreateInfo { flags, image_type, @@ -241,7 +247,7 @@ impl RawImage { let mut output = MaybeUninit::uninit(); (fns.v1_0.create_image)(device.handle(), &info_vk, ptr::null(), output.as_mut_ptr()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -260,7 +266,7 @@ impl RawImage { device: Arc, handle: ash::vk::Image, create_info: ImageCreateInfo, - ) -> Result { + ) -> Result { Self::from_handle_with_destruction(device, handle, create_info, true) } @@ -269,7 +275,7 @@ impl RawImage { handle: ash::vk::Image, create_info: ImageCreateInfo, needs_destruction: bool, - ) -> Result { + ) -> Result { let ImageCreateInfo { flags, image_type, @@ -665,7 +671,7 @@ impl RawImage { unsafe fn get_drm_format_modifier_properties( device: &Device, handle: ash::vk::Image, - ) -> Result { + ) -> Result { let mut properties_vk = ash::vk::ImageDrmFormatModifierPropertiesEXT::default(); let fns = device.fns(); @@ -676,7 +682,7 @@ impl RawImage { &mut properties_vk, ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(properties_vk.drm_format_modifier) } @@ -697,7 +703,7 @@ impl RawImage { ) -> Result< Image, ( - VulkanError, + Validated, RawImage, impl ExactSizeIterator, ), @@ -720,12 +726,15 @@ impl RawImage { }) } - fn validate_bind_memory(&self, allocations: &[MemoryAlloc]) -> Result<(), ValidationError> { + fn validate_bind_memory( + &self, + allocations: &[MemoryAlloc], + ) -> Result<(), Box> { if self.flags.intersects(ImageCreateFlags::DISJOINT) { match self.tiling { ImageTiling::Optimal | ImageTiling::Linear => { if allocations.len() != self.format.unwrap().planes().len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.flags()` contains `ImageCreateFlags::DISJOINT`, and \ `self.tiling()` is `ImageTiling::Optimal` or \ `ImageTiling::Linear`, but \ @@ -733,12 +742,12 @@ impl RawImage { the number of planes in the format of the image" .into(), ..Default::default() - }); + })); } } ImageTiling::DrmFormatModifier => { if allocations.len() != self.drm_format_modifier.unwrap().1 as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.flags()` contains `ImageCreateFlags::DISJOINT`, and \ `self.tiling()` is `ImageTiling::DrmFormatModifier`, but \ the length of `allocations` does not equal \ @@ -746,18 +755,18 @@ impl RawImage { image" .into(), ..Default::default() - }); + })); } } } } else { if allocations.len() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.flags()` does not contain `ImageCreateFlags::DISJOINT`, but \ the length of `allocations` is not 1" .into(), ..Default::default() - }); + })); } } @@ -766,14 +775,14 @@ impl RawImage { .enumerate() { if allocation.allocation_type() == AllocationType::Linear { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].allocation_type()` is `AllocationType::Linear`", index ) .into(), ..Default::default() - }); + })); } let memory = allocation.device_memory(); @@ -798,7 +807,7 @@ impl RawImage { // Assume that `allocation` was created correctly. if memory_requirements.memory_type_bits & (1 << memory.memory_type_index()) == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocation[{}].device_memory().memory_type_index()` is not a bit set in \ `self.memory_requirements().memory_type_bits`", @@ -810,11 +819,11 @@ impl RawImage { "VUID-VkBindImageMemoryInfo-pNext-01619", ], ..Default::default() - }); + })); } if !is_aligned(memory_offset, memory_requirements.layout.alignment()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].offset()` is not aligned according to \ `self.memory_requirements().layout.alignment()`", @@ -826,11 +835,11 @@ impl RawImage { "VUID-VkBindImageMemoryInfo-pNext-01620", ], ..Default::default() - }); + })); } if allocation.size() < memory_requirements.layout.size() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].size()` is less than \ `self.memory_requirements().layout.size()`", @@ -842,14 +851,14 @@ impl RawImage { "VUID-VkBindImageMemoryInfo-pNext-01621", ], ..Default::default() - }); + })); } if let Some(dedicated_to) = memory.dedicated_to() { match dedicated_to { DedicatedTo::Image(id) if id == self.id => {} _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].device_memory()` is a dedicated allocation, but \ it is not dedicated to this image", @@ -858,13 +867,13 @@ impl RawImage { .into(), vuids: &["VUID-VkBindImageMemoryInfo-memory-02628"], ..Default::default() - }); + })); } } debug_assert!(memory_offset == 0); // This should be ensured by the allocator } else { if memory_requirements.requires_dedicated_allocation { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`self.memory_requirements().requires_dedicated_allocation` is \ `true`, but `allocations[{}].device_memory()` is not a \ @@ -874,7 +883,7 @@ impl RawImage { .into(), vuids: &["VUID-VkBindImageMemoryInfo-image-01445"], ..Default::default() - }); + })); } } @@ -882,7 +891,7 @@ impl RawImage { .property_flags .intersects(MemoryPropertyFlags::PROTECTED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the `property_flags` of the memory type of \ `allocations[{}].device_memory()` contains \ @@ -892,7 +901,7 @@ impl RawImage { .into(), vuids: &["VUID-VkBindImageMemoryInfo-None-01901"], ..Default::default() - }); + })); } if !memory.export_handle_types().is_empty() @@ -900,7 +909,7 @@ impl RawImage { .export_handle_types() .intersects(self.external_memory_handle_types) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].device_memory().export_handle_types()` is not empty, \ but it does not share at least one memory type with \ @@ -910,14 +919,14 @@ impl RawImage { .into(), vuids: &["VUID-VkBindImageMemoryInfo-memory-02728"], ..Default::default() - }); + })); } if let Some(handle_type) = memory.imported_handle_type() { if !ExternalMemoryHandleTypes::from(handle_type) .intersects(self.external_memory_handle_types) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].device_memory()` is imported, but \ `self.external_memory_handle_types()` does not contain the imported \ @@ -927,7 +936,7 @@ impl RawImage { .into(), vuids: &["VUID-VkBindImageMemoryInfo-memory-02989"], ..Default::default() - }); + })); } } } @@ -952,7 +961,7 @@ impl RawImage { ) -> Result< Image, ( - RuntimeError, + VulkanError, RawImage, impl ExactSizeIterator, ), @@ -1061,7 +1070,7 @@ impl RawImage { .result(); if let Err(err) = result { - return Err((RuntimeError::from(err), self, allocations.into_iter())); + return Err((VulkanError::from(err), self, allocations.into_iter())); } Ok(Image::from_raw( @@ -1221,7 +1230,7 @@ impl RawImage { aspect: ImageAspect, mip_level: u32, array_layer: u32, - ) -> Result { + ) -> Result> { self.validate_subresource_layout(aspect, mip_level, array_layer)?; unsafe { Ok(self.subresource_layout_unchecked(aspect, mip_level, array_layer)) } @@ -1232,7 +1241,7 @@ impl RawImage { aspect: ImageAspect, mip_level: u32, array_layer: u32, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { aspect .validate_device(&self.device) .map_err(|err| ValidationError { @@ -1249,30 +1258,30 @@ impl RawImage { self.tiling, ImageTiling::Linear | ImageTiling::DrmFormatModifier ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self.tiling()".into(), problem: "is not `ImageTiling::Linear` or `ImageTiling::DrmFormatModifier`".into(), vuids: &["VUID-vkGetImageSubresourceLayout-image-02270"], ..Default::default() - }); + })); } if mip_level >= self.mip_levels { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mip_level".into(), problem: "is greater than the number of mip levels in the image".into(), vuids: &["VUID-vkGetImageSubresourceLayout-mipLevel-01716"], ..Default::default() - }); + })); } if array_layer >= self.array_layers { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "array_layer".into(), problem: "is greater than the number of array layers in the image".into(), vuids: &["VUID-vkGetImageSubresourceLayout-arrayLayer-01717"], ..Default::default() - }); + })); } let format = self.format.unwrap(); @@ -1282,13 +1291,13 @@ impl RawImage { match drm_format_modifier_plane_count { 1 => { if !matches!(aspect, ImageAspect::MemoryPlane0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the image has a DRM format modifier with 1 memory plane, \ but `aspect` is not `ImageAspect::MemoryPlane0`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-02271"], ..Default::default() - }); + })); } } 2 => { @@ -1296,14 +1305,14 @@ impl RawImage { aspect, ImageAspect::MemoryPlane0 | ImageAspect::MemoryPlane1 ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the image has a DRM format modifier with 2 memory planes, \ but `aspect` is not `ImageAspect::MemoryPlane0` or \ `ImageAspect::MemoryPlane1`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-02271"], ..Default::default() - }); + })); } } 3 => { @@ -1313,14 +1322,14 @@ impl RawImage { | ImageAspect::MemoryPlane1 | ImageAspect::MemoryPlane2 ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the image has a DRM format modifier with 3 memory planes, \ but `aspect` is not `ImageAspect::MemoryPlane0`, \ `ImageAspect::MemoryPlane1` or `ImageAspect::MemoryPlane2`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-02271"], ..Default::default() - }); + })); } } 4 => { @@ -1331,7 +1340,7 @@ impl RawImage { | ImageAspect::MemoryPlane2 | ImageAspect::MemoryPlane3 ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the image has a DRM format modifier with 4 memory planes, \ but `aspect` is not `ImageAspect::MemoryPlane0`, \ `ImageAspect::MemoryPlane1`, `ImageAspect::MemoryPlane2` or \ @@ -1339,7 +1348,7 @@ impl RawImage { .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-02271"], ..Default::default() - }); + })); } } _ => unreachable!("image has more than 4 memory planes??"), @@ -1347,7 +1356,7 @@ impl RawImage { } else if format_aspects.contains(ImageAspects::DEPTH | ImageAspects::STENCIL) { // Follows from the combination of these three VUIDs. See: // https://github.com/KhronosGroup/Vulkan-Docs/issues/1942 - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self.format()".into(), problem: "has both a depth and a stencil aspect".into(), vuids: &[ @@ -1356,61 +1365,61 @@ impl RawImage { "VUID-vkGetImageSubresourceLayout-format-04463", ], ..Default::default() - }); + })); } else if format_aspects.intersects(ImageAspects::DEPTH) { if aspect != ImageAspect::Depth { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.format()` is a depth format, but \ `aspect` is not `ImageAspect::Depth`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-format-04462"], ..Default::default() - }); + })); } } else if format_aspects.intersects(ImageAspects::STENCIL) { if aspect != ImageAspect::Stencil { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.format()` is a stencil format, but \ `aspect` is not `ImageAspect::Stencil`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-format-04463"], ..Default::default() - }); + })); } } else if format_aspects.intersects(ImageAspects::COLOR) { if format.planes().is_empty() { if aspect != ImageAspect::Color { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.format()` is a color format with a single plane, but \ `aspect` is not `ImageAspect::Color`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-format-08886"], ..Default::default() - }); + })); } } else if format.planes().len() == 2 { if !matches!(aspect, ImageAspect::Plane0 | ImageAspect::Plane1) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.format()` is a color format with two planes, but \ `aspect` is not `ImageAspect::Plane0` or `ImageAspect::Plane1`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-08717"], ..Default::default() - }); + })); } } else if format.planes().len() == 3 { if !matches!( aspect, ImageAspect::Plane0 | ImageAspect::Plane1 | ImageAspect::Plane2 ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`self.format()` is a color format with three planes, but \ `aspect` is not `ImageAspect::Plane0`, `ImageAspect::Plane1` or \ `ImageAspect::Plane2`" .into(), vuids: &["VUID-vkGetImageSubresourceLayout-tiling-08717"], ..Default::default() - }); + })); } } } @@ -1427,12 +1436,12 @@ impl RawImage { // VUID-vkGetImageSubresourceLayout-format-01581 // VUID-vkGetImageSubresourceLayout-format-01582 if !format_aspects.contains(aspect.into()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "array_layer".into(), problem: "is greater than the number of array layers in the image".into(), vuids: &["VUID-vkGetImageSubresourceLayout-arrayLayer-01717"], ..Default::default() - }); + })); } Ok(()) @@ -1656,7 +1665,7 @@ impl Default for ImageCreateInfo { } impl ImageCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, image_type, @@ -1727,12 +1736,12 @@ impl ImageCreateInfo { })?; if usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "is empty".into(), vuids: &["VUID-VkImageCreateInfo-usage-requiredbitmask"], ..Default::default() - }); + })); } let format_properties = unsafe { physical_device.format_properties_unchecked(format) }; @@ -1764,7 +1773,7 @@ impl ImageCreateInfo { if !(device.api_version() >= Version::V1_2 || device.enabled_extensions().ext_separate_stencil_usage) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and `stencil_usage` \ is not empty or equal to `usage`" .into(), @@ -1773,7 +1782,7 @@ impl ImageCreateInfo { RequiresAllOf(&[Requires::DeviceExtension("ext_separate_stencil_usage")]), ]), ..Default::default() - }); + })); } stencil_usage @@ -1785,12 +1794,12 @@ impl ImageCreateInfo { })?; if stencil_usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_usage".into(), problem: "is empty".into(), vuids: &["VUID-VkImageStencilUsageCreateInfo-usage-requiredbitmask"], ..Default::default() - }); + })); } } @@ -1806,173 +1815,173 @@ impl ImageCreateInfo { initial_layout, ImageLayout::Undefined | ImageLayout::Preinitialized ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "initial_layout".into(), problem: "is not `ImageLayout::Undefined` or `ImageLayout::Preinitialized`".into(), vuids: &["VUID-VkImageCreateInfo-initialLayout-00993"], ..Default::default() - }); + })); } if flags.intersects(ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE) && !flags.intersects(ImageCreateFlags::MUTABLE_FORMAT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "flags".into(), problem: "contains `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, but does not \ contain `ImageCreateFlags::MUTABLE_FORMAT`" .into(), vuids: &["VUID-VkImageCreateInfo-flags-01573"], ..Default::default() - }); + })); } match image_type { ImageType::Dim1d => { if extent[1] != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image_type` is `ImageType::Dim1d`, but `extent[1]` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00956"], ..Default::default() - }); + })); } if extent[2] != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image_type` is `ImageType::Dim1d`, but `extent[2]` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00956"], ..Default::default() - }); + })); } } ImageType::Dim2d => { if extent[2] != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image_type` is `ImageType::Dim2d`, but `extent[2]` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00957"], ..Default::default() - }); + })); } } ImageType::Dim3d => { if array_layers != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image_type` is `ImageType::Dim3d`, but `array_layers` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00961"], ..Default::default() - }); + })); } } } if extent[0] == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[0]".into(), problem: "is zero".into(), vuids: &["VUID-VkImageCreateInfo-extent-00944"], ..Default::default() - }); + })); } if extent[1] == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[1]".into(), problem: "is zero".into(), vuids: &["VUID-VkImageCreateInfo-extent-00945"], ..Default::default() - }); + })); } if extent[2] == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[2]".into(), problem: "is zero".into(), vuids: &["VUID-VkImageCreateInfo-extent-00946"], ..Default::default() - }); + })); } if array_layers == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "array_layers".into(), problem: "is zero".into(), vuids: &["VUID-VkImageCreateInfo-arrayLayers-00948"], ..Default::default() - }); + })); } if mip_levels == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "mip_levels".into(), problem: "is zero".into(), vuids: &["VUID-VkImageCreateInfo-mipLevels-00947"], ..Default::default() - }); + })); } let max_mip_levels = max_mip_levels(extent); debug_assert!(max_mip_levels >= 1); if mip_levels > max_mip_levels { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`mip_levels` is greater than the maximum allowed number of mip levels \ for `dimensions`" .into(), vuids: &["VUID-VkImageCreateInfo-mipLevels-00958"], ..Default::default() - }); + })); } if samples != SampleCount::Sample1 { if image_type != ImageType::Dim2d { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`samples` is not `samples != SampleCount::Sample1`, but \ `image_type` is not `ImageType::Dim2d`" .into(), vuids: &["VUID-VkImageCreateInfo-samples-02257"], ..Default::default() - }); + })); } if flags.intersects(ImageCreateFlags::CUBE_COMPATIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`samples` is not `samples != SampleCount::Sample1`, but \ `flags` contains `ImageCreateFlags::CUBE_COMPATIBLE`" .into(), vuids: &["VUID-VkImageCreateInfo-samples-02257"], ..Default::default() - }); + })); } if mip_levels != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`samples` is not `samples != SampleCount::Sample1`, but \ `mip_levels` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-samples-02257"], ..Default::default() - }); + })); } if image_create_maybe_linear { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`samples` is not `samples != SampleCount::Sample1`, but \ the image may have linear tiling" .into(), vuids: &["VUID-VkImageCreateInfo-samples-02257"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().multisample_array_image && array_layers != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, \ `samples` is not `SampleCount::Sample1`, and \ `array_layers` is greater than 1" @@ -1982,44 +1991,44 @@ impl ImageCreateInfo { )])]), vuids: &["VUID-VkImageCreateInfo-multisampleArrayImage-04460"], ..Default::default() - }); + })); } } // Check limits for YCbCr formats if let Some(chroma_sampling) = format.ycbcr_chroma_sampling() { if mip_levels != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is a YCbCr format, but \ `mip_levels` is not 1" .into(), vuids: &["VUID-VkImageCreateInfo-format-06410"], ..Default::default() - }); + })); } if samples != SampleCount::Sample1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is a YCbCr format, but \ `samples` is not `SampleCount::Sample1`" .into(), vuids: &["VUID-VkImageCreateInfo-format-06411"], ..Default::default() - }); + })); } if image_type != ImageType::Dim2d { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is a YCbCr format, but \ `image_type` is not `ImageType::Dim2d`" .into(), vuids: &["VUID-VkImageCreateInfo-format-06412"], ..Default::default() - }); + })); } if array_layers > 1 && !device.enabled_features().ycbcr_image_arrays { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is is a YCbCr format, and \ `array_layers` is greater than 1" .into(), @@ -2028,14 +2037,14 @@ impl ImageCreateInfo { )])]), vuids: &["VUID-VkImageCreateInfo-format-06413"], ..Default::default() - }); + })); } match chroma_sampling { ChromaSampling::Mode444 => (), ChromaSampling::Mode422 => { if extent[0] % 2 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is a YCbCr format with horizontal \ chroma subsampling, but \ `extent[0]` is not \ @@ -2043,12 +2052,12 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-format-04712"], ..Default::default() - }); + })); } } ChromaSampling::Mode420 => { if !(extent[0] % 2 == 0 && extent[1] % 2 == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` is a YCbCr format with horizontal and vertical \ chroma subsampling, but \ `extent[0]` and `extent[1]` are not both \ @@ -2059,7 +2068,7 @@ impl ImageCreateInfo { "VUID-VkImageCreateInfo-format-04713", ], ..Default::default() - }); + })); } } } @@ -2073,7 +2082,7 @@ impl ImageCreateInfo { && samples != SampleCount::Sample1 && !device.enabled_features().shader_storage_image_multisample { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`usage` or `stencil_usage` contains \ `ImageUsage::STORAGE`, but `samples` is not `SampleCount::Sample1`" .into(), @@ -2085,7 +2094,7 @@ impl ImageCreateInfo { "VUID-VkImageCreateInfo-format-02538", ], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) { @@ -2094,7 +2103,7 @@ impl ImageCreateInfo { | ImageUsage::DEPTH_STENCIL_ATTACHMENT | ImageUsage::INPUT_ATTACHMENT, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "contains `ImageUsage::TRANSIENT_ATTACHMENT`, but does not also \ contain one of `ImageUsage::COLOR_ATTACHMENT`, \ @@ -2102,7 +2111,7 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-usage-00966"], ..Default::default() - }); + })); } if !(usage @@ -2112,7 +2121,7 @@ impl ImageCreateInfo { | ImageUsage::INPUT_ATTACHMENT)) .is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "usage".into(), problem: "contains `ImageUsage::TRANSIENT_ATTACHMENT`, but also contains \ usages other than `ImageUsage::COLOR_ATTACHMENT`, \ @@ -2120,7 +2129,7 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-usage-00963"], ..Default::default() - }); + })); } } @@ -2131,7 +2140,7 @@ impl ImageCreateInfo { | ImageUsage::TRANSIENT_ATTACHMENT, ) { if extent[0] > device_properties.max_framebuffer_width { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`usage` or `stencil_usage` contains \ `ImageUsage::COLOR_ATTACHMENT`, \ `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, \ @@ -2144,11 +2153,11 @@ impl ImageCreateInfo { "VUID-VkImageCreateInfo-Format-02536", ], ..Default::default() - }); + })); } if extent[1] > device_properties.max_framebuffer_height { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`usage` or `stencil_usage` contains \ `ImageUsage::COLOR_ATTACHMENT`, \ `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, \ @@ -2161,7 +2170,7 @@ impl ImageCreateInfo { "VUID-VkImageCreateInfo-format-02537", ], ..Default::default() - }); + })); } } @@ -2169,7 +2178,7 @@ impl ImageCreateInfo { if usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) && !stencil_usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and \ `stencil_usage` is not empty or equal to `usage`, and \ `usage` contains `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, but \ @@ -2178,13 +2187,13 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-format-02795"], ..Default::default() - }); + })); } if !usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) && stencil_usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and \ `stencil_usage` is not empty or equal to `usage`, and \ `usage` does not contain `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, but \ @@ -2192,13 +2201,13 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-format-02796"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) && !stencil_usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and \ `stencil_usage` is not empty or equal to `usage`, and \ `usage` contains `ImageUsage::TRANSIENT_ATTACHMENT`, but \ @@ -2207,13 +2216,13 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-format-02797"], ..Default::default() - }); + })); } if !usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) && stencil_usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and \ `stencil_usage` is not empty or equal to `usage`, and \ `usage` does not contain `ImageUsage::TRANSIENT_ATTACHMENT`, but \ @@ -2222,7 +2231,7 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-format-02798"], ..Default::default() - }); + })); } if stencil_usage.intersects(ImageUsage::TRANSIENT_ATTACHMENT) @@ -2232,7 +2241,7 @@ impl ImageCreateInfo { | ImageUsage::INPUT_ATTACHMENT)) .is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has both a depth and a stencil aspect, and \ `stencil_usage` is not empty or equal to `usage`, and \ `stencil_usage contains `ImageUsage::TRANSIENT_ATTACHMENT`, but \ @@ -2241,7 +2250,7 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageStencilUsageCreateInfo-stencilUsage-02539"], ..Default::default() - }); + })); } } @@ -2249,51 +2258,51 @@ impl ImageCreateInfo { if flags.intersects(ImageCreateFlags::CUBE_COMPATIBLE) { if image_type != ImageType::Dim2d { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::CUBE_COMPATIBLE`, but \ `image_type` is not `ImageType::Dim2d`" .into(), vuids: &["VUID-VkImageCreateInfo-flags-00949"], ..Default::default() - }); + })); } if extent[0] != extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::CUBE_COMPATIBLE`, but \ `extent[0]` does not equal `extent[1]`" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00954"], ..Default::default() - }); + })); } if array_layers < 6 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::CUBE_COMPATIBLE`, but \ `array_layers` is less than 6" .into(), vuids: &["VUID-VkImageCreateInfo-imageType-00954"], ..Default::default() - }); + })); } } if flags.intersects(ImageCreateFlags::DIM2D_ARRAY_COMPATIBLE) { if image_type != ImageType::Dim3d { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::DIM2D_ARRAY_COMPATIBLE`, but \ `image_type` is not `ImageType::Dim3d`" .into(), vuids: &["VUID-VkImageCreateInfo-flags-00950"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().image_view2_d_on3_d_image { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `flags` contains `ImageCreateFlags::DIM2D_ARRAY_COMPATIBLE`" .into(), @@ -2302,54 +2311,54 @@ impl ImageCreateInfo { )])]), vuids: &["VUID-VkImageCreateInfo-imageView2DOn3DImage-04459"], ..Default::default() - }); + })); } } if flags.intersects(ImageCreateFlags::DIM2D_VIEW_COMPATIBLE) { if image_type != ImageType::Dim3d { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::DIM2D_VIEW_COMPATIBLE`, but \ `image_type` is not `ImageType::Dim3d`" .into(), vuids: &["VUID-VkImageCreateInfo-flags-07755"], ..Default::default() - }); + })); } } if flags.intersects(ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE) && format.compression().is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, \ but `format` is not a compressed format" .into(), vuids: &["VUID-VkImageCreateInfo-flags-01572"], ..Default::default() - }); + })); } if flags.intersects(ImageCreateFlags::DISJOINT) { if format.planes().len() < 2 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::DISJOINT`, but `format` \ is not a multi-planat format" .into(), vuids: &["VUID-VkImageCreateInfo-format-01577"], ..Default::default() - }); + })); } if !image_create_format_features.intersects(FormatFeatures::DISJOINT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`flags` contains `ImageCreateFlags::DISJOINT`, but the \ format features of `format` do not include \ `FormatFeatures::DISJOINT`" .into(), vuids: &["VUID-VkImageCreateInfo-imageCreateFormatFeatures-02260"], ..Default::default() - }); + })); } } @@ -2359,13 +2368,13 @@ impl ImageCreateInfo { Sharing::Exclusive => (), Sharing::Concurrent(queue_family_indices) => { if queue_family_indices.len() < 2 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "sharing".into(), problem: "is `Sharing::Concurrent`, but contains less than 2 elements" .into(), vuids: &["VUID-VkImageCreateInfo-sharingMode-00942"], ..Default::default() - }); + })); } let queue_family_count = @@ -2373,7 +2382,7 @@ impl ImageCreateInfo { for (index, &queue_family_index) in queue_family_indices.iter().enumerate() { if queue_family_indices[..index].contains(&queue_family_index) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_indices".into(), problem: format!( "the queue family index in the list at index {} is contained in \ @@ -2383,17 +2392,17 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-sharingMode-01420"], ..Default::default() - }); + })); } if queue_family_index >= queue_family_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("sharing[{}]", index).into(), problem: "is not less than the number of queue families in the device" .into(), vuids: &["VUID-VkImageCreateInfo-sharingMode-01420"], ..Default::default() - }); + })); } } } @@ -2405,7 +2414,7 @@ impl ImageCreateInfo { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_external_memory) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "external_memory_handle_types".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[ @@ -2413,7 +2422,7 @@ impl ImageCreateInfo { RequiresAllOf(&[Requires::DeviceExtension("khr_external_memory")]), ]), ..Default::default() - }); + })); } external_memory_handle_types @@ -2425,13 +2434,13 @@ impl ImageCreateInfo { })?; if initial_layout != ImageLayout::Undefined { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`external_memory_handle_types` is not empty, but \ `initial_layout` is not `ImageLayout::Undefined`" .into(), vuids: &["VUID-VkImageCreateInfo-pNext-01443"], ..Default::default() - }); + })); } } @@ -2439,23 +2448,23 @@ impl ImageCreateInfo { // This implicitly checks for the enabled extension too, // so no need to check that separately. if tiling != ImageTiling::DrmFormatModifier { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`drm_format_modifiers` is not empty, but \ `tiling` is not `ImageTiling::DrmFormatModifier`" .into(), vuids: &["VUID-VkImageCreateInfo-pNext-02262"], ..Default::default() - }); + })); } if flags.intersects(ImageCreateFlags::MUTABLE_FORMAT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`tiling` is `ImageTiling::DrmFormatModifier`, but \ `flags` contains `ImageCreateFlags::MUTABLE_FORMAT`" .into(), vuids: &["VUID-VkImageCreateInfo-tiling-02353"], ..Default::default() - }); + })); } if drm_format_modifiers.len() == 1 { @@ -2476,7 +2485,7 @@ impl ImageCreateInfo { if drm_format_modifier_plane_layouts.len() != drm_format_modifier_properties.drm_format_modifier_plane_count as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`drm_format_modifiers` has a length of 1, but the length of \ `drm_format_modifiers_plane_layouts` does not \ equal `DrmFormatModifierProperties::drm_format_modifier_plane_count` \ @@ -2484,7 +2493,7 @@ impl ImageCreateInfo { `PhysicalDevice::format_properties` for `format`".into(), vuids: &["VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-drmFormatModifierPlaneCount-02265"], ..Default::default() - }); + })); } for (index, subresource_layout) in @@ -2499,7 +2508,7 @@ impl ImageCreateInfo { } = subresource_layout; if size != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("drm_format_modifier_plane_layouts[{}].size", index) .into(), problem: "is not zero".into(), @@ -2507,11 +2516,11 @@ impl ImageCreateInfo { "VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-size-02267", ], ..Default::default() - }); + })); } if array_layers == 1 && array_pitch.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`array_layers` is 1, but \ `drm_format_modifier_plane_layouts[{}].array_pitch` is `Some`", @@ -2520,11 +2529,11 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-arrayPitch-02268"], ..Default::default() - }); + })); } if extent[2] == 1 && depth_pitch.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`extent[2]` is 1, but \ `drm_format_modifier_plane_layouts[{}].depth_pitch` is `Some`", @@ -2533,37 +2542,37 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageDrmFormatModifierExplicitCreateInfoEXT-depthPitch-02269"], ..Default::default() - }); + })); } } } else { if !drm_format_modifier_plane_layouts.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`drm_format_modifiers` does not contain one element, but \ `drm_format_modifier_plane_layouts` is not empty" .into(), ..Default::default() - }); + })); } } } else { if tiling == ImageTiling::DrmFormatModifier { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`tiling` is `ImageTiling::DrmFormatModifier`, but \ `drm_format_modifiers` is `None`" .into(), vuids: &["VUID-VkImageCreateInfo-tiling-02261"], ..Default::default() - }); + })); } if !drm_format_modifier_plane_layouts.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`drm_format_modifiers` does not contain one element, but \ `drm_format_modifier_plane_layouts` is not empty" .into(), ..Default::default() - }); + })); } } @@ -2632,76 +2641,76 @@ impl ImageCreateInfo { } = image_format_properties; if extent[0] > max_extent[0] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`extent[0]` exceeds `max_extent[0]` for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-extent-02252"], ..Default::default() - }); + })); } if extent[1] > max_extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`extent[1]` exceeds `max_extent[1]` for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-extent-02253"], ..Default::default() - }); + })); } if extent[2] > max_extent[2] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`extent[2]` exceeds `max_extent[2]` for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-extent-02254"], ..Default::default() - }); + })); } if mip_levels > max_mip_levels { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`mip_levels` exceeds `max_mip_levels` for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-mipLevels-02255"], ..Default::default() - }); + })); } if array_layers > max_array_layers { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`array_layers` exceeds `max_array_layers` for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-arrayLayers-02256"], ..Default::default() - }); + })); } if !sample_counts.contains_enum(samples) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`samples` is not present in the `sample_counts` value for \ the combination of parameters of this image, as returned by \ `PhysicalDevice::image_format_properties`" .into(), vuids: &["VUID-VkImageCreateInfo-samples-02258"], ..Default::default() - }); + })); } if !external_memory_properties .compatible_handle_types .contains(external_memory_handle_types) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`external_memory_handle_types` is not a subset of the \ `external_memory_properties.compatible_handle_types` value for \ the combination of parameters of this image, as returned by \ @@ -2709,7 +2718,7 @@ impl ImageCreateInfo { .into(), vuids: &["VUID-VkImageCreateInfo-pNext-00990"], ..Default::default() - }); + })); } } } @@ -2727,7 +2736,7 @@ mod tests { ImageAspect, ImageAspects, ImageCreateFlags, ImageSubresourceRange, ImageType, SampleCount, SubresourceRangeIterator, }, - DeviceSize, Requires, RequiresAllOf, RequiresOneOf, ValidationError, VulkanError, + DeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, }; use smallvec::SmallVec; @@ -2781,7 +2790,7 @@ mod tests { ..Default::default() }, ), - Err(VulkanError::ValidationError(_)) + Err(Validated::ValidationError(_)) ),); } @@ -2802,7 +2811,7 @@ mod tests { ); match res { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), }; } @@ -2824,14 +2833,17 @@ mod tests { ); match res { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf( - [RequiresAllOf([Requires::Feature("shader_storage_image_multisample")])], - ), - .. - })) => (), - Err(VulkanError::ValidationError(_)) => (), // unlikely but possible + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([Requires::Feature( + "shader_storage_image_multisample" + )])],), + .. + } + ) => {} + Err(Validated::ValidationError(_)) => (), // unlikely but possible _ => panic!(), }; } @@ -2852,7 +2864,7 @@ mod tests { ); match res { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), }; } @@ -2872,7 +2884,7 @@ mod tests { ..Default::default() }, ), - Err(VulkanError::ValidationError(_)) + Err(Validated::ValidationError(_)) )) } @@ -2893,7 +2905,7 @@ mod tests { ); match res { - Err(VulkanError::ValidationError(_)) => (), + Err(Validated::ValidationError(_)) => (), _ => panic!(), }; } diff --git a/vulkano/src/image/view.rs b/vulkano/src/image/view.rs index 284098ed..3017bd5a 100644 --- a/vulkano/src/image/view.rs +++ b/vulkano/src/image/view.rs @@ -26,7 +26,7 @@ use crate::{ ImageAspects, ImageCreateFlags, ImageTiling, ImageType, SampleCount, }, macros::{impl_id_counter, vulkan_enum}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use smallvec::{smallvec, SmallVec}; @@ -61,7 +61,7 @@ impl ImageView { pub fn new( image: Arc, create_info: ImageViewCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&image, &create_info)?; unsafe { Ok(Self::new_unchecked(image, create_info)?) } @@ -70,7 +70,7 @@ impl ImageView { fn validate_new( image: &Image, create_info: &ImageViewCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let device = image.device(); create_info @@ -91,47 +91,47 @@ impl ImageView { let format_features = unsafe { get_format_features(format, image) }; if format_features.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "create_info.format".into(), problem: "the format features are empty".into(), vuids: &["VUID-VkImageViewCreateInfo-None-02273"], ..Default::default() - }); + })); } let image_type = image.image_type(); if !view_type.is_compatible_with(image_type) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is not compatible with \ `image.image_type()`" .into(), vuids: &["VUID-VkImageViewCreateInfo-subResourceRange-01021"], ..Default::default() - }); + })); } if subresource_range.mip_levels.end > image.mip_levels() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.subresource_range.mip_levels.end` is greater than \ `image.mip_levels()`" .into(), vuids: &["VUID-VkImageViewCreateInfo-subresourceRange-01718"], ..Default::default() - }); + })); } if matches!(view_type, ImageViewType::Cube | ImageViewType::CubeArray) && !image.flags().intersects(ImageCreateFlags::CUBE_COMPATIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is `ImageViewType::Cube` or \ `ImageViewType::CubeArray`, but \ `image.flags()` does not contain `ImageCreateFlags::CUBE_COMPATIBLE`" .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01003"], ..Default::default() - }); + })); } if matches!(view_type, ImageViewType::Dim2d | ImageViewType::Dim2dArray) @@ -143,7 +143,7 @@ impl ImageView { .flags() .intersects(ImageCreateFlags::DIM2D_ARRAY_COMPATIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is `ImageViewType::Dim2d`, and \ `image.image_type()` is `ImageType::Dim3d`, but \ `image.flags()` does not contain \ @@ -152,7 +152,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-06728"], ..Default::default() - }); + })); } } ImageViewType::Dim2dArray => { @@ -160,7 +160,7 @@ impl ImageView { .flags() .intersects(ImageCreateFlags::DIM2D_ARRAY_COMPATIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is `ImageViewType::Dim2dArray`, and \ `image.image_type()` is `ImageType::Dim3d`, but \ `image.flags()` does not contain \ @@ -168,14 +168,14 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-06723"], ..Default::default() - }); + })); } } _ => unreachable!(), } if subresource_range.mip_levels.len() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is `ImageViewType::Dim2d` or \ `ImageViewType::Dim2dArray`, and \ `image.image_type()` is `ImageType::Dim3d`, but \ @@ -183,7 +183,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-04970"], ..Default::default() - }); + })); } // We're using the depth dimension as array layers, but because of mip scaling, the @@ -193,7 +193,7 @@ impl ImageView { mip_level_extent(image.extent(), subresource_range.mip_levels.start).unwrap(); if subresource_range.array_layers.end > mip_level_extent[2] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.view_type` is `ImageViewType::Dim2d` or \ `ImageViewType::Dim2dArray`, and \ `image.image_type()` is `ImageType::Dim3d`, but \ @@ -206,11 +206,11 @@ impl ImageView { "VUID-VkImageViewCreateInfo-subresourceRange-02725", ], ..Default::default() - }); + })); } } else { if subresource_range.array_layers.end > image.array_layers() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.subresource_range.array_layers.end` is greater than \ `image.array_layers()`" .into(), @@ -219,21 +219,21 @@ impl ImageView { "VUID-VkImageViewCreateInfo-subresourceRange-06725", ], ..Default::default() - }); + })); } } if image.samples() != SampleCount::Sample1 && !matches!(view_type, ImageViewType::Dim2d | ImageViewType::Dim2dArray) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.samples()` is not `SampleCount::Sample1`, but \ `create_info.view_type` is not `ImageViewType::Dim2d` or \ `ImageViewType::Dim2dArray`" .into(), vuids: &["VUID-VkImageViewCreateInfo-image-04972"], ..Default::default() - }); + })); } /* Check usage requirements */ @@ -251,7 +251,7 @@ impl ImageView { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_maintenance2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` is not the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`)" .into(), @@ -260,7 +260,7 @@ impl ImageView { RequiresAllOf(&[Requires::DeviceExtension("khr_maintenance2")]), ]), ..Default::default() - }); + })); } // VUID-VkImageViewUsageCreateInfo-usage-requiredbitmask @@ -268,7 +268,7 @@ impl ImageView { // (which is already validated to not be empty). if !implicit_default_usage.contains(usage) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` is not a subset of the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`)" .into(), @@ -278,7 +278,7 @@ impl ImageView { "VUID-VkImageViewCreateInfo-pNext-02664", ], ..Default::default() - }); + })); } } @@ -290,7 +290,7 @@ impl ImageView { | ImageUsage::INPUT_ATTACHMENT | ImageUsage::TRANSIENT_ATTACHMENT, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "image.usage()".into(), problem: "does not contain one of `ImageUsage::SAMPLED`, `ImageUsage::STORAGE`, \ `ImageUsage::COLOR_ATTACHMENT`, `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, \ @@ -298,13 +298,13 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-04441"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::SAMPLED) && !format_features.intersects(FormatFeatures::SAMPLED_IMAGE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` or the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`) \ contains `ImageUsage::SAMPLED`, but \ @@ -313,13 +313,13 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-usage-02274"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::STORAGE) && !format_features.intersects(FormatFeatures::STORAGE_IMAGE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` or the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`) \ contains `ImageUsage::STORAGE`, but \ @@ -328,13 +328,13 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-usage-02275"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::COLOR_ATTACHMENT) && !format_features.intersects(FormatFeatures::COLOR_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` or the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`) \ contains `ImageUsage::COLOR_ATTACHMENT`, but \ @@ -343,13 +343,13 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-usage-02276"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) && !format_features.intersects(FormatFeatures::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` or the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`) \ contains `ImageUsage::DEPTH_STENCIL_ATTACHMENT`, but \ @@ -358,7 +358,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-usage-02277"], ..Default::default() - }); + })); } if usage.intersects(ImageUsage::INPUT_ATTACHMENT) @@ -366,7 +366,7 @@ impl ImageView { FormatFeatures::COLOR_ATTACHMENT | FormatFeatures::DEPTH_STENCIL_ATTACHMENT, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.usage` or the implicit default usage \ (calculated from `image` and `create_info.subresource_range.aspects`) \ contains `ImageUsage::INPUT_ATTACHMENT`, but \ @@ -376,7 +376,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-usage-02652"], ..Default::default() - }); + })); } /* Check flags requirements */ @@ -385,24 +385,24 @@ impl ImageView { if !image.format().unwrap().planes().is_empty() && subresource_range.aspects.intersects(ImageAspects::COLOR) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.format()` is a multi-planar format, and \ `create_info.subresource_range.aspects` contains `ImageAspects::COLOR`, \ but `create_info.format` does not equal `image.format()`" .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01762"], ..Default::default() - }); + })); } if !image.flags().intersects(ImageCreateFlags::MUTABLE_FORMAT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.format` does not equal `image.format()`, but \ `image.flags()` does not contain `ImageCreateFlags::MUTABLE_FORMAT`" .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01762"], ..Default::default() - }); + })); } // TODO: it is unclear what the number of bits is for compressed formats. @@ -411,7 +411,7 @@ impl ImageView { && !device.enabled_features().image_view_format_reinterpretation && format.components() != image.format().unwrap().components() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `create_info.format` does not have the same components and \ number of bits per component as `image.format()`" @@ -421,7 +421,7 @@ impl ImageView { )])]), vuids: &["VUID-VkImageViewCreateInfo-imageViewFormatReinterpretation-04466"], ..Default::default() - }); + })); } if image @@ -431,7 +431,7 @@ impl ImageView { if !(format.compatibility() == image.format().unwrap().compatibility() || format.block_size() == image.format().unwrap().block_size()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.flags()` contains \ `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, but \ `create_info.format` is not compatible with `image.format()`, or \ @@ -439,12 +439,12 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01583"], ..Default::default() - }); + })); } if format.compression().is_none() { if subresource_range.array_layers.len() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.flags()` contains \ `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, and \ `create_info.format` is not a compressed format, but \ @@ -453,11 +453,11 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-07072"], ..Default::default() - }); + })); } if subresource_range.mip_levels.len() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.flags()` contains \ `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, and \ `create_info.format` is not a compressed format, but \ @@ -466,13 +466,13 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-07072"], ..Default::default() - }); + })); } } } else { if image.format().unwrap().planes().is_empty() { if format.compatibility() != image.format().unwrap().compatibility() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.flags()` does not contain \ `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, and \ `image.format()` is not a multi-planar format, but \ @@ -480,7 +480,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01761"], ..Default::default() - }); + })); } } else if subresource_range.aspects.intersects( ImageAspects::PLANE_0 | ImageAspects::PLANE_1 | ImageAspects::PLANE_2, @@ -497,7 +497,7 @@ impl ImageView { let plane_format = image.format().unwrap().planes()[plane]; if format.compatibility() != plane_format.compatibility() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`image.flags()` does not contain \ `ImageCreateFlags::BLOCK_TEXEL_VIEW_COMPATIBLE`, and \ `image.format()` is a multi-planar format, but \ @@ -506,7 +506,7 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-image-01586"], ..Default::default() - }); + })); } } } @@ -517,7 +517,7 @@ impl ImageView { ChromaSampling::Mode444 => (), ChromaSampling::Mode422 => { if image.extent()[0] % 2 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.format` is a YCbCr format with horizontal \ chroma subsampling, but \ `image.extent()[0]` is not \ @@ -525,12 +525,12 @@ impl ImageView { .into(), vuids: &["VUID-VkImageViewCreateInfo-format-04714"], ..Default::default() - }); + })); } } ChromaSampling::Mode420 => { if !(image.extent()[0] % 2 == 0 && image.extent()[1] % 2 == 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.format` is a YCbCr format with horizontal \ and vertical chroma subsampling, but \ `image.extent()[0]` and `image.extent()[1]` \ @@ -541,7 +541,7 @@ impl ImageView { "VUID-VkImageViewCreateInfo-format-04715", ], ..Default::default() - }); + })); } } } @@ -554,7 +554,7 @@ impl ImageView { pub unsafe fn new_unchecked( image: Arc, create_info: ImageViewCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &ImageViewCreateInfo { view_type, format, @@ -618,7 +618,7 @@ impl ImageView { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -627,7 +627,7 @@ impl ImageView { /// Creates a default `ImageView`. Equivalent to /// `ImageView::new(image, ImageViewCreateInfo::from_image(image))`. - pub fn new_default(image: Arc) -> Result, VulkanError> { + pub fn new_default(image: Arc) -> Result, Validated> { let create_info = ImageViewCreateInfo::from_image(&image); Self::new(image, create_info) @@ -643,7 +643,7 @@ impl ImageView { image: Arc, handle: ash::vk::ImageView, create_info: ImageViewCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let ImageViewCreateInfo { view_type, format, @@ -921,7 +921,7 @@ impl ImageViewCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { view_type, format, @@ -973,48 +973,48 @@ impl ImageViewCreateInfo { match view_type { ImageViewType::Dim1d | ImageViewType::Dim2d | ImageViewType::Dim3d => { if subresource_range.array_layers.len() != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`view_type` is `ImageViewType::Dim1d`, \ `ImageViewType::Dim2d` or `ImageViewType::Dim3d`, but \ the length of `subresource_range.array_layers` is not 1" .into(), vuids: &["VUID-VkImageViewCreateInfo-imageViewType-04973"], ..Default::default() - }); + })); } } ImageViewType::Cube => { if subresource_range.array_layers.len() != 6 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`view_type` is `ImageViewType::Cube`, but \ the length of `subresource_range.array_layers` is not 6" .into(), vuids: &["VUID-VkImageViewCreateInfo-viewType-02960"], ..Default::default() - }); + })); } } ImageViewType::CubeArray => { if !device.enabled_features().image_cube_array { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "view_type".into(), problem: "is `ImageViewType::CubeArray`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "image_cube_array", )])]), vuids: &["VUID-VkImageViewCreateInfo-viewType-01004"], - }); + })); } if subresource_range.array_layers.len() % 6 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`view_type` is `ImageViewType::CubeArray`, but \ the length of `subresource_range.array_layers` is not \ a multiple of 6" .into(), vuids: &["VUID-VkImageViewCreateInfo-viewType-02961"], ..Default::default() - }); + })); } } _ => (), @@ -1026,21 +1026,21 @@ impl ImageViewCreateInfo { .count() > 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "subresource_range.aspects".into(), problem: "contains more than one of `ImageAspects::PLANE_0`, \ `ImageAspects::PLANE_1` and `ImageAspects::PLANE_2`" .into(), vuids: &["VUID-VkImageViewCreateInfo-subresourceRange-07818"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset && !device.enabled_features().image_view_format_swizzle && !component_mapping.is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `component_mapping` is not the identity mapping" .into(), @@ -1049,7 +1049,7 @@ impl ImageViewCreateInfo { )])]), vuids: &["VUID-VkImageViewCreateInfo-imageViewFormatSwizzle-04465"], ..Default::default() - }); + })); } // Don't need to check features because you can't create a conversion object without the @@ -1058,23 +1058,23 @@ impl ImageViewCreateInfo { assert_eq!(device, conversion.device().as_ref()); if !component_mapping.is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `Some`, but \ `component_mapping` is not the identity mapping" .into(), vuids: &["VUID-VkImageViewCreateInfo-pNext-01970"], ..Default::default() - }); + })); } } else { if format.ycbcr_chroma_sampling().is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`sampler_ycbcr_conversion` is `None`, but \ `format.ycbcr_chroma_sampling()` is `Some`" .into(), vuids: &["VUID-VkImageViewCreateInfo-format-06415"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/instance/debug.rs b/vulkano/src/instance/debug.rs index c9633dc8..9a6aa789 100644 --- a/vulkano/src/instance/debug.rs +++ b/vulkano/src/instance/debug.rs @@ -44,7 +44,7 @@ use super::{Instance, InstanceExtensions}; use crate::{ macros::{vulkan_bitflags, vulkan_enum}, - DebugWrapper, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + DebugWrapper, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use std::{ @@ -81,7 +81,7 @@ impl DebugUtilsMessenger { pub unsafe fn new( instance: Arc, create_info: DebugUtilsMessengerCreateInfo, - ) -> Result { + ) -> Result> { Self::validate_new(&instance, &create_info)?; Ok(Self::new_unchecked(instance, create_info)?) @@ -90,14 +90,14 @@ impl DebugUtilsMessenger { fn validate_new( instance: &Instance, create_info: &DebugUtilsMessengerCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().ext_debug_utils { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_debug_utils", )])]), ..Default::default() - }); + })); } create_info @@ -111,7 +111,7 @@ impl DebugUtilsMessenger { pub unsafe fn new_unchecked( instance: Arc, create_info: DebugUtilsMessengerCreateInfo, - ) -> Result { + ) -> Result { let DebugUtilsMessengerCreateInfo { message_severity, message_type, @@ -142,7 +142,7 @@ impl DebugUtilsMessenger { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -263,7 +263,7 @@ impl DebugUtilsMessengerCreateInfo { } #[inline] - pub(crate) fn validate(&self, instance: &Instance) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, instance: &Instance) -> Result<(), Box> { self.validate_raw(instance.api_version(), instance.enabled_extensions()) } @@ -271,7 +271,7 @@ impl DebugUtilsMessengerCreateInfo { &self, instance_api_version: Version, instance_extensions: &InstanceExtensions, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let &DebugUtilsMessengerCreateInfo { message_severity, message_type, @@ -288,12 +288,12 @@ impl DebugUtilsMessengerCreateInfo { })?; if message_severity.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "message_severity".into(), problem: "is empty".into(), vuids: &["VUID-VkDebugUtilsMessengerCreateInfoEXT-messageSeverity-requiredbitmask"], ..Default::default() - }); + })); } message_type @@ -305,12 +305,12 @@ impl DebugUtilsMessengerCreateInfo { })?; if message_type.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "message_type".into(), problem: "is empty".into(), vuids: &["VUID-VkDebugUtilsMessengerCreateInfoEXT-messageType-requiredbitmask"], ..Default::default() - }); + })); } // VUID-PFN_vkDebugUtilsMessengerCallbackEXT-None-04769 diff --git a/vulkano/src/instance/mod.rs b/vulkano/src/instance/mod.rs index 2ce98465..c702bfa2 100644 --- a/vulkano/src/instance/mod.rs +++ b/vulkano/src/instance/mod.rs @@ -90,8 +90,8 @@ use crate::{ }, instance::debug::trampoline, macros::{impl_id_counter, vulkan_bitflags}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, VulkanError, - VulkanLibrary, VulkanObject, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, VulkanError, VulkanLibrary, + VulkanObject, }; pub use crate::{fns::InstanceFunctions, version::Version}; use ash::vk::Handle; @@ -291,7 +291,7 @@ impl Instance { pub fn new( library: Arc, create_info: InstanceCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { unsafe { Self::with_debug_utils_messengers(library, create_info, []) } } @@ -313,7 +313,7 @@ impl Instance { library: Arc, mut create_info: InstanceCreateInfo, debug_utils_messengers: impl IntoIterator, - ) -> Result, VulkanError> { + ) -> Result, Validated> { create_info.max_api_version.get_or_insert_with(|| { let api_version = library.api_version(); if api_version < Version::V1_1 { @@ -337,7 +337,7 @@ impl Instance { library: &VulkanLibrary, create_info: &InstanceCreateInfo, debug_utils_messengers: &[DebugUtilsMessengerCreateInfo], - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateInstance-pCreateInfo-parameter create_info .validate(library) @@ -373,14 +373,14 @@ impl Instance { if !debug_utils_messengers.is_empty() { if !create_info.enabled_extensions.ext_debug_utils { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "debug_utils_messengers".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("ext_debug_utils"), ])]), vuids: &["VUID-VkInstanceCreateInfo-pNext-04926"], - }); + })); } for (index, messenger_create_info) in debug_utils_messengers.iter().enumerate() { @@ -397,7 +397,7 @@ impl Instance { pub unsafe fn new_unchecked( library: Arc, create_info: InstanceCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { Self::with_debug_utils_messengers_unchecked(library, create_info, []) } @@ -406,7 +406,7 @@ impl Instance { library: Arc, mut create_info: InstanceCreateInfo, debug_utils_messengers: impl IntoIterator, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { create_info.max_api_version.get_or_insert_with(|| { let api_version = library.api_version(); if api_version < Version::V1_1 { @@ -572,7 +572,7 @@ impl Instance { let fns = library.fns(); (fns.v1_0.create_instance)(&create_info_vk, ptr::null(), output.as_mut_ptr()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -711,7 +711,7 @@ impl Instance { /// ``` pub fn enumerate_physical_devices( self: &Arc, - ) -> Result>, RuntimeError> { + ) -> Result>, VulkanError> { let fns = self.fns(); unsafe { @@ -719,7 +719,7 @@ impl Instance { let mut count = 0; (fns.v1_0.enumerate_physical_devices)(self.handle, &mut count, ptr::null_mut()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut handles = Vec::with_capacity(count as usize); let result = (fns.v1_0.enumerate_physical_devices)( @@ -734,7 +734,7 @@ impl Instance { break handles; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -769,23 +769,24 @@ impl Instance { #[inline] pub fn enumerate_physical_device_groups( self: &Arc, - ) -> Result, VulkanError> { + ) -> Result, Validated> + { self.validate_enumerate_physical_device_groups()?; unsafe { Ok(self.enumerate_physical_device_groups_unchecked()?) } } - fn validate_enumerate_physical_device_groups(&self) -> Result<(), ValidationError> { + fn validate_enumerate_physical_device_groups(&self) -> Result<(), Box> { if !(self.api_version() >= Version::V1_1 || self.enabled_extensions().khr_device_group_creation) { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]), RequiresAllOf(&[Requires::InstanceExtension("khr_device_group_creation")]), ]), ..Default::default() - }); + })); } Ok(()) @@ -794,7 +795,7 @@ impl Instance { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] pub unsafe fn enumerate_physical_device_groups_unchecked( self: &Arc, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let fns = self.fns(); let enumerate_physical_device_groups = if self.api_version() >= Version::V1_1 { fns.v1_1.enumerate_physical_device_groups @@ -808,7 +809,7 @@ impl Instance { enumerate_physical_device_groups(self.handle, &mut count, ptr::null_mut()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut properties = Vec::with_capacity(count as usize); let result = @@ -820,7 +821,7 @@ impl Instance { break properties; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -1068,7 +1069,7 @@ impl InstanceCreateInfo { } } - pub(crate) fn validate(&self, library: &VulkanLibrary) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, library: &VulkanLibrary) -> Result<(), Box> { let &Self { flags, application_name: _, @@ -1087,12 +1088,12 @@ impl InstanceCreateInfo { let api_version = std::cmp::min(max_api_version, library.api_version()); if max_api_version < Version::V1_0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "max_api_version".into(), problem: "is less than 1.0".into(), vuids: &["VUID-VkApplicationInfo-apiVersion-04010"], ..Default::default() - }); + })); } flags @@ -1105,14 +1106,14 @@ impl InstanceCreateInfo { if !enabled_validation_features.is_empty() { if !enabled_extensions.ext_validation_features { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_validation_features".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("ext_validation_features"), ])]), ..Default::default() - }); + })); } for (index, enabled) in enabled_validation_features.iter().enumerate() { @@ -1131,7 +1132,7 @@ impl InstanceCreateInfo { .contains(&ValidationFeatureEnable::GpuAssistedReserveBindingSlot) && !enabled_validation_features.contains(&ValidationFeatureEnable::GpuAssisted) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_validation_features".into(), problem: "contains `ValidationFeatureEnable::GpuAssistedReserveBindingSlot`, \ but does not also contain \ @@ -1139,33 +1140,33 @@ impl InstanceCreateInfo { .into(), vuids: &["VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02967"], ..Default::default() - }); + })); } if enabled_validation_features.contains(&ValidationFeatureEnable::DebugPrintf) && enabled_validation_features.contains(&ValidationFeatureEnable::GpuAssisted) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enabled_validation_features".into(), problem: "contains both `ValidationFeatureEnable::DebugPrintf` and \ `ValidationFeatureEnable::GpuAssisted`" .into(), vuids: &["VUID-VkValidationFeaturesEXT-pEnabledValidationFeatures-02968"], ..Default::default() - }); + })); } } if !disabled_validation_features.is_empty() { if !enabled_extensions.ext_validation_features { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "disabled_validation_features".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("ext_validation_features"), ])]), ..Default::default() - }); + })); } for (index, disabled) in disabled_validation_features.iter().enumerate() { diff --git a/vulkano/src/lib.rs b/vulkano/src/lib.rs index d07357b0..33dcbe48 100644 --- a/vulkano/src/lib.rs +++ b/vulkano/src/lib.rs @@ -290,72 +290,179 @@ impl Deref for DebugWrapper { } } -/// An error that can happen when calling a safe (validated) function that makes a call to the -/// Vulkan API. -#[derive(Clone)] -pub enum VulkanError { - /// The function call was invalid in some way. - ValidationError(ValidationError), +// Generated by build.rs +include!(concat!(env!("OUT_DIR"), "/errors.rs")); - /// The Vulkan driver returned an error and was unable to complete the operation. - RuntimeError(RuntimeError), -} - -impl VulkanError { - /// Returns the contained `RuntimeError` value, or panics if it contains `ValidationError`. - #[track_caller] - #[inline] - pub fn unwrap_runtime(self) -> RuntimeError { - match self { - VulkanError::ValidationError(err) => { - panic!( - "called `VulkanError::unwrap_runtime` on a `ValidationError` value: {:?}", - err - ) - } - VulkanError::RuntimeError(err) => err, - } - } -} - -impl Debug for VulkanError { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - match self { - Self::ValidationError(err) => { - write!(f, "a validation error occurred\n\nCaused by:\n {err:?}") - } - Self::RuntimeError(err) => write!(f, "a runtime error occurred: {err}"), - } - } -} +impl Error for VulkanError {} impl Display for VulkanError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + let msg = match self { + VulkanError::OutOfHostMemory => "a host memory allocation has failed", + VulkanError::OutOfDeviceMemory => "a device memory allocation has failed", + VulkanError::InitializationFailed => { + "initialization of an object could not be completed for implementation-specific \ + reasons" + } + VulkanError::DeviceLost => "the logical or physical device has been lost", + VulkanError::MemoryMapFailed => "mapping of a memory object has failed", + VulkanError::LayerNotPresent => { + "a requested layer is not present or could not be loaded" + } + VulkanError::ExtensionNotPresent => "a requested extension is not supported", + VulkanError::FeatureNotPresent => "a requested feature is not supported", + VulkanError::IncompatibleDriver => { + "the requested version of Vulkan is not supported by the driver or is otherwise \ + incompatible for implementation-specific reasons" + } + VulkanError::TooManyObjects => "too many objects of the type have already been created", + VulkanError::FormatNotSupported => "a requested format is not supported on this device", + VulkanError::FragmentedPool => { + "a pool allocation has failed due to fragmentation of the pool's memory" + } + VulkanError::Unknown => { + "an unknown error has occurred; either the application has provided invalid input, \ + or an implementation failure has occurred" + } + VulkanError::OutOfPoolMemory => "a pool memory allocation has failed", + VulkanError::InvalidExternalHandle => { + "an external handle is not a valid handle of the specified type" + } + VulkanError::Fragmentation => { + "a descriptor pool creation has failed due to fragmentation" + } + VulkanError::InvalidOpaqueCaptureAddress => { + "a buffer creation or memory allocation failed because the requested address is \ + not available. A shader group handle assignment failed because the requested \ + shader group handle information is no longer valid" + } + VulkanError::IncompatibleDisplay => { + "the display used by a swapchain does not use the same presentable image layout, \ + or is incompatible in a way that prevents sharing an image" + } + VulkanError::NotPermitted => "a requested operation was not permitted", + VulkanError::SurfaceLost => "a surface is no longer available", + VulkanError::NativeWindowInUse => { + "the requested window is already in use by Vulkan or another API in a manner which \ + prevents it from being used again" + } + VulkanError::OutOfDate => { + "a surface has changed in such a way that it is no longer compatible with the \ + swapchain, and further presentation requests using the swapchain will fail" + } + VulkanError::InvalidVideoStdParameters => { + "the provided Video Std parameters do not adhere to the requirements of the used \ + video compression standard" + } + VulkanError::ValidationFailed => "validation failed", + VulkanError::FullScreenExclusiveModeLost => { + "an operation on a swapchain created with application controlled full-screen \ + access failed as it did not have exclusive full-screen access" + } + VulkanError::InvalidDrmFormatModifierPlaneLayout => { + "the requested DRM format modifier plane layout is invalid" + } + VulkanError::InvalidShader => "one or more shaders failed to compile or link", + VulkanError::ImageUsageNotSupported => "the requested `ImageUsage` are not supported", + VulkanError::VideoPictureLayoutNotSupported => { + "the requested video picture layout is not supported" + } + VulkanError::VideoProfileOperationNotSupported => { + "a video profile operation specified via `VideoProfileInfo::video_codec_operation` \ + is not supported" + } + VulkanError::VideoProfileFormatNotSupported => { + "format parameters in a requested `VideoProfileInfo` chain are not supported" + } + VulkanError::VideoProfileCodecNotSupported => { + "codec-specific parameters in a requested `VideoProfileInfo` chain are not \ + supported" + } + VulkanError::VideoStdVersionNotSupported => { + "the specified video Std header version is not supported" + } + VulkanError::CompressionExhausted => { + "an image creation failed because internal resources required for compression are \ + exhausted" + } + VulkanError::Unnamed(result) => { + return write!(f, "unnamed error, VkResult value {}", result.as_raw()); + } + }; + + write!(f, "{msg}") + } +} + +impl From for Validated { + fn from(err: VulkanError) -> Self { + Self::Error(err) + } +} + +/// A wrapper for error types of functions that can return validation errors. +#[derive(Clone)] +pub enum Validated { + /// A non-validation error occurred. + Error(E), + + /// A validation error occurred. + ValidationError(Box), +} + +impl Validated { + /// Returns the inner `Error` value, or panics if it contains `ValidationError`. + pub fn unwrap(self) -> E { match self { - Self::ValidationError(_) => write!(f, "a validation error occurred"), - Self::RuntimeError(_) => write!(f, "a runtime error occurred"), + Self::Error(err) => err, + Self::ValidationError(err) => { + panic!( + "called `Validated::unwrap` on a `ValidationError` value: {:?}", + err + ) + } } } } -impl Error for VulkanError { +impl Error for Validated +where + E: Error + 'static, +{ fn source(&self) -> Option<&(dyn Error + 'static)> { match self { + Self::Error(err) => Some(err), Self::ValidationError(err) => Some(err), - Self::RuntimeError(err) => Some(err), } } } -impl From for VulkanError { - fn from(err: ValidationError) -> Self { - Self::ValidationError(err) +impl Display for Validated { + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + match self { + Self::Error(_) => write!(f, "a non-validation error occurred"), + Self::ValidationError(_) => write!(f, "a validation error occurred"), + } } } -impl From for VulkanError { - fn from(err: RuntimeError) -> Self { - Self::RuntimeError(err) +impl Debug for Validated +where + E: Display, +{ + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { + match self { + Self::Error(err) => write!(f, "a non-validation error occurred: {err}"), + Self::ValidationError(err) => { + write!(f, "a validation error occurred\n\nCaused by:\n {err:?}") + } + } + } +} + +impl From> for Validated { + fn from(err: Box) -> Self { + Self::ValidationError(err) } } @@ -394,18 +501,14 @@ impl ValidationError { } } - fn add_context(self, context: impl Into>) -> Self { + fn add_context(mut self: Box, context: impl Into>) -> Box { if self.context.is_empty() { - Self { - context: context.into(), - ..self - } + self.context = context.into(); } else { - Self { - context: format!("{}.{}", context.into(), self.context).into(), - ..self - } + self.context = format!("{}.{}", context.into(), self.context).into(); } + + self } } @@ -595,124 +698,16 @@ impl Display for OomError { } } -impl From for OomError { - fn from(err: RuntimeError) -> OomError { +impl From for OomError { + fn from(err: VulkanError) -> OomError { match err { - RuntimeError::OutOfHostMemory => OomError::OutOfHostMemory, - RuntimeError::OutOfDeviceMemory => OomError::OutOfDeviceMemory, + VulkanError::OutOfHostMemory => OomError::OutOfHostMemory, + VulkanError::OutOfDeviceMemory => OomError::OutOfDeviceMemory, _ => panic!("unexpected error: {:?}", err), } } } -// Generated by build.rs -include!(concat!(env!("OUT_DIR"), "/errors.rs")); - -impl Error for RuntimeError {} - -impl Display for RuntimeError { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { - let msg = match self { - RuntimeError::OutOfHostMemory => "a host memory allocation has failed", - RuntimeError::OutOfDeviceMemory => "a device memory allocation has failed", - RuntimeError::InitializationFailed => { - "initialization of an object could not be completed for implementation-specific \ - reasons" - } - RuntimeError::DeviceLost => "the logical or physical device has been lost", - RuntimeError::MemoryMapFailed => "mapping of a memory object has failed", - RuntimeError::LayerNotPresent => { - "a requested layer is not present or could not be loaded" - } - RuntimeError::ExtensionNotPresent => "a requested extension is not supported", - RuntimeError::FeatureNotPresent => "a requested feature is not supported", - RuntimeError::IncompatibleDriver => { - "the requested version of Vulkan is not supported by the driver or is otherwise \ - incompatible for implementation-specific reasons" - } - RuntimeError::TooManyObjects => { - "too many objects of the type have already been created" - } - RuntimeError::FormatNotSupported => { - "a requested format is not supported on this device" - } - RuntimeError::FragmentedPool => { - "a pool allocation has failed due to fragmentation of the pool's memory" - } - RuntimeError::Unknown => { - "an unknown error has occurred; either the application has provided invalid input, \ - or an implementation failure has occurred" - } - RuntimeError::OutOfPoolMemory => "a pool memory allocation has failed", - RuntimeError::InvalidExternalHandle => { - "an external handle is not a valid handle of the specified type" - } - RuntimeError::Fragmentation => { - "a descriptor pool creation has failed due to fragmentation" - } - RuntimeError::InvalidOpaqueCaptureAddress => { - "a buffer creation or memory allocation failed because the requested address is \ - not available. A shader group handle assignment failed because the requested \ - shader group handle information is no longer valid" - } - RuntimeError::IncompatibleDisplay => { - "the display used by a swapchain does not use the same presentable image layout, \ - or is incompatible in a way that prevents sharing an image" - } - RuntimeError::NotPermitted => "a requested operation was not permitted", - RuntimeError::SurfaceLost => "a surface is no longer available", - RuntimeError::NativeWindowInUse => { - "the requested window is already in use by Vulkan or another API in a manner which \ - prevents it from being used again" - } - RuntimeError::OutOfDate => { - "a surface has changed in such a way that it is no longer compatible with the \ - swapchain, and further presentation requests using the swapchain will fail" - } - RuntimeError::InvalidVideoStdParameters => { - "the provided Video Std parameters do not adhere to the requirements of the used \ - video compression standard" - } - RuntimeError::ValidationFailed => "validation failed", - RuntimeError::FullScreenExclusiveModeLost => { - "an operation on a swapchain created with application controlled full-screen \ - access failed as it did not have exclusive full-screen access" - } - RuntimeError::InvalidDrmFormatModifierPlaneLayout => { - "the requested DRM format modifier plane layout is invalid" - } - RuntimeError::InvalidShader => "one or more shaders failed to compile or link", - RuntimeError::ImageUsageNotSupported => "the requested `ImageUsage` are not supported", - RuntimeError::VideoPictureLayoutNotSupported => { - "the requested video picture layout is not supported" - } - RuntimeError::VideoProfileOperationNotSupported => { - "a video profile operation specified via `VideoProfileInfo::video_codec_operation` \ - is not supported" - } - RuntimeError::VideoProfileFormatNotSupported => { - "format parameters in a requested `VideoProfileInfo` chain are not supported" - } - RuntimeError::VideoProfileCodecNotSupported => { - "codec-specific parameters in a requested `VideoProfileInfo` chain are not \ - supported" - } - RuntimeError::VideoStdVersionNotSupported => { - "the specified video Std header version is not supported" - } - RuntimeError::CompressionExhausted => { - "an image creation failed because internal resources required for compression are \ - exhausted" - } - RuntimeError::Unnamed(result) => { - return write!(f, "unnamed error, VkResult value {}", result.as_raw()); - } - }; - - write!(f, "{msg}") - } -} - /// A helper type for non-exhaustive structs. /// /// This type cannot be constructed outside Vulkano. Structures with a field of this type can only diff --git a/vulkano/src/library.rs b/vulkano/src/library.rs index b806e314..528473ce 100644 --- a/vulkano/src/library.rs +++ b/vulkano/src/library.rs @@ -21,7 +21,7 @@ pub use crate::fns::EntryFunctions; use crate::{ instance::{InstanceExtensions, LayerProperties}, - ExtensionProperties, OomError, RuntimeError, SafeDeref, Version, + ExtensionProperties, OomError, SafeDeref, Version, VulkanError, }; use libloading::{Error as LibloadingError, Library}; use std::{ @@ -121,7 +121,7 @@ impl VulkanLibrary { })) } - unsafe fn get_api_version(loader: &impl Loader) -> Result { + unsafe fn get_api_version(loader: &impl Loader) -> Result { // Per the Vulkan spec: // If the vkGetInstanceProcAddr returns NULL for vkEnumerateInstanceVersion, it is a // Vulkan 1.0 implementation. Otherwise, the application can call vkEnumerateInstanceVersion @@ -133,9 +133,7 @@ impl VulkanLibrary { let version = if let Some(func) = func { let func: ash::vk::PFN_vkEnumerateInstanceVersion = transmute(func); let mut api_version = 0; - func(&mut api_version) - .result() - .map_err(RuntimeError::from)?; + func(&mut api_version).result().map_err(VulkanError::from)?; Version::from(api_version) } else { Version { @@ -151,7 +149,7 @@ impl VulkanLibrary { unsafe fn get_extension_properties( fns: &EntryFunctions, layer: Option<&str>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let layer_vk = layer.map(|layer| CString::new(layer).unwrap()); loop { @@ -164,7 +162,7 @@ impl VulkanLibrary { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut output = Vec::with_capacity(count as usize); let result = (fns.v1_0.enumerate_instance_extension_properties)( @@ -181,7 +179,7 @@ impl VulkanLibrary { return Ok(output.into_iter().map(Into::into).collect()); } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } } } @@ -243,7 +241,7 @@ impl VulkanLibrary { let mut count = 0; (fns.v1_0.enumerate_instance_layer_properties)(&mut count, ptr::null_mut()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut properties = Vec::with_capacity(count as usize); let result = (fns.v1_0.enumerate_instance_layer_properties)( @@ -257,7 +255,7 @@ impl VulkanLibrary { break properties; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } } }; @@ -272,7 +270,7 @@ impl VulkanLibrary { pub fn layer_extension_properties( &self, layer: &str, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { unsafe { Self::get_extension_properties(&self.fns, Some(layer)) } } @@ -281,7 +279,7 @@ impl VulkanLibrary { pub fn supported_layer_extensions( &self, layer: &str, - ) -> Result { + ) -> Result { Ok(self .layer_extension_properties(layer)? .iter() @@ -295,7 +293,7 @@ impl VulkanLibrary { pub fn supported_extensions_with_layers<'a>( &self, layers: impl IntoIterator, - ) -> Result { + ) -> Result { layers .into_iter() .try_fold(self.supported_extensions, |extensions, layer| { @@ -427,14 +425,14 @@ pub enum LoadingError { LibraryLoadFailure(LibloadingError), /// The Vulkan driver returned an error and was unable to complete the operation. - RuntimeError(RuntimeError), + VulkanError(VulkanError), } impl Error for LoadingError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { //Self::LibraryLoadFailure(err) => Some(err), - Self::RuntimeError(err) => Some(err), + Self::VulkanError(err) => Some(err), _ => None, } } @@ -444,14 +442,14 @@ impl Display for LoadingError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { match self { Self::LibraryLoadFailure(_) => write!(f, "failed to load the Vulkan shared library"), - Self::RuntimeError(err) => write!(f, "a runtime error occurred: {err}"), + Self::VulkanError(err) => write!(f, "a runtime error occurred: {err}"), } } } -impl From for LoadingError { - fn from(err: RuntimeError) -> Self { - Self::RuntimeError(err) +impl From for LoadingError { + fn from(err: VulkanError) -> Self { + Self::VulkanError(err) } } diff --git a/vulkano/src/memory/allocator/mod.rs b/vulkano/src/memory/allocator/mod.rs index a895192c..c71022cf 100644 --- a/vulkano/src/memory/allocator/mod.rs +++ b/vulkano/src/memory/allocator/mod.rs @@ -235,7 +235,7 @@ use super::{ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, - DeviceSize, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + DeviceSize, Requires, RequiresAllOf, RequiresOneOf, ValidationError, Version, VulkanError, }; use ash::vk::{MAX_MEMORY_HEAPS, MAX_MEMORY_TYPES}; use parking_lot::RwLock; @@ -525,7 +525,7 @@ pub enum MemoryAllocatePreference { /// [memory allocator]: MemoryAllocator #[derive(Clone, Debug, PartialEq, Eq)] pub enum MemoryAllocatorError { - RuntimeError(RuntimeError), + VulkanError(VulkanError), /// There is not enough memory in the pool. /// @@ -555,7 +555,7 @@ pub enum MemoryAllocatorError { impl Error for MemoryAllocatorError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - Self::RuntimeError(err) => Some(err), + Self::VulkanError(err) => Some(err), _ => None, } } @@ -564,7 +564,7 @@ impl Error for MemoryAllocatorError { impl Display for MemoryAllocatorError { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> { match self { - Self::RuntimeError(_) => write!(f, "a runtime error occurred"), + Self::VulkanError(_) => write!(f, "a runtime error occurred"), Self::OutOfPoolMemory => write!(f, "the pool doesn't have enough free space"), Self::DedicatedAllocationRequired => write!( f, @@ -583,9 +583,9 @@ impl Display for MemoryAllocatorError { } } -impl From for MemoryAllocatorError { - fn from(err: RuntimeError) -> Self { - MemoryAllocatorError::RuntimeError(err) +impl From for MemoryAllocatorError { + fn from(err: VulkanError) -> Self { + MemoryAllocatorError::VulkanError(err) } } @@ -695,7 +695,7 @@ impl GenericMemoryAllocator { pub fn new( device: Arc, create_info: GenericMemoryAllocatorCreateInfo<'_, '_>, - ) -> Result { + ) -> Result> { Self::validate_new(&device, &create_info)?; Ok(unsafe { Self::new_unchecked(device, create_info) }) @@ -704,7 +704,7 @@ impl GenericMemoryAllocator { fn validate_new( device: &Device, create_info: &GenericMemoryAllocatorCreateInfo<'_, '_>, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { let &GenericMemoryAllocatorCreateInfo { block_sizes, allocation_type: _, @@ -727,7 +727,7 @@ impl GenericMemoryAllocator { if !(device.api_version() >= Version::V1_1 && device.enabled_extensions().khr_external_memory) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "create_info.export_handle_types".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[ @@ -735,7 +735,7 @@ impl GenericMemoryAllocator { RequiresAllOf(&[Requires::DeviceExtension("khr_external_memory")]), ]), ..Default::default() - }); + })); } assert!( @@ -977,7 +977,7 @@ unsafe impl MemoryAllocator for GenericMemoryAllocator { /// [`protected_memory`]: crate::device::Features::protected_memory /// [`DEVICE_COHERENT`]: MemoryPropertyFlags::DEVICE_COHERENT /// [`device_coherent_memory`]: crate::device::Features::device_coherent_memory - /// [`TooManyObjects`]: RuntimeError::TooManyObjects + /// [`TooManyObjects`]: VulkanError::TooManyObjects /// [`BlockSizeExceeded`]: MemoryAllocatorError::BlockSizeExceeded /// [`SuballocatorBlockSizeExceeded`]: MemoryAllocatorError::SuballocatorBlockSizeExceeded fn allocate_from_type( @@ -1134,9 +1134,7 @@ unsafe impl MemoryAllocator for GenericMemoryAllocator { break S::new(MemoryAlloc::new(device_memory)?); } // Retry up to 3 times, halving the allocation size each time. - Err(RuntimeError::OutOfHostMemory | RuntimeError::OutOfDeviceMemory) - if i < 3 => - { + Err(VulkanError::OutOfHostMemory | VulkanError::OutOfDeviceMemory) if i < 3 => { i += 1; } Err(err) => return Err(err.into()), @@ -1151,8 +1149,8 @@ unsafe impl MemoryAllocator for GenericMemoryAllocator { Ok(allocation) => Ok(allocation), // This can happen if the block ended up smaller than advertised because there wasn't // enough memory. - Err(SuballocatorError::OutOfRegionMemory) => Err(MemoryAllocatorError::RuntimeError( - RuntimeError::OutOfDeviceMemory, + Err(SuballocatorError::OutOfRegionMemory) => Err(MemoryAllocatorError::VulkanError( + VulkanError::OutOfDeviceMemory, )), // This can not happen as the block is fresher than Febreze and we're still holding an // exclusive lock. @@ -1195,7 +1193,7 @@ unsafe impl MemoryAllocator for GenericMemoryAllocator { /// `create_info.size` is greater than `BLOCK_SIZE` and a dedicated allocation was not /// created. /// - /// [`TooManyObjects`]: RuntimeError::TooManyObjects + /// [`TooManyObjects`]: VulkanError::TooManyObjects /// [`OutOfPoolMemory`]: MemoryAllocatorError::OutOfPoolMemory /// [`DedicatedAllocationRequired`]: MemoryAllocatorError::DedicatedAllocationRequired /// [`BlockSizeExceeded`]: MemoryAllocatorError::BlockSizeExceeded diff --git a/vulkano/src/memory/allocator/suballocator.rs b/vulkano/src/memory/allocator/suballocator.rs index fbdc07f7..1377e471 100644 --- a/vulkano/src/memory/allocator/suballocator.rs +++ b/vulkano/src/memory/allocator/suballocator.rs @@ -21,7 +21,7 @@ use crate::{ device::{Device, DeviceOwned}, image::ImageTiling, memory::{is_aligned, DeviceMemory, MemoryPropertyFlags}, - DeviceSize, NonZeroDeviceSize, RuntimeError, VulkanObject, + DeviceSize, NonZeroDeviceSize, VulkanError, VulkanObject, }; use crossbeam_queue::ArrayQueue; use parking_lot::Mutex; @@ -124,7 +124,7 @@ impl MemoryAlloc { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Some(NonNull::new(output.assume_init()).unwrap()) } @@ -229,7 +229,7 @@ impl MemoryAlloc { /// [host-coherent]: crate::memory::MemoryPropertyFlags::HOST_COHERENT /// [`non_coherent_atom_size`]: crate::device::Properties::non_coherent_atom_size #[inline] - pub unsafe fn invalidate_range(&self, range: Range) -> Result<(), RuntimeError> { + pub unsafe fn invalidate_range(&self, range: Range) -> Result<(), VulkanError> { // VUID-VkMappedMemoryRange-memory-00684 if let Some(atom_size) = self.atom_size { let range = self.create_memory_range(range, atom_size); @@ -237,7 +237,7 @@ impl MemoryAlloc { let fns = device.fns(); (fns.v1_0.invalidate_mapped_memory_ranges)(device.handle(), 1, &range) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } else { self.debug_validate_memory_range(&range); } @@ -269,7 +269,7 @@ impl MemoryAlloc { /// [host-coherent]: crate::memory::MemoryPropertyFlags::HOST_COHERENT /// [`non_coherent_atom_size`]: crate::device::Properties::non_coherent_atom_size #[inline] - pub unsafe fn flush_range(&self, range: Range) -> Result<(), RuntimeError> { + pub unsafe fn flush_range(&self, range: Range) -> Result<(), VulkanError> { // VUID-VkMappedMemoryRange-memory-00684 if let Some(atom_size) = self.atom_size { let range = self.create_memory_range(range, atom_size); @@ -277,7 +277,7 @@ impl MemoryAlloc { let fns = device.fns(); (fns.v1_0.flush_mapped_memory_ranges)(device.handle(), 1, &range) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } else { self.debug_validate_memory_range(&range); } diff --git a/vulkano/src/memory/device_memory.rs b/vulkano/src/memory/device_memory.rs index fdce2ca1..6d2259f0 100644 --- a/vulkano/src/memory/device_memory.rs +++ b/vulkano/src/memory/device_memory.rs @@ -13,7 +13,7 @@ use crate::{ instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum}, memory::{is_aligned, MemoryPropertyFlags}, - DeviceSize, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, + DeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use std::{ @@ -78,7 +78,7 @@ impl DeviceMemory { pub fn allocate( device: Arc, mut allocate_info: MemoryAllocateInfo<'_>, - ) -> Result { + ) -> Result> { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_dedicated_allocation) { @@ -107,7 +107,7 @@ impl DeviceMemory { device: Arc, mut allocate_info: MemoryAllocateInfo<'_>, import_info: MemoryImportInfo, - ) -> Result { + ) -> Result> { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_dedicated_allocation) { @@ -129,7 +129,7 @@ impl DeviceMemory { device: &Device, allocate_info: &MemoryAllocateInfo<'_>, import_info: Option<&MemoryImportInfo>, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { allocate_info .validate(device) .map_err(|err| err.add_context("allocate_info"))?; @@ -149,7 +149,7 @@ impl DeviceMemory { device: Arc, mut allocate_info: MemoryAllocateInfo<'_>, import_info: Option, - ) -> Result { + ) -> Result { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_dedicated_allocation) { @@ -261,7 +261,7 @@ impl DeviceMemory { .fetch_update(Ordering::Acquire, Ordering::Relaxed, move |count| { (count < max_allocations).then_some(count + 1) }) - .map_err(|_| RuntimeError::TooManyObjects)?; + .map_err(|_| VulkanError::TooManyObjects)?; let handle = { let fns = device.fns(); @@ -275,7 +275,7 @@ impl DeviceMemory { .result() .map_err(|e| { device.allocation_count.fetch_sub(1, Ordering::Release); - RuntimeError::from(e) + VulkanError::from(e) })?; output.assume_init() @@ -381,13 +381,13 @@ impl DeviceMemory { /// /// [`LAZILY_ALLOCATED`]: crate::memory::MemoryPropertyFlags::LAZILY_ALLOCATED #[inline] - pub fn commitment(&self) -> Result { + pub fn commitment(&self) -> Result> { self.validate_commitment()?; unsafe { Ok(self.commitment_unchecked()) } } - fn validate_commitment(&self) -> Result<(), ValidationError> { + fn validate_commitment(&self) -> Result<(), Box> { let memory_type = &self .device .physical_device() @@ -398,13 +398,13 @@ impl DeviceMemory { .property_flags .intersects(MemoryPropertyFlags::LAZILY_ALLOCATED) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the `property_flags` of the memory type does not contain the \ `MemoryPropertyFlags::LAZILY_ALLOCATED` flag" .into(), vuids: &["VUID-vkGetDeviceMemoryCommitment-memory-00690"], ..Default::default() - }); + })); } Ok(()) @@ -427,7 +427,10 @@ impl DeviceMemory { /// /// - Panics if the user requests an invalid handle type for this device memory object. #[inline] - pub fn export_fd(&self, handle_type: ExternalMemoryHandleType) -> Result { + pub fn export_fd( + &self, + handle_type: ExternalMemoryHandleType, + ) -> Result> { self.validate_export_fd(handle_type)?; unsafe { Ok(self.export_fd_unchecked(handle_type)?) } @@ -436,7 +439,7 @@ impl DeviceMemory { fn validate_export_fd( &self, handle_type: ExternalMemoryHandleType, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { handle_type .validate_device(&self.device) .map_err(|err| ValidationError { @@ -449,23 +452,23 @@ impl DeviceMemory { handle_type, ExternalMemoryHandleType::OpaqueFd | ExternalMemoryHandleType::DmaBuf ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "handle_type".into(), problem: "is not `ExternalMemoryHandleType::OpaqueFd` or \ `ExternalMemoryHandleType::DmaBuf`" .into(), vuids: &["VUID-VkMemoryGetFdInfoKHR-handleType-00672"], ..Default::default() - }); + })); } if !self.export_handle_types.contains_enum(handle_type) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "handle_type".into(), problem: "is not contained in this memory's `export_handle_types`".into(), vuids: &["VUID-VkMemoryGetFdInfoKHR-handleType-00671"], ..Default::default() - }); + })); } Ok(()) @@ -475,7 +478,7 @@ impl DeviceMemory { pub unsafe fn export_fd_unchecked( &self, handle_type: ExternalMemoryHandleType, - ) -> Result { + ) -> Result { debug_assert!(self.device().enabled_extensions().khr_external_memory_fd); #[cfg(not(unix))] @@ -500,7 +503,7 @@ impl DeviceMemory { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -604,7 +607,7 @@ impl<'d> MemoryAllocateInfo<'d> { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { allocation_size, memory_type_index, @@ -631,7 +634,7 @@ impl<'d> MemoryAllocateInfo<'d> { .intersects(MemoryPropertyFlags::PROTECTED) && !device.enabled_features().protected_memory { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "memory_type_index".into(), problem: "refers to a memory type where `property_flags` contains \ `MemoryPropertyFlags::PROTECTED`" @@ -640,7 +643,7 @@ impl<'d> MemoryAllocateInfo<'d> { "protected_memory", )])]), vuids: &["VUID-VkMemoryAllocateInfo-memoryTypeIndex-01872"], - }); + })); } if memory_type @@ -648,7 +651,7 @@ impl<'d> MemoryAllocateInfo<'d> { .intersects(MemoryPropertyFlags::DEVICE_COHERENT) && !device.enabled_features().device_coherent_memory { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "memory_type_index".into(), problem: "refers to a memory type where `property_flags` contains \ `MemoryPropertyFlags::DEVICE_COHERENT`" @@ -657,25 +660,25 @@ impl<'d> MemoryAllocateInfo<'d> { "device_coherent_memory", )])]), vuids: &["VUID-vkAllocateMemory-deviceCoherentMemory-02790"], - }); + })); } if allocation_size == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "allocation_size".into(), problem: "is zero".into(), vuids: &["VUID-VkMemoryAllocateInfo-pNext-01874"], ..Default::default() - }); + })); } if memory_heap.size != 0 && allocation_size > memory_heap.size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "allocation_size".into(), problem: "is greater than the size of the memory heap".into(), vuids: &["VUID-vkAllocateMemory-pAllocateInfo-01713"], ..Default::default() - }); + })); } if let Some(dedicated_allocation) = dedicated_allocation { @@ -687,13 +690,13 @@ impl<'d> MemoryAllocateInfo<'d> { let required_size = buffer.memory_requirements().layout.size(); if allocation_size != required_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation_size` does not equal the size required for the \ buffer specified in `dedicated_allocation`" .into(), vuids: &["VUID-VkMemoryDedicatedAllocateInfo-buffer-02965"], ..Default::default() - }); + })); } } DedicatedAllocation::Image(image) => { @@ -703,13 +706,13 @@ impl<'d> MemoryAllocateInfo<'d> { let required_size = image.memory_requirements()[0].layout.size(); if allocation_size != required_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`allocation_size` does not equal the size required for the \ image specified in `dedicated_allocation`" .into(), vuids: &["VUID-VkMemoryDedicatedAllocateInfo-image-02964"], ..Default::default() - }); + })); } } } @@ -719,7 +722,7 @@ impl<'d> MemoryAllocateInfo<'d> { if !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_external_memory) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "export_handle_types".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[ @@ -727,7 +730,7 @@ impl<'d> MemoryAllocateInfo<'d> { RequiresAllOf(&[Requires::DeviceExtension("khr_external_memory")]), ]), ..Default::default() - }); + })); } export_handle_types @@ -749,7 +752,7 @@ impl<'d> MemoryAllocateInfo<'d> { if !(device.physical_device().api_version() >= Version::V1_1 || device.enabled_extensions().khr_device_group) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "flags".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[ @@ -757,7 +760,7 @@ impl<'d> MemoryAllocateInfo<'d> { RequiresAllOf(&[Requires::DeviceExtension("khr_device_group")]), ]), ..Default::default() - }); + })); } if flags.intersects(MemoryAllocateFlags::DEVICE_ADDRESS) { @@ -765,7 +768,7 @@ impl<'d> MemoryAllocateInfo<'d> { || device.enabled_extensions().khr_buffer_device_address) && device.enabled_features().buffer_device_address) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "flags".into(), problem: "contains `MemoryAllocateFlags::DEVICE_ADDRESS`".into(), requires_one_of: RequiresOneOf(&[ @@ -779,7 +782,7 @@ impl<'d> MemoryAllocateInfo<'d> { ]), ]), vuids: &["VUID-VkMemoryAllocateInfo-flags-03331"], - }); + })); } } } @@ -843,7 +846,7 @@ pub enum MemoryImportInfo { } impl MemoryImportInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { match self { MemoryImportInfo::Fd { #[cfg(unix)] @@ -853,13 +856,13 @@ impl MemoryImportInfo { file: _, } => { if !device.enabled_extensions().khr_external_memory_fd { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "is `MemoryImportInfo::Fd`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::DeviceExtension("khr_external_memory_fd"), ])]), ..Default::default() - }); + })); } #[cfg(not(unix))] @@ -888,14 +891,14 @@ impl MemoryImportInfo { } ExternalMemoryHandleType::DmaBuf => {} _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "handle_type".into(), problem: "is not `ExternalMemoryHandleType::OpaqueFd` or \ `ExternalMemoryHandleType::DmaBuf`" .into(), vuids: &["VUID-VkImportMemoryFdInfoKHR-handleType-00669"], ..Default::default() - }); + })); } } @@ -911,13 +914,13 @@ impl MemoryImportInfo { handle: _, } => { if !device.enabled_extensions().khr_external_memory_win32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "is `MemoryImportInfo::Win32`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::DeviceExtension("khr_external_memory_win32"), ])]), ..Default::default() - }); + })); } #[cfg(not(windows))] @@ -948,14 +951,14 @@ impl MemoryImportInfo { // Can't validate, must be ensured by user } _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "handle_type".into(), problem: "is not `ExternalMemoryHandleType::OpaqueWin32` or \ `ExternalMemoryHandleType::OpaqueWin32Kmt`" .into(), vuids: &["VUID-VkImportMemoryWin32HandleInfoKHR-handleType-00660"], ..Default::default() - }); + })); } } @@ -1132,7 +1135,10 @@ impl MappedDeviceMemory { /// /// - Panics if `range` is empty. #[inline] - pub fn new(memory: DeviceMemory, range: Range) -> Result { + pub fn new( + memory: DeviceMemory, + range: Range, + ) -> Result> { Self::validate_new(&memory, range.clone())?; unsafe { Ok(Self::new_unchecked(memory, range)?) } @@ -1141,14 +1147,14 @@ impl MappedDeviceMemory { fn validate_new( memory: &DeviceMemory, range: Range, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if range.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "range".into(), problem: "is empty".into(), vuids: &["VUID-vkMapMemory-size-00680"], ..Default::default() - }); + })); } let device = memory.device(); @@ -1159,28 +1165,28 @@ impl MappedDeviceMemory { .property_flags .intersects(MemoryPropertyFlags::HOST_VISIBLE) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "memory".into(), problem: "has a memory type whose `property_flags` does not contain \ `MemoryPropertyFlags::HOST_VISIBLE`" .into(), vuids: &["VUID-vkMapMemory-memory-00682"], ..Default::default() - }); + })); } // VUID-vkMapMemory-memory-00678 // Guaranteed because we take ownership of `memory`, no other mapping can exist. if range.end > memory.allocation_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`range.end` is greater than `memory.allocation_size()`".into(), vuids: &[ "VUID-vkMapMemory-offset-00679", "VUID-vkMapMemory-size-00681", ], ..Default::default() - }); + })); } let is_coherent = memory_type @@ -1195,13 +1201,13 @@ impl MappedDeviceMemory { && (!is_aligned(range.start, atom_size) || (!is_aligned(range.end, atom_size) && range.end != memory.allocation_size)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`memory` has a memory type whose `property_flags` does not contain \ `MemoryPropertyFlags::HOST_COHERENT`, and `range.start` and/or `range.end` \ are not aligned to the `non_coherent_atom_size` device property" .into(), ..Default::default() - }); + })); } Ok(()) @@ -1211,7 +1217,7 @@ impl MappedDeviceMemory { pub unsafe fn new_unchecked( memory: DeviceMemory, range: Range, - ) -> Result { + ) -> Result { let device = memory.device(); let pointer = unsafe { @@ -1226,7 +1232,7 @@ impl MappedDeviceMemory { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1279,7 +1285,10 @@ impl MappedDeviceMemory { /// /// - Panics if `range` is empty. #[inline] - pub unsafe fn invalidate_range(&self, range: Range) -> Result<(), VulkanError> { + pub unsafe fn invalidate_range( + &self, + range: Range, + ) -> Result<(), Validated> { self.validate_range(range.clone())?; Ok(self.invalidate_range_unchecked(range)?) @@ -1289,7 +1298,7 @@ impl MappedDeviceMemory { pub unsafe fn invalidate_range_unchecked( &self, range: Range, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { if self.is_coherent { return Ok(()); } @@ -1304,7 +1313,7 @@ impl MappedDeviceMemory { let fns = self.memory.device().fns(); (fns.v1_0.invalidate_mapped_memory_ranges)(self.memory.device().handle(), 1, &range) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -1330,7 +1339,10 @@ impl MappedDeviceMemory { /// /// - Panics if `range` is empty. #[inline] - pub unsafe fn flush_range(&self, range: Range) -> Result<(), VulkanError> { + pub unsafe fn flush_range( + &self, + range: Range, + ) -> Result<(), Validated> { self.validate_range(range.clone())?; Ok(self.flush_range_unchecked(range)?) @@ -1340,7 +1352,7 @@ impl MappedDeviceMemory { pub unsafe fn flush_range_unchecked( &self, range: Range, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { if self.is_coherent { return Ok(()); } @@ -1355,7 +1367,7 @@ impl MappedDeviceMemory { let fns = self.device().fns(); (fns.v1_0.flush_mapped_memory_ranges)(self.memory.device().handle(), 1, &range) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -1379,7 +1391,7 @@ impl MappedDeviceMemory { /// /// - Panics if `range` is empty. #[inline] - pub unsafe fn read(&self, range: Range) -> Result<&[u8], ValidationError> { + pub unsafe fn read(&self, range: Range) -> Result<&[u8], Box> { self.validate_range(range.clone())?; Ok(self.read_unchecked(range)) @@ -1413,7 +1425,10 @@ impl MappedDeviceMemory { /// /// - Panics if `range` is empty. #[inline] - pub unsafe fn write(&self, range: Range) -> Result<&mut [u8], ValidationError> { + pub unsafe fn write( + &self, + range: Range, + ) -> Result<&mut [u8], Box> { self.validate_range(range.clone())?; Ok(self.write_unchecked(range)) @@ -1430,25 +1445,25 @@ impl MappedDeviceMemory { } #[inline] - fn validate_range(&self, range: Range) -> Result<(), ValidationError> { + fn validate_range(&self, range: Range) -> Result<(), Box> { // VUID-VkMappedMemoryRange-memory-00684 // Guaranteed because `self` owns the memory and it's mapped during our lifetime. if range.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "range".into(), problem: "is empty".into(), ..Default::default() - }); + })); } if range.start < self.range.start || range.end > self.range.end { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "range".into(), problem: "is not within the mapped range of this mapped device memory".into(), vuids: &["VUID-VkMappedMemoryRange-size-00685"], ..Default::default() - }); + })); } if !self.is_coherent { @@ -1456,7 +1471,7 @@ impl MappedDeviceMemory { || (!is_aligned(range.end, self.atom_size) && range.end != self.memory.allocation_size) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this mapped device memory has a memory type whose `property_flags` \ does not contain `MemoryPropertyFlags::HOST_COHERENT`, and \ `range.start` and/or `range.end` are not aligned to the \ @@ -1467,7 +1482,7 @@ impl MappedDeviceMemory { "VUID-VkMappedMemoryRange-size-01390", ], ..Default::default() - }); + })); } } diff --git a/vulkano/src/pipeline/cache.rs b/vulkano/src/pipeline/cache.rs index 197ad028..0c4228ea 100644 --- a/vulkano/src/pipeline/cache.rs +++ b/vulkano/src/pipeline/cache.rs @@ -25,7 +25,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags}, - RuntimeError, ValidationError, VulkanError, VulkanObject, + Validated, ValidationError, VulkanError, VulkanObject, }; use smallvec::SmallVec; use std::{mem::MaybeUninit, num::NonZeroU64, ptr, sync::Arc}; @@ -92,7 +92,7 @@ impl PipelineCache { pub unsafe fn new( device: Arc, create_info: PipelineCacheCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; Ok(Self::new_unchecked(device, create_info)?) @@ -101,7 +101,7 @@ impl PipelineCache { fn validate_new( device: &Device, create_info: &PipelineCacheCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { create_info .validate(device) .map_err(|err| err.add_context("create_info"))?; @@ -113,7 +113,7 @@ impl PipelineCache { pub unsafe fn new_unchecked( device: Arc, create_info: PipelineCacheCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &PipelineCacheCreateInfo { flags, ref initial_data, @@ -141,7 +141,7 @@ impl PipelineCache { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -205,7 +205,7 @@ impl PipelineCache { /// } /// ``` #[inline] - pub fn get_data(&self) -> Result, RuntimeError> { + pub fn get_data(&self) -> Result, VulkanError> { let fns = self.device.fns(); let data = unsafe { @@ -218,7 +218,7 @@ impl PipelineCache { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut data: Vec = Vec::with_capacity(count); let result = (fns.v1_0.get_pipeline_cache_data)( @@ -234,7 +234,7 @@ impl PipelineCache { break data; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } } }; @@ -251,22 +251,22 @@ impl PipelineCache { pub fn merge<'a>( &self, src_caches: impl IntoIterator, - ) -> Result<(), VulkanError> { + ) -> Result<(), Validated> { let src_caches: SmallVec<[_; 8]> = src_caches.into_iter().collect(); self.validate_merge(&src_caches)?; unsafe { Ok(self.merge_unchecked(src_caches)?) } } - fn validate_merge(&self, src_caches: &[&PipelineCache]) -> Result<(), ValidationError> { + fn validate_merge(&self, src_caches: &[&PipelineCache]) -> Result<(), Box> { for (index, &src_cache) in src_caches.iter().enumerate() { if src_cache == self { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("src_caches[{}]", index).into(), problem: "equals `self`".into(), vuids: &["VUID-vkMergePipelineCaches-dstCache-00770"], ..Default::default() - }); + })); } } @@ -277,7 +277,7 @@ impl PipelineCache { pub unsafe fn merge_unchecked<'a>( &self, src_caches: impl IntoIterator, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let src_caches_vk: SmallVec<[_; 8]> = src_caches.into_iter().map(VulkanObject::handle).collect(); @@ -289,7 +289,7 @@ impl PipelineCache { src_caches_vk.as_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } @@ -358,7 +358,7 @@ impl Default for PipelineCacheCreateInfo { } impl PipelineCacheCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, initial_data: _, diff --git a/vulkano/src/pipeline/compute.rs b/vulkano/src/pipeline/compute.rs index a3efe566..95078d19 100644 --- a/vulkano/src/pipeline/compute.rs +++ b/vulkano/src/pipeline/compute.rs @@ -29,7 +29,7 @@ use crate::{ macros::impl_id_counter, pipeline::{cache::PipelineCache, layout::PipelineLayout, Pipeline, PipelineBindPoint}, shader::{DescriptorBindingRequirements, ShaderExecution, ShaderStage}, - RuntimeError, ValidationError, VulkanError, VulkanObject, + Validated, ValidationError, VulkanError, VulkanObject, }; use ahash::HashMap; use std::{ffi::CString, fmt::Debug, mem::MaybeUninit, num::NonZeroU64, ptr, sync::Arc}; @@ -59,7 +59,7 @@ impl ComputePipeline { device: Arc, cache: Option>, create_info: ComputePipelineCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, cache.as_ref().map(AsRef::as_ref), &create_info)?; unsafe { Ok(Self::new_unchecked(device, cache, create_info)?) } @@ -69,7 +69,7 @@ impl ComputePipeline { device: &Device, cache: Option<&PipelineCache>, create_info: &ComputePipelineCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateComputePipelines-pipelineCache-parent if let Some(cache) = &cache { assert_eq!(device, cache.device().as_ref()); @@ -87,7 +87,7 @@ impl ComputePipeline { device: Arc, cache: Option>, create_info: ComputePipelineCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &ComputePipelineCreateInfo { flags, ref stage, @@ -170,7 +170,7 @@ impl ComputePipeline { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -312,7 +312,7 @@ impl ComputePipelineCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref stage, @@ -342,12 +342,12 @@ impl ComputePipelineCreateInfo { let entry_point_info = entry_point.info(); if !matches!(entry_point_info.execution, ShaderExecution::Compute) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stage.entry_point".into(), problem: "is not a `ShaderStage::Compute` entry point".into(), vuids: &["VUID-VkComputePipelineCreateInfo-stage-00701"], ..Default::default() - }); + })); } // TODO: Make sure that all VUIDs are indeed checked. diff --git a/vulkano/src/pipeline/graphics/color_blend.rs b/vulkano/src/pipeline/graphics/color_blend.rs index e93929f5..61acc037 100644 --- a/vulkano/src/pipeline/graphics/color_blend.rs +++ b/vulkano/src/pipeline/graphics/color_blend.rs @@ -145,7 +145,7 @@ impl ColorBlendState { self } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, logic_op, @@ -164,14 +164,14 @@ impl ColorBlendState { if let Some(logic_op) = logic_op { if !device.enabled_features().logic_op { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "logic_op".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "logic_op", )])]), vuids: &["VUID-VkPipelineColorBlendStateCreateInfo-logicOpEnable-00606"], - }); + })); } match logic_op { @@ -188,14 +188,14 @@ impl ColorBlendState { } StateMode::Dynamic => { if !device.enabled_features().extended_dynamic_state2_logic_op { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "logic_op".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "extended_dynamic_state2_logic_op", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04869"], - }); + })); } } } @@ -214,7 +214,7 @@ impl ColorBlendState { for (index, state) in attachments.iter().enumerate().skip(1) { if state != first { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`attachments[{}]` does not equal `attachments[0]`", index @@ -225,7 +225,7 @@ impl ColorBlendState { )])]), vuids: &["VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605"], ..Default::default() - }); + })); } } } @@ -348,7 +348,7 @@ pub struct ColorBlendAttachmentState { } impl ColorBlendAttachmentState { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { ref blend, color_write_mask: _, @@ -364,26 +364,26 @@ impl ColorBlendAttachmentState { match color_write_enable { StateMode::Fixed(enable) => { if !enable && !device.enabled_features().color_write_enable { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "color_write_enable".into(), problem: "is `false`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "color_write_enable", )])]), vuids: &["VUID-VkPipelineColorWriteCreateInfoEXT-pAttachments-04801"], - }); + })); } } StateMode::Dynamic => { if !device.enabled_features().color_write_enable { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "color_write_enable".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "color_write_enable", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04800"], - }); + })); } } } @@ -459,7 +459,7 @@ impl AttachmentBlend { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { src_color_blend_factor, dst_color_blend_factor, @@ -525,14 +525,14 @@ impl AttachmentBlend { | BlendFactor::Src1Alpha | BlendFactor::OneMinusSrc1Alpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_color_blend_factor".into(), problem: "is `BlendFactor::Src1*`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "dual_src_blend", )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-srcColorBlendFactor-00608"], - }); + })); } if matches!( @@ -542,14 +542,14 @@ impl AttachmentBlend { | BlendFactor::Src1Alpha | BlendFactor::OneMinusSrc1Alpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_color_blend_factor".into(), problem: "is `BlendFactor::Src1*`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "dual_src_blend", )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-dstColorBlendFactor-00609"], - }); + })); } if matches!( @@ -559,14 +559,14 @@ impl AttachmentBlend { | BlendFactor::Src1Alpha | BlendFactor::OneMinusSrc1Alpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_alpha_blend_factor".into(), problem: "is `BlendFactor::Src1*`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "dual_src_blend", )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-srcAlphaBlendFactor-00610"], - }); + })); } if matches!( @@ -576,14 +576,14 @@ impl AttachmentBlend { | BlendFactor::Src1Alpha | BlendFactor::OneMinusSrc1Alpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_alpha_blend_factor".into(), problem: "is `BlendFactor::Src1*`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "dual_src_blend", )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-dstAlphaBlendFactor-00611"], - }); + })); } } @@ -594,7 +594,7 @@ impl AttachmentBlend { src_color_blend_factor, BlendFactor::ConstantAlpha | BlendFactor::OneMinusConstantAlpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `src_color_blend_factor` is `BlendFactor::ConstantAlpha` or \ `BlendFactor::OneMinusConstantAlpha`".into(), @@ -603,14 +603,14 @@ impl AttachmentBlend { )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-constantAlphaColorBlendFactors-04454"], ..Default::default() - }); + })); } if matches!( dst_color_blend_factor, BlendFactor::ConstantAlpha | BlendFactor::OneMinusConstantAlpha ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `dst_color_blend_factor` is `BlendFactor::ConstantAlpha` or \ `BlendFactor::OneMinusConstantAlpha`".into(), @@ -619,7 +619,7 @@ impl AttachmentBlend { )])]), vuids: &["VUID-VkPipelineColorBlendAttachmentState-constantAlphaColorBlendFactors-04455"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/pipeline/graphics/depth_stencil.rs b/vulkano/src/pipeline/graphics/depth_stencil.rs index a28c2704..f60d92b2 100644 --- a/vulkano/src/pipeline/graphics/depth_stencil.rs +++ b/vulkano/src/pipeline/graphics/depth_stencil.rs @@ -87,7 +87,7 @@ impl DepthStencilState { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref depth, @@ -112,7 +112,7 @@ impl DepthStencilState { if let Some(depth_bounds_state) = depth_bounds { if !device.enabled_features().depth_bounds { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_bounds".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( @@ -121,7 +121,7 @@ impl DepthStencilState { vuids: &[ "VUID-VkPipelineDepthStencilStateCreateInfo-depthBoundsTestEnable-00598", ], - }); + })); } depth_bounds_state @@ -198,7 +198,7 @@ pub struct DepthState { } impl DepthState { - pub(crate) fn validate(self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(self, device: &Device) -> Result<(), Box> { let Self { enable_dynamic, write_enable, @@ -209,7 +209,7 @@ impl DepthState { && !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enable_dynamic".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[ @@ -218,7 +218,7 @@ impl DepthState { ]), // vuids? ..Default::default() - }); + })); } match write_enable { @@ -227,7 +227,7 @@ impl DepthState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "write_enable".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -236,7 +236,7 @@ impl DepthState { ]), // vuids? ..Default::default() - }); + })); } } } @@ -257,7 +257,7 @@ impl DepthState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "compare_op".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -266,7 +266,7 @@ impl DepthState { ]), // vuids? ..Default::default() - }); + })); } } } @@ -310,7 +310,7 @@ pub struct DepthBoundsState { } impl DepthBoundsState { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { enable_dynamic, ref bounds, @@ -320,7 +320,7 @@ impl DepthBoundsState { && !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enable_dynamic".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[ @@ -329,31 +329,31 @@ impl DepthBoundsState { ]), // vuids? ..Default::default() - }); + })); } if let StateMode::Fixed(bounds) = bounds { if !device.enabled_extensions().ext_depth_range_unrestricted { if !(0.0..1.0).contains(bounds.start()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "bounds.start".into(), problem: "is not between 0.0 and 1.0 inclusive".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::DeviceExtension("ext_depth_range_unrestricted"), ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-02510"], - }); + })); } if !(0.0..1.0).contains(bounds.end()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "bounds.end".into(), problem: "is not between 0.0 and 1.0 inclusive".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::DeviceExtension("ext_depth_range_unrestricted"), ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-02510"], - }); + })); } } } @@ -397,7 +397,7 @@ pub struct StencilState { } impl StencilState { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &StencilState { enable_dynamic, ref front, @@ -408,7 +408,7 @@ impl StencilState { && !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "enable_dynamic".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[ @@ -417,7 +417,7 @@ impl StencilState { ]), // vuids? ..Default::default() - }); + })); } match (front.ops, back.ops) { @@ -433,7 +433,7 @@ impl StencilState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`front.ops` and `back.ops` are dynamic".into(), requires_one_of: RequiresOneOf(&[ RequiresAllOf(&[Requires::APIVersion(Version::V1_3)]), @@ -441,17 +441,17 @@ impl StencilState { ]), // vuids? ..Default::default() - }); + })); } } _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`front.ops` and `back.ops` are \ not both fixed or both dynamic" .into(), // vuids? ..Default::default() - }); + })); } } @@ -459,39 +459,39 @@ impl StencilState { (front.compare_mask, back.compare_mask), (StateMode::Fixed(_), StateMode::Fixed(_)) | (StateMode::Dynamic, StateMode::Dynamic) ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`front.compare_mask` and `back.compare_mask` are \ not both fixed or both dynamic" .into(), // vuids? ..Default::default() - }); + })); } if !matches!( (front.write_mask, back.write_mask), (StateMode::Fixed(_), StateMode::Fixed(_)) | (StateMode::Dynamic, StateMode::Dynamic) ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`front.write_mask` and `back.write_mask` are \ not both fixed or both dynamic" .into(), // vuids? ..Default::default() - }); + })); } if !matches!( (front.reference, back.reference), (StateMode::Fixed(_), StateMode::Fixed(_)) | (StateMode::Dynamic, StateMode::Dynamic) ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`front.reference` and `back.reference` are \ not both fixed or both dynamic" .into(), // vuids? ..Default::default() - }); + })); } Ok(()) @@ -560,7 +560,7 @@ pub struct StencilOps { } impl StencilOps { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { fail_op, pass_op, diff --git a/vulkano/src/pipeline/graphics/discard_rectangle.rs b/vulkano/src/pipeline/graphics/discard_rectangle.rs index 66ab50a3..3e9d2db7 100644 --- a/vulkano/src/pipeline/graphics/discard_rectangle.rs +++ b/vulkano/src/pipeline/graphics/discard_rectangle.rs @@ -46,7 +46,7 @@ impl DiscardRectangleState { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { mode, ref rectangles, @@ -67,14 +67,14 @@ impl DiscardRectangleState { }; if discard_rectangle_count > properties.max_discard_rectangles.unwrap() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "rectangles".into(), problem: "the length exceeds the `max_discard_rectangles` limit".into(), vuids: &[ "VUID-VkPipelineDiscardRectangleStateCreateInfoEXT-discardRectangleCount-00582", ], ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/pipeline/graphics/input_assembly.rs b/vulkano/src/pipeline/graphics/input_assembly.rs index 8155a52c..f2e3caef 100644 --- a/vulkano/src/pipeline/graphics/input_assembly.rs +++ b/vulkano/src/pipeline/graphics/input_assembly.rs @@ -84,7 +84,7 @@ impl InputAssemblyState { self } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { topology, primitive_restart_enable, @@ -106,7 +106,7 @@ impl InputAssemblyState { if device.enabled_extensions().khr_portability_subset && !device.enabled_features().triangle_fans { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `topology` is `PrimitiveTopology::TriangleFan`" .into(), @@ -115,7 +115,7 @@ impl InputAssemblyState { ])]), vuids: &["VUID-VkPipelineInputAssemblyStateCreateInfo-triangleFans-04452"], ..Default::default() - }); + })); } } PrimitiveTopology::LineListWithAdjacency @@ -123,7 +123,7 @@ impl InputAssemblyState { | PrimitiveTopology::TriangleListWithAdjacency | PrimitiveTopology::TriangleStripWithAdjacency => { if !device.enabled_features().geometry_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "topology".into(), problem: "is `PrimitiveTopology::*WithAdjacency`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ @@ -132,12 +132,12 @@ impl InputAssemblyState { vuids: &[ "VUID-VkPipelineInputAssemblyStateCreateInfo-topology-00429", ], - }); + })); } } PrimitiveTopology::PatchList => { if !device.enabled_features().tessellation_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "topology".into(), problem: "is `PrimitiveTopology::PatchList`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ @@ -146,7 +146,7 @@ impl InputAssemblyState { vuids: &[ "VUID-VkPipelineInputAssemblyStateCreateInfo-topology-00430", ], - }); + })); } } _ => (), @@ -165,7 +165,7 @@ impl InputAssemblyState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "topology".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -174,7 +174,7 @@ impl InputAssemblyState { ]), // vuids? ..Default::default() - }); + })); } } } @@ -191,7 +191,7 @@ impl InputAssemblyState { | PrimitiveTopology::TriangleListWithAdjacency, ) => { if !device.enabled_features().primitive_topology_list_restart { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`topology` is `PrimitiveTopology::*List`, and \ `primitive_restart_enable` is `true`" .into(), @@ -200,7 +200,7 @@ impl InputAssemblyState { ])]), vuids: &["VUID-VkPipelineInputAssemblyStateCreateInfo-topology-06252"], ..Default::default() - }); + })); } } PartialStateMode::Fixed(PrimitiveTopology::PatchList) => { @@ -208,7 +208,7 @@ impl InputAssemblyState { .enabled_features() .primitive_topology_patch_list_restart { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`topology` is `PrimitiveTopology::PatchList`, and \ `primitive_restart_enable` is `true`" .into(), @@ -217,7 +217,7 @@ impl InputAssemblyState { ])]), vuids: &["VUID-VkPipelineInputAssemblyStateCreateInfo-topology-06253"], ..Default::default() - }); + })); } } _ => (), @@ -228,7 +228,7 @@ impl InputAssemblyState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "primitive_restart_enable".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -237,7 +237,7 @@ impl InputAssemblyState { ]), // vuids? ..Default::default() - }); + })); } } } diff --git a/vulkano/src/pipeline/graphics/mod.rs b/vulkano/src/pipeline/graphics/mod.rs index 24924af7..f4a71ce3 100644 --- a/vulkano/src/pipeline/graphics/mod.rs +++ b/vulkano/src/pipeline/graphics/mod.rs @@ -93,8 +93,7 @@ use crate::{ DescriptorBindingRequirements, FragmentShaderExecution, FragmentTestsStages, ShaderExecution, ShaderScalarType, ShaderStage, ShaderStages, }, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, VulkanError, - VulkanObject, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, VulkanError, VulkanObject, }; use ahash::HashMap; use smallvec::SmallVec; @@ -154,7 +153,7 @@ impl GraphicsPipeline { device: Arc, cache: Option>, create_info: GraphicsPipelineCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, cache.as_ref().map(AsRef::as_ref), &create_info)?; unsafe { Ok(Self::new_unchecked(device, cache, create_info)?) } @@ -164,7 +163,7 @@ impl GraphicsPipeline { device: &Device, _cache: Option<&PipelineCache>, create_info: &GraphicsPipelineCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { create_info .validate(device) .map_err(|err| err.add_context("create_info"))?; @@ -177,7 +176,7 @@ impl GraphicsPipeline { device: Arc, cache: Option>, create_info: GraphicsPipelineCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &GraphicsPipelineCreateInfo { flags, ref stages, @@ -1141,7 +1140,7 @@ impl GraphicsPipeline { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1880,7 +1879,7 @@ impl GraphicsPipelineCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref stages, @@ -1926,7 +1925,7 @@ impl GraphicsPipelineCreateInfo { let stage_flag = ShaderStages::from(stage_enum); if stages_present.intersects(stage_flag) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: format!( "contains more than one element whose stage is \ @@ -1936,7 +1935,7 @@ impl GraphicsPipelineCreateInfo { .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-stage-06897"], ..Default::default() - }); + })); } const PRIMITIVE_SHADING_STAGES: ShaderStages = ShaderStages::VERTEX @@ -1950,13 +1949,13 @@ impl GraphicsPipelineCreateInfo { || stage_flag.intersects(MESH_SHADING_STAGES) && stages_present.intersects(PRIMITIVE_SHADING_STAGES) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: "contains both primitive shading stages and mesh shading stages" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-02095"], ..Default::default() - }); + })); } let stage_slot = match stage_enum { @@ -1966,12 +1965,12 @@ impl GraphicsPipelineCreateInfo { ShaderStage::Geometry => &mut geometry_stage, ShaderStage::Fragment => &mut fragment_stage, _ => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("stages[{}]", stage_index).into(), problem: "is not a pre-rasterization or fragment shader stage".into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06896"], ..Default::default() - }); + })); } }; @@ -1991,24 +1990,24 @@ impl GraphicsPipelineCreateInfo { need_pre_rasterization_shader_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization shader state, but \ `rasterization_state` is `Some`" .into(), // vuids? ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ pre-rasterization shader state, but \ `rasterization_state` is `None`" .into(), // vuids? ..Default::default() - }); + })); } _ => (), } @@ -2032,24 +2031,24 @@ impl GraphicsPipelineCreateInfo { match (vertex_stage.is_some(), need_pre_rasterization_shader_state) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization shader state, but `stages` contains a \ `ShaderStage::Vertex` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06895"], ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ pre-rasterization shader state, but `stages` does not contain a \ `ShaderStage::Vertex` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-stage-02096"], ..Default::default() - }); + })); } _ => (), } @@ -2059,14 +2058,14 @@ impl GraphicsPipelineCreateInfo { need_pre_rasterization_shader_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization shader state, but `stages` contains a \ `ShaderStage::TessellationControl` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06895"], ..Default::default() - }); + })); } (false, true) => (), _ => (), @@ -2077,14 +2076,14 @@ impl GraphicsPipelineCreateInfo { need_pre_rasterization_shader_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization shader state, but `stages` contains a \ `ShaderStage::TessellationEvaluation` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06895"], ..Default::default() - }); + })); } (false, true) => (), _ => (), @@ -2093,25 +2092,25 @@ impl GraphicsPipelineCreateInfo { if stages_present.intersects(ShaderStages::TESSELLATION_CONTROL) && !stages_present.intersects(ShaderStages::TESSELLATION_EVALUATION) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: "contains a `ShaderStage::TessellationControl` stage, but not a \ `ShaderStage::TessellationEvaluation` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-00729"], ..Default::default() - }); + })); } else if stages_present.intersects(ShaderStages::TESSELLATION_EVALUATION) && !stages_present.intersects(ShaderStages::TESSELLATION_CONTROL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: "contains a `ShaderStage::TessellationEvaluation` stage, but not a \ `ShaderStage::TessellationControl` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-00730"], ..Default::default() - }); + })); } match ( @@ -2119,14 +2118,14 @@ impl GraphicsPipelineCreateInfo { need_pre_rasterization_shader_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization shader state, but `stages` contains a \ `ShaderStage::Geometry` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06895"], ..Default::default() - }); + })); } (false, true) => (), _ => (), @@ -2134,14 +2133,14 @@ impl GraphicsPipelineCreateInfo { match (fragment_stage.is_some(), need_fragment_shader_state) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ fragment shader state, but `stages` contains a \ `ShaderStage::Geometry` stage" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-06894"], ..Default::default() - }); + })); } (false, true) => (), _ => (), @@ -2149,46 +2148,46 @@ impl GraphicsPipelineCreateInfo { match (vertex_input_state.is_some(), need_vertex_input_state) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ vertex input state, but \ `vertex_input_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ vertex input state, but \ `vertex_input_state` is `None`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-02097"], ..Default::default() - }); + })); } _ => (), } match (input_assembly_state.is_some(), need_vertex_input_state) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ vertex input state, but \ `input_assembly_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ vertex input state, but \ `input_assembly_state` is `None`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-02098"], ..Default::default() - }); + })); } _ => (), } @@ -2201,17 +2200,17 @@ impl GraphicsPipelineCreateInfo { ), ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization state, or \ `stages` does not contain tessellation shader stages, but \ `tessellation_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ pre-rasterization state, and \ `stages` contains tessellation shader stages, but \ @@ -2219,7 +2218,7 @@ impl GraphicsPipelineCreateInfo { .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-00731"], ..Default::default() - }); + })); } _ => (), } @@ -2234,17 +2233,17 @@ impl GraphicsPipelineCreateInfo { != StateMode::Fixed(true), ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization state, or \ `rasterization_state.rasterization_discard_enable` is `true`, but \ `viewport_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ pre-rasterization state, and \ `rasterization_state.rasterization_discard_enable` is `false` \ @@ -2255,30 +2254,30 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-pViewportState-04892", ], ..Default::default() - }); + })); } _ => (), } match (multisample_state.is_some(), need_fragment_output_state) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ fragment output state, but \ `multisample_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ fragment output state, but \ `multisample_state` is `None`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-rasterizerDiscardEnable-00751"], ..Default::default() - }); + })); } _ => (), } @@ -2298,17 +2297,17 @@ impl GraphicsPipelineCreateInfo { }, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ fragment output state, and \ `subpass` does not have a depth/stencil attachment, but \ `depth_stencil_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ fragment output state, or \ `subpass` has a depth/stencil attachment, but \ @@ -2320,7 +2319,7 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-renderPass-06053", ], ..Default::default() - }); + })); } _ => (), } @@ -2339,17 +2338,17 @@ impl GraphicsPipelineCreateInfo { }, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ fragment output state, or \ `subpass` does not have any color attachments, but \ `color_blend_state` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ fragment output state, and \ `subpass` has a color attachment, but \ @@ -2360,7 +2359,7 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-renderPass-06054", ], ..Default::default() - }); + })); } _ => (), } @@ -2372,23 +2371,23 @@ impl GraphicsPipelineCreateInfo { || need_fragment_output_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization, fragment shader or fragment output state, but \ `subpass` is `Some`" .into(), ..Default::default() - }); + })); } (false, true) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is being created with \ pre-rasterization, fragment shader or fragment output state, but \ `subpass` is `None`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06575"], ..Default::default() - }); + })); } _ => (), } @@ -2398,14 +2397,14 @@ impl GraphicsPipelineCreateInfo { need_pre_rasterization_shader_state, ) { (true, false) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the pipeline is not being created with \ pre-rasterization state, but \ `discard_rectangle_state` is `Some`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04058"], ..Default::default() - }); + })); } (false, true) => (), _ => (), @@ -2461,7 +2460,7 @@ impl GraphicsPipelineCreateInfo { if let Err(err) = (input.entry_point.info().input_interface) .matches(&output.entry_point.info().output_interface) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: format!( "the output interface of the `ShaderStage::{:?}` stage does not \ @@ -2476,7 +2475,7 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-None-04889", ], ..Default::default() - }); + })); } } @@ -2566,7 +2565,7 @@ impl GraphicsPipelineCreateInfo { | ShaderStages::TESSELLATION_EVALUATION, ) && !device.enabled_features().multiview_tessellation_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stages` contains tessellation shaders, and \ `subpass` has a non-zero `view_mask`" .into(), @@ -2575,13 +2574,13 @@ impl GraphicsPipelineCreateInfo { ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06047"], ..Default::default() - }); + })); } if stages_present.intersects(ShaderStages::GEOMETRY) && !device.enabled_features().multiview_geometry_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stages` contains a geometry shader, and \ `subpass` has a non-zero `view_mask`" .into(), @@ -2590,20 +2589,20 @@ impl GraphicsPipelineCreateInfo { ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06048"], ..Default::default() - }); + })); } } } PipelineSubpassType::BeginRendering(rendering_info) => { if !device.enabled_features().dynamic_rendering { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "subpass".into(), problem: "is `PipelineRenderPassType::BeginRendering`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "dynamic_rendering", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-dynamicRendering-06576"], - }); + })); } rendering_info @@ -2624,7 +2623,7 @@ impl GraphicsPipelineCreateInfo { | ShaderStages::TESSELLATION_EVALUATION, ) && !device.enabled_features().multiview_tessellation_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stages` contains tessellation shaders, and \ `subpass.view_mask` is not 0" .into(), @@ -2633,13 +2632,13 @@ impl GraphicsPipelineCreateInfo { ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06057"], ..Default::default() - }); + })); } if stages_present.intersects(ShaderStages::GEOMETRY) && !device.enabled_features().multiview_geometry_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stages` contains a geometry shader, and \ `subpass.view_mask` is not 0" .into(), @@ -2648,7 +2647,7 @@ impl GraphicsPipelineCreateInfo { ])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06058"], ..Default::default() - }); + })); } } } @@ -2657,14 +2656,14 @@ impl GraphicsPipelineCreateInfo { if let Some(discard_rectangle_state) = discard_rectangle_state { if !device.enabled_extensions().ext_discard_rectangles { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "discard_rectangle_state".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_discard_rectangles", )])]), ..Default::default() - }); + })); } discard_rectangle_state @@ -2686,7 +2685,7 @@ impl GraphicsPipelineCreateInfo { let attribute_desc = match vertex_input_state.attributes.get(&location) { Some(attribute_desc) => attribute_desc, None => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the vertex shader has an input variable with location {0}, but \ `vertex_input_state.attributes` does not contain {0}", @@ -2695,7 +2694,7 @@ impl GraphicsPipelineCreateInfo { .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-Input-07905"], ..Default::default() - }); + })); } }; @@ -2720,7 +2719,7 @@ impl GraphicsPipelineCreateInfo { ) | (ShaderScalarType::Sint, NumericType::SINT) | (ShaderScalarType::Uint, NumericType::UINT) ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`vertex_input_state.attributes[{}].format` has a different \ scalar type than the vertex shader input variable with \ @@ -2730,7 +2729,7 @@ impl GraphicsPipelineCreateInfo { .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-Input-07905"], ..Default::default() - }); + })); } } } @@ -2764,13 +2763,13 @@ impl GraphicsPipelineCreateInfo { if let PartialStateMode::Fixed(topology) = input_assembly_state.topology { if !input.is_compatible_with(topology) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`input_assembly_state.topology` is not compatible with the \ input topology of the geometry shader" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-00738"], ..Default::default() - }); + })); } } } @@ -2782,12 +2781,12 @@ impl GraphicsPipelineCreateInfo { match subpass { PipelineSubpassType::BeginRenderPass(subpass) => { if !subpass.is_compatible_with(&entry_point_info.output_interface) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`subpass` is not compatible with the \ output interface of the fragment shader" .into(), ..Default::default() - }); + })); } } PipelineSubpassType::BeginRendering(_) => { @@ -2808,13 +2807,13 @@ impl GraphicsPipelineCreateInfo { PartialStateMode::Dynamic(PrimitiveTopologyClass::Patch) | PartialStateMode::Fixed(PrimitiveTopology::PatchList) ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stages` contains tessellation shaders, but \ `input_assembly_state.topology` is not `PrimitiveTopology::PatchList`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pStages-00736"], ..Default::default() - }); + })); } } @@ -2833,7 +2832,7 @@ impl GraphicsPipelineCreateInfo { ) && front_reference != back_reference { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, \ `rasterization_state.cull_mode` is `CullMode::None`, and \ `depth_stencil_state.stencil.front.reference` does not equal \ @@ -2843,7 +2842,7 @@ impl GraphicsPipelineCreateInfo { )])]), vuids: &["VUID-VkPipelineDepthStencilStateCreateInfo-separateStencilMaskRef-04453"], ..Default::default() - }); + })); } } } @@ -2854,14 +2853,14 @@ impl GraphicsPipelineCreateInfo { PipelineSubpassType::BeginRenderPass(subpass) => { if let Some(samples) = subpass.num_samples() { if multisample_state.rasterization_samples != samples { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`multisample_state.rasterization_samples` does not \ equal the number of samples in the color and depth/stencil \ attachments of `subpass`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-subpass-00757"], ..Default::default() - }); + })); } } @@ -2899,13 +2898,13 @@ impl GraphicsPipelineCreateInfo { }; if !has_depth_attachment { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_state.depth` is `Some`, but `subpass` does not \ have a depth attachment" .into(), // vuids? ..Default::default() - }); + })); } if let StateMode::Fixed(true) = depth_state.write_enable { @@ -2929,14 +2928,14 @@ impl GraphicsPipelineCreateInfo { .intersects(ImageAspects::DEPTH) }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_state.depth.write_enable` is `true`, \ but `subpass` does not have a depth attachment whose \ layout for the depth aspect allows writing" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06039"], ..Default::default() - }); + })); } } PipelineSubpassType::BeginRendering(_) => { @@ -2966,13 +2965,13 @@ impl GraphicsPipelineCreateInfo { }; if !has_stencil_attachment { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_state.stencil` is `Some`, but `subpass` does not \ have a stencil attachment" .into(), // vuids? ..Default::default() - }); + })); } } } @@ -2988,7 +2987,7 @@ impl GraphicsPipelineCreateInfo { }; if color_attachment_count != color_blend_state.attachments.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the length of `color_blend_state.attachments` does not equal the \ number of color attachments in `subpass`" .into(), @@ -2998,7 +2997,7 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-renderPass-06060", ], ..Default::default() - }); + })); } for (attachment_index, state) in color_blend_state.attachments.iter().enumerate() { @@ -3025,7 +3024,7 @@ impl GraphicsPipelineCreateInfo { .potential_format_features() .intersects(FormatFeatures::COLOR_ATTACHMENT_BLEND) }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`color_blend_state.attachments[{}].blend` is `Some`, but \ the format features of that color attachment in `subpass` \ @@ -3038,7 +3037,7 @@ impl GraphicsPipelineCreateInfo { "VUID-VkGraphicsPipelineCreateInfo-renderPass-06062", ], ..Default::default() - }); + })); } } } diff --git a/vulkano/src/pipeline/graphics/multisample.rs b/vulkano/src/pipeline/graphics/multisample.rs index fc008a99..e58b0d8b 100644 --- a/vulkano/src/pipeline/graphics/multisample.rs +++ b/vulkano/src/pipeline/graphics/multisample.rs @@ -75,7 +75,7 @@ impl MultisampleState { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { rasterization_samples, sample_shading, @@ -97,35 +97,35 @@ impl MultisampleState { if let Some(min_sample_shading) = sample_shading { if !device.enabled_features().sample_rate_shading { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "min_sample_shading".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "sample_rate_shading", )])]), vuids: &["VUID-VkPipelineMultisampleStateCreateInfo-sampleShadingEnable-00784"], - }); + })); } if !(0.0..=1.0).contains(&min_sample_shading) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "min_sample_shading".into(), problem: "is not between 0.0 and 1.0 inclusive".into(), vuids: &["VUID-VkPipelineMultisampleStateCreateInfo-minSampleShading-00786"], ..Default::default() - }); + })); } } if alpha_to_one_enable && !device.enabled_features().alpha_to_one { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "alpha_to_one_enable".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "alpha_to_one", )])]), vuids: &["VUID-VkPipelineMultisampleStateCreateInfo-alphaToOneEnable-00785"], - }); + })); } Ok(()) diff --git a/vulkano/src/pipeline/graphics/rasterization.rs b/vulkano/src/pipeline/graphics/rasterization.rs index b5ce26e7..d5b459bb 100644 --- a/vulkano/src/pipeline/graphics/rasterization.rs +++ b/vulkano/src/pipeline/graphics/rasterization.rs @@ -140,7 +140,7 @@ impl RasterizationState { self } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { depth_clamp_enable, rasterizer_discard_enable, @@ -173,25 +173,25 @@ impl RasterizationState { })?; if depth_clamp_enable && !device.enabled_features().depth_clamp { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_clamp_enable".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "depth_clamp", )])]), vuids: &["VUID-VkPipelineRasterizationStateCreateInfo-depthClampEnable-00782"], - }); + })); } if polygon_mode != PolygonMode::Fill && !device.enabled_features().fill_mode_non_solid { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "polygon_mode".into(), problem: "is not `PolygonMode::Fill`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "fill_mode_non_solid", )])]), vuids: &["VUID-VkPipelineRasterizationStateCreateInfo-polygonMode-01507"], - }); + })); } match rasterizer_discard_enable { @@ -200,7 +200,7 @@ impl RasterizationState { && !device.enabled_features().point_polygons && polygon_mode == PolygonMode::Point { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, \ `rasterizer_discard_enable` is `false`, and \ `polygon_mode` is `PolygonMode::Point`" @@ -210,14 +210,14 @@ impl RasterizationState { )])]), vuids: &["VUID-VkPipelineRasterizationStateCreateInfo-pointPolygons-04458"], ..Default::default() - }); + })); } } StateMode::Dynamic => { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "rasterizer_discard_enable".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -226,7 +226,7 @@ impl RasterizationState { ]), // vuids? ..Default::default() - }); + })); } } _ => (), @@ -246,7 +246,7 @@ impl RasterizationState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "cull_mode".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -255,7 +255,7 @@ impl RasterizationState { ]), // vuids? ..Default::default() - }); + })); } } } @@ -274,7 +274,7 @@ impl RasterizationState { if !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "front_face".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[ @@ -283,7 +283,7 @@ impl RasterizationState { ]), // vuids? ..Default::default() - }); + })); } } } @@ -298,7 +298,7 @@ impl RasterizationState { && !(device.api_version() >= Version::V1_3 || device.enabled_features().extended_dynamic_state2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_bias.enable_dynamic".into(), problem: "is `true`".into(), requires_one_of: RequiresOneOf(&[ @@ -307,84 +307,84 @@ impl RasterizationState { ]), // vuids? ..Default::default() - }); + })); } if matches!(bias, StateMode::Fixed(bias) if bias.clamp != 0.0) && !device.enabled_features().depth_bias_clamp { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_bias.bias.clamp".into(), problem: "is not 0.0".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "depth_bias_clamp", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-00754"], - }); + })); } } if matches!(line_width, StateMode::Fixed(line_width) if line_width != 1.0) && !device.enabled_features().wide_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_width".into(), problem: "is not 1.0".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "wide_lines", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-00749"], - }); + })); } if line_rasterization_mode != LineRasterizationMode::Default { if !device.enabled_extensions().ext_line_rasterization { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_rasterization_mode".into(), problem: "`is not `LineRasterizationMode::Default`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_line_rasterization", )])]), ..Default::default() - }); + })); } match line_rasterization_mode { LineRasterizationMode::Default => (), LineRasterizationMode::Rectangular => { if !device.enabled_features().rectangular_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_rasterization_mode".into(), problem: "is `LineRasterizationMode::Rectangular`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "rectangular_lines", )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02768"], - }); + })); } } LineRasterizationMode::Bresenham => { if !device.enabled_features().bresenham_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_rasterization_mode".into(), problem: "is `LineRasterizationMode::Bresenham`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "bresenham_lines", )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02769"], - }); + })); } } LineRasterizationMode::RectangularSmooth => { if !device.enabled_features().smooth_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_rasterization_mode".into(), problem: "is `LineRasterizationMode::RectangularSmooth`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "smooth_lines", )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-lineRasterizationMode-02770"], - }); + })); } } } @@ -392,33 +392,33 @@ impl RasterizationState { if let Some(line_stipple) = line_stipple { if !device.enabled_extensions().ext_line_rasterization { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_stipple".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_line_rasterization", )])]), ..Default::default() - }); + })); } if let StateMode::Fixed(line_stipple) = line_stipple { let &LineStipple { factor, pattern: _ } = line_stipple; if !(1..=256).contains(&factor) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "line_stipple.factor".into(), problem: "is not between 1 and 256 inclusive".into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-stippledLineEnable-02767"], ..Default::default() - }); + })); } } match line_rasterization_mode { LineRasterizationMode::Default => { if !device.enabled_features().stippled_rectangular_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`line_stipple` is `Some`, and \ `line_rasterization_mode` is \ `LineRasterizationMode::Default`".into(), @@ -427,23 +427,23 @@ impl RasterizationState { )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02774"], ..Default::default() - }); + })); } if !properties.strict_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`line_stipple` is `Some`, and \ `line_rasterization_mode` is \ `LineRasterizationMode::Default`, \ but the `strict_lines` property is `false`".into(), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02774"], ..Default::default() - }); + })); } } LineRasterizationMode::Rectangular => { if !device.enabled_features().stippled_rectangular_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`line_stipple` is `Some`, and \ `line_rasterization_mode` is \ `LineRasterizationMode::Rectangular`".into(), @@ -452,12 +452,12 @@ impl RasterizationState { )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02771"], ..Default::default() - }); + })); } } LineRasterizationMode::Bresenham => { if !device.enabled_features().stippled_bresenham_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`line_stipple` is `Some`, and \ `line_rasterization_mode` is \ `LineRasterizationMode::Bresenham`".into(), @@ -466,12 +466,12 @@ impl RasterizationState { )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02772"], ..Default::default() - }); + })); } } LineRasterizationMode::RectangularSmooth => { if !device.enabled_features().stippled_smooth_lines { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`line_stipple` is `Some`, and \ `line_rasterization_mode` is \ `LineRasterizationMode::RectangularSmooth`".into(), @@ -480,7 +480,7 @@ impl RasterizationState { )])]), vuids: &["VUID-VkPipelineRasterizationLineStateCreateInfoEXT-stippledLineEnable-02773"], ..Default::default() - }); + })); } } } diff --git a/vulkano/src/pipeline/graphics/subpass.rs b/vulkano/src/pipeline/graphics/subpass.rs index 8fe541d8..46be6a7b 100644 --- a/vulkano/src/pipeline/graphics/subpass.rs +++ b/vulkano/src/pipeline/graphics/subpass.rs @@ -151,7 +151,7 @@ impl PipelineRenderingCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { view_mask, ref color_attachment_formats, @@ -163,25 +163,25 @@ impl PipelineRenderingCreateInfo { let properties = device.physical_device().properties(); if view_mask != 0 && !device.enabled_features().multiview { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "view_mask".into(), problem: "is not zero".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature("multiview")])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-multiview-06577"], - }); + })); } let view_count = u32::BITS - view_mask.leading_zeros(); if view_count > properties.max_multiview_view_count.unwrap_or(0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "view_mask".into(), problem: "the number of views exceeds the \ `max_multiview_view_count` limit" .into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature("multiview")])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06578"], - }); + })); } for (attachment_index, format) in color_attachment_formats @@ -203,14 +203,14 @@ impl PipelineRenderingCreateInfo { .potential_format_features() .intersects(FormatFeatures::COLOR_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_attachment_formats[{}]", attachment_index).into(), problem: "format features do not contain \ `FormatFeature::COLOR_ATTACHMENT`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06582"], ..Default::default() - }); + })); } } @@ -227,23 +227,23 @@ impl PipelineRenderingCreateInfo { .potential_format_features() .intersects(FormatFeatures::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_attachment_format".into(), problem: "format features do not contain \ `FormatFeature::DEPTH_STENCIL_ATTACHMENT`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06585"], ..Default::default() - }); + })); } if !format.aspects().intersects(ImageAspects::DEPTH) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_attachment_format".into(), problem: "does not have a depth aspect".into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06587"], ..Default::default() - }); + })); } } @@ -260,23 +260,23 @@ impl PipelineRenderingCreateInfo { .potential_format_features() .intersects(FormatFeatures::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "render_pass.stencil_attachment_format".into(), problem: "format features do not contain \ `FormatFeature::DEPTH_STENCIL_ATTACHMENT`" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06586"], ..Default::default() - }); + })); } if !format.aspects().intersects(ImageAspects::STENCIL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "render_pass.stencil_attachment_format".into(), problem: "does not have a stencil aspect".into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06588"], ..Default::default() - }); + })); } } @@ -284,13 +284,13 @@ impl PipelineRenderingCreateInfo { (depth_attachment_format, stencil_attachment_format) { if depth_format != stencil_format { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_attachment_format` and `stencil_attachment_format` are both \ `Some`, but are not equal" .into(), vuids: &["VUID-VkGraphicsPipelineCreateInfo-renderPass-06589"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/pipeline/graphics/tessellation.rs b/vulkano/src/pipeline/graphics/tessellation.rs index 4ff415bd..e39e42a6 100644 --- a/vulkano/src/pipeline/graphics/tessellation.rs +++ b/vulkano/src/pipeline/graphics/tessellation.rs @@ -62,7 +62,7 @@ impl TessellationState { self } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { patch_control_points, domain_origin, @@ -74,25 +74,25 @@ impl TessellationState { match patch_control_points { StateMode::Fixed(patch_control_points) => { if patch_control_points == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "patch_control_points".into(), problem: "is zero".into(), vuids: &[ "VUID-VkPipelineTessellationStateCreateInfo-patchControlPoints-01214", ], ..Default::default() - }); + })); } if patch_control_points > properties.max_tessellation_patch_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "patch_control_points".into(), problem: "exceeds the `max_tessellation_patch_size` limit".into(), vuids: &[ "VUID-VkPipelineTessellationStateCreateInfo-patchControlPoints-01214", ], ..Default::default() - }); + })); } } StateMode::Dynamic => { @@ -100,14 +100,14 @@ impl TessellationState { .enabled_features() .extended_dynamic_state2_patch_control_points { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "patch_control_points".into(), problem: "is dynamic".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "extended_dynamic_state2_patch_control_points", )])]), vuids: &["VUID-VkGraphicsPipelineCreateInfo-pDynamicStates-04870"], - }); + })); } } }; @@ -126,7 +126,7 @@ impl TessellationState { && !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_maintenance2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "domain_origin".into(), problem: "is not `TessellationDomainOrigin::UpperLeft`".into(), requires_one_of: RequiresOneOf(&[ @@ -134,7 +134,7 @@ impl TessellationState { RequiresAllOf(&[Requires::DeviceExtension("khr_maintenance2")]), ]), ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/pipeline/graphics/vertex_input/buffers.rs b/vulkano/src/pipeline/graphics/vertex_input/buffers.rs index 8f45c591..734e88a7 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/buffers.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/buffers.rs @@ -62,7 +62,10 @@ impl BuffersDefinition { #[allow(deprecated)] unsafe impl VertexDefinition for BuffersDefinition { #[inline] - fn definition(&self, interface: &ShaderInterface) -> Result { + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result> { self.0.definition(interface) } } diff --git a/vulkano/src/pipeline/graphics/vertex_input/definition.rs b/vulkano/src/pipeline/graphics/vertex_input/definition.rs index 0bc6511e..77976086 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/definition.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/definition.rs @@ -18,12 +18,18 @@ use crate::{ /// Trait for types that can create a [`VertexInputState`] from a [`ShaderInterface`]. pub unsafe trait VertexDefinition { /// Builds the `VertexInputState` for the provided `interface`. - fn definition(&self, interface: &ShaderInterface) -> Result; + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result>; } unsafe impl VertexDefinition for &[VertexBufferDescription] { #[inline] - fn definition(&self, interface: &ShaderInterface) -> Result { + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result> { let bindings = self.iter().enumerate().map(|(binding, buffer)| { ( binding as u32, @@ -47,14 +53,16 @@ unsafe impl VertexDefinition for &[VertexBufferDescription] { .get(name.as_ref()) .map(|infos| (infos.clone(), binding as u32)) }) - .ok_or_else(|| ValidationError { - problem: format!( - "the shader interface contains a variable named \"{}\", \ + .ok_or_else(|| { + Box::new(ValidationError { + problem: format!( + "the shader interface contains a variable named \"{}\", \ but no such attribute exists in the vertex definition", - name, - ) - .into(), - ..Default::default() + name, + ) + .into(), + ..Default::default() + }) })?; // TODO: ShaderInterfaceEntryType does not properly support 64bit. @@ -63,7 +71,7 @@ unsafe impl VertexDefinition for &[VertexBufferDescription] { if infos.num_components() != element.ty.num_components || infos.num_elements != element.ty.num_locations() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "for the variable \"{}\", the number of locations and components \ required by the shader don't match the number of locations and components \ @@ -72,7 +80,7 @@ unsafe impl VertexDefinition for &[VertexBufferDescription] { ) .into(), ..Default::default() - }); + })); } let mut offset = infos.offset as DeviceSize; @@ -106,21 +114,30 @@ unsafe impl VertexDefinition for &[VertexBufferDescription] { unsafe impl VertexDefinition for [VertexBufferDescription; N] { #[inline] - fn definition(&self, interface: &ShaderInterface) -> Result { + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result> { self.as_slice().definition(interface) } } unsafe impl VertexDefinition for Vec { #[inline] - fn definition(&self, interface: &ShaderInterface) -> Result { + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result> { self.as_slice().definition(interface) } } unsafe impl VertexDefinition for VertexBufferDescription { #[inline] - fn definition(&self, interface: &ShaderInterface) -> Result { + fn definition( + &self, + interface: &ShaderInterface, + ) -> Result> { std::slice::from_ref(self).definition(interface) } } diff --git a/vulkano/src/pipeline/graphics/vertex_input/mod.rs b/vulkano/src/pipeline/graphics/vertex_input/mod.rs index 630ed006..9567dda9 100644 --- a/vulkano/src/pipeline/graphics/vertex_input/mod.rs +++ b/vulkano/src/pipeline/graphics/vertex_input/mod.rs @@ -179,7 +179,7 @@ impl VertexInputState { self } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let Self { bindings, attributes, @@ -189,14 +189,14 @@ impl VertexInputState { let properties = device.physical_device().properties(); if bindings.len() > properties.max_vertex_input_bindings as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "bindings".into(), problem: "the length exceeds the `max_vertex_input_bindings` limit".into(), vuids: &[ "VUID-VkPipelineVertexInputStateCreateInfo-vertexBindingDescriptionCount-00613", ], ..Default::default() - }); + })); } // VUID-VkPipelineVertexInputStateCreateInfo-pVertexBindingDescriptions-00616 @@ -209,14 +209,14 @@ impl VertexInputState { } if attributes.len() > properties.max_vertex_input_attributes as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "attributes".into(), problem: "the length exceeds the `max_vertex_input_attributes` limit".into(), vuids: &[ "VUID-VkPipelineVertexInputStateCreateInfo-vertexAttributeDescriptionCount-00614", ], ..Default::default() - }); + })); } for (&location, attribute_desc) in attributes { @@ -231,7 +231,7 @@ impl VertexInputState { } = attribute_desc; if location > properties.max_vertex_input_attributes { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "attributes".into(), problem: format!( "the location {} exceeds the `max_vertex_input_attributes` limit", @@ -240,7 +240,7 @@ impl VertexInputState { .into(), vuids: &["VUID-VkVertexInputAttributeDescription-location-00620"], ..Default::default() - }); + })); } let binding_desc = bindings.get(&binding).ok_or(ValidationError { @@ -260,7 +260,7 @@ impl VertexInputState { && offset as DeviceSize + format.block_size().unwrap() > binding_desc.stride as DeviceSize { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "this device is a portability subset device, and \ `attributes[{0}].offset + attributes[{0}].format.block_size()` \ @@ -273,7 +273,7 @@ impl VertexInputState { )])]), vuids: &["VUID-VkVertexInputAttributeDescription-vertexAttributeAccessBeyondStride-04457"], ..Default::default() - }); + })); } } @@ -286,7 +286,7 @@ impl VertexInputState { for location in unassigned_locations { if !attributes.get(&location).is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`attributes[{}].format` takes up two locations, but \ `attributes` also contains a description for location {}", @@ -295,7 +295,7 @@ impl VertexInputState { .into(), vuids: &["VUID-VkPipelineVertexInputStateCreateInfo-pVertexAttributeDescriptions-00617"], ..Default::default() - }); + })); } } @@ -327,18 +327,18 @@ pub struct VertexInputBindingDescription { } impl VertexInputBindingDescription { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { stride, input_rate } = self; let properties = device.physical_device().properties(); if stride > properties.max_vertex_input_binding_stride { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stride".into(), problem: "exceeds the `max_vertex_input_binding_stride` limit".into(), vuids: &["VUID-VkVertexInputBindingDescription-stride-00619"], ..Default::default() - }); + })); } if device.enabled_extensions().khr_portability_subset @@ -349,14 +349,14 @@ impl VertexInputBindingDescription { .unwrap() != 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "this device is a portability subset device, and \ `stride` is not a multiple of, and at least as large as, the \ `min_vertex_input_binding_stride_alignment` limit" .into(), vuids: &["VUID-VkVertexInputBindingDescription-stride-04456"], ..Default::default() - }); + })); } match input_rate { @@ -365,7 +365,7 @@ impl VertexInputBindingDescription { .enabled_features() .vertex_attribute_instance_rate_divisor { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "input_rate".into(), problem: "is `VertexInputRate::Instance`, and \ its `divisor` value is not 1".into(), @@ -373,7 +373,7 @@ impl VertexInputBindingDescription { "vertex_attribute_instance_rate_divisor", )])]), vuids: &["VUID-VkVertexInputBindingDivisorDescriptionEXT-vertexAttributeInstanceRateDivisor-02229"], - }); + })); } if divisor == 0 @@ -381,7 +381,7 @@ impl VertexInputBindingDescription { .enabled_features() .vertex_attribute_instance_rate_zero_divisor { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "input_rate".into(), problem: "is `VertexInputRate::Instance`, and \ its `divisor` value is 0".into(), @@ -389,18 +389,18 @@ impl VertexInputBindingDescription { "vertex_attribute_instance_rate_zero_divisor", )])]), vuids: &["VUID-VkVertexInputBindingDivisorDescriptionEXT-vertexAttributeInstanceRateZeroDivisor-02228"], - }); + })); } if divisor > properties.max_vertex_attrib_divisor.unwrap() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "input_rate".into(), problem: "is `VertexInputRate::Instance`, and \ its `divisor` value exceeds the `max_vertex_attrib_divisor` limit" .into(), vuids: &["VUID-VkVertexInputBindingDivisorDescriptionEXT-divisor-01870"], ..Default::default() - }); + })); } } _ => (), @@ -430,7 +430,7 @@ pub struct VertexInputAttributeDescription { } impl VertexInputAttributeDescription { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { binding, format, @@ -448,21 +448,21 @@ impl VertexInputAttributeDescription { })?; if binding > properties.max_vertex_input_bindings { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "binding".into(), problem: "exceeds the `max_vertex_input_bindings` limit".into(), vuids: &["VUID-VkVertexInputAttributeDescription-binding-00621"], ..Default::default() - }); + })); } if offset > properties.max_vertex_input_attribute_offset { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "offset".into(), problem: "exceeds the `max_vertex_input_attribute_offset` limit".into(), vuids: &["VUID-VkVertexInputAttributeDescription-offset-00622"], ..Default::default() - }); + })); } let format_features = unsafe { @@ -473,13 +473,13 @@ impl VertexInputAttributeDescription { }; if !format_features.intersects(FormatFeatures::VERTEX_BUFFER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "format".into(), problem: "the format features do not include `FormatFeatures::VERTEX_BUFFER`" .into(), vuids: &["VUID-VkVertexInputAttributeDescription-format-00623"], ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/pipeline/graphics/viewport.rs b/vulkano/src/pipeline/graphics/viewport.rs index 0204e0ce..c26f4ae4 100644 --- a/vulkano/src/pipeline/graphics/viewport.rs +++ b/vulkano/src/pipeline/graphics/viewport.rs @@ -182,7 +182,7 @@ impl ViewportState { None } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let Self { viewports, scissors, @@ -194,12 +194,12 @@ impl ViewportState { let viewport_count = match viewports { PartialStateMode::Fixed(viewports) => { if viewports.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "viewports".into(), problem: "is empty".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-viewportCount-04135"], ..Default::default() - }); + })); } for (index, viewport) in viewports.iter().enumerate() { @@ -212,12 +212,12 @@ impl ViewportState { } PartialStateMode::Dynamic(StateMode::Fixed(count)) => { if *count == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "viewports".into(), problem: "is empty".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-viewportCount-04135"], ..Default::default() - }); + })); } *count @@ -231,12 +231,12 @@ impl ViewportState { let scissor_count = match scissors { PartialStateMode::Fixed(scissors) => { if scissors.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "scissors".into(), problem: "is empty".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-scissorCount-04136"], ..Default::default() - }); + })); } for (index, scissor) in scissors.iter().enumerate() { @@ -250,12 +250,12 @@ impl ViewportState { .and_then(|(o, e)| o.checked_add(e)) .is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("scissors[{}]", index).into(), problem: "`offset[0] + extent[0]` is greater than `i32::MAX`".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-offset-02822"], ..Default::default() - }); + })); } if (i32::try_from(offset[1]).ok()) @@ -263,12 +263,12 @@ impl ViewportState { .and_then(|(o, e)| o.checked_add(e)) .is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("scissors[{}]", index).into(), problem: "`offset[1] + extent[1]` is greater than `i32::MAX`".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-offset-02823"], ..Default::default() - }); + })); } } @@ -276,12 +276,12 @@ impl ViewportState { } PartialStateMode::Dynamic(StateMode::Fixed(count)) => { if *count == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "scissors".into(), problem: "is empty".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-scissorCount-04136"], ..Default::default() - }); + })); } *count @@ -293,52 +293,52 @@ impl ViewportState { }; if viewport_count != 0 && scissor_count != 0 && viewport_count != scissor_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the length of `viewports` and the length of `scissors` are not equal" .into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-scissorCount-04134"], ..Default::default() - }); + })); } if viewport_count > 1 && !device.enabled_features().multi_viewport { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "viewports".into(), problem: "the length is greater than 1".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "multi_viewport", )])]), vuids: &["VUID-VkPipelineViewportStateCreateInfo-viewportCount-01216"], - }); + })); } if scissor_count > 1 && !device.enabled_features().multi_viewport { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "scissors".into(), problem: "the length is greater than 1".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "multi_viewport", )])]), vuids: &["VUID-VkPipelineViewportStateCreateInfo-scissorCount-01217"], - }); + })); } if viewport_count > properties.max_viewports { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "viewports".into(), problem: "the length exceeds the `max_viewports` limit".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-viewportCount-01218"], ..Default::default() - }); + })); } if scissor_count > properties.max_viewports { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "scissors".into(), problem: "the length exceeds the `max_viewports` limit".into(), vuids: &["VUID-VkPipelineViewportStateCreateInfo-scissorCount-01219"], ..Default::default() - }); + })); } Ok(()) @@ -373,7 +373,7 @@ pub struct Viewport { } impl Viewport { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { offset, extent, @@ -383,28 +383,28 @@ impl Viewport { let properties = device.physical_device().properties(); if extent[0] <= 0.0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[0]".into(), problem: "is not greater than zero".into(), vuids: &["VUID-VkViewport-width-01770"], ..Default::default() - }); + })); } if extent[0] > properties.max_viewport_dimensions[0] as f32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[0]".into(), problem: "exceeds the `max_viewport_dimensions[0]` limit".into(), vuids: &["VUID-VkViewport-width-01771"], ..Default::default() - }); + })); } if extent[1] <= 0.0 && !(device.api_version() >= Version::V1_1 || device.enabled_extensions().khr_maintenance1) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[1]".into(), problem: "is not greater than zero".into(), requires_one_of: RequiresOneOf(&[ @@ -412,94 +412,94 @@ impl Viewport { RequiresAllOf(&[Requires::DeviceExtension("khr_maintenance1")]), ]), vuids: &["VUID-VkViewport-apiVersion-07917"], - }); + })); } if extent[1].abs() > properties.max_viewport_dimensions[1] as f32 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[1]".into(), problem: "exceeds the `max_viewport_dimensions[1]` limit".into(), vuids: &["VUID-VkViewport-height-01773"], ..Default::default() - }); + })); } if offset[0] < properties.viewport_bounds_range[0] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[0]` is less than the `viewport_bounds_range[0]` property".into(), vuids: &["VUID-VkViewport-x-01774"], ..Default::default() - }); + })); } if offset[0] + extent[0] > properties.viewport_bounds_range[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[0] + extent[0]` is greater than the \ `viewport_bounds_range[1]` property" .into(), vuids: &["VUID-VkViewport-x-01232"], ..Default::default() - }); + })); } if offset[1] < properties.viewport_bounds_range[0] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[1]` is less than the `viewport_bounds_range[0]` property".into(), vuids: &["VUID-VkViewport-y-01775"], ..Default::default() - }); + })); } if offset[1] > properties.viewport_bounds_range[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[1]` is greater than the `viewport_bounds_range[1]` property" .into(), vuids: &["VUID-VkViewport-y-01776"], ..Default::default() - }); + })); } if offset[1] + extent[1] < properties.viewport_bounds_range[0] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[1] + extent[1]` is less than the \ `viewport_bounds_range[0]` property" .into(), vuids: &["VUID-VkViewport-y-01777"], ..Default::default() - }); + })); } if offset[1] + extent[1] > properties.viewport_bounds_range[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`offset[1] + extent[1]` is greater than the \ `viewport_bounds_range[1]` property" .into(), vuids: &["VUID-VkViewport-y-01233"], ..Default::default() - }); + })); } if !device.enabled_extensions().ext_depth_range_unrestricted { if *depth_range.start() < 0.0 || *depth_range.start() > 1.0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_range.start` is not between 0.0 and 1.0 inclusive".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_depth_range_unrestricted", )])]), vuids: &["VUID-VkViewport-minDepth-01234"], ..Default::default() - }); + })); } if *depth_range.end() < 0.0 || *depth_range.end() > 1.0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_range.end` is not between 0.0 and 1.0 inclusive".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_depth_range_unrestricted", )])]), vuids: &["VUID-VkViewport-maxDepth-01235"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/pipeline/layout.rs b/vulkano/src/pipeline/layout.rs index 35a52fef..daf49813 100644 --- a/vulkano/src/pipeline/layout.rs +++ b/vulkano/src/pipeline/layout.rs @@ -73,7 +73,7 @@ use crate::{ instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags}, shader::{DescriptorBindingRequirements, ShaderStage, ShaderStages}, - RuntimeError, ValidationError, VulkanError, VulkanObject, + Validated, ValidationError, VulkanError, VulkanObject, }; use ahash::HashMap; use smallvec::SmallVec; @@ -108,7 +108,7 @@ impl PipelineLayout { pub fn new( device: Arc, create_info: PipelineLayoutCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_new(&device, &create_info)?; unsafe { Ok(Self::new_unchecked(device, create_info)?) } @@ -117,7 +117,7 @@ impl PipelineLayout { fn validate_new( device: &Device, create_info: &PipelineLayoutCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreatePipelineLayout-pCreateInfo-parameter create_info .validate(device) @@ -130,7 +130,7 @@ impl PipelineLayout { pub unsafe fn new_unchecked( device: Arc, create_info: PipelineLayoutCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let &PipelineLayoutCreateInfo { flags, ref set_layouts, @@ -167,7 +167,7 @@ impl PipelineLayout { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -320,13 +320,13 @@ impl PipelineLayout { /// Makes sure that `self` is a superset of the provided descriptor set layouts and push /// constant ranges. Returns an `Err` if this is not the case. - pub fn ensure_compatible_with_shader<'a>( + pub(crate) fn ensure_compatible_with_shader<'a>( &self, descriptor_requirements: impl IntoIterator< Item = ((u32, u32), &'a DescriptorBindingRequirements), >, push_constant_range: Option<&PushConstantRange>, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { for ((set_num, binding_num), reqs) in descriptor_requirements.into_iter() { let layout_binding = self .set_layouts @@ -336,7 +336,7 @@ impl PipelineLayout { let layout_binding = match layout_binding { Some(x) => x, None => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the requirements for descriptor set {} binding {} were not met: \ no such binding exists in the pipeline layout", @@ -344,19 +344,19 @@ impl PipelineLayout { ) .into(), ..Default::default() - }); + })); } }; if let Err(error) = layout_binding.ensure_compatible_with_shader(reqs) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the requirements for descriptor set {} binding {} were not met: {}", set_num, binding_num, error, ) .into(), ..Default::default() - }); + })); } } @@ -366,12 +366,12 @@ impl PipelineLayout { (range.offset < own_range.offset || // our range must start before and end after the given range own_range.offset + own_range.size < range.offset + range.size) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the required push constant range is larger than the \ push constant range in the pipeline layout" .into(), ..Default::default() - }); + })); } } } @@ -447,7 +447,7 @@ impl Default for PipelineLayoutCreateInfo { } impl PipelineLayoutCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let properties = device.physical_device().properties(); let &Self { @@ -466,12 +466,12 @@ impl PipelineLayoutCreateInfo { })?; if set_layouts.len() > properties.max_bound_descriptor_sets as usize { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "set_layouts".into(), problem: "the length exceeds the `max_bound_descriptor_sets` limit".into(), vuids: &["VUID-VkPipelineLayoutCreateInfo-setLayoutCount-00286"], ..Default::default() - }); + })); } struct DescriptorLimit { @@ -640,14 +640,14 @@ impl PipelineLayoutCreateInfo { .intersects(DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR) { if has_push_descriptor_set { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "set_layouts".into(), problem: "contains more than one descriptor set layout whose flags \ include `DescriptorSetLayoutCreateFlags::PUSH_DESCRIPTOR`" .into(), vuids: &["VUID-VkPipelineLayoutCreateInfo-pSetLayouts-00293"], ..Default::default() - }); + })); } has_push_descriptor_set = true; @@ -688,7 +688,7 @@ impl PipelineLayoutCreateInfo { { if let Some((max_stage, max_count)) = count.into_iter().max_by_key(|(_, c)| *c) { if max_count > (limit.get_limit)(properties) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "set_layouts".into(), problem: format!( "the combined number of {} descriptors accessible to the \ @@ -706,14 +706,14 @@ impl PipelineLayoutCreateInfo { .into(), vuids: limit.vuids, ..Default::default() - }); + })); } } } for (limit, count) in TOTAL_DESCRIPTOR_LIMITS.iter().zip(total_descriptors) { if count > (limit.get_limit)(properties) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "set_layouts".into(), problem: format!( "the combined number of {} descriptors accessible across all \ @@ -730,7 +730,7 @@ impl PipelineLayoutCreateInfo { .into(), vuids: limit.vuids, ..Default::default() - }); + })); } } @@ -748,12 +748,12 @@ impl PipelineLayoutCreateInfo { } = range; if seen_stages.intersects(stages) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "push_constant_ranges".into(), problem: "contains more than one range with the same stage".into(), vuids: &["VUID-VkPipelineLayoutCreateInfo-pPushConstantRanges-00292"], ..Default::default() - }); + })); } seen_stages |= stages; @@ -812,7 +812,7 @@ impl Default for PushConstantRange { } impl PushConstantRange { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { stages, offset, @@ -828,12 +828,12 @@ impl PushConstantRange { })?; if stages.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stages".into(), problem: "is empty".into(), vuids: &["VUID-VkPushConstantRange-stageFlags-requiredbitmask"], ..Default::default() - }); + })); } let max_push_constants_size = device @@ -842,48 +842,48 @@ impl PushConstantRange { .max_push_constants_size; if offset >= max_push_constants_size { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "offset".into(), problem: "is not less than the `max_push_constants_size` limit".into(), vuids: &["VUID-VkPushConstantRange-offset-00294"], ..Default::default() - }); + })); } if offset % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "offset".into(), problem: "is not a multiple of 4".into(), vuids: &["VUID-VkPushConstantRange-offset-00295"], ..Default::default() - }); + })); } if size == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "size".into(), problem: "is zero".into(), vuids: &["VUID-VkPushConstantRange-size-00296"], ..Default::default() - }); + })); } if size % 4 != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "size".into(), problem: "is not a multiple of 4".into(), vuids: &["VUID-VkPushConstantRange-size-00297"], ..Default::default() - }); + })); } if size > max_push_constants_size - offset { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`size` is greater than `max_push_constants_size` limit minus `offset`" .into(), vuids: &["VUID-VkPushConstantRange-size-00298"], ..Default::default() - }); + })); } Ok(()) @@ -1006,7 +1006,7 @@ impl PipelineDescriptorSetLayoutCreateInfo { #[derive(Clone, Debug)] pub struct IntoPipelineLayoutCreateInfoError { pub set_num: u32, - pub error: VulkanError, + pub error: Validated, } impl Display for IntoPipelineLayoutCreateInfoError { diff --git a/vulkano/src/pipeline/mod.rs b/vulkano/src/pipeline/mod.rs index c16a3fef..194d94cd 100644 --- a/vulkano/src/pipeline/mod.rs +++ b/vulkano/src/pipeline/mod.rs @@ -336,7 +336,7 @@ impl PipelineShaderStageCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref entry_point, @@ -381,7 +381,7 @@ impl PipelineShaderStageCreateInfo { } ShaderStage::TessellationControl | ShaderStage::TessellationEvaluation => { if !device.enabled_features().tessellation_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "entry_point".into(), problem: "specifies a `ShaderStage::TessellationControl` or \ `ShaderStage::TessellationEvaluation` entry point" @@ -390,7 +390,7 @@ impl PipelineShaderStageCreateInfo { "tessellation_shader", )])]), vuids: &["VUID-VkPipelineShaderStageCreateInfo-stage-00705"], - }); + })); } // VUID-VkPipelineShaderStageCreateInfo-stage-00713 @@ -398,14 +398,14 @@ impl PipelineShaderStageCreateInfo { } ShaderStage::Geometry => { if !device.enabled_features().geometry_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "entry_point".into(), problem: "specifies a `ShaderStage::Geometry` entry point".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "geometry_shader", )])]), vuids: &["VUID-VkPipelineShaderStageCreateInfo-stage-00704"], - }); + })); } // TODO: @@ -427,26 +427,26 @@ impl PipelineShaderStageCreateInfo { ShaderStage::Callable => (), ShaderStage::Task => { if !device.enabled_features().task_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "entry_point".into(), problem: "specifies a `ShaderStage::Task` entry point".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "task_shader", )])]), vuids: &["VUID-VkPipelineShaderStageCreateInfo-stage-02092"], - }); + })); } } ShaderStage::Mesh => { if !device.enabled_features().mesh_shader { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "entry_point".into(), problem: "specifies a `ShaderStage::Mesh` entry point".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "mesh_shader", )])]), vuids: &["VUID-VkPipelineShaderStageCreateInfo-stage-02091"], - }); + })); } } ShaderStage::SubpassShading => (), @@ -461,7 +461,7 @@ impl PipelineShaderStageCreateInfo { { // Check for equal types rather than only equal size. if !provided_value.eq_type(default_value) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`specialization_info[{0}]` does not have the same type as \ `entry_point.info().specialization_constants[{0}]`", @@ -470,7 +470,7 @@ impl PipelineShaderStageCreateInfo { .into(), vuids: &["VUID-VkSpecializationMapEntry-constantID-00776"], ..Default::default() - }); + })); } } } diff --git a/vulkano/src/query.rs b/vulkano/src/query.rs index f2c94a87..527b904c 100644 --- a/vulkano/src/query.rs +++ b/vulkano/src/query.rs @@ -18,7 +18,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags}, - DeviceSize, OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, + DeviceSize, OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, VulkanError, VulkanObject, }; use std::{ @@ -96,7 +96,7 @@ impl QueryPool { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -291,13 +291,13 @@ impl From for QueryPoolCreationError { } } -impl From for QueryPoolCreationError { - fn from(err: RuntimeError) -> QueryPoolCreationError { +impl From for QueryPoolCreationError { + fn from(err: VulkanError) -> QueryPoolCreationError { match err { - err @ RuntimeError::OutOfHostMemory => { + err @ VulkanError::OutOfHostMemory => { QueryPoolCreationError::OomError(OomError::from(err)) } - err @ RuntimeError::OutOfDeviceMemory => { + err @ VulkanError::OutOfDeviceMemory => { QueryPoolCreationError::OomError(OomError::from(err)) } _ => panic!("unexpected error: {:?}", err), @@ -424,7 +424,7 @@ impl<'a> QueriesRange<'a> { match result { ash::vk::Result::SUCCESS => Ok(true), ash::vk::Result::NOT_READY => Ok(false), - err => Err(RuntimeError::from(err).into()), + err => Err(VulkanError::from(err).into()), } } } @@ -486,13 +486,13 @@ impl Display for GetResultsError { } } -impl From for GetResultsError { - fn from(err: RuntimeError) -> Self { +impl From for GetResultsError { + fn from(err: VulkanError) -> Self { match err { - RuntimeError::OutOfHostMemory | RuntimeError::OutOfDeviceMemory => { + VulkanError::OutOfHostMemory | VulkanError::OutOfDeviceMemory => { Self::OomError(OomError::from(err)) } - RuntimeError::DeviceLost => Self::DeviceLost, + VulkanError::DeviceLost => Self::DeviceLost, _ => panic!("unexpected error: {:?}", err), } } diff --git a/vulkano/src/render_pass/create.rs b/vulkano/src/render_pass/create.rs index 47dca6ce..5d162781 100644 --- a/vulkano/src/render_pass/create.rs +++ b/vulkano/src/render_pass/create.rs @@ -11,7 +11,7 @@ use super::{AttachmentDescription, AttachmentReference, RenderPass, RenderPassCr use crate::{ device::Device, render_pass::{SubpassDependency, SubpassDescription}, - RuntimeError, Version, VulkanObject, + Version, VulkanError, VulkanObject, }; use smallvec::SmallVec; use std::{mem::MaybeUninit, ptr}; @@ -20,7 +20,7 @@ impl RenderPass { pub(super) unsafe fn create_v2( device: &Device, create_info: &RenderPassCreateInfo, - ) -> Result { + ) -> Result { let &RenderPassCreateInfo { flags, ref attachments, @@ -522,7 +522,7 @@ impl RenderPass { ) } .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }) @@ -531,7 +531,7 @@ impl RenderPass { pub(super) unsafe fn create_v1( device: &Device, create_info: &RenderPassCreateInfo, - ) -> Result { + ) -> Result { let &RenderPassCreateInfo { flags, ref attachments, @@ -891,7 +891,7 @@ impl RenderPass { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }) } diff --git a/vulkano/src/render_pass/framebuffer.rs b/vulkano/src/render_pass/framebuffer.rs index 8bf12307..8c9e2647 100644 --- a/vulkano/src/render_pass/framebuffer.rs +++ b/vulkano/src/render_pass/framebuffer.rs @@ -15,7 +15,7 @@ use crate::{ ImageAspects, ImageType, ImageUsage, }, macros::{impl_id_counter, vulkan_bitflags}, - RuntimeError, ValidationError, VulkanError, VulkanObject, + Validated, ValidationError, VulkanError, VulkanObject, }; use smallvec::SmallVec; use std::{mem::MaybeUninit, num::NonZeroU64, ops::Range, ptr, sync::Arc}; @@ -61,7 +61,7 @@ impl Framebuffer { pub fn new( render_pass: Arc, mut create_info: FramebufferCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { create_info.set_auto_extent_layers(&render_pass); Self::validate_new(&render_pass, &create_info)?; @@ -71,7 +71,7 @@ impl Framebuffer { fn validate_new( render_pass: &RenderPass, create_info: &FramebufferCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateFramebuffer-pCreateInfo-parameter create_info .validate(render_pass.device()) @@ -86,13 +86,13 @@ impl Framebuffer { } = create_info; if attachments.len() != render_pass.attachments().len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.attachments` does not have the same length as \ `render_pass.attachments()`" .into(), vuids: &["VUID-VkFramebufferCreateInfo-attachmentCount-00876"], ..Default::default() - }); + })); } for (index, ((image_view, attachment_desc), attachment_use)) in attachments @@ -104,7 +104,7 @@ impl Framebuffer { if attachment_use.color_attachment && !image_view.usage().intersects(ImageUsage::COLOR_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` uses `create_info.attachments[{}]` as \ a color attachment, but it was not created with the \ @@ -114,7 +114,7 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00877"], ..Default::default() - }); + })); } if attachment_use.depth_stencil_attachment @@ -122,7 +122,7 @@ impl Framebuffer { .usage() .intersects(ImageUsage::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` uses `create_info.attachments[{}]` as \ a depth or stencil attachment, but it was not created with the \ @@ -135,13 +135,13 @@ impl Framebuffer { "VUID-VkFramebufferCreateInfo-pAttachments-02634", ], ..Default::default() - }); + })); } if attachment_use.input_attachment && !image_view.usage().intersects(ImageUsage::INPUT_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` uses `create_info.attachments[{}]` as \ an input attachment, but it was not created with the \ @@ -151,11 +151,11 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-02633"], ..Default::default() - }); + })); } if image_view.format() != attachment_desc.format { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the format of `create_info.attachments[{}]` does not equal \ `render_pass.attachments()[{0}].format`", @@ -164,11 +164,11 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00880"], ..Default::default() - }); + })); } if image_view.image().samples() != attachment_desc.samples { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the samples of `create_info.attachments[{}]` does not equal \ `render_pass.attachments()[{0}].samples`", @@ -177,7 +177,7 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00881"], ..Default::default() - }); + })); } let image_view_extent = image_view.image().extent(); @@ -189,7 +189,7 @@ impl Framebuffer { || attachment_use.depth_stencil_attachment { if image_view_extent[0] < extent[0] || image_view_extent[1] < extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` uses `create_info.attachments[{}]` as an input, color, \ depth or stencil attachment, but \ @@ -202,11 +202,11 @@ impl Framebuffer { "VUID-VkFramebufferCreateInfo-flags-04534", ], ..Default::default() - }); + })); } if image_view_array_layers < layers { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` uses `create_info.attachments[{}]` as an input, color, \ depth or stencil attachment, but \ @@ -216,11 +216,11 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-flags-04535"], ..Default::default() - }); + })); } if image_view_array_layers < render_pass.views_used() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`render_pass` has multiview enabled, and uses \ `create_info.attachments[{}]` as an input, color, depth or stencil \ @@ -231,18 +231,18 @@ impl Framebuffer { .into(), vuids: &["VUID-VkFramebufferCreateInfo-renderPass-04536"], ..Default::default() - }); + })); } } if render_pass.views_used() != 0 && layers != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`render_pass` has multiview enabled, but \ `create_info.layers` is not 1" .into(), vuids: &["VUID-VkFramebufferCreateInfo-renderPass-02531"], ..Default::default() - }); + })); } } @@ -253,7 +253,7 @@ impl Framebuffer { pub unsafe fn new_unchecked( render_pass: Arc, mut create_info: FramebufferCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { create_info.set_auto_extent_layers(&render_pass); let &FramebufferCreateInfo { @@ -288,7 +288,7 @@ impl Framebuffer { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -514,7 +514,7 @@ impl FramebufferCreateInfo { } } - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref attachments, @@ -538,21 +538,21 @@ impl FramebufferCreateInfo { - image_view.subresource_range().mip_levels.start; if image_view_mip_levels != 1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("attachments[{}]", index).into(), problem: "has more than one mip level".into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00883"], ..Default::default() - }); + })); } if !image_view.component_mapping().is_identity() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("attachments[{}]", index).into(), problem: "is not identity swizzled".into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00884"], ..Default::default() - }); + })); } match image_view.view_type() { @@ -561,23 +561,23 @@ impl FramebufferCreateInfo { && (image_view.format().unwrap().aspects()) .intersects(ImageAspects::DEPTH | ImageAspects::STENCIL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("attachments[{}]", index).into(), problem: "is a 2D or 2D array image view, but its format is a \ depth/stencil format" .into(), vuids: &["VUID-VkFramebufferCreateInfo-pAttachments-00891"], ..Default::default() - }); + })); } } ImageViewType::Dim3d => { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("attachments[{}]", index).into(), problem: "is a 3D image view".into(), vuids: &["VUID-VkFramebufferCreateInfo-flags-04113"], ..Default::default() - }); + })); } _ => (), } @@ -586,57 +586,57 @@ impl FramebufferCreateInfo { let properties = device.physical_device().properties(); if extent[0] == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[0]".into(), problem: "is zero".into(), vuids: &["VUID-VkFramebufferCreateInfo-width-00885"], ..Default::default() - }); + })); } if extent[0] > properties.max_framebuffer_width { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[0]".into(), problem: "exceeds the `max_framebuffer_width` limit".into(), vuids: &["VUID-VkFramebufferCreateInfo-width-00886"], ..Default::default() - }); + })); } if extent[1] == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[1]".into(), problem: "is zero".into(), vuids: &["VUID-VkFramebufferCreateInfo-height-00887"], ..Default::default() - }); + })); } if extent[1] > properties.max_framebuffer_height { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "extent[1]".into(), problem: "exceeds the `max_framebuffer_height` limit".into(), vuids: &["VUID-VkFramebufferCreateInfo-height-00888"], ..Default::default() - }); + })); } if layers == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "layers".into(), problem: "is zero".into(), vuids: &["VUID-VkFramebufferCreateInfo-layers-00889"], ..Default::default() - }); + })); } if layers > properties.max_framebuffer_layers { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "layers".into(), problem: "exceeds the `max_framebuffer_layers` limit".into(), vuids: &["VUID-VkFramebufferCreateInfo-layers-00890"], ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/render_pass/mod.rs b/vulkano/src/render_pass/mod.rs index 5159acbb..07baf8ce 100644 --- a/vulkano/src/render_pass/mod.rs +++ b/vulkano/src/render_pass/mod.rs @@ -34,7 +34,7 @@ use crate::{ macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum, vulkan_enum}, shader::ShaderInterface, sync::{AccessFlags, DependencyFlags, MemoryBarrier, PipelineStages}, - Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, Version, VulkanError, + Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version, VulkanError, VulkanObject, }; use ahash::HashMap; @@ -134,7 +134,7 @@ impl RenderPass { pub fn new( device: Arc, mut create_info: RenderPassCreateInfo, - ) -> Result, VulkanError> { + ) -> Result, Validated> { for subpass in create_info.subpasses.iter_mut() { for input_attachment in subpass.input_attachments.iter_mut().flatten() { if input_attachment.aspects.is_empty() { @@ -156,7 +156,7 @@ impl RenderPass { fn validate_new( device: &Device, create_info: &RenderPassCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { // VUID-vkCreateRenderPass2-pCreateInfo-parameter create_info .validate(device) @@ -169,7 +169,7 @@ impl RenderPass { pub unsafe fn new_unchecked( device: Arc, mut create_info: RenderPassCreateInfo, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { for subpass in create_info.subpasses.iter_mut() { for input_attachment in subpass.input_attachments.iter_mut().flatten() { if input_attachment.aspects.is_empty() { @@ -824,7 +824,7 @@ impl Default for RenderPassCreateInfo { } impl RenderPassCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, ref attachments, @@ -876,12 +876,12 @@ impl RenderPassCreateInfo { } if subpasses.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "subpasses".into(), problem: "is empty".into(), vuids: &["VUID-VkRenderPassCreateInfo2-subpassCount-arraylength"], ..Default::default() - }); + })); } let mut attachment_is_used = vec![false; attachments.len()]; @@ -907,7 +907,7 @@ impl RenderPassCreateInfo { } = subpass_desc; if (view_mask != 0) != (subpasses[0].view_mask != 0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{}].view_mask != 0` does not equal \ `subpasses[0].view_mask != 0`", @@ -916,7 +916,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-viewMask-03058"], ..Default::default() - }); + })); } let mut color_samples = None; @@ -959,7 +959,7 @@ impl RenderPassCreateInfo { | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].color_attachments[{2}]`, and \ @@ -971,13 +971,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pAttachments-02522"], ..Default::default() - }); + })); } if !attachment_potential_format_features[attachment as usize] .intersects(FormatFeatures::COLOR_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is used in `subpasses[{1}].color_attachments[{2}]`, \ but the potential format features of `attachments[{0}].format` \ @@ -987,13 +987,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pColorAttachments-02898"], ..Default::default() - }); + })); } match color_samples { Some(samples) => { if samples != attachment_desc.samples { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{0}].color_attachments[{1}]` uses \ an attachment with a different number of samples than other \ @@ -1003,7 +1003,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pColorAttachments-03069"], ..Default::default() - }); + })); } } None => color_samples = Some(attachment_desc.samples), @@ -1046,7 +1046,7 @@ impl RenderPassCreateInfo { | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].color_resolve_attachments[{2}]`, and \ @@ -1058,13 +1058,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pAttachments-02522"], ..Default::default() - }); + })); } if !attachment_potential_format_features[resolve_attachment as usize] .intersects(FormatFeatures::COLOR_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is used in \ `subpasses[{1}].color_resolve_attachments[{2}]`, \ @@ -1075,11 +1075,11 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-02899"], ..Default::default() - }); + })); } if resolve_attachment_desc.samples != SampleCount::Sample1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is used in \ `subpasses[{1}].color_resolve_attachments[{2}]`, but \ @@ -1089,11 +1089,11 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-03067"], ..Default::default() - }); + })); } if attachment_desc.samples == SampleCount::Sample1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is used in \ `subpasses[{1}].color_attachments[{2}]`, and \ @@ -1104,11 +1104,11 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-03066"], ..Default::default() - }); + })); } if resolve_attachment_desc.format != attachment_desc.format { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`attachments[\ subpasses[{0}].color_attachments[{1}].attachment\ @@ -1121,7 +1121,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-03068"], ..Default::default() - }); + })); } } } @@ -1154,7 +1154,7 @@ impl RenderPassCreateInfo { if !attachment_potential_format_features[attachment as usize] .intersects(FormatFeatures::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {} is used in `subpasses[{}].depth_stencil_attachment`, \ but the potential format features of `attachments[{0}].format` \ @@ -1164,12 +1164,12 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pDepthStencilAttachment-02900"], ..Default::default() - }); + })); } if let Some(samples) = color_samples { if samples != attachment_desc.samples { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{}].depth_stencil_attachment` uses an \ attachment with a different number of samples than other color or \ @@ -1179,7 +1179,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pColorAttachments-03069"], ..Default::default() - }); + })); } } @@ -1194,7 +1194,7 @@ impl RenderPassCreateInfo { | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].depth_stencil_attachment`, and \ @@ -1206,7 +1206,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pAttachments-02522"], ..Default::default() - }); + })); } if attachment_desc @@ -1220,7 +1220,7 @@ impl RenderPassCreateInfo { | ImageLayout::DepthAttachmentStencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].depth_stencil_attachment`, and \ @@ -1232,7 +1232,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pAttachments-02523"], ..Default::default() - }); + })); } } @@ -1263,7 +1263,7 @@ impl RenderPassCreateInfo { if !(resolve_format.components()[0] == format.components()[0] && resolve_format.type_depth() == format.type_depth()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the number of bits and numeric type of the depth component of \ `attachments[\ @@ -1278,13 +1278,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03181"], ..Default::default() - }); + })); } if !(resolve_format.components()[1] == format.components()[1] && resolve_format.type_stencil() == format.type_stencil()) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "the number of bits and numeric type of the stencil component of \ `attachments[\ @@ -1299,7 +1299,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03182"], ..Default::default() - }); + })); } let is_first_use = @@ -1314,7 +1314,7 @@ impl RenderPassCreateInfo { | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].depth_stencil_resolve_attachment`, and \ @@ -1326,13 +1326,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pAttachments-02522"], ..Default::default() - }); + })); } if !attachment_potential_format_features[attachment as usize] .intersects(FormatFeatures::DEPTH_STENCIL_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {} is used in \ `subpasses[{}].depth_stencil_resolve_attachment`, \ @@ -1343,11 +1343,11 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-02651"], ..Default::default() - }); + })); } if resolve_attachment_desc.samples != SampleCount::Sample1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {} is used in \ `subpasses[{}].depth_stencil_resolve_attachment`, but \ @@ -1357,11 +1357,11 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03180"], ..Default::default() - }); + })); } if attachment_desc.samples == SampleCount::Sample1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is used in subpass {1} in \ `depth_stencil_attachment`, and \ @@ -1372,7 +1372,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03179"], ..Default::default() - }); + })); } } } @@ -1408,7 +1408,7 @@ impl RenderPassCreateInfo { let is_first_use = !replace(&mut attachment_is_used[attachment as usize], true); if is_first_use && attachment_desc.load_op == AttachmentLoadOp::Clear { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {0} is first used in \ `subpasses[{1}].input_attachments[{2}]`, and \ @@ -1418,13 +1418,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-loadOp-03064"], ..Default::default() - }); + })); } if !attachment_potential_format_features[attachment as usize].intersects( FormatFeatures::COLOR_ATTACHMENT | FormatFeatures::DEPTH_STENCIL_ATTACHMENT, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "attachment {} is used in `subpasses[{}].input_attachments[{}]`, \ but the potential format features of `attachments[{0}].format` \ @@ -1435,7 +1435,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkSubpassDescription2-pInputAttachments-02897"], ..Default::default() - }); + })); } if aspects != format_aspects { @@ -1443,7 +1443,7 @@ impl RenderPassCreateInfo { || device.enabled_extensions().khr_create_renderpass2 || device.enabled_extensions().khr_maintenance2) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{}].input_attachments[{}].aspects` does not \ equal the aspects of \ @@ -1461,11 +1461,11 @@ impl RenderPassCreateInfo { ]), // vuids? ..Default::default() - }); + })); } if !format_aspects.contains(aspects) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{}].input_attachments[{}].aspects` is not a subset of \ the aspects of \ @@ -1476,14 +1476,14 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-attachment-02525"], ..Default::default() - }); + })); } } } for (ref_index, &atch) in preserve_attachments.iter().enumerate() { if atch as usize >= attachments.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[{}].preserve_attachments[{}]` \ is not less than the length of `attachments`", @@ -1492,7 +1492,7 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-attachment-03051"], ..Default::default() - }); + })); } } } @@ -1518,7 +1518,7 @@ impl RenderPassCreateInfo { if subpasses[0].view_mask == 0 && dependency_flags.intersects(DependencyFlags::VIEW_LOCAL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`subpasses[0].view_mask` is 0, and `dependencies[{}].dependency_flags` \ includes `DependencyFlags::VIEW_LOCAL`", @@ -1527,12 +1527,12 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-viewMask-03059"], ..Default::default() - }); + })); } if let Some(src_subpass) = src_subpass { if src_subpass as usize >= subpasses.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`dependencies[{}].src_subpass` is not less than the length of \ `subpasses`", @@ -1541,13 +1541,13 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-srcSubpass-02526"], ..Default::default() - }); + })); } } if let Some(dst_subpass) = dst_subpass { if dst_subpass as usize >= subpasses.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`dependencies[{}].dst_subpass` is not less than the length of \ `subpasses`", @@ -1556,26 +1556,26 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-dstSubpass-02527"], ..Default::default() - }); + })); } } if !PipelineStages::from(QueueFlags::GRAPHICS).contains(src_stages) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("dependencies[{}].src_stages", dependency_index,).into(), problem: "contains a non-graphics stage".into(), vuids: &["VUID-VkRenderPassCreateInfo2-pDependencies-03054"], ..Default::default() - }); + })); } if !PipelineStages::from(QueueFlags::GRAPHICS).contains(dst_stages) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("dependencies[{}].dst_stages", dependency_index,).into(), problem: "contains a non-graphics stage".into(), vuids: &["VUID-VkRenderPassCreateInfo2-pDependencies-03055"], ..Default::default() - }); + })); } if let (Some(src_subpass), Some(dst_subpass)) = (src_subpass, dst_subpass) { @@ -1583,7 +1583,7 @@ impl RenderPassCreateInfo { && subpasses[src_subpass as usize].view_mask.count_ones() > 1 && !dependency_flags.intersects(DependencyFlags::VIEW_LOCAL) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`dependencies[{0}].src_subpass` equals \ `dependencies[{0}].dst_subpass`, and \ @@ -1595,20 +1595,20 @@ impl RenderPassCreateInfo { .into(), vuids: &["VUID-VkRenderPassCreateInfo2-pDependencies-03060"], ..Default::default() - }); + })); } } } if !correlated_view_masks.is_empty() { if subpasses[0].view_mask == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`correlated_view_masks` is not empty, but \ `subpasses[0].view_mask` is zero" .into(), vuids: &["VUID-VkRenderPassCreateInfo2-viewMask-03057"], ..Default::default() - }); + })); } correlated_view_masks.iter().try_fold(0, |total, &mask| { @@ -1740,7 +1740,7 @@ impl Default for AttachmentDescription { } impl AttachmentDescription { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, format, @@ -1823,12 +1823,12 @@ impl AttachmentDescription { final_layout, ImageLayout::Undefined | ImageLayout::Preinitialized ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "final_layout".into(), problem: "is `ImageLayout::Undefined` or `ImageLayout::Preinitialized`".into(), vuids: &["VUID-VkAttachmentDescription2-finalLayout-00843"], ..Default::default() - }); + })); } if !device.enabled_features().separate_depth_stencil_layouts { @@ -1839,7 +1839,7 @@ impl AttachmentDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "initial_layout".into(), problem: "specifies a layout for only the depth aspect or only the \ stencil aspect" @@ -1848,7 +1848,7 @@ impl AttachmentDescription { "separate_depth_stencil_layouts", )])]), vuids: &["VUID-VkAttachmentDescription2-separateDepthStencilLayouts-03284"], - }); + })); } if matches!( @@ -1858,7 +1858,7 @@ impl AttachmentDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "final_layout".into(), problem: "specifies a layout for only the depth aspect or only the \ stencil aspect" @@ -1867,7 +1867,7 @@ impl AttachmentDescription { "separate_depth_stencil_layouts", )])]), vuids: &["VUID-VkAttachmentDescription2-separateDepthStencilLayouts-03285"], - }); + })); } } @@ -1892,24 +1892,24 @@ impl AttachmentDescription { } if stencil_initial_layout.is_some() != stencil_final_layout.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stencil_initial_layout` and `stencil_final_layout` are not either both \ `None` or both `Some`" .into(), ..Default::default() - }); + })); } if let Some(stencil_initial_layout) = stencil_initial_layout { if !device.enabled_features().separate_depth_stencil_layouts { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_initial_layout".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "separate_depth_stencil_layouts", )])]), ..Default::default() - }); + })); } stencil_initial_layout @@ -1932,27 +1932,27 @@ impl AttachmentDescription { | ImageLayout::DepthAttachmentStencilReadOnlyOptimal | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_initial_layout".into(), problem: "cannot be used with stencil formats".into(), vuids: &[ "VUID-VkAttachmentDescriptionStencilLayout-stencilInitialLayout-03308", ], ..Default::default() - }); + })); } } if let Some(stencil_final_layout) = stencil_final_layout { if !device.enabled_features().separate_depth_stencil_layouts { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_final_layout".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "separate_depth_stencil_layouts", )])]), ..Default::default() - }); + })); } stencil_final_layout @@ -1975,24 +1975,24 @@ impl AttachmentDescription { | ImageLayout::DepthAttachmentStencilReadOnlyOptimal | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_final_layout".into(), problem: "is a color or combined depth/stencil layout".into(), vuids: &["VUID-VkAttachmentDescriptionStencilLayout-stencilFinalLayout-03309"], ..Default::default() - }); + })); } if matches!( stencil_final_layout, ImageLayout::Undefined | ImageLayout::Preinitialized ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_final_layout".into(), problem: "is `ImageLayout::Undefined` or `ImageLayout::Preinitialized`".into(), vuids: &["VUID-VkAttachmentDescriptionStencilLayout-stencilFinalLayout-03309"], ..Default::default() - }); + })); } } @@ -2010,7 +2010,7 @@ impl AttachmentDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a color component, but `initial_layout` cannot be \ used with color formats" .into(), @@ -2020,7 +2020,7 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-03286", ], ..Default::default() - }); + })); } if matches!( @@ -2034,7 +2034,7 @@ impl AttachmentDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a color component, but `final_layout` cannot be \ used with color formats" .into(), @@ -2044,40 +2044,40 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-03287", ], ..Default::default() - }); + })); } if load_op == AttachmentLoadOp::Load && initial_layout == ImageLayout::Undefined { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a color component, `load_op` is \ `AttachmentLoadOp::Load`, and `initial_layout` is \ `ImageLayout::Undefined`" .into(), vuids: &["VUID-VkAttachmentDescription2-format-06699"], ..Default::default() - }); + })); } } if format_aspects.intersects(ImageAspects::DEPTH | ImageAspects::STENCIL) { if matches!(initial_layout, ImageLayout::ColorAttachmentOptimal) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a depth component, but `initial_layout` cannot be \ used with depth formats" .into(), vuids: &["VUID-VkAttachmentDescription2-format-03281"], ..Default::default() - }); + })); } if matches!(final_layout, ImageLayout::ColorAttachmentOptimal) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a depth component, but `final_layout` cannot be \ used with depth formats" .into(), vuids: &["VUID-VkAttachmentDescription2-format-03283"], ..Default::default() - }); + })); } if format_aspects.intersects(ImageAspects::DEPTH) { @@ -2085,7 +2085,7 @@ impl AttachmentDescription { initial_layout, ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a depth component, but `initial_layout` \ specifies a layout for only the stencil component" .into(), @@ -2094,14 +2094,14 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-03290", ], ..Default::default() - }); + })); } if matches!( final_layout, ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a depth component, but `final_layout` \ specifies a layout for only the stencil component" .into(), @@ -2110,18 +2110,18 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-03291", ], ..Default::default() - }); + })); } if load_op == AttachmentLoadOp::Load && initial_layout == ImageLayout::Undefined { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a depth component, `load_op` is \ `AttachmentLoadOp::Load`, and `initial_layout` is \ `ImageLayout::Undefined`" .into(), vuids: &["VUID-VkAttachmentDescription2-format-06699"], ..Default::default() - }); + })); } } @@ -2129,7 +2129,7 @@ impl AttachmentDescription { if stencil_load_op.unwrap_or(load_op) == AttachmentLoadOp::Load && stencil_initial_layout.unwrap_or(initial_layout) == ImageLayout::Undefined { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a stencil component, `stencil_load_op` is \ `AttachmentLoadOp::Load`, and `stencil_initial_layout` is \ `ImageLayout::Undefined`" @@ -2139,7 +2139,7 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-pNext-06705", ], ..Default::default() - }); + })); } if stencil_initial_layout.is_none() && stencil_final_layout.is_none() { @@ -2147,7 +2147,7 @@ impl AttachmentDescription { initial_layout, ImageLayout::DepthAttachmentOptimal | ImageLayout::DepthReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a stencil component, `stencil_initial_layout` \ and `stencil_final_layout` are both `None`, and \ `initial_layout` does not specify a layout for the stencil aspect" @@ -2157,14 +2157,14 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-06247", ], ..Default::default() - }); + })); } if matches!( final_layout, ImageLayout::DepthAttachmentOptimal | ImageLayout::DepthReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`format` has a stencil component, `stencil_initial_layout` \ and `stencil_final_layout` are both `None`, and \ `final_layout` does not specify a layout for the stencil aspect" @@ -2174,7 +2174,7 @@ impl AttachmentDescription { "VUID-VkAttachmentDescription2-format-06248", ], ..Default::default() - }); + })); } } } @@ -2332,7 +2332,7 @@ impl Default for SubpassDescription { } impl SubpassDescription { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let properties = device.physical_device().properties(); let &Self { @@ -2358,13 +2358,13 @@ impl SubpassDescription { })?; if color_attachments.len() as u32 > properties.max_color_attachments { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "color_attachments".into(), problem: "the number of elements is greater than the `max_color_attachments` limit" .into(), vuids: &["VUID-VkSubpassDescription2-colorAttachmentCount-03063"], ..Default::default() - }); + })); } // Track the layout of each attachment used in this subpass @@ -2379,13 +2379,13 @@ impl SubpassDescription { if !color_resolve_attachments.is_empty() && color_resolve_attachments.len() != color_attachments.len() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`color_resolve_attachments` is not empty, but the length is not equal \ to the length of `color_attachments`" .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-parameter"], ..Default::default() - }); + })); } for (ref_index, color_attachment) in color_attachments.iter().enumerate() { @@ -2404,7 +2404,7 @@ impl SubpassDescription { } = color_attachment; if preserve_attachments.contains(&attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`color_attachments[{}].attachment` also occurs in \ `preserve_attachments`", @@ -2413,7 +2413,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-pPreserveAttachments-03074"], ..Default::default() - }); + })); } if matches!( @@ -2427,7 +2427,7 @@ impl SubpassDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_attachments[{}].layout", ref_index).into(), problem: "cannot be used with color attachments".into(), vuids: &[ @@ -2436,15 +2436,15 @@ impl SubpassDescription { "VUID-VkSubpassDescription2-attachment-06919", ], ..Default::default() - }); + })); } if stencil_layout.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_attachments[{}].stencil_layout", ref_index).into(), problem: "is `Some`".into(), ..Default::default() - }); + })); } let layouts_entry = Layouts { @@ -2455,14 +2455,14 @@ impl SubpassDescription { match layouts.entry(attachment) { Entry::Occupied(entry) => { if *entry.get() != layouts_entry { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_attachments[{}].layout", ref_index).into(), problem: "is not equal to the layout used for this attachment \ elsewhere in this subpass" .into(), vuids: &["VUID-VkSubpassDescription2-layout-02528"], ..Default::default() - }); + })); } } Entry::Vacant(entry) => { @@ -2471,12 +2471,12 @@ impl SubpassDescription { } if !aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_attachments[{}].aspects", ref_index).into(), problem: "is not empty for a color attachment".into(), // vuids? Not required by spec, but enforced by Vulkano for sanity. ..Default::default() - }); + })); } if let Some(color_resolve_attachment) = color_resolve_attachments @@ -2497,7 +2497,7 @@ impl SubpassDescription { } = color_resolve_attachment; if preserve_attachments.contains(&resolve_attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`color_resolve_attachments[{}].attachment` \ also occurs in `preserve_attachments`", @@ -2506,7 +2506,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-pPreserveAttachments-03074"], ..Default::default() - }); + })); } if matches!( @@ -2520,7 +2520,7 @@ impl SubpassDescription { | ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_resolve_attachments[{}].layout", ref_index) .into(), problem: "cannot be used with color resolve attachments".into(), @@ -2530,11 +2530,11 @@ impl SubpassDescription { "VUID-VkSubpassDescription2-attachment-06920", ], ..Default::default() - }); + })); } if resolve_stencil_layout.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "color_resolve_attachments[{}].stencil_layout", ref_index @@ -2542,7 +2542,7 @@ impl SubpassDescription { .into(), problem: "is `Some`".into(), ..Default::default() - }); + })); } let layouts_entry = Layouts { @@ -2553,7 +2553,7 @@ impl SubpassDescription { match layouts.entry(resolve_attachment) { Entry::Occupied(entry) => { if *entry.get() != layouts_entry { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!( "color_resolve_attachments[{}].layout", ref_index @@ -2564,7 +2564,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-layout-02528"], ..Default::default() - }); + })); } } Entry::Vacant(entry) => { @@ -2573,13 +2573,13 @@ impl SubpassDescription { } if !resolve_aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("color_resolve_attachments[{}].aspects", ref_index) .into(), problem: "is not empty for a color attachment".into(), // vuids? Not required by spec, but enforced by Vulkano for sanity. ..Default::default() - }); + })); } } } else if color_resolve_attachments @@ -2587,7 +2587,7 @@ impl SubpassDescription { .and_then(Option::as_ref) .is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`color_resolve_attachments[{}]` is `Some`, but \ `color_attachments[{0}]` is `None`", @@ -2596,7 +2596,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-pResolveAttachments-03065"], ..Default::default() - }); + })); } } @@ -2615,25 +2615,25 @@ impl SubpassDescription { } = depth_stencil_attachment; if preserve_attachments.contains(&attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_attachment.attachment` also occurs in \ `preserve_attachments`" .into(), vuids: &["VUID-VkSubpassDescription2-pPreserveAttachments-03074"], ..Default::default() - }); + })); } if matches!( layout, ImageLayout::ColorAttachmentOptimal | ImageLayout::ShaderReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_stencil_attachment.layout".into(), problem: "cannot be used with depth/stencil attachments`".into(), vuids: &["VUID-VkSubpassDescription2-attachment-06915"], ..Default::default() - }); + })); } if stencil_layout.is_some() { @@ -2641,7 +2641,7 @@ impl SubpassDescription { layout, ImageLayout::StencilAttachmentOptimal | ImageLayout::StencilReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_attachment.stencil_layout` is `Some`, but \ `depth_stencil_attachment.layout` is \ `ImageLayout::StencilAttachmentOptimal` or \ @@ -2649,7 +2649,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-attachment-06251"], ..Default::default() - }); + })); } } @@ -2661,14 +2661,14 @@ impl SubpassDescription { match layouts.entry(attachment) { Entry::Occupied(entry) => { if *entry.get() != layouts_entry { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_stencil_attachment.layout".into(), problem: "is not equal to the layout used for this attachment \ elsewhere in this subpass" .into(), vuids: &["VUID-VkSubpassDescription2-layout-02528"], ..Default::default() - }); + })); } } Entry::Vacant(entry) => { @@ -2677,12 +2677,12 @@ impl SubpassDescription { } if !aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_stencil_attachment.aspects".into(), problem: "is not empty for a depth/stencil attachment".into(), // vuids? Not required by spec, but enforced by Vulkano for sanity. ..Default::default() - }); + })); } if color_attachments @@ -2690,20 +2690,20 @@ impl SubpassDescription { .flatten() .any(|color_atch_ref| color_atch_ref.attachment == attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_attachment.attachment` also occurs in \ `color_attachments`" .into(), vuids: &["VUID-VkSubpassDescription2-pDepthStencilAttachment-04440"], ..Default::default() - }); + })); } if let Some(depth_stencil_resolve_attachment) = depth_stencil_resolve_attachment { if !(device.api_version() >= Version::V1_2 || device.enabled_extensions().khr_depth_stencil_resolve) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_stencil_resolve_attachment".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[ @@ -2714,7 +2714,7 @@ impl SubpassDescription { ]), // vuids? ..Default::default() - }); + })); } depth_stencil_resolve_attachment @@ -2730,13 +2730,13 @@ impl SubpassDescription { } = depth_stencil_resolve_attachment; if preserve_attachments.contains(&resolve_attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_resolve_attachment.attachment` also occurs in \ `preserve_attachments`" .into(), vuids: &["VUID-VkSubpassDescription2-pPreserveAttachments-03074"], ..Default::default() - }); + })); } let layouts_entry = Layouts { @@ -2747,14 +2747,14 @@ impl SubpassDescription { match layouts.entry(resolve_attachment) { Entry::Occupied(entry) => { if *entry.get() != layouts_entry { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_attachment.resolve.attachment_ref.layout".into(), problem: "is not equal to the layout used for this attachment \ elsewhere in this subpass" .into(), vuids: &["VUID-VkSubpassDescription2-layout-02528"], ..Default::default() - }); + })); } } Entry::Vacant(entry) => { @@ -2763,26 +2763,26 @@ impl SubpassDescription { } if !resolve_aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "depth_stencil_resolve_attachment.aspects".into(), problem: "is not empty for a depth/stencil attachment".into(), // vuids? Not required by spec, but enforced by Vulkano for sanity. ..Default::default() - }); + })); } match (depth_resolve_mode, stencil_resolve_mode) { (None, None) => { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_resolve_attachment` is `Some`, but \ `depth_resolve_mode` and `stencil_resolve_mode` are both `None`".into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03178"], ..Default::default() - }); + })); } (None, Some(_)) | (Some(_), None) => { if !properties.independent_resolve_none.unwrap_or(false) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_resolve_attachment` is `Some`, and \ the `independent_resolve_none` device property is \ `false`, but one of `depth_resolve_mode` and \ @@ -2790,14 +2790,14 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03186"], ..Default::default() - }); + })); } } (Some(depth_resolve_mode), Some(stencil_resolve_mode)) => { if depth_resolve_mode != stencil_resolve_mode && !properties.independent_resolve.unwrap_or(false) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_resolve_attachment` is `Some`, and \ `depth_resolve_mode` and `stencil_resolve_mode` are both \ `Some`, and the `independent_resolve` device property is \ @@ -2806,29 +2806,29 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03185"], ..Default::default() - }); + })); } } } } } else if depth_stencil_resolve_attachment.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_stencil_resolve_attachment` is `Some`, but \ `depth_stencil_attachment` is `None`" .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-pDepthStencilResolveAttachment-03177"], ..Default::default() - }); + })); } if let Some(depth_resolve_mode) = depth_resolve_mode { if depth_stencil_resolve_attachment.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_resolve_mode` is `Some`, but \ `depth_stencil_resolve_attachment` is `None`" .into(), ..Default::default() - }); + })); } depth_resolve_mode @@ -2844,24 +2844,24 @@ impl SubpassDescription { .unwrap_or_default() .contains_enum(depth_resolve_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`depth_resolve_mode` is not one of the modes in the \ `supported_depth_resolve_modes` device property" .into(), vuids: &["VUID-VkSubpassDescriptionDepthStencilResolve-depthResolveMode-03183"], ..Default::default() - }); + })); } } if let Some(stencil_resolve_mode) = stencil_resolve_mode { if depth_stencil_resolve_attachment.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`stencil_resolve_mode` is `Some`, but \ `depth_stencil_resolve_attachment` is `None`" .into(), ..Default::default() - }); + })); } stencil_resolve_mode @@ -2877,7 +2877,7 @@ impl SubpassDescription { .unwrap_or_default() .contains_enum(stencil_resolve_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "stencil_resolve_mode` is not one of the modes in the \ `supported_stencil_resolve_modes` device property" .into(), @@ -2885,7 +2885,7 @@ impl SubpassDescription { "VUID-VkSubpassDescriptionDepthStencilResolve-stencilResolveMode-03184", ], ..Default::default() - }); + })); } } @@ -2908,7 +2908,7 @@ impl SubpassDescription { } = input_attachment; if preserve_attachments.contains(&attachment) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`input_attachments[{}].attachment` also occurs in \ `preserve_attachments`", @@ -2917,7 +2917,7 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-pPreserveAttachments-03074"], ..Default::default() - }); + })); } if matches!( @@ -2927,7 +2927,7 @@ impl SubpassDescription { | ImageLayout::DepthAttachmentOptimal | ImageLayout::StencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("input_attachments[{}].layout", ref_index).into(), problem: "cannot be used with input attachments".into(), vuids: &[ @@ -2935,7 +2935,7 @@ impl SubpassDescription { "VUID-VkSubpassDescription2-attachment-06918", ], ..Default::default() - }); + })); } let layouts_entry = Layouts { @@ -2946,14 +2946,14 @@ impl SubpassDescription { match layouts.entry(attachment) { Entry::Occupied(entry) => { if *entry.get() != layouts_entry { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("input_attachments[{}].layout", ref_index).into(), problem: "is not equal to the layout used for this attachment \ elsewhere in this subpass" .into(), vuids: &["VUID-VkSubpassDescription2-layout-02528"], ..Default::default() - }); + })); } } Entry::Vacant(entry) => { @@ -2962,30 +2962,30 @@ impl SubpassDescription { } if aspects.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("input_attachments[{}].aspects", ref_index).into(), problem: "is empty for an input attachment".into(), vuids: &["VUID-VkSubpassDescription2-attachment-02800"], ..Default::default() - }); + })); } if aspects.intersects(ImageAspects::METADATA) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("input_attachments[{}].aspects", ref_index).into(), problem: "contains `ImageAspects::METADATA`".into(), vuids: &["VUID-VkSubpassDescription2-attachment-02801"], ..Default::default() - }); + })); } if aspects.intersects( ImageAspects::MEMORY_PLANE_0 | ImageAspects::MEMORY_PLANE_1 | ImageAspects::MEMORY_PLANE_2 - | ImageAspects::MEMORY_PLANE_3 + | ImageAspects::MEMORY_PLANE_3, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("input_attachments[{}].aspects", ref_index).into(), problem: "contains `ImageAspects::MEMORY_PLANE_0`, \ `ImageAspects::MEMORY_PLANE_1`, `ImageAspects::MEMORY_PLANE_2` or \ @@ -2993,30 +2993,30 @@ impl SubpassDescription { .into(), vuids: &["VUID-VkSubpassDescription2-attachment-04563"], ..Default::default() - }); + })); } } if !device.enabled_features().multiview && view_mask != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "view_mask".into(), problem: "is not 0".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature("multiview")])]), vuids: &["VUID-VkSubpassDescription2-multiview-06558"], - }); + })); } let highest_view_index = u32::BITS - view_mask.leading_zeros(); if highest_view_index >= properties.max_multiview_view_count.unwrap_or(0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "view_mask".into(), problem: "the highest enabled view index is not less than the \ `max_multiview_view_count` limit" .into(), vuids: &["VUID-VkSubpassDescription2-viewMask-06706"], ..Default::default() - }); + })); } Ok(()) @@ -3141,7 +3141,7 @@ impl Default for AttachmentReference { } impl AttachmentReference { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { attachment: _, layout, @@ -3162,14 +3162,14 @@ impl AttachmentReference { layout, ImageLayout::Undefined | ImageLayout::Preinitialized | ImageLayout::PresentSrc ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "layout".into(), problem: "is `ImageLayout::Undefined`, `ImageLayout::Preinitialized` or \ `ImageLayout::PresentSrc`" .into(), vuids: &["VUID-VkAttachmentReference2-layout-03077"], ..Default::default() - }); + })); } if matches!( @@ -3180,7 +3180,7 @@ impl AttachmentReference { | ImageLayout::StencilReadOnlyOptimal ) && !device.enabled_features().separate_depth_stencil_layouts { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "layout".into(), problem: "specifies a layout for only the depth aspect or only the stencil aspect" .into(), @@ -3188,19 +3188,19 @@ impl AttachmentReference { "separate_depth_stencil_layouts", )])]), vuids: &["VUID-VkAttachmentReference2-separateDepthStencilLayouts-03313"], - }); + })); } if let Some(stencil_layout) = stencil_layout { if !device.enabled_features().separate_depth_stencil_layouts { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_layout".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "separate_depth_stencil_layouts", )])]), ..Default::default() - }); + })); } stencil_layout @@ -3215,14 +3215,14 @@ impl AttachmentReference { stencil_layout, ImageLayout::Undefined | ImageLayout::Preinitialized | ImageLayout::PresentSrc ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_layout".into(), problem: "is `ImageLayout::Undefined`, `ImageLayout::Preinitialized` or \ `ImageLayout::PresentSrc`" .into(), vuids: &["VUID-VkAttachmentReferenceStencilLayout-stencilLayout-03318"], ..Default::default() - }); + })); } if matches!( @@ -3231,12 +3231,12 @@ impl AttachmentReference { | ImageLayout::DepthAttachmentOptimal | ImageLayout::DepthReadOnlyOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_layout".into(), problem: "does not specify a layout for the stencil aspect".into(), vuids: &["VUID-VkAttachmentReferenceStencilLayout-stencilLayout-03318"], ..Default::default() - }); + })); } if matches!( @@ -3246,12 +3246,12 @@ impl AttachmentReference { | ImageLayout::DepthAttachmentStencilReadOnlyOptimal | ImageLayout::DepthReadOnlyStencilAttachmentOptimal ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "stencil_layout".into(), problem: "specifies a layout for both the depth and the stencil aspect".into(), vuids: &["VUID-VkAttachmentReferenceStencilLayout-stencilLayout-03318"], ..Default::default() - }); + })); } } @@ -3375,7 +3375,7 @@ impl Default for SubpassDependency { } impl SubpassDependency { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { src_subpass, dst_subpass, @@ -3405,7 +3405,7 @@ impl SubpassDependency { || device.enabled_extensions().khr_create_renderpass2) { if src_stages.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains flags from `VkPipelineStageFlagBits2`".into(), requires_one_of: RequiresOneOf(&[ @@ -3413,11 +3413,11 @@ impl SubpassDependency { RequiresAllOf(&[Requires::DeviceExtension("khr_create_renderpass2")]), ]), ..Default::default() - }); + })); } if dst_stages.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains flags from `VkPipelineStageFlagBits2`".into(), requires_one_of: RequiresOneOf(&[ @@ -3425,11 +3425,11 @@ impl SubpassDependency { RequiresAllOf(&[Requires::DeviceExtension("khr_create_renderpass2")]), ]), ..Default::default() - }); + })); } if src_access.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_access".into(), problem: "contains flags from `VkAccessFlagBits2`".into(), requires_one_of: RequiresOneOf(&[ @@ -3437,11 +3437,11 @@ impl SubpassDependency { RequiresAllOf(&[Requires::DeviceExtension("khr_create_renderpass2")]), ]), ..Default::default() - }); + })); } if dst_access.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_access".into(), problem: "contains flags from `VkAccessFlagBits2`".into(), requires_one_of: RequiresOneOf(&[ @@ -3449,49 +3449,49 @@ impl SubpassDependency { RequiresAllOf(&[Requires::DeviceExtension("khr_create_renderpass2")]), ]), ..Default::default() - }); + })); } } if !device.enabled_features().synchronization2 { if src_stages.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "is empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), vuids: &["VUID-VkSubpassDependency2-srcStageMask-03937"], - }); + })); } if dst_stages.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "is empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), vuids: &["VUID-VkSubpassDependency2-dstStageMask-03937"], - }); + })); } } if src_subpass.is_none() && dst_subpass.is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_subpass` and `dst_subpass` are both `None`".into(), vuids: &["VUID-VkSubpassDependency2-srcSubpass-03085"], ..Default::default() - }); + })); } if let (Some(src_subpass), Some(dst_subpass)) = (src_subpass, dst_subpass) { if src_subpass > dst_subpass { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_subpass` is greater than `dst_subpass`".into(), vuids: &["VUID-VkSubpassDependency2-srcSubpass-03084"], ..Default::default() - }); + })); } if src_subpass == dst_subpass { @@ -3503,70 +3503,70 @@ impl SubpassDependency { if src_stages.intersects(framebuffer_stages) && !(dst_stages - framebuffer_stages).is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_subpass` equals `dst_subpass`, and `src_stages` includes \ a framebuffer-space stage, and `dst_stages` does not contain only \ framebuffer-space stages" .into(), vuids: &["VUID-VkSubpassDependency2-srcSubpass-06810"], ..Default::default() - }); + })); } if src_stages.intersects(framebuffer_stages) && dst_stages.intersects(framebuffer_stages) && !dependency_flags.intersects(DependencyFlags::BY_REGION) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_subpass` equals `dst_subpass`, and \ `src_stages` and `dst_stages` both include a framebuffer-space stage, \ and `dependency_flags` does not include `DependencyFlags::BY_REGION`" .into(), vuids: &["VUID-VkSubpassDependency2-srcSubpass-02245"], ..Default::default() - }); + })); } if view_offset != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_subpass` equals `dst_subpass`, and `view_offset` is 0" .into(), vuids: &["VUID-VkSubpassDependency2-viewOffset-02530"], ..Default::default() - }); + })); } } } if dependency_flags.intersects(DependencyFlags::VIEW_LOCAL) { if src_subpass.is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dependency_flags` includes `DependencyFlags::VIEW_LOCAL`, and \ `src_subpass` is `None`" .into(), vuids: &["VUID-VkSubpassDependency2-dependencyFlags-03090"], ..Default::default() - }); + })); } if dst_subpass.is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dependency_flags` includes `DependencyFlags::VIEW_LOCAL`, and \ `dst_subpass` is `None`" .into(), vuids: &["VUID-VkSubpassDependency2-dependencyFlags-03091"], ..Default::default() - }); + })); } } else { if view_offset != 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dependency_flags` does not include `DependencyFlags::VIEW_LOCAL`, \ and `view_offset` is not 0" .into(), vuids: &["VUID-VkSubpassDependency2-dependencyFlags-03092"], ..Default::default() - }); + })); } } diff --git a/vulkano/src/shader/mod.rs b/vulkano/src/shader/mod.rs index 47fd280f..196d0264 100644 --- a/vulkano/src/shader/mod.rs +++ b/vulkano/src/shader/mod.rs @@ -141,7 +141,7 @@ use crate::{ pipeline::{graphics::input_assembly::PrimitiveTopology, layout::PushConstantRange}, shader::spirv::{Capability, Spirv, SpirvError}, sync::PipelineStages, - OomError, RuntimeError, Version, VulkanObject, + OomError, Version, VulkanError, VulkanObject, }; use ahash::{HashMap, HashSet}; use std::{ @@ -277,7 +277,7 @@ impl ShaderModule { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1283,8 +1283,8 @@ impl Display for ShaderModuleCreationError { } } -impl From for ShaderModuleCreationError { - fn from(err: RuntimeError) -> Self { +impl From for ShaderModuleCreationError { + fn from(err: VulkanError) -> Self { Self::OomError(err.into()) } } diff --git a/vulkano/src/swapchain/acquire_present.rs b/vulkano/src/swapchain/acquire_present.rs index 285e0906..a2870ca7 100644 --- a/vulkano/src/swapchain/acquire_present.rs +++ b/vulkano/src/swapchain/acquire_present.rs @@ -17,7 +17,7 @@ use crate::{ future::{AccessCheckError, AccessError, FlushError, GpuFuture, SubmitAnyBuilder}, semaphore::{Semaphore, SemaphoreError}, }, - DeviceSize, OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, + DeviceSize, OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, VulkanError, VulkanObject, }; use smallvec::smallvec; @@ -132,7 +132,7 @@ pub unsafe fn acquire_next_image_raw( ash::vk::Result::SUBOPTIMAL_KHR => true, ash::vk::Result::NOT_READY => return Err(AcquireError::Timeout), ash::vk::Result::TIMEOUT => return Err(AcquireError::Timeout), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), }; if let Some(semaphore) = semaphore { @@ -386,15 +386,15 @@ impl From for AcquireError { } } -impl From for AcquireError { - fn from(err: RuntimeError) -> AcquireError { +impl From for AcquireError { + fn from(err: VulkanError) -> AcquireError { match err { - err @ RuntimeError::OutOfHostMemory => AcquireError::OomError(OomError::from(err)), - err @ RuntimeError::OutOfDeviceMemory => AcquireError::OomError(OomError::from(err)), - RuntimeError::DeviceLost => AcquireError::DeviceLost, - RuntimeError::SurfaceLost => AcquireError::SurfaceLost, - RuntimeError::OutOfDate => AcquireError::OutOfDate, - RuntimeError::FullScreenExclusiveModeLost => AcquireError::FullScreenExclusiveModeLost, + err @ VulkanError::OutOfHostMemory => AcquireError::OomError(OomError::from(err)), + err @ VulkanError::OutOfDeviceMemory => AcquireError::OomError(OomError::from(err)), + VulkanError::DeviceLost => AcquireError::DeviceLost, + VulkanError::SurfaceLost => AcquireError::SurfaceLost, + VulkanError::OutOfDate => AcquireError::OutOfDate, + VulkanError::FullScreenExclusiveModeLost => AcquireError::FullScreenExclusiveModeLost, _ => panic!("unexpected error: {:?}", err), } } @@ -918,7 +918,7 @@ pub fn wait_for_present( ash::vk::Result::SUBOPTIMAL_KHR => Ok(true), ash::vk::Result::TIMEOUT => Err(PresentWaitError::Timeout), err => { - let err = RuntimeError::from(err).into(); + let err = VulkanError::from(err).into(); if let PresentWaitError::FullScreenExclusiveModeLost = &err { swapchain @@ -1012,15 +1012,15 @@ impl From for PresentWaitError { } } -impl From for PresentWaitError { - fn from(err: RuntimeError) -> PresentWaitError { +impl From for PresentWaitError { + fn from(err: VulkanError) -> PresentWaitError { match err { - err @ RuntimeError::OutOfHostMemory => Self::OomError(OomError::from(err)), - err @ RuntimeError::OutOfDeviceMemory => Self::OomError(OomError::from(err)), - RuntimeError::DeviceLost => Self::DeviceLost, - RuntimeError::SurfaceLost => Self::SurfaceLost, - RuntimeError::OutOfDate => Self::OutOfDate, - RuntimeError::FullScreenExclusiveModeLost => Self::FullScreenExclusiveModeLost, + err @ VulkanError::OutOfHostMemory => Self::OomError(OomError::from(err)), + err @ VulkanError::OutOfDeviceMemory => Self::OomError(OomError::from(err)), + VulkanError::DeviceLost => Self::DeviceLost, + VulkanError::SurfaceLost => Self::SurfaceLost, + VulkanError::OutOfDate => Self::OutOfDate, + VulkanError::FullScreenExclusiveModeLost => Self::FullScreenExclusiveModeLost, _ => panic!("unexpected error: {:?}", err), } } diff --git a/vulkano/src/swapchain/display.rs b/vulkano/src/swapchain/display.rs index 1ba93551..09517bde 100644 --- a/vulkano/src/swapchain/display.rs +++ b/vulkano/src/swapchain/display.rs @@ -29,7 +29,7 @@ #![allow(unused_variables)] // TODO: this module isn't finished use crate::{ - device::physical::PhysicalDevice, swapchain::SurfaceTransforms, OomError, RuntimeError, + device::physical::PhysicalDevice, swapchain::SurfaceTransforms, OomError, VulkanError, VulkanObject, }; use std::{ @@ -71,7 +71,7 @@ impl DisplayPlane { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut properties = Vec::with_capacity(count as usize); let result = (fns @@ -88,7 +88,7 @@ impl DisplayPlane { break properties; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } } }; @@ -107,7 +107,7 @@ impl DisplayPlane { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from) + .map_err(VulkanError::from) .unwrap(); // TODO: shouldn't unwrap let mut displays = Vec::with_capacity(count as usize); @@ -202,7 +202,7 @@ impl Display { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut properties = Vec::with_capacity(count as usize); let result = (fns.khr_display.get_physical_device_display_properties_khr)( @@ -217,7 +217,7 @@ impl Display { break properties; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } } }; @@ -308,7 +308,7 @@ impl Display { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut properties = Vec::with_capacity(count as usize); let result = (fns.khr_display.get_display_mode_properties_khr)( @@ -324,7 +324,7 @@ impl Display { break properties; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } } }; @@ -390,7 +390,7 @@ impl DisplayMode { let mut output = mem::uninitialized(); (fns.v1_0.CreateDisplayModeKHR)(display.device.handle(), display.display, &infos, ptr::null(), - &mut output).result().map_err(RuntimeError::from)?; + &mut output).result().map_err(VulkanError::from)?; output }; diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index 28d3ec02..d4741bd3 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -336,7 +336,7 @@ use crate::{ instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum, vulkan_enum}, sync::Sharing, - OomError, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, VulkanError, + OomError, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, VulkanError, VulkanObject, }; use parking_lot::Mutex; @@ -420,7 +420,7 @@ impl Swapchain { device: Arc, surface: Arc, create_info: SwapchainCreateInfo, - ) -> Result<(Arc, Vec>), VulkanError> { + ) -> Result<(Arc, Vec>), Validated> { Self::validate_new_inner(&device, &surface, &create_info)?; unsafe { Ok(Self::new_unchecked(device, surface, create_info)?) } @@ -432,7 +432,7 @@ impl Swapchain { device: Arc, surface: Arc, create_info: SwapchainCreateInfo, - ) -> Result<(Arc, Vec>), RuntimeError> { + ) -> Result<(Arc, Vec>), VulkanError> { let (handle, image_handles) = Self::new_inner_unchecked(&device, &surface, &create_info, None)?; @@ -449,7 +449,7 @@ impl Swapchain { pub fn recreate( self: &Arc, create_info: SwapchainCreateInfo, - ) -> Result<(Arc, Vec>), VulkanError> { + ) -> Result<(Arc, Vec>), Validated> { Self::validate_new_inner(&self.device, &self.surface, &create_info)?; { @@ -457,12 +457,12 @@ impl Swapchain { // The swapchain has already been used to create a new one. if *is_retired { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "self".into(), problem: "has already been used to recreate a swapchain".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-oldSwapchain-01933"], ..Default::default() - } + }) .into()); } else { // According to the documentation of VkSwapchainCreateInfoKHR: @@ -483,7 +483,7 @@ impl Swapchain { pub unsafe fn recreate_unchecked( self: &Arc, create_info: SwapchainCreateInfo, - ) -> Result<(Arc, Vec>), RuntimeError> { + ) -> Result<(Arc, Vec>), VulkanError> { // According to the documentation of VkSwapchainCreateInfoKHR: // // > Upon calling vkCreateSwapchainKHR with a oldSwapchain that is not VK_NULL_HANDLE, @@ -520,14 +520,14 @@ impl Swapchain { device: &Device, surface: &Surface, create_info: &SwapchainCreateInfo, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !device.enabled_extensions().khr_swapchain { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "khr_swapchain", )])]), ..Default::default() - }); + })); } create_info @@ -568,12 +568,12 @@ impl Swapchain { .unwrap_or_default() }) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "surface".into(), problem: "is not supported by the physical device".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-surface-01270"], ..Default::default() - }); + })); } let surface_capabilities = unsafe { @@ -630,23 +630,23 @@ impl Swapchain { .max_image_count .map_or(false, |c| min_image_count > c) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.min_image_count` is greater than the `max_image_count` \ value of the capabilities of `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-minImageCount-01272"], ..Default::default() - }); + })); } if min_image_count < surface_capabilities.min_image_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.min_image_count` is less than the `min_image_count` \ value of the capabilities of `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-presentMode-02839"], ..Default::default() - }); + })); } if let Some(image_format) = image_format { @@ -654,24 +654,24 @@ impl Swapchain { .iter() .any(|&fc| fc == (image_format, image_color_space)) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the combination of `create_info.image_format` and \ `create_info.image_color_space` is not supported for `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageFormat-01273"], ..Default::default() - }); + })); } } if image_array_layers > surface_capabilities.max_image_array_layers { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.image_array_layers` is greater than the \ `max_image_array_layers` value of the capabilities of `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageArrayLayers-01275"], ..Default::default() - }); + })); } if matches!( @@ -684,7 +684,7 @@ impl Swapchain { .supported_usage_flags .contains(image_usage) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.present_mode` is `PresentMode::Immediate`, \ `PresentMode::Mailbox`, `PresentMode::Fifo` or `PresentMode::FifoRelaxed`, \ and `create_info.image_usage` contains flags that are not set in \ @@ -692,41 +692,41 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-presentMode-01427"], ..Default::default() - }); + })); } if !surface_capabilities .supported_transforms .contains_enum(pre_transform) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.pre_transform` is not present in the \ `supported_transforms` value of the capabilities of `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-preTransform-01279"], ..Default::default() - }); + })); } if !surface_capabilities .supported_composite_alpha .contains_enum(composite_alpha) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.composite_alpha` is not present in the \ `supported_composite_alpha` value of the capabilities of `surface`" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280"], ..Default::default() - }); + })); } if !surface_present_modes.contains(&present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.present_mode` is not supported for `surface`".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-presentMode-01281"], ..Default::default() - }); + })); } if present_modes.is_empty() { @@ -735,7 +735,7 @@ impl Swapchain { .supported_present_scaling .contains_enum(scaling_behavior) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`create_info.scaling_behavior` is not present in the \ `supported_present_scaling` value of the \ capabilities of `surface`" @@ -744,7 +744,7 @@ impl Swapchain { "VUID-VkSwapchainPresentScalingCreateInfoEXT-scalingBehavior-07770", ], ..Default::default() - }); + })); } } @@ -755,7 +755,7 @@ impl Swapchain { .enumerate() { if !supported_present_gravity.contains_enum(present_gravity) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`create_info.present_gravity[{0}]` is not present in the \ `supported_present_gravity[{0}]` value of the \ @@ -768,14 +768,14 @@ impl Swapchain { "VUID-VkSwapchainPresentScalingCreateInfoEXT-presentGravityY-07774", ], ..Default::default() - }); + })); } } } } else { for (index, &present_mode) in present_modes.iter().enumerate() { if !surface_present_modes.contains(&present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`create_info.present_modes[{}]` is not supported for `surface`", index, @@ -783,14 +783,14 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainPresentModesCreateInfoEXT-None-07762"], ..Default::default() - }); + })); } if !surface_capabilities .compatible_present_modes .contains(&present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`create_info.present_modes[{}]` is not present in the \ `compatible_present_modes` value of the \ @@ -800,7 +800,7 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainPresentModesCreateInfoEXT-pPresentModes-07763"], ..Default::default() - }); + })); } if scaling_behavior.is_some() || present_gravity.is_some() { @@ -828,7 +828,7 @@ impl Swapchain { .supported_present_scaling .contains_enum(scaling_behavior) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`create_info.scaling_behavior` is not present in the \ `supported_present_scaling` value of the \ @@ -841,7 +841,7 @@ impl Swapchain { "VUID-VkSwapchainPresentScalingCreateInfoEXT-scalingBehavior-07771", ], ..Default::default() - }); + })); } } @@ -853,7 +853,7 @@ impl Swapchain { .enumerate() { if !supported_present_gravity.contains_enum(present_gravity) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: format!( "`create_info.present_gravity[{0}]` is not present in the \ `supported_present_gravity[{0}]` value of the \ @@ -867,7 +867,7 @@ impl Swapchain { "VUID-VkSwapchainPresentScalingCreateInfoEXT-presentGravityY-07775", ], ..Default::default() - }); + })); } } } @@ -880,7 +880,7 @@ impl Swapchain { if image_extent[0] < min_scaled_image_extent[0] || image_extent[1] < min_scaled_image_extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`scaling_behavior` is `Some`, and an element of \ `create_info.image_extent` is less than the corresponding element \ of the `min_scaled_image_extent` value of the \ @@ -888,7 +888,7 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-pNext-07782"], ..Default::default() - }); + })); } } @@ -896,7 +896,7 @@ impl Swapchain { if image_extent[0] > max_scaled_image_extent[0] || image_extent[1] > max_scaled_image_extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`scaling_behavior` is `Some`, and an element of \ `create_info.image_extent` is greater than the corresponding element \ of the `max_scaled_image_extent` value of the \ @@ -904,7 +904,7 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-pNext-07782"], ..Default::default() - }); + })); } } } else { @@ -919,7 +919,7 @@ impl Swapchain { if image_extent[0] < surface_capabilities.min_image_extent[0] || image_extent[1] < surface_capabilities.min_image_extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`scaling_behavior` is `Some`, and an element of \ `create_info.image_extent` is less than the corresponding element \ of the `min_image_extent` value of the \ @@ -927,13 +927,13 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-pNext-07781"], ..Default::default() - }); + })); } if image_extent[0] > surface_capabilities.max_image_extent[0] || image_extent[1] > surface_capabilities.max_image_extent[1] { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`scaling_behavior` is `Some`, and an element of \ `create_info.image_extent` is greater than the corresponding element \ of the `max_image_extent` value of the \ @@ -941,7 +941,7 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-pNext-07781"], ..Default::default() - }); + })); } */ } @@ -950,7 +950,7 @@ impl Swapchain { && full_screen_exclusive == FullScreenExclusive::ApplicationControlled { if win32_monitor.is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is a Win32 surface, and \ `create_info.full_screen_exclusive` is \ `FullScreenExclusive::ApplicationControlled`, but \ @@ -958,18 +958,18 @@ impl Swapchain { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-pNext-02679"], ..Default::default() - }); + })); } } else { if win32_monitor.is_some() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`surface` is not a Win32 surface, or \ `create_info.full_screen_exclusive` is not \ `FullScreenExclusive::ApplicationControlled`, but \ `create_info.win32_monitor` is `Some`" .into(), ..Default::default() - }); + })); } } @@ -981,7 +981,7 @@ impl Swapchain { surface: &Surface, create_info: &SwapchainCreateInfo, old_swapchain: Option<&Swapchain>, - ) -> Result<(ash::vk::SwapchainKHR, Vec), RuntimeError> { + ) -> Result<(ash::vk::SwapchainKHR, Vec), VulkanError> { let &SwapchainCreateInfo { flags, min_image_count, @@ -1103,7 +1103,7 @@ impl Swapchain { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1116,7 +1116,7 @@ impl Swapchain { ptr::null_mut(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; let mut images = Vec::with_capacity(count as usize); let result = (fns.khr_swapchain.get_swapchain_images_khr)( @@ -1132,7 +1132,7 @@ impl Swapchain { break images; } ash::vk::Result::INCOMPLETE => (), - err => return Err(RuntimeError::from(err)), + err => return Err(VulkanError::from(err)), } }; @@ -1154,7 +1154,7 @@ impl Swapchain { image_handles: impl IntoIterator, surface: Arc, create_info: SwapchainCreateInfo, - ) -> Result<(Arc, Vec>), RuntimeError> { + ) -> Result<(Arc, Vec>), VulkanError> { let SwapchainCreateInfo { flags, min_image_count, @@ -1223,7 +1223,7 @@ impl Swapchain { image_index as u32, )?)) }) - .collect::>()?; + .collect::>()?; Ok((swapchain, swapchain_images)) } @@ -1398,7 +1398,7 @@ impl Swapchain { self.device.handle(), self.handle ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Ok(()) @@ -1428,7 +1428,7 @@ impl Swapchain { self.device.handle(), self.handle ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Ok(()) @@ -1662,7 +1662,7 @@ impl Default for SwapchainCreateInfo { } impl SwapchainCreateInfo { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { flags, min_image_count: _, @@ -1724,12 +1724,12 @@ impl SwapchainCreateInfo { })?; if image_usage.is_empty() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "image_usage".into(), problem: "is empty".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageUsage-requiredbitmask"], ..Default::default() - }); + })); } pre_transform @@ -1757,35 +1757,35 @@ impl SwapchainCreateInfo { })?; if image_extent.contains(&0) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "image_extent".into(), problem: "one or more elements are zero".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageExtent-01689"], ..Default::default() - }); + })); } if image_array_layers == 0 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "image_array_layers".into(), problem: "is zero".into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageArrayLayers-01275"], ..Default::default() - }); + })); } match image_sharing { Sharing::Exclusive => (), Sharing::Concurrent(queue_family_indices) => { if queue_family_indices.len() < 2 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "image_sharing".into(), problem: "is `Sharing::Concurrent`, and contains less than 2 \ queue family indices" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01278"], ..Default::default() - }); + })); } let queue_family_count = @@ -1793,7 +1793,7 @@ impl SwapchainCreateInfo { for (index, &queue_family_index) in queue_family_indices.iter().enumerate() { if queue_family_indices[..index].contains(&queue_family_index) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "queue_family_indices".into(), problem: format!( "the queue family index in the list at index {} is contained in \ @@ -1803,18 +1803,18 @@ impl SwapchainCreateInfo { .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01428"], ..Default::default() - }); + })); } if queue_family_index >= queue_family_count { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: format!("queue_family_indices[{}]", index).into(), problem: "is not less than the number of queue families in the \ physical device" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageSharingMode-01428"], ..Default::default() - }); + })); } } } @@ -1838,25 +1838,25 @@ impl SwapchainCreateInfo { }; if image_format_properties.is_none() { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "the combination of `image_format` and `image_usage` is not supported \ for images by the physical device" .into(), vuids: &["VUID-VkSwapchainCreateInfoKHR-imageFormat-01778"], ..Default::default() - }); + })); } if !present_modes.is_empty() { if !device.enabled_extensions().ext_swapchain_maintenance1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "present_modes".into(), problem: "is not empty".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_swapchain_maintenance1", )])]), ..Default::default() - }); + })); } for (index, &present_mode) in present_modes.iter().enumerate() { @@ -1872,25 +1872,25 @@ impl SwapchainCreateInfo { } if !present_modes.contains(&present_mode) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`present_modes` is not empty, but does not contain `present_mode`" .into(), vuids: &["VUID-VkSwapchainPresentModesCreateInfoEXT-presentMode-07764"], ..Default::default() - }); + })); } } if let Some(scaling_behavior) = scaling_behavior { if !device.enabled_extensions().ext_swapchain_maintenance1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "scaling_behavior".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_swapchain_maintenance1", )])]), ..Default::default() - }); + })); } scaling_behavior @@ -1909,14 +1909,14 @@ impl SwapchainCreateInfo { if let Some(present_gravity) = present_gravity { if !device.enabled_extensions().ext_swapchain_maintenance1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "present_gravity".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_swapchain_maintenance1", )])]), ..Default::default() - }); + })); } for (axis_index, present_gravity) in present_gravity.into_iter().enumerate() { @@ -1943,14 +1943,14 @@ impl SwapchainCreateInfo { if full_screen_exclusive != FullScreenExclusive::Default { if !device.enabled_extensions().ext_full_screen_exclusive { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "full_screen_exclusive".into(), problem: "is not `FullScreenExclusive::Default`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_full_screen_exclusive", )])]), ..Default::default() - }); + })); } full_screen_exclusive @@ -2145,17 +2145,17 @@ impl Display for FullScreenExclusiveError { } } -impl From for FullScreenExclusiveError { - fn from(err: RuntimeError) -> FullScreenExclusiveError { +impl From for FullScreenExclusiveError { + fn from(err: VulkanError) -> FullScreenExclusiveError { match err { - err @ RuntimeError::OutOfHostMemory => { + err @ VulkanError::OutOfHostMemory => { FullScreenExclusiveError::OomError(OomError::from(err)) } - err @ RuntimeError::OutOfDeviceMemory => { + err @ VulkanError::OutOfDeviceMemory => { FullScreenExclusiveError::OomError(OomError::from(err)) } - RuntimeError::SurfaceLost => FullScreenExclusiveError::SurfaceLost, - RuntimeError::InitializationFailed => FullScreenExclusiveError::InitializationFailed, + VulkanError::SurfaceLost => FullScreenExclusiveError::SurfaceLost, + VulkanError::InitializationFailed => FullScreenExclusiveError::InitializationFailed, _ => panic!("unexpected error: {:?}", err), } } diff --git a/vulkano/src/swapchain/surface.rs b/vulkano/src/swapchain/surface.rs index fe1cfb17..338b56e1 100644 --- a/vulkano/src/swapchain/surface.rs +++ b/vulkano/src/swapchain/surface.rs @@ -16,8 +16,8 @@ use crate::{ instance::{Instance, InstanceExtensions, InstanceOwned}, macros::{impl_id_counter, vulkan_bitflags_enum, vulkan_enum}, swapchain::display::{DisplayMode, DisplayPlane}, - DebugWrapper, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, ValidationError, - VulkanError, VulkanObject, + DebugWrapper, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, VulkanError, + VulkanObject, }; #[cfg(any(target_os = "macos", target_os = "ios"))] use objc::{class, msg_send, runtime::Object, sel, sel_impl}; @@ -83,7 +83,7 @@ impl Surface { pub fn from_window( instance: Arc, window: Arc, - ) -> Result, VulkanError> { + ) -> Result, Validated> { let mut surface = unsafe { Self::from_window_ref(instance, &*window) }?; Arc::get_mut(&mut surface).unwrap().object = Some(window); @@ -99,7 +99,7 @@ impl Surface { pub unsafe fn from_window_ref( instance: Arc, window: &(impl HasRawWindowHandle + HasRawDisplayHandle), - ) -> Result, VulkanError> { + ) -> Result, Validated> { match (window.raw_window_handle(), window.raw_display_handle()) { (RawWindowHandle::AndroidNdk(window), RawDisplayHandle::Android(_display)) => { Self::from_android(instance, window.a_native_window, None) @@ -169,20 +169,20 @@ impl Surface { pub fn headless( instance: Arc, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_headless(&instance)?; unsafe { Ok(Self::headless_unchecked(instance, object)?) } } - fn validate_headless(instance: &Instance) -> Result<(), ValidationError> { + fn validate_headless(instance: &Instance) -> Result<(), Box> { if !instance.enabled_extensions().ext_headless_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_headless_surface", )])]), ..Default::default() - }); + })); } Ok(()) @@ -192,7 +192,7 @@ impl Surface { pub unsafe fn headless_unchecked( instance: Arc, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::HeadlessSurfaceCreateInfoEXT { flags: ash::vk::HeadlessSurfaceCreateFlagsEXT::empty(), ..Default::default() @@ -208,7 +208,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -229,7 +229,7 @@ impl Surface { pub fn from_display_plane( display_mode: &DisplayMode, plane: &DisplayPlane, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_display_plane(display_mode, plane)?; unsafe { Ok(Self::from_display_plane_unchecked(display_mode, plane)?) } @@ -238,7 +238,7 @@ impl Surface { fn validate_from_display_plane( display_mode: &DisplayMode, plane: &DisplayPlane, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !display_mode .display() .physical_device() @@ -246,12 +246,12 @@ impl Surface { .enabled_extensions() .khr_display { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_display", )])]), ..Default::default() - }); + })); } assert_eq!( @@ -267,7 +267,7 @@ impl Surface { pub unsafe fn from_display_plane_unchecked( display_mode: &DisplayMode, plane: &DisplayPlane, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let instance = display_mode.display().physical_device().instance(); let create_info = ash::vk::DisplaySurfaceCreateInfoKHR { @@ -296,7 +296,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -319,7 +319,7 @@ impl Surface { instance: Arc, window: *const W, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_android(&instance, window)?; Ok(Self::from_android_unchecked(instance, window, object)?) @@ -328,14 +328,14 @@ impl Surface { fn validate_from_android( instance: &Instance, _window: *const W, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().khr_android_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_android_surface", )])]), ..Default::default() - }); + })); } // VUID-VkAndroidSurfaceCreateInfoKHR-window-01248 @@ -349,7 +349,7 @@ impl Surface { instance: Arc, window: *const W, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::AndroidSurfaceCreateInfoKHR { flags: ash::vk::AndroidSurfaceCreateFlagsKHR::empty(), window: window as *mut _, @@ -366,7 +366,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -391,7 +391,7 @@ impl Surface { dfb: *const D, surface: *const S, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_directfb(&instance, dfb, surface)?; Ok(Self::from_directfb_unchecked( @@ -403,14 +403,14 @@ impl Surface { instance: &Instance, _dfb: *const D, _surface: *const S, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().ext_directfb_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_directfb_surface", )])]), ..Default::default() - }); + })); } // VUID-VkDirectFBSurfaceCreateInfoEXT-dfb-04117 @@ -428,7 +428,7 @@ impl Surface { dfb: *const D, surface: *const S, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::DirectFBSurfaceCreateInfoEXT { flags: ash::vk::DirectFBSurfaceCreateFlagsEXT::empty(), dfb: dfb as *mut _, @@ -446,7 +446,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -469,7 +469,7 @@ impl Surface { instance: Arc, image_pipe_handle: ash::vk::zx_handle_t, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_fuchsia_image_pipe(&instance, image_pipe_handle)?; Ok(Self::from_fuchsia_image_pipe_unchecked( @@ -482,14 +482,14 @@ impl Surface { fn validate_from_fuchsia_image_pipe( instance: &Instance, _image_pipe_handle: ash::vk::zx_handle_t, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().fuchsia_imagepipe_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "fuchsia_imagepipe_surface", )])]), ..Default::default() - }); + })); } // VUID-VkImagePipeSurfaceCreateInfoFUCHSIA-imagePipeHandle-04863 @@ -503,7 +503,7 @@ impl Surface { instance: Arc, image_pipe_handle: ash::vk::zx_handle_t, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::ImagePipeSurfaceCreateInfoFUCHSIA { flags: ash::vk::ImagePipeSurfaceCreateFlagsFUCHSIA::empty(), image_pipe_handle, @@ -521,7 +521,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -544,7 +544,7 @@ impl Surface { instance: Arc, stream_descriptor: ash::vk::GgpStreamDescriptor, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_ggp_stream_descriptor(&instance, stream_descriptor)?; Ok(Self::from_ggp_stream_descriptor_unchecked( @@ -557,14 +557,14 @@ impl Surface { fn validate_from_ggp_stream_descriptor( instance: &Instance, _stream_descriptor: ash::vk::GgpStreamDescriptor, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().ggp_stream_descriptor_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ggp_stream_descriptor_surface", )])]), ..Default::default() - }); + })); } // VUID-VkStreamDescriptorSurfaceCreateInfoGGP-streamDescriptor-02681 @@ -578,7 +578,7 @@ impl Surface { instance: Arc, stream_descriptor: ash::vk::GgpStreamDescriptor, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::StreamDescriptorSurfaceCreateInfoGGP { flags: ash::vk::StreamDescriptorSurfaceCreateFlagsGGP::empty(), stream_descriptor, @@ -596,7 +596,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -621,7 +621,7 @@ impl Surface { instance: Arc, metal_layer: IOSMetalLayer, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_ios(&instance, &metal_layer)?; Ok(Self::from_ios_unchecked(instance, metal_layer, object)?) @@ -631,14 +631,14 @@ impl Surface { fn validate_from_ios( instance: &Instance, _metal_layer: &IOSMetalLayer, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().mvk_ios_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "mvk_ios_surface", )])]), ..Default::default() - }); + })); } // VUID-VkIOSSurfaceCreateInfoMVK-pView-04143 @@ -656,7 +656,7 @@ impl Surface { instance: Arc, metal_layer: IOSMetalLayer, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::IOSSurfaceCreateInfoMVK { flags: ash::vk::IOSSurfaceCreateFlagsMVK::empty(), p_view: metal_layer.render_layer.0 as *const _, @@ -673,7 +673,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -698,7 +698,7 @@ impl Surface { instance: Arc, view: *const V, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_mac_os(&instance, view)?; Ok(Self::from_mac_os_unchecked(instance, view, object)?) @@ -708,14 +708,14 @@ impl Surface { fn validate_from_mac_os( instance: &Instance, _view: *const V, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().mvk_macos_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "mvk_macos_surface", )])]), ..Default::default() - }); + })); } // VUID-VkMacOSSurfaceCreateInfoMVK-pView-04144 @@ -733,7 +733,7 @@ impl Surface { instance: Arc, view: *const V, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::MacOSSurfaceCreateInfoMVK { flags: ash::vk::MacOSSurfaceCreateFlagsMVK::empty(), p_view: view as *const _, @@ -750,7 +750,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -773,7 +773,7 @@ impl Surface { instance: Arc, layer: *const L, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_metal(&instance, layer)?; Ok(Self::from_metal_unchecked(instance, layer, object)?) @@ -782,14 +782,14 @@ impl Surface { fn validate_from_metal( instance: &Instance, _layer: *const L, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().ext_metal_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "ext_metal_surface", )])]), ..Default::default() - }); + })); } Ok(()) @@ -800,7 +800,7 @@ impl Surface { instance: Arc, layer: *const L, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::MetalSurfaceCreateInfoEXT { flags: ash::vk::MetalSurfaceCreateFlagsEXT::empty(), p_layer: layer as *const _, @@ -817,7 +817,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -842,7 +842,7 @@ impl Surface { context: *const C, window: *const W, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_qnx_screen(&instance, context, window)?; Ok(Self::from_qnx_screen_unchecked( @@ -854,14 +854,14 @@ impl Surface { instance: &Instance, _context: *const C, _window: *const W, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().qnx_screen_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "qnx_screen_surface", )])]), ..Default::default() - }); + })); } // VUID-VkScreenSurfaceCreateInfoQNX-context-04741 @@ -879,7 +879,7 @@ impl Surface { context: *const C, window: *const W, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::ScreenSurfaceCreateInfoQNX { flags: ash::vk::ScreenSurfaceCreateFlagsQNX::empty(), context: context as *mut _, @@ -897,7 +897,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -920,20 +920,23 @@ impl Surface { instance: Arc, window: *const W, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_vi(&instance, window)?; Ok(Self::from_vi_unchecked(instance, window, object)?) } - fn validate_from_vi(instance: &Instance, _window: *const W) -> Result<(), ValidationError> { + fn validate_from_vi( + instance: &Instance, + _window: *const W, + ) -> Result<(), Box> { if !instance.enabled_extensions().nn_vi_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "nn_vi_surface", )])]), ..Default::default() - }); + })); } // VUID-VkViSurfaceCreateInfoNN-window-01318 @@ -947,7 +950,7 @@ impl Surface { instance: Arc, window: *const W, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::ViSurfaceCreateInfoNN { flags: ash::vk::ViSurfaceCreateFlagsNN::empty(), window: window as *mut _, @@ -964,7 +967,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -991,7 +994,7 @@ impl Surface { display: *const D, surface: *const S, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_wayland(&instance, display, surface)?; Ok(Self::from_wayland_unchecked( @@ -1003,14 +1006,14 @@ impl Surface { instance: &Instance, _display: *const D, _surface: *const S, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().khr_wayland_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_wayland_surface", )])]), ..Default::default() - }); + })); } // VUID-VkWaylandSurfaceCreateInfoKHR-display-01304 @@ -1028,7 +1031,7 @@ impl Surface { display: *const D, surface: *const S, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::WaylandSurfaceCreateInfoKHR { flags: ash::vk::WaylandSurfaceCreateFlagsKHR::empty(), display: display as *mut _, @@ -1046,7 +1049,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1073,7 +1076,7 @@ impl Surface { hinstance: *const I, hwnd: *const W, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_win32(&instance, hinstance, hwnd)?; Ok(Self::from_win32_unchecked( @@ -1085,14 +1088,14 @@ impl Surface { instance: &Instance, _hinstance: *const I, _hwnd: *const W, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().khr_win32_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_win32_surface", )])]), ..Default::default() - }); + })); } // VUID-VkWin32SurfaceCreateInfoKHR-hinstance-01307 @@ -1110,7 +1113,7 @@ impl Surface { hinstance: *const I, hwnd: *const W, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::Win32SurfaceCreateInfoKHR { flags: ash::vk::Win32SurfaceCreateFlagsKHR::empty(), hinstance: hinstance as *mut _, @@ -1128,7 +1131,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1155,7 +1158,7 @@ impl Surface { connection: *const C, window: ash::vk::xcb_window_t, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_xcb(&instance, connection, window)?; Ok(Self::from_xcb_unchecked( @@ -1167,14 +1170,14 @@ impl Surface { instance: &Instance, _connection: *const C, _window: ash::vk::xcb_window_t, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().khr_xcb_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_xcb_surface", )])]), ..Default::default() - }); + })); } // VUID-VkXcbSurfaceCreateInfoKHR-connection-01310 @@ -1192,7 +1195,7 @@ impl Surface { connection: *const C, window: ash::vk::xcb_window_t, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::XcbSurfaceCreateInfoKHR { flags: ash::vk::XcbSurfaceCreateFlagsKHR::empty(), connection: connection as *mut _, @@ -1210,7 +1213,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1237,7 +1240,7 @@ impl Surface { display: *const D, window: ash::vk::Window, object: Option>, - ) -> Result, VulkanError> { + ) -> Result, Validated> { Self::validate_from_xlib(&instance, display, window)?; Ok(Self::from_xlib_unchecked( @@ -1249,14 +1252,14 @@ impl Surface { instance: &Instance, _display: *const D, _window: ash::vk::Window, - ) -> Result<(), ValidationError> { + ) -> Result<(), Box> { if !instance.enabled_extensions().khr_xlib_surface { - return Err(ValidationError { + return Err(Box::new(ValidationError { requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::InstanceExtension( "khr_xlib_surface", )])]), ..Default::default() - }); + })); } // VUID-VkXlibSurfaceCreateInfoKHR-dpy-01313 @@ -1274,7 +1277,7 @@ impl Surface { display: *const D, window: ash::vk::Window, object: Option>, - ) -> Result, RuntimeError> { + ) -> Result, VulkanError> { let create_info = ash::vk::XlibSurfaceCreateInfoKHR { flags: ash::vk::XlibSurfaceCreateFlagsKHR::empty(), dpy: display as *mut _, @@ -1292,7 +1295,7 @@ impl Surface { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -1850,7 +1853,10 @@ impl Default for SurfaceInfo { } impl SurfaceInfo { - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { present_mode, full_screen_exclusive, @@ -1864,14 +1870,14 @@ impl SurfaceInfo { .enabled_extensions() .ext_surface_maintenance1 { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "present_mode".into(), problem: "is `Some`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[ Requires::InstanceExtension("ext_surface_maintenance1"), ])]), ..Default::default() - }); + })); } present_mode @@ -1888,14 +1894,14 @@ impl SurfaceInfo { .supported_extensions() .ext_full_screen_exclusive { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "full_screen_exclusive".into(), problem: "is not `FullScreenExclusive::Default`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::DeviceExtension( "ext_full_screen_exclusive", )])]), ..Default::default() - }); + })); } Ok(()) @@ -2029,7 +2035,7 @@ pub struct SurfaceCapabilities { #[cfg(test)] mod tests { use crate::{ - swapchain::Surface, Requires, RequiresAllOf, RequiresOneOf, ValidationError, VulkanError, + swapchain::Surface, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, }; use std::ptr; @@ -2037,11 +2043,16 @@ mod tests { fn khr_win32_surface_ext_missing() { let instance = instance!(); match unsafe { Surface::from_win32(instance, ptr::null::(), ptr::null::(), None) } { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::InstanceExtension("khr_win32_surface")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([ + Requires::InstanceExtension("khr_win32_surface") + ])]), + .. + } + ) => {} _ => panic!(), } } @@ -2050,11 +2061,16 @@ mod tests { fn khr_xcb_surface_ext_missing() { let instance = instance!(); match unsafe { Surface::from_xcb(instance, ptr::null::(), 0, None) } { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::InstanceExtension("khr_xcb_surface")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([ + Requires::InstanceExtension("khr_xcb_surface") + ])]), + .. + } + ) => {} _ => panic!(), } } @@ -2063,11 +2079,16 @@ mod tests { fn khr_xlib_surface_ext_missing() { let instance = instance!(); match unsafe { Surface::from_xlib(instance, ptr::null::(), 0, None) } { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::InstanceExtension("khr_xlib_surface")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([ + Requires::InstanceExtension("khr_xlib_surface") + ])]), + .. + } + ) => {} _ => panic!(), } } @@ -2077,11 +2098,16 @@ mod tests { let instance = instance!(); match unsafe { Surface::from_wayland(instance, ptr::null::(), ptr::null::(), None) } { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::InstanceExtension("khr_wayland_surface")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([ + Requires::InstanceExtension("khr_wayland_surface") + ])]), + .. + } + ) => {} _ => panic!(), } } @@ -2090,11 +2116,16 @@ mod tests { fn khr_android_surface_ext_missing() { let instance = instance!(); match unsafe { Surface::from_android(instance, ptr::null::(), None) } { - Err(VulkanError::ValidationError(ValidationError { - requires_one_of: - RequiresOneOf([RequiresAllOf([Requires::InstanceExtension("khr_android_surface")])]), - .. - })) => (), + Err(Validated::ValidationError(err)) + if matches!( + *err, + ValidationError { + requires_one_of: RequiresOneOf([RequiresAllOf([ + Requires::InstanceExtension("khr_android_surface") + ])]), + .. + } + ) => {} _ => panic!(), } } diff --git a/vulkano/src/sync/event.rs b/vulkano/src/sync/event.rs index 442640ca..3cc3e249 100644 --- a/vulkano/src/sync/event.rs +++ b/vulkano/src/sync/event.rs @@ -28,7 +28,7 @@ use crate::{ device::{Device, DeviceOwned}, instance::InstanceOwnedDebugWrapper, macros::impl_id_counter, - OomError, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, VulkanObject, + OomError, Requires, RequiresAllOf, RequiresOneOf, VulkanError, VulkanObject, }; use std::{ error::Error, @@ -86,7 +86,7 @@ impl Event { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -114,7 +114,7 @@ impl Event { let fns = device.fns(); (fns.v1_0.reset_event)(device.handle(), handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Event { handle, @@ -163,7 +163,7 @@ impl Event { match result { ash::vk::Result::EVENT_SET => Ok(true), ash::vk::Result::EVENT_RESET => Ok(false), - err => Err(RuntimeError::from(err).into()), + err => Err(VulkanError::from(err).into()), } } } @@ -175,7 +175,7 @@ impl Event { let fns = self.device.fns(); (fns.v1_0.set_event)(self.device.handle(), self.handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } } @@ -199,7 +199,7 @@ impl Event { let fns = self.device.fns(); (fns.v1_0.reset_event)(self.device.handle(), self.handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; Ok(()) } } @@ -299,10 +299,10 @@ impl Display for EventError { } } -impl From for EventError { - fn from(err: RuntimeError) -> Self { +impl From for EventError { + fn from(err: VulkanError) -> Self { match err { - e @ RuntimeError::OutOfHostMemory | e @ RuntimeError::OutOfDeviceMemory => { + e @ VulkanError::OutOfHostMemory | e @ VulkanError::OutOfDeviceMemory => { Self::OomError(e.into()) } _ => panic!("unexpected error: {:?}", err), diff --git a/vulkano/src/sync/fence.rs b/vulkano/src/sync/fence.rs index 4a659c69..8239d011 100644 --- a/vulkano/src/sync/fence.rs +++ b/vulkano/src/sync/fence.rs @@ -14,8 +14,8 @@ use crate::{ device::{physical::PhysicalDevice, Device, DeviceOwned, Queue}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum}, - OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, - ValidationError, Version, VulkanObject, + OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, ValidationError, Version, + VulkanError, VulkanObject, }; use parking_lot::{Mutex, MutexGuard}; use smallvec::SmallVec; @@ -132,7 +132,7 @@ impl Fence { pub unsafe fn new_unchecked( device: Arc, create_info: FenceCreateInfo, - ) -> Result { + ) -> Result { let FenceCreateInfo { signaled, export_handle_types, @@ -173,7 +173,7 @@ impl Fence { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -207,7 +207,7 @@ impl Fence { let fns = device.fns(); (fns.v1_0.reset_fences)(device.handle(), 1, &handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; } Fence { @@ -282,7 +282,7 @@ impl Fence { match result { ash::vk::Result::SUCCESS => unsafe { state.set_signaled() }, ash::vk::Result::NOT_READY => return Ok(false), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } }; @@ -332,7 +332,7 @@ impl Fence { match result { ash::vk::Result::SUCCESS => unsafe { state.set_signaled() }, ash::vk::Result::TIMEOUT => return Err(FenceError::Timeout), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } }; @@ -434,7 +434,7 @@ impl Fence { .filter_map(|(fence, state)| state.set_signaled().map(|state| (state, fence))) .collect(), ash::vk::Result::TIMEOUT => return Err(FenceError::Timeout), - err => return Err(RuntimeError::from(err).into()), + err => return Err(VulkanError::from(err).into()), } }; @@ -469,17 +469,17 @@ impl Fence { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] #[inline] - pub unsafe fn reset_unchecked(&self) -> Result<(), RuntimeError> { + pub unsafe fn reset_unchecked(&self) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.reset_unchecked_locked(&mut state) } - unsafe fn reset_unchecked_locked(&self, state: &mut FenceState) -> Result<(), RuntimeError> { + unsafe fn reset_unchecked_locked(&self, state: &mut FenceState) -> Result<(), VulkanError> { let fns = self.device.fns(); (fns.v1_0.reset_fences)(self.device.handle(), 1, &self.handle) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.reset(); @@ -532,7 +532,7 @@ impl Fence { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] pub unsafe fn multi_reset_unchecked<'a>( fences: impl IntoIterator, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let (fences, mut states): (SmallVec<[_; 8]>, SmallVec<[_; 8]>) = fences .into_iter() .map(|fence| { @@ -547,7 +547,7 @@ impl Fence { unsafe fn multi_reset_unchecked_locked( fences: &[&Fence], states: &mut [MutexGuard<'_, FenceState>], - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { if fences.is_empty() { return Ok(()); } @@ -558,7 +558,7 @@ impl Fence { let fns = device.fns(); (fns.v1_0.reset_fences)(device.handle(), fences_vk.len() as u32, fences_vk.as_ptr()) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; for state in states { state.reset(); @@ -654,7 +654,7 @@ impl Fence { pub unsafe fn export_fd_unchecked( &self, handle_type: ExternalFenceHandleType, - ) -> Result { + ) -> Result { let mut state = self.state.lock(); self.export_fd_unchecked_locked(handle_type, &mut state) } @@ -664,7 +664,7 @@ impl Fence { &self, handle_type: ExternalFenceHandleType, state: &mut FenceState, - ) -> Result { + ) -> Result { use std::os::unix::io::FromRawFd; let info_vk = ash::vk::FenceGetFdInfoKHR { @@ -681,7 +681,7 @@ impl Fence { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.export(handle_type); @@ -785,7 +785,7 @@ impl Fence { pub unsafe fn export_win32_handle_unchecked( &self, handle_type: ExternalFenceHandleType, - ) -> Result<*mut std::ffi::c_void, RuntimeError> { + ) -> Result<*mut std::ffi::c_void, VulkanError> { let mut state = self.state.lock(); self.export_win32_handle_unchecked_locked(handle_type, &mut state) } @@ -795,7 +795,7 @@ impl Fence { &self, handle_type: ExternalFenceHandleType, state: &mut FenceState, - ) -> Result<*mut std::ffi::c_void, RuntimeError> { + ) -> Result<*mut std::ffi::c_void, VulkanError> { let info_vk = ash::vk::FenceGetWin32HandleInfoKHR { fence: self.handle, handle_type: handle_type.into(), @@ -810,7 +810,7 @@ impl Fence { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.export(handle_type); @@ -897,7 +897,7 @@ impl Fence { pub unsafe fn import_fd_unchecked( &self, import_fence_fd_info: ImportFenceFdInfo, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.import_fd_unchecked_locked(import_fence_fd_info, &mut state) } @@ -907,7 +907,7 @@ impl Fence { &self, import_fence_fd_info: ImportFenceFdInfo, state: &mut FenceState, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { use std::os::unix::io::IntoRawFd; let ImportFenceFdInfo { @@ -928,7 +928,7 @@ impl Fence { let fns = self.device.fns(); (fns.khr_external_fence_fd.import_fence_fd_khr)(self.device.handle(), &info_vk) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.import(handle_type, flags.intersects(FenceImportFlags::TEMPORARY)); @@ -1015,7 +1015,7 @@ impl Fence { pub unsafe fn import_win32_handle_unchecked( &self, import_fence_win32_handle_info: ImportFenceWin32HandleInfo, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.import_win32_handle_unchecked_locked(import_fence_win32_handle_info, &mut state) } @@ -1025,7 +1025,7 @@ impl Fence { &self, import_fence_win32_handle_info: ImportFenceWin32HandleInfo, state: &mut FenceState, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let ImportFenceWin32HandleInfo { flags, handle_type, @@ -1048,7 +1048,7 @@ impl Fence { &info_vk, ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.import(handle_type, flags.intersects(FenceImportFlags::TEMPORARY)); @@ -1420,7 +1420,10 @@ impl ExternalFenceInfo { } } - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { handle_type, _ne: _, @@ -1595,13 +1598,13 @@ impl Display for FenceError { } } -impl From for FenceError { - fn from(err: RuntimeError) -> Self { +impl From for FenceError { + fn from(err: VulkanError) -> Self { match err { - e @ RuntimeError::OutOfHostMemory | e @ RuntimeError::OutOfDeviceMemory => { + e @ VulkanError::OutOfHostMemory | e @ VulkanError::OutOfDeviceMemory => { Self::OomError(e.into()) } - RuntimeError::DeviceLost => Self::DeviceLost, + VulkanError::DeviceLost => Self::DeviceLost, _ => panic!("unexpected error: {:?}", err), } } diff --git a/vulkano/src/sync/future/mod.rs b/vulkano/src/sync/future/mod.rs index 1c134ffb..c2613a61 100644 --- a/vulkano/src/sync/future/mod.rs +++ b/vulkano/src/sync/future/mod.rs @@ -110,7 +110,7 @@ use crate::{ image::{Image, ImageLayout}, memory::BindSparseInfo, swapchain::{self, PresentFuture, PresentInfo, Swapchain, SwapchainPresentInfo}, - DeviceSize, OomError, RuntimeError, + DeviceSize, OomError, VulkanError, }; use smallvec::SmallVec; use std::{ @@ -672,16 +672,16 @@ impl From for FlushError { } } -impl From for FlushError { - fn from(err: RuntimeError) -> Self { +impl From for FlushError { + fn from(err: VulkanError) -> Self { match err { - RuntimeError::OutOfHostMemory | RuntimeError::OutOfDeviceMemory => { + VulkanError::OutOfHostMemory | VulkanError::OutOfDeviceMemory => { Self::OomError(err.into()) } - RuntimeError::DeviceLost => Self::DeviceLost, - RuntimeError::SurfaceLost => Self::SurfaceLost, - RuntimeError::OutOfDate => Self::OutOfDate, - RuntimeError::FullScreenExclusiveModeLost => Self::FullScreenExclusiveModeLost, + VulkanError::DeviceLost => Self::DeviceLost, + VulkanError::SurfaceLost => Self::SurfaceLost, + VulkanError::OutOfDate => Self::OutOfDate, + VulkanError::FullScreenExclusiveModeLost => Self::FullScreenExclusiveModeLost, _ => panic!("unexpected error: {:?}", err), } } diff --git a/vulkano/src/sync/mod.rs b/vulkano/src/sync/mod.rs index 1c84105b..da85d29a 100644 --- a/vulkano/src/sync/mod.rs +++ b/vulkano/src/sync/mod.rs @@ -25,7 +25,7 @@ pub use self::{ MemoryBarrier, PipelineStage, PipelineStages, QueueFamilyOwnershipTransfer, }, }; -use crate::{device::Queue, RuntimeError, ValidationError}; +use crate::{device::Queue, ValidationError, VulkanError}; use std::{ error::Error, fmt::{Display, Formatter}, @@ -103,7 +103,7 @@ pub(crate) enum CurrentAccess { #[derive(Clone, Debug)] pub enum HostAccessError { AccessConflict(AccessConflict), - Invalidate(RuntimeError), + Invalidate(VulkanError), ValidationError(ValidationError), } diff --git a/vulkano/src/sync/pipeline.rs b/vulkano/src/sync/pipeline.rs index 4101cc08..514f2fc3 100644 --- a/vulkano/src/sync/pipeline.rs +++ b/vulkano/src/sync/pipeline.rs @@ -1862,7 +1862,7 @@ impl Default for MemoryBarrier { } impl MemoryBarrier { - pub(crate) fn validate(&self, device: &Device) -> Result<(), ValidationError> { + pub(crate) fn validate(&self, device: &Device) -> Result<(), Box> { let &Self { src_stages, src_access, @@ -1905,71 +1905,71 @@ impl MemoryBarrier { if !device.enabled_features().synchronization2 { if src_stages.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains flags from `VkPipelineStageFlagBits2`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), ..Default::default() - }); + })); } if dst_stages.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains flags from `VkPipelineStageFlagBits2`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), ..Default::default() - }); + })); } if src_access.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_access".into(), problem: "contains flags from `VkAccessFlagBits2`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), ..Default::default() - }); + })); } if dst_access.contains_flags2() { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_access".into(), problem: "contains flags from `VkAccessFlagBits2`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "synchronization2", )])]), ..Default::default() - }); + })); } } if !device.enabled_features().geometry_shader { if src_stages.intersects(PipelineStages::GEOMETRY_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::GEOMETRY_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "geometry_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03929"], - }); + })); } if dst_stages.intersects(PipelineStages::GEOMETRY_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::GEOMETRY_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "geometry_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03929"], - }); + })); } } @@ -1978,7 +1978,7 @@ impl MemoryBarrier { PipelineStages::TESSELLATION_CONTROL_SHADER | PipelineStages::TESSELLATION_EVALUATION_SHADER, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::TESSELLATION_CONTROL_SHADER` or \ `PipelineStages::TESSELLATION_EVALUATION_SHADER`" @@ -1987,14 +1987,14 @@ impl MemoryBarrier { "tessellation_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03930"], - }); + })); } if dst_stages.intersects( PipelineStages::TESSELLATION_CONTROL_SHADER | PipelineStages::TESSELLATION_EVALUATION_SHADER, ) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::TESSELLATION_CONTROL_SHADER` or \ `PipelineStages::TESSELLATION_EVALUATION_SHADER`" @@ -2003,127 +2003,127 @@ impl MemoryBarrier { "tessellation_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03930"], - }); + })); } } if !device.enabled_features().conditional_rendering { if src_stages.intersects(PipelineStages::CONDITIONAL_RENDERING) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::CONDITIONAL_RENDERING`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "conditional_rendering", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03931"], - }); + })); } if dst_stages.intersects(PipelineStages::CONDITIONAL_RENDERING) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::CONDITIONAL_RENDERING`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "conditional_rendering", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03931"], - }); + })); } } if !device.enabled_features().fragment_density_map { if src_stages.intersects(PipelineStages::FRAGMENT_DENSITY_PROCESS) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::FRAGMENT_DENSITY_PROCESS`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "fragment_density_map", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03932"], - }); + })); } if dst_stages.intersects(PipelineStages::FRAGMENT_DENSITY_PROCESS) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::FRAGMENT_DENSITY_PROCESS`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "fragment_density_map", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03932"], - }); + })); } } if !device.enabled_features().transform_feedback { if src_stages.intersects(PipelineStages::TRANSFORM_FEEDBACK) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::TRANSFORM_FEEDBACK`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "transform_feedback", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03933"], - }); + })); } if dst_stages.intersects(PipelineStages::TRANSFORM_FEEDBACK) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::TRANSFORM_FEEDBACK`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "transform_feedback", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03933"], - }); + })); } } if !device.enabled_features().mesh_shader { if src_stages.intersects(PipelineStages::MESH_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::MESH_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "mesh_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03934"], - }); + })); } if dst_stages.intersects(PipelineStages::MESH_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::MESH_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "mesh_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03934"], - }); + })); } } if !device.enabled_features().task_shader { if src_stages.intersects(PipelineStages::TASK_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::TASK_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "task_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-03935"], - }); + })); } if dst_stages.intersects(PipelineStages::TASK_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::TASK_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "task_shader", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-03935"], - }); + })); } } @@ -2131,7 +2131,7 @@ impl MemoryBarrier { || device.enabled_features().shading_rate_image) { if src_stages.intersects(PipelineStages::FRAGMENT_SHADING_RATE_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::FRAGMENT_SHADING_RATE_ATTACHMENT`".into(), requires_one_of: RequiresOneOf(&[ @@ -2139,11 +2139,11 @@ impl MemoryBarrier { RequiresAllOf(&[Requires::Feature("shading_rate_image")]), ]), vuids: &["VUID-VkMemoryBarrier2-shadingRateImage-07316"], - }); + })); } if dst_stages.intersects(PipelineStages::FRAGMENT_SHADING_RATE_ATTACHMENT) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::FRAGMENT_SHADING_RATE_ATTACHMENT`".into(), requires_one_of: RequiresOneOf(&[ @@ -2151,55 +2151,55 @@ impl MemoryBarrier { RequiresAllOf(&[Requires::Feature("shading_rate_image")]), ]), vuids: &["VUID-VkMemoryBarrier2-shadingRateImage-07316"], - }); + })); } } if !device.enabled_features().subpass_shading { if src_stages.intersects(PipelineStages::SUBPASS_SHADING) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::SUBPASS_SHADING`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "subpass_shading", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-04957"], - }); + })); } if dst_stages.intersects(PipelineStages::SUBPASS_SHADING) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::SUBPASS_SHADING`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "subpass_shading", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-04957"], - }); + })); } } if !device.enabled_features().invocation_mask { if src_stages.intersects(PipelineStages::INVOCATION_MASK) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::INVOCATION_MASK`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "invocation_mask", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-04995"], - }); + })); } if dst_stages.intersects(PipelineStages::INVOCATION_MASK) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::INVOCATION_MASK`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "invocation_mask", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-04995"], - }); + })); } } @@ -2207,30 +2207,30 @@ impl MemoryBarrier { || device.enabled_features().ray_tracing_pipeline) { if src_stages.intersects(PipelineStages::RAY_TRACING_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "src_stages".into(), problem: "contains `PipelineStages::RAY_TRACING_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "ray_tracing_pipeline", )])]), vuids: &["VUID-VkMemoryBarrier2-srcStageMask-07946"], - }); + })); } if dst_stages.intersects(PipelineStages::RAY_TRACING_SHADER) { - return Err(ValidationError { + return Err(Box::new(ValidationError { context: "dst_stages".into(), problem: "contains `PipelineStages::RAY_TRACING_SHADER`".into(), requires_one_of: RequiresOneOf(&[RequiresAllOf(&[Requires::Feature( "ray_tracing_pipeline", )])]), vuids: &["VUID-VkMemoryBarrier2-dstStageMask-07946"], - }); + })); } } if !AccessFlags::from(src_stages).contains(src_access) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`src_access` contains one or more access types that are not performed \ by any stage in `src_stages`" .into(), @@ -2278,11 +2278,11 @@ impl MemoryBarrier { "VUID-VkMemoryBarrier2-srcAccessMask-08118", ], ..Default::default() - }); + })); } if !AccessFlags::from(dst_stages).contains(dst_access) { - return Err(ValidationError { + return Err(Box::new(ValidationError { problem: "`dst_access` contains one or more access types that are not performed \ by any stage in `dst_stages`" .into(), @@ -2330,7 +2330,7 @@ impl MemoryBarrier { "VUID-VkMemoryBarrier2-dstAccessMask-08118", ], ..Default::default() - }); + })); } Ok(()) diff --git a/vulkano/src/sync/semaphore.rs b/vulkano/src/sync/semaphore.rs index 61b9303f..016f0f8d 100644 --- a/vulkano/src/sync/semaphore.rs +++ b/vulkano/src/sync/semaphore.rs @@ -14,8 +14,8 @@ use crate::{ device::{physical::PhysicalDevice, Device, DeviceOwned, Queue}, instance::InstanceOwnedDebugWrapper, macros::{impl_id_counter, vulkan_bitflags, vulkan_bitflags_enum}, - OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, RuntimeError, - ValidationError, Version, VulkanObject, + OomError, RequirementNotMet, Requires, RequiresAllOf, RequiresOneOf, ValidationError, Version, + VulkanError, VulkanObject, }; use parking_lot::{Mutex, MutexGuard}; #[cfg(unix)] @@ -113,7 +113,7 @@ impl Semaphore { pub unsafe fn new_unchecked( device: Arc, create_info: SemaphoreCreateInfo, - ) -> Result { + ) -> Result { let SemaphoreCreateInfo { export_handle_types, _ne: _, @@ -147,7 +147,7 @@ impl Semaphore { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; output.assume_init() }; @@ -310,7 +310,7 @@ impl Semaphore { pub unsafe fn export_fd_unchecked( &self, handle_type: ExternalSemaphoreHandleType, - ) -> Result { + ) -> Result { let mut state = self.state.lock(); self.export_fd_unchecked_locked(handle_type, &mut state) } @@ -320,7 +320,7 @@ impl Semaphore { &self, handle_type: ExternalSemaphoreHandleType, state: &mut SemaphoreState, - ) -> Result { + ) -> Result { use std::os::unix::io::FromRawFd; let info = ash::vk::SemaphoreGetFdInfoKHR { @@ -337,7 +337,7 @@ impl Semaphore { output.as_mut_ptr(), ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.export(handle_type); @@ -454,7 +454,7 @@ impl Semaphore { pub unsafe fn export_win32_handle_unchecked( &self, handle_type: ExternalSemaphoreHandleType, - ) -> Result<*mut std::ffi::c_void, RuntimeError> { + ) -> Result<*mut std::ffi::c_void, VulkanError> { let mut state = self.state.lock(); self.export_win32_handle_unchecked_locked(handle_type, &mut state) } @@ -464,7 +464,7 @@ impl Semaphore { &self, handle_type: ExternalSemaphoreHandleType, state: &mut SemaphoreState, - ) -> Result<*mut std::ffi::c_void, RuntimeError> { + ) -> Result<*mut std::ffi::c_void, VulkanError> { let info_vk = ash::vk::SemaphoreGetWin32HandleInfoKHR { semaphore: self.handle, handle_type: handle_type.into(), @@ -478,7 +478,7 @@ impl Semaphore { self.device.handle(), &info_vk, output.as_mut_ptr() ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.export(handle_type); @@ -574,7 +574,7 @@ impl Semaphore { pub unsafe fn export_zircon_handle_unchecked( &self, handle_type: ExternalSemaphoreHandleType, - ) -> Result { + ) -> Result { let mut state = self.state.lock(); self.export_zircon_handle_unchecked_locked(handle_type, &mut state) } @@ -584,7 +584,7 @@ impl Semaphore { &self, handle_type: ExternalSemaphoreHandleType, state: &mut SemaphoreState, - ) -> Result { + ) -> Result { let info = ash::vk::SemaphoreGetZirconHandleInfoFUCHSIA { semaphore: self.handle, handle_type: handle_type.into(), @@ -598,7 +598,7 @@ impl Semaphore { self.device.handle(), &info, output.as_mut_ptr() ) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.export(handle_type); @@ -688,7 +688,7 @@ impl Semaphore { pub unsafe fn import_fd_unchecked( &self, import_semaphore_fd_info: ImportSemaphoreFdInfo, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.import_fd_unchecked_locked(import_semaphore_fd_info, &mut state) } @@ -698,7 +698,7 @@ impl Semaphore { &self, import_semaphore_fd_info: ImportSemaphoreFdInfo, state: &mut SemaphoreState, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { use std::os::unix::io::IntoRawFd; let ImportSemaphoreFdInfo { @@ -719,7 +719,7 @@ impl Semaphore { let fns = self.device.fns(); (fns.khr_external_semaphore_fd.import_semaphore_fd_khr)(self.device.handle(), &info_vk) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.import( handle_type, @@ -817,7 +817,7 @@ impl Semaphore { pub unsafe fn import_win32_handle_unchecked( &self, import_semaphore_win32_handle_info: ImportSemaphoreWin32HandleInfo, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.import_win32_handle_unchecked_locked(import_semaphore_win32_handle_info, &mut state) } @@ -827,7 +827,7 @@ impl Semaphore { &self, import_semaphore_win32_handle_info: ImportSemaphoreWin32HandleInfo, state: &mut SemaphoreState, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let ImportSemaphoreWin32HandleInfo { flags, handle_type, @@ -848,7 +848,7 @@ impl Semaphore { (fns.khr_external_semaphore_win32 .import_semaphore_win32_handle_khr)(self.device.handle(), &info_vk) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.import( handle_type, @@ -938,7 +938,7 @@ impl Semaphore { pub unsafe fn import_zircon_handle_unchecked( &self, import_semaphore_zircon_handle_info: ImportSemaphoreZirconHandleInfo, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let mut state = self.state.lock(); self.import_zircon_handle_unchecked_locked(import_semaphore_zircon_handle_info, &mut state) } @@ -948,7 +948,7 @@ impl Semaphore { &self, import_semaphore_zircon_handle_info: ImportSemaphoreZirconHandleInfo, state: &mut SemaphoreState, - ) -> Result<(), RuntimeError> { + ) -> Result<(), VulkanError> { let ImportSemaphoreZirconHandleInfo { flags, handle_type, @@ -968,7 +968,7 @@ impl Semaphore { (fns.fuchsia_external_semaphore .import_semaphore_zircon_handle_fuchsia)(self.device.handle(), &info_vk) .result() - .map_err(RuntimeError::from)?; + .map_err(VulkanError::from)?; state.import( handle_type, @@ -1378,7 +1378,10 @@ impl ExternalSemaphoreInfo { } } - pub(crate) fn validate(&self, physical_device: &PhysicalDevice) -> Result<(), ValidationError> { + pub(crate) fn validate( + &self, + physical_device: &PhysicalDevice, + ) -> Result<(), Box> { let &Self { handle_type, _ne: _, @@ -1556,10 +1559,10 @@ impl Display for SemaphoreError { } } -impl From for SemaphoreError { - fn from(err: RuntimeError) -> Self { +impl From for SemaphoreError { + fn from(err: VulkanError) -> Self { match err { - e @ RuntimeError::OutOfHostMemory | e @ RuntimeError::OutOfDeviceMemory => { + e @ VulkanError::OutOfHostMemory | e @ VulkanError::OutOfDeviceMemory => { Self::OomError(e.into()) } _ => panic!("unexpected error: {:?}", err),