Skip to content

Commit

Permalink
Fix allocation type validation in RawImage::bind_memory (vulkano-rs…
Browse files Browse the repository at this point in the history
…#2256)

* Fix allocation type validation in `RawImage::bind_memory`

* Fix a link

* Fix DRM format modifier image tiling to allocaion type convertion

* Add commas
  • Loading branch information
marc0246 authored and hakolao committed Feb 20, 2024
1 parent a546f5d commit f45f014
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
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`",
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

0 comments on commit f45f014

Please # to comment.