Skip to content

Commit

Permalink
Fix alignment checks when allocating buffers (#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0246 authored Feb 27, 2024
1 parent 89e75ca commit 817436b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
6 changes: 0 additions & 6 deletions vulkano/src/buffer/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
2 changes: 0 additions & 2 deletions vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 4 additions & 0 deletions vulkano/src/buffer/subbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 817436b

Please sign in to comment.