Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
run: cargo fmt --all -- --check
- name: Check
run: cargo check ${{ matrix.features }}
- name: Clippy
run: cargo clippy ${{ matrix.features }}
- name: Build
run: cargo build ${{ matrix.features }}
- name: Test
Expand Down
10 changes: 5 additions & 5 deletions benches/with_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl Mesh {
let mut vertices = Vec::new();
let mut indices = Vec::new();

for (_, model) in models.iter().enumerate() {
for model in models.iter() {
let mesh = &model.mesh;
assert!(mesh.positions.len() % 3 == 0);
assert!(mesh.positions.len().is_multiple_of(3));

vertices.reserve(mesh.indices.len());
indices.extend_from_slice(&mesh.indices);
Expand Down Expand Up @@ -280,7 +280,7 @@ fn with_input(c: &mut Criterion) {
BenchmarkId::new("decode_index_buffer", input_name),
&encoded_indices,
|b, encoded_indices| {
b.iter(|| decode_index_buffer(&mut decoded_indices, &encoded_indices).unwrap());
b.iter(|| decode_index_buffer(&mut decoded_indices, encoded_indices).unwrap());
},
);
}
Expand All @@ -303,7 +303,7 @@ fn with_input(c: &mut Criterion) {
|b, data| {
let mut buffer = vec![0; encode_index_sequence_bound(data.len(), vertex_count)];

b.iter(|| encode_index_sequence(&mut buffer, &data, IndexEncodingVersion::default()));
b.iter(|| encode_index_sequence(&mut buffer, data, IndexEncodingVersion::default()));
},
);

Expand All @@ -318,7 +318,7 @@ fn with_input(c: &mut Criterion) {
BenchmarkId::new("decode_index_sequence", input_name),
&buffer,
|b, buffer| {
b.iter(|| decode_index_sequence(&mut decoded_indices, &buffer));
b.iter(|| decode_index_sequence(&mut decoded_indices, buffer));
},
);

Expand Down
14 changes: 8 additions & 6 deletions bin/codec_bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::identity_op)]

use meshopt_rs::index::IndexEncodingVersion;
use meshopt_rs::index::buffer::{decode_index_buffer, encode_index_buffer, encode_index_buffer_bound};
use meshopt_rs::vertex::Position;
Expand Down Expand Up @@ -46,19 +48,19 @@ fn bench_codecs(vertices: &[Vertex], indices: &[u32], bestvd: &mut f64, bestid:
if verbose {
println!(
"source: vertex data {} bytes, index data {} bytes",
vertices.len() * std::mem::size_of::<Vertex>(),
std::mem::size_of_val(vertices),
indices.len() * 4
);
}

for pass in 0..if verbose { 2 } else { 1 } {
if pass == 1 {
optimize_vertex_cache_strip(&mut ib, &indices, vertices.len());
optimize_vertex_cache_strip(&mut ib, indices, vertices.len());
} else {
optimize_vertex_cache(&mut ib, &indices, vertices.len());
optimize_vertex_cache(&mut ib, indices, vertices.len());
}

optimize_vertex_fetch(&mut vb, &mut ib, &vertices);
optimize_vertex_fetch(&mut vb, &mut ib, vertices);

vc.resize_with(vc.capacity(), Default::default);
let vc_size = encode_vertex_buffer(&mut vc, &vb, VertexEncodingVersion::V0).unwrap();
Expand Down Expand Up @@ -95,7 +97,7 @@ fn bench_codecs(vertices: &[Vertex], indices: &[u32], bestvd: &mut f64, bestid:
let vertex_time = (t1 - t0).as_secs_f64();
let index_time = (t2 - t1).as_secs_f64();

let vertex_throughput = (vertices.len() * std::mem::size_of::<Vertex>()) as f64 / GB / vertex_time;
let vertex_throughput = std::mem::size_of_val(vertices) as f64 / GB / vertex_time;
let index_throughput = (indices.len() * 4) as f64 / GB / index_time;

if verbose {
Expand Down Expand Up @@ -197,7 +199,7 @@ fn main() {

let mut vertices = Vec::with_capacity(((N + 1) * (N + 1)) as usize);

let verbose = std::env::args().find(|a| a == "-v").is_some();
let verbose = std::env::args().any(|a| a == "-v");

for x in 0..=N {
for y in 0..=N {
Expand Down
35 changes: 15 additions & 20 deletions examples/demo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::identity_op)]

use meshopt_rs::index::buffer::*;
use meshopt_rs::index::generator::*;
use meshopt_rs::index::*;
Expand Down Expand Up @@ -77,9 +79,9 @@ impl Mesh {
let mut vertices = Vec::new();
let mut indices = Vec::new();

for (_, model) in models.iter().enumerate() {
for model in models.iter() {
let mesh = &model.mesh;
assert!(mesh.positions.len() % 3 == 0);
assert!(mesh.positions.len().is_multiple_of(3));

vertices.reserve(mesh.indices.len());
indices.extend_from_slice(&mesh.indices);
Expand Down Expand Up @@ -135,7 +137,7 @@ impl Mesh {
}

pub fn is_valid(&self) -> bool {
if self.indices.len() % 3 != 0 {
if !self.indices.len().is_multiple_of(3) {
return false;
}

Expand Down Expand Up @@ -200,7 +202,7 @@ impl Mesh {
std::slice::from_raw_parts(v.as_ptr() as *const u8, std::mem::size_of::<Vertex>() * v.len())
};

let hash = Self::hash_range(&data);
let hash = Self::hash_range(data);

h1 ^= hash;
h2 = h2.wrapping_add(hash);
Expand Down Expand Up @@ -405,7 +407,7 @@ fn compress_data<T>(data: &[T]) -> usize {
);
let mut compressor = CompressorOxide::new(flags);

let src = unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u8, std::mem::size_of::<T>() * data.len()) };
let src = unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u8, std::mem::size_of_val(data)) };

// Taken from miniz.c as miniz_oxide has no equivalent function
let bound = (128 + (src.len() * 110) / 100).max(128 + src.len() + ((src.len() / (31 * 1024)) + 1) * 5);
Expand Down Expand Up @@ -471,7 +473,7 @@ fn encode_index_sequence1(data: &[u32], vertex_count: usize, desc: char) {
let start = Instant::now();

let mut buffer = vec![0; encode_index_sequence_bound(data.len(), vertex_count)];
let size = encode_index_sequence(&mut buffer, &data, IndexEncodingVersion::default());
let size = encode_index_sequence(&mut buffer, data, IndexEncodingVersion::default());
buffer.resize(size, 0);

let encode = start.elapsed();
Expand Down Expand Up @@ -534,7 +536,7 @@ where
let start = Instant::now();

let mut vbuf = vec![0; encode_vertex_buffer_bound(pv.len(), std::mem::size_of::<PV>())];
let vb_size = encode_vertex_buffer(&mut vbuf, &pv, VertexEncodingVersion::default()).unwrap();
let vb_size = encode_vertex_buffer(&mut vbuf, pv, VertexEncodingVersion::default()).unwrap();
vbuf.resize(vb_size, 0);

let encode = start.elapsed();
Expand Down Expand Up @@ -681,7 +683,7 @@ fn simplify_mesh_complete(mesh: &Mesh) {
lods[0] = mesh.indices.clone();

for i in 1..LOD_COUNT {
let (source, mut lod) = {
let (source, lod) = {
let (s, l) = lods.split_at_mut(i);
(s.last_mut().unwrap(), l.first_mut().unwrap())
};
Expand All @@ -698,14 +700,7 @@ fn simplify_mesh_complete(mesh: &Mesh) {
}

lod.resize(source.len(), Default::default());
let size = simplify(
&mut lod,
&source,
&mesh.vertices,
target_index_count,
target_error,
None,
);
let size = simplify(lod, source, &mesh.vertices, target_index_count, target_error, None);
lod.resize(size, Default::default());
}

Expand Down Expand Up @@ -981,7 +976,7 @@ fn meshlets(mesh: &Mesh, scan: bool) {

// trivial accept: we can't ever backface cull this meshlet
accepted += (bounds.cone_cutoff >= 1.0) as usize;
accepted_s8 += (bounds.cone_cutoff_s8 >= 127) as usize;
accepted_s8 += (bounds.cone_cutoff_s8 == 127) as usize;

// perspective projection: dot(normalize(cone_apex - camera_position), cone_axis) > cone_cutoff
let mview = [
Expand Down Expand Up @@ -1146,7 +1141,7 @@ where

for model in models.iter() {
let mesh = &model.mesh;
assert!(mesh.positions.len() % 3 == 0);
assert!(mesh.positions.len().is_multiple_of(3));

for i in 0..mesh.indices.len() {
let pi = mesh.indices[i] as usize;
Expand Down Expand Up @@ -1300,7 +1295,7 @@ fn process(mesh: &Mesh) {
strip.resize(size, 0);

#[cfg(feature = "experimental")]
encode_index_sequence1(&mut strip, copystrip.vertices.len(), 'D');
encode_index_sequence1(&strip, copystrip.vertices.len(), 'D');

pack_vertex(&copy);
encode_vertex(&copy);
Expand All @@ -1320,7 +1315,7 @@ fn process(mesh: &Mesh) {

fn process_dev(#[allow(unused)] mesh: &Mesh) {
#[cfg(feature = "experimental")]
tessellation_adjacency(&mesh);
tessellation_adjacency(mesh);
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
Loading