From 3ccbfe55ebc65d5e82b571b72b89382d21ab33bb Mon Sep 17 00:00:00 2001 From: Albin Chaboissier Date: Mon, 16 Nov 2026 11:09:33 +0100 Subject: [PATCH] refactor: Merge vxls-data into vxls-production --- crates/vxls-data/Cargo.toml | 10 --- crates/vxls-data/src/lib.rs | 47 ------------- crates/vxls-production/src/host_production.rs | 69 ------------------- crates/vxls-production/src/lib.rs | 68 ++++++++++-------- .../src/sparse_tree.rs | 2 +- crates/vxls/src/main.rs | 23 +++---- 6 files changed, 50 insertions(+), 169 deletions(-) delete mode 100644 crates/vxls-data/Cargo.toml delete mode 100644 crates/vxls-data/src/lib.rs delete mode 100644 crates/vxls-production/src/host_production.rs rename crates/{vxls-data => vxls-production}/src/sparse_tree.rs (99%) diff --git a/crates/vxls-data/Cargo.toml b/crates/vxls-data/Cargo.toml deleted file mode 100644 index 9b00856..0000000 --- a/crates/vxls-data/Cargo.toml +++ /dev/null @@ -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 diff --git a/crates/vxls-data/src/lib.rs b/crates/vxls-data/src/lib.rs deleted file mode 100644 index 17f8df5..0000000 --- a/crates/vxls-data/src/lib.rs +++ /dev/null @@ -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 -{ - 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()) - } -} diff --git a/crates/vxls-production/src/host_production.rs b/crates/vxls-production/src/host_production.rs deleted file mode 100644 index 96b9bd1..0000000 --- a/crates/vxls-production/src/host_production.rs +++ /dev/null @@ -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> -where - [(); N * N * N]:, -{ - producer: P, - thread_pool: ThreadPool, -} - -impl + Sync> HostRequestHandler -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, - ) - { - request_buffer.host_download_requests(device, queue, |_requests, _metas| {}); - } - - pub fn produce_requests( - &self, - requests: &[RequestInformation], - informations: &mut [InsertionInformation], - 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; - }); - }) - } -} diff --git a/crates/vxls-production/src/lib.rs b/crates/vxls-production/src/lib.rs index 377a945..4826fb0 100644 --- a/crates/vxls-production/src/lib.rs +++ b/crates/vxls-production/src/lib.rs @@ -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: '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 -where - [(); N * N * N]:, +pub trait Has { - /// The voxel data produced by this producer - type Output: VoxelAttributes; + 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, [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()) + } } + diff --git a/crates/vxls-data/src/sparse_tree.rs b/crates/vxls-production/src/sparse_tree.rs similarity index 99% rename from crates/vxls-data/src/sparse_tree.rs rename to crates/vxls-production/src/sparse_tree.rs index 480f9c9..d36dd84 100644 --- a/crates/vxls-data/src/sparse_tree.rs +++ b/crates/vxls-production/src/sparse_tree.rs @@ -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; diff --git a/crates/vxls/src/main.rs b/crates/vxls/src/main.rs index 0941f05..4d91476 100644 --- a/crates/vxls/src/main.rs +++ b/crates/vxls/src/main.rs @@ -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 {