finished updating dependencies

master
mitchellhansen 4 years ago
parent f5f0346d5c
commit 5916b0d947

@ -256,7 +256,6 @@ impl CanvasState {
/// Takes physical and capabilities as we don't store that in Canvas /// Takes physical and capabilities as we don't store that in Canvas
pub fn load_shader<T: 'static, V>(&mut self, pub fn load_shader<T: 'static, V>(&mut self,
filename: String, filename: String,
physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>> capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledShader, V: Vertex { where T: CompiledShader, V: Vertex {
let handle = Arc::new(CompiledShaderHandle { let handle = Arc::new(CompiledShaderHandle {

@ -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();
} }

@ -30,9 +30,9 @@ use winit::event_loop::EventLoop;
/// VKProcessor holds the vulkan instance information, the swapchain, /// VKProcessor holds the vulkan instance information, the swapchain,
/// and the compute and canvas states /// and the compute and canvas states
pub struct VkProcessor<'a> { pub struct VkProcessor {
// Vulkan state fields // Vulkan state fields
pub physical: PhysicalDevice<'a>, //pub physical: PhysicalDevice<'a>,
pub device: Arc<Device>, pub device: Arc<Device>,
pub queues: QueuesIter, pub queues: QueuesIter,
pub queue: Arc<Queue>, pub queue: Arc<Queue>,
@ -52,12 +52,12 @@ pub struct VkProcessor<'a> {
} }
impl<'a> VkProcessor<'a> { impl VkProcessor {
/// Creates a new VkProcessor from an instance and surface /// Creates a new VkProcessor from an instance and surface
/// This includes the physical device, queues, compute and canvas state /// This includes the physical device, queues, compute and canvas state
pub fn new(instance: &'a Arc<Instance>, surface: Arc<Surface<Window>>) -> VkProcessor<'a> { pub fn new(instance: Arc<Instance>, surface: Arc<Surface<Window>>) -> VkProcessor {
let physical = PhysicalDevice::enumerate(instance).next().unwrap(); let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let queue_family = physical.queue_families().find(|&q| { let queue_family = physical.queue_families().find(|&q| {
// We take the first queue that supports drawing to our window. // We take the first queue that supports drawing to our window.
@ -78,7 +78,7 @@ impl<'a> VkProcessor<'a> {
VkProcessor { VkProcessor {
physical: physical.clone(), //physical: physical.clone(),
device: device.clone(), device: device.clone(),
queue: queue.clone(), queue: queue.clone(),
queues: queues, queues: queues,
@ -98,13 +98,15 @@ impl<'a> VkProcessor<'a> {
} }
/// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images /// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images
pub fn create_swapchain(&mut self, surface: Arc<Surface<Window>>) { pub fn create_swapchain(&mut self, instance: Arc<Instance>, surface: Arc<Surface<Window>>) {
let (mut swapchain, images) = { let (mut swapchain, images) = {
let capabilities = surface.capabilities(self.physical).unwrap(); let physical = PhysicalDevice::enumerate(&instance).next().unwrap();
let capabilities = surface.capabilities(physical).unwrap();
let usage = capabilities.supported_usage_flags; let usage = capabilities.supported_usage_flags;
let alpha = capabilities.supported_composite_alpha.iter().next().unwrap(); let alpha = capabilities.supported_composite_alpha.iter().next().unwrap();
// Choosing the internal format that the images will have. // Choosing the internal format that the images will have.
let format = capabilities.supported_formats[0].0; let format = capabilities.supported_formats[0].0;
let colorspace = capabilities.supported_formats[0].1;
// Set the swapchains window dimensions // Set the swapchains window dimensions
let initial_dimensions = if let dimensions = surface.window().inner_size() { let initial_dimensions = if let dimensions = surface.window().inner_size() {
@ -122,13 +124,13 @@ impl<'a> VkProcessor<'a> {
format, format,
initial_dimensions, initial_dimensions,
1, // Layers 1, // Layers
usage, ImageUsage::color_attachment(),
&self.queue, &self.queue,
SurfaceTransform::Identity, SurfaceTransform::Identity,
alpha, alpha,
PresentMode::Immediate, PresentMode::Immediate,
FullscreenExclusive::Default, true, FullscreenExclusive::Default, true,
ColorSpace::PassThrough).unwrap() colorspace).unwrap()
}; };
self.swapchain = Some(swapchain); self.swapchain = Some(swapchain);
@ -136,7 +138,7 @@ impl<'a> VkProcessor<'a> {
} }
/// On screen resizes, the swapchain and images must be recreated /// On screen resizes, the swapchain and images must be recreated
pub fn recreate_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) { pub fn recreate_swapchain(&mut self, surface: &Arc<Surface<Window>>) {
let dimensions = if let dimensions = surface.window().inner_size() { let dimensions = if let dimensions = surface.window().inner_size() {
let dimensions: (u32, u32) = dimensions.to_logical::<u32>(surface.window().scale_factor()).into(); let dimensions: (u32, u32) = dimensions.to_logical::<u32>(surface.window().scale_factor()).into();
[dimensions.0, dimensions.1] [dimensions.0, dimensions.1]
@ -174,10 +176,10 @@ impl<'a> VkProcessor<'a> {
/// A hardcoded list of shaders which can be preloaded from this function /// A hardcoded list of shaders which can be preloaded from this function
pub fn preload_shaders(&mut self) { pub fn preload_shaders(&mut self) {
self.canvas_state.load_shader::<GenericShader, ColorVertex3D>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone()); self.canvas_state.load_shader::<GenericShader, ColorVertex3D>(String::from("color-passthrough"), self.capabilities.clone());
self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone()); self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"), self.capabilities.clone());
self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone()); self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"), self.capabilities.clone());
self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone()); self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"), self.capabilities.clone());
} }
/// A hardcoded list of shaders which can be proloaded from this function /// A hardcoded list of shaders which can be proloaded from this function
@ -230,7 +232,7 @@ impl<'a> VkProcessor<'a> {
/// Run the VKprocessor for a single frame, consuming the Canvas/Compu Frames /// Run the VKprocessor for a single frame, consuming the Canvas/Compu Frames
pub fn run(&mut self, pub fn run(&mut self,
surface: &'a Arc<Surface<Window>>, surface: &Arc<Surface<Window>>,
canvas_frame: CanvasFrame, canvas_frame: CanvasFrame,
compute_frame: CompuFrame, compute_frame: CompuFrame,
) { ) {

Loading…
Cancel
Save