Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
828806fbc8 | ||
|
|
c13a04c8e2 |
@@ -13,18 +13,18 @@ the cache inserts them.
|
||||
|
||||
The durable system is:
|
||||
|
||||
- `src/voxel_cache.rs` and `src/voxel_cache/*` — cache API and GPU passes.
|
||||
- `src/voxel_cache/shaders/*.wgsl` — runtime-specialised cache shaders.
|
||||
- `src/gpu/*` — radix sort, top-K, indirect dispatch, compaction.
|
||||
- `crates/vxls-voxel-cache/src/lib.rs` and `crates/vxls-voxel-cache/src/*` — cache API and GPU passes.
|
||||
- `crates/vxls-voxel-cache/src/shaders/*.wgsl` — runtime-specialised cache shaders.
|
||||
- `crates/vxls-gpu/src/*` — radix sort, top-K, indirect dispatch, compaction.
|
||||
- `shaders/*.slang` — render-side ray marching, compiled ahead of time.
|
||||
- `src/voxel_cache/tables.rs` + `src/terrain.rs` — structure tables
|
||||
- `crates/vxls-voxel-cache/src/tables.rs` + `crates/vxls-terrain/src/lib.rs` — structure tables
|
||||
(`FixedStructureTable`, the freelist-backed `DynamicStructureTable`, and the
|
||||
shared `StructureTableCore`) and the toroidal world wrapper.
|
||||
|
||||
> **Temporary code:** `src/main.rs` and `src/producers.rs` are a playground/test
|
||||
> **Temporary code:** `crates/vxls/src/main.rs` and `crates/vxls/src/producers.rs` are a playground/test
|
||||
> harness built alongside the cache. They contain hardcoded parameters and
|
||||
> blocking workarounds. Do not treat them as stable architecture, public API, or
|
||||
> examples of intended concurrency. The real system is `src/voxel_cache/*` and
|
||||
> examples of intended concurrency. The real system is `crates/vxls-voxel-cache/src/*` and
|
||||
> `shaders/`.
|
||||
|
||||
## Build and run
|
||||
@@ -33,11 +33,17 @@ Requirements: a **nightly** Rust toolchain (edition 2024, `generic_const_exprs`,
|
||||
`float_algebraic`) and `slangc` if you modify Slang shaders.
|
||||
|
||||
```sh
|
||||
make -C shaders # rebuild SPIR-V into shaders/out/ (checked in)
|
||||
cargo run # window + egui overlay
|
||||
cargo check # compile check
|
||||
make -C shaders # rebuild SPIR-V into shaders/out/ (checked in)
|
||||
cargo run -p vxls # window + egui overlay
|
||||
cargo check --workspace # compile check for every crate
|
||||
cargo test --workspace # unit tests (GPU tests need an adapter)
|
||||
```
|
||||
|
||||
The repository is a virtual Cargo workspace: the binary lives in `crates/vxls`,
|
||||
the durable engine is split across `crates/vxls-voxel-cache`, `crates/vxls-gpu`,
|
||||
`crates/vxls-profiler`, `crates/vxls-production`, `crates/vxls-bvh`, and
|
||||
`crates/vxls-terrain`. Use `cargo check -p <crate>` for a single crate.
|
||||
|
||||
SPIR-V files are embedded with `include_spirv_source!` / `include_spirv!` at
|
||||
Rust compile time, so after rebuilding shaders you must also rebuild Rust.
|
||||
|
||||
@@ -100,16 +106,16 @@ Do not change these casually; they are contracts between Rust, WGSL, and Slang.
|
||||
|
||||
| Task | Start at |
|
||||
|---|---|
|
||||
| Change page/pointer layout | `src/voxel_cache/schema.rs`, `src/voxel_cache/shaders/cache_common.wgsl`, `src/voxel_cache/shaders/common.wgsl` |
|
||||
| Add/change a cache attribute | `src/voxel_cache/layout.rs`, `src/voxel_cache/attributes.rs`, `src/voxel_cache/shaders/insertion.wgsl`, Slang `fetch_*` in `shaders/voxel.slang` |
|
||||
| Change request prioritisation | `src/voxel_cache/requests.rs`, `src/gpu/top_k.rs`, `src/gpu/radix_sort.rs` |
|
||||
| Change eviction | `src/voxel_cache/eviction.rs`, `src/voxel_cache/shaders/eviction.wgsl`, `src/voxel_cache/shaders/insertion.wgsl` |
|
||||
| Change insertion semantics | `src/voxel_cache.rs` (`insert`), `src/voxel_cache/pipelines.rs`, `src/voxel_cache/shaders/insertion.wgsl`, `write_pointers.wgsl` |
|
||||
| Change world/chunk lookup | `src/voxel_cache/tables.rs`, `src/terrain.rs`, `shaders/toroidal_structure_table.slang` |
|
||||
| Add/change slot allocation or table growth | `src/voxel_cache/tables.rs` (`DynamicStructureTable`, `SlotAllocator`, `StructureTableCore`) |
|
||||
| Change structure identity / anchors | `src/voxel_cache/schema.rs` (`StructureAnchor`, wire structs), `src/production/request_queue.rs`, `src/voxel_cache/tables.rs`, `src/voxel_cache/shaders/common.wgsl`, fixed-table shaders |
|
||||
| Change page/pointer layout | `crates/vxls-voxel-cache/src/schema.rs`, `crates/vxls-voxel-cache/src/shaders/cache_common.wgsl`, `crates/vxls-voxel-cache/src/shaders/common.wgsl` |
|
||||
| Add/change a cache attribute | `crates/vxls-voxel-cache/src/layout.rs`, `crates/vxls-voxel-cache/src/attributes.rs`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl`, Slang `fetch_*` in `shaders/voxel.slang` |
|
||||
| Change request prioritisation | `crates/vxls-voxel-cache/src/requests.rs`, `crates/vxls-gpu/src/top_k.rs`, `crates/vxls-gpu/src/radix_sort.rs` |
|
||||
| Change eviction | `crates/vxls-voxel-cache/src/eviction.rs`, `crates/vxls-voxel-cache/src/shaders/eviction.wgsl`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl` |
|
||||
| Change insertion semantics | `crates/vxls-voxel-cache/src/lib.rs` (`insert`), `crates/vxls-voxel-cache/src/pipelines.rs`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl`, `write_pointers.wgsl` |
|
||||
| Change world/chunk lookup | `crates/vxls-voxel-cache/src/tables.rs`, `crates/vxls-terrain/src/lib.rs`, `shaders/toroidal_structure_table.slang` |
|
||||
| Add/change slot allocation or table growth | `crates/vxls-voxel-cache/src/tables.rs` (`DynamicStructureTable`, `SlotAllocator`, `StructureTableCore`) |
|
||||
| Change structure identity / anchors | `crates/vxls-voxel-cache/src/schema.rs` (`StructureAnchor`, wire structs), `crates/vxls-production/src/request_queue.rs`, `crates/vxls-voxel-cache/src/tables.rs`, `crates/vxls-voxel-cache/src/shaders/common.wgsl`, fixed-table shaders |
|
||||
| Change ray marching/LOD | `shaders/voxel.slang`, `shaders/voxel_cache.slang`, `shaders/lod_policies.slang` |
|
||||
| Add a producer | `src/producers.rs` (interface), `src/main.rs` (`fullfill_request`), [`docs/pipeline-and-producers.md`](./docs/pipeline-and-producers.md) |
|
||||
| Add a producer | `crates/vxls/src/producers.rs` (interface), `crates/vxls/src/main.rs` (`fullfill_request`), [`docs/pipeline-and-producers.md`](./docs/pipeline-and-producers.md) |
|
||||
|
||||
## Current demo configuration
|
||||
|
||||
@@ -138,8 +144,8 @@ The full tables live in the docs. The most important ones:
|
||||
fulfilment blocks the render thread.
|
||||
- **Insertion can silently drop pages** (`destination_indices == 0xFFFFFFFF`)
|
||||
with no signal to the producer.
|
||||
- **Several modules are not wired in:** `src/production/*`, `src/tree.rs`,
|
||||
`src/host_production.rs`, and `VoxelGiPipeline`. Mark them as inactive rather
|
||||
- **Several modules are not wired in:** `crates/vxls-production/src/*`,
|
||||
`crates/vxls/src/host_production.rs`, and `VoxelGiPipeline`. Mark them as inactive rather
|
||||
than treating them as current behaviour.
|
||||
- **`gi.slang` is a stub** with legacy bindings that do not match the Rust GI
|
||||
bind group.
|
||||
@@ -154,11 +160,11 @@ The full tables live in the docs. The most important ones:
|
||||
- **Preserve the Rust/WGSL/Slang contract.** If you change a layout, update all
|
||||
three sides and the docs.
|
||||
- **Measure before optimising.** Timestamp queries and the memory profiler are
|
||||
already available (`src/gpu_profiler`).
|
||||
already available (`crates/vxls-profiler/src`).
|
||||
- **Do not "fix" dead code by assuming it is live.** Check `mod` declarations in
|
||||
`src/main.rs` first.
|
||||
`crates/vxls/src/main.rs` first.
|
||||
- **Keep the playground separate from the engine.** New durable logic belongs in
|
||||
`src/voxel_cache/*`, `src/gpu/*`, or `shaders/*`, not in `main.rs`.
|
||||
`crates/vxls-voxel-cache/src/*`, `crates/vxls-gpu/src/*`, or `shaders/*`, not in `main.rs`.
|
||||
- **Document discrepancies as observations.** If code and comments disagree,
|
||||
state what the code does, what the comment claims, and your confidence.
|
||||
|
||||
|
||||
+7
-8
@@ -1,11 +1,10 @@
|
||||
[package]
|
||||
name = "vxls"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["crates/*"]
|
||||
|
||||
[dependencies]
|
||||
bytemuck = {version = "1.25.2", features = ["derive"]}
|
||||
crevice = {version = "0.20.1", features = ["glam"]}
|
||||
[workspace.dependencies]
|
||||
bytemuck = { version = "1.25.2", features = ["derive"] }
|
||||
crevice = { version = "0.20.1", features = ["glam"] }
|
||||
egui = "0.36.1"
|
||||
egui-wgpu = "0.36.1"
|
||||
egui-winit = "0.36.1"
|
||||
@@ -22,5 +21,5 @@ pollster = "1.0.1"
|
||||
rand = "0.10.2"
|
||||
rayon = "1.12.0"
|
||||
tiff = "0.11.3"
|
||||
wgpu = {version = "30", features = ["spirv"]}
|
||||
wgpu = { version = "30", features = ["spirv"] }
|
||||
winit = "0.30.13"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "vxls-bvh"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
egui.workspace = true
|
||||
glam.workspace = true
|
||||
wgpu.workspace = true
|
||||
vxls-profiler = { path = "../vxls-profiler" }
|
||||
vxls-production = { path = "../vxls-production" }
|
||||
vxls-voxel-cache = { path = "../vxls-voxel-cache" }
|
||||
@@ -5,7 +5,7 @@ use std::num::NonZero;
|
||||
|
||||
use egui::emath::OrderedFloat;
|
||||
|
||||
use crate::bvh::gpu::GpuBvhNode;
|
||||
use crate::gpu::GpuBvhNode;
|
||||
|
||||
use super::aabb::Aabb;
|
||||
|
||||
@@ -7,8 +7,8 @@ use wgpu::BlendState;
|
||||
// WGSL rounds structs containing vec3 up to a 16-byte alignment, so a node's
|
||||
// 40 bytes of data become a 48-byte array stride.
|
||||
const _: () = {
|
||||
assert!(size_of::<crate::bvh::gpu::GpuBvhNode>() == 48);
|
||||
assert!(size_of::<crate::bvh::gpu::GpuObject>() == 144);
|
||||
assert!(size_of::<crate::gpu::GpuBvhNode>() == 48);
|
||||
assert!(size_of::<crate::gpu::GpuObject>() == 144);
|
||||
};
|
||||
|
||||
/// Renders a GPU BVH as debug geometry.
|
||||
@@ -3,7 +3,7 @@
|
||||
use glam::Mat4;
|
||||
use glam::Vec3;
|
||||
|
||||
use crate::bvh::aabb::Aabb;
|
||||
use crate::aabb::Aabb;
|
||||
|
||||
#[derive(Debug, Clone, Copy, bytemuck::Zeroable, bytemuck::Pod)]
|
||||
#[repr(C)]
|
||||
@@ -1,3 +1,5 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
//! This is an implementation of a BVH2 as a top level ray acceleration
|
||||
//! structure for objects in a scene.
|
||||
//! The build is done only on CPU and uploaded on GPU.
|
||||
@@ -7,19 +9,19 @@ use std::mem::size_of;
|
||||
|
||||
use glam::Mat4;
|
||||
|
||||
use crate::bvh::aabb::Aabb;
|
||||
use crate::bvh::build::BvhPrimitive;
|
||||
use crate::bvh::build::build_bvh;
|
||||
use crate::bvh::gpu::GpuBvhNode;
|
||||
use crate::bvh::gpu::GpuObject;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::production::ProducerId;
|
||||
use crate::production::StructureAnchor;
|
||||
use crate::voxel_cache::CacheInvalidable;
|
||||
use crate::voxel_cache::eviction::CacheEvictor;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::tables::DynamicStructureTable;
|
||||
use crate::aabb::Aabb;
|
||||
use crate::build::BvhPrimitive;
|
||||
use crate::build::build_bvh;
|
||||
use crate::gpu::GpuBvhNode;
|
||||
use crate::gpu::GpuObject;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use vxls_production::ProducerId;
|
||||
use vxls_production::StructureAnchor;
|
||||
use vxls_voxel_cache::CacheInvalidable;
|
||||
use vxls_voxel_cache::eviction::CacheEvictor;
|
||||
use vxls_voxel_cache::insertion::CacheInsertionData;
|
||||
use vxls_voxel_cache::requests::CacheRequestBuffer;
|
||||
use vxls_voxel_cache::tables::DynamicStructureTable;
|
||||
|
||||
pub mod aabb;
|
||||
pub mod build;
|
||||
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "vxls-data"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
vxls-production = { src = "../vxls-production" }
|
||||
bytemuck.workspace = true
|
||||
itertools.workspace = true
|
||||
@@ -0,0 +1,24 @@
|
||||
//!
|
||||
//! 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: bytemuck::Pod + bytemuck::Zeroable + Clone + Copy + 'static
|
||||
{
|
||||
// Whether the two attributes can be merged into one single voxel
|
||||
pub fn mergeable(&self, other: &Self) -> bool;
|
||||
|
||||
pub fn merge(&self, other: &Self) -> Self;
|
||||
pub fn merge_iter<I: Iterator<Item = S>, S: AsRef<Self>>(iter: I) -> Option<Self>
|
||||
{
|
||||
iter.reduce(<Self as Attribute>::merge).map(|x| *x.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Has<A: Attribute>
|
||||
{
|
||||
fn get(&self) -> &A;
|
||||
fn get_mut(&mut self) -> &mut A;
|
||||
}
|
||||
@@ -4,9 +4,8 @@ use std::collections::VecDeque;
|
||||
use bytemuck::Pod;
|
||||
use bytemuck::Zeroable;
|
||||
use itertools::Itertools;
|
||||
use noise::Terrace;
|
||||
|
||||
use crate::production::tree_locator::TreeLocator;
|
||||
use vxls_production::tree_locator::TreeLocator;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable)]
|
||||
#[repr(C)]
|
||||
@@ -408,9 +407,9 @@ mod test
|
||||
use glam::Vec3;
|
||||
use rand::random;
|
||||
|
||||
use crate::production::tree_locator::TreeLocator;
|
||||
use crate::sparse_tree::Color;
|
||||
use crate::sparse_tree::NTree;
|
||||
use vxls_production::tree_locator::TreeLocator;
|
||||
|
||||
#[test]
|
||||
fn constant_set()
|
||||
@@ -424,7 +423,9 @@ mod test
|
||||
#[test]
|
||||
fn load_read_same()
|
||||
{
|
||||
let file = std::fs::read_to_string("dragon.txt").unwrap();
|
||||
let file =
|
||||
std::fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/../../dragon.txt"))
|
||||
.unwrap();
|
||||
|
||||
let mut colors = vec![Color(0., 0., 0., 0.); 256 * 256 * 256];
|
||||
for line in file.lines()
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "vxls-gpu"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
itertools.workspace = true
|
||||
wgpu.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
pollster.workspace = true
|
||||
@@ -136,7 +136,7 @@ impl NonZeroBufferCompactor
|
||||
wgpu::ShaderModuleDescriptor {
|
||||
label: Some("compaction_shader_layout"),
|
||||
source: wgpu::ShaderSource::SpirV(wgpu::__macro_helpers::Cow::Borrowed(
|
||||
wgpu::include_spirv_source!("../../shaders/out/compaction.spv"),
|
||||
wgpu::include_spirv_source!("../../../shaders/out/compaction.spv"),
|
||||
)),
|
||||
},
|
||||
wgpu::ShaderRuntimeChecks {
|
||||
@@ -225,7 +225,7 @@ impl RadixSorter
|
||||
});
|
||||
|
||||
let radix_sort_shader_module =
|
||||
device.create_shader_module(include_spirv!("../../shaders/out/radix_sort.spv"));
|
||||
device.create_shader_module(include_spirv!("../../../shaders/out/radix_sort.spv"));
|
||||
|
||||
let compilation_options = wgpu::PipelineCompilationOptions {
|
||||
zero_initialize_workgroup_memory: false,
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "vxls-production"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
itertools.workspace = true
|
||||
rayon.workspace = true
|
||||
wgpu.workspace = true
|
||||
vxls-voxel-cache = { path = "../vxls-voxel-cache" }
|
||||
@@ -4,11 +4,11 @@ use rayon::iter::IntoParallelRefIterator;
|
||||
use rayon::iter::IntoParallelRefMutIterator;
|
||||
use rayon::iter::ParallelIterator;
|
||||
|
||||
use crate::production::VoxelProducer;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::schema::InsertionInformation;
|
||||
use crate::voxel_cache::schema::RequestInformation;
|
||||
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>>
|
||||
@@ -1,9 +1,11 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use bytemuck::Pod;
|
||||
use bytemuck::Zeroable;
|
||||
|
||||
use crate::voxel_cache::schema::InsertionInformation;
|
||||
use vxls_voxel_cache::schema::InsertionInformation;
|
||||
|
||||
pub use crate::voxel_cache::schema::StructureAnchor;
|
||||
pub use vxls_voxel_cache::schema::StructureAnchor;
|
||||
|
||||
/// A structure locator format to locate node within an ntree
|
||||
pub mod tree_locator;
|
||||
@@ -2,13 +2,13 @@ use std::cmp::Ordering;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::production::ProducerId;
|
||||
use crate::production::StructureLocator;
|
||||
use crate::voxel_cache::schema::InsertionParent;
|
||||
use crate::voxel_cache::schema::NO_PARENT_PAGE;
|
||||
use crate::voxel_cache::schema::RequestInformation;
|
||||
use crate::voxel_cache::schema::RequestMeta;
|
||||
use crate::voxel_cache::schema::StructureAnchor;
|
||||
use crate::ProducerId;
|
||||
use crate::StructureLocator;
|
||||
use vxls_voxel_cache::schema::InsertionParent;
|
||||
use vxls_voxel_cache::schema::NO_PARENT_PAGE;
|
||||
use vxls_voxel_cache::schema::RequestInformation;
|
||||
use vxls_voxel_cache::schema::RequestMeta;
|
||||
use vxls_voxel_cache::schema::StructureAnchor;
|
||||
|
||||
/// Monotonic frame counter owned by the host. Using `u64` avoids concerns about
|
||||
/// the cache's `u32` timestamp wrapping.
|
||||
@@ -813,7 +813,7 @@ mod tests
|
||||
{
|
||||
use super::*;
|
||||
|
||||
use crate::voxel_cache::schema::NO_TABLE_SLOT;
|
||||
use vxls_voxel_cache::schema::NO_TABLE_SLOT;
|
||||
|
||||
const PRODUCER: ProducerId = ProducerId(0);
|
||||
const ANCHOR: StructureAnchor = StructureAnchor::ZERO;
|
||||
@@ -1,6 +1,6 @@
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::production::StructureLocator;
|
||||
use crate::StructureLocator;
|
||||
|
||||
/// Compact location of a specific node within a Voxel tree data strcutrure : depth + location
|
||||
///
|
||||
@@ -10,9 +10,9 @@ use crate::production::StructureLocator;
|
||||
/// `1` digit.
|
||||
///
|
||||
/// Thus a encoded location of `1` refers to the root : Only node of depth 0
|
||||
///
|
||||
/// an encoded location of `1032` for a 4-tree, refers to from the root : going into the 0th
|
||||
/// child, then 3rd child, then 2nd child. It refers to a node of depth 3.
|
||||
///
|
||||
/// An encoded location of `1032` for a 4-tree, refers to from the root : going into the 0th
|
||||
/// child, then 3rd child, then 2nd child. It refers to a node of depth 3.
|
||||
///
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||
pub struct TreeLocator<const N: usize>
|
||||
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "vxls-profiler"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
egui.workspace = true
|
||||
wgpu.workspace = true
|
||||
@@ -14,6 +14,7 @@ use wgpu::Queue;
|
||||
|
||||
pub mod memory_profiler;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! begin_frame {
|
||||
($encoder:ident) => {
|
||||
let mut $encoder = $encoder.begin_frame(None);
|
||||
@@ -24,15 +25,13 @@ macro_rules! begin_frame {
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! begin_scope {
|
||||
($scope:ident, $name:literal) => {
|
||||
let mut $scope = $scope.begin_scope($name);
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use begin_frame;
|
||||
pub(crate) use begin_scope;
|
||||
|
||||
pub struct ScopeEncoder<'enc, 'prof_enc, T>
|
||||
{
|
||||
encoder: &'prof_enc mut ProfilingEncoder<'enc>,
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "vxls-terrain"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
glam.workspace = true
|
||||
wgpu.workspace = true
|
||||
vxls-gpu = { path = "../vxls-gpu" }
|
||||
vxls-profiler = { path = "../vxls-profiler" }
|
||||
vxls-voxel-cache = { path = "../vxls-voxel-cache" }
|
||||
@@ -1,3 +1,5 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use std::iter::FusedIterator;
|
||||
|
||||
use bytemuck::Pod;
|
||||
@@ -6,10 +8,10 @@ use glam::Vec3;
|
||||
use wgpu::CommandEncoder;
|
||||
use wgpu::include_wgsl;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group_layout;
|
||||
use crate::voxel_cache;
|
||||
use crate::voxel_cache::schema::StructureAnchor;
|
||||
use crate::voxel_cache::tables::FixedStructureTable;
|
||||
use vxls_gpu::create_multi_buffers_bind_group_layout;
|
||||
use vxls_voxel_cache;
|
||||
use vxls_voxel_cache::schema::StructureAnchor;
|
||||
use vxls_voxel_cache::tables::FixedStructureTable;
|
||||
|
||||
/// A torroidal structure table for "infinite" world purposes.
|
||||
/// Allows rendering a X*Y*Z block of chunks arround a position, like for example arround a player.
|
||||
@@ -79,7 +81,7 @@ impl ToroidalStructureTable
|
||||
});
|
||||
|
||||
let shader_module =
|
||||
device.create_shader_module(include_wgsl!("./terrain/shaders/toroidal_structure.wgsl"));
|
||||
device.create_shader_module(include_wgsl!("./shaders/toroidal_structure.wgsl"));
|
||||
|
||||
let invalidation_pass = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
label: Some("ToroidalStructureTable::invalidation_pass"),
|
||||
@@ -250,8 +252,8 @@ impl ToroidalStructureTable
|
||||
pub fn insert<const N: usize>(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
encoder: &mut crate::gpu_profiler::ScopeEncoder<wgpu::CommandEncoder>,
|
||||
insertion: &voxel_cache::insertion::CacheInsertionData<N>,
|
||||
encoder: &mut vxls_profiler::ScopeEncoder<wgpu::CommandEncoder>,
|
||||
insertion: &vxls_voxel_cache::insertion::CacheInsertionData<N>,
|
||||
) where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
@@ -262,8 +264,8 @@ impl ToroidalStructureTable
|
||||
pub fn gather_requests(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
encoder: &mut crate::gpu_profiler::ScopeEncoder<wgpu::CommandEncoder>,
|
||||
request_buffer: &voxel_cache::requests::CacheRequestBuffer,
|
||||
encoder: &mut vxls_profiler::ScopeEncoder<wgpu::CommandEncoder>,
|
||||
request_buffer: &vxls_voxel_cache::requests::CacheRequestBuffer,
|
||||
)
|
||||
{
|
||||
self.fixed_structure_table
|
||||
@@ -271,15 +273,15 @@ impl ToroidalStructureTable
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> voxel_cache::CacheInvalidable<N> for ToroidalStructureTable
|
||||
impl<const N: usize> vxls_voxel_cache::CacheInvalidable<N> for ToroidalStructureTable
|
||||
where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
fn validate_insertion(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
encoder: &mut crate::gpu_profiler::ScopeEncoder<CommandEncoder>,
|
||||
insertion: &voxel_cache::insertion::CacheInsertionData<N>,
|
||||
encoder: &mut vxls_profiler::ScopeEncoder<CommandEncoder>,
|
||||
insertion: &vxls_voxel_cache::insertion::CacheInsertionData<N>,
|
||||
) {
|
||||
self.fixed_structure_table
|
||||
.validate_insertion(device, encoder, insertion);
|
||||
@@ -287,8 +289,8 @@ where
|
||||
|
||||
fn invalidate(
|
||||
&mut self,
|
||||
encoder: &mut crate::gpu_profiler::ScopeEncoder<CommandEncoder>,
|
||||
cache_evictor: &voxel_cache::eviction::CacheEvictor,
|
||||
encoder: &mut vxls_profiler::ScopeEncoder<CommandEncoder>,
|
||||
cache_evictor: &vxls_voxel_cache::eviction::CacheEvictor,
|
||||
invalid_timestamp: u32,
|
||||
)
|
||||
{
|
||||
@@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "vxls-voxel-cache"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
wgpu.workspace = true
|
||||
vxls-gpu = { path = "../vxls-gpu" }
|
||||
vxls-profiler = { path = "../vxls-profiler" }
|
||||
@@ -2,8 +2,8 @@ use wgpu::BindGroupLayout;
|
||||
use wgpu::Buffer;
|
||||
use wgpu::BufferUsages;
|
||||
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use crate::voxel_cache::layout::CacheLayout;
|
||||
use vxls_profiler::memory_profiler;
|
||||
use crate::layout::CacheLayout;
|
||||
|
||||
/// Contains instanciated gpu buffers to hold data for cache attributes
|
||||
pub struct CacheAttributes<const N: usize>
|
||||
@@ -6,14 +6,14 @@ use wgpu::ComputePipeline;
|
||||
use wgpu::include_wgsl;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group;
|
||||
use crate::gpu::radix_sort;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use crate::gpu_profiler::{self};
|
||||
use crate::voxel_cache::CacheRessources;
|
||||
use crate::voxel_cache::create_multi_buffers_bind_group_layout;
|
||||
use crate::voxel_cache::structure::CacheStructure;
|
||||
use vxls_gpu::create_multi_buffers_bind_group;
|
||||
use vxls_gpu::radix_sort;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use vxls_profiler::memory_profiler;
|
||||
use vxls_profiler::{self};
|
||||
use crate::CacheRessources;
|
||||
use crate::create_multi_buffers_bind_group_layout;
|
||||
use crate::structure::CacheStructure;
|
||||
|
||||
/// Retains usage information about pages in the cache under the form of timestamps.
|
||||
/// Produces an eviction order from which the cache can pull pages to recycle.
|
||||
@@ -137,7 +137,7 @@ impl CacheEvictor
|
||||
) where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "CacheEvictor::prepare_eviction_list");
|
||||
vxls_profiler::begin_scope!(encoder, "CacheEvictor::prepare_eviction_list");
|
||||
// Reset lru list
|
||||
{
|
||||
let mut reset_pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
|
||||
@@ -162,7 +162,7 @@ impl CacheEvictor
|
||||
// timestamp is equal or older), instead of being orphaned when the
|
||||
// parent is recycled.
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "depth radix");
|
||||
vxls_profiler::begin_scope!(encoder, "depth radix");
|
||||
encoder.copy_buffer_to_buffer(
|
||||
structure.depth_pages(),
|
||||
0,
|
||||
@@ -183,7 +183,7 @@ impl CacheEvictor
|
||||
}
|
||||
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "indirect copy");
|
||||
vxls_profiler::begin_scope!(encoder, "indirect copy");
|
||||
let mut indirect_copy_pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
|
||||
label: Some("CacheEvictor::indirect_copy_pass"),
|
||||
timestamp_writes: None,
|
||||
@@ -200,7 +200,7 @@ impl CacheEvictor
|
||||
// equal timestamps retain the deepest-first order from the depth sort.
|
||||
// The resulting list is LRU-first with deepest-first ties.
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "timestamp radix");
|
||||
vxls_profiler::begin_scope!(encoder, "timestamp radix");
|
||||
ressources.radix_sorter.sort(
|
||||
device,
|
||||
&ressources.scratch_buffer,
|
||||
@@ -4,10 +4,10 @@ use wgpu::BindGroupLayout;
|
||||
use wgpu::BufferUsages;
|
||||
use wgpu::ShaderStages;
|
||||
|
||||
use crate::voxel_cache::layout::CacheLayout;
|
||||
use crate::voxel_cache::schema::InsertionInformation;
|
||||
use crate::voxel_cache::schema::InsertionParent;
|
||||
use crate::voxel_cache::schema::LocationPage;
|
||||
use crate::layout::CacheLayout;
|
||||
use crate::schema::InsertionInformation;
|
||||
use crate::schema::InsertionParent;
|
||||
use crate::schema::LocationPage;
|
||||
|
||||
/// Data to be inserted in a cache insertion operation
|
||||
pub struct CacheInsertionData<const N: usize>
|
||||
@@ -1,6 +1,6 @@
|
||||
use wgpu::BufferUsages;
|
||||
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use vxls_profiler::memory_profiler;
|
||||
|
||||
/// Defines how a [`VoxelCache`]'s attribute is populated upon populating a page
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -1,25 +1,27 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use std::num::NonZero;
|
||||
|
||||
use wgpu::CommandEncoder;
|
||||
use wgpu::Device;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bg_bg_layout;
|
||||
use crate::gpu::create_multi_buffers_bind_group_layout;
|
||||
use crate::gpu::radix_sort::RadixSorter;
|
||||
use crate::gpu_profiler;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use crate::gpu_profiler::memory_profiler::MemoryProfile;
|
||||
use crate::voxel_cache::attributes::CacheAttributes;
|
||||
use crate::voxel_cache::eviction::CacheEvictor;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::pipelines::CacheInsertionPass;
|
||||
use crate::voxel_cache::pipelines::CacheInvalidationPass;
|
||||
use crate::voxel_cache::pipelines::WritePointersPass;
|
||||
use crate::voxel_cache::pipelines::WriteRequestsPass;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::requests::CacheRequestHandler;
|
||||
use crate::voxel_cache::structure::CacheStructure;
|
||||
use vxls_gpu::create_multi_buffers_bg_bg_layout;
|
||||
use vxls_gpu::create_multi_buffers_bind_group_layout;
|
||||
use vxls_gpu::radix_sort::RadixSorter;
|
||||
use vxls_profiler;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use vxls_profiler::memory_profiler;
|
||||
use vxls_profiler::memory_profiler::MemoryProfile;
|
||||
use crate::attributes::CacheAttributes;
|
||||
use crate::eviction::CacheEvictor;
|
||||
use crate::insertion::CacheInsertionData;
|
||||
use crate::pipelines::CacheInsertionPass;
|
||||
use crate::pipelines::CacheInvalidationPass;
|
||||
use crate::pipelines::WritePointersPass;
|
||||
use crate::pipelines::WriteRequestsPass;
|
||||
use crate::requests::CacheRequestBuffer;
|
||||
use crate::requests::CacheRequestHandler;
|
||||
use crate::structure::CacheStructure;
|
||||
|
||||
pub mod attributes;
|
||||
pub mod eviction;
|
||||
@@ -210,7 +212,7 @@ where
|
||||
request_buffer: &CacheRequestBuffer,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "gather_requests");
|
||||
vxls_profiler::begin_scope!(encoder, "gather_requests");
|
||||
|
||||
self.request_handler.sort_requests(
|
||||
device,
|
||||
@@ -244,7 +246,7 @@ where
|
||||
insertions: &mut [&mut VoxelCacheInsertion<N>],
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "insertion");
|
||||
vxls_profiler::begin_scope!(encoder, "insertion");
|
||||
let new_timestamp = self.frame_timestamp + 1;
|
||||
|
||||
self.evictor.prepare_eviction_list(
|
||||
@@ -4,17 +4,17 @@ use wgpu::ComputePipeline;
|
||||
use wgpu::Device;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use crate::gpu_profiler;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::voxel_cache::attributes::CacheAttributes;
|
||||
use crate::voxel_cache::create_multi_buffers_bg_bg_layout;
|
||||
use crate::voxel_cache::eviction::CacheEvictor;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::layout::CacheLayout;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::requests::CacheRequestHandler;
|
||||
use crate::voxel_cache::structure::CacheStructure;
|
||||
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use vxls_profiler;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use crate::attributes::CacheAttributes;
|
||||
use crate::create_multi_buffers_bg_bg_layout;
|
||||
use crate::eviction::CacheEvictor;
|
||||
use crate::insertion::CacheInsertionData;
|
||||
use crate::layout::CacheLayout;
|
||||
use crate::requests::CacheRequestBuffer;
|
||||
use crate::requests::CacheRequestHandler;
|
||||
use crate::structure::CacheStructure;
|
||||
|
||||
macro_rules! programmatic_common_wgsl {
|
||||
($children_count:ident, $page_count:ident, $cache_layout:ident) => {
|
||||
@@ -121,7 +121,7 @@ where
|
||||
target_request_buffer: &CacheRequestBuffer,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "WriteRequests");
|
||||
vxls_profiler::begin_scope!(encoder, "WriteRequests");
|
||||
|
||||
let indirect_dispatch_buffer = self.indirect_buffer.workgroup_count(
|
||||
device,
|
||||
@@ -282,7 +282,7 @@ where
|
||||
cache_evictor: &CacheEvictor,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "PageInsertionValidation");
|
||||
vxls_profiler::begin_scope!(encoder, "PageInsertionValidation");
|
||||
|
||||
let indirect_write_dispatch = self.indirect_dispatcher.workgroup_count(
|
||||
device,
|
||||
@@ -318,7 +318,7 @@ where
|
||||
timestamp: u32,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "PageInsertion");
|
||||
vxls_profiler::begin_scope!(encoder, "PageInsertion");
|
||||
|
||||
let indirect_write_dispatch = self.indirect_dispatcher.workgroup_count(
|
||||
device,
|
||||
@@ -414,7 +414,7 @@ where
|
||||
timestamp: u32,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "CacheInvalidation");
|
||||
vxls_profiler::begin_scope!(encoder, "CacheInvalidation");
|
||||
|
||||
let mut pass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
|
||||
label: Some("CacheInvalidationPass::pass"),
|
||||
@@ -492,7 +492,7 @@ where
|
||||
cache_insertion_data: &CacheInsertionData<N>,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "WritePointers");
|
||||
vxls_profiler::begin_scope!(encoder, "WritePointers");
|
||||
|
||||
let indirect_buffer = self.indirect_buffer.workgroup_count(
|
||||
device,
|
||||
@@ -9,18 +9,18 @@ use wgpu::Device;
|
||||
use wgpu::include_wgsl;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group;
|
||||
use crate::gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use crate::gpu::radix_sort::{self};
|
||||
use crate::gpu::top_k::TopKSelector;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use crate::gpu_profiler::{self};
|
||||
use crate::voxel_cache::CacheRessources;
|
||||
use crate::voxel_cache::create_multi_buffers_bg_bg_layout;
|
||||
use crate::voxel_cache::create_multi_buffers_bind_group_layout;
|
||||
use crate::voxel_cache::schema::RequestInformation;
|
||||
use crate::voxel_cache::schema::RequestMeta;
|
||||
use vxls_gpu::create_multi_buffers_bind_group;
|
||||
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use vxls_gpu::radix_sort::{self};
|
||||
use vxls_gpu::top_k::TopKSelector;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use vxls_profiler::memory_profiler;
|
||||
use vxls_profiler::{self};
|
||||
use crate::CacheRessources;
|
||||
use crate::create_multi_buffers_bg_bg_layout;
|
||||
use crate::create_multi_buffers_bind_group_layout;
|
||||
use crate::schema::RequestInformation;
|
||||
use crate::schema::RequestMeta;
|
||||
|
||||
/// Records, handles, and produces a list of requested data inside the cache
|
||||
pub struct CacheRequestHandler<const N: usize>
|
||||
@@ -211,11 +211,11 @@ impl<const N: usize> CacheRequestHandler<N>
|
||||
k: u32,
|
||||
)
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "RequestHandler::sort_requests");
|
||||
vxls_profiler::begin_scope!(encoder, "RequestHandler::sort_requests");
|
||||
|
||||
// Select the most requested pages.
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "top_k");
|
||||
vxls_profiler::begin_scope!(encoder, "top_k");
|
||||
self.top_k.select(
|
||||
device,
|
||||
&mut encoder,
|
||||
@@ -227,7 +227,7 @@ impl<const N: usize> CacheRequestHandler<N>
|
||||
|
||||
// Gather the selected counts and indices into contiguous sort buffers.
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "gather");
|
||||
vxls_profiler::begin_scope!(encoder, "gather");
|
||||
|
||||
let gather_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("CacheRequestHandler::gather_bind_group"),
|
||||
@@ -273,7 +273,7 @@ impl<const N: usize> CacheRequestHandler<N>
|
||||
// buffer holds the keys (counts) and `sorted_requests` the values
|
||||
// (indices). `selected_count` is the indirect element count.
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "radix");
|
||||
vxls_profiler::begin_scope!(encoder, "radix");
|
||||
ressources.radix_sorter.sort(
|
||||
device,
|
||||
&ressources.scratch_buffer,
|
||||
@@ -3,11 +3,11 @@ use wgpu::BindGroupLayout;
|
||||
use wgpu::Buffer;
|
||||
use wgpu::BufferUsages;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group;
|
||||
use crate::gpu::create_multi_buffers_bind_group_layout;
|
||||
use crate::gpu_profiler::memory_profiler;
|
||||
use crate::voxel_cache::schema::DepthPage;
|
||||
use crate::voxel_cache::schema::StructurePage;
|
||||
use vxls_gpu::create_multi_buffers_bind_group;
|
||||
use vxls_gpu::create_multi_buffers_bind_group_layout;
|
||||
use vxls_profiler::memory_profiler;
|
||||
use crate::schema::DepthPage;
|
||||
use crate::schema::StructurePage;
|
||||
|
||||
/// Contains the instanciated buffers relevant to the structure of the trees
|
||||
pub struct CacheStructure<const N: usize>
|
||||
@@ -2,19 +2,19 @@ use std::collections::HashMap;
|
||||
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group;
|
||||
use crate::gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use crate::gpu_profiler::ScopeEncoder;
|
||||
use crate::gpu_profiler::memory_profiler::MemoryProfile;
|
||||
use crate::voxel_cache::CacheInvalidable;
|
||||
use crate::voxel_cache::CacheRessources;
|
||||
use crate::voxel_cache::create_multi_buffers_bg_bg_layout;
|
||||
use crate::voxel_cache::eviction::CacheEvictor;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::requests::CacheRequestHandler;
|
||||
use crate::voxel_cache::schema::CachePointer;
|
||||
use crate::voxel_cache::schema::StructureAnchor;
|
||||
use vxls_gpu::create_multi_buffers_bind_group;
|
||||
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
|
||||
use vxls_profiler::ScopeEncoder;
|
||||
use vxls_profiler::memory_profiler::MemoryProfile;
|
||||
use crate::CacheInvalidable;
|
||||
use crate::CacheRessources;
|
||||
use crate::create_multi_buffers_bg_bg_layout;
|
||||
use crate::eviction::CacheEvictor;
|
||||
use crate::insertion::CacheInsertionData;
|
||||
use crate::requests::CacheRequestBuffer;
|
||||
use crate::requests::CacheRequestHandler;
|
||||
use crate::schema::CachePointer;
|
||||
use crate::schema::StructureAnchor;
|
||||
|
||||
/// Cache keeps pages from different structures within itself.
|
||||
/// Pages are pieces of structure pointing to each other. But, in order to start tracing inside the
|
||||
@@ -0,0 +1,33 @@
|
||||
[package]
|
||||
name = "vxls"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
vxls-bvh = { path = "../vxls-bvh" }
|
||||
vxls-gpu = { path = "../vxls-gpu" }
|
||||
vxls-production = { path = "../vxls-production" }
|
||||
vxls-profiler = { path = "../vxls-profiler" }
|
||||
vxls-terrain = { path = "../vxls-terrain" }
|
||||
vxls-voxel-cache = { path = "../vxls-voxel-cache" }
|
||||
|
||||
bytemuck.workspace = true
|
||||
crevice.workspace = true
|
||||
egui.workspace = true
|
||||
egui-wgpu.workspace = true
|
||||
egui-winit.workspace = true
|
||||
egui_ltreeview.workspace = true
|
||||
egui_plot.workspace = true
|
||||
env_logger.workspace = true
|
||||
fastapprox.workspace = true
|
||||
glam.workspace = true
|
||||
image.workspace = true
|
||||
indicatif.workspace = true
|
||||
itertools.workspace = true
|
||||
noise.workspace = true
|
||||
pollster.workspace = true
|
||||
rand.workspace = true
|
||||
rayon.workspace = true
|
||||
tiff.workspace = true
|
||||
wgpu.workspace = true
|
||||
winit.workspace = true
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::gi_pipeline::sparse_set::GpuSparseSet;
|
||||
use crate::voxel_cache::VoxelCache;
|
||||
use crate::voxel_cache::{self};
|
||||
use vxls_voxel_cache::VoxelCache;
|
||||
use vxls_voxel_cache::{self};
|
||||
|
||||
mod sparse_set;
|
||||
|
||||
@@ -24,19 +24,19 @@ where
|
||||
device: &wgpu::Device,
|
||||
cache_size: usize,
|
||||
max_requests: usize,
|
||||
cache_layout: &mut voxel_cache::CacheLayout,
|
||||
cache_layout: &mut vxls_voxel_cache::CacheLayout,
|
||||
) -> Self
|
||||
{
|
||||
let leaf_list_attribute = cache_layout.add_attribute(voxel_cache::CacheAttribute {
|
||||
let leaf_list_attribute = cache_layout.add_attribute(vxls_voxel_cache::CacheAttribute {
|
||||
label: Some("VoxelGiPipeline::leaf_list_pointer"),
|
||||
word_count: 1,
|
||||
init: voxel_cache::CacheAttributeInit::External,
|
||||
init: vxls_voxel_cache::CacheAttributeInit::External,
|
||||
});
|
||||
|
||||
cache_layout.add_attribute(voxel_cache::CacheAttribute {
|
||||
cache_layout.add_attribute(vxls_voxel_cache::CacheAttribute {
|
||||
label: Some("VoxelGiPipeline::radiance"),
|
||||
word_count: 3,
|
||||
init: voxel_cache::CacheAttributeInit::DontTouch,
|
||||
init: vxls_voxel_cache::CacheAttributeInit::DontTouch,
|
||||
});
|
||||
|
||||
let voxel_cache = VoxelCache::new(device, cache_size, max_requests, cache_layout);
|
||||
@@ -1,7 +1,7 @@
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::gpu::create_multi_buffers_bind_group;
|
||||
use crate::gpu::create_multi_buffers_bind_group_layout;
|
||||
use vxls_gpu::create_multi_buffers_bind_group;
|
||||
use vxls_gpu::create_multi_buffers_bind_group_layout;
|
||||
|
||||
/// To keep a set of voxel nodes in the cache
|
||||
pub struct GpuSparseSet
|
||||
@@ -54,54 +54,49 @@ use winit::event_loop::OwnedDisplayHandle;
|
||||
use winit::window::Window;
|
||||
use winit::window::WindowId;
|
||||
|
||||
use crate::bvh::BvhHandle;
|
||||
use crate::bvh::BvhObject;
|
||||
use crate::bvh::BvhStructureTable;
|
||||
use crate::bvh::aabb::Aabb;
|
||||
use crate::bvh::build::Bvh;
|
||||
use crate::bvh::debug::BvhDebugPipeline;
|
||||
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 crate::gpu_profiler::Frame;
|
||||
use crate::gpu_profiler::Profile;
|
||||
use crate::gpu_profiler::ProfilingEncoder;
|
||||
use vxls_profiler::Frame;
|
||||
use vxls_profiler::Profile;
|
||||
use vxls_profiler::ProfilingEncoder;
|
||||
use crate::producers::ChunkedProducer;
|
||||
use crate::producers::SdfGenerator;
|
||||
use crate::production::ProducerId;
|
||||
use crate::production::StructureAnchor;
|
||||
use crate::production::StructureLocator;
|
||||
use crate::production::request_queue::FrameId;
|
||||
use crate::production::request_queue::IncomingRequest;
|
||||
use crate::production::request_queue::QueueConfig;
|
||||
use crate::production::request_queue::RequestKey;
|
||||
use crate::production::request_queue::RequestQueue;
|
||||
use crate::production::request_queue::RequestTarget;
|
||||
use crate::production::tree_locator::TreeLocator;
|
||||
use vxls_production::ProducerId;
|
||||
use vxls_production::StructureAnchor;
|
||||
use vxls_production::StructureLocator;
|
||||
use vxls_production::request_queue::FrameId;
|
||||
use vxls_production::request_queue::IncomingRequest;
|
||||
use vxls_production::request_queue::QueueConfig;
|
||||
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 crate::terrain::ToroidalStructureTable;
|
||||
use crate::voxel_cache::VoxelCache;
|
||||
use crate::voxel_cache::VoxelCacheInsertion;
|
||||
use crate::voxel_cache::insertion::CacheInsertionData;
|
||||
use crate::voxel_cache::requests::CacheRequestBuffer;
|
||||
use crate::voxel_cache::schema::ChildInformation;
|
||||
use crate::voxel_cache::schema::InsertionInformation;
|
||||
use crate::voxel_cache::schema::LocationPage;
|
||||
use crate::voxel_cache::tables::FixedStructureTable;
|
||||
use vxls_terrain::ToroidalStructureTable;
|
||||
use vxls_voxel_cache::VoxelCache;
|
||||
use vxls_voxel_cache::VoxelCacheInsertion;
|
||||
use vxls_voxel_cache::insertion::CacheInsertionData;
|
||||
use vxls_voxel_cache::requests::CacheRequestBuffer;
|
||||
use vxls_voxel_cache::schema::ChildInformation;
|
||||
use vxls_voxel_cache::schema::InsertionInformation;
|
||||
use vxls_voxel_cache::schema::LocationPage;
|
||||
use vxls_voxel_cache::tables::FixedStructureTable;
|
||||
|
||||
pub mod bvh;
|
||||
mod camera;
|
||||
mod egui_renderer;
|
||||
mod gi_pipeline;
|
||||
mod gpu;
|
||||
pub mod gpu_profiler;
|
||||
mod producers;
|
||||
mod production;
|
||||
mod sparse_tree;
|
||||
mod terrain;
|
||||
mod voxel_cache;
|
||||
pub mod voxel_data;
|
||||
|
||||
enum DisplayTexture
|
||||
{
|
||||
@@ -401,16 +396,16 @@ impl State
|
||||
|
||||
let egui_renderer = EguiRenderer::new(&device, surface_format, &window);
|
||||
|
||||
let mut layout = voxel_cache::layout::CacheLayout::default();
|
||||
layout.add_attribute(voxel_cache::CacheAttribute {
|
||||
let mut layout = vxls_voxel_cache::layout::CacheLayout::default();
|
||||
layout.add_attribute(vxls_voxel_cache::CacheAttribute {
|
||||
label: Some("color"),
|
||||
word_count: 1,
|
||||
init: voxel_cache::CacheAttributeInit::External,
|
||||
init: vxls_voxel_cache::CacheAttributeInit::External,
|
||||
});
|
||||
layout.add_attribute(voxel_cache::CacheAttribute {
|
||||
layout.add_attribute(vxls_voxel_cache::CacheAttribute {
|
||||
label: Some("normal"),
|
||||
word_count: 3,
|
||||
init: voxel_cache::CacheAttributeInit::External,
|
||||
init: vxls_voxel_cache::CacheAttributeInit::External,
|
||||
});
|
||||
|
||||
let request_buffer = CacheRequestBuffer::new(&device, 1024);
|
||||
@@ -561,13 +556,13 @@ impl State
|
||||
// )
|
||||
// };
|
||||
|
||||
//let shader_module = device.create_shader_module(include_wgsl!("../shaders/voxel.wgsl"));
|
||||
//let shader_module = device.create_shader_module(include_wgsl!("../../../shaders/voxel.wgsl"));
|
||||
// let shader_module = unsafe {
|
||||
// device.create_shader_module_trusted(
|
||||
// wgpu::ShaderModuleDescriptor {
|
||||
// label: Some("../shaders/voxel.spv"),
|
||||
// label: Some("../../../shaders/voxel.spv"),
|
||||
// source: wgpu::ShaderSource::SpirV(wgpu::__macro_helpers::Cow::Borrowed(
|
||||
// wgpu::include_spirv_source!("../shaders/voxel.spv"),
|
||||
// wgpu::include_spirv_source!("../../../shaders/voxel.spv"),
|
||||
// )),
|
||||
// },
|
||||
// wgpu::ShaderRuntimeChecks {
|
||||
@@ -584,9 +579,9 @@ impl State
|
||||
let shader_module = unsafe {
|
||||
device.create_shader_module_passthrough({
|
||||
wgpu::ShaderModuleDescriptorPassthrough {
|
||||
label: wgpu::__macro_helpers::Some("../shaders/voxel.spv"),
|
||||
label: wgpu::__macro_helpers::Some("../../../shaders/voxel.spv"),
|
||||
spirv: Some(std::borrow::Cow::Borrowed(wgpu::include_spirv_source!(
|
||||
"../shaders/out/voxel.spv"
|
||||
"../../../shaders/out/voxel.spv"
|
||||
))),
|
||||
entry_points: std::borrow::Cow::Borrowed(&[
|
||||
wgpu::PassthroughShaderEntryPoint {
|
||||
@@ -607,9 +602,9 @@ impl State
|
||||
let gi_shader_module = unsafe {
|
||||
device.create_shader_module_passthrough({
|
||||
wgpu::ShaderModuleDescriptorPassthrough {
|
||||
label: wgpu::__macro_helpers::Some("../shaders/gi.spv"),
|
||||
label: wgpu::__macro_helpers::Some("../../../shaders/gi.spv"),
|
||||
spirv: Some(std::borrow::Cow::Borrowed(wgpu::include_spirv_source!(
|
||||
"../shaders/out/gi.spv"
|
||||
"../../../shaders/out/gi.spv"
|
||||
))),
|
||||
entry_points: std::borrow::Cow::Borrowed(&[
|
||||
wgpu::PassthroughShaderEntryPoint {
|
||||
@@ -1212,7 +1207,7 @@ impl State
|
||||
|
||||
encoder.write_timestamp(×tamp_query, 0);
|
||||
{
|
||||
gpu_profiler::begin_scope!(encoder, "Compute render pass");
|
||||
vxls_profiler::begin_scope!(encoder, "Compute render pass");
|
||||
let mut renderpass = encoder.begin_profiled_compute_pass("compute_render_pass");
|
||||
|
||||
renderpass.set_pipeline(&self.pipeline);
|
||||
@@ -1243,7 +1238,7 @@ impl State
|
||||
}];
|
||||
renderpass.set_immediates(0, unsafe { as_raw_bytes(&imm) });
|
||||
{
|
||||
gpu_profiler::begin_scope!(renderpass, "RT");
|
||||
vxls_profiler::begin_scope!(renderpass, "RT");
|
||||
renderpass.dispatch_workgroups(
|
||||
self.size.width.div_ceil(16),
|
||||
self.size.height.div_ceil(16),
|
||||
@@ -1372,7 +1367,7 @@ impl State
|
||||
pixels_per_point: self.window.as_ref().scale_factor() as f32,
|
||||
};
|
||||
|
||||
gpu_profiler::begin_scope!(encoder, "Egui");
|
||||
vxls_profiler::begin_scope!(encoder, "Egui");
|
||||
self.egui_renderer.end_frame_and_draw(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
@@ -1709,7 +1704,7 @@ impl State
|
||||
|
||||
let mut scoped_encoder = ProfilingEncoder::new(&self.device, &mut encoder);
|
||||
{
|
||||
gpu_profiler::begin_frame!(scoped_encoder, "Cache insertion");
|
||||
vxls_profiler::begin_frame!(scoped_encoder, "Cache insertion");
|
||||
let mut locked_st = self.structure_table.lock();
|
||||
self.voxel_cache.lock().insert(
|
||||
&self.device,
|
||||
@@ -10,7 +10,7 @@ use noise::Simplex;
|
||||
use rand::random;
|
||||
|
||||
use crate::sparse_tree::Color;
|
||||
use crate::voxel_cache::schema::ChildInformation;
|
||||
use vxls_voxel_cache::schema::ChildInformation;
|
||||
|
||||
pub struct BallGenerator<const N: usize>
|
||||
{
|
||||
@@ -0,0 +1,464 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use bytemuck::Pod;
|
||||
use bytemuck::Zeroable;
|
||||
use itertools::Itertools;
|
||||
use noise::Terrace;
|
||||
|
||||
use vxls_production::tree_locator::TreeLocator;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable)]
|
||||
#[repr(C)]
|
||||
pub struct Color(pub f32, pub f32, pub f32, pub f32);
|
||||
|
||||
impl Color
|
||||
{
|
||||
pub fn average<I: Iterator<Item = Color>>(iter: I) -> Self
|
||||
{
|
||||
let mut c = Color(0., 0., 0., 0.);
|
||||
let mut count = 0;
|
||||
for Color(r, g, b, a) in iter
|
||||
{
|
||||
count += 1;
|
||||
c.0 += r;
|
||||
c.1 += g;
|
||||
c.2 += b;
|
||||
c.3 += a;
|
||||
}
|
||||
c.0 /= count as f32;
|
||||
c.1 /= count as f32;
|
||||
c.2 /= count as f32;
|
||||
c.3 /= count as f32;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn as_packed_u32(&self) -> u32
|
||||
{
|
||||
let mapped_r = (self.0 * 255.0).clamp(0., 255.0) as u32;
|
||||
let mapped_g = (self.1 * 255.0).clamp(0., 255.0) as u32;
|
||||
let mapped_b = (self.2 * 255.0).clamp(0., 255.0) as u32;
|
||||
let mapped_a = (self.3 * 255.0).clamp(0., 255.0) as u32;
|
||||
mapped_r | (mapped_g << 8) | (mapped_b << 16) | (mapped_a << 24)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct NTree<const N: usize>
|
||||
{
|
||||
map: HashMap<TreeLocator<N>, NTreeNode>,
|
||||
|
||||
// Depth is the parameter such that
|
||||
// N^depth == max_number_of_voxels
|
||||
// one root => depth = 1
|
||||
depth: usize,
|
||||
}
|
||||
|
||||
pub struct NTreeIter<'a, const N: usize>
|
||||
{
|
||||
tree: &'a NTree<N>,
|
||||
dfs_stack: Vec<TreeLocator<N>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct NTreeNode
|
||||
{
|
||||
pub color: Color,
|
||||
pub subdivided: bool,
|
||||
}
|
||||
|
||||
impl<const N: usize> NTree<N>
|
||||
where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
pub fn constant(color: Color, depth: usize) -> Self
|
||||
{
|
||||
let mut map = HashMap::new();
|
||||
let root = NTreeNode {
|
||||
color,
|
||||
subdivided: false,
|
||||
};
|
||||
map.insert(TreeLocator::<N>::root(), root);
|
||||
Self { map, depth }
|
||||
}
|
||||
|
||||
pub fn set(&mut self, x: usize, y: usize, z: usize, color: Color)
|
||||
{
|
||||
self.set_at_depth(x, y, z, self.depth, color);
|
||||
}
|
||||
|
||||
pub fn get(&self, x: usize, y: usize, z: usize) -> Color
|
||||
{
|
||||
assert!(x < N.pow(self.depth as u32));
|
||||
assert!(y < N.pow(self.depth as u32));
|
||||
assert!(z < N.pow(self.depth as u32));
|
||||
|
||||
// Try to walk down the tree, and create necessary nodes
|
||||
let mut current_node_loc = TreeLocator::<N>::root();
|
||||
let mut current_node_size = N.pow(self.depth as u32);
|
||||
let mut current_node = self.map.get(¤t_node_loc).unwrap();
|
||||
|
||||
loop
|
||||
{
|
||||
if !current_node.subdivided
|
||||
{
|
||||
return current_node.color;
|
||||
}
|
||||
|
||||
// Descend to relevant node,
|
||||
let child_node_size = current_node_size / N;
|
||||
let child_x = (x % current_node_size) / child_node_size;
|
||||
let child_y = (y % current_node_size) / child_node_size;
|
||||
let child_z = (z % current_node_size) / child_node_size;
|
||||
current_node_size = child_node_size;
|
||||
|
||||
current_node_loc =
|
||||
current_node_loc.child(child_x as u32, child_y as u32, child_z as u32);
|
||||
current_node = self.map.get(¤t_node_loc).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_at_depth(&mut self, x: usize, y: usize, z: usize, depth: usize, color: Color)
|
||||
{
|
||||
assert!(x < N.pow(depth as u32));
|
||||
assert!(y < N.pow(depth as u32));
|
||||
assert!(z < N.pow(depth as u32));
|
||||
|
||||
// Try to walk down the tree, and create necessary nodes
|
||||
let mut current_node_loc = TreeLocator::<N>::root();
|
||||
let mut current_node_size = N.pow(self.depth as u32);
|
||||
let mut current_depth = 0;
|
||||
let mut current_node = self.map.get_mut(¤t_node_loc).unwrap();
|
||||
|
||||
while current_depth != depth
|
||||
{
|
||||
if current_node.color == color
|
||||
{
|
||||
// Color is already correct, work is finished
|
||||
return;
|
||||
}
|
||||
|
||||
// Current is not subdivided, and color is different => subdivide
|
||||
if !current_node.subdivided
|
||||
{
|
||||
current_node.subdivided = true;
|
||||
let new_nodes = NTreeNode {
|
||||
color: current_node.color,
|
||||
subdivided: false,
|
||||
};
|
||||
current_node_loc.children().for_each(|child| {
|
||||
self.map.insert(child, new_nodes);
|
||||
});
|
||||
}
|
||||
|
||||
// Descend to relevant node,
|
||||
let child_node_size = current_node_size / N;
|
||||
let child_x = (x % current_node_size) / child_node_size;
|
||||
let child_y = (y % current_node_size) / child_node_size;
|
||||
let child_z = (z % current_node_size) / child_node_size;
|
||||
current_node_size = child_node_size;
|
||||
current_depth += 1;
|
||||
|
||||
current_node_loc =
|
||||
current_node_loc.child(child_x as u32, child_y as u32, child_z as u32);
|
||||
current_node = self.map.get_mut(¤t_node_loc).unwrap();
|
||||
}
|
||||
|
||||
if current_node.subdivided
|
||||
{
|
||||
self.make_constant(current_node_loc, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
current_node.color = color;
|
||||
}
|
||||
|
||||
// We need to go back up the hierarchy to combine nodes
|
||||
// current_node is the modified node, go one up
|
||||
|
||||
loop
|
||||
{
|
||||
// Go one node up
|
||||
current_depth -= 1;
|
||||
current_node_loc = current_node_loc.parent().unwrap();
|
||||
//current_node_size *= N;
|
||||
|
||||
// Access all children's colors
|
||||
let children_color_avg = current_node_loc
|
||||
.children()
|
||||
.map(|child_loc| self.map.get(&child_loc).unwrap().color)
|
||||
// AGGREGATE AND AVERAGE HERE !!
|
||||
.next()
|
||||
.unwrap();
|
||||
|
||||
current_node = self.map.get_mut(¤t_node_loc).unwrap();
|
||||
current_node.color = children_color_avg;
|
||||
|
||||
if current_depth == 0
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn make_constant(&mut self, locator: TreeLocator<N>, color: Color)
|
||||
{
|
||||
let mut dfs_stack = Vec::new();
|
||||
dfs_stack.push(locator);
|
||||
|
||||
while let Some(current) = dfs_stack.pop()
|
||||
{
|
||||
// Remove element
|
||||
let removed = self.map.remove(¤t);
|
||||
let handle_children = removed.is_some_and(|x| x.subdivided);
|
||||
|
||||
// If children have to be handled, push on stack
|
||||
if handle_children
|
||||
{
|
||||
dfs_stack.extend(current.children());
|
||||
}
|
||||
}
|
||||
|
||||
self.map.insert(
|
||||
locator,
|
||||
NTreeNode {
|
||||
color,
|
||||
subdivided: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn from_array(array: &[Color], depth: usize) -> Self
|
||||
{
|
||||
let mut structure = HashMap::new();
|
||||
// Per voxel in the array :
|
||||
// 0 -> Voxel not merged yet
|
||||
// _ -> size of the block in which the voxel was merged
|
||||
let mut merged_size = vec![0; array.len()];
|
||||
let width = N.pow(depth as u32);
|
||||
|
||||
for (z, y) in (0..width).cartesian_product(0..width)
|
||||
{
|
||||
let mut x = 0;
|
||||
while x < width
|
||||
{
|
||||
if merged_size[x + y * width + z * width * width] != 0
|
||||
{
|
||||
// If current voxel has already been accounted for -> skip
|
||||
// We stumbled on a big merged block, we can skip it as a whole on the inner
|
||||
// dimension
|
||||
x += merged_size[x + y * width + z * width * width];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check smallest depth aligned with current position
|
||||
let x_trailing = base_trailing_zeroes::<N>(x).unwrap_or(depth as u32);
|
||||
let y_trailing = base_trailing_zeroes::<N>(y).unwrap_or(depth as u32);
|
||||
let z_trailing = base_trailing_zeroes::<N>(z).unwrap_or(depth as u32);
|
||||
|
||||
// Biggest block size power of which this voxel can be a lower corner
|
||||
let block_power = x_trailing.min(y_trailing.min(z_trailing));
|
||||
|
||||
// Try to merge for each depth
|
||||
let mut max_power_merge = 0; // Single voxel can always be merged
|
||||
let color = array[x + y * width + z * width * width];
|
||||
let mut locator =
|
||||
TreeLocator::<N>::from_node_coords(depth as u32, x as u32, y as u32, z as u32);
|
||||
'power_search: for power in 1..=block_power
|
||||
{
|
||||
let block_size = N.pow(power);
|
||||
// Check if candidate block has the same color
|
||||
for ((merge_z, merge_y), merge_x) in (0..block_size)
|
||||
.cartesian_product(0..block_size)
|
||||
.cartesian_product(0..block_size)
|
||||
{
|
||||
if array
|
||||
[(x + merge_x) + (y + merge_y) * width + (z + merge_z) * width * width]
|
||||
!= color
|
||||
{
|
||||
break 'power_search;
|
||||
}
|
||||
}
|
||||
|
||||
// Update biggest candidate block
|
||||
locator = locator.parent().unwrap();
|
||||
max_power_merge = power;
|
||||
}
|
||||
|
||||
// We know which size we can know merge
|
||||
// Say we accounted for those voxels :
|
||||
let block_size = N.pow(max_power_merge);
|
||||
for ((merge_z, merge_y), merge_x) in (0..block_size)
|
||||
.cartesian_product(0..block_size)
|
||||
.cartesian_product(0..block_size)
|
||||
{
|
||||
merged_size
|
||||
[(x + merge_x) + (y + merge_y) * width + (z + merge_z) * width * width] =
|
||||
block_size;
|
||||
}
|
||||
|
||||
// Add new found block in our structure
|
||||
// If power is depth, this is the whole structure, thus depth is 0
|
||||
let node = NTreeNode {
|
||||
color,
|
||||
subdivided: false,
|
||||
};
|
||||
structure.insert(locator, node);
|
||||
x += block_size;
|
||||
}
|
||||
}
|
||||
|
||||
// The structure now consists of the leaf most nodes, we need to rebuild the hierarchy
|
||||
// bottom up
|
||||
for current_power in 1..=depth
|
||||
{
|
||||
// Iterate on the blocks of this size
|
||||
let block_size = N.pow(current_power as u32);
|
||||
let block_count = width / block_size;
|
||||
|
||||
for ((block_x, block_y), block_z) in (0..block_count)
|
||||
.cartesian_product(0..block_count)
|
||||
.cartesian_product(0..block_count)
|
||||
{
|
||||
// Check the lower corner of this block
|
||||
let corner = merged_size[(block_x * block_size)
|
||||
+ (block_y * block_size) * width
|
||||
+ (block_z * block_size) * width * width];
|
||||
if corner >= block_size
|
||||
{
|
||||
// Children are merged in bigger block
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add hierarchy node
|
||||
let locator = TreeLocator::<N>::from_node_coords(
|
||||
(depth - current_power) as u32,
|
||||
block_x as u32,
|
||||
block_y as u32,
|
||||
block_z as u32,
|
||||
);
|
||||
|
||||
// Get average color of children
|
||||
let color = Color::average(
|
||||
locator
|
||||
.children()
|
||||
.map(|child_loc| structure.get(&child_loc).unwrap().color),
|
||||
);
|
||||
|
||||
let hierarchy_node = NTreeNode {
|
||||
color,
|
||||
subdivided: true,
|
||||
};
|
||||
structure.insert(locator, hierarchy_node);
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
map: structure,
|
||||
depth,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_by_loc(&self, locator: TreeLocator<N>) -> Option<NTreeNode>
|
||||
{
|
||||
self.map.get(&locator).copied()
|
||||
}
|
||||
}
|
||||
|
||||
fn base_trailing_zeroes<const N: usize>(mut number: usize) -> Option<u32>
|
||||
{
|
||||
if number == 0
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let mut trailing_zeroes = 0;
|
||||
while number % N == 0
|
||||
{
|
||||
number /= N;
|
||||
trailing_zeroes += 1;
|
||||
}
|
||||
|
||||
Some(trailing_zeroes)
|
||||
}
|
||||
|
||||
pub fn load_ply<P: AsRef<std::path::Path>, const N: usize>(path: P) -> NTree<N>
|
||||
where
|
||||
[(); N * N * N]:,
|
||||
{
|
||||
let file = std::fs::read_to_string(path).unwrap();
|
||||
|
||||
let mut colors = vec![Color(0., 0., 0., 0.); 256 * 256 * 256];
|
||||
for line in file.lines()
|
||||
{
|
||||
let coords = line
|
||||
.split(',')
|
||||
.take(3)
|
||||
.map(|s| s.trim_end().trim_start().parse::<u32>().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let (x, y, z) = (coords[0], coords[1], coords[2]);
|
||||
let index = x + z * 256 + y * 256 * 256;
|
||||
colors[index as usize] = Color(1., 1., 1., 1.);
|
||||
}
|
||||
|
||||
NTree::from_array(&colors, 4)
|
||||
}
|
||||
|
||||
mod test
|
||||
{
|
||||
use glam::Vec3;
|
||||
use rand::random;
|
||||
|
||||
use vxls_production::tree_locator::TreeLocator;
|
||||
use crate::sparse_tree::Color;
|
||||
use crate::sparse_tree::NTree;
|
||||
|
||||
#[test]
|
||||
fn constant_set()
|
||||
{
|
||||
let mut tree = NTree::<4>::constant(Color(0., 0., 0., 0.), 4);
|
||||
assert!(tree.get(0, 0, 0) == Color(0., 0., 0., 0.));
|
||||
tree.set(0, 0, 0, Color(1., 1., 1., 1.));
|
||||
assert!(tree.get(0, 0, 0) == Color(1., 1., 1., 1.));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_read_same()
|
||||
{
|
||||
let file = std::fs::read_to_string(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/../../dragon.txt"
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let mut colors = vec![Color(0., 0., 0., 0.); 256 * 256 * 256];
|
||||
for line in file.lines()
|
||||
{
|
||||
let coords = line
|
||||
.split(',')
|
||||
.take(3)
|
||||
.map(|s| s.trim_end().trim_start().parse::<u32>().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let (x, y, z) = (coords[0], coords[1], coords[2]);
|
||||
let index = x + z * 256 + y * 256 * 256;
|
||||
colors[index as usize] = Color(1., 1., 1., 1.);
|
||||
}
|
||||
|
||||
println!("building tree");
|
||||
let tree = NTree::<4>::from_array(&colors, 4);
|
||||
println!("ok");
|
||||
|
||||
for x in 0..256
|
||||
{
|
||||
for y in 0..256
|
||||
{
|
||||
for z in 0..256
|
||||
{
|
||||
let index = x + y * 256 + z * 256 * 256;
|
||||
let color = colors[index];
|
||||
let t = tree.get(x, y, z);
|
||||
assert!(t == color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-35
@@ -7,10 +7,10 @@ product vision that motivates it. For implementation-level detail see:
|
||||
- [`shaders.md`](./shaders.md) — Slang/WGSL shader architecture and compilation.
|
||||
- [`pipeline-and-producers.md`](./pipeline-and-producers.md) — how data gets into the cache.
|
||||
|
||||
> **Temporary code:** `src/main.rs` and `src/producers.rs` are a playground/test
|
||||
> **Temporary code:** `crates/vxls/src/main.rs` and `crates/vxls/src/producers.rs` are a playground/test
|
||||
> harness built alongside the cache. They contain hardcoded parameters and
|
||||
> blocking workarounds. Do not treat them as stable architecture, public API, or
|
||||
> examples of intended concurrency. The durable system is `src/voxel_cache/*`
|
||||
> examples of intended concurrency. The durable system is `crates/vxls-voxel-cache/src/*`
|
||||
> and `shaders/`.
|
||||
|
||||
---
|
||||
@@ -138,7 +138,7 @@ Both loops share the same request-buffer implementation and host download path.
|
||||
|
||||
## 4. Frame lifecycle (what the current driver does)
|
||||
|
||||
`State::render` in `src/main.rs` is the only driver. One iteration does roughly:
|
||||
`State::render` in `crates/vxls/src/main.rs` is the only driver. One iteration does roughly:
|
||||
|
||||
1. **Move the toroidal table** to the camera position. Chunks leaving the block
|
||||
are invalidated; chunks entering are marked as needing a root pointer.
|
||||
@@ -182,32 +182,33 @@ Consequences agents should keep in mind:
|
||||
|
||||
| Path | Role | Status |
|
||||
|---|---|---|
|
||||
| `src/main.rs` | Window, wgpu setup, frame loop, host fulfilment | **Temporary playground** |
|
||||
| `src/producers.rs` | `ChunkedProducer` + procedural fixtures | **Temporary playground** (trait is the useful part) |
|
||||
| `src/voxel_cache.rs` | `VoxelCache` orchestrator, public API, raytrace bind group | Active, durable |
|
||||
| `src/voxel_cache/schema.rs` | Pointer bits, page structs, request structs | Active, durable |
|
||||
| `src/voxel_cache/layout.rs` | Attribute descriptors and generated WGSL constants | Active, durable |
|
||||
| `src/voxel_cache/attributes.rs` | Attribute page buffers and bind group | Active, durable |
|
||||
| `src/voxel_cache/structure.rs` | Pointer/location/depth page buffers | Active, durable |
|
||||
| `src/voxel_cache/requests.rs` | Request counters, request buffer, top-K/sort, host download | Active, durable |
|
||||
| `src/voxel_cache/insertion.rs` | `CacheInsertionData` upload buffers | Active, durable |
|
||||
| `src/voxel_cache/eviction.rs` | Timestamp buffer and eviction ordering | Active, durable |
|
||||
| `src/voxel_cache/pipelines.rs` | Write-requests, insertion, invalidation, write-pointers passes | Active, durable |
|
||||
| `src/voxel_cache/tables.rs` | `FixedStructureTable` (dense root pointers) | Active, durable |
|
||||
| `src/terrain.rs` | `ToroidalStructureTable` wrapper around the fixed table | Active, durable (name is misleading) |
|
||||
| `src/gpu/` | Radix sort, top-K, indirect dispatch, compaction helpers | Active infrastructure |
|
||||
| `src/gpu_profiler/` | Timestamp profiling and memory accounting wrappers | Active infrastructure |
|
||||
| `src/gi_pipeline.rs` (+ `sparse_set.rs`) | Planned GI pipeline using cache attribute sets | **Compiled but never instantiated** |
|
||||
| `src/production.rs` | Producer ID, `StructureAnchor` re-export, `VoxelProducer` trait | Compiled; durable contract |
|
||||
| `src/production/host_production.rs` | Rayon-based `HostRequestHandler` | Compiled; `fullfill` still a stub |
|
||||
| `src/production/tree_locator.rs` | Compact N-tree locator encoding | Compiled; inactive |
|
||||
| `src/production/request_queue.rs` | Bounded, deduplicating, priority-ordered request queue | Compiled, unit-tested; not yet on the live async path |
|
||||
| `src/host_production.rs` | Legacy `ChunkVoxelProducer` trait | **Inactive** |
|
||||
| `src/tree.rs` | CPU N-tree prototype | **Inactive** |
|
||||
| `src/sparse_tree.rs` | Packed color helper and node locator used by producers | Active via `main.rs`/`producers.rs` |
|
||||
| `crates/vxls/src/main.rs` | Window, wgpu setup, frame loop, host fulfilment | **Temporary playground** |
|
||||
| `crates/vxls/src/producers.rs` | `ChunkedProducer` + procedural fixtures | **Temporary playground** (trait is the useful part) |
|
||||
| `crates/vxls-voxel-cache/src/lib.rs` | `VoxelCache` orchestrator, public API, raytrace bind group | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/schema.rs` | Pointer bits, page structs, request structs | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/layout.rs` | Attribute descriptors and generated WGSL constants | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/attributes.rs` | Attribute page buffers and bind group | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/structure.rs` | Pointer/location/depth page buffers | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/requests.rs` | Request counters, request buffer, top-K/sort, host download | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/insertion.rs` | `CacheInsertionData` upload buffers | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/eviction.rs` | Timestamp buffer and eviction ordering | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/pipelines.rs` | Write-requests, insertion, invalidation, write-pointers passes | Active, durable |
|
||||
| `crates/vxls-voxel-cache/src/tables.rs` | `FixedStructureTable` (dense root pointers) | Active, durable |
|
||||
| `crates/vxls-terrain/src/lib.rs` | `ToroidalStructureTable` wrapper around the fixed table | Active, durable (name is misleading) |
|
||||
| `crates/vxls-bvh/src/lib.rs` (+ `aabb`, `build`, `debug`, `gpu`) | CPU BVH2 build, GPU buffers, and debug render | Active infrastructure |
|
||||
| `crates/vxls-gpu/src/` | Radix sort, top-K, indirect dispatch, compaction helpers | Active infrastructure |
|
||||
| `crates/vxls-profiler/src/` | Timestamp profiling and memory accounting wrappers | Active infrastructure |
|
||||
| `crates/vxls/src/gi_pipeline.rs` (+ `sparse_set.rs`) | Planned GI pipeline using cache attribute sets | **Compiled but never instantiated** |
|
||||
| `crates/vxls-production/src/lib.rs` | Producer ID, `StructureAnchor` re-export, `VoxelProducer` trait | Compiled; durable contract |
|
||||
| `crates/vxls-production/src/host_production.rs` | Rayon-based `HostRequestHandler` | Compiled; `fullfill` still a stub |
|
||||
| `crates/vxls-production/src/tree_locator.rs` | Compact N-tree locator encoding | Compiled; inactive |
|
||||
| `crates/vxls-production/src/request_queue.rs` | Bounded, deduplicating, priority-ordered request queue | Compiled, unit-tested; not yet on the live async path |
|
||||
| `crates/vxls/src/host_production.rs` | Legacy `ChunkVoxelProducer` trait | **Inactive** |
|
||||
| `crates/vxls/src/sparse_tree.rs` | CPU `NTree` prototype, packed color helper and node locator used by producers | Active via `main.rs`/`producers.rs` |
|
||||
|
||||
`Cargo.toml` uses edition 2024 and nightly features (`generic_const_exprs`,
|
||||
`float_algebraic`). Building requires a nightly toolchain.
|
||||
The workspace uses edition 2024. Crates that use const-generic expressions enable
|
||||
`generic_const_exprs` (voxel cache, production, BVH, terrain, app); `float_algebraic`
|
||||
is only used by the app crate. Building requires a nightly toolchain.
|
||||
|
||||
---
|
||||
|
||||
@@ -254,7 +255,7 @@ There are two independent shader worlds, described fully in
|
||||
- **Slang** (`shaders/*.slang`) for rendering. Built offline with `slangc` into
|
||||
checked-in `shaders/out/*.spv`, embedded with `include_spirv_source!`, and
|
||||
loaded as passthrough modules.
|
||||
- **WGSL** (`src/voxel_cache/shaders/*.wgsl`) for cache management. Concatenated
|
||||
- **WGSL** (`crates/vxls-voxel-cache/src/shaders/*.wgsl`) for cache management. Concatenated
|
||||
at runtime with generated constants (`CHILDREN_COUNT`, `PAGE_COUNT`, attribute
|
||||
metadata) and compiled with `include_wgsl!`-style module creation.
|
||||
|
||||
@@ -295,11 +296,11 @@ demo; the UI plots both a frame timer and a ray-march timer.
|
||||
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| Location pages are sized with `size_of::<StructurePage<N>>()` (264 B at N=4) instead of `LocationPage` (28 B). | `src/voxel_cache/structure.rs:44` | ~39.6 MB allocated where ~4.2 MB is needed. | High — direct code read. |
|
||||
| The host request path busy-waits on `device.poll`, making a callback design behave synchronously. | `src/main.rs` around the `loop { ... poll ... }` after request downloads | Stalls the CPU on the render thread; prevents real pipelining/streaming. | High. |
|
||||
| Location pages are sized with `size_of::<StructurePage<N>>()` (264 B at N=4) instead of `LocationPage` (28 B). | `crates/vxls-voxel-cache/src/structure.rs:44` | ~39.6 MB allocated where ~4.2 MB is needed. | High — direct code read. |
|
||||
| The host request path busy-waits on `device.poll`, making a callback design behave synchronously. | `crates/vxls/src/main.rs` around the `loop { ... poll ... }` after request downloads | Stalls the CPU on the render thread; prevents real pipelining/streaming. | High. |
|
||||
| `VoxelTraceStack` is 5 entries and indexes `stack[10 - scale_exp/2]`, assuming `N = 4` and `chunk_power = 5`. | `shaders/voxel_cache.slang:93-96,177,189,257` | Changing branching or chunk depth silently corrupts tracing. | High. |
|
||||
| Slang hardcodes `64` children per node and attribute meanings (0 = packed color, 1 = 3-word normal). | `shaders/voxel_cache.slang`, `shaders/voxel.slang` | Any cache layout change must be mirrored in Slang; mismatches are not caught at compile time. | High. |
|
||||
| `gi.slang` is a stub that copies albedo and declares legacy bindings that do not match the Rust GI bind group. | `shaders/gi.slang`, `src/main.rs` | Works only because the declared bindings are unused; misleading as an example. | High. |
|
||||
| `FixedStructureTable` / `ToroidalStructureTable` naming: the toroidal wrapper delegates to the fixed table, and `fixed_structure_table.slang` is imported but unused by `voxel.slang`. | `src/terrain.rs`, `shaders/fixed_structure_table.slang`, `shaders/voxel.slang:3` | Readers may look for toroidal logic in the wrong shader/module. | High. |
|
||||
| Several subsystems are present but not wired into the binary (see module map). | `src/production/*`, `src/tree.rs`, `src/host_production.rs`, `src/gi_pipeline.rs` | Dead code can be mistaken for current architecture; it does not compile into the binary unless declared. | High. |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>` and a `+5000` chunk offset. | `src/main.rs:1762-1838` | Not generic over the cache branching factor; offsets are demo-specific. | High. |
|
||||
| `gi.slang` is a stub that copies albedo and declares legacy bindings that do not match the Rust GI bind group. | `shaders/gi.slang`, `crates/vxls/src/main.rs` | Works only because the declared bindings are unused; misleading as an example. | High. |
|
||||
| `FixedStructureTable` / `ToroidalStructureTable` naming: the toroidal wrapper delegates to the fixed table, and `fixed_structure_table.slang` is imported but unused by `voxel.slang`. | `crates/vxls-terrain/src/lib.rs`, `shaders/fixed_structure_table.slang`, `shaders/voxel.slang:3` | Readers may look for toroidal logic in the wrong shader/module. | High. |
|
||||
| Several subsystems are present but not wired into the binary (see module map). | `crates/vxls-production/src/*`, `crates/vxls/src/host_production.rs`, `crates/vxls/src/gi_pipeline.rs` | Dead code can be mistaken for current architecture; it does not compile into the binary unless declared. | High. |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>` and a `+5000` chunk offset. | `crates/vxls/src/main.rs:1762-1838` | Not generic over the cache branching factor; offsets are demo-specific. | High. |
|
||||
|
||||
@@ -4,7 +4,7 @@ This document follows data from a GPU-emitted request to a resident cache page,
|
||||
and describes the producer interface. It also marks which producer code is
|
||||
durable and which is throwaway.
|
||||
|
||||
> **Temporary code:** `src/main.rs` and `src/producers.rs` are a playground/test
|
||||
> **Temporary code:** `crates/vxls/src/main.rs` and `crates/vxls/src/producers.rs` are a playground/test
|
||||
> harness built alongside the cache. They contain hardcoded parameters and
|
||||
> blocking workarounds. Do not treat them as stable architecture, public API, or
|
||||
> examples of intended concurrency. The `ChunkedProducer` shape and the
|
||||
@@ -141,7 +141,7 @@ corrupting the tree.
|
||||
|
||||
## 3. The durable producer shape
|
||||
|
||||
`src/producers.rs` defines:
|
||||
`crates/vxls/src/producers.rs` defines:
|
||||
|
||||
```rust
|
||||
pub trait ChunkedProducer<const N: usize>
|
||||
@@ -184,7 +184,7 @@ child instead of hardcoding color/normal.
|
||||
|
||||
### 3.1 Fulfilling a request
|
||||
|
||||
The demo's `fullfill_request` (`src/main.rs`) does:
|
||||
The demo's `fullfill_request` (`crates/vxls/src/main.rs`) does:
|
||||
|
||||
1. Decode the table-defined anchor with
|
||||
`ToroidalStructureTable::position_for_anchor` to get an absolute chunk
|
||||
@@ -212,10 +212,10 @@ chunk dimensions of 20×20×20 and a 4-ary tree.
|
||||
|
||||
Two locator implementations exist:
|
||||
|
||||
- **`NTreeNodeLocator<N>`** (`src/sparse_tree.rs`) — used by the demo. A packed
|
||||
- **`NTreeNodeLocator<N>`** (`crates/vxls/src/sparse_tree.rs`) — used by the demo. A packed
|
||||
`usize`; supports `root`, `from_usize`, `depth`, `child`, `node_location`,
|
||||
`as_usize`, `parent`, `children`.
|
||||
- **`TreeLocator<N>`** (`src/production/tree_locator.rs`) — the unwired
|
||||
- **`TreeLocator<N>`** (`crates/vxls-production/src/tree_locator.rs`) — the unwired
|
||||
production subsystem's version. Three base-N accumulators (`x`, `y`, `z`) with
|
||||
a leading `1` digit; root is `(1,1,1)`; `depth = ilog_N(x)`; `parent` divides
|
||||
each coordinate by `N`; `child` multiplies by `N` and adds the child digit.
|
||||
@@ -229,7 +229,7 @@ coordinates. Whichever is used, it must round-trip through the 32-bit
|
||||
|
||||
## 4. The current driver, step by step
|
||||
|
||||
Relevant code: `State::render` and `fullfill_request` in `src/main.rs`.
|
||||
Relevant code: `State::render` and `fullfill_request` in `crates/vxls/src/main.rs`.
|
||||
|
||||
1. **Render** writes G-buffers and request counters.
|
||||
2. **Gather** encodes both request pipelines (cache + table) into the same
|
||||
@@ -296,7 +296,7 @@ real engine.
|
||||
|
||||
---
|
||||
|
||||
## 5. Generators in `src/producers.rs`
|
||||
## 5. Generators in `crates/vxls/src/producers.rs`
|
||||
|
||||
All are fixtures. They exist to exercise the cache and should not be treated as
|
||||
stable.
|
||||
@@ -322,11 +322,11 @@ branching logic based on `depth <= 2`.
|
||||
|
||||
## 6. The production subsystem
|
||||
|
||||
`src/production.rs` and its children are compiled (`mod production;`), but the
|
||||
`crates/vxls-production/src/lib.rs` and its children are compiled (`mod production;`), but the
|
||||
demo driver in `main.rs` still uses its synchronous `fullfill_request` path. The
|
||||
production types are the durable contract; the driver is still the playground.
|
||||
|
||||
### 6.1 `src/production.rs`
|
||||
### 6.1 `crates/vxls-production/src/lib.rs`
|
||||
|
||||
Defines a more ambitious interface:
|
||||
|
||||
@@ -375,19 +375,19 @@ table keeps an anchor's identity while it stays in view and retires anchors that
|
||||
leave. An anchor must keep naming the same content if it later re-enters; bump
|
||||
its version word when content generation changes for the same coordinates.
|
||||
|
||||
### 6.2 `src/production/host_production.rs`
|
||||
### 6.2 `crates/vxls-production/src/host_production.rs`
|
||||
|
||||
`HostRequestHandler<N, P: VoxelProducer<N>>` owns a rayon `ThreadPool` and a
|
||||
producer, and is intended to fulfil requests on the CPU. Note that its
|
||||
`fullfill` method is a stub: it downloads the request buffer with an empty
|
||||
callback. `produce_requests` does the real parallel mapping.
|
||||
|
||||
### 6.3 `src/production/tree_locator.rs`
|
||||
### 6.3 `crates/vxls-production/src/tree_locator.rs`
|
||||
|
||||
`TreeLocator<N>` (described in §3.2) plus `From<StructureLocator>` /
|
||||
`Into<StructureLocator>` conversions.
|
||||
|
||||
### 6.4 `src/production/request_queue.rs`
|
||||
### 6.4 `crates/vxls-production/src/request_queue.rs`
|
||||
|
||||
A bounded, deduplicating, priority-ordered request queue. It is the durable
|
||||
answer to "the cache re-emits the same request every frame".
|
||||
@@ -429,9 +429,9 @@ Properties:
|
||||
- `ReadyItem::insertion_parent()` builds the `InsertionParent` for the insertion
|
||||
batch from the key and the latest `RequestMeta` (which carries `table_slot`).
|
||||
|
||||
The queue is unit-tested without a GPU (`cargo test production::request_queue`).
|
||||
The queue is unit-tested without a GPU (`cargo test -p vxls-production request_queue`).
|
||||
|
||||
### 6.5 `src/host_production.rs`
|
||||
### 6.5 `crates/vxls/src/host_production.rs`
|
||||
|
||||
An older, simpler trait:
|
||||
|
||||
@@ -444,13 +444,14 @@ pub trait ChunkVoxelProducer {
|
||||
It has no return value and no cache insertion types; it predates the current
|
||||
request/response pipeline.
|
||||
|
||||
### 6.6 `src/tree.rs`
|
||||
### 6.6 `crates/vxls/src/sparse_tree.rs`
|
||||
|
||||
A CPU `NTree<N>` prototype backed by a `HashMap<NTreeLocator<N>, NTreeNode<N>>`,
|
||||
A CPU `NTree<N>` prototype backed by a `HashMap<TreeLocator<N>, NTreeNode>`,
|
||||
with `constant`, `get`, `set`, array conversion, and explicit-structure export.
|
||||
Useful for understanding the tree, not used by the renderer.
|
||||
It also provides the packed `Color` helper and PLY loading. Useful for
|
||||
understanding the tree and used by the playground producers, not by the renderer.
|
||||
|
||||
### 6.7 `src/gi_pipeline.rs` + `sparse_set.rs`
|
||||
### 6.7 `crates/vxls/src/gi_pipeline.rs` + `sparse_set.rs`
|
||||
|
||||
Compiles (declared in `main.rs`) but `VoxelGiPipeline` is never instantiated. It
|
||||
adds `DontTouch` attributes for a leaf list and radiance, and a `GpuSparseSet`
|
||||
@@ -507,15 +508,15 @@ A production-ready producer should additionally:
|
||||
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| The host request path busy-waits on `device.poll`; production blocks the render thread. | `src/main.rs` (`loop { ... poll ... }` in `render`) | No overlap, frame stalls, no streaming. | High |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>`, x/y/z child unpacking with `4` and `16`, and a `+5000` chunk offset. | `src/main.rs:1814-1905` | Not generic; offsets only make sense for the demo terrain. | High |
|
||||
| The demo driver is still synchronous: it downloads, produces, and inserts in one frame. The queue exists but `main.rs` does not schedule through it yet. | `src/main.rs` (`render`), `src/production/request_queue.rs` | No overlap between production and rendering in the demo. The durable contract is ready for an async scheduler. | High |
|
||||
| `page_count_buffer` is set to `request_informations.len()`, which may exceed `CacheInsertionData`'s `max_page_count` (1024) if `max_requests` is raised without resizing. | `src/main.rs` (write of `page_count_buffer`), `CacheInsertionData::new` | Buffer overrun / truncated production. | High |
|
||||
| The host request path busy-waits on `device.poll`; production blocks the render thread. | `crates/vxls/src/main.rs` (`loop { ... poll ... }` in `render`) | No overlap, frame stalls, no streaming. | High |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>`, x/y/z child unpacking with `4` and `16`, and a `+5000` chunk offset. | `crates/vxls/src/main.rs:1814-1905` | Not generic; offsets only make sense for the demo terrain. | High |
|
||||
| The demo driver is still synchronous: it downloads, produces, and inserts in one frame. The queue exists but `main.rs` does not schedule through it yet. | `crates/vxls/src/main.rs` (`render`), `crates/vxls-production/src/request_queue.rs` | No overlap between production and rendering in the demo. The durable contract is ready for an async scheduler. | High |
|
||||
| `page_count_buffer` is set to `request_informations.len()`, which may exceed `CacheInsertionData`'s `max_page_count` (1024) if `max_requests` is raised without resizing. | `crates/vxls/src/main.rs` (write of `page_count_buffer`), `CacheInsertionData::new` | Buffer overrun / truncated production. | High |
|
||||
| If `destination_indices[i] == 0xFFFFFFFF`, the producer is not told; the cache will re-request the node later. | `insertion.wgsl`, host callback | Wasted work and repeated requests; no metric for dropped pages. | High |
|
||||
| The external table insertion consumes the same eviction list as the cache insertion; if it inserts fewer roots than requested, the table has missing entries with no host-visible signal. | `VoxelCache::insert`, `fixed_table/insertion.wgsl` | Silent holes in the world. | Medium |
|
||||
| `TerrainGenerator` uses hardcoded mip factor 8 and `depth <= 2` special cases. | `src/producers.rs:207-263,330` | Not robust to different chunk resolutions. | High |
|
||||
| `BallGenerator` implements the old `Producer` trait, not `ChunkedProducer`. | `src/producers.rs:31-116` | Copying it as a template will not work with the current driver. | High |
|
||||
| The `production/` subsystem is compiled but not used by the demo driver. | `src/production.rs`, `src/production/*` | Agents may assume the queue is on the live path; it is the durable target, while `fullfill_request` is still the active playground path. | High |
|
||||
| `src/production/request_queue.rs` is new. | same | Its API may still change; `main.rs` does not depend on it yet. | Medium |
|
||||
| The demo uploads all attribute payloads with `bytemuck::cast_slice` of Rust arrays, so layout mismatches (padding, alignment) are not checked. | `src/main.rs` upload section | Silent corruption if the Rust struct layout diverges from the WGSL/Slang layout. | Medium |
|
||||
| The `+5000` offset plus `chunk_y.abs()` means negative chunk coordinates fold onto positive ones. | `src/main.rs:1785-1789` | Duplicate chunks / visual artifacts at negative y. | Medium |
|
||||
| `TerrainGenerator` uses hardcoded mip factor 8 and `depth <= 2` special cases. | `crates/vxls/src/producers.rs:207-263,330` | Not robust to different chunk resolutions. | High |
|
||||
| `BallGenerator` implements the old `Producer` trait, not `ChunkedProducer`. | `crates/vxls/src/producers.rs:31-116` | Copying it as a template will not work with the current driver. | High |
|
||||
| The `production/` subsystem is compiled but not used by the demo driver. | `crates/vxls-production/src/lib.rs`, `crates/vxls-production/src/*` | Agents may assume the queue is on the live path; it is the durable target, while `fullfill_request` is still the active playground path. | High |
|
||||
| `crates/vxls-production/src/request_queue.rs` is new. | same | Its API may still change; `main.rs` does not depend on it yet. | Medium |
|
||||
| The demo uploads all attribute payloads with `bytemuck::cast_slice` of Rust arrays, so layout mismatches (padding, alignment) are not checked. | `crates/vxls/src/main.rs` upload section | Silent corruption if the Rust struct layout diverges from the WGSL/Slang layout. | Medium |
|
||||
| The `+5000` offset plus `chunk_y.abs()` means negative chunk coordinates fold onto positive ones. | `crates/vxls/src/main.rs:1785-1789` | Duplicate chunks / visual artifacts at negative y. | Medium |
|
||||
|
||||
+9
-9
@@ -2,7 +2,7 @@
|
||||
|
||||
The project uses two shader languages for two different jobs:
|
||||
|
||||
| | Slang (`shaders/*.slang`) | WGSL (`src/voxel_cache/shaders/*.wgsl`) |
|
||||
| | Slang (`shaders/*.slang`) | WGSL (`crates/vxls-voxel-cache/src/shaders/*.wgsl`) |
|
||||
|---|---|---|
|
||||
| Used for | Rendering / ray marching | Cache management passes |
|
||||
| Compilation | Offline via `slangc`, SPIR-V checked in | Runtime via wgpu |
|
||||
@@ -10,9 +10,9 @@ The project uses two shader languages for two different jobs:
|
||||
| Embedded with | `include_spirv_source!` / `include_spirv!` | `include_str!` into a generated module |
|
||||
| Rust entry point | `main.rs` passthrough shader modules | `pipelines.rs`, `requests.rs`, `eviction.rs`, `tables.rs` |
|
||||
|
||||
> **Temporary code:** bind-group and pipeline setup in `src/main.rs` is part of
|
||||
> **Temporary code:** bind-group and pipeline setup in `crates/vxls/src/main.rs` is part of
|
||||
> the playground driver. Read shader contracts from the Rust cache/table
|
||||
> wrappers (`src/voxel_cache/*`) and this document, not from `main.rs` alone.
|
||||
> wrappers (`crates/vxls-voxel-cache/src/*`) and this document, not from `main.rs` alone.
|
||||
|
||||
---
|
||||
|
||||
@@ -48,8 +48,8 @@ them; edit the `.slang` source and rebuild.
|
||||
- `shaders/out/voxel.spv` → entry `ray_march_compute`, workgroup `(16,16,1)`
|
||||
- `shaders/out/gi.spv` → entry `gi`, workgroup `(16,16,1)`
|
||||
- Utility shaders are loaded with ordinary `include_spirv!`:
|
||||
- `shaders/out/radix_sort.spv` in `src/gpu/radix_sort.rs`
|
||||
- `shaders/out/compaction.spv` in `src/gpu/buffer_compactor.rs`
|
||||
- `shaders/out/radix_sort.spv` in `crates/vxls-gpu/src/radix_sort.rs`
|
||||
- `shaders/out/compaction.spv` in `crates/vxls-gpu/src/buffer_compactor.rs`
|
||||
- `radix_reduce.spv` is built by the Makefile but currently not referenced by
|
||||
Rust source.
|
||||
|
||||
@@ -504,7 +504,7 @@ Do not do this casually. Required changes include:
|
||||
|
||||
```sh
|
||||
make -C shaders # regenerates shaders/out/*.spv
|
||||
cargo run # wgpu embeds the checked-in SPIR-V at compile time
|
||||
cargo run -p vxls # wgpu embeds the checked-in SPIR-V at compile time
|
||||
```
|
||||
|
||||
Because SPIR-V is embedded with `include_*!`, changing `.spv` requires a Rust
|
||||
@@ -518,12 +518,12 @@ Makefile before building.
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| `voxel.slang` imports `fixed_structure_table` but never uses it. | `shaders/voxel.slang:3` | Misleads readers; increases compile surface. | High |
|
||||
| `gi.slang` declares legacy bindings (`structure_pool`, `attributes_pool`, request/usage buffers, table buffers) that do not match the GI bind group Rust actually creates. | `shaders/gi.slang:17-45`, `src/main.rs:563-611` | Works only because the mismatched bindings are unused. Any real GI work will hit validation errors. | High |
|
||||
| `gi.slang` declares legacy bindings (`structure_pool`, `attributes_pool`, request/usage buffers, table buffers) that do not match the GI bind group Rust actually creates. | `shaders/gi.slang:17-45`, `crates/vxls/src/main.rs:563-611` | Works only because the mismatched bindings are unused. Any real GI work will hit validation errors. | High |
|
||||
| `PixelFootprintLod` demo parameters are hardcoded (100° FOV, 1080 px, threshold 2). | `shaders/voxel.slang:149` | LOD does not follow the window/FOV; resizing the window changes effective LOD. | High |
|
||||
| `VoxelTraceStack` size and indexing assume `N = 4` and `chunk_power = 5`. | `shaders/voxel_cache.slang:93-96,177,189,257` | Branching/depth changes silently break tracing. | High |
|
||||
| `fetch_color` / `fetch_normal` hardcode stride 64 and attribute indices 0/1. | `shaders/voxel.slang:68-79` | Cache layout changes break rendering with no compile-time error. | High |
|
||||
| The child-index and child-mirror arithmetic hardcodes `4` and `16`. | `shaders/voxel_cache.slang:103-108,154-165` | Not generic over branching factor. | High |
|
||||
| The toroidal tracer walks one unit cell per axis crossing with no empty-chunk skip. | `shaders/toroidal_structure_table.slang:62-101` | Cost scales with traversed grid cells, not just occupied chunks. | Medium |
|
||||
| `chunk_*` immediate field naming/order differs between Rust (`width, height, alt`) and the table extent (`width, alt, height`). | `src/main.rs:1049-1062`, `shaders/voxel.slang:140` | Hidden because the demo uses 20×20×20; non-cubic extents would mismatch. | Medium |
|
||||
| `chunk_*` immediate field naming/order differs between Rust (`width, height, alt`) and the table extent (`width, alt, height`). | `crates/vxls/src/main.rs:1049-1062`, `shaders/voxel.slang:140` | Hidden because the demo uses 20×20×20; non-cubic extents would mismatch. | Medium |
|
||||
| `radix_reduce.spv` is built and checked in but unused. | `shaders/Makefile:1` | Confusing build artifact. | High |
|
||||
| `voxel.slang` uses `groupshared VoxelTraceStack stacks[256]` but `create_shader_module_passthrough` bypasses wgpu validation. | `shaders/voxel.slang:118`, `src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
| `voxel.slang` uses `groupshared VoxelTraceStack stacks[256]` but `create_shader_module_passthrough` bypasses wgpu validation. | `shaders/voxel.slang:118`, `crates/vxls/src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
|
||||
+13
-13
@@ -1,12 +1,12 @@
|
||||
# Voxel cache
|
||||
|
||||
`src/voxel_cache.rs` and `src/voxel_cache/*` implement a GPU-resident sparse
|
||||
`crates/vxls-voxel-cache/src/lib.rs` and `crates/vxls-voxel-cache/src/*` implement a GPU-resident sparse
|
||||
voxel cache. This document covers the page model, pointer encoding, public API,
|
||||
request/insertion pipelines, eviction, and the structure tables that provide
|
||||
entry points into the cache.
|
||||
|
||||
> **Temporary caller:** the public `VoxelCache` surface is intended API;
|
||||
> `src/main.rs` is only one caller and currently uses it in a blocking,
|
||||
> `crates/vxls/src/main.rs` is only one caller and currently uses it in a blocking,
|
||||
> single-threaded playground way. See [`pipeline-and-producers.md`](./pipeline-and-producers.md).
|
||||
|
||||
---
|
||||
@@ -167,7 +167,7 @@ Rust API: `CachePointer::new(Option<Option<u32>>)`.
|
||||
| `Some(None)` | `0x80000000` | subdividable, unavailable |
|
||||
| `Some(Some(p))` | `0xC0000000 \| p` | subdividable, available at page `p` |
|
||||
|
||||
WGSL helpers in `src/voxel_cache/shaders/common.wgsl`:
|
||||
WGSL helpers in `crates/vxls-voxel-cache/src/shaders/common.wgsl`:
|
||||
|
||||
- `child_pointer_empty(subdivisible)`
|
||||
- `child_pointer_subdivided(pointer)`
|
||||
@@ -602,7 +602,7 @@ root page? Structure tables answer that and emit requests when it is missing.
|
||||
|
||||
### 8.1 `FixedStructureTable`
|
||||
|
||||
`src/voxel_cache/tables.rs`.
|
||||
`crates/vxls-voxel-cache/src/tables.rs`.
|
||||
|
||||
- Backing buffer: one `CachePointer` per slot, initialised to
|
||||
`subdividable, unavailable`.
|
||||
@@ -625,7 +625,7 @@ The table is dense: allocation is `slot_count * 4` bytes for pointers plus
|
||||
|
||||
### 8.2 `ToroidalStructureTable`
|
||||
|
||||
`src/terrain.rs`. Wraps `FixedStructureTable` with a movable block of chunks.
|
||||
`crates/vxls-terrain/src/lib.rs`. Wraps `FixedStructureTable` with a movable block of chunks.
|
||||
|
||||
- `extent = (x, y, z)` chunk counts.
|
||||
- Slot index from local coordinates:
|
||||
@@ -650,7 +650,7 @@ is imported by `voxel.slang` but unused.
|
||||
|
||||
### 8.3 `DynamicStructureTable`
|
||||
|
||||
`src/voxel_cache/tables.rs`. A table whose slots are allocated and released at
|
||||
`crates/vxls-voxel-cache/src/tables.rs`. A table whose slots are allocated and released at
|
||||
runtime. It shares the GPU scaffolding with `FixedStructureTable` through the
|
||||
private `StructureTableCore`; only the host-side slot management differs.
|
||||
|
||||
@@ -758,12 +758,12 @@ Memory example at 150k pages and 2 attributes is tabulated in
|
||||
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| `CacheStructure::new` allocates `location_pages` with `size_of::<StructurePage<N>>()` instead of `size_of::<LocationPage>()`. | `src/voxel_cache/structure.rs:44` | At N=4, 264 B/page instead of 8 B/page: ~39.6 MB instead of ~1.2 MB for 150k pages. No correctness issue because shaders index by `LocationPage` stride. | High |
|
||||
| `StructurePage` (Rust, `u64` mask) and `PointerPage` (WGSL, two `u32`) are duplicated layout definitions. | `src/voxel_cache/schema.rs:89-100`, `src/voxel_cache/shaders/cache_common.wgsl:3-8` | Little-endian compatible today; any field reorder breaks silently. `StructurePage` is only used for sizing. | High |
|
||||
| `request_buffer_count` is written by every invocation of `write_requests.wgsl` with the same value. | `src/voxel_cache/shaders/write_requests.wgsl:50` | Benign data race (identical writes), but unnecessary and confusing. | Medium |
|
||||
| `CacheStructure::new` allocates `location_pages` with `size_of::<StructurePage<N>>()` instead of `size_of::<LocationPage>()`. | `crates/vxls-voxel-cache/src/structure.rs:44` | At N=4, 264 B/page instead of 8 B/page: ~39.6 MB instead of ~1.2 MB for 150k pages. No correctness issue because shaders index by `LocationPage` stride. | High |
|
||||
| `StructurePage` (Rust, `u64` mask) and `PointerPage` (WGSL, two `u32`) are duplicated layout definitions. | `crates/vxls-voxel-cache/src/schema.rs:89-100`, `crates/vxls-voxel-cache/src/shaders/cache_common.wgsl:3-8` | Little-endian compatible today; any field reorder breaks silently. `StructurePage` is only used for sizing. | High |
|
||||
| `request_buffer_count` is written by every invocation of `write_requests.wgsl` with the same value. | `crates/vxls-voxel-cache/src/shaders/write_requests.wgsl:50` | Benign data race (identical writes), but unnecessary and confusing. | Medium |
|
||||
| Insertion order no longer matters: each entry is validated against its `InsertionParent` and linked statelessly. | `insertion.wgsl`, `write_pointers.wgsl`, `fixed_table/insertion.wgsl` | A producer may reorder or filter results; unchanged request order is no longer a correctness requirement. | High |
|
||||
| `CacheInsertionPass` can silently insert fewer pages than requested (`0xFFFFFFFF` destinations) with no host feedback. | `src/voxel_cache/shaders/insertion.wgsl` | Producer believes data is resident; requests may repeat or data may be missing. | High |
|
||||
| The first `VoxelCache::insert` call inserts nothing: `new_timestamp = 1`, unused pages have timestamp 0, and the guard rejects `0 >= new_timestamp - 1` (`0 >= 0`). | `src/voxel_cache.rs:248`, `src/voxel_cache/shaders/insertion.wgsl:141-146` | One-frame startup delay; any external roots submitted in the first batch are dropped and must be re-requested. | High |
|
||||
| `CacheInsertionPass` can silently insert fewer pages than requested (`0xFFFFFFFF` destinations) with no host feedback. | `crates/vxls-voxel-cache/src/shaders/insertion.wgsl` | Producer believes data is resident; requests may repeat or data may be missing. | High |
|
||||
| The first `VoxelCache::insert` call inserts nothing: `new_timestamp = 1`, unused pages have timestamp 0, and the guard rejects `0 >= new_timestamp - 1` (`0 >= 0`). | `crates/vxls-voxel-cache/src/lib.rs:248`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl:141-146` | One-frame startup delay; any external roots submitted in the first batch are dropped and must be re-requested. | High |
|
||||
| Pointer/page-count limits are implicit (`< 2^30`, total elements `< 2^32`). | `schema.rs`, `requests.rs:82-85` | Large configurations fail via asserts or truncation. | High |
|
||||
| `CacheAttributeInit::DontTouch` attributes can become stale after a page is recycled; the cache deliberately does not clear them. | `src/voxel_cache/shaders/insertion.wgsl:164-178` | Any consumer of such an attribute must tolerate garbage for recycled pages. | Medium |
|
||||
| The cache exposes `usage_timestamps()` for debugging only; timestamps are also used internally for invalidation and eviction. | `src/voxel_cache.rs:445-449` | Easy to corrupt cache behaviour by writing to that buffer. | Medium |
|
||||
| `CacheAttributeInit::DontTouch` attributes can become stale after a page is recycled; the cache deliberately does not clear them. | `crates/vxls-voxel-cache/src/shaders/insertion.wgsl:164-178` | Any consumer of such an attribute must tolerate garbage for recycled pages. | Medium |
|
||||
| The cache exposes `usage_timestamps()` for debugging only; timestamps are also used internally for invalidation and eviction. | `crates/vxls-voxel-cache/src/lib.rs:445-449` | Easy to corrupt cache behaviour by writing to that buffer. | Medium |
|
||||
|
||||
Reference in New Issue
Block a user