implement more intervals
This commit is contained in:
@@ -90,12 +90,7 @@ pub(crate) fn compile_interval_function(
|
|||||||
b: &mut rspirv::dr::Builder,
|
b: &mut rspirv::dr::Builder,
|
||||||
mapping: &mut HashMap<u32, (u32, u32)>,
|
mapping: &mut HashMap<u32, (u32, u32)>,
|
||||||
instruction: &SSAInstruction,
|
instruction: &SSAInstruction,
|
||||||
func: impl Fn(
|
func: impl Fn(&mut rspirv::dr::Builder, (u32, u32), (u32, u32), (u32, u32)) -> (u32, u32),
|
||||||
&mut rspirv::dr::Builder,
|
|
||||||
(u32, u32),
|
|
||||||
(u32, u32),
|
|
||||||
(u32, u32),
|
|
||||||
) -> (u32, u32),
|
|
||||||
) {
|
) {
|
||||||
for i in 0..instruction.opcode.size as usize {
|
for i in 0..instruction.opcode.size as usize {
|
||||||
let val_a = input_resolve(float, b, &mapping, instruction.inputs[i]);
|
let val_a = input_resolve(float, b, &mapping, instruction.inputs[i]);
|
||||||
@@ -324,14 +319,30 @@ pub(crate) fn compile_interval_function(
|
|||||||
b.ret_value(value_vec2).unwrap();
|
b.ret_value(value_vec2).unwrap();
|
||||||
},
|
},
|
||||||
SSAPosition => {
|
SSAPosition => {
|
||||||
let pos_low_x = b.composite_extract(types.float, None, pos_low, [0]).unwrap();
|
let pos_low_x = b
|
||||||
let pos_low_y = b.composite_extract(types.float, None, pos_low, [1]).unwrap();
|
.composite_extract(types.float, None, pos_low, [0])
|
||||||
let pos_low_z = b.composite_extract(types.float, None, pos_low, [2]).unwrap();
|
.unwrap();
|
||||||
let pos_low_w = b.composite_extract(types.float, None, pos_low, [3]).unwrap();
|
let pos_low_y = b
|
||||||
let pos_high_x = b.composite_extract(types.float, None, pos_high, [0]).unwrap();
|
.composite_extract(types.float, None, pos_low, [1])
|
||||||
let pos_high_y = b.composite_extract(types.float, None, pos_high, [1]).unwrap();
|
.unwrap();
|
||||||
let pos_high_z = b.composite_extract(types.float, None, pos_high, [2]).unwrap();
|
let pos_low_z = b
|
||||||
let pos_high_w = b.composite_extract(types.float, None, pos_high, [3]).unwrap();
|
.composite_extract(types.float, None, pos_low, [2])
|
||||||
|
.unwrap();
|
||||||
|
let pos_low_w = b
|
||||||
|
.composite_extract(types.float, None, pos_low, [3])
|
||||||
|
.unwrap();
|
||||||
|
let pos_high_x = b
|
||||||
|
.composite_extract(types.float, None, pos_high, [0])
|
||||||
|
.unwrap();
|
||||||
|
let pos_high_y = b
|
||||||
|
.composite_extract(types.float, None, pos_high, [1])
|
||||||
|
.unwrap();
|
||||||
|
let pos_high_z = b
|
||||||
|
.composite_extract(types.float, None, pos_high, [2])
|
||||||
|
.unwrap();
|
||||||
|
let pos_high_w = b
|
||||||
|
.composite_extract(types.float, None, pos_high, [3])
|
||||||
|
.unwrap();
|
||||||
mapping.insert(instruction.outputs[0], (pos_low_x, pos_high_x));
|
mapping.insert(instruction.outputs[0], (pos_low_x, pos_high_x));
|
||||||
mapping.insert(instruction.outputs[1], (pos_low_y, pos_high_y));
|
mapping.insert(instruction.outputs[1], (pos_low_y, pos_high_y));
|
||||||
mapping.insert(instruction.outputs[2], (pos_low_z, pos_high_z));
|
mapping.insert(instruction.outputs[2], (pos_low_z, pos_high_z));
|
||||||
@@ -410,13 +421,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
b.f_ord_not_equal(types.bool, None, v1, v1_floor).unwrap();
|
b.f_ord_not_equal(types.bool, None, v1, v1_floor).unwrap();
|
||||||
let v2_floor_eq =
|
let v2_floor_eq =
|
||||||
b.f_ord_equal(types.bool, None, v1_floor, v2_floor).unwrap();
|
b.f_ord_equal(types.bool, None, v1_floor, v2_floor).unwrap();
|
||||||
let floors =
|
let floors = b
|
||||||
b.logical_and(types.bool, None, v1_floor_eq, v2_floor_eq).unwrap();
|
.logical_and(types.bool, None, v1_floor_eq, v2_floor_eq)
|
||||||
let final_bool =
|
.unwrap();
|
||||||
b.logical_and(types.bool, None, other_constant, floors).unwrap();
|
let final_bool = b
|
||||||
|
.logical_and(types.bool, None, other_constant, floors)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let llt =
|
let llt = b
|
||||||
b.f_ord_less_than(types.bool, None, val_b.0, zero_const).unwrap();
|
.f_ord_less_than(types.bool, None, val_b.0, zero_const)
|
||||||
|
.unwrap();
|
||||||
let ugt = b
|
let ugt = b
|
||||||
.f_ord_greater_than(types.bool, None, val_b.1, zero_const)
|
.f_ord_greater_than(types.bool, None, val_b.1, zero_const)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -473,7 +487,8 @@ pub(crate) fn compile_interval_function(
|
|||||||
&mut mapping,
|
&mut mapping,
|
||||||
instruction,
|
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 pi_const =
|
||||||
|
b.constant_bit32(types.float, (std::f32::consts::PI).to_bits());
|
||||||
let npi_const =
|
let npi_const =
|
||||||
b.constant_bit32(types.float, (-std::f32::consts::PI).to_bits());
|
b.constant_bit32(types.float, (-std::f32::consts::PI).to_bits());
|
||||||
(npi_const, pi_const)
|
(npi_const, pi_const)
|
||||||
@@ -632,8 +647,12 @@ pub(crate) fn compile_interval_function(
|
|||||||
let val_a_lowers = val_a
|
let val_a_lowers = val_a
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
let lt = b.f_ord_less_than(types.bool, None, v.0, zero_const).unwrap();
|
let lt = b
|
||||||
let gt = b.f_ord_greater_than(types.bool, None, v.1, zero_const).unwrap();
|
.f_ord_less_than(types.bool, None, v.0, zero_const)
|
||||||
|
.unwrap();
|
||||||
|
let gt = b
|
||||||
|
.f_ord_greater_than(types.bool, None, v.1, zero_const)
|
||||||
|
.unwrap();
|
||||||
let both = b.logical_and(types.bool, None, lt, gt).unwrap();
|
let both = b.logical_and(types.bool, None, lt, gt).unwrap();
|
||||||
let abs_l = b
|
let abs_l = b
|
||||||
.ext_inst(
|
.ext_inst(
|
||||||
@@ -746,7 +765,12 @@ pub(crate) fn compile_interval_function(
|
|||||||
.f_mul(types.float, None, val_a_lowers[2], val_a_lowers[2])
|
.f_mul(types.float, None, val_a_lowers[2], val_a_lowers[2])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let sum = b
|
let sum = b
|
||||||
.f_add(types.float, None, b.f_add(types.float, None, x, y).unwrap(), z)
|
.f_add(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
b.f_add(types.float, None, x, y).unwrap(),
|
||||||
|
z,
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let sqrt_low = b
|
let sqrt_low = b
|
||||||
.ext_inst(
|
.ext_inst(
|
||||||
@@ -767,7 +791,12 @@ pub(crate) fn compile_interval_function(
|
|||||||
.f_mul(types.float, None, val_a_uppers[2], val_a_uppers[2])
|
.f_mul(types.float, None, val_a_uppers[2], val_a_uppers[2])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let sum = b
|
let sum = b
|
||||||
.f_add(types.float, None, b.f_add(types.float, None, x, y).unwrap(), z)
|
.f_add(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
b.f_add(types.float, None, x, y).unwrap(),
|
||||||
|
z,
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let sqrt_high = b
|
let sqrt_high = b
|
||||||
.ext_inst(
|
.ext_inst(
|
||||||
@@ -857,24 +886,41 @@ pub(crate) fn compile_interval_function(
|
|||||||
mapping.insert(instruction.outputs[0], length);
|
mapping.insert(instruction.outputs[0], length);
|
||||||
},
|
},
|
||||||
SSARecip => {
|
SSARecip => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
let one = b.constant_bit32(types.float, (1.0f32).to_bits());
|
let one = b.constant_bit32(types.float, (1.0f32).to_bits());
|
||||||
(
|
(
|
||||||
b.f_div(types.float, None, one, val_a.1).unwrap(),
|
b.f_div(types.float, None, one, val_a.1).unwrap(),
|
||||||
b.f_div(types.float, None, one, val_a.0).unwrap(),
|
b.f_div(types.float, None, one, val_a.0).unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSANegate => {
|
SSANegate => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
(
|
(
|
||||||
b.f_negate(types.float, None, val_a.1).unwrap(),
|
b.f_negate(types.float, None, val_a.1).unwrap(),
|
||||||
b.f_negate(types.float, None, val_a.0).unwrap(),
|
b.f_negate(types.float, None, val_a.0).unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSARound => {
|
SSARound => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
(
|
(
|
||||||
b.ext_inst(
|
b.ext_inst(
|
||||||
types.float,
|
types.float,
|
||||||
@@ -893,12 +939,20 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAAbs => {
|
SSAAbs => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
||||||
let llt = b.f_ord_less_than(types.bool, None, val_a.0, zero_const).unwrap();
|
let llt = b
|
||||||
|
.f_ord_less_than(types.bool, None, val_a.0, zero_const)
|
||||||
|
.unwrap();
|
||||||
let ugt = b
|
let ugt = b
|
||||||
.f_ord_greater_than(types.bool, None, val_a.1, zero_const)
|
.f_ord_greater_than(types.bool, None, val_a.1, zero_const)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -938,10 +992,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
(abs_low, abs_high)
|
(abs_low, abs_high)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAFloor => {
|
SSAFloor => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
(
|
(
|
||||||
b.ext_inst(
|
b.ext_inst(
|
||||||
types.float,
|
types.float,
|
||||||
@@ -960,10 +1020,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSACeil => {
|
SSACeil => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
(
|
(
|
||||||
b.ext_inst(
|
b.ext_inst(
|
||||||
types.float,
|
types.float,
|
||||||
@@ -982,10 +1048,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAFract => {
|
SSAFract => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut 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
|
let ge1 = b
|
||||||
@@ -1028,11 +1100,18 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASin | SSACos => {
|
SSASin | SSACos => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
let pi_2 = b.constant_bit32(types.float, (std::f32::consts::FRAC_PI_2).to_bits());
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let pi_2 =
|
||||||
|
b.constant_bit32(types.float, (std::f32::consts::FRAC_PI_2).to_bits());
|
||||||
let pi = b.constant_bit32(types.float, (std::f32::consts::PI).to_bits());
|
let pi = b.constant_bit32(types.float, (std::f32::consts::PI).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 two = b.constant_bit32(types.float, (2.0f32).to_bits());
|
let two = b.constant_bit32(types.float, (2.0f32).to_bits());
|
||||||
@@ -1061,14 +1140,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
[IdRef(b.f_div(types.float, None, val_a.1, pi).unwrap())],
|
[IdRef(b.f_div(types.float, None, val_a.1, pi).unwrap())],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let same_cycle =
|
let same_cycle = b
|
||||||
b.f_ord_equal(types.bool, None, lower_cycle, upper_cycle).unwrap();
|
.f_ord_equal(types.bool, None, lower_cycle, upper_cycle)
|
||||||
|
.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_ord_equal(
|
||||||
types.bool,
|
types.bool,
|
||||||
None,
|
None,
|
||||||
b.f_sub(types.float, None, upper_cycle, lower_cycle).unwrap(),
|
b.f_sub(types.float, None, upper_cycle, lower_cycle)
|
||||||
|
.unwrap(),
|
||||||
one,
|
one,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -1151,63 +1232,347 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
(lower, upper)
|
(lower, upper)
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSATan => {
|
SSATan => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Tan as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let pi = b.constant_bit32(types.float, (std::f32::consts::PI).to_bits());
|
||||||
|
let nan = b.constant_bit32(types.float, (f32::NAN).to_bits());
|
||||||
|
let size = b.f_sub(types.float, None, val_a.1, val_a.0).unwrap();
|
||||||
|
let lower_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Tan as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let upper_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Tan as u32,
|
||||||
|
[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(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
(
|
||||||
|
b.select(types.float, None, result_valid, lower_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
b.select(types.float, None, result_valid, upper_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAAsin => {
|
SSAAsin => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Asin as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let one = b.constant_bit32(types.float, (1.0f32).to_bits());
|
||||||
|
let minus_one = b.constant_bit32(types.float, (-1.0f32).to_bits());
|
||||||
|
let nan = b.constant_bit32(types.float, (f32::NAN).to_bits());
|
||||||
|
let lower_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Asin as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let upper_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Asin as u32,
|
||||||
|
[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(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
(
|
||||||
|
b.select(types.float, None, result_valid, lower_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
b.select(types.float, None, result_valid, upper_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAAcos => {
|
SSAAcos => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Acos as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let one = b.constant_bit32(types.float, (1.0f32).to_bits());
|
||||||
|
let minus_one = b.constant_bit32(types.float, (-1.0f32).to_bits());
|
||||||
|
let nan = b.constant_bit32(types.float, (f32::NAN).to_bits());
|
||||||
|
let lower_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Acos as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let upper_tmp = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Acos as u32,
|
||||||
|
[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(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
(
|
||||||
|
b.select(types.float, None, result_valid, lower_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
b.select(types.float, None, result_valid, upper_tmp, nan)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAAtan => {
|
SSAAtan => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Atan as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
(
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Atan as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Atan as u32,
|
||||||
|
[IdRef(val_a.1)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSAExp => {
|
SSAExp => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Exp as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
(
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Exp as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Exp as u32,
|
||||||
|
[IdRef(val_a.1)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSALog => {
|
SSALog => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Log as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
(
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Log as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Log as u32,
|
||||||
|
[IdRef(val_a.1)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASqrt => {
|
SSASqrt => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.ext_inst(types.float, None, types.glsl, spirv::GLOp::Sqrt as u32, [IdRef(val_a)])
|
types.float,
|
||||||
.unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
(
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Sqrt as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
b.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Sqrt as u32,
|
||||||
|
[IdRef(val_a.1)],
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASquare => {
|
SSASquare => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
b.f_mul(types.float, None, val_a, val_a).unwrap()
|
types.float,
|
||||||
});
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
|
||||||
|
let ult = b.f_ord_less_than(types.bool, None, val_a.1, zero).unwrap();
|
||||||
|
let lgt = b
|
||||||
|
.f_ord_greater_than(types.bool, None, val_a.0, zero)
|
||||||
|
.unwrap();
|
||||||
|
let squ_lower = b.f_mul(types.float, None, val_a.0, val_a.0).unwrap();
|
||||||
|
let squ_upper = b.f_mul(types.float, None, val_a.1, val_a.1).unwrap();
|
||||||
|
let abs_lower = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::FAbs as u32,
|
||||||
|
[IdRef(val_a.0)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let abs_upper = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::FAbs as u32,
|
||||||
|
[IdRef(val_a.1)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let k = b
|
||||||
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::FMax as u32,
|
||||||
|
[IdRef(abs_lower), IdRef(abs_upper)],
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let squ_k = b.f_mul(types.float, None, k, k).unwrap();
|
||||||
|
(
|
||||||
|
b.select(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
ult,
|
||||||
|
squ_upper,
|
||||||
|
b.select(types.float, None, lgt, squ_lower, zero).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
b.select(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
ult,
|
||||||
|
squ_lower,
|
||||||
|
b.select(types.float, None, lgt, squ_upper, squ_k).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSACube => {
|
SSACube => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
let square = b.f_mul(types.float, None, val_a, val_a).unwrap();
|
types.float,
|
||||||
b.f_mul(types.float, None, val_a, square).unwrap()
|
&mut b,
|
||||||
});
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, val_a| {
|
||||||
|
let squ_lower = b.f_mul(types.float, None, val_a.0, val_a.0).unwrap();
|
||||||
|
let squ_upper = b.f_mul(types.float, None, val_a.1, val_a.1).unwrap();
|
||||||
|
(
|
||||||
|
b.f_mul(types.float, None, val_a.0, squ_lower).unwrap(),
|
||||||
|
b.f_mul(types.float, None, val_a.1, squ_upper).unwrap(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASmoothMin => {
|
SSASmoothMin => {
|
||||||
param_three(types.float, &mut b, &mut mapping, instruction, |b, d1, d2, k| {
|
param_three(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, d1, d2, k| {
|
||||||
let half_const = b.constant_bit32(types.float, (0.5f32).to_bits());
|
let half_const = b.constant_bit32(types.float, (0.5f32).to_bits());
|
||||||
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
||||||
let one_const = b.constant_bit32(types.float, (1.0f32).to_bits());
|
let one_const = b.constant_bit32(types.float, (1.0f32).to_bits());
|
||||||
@@ -1237,10 +1602,16 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
b.f_sub(types.float, None, mix, kh_negh).unwrap()
|
b.f_sub(types.float, None, mix, kh_negh).unwrap()
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASmoothMax => {
|
SSASmoothMax => {
|
||||||
param_three(types.float, &mut b, &mut mapping, instruction, |b, d1, d2, k| {
|
param_three(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mut mapping,
|
||||||
|
instruction,
|
||||||
|
|b, d1, d2, k| {
|
||||||
let half_const = b.constant_bit32(types.float, (0.5f32).to_bits());
|
let half_const = b.constant_bit32(types.float, (0.5f32).to_bits());
|
||||||
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
let zero_const = b.constant_bit32(types.float, (0.0f32).to_bits());
|
||||||
let one_const = b.constant_bit32(types.float, (1.0f32).to_bits());
|
let one_const = b.constant_bit32(types.float, (1.0f32).to_bits());
|
||||||
@@ -1271,7 +1642,8 @@ pub(crate) fn compile_interval_function(
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
b.f_add(types.float, None, mix, kh_negh).unwrap()
|
b.f_add(types.float, None, mix, kh_negh).unwrap()
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
SSASmoothMinMaterial => todo!(),
|
SSASmoothMinMaterial => todo!(),
|
||||||
SSASmoothMaxMaterial => todo!(),
|
SSASmoothMaxMaterial => todo!(),
|
||||||
@@ -1342,11 +1714,21 @@ pub(crate) fn compile_interval_function(
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let pos = b.composite_construct(types.vec3, None, pos_part).unwrap();
|
let pos = b.composite_construct(types.vec3, None, pos_part).unwrap();
|
||||||
let radius =
|
let radius = input_resolve(
|
||||||
input_resolve(types.float, &mut b, &mapping, instruction.inputs[3 as usize]);
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mapping,
|
||||||
|
instruction.inputs[3 as usize],
|
||||||
|
);
|
||||||
|
|
||||||
let length = b
|
let length = b
|
||||||
.ext_inst(types.float, None, types.glsl, spirv::GLOp::Length as u32, [IdRef(pos)])
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Length as u32,
|
||||||
|
[IdRef(pos)],
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let sphere = b.f_sub(types.float, None, length, radius).unwrap();
|
let sphere = b.f_sub(types.float, None, length, radius).unwrap();
|
||||||
|
|
||||||
@@ -1380,7 +1762,13 @@ pub(crate) fn compile_interval_function(
|
|||||||
let dim = b.composite_construct(types.vec3, None, dim_part).unwrap();
|
let dim = b.composite_construct(types.vec3, None, dim_part).unwrap();
|
||||||
|
|
||||||
let abs = b
|
let abs = b
|
||||||
.ext_inst(types.vec3, None, types.glsl, spirv::GLOp::FAbs as u32, [IdRef(pos)])
|
.ext_inst(
|
||||||
|
types.vec3,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::FAbs as u32,
|
||||||
|
[IdRef(pos)],
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let q = b.f_sub(types.vec3, None, abs, dim).unwrap();
|
let q = b.f_sub(types.vec3, None, abs, dim).unwrap();
|
||||||
@@ -1461,14 +1849,28 @@ pub(crate) fn compile_interval_function(
|
|||||||
.composite_construct(types.vec2, None, [pos_part[0], pos_part[2]])
|
.composite_construct(types.vec2, None, [pos_part[0], pos_part[2]])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let rad1 =
|
let rad1 = input_resolve(
|
||||||
input_resolve(types.float, &mut b, &mapping, instruction.inputs[3 as usize]);
|
types.float,
|
||||||
let rad2 =
|
&mut b,
|
||||||
input_resolve(types.float, &mut b, &mapping, instruction.inputs[4 as usize]);
|
&mapping,
|
||||||
|
instruction.inputs[3 as usize],
|
||||||
|
);
|
||||||
|
let rad2 = input_resolve(
|
||||||
|
types.float,
|
||||||
|
&mut b,
|
||||||
|
&mapping,
|
||||||
|
instruction.inputs[4 as usize],
|
||||||
|
);
|
||||||
|
|
||||||
let dot = b.dot(types.float, None, pos_vec2, pos_vec2).unwrap();
|
let dot = b.dot(types.float, None, pos_vec2, pos_vec2).unwrap();
|
||||||
let sqrt = b
|
let sqrt = b
|
||||||
.ext_inst(types.float, None, types.glsl, spirv::GLOp::Sqrt as u32, [IdRef(dot)])
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Sqrt as u32,
|
||||||
|
[IdRef(dot)],
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let subtx = b.f_sub(types.float, None, sqrt, rad1).unwrap();
|
let subtx = b.f_sub(types.float, None, sqrt, rad1).unwrap();
|
||||||
|
|
||||||
@@ -1477,7 +1879,13 @@ pub(crate) fn compile_interval_function(
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let length = b
|
let length = b
|
||||||
.ext_inst(types.float, None, types.glsl, spirv::GLOp::Length as u32, [IdRef(q)])
|
.ext_inst(
|
||||||
|
types.float,
|
||||||
|
None,
|
||||||
|
types.glsl,
|
||||||
|
spirv::GLOp::Length as u32,
|
||||||
|
[IdRef(q)],
|
||||||
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
mapping.insert(
|
mapping.insert(
|
||||||
@@ -1498,12 +1906,15 @@ pub(crate) fn compile_interval_function(
|
|||||||
let onen = b.constant_bit32(types.float, (-1.0f32).to_bits());
|
let onen = b.constant_bit32(types.float, (-1.0f32).to_bits());
|
||||||
let equal = b.f_ord_equal(types.bool, None, val_a, val_b).unwrap();
|
let equal = b.f_ord_equal(types.bool, None, val_a, val_b).unwrap();
|
||||||
let less = b.f_ord_less_than(types.bool, None, val_a, val_b).unwrap();
|
let less = b.f_ord_less_than(types.bool, None, val_a, val_b).unwrap();
|
||||||
let more = b.f_ord_greater_than(types.bool, None, val_a, val_b).unwrap();
|
let more = b
|
||||||
|
.f_ord_greater_than(types.bool, None, val_a, val_b)
|
||||||
|
.unwrap();
|
||||||
let select_less = b.select(types.float, None, less, onen, nan).unwrap();
|
let select_less = b.select(types.float, None, less, onen, nan).unwrap();
|
||||||
let select_more =
|
let select_more =
|
||||||
b.select(types.float, None, more, one, select_less).unwrap();
|
b.select(types.float, None, more, one, select_less).unwrap();
|
||||||
let select_eq =
|
let select_eq = b
|
||||||
b.select(types.float, None, equal, zero, select_more).unwrap();
|
.select(types.float, None, equal, zero, select_more)
|
||||||
|
.unwrap();
|
||||||
select_eq
|
select_eq
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -1535,14 +1946,20 @@ pub(crate) fn compile_interval_function(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
SSANot => {
|
SSANot => {
|
||||||
param_one(types.float, &mut b, &mut mapping, instruction, |b, val_a| {
|
param_one(
|
||||||
|
types.float,
|
||||||
|
&mut 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 equal = b.f_ord_equal(types.bool, None, val_a, zero).unwrap();
|
let equal = b.f_ord_equal(types.bool, None, val_a, zero).unwrap();
|
||||||
b.select(types.float, None, equal, one, zero).unwrap()
|
b.select(types.float, None, equal, one, zero).unwrap()
|
||||||
});
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.end_function().unwrap();
|
b.end_function().unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
pub(crate) mod gradient;
|
//pub(crate) mod gradient;
|
||||||
pub(crate) mod point;
|
|
||||||
//pub(crate) mod interval;
|
//pub(crate) mod interval;
|
||||||
|
pub(crate) mod point;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub(crate) struct SpirVTypes {
|
pub(crate) struct SpirVTypes {
|
||||||
|
|||||||
@@ -228,11 +228,11 @@ impl Interval {
|
|||||||
pub fn acos(self) -> Self {
|
pub fn acos(self) -> Self {
|
||||||
let lower = (self.lower.simd_lt(VALUE_M1) | self.upper.simd_gt(VALUE_1)).select(
|
let lower = (self.lower.simd_lt(VALUE_M1) | self.upper.simd_gt(VALUE_1)).select(
|
||||||
VALUE_NAN,
|
VALUE_NAN,
|
||||||
Value::from_array(self.upper.to_array().map(|f| f.asin())),
|
Value::from_array(self.upper.to_array().map(|f| f.acos())),
|
||||||
);
|
);
|
||||||
let upper = (self.lower.simd_lt(VALUE_M1) | self.upper.simd_gt(VALUE_1)).select(
|
let upper = (self.lower.simd_lt(VALUE_M1) | self.upper.simd_gt(VALUE_1)).select(
|
||||||
VALUE_NAN,
|
VALUE_NAN,
|
||||||
Value::from_array(self.lower.to_array().map(|f| f.asin())),
|
Value::from_array(self.lower.to_array().map(|f| f.acos())),
|
||||||
);
|
);
|
||||||
Interval::new(lower, upper)
|
Interval::new(lower, upper)
|
||||||
}
|
}
|
||||||
@@ -240,8 +240,8 @@ impl Interval {
|
|||||||
/// Computes the arctangent of the interval
|
/// Computes the arctangent of the interval
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn atan(self) -> Self {
|
pub fn atan(self) -> Self {
|
||||||
let lower = Value::from_array(self.lower.to_array().map(|f| f.asin()));
|
let lower = Value::from_array(self.lower.to_array().map(|f| f.atan()));
|
||||||
let upper = Value::from_array(self.upper.to_array().map(|f| f.asin()));
|
let upper = Value::from_array(self.upper.to_array().map(|f| f.atan()));
|
||||||
Interval::new(lower, upper)
|
Interval::new(lower, upper)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user