|
|
@ -4,39 +4,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern crate cgmath;
|
|
|
|
extern crate cgmath;
|
|
|
|
|
|
|
|
extern crate hprof;
|
|
|
|
extern crate image;
|
|
|
|
extern crate image;
|
|
|
|
extern crate nalgebra as na;
|
|
|
|
extern crate nalgebra as na;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate time;
|
|
|
|
extern crate time;
|
|
|
|
extern crate hprof;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use vulkano::sync;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::util::timer::Timer;
|
|
|
|
|
|
|
|
|
|
|
|
use vulkano::instance::debug::DebugCallback;
|
|
|
|
use vulkano::instance::Instance;
|
|
|
|
use vulkano::instance::Instance;
|
|
|
|
|
|
|
|
use vulkano::sync;
|
|
|
|
use vulkano::sync::GpuFuture;
|
|
|
|
use vulkano::sync::GpuFuture;
|
|
|
|
use vulkano_win::VkSurfaceBuild;
|
|
|
|
use vulkano_win::VkSurfaceBuild;
|
|
|
|
|
|
|
|
use winit::dpi::LogicalSize;
|
|
|
|
|
|
|
|
use winit::event::{DeviceEvent, ElementState, Event, VirtualKeyCode, WindowEvent};
|
|
|
|
|
|
|
|
use winit::event_loop::{EventLoop, ControlFlow};
|
|
|
|
|
|
|
|
use winit::platform::unix::WindowBuilderExtUnix;
|
|
|
|
|
|
|
|
use winit::window::WindowBuilder;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::util::load_raw;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use vulkano::instance::debug::DebugCallback;
|
|
|
|
|
|
|
|
use crate::compute::compu_frame::CompuFrame;
|
|
|
|
|
|
|
|
use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
|
|
|
|
use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
|
|
|
|
use crate::canvas::managed::handles::{CanvasTextureHandle, Handle, CanvasFontHandle};
|
|
|
|
use crate::compute::compu_frame::CompuFrame;
|
|
|
|
use crate::util::vertex::{VertexTypes, TextureVertex3D};
|
|
|
|
|
|
|
|
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
|
|
|
|
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
|
|
|
|
use crate::drawables::sprite::Sprite;
|
|
|
|
|
|
|
|
use crate::drawables::rect::Rect;
|
|
|
|
|
|
|
|
use crate::drawables::compu_sprite::CompuSprite;
|
|
|
|
use crate::drawables::compu_sprite::CompuSprite;
|
|
|
|
|
|
|
|
use crate::drawables::rect::Rect;
|
|
|
|
|
|
|
|
use crate::drawables::sprite::Sprite;
|
|
|
|
use crate::drawables::text::Text;
|
|
|
|
use crate::drawables::text::Text;
|
|
|
|
use winit::window::{WindowBuilder};
|
|
|
|
use crate::util::load_raw;
|
|
|
|
use winit::dpi::LogicalSize;
|
|
|
|
use crate::util::timer::Timer;
|
|
|
|
use winit::event_loop::EventLoop;
|
|
|
|
use crate::util::vertex::{TextureVertex3D, VertexTypes};
|
|
|
|
use winit::event::{Event, WindowEvent, DeviceEvent, VirtualKeyCode, ElementState};
|
|
|
|
|
|
|
|
use winit::platform::unix::WindowBuilderExtUnix;
|
|
|
|
|
|
|
|
use crate::vkprocessor::VkProcessor;
|
|
|
|
use crate::vkprocessor::VkProcessor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub mod util;
|
|
|
|
pub mod util;
|
|
|
|
pub mod vkprocessor;
|
|
|
|
pub mod vkprocessor;
|
|
|
|
pub mod drawables;
|
|
|
|
pub mod drawables;
|
|
|
@ -60,15 +59,14 @@ pub fn main() {
|
|
|
|
let mut events_loop = EventLoop::new();
|
|
|
|
let mut events_loop = EventLoop::new();
|
|
|
|
|
|
|
|
|
|
|
|
let mut surface = WindowBuilder::new()
|
|
|
|
let mut surface = WindowBuilder::new()
|
|
|
|
.with_inner_size(LogicalSize::new(800, 800));
|
|
|
|
.with_inner_size(LogicalSize::new(800, 800))
|
|
|
|
// Some weird namespacing issue here
|
|
|
|
.build_vk_surface(&events_loop, instance.clone()).unwrap();
|
|
|
|
let mut surface = VkSurfaceBuild::build_vk_surface(surface.clone(), &events_loop, instance.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut processor = VkProcessor::new(&instance, surface.clone());
|
|
|
|
let mut processor = VkProcessor::new(instance.clone(), surface.clone());
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let g = hprof::enter("vulkan preload");
|
|
|
|
let g = hprof::enter("vulkan preload");
|
|
|
|
processor.create_swapchain(surface.clone());
|
|
|
|
processor.create_swapchain(instance.clone(), surface.clone());
|
|
|
|
|
|
|
|
|
|
|
|
processor.preload_kernels();
|
|
|
|
processor.preload_kernels();
|
|
|
|
processor.preload_shaders();
|
|
|
|
processor.preload_shaders();
|
|
|
@ -129,54 +127,35 @@ pub fn main() {
|
|
|
|
|
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
let mut count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
while let true = processor.is_open() {
|
|
|
|
// while let true = processor.is_open() {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Take care of our timing
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// elapsed_time = timer.elap_time();
|
|
|
|
|
|
|
|
// delta_time = elapsed_time - current_time;
|
|
|
|
|
|
|
|
// current_time = elapsed_time;
|
|
|
|
|
|
|
|
// if delta_time > 0.02 {
|
|
|
|
|
|
|
|
// delta_time = 0.02;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// accumulator_time += delta_time;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
|
|
|
// accumulator_time -= step_size;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Take care of our timing
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
elapsed_time = timer.elap_time();
|
|
|
|
|
|
|
|
delta_time = elapsed_time - current_time;
|
|
|
|
|
|
|
|
current_time = elapsed_time;
|
|
|
|
|
|
|
|
if delta_time > 0.02 {
|
|
|
|
|
|
|
|
delta_time = 0.02;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
accumulator_time += delta_time;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
|
|
|
accumulator_time -= step_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Events loop is borrowed from the surface
|
|
|
|
// Events loop is borrowed from the surface
|
|
|
|
events_loop.run(move |event, _, control_flow| {
|
|
|
|
events_loop.run(move |event, _, control_flow| {
|
|
|
|
match event {
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
exit = true;
|
|
|
|
*control_flow = ControlFlow::Exit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
|
|
|
|
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
|
|
|
|
processor.swapchain_recreate_needed = true;
|
|
|
|
processor.swapchain_recreate_needed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
|
|
|
Event::MainEventsCleared => {
|
|
|
|
match keyboard_input.virtual_keycode.unwrap() {
|
|
|
|
|
|
|
|
VirtualKeyCode::A => {
|
|
|
|
|
|
|
|
if keyboard_input.state == ElementState::Pressed {
|
|
|
|
|
|
|
|
// processor.save_edges_image();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event::DeviceEvent { event: DeviceEvent::Button(mouse_input), .. } => {
|
|
|
|
|
|
|
|
// mouse_xy.x
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if exit {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut canvas_frame = CanvasFrame::default();
|
|
|
|
let mut canvas_frame = CanvasFrame::default();
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
canvas_frame.draw(&text_sprite);
|
|
|
|
canvas_frame.draw(&text_sprite);
|
|
|
@ -186,7 +165,6 @@ pub fn main() {
|
|
|
|
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let g = hprof::enter("Run");
|
|
|
|
let g = hprof::enter("Run");
|
|
|
|
processor.run(&surface.clone(),
|
|
|
|
processor.run(&surface.clone(),
|
|
|
@ -194,12 +172,27 @@ pub fn main() {
|
|
|
|
compu_frame);
|
|
|
|
compu_frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Event::DeviceEvent { event: DeviceEvent::Key(keyboard_input), .. } => {
|
|
|
|
|
|
|
|
match keyboard_input.virtual_keycode.unwrap() {
|
|
|
|
|
|
|
|
VirtualKeyCode::A => {
|
|
|
|
|
|
|
|
if keyboard_input.state == ElementState::Pressed {
|
|
|
|
|
|
|
|
// processor.save_edges_image();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Event::DeviceEvent { event: DeviceEvent::Button(mouse_input), .. } => {
|
|
|
|
|
|
|
|
// mouse_xy.x
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
_ => ()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
drop(l);
|
|
|
|
drop(l);
|
|
|
|
|
|
|
|
|
|
|
|
hprof::end_frame();
|
|
|
|
hprof::end_frame();
|
|
|
|
hprof::profiler().print_timing();
|
|
|
|
hprof::profiler().print_timing();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|