compiles, slowly moving everything over to spec stuff
This commit is contained in:
@@ -39,6 +39,14 @@ impl CanvasFrame {
|
|||||||
window_size: window_size,
|
window_size: window_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Push this drawable onto the back of the accumulator
|
||||||
|
pub fn add(&mut self, drawable: Vec<VertexTypeContainer>) {
|
||||||
|
for i in drawable{
|
||||||
|
self.map.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Push this drawable onto the back of the accumulator
|
/// Push this drawable onto the back of the accumulator
|
||||||
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
||||||
for i in drawable.get(self.window_size) {
|
for i in drawable.get(self.window_size) {
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ use crate::canvas::compu_frame::CompuFrame;
|
|||||||
|
|
||||||
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
||||||
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct CanvasState {
|
pub struct CanvasState {
|
||||||
/// Generated during new()
|
/// Generated during new()
|
||||||
dynamic_state: DynamicState,
|
dynamic_state: DynamicState,
|
||||||
/// Generated during new()
|
/// Generated during new()
|
||||||
sampler: Arc<Sampler>,
|
sampler: Option<Arc<Sampler>>,
|
||||||
|
|
||||||
/// hold the image, texture, and Fonts the same was as we do CompuState
|
/// hold the image, texture, and Fonts the same was as we do CompuState
|
||||||
image_buffers: Vec<Arc<CanvasImage>>,
|
image_buffers: Vec<Arc<CanvasImage>>,
|
||||||
@@ -58,9 +58,9 @@ pub struct CanvasState {
|
|||||||
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + Sync>>>,
|
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + Sync>>>,
|
||||||
|
|
||||||
/// Looks like we gotta hold onto the queue for managing textures
|
/// Looks like we gotta hold onto the queue for managing textures
|
||||||
queue: Arc<Queue>,
|
queue: Option<Arc<Queue>>,
|
||||||
device: Arc<Device>,
|
device: Option<Arc<Device>>,
|
||||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,
|
render_pass: Option<Arc<dyn RenderPassAbstract + Send + Sync>>,
|
||||||
|
|
||||||
compute_buffers: Vec<CompuBuffers>,
|
compute_buffers: Vec<CompuBuffers>,
|
||||||
kernels: Vec<CompuKernel>,
|
kernels: Vec<CompuKernel>,
|
||||||
@@ -81,11 +81,11 @@ impl CanvasState {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
let dimensions = [dimensions.width(), dimensions.height()];
|
let dimensions = [dimensions.width(), dimensions.height()];
|
||||||
let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
|
let depth_buffer = AttachmentImage::transient(self.device.clone().unwrap(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
|
||||||
|
|
||||||
images.iter().map(|image| {
|
images.iter().map(|image| {
|
||||||
Arc::new(
|
Arc::new(
|
||||||
Framebuffer::start(self.render_pass.clone())
|
Framebuffer::start(self.render_pass.clone().unwrap())
|
||||||
.add(image.clone()).unwrap()
|
.add(image.clone()).unwrap()
|
||||||
.add(depth_buffer.clone()).unwrap()
|
.add(depth_buffer.clone()).unwrap()
|
||||||
.build().unwrap()
|
.build().unwrap()
|
||||||
@@ -160,19 +160,19 @@ impl CanvasState {
|
|||||||
value: 0xFF,
|
value: 0xFF,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
sampler: Sampler::new(device.clone(),
|
sampler: Some(Sampler::new(device.clone(),
|
||||||
Filter::Linear, Filter::Linear,
|
Filter::Linear, Filter::Linear,
|
||||||
MipmapMode::Nearest,
|
MipmapMode::Nearest,
|
||||||
SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
SamplerAddressMode::Repeat, SamplerAddressMode::Repeat,
|
||||||
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(),
|
SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap()),
|
||||||
image_buffers: vec![],
|
image_buffers: vec![],
|
||||||
texture_buffers: vec![],
|
texture_buffers: vec![],
|
||||||
shader_buffers: vec![],
|
shader_buffers: vec![],
|
||||||
font_buffers: vec![],
|
font_buffers: vec![],
|
||||||
|
|
||||||
queue: queue.clone(),
|
queue: Some(queue.clone()),
|
||||||
device: device.clone(),
|
device: Some(device.clone()),
|
||||||
render_pass: render_pass.clone(),
|
render_pass: Some(render_pass.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -310,7 +310,7 @@ impl CanvasState {
|
|||||||
let image = CanvasImage {
|
let image = CanvasImage {
|
||||||
handle: handle.clone(),
|
handle: handle.clone(),
|
||||||
buffer: AttachmentImage::with_usage(
|
buffer: AttachmentImage::with_usage(
|
||||||
self.device.clone(),
|
self.device.clone().unwrap(),
|
||||||
[dimensions.0, dimensions.1],
|
[dimensions.0, dimensions.1],
|
||||||
Format::R8G8B8A8Uint,
|
Format::R8G8B8A8Uint,
|
||||||
usage).unwrap(),
|
usage).unwrap(),
|
||||||
@@ -364,7 +364,7 @@ impl CanvasState {
|
|||||||
image_buffer.iter().cloned(),
|
image_buffer.iter().cloned(),
|
||||||
Dimensions::Dim2d { width: xy.0, height: xy.1 },
|
Dimensions::Dim2d { width: xy.0, height: xy.1 },
|
||||||
Format::R8G8B8A8Srgb,
|
Format::R8G8B8A8Srgb,
|
||||||
self.queue.clone(),
|
self.queue.clone().unwrap(),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
texture
|
texture
|
||||||
@@ -391,8 +391,7 @@ impl CanvasState {
|
|||||||
/// Load and Compile a shader with the filename at resources/shaders
|
/// Load and Compile a shader with the filename at resources/shaders
|
||||||
/// 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, V>(&mut self,
|
pub fn load_shader<T, V>(&mut self,
|
||||||
filename: String,
|
filename: String) -> Option<Arc<CompiledShaderHandle>>
|
||||||
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
|
|
||||||
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
|
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
|
||||||
|
|
||||||
let handle = Arc::new(CompiledShaderHandle {
|
let handle = Arc::new(CompiledShaderHandle {
|
||||||
@@ -401,9 +400,9 @@ impl CanvasState {
|
|||||||
|
|
||||||
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
|
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
|
||||||
filename.clone(),
|
filename.clone(),
|
||||||
self.device.clone(),
|
self.device.clone().unwrap(),
|
||||||
handle.clone(),
|
handle.clone(),
|
||||||
self.render_pass.clone(),
|
self.render_pass.clone().unwrap(),
|
||||||
));
|
));
|
||||||
|
|
||||||
self.shader_buffers.push(Arc::new(shader));
|
self.shader_buffers.push(Arc::new(shader));
|
||||||
@@ -461,7 +460,7 @@ impl CanvasState {
|
|||||||
name: name,
|
name: name,
|
||||||
buffer: ImmutableBuffer::from_iter(
|
buffer: ImmutableBuffer::from_iter(
|
||||||
accumulator.iter().cloned(),
|
accumulator.iter().cloned(),
|
||||||
BufferUsage::vertex_buffer(), self.queue.clone()).unwrap().0,
|
BufferUsage::vertex_buffer(), self.queue.clone().unwrap()).unwrap().0,
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -556,7 +555,7 @@ impl CanvasState {
|
|||||||
allocated_colored_buffer.push(ImmutableBuffer::from_iter(
|
allocated_colored_buffer.push(ImmutableBuffer::from_iter(
|
||||||
colored_vertex_buffer.iter().cloned(),
|
colored_vertex_buffer.iter().cloned(),
|
||||||
BufferUsage::vertex_buffer(),
|
BufferUsage::vertex_buffer(),
|
||||||
self.queue.clone(),
|
self.queue.clone().unwrap(),
|
||||||
).unwrap().0);
|
).unwrap().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,7 +564,7 @@ impl CanvasState {
|
|||||||
allocated_text_buffer.push(ImmutableBuffer::from_iter(
|
allocated_text_buffer.push(ImmutableBuffer::from_iter(
|
||||||
text_vertex_buffer.iter().cloned(),
|
text_vertex_buffer.iter().cloned(),
|
||||||
BufferUsage::vertex_buffer(),
|
BufferUsage::vertex_buffer(),
|
||||||
self.queue.clone(),
|
self.queue.clone().unwrap(),
|
||||||
).unwrap().0);
|
).unwrap().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -576,7 +575,7 @@ impl CanvasState {
|
|||||||
ImmutableBuffer::from_iter(
|
ImmutableBuffer::from_iter(
|
||||||
v.iter().cloned(),
|
v.iter().cloned(),
|
||||||
BufferUsage::vertex_buffer(),
|
BufferUsage::vertex_buffer(),
|
||||||
self.queue.clone(),
|
self.queue.clone().unwrap(),
|
||||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||||
}).collect(),
|
}).collect(),
|
||||||
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
|
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
|
||||||
@@ -584,7 +583,7 @@ impl CanvasState {
|
|||||||
ImmutableBuffer::from_iter(
|
ImmutableBuffer::from_iter(
|
||||||
v.iter().cloned(),
|
v.iter().cloned(),
|
||||||
BufferUsage::vertex_buffer(),
|
BufferUsage::vertex_buffer(),
|
||||||
self.queue.clone(),
|
self.queue.clone().unwrap(),
|
||||||
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
|
||||||
}).collect(),
|
}).collect(),
|
||||||
text_instances: Default::default(),
|
text_instances: Default::default(),
|
||||||
@@ -669,7 +668,7 @@ impl CanvasState {
|
|||||||
for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
|
for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
|
||||||
let handle = texture_handle.clone().get_handle() as usize;
|
let handle = texture_handle.clone().get_handle() as usize;
|
||||||
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
|
||||||
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
|
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone().unwrap());
|
||||||
|
|
||||||
command_buffer = command_buffer.draw(
|
command_buffer = command_buffer.draw(
|
||||||
shader.get_pipeline().clone(),
|
shader.get_pipeline().clone(),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::drawables::compu_sprite::CompuSprite;
|
|||||||
use crate::canvas::canvas_frame::Drawable;
|
use crate::canvas::canvas_frame::Drawable;
|
||||||
use crate::util::vertex::VertexTypeContainer;
|
use crate::util::vertex::VertexTypeContainer;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct CompuFrame {
|
pub struct CompuFrame {
|
||||||
// Vec<(Buffer, Kernel)>
|
// Vec<(Buffer, Kernel)>
|
||||||
pub pure_compute: Vec<(
|
pub pure_compute: Vec<(
|
||||||
|
|||||||
97
src/main.rs
97
src/main.rs
@@ -23,7 +23,7 @@ use winit::dpi::LogicalSize;
|
|||||||
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent};
|
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent};
|
||||||
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
|
||||||
use winit::platform::unix::WindowBuilderExtUnix;
|
use winit::platform::unix::WindowBuilderExtUnix;
|
||||||
use winit::window::WindowBuilder;
|
use winit::window::{WindowBuilder, Window};
|
||||||
|
|
||||||
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable};
|
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable};
|
||||||
use crate::canvas::canvas_state::CanvasState;
|
use crate::canvas::canvas_state::CanvasState;
|
||||||
@@ -50,16 +50,15 @@ pub mod canvas;
|
|||||||
extern crate specs;
|
extern crate specs;
|
||||||
|
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
|
use vulkano::swapchain::Surface;
|
||||||
|
|
||||||
|
|
||||||
struct Draws(VertexTypeContainer);
|
struct Draws(Sprite);
|
||||||
|
|
||||||
impl Component for Draws {
|
impl Component for Draws {
|
||||||
type Storage = VecStorage<Self>;
|
type Storage = VecStorage<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Renderer(u32);
|
|
||||||
|
|
||||||
struct Vel(f32);
|
struct Vel(f32);
|
||||||
|
|
||||||
impl Component for Vel {
|
impl Component for Vel {
|
||||||
@@ -72,17 +71,33 @@ impl Component for Pos {
|
|||||||
type Storage = VecStorage<Self>;
|
type Storage = VecStorage<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RenderSystem;
|
#[derive(Default)]
|
||||||
|
struct PersistentState {
|
||||||
|
surface: Option<Arc<Surface<Window>>>,
|
||||||
|
window_size: (u32, u32),
|
||||||
|
canvas_frame: CanvasFrame,
|
||||||
|
compu_frame: CompuFrame,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct RenderSystem;
|
||||||
impl<'a> System<'a> for RenderSystem {
|
impl<'a> System<'a> for RenderSystem {
|
||||||
|
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
WriteStorage<'a, Pos>,
|
WriteStorage<'a, Pos>,
|
||||||
WriteStorage<'a, Vel>,
|
WriteStorage<'a, Vel>,
|
||||||
WriteStorage<'a, Draws>,
|
WriteStorage<'a, Draws>,
|
||||||
|
Write<'a, PersistentState>,
|
||||||
|
Write<'a, VkProcessor>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, (mut pos, vel, data): Self::SystemData) {
|
fn run(&mut self, (mut pos, vel, draw, mut state, mut vk_processor): Self::SystemData) {
|
||||||
|
|
||||||
|
state.canvas_frame = CanvasFrame::new(state.window_size);
|
||||||
|
state.compu_frame = CompuFrame::new(state.window_size);
|
||||||
|
|
||||||
|
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||||
|
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||||
|
|
||||||
// The `.join()` combines multiple components,
|
// The `.join()` combines multiple components,
|
||||||
// so we only access those entities which have
|
// so we only access those entities which have
|
||||||
@@ -92,9 +107,19 @@ impl<'a> System<'a> for RenderSystem {
|
|||||||
// and Velocity together; it's also possible to do this
|
// and Velocity together; it's also possible to do this
|
||||||
// in parallel using rayon's `ParallelIterator`s.
|
// in parallel using rayon's `ParallelIterator`s.
|
||||||
// See `ParJoin` for more.
|
// See `ParJoin` for more.
|
||||||
for (pos, vel) in (&mut pos, &vel).join() {
|
|
||||||
pos.0 += vel.0;
|
for draw_data in (&draw).join() {
|
||||||
|
let size = state.window_size.clone();
|
||||||
|
state.canvas_frame.add(draw_data.0.get(size))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vk_processor.run(&state.surface.clone().unwrap(),
|
||||||
|
&state.canvas_frame,
|
||||||
|
&state.compu_frame);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +184,7 @@ pub fn main() {
|
|||||||
|
|
||||||
let mut timer = Timer::new();
|
let mut timer = Timer::new();
|
||||||
let mut frame_future: Box<dyn GpuFuture> =
|
let mut frame_future: Box<dyn GpuFuture> =
|
||||||
Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
|
Box::new(sync::now(processor.device.clone().unwrap())) as Box<dyn GpuFuture>;
|
||||||
|
|
||||||
let step_size: f32 = 0.005;
|
let step_size: f32 = 0.005;
|
||||||
let mut elapsed_time: f32 = timer.elap_time();
|
let mut elapsed_time: f32 = timer.elap_time();
|
||||||
@@ -214,9 +239,13 @@ pub fn main() {
|
|||||||
world.register::<Pos>();
|
world.register::<Pos>();
|
||||||
world.register::<Vel>();
|
world.register::<Vel>();
|
||||||
world.register::<Draws>();
|
world.register::<Draws>();
|
||||||
world.insert::<Renderer>(Renderer(10));
|
|
||||||
world.insert::<VkProcessor>(processor);
|
world.insert::<VkProcessor>(processor);
|
||||||
|
world.insert::<PersistentState>(PersistentState {
|
||||||
|
surface: Some(surface.clone()),
|
||||||
|
window_size: (0, 0),
|
||||||
|
canvas_frame: CanvasFrame::new((0,0)),
|
||||||
|
compu_frame: CompuFrame::new((0,0)),
|
||||||
|
});
|
||||||
|
|
||||||
// An entity may or may not contain some component.
|
// An entity may or may not contain some component.
|
||||||
world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build();
|
world.create_entity().with(Vel(2.0)).with(Pos(0.0)).build();
|
||||||
@@ -232,9 +261,6 @@ pub fn main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut funky_sprite = Sprite::new(
|
let mut funky_sprite = Sprite::new(
|
||||||
(200.0, 200.0),
|
(200.0, 200.0),
|
||||||
(100.0, 150.0), 10, funky_handle.clone());
|
(100.0, 150.0), 10, funky_handle.clone());
|
||||||
@@ -242,15 +268,18 @@ pub fn main() {
|
|||||||
|
|
||||||
let slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
let slider = Slider::new((300.0, 50.0), (550.0, 100.0), 30000);
|
||||||
|
|
||||||
//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));
|
|
||||||
|
|
||||||
drop(q2);
|
drop(q2);
|
||||||
drop(q1);
|
drop(q1);
|
||||||
|
|
||||||
let l = hprof::enter("Loop");
|
let l = hprof::enter("Loop");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let event_loop_proxy = events_loop.create_proxy();
|
let event_loop_proxy = events_loop.create_proxy();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
@@ -285,11 +314,6 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut window_size: (u32, u32) = (0, 0);
|
|
||||||
|
|
||||||
let mut canvas_frame = CanvasFrame::new(window_size);
|
|
||||||
let mut compu_frame = CompuFrame::new(window_size);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// What would the component for a sprite be...
|
// What would the component for a sprite be...
|
||||||
@@ -320,11 +344,8 @@ pub fn main() {
|
|||||||
match event {
|
match event {
|
||||||
Event::NewEvents(cause) => {
|
Event::NewEvents(cause) => {
|
||||||
if cause == StartCause::Init {
|
if cause == StartCause::Init {
|
||||||
canvas_frame.draw(&funky_sprite);
|
world.write_resource::<PersistentState>()
|
||||||
canvas_frame.draw(&compu_sprite1);
|
.window_size = surface.window().inner_size().into();
|
||||||
canvas_frame.draw(&slider);
|
|
||||||
|
|
||||||
window_size = surface.window().inner_size().into();
|
|
||||||
}
|
}
|
||||||
elapsed_time = timer.elap_time();
|
elapsed_time = timer.elap_time();
|
||||||
delta_time = elapsed_time - current_time;
|
delta_time = elapsed_time - current_time;
|
||||||
@@ -338,7 +359,8 @@ pub fn main() {
|
|||||||
*control_flow = ControlFlow::Exit
|
*control_flow = ControlFlow::Exit
|
||||||
}
|
}
|
||||||
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
|
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
|
||||||
world.write_resource::<VkProcessor>().swapchain_recreate_needed = true;
|
world.write_resource::<VkProcessor>()
|
||||||
|
.swapchain_recreate_needed = true;
|
||||||
let size = (new_size.width, new_size.height);
|
let size = (new_size.width, new_size.height);
|
||||||
}
|
}
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
@@ -373,25 +395,6 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
funky_sprite.update(delta_time);
|
|
||||||
|
|
||||||
canvas_frame = CanvasFrame::new(window_size);
|
|
||||||
canvas_frame.draw(&funky_sprite);
|
|
||||||
//canvas_frame.draw(&container);
|
|
||||||
// canvas_frame.draw(&compu_sprite1);
|
|
||||||
canvas_frame.draw(&slider);
|
|
||||||
|
|
||||||
compu_frame = CompuFrame::new(window_size);
|
|
||||||
// compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
|
||||||
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
|
||||||
|
|
||||||
{
|
|
||||||
let g = hprof::enter("Run");
|
|
||||||
world.write_resource::<VkProcessor>()
|
|
||||||
.run(&surface.clone(),
|
|
||||||
&canvas_frame,
|
|
||||||
&compu_frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
// while (accumulator_time - step_size) >= step_size {
|
// while (accumulator_time - step_size) >= step_size {
|
||||||
// accumulator_time -= step_size;
|
// accumulator_time -= step_size;
|
||||||
|
|||||||
@@ -30,12 +30,13 @@ use specs::prelude::Resource;
|
|||||||
|
|
||||||
/// 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
|
||||||
|
#[derive(Default)]
|
||||||
pub struct VkProcessor {
|
pub struct VkProcessor {
|
||||||
|
|
||||||
// Vulkan state fields
|
// Vulkan state fields
|
||||||
//pub physical: PhysicalDevice<'a>,
|
pub device: Option<Arc<Device>>,
|
||||||
pub device: Arc<Device>,
|
pub queues: Option<QueuesIter>,
|
||||||
pub queues: QueuesIter,
|
pub queue: Option<Arc<Queue>>,
|
||||||
pub queue: Arc<Queue>,
|
|
||||||
|
|
||||||
pub swapchain: Option<Arc<Swapchain<Window>>>,
|
pub swapchain: Option<Arc<Swapchain<Window>>>,
|
||||||
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
|
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
|
||||||
@@ -45,8 +46,6 @@ pub struct VkProcessor {
|
|||||||
/// State holding textures, images, and their related vertex buffers
|
/// State holding textures, images, and their related vertex buffers
|
||||||
canvas_state: CanvasState,
|
canvas_state: CanvasState,
|
||||||
|
|
||||||
capabilities: Capabilities,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -76,13 +75,12 @@ impl VkProcessor {
|
|||||||
let capabilities = surface.capabilities(physical).unwrap();
|
let capabilities = surface.capabilities(physical).unwrap();
|
||||||
|
|
||||||
VkProcessor {
|
VkProcessor {
|
||||||
device: device.clone(),
|
device: Some(device.clone()),
|
||||||
queue: queue.clone(),
|
queue: Some(queue.clone()),
|
||||||
queues: queues,
|
queues: Some(queues),
|
||||||
swapchain: None,
|
swapchain: None,
|
||||||
swapchain_images: None,
|
swapchain_images: None,
|
||||||
swapchain_recreate_needed: false,
|
swapchain_recreate_needed: false,
|
||||||
capabilities: capabilities.clone(),
|
|
||||||
canvas_state: CanvasState::new(queue, device, physical, capabilities),
|
canvas_state: CanvasState::new(queue, device, physical, capabilities),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,14 +110,14 @@ impl VkProcessor {
|
|||||||
panic!("window closed");
|
panic!("window closed");
|
||||||
};
|
};
|
||||||
|
|
||||||
Swapchain::new(self.device.clone(),
|
Swapchain::new(self.device.clone().unwrap(),
|
||||||
surface.clone(),
|
surface.clone(),
|
||||||
capabilities.min_image_count, // number of attachment images
|
capabilities.min_image_count, // number of attachment images
|
||||||
format,
|
format,
|
||||||
initial_dimensions,
|
initial_dimensions,
|
||||||
1, // Layers
|
1, // Layers
|
||||||
ImageUsage::color_attachment(),
|
ImageUsage::color_attachment(),
|
||||||
&self.queue,
|
(&self.queue).as_ref().unwrap(),
|
||||||
SurfaceTransform::Identity,
|
SurfaceTransform::Identity,
|
||||||
alpha,
|
alpha,
|
||||||
PresentMode::Immediate,
|
PresentMode::Immediate,
|
||||||
@@ -165,16 +163,16 @@ impl VkProcessor {
|
|||||||
|
|
||||||
/// A hardcoded list of kernels which can be preloaded from this function
|
/// A hardcoded list of kernels which can be preloaded from this function
|
||||||
pub fn preload_kernels(&mut self) {
|
pub fn preload_kernels(&mut self) {
|
||||||
self.canvas_state.new_kernel(String::from("simple-homogenize.compute"), self.device.clone());
|
self.canvas_state.new_kernel(String::from("simple-homogenize.compute"), self.device.clone().unwrap());
|
||||||
self.canvas_state.new_kernel(String::from("simple-edge.compute"), self.device.clone());
|
self.canvas_state.new_kernel(String::from("simple-edge.compute"), self.device.clone().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.capabilities.clone());
|
self.canvas_state.load_shader::<GenericShader, ColorVertex3D>(String::from("color-passthrough"));
|
||||||
self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"), self.capabilities.clone());
|
self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"));
|
||||||
self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"), self.capabilities.clone());
|
self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"));
|
||||||
self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"), self.capabilities.clone());
|
self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A hardcoded list of shaders which can be proloaded from this function
|
/// A hardcoded list of shaders which can be proloaded from this function
|
||||||
@@ -212,7 +210,7 @@ impl VkProcessor {
|
|||||||
|
|
||||||
/// Builds a compute buffer and returns it's handle
|
/// Builds a compute buffer and returns it's handle
|
||||||
pub fn new_compute_buffer(&mut self, data: Vec<u8>, dimensions: (u32, u32), stride: u32) -> Arc<CompuBufferHandle> {
|
pub fn new_compute_buffer(&mut self, data: Vec<u8>, dimensions: (u32, u32), stride: u32) -> Arc<CompuBufferHandle> {
|
||||||
self.canvas_state.new_compute_buffer(data, dimensions, stride, self.device.clone())
|
self.canvas_state.new_compute_buffer(data, dimensions, stride, self.device.clone().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes a compute buffer handle and returns the read data
|
/// Takes a compute buffer handle and returns the read data
|
||||||
@@ -233,7 +231,7 @@ impl VkProcessor {
|
|||||||
) {
|
) {
|
||||||
{
|
{
|
||||||
let g = hprof::enter("Waiting at queue");
|
let g = hprof::enter("Waiting at queue");
|
||||||
self.queue.wait();
|
self.queue.as_ref().unwrap().wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
let g = hprof::enter("Frame buffer, future, swapchain recreate");
|
let g = hprof::enter("Frame buffer, future, swapchain recreate");
|
||||||
@@ -280,7 +278,7 @@ impl VkProcessor {
|
|||||||
// let mut draw_text = DrawText::new(self.device.clone(), self.queue.clone(), self.swapchain.unwrap().clone(), &self.swapchain_images.images);
|
// let mut draw_text = DrawText::new(self.device.clone(), self.queue.clone(), self.swapchain.unwrap().clone(), &self.swapchain_images.images);
|
||||||
|
|
||||||
let mut command_buffer =
|
let mut command_buffer =
|
||||||
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap();
|
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone().unwrap(), self.queue.as_ref().unwrap().family()).unwrap();
|
||||||
|
|
||||||
let g = hprof::enter("Push compute commands to command buffer");
|
let g = hprof::enter("Push compute commands to command buffer");
|
||||||
// Add the compute commands
|
// Add the compute commands
|
||||||
@@ -300,15 +298,15 @@ impl VkProcessor {
|
|||||||
// Wait on the previous frame, then execute the command buffer and present the image
|
// Wait on the previous frame, then execute the command buffer and present the image
|
||||||
{
|
{
|
||||||
let g = hprof::enter("Joining on the framebuffer");
|
let g = hprof::enter("Joining on the framebuffer");
|
||||||
let mut future = sync::now(self.device.clone())
|
let mut future = sync::now(self.device.clone().unwrap())
|
||||||
.join(acquire_future);
|
.join(acquire_future);
|
||||||
drop(g);
|
drop(g);
|
||||||
|
|
||||||
let g = hprof::enter("Running the kernel and waiting on the future");
|
let g = hprof::enter("Running the kernel and waiting on the future");
|
||||||
|
|
||||||
let future = future
|
let future = future
|
||||||
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
.then_execute(self.queue.clone().unwrap(), command_buffer).unwrap()
|
||||||
.then_swapchain_present(self.queue.clone(), self.swapchain.clone().unwrap().clone(), image_num)
|
.then_swapchain_present(self.queue.clone().unwrap(), self.swapchain.clone().unwrap().clone(), image_num)
|
||||||
.then_signal_fence_and_flush();
|
.then_signal_fence_and_flush();
|
||||||
|
|
||||||
match future {
|
match future {
|
||||||
|
|||||||
Reference in New Issue
Block a user