Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tosti007 committed Sep 14, 2023
1 parent 91b7642 commit a5824c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
27 changes: 16 additions & 11 deletions src/visualizer/allocation_reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub(crate) fn render_allocation_reports_ui(

let mut allocations = allocations
.into_iter()
.filter(|report| report.name.to_lowercase().contains(&breakdown_filter))
.enumerate()
.filter(|(_, report)| report.name.to_lowercase().contains(&breakdown_filter))
.collect::<Vec<_>>();

// TODO: use this
Expand All @@ -47,9 +47,9 @@ pub(crate) fn render_allocation_reports_ui(
let table = TableBuilder::new(ui)
.striped(true)
.resizable(true)
.column(Column::exact(50.0))
.column(Column::exact(30.0))
.column(Column::initial(300.0).at_least(200.0).clip(true))
.column(Column::auto());
.column(Column::exact(70.0));

fn header_button(ui: &mut Ui, label: &str) -> Response {
let label = WidgetText::from(label).strong();
Expand Down Expand Up @@ -113,21 +113,26 @@ pub(crate) fn render_allocation_reports_ui(
table.body(|mut body| {
for (idx, alloc) in allocations {
body.row(row_height, |mut row| {
let backtrace = alloc.backtrace.clone();
let size = alloc.size;
let AllocationReport {
name,
size,
backtrace,
} = alloc;

row.col(|ui| {
ui.label(idx.to_string());
});

row.col(|ui| {
ui.label(alloc.name);
})
.1
.on_hover_ui(|ui| {
ui.label(resolve_backtrace(&backtrace));
let resp = row.col(|ui| {
ui.label(name);
});

if backtrace.is_some() {
resp.1.on_hover_ui(|ui| {
ui.label(resolve_backtrace(&backtrace));
});
}

row.col(|ui| {
ui.label(fmt_bytes(size));
});
Expand Down
33 changes: 8 additions & 25 deletions src/vulkan/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl AllocatorVisualizer {
self.color_scheme = color_scheme;
}

fn render_main_ui(&mut self, ui: &mut egui::Ui, alloc: &Allocator) {
pub fn render_memory_block_ui(&mut self, ui: &mut egui::Ui, alloc: &Allocator) {
ui.label(format!(
"buffer image granularity: {:?}",
alloc.buffer_image_granularity
Expand Down Expand Up @@ -150,7 +150,7 @@ impl AllocatorVisualizer {
);
}

fn render_memory_block_windows(&mut self, ctx: &egui::Context, alloc: &Allocator) {
pub fn render_memory_block_windows(&mut self, ctx: &egui::Context, allocator: &Allocator) {
// Draw each window.
let color_scheme = &self.color_scheme;

Expand All @@ -168,7 +168,7 @@ impl AllocatorVisualizer {
.default_size([1920.0 * 0.5, 1080.0 * 0.5])
.open(&mut open)
.show(ctx, |ui| {
let memblock = &alloc.memory_types[window.memory_type_index].memory_blocks
let memblock = &allocator.memory_types[window.memory_type_index].memory_blocks
[window.block_index]
.as_ref();
if let Some(memblock) = memblock {
Expand All @@ -181,7 +181,7 @@ impl AllocatorVisualizer {

window
.settings
.ui(ui, alloc.debug_settings.store_stack_traces);
.ui(ui, allocator.debug_settings.store_stack_traces);

memblock
.sub_allocator
Expand All @@ -198,28 +198,11 @@ impl AllocatorVisualizer {
self.focus = None;
}

/// Renders imgui widgets.
///
/// The [`Option<&mut bool>`] can be used control and track changes to the opened/closed status of the widget.
/// Pass [`None`] if no control and readback information is required. This will always render the widget.
/// When passing `Some(&mut bool)`:
/// - If [`false`], the widget won't be drawn.
/// - If [`true`], the widget will be drawn and an (X) closing button will be added to the widget bar.
pub fn render(
&mut self,
allocator: &Allocator,
ctx: &egui::Context,
opened: Option<&mut bool>,
) {
if opened != Some(&mut false) {
egui::Window::new("Allocator visualization")
.default_size([512.0, 512.0])
.show(ctx, |ui| self.render_main_ui(ui, allocator));
self.render_memory_block_windows(ctx, allocator);
}
}
// egui::Window::new("Allocator visualization")
// .default_size([512.0, 512.0])
// .show(ctx, |ui| self.render_main_ui(ui, allocator));

pub fn render_breakdown(&mut self, allocator: &Allocator, ui: &mut egui::Ui) {
pub fn render_breakdown_ui(&mut self, ui: &mut egui::Ui, allocator: &Allocator) {
render_allocation_reports_ui(
ui,
&mut self.breakdown_settings,
Expand Down

0 comments on commit a5824c6

Please sign in to comment.