From e562575b1b176977205f12482af694726b83ea09 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Sat, 8 Jul 2023 11:22:40 +0200 Subject: [PATCH 1/4] Fix allocation type validation in `RawImage::bind_memory` --- vulkano/src/image/sys.rs | 52 +++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index 5c78575a66..f5f9a9f75a 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -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() })); @@ -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() })); @@ -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(); From c820c966fd9aa112157ec57e006c4f3423b462ec Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Sat, 8 Jul 2023 11:23:43 +0200 Subject: [PATCH 2/4] Fix a link --- vulkano/src/image/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vulkano/src/image/mod.rs b/vulkano/src/image/mod.rs index d117cf21ff..8027746b7c 100644 --- a/vulkano/src/image/mod.rs +++ b/vulkano/src/image/mod.rs @@ -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() From c39dd2ce5753f1e5a501c88dcc505b47ded61b00 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Sat, 8 Jul 2023 11:26:27 +0200 Subject: [PATCH 3/4] Fix DRM format modifier image tiling to allocaion type convertion --- vulkano/src/memory/allocator/suballocator.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vulkano/src/memory/allocator/suballocator.rs b/vulkano/src/memory/allocator/suballocator.rs index 1377e471c9..afe7c5af13 100644 --- a/vulkano/src/memory/allocator/suballocator.rs +++ b/vulkano/src/memory/allocator/suballocator.rs @@ -773,7 +773,7 @@ impl From for AllocationType { match tiling { ImageTiling::Optimal => AllocationType::NonLinear, ImageTiling::Linear => AllocationType::Linear, - ImageTiling::DrmFormatModifier => AllocationType::Linear, // TODO: improve + ImageTiling::DrmFormatModifier => AllocationType::Unknown, } } } From 2e597379866a27b210ee01261dc2772d823ffbe4 Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Sat, 8 Jul 2023 11:39:17 +0200 Subject: [PATCH 4/4] Add commas --- vulkano/src/image/sys.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vulkano/src/image/sys.rs b/vulkano/src/image/sys.rs index f5f9a9f75a..7ccd1c5a77 100644 --- a/vulkano/src/image/sys.rs +++ b/vulkano/src/image/sys.rs @@ -780,7 +780,7 @@ impl RawImage { if self.tiling() != ImageTiling::Linear { return Err(Box::new(ValidationError { problem: format!( - "`allocations[{}].allocation_type()` is `AllocationType::Linear` \ + "`allocations[{}].allocation_type()` is `AllocationType::Linear`, \ but `self.tiling()` is not `ImageTiling::Linear`", index ) @@ -794,7 +794,7 @@ impl RawImage { return Err(Box::new(ValidationError { problem: format!( "`allocations[{}].allocation_type()` is \ - `AllocationType::NonLinear` but `self.tiling()` is not \ + `AllocationType::NonLinear`, but `self.tiling()` is not \ `ImageTiling::Optimal`", index )