Adding histogram
This commit is contained in:
+47
-7
@@ -15,6 +15,7 @@ use crevice::std140::AsStd140;
|
||||
use crevice::std430::AsStd430;
|
||||
use egui::emath::fast_midpoint;
|
||||
use egui::mutex::Mutex;
|
||||
use egui_plot::BarChart;
|
||||
use glam::Mat4;
|
||||
use glam::Vec3;
|
||||
use glam::Vec4;
|
||||
@@ -102,6 +103,7 @@ struct State
|
||||
|
||||
pipeline: RenderPipeline,
|
||||
voxel_cache: Arc<Mutex<VoxelCache<4>>>,
|
||||
usage_vec: Arc<Mutex<Vec<usize>>>,
|
||||
insertion_debounce: bool,
|
||||
|
||||
camera: Camera,
|
||||
@@ -158,7 +160,7 @@ impl State
|
||||
|
||||
let egui_renderer = EguiRenderer::new(&device, surface_format, &window);
|
||||
|
||||
let mut voxel_cache = VoxelCache::<4>::new(4096, device.clone(), queue.clone());
|
||||
let mut voxel_cache = VoxelCache::<4>::new(16000, device.clone(), queue.clone());
|
||||
let id = voxel_cache.structure_table.allocate_structure(true);
|
||||
println!("id: {id}");
|
||||
|
||||
@@ -228,6 +230,7 @@ impl State
|
||||
depth_buffer: Self::create_depth_buffer(&device, size.width, size.height),
|
||||
queue,
|
||||
device,
|
||||
usage_vec: Arc::new(Mutex::new(vec![])),
|
||||
pipeline: chunk_pipeline,
|
||||
voxel_cache: Arc::new(Mutex::new(voxel_cache)),
|
||||
insertion_debounce: false,
|
||||
@@ -407,7 +410,7 @@ impl State
|
||||
|
||||
let requests = self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("dummy_dumb_dinky_aaaahhh_buffer"),
|
||||
size: 16 * 64,
|
||||
size: 16 * 256,
|
||||
usage: BufferUsages::STORAGE | BufferUsages::COPY_SRC,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
@@ -419,9 +422,23 @@ impl State
|
||||
// If you wanted to call any drawing commands, they would go here.
|
||||
{
|
||||
self.egui_renderer.begin_frame(&self.window);
|
||||
egui::Window::new("Window ! ")
|
||||
.resizable(true)
|
||||
.show(self.egui_renderer.context(), |ui| ui.label("Hello !"));
|
||||
egui::Window::new("Window ! ").resizable(true).show(
|
||||
self.egui_renderer.context(),
|
||||
|ui| {
|
||||
egui_plot::Plot::new("Plot").show(ui, |plot_ui| {
|
||||
plot_ui.bar_chart(BarChart::new(
|
||||
"histo",
|
||||
self.usage_vec
|
||||
.lock()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, x)| egui_plot::Bar::new(i as f64, *x as f64))
|
||||
.collect(),
|
||||
));
|
||||
});
|
||||
ui.label("Hello !")
|
||||
},
|
||||
);
|
||||
|
||||
let screen_descriptor = egui_wgpu::ScreenDescriptor {
|
||||
size_in_pixels: [self.size.width, self.size.height],
|
||||
@@ -438,6 +455,26 @@ impl State
|
||||
);
|
||||
}
|
||||
|
||||
// Report usage
|
||||
let time_stamp = self.voxel_cache.lock().current_timestamp();
|
||||
let cloned_usage_histogram = self.usage_vec.clone();
|
||||
DownloadBuffer::read_buffer(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
&self.voxel_cache.lock().usage_buffer.usage_buffer.slice(..),
|
||||
move |slice| {
|
||||
let slice = slice.unwrap();
|
||||
let cache_slice: &[u32] = bytemuck::cast_slice(&slice);
|
||||
let mut v = vec![0; 100];
|
||||
for x in cache_slice.iter()
|
||||
{
|
||||
let diff = (time_stamp - x).min(99);
|
||||
v[diff as usize] += 1;
|
||||
}
|
||||
*cloned_usage_histogram.lock() = v;
|
||||
},
|
||||
);
|
||||
|
||||
// Submit the command in the queue to execute
|
||||
self.queue.submit([encoder.finish()]);
|
||||
self.window.pre_present_notify();
|
||||
@@ -446,14 +483,16 @@ impl State
|
||||
.camera
|
||||
.pressed_keyset
|
||||
.contains(&winit::keyboard::KeyCode::KeyF)
|
||||
&& self.insertion_debounce
|
||||
{
|
||||
self.insertion_debounce = false;
|
||||
}
|
||||
|
||||
if (!self
|
||||
if (self
|
||||
.camera
|
||||
.pressed_keyset
|
||||
.contains(&winit::keyboard::KeyCode::KeyF))
|
||||
&& !self.insertion_debounce
|
||||
{
|
||||
self.insertion_debounce = true;
|
||||
let request_count = self.voxel_cache.lock().total_request_count();
|
||||
@@ -566,7 +605,6 @@ impl State
|
||||
);
|
||||
cloned_queue.submit([encoder.finish()]);
|
||||
}
|
||||
cloned_cache.lock().next_frame();
|
||||
},
|
||||
);
|
||||
println!("Total request count: {}", request_count);
|
||||
@@ -578,6 +616,8 @@ impl State
|
||||
}
|
||||
let _ = self.device.poll(wgpu::wgt::PollType::Poll);
|
||||
}
|
||||
|
||||
self.voxel_cache.lock().next_frame();
|
||||
drop(rx);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user