Remove obsolete code

This commit is contained in:
Andreas Sundquist
2025-05-30 10:49:49 -07:00
parent 7defe60edb
commit 8b5f854848
25 changed files with 5267 additions and 7213 deletions
-1
View File
@@ -15,4 +15,3 @@ anyhow.workspace = true
half.workspace = true
js-sys.workspace = true
wasm-bindgen.workspace = true
wlg = { path = "../wlg" }
+2 -77
View File
@@ -1,12 +1,10 @@
use std::cell::RefCell;
use js_sys::{Array, ArrayBuffer, Float32Array, Object, Reflect, Uint16Array, Uint32Array, Uint8Array};
use js_sys::{Float32Array, Uint16Array, Uint32Array};
use wasm_bindgen::prelude::*;
use wlg::decode12_packed;
mod sort;
use sort::{old_sort_internal, OldSortBuffers, sort_internal, SortBuffers};
use sort::{sort_internal, SortBuffers};
mod raycast;
use raycast::{raycast_ellipsoids, raycast_spheres};
@@ -15,82 +13,9 @@ const RAYCAST_BUFFER_COUNT: u32 = 65536;
thread_local! {
static SORT_BUFFERS: RefCell<SortBuffers> = RefCell::new(SortBuffers::default());
static OLD_SORT_BUFFERS: RefCell<OldSortBuffers> = RefCell::new(OldSortBuffers::default());
static RAYCAST_BUFFER: RefCell<Vec<u32>> = RefCell::new(vec![0; RAYCAST_BUFFER_COUNT as usize * 4]);
}
#[wasm_bindgen]
pub fn decode_wlg(bytes: ArrayBuffer, tex_width: u32, tex_height: u32) -> Object {
let mut bytes = Uint8Array::new(&bytes).to_vec();
let (_settings, packed_splats) = match decode12_packed(&mut bytes) {
Ok(result) => result,
Err(err) => {
wasm_bindgen::throw_str(&format!("{}", err));
}
};
let num_splats = packed_splats.0.len() / 4;
let max_splats = if tex_width != 0 && tex_height != 0 {
let width = tex_width as usize;
let height = num_splats.div_ceil(width).min(tex_height as usize);
let depth = num_splats.div_ceil(width * height);
width * height * depth
} else {
num_splats
};
let packed = Uint32Array::new_with_length(max_splats as u32 * 4);
let packed_slice = packed.subarray(0, packed_splats.0.len() as u32);
packed_slice.copy_from(&packed_splats.0);
let result = Object::new();
Reflect::set(&result, &JsValue::from_str("numSplats"), &JsValue::from_f64(num_splats as f64)).unwrap();
Reflect::set(&result, &JsValue::from_str("packedSplats"), &JsValue::from(packed)).unwrap();
result
}
#[wasm_bindgen]
pub fn old_sort_splats(
max_splats: u32, total_splats: u32, readback: Array, ordering: Uint32Array,
) -> u32 {
let max_splats = max_splats as usize;
let total_splats = total_splats as usize;
let num_layers = readback.length() as usize;
let layer_size = readback.get(0).dyn_into::<Uint8Array>().unwrap().length() as usize / 4;
let active_splats = OLD_SORT_BUFFERS.with_borrow_mut(|buffers| {
buffers.ensure_size(max_splats);
// Copy the readback data layers into a contiguous buffer
let mut layer_base = 0;
for layer in 0..num_layers {
let layer_count = layer_size.min(total_splats - layer_base);
if layer_count > 0 {
let layer_buffer = readback.get(layer as u32).dyn_into::<Uint8Array>().unwrap().buffer();
let layer_uint32 = Uint32Array::new_with_byte_offset_and_length(&layer_buffer, 0, layer_count as u32);
layer_uint32.copy_to(&mut buffers.readback[layer_base..layer_base + layer_count]);
}
layer_base += layer_count;
}
let active_splats = match old_sort_internal(buffers, total_splats) {
Ok(active_splats) => active_splats,
Err(err) => {
wasm_bindgen::throw_str(&format!("{}", err));
}
};
if active_splats > 0 {
// Copy out ordering result
let subarray = &buffers.ordering[..active_splats as usize];
ordering.subarray(0, active_splats).copy_from(&subarray);
}
active_splats
});
active_splats
}
#[wasm_bindgen]
pub fn sort_splats(
num_splats: u32, readback: Uint16Array, ordering: Uint32Array,
+21 -1
View File
@@ -1,8 +1,28 @@
use half::f16;
use wlg::decode_scale;
const MIN_OPACITY: f32 = 0.1;
pub const LN_SCALE_MIN: f32 = -9.0;
pub const LN_SCALE_MAX: f32 = 9.0;
pub const LN_RESCALE: f32 = (LN_SCALE_MAX - LN_SCALE_MIN) / 254.0; // 1..=255
// pub fn encode_scale(scale: f32) -> u8 {
// if scale == 0.0 {
// 0
// } else {
// // Allow scales below LN_SCALE_MIN to be encoded as 0, which signifies a 2DGS
// ((scale.ln() - LN_SCALE_MIN) / LN_RESCALE + 1.0).clamp(0.0, 255.0).round() as u8
// }
// }
pub fn decode_scale(scale: u8) -> f32 {
if scale == 0 {
0.0
} else {
(LN_SCALE_MIN + (scale - 1) as f32 * LN_RESCALE).exp()
}
}
pub fn raycast_spheres(
buffer: &[u32], distances: &mut Vec<f32>,
origin: [f32; 3], dir: [f32; 3], near: f32, far: f32,
-66
View File
@@ -3,72 +3,6 @@ use anyhow::anyhow;
const DEPTH_INFINITY: u32 = 0x7c00;
const DEPTH_SIZE: usize = DEPTH_INFINITY as usize + 1;
#[derive(Default)]
pub struct OldSortBuffers {
pub readback: Vec<u32>,
pub ordering: Vec<u32>,
pub buckets: Vec<u32>,
}
impl OldSortBuffers {
pub fn ensure_size(&mut self, max_splats: usize) {
if self.readback.len() < max_splats {
self.readback.resize(max_splats, 0);
}
if self.ordering.len() < max_splats {
self.ordering.resize(max_splats, 0);
}
if self.buckets.len() < DEPTH_SIZE {
self.buckets.resize(DEPTH_SIZE, 0);
}
}
}
pub fn old_sort_internal(buffers: &mut OldSortBuffers, total_splats: usize) -> anyhow::Result<u32> {
let OldSortBuffers { readback, ordering, buckets } = buffers;
let readback = &readback[..total_splats];
// Set the bucket counts to zero
buckets.clear();
buckets.resize(DEPTH_SIZE, 0);
// Count the number of splats in each bucket
for &readback_u32 in readback.iter() {
let priority = readback_u32 & 0x7FFF;
if priority < DEPTH_INFINITY {
buckets[priority as usize] += 1;
}
}
// Compute bucket starting offset
let mut active_splats = 0;
for count in buckets.iter_mut() {
let new_total = active_splats + *count;
*count = active_splats;
active_splats = new_total;
}
// Write out splat indices at the right location using bucket offsets
for (index, &readback_u32) in readback.iter().enumerate() {
let priority = readback_u32 & 0x7FFF;
if priority < DEPTH_INFINITY {
ordering[buckets[priority as usize] as usize] = index as u32;
buckets[priority as usize] += 1;
}
}
// Sanity check
if buckets[DEPTH_SIZE - 1] != active_splats {
return Err(anyhow!(
"Expected {} active splats but got {}",
active_splats,
buckets[DEPTH_SIZE - 1]
));
}
Ok(active_splats)
}
#[derive(Default)]
pub struct SortBuffers {
pub readback: Vec<u16>,