Starting decoupling requests
This commit is contained in:
+79
-12
@@ -17,6 +17,7 @@ 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;
|
||||
@@ -65,8 +66,11 @@ 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;
|
||||
@@ -75,6 +79,7 @@ mod gi_pipeline;
|
||||
mod gpu;
|
||||
pub mod gpu_profiler;
|
||||
mod producers;
|
||||
mod production;
|
||||
mod sparse_tree;
|
||||
mod terrain;
|
||||
mod voxel_cache;
|
||||
@@ -407,6 +412,7 @@ impl State
|
||||
(terrain_width, terrain_alt, terrain_height),
|
||||
Vec3::ZERO,
|
||||
structure_table_request_buffer.max_requests,
|
||||
0,
|
||||
);
|
||||
let structure_table_insertion_data = CacheInsertionData::new(&device, 128, &layout);
|
||||
let chunk_instances = (0..terrain_alt)
|
||||
@@ -1292,7 +1298,7 @@ impl State
|
||||
self.request_buffer.host_download_requests(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
move |request_informations| {
|
||||
move |request_informations, request_metas| {
|
||||
let done = request_buffer_done_1.load(std::sync::atomic::Ordering::Relaxed);
|
||||
if !done
|
||||
{
|
||||
@@ -1310,26 +1316,32 @@ impl State
|
||||
let mut color_attributes = vec![];
|
||||
let mut normal_attributes: Vec<[[f32; 3]; 64]> = vec![];
|
||||
let mut location_pages = vec![];
|
||||
let mut insertion_parents = vec![];
|
||||
|
||||
request_informations
|
||||
.par_iter()
|
||||
.map(|request| {
|
||||
.zip(request_metas.par_iter())
|
||||
.map(|(request, meta)| {
|
||||
fullfill_request(
|
||||
cloned_generator.as_ref(),
|
||||
request,
|
||||
meta,
|
||||
cloned_map.as_ref(),
|
||||
&cloned_table_1,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.for_each(|(colors, normals, insertion_info, location)| {
|
||||
.for_each(|(colors, normals, insertion_info, location, parent)| {
|
||||
insertion_infos.push(insertion_info);
|
||||
color_attributes.push(colors);
|
||||
normal_attributes.push(std::array::from_fn(|i| normals[i].into()));
|
||||
location_pages.push(location);
|
||||
insertion_parents.push(parent);
|
||||
});
|
||||
|
||||
let request_count = request_informations.len() as u32;
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_insertion_data.insertion_information_buffer(),
|
||||
0,
|
||||
@@ -1342,6 +1354,12 @@ impl State
|
||||
bytemuck::cast_slice(&location_pages),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_insertion_data.insertion_parents_buffer(),
|
||||
0,
|
||||
bytemuck::cast_slice(&insertion_parents),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
&cloned_insertion_data.attributes_buffers()[0],
|
||||
0,
|
||||
@@ -1354,10 +1372,22 @@ impl State
|
||||
bytemuck::cast_slice(&normal_attributes),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_insertion_data.destination_indices_buffer(),
|
||||
0,
|
||||
bytemuck::cast_slice(&vec![u32::MAX; request_count as usize]),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_insertion_data.valid_count_buffer(),
|
||||
0,
|
||||
bytemuck::bytes_of(&0u32),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_insertion_data.page_count_buffer(),
|
||||
0,
|
||||
bytemuck::bytes_of(&(request_informations.len() as u32)),
|
||||
bytemuck::bytes_of(&request_count),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1375,7 +1405,7 @@ impl State
|
||||
self.structure_table_request_buffer.host_download_requests(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
move |request_informations| {
|
||||
move |request_informations, request_metas| {
|
||||
let done = structure_table_request_buffer_done_1
|
||||
.load(std::sync::atomic::Ordering::Relaxed);
|
||||
if !done
|
||||
@@ -1395,26 +1425,32 @@ impl State
|
||||
let mut color_attributes = vec![];
|
||||
let mut normal_attributes: Vec<[[f32; 3]; 64]> = vec![];
|
||||
let mut location_pages = vec![];
|
||||
let mut insertion_parents = vec![];
|
||||
|
||||
request_informations
|
||||
.par_iter()
|
||||
.map(|request| {
|
||||
.zip(request_metas.par_iter())
|
||||
.map(|(request, meta)| {
|
||||
fullfill_request(
|
||||
cloned_generator.as_ref(),
|
||||
request,
|
||||
meta,
|
||||
cloned_map.as_ref(),
|
||||
&cloned_table_2,
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.for_each(|(colors, normals, insertion_info, location)| {
|
||||
.for_each(|(colors, normals, insertion_info, location, parent)| {
|
||||
insertion_infos.push(insertion_info);
|
||||
color_attributes.push(colors);
|
||||
normal_attributes.push(std::array::from_fn(|i| normals[i].into()));
|
||||
location_pages.push(location);
|
||||
insertion_parents.push(parent);
|
||||
});
|
||||
|
||||
let request_count = request_informations.len() as u32;
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_st_insertion_data.insertion_information_buffer(),
|
||||
0,
|
||||
@@ -1427,6 +1463,12 @@ impl State
|
||||
bytemuck::cast_slice(&location_pages),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_st_insertion_data.insertion_parents_buffer(),
|
||||
0,
|
||||
bytemuck::cast_slice(&insertion_parents),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
&cloned_st_insertion_data.attributes_buffers()[0],
|
||||
0,
|
||||
@@ -1439,10 +1481,22 @@ impl State
|
||||
bytemuck::cast_slice(&normal_attributes),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_st_insertion_data.destination_indices_buffer(),
|
||||
0,
|
||||
bytemuck::cast_slice(&vec![u32::MAX; request_count as usize]),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_st_insertion_data.valid_count_buffer(),
|
||||
0,
|
||||
bytemuck::bytes_of(&0u32),
|
||||
);
|
||||
|
||||
cloned_queue.write_buffer(
|
||||
cloned_st_insertion_data.page_count_buffer(),
|
||||
0,
|
||||
bytemuck::bytes_of(&(request_informations.len() as u32)),
|
||||
bytemuck::bytes_of(&request_count),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -1614,7 +1668,6 @@ impl State
|
||||
),
|
||||
&mut VoxelCacheInsertion::InternalRequest(
|
||||
&self.cache_insertion,
|
||||
&self.request_buffer,
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -1623,7 +1676,6 @@ impl State
|
||||
&self.device,
|
||||
&mut scoped_encoder,
|
||||
&self.structure_table_cache_insertion,
|
||||
&self.structure_table_request_buffer,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1762,6 +1814,7 @@ pub struct ChunkImmediate
|
||||
fn fullfill_request<const N: usize>(
|
||||
generator: &dyn ChunkedProducer<N>,
|
||||
request: &RequestInformation,
|
||||
meta: &RequestMeta,
|
||||
map: &HashMap<u32, (usize, usize, usize)>,
|
||||
table: &Arc<Mutex<ToroidalStructureTable>>,
|
||||
) -> (
|
||||
@@ -1769,6 +1822,7 @@ fn fullfill_request<const N: usize>(
|
||||
[[f32; 3]; N * N * N],
|
||||
InsertionInformation<N>,
|
||||
LocationPage,
|
||||
InsertionParent,
|
||||
)
|
||||
where
|
||||
[(); N * N * N]:,
|
||||
@@ -1795,14 +1849,19 @@ where
|
||||
|
||||
let location;
|
||||
let node;
|
||||
if request.node_id == 0
|
||||
let parent;
|
||||
if meta.page_index == NO_PARENT_PAGE
|
||||
{
|
||||
// Produce root node
|
||||
// Produce root node. An external (structure-table) request is the only
|
||||
// one without a parent page; `node_id == 0` also happens for child 0 of
|
||||
// the root, so it cannot be used to detect roots.
|
||||
node = generator.produce_node(0, 0, 0, 0, (chunk_x, chunk_y, chunk_z));
|
||||
location = LocationPage {
|
||||
structure_id: request.structure_id,
|
||||
node_id: NTreeNodeLocator::<4>::root().as_usize() as u32,
|
||||
producer_id: request.producer_id,
|
||||
};
|
||||
parent = InsertionParent::external(request.structure_id, request.producer_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1824,7 +1883,14 @@ where
|
||||
location = LocationPage {
|
||||
structure_id: request.structure_id,
|
||||
node_id: child_locator.as_usize() as u32,
|
||||
producer_id: request.producer_id,
|
||||
};
|
||||
parent = InsertionParent::internal(
|
||||
meta,
|
||||
request.structure_id,
|
||||
request.node_id,
|
||||
request.producer_id,
|
||||
);
|
||||
}
|
||||
|
||||
(
|
||||
@@ -1834,5 +1900,6 @@ where
|
||||
children: node.children,
|
||||
},
|
||||
location,
|
||||
parent,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user