Skip to content

Commit 0f0661d

Browse files
committed
Add allow_capacity_increase option to AllocationCreateDesc
This allows the user to bound the growth of the capacity without relying on the driver to return ERROR_OUT_OF_DEVICE_MEMORY (which they sometimes don't).
1 parent 642dc91 commit 0f0661d

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ let allocation = allocator
6262
location: MemoryLocation::CpuToGpu,
6363
linear: true, // Buffers are always linear
6464
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
65+
allow_capacity_increase: true,
6566
}).unwrap();
6667

6768
// Bind memory to the buffer

examples/vulkan-buffer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ fn main() {
110110
linear: true,
111111
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
112112
name: "Test allocation (Gpu Only)",
113+
allow_capacity_increase: true,
113114
})
114115
.unwrap();
115116

@@ -143,6 +144,7 @@ fn main() {
143144
linear: true,
144145
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
145146
name: "Test allocation (Cpu to Gpu)",
147+
allow_capacity_increase: true,
146148
})
147149
.unwrap();
148150

@@ -176,6 +178,7 @@ fn main() {
176178
linear: true,
177179
allocation_scheme: AllocationScheme::GpuAllocatorManaged,
178180
name: "Test allocation (Gpu to Cpu)",
181+
allow_capacity_increase: true,
179182
})
180183
.unwrap();
181184

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
//! location: MemoryLocation::CpuToGpu,
6767
//! linear: true, // Buffers are always linear
6868
//! allocation_scheme: AllocationScheme::GpuAllocatorManaged,
69+
//! allow_capacity_increase: true,
6970
//! }).unwrap();
7071
//!
7172
//! // Bind memory to the buffer

src/vulkan/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct AllocationCreateDesc<'a> {
3737
pub linear: bool,
3838
/// Determines how this allocation should be managed.
3939
pub allocation_scheme: AllocationScheme,
40+
/// Allow the allocator to request additional memory from the device to fulfill this request.
41+
pub allow_capacity_increase: bool,
4042
}
4143

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

584+
if !desc.allow_capacity_increase {
585+
return Err(AllocationError::OutOfMemory);
586+
}
587+
582588
let new_memory_block = MemoryBlock::new(
583589
device,
584590
memblock_size,

0 commit comments

Comments
 (0)