Add bevy support

This commit is contained in:
2026-10-02 17:38:08 +01:00
parent 45762855bc
commit 6b7112d011
9 changed files with 1057 additions and 579 deletions
Generated
+788 -381
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -18,7 +18,7 @@ bytemuck = { version = "1.13", features = [
"min_const_generics",
] }
glam = "0.30.3"
glam = "0.33.12"
egui = "0.31.1"
egui_winit_vulkano = "0.28.0"
@@ -29,13 +29,13 @@ egui_plot = "0.32.1"
utf-8 = "0.7"
rand = "0.9.1"
rand = "0.10.3"
foldhash = "0.1.5"
log = "0.4"
simplelog = "0.12"
rspirv = "0.12"
rspirv = "0.13.0"
num_cpus = "1"
+14 -9
View File
@@ -41,7 +41,7 @@ use notify::{RecommendedWatcher, Watcher};
use rspirv::dr::Module;
use simplelog::{CombinedLogger, Config, TermLogger, WriteLogger};
use tape_load::{
interpreters::{self, interval::IntervalInterpreter, point::PointInterpreter},
interpreters::{interval::IntervalInterpreter, point::PointInterpreter},
ssa, types,
};
use vulkano::{
@@ -474,7 +474,8 @@ impl App {
.map(|i| (p, i))
})
.min_by_key(|(p, _)| {
// We assign a lower score to device types that are likely to be faster/better.
// We assign a lower score to device types that are likely
// to be faster/better.
match p.properties().device_type {
PhysicalDeviceType::DiscreteGpu => 0,
PhysicalDeviceType::IntegratedGpu => 1,
@@ -884,8 +885,8 @@ impl ApplicationHandler for App {
present_modes
.into_iter()
.min_by_key(|p| {
// We assign a lower score to device types that are likely to be
// faster/better.
// We assign a lower score to device types that are
// likely to be faster/better.
match p {
PresentMode::Mailbox => 0,
PresentMode::FifoRelaxed => 1,
@@ -1264,8 +1265,12 @@ impl App {
let aspect_ratio =
rcx.swapchain.image_extent()[0] as f32 / rcx.swapchain.image_extent()[1] as f32;
let proj =
Mat4::perspective_infinite_reverse_rh(std::f32::consts::FRAC_PI_2, aspect_ratio, near);
// TODO: Make this use the vulkan projection
let proj = glam::camera::rh::proj::directx::perspective_infinite_reverse(
std::f32::consts::FRAC_PI_2,
aspect_ratio,
near,
);
let view = Mat4::from_euler(EulerRot::XYZ, self.cstate.forward.x.to_radians(), self.cstate.forward.y.to_radians(), self.cstate.forward.z.to_radians())
//* Mat4::from_rotation_z(std::f32::consts::PI)
* Mat4::from_translation(Vec3::ZERO - self.cstate.position);
@@ -2385,9 +2390,9 @@ fn pipeline_recompile(
)
.unwrap();
// Define the shader groups that will eventually turn into the shader binding
// table. The numbers are the indices of the stages in the `stages`
// array.
// Define the shader groups that will eventually turn into the shader
// binding table. The numbers are the indices of the stages in
// the `stages` array.
let mut groups = vec![
RayTracingShaderGroupCreateInfo::General { general_shader: 0 },
RayTracingShaderGroupCreateInfo::General { general_shader: 1 },
+2 -34
View File
@@ -1,7 +1,6 @@
use std::{
fs::File,
io::Write,
simd::StdFloat,
sync::{
Arc, Mutex, RwLock,
atomic::{AtomicU64, Ordering},
@@ -13,9 +12,8 @@ use std::{
use foldhash::{HashMap, HashMapExt};
use glam::Vec3;
use log::info;
use rand::{Rng, SeedableRng, rngs::SmallRng};
use rand::{RngExt as _, SeedableRng, rngs::SmallRng};
use rspirv::{binary::Assemble, dr::Module};
use tape_load::interpreters;
use vulkano::{
buffer::{Subbuffer, allocator::SubbufferAllocator},
descriptor_set::{DescriptorSet, WriteDescriptorSet, allocator::DescriptorSetAllocator},
@@ -34,7 +32,6 @@ use vulkano::{
use crate::{
ARGS, MAX_TRANSFORM_BUFFER, MAXIMUM_SUBDIVISION, get_spec_constants,
gui::PreviousDebug,
interpreters::point::PointInterpreter,
objects::{self, CSG, Position},
ssa::{SSAInput, SSAOpcode, SSAOpcodeSized, SSATape},
};
@@ -528,36 +525,7 @@ fn create_csg(seed: u64) -> SSATape {
}
fn interval_check(csg: &CSG, time: f32) -> (Vec3, Vec3) {
const INTERPRET_INPUT_X: interpreters::Value =
interpreters::Value::from_array([10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0, 0.0]);
const INTERPRET_INPUT_Y: interpreters::Value =
interpreters::Value::from_array([0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0]);
const INTERPRET_INPUT_Z: interpreters::Value =
interpreters::Value::from_array([0.0, 0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0]);
const INTERPRET_MUL: interpreters::Value =
interpreters::Value::from_array([-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 0.0]);
const INTERPRET_ADD: interpreters::Value = interpreters::Value::from_array([
10000.0, 10000.0, 10000.0, -10000.0, -10000.0, -10000.0, 0.0, 0.0,
]);
let mut interpreter = PointInterpreter::new(&csg.parts);
let interpreter_out = interpreter
.scene(
INTERPRET_INPUT_X,
INTERPRET_INPUT_Y,
INTERPRET_INPUT_Z,
interpreters::Value::splat(time),
)
.mul_add(INTERPRET_MUL, INTERPRET_ADD)
.to_array();
const EPSILON: f32 = 0.1;
let highest_corner =
Vec3::new(interpreter_out[0], interpreter_out[1], interpreter_out[2]) + EPSILON;
let lowest_corner =
Vec3::new(interpreter_out[3], interpreter_out[4], interpreter_out[5]) - EPSILON;
let (highest_corner, lowest_corner) = csg.parts.get_aabb(time);
(highest_corner - lowest_corner, lowest_corner)
}
+7 -2
View File
@@ -4,7 +4,12 @@ version = "0.1.0"
edition = "2024"
[dependencies]
glam = "0.30.3"
rspirv = "0.12"
bevy_reflect = { git = "https://github.com/bevyengine/bevy.git", rev = "0f38358f573a7dc6ea961076f6151be662142010", optional = true }
glam = "0.33.12"
rspirv = "0.13.0"
foldhash = "0.1.5"
humantime = "2.3"
[features]
default = []
bevy = ["dep:bevy_reflect"]
+35 -35
View File
@@ -198,7 +198,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan2 as u32,
spirv::GlslStd450Op::Atan2 as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -216,7 +216,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -235,7 +235,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -281,7 +281,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -310,7 +310,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Distance as u32,
spirv::GlslStd450Op::Distance as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -334,7 +334,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Round as u32,
spirv::GlslStd450Op::Round as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -346,7 +346,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -358,7 +358,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -370,7 +370,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Ceil as u32,
spirv::GlslStd450Op::Ceil as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -382,7 +382,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
spirv::GlslStd450Op::Fract as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -394,7 +394,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sin as u32,
spirv::GlslStd450Op::Sin as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -406,7 +406,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Cos as u32,
spirv::GlslStd450Op::Cos as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -418,7 +418,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Tan as u32,
spirv::GlslStd450Op::Tan as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -430,7 +430,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Asin as u32,
spirv::GlslStd450Op::Asin as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -442,7 +442,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Acos as u32,
spirv::GlslStd450Op::Acos as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -454,7 +454,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan as u32,
spirv::GlslStd450Op::Atan as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -466,7 +466,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Exp as u32,
spirv::GlslStd450Op::Exp as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -478,7 +478,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Log as u32,
spirv::GlslStd450Op::Log as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -490,7 +490,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -521,7 +521,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half), IdRef(zero_const), IdRef(one_const)],
)
.unwrap();
@@ -533,7 +533,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(d2), IdRef(d1), IdRef(h)],
)
.unwrap();
@@ -554,7 +554,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half), IdRef(zero_const), IdRef(one_const)],
)
.unwrap();
@@ -567,7 +567,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(d2), IdRef(negate), IdRef(h)],
)
.unwrap();
@@ -587,7 +587,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -605,7 +605,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -623,7 +623,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fma as u32,
spirv::GlslStd450Op::Fma as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -646,7 +646,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(pos)],
)
.unwrap();
@@ -676,7 +676,7 @@ pub(crate) fn compile_gradient_function(
types.vec3,
None,
types.glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(pos)],
)
.unwrap();
@@ -692,7 +692,7 @@ pub(crate) fn compile_gradient_function(
types.vec3,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(q), IdRef(zero_vec3)],
)
.unwrap();
@@ -702,7 +702,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(q_limit)],
)
.unwrap();
@@ -715,7 +715,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(q_x), IdRef(q_y)],
)
.unwrap();
@@ -724,7 +724,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max1), IdRef(q_z)],
)
.unwrap();
@@ -733,7 +733,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max2), IdRef(zero)],
)
.unwrap();
@@ -763,7 +763,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(dot)],
)
.unwrap();
@@ -778,7 +778,7 @@ pub(crate) fn compile_gradient_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(q)],
)
.unwrap();
+75 -75
View File
@@ -130,7 +130,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(m0), IdRef(m1)],
)
.unwrap();
@@ -139,7 +139,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(min), IdRef(m2)],
)
.unwrap();
@@ -148,7 +148,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(min), IdRef(m3)],
)
.unwrap();
@@ -157,7 +157,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(m0), IdRef(m1)],
)
.unwrap();
@@ -166,7 +166,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max), IdRef(m2)],
)
.unwrap();
@@ -175,7 +175,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max), IdRef(m3)],
)
.unwrap();
@@ -198,7 +198,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(m0), IdRef(m1)],
)
.unwrap();
@@ -207,7 +207,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(min), IdRef(m2)],
)
.unwrap();
@@ -216,7 +216,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(min), IdRef(m3)],
)
.unwrap();
@@ -225,7 +225,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(m0), IdRef(m1)],
)
.unwrap();
@@ -234,7 +234,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max), IdRef(m2)],
)
.unwrap();
@@ -243,7 +243,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max), IdRef(m3)],
)
.unwrap();
@@ -312,17 +312,17 @@ pub(crate) fn compile_interval_function(
let gt = b.f_ord_greater_than(bool, None, v.1, zero_const).unwrap();
let both = b.logical_and(bool, None, lt, gt).unwrap();
let abs_l = b
.ext_inst(float, None, glsl, spirv::GLOp::FAbs as u32, [IdRef(v.0)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.0)])
.unwrap();
let abs_h = b
.ext_inst(float, None, glsl, spirv::GLOp::FAbs as u32, [IdRef(v.1)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.1)])
.unwrap();
let min = b
.ext_inst(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(abs_l), IdRef(abs_h)],
)
.unwrap();
@@ -334,16 +334,16 @@ pub(crate) fn compile_interval_function(
.iter()
.map(|v| {
let abs_l = b
.ext_inst(float, None, glsl, spirv::GLOp::FAbs as u32, [IdRef(v.0)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.0)])
.unwrap();
let abs_h = b
.ext_inst(float, None, glsl, spirv::GLOp::FAbs as u32, [IdRef(v.1)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.1)])
.unwrap();
b.ext_inst(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(abs_l), IdRef(abs_h)],
)
.unwrap()
@@ -361,7 +361,7 @@ pub(crate) fn compile_interval_function(
.unwrap();
let xy_sum = b.f_add(float, None, x, y).unwrap();
let sqrt_low = b
.ext_inst(float, None, glsl, spirv::GLOp::Sqrt as u32, [IdRef(xy_sum)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::Sqrt as u32, [IdRef(xy_sum)])
.unwrap();
let x = b
.f_mul(float, None, val_a_uppers[0], val_a_uppers[0])
@@ -371,7 +371,7 @@ pub(crate) fn compile_interval_function(
.unwrap();
let xy_sum = b.f_add(float, None, x, y).unwrap();
let sqrt_high = b
.ext_inst(float, None, glsl, spirv::GLOp::Sqrt as u32, [IdRef(xy_sum)])
.ext_inst(float, None, glsl, spirv::GlslStd450Op::Sqrt as u32, [IdRef(xy_sum)])
.unwrap();
(sqrt_low, sqrt_high)
},
@@ -392,7 +392,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xyz_sum)],
)
.unwrap();
@@ -412,7 +412,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xyz_sum)],
)
.unwrap();
@@ -439,7 +439,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xyzw_sum)],
)
.unwrap();
@@ -463,7 +463,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xyzw_sum)],
)
.unwrap();
@@ -496,7 +496,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_a.1), IdRef(n_val_a_low)],
)
.unwrap();
@@ -540,7 +540,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_a.0), IdRef(val_b.0)],
)
.unwrap(),
@@ -548,7 +548,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_a.1), IdRef(val_b.1)],
)
.unwrap(),
@@ -592,7 +592,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_a.0), IdRef(val_b.0)],
)
.unwrap(),
@@ -600,7 +600,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_a.1), IdRef(val_b.1)],
)
.unwrap(),
@@ -650,7 +650,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_b.0), IdRef(zero_const)],
)
.unwrap();
@@ -659,7 +659,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_b.1), IdRef(zero_const)],
)
.unwrap();
@@ -711,7 +711,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_b.0), IdRef(zero_const)],
)
.unwrap();
@@ -720,7 +720,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_b.1), IdRef(zero_const)],
)
.unwrap();
@@ -748,7 +748,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -757,7 +757,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -766,7 +766,7 @@ pub(crate) fn compile_interval_function(
float,
None,
glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(abs_lower), IdRef(abs_upper)],
)
.unwrap();
@@ -877,7 +877,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(v1)],
)
.unwrap();
@@ -886,7 +886,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(v2)],
)
.unwrap();
@@ -913,7 +913,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_b.1), IdRef(n_val_b_low)],
)
.unwrap();
@@ -1079,7 +1079,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Round as u32,
spirv::GlslStd450Op::Round as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1087,7 +1087,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Round as u32,
spirv::GlslStd450Op::Round as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1106,7 +1106,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1114,7 +1114,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1128,7 +1128,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Ceil as u32,
spirv::GlslStd450Op::Ceil as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1136,7 +1136,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Ceil as u32,
spirv::GlslStd450Op::Ceil as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1156,7 +1156,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
spirv::GlslStd450Op::Fract as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -1165,7 +1165,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
spirv::GlslStd450Op::Fract as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -1195,7 +1195,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(lower_cycle)],
)
.unwrap();
@@ -1205,7 +1205,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(upper_cycle)],
)
.unwrap();
@@ -1224,7 +1224,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Cos as u32,
spirv::GlslStd450Op::Cos as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -1233,7 +1233,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Cos as u32,
spirv::GlslStd450Op::Cos as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -1256,7 +1256,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap();
@@ -1268,7 +1268,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(temp0), IdRef(temp1)],
)
.unwrap();
@@ -1288,7 +1288,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Tan as u32,
spirv::GlslStd450Op::Tan as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -1297,7 +1297,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Tan as u32,
spirv::GlslStd450Op::Tan as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -1324,7 +1324,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Asin as u32,
spirv::GlslStd450Op::Asin as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -1333,7 +1333,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Asin as u32,
spirv::GlslStd450Op::Asin as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -1362,7 +1362,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Acos as u32,
spirv::GlslStd450Op::Acos as u32,
[IdRef(val_a.0)],
)
.unwrap();
@@ -1371,7 +1371,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Acos as u32,
spirv::GlslStd450Op::Acos as u32,
[IdRef(val_a.1)],
)
.unwrap();
@@ -1397,7 +1397,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan as u32,
spirv::GlslStd450Op::Atan as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1405,7 +1405,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan as u32,
spirv::GlslStd450Op::Atan as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1419,7 +1419,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Exp as u32,
spirv::GlslStd450Op::Exp as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1427,7 +1427,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Exp as u32,
spirv::GlslStd450Op::Exp as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1441,7 +1441,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Log as u32,
spirv::GlslStd450Op::Log as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1449,7 +1449,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Log as u32,
spirv::GlslStd450Op::Log as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1463,7 +1463,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(val_a.0)],
)
.unwrap(),
@@ -1471,7 +1471,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(val_a.1)],
)
.unwrap(),
@@ -1513,7 +1513,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half.0), IdRef(zero_const), IdRef(one_const)],
)
.unwrap(),
@@ -1521,7 +1521,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half.1), IdRef(zero_const), IdRef(one_const)],
)
.unwrap(),
@@ -1553,7 +1553,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half.0), IdRef(zero_const), IdRef(one_const)],
)
.unwrap(),
@@ -1561,7 +1561,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half.1), IdRef(zero_const), IdRef(one_const)],
)
.unwrap(),
@@ -1588,7 +1588,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(val_a.0), IdRef(val_b.0), IdRef(val_c.1)],
)
.unwrap(),
@@ -1596,7 +1596,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(val_a.1), IdRef(val_b.0), IdRef(val_c.1)],
)
.unwrap(),
@@ -1742,7 +1742,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(dot.0)],
)
.unwrap(),
@@ -1750,7 +1750,7 @@ pub(crate) fn compile_interval_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(dot.1)],
)
.unwrap(),
+35 -35
View File
@@ -191,7 +191,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan2 as u32,
spirv::GlslStd450Op::Atan2 as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -209,7 +209,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMin as u32,
spirv::GlslStd450Op::FMin as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -228,7 +228,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -274,7 +274,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -303,7 +303,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Distance as u32,
spirv::GlslStd450Op::Distance as u32,
[IdRef(val_a), IdRef(val_b)],
)
.unwrap()
@@ -327,7 +327,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Round as u32,
spirv::GlslStd450Op::Round as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -339,7 +339,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -351,7 +351,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Floor as u32,
spirv::GlslStd450Op::Floor as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -363,7 +363,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Ceil as u32,
spirv::GlslStd450Op::Ceil as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -375,7 +375,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fract as u32,
spirv::GlslStd450Op::Fract as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -387,7 +387,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sin as u32,
spirv::GlslStd450Op::Sin as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -399,7 +399,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Cos as u32,
spirv::GlslStd450Op::Cos as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -411,7 +411,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Tan as u32,
spirv::GlslStd450Op::Tan as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -423,7 +423,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Asin as u32,
spirv::GlslStd450Op::Asin as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -435,7 +435,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Acos as u32,
spirv::GlslStd450Op::Acos as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -447,7 +447,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Atan as u32,
spirv::GlslStd450Op::Atan as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -459,7 +459,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Exp as u32,
spirv::GlslStd450Op::Exp as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -471,7 +471,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Log as u32,
spirv::GlslStd450Op::Log as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -483,7 +483,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(val_a)],
)
.unwrap()
@@ -514,7 +514,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half), IdRef(zero_const), IdRef(one_const)],
)
.unwrap();
@@ -526,7 +526,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(d2), IdRef(d1), IdRef(h)],
)
.unwrap();
@@ -547,7 +547,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(add_half), IdRef(zero_const), IdRef(one_const)],
)
.unwrap();
@@ -560,7 +560,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(d2), IdRef(negate), IdRef(h)],
)
.unwrap();
@@ -580,7 +580,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FClamp as u32,
spirv::GlslStd450Op::FClamp as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -598,7 +598,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMix as u32,
spirv::GlslStd450Op::FMix as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -616,7 +616,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Fma as u32,
spirv::GlslStd450Op::Fma as u32,
[IdRef(val_a), IdRef(val_b), IdRef(val_c)],
)
.unwrap()
@@ -638,7 +638,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(pos)],
)
.unwrap();
@@ -668,7 +668,7 @@ pub(crate) fn compile_point_function(
types.vec3,
None,
types.glsl,
spirv::GLOp::FAbs as u32,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(pos)],
)
.unwrap();
@@ -684,7 +684,7 @@ pub(crate) fn compile_point_function(
types.vec3,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(q), IdRef(zero_vec3)],
)
.unwrap();
@@ -694,7 +694,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(q_limit)],
)
.unwrap();
@@ -707,7 +707,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(q_x), IdRef(q_y)],
)
.unwrap();
@@ -716,7 +716,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max1), IdRef(q_z)],
)
.unwrap();
@@ -725,7 +725,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::FMax as u32,
spirv::GlslStd450Op::FMax as u32,
[IdRef(max2), IdRef(zero)],
)
.unwrap();
@@ -755,7 +755,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Sqrt as u32,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(dot)],
)
.unwrap();
@@ -770,7 +770,7 @@ pub(crate) fn compile_point_function(
types.float,
None,
types.glsl,
spirv::GLOp::Length as u32,
spirv::GlslStd450Op::Length as u32,
[IdRef(q)],
)
.unwrap();
+98 -5
View File
@@ -1,10 +1,18 @@
use core::f32;
use std::{
hash::{Hash, Hasher},
simd::StdFloat as _,
};
#[cfg(feature = "bevy")]
use bevy_reflect::prelude::*;
use glam::Vec3;
use rspirv::{binary::Disassemble, dr::Module, spirv};
use crate::{
DUMP_SPV_DIS_TO_FILE,
instruction_set::InstructionSet,
interpreters::{self, point::PointInterpreter},
spirv_compilers::{
SpirVTypes, gradient::compile_gradient_function, interval::compile_interval_function,
point::compile_point_function,
@@ -13,7 +21,9 @@ use crate::{
const JIT_VERSION: u32 = 1;
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub enum SSAOpcode {
SSAAdd,
SSASub,
@@ -70,19 +80,35 @@ pub enum SSAOpcode {
SSASDFTorus,
}
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSAOpcodeSized {
pub opcode: SSAOpcode,
pub size: u8,
}
#[derive(Debug, PartialEq, Clone, Copy)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub enum SSAInput {
Register(u32),
Constant(f32),
}
#[derive(Debug, Default, PartialEq, Clone)]
impl Hash for SSAInput {
fn hash<H: Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
match self {
SSAInput::Register(e) => e.hash(state),
SSAInput::Constant(e) => e.to_bits().hash(state),
}
}
}
#[derive(Debug, Default, PartialEq, Clone, Hash)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSAInstruction {
pub opcode: SSAOpcodeSized,
pub inputs: Vec<SSAInput>,
@@ -90,21 +116,50 @@ pub struct SSAInstruction {
}
#[derive(Debug, Default, PartialEq, Clone)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSATape {
pub last_output: u32,
pub tape: Vec<SSAInstruction>,
constants: Vec<f32>,
}
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
impl Hash for SSATape {
fn hash<H: Hasher>(&self, state: &mut H) {
self.last_output.hash(state);
self.tape.hash(state);
self.constants.len().hash(state);
for constant in &self.constants {
constant.to_bits().hash(state);
}
}
}
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy, Hash)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
struct GPUOpcode(u8);
#[derive(Debug, Default, PartialEq, Clone)]
#[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct GPUTape {
pub instructions: Vec<u8>,
pub io: Vec<u8>,
pub constants: Vec<f32>,
}
impl Hash for GPUTape {
fn hash<H: Hasher>(&self, state: &mut H) {
self.instructions.hash(state);
self.io.hash(state);
self.constants.len().hash(state);
for constant in &self.constants {
constant.to_bits().hash(state);
}
}
}
impl SSAOpcodeSized {
const fn output(&self) -> u8 {
use SSAOpcode::*;
@@ -262,6 +317,44 @@ impl SSATape {
outputs_register
}
/**
* Returns the AABB of the tape as a tuple of lowest corner, highest
* corner.
*/
pub fn get_aabb(&self, time: f32) -> (Vec3, Vec3) {
const INTERPRET_INPUT_X: interpreters::Value =
interpreters::Value::from_array([10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0, 0.0]);
const INTERPRET_INPUT_Y: interpreters::Value =
interpreters::Value::from_array([0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0, 0.0]);
const INTERPRET_INPUT_Z: interpreters::Value =
interpreters::Value::from_array([0.0, 0.0, 10000.0, 0.0, 0.0, -10000.0, 0.0, 0.0]);
const INTERPRET_MUL: interpreters::Value =
interpreters::Value::from_array([-1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 0.0]);
const INTERPRET_ADD: interpreters::Value = interpreters::Value::from_array([
10000.0, 10000.0, 10000.0, -10000.0, -10000.0, -10000.0, 0.0, 0.0,
]);
let mut interpreter = PointInterpreter::new(self);
let interpreter_out = interpreter
.scene(
INTERPRET_INPUT_X,
INTERPRET_INPUT_Y,
INTERPRET_INPUT_Z,
interpreters::Value::splat(time),
)
.mul_add(INTERPRET_MUL, INTERPRET_ADD)
.to_array();
const EPSILON: f32 = 0.1;
let highest_corner =
Vec3::new(interpreter_out[0], interpreter_out[1], interpreter_out[2]) + EPSILON;
let lowest_corner =
Vec3::new(interpreter_out[3], interpreter_out[4], interpreter_out[5]) - EPSILON;
(lowest_corner, highest_corner)
}
pub fn compile_to_gpu(&self) -> GPUTape {
let mut lifetimes = Vec::<(u32, u32)>::with_capacity(self.last_output as usize);
@@ -473,7 +566,7 @@ impl SSATape {
};
let void = b.type_void();
let float = b.type_float(32);
let float = b.type_float(32, None);
let bool = b.type_bool();
let choice = b.type_int(32, 0);
let vec2 = b.type_vector(float, 2);