Fix alignment checks when allocating buffers (#2476)

This commit is contained in:
marc0246 2024-02-27 14:59:59 +01:00 committed by GitHub
parent 89e75cae2d
commit 817436b13c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 8 deletions

View File

@ -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<Subbuffer<[u8]>, MemoryAllocatorError> {
assert!(layout.alignment().as_devicesize() <= 64);
unsafe { &mut *self.state.get() }.allocate(layout)
}
}

View File

@ -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<dyn MemoryAllocator>,
mut create_info: BufferCreateInfo,
allocation_info: AllocationCreateInfo,
layout: DeviceLayout,
) -> Result<Arc<Self>, Validated<AllocateBufferError>> {
assert!(layout.alignment().as_devicesize() <= 64);
// TODO: Enable once sparse binding materializes
// assert!(!allocate_info.flags.contains(BufferCreateFlags::SPARSE_BINDING));

View File

@ -300,6 +300,8 @@ where
/// [`SubbufferAllocator`]: super::allocator::SubbufferAllocator
/// [`RawBuffer::assume_bound`]: crate::buffer::sys::RawBuffer::assume_bound
pub fn read(&self) -> Result<BufferReadGuard<'_, T>, 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<BufferWriteGuard<'_, T>, 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"),