|
|
|
@ -3,7 +3,6 @@
|
|
|
|
|
#![allow(unused_mut)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern crate cgmath;
|
|
|
|
|
extern crate image;
|
|
|
|
|
extern crate nalgebra as na;
|
|
|
|
@ -35,6 +34,7 @@ use winit::dpi::LogicalSize;
|
|
|
|
|
use winit::event_loop::EventLoop;
|
|
|
|
|
use winit::event::{Event, WindowEvent, DeviceEvent, VirtualKeyCode, ElementState};
|
|
|
|
|
use winit::platform::unix::WindowBuilderExtUnix;
|
|
|
|
|
use crate::vkprocessor::VkProcessor;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub mod util;
|
|
|
|
@ -43,157 +43,163 @@ pub mod drawables;
|
|
|
|
|
pub mod canvas;
|
|
|
|
|
pub mod compute;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
|
hprof::start_frame();
|
|
|
|
|
|
|
|
|
|
let q1 = hprof::enter("setup");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let instance = {
|
|
|
|
|
let extensions = vulkano_win::required_extensions();
|
|
|
|
|
Instance::new(None, &extensions, None).unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let mut processor = vkprocessor::VkProcessor::new(instance.clone());
|
|
|
|
|
let _callback = DebugCallback::errors_and_warnings(&instance, |msg| {
|
|
|
|
|
println!("Debug callback: {:?}", msg.description);
|
|
|
|
|
}).ok();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("vulkan preload");
|
|
|
|
|
processor.create_swapchain();
|
|
|
|
|
let mut events_loop = EventLoop::new();
|
|
|
|
|
|
|
|
|
|
processor.preload_kernels();
|
|
|
|
|
processor.preload_shaders();
|
|
|
|
|
processor.preload_textures();
|
|
|
|
|
processor.preload_fonts();
|
|
|
|
|
}
|
|
|
|
|
let mut surface = WindowBuilder::new()
|
|
|
|
|
.with_inner_size(LogicalSize::new(800, 800));
|
|
|
|
|
// Some weird namespacing issue here
|
|
|
|
|
let mut surface = VkSurfaceBuild::build_vk_surface(surface.clone(), &events_loop, instance.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
let mut processor = VkProcessor::new(&instance, surface.clone());
|
|
|
|
|
|
|
|
|
|
let q2 = hprof::enter("Game Objects");
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("vulkan preload");
|
|
|
|
|
processor.create_swapchain(surface.clone());
|
|
|
|
|
|
|
|
|
|
let mut timer = Timer::new();
|
|
|
|
|
let mut frame_future: Box<dyn GpuFuture> =
|
|
|
|
|
Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
|
|
|
|
processor.preload_kernels();
|
|
|
|
|
processor.preload_shaders();
|
|
|
|
|
processor.preload_textures();
|
|
|
|
|
processor.preload_fonts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let step_size: f32 = 0.005;
|
|
|
|
|
let mut elapsed_time: f32;
|
|
|
|
|
let mut delta_time: f32;
|
|
|
|
|
let mut accumulator_time: f32 = 0.0;
|
|
|
|
|
let mut current_time: f32 = timer.elap_time();
|
|
|
|
|
let q2 = hprof::enter("Game Objects");
|
|
|
|
|
|
|
|
|
|
let image_data = load_raw(String::from("funky-bird.jpg"));
|
|
|
|
|
let image_dimensions_f: (f32, f32) = ((image_data.1).0 as f32, (image_data.1).1 as f32);
|
|
|
|
|
let image_dimensions_u: (u32, u32) = image_data.1;
|
|
|
|
|
let compu_sprite1: CompuSprite =
|
|
|
|
|
CompuSprite::new((0.0, -0.5), (0.4, 0.4), 0, image_dimensions_f,
|
|
|
|
|
// Swap image to render the result to. Must match dimensions
|
|
|
|
|
processor.new_swap_image(image_dimensions_u));
|
|
|
|
|
let mut timer = Timer::new();
|
|
|
|
|
let mut frame_future: Box<dyn GpuFuture> =
|
|
|
|
|
Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
|
|
|
|
|
|
|
|
|
let compute_buffer: Arc<CompuBufferHandle> =
|
|
|
|
|
processor.new_compute_buffer(image_data.0, image_data.1, 4);
|
|
|
|
|
let step_size: f32 = 0.005;
|
|
|
|
|
let mut elapsed_time: f32;
|
|
|
|
|
let mut delta_time: f32;
|
|
|
|
|
let mut accumulator_time: f32 = 0.0;
|
|
|
|
|
let mut current_time: f32 = timer.elap_time();
|
|
|
|
|
|
|
|
|
|
let compute_kernel: Arc<CompuKernelHandle> =
|
|
|
|
|
processor.get_kernel_handle(String::from("simple-edge.compute"))
|
|
|
|
|
.expect("Can't find that kernel");
|
|
|
|
|
let image_data = load_raw(String::from("funky-bird.jpg"));
|
|
|
|
|
let image_dimensions_f: (f32, f32) = ((image_data.1).0 as f32, (image_data.1).1 as f32);
|
|
|
|
|
let image_dimensions_u: (u32, u32) = image_data.1;
|
|
|
|
|
let compu_sprite1: CompuSprite =
|
|
|
|
|
CompuSprite::new((0.0, -0.5), (0.4, 0.4), 0, image_dimensions_f,
|
|
|
|
|
// Swap image to render the result to. Must match dimensions
|
|
|
|
|
processor.new_swap_image(image_dimensions_u));
|
|
|
|
|
|
|
|
|
|
// Get the handles for the assets
|
|
|
|
|
let funky_handle: Arc<CanvasTextureHandle> =
|
|
|
|
|
processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
|
|
|
|
let sfml_handle: Arc<CanvasTextureHandle> =
|
|
|
|
|
processor.get_texture_handle(String::from("sfml.png")).unwrap();
|
|
|
|
|
//let font_handle : Arc<CanvasFontHandle> =
|
|
|
|
|
// processor.get_font_handle(String::from("sansation.ttf")).unwrap();
|
|
|
|
|
let compute_buffer: Arc<CompuBufferHandle> =
|
|
|
|
|
processor.new_compute_buffer(image_data.0, image_data.1, 4);
|
|
|
|
|
|
|
|
|
|
let funky_sprite = Sprite::new((0.0, 0.5), (0.5, 0.5), 0, funky_handle.clone());
|
|
|
|
|
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
let rect = Rect::new((-0.5, -0.5), (0.5, 0.5), 1);
|
|
|
|
|
let compute_kernel: Arc<CompuKernelHandle> =
|
|
|
|
|
processor.get_kernel_handle(String::from("simple-edge.compute"))
|
|
|
|
|
.expect("Can't find that kernel");
|
|
|
|
|
|
|
|
|
|
// Get the handles for the assets
|
|
|
|
|
let funky_handle: Arc<CanvasTextureHandle> =
|
|
|
|
|
processor.get_texture_handle(String::from("funky-bird.jpg")).unwrap();
|
|
|
|
|
let sfml_handle: Arc<CanvasTextureHandle> =
|
|
|
|
|
processor.get_texture_handle(String::from("sfml.png")).unwrap();
|
|
|
|
|
//let font_handle : Arc<CanvasFontHandle> =
|
|
|
|
|
// processor.get_font_handle(String::from("sansation.ttf")).unwrap();
|
|
|
|
|
|
|
|
|
|
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
|
|
|
|
|
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
|
|
|
|
let funky_sprite = Sprite::new((0.0, 0.5), (0.5, 0.5), 0, funky_handle.clone());
|
|
|
|
|
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
let rect = Rect::new((-0.5, -0.5), (0.5, 0.5), 1);
|
|
|
|
|
|
|
|
|
|
drop(q2);
|
|
|
|
|
drop(q1);
|
|
|
|
|
|
|
|
|
|
let l = hprof::enter("Loop");
|
|
|
|
|
//let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
|
|
|
|
let text_sprite = Text::new((-0.1, -0.1), (10.0, 10.0), 1);
|
|
|
|
|
//let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
|
|
|
|
|
|
|
|
|
let mut exit = false;
|
|
|
|
|
drop(q2);
|
|
|
|
|
drop(q1);
|
|
|
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
|
let l = hprof::enter("Loop");
|
|
|
|
|
|
|
|
|
|
while let true = processor.is_open() {
|
|
|
|
|
let mut exit = false;
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
let mut count = 0;
|
|
|
|
|
|
|
|
|
|
while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
accumulator_time -= step_size;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Events loop is borrowed from the surface
|
|
|
|
|
processor.event_loop().clone().run(move |event, _, control_flow| {
|
|
|
|
|
match event {
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
|
|
|
|
{
|
|
|
|
|
exit = true;
|
|
|
|
|
}
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::Resized(_), .. } => {
|
|
|
|
|
processor.swapchain_recreate_needed = true;
|
|
|
|
|
while (accumulator_time - step_size) >= step_size {
|
|
|
|
|
accumulator_time -= step_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Events loop is borrowed from the surface
|
|
|
|
|
events_loop.run(move |event, _, control_flow| {
|
|
|
|
|
match event {
|
|
|
|
|
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } =>
|
|
|
|
|
{
|
|
|
|
|
exit = true;
|
|
|
|
|
}
|
|
|
|
|
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::WindowEvent { event: WindowEvent::Resized(_), .. } => {
|
|
|
|
|
processor.swapchain_recreate_needed = true;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
// },
|
|
|
|
|
_ => ()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if exit {
|
|
|
|
|
break;
|
|
|
|
|
_ => ()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let mut canvas_frame = CanvasFrame::default();
|
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
|
canvas_frame.draw(&text_sprite);
|
|
|
|
|
if exit {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut canvas_frame = CanvasFrame::default();
|
|
|
|
|
canvas_frame.draw(&funky_sprite);
|
|
|
|
|
canvas_frame.draw(&text_sprite);
|
|
|
|
|
// canvas_frame.draw(&rect);
|
|
|
|
|
|
|
|
|
|
let mut compu_frame = CompuFrame::new();
|
|
|
|
|
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
|
let mut compu_frame = CompuFrame::new();
|
|
|
|
|
//compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
|
|
|
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("Run");
|
|
|
|
|
processor.run(canvas_frame,
|
|
|
|
|
compu_frame);
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
let g = hprof::enter("Run");
|
|
|
|
|
processor.run(&surface.clone(),
|
|
|
|
|
canvas_frame,
|
|
|
|
|
compu_frame);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
drop(l);
|
|
|
|
|
|
|
|
|
|
drop(l);
|
|
|
|
|
|
|
|
|
|
hprof::end_frame();
|
|
|
|
|
hprof::profiler().print_timing();
|
|
|
|
|
hprof::end_frame();
|
|
|
|
|
hprof::profiler().print_timing();
|
|
|
|
|
|
|
|
|
|
drop(processor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|