Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix allocation type validation in RawImage::bind_memory #2256

Merged
merged 4 commits into from
Jul 8, 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
2 changes: 1 addition & 1 deletion vulkano/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ vulkan_enum! {
/// ```
#[inline]
pub fn max_mip_levels(extent: [u32; 3]) -> u32 {
// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#resources-image-miplevel-sizing
// https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#resources-image-mip-level-sizing
//
// This calculates `floor(log2(max(width, height, depth))) + 1` using fast integer operations.
32 - (extent[0] | extent[1] | extent[2]).leading_zeros()
Expand Down
52 changes: 36 additions & 16 deletions vulkano/src/image/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,8 @@ impl RawImage {
return Err(Box::new(ValidationError {
problem: "`self.flags()` contains `ImageCreateFlags::DISJOINT`, and \
`self.tiling()` is `ImageTiling::Optimal` or \
`ImageTiling::Linear`, but \
the length of `allocations` does not equal \
the number of planes in the format of the image"
`ImageTiling::Linear`, but the length of `allocations` does not \
equal the number of planes in the format of the image"
.into(),
..Default::default()
}));
Expand All @@ -749,10 +748,9 @@ impl RawImage {
if allocations.len() != self.drm_format_modifier.unwrap().1 as usize {
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 \
the number of memory planes of the DRM format modifier of the \
image"
`self.tiling()` is `ImageTiling::DrmFormatModifier`, but the \
length of `allocations` does not equal the number of memory planes \
of the DRM format modifier of the image"
.into(),
..Default::default()
}));
Expand All @@ -774,15 +772,37 @@ impl RawImage {
.zip(self.memory_requirements.iter())
.enumerate()
{
if allocation.allocation_type() == AllocationType::Linear {
return Err(Box::new(ValidationError {
problem: format!(
"`allocations[{}].allocation_type()` is `AllocationType::Linear`",
index
)
.into(),
..Default::default()
}));
match allocation.allocation_type() {
AllocationType::Unknown => {
// This allocation type is suitable for all image tilings by definition.
}
AllocationType::Linear => {
if self.tiling() != ImageTiling::Linear {
return Err(Box::new(ValidationError {
problem: format!(
"`allocations[{}].allocation_type()` is `AllocationType::Linear`, \
but `self.tiling()` is not `ImageTiling::Linear`",
marc0246 marked this conversation as resolved.
Show resolved Hide resolved
index
)
.into(),
..Default::default()
}));
}
}
AllocationType::NonLinear => {
if self.tiling() != ImageTiling::Optimal {
return Err(Box::new(ValidationError {
problem: format!(
"`allocations[{}].allocation_type()` is \
`AllocationType::NonLinear`, but `self.tiling()` is not \
`ImageTiling::Optimal`",
index
)
.into(),
..Default::default()
}));
}
}
}

let memory = allocation.device_memory();
Expand Down
2 changes: 1 addition & 1 deletion vulkano/src/memory/allocator/suballocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl From<ImageTiling> for AllocationType {
match tiling {
ImageTiling::Optimal => AllocationType::NonLinear,
ImageTiling::Linear => AllocationType::Linear,
ImageTiling::DrmFormatModifier => AllocationType::Linear, // TODO: improve
ImageTiling::DrmFormatModifier => AllocationType::Unknown,
}
}
}
Expand Down