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() {
//let mut output = std::fs::File::create("output.txt").unwrap();
+1 -1
View File
@@ -40,7 +40,7 @@ pub(crate) struct Mesh {
#[derive(Debug)]
pub(crate) struct CSG {
pub(crate) name: String,
pub(crate) seed: u64,
pub(crate) _seed: u64,
pub(crate) parts: SSATape,
pub(crate) pos: 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 {
name: "example".to_string(),
seed,
_seed: seed,
parts,
pos: 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
// --rust > scene.asm
pub fn scene(
&mut self,
px: Interval,
py: Interval,
pz: Interval,
time: Interval,
) -> Interval {
pub fn scene(&mut self, px: Interval, py: Interval, pz: Interval, time: Interval) -> Interval {
self.clear_stacks();
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
// --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(
float: u32,
b: &mut rspirv::dr::Builder,
@@ -964,7 +927,7 @@ pub(crate) fn compile_interval_function(
b,
&mut mapping,
instruction,
|b, val_a, val_b| {
|b, _val_a, _val_b| {
let pi_const =
b.constant_bit32(types.float, (std::f32::consts::PI).to_bits());
let npi_const =
@@ -1028,39 +991,29 @@ pub(crate) fn compile_interval_function(
.collect::<Vec<_>>();
let dot = match instruction.opcode.size {
1 => multiply(types.float, b, types.glsl, val_a[0], val_b[0]),
2 => 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]),
),
3 => add(
types.float,
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]),
),
4 => add(
types.float,
b,
add(
types.float,
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]),
),
2 => {
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
let muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
add(types.float, b, mulx, muly)
},
3 => {
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
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]);
let accum = add(types.float, b, mulx, muly);
let accum = add(types.float, b, accum, mulz);
accum
},
4 => {
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]);
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]);
let mulw = multiply(types.float, b, types.glsl, val_a[3], val_b[3]);
let accum = add(types.float, b, mulx, muly);
let accum = add(types.float, b, accum, mulz);
let accum = add(types.float, b, accum, mulw);
accum
},
_ => unreachable!("Invalid opcode size {}", instruction.opcode.size),
};
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| {
let zero = b.constant_bit32(types.float, (0.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
.f_ord_greater_than_equal(
types.bool,
.f_ord_greater_than_equal(types.bool, None, ge1, one)
.unwrap();
let fract_low = b
.ext_inst(
types.float,
None,
b.f_sub(types.float, None, val_a.1, val_a.0).unwrap(),
one,
types.glsl,
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();
(
b.select(
types.float,
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(),
b.select(types.float, None, ge1, zero, fract_low).unwrap(),
b.select(types.float, None, ge1, one, fract_high).unwrap(),
)
});
},
@@ -1243,22 +1182,24 @@ pub(crate) fn compile_interval_function(
} else {
val_a
};
let lower_cycle = b.f_div(types.float, None, val_a.0, pi).unwrap();
let lower_cycle = b
.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
[IdRef(b.f_div(types.float, None, val_a.0, pi).unwrap())],
[IdRef(lower_cycle)],
)
.unwrap();
let upper_cycle = b.f_div(types.float, None, val_a.1, pi).unwrap();
let upper_cycle = b
.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
[IdRef(b.f_div(types.float, None, val_a.1, pi).unwrap())],
[IdRef(upper_cycle)],
)
.unwrap();
let same_cycle = b
@@ -1266,13 +1207,10 @@ pub(crate) fn compile_interval_function(
.unwrap();
let cycle = b.f_mod(types.float, None, upper_cycle, two).unwrap();
let within_one_cycle = b
.f_ord_equal(
types.bool,
None,
b.f_sub(types.float, None, upper_cycle, lower_cycle)
.unwrap(),
one,
)
.f_sub(types.float, None, upper_cycle, lower_cycle)
.unwrap();
let within_one_cycle = b
.f_ord_equal(types.bool, None, within_one_cycle, one)
.unwrap();
let temp0 = b
.ext_inst(
@@ -1292,65 +1230,43 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)],
)
.unwrap();
let lower_valid = b.f_ord_equal(types.bool, None, cycle, zero).unwrap();
let lower_valid = b
.logical_or(
types.bool,
None,
same_cycle,
b.logical_and(
types.bool,
None,
within_one_cycle,
b.f_ord_equal(types.bool, None, cycle, zero).unwrap(),
)
.unwrap(),
)
.logical_and(types.bool, None, within_one_cycle, lower_valid)
.unwrap();
let lower_valid = b
.logical_or(types.bool, None, same_cycle, lower_valid)
.unwrap();
let upper_valid = b.f_ord_equal(types.bool, None, cycle, one).unwrap();
let upper_valid = b
.logical_and(types.bool, None, within_one_cycle, upper_valid)
.unwrap();
let upper_valid = b
.logical_or(
types.bool,
.logical_or(types.bool, None, same_cycle, upper_valid)
.unwrap();
let lower = b
.ext_inst(
types.float,
None,
same_cycle,
b.logical_and(
types.bool,
None,
within_one_cycle,
b.f_ord_equal(types.bool, None, cycle, one).unwrap(),
)
.unwrap(),
types.glsl,
spirv::GLOp::FMin as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap();
let lower = b
.select(
.select(types.float, None, lower_valid, lower, minus_one)
.unwrap();
let upper = b
.ext_inst(
types.float,
None,
lower_valid,
b.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::FMin as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap(),
minus_one,
types.glsl,
spirv::GLOp::FMax as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap();
let upper = b
.select(
types.float,
None,
upper_valid,
b.ext_inst(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap(),
one,
)
.select(types.float, None, upper_valid, upper, one)
.unwrap();
(lower, upper)
});
@@ -1378,15 +1294,11 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)],
)
.unwrap();
let result_valid = b
.logical_and(
types.bool,
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(),
)
let lt = b.f_ord_less_than(types.bool, None, size, pi).unwrap();
let gte = b
.f_ord_greater_than_equal(types.bool, None, upper_tmp, lower_tmp)
.unwrap();
let result_valid = b.logical_and(types.bool, None, lt, gte).unwrap();
(
b.select(types.float, None, result_valid, lower_tmp, nan)
.unwrap(),
@@ -1418,16 +1330,13 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)],
)
.unwrap();
let result_valid = b
.logical_and(
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(),
)
let gte = b
.f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
.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)
.unwrap(),
@@ -1459,16 +1368,13 @@ pub(crate) fn compile_interval_function(
[IdRef(val_a.1)],
)
.unwrap();
let result_valid = b
.logical_and(
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(),
)
let gte = b
.f_ord_greater_than_equal(types.bool, None, val_a.0, minus_one)
.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)
.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 rad2 = input_resolve(types.float, b, &mapping, instruction.inputs[4 as usize]);
let dot = add(
types.float,
b,
square(types.float, b, types.bool, types.glsl, pos_part[0]),
square(types.float, b, types.bool, types.glsl, pos_part[2]),
);
let squ1 = square(types.float, b, types.bool, types.glsl, pos_part[0]);
let squ2 = square(types.float, b, types.bool, types.glsl, pos_part[2]);
let dot = add(types.float, b, squ1, squ2);
let sqrt = (
b.ext_inst(
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 {
SSAStop => {
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,
instruction_set::InstructionSet,
spirv_compilers::{
SpirVTypes,
//gradient::compile_gradient_function,
//interval::compile_interval_function,
point::compile_point_function,
SpirVTypes, interval::compile_interval_function, point::compile_point_function,
},
};
@@ -508,12 +505,12 @@ impl SSATape {
if with_module { Some(1000) } else { None },
);
//compile_interval_function(
// &mut b,
// &self,
// types,
// if with_module { Some(2000) } else { None },
//);
compile_interval_function(
&mut b,
&self,
types,
if with_module { Some(2000) } else { None },
);
//compile_gradient_function(
// &mut b,
+1
View File
@@ -248,6 +248,7 @@ impl Grad {
/// Checks that the two values are roughly equal, panicking otherwise
#[cfg(test)]
#[allow(unused)]
pub(crate) fn compare_eq(&self, other: Self) {
let d = (self.v - other.v)
.abs()
+3 -3
View File
@@ -6,10 +6,9 @@ use std::simd::{
use crate::{
interpreters::{
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_05, VALUE_M1, VALUE_NAN, VALUE_PI, VALUE_PI_2,
VALUE_TAU, Value, glfract, glsign,
Mask, VALUE_0, VALUE_1, VALUE_2, VALUE_M1, VALUE_NAN, VALUE_PI, Value, glfract, glsign,
},
vm::choice::{Choice, VChoice},
vm::choice::VChoice,
};
/// 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
#[cfg(test)]
#[allow(unused)]
pub(crate) fn compare_eq(&self, other: Self) {
let d = (self.lower - other.lower)
.abs()
+1 -6
View File
@@ -1,9 +1,4 @@
use std::simd::{
StdFloat,
cmp::{SimdPartialEq, SimdPartialOrd},
num::SimdFloat,
u32x8,
};
use std::simd::u32x8;
/// A single choice made at a min/max node.
///