StructureID separate from chunk 'anchor'
This commit is contained in:
+20
-25
@@ -1,7 +1,6 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
#![feature(float_algebraic)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
@@ -20,7 +19,6 @@ use glam::Mat4;
|
||||
use glam::Vec3;
|
||||
use glam::Vec4;
|
||||
use itertools::Itertools;
|
||||
use rayon::iter::IndexedParallelIterator;
|
||||
use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
use wgpu::BindGroupLayout;
|
||||
@@ -48,20 +46,16 @@ use winit::event_loop::ActiveEventLoop;
|
||||
use winit::event_loop::ControlFlow;
|
||||
use winit::event_loop::EventLoop;
|
||||
use winit::event_loop::OwnedDisplayHandle;
|
||||
use winit::platform::x11::EventLoopBuilderExtX11;
|
||||
use winit::window::Window;
|
||||
use winit::window::WindowId;
|
||||
|
||||
use crate::camera::Camera;
|
||||
use crate::egui_renderer::EguiRenderer;
|
||||
use crate::gpu::radix_sort;
|
||||
use crate::gpu::radix_sort::RadixSorter;
|
||||
use crate::gpu_profiler::Frame;
|
||||
use crate::gpu_profiler::Profile;
|
||||
use crate::gpu_profiler::ProfilingEncoder;
|
||||
use crate::producers::ChunkedProducer;
|
||||
use crate::producers::SdfGenerator;
|
||||
use crate::producers::TerrainGenerator;
|
||||
use crate::production::request_queue::FrameId;
|
||||
use crate::production::request_queue::IncomingRequest;
|
||||
use crate::production::request_queue::QueueConfig;
|
||||
@@ -75,12 +69,7 @@ use crate::voxel_cache::VoxelCacheInsertion;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::schema::InsertionInformation;
|
||||
use crate::voxel_cache::schema::InsertionParent;
|
||||
use crate::voxel_cache::schema::LocationPage;
|
||||
use crate::voxel_cache::schema::NO_PARENT_PAGE;
|
||||
use crate::voxel_cache::schema::RequestInformation;
|
||||
use crate::voxel_cache::schema::RequestMeta;
|
||||
use crate::voxel_cache::tables::FixedStructureTable;
|
||||
|
||||
mod camera;
|
||||
mod egui_renderer;
|
||||
@@ -145,7 +134,6 @@ struct State
|
||||
structure_table: Arc<Mutex<ToroidalStructureTable>>,
|
||||
structure_table_request_buffer: Arc<CacheRequestBuffer>,
|
||||
structure_table_cache_insertion: Arc<CacheInsertionData<4>>,
|
||||
chunk_pos_map: Arc<HashMap<u32, (usize, usize, usize)>>,
|
||||
instance_buffer: Buffer,
|
||||
instance_count: usize,
|
||||
usage_vec: Arc<Mutex<Vec<usize>>>,
|
||||
@@ -214,6 +202,7 @@ impl State
|
||||
.request_adapter(&wgpu::RequestAdapterOptions::default())
|
||||
.await
|
||||
.unwrap();
|
||||
println!("{:#?}", adapter.get_info());
|
||||
let (device, queue) = adapter
|
||||
.request_device(&wgpu::DeviceDescriptor {
|
||||
required_features: Features::IMMEDIATES
|
||||
@@ -419,7 +408,6 @@ impl State
|
||||
terrain_width * terrain_height * terrain_alt
|
||||
);
|
||||
|
||||
let mut chunk_pos_map = HashMap::new();
|
||||
let total_chunk_count = terrain_height * terrain_width * terrain_alt;
|
||||
|
||||
let structure_table_request_buffer = CacheRequestBuffer::new(&device, 128);
|
||||
@@ -443,7 +431,6 @@ impl State
|
||||
//dbg!(chunk_id);
|
||||
let chunk_id = y * terrain_width * terrain_height + z * terrain_width + x;
|
||||
|
||||
chunk_pos_map.insert(chunk_id as u32, (x, y, z));
|
||||
InstanceAttribute {
|
||||
x: x as f32,
|
||||
y: y as f32,
|
||||
@@ -720,7 +707,6 @@ impl State
|
||||
let d = fullfill_request(
|
||||
&terrain_generator,
|
||||
&work_item.key,
|
||||
&Default::default(),
|
||||
&structure_table_1,
|
||||
);
|
||||
(
|
||||
@@ -795,7 +781,6 @@ impl State
|
||||
camera: Default::default(),
|
||||
instance_buffer,
|
||||
instance_count,
|
||||
chunk_pos_map: chunk_pos_map.into(),
|
||||
rm_time: Arc::new(Mutex::new(0.)),
|
||||
frame_time: Arc::new(Mutex::new(0.)),
|
||||
terrain_width,
|
||||
@@ -1107,9 +1092,19 @@ impl State
|
||||
let mut prof_command_encoder = ProfilingEncoder::new(&self.device, &mut command_encoder);
|
||||
|
||||
{
|
||||
self.structure_table
|
||||
.lock()
|
||||
.move_position(&mut prof_command_encoder, self.camera.position);
|
||||
let retired = self.structure_table.lock().move_position(
|
||||
&self.queue,
|
||||
&mut prof_command_encoder,
|
||||
self.camera.position,
|
||||
);
|
||||
|
||||
// Cancellation is only an optimisation: stale insertions are
|
||||
// rejected by the GPU because they no longer match the slot.
|
||||
let mut request_queue = self.request_queue.lock();
|
||||
for structure in retired
|
||||
{
|
||||
request_queue.invalidate_structure(structure);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1369,7 +1364,6 @@ impl State
|
||||
self.insertion_debounce = true;
|
||||
let frame_id: FrameId = self.voxel_cache.lock().current_timestamp().into();
|
||||
let cloned_queue = self.queue.clone();
|
||||
let cloned_map = self.chunk_pos_map.clone();
|
||||
let finished = Arc::new(AtomicU32::new(0));
|
||||
|
||||
// Cache requests
|
||||
@@ -1474,7 +1468,6 @@ impl State
|
||||
);
|
||||
|
||||
let cloned_queue = self.queue.clone();
|
||||
let cloned_map = self.chunk_pos_map.clone();
|
||||
|
||||
// Structure table requests
|
||||
let cloned_st_insertion_data = self.structure_table_cache_insertion.clone();
|
||||
@@ -1752,7 +1745,6 @@ pub struct ChunkImmediate
|
||||
fn fullfill_request<const N: usize>(
|
||||
generator: &dyn ChunkedProducer<N>,
|
||||
request: &RequestKey,
|
||||
map: &HashMap<u32, (usize, usize, usize)>,
|
||||
table: &Arc<Mutex<ToroidalStructureTable>>,
|
||||
) -> (
|
||||
[u32; N * N * N],
|
||||
@@ -1763,9 +1755,10 @@ fn fullfill_request<const N: usize>(
|
||||
where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
// Unpack structure id
|
||||
//let (chunk_x, chunk_y, chunk_z) = *map.get(&request.structure_id).unwrap();
|
||||
let (chunk_x, chunk_y, chunk_z) = table.lock().get_request_position(request.structure_id.0);
|
||||
// Unpack structure identity: the anchor is the table-defined content
|
||||
// identity, independent of the table slot that currently holds it.
|
||||
let anchor = request.anchor;
|
||||
let (chunk_x, chunk_y, chunk_z) = table.lock().position_for_anchor(anchor);
|
||||
|
||||
// let (chunk_x, chunk_y, chunk_z) = (
|
||||
// (u32::MAX as isize + chunk_x) as usize,
|
||||
@@ -1795,6 +1788,7 @@ where
|
||||
structure_id: request.structure_id.0,
|
||||
node_id: NTreeNodeLocator::<4>::root().as_usize() as u32,
|
||||
producer_id: request.producer_id.0,
|
||||
anchor,
|
||||
};
|
||||
}
|
||||
else
|
||||
@@ -1826,6 +1820,7 @@ where
|
||||
structure_id: request.structure_id.0,
|
||||
node_id: child_locator.as_usize() as u32,
|
||||
producer_id: request.producer_id.0,
|
||||
anchor,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user