Deterministic CSG

This commit is contained in:
2025-12-01 19:12:34 +00:00
parent 925b58418c
commit ed7ce78c33
5 changed files with 56 additions and 48 deletions
Generated
+36 -36
View File
@@ -349,9 +349,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.46" version = "1.2.48"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97463e1064cb1b1c1384ad0a0b9c8abd0988e2a91f52606c80ef14aadb63e36" checksum = "c481bdbf0ed3b892f6f806287d72acd515b352a4ec27a208489b8c1bc839633a"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"jobserver", "jobserver",
@@ -896,9 +896,9 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.16.0" version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
[[package]] [[package]]
name = "heck" name = "heck"
@@ -1056,9 +1056,9 @@ checksum = "e7c5cedc30da3a610cac6b4ba17597bdf7152cf974e8aab3afb3d54455e371c8"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.12.0" version = "2.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@@ -1124,9 +1124,9 @@ dependencies = [
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.82" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"wasm-bindgen", "wasm-bindgen",
@@ -1260,9 +1260,9 @@ dependencies = [
[[package]] [[package]]
name = "moxcms" name = "moxcms"
version = "0.7.9" version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fbdd3d7436f8b5e892b8b7ea114271ff0fa00bc5acae845d53b07d498616ef6" checksum = "80986bbbcf925ebd3be54c26613d861255284584501595cf418320c078945608"
dependencies = [ dependencies = [
"num-traits", "num-traits",
"pxfm", "pxfm",
@@ -1919,9 +1919,9 @@ dependencies = [
[[package]] [[package]]
name = "pxfm" name = "pxfm"
version = "0.1.25" version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3cbdf373972bf78df4d3b518d07003938e2c7d1fb5891e55f9cb6df57009d84" checksum = "b3502d6155304a4173a5f2c34b52b7ed0dd085890326cb50fd625fdf39e86b3b"
dependencies = [ dependencies = [
"num-traits", "num-traits",
] ]
@@ -2412,9 +2412,9 @@ checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.110" version = "2.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a99801b5bd34ede4cf3fc688c5919368fea4e4814a4664359503e6015b280aea" checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -2627,9 +2627,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.41" version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647"
dependencies = [ dependencies = [
"log", "log",
"pin-project-lite", "pin-project-lite",
@@ -2638,9 +2638,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.34" version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c"
[[package]] [[package]]
name = "ttf-parser" name = "ttf-parser"
@@ -2801,9 +2801,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.105" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell", "once_cell",
@@ -2814,9 +2814,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.55" version = "0.4.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551f88106c6d5e7ccc7cd9a16f312dd3b5d36ea8b4954304657d5dfba115d4a0" checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys", "js-sys",
@@ -2827,9 +2827,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.105" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@@ -2837,9 +2837,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.105" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"proc-macro2", "proc-macro2",
@@ -2850,9 +2850,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.105" version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -2994,9 +2994,9 @@ dependencies = [
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.82" version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@@ -3334,9 +3334,9 @@ dependencies = [
[[package]] [[package]]
name = "winnow" name = "winnow"
version = "0.7.13" version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@@ -3453,18 +3453,18 @@ dependencies = [
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.8.27" version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3"
dependencies = [ dependencies = [
"zerocopy-derive", "zerocopy-derive",
] ]
[[package]] [[package]]
name = "zerocopy-derive" name = "zerocopy-derive"
version = "0.8.27" version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
+3 -1
View File
@@ -270,7 +270,7 @@ impl App {
enabled_extensions: InstanceExtensions { enabled_extensions: InstanceExtensions {
..required_extensions ..required_extensions
}, },
engine_name: Some("ImplEng".to_owned()), engine_name: Some("Tape Drive".to_owned()),
engine_version: Version::major_minor(0, 1), engine_version: Version::major_minor(0, 1),
application_name: Some(env!("CARGO_PKG_NAME").to_owned()), application_name: Some(env!("CARGO_PKG_NAME").to_owned()),
application_version: app_version(), application_version: app_version(),
@@ -949,6 +949,7 @@ impl ApplicationHandler for App {
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
rcx.swapchain.image_count(), rcx.swapchain.image_count(),
DEFAULT_SUBDIVISION, DEFAULT_SUBDIVISION,
rand::random(),
0, 0,
)) ))
.unwrap(); .unwrap();
@@ -1407,6 +1408,7 @@ impl App {
self.descriptor_set_allocator.clone(), self.descriptor_set_allocator.clone(),
rcx.swapchain.image_count(), rcx.swapchain.image_count(),
DEFAULT_SUBDIVISION, DEFAULT_SUBDIVISION,
rand::random(),
-1, -1,
)) ))
.unwrap(); .unwrap();
+1
View File
@@ -39,6 +39,7 @@ pub(crate) struct Mesh {
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct CSG { pub(crate) struct CSG {
pub(crate) name: String, pub(crate) name: String,
pub(crate) seed: u64,
pub(crate) parts: SSATape, pub(crate) parts: SSATape,
pub(crate) pos: Vec3, pub(crate) pos: Vec3,
pub(crate) rot: Vec3, pub(crate) rot: Vec3,
+3 -3
View File
@@ -457,7 +457,7 @@ impl SSATape {
} else { } else {
let mut b = rspirv::dr::Builder::new(); let mut b = rspirv::dr::Builder::new();
b.set_version(1, 6); b.set_version(1, 6);
b.module_processed(format!("ImplEng JIT {JIT_VERSION}")); b.module_processed(format!("Tape Drive JIT {JIT_VERSION}"));
b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450); b.memory_model(spirv::AddressingModel::Logical, spirv::MemoryModel::GLSL450);
b b
}; };
@@ -493,8 +493,8 @@ impl SSATape {
if with_module { Some(1000) } else { None }, if with_module { Some(1000) } else { None },
//spirv::FunctionControl::DONT_INLINE //spirv::FunctionControl::DONT_INLINE
spirv::FunctionControl::INLINE spirv::FunctionControl::INLINE
| spirv::FunctionControl::PURE | spirv::FunctionControl::PURE
| spirv::FunctionControl::CONST, | spirv::FunctionControl::CONST,
point_fn_type, point_fn_type,
) )
.unwrap(); .unwrap();
+13 -8
View File
@@ -9,6 +9,7 @@ use std::{
use foldhash::HashSet; use foldhash::HashSet;
use glam::{EulerRot, Mat4, Vec3}; use glam::{EulerRot, Mat4, Vec3};
use log::info; use log::info;
use rand::{Rng, SeedableRng, rngs::SmallRng};
use rspirv::{binary::Assemble, dr::Module}; use rspirv::{binary::Assemble, dr::Module};
use vulkano::{ use vulkano::{
buffer::{Subbuffer, allocator::SubbufferAllocator}, buffer::{Subbuffer, allocator::SubbufferAllocator},
@@ -63,6 +64,7 @@ pub enum WorkItem {
Arc<StandardDescriptorSetAllocator>, Arc<StandardDescriptorSetAllocator>,
u32, u32,
u32, u32,
u64,
isize, isize,
), ),
GetPushConstants( GetPushConstants(
@@ -106,10 +108,11 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
descriptor_set_allocator, descriptor_set_allocator,
frames, frames,
subdivision, subdivision,
seed,
index, index,
) => { ) => {
let csg_start = Instant::now(); let csg_start = Instant::now();
let parts = create_csg(); let parts = create_csg(seed);
let trace_shader_module = let trace_shader_module =
sdf_specialize_module(device.clone(), &parts, trace_module, &format!("trace")); sdf_specialize_module(device.clone(), &parts, trace_module, &format!("trace"));
@@ -187,6 +190,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
let csg = Arc::new(RwLock::new(CSG { let csg = Arc::new(RwLock::new(CSG {
name: "example".to_string(), name: "example".to_string(),
seed,
parts, parts,
pos: Vec3::ZERO, pos: Vec3::ZERO,
rot: Vec3::ZERO, rot: Vec3::ZERO,
@@ -418,7 +422,8 @@ fn deferred_pipelines_recompile(
(trace_pipeline, normals_pipeline) (trace_pipeline, normals_pipeline)
} }
fn create_csg() -> SSATape { fn create_csg(seed: u64) -> SSATape {
let mut rng = SmallRng::seed_from_u64(seed);
let mut tape = SSATape::default(); let mut tape = SSATape::default();
let pos = tape.push_instruction( let pos = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
@@ -436,9 +441,9 @@ fn create_csg() -> SSATape {
pos[0], pos[0],
pos[1], pos[1],
pos[2], pos[2],
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
], ],
); );
let sphere = tape.push_instruction( let sphere = tape.push_instruction(
@@ -450,7 +455,7 @@ fn create_csg() -> SSATape {
offset[0], offset[0],
offset[1], offset[1],
offset[2], offset[2],
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
], ],
); );
let torus = tape.push_instruction( let torus = tape.push_instruction(
@@ -462,8 +467,8 @@ fn create_csg() -> SSATape {
pos[0], pos[0],
pos[1], pos[1],
pos[2], pos[2],
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
SSAInput::Constant(rand::random_range(0.0..1.0)), SSAInput::Constant(rng.random_range(0.0..1.0)),
], ],
); );
let min = tape.push_instruction( let min = tape.push_instruction(