mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2025-02-16 17:12:29 +00:00
Remove duplicate validation in GenericMemoryAllocator
(#2336)
* Remove duplicate validation * Merge `GenericMemoryAllocator::new[_unchecked]` * Fix oopsie from earlier PR
This commit is contained in:
parent
44732afefe
commit
b49476036c
@ -235,8 +235,7 @@ use super::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
device::{Device, DeviceOwned},
|
device::{Device, DeviceOwned},
|
||||||
instance::InstanceOwnedDebugWrapper,
|
instance::InstanceOwnedDebugWrapper,
|
||||||
DeviceSize, Requires, RequiresAllOf, RequiresOneOf, Validated, ValidationError, Version,
|
DeviceSize, Validated, Version, VulkanError,
|
||||||
VulkanError,
|
|
||||||
};
|
};
|
||||||
use ash::vk::MAX_MEMORY_TYPES;
|
use ash::vk::MAX_MEMORY_TYPES;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
@ -855,7 +854,7 @@ impl StandardMemoryAllocator {
|
|||||||
memory_heaps,
|
memory_heaps,
|
||||||
} = device.physical_device().memory_properties();
|
} = device.physical_device().memory_properties();
|
||||||
|
|
||||||
let mut block_sizes = [0; MAX_MEMORY_TYPES];
|
let mut block_sizes = vec![0; memory_types.len()];
|
||||||
let mut memory_type_bits = u32::MAX;
|
let mut memory_type_bits = u32::MAX;
|
||||||
|
|
||||||
for (index, memory_type) in memory_types.iter().enumerate() {
|
for (index, memory_type) in memory_types.iter().enumerate() {
|
||||||
@ -888,7 +887,7 @@ impl StandardMemoryAllocator {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
unsafe { Self::new_unchecked(device, create_info) }
|
Self::new(device, create_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,31 +968,7 @@ impl<S> GenericMemoryAllocator<S> {
|
|||||||
/// memory types.
|
/// memory types.
|
||||||
/// - Panics if `create_info.export_handle_types` is non-empty and doesn't contain as many
|
/// - Panics if `create_info.export_handle_types` is non-empty and doesn't contain as many
|
||||||
/// elements as the number of memory types.
|
/// elements as the number of memory types.
|
||||||
pub fn new(
|
pub fn new(device: Arc<Device>, create_info: GenericMemoryAllocatorCreateInfo<'_>) -> Self {
|
||||||
device: Arc<Device>,
|
|
||||||
create_info: GenericMemoryAllocatorCreateInfo<'_>,
|
|
||||||
) -> Result<Self, Box<ValidationError>> {
|
|
||||||
Self::validate_new(&device, &create_info)?;
|
|
||||||
|
|
||||||
Ok(unsafe { Self::new_unchecked(device, create_info) })
|
|
||||||
}
|
|
||||||
|
|
||||||
fn validate_new(
|
|
||||||
device: &Device,
|
|
||||||
create_info: &GenericMemoryAllocatorCreateInfo<'_>,
|
|
||||||
) -> Result<(), Box<ValidationError>> {
|
|
||||||
create_info
|
|
||||||
.validate(device)
|
|
||||||
.map_err(|err| err.add_context("create_info"))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
|
|
||||||
pub unsafe fn new_unchecked(
|
|
||||||
device: Arc<Device>,
|
|
||||||
create_info: GenericMemoryAllocatorCreateInfo<'_>,
|
|
||||||
) -> Self {
|
|
||||||
let GenericMemoryAllocatorCreateInfo {
|
let GenericMemoryAllocatorCreateInfo {
|
||||||
block_sizes,
|
block_sizes,
|
||||||
memory_type_bits,
|
memory_type_bits,
|
||||||
@ -1003,6 +978,23 @@ impl<S> GenericMemoryAllocator<S> {
|
|||||||
_ne: _,
|
_ne: _,
|
||||||
} = create_info;
|
} = create_info;
|
||||||
|
|
||||||
|
let memory_types = &device.physical_device().memory_properties().memory_types;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
block_sizes.len(),
|
||||||
|
memory_types.len(),
|
||||||
|
"`create_info.block_sizes` must contain as many elements as the number of memory types",
|
||||||
|
);
|
||||||
|
|
||||||
|
if !export_handle_types.is_empty() {
|
||||||
|
assert_eq!(
|
||||||
|
export_handle_types.len(),
|
||||||
|
memory_types.len(),
|
||||||
|
"`create_info.export_handle_types` must contain as many elements as the number of \
|
||||||
|
memory types if not empty",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let buffer_image_granularity = device
|
let buffer_image_granularity = device
|
||||||
.physical_device()
|
.physical_device()
|
||||||
.properties()
|
.properties()
|
||||||
@ -1685,56 +1677,6 @@ pub struct GenericMemoryAllocatorCreateInfo<'a> {
|
|||||||
pub _ne: crate::NonExhaustive,
|
pub _ne: crate::NonExhaustive,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GenericMemoryAllocatorCreateInfo<'_> {
|
|
||||||
pub(crate) fn validate(&self, device: &Device) -> Result<(), Box<ValidationError>> {
|
|
||||||
let &Self {
|
|
||||||
block_sizes,
|
|
||||||
memory_type_bits: _,
|
|
||||||
dedicated_allocation: _,
|
|
||||||
export_handle_types,
|
|
||||||
device_address: _,
|
|
||||||
_ne: _,
|
|
||||||
} = self;
|
|
||||||
|
|
||||||
let memory_types = &device.physical_device().memory_properties().memory_types;
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
block_sizes.len() == memory_types.len(),
|
|
||||||
"`create_info.block_sizes` must contain as many elements as the number of memory types",
|
|
||||||
);
|
|
||||||
|
|
||||||
if !export_handle_types.is_empty() {
|
|
||||||
if !(device.api_version() >= Version::V1_1
|
|
||||||
&& device.enabled_extensions().khr_external_memory)
|
|
||||||
{
|
|
||||||
return Err(Box::new(ValidationError {
|
|
||||||
context: "export_handle_types".into(),
|
|
||||||
problem: "is not empty".into(),
|
|
||||||
requires_one_of: RequiresOneOf(&[
|
|
||||||
RequiresAllOf(&[Requires::APIVersion(Version::V1_1)]),
|
|
||||||
RequiresAllOf(&[Requires::DeviceExtension("khr_external_memory")]),
|
|
||||||
]),
|
|
||||||
..Default::default()
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
export_handle_types.len() == memory_types.len(),
|
|
||||||
"`create_info.export_handle_types` must contain as many elements as the number of \
|
|
||||||
memory types if not empty",
|
|
||||||
);
|
|
||||||
|
|
||||||
for (index, export_handle_types) in export_handle_types.iter().enumerate() {
|
|
||||||
export_handle_types
|
|
||||||
.validate_device(device)
|
|
||||||
.map_err(|err| err.add_context(format!("export_handle_types[{}]", index)))?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for GenericMemoryAllocatorCreateInfo<'_> {
|
impl Default for GenericMemoryAllocatorCreateInfo<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user