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

Add missing validation to DeviceMemory #2057

Merged
merged 1 commit into from
Oct 30, 2022
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
16 changes: 8 additions & 8 deletions vulkano/src/memory/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,22 +878,22 @@ impl<S: Suballocator> GenericMemoryAllocator<S> {
let memory_type = &self.pools[memory_type_index as usize].memory_type;
// VUID-VkMemoryAllocateInfo-memoryTypeIndex-01872
assert!(
!memory_type
memory_type
.property_flags
.contains(ash::vk::MemoryPropertyFlags::PROTECTED)
|| self.device.enabled_features().protected_memory,
&& !self.device.enabled_features().protected_memory,
"attempted to allocate from a protected memory type without the `protected_memory` \
feature being enabled on the device",
);

// VUID-vkAllocateMemory-deviceCoherentMemory-02790
assert!(
!memory_type.property_flags.intersects(
ash::vk::MemoryPropertyFlags::DEVICE_COHERENT_AMD
| ash::vk::MemoryPropertyFlags::DEVICE_UNCACHED_AMD
) || self.device.enabled_features().device_coherent_memory,
"attempted to allocate memory from a device-coherent/device-uncached memory type \
without the `device_coherent_memory` feature being enabled on the device",
memory_type
.property_flags
.contains(ash::vk::MemoryPropertyFlags::DEVICE_COHERENT_AMD)
&& !self.device.enabled_features().device_coherent_memory,
"attempted to allocate memory from a device-coherent memory type without the \
`device_coherent_memory` feature being enabled on the device",
);

let block_size = self.block_sizes[memory_type.heap_index as usize];
Expand Down
17 changes: 16 additions & 1 deletion vulkano/src/memory/device_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ impl DeviceMemory {
// VUID-VkMemoryAllocateInfo-memoryTypeIndex-01872
if memory_type.property_flags.protected && !device.enabled_features().protected_memory {
return Err(DeviceMemoryError::RequirementNotMet {
required_for: "`allocate_info.memory_type_index` refers to a memory type where `property_flags.protected` is set",
required_for: "`allocate_info.memory_type_index` refers to a memory type where \
`property_flags.protected` is set",
requires_one_of: RequiresOneOf {
features: &["protected_memory"],
..Default::default()
Expand All @@ -193,6 +194,20 @@ impl DeviceMemory {
});
}

// VUID-vkAllocateMemory-deviceCoherentMemory-02790
if memory_type.property_flags.device_coherent
&& !device.enabled_features().device_coherent_memory
{
return Err(DeviceMemoryError::RequirementNotMet {
required_for: "`allocate_info.memory_type_index` refers to a memory type where \
`property_flags.device_coherent` is set",
requires_one_of: RequiresOneOf {
features: &["device_coherent_memory"],
..Default::default()
},
});
}

if let Some(dedicated_allocation) = dedicated_allocation {
match dedicated_allocation {
DedicatedAllocation::Buffer(buffer) => {
Expand Down