Skip to content
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

Update imgui to 0.8 and winit to 0.25 #73

Merged
merged 4 commits into from
Oct 3, 2021
Merged
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ ash = { version = "0.33", optional = true }
# Only needed for d3d12.
winapi = { version = "0.3.9", features = ["d3d12", "winerror", "impl-default", "impl-debug"], optional = true }
# Only needed for visualizer.
imgui = { version = "0.7", optional = true }
imgui-winit-support = { version = "0.7", optional = true }
imgui = { version = "0.8", optional = true }
imgui-winit-support = { version = "0.8", optional = true }

[dev-dependencies]
ash-window = "0.7"
hassle-rs = "0.5.2"
raw-window-handle = "0.3"
widestring = "0.4.3"
winapi = { version = "0.3.9", features = ["d3d12", "d3d12sdklayers", "dxgi1_6", "winerror", "impl-default", "impl-debug", "winuser", "windowsx", "libloaderapi"] }
winit = "0.24"
winit = "0.25"

[[example]]
name = "vulkan-buffer"
Expand Down
70 changes: 25 additions & 45 deletions src/d3d12/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ impl AllocatorVisualizer {
}

fn render_main_window(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
imgui::Window::new(imgui::im_str!("Allocator visualization"))
imgui::Window::new("Allocator visualization")
.collapsed(true, Condition::FirstUseEver)
.size([512.0, 512.0], imgui::Condition::FirstUseEver)
.build(ui, || {
use imgui::*;

if CollapsingHeader::new(&im_str!(
if CollapsingHeader::new(format!(
"Memory Types: ({} types)",
alloc.memory_types.len()
))
Expand All @@ -93,7 +93,7 @@ impl AllocatorVisualizer {
{
ui.indent();
for (mem_type_i, mem_type) in alloc.memory_types.iter().enumerate() {
if CollapsingHeader::new(&im_str!("Type: {}", mem_type_i)).build(ui) {
if CollapsingHeader::new(format!("Type: {}", mem_type_i)).build(ui) {
let mut total_block_size = 0;
let mut total_allocated = 0;
for block in mem_type.memory_blocks.iter().flatten() {
Expand Down Expand Up @@ -127,13 +127,7 @@ impl AllocatorVisualizer {
ui.text(format!("block count: {}", active_block_count));
for (block_i, block) in mem_type.memory_blocks.iter().enumerate() {
if let Some(block) = block {
TreeNode::new(&im_str!(
"Block: {}##memtype({})",
block_i,
mem_type_i
))
.label(&im_str!("Block: {}", block_i))
.build(ui, || {
TreeNode::new(format!("Block: {}", block_i)).build(ui, || {
ui.indent();
ui.text(format!(
"size: {} KiB",
Expand All @@ -146,32 +140,21 @@ impl AllocatorVisualizer {
ui.text(format!("D3D12 heap: {:?}", block.heap));
block.sub_allocator.draw_base_info(ui);

if block.sub_allocator.supports_visualization() {
let button_name = format!(
"visualize##memtype({})block({})",
mem_type_i, block_i
);
if ui.small_button(&ImString::new(button_name)) {
match self
.selected_blocks
.iter()
.enumerate()
.find_map(|(i, x)| {
if x.memory_type_index == mem_type_i
&& x.block_index == block_i
{
Some((i, (x)))
} else {
None
}
}) {
Some(x) => self.focus = Some(x.0),
None => self.selected_blocks.push(
AllocatorVisualizerBlockWindow::new(
mem_type_i, block_i,
),
if block.sub_allocator.supports_visualization()
&& ui.small_button("visualize")
{
match self.selected_blocks.iter().enumerate().find(
|(_, x)| {
x.memory_type_index == mem_type_i
&& x.block_index == block_i
},
) {
Some(x) => self.focus = Some(x.0),
None => self.selected_blocks.push(
AllocatorVisualizerBlockWindow::new(
mem_type_i, block_i,
),
}
),
}
}
ui.unindent();
Expand All @@ -186,7 +169,6 @@ impl AllocatorVisualizer {
}

fn render_memory_block_windows(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
use imgui::*;
// Copy here to workaround the borrow checker.
let focus_opt = self.focus;
// Keep track of a list of windows that are signaled by imgui to be closed.
Expand All @@ -201,10 +183,9 @@ impl AllocatorVisualizer {
false
};
let mut is_open = true;
imgui::Window::new(&imgui::im_str!(
imgui::Window::new(format!(
"Block Visualizer##memtype({})block({})",
window.memory_type_index,
window.block_index
window.memory_type_index, window.block_index
))
.size([1920.0 * 0.5, 1080.0 * 0.5], imgui::Condition::FirstUseEver)
.title_bar(true)
Expand All @@ -227,13 +208,13 @@ impl AllocatorVisualizer {
));

if alloc.debug_settings.store_stack_traces {
ui.checkbox(im_str!("Show backtraces"), &mut window.show_backtraces);
ui.checkbox("Show backtraces", &mut window.show_backtraces);
}
// Slider for changing the 'zoom' level of the visualizer.
const BYTES_PER_UNIT_MIN: i32 = 1;
const BYTES_PER_UNIT_MAX: i32 = 1024 * 1024;
Drag::new(im_str!("Bytes per Pixel (zoom)"))
.range(BYTES_PER_UNIT_MIN..=BYTES_PER_UNIT_MAX)
Drag::new("Bytes per Pixel (zoom)")
.range(BYTES_PER_UNIT_MIN, BYTES_PER_UNIT_MAX)
.speed(10.0f32)
.build(ui, &mut window.bytes_per_unit);

Expand All @@ -244,10 +225,9 @@ impl AllocatorVisualizer {
.max(BYTES_PER_UNIT_MIN);

// Draw the visualization in a child window.
imgui::ChildWindow::new(&im_str!(
imgui::ChildWindow::new(&format!(
"Visualization Sub-window##memtype({})block({})",
window.memory_type_index,
window.block_index
window.memory_type_index, window.block_index
))
.scrollable(true)
.scroll_bar(true)
Expand Down
77 changes: 28 additions & 49 deletions src/vulkan/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AllocatorVisualizer {
}

fn render_main_window(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
imgui::Window::new(imgui::im_str!("Allocator visualization"))
imgui::Window::new("Allocator visualization")
.collapsed(true, Condition::FirstUseEver)
.size([512.0, 512.0], imgui::Condition::FirstUseEver)
.build(ui, || {
Expand All @@ -56,11 +56,10 @@ impl AllocatorVisualizer {
));

let heap_count = alloc.memory_heaps.len();
if CollapsingHeader::new(&im_str!("Memory Heaps ({} heaps)", heap_count)).build(ui)
{
if CollapsingHeader::new(format!("Memory Heaps ({} heaps)", heap_count)).build(ui) {
for (i, heap) in alloc.memory_heaps.iter().enumerate() {
ui.indent();
if CollapsingHeader::new(&im_str!("Heap: {}", i)).build(ui) {
if CollapsingHeader::new(format!("Heap: {}", i)).build(ui) {
ui.indent();
ui.text(format!("flags: {:?}", heap.flags));
ui.text(format!(
Expand All @@ -73,7 +72,7 @@ impl AllocatorVisualizer {
}
}

if CollapsingHeader::new(&im_str!(
if CollapsingHeader::new(format!(
"Memory Types: ({} types)",
alloc.memory_types.len()
))
Expand All @@ -82,8 +81,8 @@ impl AllocatorVisualizer {
{
ui.indent();
for (mem_type_i, mem_type) in alloc.memory_types.iter().enumerate() {
if CollapsingHeader::new(&im_str!(
"Type: {} ({} blocks)###Type{}",
if CollapsingHeader::new(format!(
"Type: {} ({} blocks)##Type{}",
mem_type_i,
mem_type.memory_blocks.len(),
mem_type_i,
Expand All @@ -109,13 +108,7 @@ impl AllocatorVisualizer {
ui.text(format!("block count: {}", active_block_count));
for (block_i, block) in mem_type.memory_blocks.iter().enumerate() {
if let Some(block) = block {
TreeNode::new(&im_str!(
"Block: {}##memtype({})",
block_i,
mem_type_i
))
.label(&im_str!("Block: {}", block_i))
.build(ui, || {
TreeNode::new(format!("Block: {}", block_i)).build(ui, || {
use ash::vk::Handle;
ui.indent();
ui.text(format!("size: {} KiB", block.size / 1024));
Expand All @@ -134,32 +127,21 @@ impl AllocatorVisualizer {

block.sub_allocator.draw_base_info(ui);

if block.sub_allocator.supports_visualization() {
let button_name = format!(
"visualize##memtype({})block({})",
mem_type_i, block_i
);
if ui.small_button(&ImString::new(button_name)) {
match self
.selected_blocks
.iter()
.enumerate()
.find_map(|(i, x)| {
if x.memory_type_index == mem_type_i
&& x.block_index == block_i
{
Some((i, (x)))
} else {
None
}
}) {
Some(x) => self.focus = Some(x.0),
None => self.selected_blocks.push(
AllocatorVisualizerBlockWindow::new(
mem_type_i, block_i,
),
if block.sub_allocator.supports_visualization()
&& ui.small_button("visualize")
{
match self.selected_blocks.iter().enumerate().find(
|(_, x)| {
x.memory_type_index == mem_type_i
&& x.block_index == block_i
},
) {
Some(x) => self.focus = Some(x.0),
None => self.selected_blocks.push(
AllocatorVisualizerBlockWindow::new(
mem_type_i, block_i,
),
}
),
}
}
ui.unindent();
Expand All @@ -174,7 +156,6 @@ impl AllocatorVisualizer {
}

fn render_memory_block_windows(&mut self, ui: &imgui::Ui, alloc: &Allocator) {
use imgui::*;
// Copy here to workaround the borrow checker.
let focus_opt = self.focus;
// Keep track of a list of windows that are signaled by imgui to be closed.
Expand All @@ -189,10 +170,9 @@ impl AllocatorVisualizer {
false
};
let mut is_open = true;
imgui::Window::new(&imgui::im_str!(
imgui::Window::new(format!(
"Block Visualizer##memtype({})block({})",
window.memory_type_index,
window.block_index
window.memory_type_index, window.block_index
))
.size([1920.0 * 0.5, 1080.0 * 0.5], imgui::Condition::FirstUseEver)
.title_bar(true)
Expand All @@ -215,13 +195,13 @@ impl AllocatorVisualizer {
));

if alloc.debug_settings.store_stack_traces {
ui.checkbox(im_str!("Show backtraces"), &mut window.show_backtraces);
ui.checkbox("Show backtraces", &mut window.show_backtraces);
}
// Slider for changing the 'zoom' level of the visualizer.
const BYTES_PER_UNIT_MIN: i32 = 1;
const BYTES_PER_UNIT_MAX: i32 = 1024 * 1024;
Drag::new(im_str!("Bytes per Pixel (zoom)"))
.range(BYTES_PER_UNIT_MIN..=BYTES_PER_UNIT_MAX)
Drag::new("Bytes per Pixel (zoom)")
.range(BYTES_PER_UNIT_MIN, BYTES_PER_UNIT_MAX)
.speed(10.0f32)
.build(ui, &mut window.bytes_per_unit);

Expand All @@ -232,10 +212,9 @@ impl AllocatorVisualizer {
.max(BYTES_PER_UNIT_MIN);

// Draw the visualization in a child window.
imgui::ChildWindow::new(&im_str!(
imgui::ChildWindow::new(&format!(
"Visualization Sub-window##memtype({})block({})",
window.memory_type_index,
window.block_index
window.memory_type_index, window.block_index
))
.scrollable(true)
.scroll_bar(true)
Expand Down