Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove remaining old error types, other cleanup #2281

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions vulkano-shaders/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,7 @@ impl TypeStruct {
members.push(Member { ident, ty, offset });
}

Ok(TypeStruct {
ident,
members,
})
Ok(TypeStruct { ident, members })
}

fn size(&self) -> Option<usize> {
Expand Down
15 changes: 8 additions & 7 deletions vulkano/autogen/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
let ident = format_ident!("{}", ext_name);
quote! { instance_extensions.#ident }
}));
let required_for = format!("`Format::{}`", name);
let required_for = format!("is `Format::{}`", name);
let requires_one_of_items = (api_version.iter().map(|(major, minor)| {
let version = format_ident!("V{}_{}", major, minor);
quote! {
Expand All @@ -317,12 +317,13 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {

quote! {
if !(#(#condition_items)||*) {
return Err(crate::RequirementNotMet {
required_for: #required_for,
return Err(Box::new(crate::ValidationError {
problem: #required_for.into(),
requires_one_of: crate::RequiresOneOf(&[
#(#requires_one_of_items)*
]),
});
..Default::default()
}));
}
}
},
Expand Down Expand Up @@ -482,7 +483,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
pub(crate) fn validate_device(
self,
#[allow(unused_variables)] device: &crate::device::Device,
) -> Result<(), crate::RequirementNotMet> {
) -> Result<(), Box<crate::ValidationError>> {
self.validate_device_raw(
device.api_version(),
device.enabled_features(),
Expand All @@ -495,7 +496,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
pub(crate) fn validate_physical_device(
self,
#[allow(unused_variables)] physical_device: &crate::device::physical::PhysicalDevice,
) -> Result<(), crate::RequirementNotMet> {
) -> Result<(), Box<crate::ValidationError>> {
self.validate_device_raw(
physical_device.api_version(),
physical_device.supported_features(),
Expand All @@ -511,7 +512,7 @@ fn formats_output(members: &[FormatMember]) -> TokenStream {
#[allow(unused_variables)] device_features: &crate::device::Features,
#[allow(unused_variables)] device_extensions: &crate::device::DeviceExtensions,
#[allow(unused_variables)] instance_extensions: &crate::instance::InstanceExtensions,
) -> Result<(), crate::RequirementNotMet> {
) -> Result<(), Box<crate::ValidationError>> {
match self {
#(#validate_device_items)*
}
Expand Down
108 changes: 41 additions & 67 deletions vulkano/src/acceleration_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,14 @@ impl AccelerationStructureCreateInfo {
_ne: _,
} = self;

create_flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "create_flags".into(),
vuids: &["VUID-VkAccelerationStructureCreateInfoKHR-createFlags-parameter"],
..ValidationError::from_requirement(err)
})?;

ty.validate_device(device).map_err(|err| ValidationError {
context: "ty".into(),
vuids: &["VUID-VkAccelerationStructureCreateInfoKHR-type-parameter"],
..ValidationError::from_requirement(err)
create_flags.validate_device(device).map_err(|err| {
err.add_context("create_flags")
.set_vuids(&["VUID-VkAccelerationStructureCreateInfoKHR-createFlags-parameter"])
})?;

ty.validate_device(device).map_err(|err| {
err.add_context("ty")
.set_vuids(&["VUID-VkAccelerationStructureCreateInfoKHR-type-parameter"])
})?;

if !buffer
Expand Down Expand Up @@ -513,13 +509,10 @@ impl AccelerationStructureBuildGeometryInfo {
_ne: _,
} = self;

flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-parameter"],
..ValidationError::from_requirement(err)
})?;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkAccelerationStructureBuildGeometryInfoKHR-flags-parameter"])
})?;

let max_geometry_count = device
.physical_device()
Expand Down Expand Up @@ -1009,23 +1002,16 @@ impl AccelerationStructureGeometryTrianglesData {
_ne: _,
} = self;

flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"],
..ValidationError::from_requirement(err)
})?;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"])
})?;

vertex_format
.validate_device(device)
.map_err(|err| ValidationError {
context: "vertex_format".into(),
vuids: &[
"VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexFormat-parameter",
],
..ValidationError::from_requirement(err)
})?;
vertex_format.validate_device(device).map_err(|err| {
err.add_context("vertex_format").set_vuids(&[
"VUID-VkAccelerationStructureGeometryTrianglesDataKHR-vertexFormat-parameter",
])
})?;

if unsafe {
!device
Expand Down Expand Up @@ -1127,13 +1113,10 @@ impl AccelerationStructureGeometryAabbsData {
_ne: _,
} = self;

flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"],
..ValidationError::from_requirement(err)
})?;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"])
})?;

if stride % 8 != 0 {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -1199,13 +1182,10 @@ impl AccelerationStructureGeometryInstancesData {
_ne: _,
} = self;

flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"],
..ValidationError::from_requirement(err)
})?;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkAccelerationStructureGeometryKHR-flags-parameter"])
})?;

Ok(())
}
Expand Down Expand Up @@ -1402,12 +1382,10 @@ impl CopyAccelerationStructureInfo {
assert_eq!(device, src.device().as_ref());
assert_eq!(device, dst.device().as_ref());

mode.validate_device(device)
.map_err(|err| ValidationError {
context: "mode".into(),
vuids: &["VUID-VkCopyAccelerationStructureInfoKHR-mode-parameter"],
..ValidationError::from_requirement(err)
})?;
mode.validate_device(device).map_err(|err| {
err.add_context("mode")
.set_vuids(&["VUID-VkCopyAccelerationStructureInfoKHR-mode-parameter"])
})?;

if !matches!(
mode,
Expand Down Expand Up @@ -1485,12 +1463,10 @@ impl CopyAccelerationStructureToMemoryInfo {
assert_eq!(device, src.device().as_ref());
assert_eq!(device, dst.device().as_ref());

mode.validate_device(device)
.map_err(|err| ValidationError {
context: "mode".into(),
vuids: &["VUID-VkCopyAccelerationStructureToMemoryInfoKHR-mode-parameter"],
..ValidationError::from_requirement(err)
})?;
mode.validate_device(device).map_err(|err| {
err.add_context("mode")
.set_vuids(&["VUID-VkCopyAccelerationStructureToMemoryInfoKHR-mode-parameter"])
})?;

if !matches!(mode, CopyAccelerationStructureMode::Serialize) {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -1555,12 +1531,10 @@ impl CopyMemoryToAccelerationStructureInfo {
assert_eq!(device, src.device().as_ref());
assert_eq!(device, dst.device().as_ref());

mode.validate_device(device)
.map_err(|err| ValidationError {
context: "mode".into(),
vuids: &["VUID-VkCopyMemoryToAccelerationStructureInfoKHR-mode-parameter"],
..ValidationError::from_requirement(err)
})?;
mode.validate_device(device).map_err(|err| {
err.add_context("mode")
.set_vuids(&["VUID-VkCopyMemoryToAccelerationStructureInfoKHR-mode-parameter"])
})?;

if !matches!(mode, CopyAccelerationStructureMode::Deserialize) {
return Err(Box::new(ValidationError {
Expand Down
21 changes: 9 additions & 12 deletions vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,18 +912,16 @@ impl ExternalBufferInfo {

flags
.validate_physical_device(physical_device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkPhysicalDeviceExternalBufferInfo-flags-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkPhysicalDeviceExternalBufferInfo-flags-parameter"])
})?;

usage
.validate_physical_device(physical_device)
.map_err(|err| ValidationError {
context: "usage".into(),
vuids: &["VUID-VkPhysicalDeviceExternalBufferInfo-usage-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("usage")
.set_vuids(&["VUID-VkPhysicalDeviceExternalBufferInfo-usage-parameter"])
})?;

if usage.is_empty() {
Expand All @@ -937,10 +935,9 @@ impl ExternalBufferInfo {

handle_type
.validate_physical_device(physical_device)
.map_err(|err| ValidationError {
context: "handle_type".into(),
vuids: &["VUID-VkPhysicalDeviceExternalBufferInfo-handleType-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("handle_type")
.set_vuids(&["VUID-VkPhysicalDeviceExternalBufferInfo-handleType-parameter"])
})?;

Ok(())
Expand Down
24 changes: 12 additions & 12 deletions vulkano/src/buffer/subbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ where
};
}

let mapped_ptr =
self.mapped_ptr()
.ok_or(HostAccessError::ValidationError(ValidationError {
problem: "the memory of this subbuffer is not host-visible".into(),
..Default::default()
}))?;
let mapped_ptr = self.mapped_ptr().ok_or_else(|| {
HostAccessError::ValidationError(Box::new(ValidationError {
problem: "the memory of this subbuffer is not host-visible".into(),
..Default::default()
}))
})?;
// SAFETY: `Subbuffer` guarantees that its contents are laid out correctly for `T`.
let data = unsafe { &*T::from_ffi(mapped_ptr.as_ptr(), self.size as usize) };

Expand Down Expand Up @@ -415,12 +415,12 @@ where
};
}

let mapped_ptr =
self.mapped_ptr()
.ok_or(HostAccessError::ValidationError(ValidationError {
problem: "the memory of this subbuffer is not host-visible".into(),
..Default::default()
}))?;
let mapped_ptr = self.mapped_ptr().ok_or_else(|| {
HostAccessError::ValidationError(Box::new(ValidationError {
problem: "the memory of this subbuffer is not host-visible".into(),
..Default::default()
}))
})?;
// SAFETY: `Subbuffer` guarantees that its contents are laid out correctly for `T`.
let data = unsafe { &mut *T::from_ffi(mapped_ptr.as_ptr(), self.size as usize) };

Expand Down
31 changes: 12 additions & 19 deletions vulkano/src/buffer/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,21 +674,15 @@ impl BufferCreateInfo {
_ne: _,
} = self;

flags
.validate_device(device)
.map_err(|err| ValidationError {
context: "flags".into(),
vuids: &["VUID-VkBufferCreateInfo-flags-parameter"],
..ValidationError::from_requirement(err)
})?;

usage
.validate_device(device)
.map_err(|err| ValidationError {
context: "usage".into(),
vuids: &["VUID-VkBufferCreateInfo-usage-parameter"],
..ValidationError::from_requirement(err)
})?;
flags.validate_device(device).map_err(|err| {
err.add_context("flags")
.set_vuids(&["VUID-VkBufferCreateInfo-flags-parameter"])
})?;

usage.validate_device(device).map_err(|err| {
err.add_context("usage")
.set_vuids(&["VUID-VkBufferCreateInfo-usage-parameter"])
})?;

if usage.is_empty() {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -819,10 +813,9 @@ impl BufferCreateInfo {

external_memory_handle_types
.validate_device(device)
.map_err(|err| ValidationError {
context: "external_memory_handle_types".into(),
vuids: &["VUID-VkExternalMemoryBufferCreateInfo-handleTypes-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("external_memory_handle_types")
.set_vuids(&["VUID-VkExternalMemoryBufferCreateInfo-handleTypes-parameter"])
})?;

// TODO:
Expand Down
11 changes: 4 additions & 7 deletions vulkano/src/buffer/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,10 @@ impl BufferViewCreateInfo {
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
let Self { format, _ne: _ } = self;

format
.validate_device(device)
.map_err(|err| ValidationError {
context: "format".into(),
vuids: &["VUID-VkBufferViewCreateInfo-format-parameter"],
..ValidationError::from_requirement(err)
})?;
format.validate_device(device).map_err(|err| {
err.add_context("format")
.set_vuids(&["VUID-VkBufferViewCreateInfo-format-parameter"])
})?;

Ok(())
}
Expand Down
14 changes: 6 additions & 8 deletions vulkano/src/command_buffer/commands/bind_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,9 @@ where
) -> Result<(), Box<ValidationError>> {
pipeline_bind_point
.validate_device(self.device())
.map_err(|err| ValidationError {
context: "pipeline_bind_point".into(),
vuids: &["VUID-vkCmdBindDescriptorSets-pipelineBindPoint-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("pipeline_bind_point")
.set_vuids(&["VUID-vkCmdBindDescriptorSets-pipelineBindPoint-parameter"])
})?;

let queue_family_properties = self.queue_family_properties();
Expand Down Expand Up @@ -1185,10 +1184,9 @@ where

pipeline_bind_point
.validate_device(self.device())
.map_err(|err| ValidationError {
context: "pipeline_bind_point".into(),
vuids: &["VUID-vkCmdPushDescriptorSetKHR-pipelineBindPoint-parameter"],
..ValidationError::from_requirement(err)
.map_err(|err| {
err.add_context("pipeline_bind_point")
.set_vuids(&["VUID-vkCmdPushDescriptorSetKHR-pipelineBindPoint-parameter"])
})?;

let queue_family_properties = self.queue_family_properties();
Expand Down
Loading