Skip to content

Commit

Permalink
Fix validation for physical device surface methods (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rua authored Sep 11, 2022
1 parent e3ebcbf commit 34f0a38
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
70 changes: 69 additions & 1 deletion vulkano/src/device/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,21 @@ impl PhysicalDevice {
surface: &Surface<W>,
surface_info: &SurfaceInfo,
) -> Result<(), SurfacePropertiesError> {
if !(self
.instance
.enabled_extensions()
.khr_get_surface_capabilities2
|| self.instance.enabled_extensions().khr_surface)
{
return Err(SurfacePropertiesError::RequirementNotMet {
required_for: "`surface_capabilities`",
requires_one_of: RequiresOneOf {
instance_extensions: &["khr_get_surface_capabilities2", "khr_surface"],
..Default::default()
},
});
}

// VUID-vkGetPhysicalDeviceSurfaceCapabilities2KHR-commonparent
assert_eq!(self.instance(), surface.instance());

Expand Down Expand Up @@ -1356,6 +1371,21 @@ impl PhysicalDevice {
surface: &Surface<W>,
surface_info: &SurfaceInfo,
) -> Result<(), SurfacePropertiesError> {
if !(self
.instance
.enabled_extensions()
.khr_get_surface_capabilities2
|| self.instance.enabled_extensions().khr_surface)
{
return Err(SurfacePropertiesError::RequirementNotMet {
required_for: "`surface_formats`",
requires_one_of: RequiresOneOf {
instance_extensions: &["khr_get_surface_capabilities2", "khr_surface"],
..Default::default()
},
});
}

// VUID-vkGetPhysicalDeviceSurfaceFormats2KHR-commonparent
assert_eq!(self.instance(), surface.instance());

Expand Down Expand Up @@ -1551,6 +1581,16 @@ impl PhysicalDevice {
&self,
surface: &Surface<W>,
) -> Result<(), SurfacePropertiesError> {
if !self.instance.enabled_extensions().khr_surface {
return Err(SurfacePropertiesError::RequirementNotMet {
required_for: "`surface_present_modes`",
requires_one_of: RequiresOneOf {
instance_extensions: &["khr_surface"],
..Default::default()
},
});
}

// VUID-vkGetPhysicalDeviceSurfacePresentModesKHR-commonparent
assert_eq!(self.instance(), surface.instance());

Expand Down Expand Up @@ -1624,9 +1664,22 @@ impl PhysicalDevice {
queue_family_index: u32,
_surface: &Surface<W>,
) -> Result<(), SurfacePropertiesError> {
if !self.instance.enabled_extensions().khr_surface {
return Err(SurfacePropertiesError::RequirementNotMet {
required_for: "`surface_support`",
requires_one_of: RequiresOneOf {
instance_extensions: &["khr_surface"],
..Default::default()
},
});
}

// VUID-vkGetPhysicalDeviceSurfaceSupportKHR-queueFamilyIndex-01269
if queue_family_index >= self.queue_family_properties.len() as u32 {
todo!()
return Err(SurfacePropertiesError::QueueFamilyIndexOutOfRange {
queue_family_index,
queue_family_count: self.queue_family_properties.len() as u32,
});
}

Ok(())
Expand Down Expand Up @@ -2034,6 +2087,11 @@ pub enum SurfacePropertiesError {
// The given `SurfaceInfo` values are not supported for the surface by the physical device.
NotSupported,

RequirementNotMet {
required_for: &'static str,
requires_one_of: RequiresOneOf,
},

/// The provided `queue_family_index` was not less than the number of queue families in the
/// physical device.
QueueFamilyIndexOutOfRange {
Expand Down Expand Up @@ -2068,6 +2126,16 @@ impl Display for SurfacePropertiesError {
f,
"the given `SurfaceInfo` values are not supported for the surface by the physical device",
),

Self::RequirementNotMet {
required_for,
requires_one_of,
} => write!(
f,
"a requirement was not met for: {}; requires one of: {}",
required_for, requires_one_of,
),

Self::QueueFamilyIndexOutOfRange {
queue_family_index,
queue_family_count,
Expand Down
1 change: 1 addition & 0 deletions vulkano/src/swapchain/swapchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ impl From<SurfacePropertiesError> for SwapchainCreationError {
SurfacePropertiesError::SurfaceLost => Self::SurfaceLost,
SurfacePropertiesError::NotSupported => unreachable!(),
SurfacePropertiesError::QueueFamilyIndexOutOfRange { .. } => unreachable!(),
SurfacePropertiesError::RequirementNotMet { .. } => unreachable!(),
}
}
}
Expand Down

0 comments on commit 34f0a38

Please sign in to comment.