no warnings or errors

This commit is contained in:
2025-12-26 00:28:18 +00:00
parent 00b05d6e3c
commit 18fdec939c
11 changed files with 112 additions and 281 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
use std::{fs::read_dir, io::Write, process::Command}; use std::{fs::read_dir, process::Command};
fn main() { fn main() {
//let mut output = std::fs::File::create("output.txt").unwrap(); //let mut output = std::fs::File::create("output.txt").unwrap();
+1 -1
View File
@@ -40,7 +40,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) _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,
+1 -1
View File
@@ -191,7 +191,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, _seed: seed,
parts, parts,
pos: Vec3::ZERO, pos: Vec3::ZERO,
rot: Vec3::ZERO, rot: Vec3::ZERO,
+1 -21
View File
@@ -69,30 +69,10 @@ impl<'csg> IntervalInterpreter<'csg> {
} }
} }
fn param_four(
&mut self,
instruction: &SSAInstruction,
func: impl Fn(Interval, Interval, Interval, Interval) -> Interval,
) {
for i in 0..instruction.opcode.size as usize {
let val_a = self.load(instruction.inputs[i]);
let val_b = self.load(instruction.inputs[i + instruction.opcode.size as usize]);
let val_c = self.load(instruction.inputs[i + (instruction.opcode.size * 2) as usize]);
let val_d = self.load(instruction.inputs[i + (instruction.opcode.size * 3) as usize]);
self.store(instruction.outputs[i], func(val_a, val_b, val_c, val_d));
}
}
// cargo asm "tape-drive::interpreter::IntervalInterpreter::scene" --no-color // cargo asm "tape-drive::interpreter::IntervalInterpreter::scene" --no-color
// --rust > scene.asm // --rust > scene.asm
pub fn scene( pub fn scene(&mut self, px: Interval, py: Interval, pz: Interval, time: Interval) -> Interval {
&mut self,
px: Interval,
py: Interval,
pz: Interval,
time: Interval,
) -> Interval {
self.clear_stacks(); self.clear_stacks();
for instruction in &self.csg.tape { for instruction in &self.csg.tape {
-14
View File
@@ -68,20 +68,6 @@ impl<'csg> PointInterpreter<'csg> {
} }
} }
fn param_four(
&mut self,
instruction: &SSAInstruction,
func: impl Fn(Value, Value, Value, Value) -> Value,
) {
for i in 0..instruction.opcode.size as usize {
let val_a = self.load(instruction.inputs[i]);
let val_b = self.load(instruction.inputs[i + instruction.opcode.size as usize]);
let val_c = self.load(instruction.inputs[i + (instruction.opcode.size * 2) as usize]);
let val_d = self.load(instruction.inputs[i + (instruction.opcode.size * 3) as usize]);
self.store(instruction.outputs[i], func(val_a, val_b, val_c, val_d));
}
}
// cargo asm "tape-drive::interpreter::PointInterpreter::scene" --no-color // cargo asm "tape-drive::interpreter::PointInterpreter::scene" --no-color
// --rust > scene.asm // --rust > scene.asm
+96 -193
View File
@@ -111,43 +111,6 @@ pub(crate) fn compile_interval_function(
} }
} }
fn param_four(
float: u32,
b: &mut rspirv::dr::Builder,
mapping: &mut HashMap<u32, (u32, u32)>,
instruction: &SSAInstruction,
func: impl Fn(
&mut rspirv::dr::Builder,
(u32, u32),
(u32, u32),
(u32, u32),
(u32, u32),
) -> (u32, u32),
) {
for i in 0..instruction.opcode.size as usize {
let val_a = input_resolve(float, b, &mapping, instruction.inputs[i]);
let val_b = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + instruction.opcode.size as usize],
);
let val_c = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + (instruction.opcode.size as usize * 2)],
);
let val_d = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + (instruction.opcode.size as usize * 3)],
);
mapping.insert(instruction.outputs[i], func(b, val_a, val_b, val_c, val_d));
}
}
fn multiply( fn multiply(
float: u32, float: u32,
b: &mut rspirv::dr::Builder, b: &mut rspirv::dr::Builder,
@@ -964,7 +927,7 @@ pub(crate) fn compile_interval_function(
b, b,
&mut mapping, &mut mapping,
instruction, instruction,
|b, val_a, val_b| { |b, _val_a, _val_b| {
let pi_const = let pi_const =
b.constant_bit32(types.float, (std::f32::consts::PI).to_bits()); b.constant_bit32(types.float, (std::f32::consts::PI).to_bits());
let npi_const = let npi_const =
@@ -1028,39 +991,29 @@ pub(crate) fn compile_interval_function(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let dot = match instruction.opcode.size { let dot = match instruction.opcode.size {
1 => multiply(types.float, b, types.glsl, val_a[0], val_b[0]), 1 => multiply(types.float, b, types.glsl, val_a[0], val_b[0]),
2 => add( 2 => {
types.float, let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
b, let muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
multiply(types.float, b, types.glsl, val_a[0], val_b[0]), add(types.float, b, mulx, muly)
multiply(types.float, b, types.glsl, val_a[1], val_b[1]), },
), 3 => {
3 => add( let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
types.float, let muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
b, let mulz = multiply(types.float, b, types.glsl, val_a[2], val_b[2]);
add( let accum = add(types.float, b, mulx, muly);
types.float, let accum = add(types.float, b, accum, mulz);
b, accum
multiply(types.float, b, types.glsl, val_a[0], val_b[0]), },
multiply(types.float, b, types.glsl, val_a[1], val_b[1]), 4 => {
), let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
multiply(types.float, b, types.glsl, val_a[2], val_b[2]), let muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
), let mulz = multiply(types.float, b, types.glsl, val_a[2], val_b[2]);
4 => add( let mulw = multiply(types.float, b, types.glsl, val_a[3], val_b[3]);
types.float, let accum = add(types.float, b, mulx, muly);
b, let accum = add(types.float, b, accum, mulz);
add( let accum = add(types.float, b, accum, mulw);
types.float, accum
b, },
add(
types.float,
b,
multiply(types.float, b, types.glsl, val_a[0], val_b[0]),
multiply(types.float, b, types.glsl, val_a[1], val_b[1]),
),
multiply(types.float, b, types.glsl, val_a[2], val_b[2]),
),
multiply(types.float, b, types.glsl, val_a[3], val_b[3]),
),
_ => unreachable!("Invalid opcode size {}", instruction.opcode.size), _ => unreachable!("Invalid opcode size {}", instruction.opcode.size),
}; };
mapping.insert(instruction.outputs[0], dot); mapping.insert(instruction.outputs[0], dot);
@@ -1187,45 +1140,31 @@ pub(crate) fn compile_interval_function(
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
let zero = b.constant_bit32(types.float, (0.0f32).to_bits()); let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
let one = b.constant_bit32(types.float, (1.0f32).to_bits()); let one = b.constant_bit32(types.float, (1.0f32).to_bits());
let ge1 = b.f_sub(types.float, None, val_a.1, val_a.0).unwrap();
let ge1 = b let ge1 = b
.f_ord_greater_than_equal( .f_ord_greater_than_equal(types.bool, None, ge1, one)
types.bool, .unwrap();
let fract_low = b
.ext_inst(
types.float,
None, None,
b.f_sub(types.float, None, val_a.1, val_a.0).unwrap(), types.glsl,
one, spirv::GLOp::Fract as u32,
[IdRef(val_a.0)],
)
.unwrap();
let fract_high = b
.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
[IdRef(val_a.1)],
) )
.unwrap(); .unwrap();
( (
b.select( b.select(types.float, None, ge1, zero, fract_low).unwrap(),
types.float, b.select(types.float, None, ge1, one, fract_high).unwrap(),
None,
ge1,
zero,
b.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
[IdRef(val_a.0)],
)
.unwrap(),
)
.unwrap(),
b.select(
types.float,
None,
ge1,
one,
b.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
[IdRef(val_a.1)],
)
.unwrap(),
)
.unwrap(),
) )
}); });
}, },
@@ -1243,22 +1182,24 @@ pub(crate) fn compile_interval_function(
} else { } else {
val_a val_a
}; };
let lower_cycle = b.f_div(types.float, None, val_a.0, pi).unwrap();
let lower_cycle = b let lower_cycle = b
.ext_inst( .ext_inst(
types.float, types.float,
None, None,
types.glsl, types.glsl,
spirv::GLOp::Floor as u32, spirv::GLOp::Floor as u32,
[IdRef(b.f_div(types.float, None, val_a.0, pi).unwrap())], [IdRef(lower_cycle)],
) )
.unwrap(); .unwrap();
let upper_cycle = b.f_div(types.float, None, val_a.1, pi).unwrap();
let upper_cycle = b let upper_cycle = b
.ext_inst( .ext_inst(
types.float, types.float,
None, None,
types.glsl, types.glsl,
spirv::GLOp::Floor as u32, spirv::GLOp::Floor as u32,
[IdRef(b.f_div(types.float, None, val_a.1, pi).unwrap())], [IdRef(upper_cycle)],
) )
.unwrap(); .unwrap();
let same_cycle = b let same_cycle = b
@@ -1266,13 +1207,10 @@ pub(crate) fn compile_interval_function(
.unwrap(); .unwrap();
let cycle = b.f_mod(types.float, None, upper_cycle, two).unwrap(); let cycle = b.f_mod(types.float, None, upper_cycle, two).unwrap();
let within_one_cycle = b let within_one_cycle = b
.f_ord_equal( .f_sub(types.float, None, upper_cycle, lower_cycle)
types.bool, .unwrap();
None, let within_one_cycle = b
b.f_sub(types.float, None, upper_cycle, lower_cycle) .f_ord_equal(types.bool, None, within_one_cycle, one)
.unwrap(),
one,
)
.unwrap(); .unwrap();
let temp0 = b let temp0 = b
.ext_inst( .ext_inst(
@@ -1292,65 +1230,43 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)], [IdRef(val_a.1)],
) )
.unwrap(); .unwrap();
let lower_valid = b.f_ord_equal(types.bool, None, cycle, zero).unwrap();
let lower_valid = b let lower_valid = b
.logical_or( .logical_and(types.bool, None, within_one_cycle, lower_valid)
types.bool, .unwrap();
None, let lower_valid = b
same_cycle, .logical_or(types.bool, None, same_cycle, lower_valid)
b.logical_and( .unwrap();
types.bool, let upper_valid = b.f_ord_equal(types.bool, None, cycle, one).unwrap();
None, let upper_valid = b
within_one_cycle, .logical_and(types.bool, None, within_one_cycle, upper_valid)
b.f_ord_equal(types.bool, None, cycle, zero).unwrap(),
)
.unwrap(),
)
.unwrap(); .unwrap();
let upper_valid = b let upper_valid = b
.logical_or( .logical_or(types.bool, None, same_cycle, upper_valid)
types.bool, .unwrap();
let lower = b
.ext_inst(
types.float,
None, None,
same_cycle, types.glsl,
b.logical_and( spirv::GLOp::FMin as u32,
types.bool, [IdRef(temp0), IdRef(temp1)],
None,
within_one_cycle,
b.f_ord_equal(types.bool, None, cycle, one).unwrap(),
)
.unwrap(),
) )
.unwrap(); .unwrap();
let lower = b let lower = b
.select( .select(types.float, None, lower_valid, lower, minus_one)
.unwrap();
let upper = b
.ext_inst(
types.float, types.float,
None, None,
lower_valid, types.glsl,
b.ext_inst( spirv::GLOp::FMax as u32,
types.float, [IdRef(temp0), IdRef(temp1)],
None,
types.glsl,
spirv::GLOp::FMin as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap(),
minus_one,
) )
.unwrap(); .unwrap();
let upper = b let upper = b
.select( .select(types.float, None, upper_valid, upper, one)
types.float,
None,
upper_valid,
b.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap(),
one,
)
.unwrap(); .unwrap();
(lower, upper) (lower, upper)
}); });
@@ -1378,15 +1294,11 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)], [IdRef(val_a.1)],
) )
.unwrap(); .unwrap();
let result_valid = b let lt = b.f_ord_less_than(types.bool, None, size, pi).unwrap();
.logical_and( let gte = b
types.bool, .f_ord_greater_than_equal(types.bool, None, upper_tmp, lower_tmp)
None,
b.f_ord_less_than(types.bool, None, size, pi).unwrap(),
b.f_ord_greater_than_equal(types.bool, None, upper_tmp, lower_tmp)
.unwrap(),
)
.unwrap(); .unwrap();
let result_valid = b.logical_and(types.bool, None, lt, gte).unwrap();
( (
b.select(types.float, None, result_valid, lower_tmp, nan) b.select(types.float, None, result_valid, lower_tmp, nan)
.unwrap(), .unwrap(),
@@ -1418,16 +1330,13 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)], [IdRef(val_a.1)],
) )
.unwrap(); .unwrap();
let result_valid = b let gte = b
.logical_and( .f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
types.bool,
None,
b.f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
.unwrap(),
b.f_ord_less_than_equal(types.bool, None, val_a.1, one)
.unwrap(),
)
.unwrap(); .unwrap();
let lte = b
.f_ord_less_than_equal(types.bool, None, val_a.1, one)
.unwrap();
let result_valid = b.logical_and(types.bool, None, gte, lte).unwrap();
( (
b.select(types.float, None, result_valid, lower_tmp, nan) b.select(types.float, None, result_valid, lower_tmp, nan)
.unwrap(), .unwrap(),
@@ -1459,16 +1368,13 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)], [IdRef(val_a.1)],
) )
.unwrap(); .unwrap();
let result_valid = b let gte = b
.logical_and( .f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
types.bool,
None,
b.f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
.unwrap(),
b.f_ord_less_than_equal(types.bool, None, val_a.1, one)
.unwrap(),
)
.unwrap(); .unwrap();
let lte = b
.f_ord_less_than_equal(types.bool, None, val_a.1, one)
.unwrap();
let result_valid = b.logical_and(types.bool, None, gte, lte).unwrap();
( (
b.select(types.float, None, result_valid, lower_tmp, nan) b.select(types.float, None, result_valid, lower_tmp, nan)
.unwrap(), .unwrap(),
@@ -1822,12 +1728,9 @@ pub(crate) fn compile_interval_function(
let rad1 = input_resolve(types.float, b, &mapping, instruction.inputs[3 as usize]); let rad1 = input_resolve(types.float, b, &mapping, instruction.inputs[3 as usize]);
let rad2 = input_resolve(types.float, b, &mapping, instruction.inputs[4 as usize]); let rad2 = input_resolve(types.float, b, &mapping, instruction.inputs[4 as usize]);
let dot = add( let squ1 = square(types.float, b, types.bool, types.glsl, pos_part[0]);
types.float, let squ2 = square(types.float, b, types.bool, types.glsl, pos_part[2]);
b, let dot = add(types.float, b, squ1, squ2);
square(types.float, b, types.bool, types.glsl, pos_part[0]),
square(types.float, b, types.bool, types.glsl, pos_part[2]),
);
let sqrt = ( let sqrt = (
b.ext_inst( b.ext_inst(
types.float, types.float,
-31
View File
@@ -106,37 +106,6 @@ pub(crate) fn compile_point_function(
} }
} }
fn param_four(
float: u32,
b: &mut rspirv::dr::Builder,
mapping: &mut HashMap<u32, u32>,
instruction: &SSAInstruction,
func: impl Fn(&mut rspirv::dr::Builder, u32, u32, u32, u32) -> u32,
) {
for i in 0..instruction.opcode.size as usize {
let val_a = input_resolve(float, b, &mapping, instruction.inputs[i]);
let val_b = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + instruction.opcode.size as usize],
);
let val_c = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + (instruction.opcode.size as usize * 2)],
);
let val_d = input_resolve(
float,
b,
&mapping,
instruction.inputs[i + (instruction.opcode.size as usize * 3)],
);
mapping.insert(instruction.outputs[i], func(b, val_a, val_b, val_c, val_d));
}
}
match instruction.opcode.opcode { match instruction.opcode.opcode {
SSAStop => { SSAStop => {
let zero = b.constant_bit32(types.float, (0.0f32).to_bits()); let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
+7 -10
View File
@@ -6,10 +6,7 @@ use crate::{
DUMP_SPV_DIS_TO_FILE, DUMP_SPV_DIS_TO_FILE,
instruction_set::InstructionSet, instruction_set::InstructionSet,
spirv_compilers::{ spirv_compilers::{
SpirVTypes, SpirVTypes, interval::compile_interval_function, point::compile_point_function,
//gradient::compile_gradient_function,
//interval::compile_interval_function,
point::compile_point_function,
}, },
}; };
@@ -508,12 +505,12 @@ impl SSATape {
if with_module { Some(1000) } else { None }, if with_module { Some(1000) } else { None },
); );
//compile_interval_function( compile_interval_function(
// &mut b, &mut b,
// &self, &self,
// types, types,
// if with_module { Some(2000) } else { None }, if with_module { Some(2000) } else { None },
//); );
//compile_gradient_function( //compile_gradient_function(
// &mut b, // &mut b,
+1
View File
@@ -248,6 +248,7 @@ impl Grad {
/// Checks that the two values are roughly equal, panicking otherwise /// Checks that the two values are roughly equal, panicking otherwise
#[cfg(test)] #[cfg(test)]
#[allow(unused)]
pub(crate) fn compare_eq(&self, other: Self) { pub(crate) fn compare_eq(&self, other: Self) {
let d = (self.v - other.v) let d = (self.v - other.v)
.abs() .abs()
+3 -3
View File
@@ -6,10 +6,9 @@ use std::simd::{
use crate::{ use crate::{
interpreters::{ interpreters::{
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, VALUE_PI_2, Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_M1, VALUE_NAN, VALUE_PI, Value, glfract, glsign,
VALUE_TAU, Value, glfract, glsign,
}, },
vm::choice::{Choice, VChoice}, vm::choice::VChoice,
}; };
/// Stores a range, with conservative calculations to guarantee that it always /// Stores a range, with conservative calculations to guarantee that it always
@@ -469,6 +468,7 @@ impl Interval {
/// Checks that the two values are roughly equal, panicking otherwise /// Checks that the two values are roughly equal, panicking otherwise
#[cfg(test)] #[cfg(test)]
#[allow(unused)]
pub(crate) fn compare_eq(&self, other: Self) { pub(crate) fn compare_eq(&self, other: Self) {
let d = (self.lower - other.lower) let d = (self.lower - other.lower)
.abs() .abs()
+1 -6
View File
@@ -1,9 +1,4 @@
use std::simd::{ use std::simd::u32x8;
StdFloat,
cmp::{SimdPartialEq, SimdPartialOrd},
num::SimdFloat,
u32x8,
};
/// A single choice made at a min/max node. /// A single choice made at a min/max node.
/// ///