From 817436b13cece56d930ed63b14c8a8219675621d Mon Sep 17 00:00:00 2001 From: marc0246 <40955683+marc0246@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:59:59 +0100 Subject: [PATCH] Fix alignment checks when allocating buffers (#2476) --- vulkano/src/buffer/allocator.rs | 6 ------ vulkano/src/buffer/mod.rs | 2 -- vulkano/src/buffer/subbuffer.rs | 4 ++++ 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/vulkano/src/buffer/allocator.rs b/vulkano/src/buffer/allocator.rs index ad1929cf..88324584 100644 --- a/vulkano/src/buffer/allocator.rs +++ b/vulkano/src/buffer/allocator.rs @@ -252,13 +252,7 @@ where } /// Allocates a subbuffer with the given `layout`. - /// - /// # Panics - /// - /// - Panics if `layout.alignment()` exceeds `64`. pub fn allocate(&self, layout: DeviceLayout) -> Result, MemoryAllocatorError> { - assert!(layout.alignment().as_devicesize() <= 64); - unsafe { &mut *self.state.get() }.allocate(layout) } } diff --git a/vulkano/src/buffer/mod.rs b/vulkano/src/buffer/mod.rs index 46ee0043..14340a67 100644 --- a/vulkano/src/buffer/mod.rs +++ b/vulkano/src/buffer/mod.rs @@ -376,14 +376,12 @@ impl Buffer { /// # Panics /// /// - Panics if `create_info.size` is not zero. - /// - Panics if `layout.alignment()` is greater than 64. pub fn new( allocator: Arc, mut create_info: BufferCreateInfo, allocation_info: AllocationCreateInfo, layout: DeviceLayout, ) -> Result, Validated> { - assert!(layout.alignment().as_devicesize() <= 64); // TODO: Enable once sparse binding materializes // assert!(!allocate_info.flags.contains(BufferCreateFlags::SPARSE_BINDING)); diff --git a/vulkano/src/buffer/subbuffer.rs b/vulkano/src/buffer/subbuffer.rs index 3bc27100..77accb1c 100644 --- a/vulkano/src/buffer/subbuffer.rs +++ b/vulkano/src/buffer/subbuffer.rs @@ -300,6 +300,8 @@ where /// [`SubbufferAllocator`]: super::allocator::SubbufferAllocator /// [`RawBuffer::assume_bound`]: crate::buffer::sys::RawBuffer::assume_bound pub fn read(&self) -> Result, HostAccessError> { + assert!(T::LAYOUT.alignment().as_devicesize() <= 64); + let allocation = match self.buffer().memory() { BufferMemory::Normal(a) => a, BufferMemory::Sparse => todo!("`Subbuffer::read` doesn't support sparse binding yet"), @@ -391,6 +393,8 @@ where /// [`SubbufferAllocator`]: super::allocator::SubbufferAllocator /// [`RawBuffer::assume_bound`]: crate::buffer::sys::RawBuffer::assume_bound pub fn write(&self) -> Result, HostAccessError> { + assert!(T::LAYOUT.alignment().as_devicesize() <= 64); + let allocation = match self.buffer().memory() { BufferMemory::Normal(a) => a, BufferMemory::Sparse => todo!("`Subbuffer::write` doesn't support sparse binding yet"),