Works
This commit is contained in:
+68
-20
@@ -1,4 +1,5 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
#![feature(float_algebraic)]
|
||||
|
||||
use core::sync;
|
||||
use std::cell::RefCell;
|
||||
@@ -12,6 +13,7 @@ use std::sync::mpsc::sync_channel;
|
||||
|
||||
use bytemuck::Pod;
|
||||
use bytemuck::Zeroable;
|
||||
use bytemuck::cast_slice;
|
||||
use crevice::std140::AsStd140;
|
||||
use crevice::std430::AsStd430;
|
||||
use egui::Color32;
|
||||
@@ -78,26 +80,18 @@ use crate::producers::ChunkedProducer;
|
||||
use crate::producers::Producer;
|
||||
use crate::producers::SineGenerator;
|
||||
use crate::producers::TerrainGenerator;
|
||||
use crate::voxel::cache::CacheNodeRequest;
|
||||
use crate::voxel::cache::CacheResponse;
|
||||
use crate::voxel::cache::ColorBytes;
|
||||
use crate::voxel::cache::DestinationElement;
|
||||
use crate::voxel::cache::LocationPoolElement;
|
||||
use crate::voxel::cache::RequestBuffer;
|
||||
use crate::voxel::cache::UsageBuffer;
|
||||
use crate::voxel::cache::VoxelCache;
|
||||
use crate::voxel::gpu::ExplicitNTreeNode;
|
||||
use crate::voxel::pipeline::ChunkHandle;
|
||||
use crate::voxel::pipeline::ChunkObject;
|
||||
use crate::voxel::pipeline::VoxelPipeline;
|
||||
use crate::voxel::sparse::Color;
|
||||
use crate::voxel::sparse::NTree;
|
||||
use crate::voxel::sparse::NTreeNodeLocator;
|
||||
use crate::voxel_cache::cache::CacheNodeRequest;
|
||||
use crate::voxel_cache::cache::CacheResponse;
|
||||
use crate::voxel_cache::cache::ColorBytes;
|
||||
use crate::voxel_cache::cache::DestinationElement;
|
||||
use crate::voxel_cache::cache::LocationPoolElement;
|
||||
use crate::voxel_cache::cache::VoxelCache;
|
||||
use crate::voxel_cache::sparse::NTreeNodeLocator;
|
||||
|
||||
mod camera;
|
||||
mod egui_renderer;
|
||||
mod producers;
|
||||
mod voxel;
|
||||
mod voxel_cache;
|
||||
//mod tree;
|
||||
//
|
||||
|
||||
@@ -120,6 +114,7 @@ struct State
|
||||
instance_buffer: Buffer,
|
||||
instance_count: usize,
|
||||
usage_vec: Arc<Mutex<Vec<usize>>>,
|
||||
rm_time: Arc<Mutex<f32>>,
|
||||
insertion_debounce: bool,
|
||||
|
||||
camera: Camera,
|
||||
@@ -188,9 +183,21 @@ impl State
|
||||
|
||||
let egui_renderer = EguiRenderer::new(&device, surface_format, &window);
|
||||
|
||||
let mut voxel_cache = VoxelCache::<4>::new(80_000, device.clone(), queue.clone());
|
||||
let mut voxel_cache = VoxelCache::<4>::new(200_000, device.clone(), queue.clone());
|
||||
|
||||
let terrain_generator = TerrainGenerator::<4>::new(5, "vxls_height.tif", 0.2, "img.jpg");
|
||||
//let terrain_generator = TerrainGenerator::<4>::new(5, "vxls_height.tif", 0.2, "img.jpg");
|
||||
// let terrain_generator = TerrainGenerator::<4>::new(
|
||||
// 5,
|
||||
// "./pointe_percee/height.tif",
|
||||
// 0.2,
|
||||
// "./pointe_percee/ortho.jpg",
|
||||
// );
|
||||
let terrain_generator = TerrainGenerator::<4>::new(
|
||||
5,
|
||||
"/home/albin/Documents/vxls_maps/lapiz/height.tif",
|
||||
0.2,
|
||||
"/home/albin/Documents/vxls_maps/lapiz/ortho.jpg",
|
||||
);
|
||||
|
||||
let mut chunk_pos_map = HashMap::new();
|
||||
let chunk_instances = (0..terrain_generator.chunk_width)
|
||||
@@ -307,6 +314,7 @@ impl State
|
||||
instance_count,
|
||||
terrain_generator: Arc::new(terrain_generator),
|
||||
chunk_pos_map: chunk_pos_map.into(),
|
||||
rm_time: Arc::new(Mutex::new(0.)),
|
||||
};
|
||||
|
||||
// Configure surface for the first time
|
||||
@@ -427,6 +435,19 @@ impl State
|
||||
}
|
||||
};
|
||||
|
||||
let timestamp_query = self.device.create_query_set(&wgpu::QuerySetDescriptor {
|
||||
label: Some("timestamp_query_set"),
|
||||
ty: wgpu::QueryType::Timestamp,
|
||||
count: 2,
|
||||
});
|
||||
|
||||
let timestamp_buffer = self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("timestamp_buffer"),
|
||||
size: (size_of::<u64>() * 2) as u64,
|
||||
usage: BufferUsages::QUERY_RESOLVE | BufferUsages::COPY_SRC,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let texture_view = surface_texture
|
||||
.texture
|
||||
.create_view(&wgpu::TextureViewDescriptor {
|
||||
@@ -459,7 +480,11 @@ impl State
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
timestamp_writes: None,
|
||||
timestamp_writes: Some(wgpu::RenderPassTimestampWrites {
|
||||
query_set: ×tamp_query,
|
||||
beginning_of_pass_write_index: Some(0),
|
||||
end_of_pass_write_index: Some(1),
|
||||
}),
|
||||
occlusion_query_set: None,
|
||||
multiview_mask: None,
|
||||
});
|
||||
@@ -477,11 +502,13 @@ impl State
|
||||
|
||||
// End the renderpass.
|
||||
drop(renderpass);
|
||||
|
||||
encoder.resolve_query_set(×tamp_query, 0..2, ×tamp_buffer, 0);
|
||||
}
|
||||
|
||||
let requests = self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("dummy_dumb_dinky_aaaahhh_buffer"),
|
||||
size: 16 * 1024,
|
||||
size: 16 * 2000,
|
||||
usage: BufferUsages::STORAGE | BufferUsages::COPY_SRC,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
@@ -513,6 +540,11 @@ impl State
|
||||
.size(28.),
|
||||
);
|
||||
}
|
||||
|
||||
ui.label(format!(
|
||||
"Ray-marching time: {}",
|
||||
*self.rm_time.lock() / 1_000_000.
|
||||
));
|
||||
egui_plot::Plot::new("Plot").show(ui, |plot_ui| {
|
||||
plot_ui.bar_chart(BarChart::new(
|
||||
"histo",
|
||||
@@ -582,6 +614,22 @@ impl State
|
||||
// .contains(&winit::keyboard::KeyCode::KeyF))
|
||||
// && !self.insertion_debounce
|
||||
// {
|
||||
|
||||
// Report frame time
|
||||
let cloned_rm_time = self.rm_time.clone();
|
||||
let cloned_queue = self.queue.clone();
|
||||
DownloadBuffer::read_buffer(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
×tamp_buffer.slice(..),
|
||||
move |buffer| {
|
||||
let buffer_slice = buffer.unwrap();
|
||||
let slice: &[u64] = cast_slice(&buffer_slice);
|
||||
let time = (slice[1] - slice[0]) as f32 * cloned_queue.get_timestamp_period();
|
||||
*cloned_rm_time.lock() = time;
|
||||
},
|
||||
);
|
||||
|
||||
if !self
|
||||
.camera
|
||||
.pressed_keyset
|
||||
|
||||
Reference in New Issue
Block a user