Skip to content

Add option to disallow increasing capacity when allocating #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ let allocation = allocator
location: MemoryLocation::CpuToGpu,
linear: true, // Buffers are always linear
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
allow_capacity_increase: true,
}).unwrap();

// Bind memory to the buffer
Expand Down
3 changes: 3 additions & 0 deletions examples/vulkan-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fn main() {
linear: true,
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
name: "Test allocation (Gpu Only)",
allow_capacity_increase: true,
})
.unwrap();

Expand Down Expand Up @@ -143,6 +144,7 @@ fn main() {
linear: true,
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
name: "Test allocation (Cpu to Gpu)",
allow_capacity_increase: true,
})
.unwrap();

Expand Down Expand Up @@ -176,6 +178,7 @@ fn main() {
linear: true,
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
name: "Test allocation (Gpu to Cpu)",
allow_capacity_increase: true,
})
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
//! location: MemoryLocation::CpuToGpu,
//! linear: true, // Buffers are always linear
//! allocation_scheme: AllocationScheme::GpuAllocatorManaged,
//! allow_capacity_increase: true,
//! }).unwrap();
//!
//! // Bind memory to the buffer
Expand Down
6 changes: 6 additions & 0 deletions src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct AllocationCreateDesc<'a> {
pub linear: bool,
/// Determines how this allocation should be managed.
pub allocation_scheme: AllocationScheme,
/// Allow the allocator to request additional memory from the device to fulfill this request.
pub allow_capacity_increase: bool,
}

/// Wrapper type to only mark a raw pointer [`Send`] + [`Sync`] without having to
Expand Down Expand Up @@ -579,6 +581,10 @@ impl MemoryType {
}
}

if !desc.allow_capacity_increase {
return Err(AllocationError::OutOfMemory);
}

let new_memory_block = MemoryBlock::new(
device,
memblock_size,
Expand Down