@@ -278,20 +278,27 @@ impl Default for AllocatorDebugSettings {
278
278
279
279
/// The sizes of the memory blocks that the allocator will create.
280
280
///
281
- /// Useful for tuning the allocator to your application's needs. For example most games will be fine with the defaultsize
281
+ /// Useful for tuning the allocator to your application's needs. For example most games will be fine with the default
282
282
/// values, but eg. an app might want to use smaller block sizes to reduce the amount of memory used.
283
283
///
284
284
/// Clamped between 4MB and 256MB, and rounds up to the nearest multiple of 4MB for alignment reasons.
285
285
///
286
+ /// Note that these limits only apply to shared memory blocks that can hold multiple allocations.
287
+ /// If an allocation does not fit within the corresponding maximum block size, it will be placed
288
+ /// in a dedicated memory block holding only this allocation, without limitations other than what
289
+ /// the underlying hardware and driver are able to provide.
290
+ ///
286
291
/// # Fixed or growable block size
287
292
///
288
293
/// This structure represents ranges of allowed sizes for shared memory blocks.
289
- /// By default, If the bounds of a given range are equal, the allocator will
290
- /// be configured to used a fixed memory block size for shared allocations.
294
+ /// By default, if the upper bounds are not extended using `with_max_*_memblock_size`,
295
+ /// the allocator will be configured to use a fixed memory block size for shared
296
+ /// allocations.
291
297
///
292
298
/// Otherwise, the allocator will pick a memory block size within the specifed
293
- /// range, dependending on the number of existing allocations for the memory
299
+ /// range, depending on the number of existing allocations for the memory
294
300
/// type.
301
+ ///
295
302
/// As a rule of thumb, the allocator will start with the minimum block size
296
303
/// and double the size with each new allocation, up to the specified maximum
297
304
/// block size. This growth is tracked independently for each memory type.
@@ -315,28 +322,36 @@ impl Default for AllocatorDebugSettings {
315
322
/// ```
316
323
#[ derive( Clone , Copy , Debug ) ]
317
324
pub struct AllocationSizes {
318
- /// The initial size of the memory blocks that will be created for the GPU only memory type.
325
+ /// The initial size for device memory blocks.
326
+ ///
327
+ /// The size of new device memory blocks doubles each time a new block is needed, up to
328
+ /// [`AllocationSizes::max_device_memblock_size`].
319
329
///
320
330
/// Defaults to 256MB.
321
331
min_device_memblock_size : u64 ,
322
- /// The size of device memory blocks doubles each time a new allocation is needed, up to
323
- /// `device_maximum_memblock_size`.
332
+ /// The maximum size for device memory blocks.
333
+ ///
334
+ /// Defaults to the value of [`AllocationSizes::min_device_memblock_size`].
324
335
max_device_memblock_size : u64 ,
325
- /// The size of the memory blocks that will be created for the CPU visible memory types.
336
+ /// The initial size for host memory blocks.
337
+ ///
338
+ /// The size of new host memory blocks doubles each time a new block is needed, up to
339
+ /// [`AllocationSizes::max_host_memblock_size`].
326
340
///
327
341
/// Defaults to 64MB.
328
342
min_host_memblock_size : u64 ,
329
- /// The size of host memory blocks doubles each time a new allocation is needed, up to
330
- /// `host_maximum_memblock_size`.
343
+ /// The maximum size for host memory blocks.
344
+ ///
345
+ /// Defaults to the value of [`AllocationSizes::min_host_memblock_size`].
331
346
max_host_memblock_size : u64 ,
332
347
}
333
348
334
349
impl AllocationSizes {
335
350
/// Sets the minimum device and host memory block sizes.
336
351
///
337
352
/// The maximum block sizes are initialized to the minimum sizes and
338
- /// can be changed using ` with_max_device_memblock_size` and
339
- /// ` with_max_host_memblock_size`.
353
+ /// can be increased using [`AllocationSizes:: with_max_device_memblock_size`] and
354
+ /// [`AllocationSizes:: with_max_host_memblock_size`] .
340
355
pub fn new ( device_memblock_size : u64 , host_memblock_size : u64 ) -> Self {
341
356
let device_memblock_size = Self :: adjust_memblock_size ( device_memblock_size, "Device" ) ;
342
357
let host_memblock_size = Self :: adjust_memblock_size ( host_memblock_size, "Host" ) ;
@@ -385,8 +400,11 @@ impl AllocationSizes {
385
400
}
386
401
387
402
/// Used internally to decide the size of a shared memory block
388
- /// based withing the allowed range, based on the number of
389
- /// existing allocations
403
+ /// based within the allowed range, based on the number of
404
+ /// existing allocations. The more blocks there already are
405
+ /// (where the requested allocation didn't fit), the larger
406
+ /// the returned memory block size is going to be (up to
407
+ /// `max_*_memblock_size`).
390
408
pub ( crate ) fn get_memblock_size ( & self , is_host : bool , count : usize ) -> u64 {
391
409
let ( min_size, max_size) = if is_host {
392
410
( self . min_host_memblock_size , self . max_host_memblock_size )
0 commit comments