This commit is contained in:
2024-12-29 20:38:02 +00:00
parent 12832b3deb
commit 3d401b0ae1
12 changed files with 2122 additions and 1033 deletions
-1
View File
@@ -1,2 +1 @@
/target /target
Cargo.lock
+8 -8
View File
@@ -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
View File
@@ -1,8 +0,0 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {}
}
Generated
+1253 -373
View File
File diff suppressed because it is too large Load Diff
+13 -18
View File
@@ -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" }
+2 -2
View File
@@ -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
+7 -8
View File
@@ -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");
+124 -32
View File
@@ -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)",
);
}); });
}); });
}); });
+221 -224
View File
File diff suppressed because it is too large Load Diff
+295 -163
View File
@@ -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,
Vector3,
};
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 bytemuck::{Pod, Zeroable};
use cgmath::{Deg, EuclideanSpace, Euler, Matrix3, Matrix4, Point3, Rad, SquareMatrix, Vector3};
use egui_winit_vulkano::{Gui, GuiConfig}; use egui_winit_vulkano::{Gui, GuiConfig};
use instruction_set::InputTypes;
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( || { })
.or_else(|| {
p.queue_family_properties() p.queue_family_properties()
.iter() .iter()
.enumerate() .enumerate()
.position(|(_i, q)| { .position(|(_i, q)| q.queue_flags.intersects(QueueFlags::TRANSFER))
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![
QueueCreateInfo {
queue_family_index, queue_family_index,
..Default::default() ..Default::default()
}, },
QueueCreateInfo { QueueCreateInfo {
queue_family_index: transfer_index, queue_family_index: transfer_index,
..Default::default() ..Default::default()
}], },
],
enabled_features: Features { enabled_features: Features {
mesh_shader: true, mesh_shader: true,
task_shader: true, task_shader: true,
@@ -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>,
@@ -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, },
implicit_ms::SpecializationConstants {
DISABLE_TRACE: gstate.debug.disable_meshcull as u32,
DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32, DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32,
DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32, DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32,}, BRUTE_FORCE: gstate.debug.brute_force as u32,
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull as u32}, },
implicit_ts::SpecializationConstants {
DISABLE_TRACE: gstate.debug.disable_taskcull as u32,
},
gstate.debug.brute_force, gstate.debug.brute_force,
); );
@@ -467,8 +471,8 @@ fn main() {
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,
},
implicit_ms::SpecializationConstants {
DISABLE_TRACE: gstate.debug.disable_meshcull as u32,
DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32, DISABLE_SCALING_1: gstate.debug.disable_meshscale1 as u32,
DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32, DISABLE_SCALING_2: gstate.debug.disable_meshscale2 as u32,
BRUTE_FORCE:gstate.debug.brute_force as u32}, BRUTE_FORCE: gstate.debug.brute_force as u32,
implicit_ts::SpecializationConstants {DISABLE_TRACE:gstate.debug.disable_taskcull 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;
@@ -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();
@@ -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,23 +1043,24 @@ 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
/// window is resized
fn window_size_dependent_setup<Fs, Ms, Ts>( fn window_size_dependent_setup<Fs, Ms, Ts>(
allocator: &StandardMemoryAllocator, allocator: &StandardMemoryAllocator,
mesh_vs: &ShaderModule, mesh_vs: &ShaderModule,
@@ -1131,15 +1193,13 @@ 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");
@@ -1147,7 +1207,6 @@ where
([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 {
@@ -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,13 +1275,13 @@ 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
.execute(transfer_queue)
.unwrap() .unwrap()
.then_signal_fence_and_flush() .then_signal_fence_and_flush()
.unwrap() .unwrap()
@@ -1232,13 +1291,10 @@ where
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() {
for y in 0..input.len()
{
out[x][y] = input[x][y] as f32; out[x][y] = input[x][y] as f32;
} }
} }
@@ -1280,19 +1336,41 @@ 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]),
]; ];
@@ -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,7 +1545,17 @@ 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.;
@@ -1483,13 +1571,14 @@ fn object_size_dependent_setup(
//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:?}");
@@ -1524,15 +1613,58 @@ 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);
+19 -16
View File
@@ -1,13 +1,16 @@
use std::fmt::Display; use std::{
use std::io::{BufReader, Read}; fmt::Display,
io::{BufReader, Read},
str::Chars,
};
use std::str::Chars; use serde::{
de::{
use serde::de::{
self, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess, VariantAccess, self, DeserializeSeed, EnumAccess, IntoDeserializer, MapAccess, SeqAccess, VariantAccess,
Visitor, 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>;
@@ -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,
+9 -9
View File
@@ -16,16 +16,16 @@ 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 {
@@ -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 {
@@ -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)
}) })