Skip to content

Commit 937e09a

Browse files
authored
Debug-print how much memory we have reserved in addition to how much is used (#131)
1 parent eb63173 commit 937e09a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/d3d12/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ impl Allocation {
262262
#[derive(Debug)]
263263
struct MemoryBlock {
264264
heap: ID3D12Heap,
265+
size: u64,
265266
sub_allocator: Box<dyn allocator::SubAllocator>,
266267
}
267268
impl MemoryBlock {
@@ -310,6 +311,7 @@ impl MemoryBlock {
310311

311312
Ok(Self {
312313
heap,
314+
size,
313315
sub_allocator,
314316
})
315317
}
@@ -746,25 +748,28 @@ impl Allocator {
746748
impl fmt::Debug for Allocator {
747749
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
748750
let mut allocation_report = vec![];
751+
let mut total_reserved_size_in_bytes = 0;
749752

750753
for memory_type in &self.memory_types {
751754
for block in memory_type.memory_blocks.iter().flatten() {
755+
total_reserved_size_in_bytes += block.size;
752756
allocation_report.extend(block.sub_allocator.report_allocations())
753757
}
754758
}
755759

756-
let total_size_in_bytes = allocation_report.iter().map(|report| report.size).sum();
760+
let total_used_size_in_bytes = allocation_report.iter().map(|report| report.size).sum();
757761

758762
allocation_report.sort_by_key(|alloc| std::cmp::Reverse(alloc.size));
759763

760764
writeln!(
761765
f,
762-
"================================================================"
766+
"================================================================",
763767
)?;
764768
writeln!(
765769
f,
766-
"ALLOCATION BREAKDOWN ({})",
767-
fmt_bytes(total_size_in_bytes)
770+
"ALLOCATION BREAKDOWN ({} / {})",
771+
fmt_bytes(total_used_size_in_bytes),
772+
fmt_bytes(total_reserved_size_in_bytes),
768773
)?;
769774

770775
let max_num_allocations_to_print = f.precision().map_or(usize::MAX, |n| n);

src/vulkan/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ impl Default for Allocation {
129129
#[derive(Debug)]
130130
pub(crate) struct MemoryBlock {
131131
pub(crate) device_memory: vk::DeviceMemory,
132-
#[cfg(feature = "visualizer")]
133132
pub(crate) size: u64,
134133
pub(crate) mapped_ptr: *mut std::ffi::c_void,
135134
pub(crate) sub_allocator: Box<dyn allocator::SubAllocator>,
@@ -192,7 +191,6 @@ impl MemoryBlock {
192191

193192
Ok(Self {
194193
device_memory,
195-
#[cfg(feature = "visualizer")]
196194
size,
197195
mapped_ptr,
198196
sub_allocator,
@@ -456,25 +454,28 @@ pub struct Allocator {
456454
impl fmt::Debug for Allocator {
457455
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
458456
let mut allocation_report = vec![];
457+
let mut total_reserved_size_in_bytes = 0;
459458

460459
for memory_type in &self.memory_types {
461460
for block in memory_type.memory_blocks.iter().flatten() {
461+
total_reserved_size_in_bytes += block.size;
462462
allocation_report.extend(block.sub_allocator.report_allocations())
463463
}
464464
}
465465

466-
let total_size_in_bytes = allocation_report.iter().map(|report| report.size).sum();
466+
let total_used_size_in_bytes = allocation_report.iter().map(|report| report.size).sum();
467467

468468
allocation_report.sort_by_key(|alloc| std::cmp::Reverse(alloc.size));
469469

470470
writeln!(
471471
f,
472-
"================================================================"
472+
"================================================================",
473473
)?;
474474
writeln!(
475475
f,
476-
"ALLOCATION BREAKDOWN ({})",
477-
fmt_bytes(total_size_in_bytes)
476+
"ALLOCATION BREAKDOWN ({} / {})",
477+
fmt_bytes(total_used_size_in_bytes),
478+
fmt_bytes(total_reserved_size_in_bytes),
478479
)?;
479480

480481
let max_num_allocations_to_print = f.precision().map_or(usize::MAX, |n| n);

0 commit comments

Comments
 (0)