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