allow non-pointers

This commit is contained in:
2026-10-12 23:13:49 +01:00
parent b7f83169e2
commit 23e3630491
18 changed files with 577 additions and 488 deletions
Generated
+1 -1
View File
@@ -3113,7 +3113,7 @@ dependencies = [
[[package]] [[package]]
name = "tape-load" name = "tape-load"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"bevy_reflect", "bevy_reflect",
"foldhash 0.1.5", "foldhash 0.1.5",
+1 -1
View File
@@ -16,7 +16,7 @@ where
//warn!("WAITING FOR HOST BUFFER FREE"); //warn!("WAITING FOR HOST BUFFER FREE");
thread::yield_now(); thread::yield_now();
writer = device_local.write(); writer = device_local.write();
}, }
_ => break 'writerloop, _ => break 'writerloop,
} }
} }
+18 -18
View File
@@ -15,29 +15,29 @@ fn sized_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32) {
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub(crate) struct PreviousDebug { pub(crate) struct PreviousDebug {
pub(crate) bounding_boxes: bool, pub(crate) bounding_boxes: bool,
pub(crate) brute_force: bool, pub(crate) brute_force: bool,
pub(crate) show_normals: bool, pub(crate) show_normals: bool,
pub(crate) show_depth: bool, pub(crate) show_depth: bool,
pub(crate) show_position: bool, pub(crate) show_position: bool,
pub(crate) show_albedo: bool, pub(crate) show_albedo: bool,
pub(crate) show_material1: bool, pub(crate) show_material1: bool,
pub(crate) show_material2: bool, pub(crate) show_material2: bool,
pub(crate) show_material3: bool, pub(crate) show_material3: bool,
pub(crate) show_all: bool, pub(crate) show_all: bool,
pub(crate) disable_ao: bool, pub(crate) disable_ao: bool,
pub(crate) use_linear_ao: bool, pub(crate) use_linear_ao: bool,
pub(crate) use_spatial_textures: bool, pub(crate) use_spatial_textures: bool,
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct GState { pub(crate) struct GState {
pub(crate) cursor_sensitivity: f32, pub(crate) cursor_sensitivity: f32,
pub(crate) move_speed: f32, pub(crate) move_speed: f32,
pub(crate) meshes: Vec<Mesh>, pub(crate) meshes: Vec<Mesh>,
pub(crate) lights: Vec<Light>, pub(crate) lights: Vec<Light>,
pub(crate) csg: Vec<Arc<RwLock<CSG>>>, pub(crate) csg: Vec<Arc<RwLock<CSG>>>,
pub(crate) new_csgs_needed: u8, pub(crate) new_csgs_needed: u8,
@@ -47,18 +47,18 @@ pub(crate) struct GState {
pub(crate) debug: PreviousDebug, pub(crate) debug: PreviousDebug,
pub(crate) recreate_pipelines: bool, pub(crate) recreate_pipelines: bool,
pub(crate) reset_time: bool, pub(crate) reset_time: bool,
} }
impl Default for GState { impl Default for GState {
fn default() -> Self { fn default() -> Self {
Self { Self {
cursor_sensitivity: 1.0, cursor_sensitivity: 1.0,
move_speed: 1.0, move_speed: 1.0,
meshes: vec![], meshes: vec![],
lights: vec![], lights: vec![],
csg: vec![], csg: vec![],
new_csgs_needed: 1, new_csgs_needed: 1,
@@ -68,7 +68,7 @@ impl Default for GState {
debug: Default::default(), debug: Default::default(),
recreate_pipelines: false, recreate_pipelines: false,
reset_time: false, reset_time: false,
} }
} }
} }
+63 -63
View File
@@ -180,18 +180,18 @@ struct Keys {
struct CState { struct CState {
position: Vec3, position: Vec3,
forward: Vec3, forward: Vec3,
looking: bool, looking: bool,
keys: Keys, keys: Keys,
} }
impl Default for CState { impl Default for CState {
fn default() -> Self { fn default() -> Self {
CState { CState {
position: vec3(0., 0., 3.), position: vec3(0., 0., 3.),
forward: vec3(0., 0., 0.), forward: vec3(0., 0., 0.),
looking: false, looking: false,
keys: Keys { keys: Keys {
w: false, w: false,
s: false, s: false,
a: false, a: false,
@@ -240,22 +240,22 @@ struct App {
} }
struct RenderContext { struct RenderContext {
window: Arc<Window>, window: Arc<Window>,
swapchain: Arc<Swapchain>, swapchain: Arc<Swapchain>,
framebuffers: Vec<Arc<ImageView>>, framebuffers: Vec<Arc<ImageView>>,
camera_buffers: Vec<Subbuffer<enable_gen_cs::Camera>>, camera_buffers: Vec<Subbuffer<enable_gen_cs::Camera>>,
lights_buffers: Vec<Subbuffer<enable_gen_cs::Lights>>, lights_buffers: Vec<Subbuffer<enable_gen_cs::Lights>>,
shader_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>, shader_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
rt_pipeline: Arc<RayTracingPipeline>, rt_pipeline: Arc<RayTracingPipeline>,
rt_shader_binding_table: ShaderBindingTable, rt_shader_binding_table: ShaderBindingTable,
scene: Vec<Scene>, scene: Vec<Scene>,
viewport: Viewport, viewport: Viewport,
recreate_swapchain: bool, recreate_swapchain: bool,
recreate_pipelines: bool, recreate_pipelines: bool,
previous_frame_end: Vec<Option<FenceSignalFuture<Box<dyn GpuFuture>>>>, previous_frame_end: Vec<Option<FenceSignalFuture<Box<dyn GpuFuture>>>>,
time_query_pool: Arc<QueryPool>, time_query_pool: Arc<QueryPool>,
gui: Gui, gui: Gui,
render_start: Instant, render_start: Instant,
} }
fn app_version() -> Version { fn app_version() -> Version {
@@ -769,7 +769,7 @@ impl App {
info!("event: {:?}", event); info!("event: {:?}", event);
watcher_glsl_changed.store(true, std::sync::atomic::Ordering::Relaxed); watcher_glsl_changed.store(true, std::sync::atomic::Ordering::Relaxed);
} }
}, }
Err(e) => error!("watch error: {:?}", e), Err(e) => error!("watch error: {:?}", e),
}, },
) )
@@ -988,8 +988,8 @@ impl ApplicationHandler for App {
let shader_modules = Arc::new(RwLock::new(shader_modules)); let shader_modules = Arc::new(RwLock::new(shader_modules));
let viewport = Viewport { let viewport = Viewport {
offset: [0.0, window_size.height as f32], offset: [0.0, window_size.height as f32],
extent: [window_size.width as f32, -(window_size.height as f32)], extent: [window_size.width as f32, -(window_size.height as f32)],
depth_range: 0.0..=1.0, depth_range: 0.0..=1.0,
}; };
@@ -1058,8 +1058,8 @@ impl ApplicationHandler for App {
images[0].format(), images[0].format(),
GuiConfig { GuiConfig {
allow_srgb_render_target: true, allow_srgb_render_target: true,
is_overlay: true, is_overlay: true,
samples: SampleCount::Sample1, samples: SampleCount::Sample1,
}, },
); );
@@ -1122,13 +1122,13 @@ impl ApplicationHandler for App {
match &event { match &event {
WindowEvent::CloseRequested => { WindowEvent::CloseRequested => {
event_loop.exit(); event_loop.exit();
}, }
WindowEvent::Resized(_) => { WindowEvent::Resized(_) => {
rcx.recreate_swapchain = true; rcx.recreate_swapchain = true;
}, }
WindowEvent::ScaleFactorChanged { .. } => { WindowEvent::ScaleFactorChanged { .. } => {
rcx.recreate_swapchain = true; rcx.recreate_swapchain = true;
}, }
WindowEvent::DroppedFile(path) => { WindowEvent::DroppedFile(path) => {
if let Ok(file) = std::fs::File::open(path) { if let Ok(file) = std::fs::File::open(path) {
if let Ok(mut mesh) = load_obj( if let Ok(mut mesh) = load_obj(
@@ -1147,7 +1147,7 @@ impl ApplicationHandler for App {
} else { } else {
error!("Could not open path {}", path.display()); error!("Could not open path {}", path.display());
} }
}, }
WindowEvent::MouseInput { WindowEvent::MouseInput {
device_id: d, device_id: d,
state: s, state: s,
@@ -1158,7 +1158,7 @@ impl ApplicationHandler for App {
if b == &MouseButton::Right { if b == &MouseButton::Right {
self.cstate.looking = s == &ElementState::Pressed; self.cstate.looking = s == &ElementState::Pressed;
} }
}, }
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
device_id: _, device_id: _,
event: input, event: input,
@@ -1166,19 +1166,19 @@ impl ApplicationHandler for App {
} => match input.physical_key { } => match input.physical_key {
PhysicalKey::Code(KeyCode::KeyW) => { PhysicalKey::Code(KeyCode::KeyW) => {
self.cstate.keys.w = input.state == ElementState::Pressed; self.cstate.keys.w = input.state == ElementState::Pressed;
}, }
PhysicalKey::Code(KeyCode::KeyS) => { PhysicalKey::Code(KeyCode::KeyS) => {
self.cstate.keys.s = input.state == ElementState::Pressed; self.cstate.keys.s = input.state == ElementState::Pressed;
}, }
PhysicalKey::Code(KeyCode::KeyA) => { PhysicalKey::Code(KeyCode::KeyA) => {
self.cstate.keys.a = input.state == ElementState::Pressed; self.cstate.keys.a = input.state == ElementState::Pressed;
}, }
PhysicalKey::Code(KeyCode::KeyD) => { PhysicalKey::Code(KeyCode::KeyD) => {
self.cstate.keys.d = input.state == ElementState::Pressed; self.cstate.keys.d = input.state == ElementState::Pressed;
}, }
PhysicalKey::Code(KeyCode::ShiftLeft) => { PhysicalKey::Code(KeyCode::ShiftLeft) => {
self.cstate.looking = input.state == ElementState::Pressed; self.cstate.looking = input.state == ElementState::Pressed;
}, }
PhysicalKey::Code(KeyCode::Space) => { PhysicalKey::Code(KeyCode::Space) => {
if input.state == ElementState::Pressed { if input.state == ElementState::Pressed {
self.thread_work_creation self.thread_work_creation
@@ -1198,18 +1198,18 @@ impl ApplicationHandler for App {
)) ))
.unwrap(); .unwrap();
} }
}, }
PhysicalKey::Code(KeyCode::KeyG) => { PhysicalKey::Code(KeyCode::KeyG) => {
if input.state == ElementState::Pressed { if input.state == ElementState::Pressed {
self.draw_gui = !self.draw_gui; self.draw_gui = !self.draw_gui;
} }
}, }
_ => {}, _ => {}
}, },
WindowEvent::RedrawRequested => { WindowEvent::RedrawRequested => {
self.redraw(rcx); self.redraw(rcx);
}, }
_ => {}, _ => {}
} }
} }
@@ -1276,10 +1276,10 @@ impl App {
* Mat4::from_translation(Vec3::ZERO - self.cstate.position); * Mat4::from_translation(Vec3::ZERO - self.cstate.position);
let uniform_data = enable_gen_cs::Camera { let uniform_data = enable_gen_cs::Camera {
proj_view: (proj * view).to_cols_array_2d(), proj_view: (proj * view).to_cols_array_2d(),
inv_proj_view: (proj * view).inverse().to_cols_array_2d(), inv_proj_view: (proj * view).inverse().to_cols_array_2d(),
inv_proj: (proj).inverse().to_cols_array_2d(), inv_proj: (proj).inverse().to_cols_array_2d(),
inv_view: (view).inverse().to_cols_array_2d(), inv_view: (view).inverse().to_cols_array_2d(),
campos_and_time: [ campos_and_time: [
self.cstate.position.x, self.cstate.position.x,
self.cstate.position.y, self.cstate.position.y,
@@ -1568,10 +1568,10 @@ impl App {
self.gstate.csg[index as usize] = csg; self.gstate.csg[index as usize] = csg;
} }
self.recreate_pipelines = true; self.recreate_pipelines = true;
}, }
WorkComplete::GetPushConstants(..) => {}, WorkComplete::GetPushConstants(..) => {}
WorkComplete::RecompilePipelines(..) => {}, WorkComplete::RecompilePipelines(..) => {}
WorkComplete::RecompileShaders(..) => {}, WorkComplete::RecompileShaders(..) => {}
} }
} }
@@ -1714,10 +1714,10 @@ impl App {
index, index,
)) ))
.unwrap(); .unwrap();
}, }
WorkComplete::RecompilePipelines(_index) => { WorkComplete::RecompilePipelines(_index) => {
csg_pipelines_left -= 1; csg_pipelines_left -= 1;
}, }
other => work_for_later.push(other), other => work_for_later.push(other),
} }
} }
@@ -1736,7 +1736,7 @@ impl App {
match work { match work {
WorkComplete::RecompilePipelines(_index) => { WorkComplete::RecompilePipelines(_index) => {
csg_pipelines_left -= 1; csg_pipelines_left -= 1;
}, }
other => work_for_later.push(other), other => work_for_later.push(other),
} }
} }
@@ -1816,7 +1816,7 @@ impl App {
} else { } else {
work_for_later.push(work); work_for_later.push(work);
} }
}, }
other => work_for_later.push(other), other => work_for_later.push(other),
} }
} }
@@ -2042,7 +2042,7 @@ impl App {
Err(VulkanError::OutOfDate) => { Err(VulkanError::OutOfDate) => {
rcx.recreate_swapchain = true; rcx.recreate_swapchain = true;
return; return;
}, }
Err(e) => panic!("Failed to acquire next image: {e}"), Err(e) => panic!("Failed to acquire next image: {e}"),
}; };
@@ -2097,7 +2097,7 @@ impl App {
write.lowest_corner = lowest_corner; write.lowest_corner = lowest_corner;
write.blas = None; write.blas = None;
push_constants_left -= 1; push_constants_left -= 1;
}, }
other => work_for_later.push(other), other => work_for_later.push(other),
} }
} }
@@ -2197,20 +2197,20 @@ impl App {
match future.map_err(Validated::unwrap) { match future.map_err(Validated::unwrap) {
Ok(future) => { Ok(future) => {
rcx.previous_frame_end[image_index] = Some(future); rcx.previous_frame_end[image_index] = Some(future);
}, }
Err(VulkanError::OutOfDate) => { Err(VulkanError::OutOfDate) => {
rcx.recreate_swapchain = true; rcx.recreate_swapchain = true;
rcx.previous_frame_end[image_index] = None; rcx.previous_frame_end[image_index] = None;
}, }
Err(e) => { Err(e) => {
error!("Failed to flush future: {e:?}"); error!("Failed to flush future: {e:?}");
rcx.previous_frame_end[image_index] = None; rcx.previous_frame_end[image_index] = None;
}, }
} }
for work in self.thread_work_completion.try_iter() { for work in self.thread_work_completion.try_iter() {
match work { match work {
WorkComplete::GetPushConstants(..) => {}, WorkComplete::GetPushConstants(..) => {}
other => work_for_later.push(other), other => work_for_later.push(other),
} }
} }
@@ -2231,7 +2231,7 @@ impl App {
warn!("WAITING FOR HOST BUFFER FREE"); warn!("WAITING FOR HOST BUFFER FREE");
thread::yield_now(); thread::yield_now();
reader = csg.aabb_buffer[image_index].read(); reader = csg.aabb_buffer[image_index].read();
}, }
_ => break 'writerloop, _ => break 'writerloop,
} }
} }
@@ -2398,14 +2398,14 @@ fn pipeline_recompile(
RayTracingShaderGroupCreateInfo::General { general_shader: 1 }, RayTracingShaderGroupCreateInfo::General { general_shader: 1 },
RayTracingShaderGroupCreateInfo::TrianglesHit { RayTracingShaderGroupCreateInfo::TrianglesHit {
closest_hit_shader: Some(2), closest_hit_shader: Some(2),
any_hit_shader: None, any_hit_shader: None,
}, },
]; ];
for i in 0..csgs.len() { for i in 0..csgs.len() {
groups.push(RayTracingShaderGroupCreateInfo::ProceduralHit { groups.push(RayTracingShaderGroupCreateInfo::ProceduralHit {
closest_hit_shader: Some((3 + (i * 2)) as u32), closest_hit_shader: Some((3 + (i * 2)) as u32),
any_hit_shader: None, any_hit_shader: None,
intersection_shader: (4 + (i * 2)) as u32, intersection_shader: (4 + (i * 2)) as u32,
}) })
} }
+46 -46
View File
@@ -32,7 +32,7 @@ pub(crate) struct OVertex {
#[format(R32G32B32A32_SFLOAT)] #[format(R32G32B32A32_SFLOAT)]
position: [f32; 4], position: [f32; 4],
#[format(R32G32B32A32_SFLOAT)] #[format(R32G32B32A32_SFLOAT)]
normal: [f32; 4], normal: [f32; 4],
} }
#[derive(Debug, Default, PartialEq, Eq)] #[derive(Debug, Default, PartialEq, Eq)]
@@ -44,73 +44,73 @@ pub(crate) enum State {
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Position { pub(crate) struct Position {
pub(crate) pos: Vec3, pub(crate) pos: Vec3,
pub(crate) rot: Vec3, pub(crate) rot: Vec3,
pub(crate) scale: Vec3, pub(crate) scale: Vec3,
pub(crate) transform_offset: DeviceSize, pub(crate) transform_offset: DeviceSize,
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Material { pub(crate) struct Material {
pub(crate) colour: Vec3, pub(crate) colour: Vec3,
pub(crate) roughness: f32, pub(crate) roughness: f32,
pub(crate) metallic: f32, pub(crate) metallic: f32,
pub(crate) subsurface: f32, pub(crate) subsurface: f32,
pub(crate) specular: f32, pub(crate) specular: f32,
pub(crate) specular_tint: f32, pub(crate) specular_tint: f32,
pub(crate) sheen: f32, pub(crate) sheen: f32,
pub(crate) sheen_tint: f32, pub(crate) sheen_tint: f32,
pub(crate) clear_coat_gloss: f32, pub(crate) clear_coat_gloss: f32,
pub(crate) clear_coat: f32, pub(crate) clear_coat: f32,
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Mesh { pub(crate) struct Mesh {
pub(crate) name: String, pub(crate) name: String,
pub(crate) position: Position, pub(crate) position: Position,
pub(crate) material: Material, pub(crate) material: Material,
pub(crate) state: State, pub(crate) state: State,
pub(crate) blas: Option<Arc<AccelerationStructure>>, pub(crate) blas: Option<Arc<AccelerationStructure>>,
pub(crate) vert_offset: DeviceSize, pub(crate) vert_offset: DeviceSize,
pub(crate) vert_len: DeviceSize, pub(crate) vert_len: DeviceSize,
pub(crate) index_offset: DeviceSize, pub(crate) index_offset: DeviceSize,
pub(crate) index_len: DeviceSize, pub(crate) index_len: DeviceSize,
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct CSG { pub(crate) struct CSG {
pub(crate) name: String, pub(crate) name: String,
pub(crate) position: Position, pub(crate) position: Position,
pub(crate) material: Material, pub(crate) material: Material,
pub(crate) state: State, pub(crate) state: State,
pub(crate) blas: Option<Arc<AccelerationStructure>>, pub(crate) blas: Option<Arc<AccelerationStructure>>,
pub(crate) parts: SSATape, pub(crate) parts: SSATape,
pub(crate) _seed: u64, pub(crate) _seed: u64,
pub(crate) subdivision: u32, pub(crate) subdivision: u32,
pub(crate) dimensions: Vec3, pub(crate) dimensions: Vec3,
pub(crate) lowest_corner: Vec3, pub(crate) lowest_corner: Vec3,
pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>, pub(crate) replacement_modules: Arc<RwLock<HashMap<String, Arc<ShaderModule>>>>,
pub(crate) fuzz_pipeline: Arc<ComputePipeline>, pub(crate) fuzz_pipeline: Arc<ComputePipeline>,
pub(crate) enable_gen_pipeline: Arc<ComputePipeline>, pub(crate) enable_gen_pipeline: Arc<ComputePipeline>,
pub(crate) spatial_texture_pipeline: Arc<ComputePipeline>, pub(crate) spatial_texture_pipeline: Arc<ComputePipeline>,
pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>, pub(crate) aabb_buffer: Vec<Subbuffer<[u8]>>,
pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>, pub(crate) enable_gen_descriptor_set: Vec<Arc<DescriptorSet>>,
pub(crate) spatial_texture: Vec<Arc<ImageView>>, pub(crate) spatial_texture: Vec<Arc<ImageView>>,
pub(crate) spatial_texture_descriptor_set: Vec<Arc<DescriptorSet>>, pub(crate) spatial_texture_descriptor_set: Vec<Arc<DescriptorSet>>,
} }
impl Default for Position { impl Default for Position {
fn default() -> Self { fn default() -> Self {
Self { Self {
pos: Vec3::ZERO, pos: Vec3::ZERO,
rot: Vec3::ZERO, rot: Vec3::ZERO,
scale: Vec3::ONE, scale: Vec3::ONE,
transform_offset: 0, transform_offset: 0,
} }
} }
@@ -119,16 +119,16 @@ impl Default for Position {
impl Default for Material { impl Default for Material {
fn default() -> Self { fn default() -> Self {
Self { Self {
colour: Vec3::ONE, colour: Vec3::ONE,
roughness: 1.0, roughness: 1.0,
metallic: 0.67, metallic: 0.67,
specular: 0.73, specular: 0.73,
specular_tint: 0., specular_tint: 0.,
sheen_tint: 0., sheen_tint: 0.,
sheen: 0.58, sheen: 0.58,
clear_coat_gloss: 0.63, clear_coat_gloss: 0.63,
subsurface: 0., subsurface: 0.,
clear_coat: 0.85, clear_coat: 0.85,
} }
} }
} }
@@ -174,7 +174,7 @@ pub(crate) fn load_obj(
} else { } else {
let mut vertex = OVertex { let mut vertex = OVertex {
position: [0.; 4], position: [0.; 4],
normal: [0.; 4], normal: [0.; 4],
}; };
vertex.position[0..3].copy_from_slice(&object.position[mapping.0 as usize]); vertex.position[0..3].copy_from_slice(&object.position[mapping.0 as usize]);
vertex.normal[0..3].copy_from_slice(&object.normal[mapping.1 as usize]); vertex.normal[0..3].copy_from_slice(&object.normal[mapping.1 as usize]);
@@ -222,7 +222,7 @@ pub(crate) fn load_obj(
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Light { pub(crate) struct Light {
pub(crate) pos: Vec3, pub(crate) pos: Vec3,
pub(crate) colour: Vec3, pub(crate) colour: Vec3,
} }
@@ -230,7 +230,7 @@ impl Light {
pub(crate) fn new(pos: [f32; 3], colour: [f32; 3], intensity: f32) -> Light { pub(crate) fn new(pos: [f32; 3], colour: [f32; 3], intensity: f32) -> Light {
let c: Vec3 = colour.into(); let c: Vec3 = colour.into();
Light { Light {
pos: pos.into(), pos: pos.into(),
colour: c * intensity, colour: c * intensity,
} }
} }
@@ -239,7 +239,7 @@ impl Light {
impl Default for Light { impl Default for Light {
fn default() -> Self { fn default() -> Self {
Self { Self {
pos: Vec3::ZERO, pos: Vec3::ZERO,
colour: Vec3::ONE, colour: Vec3::ONE,
} }
} }
+4 -4
View File
@@ -34,8 +34,8 @@ pub struct Scene {
// The bottom-level acceleration structure is required to be kept alive // The bottom-level acceleration structure is required to be kept alive
// as we reference it in the top-level acceleration structure. // as we reference it in the top-level acceleration structure.
pub _mesh_blases: Vec<(Arc<AccelerationStructure>, [[f32; 4]; 3])>, pub _mesh_blases: Vec<(Arc<AccelerationStructure>, [[f32; 4]; 3])>,
pub _csg_blases: Vec<(Arc<AccelerationStructure>, [[f32; 4]; 3])>, pub _csg_blases: Vec<(Arc<AccelerationStructure>, [[f32; 4]; 3])>,
pub tlas: Option<Arc<AccelerationStructure>>, pub tlas: Option<Arc<AccelerationStructure>>,
} }
impl Drop for Scene { impl Drop for Scene {
@@ -136,8 +136,8 @@ impl Scene {
Scene { Scene {
_mesh_blases: mesh_blases, _mesh_blases: mesh_blases,
_csg_blases: csg_blases, _csg_blases: csg_blases,
tlas: Some(tlas), tlas: Some(tlas),
} }
} }
} }
+21 -21
View File
@@ -210,7 +210,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
"CSG compile took {} milliseconds", "CSG compile took {} milliseconds",
(csg_end - csg_start).as_secs_f64() * 1000.0 (csg_end - csg_start).as_secs_f64() * 1000.0
); );
}, }
WorkItem::GetPushConstants(csg, time, index) => { WorkItem::GetPushConstants(csg, time, index) => {
let csg = csg.read().unwrap(); let csg = csg.read().unwrap();
@@ -218,7 +218,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
send.send(WorkComplete::GetPushConstants(dim, lowest, index)) send.send(WorkComplete::GetPushConstants(dim, lowest, index))
.unwrap(); .unwrap();
}, }
WorkItem::RecompileShaders(csg, device, replacement_modules, index) => { WorkItem::RecompileShaders(csg, device, replacement_modules, index) => {
let csg_start = Instant::now(); let csg_start = Instant::now();
let csg = csg.read().unwrap(); let csg = csg.read().unwrap();
@@ -240,7 +240,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
index, index,
(csg_end - csg_start).as_secs_f64() * 1000.0 (csg_end - csg_start).as_secs_f64() * 1000.0
); );
}, }
WorkItem::RecompilePipelines(csg, device, cache, debug, index) => { WorkItem::RecompilePipelines(csg, device, cache, debug, index) => {
let csg_start = Instant::now(); let csg_start = Instant::now();
let mut csg = csg.write().unwrap(); let mut csg = csg.write().unwrap();
@@ -263,7 +263,7 @@ pub fn thread_loop(recv: mpmc::Receiver<WorkItem>, send: mpsc::SyncSender<WorkCo
index, index,
(csg_end - csg_start).as_secs_f64() * 1000.0 (csg_end - csg_start).as_secs_f64() * 1000.0
); );
}, }
} }
} }
} }
@@ -366,14 +366,14 @@ fn create_csg(seed: u64) -> SSATape {
let pos = tape.push_instruction( let pos = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAPosition, opcode: SSAOpcode::SSAPosition,
size: 1, size: 1,
}, },
vec![], vec![],
); );
let offset = tape.push_instruction( let offset = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAAdd, opcode: SSAOpcode::SSAAdd,
size: 3, size: 3,
}, },
vec![ vec![
pos[0], pos[0],
@@ -387,14 +387,14 @@ fn create_csg(seed: u64) -> SSATape {
let sin = tape.push_instruction( let sin = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSASin, opcode: SSAOpcode::SSASin,
size: 1, size: 1,
}, },
vec![pos[3]], vec![pos[3]],
); );
let offset = tape.push_instruction( let offset = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAAdd, opcode: SSAOpcode::SSAAdd,
size: 3, size: 3,
}, },
vec![ vec![
offset[0], offset[0],
@@ -408,7 +408,7 @@ fn create_csg(seed: u64) -> SSATape {
let sphere = tape.push_instruction( let sphere = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSASDFSphere, opcode: SSAOpcode::SSASDFSphere,
size: 1, size: 1,
}, },
vec![ vec![
offset[0], offset[0],
@@ -420,7 +420,7 @@ fn create_csg(seed: u64) -> SSATape {
let torus = tape.push_instruction( let torus = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSASDFTorus, opcode: SSAOpcode::SSASDFTorus,
size: 1, size: 1,
}, },
vec![ vec![
pos[0], pos[0],
@@ -433,21 +433,21 @@ fn create_csg(seed: u64) -> SSATape {
let min = tape.push_instruction( let min = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMin, opcode: SSAOpcode::SSAMin,
size: 1, size: 1,
}, },
vec![sphere[0], torus[0]], vec![sphere[0], torus[0]],
); );
let scaled_time = tape.push_instruction( let scaled_time = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMul, opcode: SSAOpcode::SSAMul,
size: 1, size: 1,
}, },
vec![pos[3], SSAInput::Constant(0.2)], vec![pos[3], SSAInput::Constant(0.2)],
); );
let moving_pos = tape.push_instruction( let moving_pos = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAAdd, opcode: SSAOpcode::SSAAdd,
size: 3, size: 3,
}, },
vec![ vec![
pos[0], pos[0],
@@ -461,7 +461,7 @@ fn create_csg(seed: u64) -> SSATape {
let pos_times_20 = tape.push_instruction( let pos_times_20 = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMul, opcode: SSAOpcode::SSAMul,
size: 3, size: 3,
}, },
vec![ vec![
moving_pos[0], moving_pos[0],
@@ -475,14 +475,14 @@ fn create_csg(seed: u64) -> SSATape {
let sine_of_the_times = tape.push_instruction( let sine_of_the_times = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSASin, opcode: SSAOpcode::SSASin,
size: 3, size: 3,
}, },
pos_times_20, pos_times_20,
); );
let sine_of_the_times = tape.push_instruction( let sine_of_the_times = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMul, opcode: SSAOpcode::SSAMul,
size: 3, size: 3,
}, },
vec![ vec![
sine_of_the_times[0], sine_of_the_times[0],
@@ -496,28 +496,28 @@ fn create_csg(seed: u64) -> SSATape {
let multiply_out_1 = tape.push_instruction( let multiply_out_1 = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMul, opcode: SSAOpcode::SSAMul,
size: 1, size: 1,
}, },
vec![sine_of_the_times[0], sine_of_the_times[1]], vec![sine_of_the_times[0], sine_of_the_times[1]],
); );
let multiply_out_2 = tape.push_instruction( let multiply_out_2 = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAMul, opcode: SSAOpcode::SSAMul,
size: 1, size: 1,
}, },
vec![multiply_out_1[0], sine_of_the_times[2]], vec![multiply_out_1[0], sine_of_the_times[2]],
); );
let displacement = tape.push_instruction( let displacement = tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAAdd, opcode: SSAOpcode::SSAAdd,
size: 1, size: 1,
}, },
vec![min[0], multiply_out_2[0]], vec![min[0], multiply_out_2[0]],
); );
tape.push_instruction( tape.push_instruction(
SSAOpcodeSized { SSAOpcodeSized {
opcode: SSAOpcode::SSAReturn, opcode: SSAOpcode::SSAReturn,
size: 1, size: 1,
}, },
displacement, displacement,
); );
@@ -535,7 +535,7 @@ fn sdf_specialize_module(
module: Module, module: Module,
name: &str, name: &str,
) -> Arc<ShaderModule> { ) -> Arc<ShaderModule> {
let new_module = parts.compile_to_spirv(Some(module)); let new_module = parts.compile_to_spirv(Some(module), true);
let assembled_module = new_module.assemble(); let assembled_module = new_module.assemble();
let module_as_bytes = assembled_module let module_as_bytes = assembled_module
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "tape-load" name = "tape-load"
version = "0.1.0" version = "0.2.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
+47 -47
View File
@@ -5,187 +5,187 @@ pub enum InstructionSet {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the input. Useful for copying registers. /// Returns the input. Useful for copying registers.
OPCopy = (1), OPCopy = (1),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Adds a vector to a vector component-wise. /// Adds a vector to a vector component-wise.
OPAdd = (2), OPAdd = (2),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Subtracts a vector from a vector component-wise. /// Subtracts a vector from a vector component-wise.
OPSub = (3), OPSub = (3),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Multiplies a vector and a vector component-wise. /// Multiplies a vector and a vector component-wise.
OPMul = (4), OPMul = (4),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Divides a vector by a vector component-wise. /// Divides a vector by a vector component-wise.
OPDiv = (5), OPDiv = (5),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates a vector Atan2 a vector component-wise. /// Calculates a vector Atan2 a vector component-wise.
OPAtan2 = (6), OPAtan2 = (6),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates the minimum of a vector and a vector component-wise. /// Calculates the minimum of a vector and a vector component-wise.
OPMin = (7), OPMin = (7),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates the maximum of a vector and a vector component-wise. /// Calculates the maximum of a vector and a vector component-wise.
OPMax = (8), OPMax = (8),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Threeway comparison operator. /// Threeway comparison operator.
OPCompare = (9), OPCompare = (9),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates a vector modulo a vector component-wise. /// Calculates a vector modulo a vector component-wise.
OPMod = (10), OPMod = (10),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// If both arguments are non-zero, returns the right-hand argument. /// If both arguments are non-zero, returns the right-hand argument.
/// Otherwise, returns zero. /// Otherwise, returns zero.
OPAnd = (11), OPAnd = (11),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// If the left-hand argument is non-zero, it is returned. Otherwise, the /// If the left-hand argument is non-zero, it is returned. Otherwise, the
/// right-hand argument is returned. /// right-hand argument is returned.
OPOr = (12), OPOr = (12),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the negation of all components of a vector. /// Returns the negation of all components of a vector.
OPNegate = (13), OPNegate = (13),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the absolute value of all components of a vector. /// Returns the absolute value of all components of a vector.
OPAbs = (14), OPAbs = (14),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns 1 over all components of a vector. /// Returns 1 over all components of a vector.
OPRecip = (15), OPRecip = (15),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the square root of all components of a vector. /// Returns the square root of all components of a vector.
OPSqrt = (16), OPSqrt = (16),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the square of all components of a vector. /// Returns the square of all components of a vector.
OPSquare = (17), OPSquare = (17),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the floor of all components of a vector. /// Returns the floor of all components of a vector.
OPFloor = (18), OPFloor = (18),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the ceiling of all components of a vector. /// Returns the ceiling of all components of a vector.
OPCeil = (19), OPCeil = (19),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns all components of a vector rounded to the nearest integer, 0.5 /// Returns all components of a vector rounded to the nearest integer, 0.5
/// away from zero. /// away from zero.
OPRound = (20), OPRound = (20),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the sine of all components of a vector. /// Returns the sine of all components of a vector.
OPSin = (21), OPSin = (21),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the cosine of all components of a vector. /// Returns the cosine of all components of a vector.
OPCos = (22), OPCos = (22),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the tangent of all components of a vector. /// Returns the tangent of all components of a vector.
OPTan = (23), OPTan = (23),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the arc sine of all components of a vector. /// Returns the arc sine of all components of a vector.
OPAsin = (24), OPAsin = (24),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the arc cosine of all components of a vector. /// Returns the arc cosine of all components of a vector.
OPAcos = (25), OPAcos = (25),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the arc tangent of all components of a vector. /// Returns the arc tangent of all components of a vector.
OPAtan = (26), OPAtan = (26),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns e raised to all components of a vector. /// Returns e raised to all components of a vector.
OPExp = (27), OPExp = (27),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the natural logarithm of all components of a vector. /// Returns the natural logarithm of all components of a vector.
OPLog = (28), OPLog = (28),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// The output is 1 if the argument is 0, and 0 otherwise. /// The output is 1 if the argument is 0, and 0 otherwise.
OPNot = (29), OPNot = (29),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the fractional part of all components of a vector. /// Returns the fractional part of all components of a vector.
OPFract = (30), OPFract = (30),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the cube of all components of a vector. /// Returns the cube of all components of a vector.
OPCube = (31), OPCube = (31),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the smooth minimum between a vector and a vector, varied by a /// Returns the smooth minimum between a vector and a vector, varied by a
/// vector. /// vector.
OPSmoothMin = (32), OPSmoothMin = (32),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the smooth maximum between a vector and a vector, varied by a /// Returns the smooth maximum between a vector and a vector, varied by a
/// vector. /// vector.
OPSmoothMax = (33), OPSmoothMax = (33),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Clamps a vector between a vector and a vector. /// Clamps a vector between a vector and a vector.
OPClamp = (34), OPClamp = (34),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Mixes between a vector and a vector, varied by a vector. /// Mixes between a vector and a vector, varied by a vector.
OPMix = (35), OPMix = (35),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates a vector multiplied by a vector, then adds a vector. /// Calculates a vector multiplied by a vector, then adds a vector.
OPFMA = (36), OPFMA = (36),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the length (magnitude) of a vector. /// Returns the length (magnitude) of a vector.
OPLength = (37), OPLength = (37),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the dot product of two vectors. /// Returns the dot product of two vectors.
OPDot = (38), OPDot = (38),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the length (magnitude) of the vector between two vectors. /// Returns the length (magnitude) of the vector between two vectors.
OPDistance = (39), OPDistance = (39),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// No operation. /// No operation.
OPNop = ((3 * 64) + 63), OPNop = ((3 * 64) + 63),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Stops execution of the tape and returns a single value. /// Stops execution of the tape and returns a single value.
OPReturn = ((2 * 64) + 63), OPReturn = ((2 * 64) + 63),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the current position being sampled. /// Returns the current position being sampled.
OPPosition = ((1 * 64) + 63), OPPosition = ((1 * 64) + 63),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
#[allow(clippy::erasing_op)] #[allow(clippy::erasing_op)]
/// Calculates the minimum of two Vec1s, and also carries over the relevant /// Calculates the minimum of two Vec1s, and also carries over the relevant
/// material metadata. /// material metadata.
OPMinMaterial = ((0 * 64) + 63), OPMinMaterial = ((0 * 64) + 63),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Calculates the maximum of two Vec1s, and also carries over the relevant /// Calculates the maximum of two Vec1s, and also carries over the relevant
/// material metadata. /// material metadata.
OPMaxMaterial = ((3 * 64) + 62), OPMaxMaterial = ((3 * 64) + 62),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the smooth minimum between a Vec1 and a Vec1, varied by a Vec1, /// Returns the smooth minimum between a Vec1 and a Vec1, varied by a Vec1,
@@ -199,13 +199,13 @@ pub enum InstructionSet {
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the distance to a sphere. /// Returns the distance to a sphere.
OPSDFSphere = ((3 * 64) + 61), OPSDFSphere = ((3 * 64) + 61),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the distance to a box. /// Returns the distance to a box.
OPSDFBox = ((2 * 64) + 61), OPSDFBox = ((2 * 64) + 61),
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[allow(dead_code)] #[allow(dead_code)]
/// Returns the distance to a torus. /// Returns the distance to a torus.
OPSDFTorus = ((1 * 64) + 61), OPSDFTorus = ((1 * 64) + 61),
} }
+45 -45
View File
@@ -9,7 +9,7 @@ use crate::{
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct IntervalInterpreter<'csg> { pub struct IntervalInterpreter<'csg> {
value_map: Vec<Interval>, value_map: Vec<Interval>,
csg: &'csg SSATape, csg: &'csg SSATape,
} }
impl IntervalInterpreter<'_> { impl IntervalInterpreter<'_> {
@@ -80,36 +80,36 @@ impl<'csg> IntervalInterpreter<'csg> {
match instruction.opcode.opcode { match instruction.opcode.opcode {
SSAReturn => { SSAReturn => {
return self.load(instruction.inputs[0]); return self.load(instruction.inputs[0]);
}, }
SSAPosition => { SSAPosition => {
self.store(instruction.outputs[0], px); self.store(instruction.outputs[0], px);
self.store(instruction.outputs[1], py); self.store(instruction.outputs[1], py);
self.store(instruction.outputs[2], pz); self.store(instruction.outputs[2], pz);
self.store(instruction.outputs[3], time); self.store(instruction.outputs[3], time);
}, }
SSAAdd => { SSAAdd => {
self.param_two(instruction, |val_a, val_b| val_a + val_b); self.param_two(instruction, |val_a, val_b| val_a + val_b);
}, }
SSASub => { SSASub => {
self.param_two(instruction, |val_a, val_b| val_a - val_b); self.param_two(instruction, |val_a, val_b| val_a - val_b);
}, }
SSAMul => { SSAMul => {
self.param_two(instruction, |val_a, val_b| val_a * val_b); self.param_two(instruction, |val_a, val_b| val_a * val_b);
}, }
SSADiv => { SSADiv => {
self.param_two(instruction, |val_a, val_b| val_a / val_b); self.param_two(instruction, |val_a, val_b| val_a / val_b);
}, }
SSAMod => { SSAMod => {
self.param_two(instruction, |val_a, val_b| val_a % val_b); self.param_two(instruction, |val_a, val_b| val_a % val_b);
}, }
SSAAtan2 => self.param_two(instruction, |val_a, val_b| val_a.atan2(val_b)), SSAAtan2 => self.param_two(instruction, |val_a, val_b| val_a.atan2(val_b)),
SSAMin => { SSAMin => {
self.param_two(instruction, |val_a, val_b| val_a.min_choice(val_b).0); self.param_two(instruction, |val_a, val_b| val_a.min_choice(val_b).0);
}, }
SSAMinMaterial => todo!(), SSAMinMaterial => todo!(),
SSAMax => { SSAMax => {
self.param_two(instruction, |val_a, val_b| val_a.max_choice(val_b).0); self.param_two(instruction, |val_a, val_b| val_a.max_choice(val_b).0);
}, }
SSAMaxMaterial => todo!(), SSAMaxMaterial => todo!(),
SSADot => { SSADot => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
@@ -127,17 +127,17 @@ impl<'csg> IntervalInterpreter<'csg> {
(val_a[0] * val_b[0]) (val_a[0] * val_b[0])
+ (val_a[1] * val_b[1]) + (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2]) + (val_a[2] * val_b[2])
}, }
4 => { 4 => {
(val_a[0] * val_b[0]) (val_a[0] * val_b[0])
+ (val_a[1] * val_b[1]) + (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2]) + (val_a[2] * val_b[2])
+ (val_a[3] * val_b[3]) + (val_a[3] * val_b[3])
}, }
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSALength => { SSALength => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize])) .map(|i| self.load(instruction.inputs[i as usize]))
@@ -190,7 +190,7 @@ impl<'csg> IntervalInterpreter<'csg> {
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSADistance => { SSADistance => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize])) .map(|i| self.load(instruction.inputs[i as usize]))
@@ -251,85 +251,85 @@ impl<'csg> IntervalInterpreter<'csg> {
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSANegate => { SSANegate => {
self.param_one(instruction, |val_a| -val_a); self.param_one(instruction, |val_a| -val_a);
}, }
SSARound => { SSARound => {
self.param_one(instruction, |val_a| val_a.round()); self.param_one(instruction, |val_a| val_a.round());
}, }
SSAAbs => { SSAAbs => {
self.param_one(instruction, |val_a| val_a.abs()); self.param_one(instruction, |val_a| val_a.abs());
}, }
SSAFloor => { SSAFloor => {
self.param_one(instruction, |val_a| val_a.floor()); self.param_one(instruction, |val_a| val_a.floor());
}, }
SSACeil => { SSACeil => {
self.param_one(instruction, |val_a| val_a.ceil()); self.param_one(instruction, |val_a| val_a.ceil());
}, }
SSAFract => { SSAFract => {
self.param_one(instruction, |val_a| val_a.fract()); self.param_one(instruction, |val_a| val_a.fract());
}, }
SSASin => { SSASin => {
self.param_one(instruction, |val_a| val_a.sin()); self.param_one(instruction, |val_a| val_a.sin());
}, }
SSACos => { SSACos => {
self.param_one(instruction, |val_a| val_a.cos()); self.param_one(instruction, |val_a| val_a.cos());
}, }
SSATan => { SSATan => {
self.param_one(instruction, |val_a| val_a.tan()); self.param_one(instruction, |val_a| val_a.tan());
}, }
SSAAsin => { SSAAsin => {
self.param_one(instruction, |val_a| val_a.asin()); self.param_one(instruction, |val_a| val_a.asin());
}, }
SSAAcos => { SSAAcos => {
self.param_one(instruction, |val_a| val_a.acos()); self.param_one(instruction, |val_a| val_a.acos());
}, }
SSAAtan => { SSAAtan => {
self.param_one(instruction, |val_a| val_a.atan()); self.param_one(instruction, |val_a| val_a.atan());
}, }
SSAExp => { SSAExp => {
self.param_one(instruction, |val_a| val_a.exp()); self.param_one(instruction, |val_a| val_a.exp());
}, }
SSALog => { SSALog => {
self.param_one(instruction, |val_a| val_a.ln()); self.param_one(instruction, |val_a| val_a.ln());
}, }
SSASqrt => { SSASqrt => {
self.param_one(instruction, |val_a| val_a.sqrt()); self.param_one(instruction, |val_a| val_a.sqrt());
}, }
SSASquare => { SSASquare => {
self.param_one(instruction, |val_a| val_a.square()); self.param_one(instruction, |val_a| val_a.square());
}, }
SSACube => { SSACube => {
self.param_one(instruction, |val_a| val_a.cube()); self.param_one(instruction, |val_a| val_a.cube());
}, }
SSASmoothMin => { SSASmoothMin => {
self.param_three(instruction, |d1, d2, k| { self.param_three(instruction, |d1, d2, k| {
let h = (Interval::HALF + (Interval::HALF * (d2 - d1) / k)) let h = (Interval::HALF + (Interval::HALF * (d2 - d1) / k))
.clamp(Interval::ZERO, Interval::ONE); .clamp(Interval::ZERO, Interval::ONE);
((d2 * (Interval::ONE - h)) + (d1 * h)) - k * h * (Interval::ONE - h) ((d2 * (Interval::ONE - h)) + (d1 * h)) - k * h * (Interval::ONE - h)
}); });
}, }
SSASmoothMax => { SSASmoothMax => {
self.param_three(instruction, |d1, d2, k| { self.param_three(instruction, |d1, d2, k| {
let h = (Interval::HALF - (Interval::HALF * (d2 + d1) / k)) let h = (Interval::HALF - (Interval::HALF * (d2 + d1) / k))
.clamp(Interval::ZERO, Interval::ONE); .clamp(Interval::ZERO, Interval::ONE);
((d2 * (Interval::ONE - h)) + (-d1 * h)) + k * h * (Interval::ONE - h) ((d2 * (Interval::ONE - h)) + (-d1 * h)) + k * h * (Interval::ONE - h)
}); });
}, }
SSASmoothMinMaterial => todo!(), SSASmoothMinMaterial => todo!(),
SSASmoothMaxMaterial => todo!(), SSASmoothMaxMaterial => todo!(),
SSAClamp => { SSAClamp => {
self.param_three(instruction, |val_a, val_b, val_c| val_a.clamp(val_b, val_c)); self.param_three(instruction, |val_a, val_b, val_c| val_a.clamp(val_b, val_c));
}, }
SSAMix => { SSAMix => {
self.param_three(instruction, |val_a, val_b, val_c| { self.param_three(instruction, |val_a, val_b, val_c| {
(val_a * (Interval::ONE - val_c)) + (val_b * val_c) (val_a * (Interval::ONE - val_c)) + (val_b * val_c)
}); });
}, }
SSAFMA => { SSAFMA => {
self.param_three(instruction, |val_a, val_b, val_c| (val_a * val_b) + val_c); self.param_three(instruction, |val_a, val_b, val_c| (val_a * val_b) + val_c);
}, }
SSASDFSphere => { SSASDFSphere => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -339,7 +339,7 @@ impl<'csg> IntervalInterpreter<'csg> {
instruction.outputs[0], instruction.outputs[0],
((pos_x.square()) + (pos_y.square()) + (pos_z.square())).sqrt() - radius, ((pos_x.square()) + (pos_y.square()) + (pos_z.square())).sqrt() - radius,
); );
}, }
SSASDFBox => { SSASDFBox => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -361,7 +361,7 @@ impl<'csg> IntervalInterpreter<'csg> {
.min_choice(Interval::ZERO) .min_choice(Interval::ZERO)
.0, .0,
); );
}, }
SSASDFTorus => { SSASDFTorus => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -373,22 +373,22 @@ impl<'csg> IntervalInterpreter<'csg> {
instruction.outputs[0], instruction.outputs[0],
((q.square()) + (pos_y.square())).sqrt() - radius2, ((q.square()) + (pos_y.square())).sqrt() - radius2,
); );
}, }
SSACompare => { SSACompare => {
self.param_two(instruction, |val_a, val_b| val_a.compare(val_b)); self.param_two(instruction, |val_a, val_b| val_a.compare(val_b));
}, }
SSAAnd => { SSAAnd => {
self.param_two(instruction, |val_a, val_b| val_a.and_choice(val_b).0); self.param_two(instruction, |val_a, val_b| val_a.and_choice(val_b).0);
}, }
SSAOr => { SSAOr => {
self.param_two(instruction, |val_a, val_b| val_a.or_choice(val_b).0); self.param_two(instruction, |val_a, val_b| val_a.or_choice(val_b).0);
}, }
SSARecip => { SSARecip => {
self.param_one(instruction, |val_a| val_a.recip()); self.param_one(instruction, |val_a| val_a.recip());
}, }
SSANot => { SSANot => {
self.param_one(instruction, |val_a| !val_a); self.param_one(instruction, |val_a| !val_a);
}, }
SSAStop => return Interval::ZERO, SSAStop => return Interval::ZERO,
} }
} }
+45 -45
View File
@@ -12,7 +12,7 @@ use crate::{
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PointInterpreter<'csg> { pub struct PointInterpreter<'csg> {
value_map: Vec<Value>, value_map: Vec<Value>,
csg: &'csg SSATape, csg: &'csg SSATape,
} }
impl PointInterpreter<'_> { impl PointInterpreter<'_> {
@@ -79,28 +79,28 @@ impl<'csg> PointInterpreter<'csg> {
match instruction.opcode.opcode { match instruction.opcode.opcode {
SSAReturn => { SSAReturn => {
return self.load(instruction.inputs[0]); return self.load(instruction.inputs[0]);
}, }
SSAPosition => { SSAPosition => {
self.store(instruction.outputs[0], px); self.store(instruction.outputs[0], px);
self.store(instruction.outputs[1], py); self.store(instruction.outputs[1], py);
self.store(instruction.outputs[2], pz); self.store(instruction.outputs[2], pz);
self.store(instruction.outputs[3], time); self.store(instruction.outputs[3], time);
}, }
SSAAdd => { SSAAdd => {
self.param_two(instruction, |val_a, val_b| val_a + val_b); self.param_two(instruction, |val_a, val_b| val_a + val_b);
}, }
SSASub => { SSASub => {
self.param_two(instruction, |val_a, val_b| val_a - val_b); self.param_two(instruction, |val_a, val_b| val_a - val_b);
}, }
SSAMul => { SSAMul => {
self.param_two(instruction, |val_a, val_b| val_a * val_b); self.param_two(instruction, |val_a, val_b| val_a * val_b);
}, }
SSADiv => { SSADiv => {
self.param_two(instruction, |val_a, val_b| val_a / val_b); self.param_two(instruction, |val_a, val_b| val_a / val_b);
}, }
SSAMod => { SSAMod => {
self.param_two(instruction, |val_a, val_b| val_a % val_b); self.param_two(instruction, |val_a, val_b| val_a % val_b);
}, }
SSAAtan2 => self.param_two(instruction, |val_a, val_b| { SSAAtan2 => self.param_two(instruction, |val_a, val_b| {
let mut val_a = val_a.to_array(); let mut val_a = val_a.to_array();
let val_b = val_b.to_array(); let val_b = val_b.to_array();
@@ -111,11 +111,11 @@ impl<'csg> PointInterpreter<'csg> {
}), }),
SSAMin => { SSAMin => {
self.param_two(instruction, |val_a, val_b| val_a.simd_min(val_b)); self.param_two(instruction, |val_a, val_b| val_a.simd_min(val_b));
}, }
SSAMinMaterial => todo!(), SSAMinMaterial => todo!(),
SSAMax => { SSAMax => {
self.param_two(instruction, |val_a, val_b| val_a.simd_max(val_b)); self.param_two(instruction, |val_a, val_b| val_a.simd_max(val_b));
}, }
SSAMaxMaterial => todo!(), SSAMaxMaterial => todo!(),
SSADot => { SSADot => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
@@ -133,17 +133,17 @@ impl<'csg> PointInterpreter<'csg> {
(val_a[0] * val_b[0]) (val_a[0] * val_b[0])
+ (val_a[1] * val_b[1]) + (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2]) + (val_a[2] * val_b[2])
}, }
4 => { 4 => {
(val_a[0] * val_b[0]) (val_a[0] * val_b[0])
+ (val_a[1] * val_b[1]) + (val_a[1] * val_b[1])
+ (val_a[2] * val_b[2]) + (val_a[2] * val_b[2])
+ (val_a[3] * val_b[3]) + (val_a[3] * val_b[3])
}, }
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSALength => { SSALength => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize])) .map(|i| self.load(instruction.inputs[i as usize]))
@@ -165,7 +165,7 @@ impl<'csg> PointInterpreter<'csg> {
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSADistance => { SSADistance => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| self.load(instruction.inputs[i as usize])) .map(|i| self.load(instruction.inputs[i as usize]))
@@ -194,97 +194,97 @@ impl<'csg> PointInterpreter<'csg> {
_ => unreachable!(), _ => unreachable!(),
}, },
); );
}, }
SSANegate => { SSANegate => {
self.param_one(instruction, |val_a| -val_a); self.param_one(instruction, |val_a| -val_a);
}, }
SSARound => { SSARound => {
self.param_one(instruction, |val_a| val_a.round()); self.param_one(instruction, |val_a| val_a.round());
}, }
SSAAbs => { SSAAbs => {
self.param_one(instruction, |val_a| val_a.abs()); self.param_one(instruction, |val_a| val_a.abs());
}, }
SSAFloor => { SSAFloor => {
self.param_one(instruction, |val_a| val_a.floor()); self.param_one(instruction, |val_a| val_a.floor());
}, }
SSACeil => { SSACeil => {
self.param_one(instruction, |val_a| val_a.ceil()); self.param_one(instruction, |val_a| val_a.ceil());
}, }
SSAFract => { SSAFract => {
self.param_one(instruction, glfract); self.param_one(instruction, glfract);
}, }
SSASin => { SSASin => {
self.param_one(instruction, |val_a| val_a.sin()); self.param_one(instruction, |val_a| val_a.sin());
}, }
SSACos => { SSACos => {
self.param_one(instruction, |val_a| val_a.cos()); self.param_one(instruction, |val_a| val_a.cos());
}, }
SSATan => { SSATan => {
self.param_one(instruction, |val_a| { self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.tan())) Value::from_array(val_a.to_array().map(|f| f.tan()))
}); });
}, }
SSAAsin => { SSAAsin => {
self.param_one(instruction, |val_a| { self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.asin())) Value::from_array(val_a.to_array().map(|f| f.asin()))
}); });
}, }
SSAAcos => { SSAAcos => {
self.param_one(instruction, |val_a| { self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.acos())) Value::from_array(val_a.to_array().map(|f| f.acos()))
}); });
}, }
SSAAtan => { SSAAtan => {
self.param_one(instruction, |val_a| { self.param_one(instruction, |val_a| {
Value::from_array(val_a.to_array().map(|f| f.atan())) Value::from_array(val_a.to_array().map(|f| f.atan()))
}); });
}, }
SSAExp => { SSAExp => {
self.param_one(instruction, |val_a| val_a.exp()); self.param_one(instruction, |val_a| val_a.exp());
}, }
SSALog => { SSALog => {
self.param_one(instruction, |val_a| val_a.ln()); self.param_one(instruction, |val_a| val_a.ln());
}, }
SSASqrt => { SSASqrt => {
self.param_one(instruction, |val_a| val_a.sqrt()); self.param_one(instruction, |val_a| val_a.sqrt());
}, }
SSASquare => { SSASquare => {
self.param_one(instruction, |val_a| val_a * val_a); self.param_one(instruction, |val_a| val_a * val_a);
}, }
SSACube => { SSACube => {
self.param_one(instruction, |val_a| val_a * val_a * val_a); self.param_one(instruction, |val_a| val_a * val_a * val_a);
}, }
SSASmoothMin => { SSASmoothMin => {
self.param_three(instruction, |d1, d2, k| { self.param_three(instruction, |d1, d2, k| {
let h = let h =
(VALUE_05 + (VALUE_05 * (d2 - d1) / k)).simd_clamp(VALUE_0, VALUE_1); (VALUE_05 + (VALUE_05 * (d2 - d1) / k)).simd_clamp(VALUE_0, VALUE_1);
((d2 * (VALUE_1 - h)) + (d1 * h)) - k * h * (VALUE_1 - h) ((d2 * (VALUE_1 - h)) + (d1 * h)) - k * h * (VALUE_1 - h)
}); });
}, }
SSASmoothMax => { SSASmoothMax => {
self.param_three(instruction, |d1, d2, k| { self.param_three(instruction, |d1, d2, k| {
let h = let h =
(VALUE_05 - (VALUE_05 * (d2 + d1) / k)).simd_clamp(VALUE_0, VALUE_1); (VALUE_05 - (VALUE_05 * (d2 + d1) / k)).simd_clamp(VALUE_0, VALUE_1);
((d2 * (VALUE_1 - h)) + (-d1 * h)) + k * h * (VALUE_1 - h) ((d2 * (VALUE_1 - h)) + (-d1 * h)) + k * h * (VALUE_1 - h)
}); });
}, }
SSASmoothMinMaterial => todo!(), SSASmoothMinMaterial => todo!(),
SSASmoothMaxMaterial => todo!(), SSASmoothMaxMaterial => todo!(),
SSAClamp => { SSAClamp => {
self.param_three(instruction, |val_a, val_b, val_c| { self.param_three(instruction, |val_a, val_b, val_c| {
val_a.simd_clamp(val_b, val_c) val_a.simd_clamp(val_b, val_c)
}); });
}, }
SSAMix => { SSAMix => {
self.param_three(instruction, |val_a, val_b, val_c| { self.param_three(instruction, |val_a, val_b, val_c| {
(val_a * (VALUE_1 - val_c)) + (val_b * val_c) (val_a * (VALUE_1 - val_c)) + (val_b * val_c)
}); });
}, }
SSAFMA => { SSAFMA => {
self.param_three(instruction, |val_a, val_b, val_c| { self.param_three(instruction, |val_a, val_b, val_c| {
val_a.mul_add(val_b, val_c) val_a.mul_add(val_b, val_c)
}); });
}, }
SSASDFSphere => { SSASDFSphere => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -294,7 +294,7 @@ impl<'csg> PointInterpreter<'csg> {
instruction.outputs[0], instruction.outputs[0],
((pos_x * pos_x) + (pos_y * pos_y) + (pos_z * pos_z)).sqrt() - radius, ((pos_x * pos_x) + (pos_y * pos_y) + (pos_z * pos_z)).sqrt() - radius,
); );
}, }
SSASDFBox => { SSASDFBox => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -313,7 +313,7 @@ impl<'csg> PointInterpreter<'csg> {
((qxmax * qxmax) + (qymax * qymax) + (qzmax * qzmax)).sqrt() ((qxmax * qxmax) + (qymax * qymax) + (qzmax * qzmax)).sqrt()
+ qx.simd_max(qy.simd_max(qz)).simd_min(VALUE_0), + qx.simd_max(qy.simd_max(qz)).simd_min(VALUE_0),
); );
}, }
SSASDFTorus => { SSASDFTorus => {
let pos_x = self.load(instruction.inputs[0]); let pos_x = self.load(instruction.inputs[0]);
let pos_y = self.load(instruction.inputs[1]); let pos_y = self.load(instruction.inputs[1]);
@@ -325,32 +325,32 @@ impl<'csg> PointInterpreter<'csg> {
instruction.outputs[0], instruction.outputs[0],
((q * q) + (pos_y * pos_y)).sqrt() - radius2, ((q * q) + (pos_y * pos_y)).sqrt() - radius2,
); );
}, }
SSACompare => { SSACompare => {
self.param_two(instruction, |val_a, val_b| { self.param_two(instruction, |val_a, val_b| {
val_a val_a
.simd_gt(val_b) .simd_gt(val_b)
.select(VALUE_1, val_a.simd_lt(val_b).select(VALUE_M1, VALUE_0)) .select(VALUE_1, val_a.simd_lt(val_b).select(VALUE_M1, VALUE_0))
}); });
}, }
SSAAnd => { SSAAnd => {
self.param_two(instruction, |val_a, val_b| { self.param_two(instruction, |val_a, val_b| {
val_a.simd_eq(VALUE_0).select(val_a, val_b) val_a.simd_eq(VALUE_0).select(val_a, val_b)
}); });
}, }
SSAOr => { SSAOr => {
self.param_two(instruction, |val_a, val_b| { self.param_two(instruction, |val_a, val_b| {
val_a.simd_eq(VALUE_0).select(val_b, val_a) val_a.simd_eq(VALUE_0).select(val_b, val_a)
}); });
}, }
SSARecip => { SSARecip => {
self.param_one(instruction, |val_a| val_a.recip()); self.param_one(instruction, |val_a| val_a.recip());
}, }
SSANot => { SSANot => {
self.param_one(instruction, |val_a| { self.param_one(instruction, |val_a| {
val_a.simd_eq(VALUE_0).select(VALUE_1, VALUE_0) val_a.simd_eq(VALUE_0).select(VALUE_1, VALUE_0)
}); });
}, }
SSAStop => return VALUE_0, SSAStop => return VALUE_0,
} }
} }
+61 -47
View File
@@ -11,8 +11,16 @@ pub(crate) fn compile_gradient_function(
tape: &SSATape, tape: &SSATape,
types: SpirVTypes, types: SpirVTypes,
function_id: Option<spirv::Word>, function_id: Option<spirv::Word>,
pointers_in: bool,
) { ) {
let gradient_fn_type = b.type_function(types.vec4, vec![types.vec4p]); let gradient_fn_type = b.type_function(
types.vec4,
if pointers_in {
vec![types.vec4p]
} else {
vec![types.vec4]
},
);
let jit_string = b.string("Gradient JIT"); let jit_string = b.string("Gradient JIT");
let _scene = b let _scene = b
.begin_function( .begin_function(
@@ -25,11 +33,17 @@ pub(crate) fn compile_gradient_function(
gradient_fn_type, gradient_fn_type,
) )
.unwrap(); .unwrap();
let pos_p = b.function_parameter(types.vec4p).unwrap(); let pos_p = b
.function_parameter(if pointers_in { types.vec4p } else { types.vec4 })
.unwrap();
b.begin_block(None).unwrap(); b.begin_block(None).unwrap();
let pos = b.load(types.vec4, None, pos_p, None, []).unwrap(); let pos = if pointers_in {
b.load(types.vec4, None, pos_p, None, []).unwrap()
} else {
pos_p
};
let mut mapping = HashMap::<u32, u32>::new(); let mut mapping = HashMap::<u32, u32>::new();
@@ -115,7 +129,7 @@ pub(crate) fn compile_gradient_function(
.composite_construct(types.vec4, None, vec![zero, zero, zero, zero]) .composite_construct(types.vec4, None, vec![zero, zero, zero, zero])
.unwrap(); .unwrap();
b.ret_value(out).unwrap(); b.ret_value(out).unwrap();
}, }
SSAReturn => { SSAReturn => {
let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]); let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]);
let zero = b.constant_bit32(types.float, (0.0f32).to_bits()); let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
@@ -123,7 +137,7 @@ pub(crate) fn compile_gradient_function(
.composite_construct(types.vec4, None, vec![value, zero, zero, zero]) .composite_construct(types.vec4, None, vec![value, zero, zero, zero])
.unwrap(); .unwrap();
b.ret_value(out).unwrap(); b.ret_value(out).unwrap();
}, }
SSAPosition => { SSAPosition => {
mapping.insert( mapping.insert(
instruction.outputs[0], instruction.outputs[0],
@@ -141,7 +155,7 @@ pub(crate) fn compile_gradient_function(
instruction.outputs[3], instruction.outputs[3],
b.composite_extract(types.float, None, pos, [3]).unwrap(), b.composite_extract(types.float, None, pos, [3]).unwrap(),
); );
}, }
SSAAdd => { SSAAdd => {
param_two( param_two(
types.float, types.float,
@@ -150,7 +164,7 @@ pub(crate) fn compile_gradient_function(
instruction, instruction,
|b, val_a, val_b| b.f_add(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_add(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSASub => { SSASub => {
param_two( param_two(
types.float, types.float,
@@ -159,7 +173,7 @@ pub(crate) fn compile_gradient_function(
instruction, instruction,
|b, val_a, val_b| b.f_sub(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_sub(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAMul => { SSAMul => {
param_two( param_two(
types.float, types.float,
@@ -168,7 +182,7 @@ pub(crate) fn compile_gradient_function(
instruction, instruction,
|b, val_a, val_b| b.f_mul(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_mul(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSADiv => { SSADiv => {
param_two( param_two(
types.float, types.float,
@@ -177,7 +191,7 @@ pub(crate) fn compile_gradient_function(
instruction, instruction,
|b, val_a, val_b| b.f_div(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_div(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAMod => { SSAMod => {
param_two( param_two(
types.float, types.float,
@@ -186,7 +200,7 @@ pub(crate) fn compile_gradient_function(
instruction, instruction,
|b, val_a, val_b| b.f_mod(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_mod(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAAtan2 => { SSAAtan2 => {
param_two( param_two(
types.float, types.float,
@@ -204,7 +218,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMin => { SSAMin => {
param_two( param_two(
types.float, types.float,
@@ -222,7 +236,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMinMaterial => todo!(), SSAMinMaterial => todo!(),
SSAMax => { SSAMax => {
param_two( param_two(
@@ -241,7 +255,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMaxMaterial => todo!(), SSAMaxMaterial => todo!(),
SSADot => { SSADot => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
@@ -264,7 +278,7 @@ pub(crate) fn compile_gradient_function(
b.dot(types.float, None, val_a, val_b).unwrap() b.dot(types.float, None, val_a, val_b).unwrap()
}; };
mapping.insert(instruction.outputs[0], dot); mapping.insert(instruction.outputs[0], dot);
}, }
SSALength => { SSALength => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| { .map(|i| {
@@ -287,7 +301,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}; };
mapping.insert(instruction.outputs[0], length); mapping.insert(instruction.outputs[0], length);
}, }
SSADistance => { SSADistance => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| { .map(|i| {
@@ -316,18 +330,18 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}; };
mapping.insert(instruction.outputs[0], distance); mapping.insert(instruction.outputs[0], distance);
}, }
SSARecip => { SSARecip => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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).unwrap() b.f_div(types.float, None, one, val_a).unwrap()
}); });
}, }
SSANegate => { SSANegate => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.f_negate(types.float, None, val_a).unwrap() b.f_negate(types.float, None, val_a).unwrap()
}); });
}, }
SSARound => { SSARound => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -339,7 +353,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAbs => { SSAAbs => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -351,7 +365,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAFloor => { SSAFloor => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -363,7 +377,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSACeil => { SSACeil => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -375,7 +389,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAFract => { SSAFract => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -387,7 +401,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASin => { SSASin => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -399,7 +413,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSACos => { SSACos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -411,7 +425,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSATan => { SSATan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -423,7 +437,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAsin => { SSAAsin => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -435,7 +449,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAcos => { SSAAcos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -447,7 +461,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAtan => { SSAAtan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -459,7 +473,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAExp => { SSAExp => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -471,7 +485,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSALog => { SSALog => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -483,7 +497,7 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASqrt => { SSASqrt => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -495,18 +509,18 @@ pub(crate) fn compile_gradient_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASquare => { SSASquare => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.f_mul(types.float, None, val_a, val_a).unwrap() b.f_mul(types.float, None, val_a, val_a).unwrap()
}); });
}, }
SSACube => { SSACube => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
let square = b.f_mul(types.float, None, val_a, val_a).unwrap(); let square = b.f_mul(types.float, None, val_a, val_a).unwrap();
b.f_mul(types.float, None, val_a, square).unwrap() b.f_mul(types.float, None, val_a, square).unwrap()
}); });
}, }
SSASmoothMin => { SSASmoothMin => {
param_three(types.float, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -539,7 +553,7 @@ pub(crate) fn compile_gradient_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, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -573,7 +587,7 @@ pub(crate) fn compile_gradient_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!(),
SSAClamp => { SSAClamp => {
@@ -593,7 +607,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMix => { SSAMix => {
param_three( param_three(
types.float, types.float,
@@ -611,7 +625,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAFMA => { SSAFMA => {
param_three( param_three(
types.float, types.float,
@@ -629,7 +643,7 @@ pub(crate) fn compile_gradient_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSASDFSphere => { SSASDFSphere => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -653,7 +667,7 @@ pub(crate) fn compile_gradient_function(
let sphere = b.f_sub(types.float, None, length, radius).unwrap(); let sphere = b.f_sub(types.float, None, length, radius).unwrap();
mapping.insert(instruction.outputs[0], sphere); mapping.insert(instruction.outputs[0], sphere);
}, }
SSASDFBox => { SSASDFBox => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -742,7 +756,7 @@ pub(crate) fn compile_gradient_function(
instruction.outputs[0], instruction.outputs[0],
b.f_add(types.float, None, length, min).unwrap(), b.f_add(types.float, None, length, min).unwrap(),
); );
}, }
SSASDFTorus => { SSASDFTorus => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -787,7 +801,7 @@ pub(crate) fn compile_gradient_function(
instruction.outputs[0], instruction.outputs[0],
b.f_sub(types.float, None, length, rad2).unwrap(), b.f_sub(types.float, None, length, rad2).unwrap(),
); );
}, }
SSACompare => { SSACompare => {
param_two( param_two(
types.float, types.float,
@@ -813,7 +827,7 @@ pub(crate) fn compile_gradient_function(
select_eq select_eq
}, },
); );
}, }
SSAAnd => { SSAAnd => {
param_two( param_two(
types.float, types.float,
@@ -826,7 +840,7 @@ pub(crate) fn compile_gradient_function(
b.select(types.float, None, equal, val_a, val_b).unwrap() b.select(types.float, None, equal, val_a, val_b).unwrap()
}, },
); );
}, }
SSAOr => { SSAOr => {
param_two( param_two(
types.float, types.float,
@@ -839,7 +853,7 @@ pub(crate) fn compile_gradient_function(
b.select(types.float, None, equal, val_b, val_a).unwrap() b.select(types.float, None, equal, val_b, val_a).unwrap()
}, },
); );
}, }
SSANot => { SSANot => {
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());
@@ -847,7 +861,7 @@ pub(crate) fn compile_gradient_function(
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();
+114 -60
View File
@@ -12,8 +12,16 @@ pub(crate) fn compile_interval_function(
tape: &SSATape, tape: &SSATape,
types: SpirVTypes, types: SpirVTypes,
function_id: Option<spirv::Word>, function_id: Option<spirv::Word>,
pointers_in: bool,
) { ) {
let interval_fn_type = b.type_function(types.vec2, vec![types.vec4p, types.vec4p]); let interval_fn_type = b.type_function(
types.vec2,
if pointers_in {
vec![types.vec4p, types.vec4p]
} else {
vec![types.vec4, types.vec4]
},
);
let jit_string = b.string("Interval JIT"); let jit_string = b.string("Interval JIT");
let _scene = b let _scene = b
.begin_function( .begin_function(
@@ -26,13 +34,23 @@ pub(crate) fn compile_interval_function(
interval_fn_type, interval_fn_type,
) )
.unwrap(); .unwrap();
let pos_low = b.function_parameter(types.vec4p).unwrap(); let pos_low = b
let pos_high = b.function_parameter(types.vec4p).unwrap(); .function_parameter(if pointers_in { types.vec4p } else { types.vec4 })
.unwrap();
let pos_high = b
.function_parameter(if pointers_in { types.vec4p } else { types.vec4 })
.unwrap();
b.begin_block(None).unwrap(); b.begin_block(None).unwrap();
let pos_low = b.load(types.vec4, None, pos_low, None, []).unwrap(); let (pos_low, pos_high) = if pointers_in {
let pos_high = b.load(types.vec4, None, pos_high, None, []).unwrap(); (
b.load(types.vec4, None, pos_low, None, []).unwrap(),
b.load(types.vec4, None, pos_high, None, []).unwrap(),
)
} else {
(pos_low, pos_high)
};
let mut mapping = HashMap::<u32, (u32, u32)>::new(); let mut mapping = HashMap::<u32, (u32, u32)>::new();
@@ -53,7 +71,7 @@ pub(crate) fn compile_interval_function(
SSAInput::Constant(c) => { SSAInput::Constant(c) => {
let constant = b.constant_bit32(float, c.to_bits()); let constant = b.constant_bit32(float, c.to_bits());
(constant, constant) (constant, constant)
}, }
} }
} }
@@ -312,10 +330,22 @@ pub(crate) fn compile_interval_function(
let gt = b.f_ord_greater_than(bool, None, v.1, zero_const).unwrap(); 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 both = b.logical_and(bool, None, lt, gt).unwrap();
let abs_l = b let abs_l = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.0)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(v.0)],
)
.unwrap(); .unwrap();
let abs_h = b let abs_h = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.1)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(v.1)],
)
.unwrap(); .unwrap();
let min = b let min = b
.ext_inst( .ext_inst(
@@ -334,10 +364,22 @@ pub(crate) fn compile_interval_function(
.iter() .iter()
.map(|v| { .map(|v| {
let abs_l = b let abs_l = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.0)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(v.0)],
)
.unwrap(); .unwrap();
let abs_h = b let abs_h = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::FAbs as u32, [IdRef(v.1)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::FAbs as u32,
[IdRef(v.1)],
)
.unwrap(); .unwrap();
b.ext_inst( b.ext_inst(
float, float,
@@ -361,7 +403,13 @@ pub(crate) fn compile_interval_function(
.unwrap(); .unwrap();
let xy_sum = b.f_add(float, None, x, y).unwrap(); let xy_sum = b.f_add(float, None, x, y).unwrap();
let sqrt_low = b let sqrt_low = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::Sqrt as u32, [IdRef(xy_sum)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xy_sum)],
)
.unwrap(); .unwrap();
let x = b let x = b
.f_mul(float, None, val_a_uppers[0], val_a_uppers[0]) .f_mul(float, None, val_a_uppers[0], val_a_uppers[0])
@@ -371,10 +419,16 @@ pub(crate) fn compile_interval_function(
.unwrap(); .unwrap();
let xy_sum = b.f_add(float, None, x, y).unwrap(); let xy_sum = b.f_add(float, None, x, y).unwrap();
let sqrt_high = b let sqrt_high = b
.ext_inst(float, None, glsl, spirv::GlslStd450Op::Sqrt as u32, [IdRef(xy_sum)]) .ext_inst(
float,
None,
glsl,
spirv::GlslStd450Op::Sqrt as u32,
[IdRef(xy_sum)],
)
.unwrap(); .unwrap();
(sqrt_low, sqrt_high) (sqrt_low, sqrt_high)
}, }
3 => { 3 => {
let x = b let x = b
.f_mul(float, None, val_a_lowers[0], val_a_lowers[0]) .f_mul(float, None, val_a_lowers[0], val_a_lowers[0])
@@ -417,7 +471,7 @@ pub(crate) fn compile_interval_function(
) )
.unwrap(); .unwrap();
(sqrt_low, sqrt_high) (sqrt_low, sqrt_high)
}, }
4 => { 4 => {
let x = b let x = b
.f_mul(float, None, val_a_lowers[0], val_a_lowers[0]) .f_mul(float, None, val_a_lowers[0], val_a_lowers[0])
@@ -468,7 +522,7 @@ pub(crate) fn compile_interval_function(
) )
.unwrap(); .unwrap();
(sqrt_low, sqrt_high) (sqrt_low, sqrt_high)
}, }
_ => unreachable!("Invalid opcode size {}", opcode_size), _ => unreachable!("Invalid opcode size {}", opcode_size),
} }
} }
@@ -783,14 +837,14 @@ pub(crate) fn compile_interval_function(
let zero = b.constant_bit32(types.float, (0.0f32).to_bits()); let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
let zero_vec2 = b.constant_composite(types.vec2, [zero, zero]); let zero_vec2 = b.constant_composite(types.vec2, [zero, zero]);
b.ret_value(zero_vec2).unwrap(); b.ret_value(zero_vec2).unwrap();
}, }
SSAReturn => { SSAReturn => {
let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]); let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]);
let value_vec2 = b let value_vec2 = b
.composite_construct(types.vec2, None, [value.0, value.1]) .composite_construct(types.vec2, None, [value.0, value.1])
.unwrap(); .unwrap();
b.ret_value(value_vec2).unwrap(); b.ret_value(value_vec2).unwrap();
}, }
SSAPosition => { SSAPosition => {
let pos_low_x = b let pos_low_x = b
.composite_extract(types.float, None, pos_low, [0]) .composite_extract(types.float, None, pos_low, [0])
@@ -820,7 +874,7 @@ pub(crate) fn compile_interval_function(
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));
mapping.insert(instruction.outputs[3], (pos_low_w, pos_high_w)); mapping.insert(instruction.outputs[3], (pos_low_w, pos_high_w));
}, }
SSAAdd => { SSAAdd => {
param_two( param_two(
types.float, types.float,
@@ -829,7 +883,7 @@ pub(crate) fn compile_interval_function(
instruction, instruction,
|b, val_a, val_b| add(types.float, b, val_a, val_b), |b, val_a, val_b| add(types.float, b, val_a, val_b),
); );
}, }
SSASub => { SSASub => {
param_two( param_two(
types.float, types.float,
@@ -838,7 +892,7 @@ pub(crate) fn compile_interval_function(
instruction, instruction,
|b, val_a, val_b| sub(types.float, b, val_a, val_b), |b, val_a, val_b| sub(types.float, b, val_a, val_b),
); );
}, }
SSAMul => { SSAMul => {
param_two( param_two(
types.float, types.float,
@@ -847,7 +901,7 @@ pub(crate) fn compile_interval_function(
instruction, instruction,
|b, val_a, val_b| multiply(types.float, b, types.glsl, val_a, val_b), |b, val_a, val_b| multiply(types.float, b, types.glsl, val_a, val_b),
); );
}, }
SSADiv => { SSADiv => {
param_two( param_two(
types.float, types.float,
@@ -856,7 +910,7 @@ pub(crate) fn compile_interval_function(
instruction, instruction,
|b, val_a, val_b| divide(types.float, b, types.glsl, val_a, val_b), |b, val_a, val_b| divide(types.float, b, types.glsl, val_a, val_b),
); );
}, }
SSAMod => { SSAMod => {
param_two( param_two(
types.float, types.float,
@@ -929,7 +983,7 @@ pub(crate) fn compile_interval_function(
(low, high) (low, high)
}, },
); );
}, }
SSAAtan2 => { SSAAtan2 => {
param_two( param_two(
types.float, types.float,
@@ -944,7 +998,7 @@ pub(crate) fn compile_interval_function(
(npi_const, pi_const) (npi_const, pi_const)
}, },
); );
}, }
SSAMin => { SSAMin => {
param_two( param_two(
types.float, types.float,
@@ -964,7 +1018,7 @@ pub(crate) fn compile_interval_function(
.0 .0
}, },
); );
}, }
SSAMinMaterial => todo!(), SSAMinMaterial => todo!(),
SSAMax => { SSAMax => {
param_two( param_two(
@@ -985,7 +1039,7 @@ pub(crate) fn compile_interval_function(
.0 .0
}, },
); );
}, }
SSAMaxMaterial => todo!(), SSAMaxMaterial => todo!(),
SSADot => { SSADot => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
@@ -1004,14 +1058,14 @@ pub(crate) fn compile_interval_function(
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]); 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 muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
add(types.float, b, mulx, muly) add(types.float, b, mulx, muly)
}, }
3 => { 3 => {
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]); 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 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 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, mulx, muly);
add(types.float, b, accum, mulz) add(types.float, b, accum, mulz)
}, }
4 => { 4 => {
let mulx = multiply(types.float, b, types.glsl, val_a[0], val_b[0]); 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 muly = multiply(types.float, b, types.glsl, val_a[1], val_b[1]);
@@ -1020,11 +1074,11 @@ pub(crate) fn compile_interval_function(
let accum = add(types.float, b, mulx, muly); let accum = add(types.float, b, mulx, muly);
let accum = add(types.float, b, accum, mulz); let accum = add(types.float, b, accum, mulz);
add(types.float, b, accum, mulw) add(types.float, b, accum, mulw)
}, }
_ => 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);
}, }
SSALength | SSADistance => { SSALength | SSADistance => {
let mut val_a = (0..instruction.opcode.size) let mut val_a = (0..instruction.opcode.size)
.map(|i| { .map(|i| {
@@ -1057,7 +1111,7 @@ pub(crate) fn compile_interval_function(
&val_a, &val_a,
), ),
); );
}, }
SSARecip => { SSARecip => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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());
@@ -1066,12 +1120,12 @@ pub(crate) fn compile_interval_function(
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, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
negate(types.float, b, val_a) negate(types.float, b, val_a)
}); });
}, }
SSARound => { SSARound => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1093,12 +1147,12 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAAbs => { SSAAbs => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
abs(types.float, b, types.bool, types.glsl, val_a) abs(types.float, b, types.bool, types.glsl, val_a)
}); });
}, }
SSAFloor => { SSAFloor => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1120,7 +1174,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSACeil => { SSACeil => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1142,7 +1196,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAFract => { SSAFract => {
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());
@@ -1174,7 +1228,7 @@ pub(crate) fn compile_interval_function(
b.select(types.float, None, ge1, one, fract_high).unwrap(), b.select(types.float, None, ge1, one, fract_high).unwrap(),
) )
}); });
}, }
SSASin | SSACos => { SSASin | SSACos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
let pi_2 = let pi_2 =
@@ -1277,7 +1331,7 @@ pub(crate) fn compile_interval_function(
.unwrap(); .unwrap();
(lower, upper) (lower, upper)
}); });
}, }
SSATan => { SSATan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
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());
@@ -1313,7 +1367,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAAsin => { SSAAsin => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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());
@@ -1351,7 +1405,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAAcos => { SSAAcos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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());
@@ -1389,7 +1443,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAAtan => { SSAAtan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1411,7 +1465,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSAExp => { SSAExp => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1433,7 +1487,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSALog => { SSALog => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1455,7 +1509,7 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSASqrt => { SSASqrt => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
( (
@@ -1477,12 +1531,12 @@ pub(crate) fn compile_interval_function(
.unwrap(), .unwrap(),
) )
}); });
}, }
SSASquare => { SSASquare => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
square(types.float, b, types.bool, types.glsl, val_a) square(types.float, b, types.bool, types.glsl, val_a)
}); });
}, }
SSACube => { SSACube => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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_lower = b.f_mul(types.float, None, val_a.0, val_a.0).unwrap();
@@ -1492,7 +1546,7 @@ pub(crate) fn compile_interval_function(
b.f_mul(types.float, None, val_a.1, squ_upper).unwrap(), b.f_mul(types.float, None, val_a.1, squ_upper).unwrap(),
) )
}); });
}, }
SSASmoothMin => { SSASmoothMin => {
param_three(types.float, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -1532,7 +1586,7 @@ pub(crate) fn compile_interval_function(
let mix = mix(types.float, b, types.glsl, d2, d1, h); let mix = mix(types.float, b, types.glsl, d2, d1, h);
sub(types.float, b, mix, kh_negh) sub(types.float, b, mix, kh_negh)
}); });
}, }
SSASmoothMax => { SSASmoothMax => {
param_three(types.float, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -1573,7 +1627,7 @@ pub(crate) fn compile_interval_function(
let mix = mix(types.float, b, types.glsl, d2, negd1, h); let mix = mix(types.float, b, types.glsl, d2, negd1, h);
add(types.float, b, mix, kh_negh) add(types.float, b, mix, kh_negh)
}); });
}, }
SSASmoothMinMaterial => todo!(), SSASmoothMinMaterial => todo!(),
SSASmoothMaxMaterial => todo!(), SSASmoothMaxMaterial => todo!(),
SSAClamp => { SSAClamp => {
@@ -1603,7 +1657,7 @@ pub(crate) fn compile_interval_function(
) )
}, },
); );
}, }
SSAMix => { SSAMix => {
param_three( param_three(
types.float, types.float,
@@ -1612,7 +1666,7 @@ pub(crate) fn compile_interval_function(
instruction, instruction,
|b, val_a, val_b, val_c| mix(types.float, b, types.glsl, val_a, val_b, val_c), |b, val_a, val_b, val_c| mix(types.float, b, types.glsl, val_a, val_b, val_c),
); );
}, }
SSAFMA => { SSAFMA => {
param_three( param_three(
types.float, types.float,
@@ -1624,7 +1678,7 @@ pub(crate) fn compile_interval_function(
add(types.float, b, mul, val_c) add(types.float, b, mul, val_c)
}, },
); );
}, }
SSASDFSphere => { SSASDFSphere => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -1638,7 +1692,7 @@ pub(crate) fn compile_interval_function(
let sphere = sub(types.float, b, length, radius); let sphere = sub(types.float, b, length, radius);
mapping.insert(instruction.outputs[0], sphere); mapping.insert(instruction.outputs[0], sphere);
}, }
SSASDFBox => { SSASDFBox => {
let abs_pos = (0..3) let abs_pos = (0..3)
.map(|i| { .map(|i| {
@@ -1723,7 +1777,7 @@ pub(crate) fn compile_interval_function(
.0; .0;
mapping.insert(instruction.outputs[0], add(types.float, b, length, min)); mapping.insert(instruction.outputs[0], add(types.float, b, length, min));
}, }
SSASDFTorus => { SSASDFTorus => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -1767,7 +1821,7 @@ pub(crate) fn compile_interval_function(
); );
mapping.insert(instruction.outputs[0], sub(types.float, b, length, rad2)); mapping.insert(instruction.outputs[0], sub(types.float, b, length, rad2));
}, }
SSACompare => { SSACompare => {
param_two( param_two(
types.float, types.float,
@@ -1797,7 +1851,7 @@ pub(crate) fn compile_interval_function(
(low, high) (low, high)
}, },
); );
}, }
SSAAnd => { SSAAnd => {
param_two( param_two(
types.float, types.float,
@@ -1817,7 +1871,7 @@ pub(crate) fn compile_interval_function(
.0 .0
}, },
); );
}, }
SSAOr => { SSAOr => {
param_two( param_two(
types.float, types.float,
@@ -1837,7 +1891,7 @@ pub(crate) fn compile_interval_function(
.0 .0
}, },
); );
}, }
SSANot => { SSANot => {
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());
@@ -1860,7 +1914,7 @@ pub(crate) fn compile_interval_function(
let upper = b.select(types.float, None, contains, one, zero).unwrap(); let upper = b.select(types.float, None, contains, one, zero).unwrap();
(lower, upper) (lower, upper)
}); });
}, }
} }
} }
b.end_function().unwrap(); b.end_function().unwrap();
+8 -8
View File
@@ -4,13 +4,13 @@ pub(crate) mod point;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub(crate) struct SpirVTypes { pub(crate) struct SpirVTypes {
pub glsl: u32, pub glsl: u32,
pub void: u32, pub void: u32,
pub float: u32, pub float: u32,
pub bool: u32, pub bool: u32,
pub choice: u32, pub choice: u32,
pub vec2: u32, pub vec2: u32,
pub vec3: u32, pub vec3: u32,
pub vec4: u32, pub vec4: u32,
pub vec4p: u32, pub vec4p: u32,
} }
+61 -47
View File
@@ -11,8 +11,16 @@ pub(crate) fn compile_point_function(
tape: &SSATape, tape: &SSATape,
types: SpirVTypes, types: SpirVTypes,
function_id: Option<spirv::Word>, function_id: Option<spirv::Word>,
pointers_in: bool,
) { ) {
let point_fn_type = b.type_function(types.float, vec![types.vec4p]); let point_fn_type = b.type_function(
types.float,
if pointers_in {
vec![types.vec4p]
} else {
vec![types.vec4]
},
);
let jit_string = b.string("Point JIT"); let jit_string = b.string("Point JIT");
let _scene = b let _scene = b
.begin_function( .begin_function(
@@ -25,11 +33,17 @@ pub(crate) fn compile_point_function(
point_fn_type, point_fn_type,
) )
.unwrap(); .unwrap();
let pos_p = b.function_parameter(types.vec4p).unwrap(); let pos_p = b
.function_parameter(if pointers_in { types.vec4p } else { types.vec4 })
.unwrap();
b.begin_block(None).unwrap(); b.begin_block(None).unwrap();
let pos = b.load(types.vec4, None, pos_p, None, []).unwrap(); let pos = if pointers_in {
b.load(types.vec4, None, pos_p, None, []).unwrap()
} else {
pos_p
};
let mut mapping = HashMap::<u32, u32>::new(); let mut mapping = HashMap::<u32, u32>::new();
@@ -112,11 +126,11 @@ pub(crate) fn compile_point_function(
SSAStop => { SSAStop => {
let zero = b.constant_bit32(types.float, (0.0f32).to_bits()); let zero = b.constant_bit32(types.float, (0.0f32).to_bits());
b.ret_value(zero).unwrap(); b.ret_value(zero).unwrap();
}, }
SSAReturn => { SSAReturn => {
let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]); let value = input_resolve(types.float, b, &mapping, instruction.inputs[0]);
b.ret_value(value).unwrap(); b.ret_value(value).unwrap();
}, }
SSAPosition => { SSAPosition => {
mapping.insert( mapping.insert(
instruction.outputs[0], instruction.outputs[0],
@@ -134,7 +148,7 @@ pub(crate) fn compile_point_function(
instruction.outputs[3], instruction.outputs[3],
b.composite_extract(types.float, None, pos, [3]).unwrap(), b.composite_extract(types.float, None, pos, [3]).unwrap(),
); );
}, }
SSAAdd => { SSAAdd => {
param_two( param_two(
types.float, types.float,
@@ -143,7 +157,7 @@ pub(crate) fn compile_point_function(
instruction, instruction,
|b, val_a, val_b| b.f_add(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_add(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSASub => { SSASub => {
param_two( param_two(
types.float, types.float,
@@ -152,7 +166,7 @@ pub(crate) fn compile_point_function(
instruction, instruction,
|b, val_a, val_b| b.f_sub(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_sub(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAMul => { SSAMul => {
param_two( param_two(
types.float, types.float,
@@ -161,7 +175,7 @@ pub(crate) fn compile_point_function(
instruction, instruction,
|b, val_a, val_b| b.f_mul(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_mul(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSADiv => { SSADiv => {
param_two( param_two(
types.float, types.float,
@@ -170,7 +184,7 @@ pub(crate) fn compile_point_function(
instruction, instruction,
|b, val_a, val_b| b.f_div(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_div(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAMod => { SSAMod => {
param_two( param_two(
types.float, types.float,
@@ -179,7 +193,7 @@ pub(crate) fn compile_point_function(
instruction, instruction,
|b, val_a, val_b| b.f_mod(types.float, None, val_a, val_b).unwrap(), |b, val_a, val_b| b.f_mod(types.float, None, val_a, val_b).unwrap(),
); );
}, }
SSAAtan2 => { SSAAtan2 => {
param_two( param_two(
types.float, types.float,
@@ -197,7 +211,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMin => { SSAMin => {
param_two( param_two(
types.float, types.float,
@@ -215,7 +229,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMinMaterial => todo!(), SSAMinMaterial => todo!(),
SSAMax => { SSAMax => {
param_two( param_two(
@@ -234,7 +248,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMaxMaterial => todo!(), SSAMaxMaterial => todo!(),
SSADot => { SSADot => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
@@ -257,7 +271,7 @@ pub(crate) fn compile_point_function(
b.dot(types.float, None, val_a, val_b).unwrap() b.dot(types.float, None, val_a, val_b).unwrap()
}; };
mapping.insert(instruction.outputs[0], dot); mapping.insert(instruction.outputs[0], dot);
}, }
SSALength => { SSALength => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| { .map(|i| {
@@ -280,7 +294,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}; };
mapping.insert(instruction.outputs[0], length); mapping.insert(instruction.outputs[0], length);
}, }
SSADistance => { SSADistance => {
let val_a = (0..instruction.opcode.size) let val_a = (0..instruction.opcode.size)
.map(|i| { .map(|i| {
@@ -309,18 +323,18 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}; };
mapping.insert(instruction.outputs[0], distance); mapping.insert(instruction.outputs[0], distance);
}, }
SSARecip => { SSARecip => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, 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).unwrap() b.f_div(types.float, None, one, val_a).unwrap()
}); });
}, }
SSANegate => { SSANegate => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.f_negate(types.float, None, val_a).unwrap() b.f_negate(types.float, None, val_a).unwrap()
}); });
}, }
SSARound => { SSARound => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -332,7 +346,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAbs => { SSAAbs => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -344,7 +358,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAFloor => { SSAFloor => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -356,7 +370,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSACeil => { SSACeil => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -368,7 +382,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAFract => { SSAFract => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -380,7 +394,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASin => { SSASin => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -392,7 +406,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSACos => { SSACos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -404,7 +418,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSATan => { SSATan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -416,7 +430,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAsin => { SSAAsin => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -428,7 +442,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAcos => { SSAAcos => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -440,7 +454,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAAtan => { SSAAtan => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -452,7 +466,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSAExp => { SSAExp => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -464,7 +478,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSALog => { SSALog => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -476,7 +490,7 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASqrt => { SSASqrt => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.ext_inst( b.ext_inst(
@@ -488,18 +502,18 @@ pub(crate) fn compile_point_function(
) )
.unwrap() .unwrap()
}); });
}, }
SSASquare => { SSASquare => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
b.f_mul(types.float, None, val_a, val_a).unwrap() b.f_mul(types.float, None, val_a, val_a).unwrap()
}); });
}, }
SSACube => { SSACube => {
param_one(types.float, b, &mut mapping, instruction, |b, val_a| { param_one(types.float, b, &mut mapping, instruction, |b, val_a| {
let square = b.f_mul(types.float, None, val_a, val_a).unwrap(); let square = b.f_mul(types.float, None, val_a, val_a).unwrap();
b.f_mul(types.float, None, val_a, square).unwrap() b.f_mul(types.float, None, val_a, square).unwrap()
}); });
}, }
SSASmoothMin => { SSASmoothMin => {
param_three(types.float, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -532,7 +546,7 @@ pub(crate) fn compile_point_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, b, &mut mapping, instruction, |b, d1, d2, k| { param_three(types.float, 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());
@@ -566,7 +580,7 @@ pub(crate) fn compile_point_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!(),
SSAClamp => { SSAClamp => {
@@ -586,7 +600,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAMix => { SSAMix => {
param_three( param_three(
types.float, types.float,
@@ -604,7 +618,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAFMA => { SSAFMA => {
param_three( param_three(
types.float, types.float,
@@ -622,7 +636,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSASDFSphere => { SSASDFSphere => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -645,7 +659,7 @@ pub(crate) fn compile_point_function(
let sphere = b.f_sub(types.float, None, length, radius).unwrap(); let sphere = b.f_sub(types.float, None, length, radius).unwrap();
mapping.insert(instruction.outputs[0], sphere); mapping.insert(instruction.outputs[0], sphere);
}, }
SSASDFBox => { SSASDFBox => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -734,7 +748,7 @@ pub(crate) fn compile_point_function(
instruction.outputs[0], instruction.outputs[0],
b.f_add(types.float, None, length, min).unwrap(), b.f_add(types.float, None, length, min).unwrap(),
); );
}, }
SSASDFTorus => { SSASDFTorus => {
let pos_part = (0..3) let pos_part = (0..3)
.map(|i| { .map(|i| {
@@ -779,7 +793,7 @@ pub(crate) fn compile_point_function(
instruction.outputs[0], instruction.outputs[0],
b.f_sub(types.float, None, length, rad2).unwrap(), b.f_sub(types.float, None, length, rad2).unwrap(),
); );
}, }
SSACompare => { SSACompare => {
param_two( param_two(
types.float, types.float,
@@ -803,7 +817,7 @@ pub(crate) fn compile_point_function(
.unwrap() .unwrap()
}, },
); );
}, }
SSAAnd => { SSAAnd => {
param_two( param_two(
types.float, types.float,
@@ -816,7 +830,7 @@ pub(crate) fn compile_point_function(
b.select(types.float, None, equal, val_a, val_b).unwrap() b.select(types.float, None, equal, val_a, val_b).unwrap()
}, },
); );
}, }
SSAOr => { SSAOr => {
param_two( param_two(
types.float, types.float,
@@ -829,7 +843,7 @@ pub(crate) fn compile_point_function(
b.select(types.float, None, equal, val_b, val_a).unwrap() b.select(types.float, None, equal, val_b, val_a).unwrap()
}, },
); );
}, }
SSANot => { SSANot => {
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());
@@ -837,7 +851,7 @@ pub(crate) fn compile_point_function(
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();
+17 -10
View File
@@ -89,7 +89,7 @@ pub enum SSAOpcode {
#[cfg_attr(feature = "bevy", reflect(Clone))] #[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSAOpcodeSized { pub struct SSAOpcodeSized {
pub opcode: SSAOpcode, pub opcode: SSAOpcode,
pub size: u8, pub size: u8,
} }
#[derive(Debug, PartialEq, Clone, Copy)] #[derive(Debug, PartialEq, Clone, Copy)]
@@ -114,8 +114,8 @@ impl Hash for SSAInput {
#[cfg_attr(feature = "bevy", derive(Reflect))] #[cfg_attr(feature = "bevy", derive(Reflect))]
#[cfg_attr(feature = "bevy", reflect(Clone))] #[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSAInstruction { pub struct SSAInstruction {
pub opcode: SSAOpcodeSized, pub opcode: SSAOpcodeSized,
pub inputs: Vec<SSAInput>, pub inputs: Vec<SSAInput>,
pub outputs: Vec<u32>, pub outputs: Vec<u32>,
} }
@@ -124,8 +124,8 @@ pub struct SSAInstruction {
#[cfg_attr(feature = "bevy", reflect(Clone))] #[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct SSATape { pub struct SSATape {
pub last_output: u32, pub last_output: u32,
pub tape: Vec<SSAInstruction>, pub tape: Vec<SSAInstruction>,
constants: Vec<f32>, constants: Vec<f32>,
} }
impl Hash for SSATape { impl Hash for SSATape {
@@ -149,8 +149,8 @@ struct GPUOpcode(u8);
#[cfg_attr(feature = "bevy", reflect(Clone))] #[cfg_attr(feature = "bevy", reflect(Clone))]
pub struct GPUTape { pub struct GPUTape {
pub instructions: Vec<u8>, pub instructions: Vec<u8>,
pub io: Vec<u8>, pub io: Vec<u8>,
pub constants: Vec<f32>, pub constants: Vec<f32>,
} }
impl Hash for GPUTape { impl Hash for GPUTape {
@@ -435,8 +435,8 @@ impl SSATape {
let mut gpu_tape = GPUTape { let mut gpu_tape = GPUTape {
instructions: vec![], instructions: vec![],
io: vec![], io: vec![],
constants: self.constants.clone(), constants: self.constants.clone(),
}; };
let mut low_nibble = true; let mut low_nibble = true;
@@ -552,7 +552,11 @@ impl SSATape {
gpu_tape gpu_tape
} }
pub fn compile_to_spirv(&self, module: Option<Module>) -> rspirv::dr::Module { pub fn compile_to_spirv(
&self,
module: Option<Module>,
pointers_in: bool,
) -> rspirv::dr::Module {
let with_module = module.is_some(); let with_module = module.is_some();
let mut b = if let Some(module) = module { let mut b = if let Some(module) = module {
rspirv::dr::Builder::new_from_module(module) rspirv::dr::Builder::new_from_module(module)
@@ -610,6 +614,7 @@ impl SSATape {
} else { } else {
None None
}, },
pointers_in,
); );
// Manually fix the header bounds // Manually fix the header bounds
@@ -627,6 +632,7 @@ impl SSATape {
} else { } else {
None None
}, },
pointers_in,
); );
// Manually fix the header bounds // Manually fix the header bounds
@@ -644,6 +650,7 @@ impl SSATape {
} else { } else {
None None
}, },
pointers_in,
); );
let module = b.module(); let module = b.module();
+21 -21
View File
@@ -5,7 +5,7 @@ use glam::Vec4;
#[repr(C)] #[repr(C)]
pub struct Grad { pub struct Grad {
/// Value of the distance field at this point /// Value of the distance field at this point
pub v: f32, pub v: f32,
/// Partial derivative with respect to `x` /// Partial derivative with respect to `x`
pub dx: f32, pub dx: f32,
/// Partial derivative with respect to `y` /// Partial derivative with respect to `y`
@@ -46,7 +46,7 @@ impl Grad {
pub fn abs(self) -> Self { pub fn abs(self) -> Self {
if self.v < 0.0 { if self.v < 0.0 {
Grad { Grad {
v: -self.v, v: -self.v,
dx: -self.dx, dx: -self.dx,
dy: -self.dy, dy: -self.dy,
dz: -self.dz, dz: -self.dz,
@@ -73,7 +73,7 @@ impl Grad {
pub fn sin(self) -> Self { pub fn sin(self) -> Self {
let c = self.v.cos(); let c = self.v.cos();
Grad { Grad {
v: self.v.sin(), v: self.v.sin(),
dx: self.dx * c, dx: self.dx * c,
dy: self.dy * c, dy: self.dy * c,
dz: self.dz * c, dz: self.dz * c,
@@ -85,7 +85,7 @@ impl Grad {
pub fn cos(self) -> Self { pub fn cos(self) -> Self {
let s = -self.v.sin(); let s = -self.v.sin();
Grad { Grad {
v: self.v.cos(), v: self.v.cos(),
dx: self.dx * s, dx: self.dx * s,
dy: self.dy * s, dy: self.dy * s,
dz: self.dz * s, dz: self.dz * s,
@@ -97,7 +97,7 @@ impl Grad {
pub fn tan(self) -> Self { pub fn tan(self) -> Self {
let c = self.v.cos().powi(2); let c = self.v.cos().powi(2);
Grad { Grad {
v: self.v.tan(), v: self.v.tan(),
dx: self.dx / c, dx: self.dx / c,
dy: self.dy / c, dy: self.dy / c,
dz: self.dz / c, dz: self.dz / c,
@@ -109,7 +109,7 @@ impl Grad {
pub fn asin(self) -> Self { pub fn asin(self) -> Self {
let r = (1.0 - self.v.powi(2)).sqrt(); let r = (1.0 - self.v.powi(2)).sqrt();
Grad { Grad {
v: self.v.asin(), v: self.v.asin(),
dx: self.dx / r, dx: self.dx / r,
dy: self.dy / r, dy: self.dy / r,
dz: self.dz / r, dz: self.dz / r,
@@ -121,7 +121,7 @@ impl Grad {
pub fn acos(self) -> Self { pub fn acos(self) -> Self {
let r = (1.0 - self.v.powi(2)).sqrt(); let r = (1.0 - self.v.powi(2)).sqrt();
Grad { Grad {
v: self.v.acos(), v: self.v.acos(),
dx: -self.dx / r, dx: -self.dx / r,
dy: -self.dy / r, dy: -self.dy / r,
dz: -self.dz / r, dz: -self.dz / r,
@@ -133,7 +133,7 @@ impl Grad {
pub fn atan(self) -> Self { pub fn atan(self) -> Self {
let r = self.v.powi(2) + 1.0; let r = self.v.powi(2) + 1.0;
Grad { Grad {
v: self.v.atan(), v: self.v.atan(),
dx: self.dx / r, dx: self.dx / r,
dy: self.dy / r, dy: self.dy / r,
dz: self.dz / r, dz: self.dz / r,
@@ -156,7 +156,7 @@ impl Grad {
#[inline] #[inline]
pub fn ln(self) -> Self { pub fn ln(self) -> Self {
Grad { Grad {
v: self.v.ln(), v: self.v.ln(),
dx: self.dx / self.v, dx: self.dx / self.v,
dy: self.dy / self.v, dy: self.dy / self.v,
dz: self.dz / self.v, dz: self.dz / self.v,
@@ -168,7 +168,7 @@ impl Grad {
pub fn recip(self) -> Self { pub fn recip(self) -> Self {
let v2 = -self.v.powi(2); let v2 = -self.v.powi(2);
Grad { Grad {
v: 1.0 / self.v, v: 1.0 / self.v,
dx: self.dx / v2, dx: self.dx / v2,
dy: self.dy / v2, dy: self.dy / v2,
dz: self.dz / v2, dz: self.dz / v2,
@@ -192,7 +192,7 @@ impl Grad {
pub fn rem_euclid(&self, rhs: Grad) -> Self { pub fn rem_euclid(&self, rhs: Grad) -> Self {
let e = self.v.div_euclid(rhs.v); let e = self.v.div_euclid(rhs.v);
Grad { Grad {
v: self.v.rem_euclid(rhs.v), v: self.v.rem_euclid(rhs.v),
dx: self.dx - rhs.dx * e, dx: self.dx - rhs.dx * e,
dy: self.dy - rhs.dy * e, dy: self.dy - rhs.dy * e,
dz: self.dz - rhs.dz * e, dz: self.dz - rhs.dz * e,
@@ -203,7 +203,7 @@ impl Grad {
#[inline] #[inline]
pub fn floor(&self) -> Self { pub fn floor(&self) -> Self {
Grad { Grad {
v: self.v.floor(), v: self.v.floor(),
dx: 0.0, dx: 0.0,
dy: 0.0, dy: 0.0,
dz: 0.0, dz: 0.0,
@@ -214,7 +214,7 @@ impl Grad {
#[inline] #[inline]
pub fn ceil(&self) -> Self { pub fn ceil(&self) -> Self {
Grad { Grad {
v: self.v.ceil(), v: self.v.ceil(),
dx: 0.0, dx: 0.0,
dy: 0.0, dy: 0.0,
dz: 0.0, dz: 0.0,
@@ -225,7 +225,7 @@ impl Grad {
#[inline] #[inline]
pub fn round(&self) -> Self { pub fn round(&self) -> Self {
Grad { Grad {
v: self.v.round(), v: self.v.round(),
dx: 0.0, dx: 0.0,
dy: 0.0, dy: 0.0,
dz: 0.0, dz: 0.0,
@@ -239,7 +239,7 @@ impl Grad {
let d = x.v.powi(2) + y.v.powi(2); let d = x.v.powi(2) + y.v.powi(2);
Grad { Grad {
v: y.v.atan2(x.v), v: y.v.atan2(x.v),
dx: (x.v * y.dx - y.v * x.dx) / d, dx: (x.v * y.dx - y.v * x.dx) / d,
dy: (x.v * y.dy - y.v * x.dy) / d, dy: (x.v * y.dy - y.v * x.dy) / d,
dz: (x.v * y.dz - y.v * x.dz) / d, dz: (x.v * y.dz - y.v * x.dz) / d,
@@ -286,7 +286,7 @@ impl std::ops::Add<Grad> for Grad {
#[inline] #[inline]
fn add(self, rhs: Self) -> Self { fn add(self, rhs: Self) -> Self {
Grad { Grad {
v: self.v + rhs.v, v: self.v + rhs.v,
dx: self.dx + rhs.dx, dx: self.dx + rhs.dx,
dy: self.dy + rhs.dy, dy: self.dy + rhs.dy,
dz: self.dz + rhs.dz, dz: self.dz + rhs.dz,
@@ -300,7 +300,7 @@ impl std::ops::Mul<Grad> for Grad {
#[inline] #[inline]
fn mul(self, rhs: Self) -> Self { fn mul(self, rhs: Self) -> Self {
Self { Self {
v: self.v * rhs.v, v: self.v * rhs.v,
dx: self.v * rhs.dx + rhs.v * self.dx, dx: self.v * rhs.dx + rhs.v * self.dx,
dy: self.v * rhs.dy + rhs.v * self.dy, dy: self.v * rhs.dy + rhs.v * self.dy,
dz: self.v * rhs.dz + rhs.v * self.dz, dz: self.v * rhs.dz + rhs.v * self.dz,
@@ -314,7 +314,7 @@ impl std::ops::Mul<f32> for Grad {
#[inline] #[inline]
fn mul(self, rhs: f32) -> Self { fn mul(self, rhs: f32) -> Self {
Self { Self {
v: self.v * rhs, v: self.v * rhs,
dx: self.dx * rhs, dx: self.dx * rhs,
dy: self.dy * rhs, dy: self.dy * rhs,
dz: self.dz * rhs, dz: self.dz * rhs,
@@ -329,7 +329,7 @@ impl std::ops::Div<Grad> for Grad {
fn div(self, rhs: Self) -> Self { fn div(self, rhs: Self) -> Self {
let d = rhs.v.powi(2); let d = rhs.v.powi(2);
Self { Self {
v: self.v / rhs.v, v: self.v / rhs.v,
dx: (rhs.v * self.dx - self.v * rhs.dx) / d, dx: (rhs.v * self.dx - self.v * rhs.dx) / d,
dy: (rhs.v * self.dy - self.v * rhs.dy) / d, dy: (rhs.v * self.dy - self.v * rhs.dy) / d,
dz: (rhs.v * self.dz - self.v * rhs.dz) / d, dz: (rhs.v * self.dz - self.v * rhs.dz) / d,
@@ -343,7 +343,7 @@ impl std::ops::Sub<Grad> for Grad {
#[inline] #[inline]
fn sub(self, rhs: Self) -> Self { fn sub(self, rhs: Self) -> Self {
Self { Self {
v: self.v - rhs.v, v: self.v - rhs.v,
dx: self.dx - rhs.dx, dx: self.dx - rhs.dx,
dy: self.dy - rhs.dy, dy: self.dy - rhs.dy,
dz: self.dz - rhs.dz, dz: self.dz - rhs.dz,
@@ -357,7 +357,7 @@ impl std::ops::Neg for Grad {
#[inline] #[inline]
fn neg(self) -> Self { fn neg(self) -> Self {
Self { Self {
v: -self.v, v: -self.v,
dx: -self.dx, dx: -self.dx,
dy: -self.dy, dy: -self.dy,
dz: -self.dz, dz: -self.dz,
+3 -3
View File
@@ -21,13 +21,13 @@ pub enum Choice {
Unknown = 0, Unknown = 0,
/// The operation always picks the left-hand input /// The operation always picks the left-hand input
Left = 1, Left = 1,
/// The operation always picks the right-hand input /// The operation always picks the right-hand input
Right = 2, Right = 2,
/// The operation may pick either input /// The operation may pick either input
Both = 3, Both = 3,
} }
impl std::ops::BitOrAssign<Choice> for Choice { impl std::ops::BitOrAssign<Choice> for Choice {