refactor: Merge vxls-data into vxls-production

This commit is contained in:
2026-11-16 11:09:33 +01:00
parent cbb3b4eaf0
commit 3ccbfe55eb
6 changed files with 50 additions and 169 deletions
-10
View File
@@ -1,10 +0,0 @@
[package]
name = "vxls-data"
version = "0.1.0"
edition = "2024"
[dependencies]
vxls-production = { path = "../vxls-production" }
bytemuck.workspace = true
itertools.workspace = true
-47
View File
@@ -1,47 +0,0 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
//!
//! This crate contains types and structures to store voxel data
//!
pub mod sparse_tree;
/// A voxel attribute must be able to be turned into bytes, and just be a bit of data
pub trait Attribute:
// An attribute can be turned into predictable, safe, raw bytes
bytemuck::Pod +
bytemuck::Zeroable +
// It can be compared with itself, equal attributes mean they can be merged in a sparse structure
PartialEq +
Eq +
// It can be crated by anybody, without knowing what is inside
Default +
// It can be moved arround without problems, and does not depend on anything
Clone +
Copy +
Send +
Sync +
'static
{
/// Many attributes can be averaged together
fn average(attributes: &[Self]) -> Self;
}
pub trait Has<A: Attribute>
{
fn get(&self) -> &A;
fn get_mut(&mut self) -> &mut A;
fn get_bytes(&self) -> &[u8]
{
bytemuck::bytes_of(self.get())
}
fn get_bytes_mut(&mut self) -> &mut [u8]
{
bytemuck::bytes_of_mut(self.get_mut())
}
}
@@ -1,69 +0,0 @@
use rayon::ThreadPool;
use rayon::iter::IndexedParallelIterator;
use rayon::iter::IntoParallelRefIterator;
use rayon::iter::IntoParallelRefMutIterator;
use rayon::iter::ParallelIterator;
use crate::VoxelProducer;
use vxls_voxel_cache::insertion::CacheInsertionData;
use vxls_voxel_cache::requests::CacheRequestBuffer;
use vxls_voxel_cache::schema::InsertionInformation;
use vxls_voxel_cache::schema::RequestInformation;
/// Handles requests made by the cache on the host
pub struct HostRequestHandler<const N: usize, P: VoxelProducer<N>>
where
[(); N * N * N]:,
{
producer: P,
thread_pool: ThreadPool,
}
impl<const N: usize, P: VoxelProducer<N> + Sync> HostRequestHandler<N, P>
where
[(); N * N * N]:,
{
pub fn new(producer: P, thread_pool: ThreadPool) -> Self
{
Self {
producer,
thread_pool,
}
}
pub fn fullfill(
&self,
device: &wgpu::Device,
queue: &wgpu::Queue,
request_buffer: &CacheRequestBuffer,
insertion: &CacheInsertionData<N>,
)
{
request_buffer.host_download_requests(device, queue, |_requests, _metas| {});
}
pub fn produce_requests(
&self,
requests: &[RequestInformation],
informations: &mut [InsertionInformation<N>],
attributes: &mut [[P::Output; N * N * N]],
)
{
self.thread_pool.install(|| {
requests
.par_iter()
.zip(informations.par_iter_mut())
.zip(attributes.par_iter_mut())
.for_each(|((request, dest_information), dest_attributes)| {
let (info, attributes) = self.producer.produce(
super::ProducerId(0),
request.anchor,
super::StructureLocator(request.node_id),
);
*dest_information = info;
*dest_attributes = attributes;
});
})
}
}
+38 -30
View File
@@ -1,23 +1,22 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use bytemuck::Pod;
use bytemuck::Zeroable;
use vxls_voxel_cache::schema::InsertionInformation;
pub use vxls_voxel_cache::schema::StructureAnchor;
/// A structure locator format to locate node within an ntree
pub mod tree_locator;
/// Facilities for voxel production on the host (CPU) side
pub mod host_production;
/// Sparse NTree to store voxel data
pub mod sparse_tree;
/// Bounded, deduplicating, priority-ordered cache request queue
pub mod request_queue;
/// This module contains definition and common logic to produce voxel data to feed a [`VoxelCache`]
/// A cache might hold data owned by multiple different producers. To discriminate where to route the
/// request, a node is always tagged by a [`ProducerId`].
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroable, Pod)]
@@ -30,34 +29,43 @@ pub struct ProducerId(pub u32);
#[repr(transparent)]
pub struct StructureLocator(pub u32);
/// For structs which can be used as a voxel attribute source
pub trait VoxelAttributes<const N: usize>: 'static + Clone + Send + Sync
{
/// The amount of attributes this struct holds
fn attribute_count() -> usize;
/// A voxel attribute must be able to be turned into bytes, and just be a bit of data
pub trait Attribute:
// An attribute can be turned into predictable, safe, raw bytes
bytemuck::Pod +
bytemuck::Zeroable +
/// Must returns the words for a single attribute.
fn attribute(&self, attribute_index: usize) -> &[u32];
// It can be compared with itself, equal attributes mean they can be merged in a sparse structure
PartialEq +
Eq +
// It can be crated by anybody, without knowing what is inside
Default +
// It can be moved arround without problems, and does not depend on anything
Clone +
Copy +
Send +
Sync +
'static
{
/// Many attributes can be averaged together
fn average(attributes: &[Self]) -> Self;
}
/// Represents something that can produce a voxel node.
pub trait VoxelProducer<const N: usize>
where
[(); N * N * N]:,
pub trait Has<A: Attribute>
{
/// The voxel data produced by this producer
type Output: VoxelAttributes<N>;
fn get(&self) -> &A;
fn get_mut(&mut self) -> &mut A;
/// A pure function that can produce a voxel node based on the owner producer
/// id, requesting structure, and the requesting location within the structure.
///
/// `anchor` is the table-defined content identity of the structure. Producers
/// must derive world position/content from it rather than from any table
/// slot: slots are placement and may change while the anchor stays stable.
fn produce(
&self,
producer_id: ProducerId,
anchor: StructureAnchor,
locator: StructureLocator,
) -> (InsertionInformation<N>, [Self::Output; N * N * N]);
fn get_bytes(&self) -> &[u8]
{
bytemuck::bytes_of(self.get())
}
fn get_bytes_mut(&mut self) -> &mut [u8]
{
bytemuck::bytes_of_mut(self.get_mut())
}
}
@@ -4,7 +4,7 @@ use bytemuck::Pod;
use bytemuck::Zeroable;
use itertools::Itertools;
use vxls_production::tree_locator::TreeLocator;
use super::tree_locator::TreeLocator;
use crate::Attribute;
+11 -12
View File
@@ -54,19 +54,20 @@ use winit::event_loop::OwnedDisplayHandle;
use winit::window::Window;
use winit::window::WindowId;
use crate::camera::Camera;
use crate::egui_renderer::EguiRenderer;
use crate::producers::ChunkedProducer;
use crate::producers::SdfGenerator;
use crate::sparse_tree::Color;
use crate::sparse_tree::NTree;
use crate::sparse_tree::NTreeNode;
use crate::sparse_tree::load_ply;
use vxls_bvh::BvhHandle;
use vxls_bvh::BvhObject;
use vxls_bvh::BvhStructureTable;
use vxls_bvh::aabb::Aabb;
use vxls_bvh::build::Bvh;
use vxls_bvh::debug::BvhDebugPipeline;
use crate::camera::Camera;
use crate::egui_renderer::EguiRenderer;
use vxls_profiler::Frame;
use vxls_profiler::Profile;
use vxls_profiler::ProfilingEncoder;
use crate::producers::ChunkedProducer;
use crate::producers::SdfGenerator;
use vxls_production::ProducerId;
use vxls_production::StructureAnchor;
use vxls_production::StructureLocator;
@@ -77,10 +78,9 @@ use vxls_production::request_queue::RequestKey;
use vxls_production::request_queue::RequestQueue;
use vxls_production::request_queue::RequestTarget;
use vxls_production::tree_locator::TreeLocator;
use crate::sparse_tree::Color;
use crate::sparse_tree::NTree;
use crate::sparse_tree::NTreeNode;
use crate::sparse_tree::load_ply;
use vxls_profiler::Frame;
use vxls_profiler::Profile;
use vxls_profiler::ProfilingEncoder;
use vxls_terrain::ToroidalStructureTable;
use vxls_voxel_cache::VoxelCache;
use vxls_voxel_cache::VoxelCacheInsertion;
@@ -96,7 +96,6 @@ mod egui_renderer;
mod gi_pipeline;
mod producers;
mod sparse_tree;
pub mod voxel_data;
enum DisplayTexture
{