Skip to content

Commit

Permalink
Fix validation and errors in MemoryAllocator (vulkano-rs#2306)
Browse files Browse the repository at this point in the history
* Fix validation and errors in `MemoryAllocator`

* Doc tests

* Update vulkano/src/memory/allocator/mod.rs

Co-authored-by: Rua <ruawhitepaw@gmail.com>

---------

Co-authored-by: Rua <ruawhitepaw@gmail.com>
  • Loading branch information
2 people authored and hakolao committed Feb 20, 2024
1 parent e0366da commit a1c6785
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 381 deletions.
18 changes: 8 additions & 10 deletions vulkano/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,14 @@ impl Buffer {
let mut requirements = *raw_buffer.memory_requirements();
requirements.layout = requirements.layout.align_to(layout.alignment()).unwrap();

let allocation = unsafe {
allocator
.allocate_unchecked(
requirements,
AllocationType::Linear,
allocation_info,
Some(DedicatedAllocation::Buffer(&raw_buffer)),
)
.map_err(BufferAllocateError::AllocateMemory)?
};
let allocation = allocator
.allocate(
requirements,
AllocationType::Linear,
allocation_info,
Some(DedicatedAllocation::Buffer(&raw_buffer)),
)
.map_err(BufferAllocateError::AllocateMemory)?;

let buffer = raw_buffer.bind_memory(allocation).map_err(|(err, _, _)| {
err.map(BufferAllocateError::BindMemory)
Expand Down
18 changes: 8 additions & 10 deletions vulkano/src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,14 @@ impl Image {
})?;
let requirements = raw_image.memory_requirements()[0];

let allocation = unsafe {
allocator
.allocate_unchecked(
requirements,
allocation_type,
allocation_info,
Some(DedicatedAllocation::Image(&raw_image)),
)
.map_err(ImageAllocateError::AllocateMemory)?
};
let allocation = allocator
.allocate(
requirements,
allocation_type,
allocation_info,
Some(DedicatedAllocation::Image(&raw_image)),
)
.map_err(ImageAllocateError::AllocateMemory)?;

let image = raw_image.bind_memory([allocation]).map_err(|(err, _, _)| {
err.map(ImageAllocateError::BindMemory)
Expand Down
Loading

0 comments on commit a1c6785

Please # to comment.