cleanup
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
/target
|
/target
|
||||||
Cargo.lock
|
|
||||||
Vendored
+8
-8
@@ -7,15 +7,15 @@
|
|||||||
{
|
{
|
||||||
"type": "lldb",
|
"type": "lldb",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug executable 'erroccfisumreg'",
|
"name": "Debug executable 'erroccfisuvsc'",
|
||||||
"cargo": {
|
"cargo": {
|
||||||
"args": [
|
"args": [
|
||||||
"build",
|
"build",
|
||||||
"--bin=erroccfisumreg",
|
"--bin=erroccfisuvsc",
|
||||||
"--package=erroccfisumreg"
|
"--package=erroccfisuvsc"
|
||||||
],
|
],
|
||||||
"filter": {
|
"filter": {
|
||||||
"name": "erroccfisumreg",
|
"name": "erroccfisuvsc",
|
||||||
"kind": "bin"
|
"kind": "bin"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -25,16 +25,16 @@
|
|||||||
{
|
{
|
||||||
"type": "lldb",
|
"type": "lldb",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug unit tests in executable 'erroccfisumreg'",
|
"name": "Debug unit tests in executable 'erroccfisuvsc'",
|
||||||
"cargo": {
|
"cargo": {
|
||||||
"args": [
|
"args": [
|
||||||
"test",
|
"test",
|
||||||
"--no-run",
|
"--no-run",
|
||||||
"--bin=erroccfisumreg",
|
"--bin=erroccfisuvsc",
|
||||||
"--package=erroccfisumreg"
|
"--package=erroccfisuvsc"
|
||||||
],
|
],
|
||||||
"filter": {
|
"filter": {
|
||||||
"name": "erroccfisumreg",
|
"name": "erroccfisuvsc",
|
||||||
"kind": "bin"
|
"kind": "bin"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
-8
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"folders": [
|
|
||||||
{
|
|
||||||
"path": ".."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"settings": {}
|
|
||||||
}
|
|
||||||
Generated
+1253
-373
File diff suppressed because it is too large
Load Diff
+13
-18
@@ -1,21 +1,16 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "erroccfisumreg"
|
name = "erroccfisuvsc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
vulkano = "0.32"
|
vulkano = "0.34"
|
||||||
# Provides the `shader!` macro that is used to generate code for using shaders.
|
vulkano-shaders = "0.34"
|
||||||
vulkano-shaders = "0.32"
|
winit = "0.30"
|
||||||
# The Vulkan library doesn't provide any functionality to create and handle windows, as
|
vulkano-win = "0.34"
|
||||||
# this would be out of scope. In order to open a window, we are going to use the `winit` crate.
|
vulkano-util = "0.34"
|
||||||
winit = "0.28"
|
|
||||||
# The `vulkano_win` crate is the link between `vulkano` and `winit`. Vulkano doesn't know about winit,
|
|
||||||
# and winit doesn't know about vulkano, so import a crate that will provide a link between the two.
|
|
||||||
vulkano-win = "0.32"
|
|
||||||
vulkano-util = "0.32"
|
|
||||||
|
|
||||||
obj = "0.10"
|
obj = "0.10"
|
||||||
bytemuck = { version = "1.13", features = [
|
bytemuck = { version = "1.13", features = [
|
||||||
@@ -26,8 +21,8 @@ bytemuck = { version = "1.13", features = [
|
|||||||
|
|
||||||
cgmath = "0.18"
|
cgmath = "0.18"
|
||||||
|
|
||||||
egui = "0.21"
|
egui = "0.30"
|
||||||
egui_winit_vulkano = "0.23"
|
egui_winit_vulkano = "0.27"
|
||||||
|
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
@@ -40,8 +35,8 @@ rand = "0.8.5"
|
|||||||
|
|
||||||
# using latest gits
|
# using latest gits
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
vulkano = { git = "https://github.com/Molive-0/vulkano" }
|
vulkano = { git = "https://github.com/vulkano-rs/vulkano" }
|
||||||
vulkano-shaders = { git = "https://github.com/Molive-0/vulkano" }
|
vulkano-shaders = { git = "https://github.com/vulkano-rs/vulkano" }
|
||||||
vulkano-win = { git = "https://github.com/Molive-0/vulkano" }
|
vulkano-win = { git = "https://github.com/vulkano-rs/vulkano" }
|
||||||
vulkano-util = { git = "https://github.com/Molive-0/vulkano" }
|
vulkano-util = { git = "https://github.com/vulkano-rs/vulkano" }
|
||||||
egui_winit_vulkano = { git = "https://github.com/Molive-0/egui_winit_vulkano" }
|
egui_winit_vulkano = { git = "https://github.com/hakolao/egui_winit_vulkano" }
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# Efficient Realtime Rendering of Complex Closed Form Implicit Surfaces Using Modern RTX Enabled GPUs
|
# Efficient Realtime Rendering of Complex Closed Form Implicit Surfaces Using Vulkan Specialisation Constants
|
||||||
|
|
||||||
## See the [report](https://mo.molive.live/dump/Final_Report.pdf)
|
"The elites don’t want you to know this but the Specialisation Constants at the Vulkan are free you can take them home I have 458 Specialisation Constants." - Adolphe Vulk, inventor of Vulkan
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
use std::env;
|
use std::{
|
||||||
|
env, fs,
|
||||||
use std::fs;
|
fs::File,
|
||||||
use std::fs::File;
|
io,
|
||||||
use std::io;
|
io::{BufRead, BufReader},
|
||||||
use std::io::BufRead;
|
path::Path,
|
||||||
use std::io::BufReader;
|
};
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
println!("cargo:rerun-if-changed=src/instructionset.glsl");
|
println!("cargo:rerun-if-changed=src/instructionset.glsl");
|
||||||
|
|||||||
+132
-40
@@ -12,22 +12,22 @@ fn sized_text(ui: &mut egui::Ui, text: impl Into<String>, size: f32) {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
|
||||||
pub(crate) struct PreviousDebug {
|
pub(crate) struct PreviousDebug {
|
||||||
pub(crate) bounding_boxes: bool,
|
pub(crate) bounding_boxes: bool,
|
||||||
pub(crate) disable_meshcull: bool,
|
pub(crate) disable_meshcull: bool,
|
||||||
pub(crate) disable_meshscale1: bool,
|
pub(crate) disable_meshscale1: bool,
|
||||||
pub(crate) disable_meshscale2: bool,
|
pub(crate) disable_meshscale2: bool,
|
||||||
pub(crate) disable_taskcull: bool,
|
pub(crate) disable_taskcull: bool,
|
||||||
pub(crate) brute_force: bool,
|
pub(crate) brute_force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct GState {
|
pub(crate) struct GState {
|
||||||
pub(crate) cursor_sensitivity: f32,
|
pub(crate) cursor_sensitivity: f32,
|
||||||
pub(crate) move_speed: f32,
|
pub(crate) move_speed: f32,
|
||||||
|
|
||||||
pub(crate) meshes: Vec<Mesh>,
|
pub(crate) meshes: Vec<Mesh>,
|
||||||
pub(crate) lights: Vec<Light>,
|
pub(crate) lights: Vec<Light>,
|
||||||
pub(crate) csg: Vec<CSG>,
|
pub(crate) csg: Vec<CSG>,
|
||||||
|
|
||||||
pub(crate) fps: [f64; 128],
|
pub(crate) fps: [f64; 128],
|
||||||
|
|
||||||
@@ -38,11 +38,11 @@ impl Default for GState {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
cursor_sensitivity: 1.0,
|
cursor_sensitivity: 1.0,
|
||||||
move_speed: 1.0,
|
move_speed: 1.0,
|
||||||
|
|
||||||
meshes: vec![],
|
meshes: vec![],
|
||||||
lights: vec![],
|
lights: vec![],
|
||||||
csg: vec![],
|
csg: vec![],
|
||||||
|
|
||||||
fps: [0.0; 128],
|
fps: [0.0; 128],
|
||||||
|
|
||||||
@@ -58,31 +58,61 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
|||||||
.frame(Frame::default().fill(Color32::from_rgba_unmultiplied(50, 50, 50, 200)))
|
.frame(Frame::default().fill(Color32::from_rgba_unmultiplied(50, 50, 50, 200)))
|
||||||
.show(&ctx, |ui| {
|
.show(&ctx, |ui| {
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
ui.add(egui::widgets::Label::new("Efficient Realtime Rendering of Complex Closed Form Implicit Surfaces Using Modern RTX Enabled GPUs"));
|
ui.add(egui::widgets::Label::new(
|
||||||
|
"Efficient Realtime Rendering of Complex Closed Form Implicit Surfaces \
|
||||||
|
Using Modern RTX Enabled GPUs",
|
||||||
|
));
|
||||||
sized_text(ui, "Settings", 32.0);
|
sized_text(ui, "Settings", 32.0);
|
||||||
});
|
});
|
||||||
ui.separator();
|
ui.separator();
|
||||||
egui::ScrollArea::vertical().show(ui, |ui| {
|
egui::ScrollArea::vertical().show(ui, |ui| {
|
||||||
ui.vertical_centered(|ui| {
|
ui.vertical_centered(|ui| {
|
||||||
ui.heading("Camera Control");
|
ui.heading("Camera Control");
|
||||||
ui.add(egui::Slider::new(&mut state.cursor_sensitivity, 0.0..=2.0).text("Mouse Sensitivity"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut state.move_speed, 0.0..=2.0).text("Movement Speed"));
|
egui::Slider::new(&mut state.cursor_sensitivity, 0.0..=2.0)
|
||||||
|
.text("Mouse Sensitivity"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut state.move_speed, 0.0..=2.0)
|
||||||
|
.text("Movement Speed"),
|
||||||
|
);
|
||||||
ui.heading("Meshes");
|
ui.heading("Meshes");
|
||||||
let mut meshdel = vec![];
|
let mut meshdel = vec![];
|
||||||
for mesh in &mut state.meshes {
|
for mesh in &mut state.meshes {
|
||||||
ui.label(mesh.name.clone());
|
ui.label(mesh.name.clone());
|
||||||
meshdel.push(ui.small_button("remove mesh").clicked());
|
meshdel.push(ui.small_button("remove mesh").clicked());
|
||||||
ui.add(egui::Slider::new(&mut mesh.pos.x, -100.0..=100.0).text("Position.x"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut mesh.pos.y, -100.0..=100.0).text("Position.y"));
|
egui::Slider::new(&mut mesh.pos.x, -100.0..=100.0)
|
||||||
ui.add(egui::Slider::new(&mut mesh.pos.z, -100.0..=100.0).text("Position.z"));
|
.text("Position.x"),
|
||||||
ui.add(egui::Slider::new(&mut mesh.rot.x.0, 0.0..=360.0).text("Rotation.x"));
|
);
|
||||||
ui.add(egui::Slider::new(&mut mesh.rot.y.0, 0.0..=360.0).text("Rotation.y"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut mesh.rot.z.0, 0.0..=360.0).text("Rotation.z"));
|
egui::Slider::new(&mut mesh.pos.y, -100.0..=100.0)
|
||||||
|
.text("Position.y"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut mesh.pos.z, -100.0..=100.0)
|
||||||
|
.text("Position.z"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut mesh.rot.x.0, 0.0..=360.0)
|
||||||
|
.text("Rotation.x"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut mesh.rot.y.0, 0.0..=360.0)
|
||||||
|
.text("Rotation.y"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut mesh.rot.z.0, 0.0..=360.0)
|
||||||
|
.text("Rotation.z"),
|
||||||
|
);
|
||||||
ui.add(egui::Slider::new(&mut mesh.scale.x, 0.0..=2.0).text("Scale.x"));
|
ui.add(egui::Slider::new(&mut mesh.scale.x, 0.0..=2.0).text("Scale.x"));
|
||||||
ui.add(egui::Slider::new(&mut mesh.scale.y, 0.0..=2.0).text("Scale.y"));
|
ui.add(egui::Slider::new(&mut mesh.scale.y, 0.0..=2.0).text("Scale.y"));
|
||||||
ui.add(egui::Slider::new(&mut mesh.scale.z, 0.0..=2.0).text("Scale.z"));
|
ui.add(egui::Slider::new(&mut mesh.scale.z, 0.0..=2.0).text("Scale.z"));
|
||||||
}
|
}
|
||||||
for i in meshdel.into_iter().enumerate().filter_map(|(a,b)| if b {Some(a)} else {None})
|
for i in meshdel
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(a, b)| if b { Some(a) } else { None })
|
||||||
{
|
{
|
||||||
state.meshes.remove(i);
|
state.meshes.remove(i);
|
||||||
}
|
}
|
||||||
@@ -91,17 +121,35 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
|||||||
for csg in &mut state.csg {
|
for csg in &mut state.csg {
|
||||||
ui.label(csg.name.clone());
|
ui.label(csg.name.clone());
|
||||||
csgdel.push(ui.small_button("remove csg").clicked());
|
csgdel.push(ui.small_button("remove csg").clicked());
|
||||||
ui.add(egui::Slider::new(&mut csg.pos.x, -100.0..=100.0).text("Position.x"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut csg.pos.y, -100.0..=100.0).text("Position.y"));
|
egui::Slider::new(&mut csg.pos.x, -100.0..=100.0)
|
||||||
ui.add(egui::Slider::new(&mut csg.pos.z, -100.0..=100.0).text("Position.z"));
|
.text("Position.x"),
|
||||||
ui.add(egui::Slider::new(&mut csg.rot.x.0, 0.0..=360.0).text("Rotation.x"));
|
);
|
||||||
ui.add(egui::Slider::new(&mut csg.rot.y.0, 0.0..=360.0).text("Rotation.y"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut csg.rot.z.0, 0.0..=360.0).text("Rotation.z"));
|
egui::Slider::new(&mut csg.pos.y, -100.0..=100.0)
|
||||||
|
.text("Position.y"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut csg.pos.z, -100.0..=100.0)
|
||||||
|
.text("Position.z"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut csg.rot.x.0, 0.0..=360.0).text("Rotation.x"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut csg.rot.y.0, 0.0..=360.0).text("Rotation.y"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut csg.rot.z.0, 0.0..=360.0).text("Rotation.z"),
|
||||||
|
);
|
||||||
ui.add(egui::Slider::new(&mut csg.scale.x, 0.0..=2.0).text("Scale.x"));
|
ui.add(egui::Slider::new(&mut csg.scale.x, 0.0..=2.0).text("Scale.x"));
|
||||||
ui.add(egui::Slider::new(&mut csg.scale.y, 0.0..=2.0).text("Scale.y"));
|
ui.add(egui::Slider::new(&mut csg.scale.y, 0.0..=2.0).text("Scale.y"));
|
||||||
ui.add(egui::Slider::new(&mut csg.scale.z, 0.0..=2.0).text("Scale.z"));
|
ui.add(egui::Slider::new(&mut csg.scale.z, 0.0..=2.0).text("Scale.z"));
|
||||||
}
|
}
|
||||||
for i in csgdel.into_iter().enumerate().filter_map(|(a,b)| if b {Some(a)} else {None})
|
for i in csgdel
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(a, b)| if b { Some(a) } else { None })
|
||||||
{
|
{
|
||||||
state.csg.remove(i);
|
state.csg.remove(i);
|
||||||
}
|
}
|
||||||
@@ -110,14 +158,32 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
|||||||
for light in &mut state.lights {
|
for light in &mut state.lights {
|
||||||
ui.label("Light");
|
ui.label("Light");
|
||||||
lightdel.push(ui.small_button("remove light").clicked());
|
lightdel.push(ui.small_button("remove light").clicked());
|
||||||
ui.add(egui::Slider::new(&mut light.pos.x, -100.0..=100.0).text("Position.x"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut light.pos.y, -100.0..=100.0).text("Position.y"));
|
egui::Slider::new(&mut light.pos.x, -100.0..=100.0)
|
||||||
ui.add(egui::Slider::new(&mut light.pos.z, -100.0..=100.0).text("Position.z"));
|
.text("Position.x"),
|
||||||
ui.add(egui::Slider::new(&mut light.colour.x, 0.0..=1.0).text("Colour.r"));
|
);
|
||||||
ui.add(egui::Slider::new(&mut light.colour.y, 0.0..=1.0).text("Colour.g"));
|
ui.add(
|
||||||
ui.add(egui::Slider::new(&mut light.colour.z, 0.0..=1.0).text("Colour.b"));
|
egui::Slider::new(&mut light.pos.y, -100.0..=100.0)
|
||||||
|
.text("Position.y"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut light.pos.z, -100.0..=100.0)
|
||||||
|
.text("Position.z"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut light.colour.x, 0.0..=1.0).text("Colour.r"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut light.colour.y, 0.0..=1.0).text("Colour.g"),
|
||||||
|
);
|
||||||
|
ui.add(
|
||||||
|
egui::Slider::new(&mut light.colour.z, 0.0..=1.0).text("Colour.b"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
for i in lightdel.into_iter().enumerate().filter_map(|(a,b)| if b {Some(a)} else {None})
|
for i in lightdel
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(a, b)| if b { Some(a) } else { None })
|
||||||
{
|
{
|
||||||
state.lights.remove(i);
|
state.lights.remove(i);
|
||||||
}
|
}
|
||||||
@@ -125,18 +191,44 @@ pub(crate) fn gui_up(gui: &mut Gui, state: &mut GState) {
|
|||||||
state.lights.push(Light::default());
|
state.lights.push(Light::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
let fps: PlotPoints = state.fps.iter().enumerate().map(|(x,y)| [x as f64,*y]).collect::<Vec<_>>().into();
|
let fps: PlotPoints = state
|
||||||
|
.fps
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(x, y)| [x as f64, *y])
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.into();
|
||||||
let line = Line::new(fps);
|
let line = Line::new(fps);
|
||||||
ui.heading("FPS");
|
ui.heading("FPS");
|
||||||
Plot::new("fps").view_aspect(2.0).show(ui, |plot_ui| plot_ui.line(line));
|
Plot::new("fps")
|
||||||
|
.view_aspect(2.0)
|
||||||
|
.show(ui, |plot_ui| plot_ui.line(line));
|
||||||
|
|
||||||
ui.heading("Debug");
|
ui.heading("Debug");
|
||||||
ui.toggle_value(&mut state.debug.bounding_boxes, "Render bounding boxes instead");
|
ui.toggle_value(
|
||||||
ui.toggle_value(&mut state.debug.disable_meshcull, "Disable mesh shader culling");
|
&mut state.debug.bounding_boxes,
|
||||||
ui.toggle_value(&mut state.debug.disable_meshscale1, "Disable mesh shader scaling part 1");
|
"Render bounding boxes instead",
|
||||||
ui.toggle_value(&mut state.debug.disable_meshscale2, "Disable mesh shader scaling part 2");
|
);
|
||||||
ui.toggle_value(&mut state.debug.disable_taskcull, "Disable task shader culling");
|
ui.toggle_value(
|
||||||
ui.toggle_value(&mut state.debug.brute_force, "Brute force the render (use no new techniques)");
|
&mut state.debug.disable_meshcull,
|
||||||
|
"Disable mesh shader culling",
|
||||||
|
);
|
||||||
|
ui.toggle_value(
|
||||||
|
&mut state.debug.disable_meshscale1,
|
||||||
|
"Disable mesh shader scaling part 1",
|
||||||
|
);
|
||||||
|
ui.toggle_value(
|
||||||
|
&mut state.debug.disable_meshscale2,
|
||||||
|
"Disable mesh shader scaling part 2",
|
||||||
|
);
|
||||||
|
ui.toggle_value(
|
||||||
|
&mut state.debug.disable_taskcull,
|
||||||
|
"Disable task shader culling",
|
||||||
|
);
|
||||||
|
ui.toggle_value(
|
||||||
|
&mut state.debug.brute_force,
|
||||||
|
"Brute force the render (use no new techniques)",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+271
-274
File diff suppressed because it is too large
Load Diff
+374
-242
@@ -1,65 +1,58 @@
|
|||||||
#![feature(variant_count)]
|
#![feature(variant_count)]
|
||||||
use bytemuck::{Zeroable, Pod};
|
use std::{io::Cursor, sync::Arc, time::Instant};
|
||||||
use cgmath::{
|
|
||||||
Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix,
|
use bytemuck::{Pod, Zeroable};
|
||||||
Vector3,
|
use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector3};
|
||||||
};
|
use egui_winit_vulkano::{Gui, GuiConfig};
|
||||||
use instruction_set::InputTypes;
|
use instruction_set::InputTypes;
|
||||||
use vulkano::command_buffer::{CopyBufferInfo, PrimaryCommandBufferAbstract};
|
|
||||||
use std::io::Cursor;
|
|
||||||
use std::{sync::Arc, time::Instant};
|
|
||||||
use vulkano::buffer::allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo};
|
|
||||||
use vulkano::buffer::{Buffer, BufferAllocateInfo, Subbuffer};
|
|
||||||
use vulkano::command_buffer::allocator::StandardCommandBufferAllocator;
|
|
||||||
use vulkano::descriptor_set::allocator::StandardDescriptorSetAllocator;
|
|
||||||
use vulkano::descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet};
|
|
||||||
use vulkano::device::{DeviceOwned, Features, QueueFlags, Queue};
|
|
||||||
use vulkano::format::Format;
|
|
||||||
|
|
||||||
use vulkano::image::view::ImageViewCreateInfo;
|
|
||||||
use vulkano::image::{AttachmentImage, SampleCount};
|
|
||||||
use vulkano::memory::allocator::{MemoryAllocatePreference, MemoryUsage, StandardMemoryAllocator};
|
|
||||||
use vulkano::pipeline::graphics::depth_stencil::DepthStencilState;
|
|
||||||
use vulkano::pipeline::graphics::multisample::MultisampleState;
|
|
||||||
use vulkano::pipeline::graphics::rasterization::CullMode;
|
|
||||||
use vulkano::pipeline::graphics::rasterization::FrontFace::Clockwise;
|
|
||||||
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
|
||||||
use vulkano::pipeline::PipelineBindPoint;
|
|
||||||
use vulkano::shader::{ShaderModule, SpecializationConstants};
|
|
||||||
use vulkano::swapchain::{PresentMode, SwapchainPresentInfo};
|
|
||||||
use vulkano::VulkanLibrary;
|
|
||||||
use winit::event::{DeviceEvent, ElementState, MouseButton, VirtualKeyCode};
|
|
||||||
|
|
||||||
use egui_winit_vulkano::{Gui,GuiConfig};
|
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use vulkano::pipeline::StateMode::Fixed;
|
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
buffer::BufferUsage,
|
buffer::{
|
||||||
|
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
|
||||||
|
Buffer, BufferAllocateInfo, BufferUsage, Subbuffer,
|
||||||
|
},
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
AutoCommandBufferBuilder, CommandBufferUsage, RenderPassBeginInfo, SubpassContents,
|
allocator::StandardCommandBufferAllocator, AutoCommandBufferBuilder, CommandBufferUsage,
|
||||||
|
CopyBufferInfo, PrimaryCommandBufferAbstract, RenderPassBeginInfo, SubpassContents,
|
||||||
|
},
|
||||||
|
descriptor_set::{
|
||||||
|
allocator::StandardDescriptorSetAllocator, PersistentDescriptorSet, WriteDescriptorSet,
|
||||||
},
|
},
|
||||||
device::{
|
device::{
|
||||||
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, QueueCreateInfo,
|
physical::PhysicalDeviceType, Device, DeviceCreateInfo, DeviceExtensions, DeviceOwned,
|
||||||
|
Features, Queue, QueueCreateInfo, QueueFlags,
|
||||||
|
},
|
||||||
|
format::Format,
|
||||||
|
image::{
|
||||||
|
view::{ImageView, ImageViewCreateInfo},
|
||||||
|
AttachmentImage, ImageAccess, ImageUsage, SampleCount, SwapchainImage,
|
||||||
},
|
},
|
||||||
image::{view::ImageView, ImageAccess, ImageUsage, SwapchainImage},
|
|
||||||
instance::{Instance, InstanceCreateInfo, InstanceExtensions},
|
instance::{Instance, InstanceCreateInfo, InstanceExtensions},
|
||||||
|
memory::allocator::{MemoryAllocatePreference, MemoryUsage, StandardMemoryAllocator},
|
||||||
pipeline::{
|
pipeline::{
|
||||||
graphics::{
|
graphics::{
|
||||||
|
depth_stencil::DepthStencilState,
|
||||||
input_assembly::InputAssemblyState,
|
input_assembly::InputAssemblyState,
|
||||||
rasterization::RasterizationState,
|
multisample::MultisampleState,
|
||||||
|
rasterization::{CullMode, FrontFace::Clockwise, RasterizationState},
|
||||||
|
vertex_input::Vertex,
|
||||||
viewport::{Viewport, ViewportState},
|
viewport::{Viewport, ViewportState},
|
||||||
},
|
},
|
||||||
GraphicsPipeline, Pipeline,
|
GraphicsPipeline, Pipeline, PipelineBindPoint,
|
||||||
|
StateMode::Fixed,
|
||||||
},
|
},
|
||||||
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
|
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
|
||||||
|
shader::{ShaderModule, SpecializationConstants},
|
||||||
swapchain::{
|
swapchain::{
|
||||||
acquire_next_image, AcquireError, Swapchain, SwapchainCreateInfo, SwapchainCreationError,
|
acquire_next_image, AcquireError, PresentMode, Swapchain, SwapchainCreateInfo,
|
||||||
|
SwapchainCreationError, SwapchainPresentInfo,
|
||||||
},
|
},
|
||||||
sync::{self, FlushError, GpuFuture},
|
sync::{self, FlushError, GpuFuture},
|
||||||
|
VulkanLibrary,
|
||||||
};
|
};
|
||||||
use vulkano_win::VkSurfaceBuild;
|
use vulkano_win::VkSurfaceBuild;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{Event, WindowEvent},
|
event::{DeviceEvent, ElementState, Event, MouseButton, VirtualKeyCode, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
window::{Window, WindowBuilder},
|
window::{Window, WindowBuilder},
|
||||||
};
|
};
|
||||||
@@ -67,8 +60,7 @@ use winit::{
|
|||||||
mod gui;
|
mod gui;
|
||||||
use crate::gui::*;
|
use crate::gui::*;
|
||||||
mod objects;
|
mod objects;
|
||||||
use crate::interpreter::Interpreter;
|
use crate::{interpreter::Interpreter, objects::*};
|
||||||
use crate::objects::*;
|
|
||||||
mod mcsg_deserialise;
|
mod mcsg_deserialise;
|
||||||
|
|
||||||
mod instruction_set {
|
mod instruction_set {
|
||||||
@@ -91,7 +83,8 @@ fn main() {
|
|||||||
enabled_extensions: InstanceExtensions {
|
enabled_extensions: InstanceExtensions {
|
||||||
..required_extensions
|
..required_extensions
|
||||||
},
|
},
|
||||||
// Enable enumerating devices that use non-conformant vulkan implementations. (ex. MoltenVK)
|
// Enable enumerating devices that use non-conformant vulkan implementations. (ex.
|
||||||
|
// MoltenVK)
|
||||||
enumerate_portability: true,
|
enumerate_portability: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
@@ -122,21 +115,23 @@ fn main() {
|
|||||||
.position(|(i, q)| {
|
.position(|(i, q)| {
|
||||||
q.queue_flags.intersects(QueueFlags::GRAPHICS)
|
q.queue_flags.intersects(QueueFlags::GRAPHICS)
|
||||||
&& p.surface_support(i as u32, &surface).unwrap_or(false)
|
&& p.surface_support(i as u32, &surface).unwrap_or(false)
|
||||||
}).and_then( | graphics| {
|
})
|
||||||
|
.and_then(|graphics| {
|
||||||
p.queue_family_properties()
|
p.queue_family_properties()
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.position(|(i, q)| {
|
.position(|(i, q)| {
|
||||||
q.queue_flags.intersects(QueueFlags::TRANSFER) && i != graphics
|
q.queue_flags.intersects(QueueFlags::TRANSFER) && i != graphics
|
||||||
}).or_else( || {
|
})
|
||||||
p.queue_family_properties()
|
.or_else(|| {
|
||||||
.iter()
|
p.queue_family_properties()
|
||||||
.enumerate()
|
.iter()
|
||||||
.position(|(_i, q)| {
|
.enumerate()
|
||||||
q.queue_flags.intersects(QueueFlags::TRANSFER)
|
.position(|(_i, q)| q.queue_flags.intersects(QueueFlags::TRANSFER))
|
||||||
})}
|
})
|
||||||
|
.map(|i| (graphics as u32, i as u32))
|
||||||
).map(|i| (graphics as u32, i as u32))}).map(|i| (p, i))
|
})
|
||||||
|
.map(|i| (p, i))
|
||||||
})
|
})
|
||||||
.min_by_key(|(p, _)| {
|
.min_by_key(|(p, _)| {
|
||||||
// We assign a lower score to device types that are likely to be faster/better.
|
// We assign a lower score to device types that are likely to be faster/better.
|
||||||
@@ -149,7 +144,10 @@ fn main() {
|
|||||||
_ => 5,
|
_ => 5,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.expect("No suitable physical device found. Do you have a Mesh Shader capable GPU and are your drivers up to date?");
|
.expect(
|
||||||
|
"No suitable physical device found. Do you have a Mesh Shader capable GPU and are \
|
||||||
|
your drivers up to date?",
|
||||||
|
);
|
||||||
|
|
||||||
// Some little debug infos.
|
// Some little debug infos.
|
||||||
println!(
|
println!(
|
||||||
@@ -162,14 +160,16 @@ fn main() {
|
|||||||
physical_device,
|
physical_device,
|
||||||
DeviceCreateInfo {
|
DeviceCreateInfo {
|
||||||
enabled_extensions: device_extensions,
|
enabled_extensions: device_extensions,
|
||||||
queue_create_infos: vec![QueueCreateInfo {
|
queue_create_infos: vec![
|
||||||
queue_family_index,
|
QueueCreateInfo {
|
||||||
..Default::default()
|
queue_family_index,
|
||||||
},
|
..Default::default()
|
||||||
QueueCreateInfo {
|
},
|
||||||
queue_family_index: transfer_index,
|
QueueCreateInfo {
|
||||||
..Default::default()
|
queue_family_index: transfer_index,
|
||||||
}],
|
..Default::default()
|
||||||
|
},
|
||||||
|
],
|
||||||
enabled_features: Features {
|
enabled_features: Features {
|
||||||
mesh_shader: true,
|
mesh_shader: true,
|
||||||
task_shader: true,
|
task_shader: true,
|
||||||
@@ -285,7 +285,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod cs {
|
mod cs {
|
||||||
vulkano_shaders::shader!{
|
vulkano_shaders::shader! {
|
||||||
ty: "compute",
|
ty: "compute",
|
||||||
path: "src/fuzz.comp.glsl",
|
path: "src/fuzz.comp.glsl",
|
||||||
vulkan_version: "1.2",
|
vulkan_version: "1.2",
|
||||||
@@ -294,7 +294,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let loaders: Vec<
|
let loaders: Vec<
|
||||||
fn(
|
fn(
|
||||||
::std::sync::Arc<::vulkano::device::Device>,
|
::std::sync::Arc<::vulkano::device::Device>,
|
||||||
@@ -366,11 +365,11 @@ fn main() {
|
|||||||
use vulkano::pipeline::ComputePipeline;
|
use vulkano::pipeline::ComputePipeline;
|
||||||
|
|
||||||
let compute_pipeline = ComputePipeline::new(
|
let compute_pipeline = ComputePipeline::new(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
compute_shader.entry_point("main").unwrap(),
|
compute_shader.entry_point("main").unwrap(),
|
||||||
&(),
|
&(),
|
||||||
None,
|
None,
|
||||||
|_| {},
|
|_| {},
|
||||||
)
|
)
|
||||||
.expect("failed to create compute pipeline");
|
.expect("failed to create compute pipeline");
|
||||||
|
|
||||||
@@ -412,8 +411,8 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut viewport = Viewport {
|
let mut viewport = Viewport {
|
||||||
origin: [0.0, 0.0],
|
origin: [0.0, 0.0],
|
||||||
dimensions: [0.0, 0.0],
|
dimensions: [0.0, 0.0],
|
||||||
depth_range: 0.0..1.0,
|
depth_range: 0.0..1.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -431,14 +430,19 @@ fn main() {
|
|||||||
&images,
|
&images,
|
||||||
render_pass.clone(),
|
render_pass.clone(),
|
||||||
&mut viewport,
|
&mut viewport,
|
||||||
|
implicit_fs::SpecializationConstants {
|
||||||
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32,
|
DISABLE_TRACE: gstate.debug.bounding_boxes as u32,
|
||||||
BRUTE_FORCE:gstate.debug.brute_force as u32,},
|
BRUTE_FORCE: gstate.debug.brute_force as u32,
|
||||||
implicit_ms::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_meshcull as u32,
|
},
|
||||||
DISABLE_SCALING_1:gstate.debug.disable_meshscale1 as u32,
|
implicit_ms::SpecializationConstants {
|
||||||
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32,
|
DISABLE_TRACE: gstate.debug.disable_meshcull as u32,
|
||||||
BRUTE_FORCE:gstate.debug.brute_force as u32,},
|
DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32,
|
||||||
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull as u32},
|
DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32,
|
||||||
|
BRUTE_FORCE: gstate.debug.brute_force as u32,
|
||||||
|
},
|
||||||
|
implicit_ts::SpecializationConstants {
|
||||||
|
DISABLE_TRACE: gstate.debug.disable_taskcull as u32,
|
||||||
|
},
|
||||||
gstate.debug.brute_force,
|
gstate.debug.brute_force,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -466,9 +470,9 @@ fn main() {
|
|||||||
Subpass::from(render_pass.clone(), 1).unwrap(),
|
Subpass::from(render_pass.clone(), 1).unwrap(),
|
||||||
GuiConfig {
|
GuiConfig {
|
||||||
preferred_format: Some(images[0].format()),
|
preferred_format: Some(images[0].format()),
|
||||||
is_overlay: true,
|
is_overlay: true,
|
||||||
samples: SampleCount::Sample4
|
samples: SampleCount::Sample4,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut campos = Point3 {
|
let mut campos = Point3 {
|
||||||
@@ -518,7 +522,14 @@ fn main() {
|
|||||||
.lights
|
.lights
|
||||||
.push(Light::new([-4., 6., -8.], [8., 4., 1.], 0.05));
|
.push(Light::new([-4., 6., -8.], [8., 4., 1.], 0.05));
|
||||||
|
|
||||||
let subbuffers = object_size_dependent_setup(memory_allocator.clone(), &gstate.csg, &command_buffer_allocator, transfer_queue.clone(), None, false);
|
let subbuffers = object_size_dependent_setup(
|
||||||
|
memory_allocator.clone(),
|
||||||
|
&gstate.csg,
|
||||||
|
&command_buffer_allocator,
|
||||||
|
transfer_queue.clone(),
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
|
||||||
let mut prevdub = PreviousDebug::default();
|
let mut prevdub = PreviousDebug::default();
|
||||||
|
|
||||||
@@ -530,16 +541,16 @@ fn main() {
|
|||||||
match &we {
|
match &we {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
*control_flow = ControlFlow::Exit;
|
*control_flow = ControlFlow::Exit;
|
||||||
}
|
},
|
||||||
WindowEvent::Resized(_) => {
|
WindowEvent::Resized(_) => {
|
||||||
recreate_swapchain = true;
|
recreate_swapchain = true;
|
||||||
}
|
},
|
||||||
WindowEvent::ScaleFactorChanged { .. } => {
|
WindowEvent::ScaleFactorChanged { .. } => {
|
||||||
recreate_swapchain = true;
|
recreate_swapchain = true;
|
||||||
}
|
},
|
||||||
WindowEvent::DroppedFile(_file) => {
|
WindowEvent::DroppedFile(_file) => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
},
|
||||||
WindowEvent::MouseInput {
|
WindowEvent::MouseInput {
|
||||||
device_id: d,
|
device_id: d,
|
||||||
state: s,
|
state: s,
|
||||||
@@ -550,23 +561,23 @@ fn main() {
|
|||||||
if b == &MouseButton::Right {
|
if b == &MouseButton::Right {
|
||||||
looking = s == &ElementState::Pressed;
|
looking = s == &ElementState::Pressed;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
|
WindowEvent::KeyboardInput { input, .. } => match input.virtual_keycode {
|
||||||
Some(VirtualKeyCode::W) => {
|
Some(VirtualKeyCode::W) => {
|
||||||
keys.w = input.state == ElementState::Pressed;
|
keys.w = input.state == ElementState::Pressed;
|
||||||
}
|
},
|
||||||
Some(VirtualKeyCode::S) => {
|
Some(VirtualKeyCode::S) => {
|
||||||
keys.s = input.state == ElementState::Pressed;
|
keys.s = input.state == ElementState::Pressed;
|
||||||
}
|
},
|
||||||
Some(VirtualKeyCode::A) => {
|
Some(VirtualKeyCode::A) => {
|
||||||
keys.a = input.state == ElementState::Pressed;
|
keys.a = input.state == ElementState::Pressed;
|
||||||
}
|
},
|
||||||
Some(VirtualKeyCode::D) => {
|
Some(VirtualKeyCode::D) => {
|
||||||
keys.d = input.state == ElementState::Pressed;
|
keys.d = input.state == ElementState::Pressed;
|
||||||
}
|
},
|
||||||
_ => {}
|
_ => {},
|
||||||
},
|
},
|
||||||
_ => {}
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,7 +592,7 @@ fn main() {
|
|||||||
camforward.x += Deg(360f32) % Deg(360f32);
|
camforward.x += Deg(360f32) % Deg(360f32);
|
||||||
camforward.y += Deg(360f32) % Deg(360f32);
|
camforward.y += Deg(360f32) % Deg(360f32);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
Event::RedrawEventsCleared => {
|
Event::RedrawEventsCleared => {
|
||||||
for i in 1..gstate.fps.len() {
|
for i in 1..gstate.fps.len() {
|
||||||
gstate.fps[i - 1] = gstate.fps[i];
|
gstate.fps[i - 1] = gstate.fps[i];
|
||||||
@@ -628,13 +639,19 @@ fn main() {
|
|||||||
&new_images,
|
&new_images,
|
||||||
render_pass.clone(),
|
render_pass.clone(),
|
||||||
&mut viewport,
|
&mut viewport,
|
||||||
implicit_fs::SpecializationConstants {DISABLE_TRACE:gstate.debug.bounding_boxes as u32,
|
implicit_fs::SpecializationConstants {
|
||||||
BRUTE_FORCE:gstate.debug.brute_force as u32},
|
DISABLE_TRACE: gstate.debug.bounding_boxes as u32,
|
||||||
implicit_ms::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_meshcull as u32,
|
BRUTE_FORCE: gstate.debug.brute_force as u32,
|
||||||
DISABLE_SCALING_1:gstate.debug.disable_meshscale1 as u32,
|
},
|
||||||
DISABLE_SCALING_2:gstate.debug.disable_meshscale2 as u32,
|
implicit_ms::SpecializationConstants {
|
||||||
BRUTE_FORCE:gstate.debug.brute_force as u32},
|
DISABLE_TRACE: gstate.debug.disable_meshcull as u32,
|
||||||
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull as u32},
|
DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32,
|
||||||
|
DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32,
|
||||||
|
BRUTE_FORCE: gstate.debug.brute_force as u32,
|
||||||
|
},
|
||||||
|
implicit_ts::SpecializationConstants {
|
||||||
|
DISABLE_TRACE: gstate.debug.disable_taskcull as u32,
|
||||||
|
},
|
||||||
gstate.debug.brute_force,
|
gstate.debug.brute_force,
|
||||||
);
|
);
|
||||||
recreate_swapchain = false;
|
recreate_swapchain = false;
|
||||||
@@ -698,8 +715,8 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let uniform_data = implicit_fs::Camera {
|
let uniform_data = implicit_fs::Camera {
|
||||||
view: view.into(),
|
view: view.into(),
|
||||||
proj: proj.into(),
|
proj: proj.into(),
|
||||||
campos: (campos).into(),
|
campos: (campos).into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -774,35 +791,78 @@ fn main() {
|
|||||||
const COMPUTE_FUZZING: bool = false;
|
const COMPUTE_FUZZING: bool = false;
|
||||||
|
|
||||||
if COMPUTE_FUZZING {
|
if COMPUTE_FUZZING {
|
||||||
|
|
||||||
let mut fake_csg = vec![];
|
let mut fake_csg = vec![];
|
||||||
for i in 0..32
|
for i in 0..32 {
|
||||||
{
|
fake_csg.push(CSG {
|
||||||
fake_csg.push(
|
name: format!("fuzz_{i}"),
|
||||||
CSG{ name: format!("fuzz_{i}"), parts: vec![
|
parts: vec![
|
||||||
CSGPart::opcode(InstructionSet::OPMulVec3Float, vec![Inputs::Variable, Inputs::Float(0.9)]),
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPMulVec3Float,
|
||||||
|
vec![Inputs::Variable, Inputs::Float(0.9)],
|
||||||
|
),
|
||||||
CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
||||||
CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.7, (i as f64), -0.7].into())]),
|
CSGPart::opcode(
|
||||||
CSGPart::opcode(InstructionSet::OPSDFSphere,vec![Inputs::Float(0.5), Inputs::Variable]),
|
InstructionSet::OPAddVec3Vec3,
|
||||||
|
vec![
|
||||||
|
Inputs::Variable,
|
||||||
|
Inputs::Vec3([-0.7, (i as f64), -0.7].into()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPSDFSphere,
|
||||||
|
vec![Inputs::Float(0.5), Inputs::Variable],
|
||||||
|
),
|
||||||
//CSGPart::opcode(InstructionSet::OPNop,vec![]),
|
//CSGPart::opcode(InstructionSet::OPNop,vec![]),
|
||||||
//CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
//CSGPart::opcode(InstructionSet::OPDupVec3,
|
||||||
//CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.2, -0.2, -0.2].into())]),
|
// vec![Inputs::Variable]),
|
||||||
//CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.0, -0.0, -0.0].into())]),
|
// CSGPart::opcode(InstructionSet::OPAddVec3Vec3,
|
||||||
CSGPart::opcode(InstructionSet::OPSDFSphere,vec![Inputs::Float(1.2), Inputs::Variable]),
|
// vec![Inputs::Variable, Inputs::Vec3([-0.2, -0.2,
|
||||||
//CSGPart::opcode(InstructionSet::OPSDFBox, vec![Inputs::Variable, Inputs::Vec3([0.7, 0.7, 0.7].into())]),
|
// -0.2].into())]),
|
||||||
CSGPart::opcode(InstructionSet::OPMinFloat, vec![Inputs::Variable,Inputs::Variable]),
|
// CSGPart::opcode(InstructionSet::OPAddVec3Vec3,
|
||||||
CSGPart::opcode(InstructionSet::OPDivFloatFloat, vec![Inputs::Variable, Inputs::Float(0.9)]),
|
// vec![Inputs::Variable, Inputs::Vec3([-0.0, -0.0,
|
||||||
|
// -0.0].into())]),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPSDFSphere,
|
||||||
|
vec![Inputs::Float(1.2), Inputs::Variable],
|
||||||
|
),
|
||||||
|
//CSGPart::opcode(InstructionSet::OPSDFBox, vec![Inputs::Variable,
|
||||||
|
// Inputs::Vec3([0.7, 0.7, 0.7].into())]),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPMinFloat,
|
||||||
|
vec![Inputs::Variable, Inputs::Variable],
|
||||||
|
),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPDivFloatFloat,
|
||||||
|
vec![Inputs::Variable, Inputs::Float(0.9)],
|
||||||
|
),
|
||||||
CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]),
|
CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]),
|
||||||
], pos: Point3::origin(), rot: Euler { x: Deg(0.), y: Deg(0.), z: Deg(0.) }, scale: Vector3 { x: 1., y: 1., z: 1. } }
|
],
|
||||||
)
|
pos: Point3::origin(),
|
||||||
|
rot: Euler {
|
||||||
|
x: Deg(0.),
|
||||||
|
y: Deg(0.),
|
||||||
|
z: Deg(0.),
|
||||||
|
},
|
||||||
|
scale: Vector3 {
|
||||||
|
x: 1.,
|
||||||
|
y: 1.,
|
||||||
|
z: 1.,
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let compute_subbuffers = object_size_dependent_setup(memory_allocator.clone(), &fake_csg, &command_buffer_allocator, transfer_queue.clone(), Some(
|
let compute_subbuffers = object_size_dependent_setup(
|
||||||
[1.,1.,1.,1.,5.,1.]
|
memory_allocator.clone(),
|
||||||
),true);
|
&fake_csg,
|
||||||
|
&command_buffer_allocator,
|
||||||
let compute_result_buffer:Subbuffer<[cs::Results]> = uniform_buffer.allocate_slice((fake_csg.len()+1) as u64).unwrap();
|
transfer_queue.clone(),
|
||||||
|
Some([1., 1., 1., 1., 5., 1.]),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
let compute_result_buffer: Subbuffer<[cs::Results]> = uniform_buffer
|
||||||
|
.allocate_slice((fake_csg.len() + 1) as u64)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let compute_layout = compute_pipeline.layout().set_layouts().get(0).unwrap();
|
let compute_layout = compute_pipeline.layout().set_layouts().get(0).unwrap();
|
||||||
let compute_set = PersistentDescriptorSet::new(
|
let compute_set = PersistentDescriptorSet::new(
|
||||||
@@ -823,7 +883,8 @@ fn main() {
|
|||||||
//WriteDescriptorSet::buffer(11, compute_subbuffers.mats.clone()),
|
//WriteDescriptorSet::buffer(11, compute_subbuffers.mats.clone()),
|
||||||
WriteDescriptorSet::buffer(12, compute_subbuffers.deps),
|
WriteDescriptorSet::buffer(12, compute_subbuffers.deps),
|
||||||
//WriteDescriptorSet::buffer(20, compute_subbuffers.masks.clone()),
|
//WriteDescriptorSet::buffer(20, compute_subbuffers.masks.clone()),
|
||||||
WriteDescriptorSet::buffer(30, compute_result_buffer.clone()),],
|
WriteDescriptorSet::buffer(30, compute_result_buffer.clone()),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -856,9 +917,9 @@ fn main() {
|
|||||||
future.wait(None).unwrap();
|
future.wait(None).unwrap();
|
||||||
|
|
||||||
let content = compute_result_buffer.read().unwrap();
|
let content = compute_result_buffer.read().unwrap();
|
||||||
for (val,csg) in content.iter().zip(fake_csg.iter()) {
|
for (val, csg) in content.iter().zip(fake_csg.iter()) {
|
||||||
println!("{val:?}");
|
println!("{val:?}");
|
||||||
let expected = Interpreter::new(csg).scene(Vector3::new(1.,1.,1.)) as f32;
|
let expected = Interpreter::new(csg).scene(Vector3::new(1., 1., 1.)) as f32;
|
||||||
if expected != val.f[0] {
|
if expected != val.f[0] {
|
||||||
println!("ERROR: expected {}, got {}", expected, val.f[0]);
|
println!("ERROR: expected {}, got {}", expected, val.f[0]);
|
||||||
}
|
}
|
||||||
@@ -871,7 +932,7 @@ fn main() {
|
|||||||
Err(AcquireError::OutOfDate) => {
|
Err(AcquireError::OutOfDate) => {
|
||||||
recreate_swapchain = true;
|
recreate_swapchain = true;
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
Err(e) => panic!("Failed to acquire next image: {e:?}"),
|
Err(e) => panic!("Failed to acquire next image: {e:?}"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -982,24 +1043,25 @@ fn main() {
|
|||||||
match future {
|
match future {
|
||||||
Ok(future) => {
|
Ok(future) => {
|
||||||
previous_frame_end = Some(future.boxed());
|
previous_frame_end = Some(future.boxed());
|
||||||
}
|
},
|
||||||
Err(FlushError::OutOfDate) => {
|
Err(FlushError::OutOfDate) => {
|
||||||
recreate_swapchain = true;
|
recreate_swapchain = true;
|
||||||
previous_frame_end = Some(sync::now(device.clone()).boxed());
|
previous_frame_end = Some(sync::now(device.clone()).boxed());
|
||||||
}
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to flush future: {e:?}");
|
println!("Failed to flush future: {e:?}");
|
||||||
previous_frame_end = Some(sync::now(device.clone()).boxed());
|
previous_frame_end = Some(sync::now(device.clone()).boxed());
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This method is called once during initialization, then again whenever the window is resized
|
/// This method is called once during initialization, then again whenever the
|
||||||
fn window_size_dependent_setup<Fs,Ms,Ts>(
|
/// window is resized
|
||||||
|
fn window_size_dependent_setup<Fs, Ms, Ts>(
|
||||||
allocator: &StandardMemoryAllocator,
|
allocator: &StandardMemoryAllocator,
|
||||||
mesh_vs: &ShaderModule,
|
mesh_vs: &ShaderModule,
|
||||||
mesh_fs: &ShaderModule,
|
mesh_fs: &ShaderModule,
|
||||||
@@ -1079,8 +1141,8 @@ where
|
|||||||
.vertex_shader(mesh_vs.entry_point("main").unwrap(), ())
|
.vertex_shader(mesh_vs.entry_point("main").unwrap(), ())
|
||||||
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
|
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
|
||||||
Viewport {
|
Viewport {
|
||||||
origin: [0.0, 0.0],
|
origin: [0.0, 0.0],
|
||||||
dimensions: [dimensions[0] as f32, dimensions[1] as f32],
|
dimensions: [dimensions[0] as f32, dimensions[1] as f32],
|
||||||
depth_range: 0.0..1.0,
|
depth_range: 0.0..1.0,
|
||||||
},
|
},
|
||||||
]))
|
]))
|
||||||
@@ -1109,8 +1171,8 @@ where
|
|||||||
.input_assembly_state(InputAssemblyState::new())
|
.input_assembly_state(InputAssemblyState::new())
|
||||||
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
|
.viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([
|
||||||
Viewport {
|
Viewport {
|
||||||
origin: [0.0, 0.0],
|
origin: [0.0, 0.0],
|
||||||
dimensions: [dimensions[0] as f32, dimensions[1] as f32],
|
dimensions: [dimensions[0] as f32, dimensions[1] as f32],
|
||||||
depth_range: 0.0..1.0,
|
depth_range: 0.0..1.0,
|
||||||
},
|
},
|
||||||
]))
|
]))
|
||||||
@@ -1131,43 +1193,40 @@ where
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let built_implicit_pipeline =
|
let built_implicit_pipeline = if !brute_force {
|
||||||
if !brute_force {
|
implicit_pipeline
|
||||||
implicit_pipeline.task_shader(implicit_ts.entry_point("main").unwrap(),implicit_ts_specs)
|
.task_shader(implicit_ts.entry_point("main").unwrap(), implicit_ts_specs)
|
||||||
.build(allocator.device().clone())
|
.build(allocator.device().clone())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
} else {
|
} else {
|
||||||
implicit_pipeline
|
implicit_pipeline.build(allocator.device().clone()).unwrap()
|
||||||
.build(allocator.device().clone())
|
};
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Implicit pipeline compiled");
|
println!("Implicit pipeline compiled");
|
||||||
|
|
||||||
([mesh_pipeline, built_implicit_pipeline], framebuffers)
|
([mesh_pipeline, built_implicit_pipeline], framebuffers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone,Copy,Pod,Zeroable, Default, Debug)]
|
#[derive(Clone, Copy, Pod, Zeroable, Default, Debug)]
|
||||||
struct Description {
|
struct Description {
|
||||||
pointers: [u32; 9],
|
pointers: [u32; 9],
|
||||||
bounds: [f32;6],
|
bounds: [f32; 6],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Subbuffers {
|
struct Subbuffers {
|
||||||
masks: Subbuffer<[[u8; 29]]>,
|
masks: Subbuffer<[[u8; 29]]>,
|
||||||
floats: Subbuffer<[f32]>,
|
floats: Subbuffer<[f32]>,
|
||||||
vec2s: Subbuffer<[[f32; 2]]>,
|
vec2s: Subbuffer<[[f32; 2]]>,
|
||||||
//vec3s: Subbuffer<[[f32; 4]]>,
|
//vec3s: Subbuffer<[[f32; 4]]>,
|
||||||
vec4s: Subbuffer<[[f32; 4]]>,
|
vec4s: Subbuffer<[[f32; 4]]>,
|
||||||
mat2s: Subbuffer<[[[f32; 2]; 2]]>,
|
mat2s: Subbuffer<[[[f32; 2]; 2]]>,
|
||||||
mat3s: Subbuffer<[[[f32; 3]; 3]]>,
|
mat3s: Subbuffer<[[[f32; 3]; 3]]>,
|
||||||
mat4s: Subbuffer<[[[f32; 4]; 4]]>,
|
mat4s: Subbuffer<[[[f32; 4]; 4]]>,
|
||||||
mats: Subbuffer<[[[f32; 4]; 4]]>,
|
mats: Subbuffer<[[[f32; 4]; 4]]>,
|
||||||
scene: Subbuffer<[[u32; 4]]>,
|
scene: Subbuffer<[[u32; 4]]>,
|
||||||
deps: Subbuffer<[[u8; 2]]>,
|
deps: Subbuffer<[[u8; 2]]>,
|
||||||
desc: Subbuffer<[Description]>,
|
desc: Subbuffer<[Description]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq<InputTypes> for Inputs {
|
impl PartialEq<InputTypes> for Inputs {
|
||||||
@@ -1193,7 +1252,7 @@ fn gpu_buffer<T>(
|
|||||||
transfer_queue: Arc<Queue>,
|
transfer_queue: Arc<Queue>,
|
||||||
) -> Subbuffer<[T]>
|
) -> Subbuffer<[T]>
|
||||||
where
|
where
|
||||||
T: bytemuck::Pod + Send + Sync
|
T: bytemuck::Pod + Send + Sync,
|
||||||
{
|
{
|
||||||
let buffer = Buffer::new_slice(
|
let buffer = Buffer::new_slice(
|
||||||
allocator,
|
allocator,
|
||||||
@@ -1216,32 +1275,29 @@ where
|
|||||||
CommandBufferUsage::OneTimeSubmit,
|
CommandBufferUsage::OneTimeSubmit,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
builder.copy_buffer(CopyBufferInfo::buffers(
|
builder
|
||||||
staging,
|
.copy_buffer(CopyBufferInfo::buffers(staging, buffer.clone()))
|
||||||
buffer.clone())
|
.unwrap();
|
||||||
).unwrap();
|
|
||||||
let commands = builder.build().unwrap();
|
let commands = builder.build().unwrap();
|
||||||
|
|
||||||
commands.execute(transfer_queue)
|
commands
|
||||||
.unwrap()
|
.execute(transfer_queue)
|
||||||
.then_signal_fence_and_flush()
|
.unwrap()
|
||||||
.unwrap()
|
.then_signal_fence_and_flush()
|
||||||
.wait(None)
|
.unwrap()
|
||||||
.unwrap();
|
.wait(None)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f64tof32<const A:usize>(input: [[f64;A];A]) -> [[f32;A];A]
|
fn f64tof32<const A: usize>(input: [[f64; A]; A]) -> [[f32; A]; A] {
|
||||||
{
|
let mut out = [[0_f32; A]; A];
|
||||||
let mut out = [[0_f32;A];A];
|
for x in 0..input.len() {
|
||||||
for x in 0..input.len()
|
for y in 0..input.len() {
|
||||||
{
|
out[x][y] = input[x][y] as f32;
|
||||||
for y in 0..input.len()
|
}
|
||||||
{
|
|
||||||
out[x][y] = input[x][y] as f32;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1250,7 +1306,7 @@ fn object_size_dependent_setup(
|
|||||||
state: &Vec<CSG>,
|
state: &Vec<CSG>,
|
||||||
command_allocator: &StandardCommandBufferAllocator,
|
command_allocator: &StandardCommandBufferAllocator,
|
||||||
queue: Arc<Queue>,
|
queue: Arc<Queue>,
|
||||||
set_bound: Option<[f32;6]>,
|
set_bound: Option<[f32; 6]>,
|
||||||
actual: bool,
|
actual: bool,
|
||||||
) -> Subbuffers {
|
) -> Subbuffers {
|
||||||
let mut floats: Vec<f32> = vec![Default::default()];
|
let mut floats: Vec<f32> = vec![Default::default()];
|
||||||
@@ -1280,23 +1336,45 @@ fn object_size_dependent_setup(
|
|||||||
];
|
];
|
||||||
|
|
||||||
let example = vec![
|
let example = vec![
|
||||||
CSGPart::opcode(InstructionSet::OPMulVec3Float, vec![Inputs::Variable, Inputs::Float(0.9)]),
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPMulVec3Float,
|
||||||
|
vec![Inputs::Variable, Inputs::Float(0.9)],
|
||||||
|
),
|
||||||
CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
||||||
CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.7, -1.2, -0.7].into())]),
|
CSGPart::opcode(
|
||||||
CSGPart::opcode(InstructionSet::OPSDFSphere,vec![Inputs::Float(0.5), Inputs::Variable]),
|
InstructionSet::OPAddVec3Vec3,
|
||||||
|
vec![Inputs::Variable, Inputs::Vec3([-0.7, -1.2, -0.7].into())],
|
||||||
|
),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPSDFSphere,
|
||||||
|
vec![Inputs::Float(0.5), Inputs::Variable],
|
||||||
|
),
|
||||||
//CSGPart::opcode(InstructionSet::OPNop,vec![]),
|
//CSGPart::opcode(InstructionSet::OPNop,vec![]),
|
||||||
//CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
//CSGPart::opcode(InstructionSet::OPDupVec3, vec![Inputs::Variable]),
|
||||||
//CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.2, -0.2, -0.2].into())]),
|
//CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable,
|
||||||
//CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable, Inputs::Vec3([-0.0, -0.0, -0.0].into())]),
|
// Inputs::Vec3([-0.2, -0.2, -0.2].into())]),
|
||||||
//CSGPart::opcode(InstructionSet::OPSDFSphere,vec![Inputs::Float(1.2), Inputs::Variable]),
|
// CSGPart::opcode(InstructionSet::OPAddVec3Vec3, vec![Inputs::Variable,
|
||||||
CSGPart::opcode(InstructionSet::OPSDFTorus, vec![Inputs::Vec2([0.7, 0.4].into()), Inputs::Variable]),
|
// Inputs::Vec3([-0.0, -0.0, -0.0].into())]),
|
||||||
//CSGPart::opcode(InstructionSet::OPSDFBox, vec![Inputs::Vec3([0.7, 0.4, 0.7].into()), Inputs::Variable]),
|
// CSGPart::opcode(InstructionSet::OPSDFSphere,vec![Inputs::Float(1.2),
|
||||||
CSGPart::opcode(InstructionSet::OPMinFloat, vec![Inputs::Variable,Inputs::Variable]),
|
// Inputs::Variable]),
|
||||||
CSGPart::opcode(InstructionSet::OPDivFloatFloat, vec![Inputs::Variable, Inputs::Float(0.9)]),
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPSDFTorus,
|
||||||
|
vec![Inputs::Vec2([0.7, 0.4].into()), Inputs::Variable],
|
||||||
|
),
|
||||||
|
//CSGPart::opcode(InstructionSet::OPSDFBox, vec![Inputs::Vec3([0.7, 0.4, 0.7].into()),
|
||||||
|
// Inputs::Variable]),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPMinFloat,
|
||||||
|
vec![Inputs::Variable, Inputs::Variable],
|
||||||
|
),
|
||||||
|
CSGPart::opcode(
|
||||||
|
InstructionSet::OPDivFloatFloat,
|
||||||
|
vec![Inputs::Variable, Inputs::Float(0.9)],
|
||||||
|
),
|
||||||
CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]),
|
CSGPart::opcode(InstructionSet::OPStop, vec![Inputs::Variable]),
|
||||||
];
|
];
|
||||||
|
|
||||||
let parts = if actual {&csg.parts} else {&example};
|
let parts = if actual { &csg.parts } else { &example };
|
||||||
|
|
||||||
let mut dependencies: Vec<[u8; 2]> = vec![];
|
let mut dependencies: Vec<[u8; 2]> = vec![];
|
||||||
for _ in 0..parts.len() {
|
for _ in 0..parts.len() {
|
||||||
@@ -1330,11 +1408,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on floats", csg.name);
|
eprintln!("csg {} underflowed on floats", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Vec2 => match runtime_vec2s.pop() {
|
InputTypes::Vec2 => match runtime_vec2s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1343,11 +1421,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on vec2s", csg.name);
|
eprintln!("csg {} underflowed on vec2s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Vec3 => match runtime_vec3s.pop() {
|
InputTypes::Vec3 => match runtime_vec3s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1358,11 +1436,11 @@ fn object_size_dependent_setup(
|
|||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on vec3s", csg.name);
|
eprintln!("csg {} underflowed on vec3s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Vec4 => match runtime_vec4s.pop() {
|
InputTypes::Vec4 => match runtime_vec4s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1371,11 +1449,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on vec4s", csg.name);
|
eprintln!("csg {} underflowed on vec4s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Mat2 => match runtime_mat2s.pop() {
|
InputTypes::Mat2 => match runtime_mat2s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1384,11 +1462,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on mat2s", csg.name);
|
eprintln!("csg {} underflowed on mat2s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Mat3 => match runtime_mat3s.pop() {
|
InputTypes::Mat3 => match runtime_mat3s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1397,11 +1475,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on mat3s", csg.name);
|
eprintln!("csg {} underflowed on mat3s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
InputTypes::Mat4 => match runtime_mat4s.pop() {
|
InputTypes::Mat4 => match runtime_mat4s.pop() {
|
||||||
Some(u) => {
|
Some(u) => {
|
||||||
@@ -1410,11 +1488,11 @@ fn object_size_dependent_setup(
|
|||||||
} else {
|
} else {
|
||||||
dependencies[u][0] = index as u8
|
dependencies[u][0] = index as u8
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("csg {} underflowed on mat4s", csg.name);
|
eprintln!("csg {} underflowed on mat4s", csg.name);
|
||||||
continue 'nextcsg;
|
continue 'nextcsg;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1467,29 +1545,40 @@ fn object_size_dependent_setup(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let temp_csg = &CSG { name: "test".to_string(), parts: parts.to_vec(), pos: Point3::origin(), rot: Euler::new(Deg(0.), Deg(0.), Deg(0.)), scale: Vector3 { x: 1., y: 1., z: 1. } };
|
let temp_csg = &CSG {
|
||||||
|
name: "test".to_string(),
|
||||||
|
parts: parts.to_vec(),
|
||||||
|
pos: Point3::origin(),
|
||||||
|
rot: Euler::new(Deg(0.), Deg(0.), Deg(0.)),
|
||||||
|
scale: Vector3 {
|
||||||
|
x: 1.,
|
||||||
|
y: 1.,
|
||||||
|
z: 1.,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let mut interpreter = interpreter::Interpreter::new( temp_csg);
|
let mut interpreter = interpreter::Interpreter::new(temp_csg);
|
||||||
const CLIPCHECK:Float =65536.;
|
const CLIPCHECK: Float = 65536.;
|
||||||
|
|
||||||
let bounds = set_bound.unwrap_or([
|
let bounds = set_bound.unwrap_or([
|
||||||
((CLIPCHECK-interpreter.scene(Vector3::new(CLIPCHECK,0.,0.)))*1.00001) as f32,
|
((CLIPCHECK - interpreter.scene(Vector3::new(CLIPCHECK, 0., 0.))) * 1.00001) as f32,
|
||||||
((CLIPCHECK-interpreter.scene(Vector3::new(0.,CLIPCHECK,0.)))*1.00001) as f32,
|
((CLIPCHECK - interpreter.scene(Vector3::new(0., CLIPCHECK, 0.))) * 1.00001) as f32,
|
||||||
((CLIPCHECK-interpreter.scene(Vector3::new(0.,0.,CLIPCHECK)))*1.00001) as f32,
|
((CLIPCHECK - interpreter.scene(Vector3::new(0., 0., CLIPCHECK))) * 1.00001) as f32,
|
||||||
((-CLIPCHECK+interpreter.scene(Vector3::new(-CLIPCHECK,0.,0.)))*1.00001) as f32,
|
((-CLIPCHECK + interpreter.scene(Vector3::new(-CLIPCHECK, 0., 0.))) * 1.00001) as f32,
|
||||||
((-CLIPCHECK+interpreter.scene(Vector3::new(0.,-CLIPCHECK,0.)))*1.00001) as f32,
|
((-CLIPCHECK + interpreter.scene(Vector3::new(0., -CLIPCHECK, 0.))) * 1.00001) as f32,
|
||||||
((-CLIPCHECK+interpreter.scene(Vector3::new(0.,0.,-CLIPCHECK)))*1.00001) as f32,
|
((-CLIPCHECK + interpreter.scene(Vector3::new(0., 0., -CLIPCHECK))) * 1.00001) as f32,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
//println!("bounds: {:?}",bounds);
|
//println!("bounds: {:?}",bounds);
|
||||||
|
|
||||||
desc.push(Description {pointers:to_push,bounds});
|
desc.push(Description {
|
||||||
|
pointers: to_push,
|
||||||
|
bounds,
|
||||||
|
});
|
||||||
|
|
||||||
scene.append(&mut data);
|
scene.append(&mut data);
|
||||||
|
|
||||||
deps.append(&mut dependencies);
|
deps.append(&mut dependencies);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("floats: {floats:?}");
|
println!("floats: {floats:?}");
|
||||||
@@ -1511,7 +1600,7 @@ fn object_size_dependent_setup(
|
|||||||
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
allocate_preference: MemoryAllocatePreference::AlwaysAllocate,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
((desc.len()-1) * (4 * 4 * 4) * (4 * 4 * 2) * 29) as u64,
|
((desc.len() - 1) * (4 * 4 * 4) * (4 * 4 * 2) * 29) as u64,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@@ -1524,30 +1613,73 @@ fn object_size_dependent_setup(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let csg_scene = gpu_buffer(scene, &allocator, &staging, command_allocator, queue.clone());
|
let csg_scene = gpu_buffer(
|
||||||
|
scene,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
let csg_desc = gpu_buffer(desc, &allocator, &staging, command_allocator, queue.clone());
|
let csg_desc = gpu_buffer(desc, &allocator, &staging, command_allocator, queue.clone());
|
||||||
let csg_floats = gpu_buffer(floats, &allocator, &staging, command_allocator, queue.clone());
|
let csg_floats = gpu_buffer(
|
||||||
let csg_vec2s = gpu_buffer(vec2s, &allocator, &staging, command_allocator, queue.clone());
|
floats,
|
||||||
//let csg_vec3s = gpu_buffer(vec3s, &allocator, &staging, command_allocator, queue.clone());
|
&allocator,
|
||||||
let csg_vec4s = gpu_buffer(vec4s, &allocator, &staging, command_allocator, queue.clone());
|
&staging,
|
||||||
let csg_mat2s = gpu_buffer(mat2s, &allocator, &staging, command_allocator, queue.clone());
|
command_allocator,
|
||||||
let csg_mat3s = gpu_buffer(mat3s, &allocator, &staging, command_allocator, queue.clone());
|
queue.clone(),
|
||||||
let csg_mat4s = gpu_buffer(mat4s, &allocator, &staging, command_allocator, queue.clone());
|
);
|
||||||
|
let csg_vec2s = gpu_buffer(
|
||||||
|
vec2s,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
|
//let csg_vec3s = gpu_buffer(vec3s, &allocator, &staging, command_allocator,
|
||||||
|
// queue.clone());
|
||||||
|
let csg_vec4s = gpu_buffer(
|
||||||
|
vec4s,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
|
let csg_mat2s = gpu_buffer(
|
||||||
|
mat2s,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
|
let csg_mat3s = gpu_buffer(
|
||||||
|
mat3s,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
|
let csg_mat4s = gpu_buffer(
|
||||||
|
mat4s,
|
||||||
|
&allocator,
|
||||||
|
&staging,
|
||||||
|
command_allocator,
|
||||||
|
queue.clone(),
|
||||||
|
);
|
||||||
let csg_mats = gpu_buffer(mats, &allocator, &staging, command_allocator, queue.clone());
|
let csg_mats = gpu_buffer(mats, &allocator, &staging, command_allocator, queue.clone());
|
||||||
let csg_deps = gpu_buffer(deps, &allocator, &staging, command_allocator, queue);
|
let csg_deps = gpu_buffer(deps, &allocator, &staging, command_allocator, queue);
|
||||||
|
|
||||||
Subbuffers {
|
Subbuffers {
|
||||||
masks: fragment_masks_buffer,
|
masks: fragment_masks_buffer,
|
||||||
floats: csg_floats,
|
floats: csg_floats,
|
||||||
vec2s: csg_vec2s,
|
vec2s: csg_vec2s,
|
||||||
//vec3s: csg_vec3s,
|
//vec3s: csg_vec3s,
|
||||||
vec4s: csg_vec4s,
|
vec4s: csg_vec4s,
|
||||||
mat2s: csg_mat2s,
|
mat2s: csg_mat2s,
|
||||||
mat3s: csg_mat3s,
|
mat3s: csg_mat3s,
|
||||||
mat4s: csg_mat4s,
|
mat4s: csg_mat4s,
|
||||||
mats: csg_mats,
|
mats: csg_mats,
|
||||||
scene: csg_scene,
|
scene: csg_scene,
|
||||||
deps: csg_deps,
|
deps: csg_deps,
|
||||||
desc: csg_desc,
|
desc: csg_desc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-23
@@ -1,13 +1,16 @@
|
|||||||
use std::fmt::Display;
|
use std::{
|
||||||
use std::io::{BufReader, Read};
|
fmt::Display,
|
||||||
|
io::{BufReader, Read},
|
||||||
use std::str::Chars;
|
str::Chars,
|
||||||
|
};
|
||||||
use serde::de::{
|
|
||||||
self, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess, VariantAccess,
|
use serde::{
|
||||||
Visitor,
|
de::{
|
||||||
|
self, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess, VariantAccess,
|
||||||
|
Visitor,
|
||||||
|
},
|
||||||
|
forward_to_deserialize_any, Deserialize,
|
||||||
};
|
};
|
||||||
use serde::{forward_to_deserialize_any, Deserialize};
|
|
||||||
use utf8::BufReadDecoder;
|
use utf8::BufReadDecoder;
|
||||||
|
|
||||||
type Result<T> = core::result::Result<T, Error>;
|
type Result<T> = core::result::Result<T, Error>;
|
||||||
@@ -50,9 +53,9 @@ impl serde::ser::Error for Error {
|
|||||||
pub(crate) struct Deserializer<'de> {
|
pub(crate) struct Deserializer<'de> {
|
||||||
// This string starts with the input data and characters are truncated off
|
// This string starts with the input data and characters are truncated off
|
||||||
// the beginning as data is parsed.
|
// the beginning as data is parsed.
|
||||||
input: BufReadDecoder<BufReader<&'de mut dyn Read>>,
|
input: BufReadDecoder<BufReader<&'de mut dyn Read>>,
|
||||||
read_buf: String,
|
read_buf: String,
|
||||||
peek: Option<(char, usize)>,
|
peek: Option<(char, usize)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'de> Deserializer<'de> {
|
impl<'de> Deserializer<'de> {
|
||||||
@@ -63,9 +66,9 @@ impl<'de> Deserializer<'de> {
|
|||||||
|
|
||||||
pub(crate) fn from_reader(input: &'de mut dyn Read) -> Self {
|
pub(crate) fn from_reader(input: &'de mut dyn Read) -> Self {
|
||||||
Deserializer {
|
Deserializer {
|
||||||
input: BufReadDecoder::new(BufReader::new(input)),
|
input: BufReadDecoder::new(BufReader::new(input)),
|
||||||
read_buf: String::new(),
|
read_buf: String::new(),
|
||||||
peek: None,
|
peek: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,16 +131,16 @@ impl<'de> Deserializer<'de> {
|
|||||||
Ok(c) => {
|
Ok(c) => {
|
||||||
self.peek = Some(c);
|
self.peek = Some(c);
|
||||||
return Ok(c);
|
return Ok(c);
|
||||||
}
|
},
|
||||||
Err(Error::Eof) => match self.input.next_strict() {
|
Err(Error::Eof) => match self.input.next_strict() {
|
||||||
Some(e) => {
|
Some(e) => {
|
||||||
match e {
|
match e {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
s.clone_into(&mut self.read_buf);
|
s.clone_into(&mut self.read_buf);
|
||||||
}
|
},
|
||||||
Err(e) => return Err(Error::UTF8(format!("{e}"))),
|
Err(e) => return Err(Error::UTF8(format!("{e}"))),
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
None => return Err(Error::Eof),
|
None => return Err(Error::Eof),
|
||||||
},
|
},
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
@@ -168,16 +171,16 @@ impl<'de> Deserializer<'de> {
|
|||||||
let out = self.read_buf[..len].to_string();
|
let out = self.read_buf[..len].to_string();
|
||||||
self.read_buf = self.read_buf[len + 1..].to_string();
|
self.read_buf = self.read_buf[len + 1..].to_string();
|
||||||
return Ok(out);
|
return Ok(out);
|
||||||
}
|
},
|
||||||
None => match self.input.next_strict() {
|
None => match self.input.next_strict() {
|
||||||
Some(e) => {
|
Some(e) => {
|
||||||
match e {
|
match e {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
s.clone_into(&mut self.read_buf);
|
s.clone_into(&mut self.read_buf);
|
||||||
}
|
},
|
||||||
Err(e) => return Err(Error::UTF8(format!("{e}"))),
|
Err(e) => return Err(Error::UTF8(format!("{e}"))),
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
None => return Err(Error::Eof),
|
None => return Err(Error::Eof),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -188,6 +191,10 @@ impl<'de> Deserializer<'de> {
|
|||||||
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
forward_to_deserialize_any! {
|
||||||
|
bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char bytes byte_buf option unit unit_struct
|
||||||
|
}
|
||||||
|
|
||||||
// Look at the input data to decide what Serde data model type to
|
// Look at the input data to decide what Serde data model type to
|
||||||
// deserialize as. Not all data formats are able to support this operation.
|
// deserialize as. Not all data formats are able to support this operation.
|
||||||
// Formats that support `deserialize_any` are known as self-describing.
|
// Formats that support `deserialize_any` are known as self-describing.
|
||||||
@@ -371,10 +378,6 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
|
|||||||
{
|
{
|
||||||
self.deserialize_any(visitor)
|
self.deserialize_any(visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
forward_to_deserialize_any! {
|
|
||||||
bool i8 i16 i32 i64 u8 u16 u32 u64 f32 f64 char bytes byte_buf option unit unit_struct
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In order to handle commas correctly when deserializing a JSON array or map,
|
// In order to handle commas correctly when deserializing a JSON array or map,
|
||||||
|
|||||||
+30
-30
@@ -16,41 +16,41 @@ use vulkano::{
|
|||||||
pipeline::graphics::vertex_input::Vertex,
|
pipeline::graphics::vertex_input::Vertex,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::instruction_set::InstructionSet;
|
use crate::{instruction_set::InstructionSet, mcsg_deserialise::from_reader, MemoryAllocator};
|
||||||
use crate::{mcsg_deserialise::from_reader, MemoryAllocator};
|
|
||||||
|
|
||||||
pub(crate) const PLATONIC_SOLIDS: [(&str, &[u8]); 1] = [("Buny", include_bytes!("bunny.obj"))];
|
pub(crate) const PLATONIC_SOLIDS: [(&str, &[u8]); 1] = [("Buny", include_bytes!("bunny.obj"))];
|
||||||
pub(crate) const CSG_SOLIDS: [(&str, &[u8]); 1] =
|
pub(crate) const CSG_SOLIDS: [(&str, &[u8]); 1] =
|
||||||
[("Primitives", include_bytes!("primitive.mcsg"))];
|
[("Primitives", include_bytes!("primitive.mcsg"))];
|
||||||
|
|
||||||
// We now create a buffer that will store the shape of our triangle.
|
// We now create a buffer that will store the shape of our triangle.
|
||||||
// We use #[repr(C)] here to force rustc to not do anything funky with our data, although for this
|
// We use #[repr(C)] here to force rustc to not do anything funky with our data,
|
||||||
// particular example, it doesn't actually change the in-memory representation.
|
// although for this particular example, it doesn't actually change the
|
||||||
|
// in-memory representation.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Default, Zeroable, Pod, Vertex)]
|
#[derive(Clone, Copy, Debug, Default, Zeroable, Pod, Vertex)]
|
||||||
pub(crate) struct OVertex {
|
pub(crate) struct OVertex {
|
||||||
#[format(R32G32B32_SFLOAT)]
|
#[format(R32G32B32_SFLOAT)]
|
||||||
position: [f32; 3],
|
position: [f32; 3],
|
||||||
#[format(R32G32B32_SFLOAT)]
|
#[format(R32G32B32_SFLOAT)]
|
||||||
normal: [f32; 3],
|
normal: [f32; 3],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Mesh {
|
pub(crate) struct Mesh {
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) vertices: Subbuffer<[OVertex]>,
|
pub(crate) vertices: Subbuffer<[OVertex]>,
|
||||||
pub(crate) indices: Subbuffer<[u32]>,
|
pub(crate) indices: Subbuffer<[u32]>,
|
||||||
pub(crate) pos: Point3<f32>,
|
pub(crate) pos: Point3<f32>,
|
||||||
pub(crate) rot: Euler<Deg<f32>>,
|
pub(crate) rot: Euler<Deg<f32>>,
|
||||||
pub(crate) scale: Vector3<f32>,
|
pub(crate) scale: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct CSG {
|
pub(crate) struct CSG {
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) parts: Vec<CSGPart>,
|
pub(crate) parts: Vec<CSGPart>,
|
||||||
pub(crate) pos: Point3<f32>,
|
pub(crate) pos: Point3<f32>,
|
||||||
pub(crate) rot: Euler<Deg<f32>>,
|
pub(crate) rot: Euler<Deg<f32>>,
|
||||||
pub(crate) scale: Vector3<f32>,
|
pub(crate) scale: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,10 +78,10 @@ pub(crate) enum Inputs {
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct CSGPart {
|
pub(crate) struct CSGPart {
|
||||||
pub(crate) code: u16,
|
pub(crate) code: u16,
|
||||||
pub(crate) opcode: InstructionSet,
|
pub(crate) opcode: InstructionSet,
|
||||||
pub(crate) constants: Vec<Inputs>,
|
pub(crate) constants: Vec<Inputs>,
|
||||||
pub(crate) material: Option<Mat4>,
|
pub(crate) material: Option<Mat4>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSGPart {
|
impl CSGPart {
|
||||||
@@ -130,9 +130,9 @@ pub(crate) fn load_obj(
|
|||||||
let mut temp_hash_map = HashMap::<(u32, u32), u32>::new();
|
let mut temp_hash_map = HashMap::<(u32, u32), u32>::new();
|
||||||
|
|
||||||
// We're gonna have to remap all the indices that OBJ uses. Annoying.
|
// We're gonna have to remap all the indices that OBJ uses. Annoying.
|
||||||
// Get each pair of vertex position to vertex normal and assign it a new index. This might duplicate
|
// Get each pair of vertex position to vertex normal and assign it a new index.
|
||||||
// vertices or normals but each *pair* needs a unique index
|
// This might duplicate vertices or normals but each *pair* needs a unique
|
||||||
// Uses the hash map to check that we're not duplicating unnecessarily
|
// index Uses the hash map to check that we're not duplicating unnecessarily
|
||||||
for g in &object.objects[0].groups {
|
for g in &object.objects[0].groups {
|
||||||
for p in &g.polys {
|
for p in &g.polys {
|
||||||
for v in &p.0 {
|
for v in &p.0 {
|
||||||
@@ -144,7 +144,7 @@ pub(crate) fn load_obj(
|
|||||||
} else {
|
} else {
|
||||||
vertices.push(OVertex {
|
vertices.push(OVertex {
|
||||||
position: object.position[mapping.0 as usize],
|
position: object.position[mapping.0 as usize],
|
||||||
normal: object.normal[mapping.1 as usize],
|
normal: object.normal[mapping.1 as usize],
|
||||||
});
|
});
|
||||||
temp_hash_map.insert(mapping, (vertices.len() - 1) as u32);
|
temp_hash_map.insert(mapping, (vertices.len() - 1) as u32);
|
||||||
indices.push((vertices.len() - 1) as u32);
|
indices.push((vertices.len() - 1) as u32);
|
||||||
@@ -194,7 +194,7 @@ pub(crate) fn load_obj(
|
|||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
struct MCSG {
|
struct MCSG {
|
||||||
object: Vec<MCSGObject>,
|
object: Vec<MCSGObject>,
|
||||||
csg: Vec<MCSGCSG>,
|
csg: Vec<MCSGCSG>,
|
||||||
}
|
}
|
||||||
type MCSGObject = HashMap<String, String>;
|
type MCSGObject = HashMap<String, String>;
|
||||||
type MCSGCSG = Vec<MCSGCSGPart>;
|
type MCSGCSG = Vec<MCSGCSGPart>;
|
||||||
@@ -234,8 +234,8 @@ fn point3_from_string(input: &str) -> Result<Point3<f32>, String> {
|
|||||||
}
|
}
|
||||||
struct TRS {
|
struct TRS {
|
||||||
translation: Point3<f32>,
|
translation: Point3<f32>,
|
||||||
rotation: Matrix3<f32>,
|
rotation: Matrix3<f32>,
|
||||||
scale: Vector3<f32>,
|
scale: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> {
|
fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> {
|
||||||
@@ -246,13 +246,13 @@ fn get_trs(o: &HashMap<String, String>) -> Result<TRS, String> {
|
|||||||
.map(point3_from_string)
|
.map(point3_from_string)
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(Point3::origin()),
|
.unwrap_or(Point3::origin()),
|
||||||
rotation: o
|
rotation: o
|
||||||
.get("r")
|
.get("r")
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
.map(matrix3_from_string)
|
.map(matrix3_from_string)
|
||||||
.transpose()?
|
.transpose()?
|
||||||
.unwrap_or(Matrix3::identity()),
|
.unwrap_or(Matrix3::identity()),
|
||||||
scale: o
|
scale: o
|
||||||
.get("s")
|
.get("s")
|
||||||
.map(String::as_str)
|
.map(String::as_str)
|
||||||
.map(vector3_from_string)
|
.map(vector3_from_string)
|
||||||
@@ -379,8 +379,8 @@ pub(crate) fn load_csg(
|
|||||||
let _rgb = get_rgb(inpart)?;
|
let _rgb = get_rgb(inpart)?;
|
||||||
let _trs = get_trs(inpart)?;
|
let _trs = get_trs(inpart)?;
|
||||||
let _half = get_half(inpart)?;
|
let _half = get_half(inpart)?;
|
||||||
}
|
},
|
||||||
_ => {} //return Err("unknown type of csg".to_owned()),
|
_ => {}, //return Err("unknown type of csg".to_owned()),
|
||||||
}
|
}
|
||||||
Ok(csgpart)
|
Ok(csgpart)
|
||||||
})
|
})
|
||||||
@@ -407,7 +407,7 @@ pub(crate) fn load_csg(
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct Light {
|
pub(crate) struct Light {
|
||||||
pub(crate) pos: Point3<f32>,
|
pub(crate) pos: Point3<f32>,
|
||||||
pub(crate) colour: Vector3<f32>,
|
pub(crate) colour: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +415,7 @@ impl Light {
|
|||||||
pub(crate) fn new(pos: [f32; 3], colour: [f32; 3], intensity: f32) -> Light {
|
pub(crate) fn new(pos: [f32; 3], colour: [f32; 3], intensity: f32) -> Light {
|
||||||
let c: Vector3<f32> = colour.into();
|
let c: Vector3<f32> = colour.into();
|
||||||
Light {
|
Light {
|
||||||
pos: pos.into(),
|
pos: pos.into(),
|
||||||
colour: c * intensity,
|
colour: c * intensity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -424,7 +424,7 @@ impl Light {
|
|||||||
impl Default for Light {
|
impl Default for Light {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
pos: Point3::origin(),
|
pos: Point3::origin(),
|
||||||
colour: Vector3 {
|
colour: Vector3 {
|
||||||
x: 1.,
|
x: 1.,
|
||||||
y: 1.,
|
y: 1.,
|
||||||
|
|||||||
Reference in New Issue
Block a user