Compare commits

..
2 Commits
26 changed files with 297 additions and 741 deletions
+37
View File
@@ -271,6 +271,43 @@ impl AttributesLayout
hash
}
///
/// Produces a wgsl declaration describing this layout :
///
/// ```wgsl
///
/// const ATTRIBUTE_COUNT: u32 = /* attribute count */;
/// const ATTRIBUTE_WORD_COUNTS: array<u32, ...> = {
/// /* word count for attribute 0 */,
/// /* word count for attribute 1 */,
/// ...
/// };
///
///
/// ```
pub fn wgsl_layout_decl(&self) -> String
{
let mut decl = String::new();
decl += &format!("const ATTRIBUTE_COUNT: u32 = {};", self.attributes.len());
// Word counts
decl += &format!(
"const ATTRIBUTE_WORD_COUNTS: array<u32, {}> = array<u32, {}>(",
self.attributes.len(),
self.attributes.len()
);
for attribute in self.attributes.iter()
{
decl += &format!(" {},", attribute.word_count);
}
decl += ");";
decl
}
}
fn fnv1a(hash: &mut u64, bytes: &[u8])
-1
View File
@@ -1,7 +1,6 @@
//! Contains rendering code to display a debug overlay for the BVH.
use glam::Mat4;
use wgpu::BlendState;
// debug.wgsl mirrors the GPU structs manually. Keep the array strides in sync:
// WGSL rounds structs containing vec3 up to a 16-byte alignment, so a node's
+2 -1
View File
@@ -1,3 +1,4 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
//! This is an implementation of a BVH2 as a top level ray acceleration
@@ -14,9 +15,9 @@ 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_profiler::ScopeEncoder;
use vxls_voxel_cache::CacheInvalidable;
use vxls_voxel_cache::eviction::CacheEvictor;
use vxls_voxel_cache::insertion::CacheInsertionData;
+2 -3
View File
@@ -12,9 +12,9 @@ use wgpu::util::DeviceExt;
pub struct NonZeroBufferCompactor
{
size: usize,
block_count: usize,
reduced_buffer: Buffer,
#[allow(unused)]
sum_buffer: Buffer,
count_buffer_bg_layout: BindGroupLayout,
compaction_bg: BindGroup,
@@ -178,7 +178,6 @@ impl NonZeroBufferCompactor
});
NonZeroBufferCompactor {
size,
block_count,
reduced_buffer,
sum_buffer,
@@ -230,7 +229,7 @@ impl NonZeroBufferCompactor
},
wgpu::BindGroupEntry {
binding: 2,
resource: compact_buffer.unwrap_or(&count_buffer).as_entire_binding(),
resource: compact_buffer.unwrap_or(count_buffer).as_entire_binding(),
},
],
});
+2 -2
View File
@@ -1,8 +1,8 @@
//! Provides utility object to manage indirect dispatches workgroup count computations on the GPU
use wgpu::Buffer;
use wgpu::CommandEncoder;
/// Provides utility object to manage indirect dispatches workgroup count computations on the GPU
/// Takes in a single u32, and computes the amount of workgroups to dispatch given a workgroup size
pub struct IndirectBuffer1D
{
+4 -8
View File
@@ -1,18 +1,12 @@
use std::num::NonZero;
use itertools::Itertools;
use wgpu::BindGroup;
use wgpu::BindGroupLayout;
use wgpu::Buffer;
use wgpu::BufferUsages;
use wgpu::CommandEncoder;
use wgpu::ComputePass;
use wgpu::ComputePipeline;
use wgpu::Device;
use wgpu::QuerySet;
use wgpu::ShaderStages;
use wgpu::include_spirv;
use wgpu::util::DeviceExt;
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum RadixSortDirection
@@ -34,14 +28,16 @@ pub struct RadixSorter
{
max_size: usize,
histogram_count: usize,
histo_block_count: usize,
#[allow(unused)]
histograms: Buffer,
histograms_bind_group: BindGroup,
data_bind_group_layout: BindGroupLayout,
#[allow(unused)]
double_buffer_keys: Buffer,
#[allow(unused)]
double_buffer_values: Buffer,
double_buffer_bind_group: BindGroup,
@@ -294,7 +290,6 @@ impl RadixSorter
RadixSorter {
max_size,
histo_block_count,
histogram_count,
histograms,
histograms_bind_group,
@@ -325,6 +320,7 @@ impl RadixSorter
/// An indirect count can be passed in `indirect` as a buffer of a single u32 on GPU.
/// A CPU side length can be passed in `direct_length`
/// `sort_direction` dictates the direction of the sort.
#[allow(clippy::too_many_arguments)]
pub fn sort(
&self,
device: &Device,
+1 -1
View File
@@ -41,7 +41,7 @@ const LOG_SUB_BINS: u32 = SUB_BINS.trailing_zeros();
/// Threads per workgroup for the histogram and selection passes.
const WORKGROUP_SIZE: u32 = 256;
const _: () = assert!(BIN_COUNT % 32 == 0);
const _: () = assert!(BIN_COUNT.is_multiple_of(32));
const _: () = assert!(SUB_BINS.is_power_of_two());
/// Parameters passed to the shader through immediates.
+4 -11
View File
@@ -171,12 +171,7 @@ impl IncomingRequest
else
{
(
RequestKey::child(
producer_id,
anchor,
request.node_id,
request.children_index,
),
RequestKey::child(producer_id, anchor, request.node_id, request.children_index),
RequestPriority::child(request.demand, meta.depth),
)
};
@@ -616,12 +611,10 @@ impl<T> RequestQueue<T>
// necessary; the failed job is already admitted, so it is not dropped
// just because the queued bound was reached while it was in flight.
if self.queued.len() >= self.config.max_queued
&& let Some(victim) = self.queued.first().copied()
{
if let Some(victim) = self.queued.first().copied()
{
self.remove_job(&victim.key);
self.stats.total_evicted += 1;
}
self.remove_job(&victim.key);
self.stats.total_evicted += 1;
}
let job = self
+3 -7
View File
@@ -115,12 +115,6 @@ pub struct NTree<const N: usize, T: Attribute>
depth: usize,
}
pub struct NTreeIter<'a, const N: usize, T: Attribute>
{
tree: &'a NTree<N, T>,
dfs_stack: Vec<TreeLocator<N>>,
}
#[derive(Debug, Clone, Copy)]
pub struct NTreeNode<T: Attribute>
{
@@ -478,7 +472,7 @@ fn base_trailing_zeroes<const N: usize>(mut number: usize) -> Option<u32>
return None;
}
let mut trailing_zeroes = 0;
while number % N == 0
while number.is_multiple_of(N)
{
number /= N;
trailing_zeroes += 1;
@@ -511,7 +505,9 @@ where
mod test
{
#[allow(unused_imports)]
use crate::sparse_tree::Color;
#[allow(unused_imports)]
use crate::sparse_tree::NTree;
#[test]
+12 -42
View File
@@ -9,9 +9,6 @@ use vxls_production::Attributes;
use vxls_production::AttributesLayout;
use vxls_production::LayoutError;
use vxls_production::ProducedNode;
use vxls_voxel_cache::CacheAttribute;
use vxls_voxel_cache::CacheAttributeInit;
use vxls_voxel_cache::CacheLayout;
use vxls_voxel_cache::schema::ChildInformation;
use vxls_voxel_cache::schema::InsertionInformation;
@@ -72,7 +69,9 @@ fn get_attr_returns_the_field_bytes()
assert!(value.try_get_attr(2).is_none());
let mut value = value;
value.get_attr_mut(0).copy_from_slice(&0xAABB_CCDDu32.to_ne_bytes());
value
.get_attr_mut(0)
.copy_from_slice(&0xAABB_CCDDu32.to_ne_bytes());
assert_eq!(value.color, 0xAABB_CCDD);
assert!(value.try_get_attr_mut(2).is_none());
}
@@ -100,38 +99,6 @@ fn average_is_component_wise_and_skips_the_reserved_field()
assert_eq!(TestAttributes::average(&[]), TestAttributes::default());
}
#[test]
fn cache_layout_starts_with_external_attributes_then_extras()
{
let layout = CacheLayout::from_attributes(
&TestAttributes::LAYOUT,
&[CacheAttribute {
label: Some("gi"),
word_count: 2,
init: CacheAttributeInit::DontTouch,
}],
);
let attributes = layout.attributes();
assert_eq!(attributes.len(), 3);
assert_eq!(attributes[0].label, Some("color"));
assert_eq!(attributes[0].word_count, 1);
assert_eq!(attributes[0].init, CacheAttributeInit::External);
assert_eq!(attributes[1].label, Some("normal"));
assert_eq!(attributes[1].word_count, 3);
assert_eq!(attributes[2].label, Some("gi"));
assert_eq!(attributes[2].word_count, 2);
assert_eq!(attributes[2].init, CacheAttributeInit::DontTouch);
assert_eq!(
CacheLayout::from_attributes(&TestAttributes::LAYOUT, &[])
.attributes()
.len(),
2
);
}
#[test]
fn validate_rejects_duplicate_labels_and_semantics()
{
@@ -152,7 +119,10 @@ fn validate_rejects_duplicate_labels_and_semantics()
assert_eq!(
DUPLICATE_LABELS.validate(),
Err(LayoutError::DuplicateLabel { first: 0, second: 1 })
Err(LayoutError::DuplicateLabel {
first: 0,
second: 1
})
);
const DUPLICATE_SEMANTICS: AttributesLayout = AttributesLayout {
@@ -164,7 +134,10 @@ fn validate_rejects_duplicate_labels_and_semantics()
assert_eq!(
DUPLICATE_SEMANTICS.validate(),
Err(LayoutError::DuplicateSemantic { first: 0, second: 1 })
Err(LayoutError::DuplicateSemantic {
first: 0,
second: 1
})
);
assert_eq!(AttributesLayout::EMPTY.validate(), Err(LayoutError::Empty));
@@ -190,10 +163,7 @@ fn produced_node_transposes_attributes_for_the_insertion_buffer()
node.write_attribute_words(1, &mut words);
assert_eq!(words.len(), 64 * 3);
assert_eq!(
&words[..3],
bytemuck::cast_slice::<f32, u32>(&value.normal)
);
assert_eq!(&words[..3], bytemuck::cast_slice::<f32, u32>(&value.normal));
node.write_attribute_words(0, &mut words);
assert_eq!(words.len(), 64);
+5 -3
View File
@@ -598,7 +598,9 @@ impl Profile
let fspan = full.1 - full.0;
let norm: (f64, f64) = ui.data_mut(|d| d.get_temp(id)).unwrap_or((0.0, 1.0));
let mut view = (full.0 + norm.0 * fspan, full.0 + norm.1 * fspan);
if !(view.1 > view.0) || !view.0.is_finite() || !view.1.is_finite()
if !(egui::emath::OrderedFloat(view.1) > egui::emath::OrderedFloat(view.0))
|| !view.0.is_finite()
|| !view.1.is_finite()
{
view = full;
}
@@ -668,7 +670,7 @@ impl Profile
{
hovered = Some(i);
}
let mut color = color_for(&s.name);
let mut color = color_for(s.name);
if is_hovered
{
color = color.gamma_multiply(1.15);
@@ -679,7 +681,7 @@ impl Profile
painter.with_clip_rect(r).text(
r.left_center() + vec2(3.0, 0.0),
egui::Align2::LEFT_CENTER,
&s.name,
s.name,
font.clone(),
egui::Color32::BLACK,
);
+2 -2
View File
@@ -120,7 +120,7 @@ impl MemoryProfile
}
}
pub fn begin(&mut self, device: &wgpu::Device) -> Device
pub fn begin(&mut self, device: &wgpu::Device) -> Device<'_>
{
Device {
device: device.clone(),
@@ -195,7 +195,7 @@ impl Group
}
// Print subgroups
for (i, group) in self.sub_groups.iter().enumerate()
for group in self.sub_groups.iter()
{
group.fmt_with_indent(f, indent + 1)?;
}
+3 -69
View File
@@ -1,7 +1,6 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use std::iter::FusedIterator;
use bytemuck::Pod;
use bytemuck::Zeroable;
use glam::Vec3;
@@ -9,7 +8,6 @@ use wgpu::CommandEncoder;
use wgpu::include_wgsl;
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;
@@ -282,7 +280,8 @@ where
device: &wgpu::Device,
encoder: &mut vxls_profiler::ScopeEncoder<CommandEncoder>,
insertion: &vxls_voxel_cache::insertion::CacheInsertionData<N>,
) {
)
{
self.fixed_structure_table
.validate_insertion(device, encoder, insertion);
}
@@ -298,68 +297,3 @@ where
.invalidate(encoder, cache_evictor, invalid_timestamp);
}
}
pub struct CenterChunkIter
{
center_chunk: (isize, isize, isize),
extent: (usize, usize, usize),
block_corner: (isize, isize, isize),
current: usize,
length: usize,
}
impl CenterChunkIter
{
pub fn new(center_chunk: (isize, isize, isize), extent: (usize, usize, usize)) -> Self
{
let half_extent = (extent.0 / 2, extent.1 / 2, extent.2 / 2);
let block_corner = (
center_chunk.0 - half_extent.0 as isize,
center_chunk.1 - half_extent.1 as isize,
center_chunk.2 - half_extent.2 as isize,
);
Self {
center_chunk,
extent,
block_corner,
current: 0,
length: extent.0 * extent.1 * extent.2,
}
}
}
impl FusedIterator for CenterChunkIter {}
impl ExactSizeIterator for CenterChunkIter {}
impl Iterator for CenterChunkIter
{
type Item = (isize, isize, isize);
fn next(&mut self) -> Option<Self::Item>
{
if self.current >= self.length
{
None
}
else
{
let x = self.current % self.extent.0;
let y = (self.current / self.extent.0) % self.extent.1;
let z = self.current / (self.extent.0 * self.extent.1);
self.current += 1;
Some((
x as isize + self.block_corner.0,
y as isize + self.block_corner.1,
z as isize + self.block_corner.2,
))
}
}
fn size_hint(&self) -> (usize, Option<usize>)
{
let remaining = self.length - self.current;
(remaining, Some(remaining))
}
}
+55 -9
View File
@@ -1,9 +1,9 @@
use vxls_attributes::AttributeDescriptor;
use vxls_attributes::AttributesLayout;
use wgpu::BindGroupLayout;
use wgpu::Buffer;
use wgpu::BufferUsages;
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>
@@ -16,9 +16,9 @@ pub struct CacheAttributes<const N: usize>
impl<const N: usize> CacheAttributes<N>
{
pub fn from_cache_layout(
pub fn from_attribute_layout(
device: &mut memory_profiler::Device,
layout: &CacheLayout,
layout: &AttributesLayout,
page_count: usize,
) -> Self
{
@@ -26,11 +26,11 @@ impl<const N: usize> CacheAttributes<N>
.attributes
.iter()
.map(|attribute| {
attribute.create_buffer_profiled(
create_attributes_buffer_profiled::<N>(
device,
N * N * N,
attribute,
page_count,
BufferUsages::STORAGE,
wgpu::BufferUsages::STORAGE,
)
})
.collect::<Vec<_>>();
@@ -58,8 +58,10 @@ impl<const N: usize> CacheAttributes<N>
}
}
pub fn create_bind_group_layout(device: &wgpu::Device, layout: &CacheLayout)
-> BindGroupLayout
pub fn create_bind_group_layout(
device: &wgpu::Device,
layout: &AttributesLayout,
) -> BindGroupLayout
{
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("CacheAttributes::bind_group_layout"),
@@ -94,3 +96,47 @@ impl<const N: usize> CacheAttributes<N>
&self.attribute_buffers
}
}
pub fn create_attributes_buffer_profiled<const N: usize>(
device: &mut memory_profiler::Device,
attribute_descriptor: &AttributeDescriptor,
page_count: usize,
usage: wgpu::BufferUsages,
) -> wgpu::Buffer
{
device.create_buffer(&wgpu::BufferDescriptor {
label: Some(
format!(
"VoxelCacheAttribute ({}) {} word(s)",
attribute_descriptor.label, attribute_descriptor.word_count
)
.as_str(),
),
size: (page_count * attribute_descriptor.word_count as usize * N * N * N * size_of::<u32>())
as u64,
usage,
mapped_at_creation: false,
})
}
pub fn create_attributes_buffer<const N: usize>(
device: &wgpu::Device,
attribute_descriptor: &AttributeDescriptor,
page_count: usize,
usage: wgpu::BufferUsages,
) -> wgpu::Buffer
{
device.create_buffer(&wgpu::BufferDescriptor {
label: Some(
format!(
"VoxelCacheAttribute ({}) {} word(s)",
attribute_descriptor.label, attribute_descriptor.word_count
)
.as_str(),
),
size: (page_count * attribute_descriptor.word_count as usize * N * N * N * size_of::<u32>())
as u64,
usage,
mapped_at_creation: false,
})
}
+6 -6
View File
@@ -2,18 +2,16 @@
use wgpu::BindGroup;
use wgpu::BindGroupLayout;
use wgpu::CommandEncoder;
use wgpu::ComputePipeline;
use wgpu::include_wgsl;
use wgpu::util::DeviceExt;
use crate::CacheRessources;
use crate::create_multi_buffers_bind_group_layout;
use crate::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.
@@ -34,6 +32,7 @@ pub struct CacheEvictor
lru_list: wgpu::Buffer,
/// When reusing pages, count of lru pages consumed
#[allow(unused)]
consumed_count: wgpu::Buffer,
/// To reset lru indices between insertions
@@ -44,6 +43,7 @@ pub struct CacheEvictor
pipelines_dispatch_count: u32,
// For external passes
#[allow(unused)]
bind_group_layout: BindGroupLayout,
bind_group: BindGroup,
}
@@ -128,7 +128,7 @@ impl CacheEvictor
}
}
pub fn prepare_eviction_list<const N: usize>(
pub(crate) fn prepare_eviction_list<const N: usize>(
&self,
device: &wgpu::Device,
ressources: &CacheRessources<N>,
+29 -169
View File
@@ -1,13 +1,12 @@
use std::num::NonZero;
use vxls_attributes::AttributesLayout;
use wgpu::BindGroupLayout;
use wgpu::BufferUsages;
use wgpu::ShaderStages;
use vxls_attributes::Attributes;
use crate::layout::CacheAttributeInit;
use crate::layout::CacheLayout;
use crate::schema::InsertionInformation;
use crate::schema::InsertionParent;
use crate::schema::LocationPage;
@@ -34,7 +33,7 @@ where
/// Layout the attribute buffers were created from. Kept so attribute
/// uploads can validate producer layouts against the cache layout.
layout: CacheLayout,
layout: AttributesLayout,
/// Contains the indicies of the page in which the data was written
destination_indices: wgpu::Buffer,
@@ -48,6 +47,7 @@ where
/// Amount of entries written to [`Self::valid_indices`]
valid_count: wgpu::Buffer,
#[allow(unused)]
bind_group_layout: wgpu::BindGroupLayout,
bind_group: wgpu::BindGroup,
bind_group_no_attributes: wgpu::BindGroup,
@@ -61,33 +61,31 @@ pub enum AttributeUploadError
/// The slice is not a whole number of pages.
NotWholePages
{
voxel_count: usize,
children: usize,
voxel_count: usize, children: usize
},
/// The slice does not fit in this insertion batch.
TooManyVoxels
{
voxel_count: usize,
capacity: usize,
voxel_count: usize, capacity: usize
},
/// The producer declares more attributes than the cache layout has.
MissingCacheAttribute
{
index: usize,
index: usize
},
/// The producer attribute index is out of bounds.
AttributeIndexOutOfBounds
{
index: usize,
index: usize
},
/// The cache attribute is not `External`, so insertion will not copy it.
NotExternal
{
index: usize,
index: usize
},
/// Declared word counts disagree.
@@ -115,52 +113,6 @@ pub enum AttributeUploadError
},
}
/// Checks that `A::LAYOUT` is a valid prefix of `layout`.
///
/// Every producer attribute must map to an `External` cache attribute with the
/// same word count and (when present) the same label. Extra attributes after
/// the producer prefix are allowed; they are meant for GPU-only data.
pub fn validate_attribute_layout<A: Attributes>(
layout: &CacheLayout,
) -> Result<(), AttributeUploadError>
{
let producer_layout = &A::LAYOUT;
for (index, descriptor) in producer_layout.attributes.iter().enumerate()
{
let Some(cache_attribute) = layout.attributes().get(index) else
{
return Err(AttributeUploadError::MissingCacheAttribute { index });
};
if cache_attribute.init != CacheAttributeInit::External
{
return Err(AttributeUploadError::NotExternal { index });
}
if cache_attribute.word_count != descriptor.word_count
{
return Err(AttributeUploadError::WordCountMismatch {
index,
producer: descriptor.word_count,
cache: cache_attribute.word_count,
});
}
if let Some(cache_label) = cache_attribute.label
&& cache_label != descriptor.label
{
return Err(AttributeUploadError::LabelMismatch {
index,
producer: descriptor.label,
cache: Some(cache_label),
});
}
}
Ok(())
}
/// Checks that a voxel slice is a whole number of pages and fits the batch.
pub fn validate_voxel_count(
voxel_count: usize,
@@ -168,7 +120,7 @@ pub fn validate_voxel_count(
capacity: usize,
) -> Result<(), AttributeUploadError>
{
if voxel_count % children != 0
if !voxel_count.is_multiple_of(children)
{
return Err(AttributeUploadError::NotWholePages {
voxel_count,
@@ -196,7 +148,8 @@ pub fn collect_attribute_bytes<A: Attributes>(
index: usize,
) -> Result<Vec<u8>, AttributeUploadError>
{
let Some(descriptor) = A::LAYOUT.attributes.get(index) else
let Some(descriptor) = A::LAYOUT.attributes.get(index)
else
{
return Err(AttributeUploadError::AttributeIndexOutOfBounds { index });
};
@@ -227,7 +180,7 @@ impl<const N: usize> CacheInsertionData<N>
where
[(); N * N * N]:,
{
pub fn new(device: &wgpu::Device, max_page_count: usize, layout: &CacheLayout) -> Self
pub fn new(device: &wgpu::Device, max_page_count: usize, layout: &AttributesLayout) -> Self
{
let page_count_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("CacheInsertionData::page_count_buffer"),
@@ -282,9 +235,9 @@ where
.attributes
.iter()
.map(|attribute| {
attribute.create_buffer(
crate::attributes::create_attributes_buffer::<N>(
device,
N * N * N,
attribute,
max_page_count,
BufferUsages::STORAGE | BufferUsages::COPY_DST,
)
@@ -355,7 +308,7 @@ where
valid_indices,
valid_count,
attributes,
layout: layout.clone(),
layout: *layout,
bind_group_layout,
bind_group,
@@ -376,7 +329,7 @@ where
///
pub fn create_bind_group_layout(
device: &wgpu::Device,
layout: Option<&CacheLayout>,
layout: Option<&AttributesLayout>,
) -> BindGroupLayout
{
let storage_entry = |binding: u32| wgpu::BindGroupLayoutEntry {
@@ -476,7 +429,7 @@ where
}
/// The layout this insertion data was created from.
pub fn layout(&self) -> &CacheLayout
pub fn layout(&self) -> &AttributesLayout
{
&self.layout
}
@@ -513,7 +466,14 @@ where
voxels: &[A],
) -> Result<usize, AttributeUploadError>
{
validate_attribute_layout::<A>(&self.layout)?;
if A::LAYOUT != self.layout
{
return Err(AttributeUploadError::LabelMismatch {
index: 0,
producer: "..",
cache: None,
});
}
validate_voxel_count(voxels.len(), N * N * N, self.attribute_capacity())?;
if voxels.is_empty()
@@ -540,8 +500,6 @@ mod tests
use vxls_attributes::AttributeDescriptor;
use vxls_attributes::AttributesLayout;
use crate::layout::CacheAttribute;
#[derive(Clone, Copy, Debug, Default, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
#[repr(C)]
struct TestAttributes
@@ -562,7 +520,10 @@ mod tests
let count = attributes.len() as f32;
Self {
color: (attributes.iter().map(|value| value.color as u64).sum::<u64>()
color: (attributes
.iter()
.map(|value| value.color as u64)
.sum::<u64>()
/ attributes.len() as u64) as u32,
normal: std::array::from_fn(|index| {
attributes
@@ -603,11 +564,6 @@ mod tests
}
}
fn cache_layout() -> CacheLayout
{
CacheLayout::from_attributes(&TestAttributes::LAYOUT, &[])
}
#[test]
fn collect_attribute_bytes_orders_by_voxel()
{
@@ -637,102 +593,6 @@ mod tests
);
}
#[test]
fn matching_layout_passes_validation()
{
assert_eq!(
validate_attribute_layout::<TestAttributes>(&cache_layout()),
Ok(())
);
}
#[test]
fn validation_rejects_word_count_mismatch()
{
let mut layout = CacheLayout::default();
layout.add_attribute(CacheAttribute {
label: Some("color"),
word_count: 2,
init: CacheAttributeInit::External,
});
layout.add_attribute(CacheAttribute {
label: Some("normal"),
word_count: 3,
init: CacheAttributeInit::External,
});
assert_eq!(
validate_attribute_layout::<TestAttributes>(&layout),
Err(AttributeUploadError::WordCountMismatch {
index: 0,
producer: 1,
cache: 2,
})
);
}
#[test]
fn validation_rejects_non_external_attributes()
{
let mut layout = CacheLayout::default();
layout.add_attribute(CacheAttribute {
label: Some("color"),
word_count: 1,
init: CacheAttributeInit::DontTouch,
});
layout.add_attribute(CacheAttribute {
label: Some("normal"),
word_count: 3,
init: CacheAttributeInit::External,
});
assert_eq!(
validate_attribute_layout::<TestAttributes>(&layout),
Err(AttributeUploadError::NotExternal { index: 0 })
);
}
#[test]
fn validation_rejects_missing_attributes()
{
let mut layout = CacheLayout::default();
layout.add_attribute(CacheAttribute {
label: Some("color"),
word_count: 1,
init: CacheAttributeInit::External,
});
assert_eq!(
validate_attribute_layout::<TestAttributes>(&layout),
Err(AttributeUploadError::MissingCacheAttribute { index: 1 })
);
}
#[test]
fn validation_rejects_label_mismatch()
{
let mut layout = CacheLayout::default();
layout.add_attribute(CacheAttribute {
label: Some("not-color"),
word_count: 1,
init: CacheAttributeInit::External,
});
layout.add_attribute(CacheAttribute {
label: Some("normal"),
word_count: 3,
init: CacheAttributeInit::External,
});
assert_eq!(
validate_attribute_layout::<TestAttributes>(&layout),
Err(AttributeUploadError::LabelMismatch {
index: 0,
producer: "color",
cache: Some("not-color"),
})
);
}
#[test]
fn voxel_counts_must_be_whole_pages_within_capacity()
{
-187
View File
@@ -1,187 +0,0 @@
use wgpu::BufferUsages;
use vxls_attributes::AttributesLayout;
use vxls_profiler::memory_profiler;
/// Defines how a [`VoxelCache`]'s attribute is populated upon populating a page
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CacheAttributeInit
{
/// Attribute is external : it is copied from the insertion operation
External,
/// Attribute will not be touched by the cache mechanism. It is left to the discrecy of the
/// cache user.
///
/// Some applications requires pieces of data into the resident data of the cache that are
/// computed on the fly : e.g. global illumination
DontTouch,
}
/// Describes an attribute of a [`VoxelCache`]
#[derive(Clone, Copy, Debug)]
pub struct CacheAttribute
{
pub label: Option<&'static str>,
pub word_count: u32,
pub init: CacheAttributeInit,
}
impl CacheAttribute
{
pub fn create_buffer_profiled(
&self,
device: &mut memory_profiler::Device,
child_count: usize,
page_count: usize,
usage: wgpu::BufferUsages,
) -> wgpu::Buffer
{
device.create_buffer(&wgpu::BufferDescriptor {
label: Some(
format!(
"VoxelCacheAttribute ({}) {} word(s)",
self.label.unwrap_or("no-name"),
self.word_count
)
.as_str(),
),
size: (self.word_count as usize * page_count * child_count * size_of::<u32>()) as u64,
usage,
mapped_at_creation: false,
})
}
/// Creates the wgpu buffer necessary to store this attribute in the cache
pub fn create_buffer(
&self,
device: &wgpu::Device,
child_count: usize,
page_count: usize,
usage: wgpu::BufferUsages,
) -> wgpu::Buffer
{
device.create_buffer(&wgpu::BufferDescriptor {
label: Some(
format!(
"VoxelCacheAttribute ({}) {} word(s)",
self.label.unwrap_or("no-name"),
self.word_count
)
.as_str(),
),
size: (self.word_count as usize * page_count * child_count * size_of::<u32>()) as u64,
usage,
mapped_at_creation: false,
})
}
}
#[derive(Clone, Default)]
pub struct CacheLayout
{
pub(super) attributes: Vec<CacheAttribute>,
}
impl CacheLayout
{
/// Adds a new [`VoxelCacheAttribute`] in the layout
///
/// Attributes are added starting from 0 counting up
///
/// Returns the index of the new added attirbute
pub fn add_attribute(&mut self, attribute: CacheAttribute) -> usize
{
let index = self.attributes.len();
self.attributes.push(attribute);
index
}
/// Builds a cache layout from producer attributes followed by `extra`.
///
/// Every attribute of `layout` is inserted from the producer and is
/// therefore [`CacheAttributeInit::External`]. `extra` attributes are
/// appended after them and are meant for GPU-only data
/// ([`CacheAttributeInit::DontTouch`]), which producers never fill.
pub fn from_attributes(layout: &AttributesLayout, extra: &[CacheAttribute]) -> Self
{
let mut cache_layout = Self::default();
for attribute in layout.attributes
{
cache_layout.add_attribute(CacheAttribute {
label: Some(attribute.label),
word_count: attribute.word_count,
init: CacheAttributeInit::External,
});
}
for attribute in extra
{
cache_layout.add_attribute(*attribute);
}
cache_layout
}
/// The attributes of this layout, in binding order
pub fn attributes(&self) -> &[CacheAttribute]
{
&self.attributes
}
/// Produces a wgsl declaration describing this layout :
///
/// ```wgsl
///
/// const ATTRIBUTE_COUNT: u32 = /* attribute count */;
/// const ATTRIBUTE_WORD_COUNTS: array<u32, ...> = {
/// /* word count for attribute 0 */,
/// /* word count for attribute 1 */,
/// ...
/// };
///
/// const ATTRIBUTE_COPY: array<bool, ...> = {
/// /* external? for attribute 0 */,
/// /* external? for attribute 1 */,
/// ...
/// };
///
/// ```
pub fn wgsl_layout_decl(&self) -> String
{
let mut decl = String::new();
decl += &format!("const ATTRIBUTE_COUNT: u32 = {};", self.attributes.len());
// Word counts
decl += &format!(
"const ATTRIBUTE_WORD_COUNTS: array<u32, {}> = array<u32, {}>(",
self.attributes.len(),
self.attributes.len()
);
for attribute in self.attributes.iter()
{
decl += &format!(" {},", attribute.word_count);
}
decl += ");";
// Copy
decl += &format!(
"const ATTRIBUTE_COPY: array<bool, {}> = array<bool, {}>(",
self.attributes.len(),
self.attributes.len()
);
for attribute in self.attributes.iter()
{
decl += &format!(" {},", attribute.init == CacheAttributeInit::External);
}
decl += ");";
decl
}
}
+25 -26
View File
@@ -1,17 +1,12 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use std::num::NonZero;
use vxls_attributes::AttributesLayout;
use wgpu::CommandEncoder;
use wgpu::Device;
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;
@@ -22,21 +17,23 @@ use crate::pipelines::WriteRequestsPass;
use crate::requests::CacheRequestBuffer;
use crate::requests::CacheRequestHandler;
use crate::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::ScopeEncoder;
use vxls_profiler::memory_profiler;
use vxls_profiler::memory_profiler::MemoryProfile;
pub mod attributes;
pub mod eviction;
pub mod insertion;
pub mod layout;
//pub mod layout;
pub mod pipelines;
pub mod requests;
pub mod schema;
pub mod structure;
pub mod tables;
pub use layout::CacheAttribute;
pub use layout::CacheAttributeInit;
pub use layout::CacheLayout;
/// Stores some ressources that can be reused throughout the modules of the cache
struct CacheRessources<const N: usize>
{
@@ -147,16 +144,16 @@ where
device: &Device,
page_count: usize,
max_requests: usize,
layout: &CacheLayout,
attributes_layout: &AttributesLayout,
) -> Self
{
let mut cache_memory_profile = MemoryProfile::new("VoxelCache");
let mut mem_device = cache_memory_profile.begin(device);
let structure = CacheStructure::new(&mut mem_device.group("CacheStructure"), page_count);
let attributes = CacheAttributes::from_cache_layout(
let attributes = CacheAttributes::from_attribute_layout(
&mut mem_device.group("CacheAttributes"),
layout,
attributes_layout,
page_count,
);
let request_handler = CacheRequestHandler::new(
@@ -168,10 +165,11 @@ where
let common_ressources =
CacheRessources::new(&mut mem_device.group("CacheRessources"), page_count);
let write_requests_pass = WriteRequestsPass::new(device, page_count, layout);
let cache_insertion_pass = CacheInsertionPass::new(device, page_count, layout);
let cache_invalidation_pass = CacheInvalidationPass::new(device, page_count, layout);
let write_pointers_pass = WritePointersPass::new(device, page_count, layout);
let write_requests_pass = WriteRequestsPass::new(device, page_count, attributes_layout);
let cache_insertion_pass = CacheInsertionPass::new(device, page_count, attributes_layout);
let cache_invalidation_pass =
CacheInvalidationPass::new(device, page_count, attributes_layout);
let write_pointers_pass = WritePointersPass::new(device, page_count, attributes_layout);
let (raytrace_bind_group_layout, raytrace_bind_group) = Self::create_raytrace_bind_group(
device,
@@ -182,7 +180,7 @@ where
);
drop(mem_device);
let mut root_group = cache_memory_profile.terminate();
let root_group = cache_memory_profile.terminate();
println!("{}", root_group);
Self {
@@ -322,12 +320,8 @@ where
{
if let VoxelCacheInsertion::InternalRequest(insertion) = insertion
{
self.write_pointers_pass.encode(
&mut encoder,
device,
&self.structure,
insertion,
);
self.write_pointers_pass
.encode(&mut encoder, device, &self.structure, insertion);
}
}
@@ -448,4 +442,9 @@ where
{
self.evictor.timestamp_pages_buffer()
}
pub fn size(&self) -> usize
{
self.page_count
}
}
+9 -10
View File
@@ -1,20 +1,20 @@
use vxls_attributes::AttributesLayout;
use wgpu::BufferUsages;
use wgpu::CommandEncoder;
use wgpu::ComputePipeline;
use wgpu::Device;
use wgpu::util::DeviceExt;
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;
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
use vxls_profiler;
use vxls_profiler::ScopeEncoder;
macro_rules! programmatic_common_wgsl {
($children_count:ident, $page_count:ident, $cache_layout:ident) => {
@@ -54,8 +54,6 @@ macro_rules! include_cache_wgsl {
}};
}
pub(super) use include_cache_wgsl;
pub struct WriteRequestsPass<const N: usize>
where
[(); N * N * N]:,
@@ -69,7 +67,7 @@ impl<const N: usize> WriteRequestsPass<N>
where
[(); N * N * N]:,
{
pub fn new(device: &Device, page_count: usize, cache_layout: &CacheLayout) -> Self
pub fn new(device: &Device, page_count: usize, cache_layout: &AttributesLayout) -> Self
{
// Binds
// - structure
@@ -164,6 +162,7 @@ where
validate_internal_pipeline: ComputePipeline,
/// u32 buffer containing amount of inserted data of current pass
#[allow(unused)]
inserted_count: wgpu::Buffer,
inserted_count_bind_group: wgpu::BindGroup,
@@ -178,7 +177,7 @@ impl<const N: usize> CacheInsertionPass<N>
where
[(); N * N * N]:,
{
pub fn new(device: &Device, page_count: usize, layout: &CacheLayout) -> Self
pub fn new(device: &Device, page_count: usize, layout: &AttributesLayout) -> Self
{
// Binds
// - structure
@@ -363,7 +362,7 @@ impl<const N: usize> CacheInvalidationPass<N>
where
[(); N * N * N]:,
{
pub fn new(device: &Device, page_count: usize, layout: &CacheLayout) -> Self
pub fn new(device: &Device, page_count: usize, layout: &AttributesLayout) -> Self
{
// Binds
// - structure
@@ -444,7 +443,7 @@ impl<const N: usize> WritePointersPass<N>
where
[(); N * N * N]:,
{
pub fn new(device: &Device, page_count: usize, layout: &CacheLayout) -> Self
pub fn new(device: &Device, page_count: usize, layout: &AttributesLayout) -> Self
{
let bindings = [
// To find where pages are pointing
+11 -13
View File
@@ -9,6 +9,11 @@ use wgpu::Device;
use wgpu::include_wgsl;
use wgpu::util::DeviceExt;
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;
use vxls_gpu::create_multi_buffers_bind_group;
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
use vxls_gpu::radix_sort::{self};
@@ -16,11 +21,6 @@ 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>
@@ -52,6 +52,7 @@ pub struct CacheRequestHandler<const N: usize>
reset_pass_dispatch: u32,
// External bind group
#[allow(unused)]
bind_group_layout: BindGroupLayout,
bind_group: BindGroup,
}
@@ -70,6 +71,7 @@ pub struct CacheRequestBuffer
/// Buffer containing the meta information about the requests, a dense array of [`voxel_cache::schema::RequestMeta`]
request_meta: wgpu::Buffer,
#[allow(unused)]
bind_group_layout: wgpu::BindGroupLayout,
bind_group: wgpu::BindGroup,
}
@@ -203,7 +205,7 @@ impl<const N: usize> CacheRequestHandler<N>
/// Uses both the sorter and the scratch buffer in the ressources
///
/// The `request_count` buffer will contain the amount of request produced this time.
pub fn sort_requests(
pub(crate) fn sort_requests(
&self,
device: &wgpu::Device,
ressources: &CacheRessources<N>,
@@ -443,8 +445,7 @@ impl CacheRequestBuffer
&self.request_meta.slice(..),
move |buffer| {
let mapped_buffer = buffer.expect("Could not map request buffer (meta).");
let request_metas: Vec<RequestMeta> =
bytemuck::pod_collect_to_vec(&mapped_buffer);
let request_metas: Vec<RequestMeta> = bytemuck::pod_collect_to_vec(&mapped_buffer);
request_map_state_3
.lock()
@@ -477,11 +478,8 @@ impl<F: FnMut(&[RequestInformation], &[RequestMeta]) + Send + Sync + 'static> Re
fn try_callback(&mut self)
{
if let (Some(request_count), Some(request_infos), Some(request_metas)) = (
self.request_count,
&self.request_infos,
&self.request_metas,
)
if let (Some(request_count), Some(request_infos), Some(request_metas)) =
(self.request_count, &self.request_infos, &self.request_metas)
{
(self.callback)(
&request_infos[0..request_count],
@@ -171,11 +171,6 @@ fn insertion(@builtin(global_invocation_id) gid: vec3<u32>)
// Copy attributes
for(var attribute_index = u32(0); attribute_index < ATTRIBUTE_COUNT; attribute_index ++)
{
if(!ATTRIBUTE_COPY[attribute_index])
{
continue;
}
var page_stride = CHILDREN_COUNT * ATTRIBUTE_WORD_COUNTS[attribute_index];
var dest_offset = page_stride * page_index;
var src_offset = page_stride * index;
+3 -2
View File
@@ -3,11 +3,11 @@ use wgpu::BindGroupLayout;
use wgpu::Buffer;
use wgpu::BufferUsages;
use crate::schema::DepthPage;
use crate::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>
@@ -15,6 +15,7 @@ where
[(); N * N * N]:,
{
pointer_pages: Buffer,
#[allow(unused)]
location_pages: Buffer,
depth_pages: Buffer,
+79 -82
View File
@@ -1,11 +1,14 @@
//! 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
//! voxels, we must enter the cache from somewhere
//!
//! The structure table is a structure that keeps information about where to find the root node
//! inside the cache, or if it is not preset, emit requests.
use std::collections::HashMap;
use wgpu::util::DeviceExt;
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;
@@ -15,14 +18,10 @@ 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
/// voxels, we must enter the cache from somewhere
///
/// The structure table is a structure that keeps information about where to find the root node
/// inside the cache, or if it is not preset, emit requests.
///
use vxls_gpu::create_multi_buffers_bind_group;
use vxls_gpu::indirect_buffer::IndirectBuffer1D;
use vxls_profiler::ScopeEncoder;
use vxls_profiler::memory_profiler::MemoryProfile;
macro_rules! include_table_wgsl {
($path:literal) => {{
@@ -265,12 +264,11 @@ impl StructureTableCore
contents: bytemuck::cast_slice(initial_pointers),
});
let (metadata_bind_group_layout, metadata_bind_group) =
create_multi_buffers_bg_bg_layout(
device,
&[&anchors_buffer],
Some("StructureTableCore::metadata"),
);
let (metadata_bind_group_layout, metadata_bind_group) = create_multi_buffers_bg_bg_layout(
device,
&[&anchors_buffer],
Some("StructureTableCore::metadata"),
);
let (pointers_bind_group_layout, pointers_bind_group) = create_multi_buffers_bg_bg_layout(
device,
@@ -714,12 +712,7 @@ impl FixedStructureTable
/// Retained for callers that do not move slots; [`Self::new_with_anchors`]
/// is the general constructor.
#[allow(dead_code)]
pub fn new(
device: &wgpu::Device,
size: usize,
max_requests: usize,
producer_id: u32,
) -> Self
pub fn new(device: &wgpu::Device, size: usize, max_requests: usize, producer_id: u32) -> Self
{
let anchors = (0..size)
.map(|slot| StructureAnchor {
@@ -741,9 +734,8 @@ impl FixedStructureTable
assert_eq!(anchors.len(), size);
let pointers = vec![CachePointer::new(Some(None)); size];
let core = StructureTableCore::new(
device, size, max_requests, producer_id, &anchors, &pointers,
);
let core =
StructureTableCore::new(device, size, max_requests, producer_id, &anchors, &pointers);
Self {
core,
@@ -767,6 +759,7 @@ impl FixedStructureTable
let retired = retired_anchors(&self.slot_anchors, new_anchors);
#[allow(clippy::needless_range_loop)]
for slot in 0..self.core.size
{
let anchor = new_anchors[slot];
@@ -876,7 +869,12 @@ impl DynamicStructureTable
let anchors = vec![StructureAnchor::ZERO; capacity];
let pointers = vec![CachePointer::new(None); capacity];
let core = StructureTableCore::new(
device, capacity, max_requests, producer_id, &anchors, &pointers,
device,
capacity,
max_requests,
producer_id,
&anchors,
&pointers,
);
Self {
@@ -922,12 +920,7 @@ impl DynamicStructureTable
///
/// Capacity doubles from the current value until it reaches `min_capacity`.
/// Must be called between frames.
pub fn reserve(
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
min_capacity: usize,
)
pub fn reserve(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, min_capacity: usize)
{
assert!(
min_capacity <= u32::MAX as usize,
@@ -1058,6 +1051,58 @@ impl DynamicStructureTable
}
}
impl<const N: usize> CacheInvalidable<N> for FixedStructureTable
where
[(); N * N * N]:,
{
fn validate_insertion(
&mut self,
device: &wgpu::Device,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
insertion: &CacheInsertionData<N>,
)
{
self.core.validate_insertion(device, encoder, insertion);
}
fn invalidate(
&mut self,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
cache_evictor: &CacheEvictor,
invalid_timestamp: u32,
)
{
self.core
.invalidate(encoder, cache_evictor, invalid_timestamp);
}
}
impl<const N: usize> CacheInvalidable<N> for DynamicStructureTable
where
[(); N * N * N]:,
{
fn validate_insertion(
&mut self,
device: &wgpu::Device,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
insertion: &CacheInsertionData<N>,
)
{
self.core.validate_insertion(device, encoder, insertion);
}
fn invalidate(
&mut self,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
cache_evictor: &CacheEvictor,
invalid_timestamp: u32,
)
{
self.core
.invalidate(encoder, cache_evictor, invalid_timestamp);
}
}
#[cfg(test)]
mod tests
{
@@ -1190,51 +1235,3 @@ mod tests
assert_eq!(allocator.allocate(anchor(4)), None);
}
}
impl<const N: usize> CacheInvalidable<N> for FixedStructureTable
where
[(); N * N * N]:,
{
fn validate_insertion(
&mut self,
device: &wgpu::Device,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
insertion: &CacheInsertionData<N>,
) {
self.core.validate_insertion(device, encoder, insertion);
}
fn invalidate(
&mut self,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
cache_evictor: &CacheEvictor,
invalid_timestamp: u32,
)
{
self.core.invalidate(encoder, cache_evictor, invalid_timestamp);
}
}
impl<const N: usize> CacheInvalidable<N> for DynamicStructureTable
where
[(); N * N * N]:,
{
fn validate_insertion(
&mut self,
device: &wgpu::Device,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
insertion: &CacheInsertionData<N>,
) {
self.core.validate_insertion(device, encoder, insertion);
}
fn invalidate(
&mut self,
encoder: &mut ScopeEncoder<wgpu::CommandEncoder>,
cache_evictor: &CacheEvictor,
invalid_timestamp: u32,
)
{
self.core.invalidate(encoder, cache_evictor, invalid_timestamp);
}
}
-50
View File
@@ -1,50 +0,0 @@
use crate::gi_pipeline::sparse_set::GpuSparseSet;
use vxls_voxel_cache::VoxelCache;
use vxls_voxel_cache::{self};
mod sparse_set;
pub struct VoxelGiPipeline<const N: usize>
where
[(); N * N * N]:,
{
voxel_cache: VoxelCache<N>,
/// Keeps a set of the leaves present in the cache.
/// Kept in correspondancy with the leaf list attribute within the cache
leaf_list: GpuSparseSet,
leaf_list_attribute: usize,
}
impl<const N: usize> VoxelGiPipeline<N>
where
[(); N * N * N]:,
{
pub fn new(
device: &wgpu::Device,
cache_size: usize,
max_requests: usize,
cache_layout: &mut vxls_voxel_cache::CacheLayout,
) -> Self
{
let leaf_list_attribute = cache_layout.add_attribute(vxls_voxel_cache::CacheAttribute {
label: Some("VoxelGiPipeline::leaf_list_pointer"),
word_count: 1,
init: vxls_voxel_cache::CacheAttributeInit::External,
});
cache_layout.add_attribute(vxls_voxel_cache::CacheAttribute {
label: Some("VoxelGiPipeline::radiance"),
word_count: 3,
init: vxls_voxel_cache::CacheAttributeInit::DontTouch,
});
let voxel_cache = VoxelCache::new(device, cache_size, max_requests, cache_layout);
Self {
voxel_cache,
leaf_list: GpuSparseSet::new(device, cache_size),
leaf_list_attribute,
}
}
}
-15
View File
@@ -1,15 +0,0 @@
// Contains useful facilities to render data streamed in from the host
// Can produce a voxel given
// - Its depth
// - Its position within the chunk
// - The chunks position
pub trait ChunkVoxelProducer
{
fn produce_voxel(
&mut self,
depth: usize,
chunk_position: (usize, usize, usize),
voxel_position: (usize, usize, usize),
);
}
+3 -17
View File
@@ -1,13 +1,11 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
#![feature(float_algebraic)]
use std::arch::x86_64;
use std::marker::PhantomData;
use std::sync::Arc;
use std::sync::atomic::AtomicBool;
use std::sync::atomic::AtomicU32;
use std::sync::mpsc::Sender;
use std::thread::Thread;
use std::time::Instant;
use bytemuck::Pod;
@@ -22,12 +20,10 @@ use glam::Quat;
use glam::Vec3;
use glam::Vec4;
use itertools::Itertools;
use rand::random_bool;
use rand::random_range;
use rayon::iter::IntoParallelRefIterator;
use rayon::iter::ParallelIterator;
use wgpu::BindGroupLayout;
use wgpu::Buffer;
use wgpu::BufferUsages;
use wgpu::ComputePipeline;
use wgpu::Device;
@@ -56,17 +52,13 @@ use winit::window::WindowId;
use crate::camera::Camera;
use crate::egui_renderer::EguiRenderer;
use crate::producers::ChunkedProducer;
use crate::producers::SdfGenerator;
use crate::sparse_tree::Color;
use crate::sparse_tree::NTree;
use crate::sparse_tree::NTreeNode;
use crate::sparse_tree::load_ply;
use vxls_bvh::BvhHandle;
use vxls_bvh::BvhObject;
use vxls_bvh::BvhStructureTable;
use vxls_bvh::aabb::Aabb;
use vxls_bvh::build::Bvh;
use vxls_bvh::debug::BvhDebugPipeline;
use vxls_production::Attributes;
use vxls_production::ProducerId;
@@ -82,8 +74,6 @@ use vxls_production::tree_locator::TreeLocator;
use vxls_profiler::Frame;
use vxls_profiler::Profile;
use vxls_profiler::ProfilingEncoder;
use vxls_terrain::ToroidalStructureTable;
use vxls_voxel_cache::CacheLayout;
use vxls_voxel_cache::VoxelCache;
use vxls_voxel_cache::VoxelCacheInsertion;
use vxls_voxel_cache::insertion::CacheInsertionData;
@@ -91,11 +81,9 @@ 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;
mod camera;
mod egui_renderer;
mod gi_pipeline;
mod producers;
mod sparse_tree;
@@ -377,7 +365,7 @@ impl State
*/
// Load dragon ply
let tree: NTree<4> = load_ply("dragon.txt");
let tree: NTree<4> = load_ply("../../dragon.txt");
// let mut arrays = vec![Color(0., 0., 0., 0.); 256 * 256 * 256];
// for ((x, y), z) in (0..256).cartesian_product(0..256).cartesian_product(0..256)
// {
@@ -397,9 +385,7 @@ impl State
let egui_renderer = EguiRenderer::new(&device, surface_format, &window);
let layout =
CacheLayout::from_attributes(&crate::producers::VoxelAttributes::LAYOUT, &[]);
let layout = crate::producers::VoxelAttributes::LAYOUT;
let request_buffer = CacheRequestBuffer::new(&device, 1024);
let voxel_cache =
VoxelCache::<4>::new(&device, 150_000, request_buffer.max_requests, &layout);