Compare commits

..

No commits in common. 'a-star' and 'master' have entirely different histories.

@ -18,7 +18,6 @@ vulkano-win = "0.19.0"
#shade_runner = {version = "0.1.1", git = "https://github.com/MitchellHansen/shade_runner"}
shade_runner = {path = "../shade_runner"}
specs = "0.16.1"
gilrs = "0.7.2"
cgmath = "0.17.0"
simple-stopwatch="0.1.4"
@ -32,4 +31,3 @@ winit = "0.22.0"
hprof = "0.1.3"
rusttype = { version = "0.7.0", features = ["gpu_cache"] }
vulkano_text = "0.12.0"
petgraph = "0.5.1"

@ -1,53 +0,0 @@
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2020-08-06T21:51:48-07:00
====== MakingAnActualThing ======
Created Thursday 06 August 2020
So, I need to figure out how to determine which objects will :
* Be rendered
* Be notified
* Get batched
* And initialized
Looks like it could possibly be specs...
Sprites currently are just a container for the meta-information needed in order to return a VertexTypeContainer.
{{{code: lang="rust" linenumbers="True"
pub enum VertexTypeContainer {
TextureType(Vec<TextureVertex3D>, Arc<CanvasTextureHandle>),
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex3D>),
ThreeDType(Vec<Vertex3D>),
TextType(Vec<ColorVertex3D>),
}
}}}
So for a sprite, which is a generic texture and position/size combo
Images are similar, but instead of a "sprite" I made a computsprite because that's the only thing that uses them.
Now if I had to shove these into a component / a set of components... I could have a component of the vertex type even?
===== Sep 2020 =====
Lets think about this for a minute...
* We have components which are purely data...
* But can also have structs that impl functionality
* The data can be contained within traits. But it has to do all IO through the trait interface. ALL
* Problem, for example I have primitives like textured sprites, and also complex widgets which also have additional IO they they need. Like text input or buttons. I suppose This could all be made message based. So when the text input receives a focus, and then key presses it would update. When the enter key is pressed it could create a customer event for which another component is the listener...
* Maybe this is the way to go... Have some generic structure that has a render(params), notify(event), update(delta) -> VEvent
* So if I had a textbox sprite it could notify(key events) render
* We can split up components in order to have sharable sets of data for shared functionality. e.g rendering
[[paste]]
So that article more or less talked about what I was thinking with the ECS. But they didn't really go into the separation of components.

@ -1,40 +0,0 @@
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2020-09-09T22:41:18-07:00
====== paste ======
Created Wednesday 09 September 2020
// If I were to have multiple systems
/*
One for rendering
One for updating
One for eventing
Rendering is easy enough. It needs all the components necessary in order
to generate the vertices. This includes the position, size, and vertex generator
Updating can probably be multiple types, I imagine something that implemented an Updatable
trait could then be used.
So the big problem here is that I have two traits that I want to expose, BUT
I have to put the concrete value in both containers... I don't think this is something
that specs will like since it wants to be the only owner. No use in RefCell'ing it
because that's just stupid
What if I turn this on it's head and really embrace the systems. So for example I could have
the User system. Ooof this is a big question actually...
// Components that want to be updated
Move
// want to be drawn
Drawable
Geom
Notifyable
*/

File diff suppressed because one or more lines are too long

@ -6,64 +6,45 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
use vulkano::pipeline::vertex::Vertex;
use std::any::Any;
use crate::{VertexTypeContainer};
use crate::VertexType;
use winit::event::Event;
use crate::util::tr_event::{TrEvent, TrUIEvent};
use crate::render_system::Position;
enum CustomEvent {
}
/// Trait which may be inherited by objects that wish to be drawn to the screen
pub trait Drawable {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType>;
}
// Render expects the implementer to create custom render logic based on interior data within
// the struct. This data as of right now, will *only* be mutatable via events & update
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer>;
/// Trait which may be inherited by objects that wish to receive events
pub trait Eventable<T> {
fn notify(&mut self, event: &Event<T>) -> ();
}
/// Trait which may be inherited by objects that wish to be updated
pub trait Updatable {
fn update(&mut self, delta_time: f32) -> ();
}
/// Accumulator for Vectors of VertexTypes
#[derive(Default)]
pub struct CanvasFrame {
pub map: Vec<VertexTypeContainer>,
pub map: Vec<VertexType>,
window_size: (u32, u32),
}
impl CanvasFrame {
pub fn new(window_size: (u32, u32)) -> CanvasFrame {
CanvasFrame {
map: vec![],
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 {
pub fn draw(&mut self, drawable: &dyn Drawable) {
for i in drawable.get(self.window_size) {
self.map.push(i);
}
}
// /// Push this drawable onto the back of the accumulator
// pub fn draw(&mut self, drawable: &dyn Drawable, pos: Position, geom: Geometry) {
// for i in drawable.render(
// self.window_size,
// (mv.pos_x, mv.pos_y),
// geom.rotation,
// (geom.size_x, geom.size_y),
// geom.depth
// ) {
// self.map.push(i);
// }
// }
}

@ -27,27 +27,24 @@ use std::io::Read;
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment};
use vulkano::pipeline::vertex::{VertexDefinition, Vertex};
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle, CompuBufferHandle, CompuKernelHandle};
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle, DrawableHandle};
use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont};
use crate::canvas::managed::shader::shader_common::CompiledShader;
use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::VertexTypeContainer;
use crate::VertexType;
use crate::util::vertex::{TextVertex3D, TextureVertex3D, ImageVertex3D, ColorVertex3D, CanvasFrameAllocation};
use shade_runner::Input;
use winit::window::Window;
use crate::canvas::managed::compu_buffer::CompuBuffers;
use crate::canvas::managed::compu_kernel::CompuKernel;
use crate::canvas::compu_frame::CompuFrame;
/// 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
#[derive(Clone, Default)]
#[derive(Clone)]
pub struct CanvasState {
/// Generated during new()
dynamic_state: DynamicState,
/// Generated during new()
sampler: Option<Arc<Sampler>>,
sampler: Arc<Sampler>,
/// hold the image, texture, and Fonts the same was as we do CompuState
image_buffers: Vec<Arc<CanvasImage>>,
@ -55,15 +52,12 @@ pub struct CanvasState {
font_buffers: Vec<Arc<CanvasFont>>,
/// Compiled Graphics pipelines have a handle which self describe their position in this vector
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + Sync>>>,
shader_buffers: Vec<Arc<Box<dyn CompiledShader>>>,
/// Looks like we gotta hold onto the queue for managing textures
queue: Option<Arc<Queue>>,
device: Option<Arc<Device>>,
render_pass: Option<Arc<dyn RenderPassAbstract + Send + Sync>>,
compute_buffers: Vec<CompuBuffers>,
kernels: Vec<CompuKernel>,
queue: Arc<Queue>,
device: Arc<Device>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,
}
@ -81,11 +75,11 @@ impl CanvasState {
}]);
let dimensions = [dimensions.width(), dimensions.height()];
let depth_buffer = AttachmentImage::transient(self.device.clone().unwrap(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
let depth_buffer = AttachmentImage::transient(self.device.clone(), dimensions, Format::D32Sfloat_S8Uint).unwrap();
images.iter().map(|image| {
Arc::new(
Framebuffer::start(self.render_pass.clone().unwrap())
Framebuffer::start(self.render_pass.clone())
.add(image.clone()).unwrap()
.add(depth_buffer.clone()).unwrap()
.build().unwrap()
@ -139,9 +133,6 @@ impl CanvasState {
CanvasState {
compute_buffers: vec![],
kernels: vec![],
// TODO: Might need to move this
dynamic_state: DynamicState {
line_width: None,
@ -160,147 +151,20 @@ impl CanvasState {
value: 0xFF,
}),
},
sampler: Some(Sampler::new(device.clone(),
sampler: Sampler::new(device.clone(),
Filter::Linear, Filter::Linear,
MipmapMode::Nearest,
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![],
texture_buffers: vec![],
shader_buffers: vec![],
font_buffers: vec![],
queue: Some(queue.clone()),
device: Some(device.clone()),
render_pass: Some(render_pass.clone()),
}
}
pub fn read_compute_buffer(&mut self, handle: Arc<CompuBufferHandle>) -> Vec<u8> {
let mut buffer : &CompuBuffers = self.compute_buffers.get(handle.handle as usize).unwrap();
let v = buffer.read_output_buffer();
v.into_vec()
}
/// Write to the compute buffer, ostensibly overwriting what's already there
pub fn write_compute_buffer(&self, handle: Arc<CompuBufferHandle>, data: Vec<u8>) {
unimplemented!("read_compute_buffer is not implemented")
}
pub fn new_kernel(&mut self,
filename: String,
device: Arc<Device>) -> Arc<CompuKernelHandle> {
let handle = Arc::new(CompuKernelHandle {
handle: self.kernels.len() as u32
});
self.kernels.push((CompuKernel::new(filename, device.clone(), handle.clone())));
handle
}
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
for i in self.kernels.clone() {
if i.get_name() == kernel_name {
return Some(i.get_handle());
}
}
None
queue: queue.clone(),
device: device.clone(),
render_pass: render_pass.clone(),
}
pub fn compute_commands(&mut self,
compute_frame: &CompuFrame,
mut command_buffer: &mut AutoCommandBufferBuilder) {
// i = (Buffer, Kernel)
for i in &compute_frame.pure_compute {
let buffer_id = (*i.0).clone().get_handle() as usize;
let kernel_id = (*i.1).clone().get_handle() as usize;
let buffer = self.compute_buffers.get(buffer_id).unwrap();
let kernel = self.kernels.get(kernel_id).unwrap();
let pipeline = kernel.clone().get_pipeline();
let descriptorset = buffer.get_descriptor_set(kernel.clone().get_pipeline());
let size = buffer.get_size();
command_buffer = command_buffer
.dispatch([size.0 / 8, size.1 / 8, 1], pipeline, descriptorset, ()).unwrap()
}
// i = (Buffer, Image, Kernel)
for i in &compute_frame.swapped_to_image {
let buffer_id = (*i.0).clone().get_handle() as usize;
let image_id = i.1.clone();
let kernel_id = (*i.2).clone().handle as usize;
let buffer = self.compute_buffers.get(buffer_id).unwrap();
let image = self.get_image(image_id);
let kernel = self.kernels.get(kernel_id).unwrap();
let p = kernel.clone().get_pipeline();
let d = buffer.get_descriptor_set(kernel.clone().get_pipeline());
let dimensions = image.dimensions();
let dimensions = (dimensions.width(), dimensions.height());
if dimensions != buffer.get_size() {
panic!("Buffer sizes not the same");
}
let size = buffer.get_size();
command_buffer = command_buffer
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
.copy_buffer_to_image(buffer.get_output_buffer(), image).unwrap();
}
// i = (Input Buffer, Output Buffer, Kernel)
// Input buffer -> Kernel -> Output buffer
for i in &compute_frame.swapped_to_buffer {
let input_buffer_id = (*i.0).clone().get_handle() as usize;
let output_buffer_id = (*i.1).clone().get_handle() as usize;
let kernel_id = (*i.2).clone().handle as usize;
let input_buffer = self.compute_buffers.get(input_buffer_id).unwrap();
let output_buffer = self.compute_buffers.get(output_buffer_id).unwrap();
let kernel = self.kernels.get(kernel_id).unwrap();
let pipeline = kernel.clone().get_pipeline();
let descriptor_set = input_buffer.get_descriptor_set(kernel.clone().get_pipeline());
if input_buffer.get_size() != output_buffer.get_size() {
panic!("Buffer sizes not the same");
}
let size = input_buffer.get_size();
command_buffer = command_buffer
// .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
.copy_buffer(
input_buffer.get_output_buffer(),
output_buffer.get_input_buffer()).unwrap();
}
}
/// Creates a 2d compute buffer from incoming data
pub fn new_compute_buffer(&mut self,
data: Vec<u8>,
dimensions: (u32, u32),
stride: u32,
device: Arc<Device>) -> Arc<CompuBufferHandle> {
let handle = Arc::new(CompuBufferHandle {
handle: self.compute_buffers.len() as u32
});
self.compute_buffers.push(
(CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())));
handle
}
/// Using the dimensions and suggested usage, load a CanvasImage and return it's handle
@ -310,7 +174,7 @@ impl CanvasState {
let image = CanvasImage {
handle: handle.clone(),
buffer: AttachmentImage::with_usage(
self.device.clone().unwrap(),
self.device.clone(),
[dimensions.0, dimensions.1],
Format::R8G8B8A8Uint,
usage).unwrap(),
@ -364,7 +228,7 @@ impl CanvasState {
image_buffer.iter().cloned(),
Dimensions::Dim2d { width: xy.0, height: xy.1 },
Format::R8G8B8A8Srgb,
self.queue.clone().unwrap(),
self.queue.clone(),
).unwrap();
texture
@ -390,19 +254,19 @@ impl CanvasState {
/// Load and Compile a shader with the filename at resources/shaders
/// Takes physical and capabilities as we don't store that in Canvas
pub fn load_shader<T, V>(&mut self,
filename: String) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
pub fn load_shader<T: 'static, V>(&mut self,
filename: String,
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledShader, V: Vertex {
let handle = Arc::new(CompiledShaderHandle {
handle: self.shader_buffers.len() as u32
});
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
let shader: Box<dyn CompiledShader> = Box::new(T::new::<V>(
filename.clone(),
self.device.clone().unwrap(),
self.device.clone(),
handle.clone(),
self.render_pass.clone().unwrap(),
self.render_pass.clone(),
));
self.shader_buffers.push(Arc::new(shader));
@ -460,7 +324,7 @@ impl CanvasState {
name: name,
buffer: ImmutableBuffer::from_iter(
accumulator.iter().cloned(),
BufferUsage::vertex_buffer(), self.queue.clone().unwrap()).unwrap().0,
BufferUsage::vertex_buffer(), self.queue.clone()).unwrap().0,
}
}));
@ -532,19 +396,19 @@ impl CanvasState {
// separate the mux of vertex containers back out
for value in &canvas_frame.map {
match value {
VertexTypeContainer::TextureType(vertices, handle) => {
VertexType::TextureType(vertices, handle) => {
textured_vertex_buffer.entry(handle.clone()).or_insert(vertices.clone()).extend(vertices);
}
VertexTypeContainer::ImageType(vertices, handle) => {
VertexType::ImageType(vertices, handle) => {
image_vertex_buffer.entry(handle.clone()).or_insert(vertices.clone()).extend(vertices);
}
VertexTypeContainer::ColorType(vertices) => {
VertexType::ColorType(vertices) => {
colored_vertex_buffer.extend(vertices);
}
VertexTypeContainer::ThreeDType(vertices) => {
VertexType::ThreeDType(vertices) => {
}
VertexTypeContainer::TextType(vertices) => {
VertexType::TextType(vertices) => {
text_vertex_buffer.extend(vertices);
}
};
@ -555,7 +419,7 @@ impl CanvasState {
allocated_colored_buffer.push(ImmutableBuffer::from_iter(
colored_vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone().unwrap(),
self.queue.clone(),
).unwrap().0);
}
@ -564,7 +428,7 @@ impl CanvasState {
allocated_text_buffer.push(ImmutableBuffer::from_iter(
text_vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone().unwrap(),
self.queue.clone(),
).unwrap().0);
}
@ -575,7 +439,7 @@ impl CanvasState {
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone().unwrap(),
self.queue.clone(),
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
}).collect(),
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
@ -583,7 +447,7 @@ impl CanvasState {
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone().unwrap(),
self.queue.clone(),
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
}).collect(),
text_instances: Default::default(),
@ -668,7 +532,7 @@ impl CanvasState {
for (texture_handle, vertex_buffer) in allocated_buffers.textured_vertex_buffer.clone() {
let handle = texture_handle.clone().get_handle() as usize;
let descriptor_set = self.texture_buffers.get(handle).clone().unwrap().clone()
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone().unwrap());
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone());
command_buffer = command_buffer.draw(
shader.get_pipeline().clone(),

@ -57,31 +57,4 @@ impl Handle for CompiledShaderHandle {
}
}
/// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompuBufferHandle {
pub(in crate::canvas) handle: u32,
}
impl Handle for CompuBufferHandle {
fn get_handle(&self) -> u32 {
self.handle
}
}
/// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompuKernelHandle {
pub(in crate::canvas) handle: u32,
}
impl Handle for CompuKernelHandle {
fn get_handle(&self) -> u32 {
self.handle
}
}

@ -3,8 +3,6 @@ pub mod shader;
pub mod handles;
pub mod canvas_text;
pub mod gpu_buffers;
pub mod compu_buffer;
pub mod compu_kernel;
use vulkano::pipeline::shader::{SpecializationConstants, SpecializationMapEntry};

@ -18,7 +18,7 @@ use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledShaderRe
use crate::canvas::managed::handles::CompiledShaderHandle;
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
use crate::canvas::managed::ShaderSpecializationConstants;
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D};
use crate::util::vertex::{VertexType, ColorVertex3D};
/// CanvasShader holds the pipeline and render pass for the input shader source
#[derive(Clone)]

@ -98,18 +98,19 @@ pub trait CompiledShaderResources {
}
}
pub trait CompiledShader {
fn new<V: Vertex + Send>(filename: String,
fn new<V>(filename: String,
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
-> Self where Self: Sized + Send + Sync;
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized, V: Vertex,;
fn get_name(&self) -> String;
fn get_handle(&self) -> Arc<CompiledShaderHandle>;
fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
fn get_renderpass(&self) -> Arc<dyn RenderPassAbstract + Send + Sync>;
fn recompile<V: Vertex + Send>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
-> Self where Self: Sized + Send;
fn recompile<V: Vertex>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)
-> Self where Self: Sized;
}
/// Legacy ShaderType enum for single type shaders.

@ -2,6 +2,5 @@
pub mod canvas_state;
pub mod canvas_frame;
pub mod managed;
pub mod compu_frame;

@ -1,58 +0,0 @@
use std::sync::Arc;
use specs::{Component, Join, System, VecStorage, Write, WriteStorage};
use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle, CompuBufferHandle, CompuKernelHandle};
use crate::PersistentState;
use crate::render_system::{Geometry, Images, Position, Textures};
use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
use crate::vkprocessor::VkProcessor;
pub struct Compu {
pub kernels: Vec<Arc<CompuKernelHandle>>,
pub buffers: Vec<Arc<CompuBufferHandle>>,
}
impl Component for Compu {
type Storage = VecStorage<Self>;
}
pub struct CompuSystem;
impl<'a> System<'a> for CompuSystem {
type SystemData = (
WriteStorage<'a, Compu>,
WriteStorage<'a, Images>,
Write<'a, PersistentState>, // delta_time, window size, etc.
Write<'a, VkProcessor>, // Renderer
);
fn run(&mut self, (
mut compu_list,
mut image_list,
mut state,
mut vk_processor
): Self::SystemData) {
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());
for (compute_item, image) in (&mut compu_list, &mut image_list).join() {
state.compu_frame.add_with_image_swap(
compute_item.buffers.get(0).unwrap().clone(),
compute_item.kernels.get(0).unwrap().clone(),
image,
);
}
for (compute_item) in (&mut compu_list).join() {
state.compu_frame.add(
compute_item.buffers.get(0).unwrap().clone(),
compute_item.kernels.get(0).unwrap().clone(),
);
}
}
}

@ -1,12 +1,10 @@
use std::sync::Arc;
use crate::canvas::managed::handles::{CanvasImageHandle, CompuBufferHandle};
use crate::canvas::managed::handles::{CompuKernelHandle};
use crate::canvas::managed::handles::{CanvasImageHandle};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::drawables::compu_sprite::CompuSprite;
use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::VertexTypeContainer;
use crate::render_system::{Images, Geometry};
use crate::util::vertex::VertexType;
#[derive(Default)]
pub struct CompuFrame {
// Vec<(Buffer, Kernel)>
pub pure_compute: Vec<(
@ -57,9 +55,15 @@ impl CompuFrame {
pub fn add_with_image_swap(&mut self,
buffer: Arc<CompuBufferHandle>,
kernel: Arc<CompuKernelHandle>,
images: &Images,
) {
self.swapped_to_image.push((buffer, images.images.get(0).unwrap().clone(), kernel))
sprite: &CompuSprite) {
let compu_sprites = sprite.get(self.window_size);
if compu_sprites.len() == 1 {
if let VertexType::ImageType(a, b) = compu_sprites.first().unwrap() {
self.swapped_to_image.push((buffer, b.clone(), kernel))
};
}
}
}

@ -0,0 +1,169 @@
use std::ffi::CStr;
use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage};
use std::sync::Arc;
use vulkano::framebuffer::RenderPassAbstract;
use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline};
use vulkano::device::Device;
use image::ImageBuffer;
use image::GenericImageView;
use vulkano::image::{ImageUsage, AttachmentImage};
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSetBuf, PersistentDescriptorSet};
use vulkano::format::Format;
use vulkano::descriptor::pipeline_layout::PipelineLayout;
use std::borrow::Borrow;
use image::Rgba;
use vulkano::command_buffer::AutoCommandBufferBuilder;
use std::path::PathBuf;
use shade_runner::{CompiledShaders, Entry, CompileError};
use vulkano::pipeline::shader::ShaderModule;
use shaderc::CompileOptions;
use crate::compute::compu_frame::CompuFrame;
use crate::canvas::managed::handles::Handle;
use crate::compute::managed::compu_buffer::CompuBuffers;
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::compute::managed::compu_kernel::CompuKernel;
use crate::canvas::canvas_state::CanvasState;
/// State holding the compute buffers for computation and the kernels which will compute them
pub struct CompuState {
compute_buffers: Vec<CompuBuffers>,
kernels: Vec<CompuKernel>,
}
impl CompuState {
pub fn new() -> CompuState {
CompuState {
compute_buffers: vec![],
kernels: vec![],
}
}
/// Creates a 2d compute buffer from incoming data
pub fn new_compute_buffer(&mut self,
data: Vec<u8>,
dimensions: (u32, u32),
stride: u32,
device: Arc<Device>) -> Arc<CompuBufferHandle> {
let handle = Arc::new(CompuBufferHandle {
handle: self.compute_buffers.len() as u32
});
self.compute_buffers.push(
(CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())));
handle
}
pub fn read_compute_buffer(&mut self, handle: Arc<CompuBufferHandle>) -> Vec<u8> {
let mut buffer : &CompuBuffers = self.compute_buffers.get(handle.handle as usize).unwrap();
let v = buffer.read_output_buffer();
v.into_vec()
}
/// Write to the compute buffer, ostensibly overwriting what's already there
pub fn write_compute_buffer(&self, handle: Arc<CompuBufferHandle>, data: Vec<u8>) {
unimplemented!("read_compute_buffer is not implemented")
}
pub fn new_kernel(&mut self,
filename: String,
device: Arc<Device>) -> Arc<CompuKernelHandle> {
let handle = Arc::new(CompuKernelHandle {
handle: self.kernels.len() as u32
});
self.kernels.push((CompuKernel::new(filename, device.clone(), handle.clone())));
handle
}
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
for i in self.kernels.clone() {
if i.get_name() == kernel_name {
return Some(i.get_handle());
}
}
None
}
pub fn compute_commands(&mut self,
compute_frame: &CompuFrame,
mut command_buffer: &mut AutoCommandBufferBuilder,
canvas: &CanvasState) {
// i = (Buffer, Kernel)
for i in &compute_frame.pure_compute {
let buffer_id = (*i.0).clone().get_handle() as usize;
let kernel_id = (*i.1).clone().get_handle() as usize;
let buffer = self.compute_buffers.get(buffer_id).unwrap();
let kernel = self.kernels.get(kernel_id).unwrap();
let pipeline = kernel.clone().get_pipeline();
let descriptorset = buffer.get_descriptor_set(kernel.clone().get_pipeline());
let size = buffer.get_size();
command_buffer = command_buffer
.dispatch([size.0 / 8, size.1 / 8, 1], pipeline, descriptorset, ()).unwrap()
}
// i = (Buffer, Image, Kernel)
for i in &compute_frame.swapped_to_image {
let buffer_id = (*i.0).clone().get_handle() as usize;
let image_id = i.1.clone();
let kernel_id = (*i.2).clone().handle as usize;
let buffer = self.compute_buffers.get(buffer_id).unwrap();
let image = canvas.get_image(image_id);
let kernel = self.kernels.get(kernel_id).unwrap();
let p = kernel.clone().get_pipeline();
let d = buffer.get_descriptor_set(kernel.clone().get_pipeline());
let dimensions = image.dimensions();
let dimensions = (dimensions[0], dimensions[1]);
if dimensions != buffer.get_size() {
panic!("Buffer sizes not the same");
}
let size = buffer.get_size();
command_buffer = command_buffer
.dispatch([size.0 / 8, size.1 / 8, 1], p, d, ()).unwrap()
.copy_buffer_to_image(buffer.get_output_buffer(), image).unwrap();
}
// i = (Input Buffer, Output Buffer, Kernel)
// Input buffer -> Kernel -> Output buffer
for i in &compute_frame.swapped_to_buffer {
let input_buffer_id = (*i.0).clone().get_handle() as usize;
let output_buffer_id = (*i.1).clone().get_handle() as usize;
let kernel_id = (*i.2).clone().handle as usize;
let input_buffer = self.compute_buffers.get(input_buffer_id).unwrap();
let output_buffer = self.compute_buffers.get(output_buffer_id).unwrap();
let kernel = self.kernels.get(kernel_id).unwrap();
let pipeline = kernel.clone().get_pipeline();
let descriptor_set = input_buffer.get_descriptor_set(kernel.clone().get_pipeline());
if input_buffer.get_size() != output_buffer.get_size() {
panic!("Buffer sizes not the same");
}
let size = input_buffer.get_size();
command_buffer = command_buffer
// .dispatch([size.0/8, size.1/8,1], pipeline, descriptor_set, ()).unwrap()
.copy_buffer(
input_buffer.get_output_buffer(),
output_buffer.get_input_buffer()).unwrap();
}
}
}

@ -7,8 +7,8 @@ use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, PersistentDes
use image::ImageBuffer;
use image::Rgba;
use shade_runner::Layout;
use crate::compute::managed::handles::CompuBufferHandle;
use vulkano::descriptor::PipelineLayoutAbstract;
use crate::canvas::managed::handles::CompuBufferHandle;
#[derive(Clone)]

@ -8,7 +8,7 @@ use vulkano::descriptor::pipeline_layout::PipelineLayout;
use shade_runner::{CompileError, Layout, Input, Output, CompiledShaders, Entry, CompiledShader};
use shaderc::CompileOptions;
use vulkano::pipeline::shader::{ShaderModule, GraphicsEntryPoint, SpecializationConstants, SpecializationMapEntry};
use crate::canvas::managed::handles::CompuKernelHandle;
use crate::compute::managed::handles::CompuKernelHandle;
#[derive(Clone)]

@ -0,0 +1,29 @@
use crate::canvas::managed::handles::Handle;
/// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompuBufferHandle {
pub(in crate::compute) handle: u32,
}
impl Handle for CompuBufferHandle {
fn get_handle(&self) -> u32 {
self.handle
}
}
/// Typed wrapper for a u32 handle
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct CompuKernelHandle {
pub(in crate::compute) handle: u32,
}
impl Handle for CompuKernelHandle {
fn get_handle(&self) -> u32 {
self.handle
}
}

@ -0,0 +1,4 @@
pub mod compu_buffer;
pub mod compu_kernel;
pub mod handles;

@ -0,0 +1,6 @@
pub mod compu_frame;
pub mod compu_state;
pub mod managed;
use crate::compute::compu_state::CompuState;
use crate::compute::compu_frame::CompuFrame;

@ -1,12 +1,11 @@
use std::sync::Arc;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ImageVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
use crate::util::vertex::{VertexType, ImageVertex3D};
pub struct CompuSprite {
pub verts: VertexTypeContainer,
pub verts: VertexType,
position: (f32, f32),
size: (f32, f32),
@ -45,7 +44,7 @@ impl CompuSprite {
];
CompuSprite {
verts: VertexTypeContainer::ImageType(verts, image_handle.clone()),
verts: VertexType::ImageType(verts, image_handle.clone()),
position: position,
size: size,
color: (0.0, 0.0, 0.0, 0.0),
@ -54,21 +53,7 @@ impl CompuSprite {
}
impl Drawable for CompuSprite {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
vec![self.verts.clone()]
}
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
}

@ -2,15 +2,14 @@ use std::sync::Arc;
use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D, ColorVertex3D};
use crate::util::vertex::{VertexType, TextureVertex3D, Vertex3D, ColorVertex3D};
use crate::drawables::sprite::Sprite;
use crate::util::tr_event::{TrUIEvent, TrEvent};
/// Convex multi verticy polygon
#[derive(Debug, Clone)]
pub struct Polygon {
pub verts: VertexTypeContainer,
pub verts: VertexType,
position: (f32, f32),
size: (f32, f32),
@ -55,30 +54,17 @@ impl Polygon {
Polygon {
verts: VertexTypeContainer::ColorType(verts),
verts: VertexType::ColorType(verts),
position: position,
size: size,
}
}
}
impl Drawable for Polygon {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
vec![self.verts.clone()]
}
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
}

@ -1,6 +1,5 @@
use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
use crate::util::vertex::{VertexType, ColorVertex3D};
///
#[derive(Debug, Clone)]
@ -74,25 +73,11 @@ impl Rect {
}
impl Drawable for Rect {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
vec![
VertexTypeContainer::ColorType(
VertexType::ColorType(
Rect::generate_vertices(window_size, self.position, self.size, self.depth, self.color)
)
]
}
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
}

@ -1,14 +1,12 @@
use std::collections::HashSet;
use winit::event::{Event, ElementState, MouseButton};
use winit::event::Event;
use crate::canvas::canvas_frame::{Drawable};
use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexTypeContainer;
use crate::util::tr_event::{TrEvent, TrWindowEvent, TrUIEvent};
use crate::util::vertex::VertexType;
#[derive(Debug, Clone)]
pub struct Slider {
handle: Rect,
guide: Vec<Rect>,
@ -30,7 +28,7 @@ impl Slider {
let left_guide_bar = Rect::new((position.0, position.1), (2.0, size.1), 1, red);
let right_guide_bar = Rect::new((position.0 + size.0, position.1), (2.0, size.1), 1, blue);
let line = Rect::new((position.0, position.1 - (size.1 / 2.0)), (size.0, 2.0), 1, green);
let line = Rect::new((position.0, position.1 - (size.1 / 2.0) ), (size.0, 2.0), 1, green);
let scale = value as f32 / u16::max_value() as f32;
let handle = Rect::new((position.0 + (size.0 * scale), position.1), (15.0, size.1), 1, rg);
@ -44,88 +42,27 @@ impl Slider {
value,
}
}
pub fn update(&mut self) {
// render the guide first
let red = (1.0, 0.0, 0.0, 0.0);
let green = (0.0, 1.0, 0.0, 0.0);
let blue = (0.0, 1.0, 1.0, 0.0);
let rg = (1.0, 1.0, 0.0, 0.0);
let left_guide_bar = Rect::new((self.position.0, self.position.1), (2.0, self.size.1), 1, red);
let right_guide_bar = Rect::new((self.position.0 + self.size.0, self.position.1), (2.0, self.size.1), 1, blue);
let line = Rect::new((self.position.0, self.position.1 - (self.size.1 / 2.0)), (self.size.0, 2.0), 1, green);
let scale = self.value as f32 / u16::max_value() as f32;
let handle = Rect::new((self.position.0 + (self.size.0 * scale), self.position.1), (15.0, self.size.1), 1, rg);
self.handle = handle;
self.guide = vec![left_guide_bar, right_guide_bar, line];
self.scaler = 255;
}
}
impl Drawable for Slider {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
let mut vertices = self.handle.render(
window_size,
position,
rotation,
size,
depth,
).clone();
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
let mut vertices = self.handle.get(window_size).clone();
vertices.extend_from_slice(
self.guide.iter()
.map(|x| x.render(window_size,
position,
rotation,
size,
depth,
)).flatten()
.collect::<Vec<VertexTypeContainer>>()
.map(|x| x.get(window_size))
.flatten()
.collect::<Vec<VertexType>>()
.as_slice()
);
vertices.extend_from_slice(
self.guide[0].render(window_size,
position,
rotation,
size,
depth,
).as_slice());
vertices.extend_from_slice(self.guide[0].get(window_size).as_slice());
vertices
}
}
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// match tr_event {
// TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
//
//
// match button {
// MouseButton::Left => {
// if *state == ElementState::Pressed {
// self.position.0 += 30.0;
// self.value += 10;
// self.update()
// }
// }
// _ => {}
// }
// }
// _ => {}
// }
// Vec::new()
// }
impl<T> Eventable<T> for Slider {
fn notify(&mut self, event: &Event<T>) -> () {
unimplemented!()
}
}

@ -1,27 +1,23 @@
use std::sync::Arc;
use crate::canvas::*;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
use crate::canvas::canvas_frame::{Drawable};
use crate::util::vertex::{VertexTypeContainer, TextureVertex3D, Vertex3D};
use crate::canvas::canvas_frame::{Drawable, Eventable, Updatable};
use crate::util::vertex::{VertexType, TextureVertex3D, Vertex3D};
use winit::event::{DeviceEvent, MouseButton, ElementState, Event, WindowEvent};
use crate::util::tr_event::{TrEvent, TrWindowEvent, TrUIEvent};
///
#[derive(Debug, Clone)]
pub struct Sprite {
pub position: (f32, f32),
pub size: (f32, f32),
depth: f32,
texture_handle: Arc<CanvasTextureHandle>,
}
/// Container class which implements drawable.
impl Sprite {
fn generate_verts(
window_size: (u32, u32),
position: (f32, f32),
size: (f32, f32),
depth: f32,
) -> Vec<TextureVertex3D> {
fn generate_verts(window_size: (u32, u32), position: (f32, f32), size: (f32, f32), depth: f32) -> Vec<TextureVertex3D> {
let ss_position = (
position.0 / window_size.0 as f32 - 1.0,
position.1 / window_size.1 as f32 - 1.0
@ -61,50 +57,51 @@ impl Sprite {
}
///
pub fn new(texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
pub fn new(position: (f32, f32),
size: (f32, f32),
depth: u32,
texture_handle: Arc<CanvasTextureHandle>) -> Sprite {
let normalized_depth = (depth as f32 / 255.0);
Sprite {
position: position,
size: size,
depth: normalized_depth,
texture_handle: texture_handle.clone(),
}
}
}
impl Drawable for Sprite {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
let normalized_depth = (depth / 255.0);
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
vec![
VertexTypeContainer::TextureType(
Sprite::generate_verts(window_size, position, size, normalized_depth),
VertexType::TextureType(
Sprite::generate_verts(window_size, self.position, self.size, self.depth),
self.texture_handle.clone())
]
}
//
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// match tr_event {
// TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
// match button {
// MouseButton::Left => {
// if *state == ElementState::Pressed {
//
// }
// }
// _ => {}
// }
// }
// _ => {}
// }
// Vec::new()
// }
}
impl<T> Eventable<T> for Sprite {
fn notify(&mut self, event: &Event<T>) -> () {
match event {
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if *state == ElementState::Pressed {
self.position = (self.position.0, self.position.1 + 0.1);
}
}
_ => {}
}
}
_ => {}
}
}
}
impl Updatable for Sprite {
fn update(&mut self, delta_time: f32) -> () {
}
}

@ -1,11 +1,10 @@
use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D};
use crate::util::tr_event::{TrUIEvent, TrEvent};
use crate::util::vertex::{VertexType, ColorVertex3D};
///
#[derive(Debug, Clone)]
pub struct Text {
pub verts: VertexTypeContainer,
pub verts: VertexType,
position: (f32, f32),
size: (f32, f32),
@ -130,7 +129,7 @@ impl Text {
};
Text {
verts: VertexTypeContainer::TextType(verts),
verts: VertexType::TextType(verts),
position: position,
size: size,
}
@ -138,21 +137,7 @@ impl Text {
}
impl Drawable for Text {
fn render(&self,
window_size: (u32, u32),
position: (f32, f32),
rotation: f32,
size: (f32, f32),
depth: f32,
) -> Vec<VertexTypeContainer> {
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
vec![self.verts.clone()]
}
// fn update<T>(&self, delta_time: f32) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
//
// fn notify<Y, T>(&self, tr_event: Vec<TrEvent<Y>>, ui_events: Vec<TrUIEvent<T>>) -> Vec<TrUIEvent<T>> {
// Vec::new()
// }
}

@ -1,64 +0,0 @@
use std::sync::Arc;
use specs::{Component, Entities, Join, System, VecStorage, Write, WriteStorage};
use vulkano::swapchain::Surface;
use winit::window::Window;
use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame;
use crate::PersistentState;
use crate::render_system::Position;
use crate::util::tr_event::{TrEvent, TrEventExtension, TrWindowEvent};
use crate::vkprocessor::VkProcessor;
use winit::event::ElementState;
#[derive(Debug, Clone)]
pub struct Evented {
pub subscribed: fn(event: TrEvent<TrEventExtension>) -> bool,
}
impl Component for Evented {
type Storage = VecStorage<Self>;
}
pub struct EventSystem;
impl<'a> System<'a> for EventSystem {
type SystemData = (
Entities<'a>,
WriteStorage<'a, Position>,
WriteStorage<'a, Evented>,
Write<'a, PersistentState>,
Write<'a, VkProcessor>,
Write<'a, Vec<TrEvent<TrEventExtension>>>
);
fn run(&mut self, (
entity,
mut position_list,
mut evented_list,
mut state,
mut vk_processor,
event_stack
): Self::SystemData) {
for (position, evented) in (&mut position_list, &evented_list).join() {
for event in &*event_stack {
match event {
TrEvent::WindowEvent { window_id, event } => {
match event {
TrWindowEvent::MouseInput { device_id, state, button, modifiers } => {
if *state == ElementState::Pressed {
position.x += 100.0;
}
},
_ => {}
}
}
_ => {}
}
}
}
for (entity, evented) in (&*entity, &mut evented_list).join() {}
}
}

@ -8,17 +8,14 @@ extern crate hprof;
extern crate image;
extern crate nalgebra as na;
extern crate rand;
extern crate specs;
extern crate time;
use std::path::Path;
use std::sync::Arc;
use gilrs::{Button, Event as GilEvent, Gamepad, GamepadId, Gilrs};
use specs::prelude::*;
use vulkano::instance::debug::DebugCallback;
use vulkano::instance::Instance;
use vulkano::swapchain::Surface;
use vulkano::sync;
use vulkano::sync::GpuFuture;
use vulkano_win::VkSurfaceBuild;
@ -26,54 +23,35 @@ use winit::dpi::LogicalSize;
use winit::event::{DeviceEvent, ElementState, Event, MouseButton, StartCause, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopProxy};
use winit::platform::unix::WindowBuilderExtUnix;
use winit::window::{Window, WindowBuilder};
use winit::window::WindowBuilder;
use canvas::compu_frame::CompuFrame;
use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable};
use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasTextureHandle, Handle};
use crate::canvas::managed::handles::{CompuBufferHandle, CompuKernelHandle};
use crate::compute::compu_frame::CompuFrame;
use crate::compute::managed::handles::{CompuBufferHandle, CompuKernelHandle};
use crate::drawables::compu_sprite::CompuSprite;
use crate::drawables::rect::Rect;
use crate::drawables::slider::Slider;
use crate::drawables::sprite::Sprite;
use crate::drawables::text::Text;
use crate::render_system::{Geometry, Images, Position, RenderSystem, Textures};
use crate::util::load_raw;
use crate::util::timer::Timer;
use crate::util::tr_event::{TrEvent, TrEventExtension};
use crate::util::vertex::{TextureVertex3D, VertexTypeContainer};
use crate::util::tr_event::TrEvent;
use crate::util::vertex::{TextureVertex3D, VertexType};
use crate::vkprocessor::VkProcessor;
use crate::compu_system::{CompuSystem, Compu};
use crate::event_system::{EventSystem, Evented};
use petgraph::Graph;
use petgraph::graph::NodeIndex;
use crate::drawables::slider::Slider;
pub mod util;
pub mod vkprocessor;
pub mod drawables;
pub mod canvas;
pub mod render_system;
pub mod compu_system;
pub mod event_system;
#[derive(Default)]
pub struct PersistentState {
surface: Option<Arc<Surface<Window>>>,
window_size: (u32, u32),
delta_time: f32,
canvas_frame: CanvasFrame,
compu_frame: CompuFrame,
}
pub mod compute;
struct TrSprite {
entity: Entity,
}
pub fn main() {
//hprof::start_frame();
//let g = hprof::enter("vulkan preload");
hprof::start_frame();
let q1 = hprof::enter("setup");
let instance = {
let extensions = vulkano_win::required_extensions();
@ -84,27 +62,32 @@ pub fn main() {
println!("Debug callback: {:?}", msg.description);
}).ok();
let mut events_loop = EventLoop::<TrEventExtension>::with_user_event();
let mut events_loop = EventLoop::<TrEvent>::with_user_event();
let mut surface = WindowBuilder::new()
.with_inner_size(LogicalSize::new(800, 800))
.build_vk_surface(&events_loop, instance.clone()).unwrap();
let mut processor = VkProcessor::new(instance.clone(), surface.clone());
{
let g = hprof::enter("vulkan preload");
processor.create_swapchain(instance.clone(), surface.clone());
processor.preload_kernels();
processor.preload_shaders();
processor.preload_textures();
processor.preload_fonts();
}
let q2 = hprof::enter("Game Objects");
let mut timer = Timer::new();
let mut frame_future: Box<dyn GpuFuture> =
Box::new(sync::now(processor.device.clone().unwrap())) as Box<dyn GpuFuture>;
Box::new(sync::now(processor.device.clone())) as Box<dyn GpuFuture>;
let step_size: f32 = 0.005;
let mut elapsed_time: f32 = timer.elap_time();
;
let mut delta_time: f32 = 0.0;
let mut accumulator_time: f32 = 0.0;
let mut current_time: f32 = timer.elap_time();
@ -112,7 +95,12 @@ pub fn main() {
let image_data = load_raw(String::from("ford2.jpg"));
let image_dimensions_f: (f32, f32) = ((image_data.1).clone().0 as f32, (image_data.1).clone().1 as f32);
let image_dimensions_u: (u32, u32) = image_data.1;
let compu_sprite1: CompuSprite =
CompuSprite::new((-1.0, -1.0), (1.0, 1.0), 0, image_dimensions_f,
// Swap image to render the result to. Must match dimensions
processor.new_swap_image(image_dimensions_u));
// Need to
let compute_buffer: Arc<CompuBufferHandle> =
processor.new_compute_buffer(image_data.0.clone(), image_data.1, 4);
@ -123,86 +111,29 @@ pub fn main() {
processor.get_kernel_handle(String::from("simple-edge.compute"))
.expect("Can't find that kernel");
let compu_image = 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 mut world = World::new();
world.register::<Evented>();
world.register::<Compu>();
world.register::<Position>();
world.register::<Geometry>();
world.register::<Textures>();
world.register::<Images>();
world.insert::<VkProcessor>(processor);
world.insert::<Vec<TrEvent<TrEventExtension>>>(Vec::new());
world.insert::<PersistentState>(PersistentState {
surface: Some(surface.clone()),
window_size: (0, 0),
delta_time,
canvas_frame: CanvasFrame::new((0, 0)),
compu_frame: CompuFrame::new((0, 0)),
});
let mut g = Graph::new();
let mut matrix : Vec<Vec<NodeIndex<u32>>> = vec![vec![NodeIndex::new(1); 20]; 20];
let mut funky_sprite = Sprite::new(
(200.0, 200.0),
(100.0, 150.0), 10, funky_handle.clone());
let sfml_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
for x in 0..20 {
for y in 0..20 {
matrix[x][y] = g.add_node(((x, y), 0.));
}
}
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));
for x in 0..20 {
for y in 0..20 {
matrix[x][y] = g.add_node(((x, y), 0.));
}
}
drop(q2);
drop(q1);
g.extend_with_edges(&[
(a, b, 1),
(a, d, 1),
(b, c, 1),
(b, f, 1),
(c, e, 1),
(e, f, 1),
(d, e, 1),
]);
// and the thing that renders it
world.create_entity()
.with(Compu { kernels: vec![compute_kernel], buffers: vec![compute_buffer] })// just a drawable
.with(Position { x: 900.0, y: 900.0, z: 0 })
.with(Geometry { size_x: 600.0, size_y: 600.0, rotation: 0.0 })
.with(Images { images: vec![compu_image], image_resolutions: vec![image_dimensions_u] })
.build();
let sprite = world.create_entity()
.with(Evented { subscribed: |event| {true} })
.with(Position { x: 0.0, y: 0.0, z: 0 })
.with(Geometry { size_x: 300.0, size_y: 300.0, rotation: 0.0 })
.with(Textures { textures: vec![funky_handle] })
.build();
// call the run method for the following systems & deps
let mut dispatcher = DispatcherBuilder::new()
// .with(SysA, "sys_a", &[])
.with(EventSystem, "event_s", &[])
.with(CompuSystem, "compu_s", &["event_s"])
.with(RenderSystem, "render_s", &["event_s", "compu_s"]).build();
let l = hprof::enter("Loop");
let event_loop_proxy = events_loop.create_proxy();
@ -222,7 +153,7 @@ pub fn main() {
while let Some(GilEvent { id, event, time }) = gilrs.next_event() {
println!("{:?} New event from {}: {:?}", time, id, event);
active_gamepad = Some(id);
event_loop_proxy.send_event(TrEventExtension::GamepadEvent {
event_loop_proxy.send_event(TrEvent::GamepadEvent {
gil_event: GilEvent { id, event, time }
}).ok();
}
@ -238,39 +169,39 @@ 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);
let mut big_container = vec![
Box::new(Slider::new((0.1, 0.1), (0.9, 0.9), 5000)),
Box::new(Sprite::new((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone())),
];
//container.push(Sprite::new((0.1)));
// Events loop is borrowed from the surface
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
// The incoming event type will indicate what section of the event loop we are in
for eventable in &mut big_container {
eventable.notify(&event);
}
for drawable in &mut big_container {
canvas_frame.draw(&drawable);
}
match event {
Event::NewEvents(cause) => {
if cause == StartCause::Init {
world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into();
} else {
// println!("{}", world.write_resource::<Vec<TrEvent<TrEventExtension>>>().len());
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().clear();
}
}
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit
}
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
match button {
MouseButton::Left => {
if state == ElementState::Pressed {}
}
_ => {}
}
}
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
world.write_resource::<VkProcessor>()
.swapchain_recreate_needed = true;
world.write_resource::<PersistentState>()
.window_size = (new_size.width, new_size.height);
canvas_frame.draw(&funky_sprite);
canvas_frame.draw(&compu_sprite1);
canvas_frame.draw(&slider);
window_size = surface.window().inner_size().into();
}
Event::MainEventsCleared => {
elapsed_time = timer.elap_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
@ -278,28 +209,22 @@ pub fn main() {
delta_time = 0.02;
}
accumulator_time += delta_time;
// This dispatches all the systems in parallel (but blocking).
world.write_resource::<PersistentState>()
.delta_time = delta_time;
dispatcher.dispatch(&mut world);
// while (accumulator_time - step_size) >= step_size {
// accumulator_time -= step_size;
// }
}
_ => {}
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => {
*control_flow = ControlFlow::Exit
}
// Each NewEvents event will clear this event stack
world.write_resource::<Vec<TrEvent<TrEventExtension>>>().push(event.into());
/*
match event {
Event::UserEvent(TrEventExtension::KeyHeldEvent {}) => {}
Event::UserEvent(TrEventExtension::MouseHeldEvent {}) => {}
Event::UserEvent(TrEventExtension::GamepadEvent { gil_event }) => {}
Event::WindowEvent { event: WindowEvent::Resized(new_size), .. } => {
processor.swapchain_recreate_needed = true;
let size = (new_size.width, new_size.height);
}
Event::WindowEvent {
event: WindowEvent::MouseInput {
device_id, state, button, modifiers
}, ..
} => {}
Event::UserEvent(TrEvent::KeyHeldEvent {}) => {}
Event::UserEvent(TrEvent::MouseHeldEvent {}) => {}
Event::UserEvent(TrEvent::GamepadEvent { gil_event }) => {}
Event::DeviceEvent { device_id, event } => {
match event {
DeviceEvent::Key(keyboard_input) => {
@ -312,7 +237,7 @@ pub fn main() {
}
VirtualKeyCode::P => {
if keyboard_input.state == ElementState::Pressed {
let data = world.write_resource::<VkProcessor>().read_compute_buffer(compute_buffer.clone());
let data = processor.read_compute_buffer(compute_buffer.clone());
image::save_buffer(&Path::new("image.png"), data.as_slice(), (image_data.1).0, (image_data.1).1, image::RGBA(8));
}
}
@ -323,32 +248,68 @@ pub fn main() {
}
}
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");
processor.run(&surface.clone(),
&canvas_frame,
&compu_frame);
}
// while (accumulator_time - step_size) >= step_size {
// accumulator_time -= step_size;
// }
}
_ => ()
}
bucket the events out, but not really
match
event {
Event::NewEvents(_) => {}
Event::WindowEvent { window_id, event } => {}
Event::DeviceEvent { device_id, event } => {}
Event::UserEvent(tr_event) => {}
Event::Suspended => {}
Event::Resumed => {}
Event::MainEventsCleared => {}
Event::RedrawRequested(_) => {}
Event::RedrawEventsCleared => {}
Event::LoopDestroyed => {}
}*/
// bucket the events out, but not really
// match
// event {
// Event::NewEvents(_) => {}
// Event::WindowEvent { window_id, event } => {}
// Event::DeviceEvent { device_id, event } => {}
// Event::UserEvent(tr_event) => {}
// Event::Suspended => {}
// Event::Resumed => {}
// Event::MainEventsCleared => {}
// Event::RedrawRequested(_) => {}
// Event::RedrawEventsCleared => {}
// Event::LoopDestroyed => {}
// }
});
drop(l);
// hprof::end_frame();
// hprof::profiler().print_timing();
hprof::end_frame();
hprof::profiler().print_timing();
}
pub fn click_test(event_loop_proxy: EventLoopProxy<TrEvent>, canvas_state: &CanvasState) {
// for i in canvas_state. {
// event_loop_proxy.send_event(TrEvent::MouseClickEvent {
// position: (0.0, 0.0),
// button: MouseButton::Left,
// }).ok();
// }
}

@ -1,220 +0,0 @@
use std::sync::Arc;
use specs::{Component, Join, System, VecStorage, Write, WriteStorage};
use crate::canvas::canvas_frame::CanvasFrame;
use crate::canvas::compu_frame::CompuFrame;
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
use crate::PersistentState;
use crate::util::vertex::{ImageVertex3D, TextureVertex3D, VertexTypeContainer};
use crate::vkprocessor::VkProcessor;
#[derive(Debug, Clone)]
pub struct Position {
pub x: f32,
pub y: f32,
pub z: u8,
}
impl Component for Position {
type Storage = VecStorage<Self>;
}
#[derive(Debug, Clone)]
pub struct Geometry {
pub size_x: f32,
pub size_y: f32,
pub rotation: f32,
}
impl Component for Geometry {
type Storage = VecStorage<Self>;
}
#[derive(Debug, Clone)]
pub struct Textures {
pub textures: Vec<Arc<CanvasTextureHandle>>,
}
impl Component for Textures {
type Storage = VecStorage<Self>;
}
#[derive(Debug, Clone)]
pub struct Images {
pub images: Vec<Arc<CanvasImageHandle>>,
pub image_resolutions: Vec<(u32, u32)>,
}
impl Component for Images {
type Storage = VecStorage<Self>;
}
pub struct RenderSystem;
impl<'a> System<'a> for RenderSystem {
type SystemData = (
WriteStorage<'a, Position>,
WriteStorage<'a, Geometry>,
WriteStorage<'a, Textures>,
WriteStorage<'a, Images>,
Write<'a, PersistentState>, // delta_time, window size, etc.
Write<'a, VkProcessor>, // Renderer
);
fn run(&mut self, (
mut pos_list,
mut geom_list,
mut textures_list,
mut images_list,
mut state,
mut vk_processor
): Self::SystemData) {
state.canvas_frame = CanvasFrame::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());
for (position, geometry, textures) in (&mut pos_list, &mut geom_list, &mut textures_list).join() {
// geom.pos_x += mv.vel_x * state.delta_time;
// geom.pos_y += mv.vel_y * state.delta_time;
let window_size = state.window_size.clone();
let pos = (position.x, position.y);
let size = (geometry.size_x, geometry.size_y);
let normalized_depth = position.z as f32 / 255.0;
let textured_vertices = vec![
VertexTypeContainer::TextureType(
generate_textured_verts(window_size, pos, size, normalized_depth),
textures.textures.get(0).unwrap().clone(),
)
];
state.canvas_frame.add(textured_vertices);
}
for (position, geometry, images) in (&mut pos_list, &mut geom_list, &mut images_list).join() {
// geom.pos_x += mv.vel_x * state.delta_time;
// geom.pos_y += mv.vel_y * state.delta_time;
let window_size = state.window_size.clone();
let pos = (position.x, position.y);
let size = (geometry.size_x, geometry.size_y);
let normalized_depth = position.z as f32 / 255.0;
let textured_vertices = vec![
VertexTypeContainer::ImageType(
generate_image_verts(window_size, pos, size, images.image_resolutions.get(0).unwrap().clone(), normalized_depth),
images.images.get(0).unwrap().clone(),
)
];
state.canvas_frame.add(textured_vertices);
}
let compu_frame = &state.compu_frame;
vk_processor.run(&state.surface.clone().unwrap(),
&state.canvas_frame,
compu_frame);
}
}
fn generate_image_verts(
window_size: (u32, u32),
position: (f32, f32),
size: (f32, f32),
image_size: (u32, u32),
depth: f32,
) -> Vec<ImageVertex3D> {
let image_size = (image_size.0 as f32, image_size.1 as f32);
// screen space position
let ss_position = (
position.0 / window_size.0 as f32 - 1.0,
position.1 / window_size.1 as f32 - 1.0
);
// screen space size
let ss_size = (
size.0 / window_size.0 as f32,
size.1 / window_size.1 as f32
);
// pub fn new(position: (f32, f32),
// size: (f32, f32),
// depth: u32,
// image_size: (f32, f32),
// image_handle: Arc<CanvasImageHandle>) -> CompuSprite {
vec![
ImageVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0],
},
ImageVertex3D {
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left
ti_position: [-0.0, image_size.1],
},
ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
ti_position: [image_size.0, image_size.1],
},
ImageVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0],
},
ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
ti_position: [image_size.0, image_size.1],
},
ImageVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
ti_position: [image_size.0, -0.0],
},
]
}
fn generate_textured_verts(
window_size: (u32, u32),
position: (f32, f32),
size: (f32, f32),
depth: f32,
) -> Vec<TextureVertex3D> {
let ss_position = (
position.0 / window_size.0 as f32 - 1.0,
position.1 / window_size.1 as f32 - 1.0
);
let ss_size = (
size.0 / window_size.0 as f32,
size.1 / window_size.1 as f32
);
vec![
TextureVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0],
},
TextureVertex3D {
v_position: [ss_position.0, ss_position.1 + ss_size.1, depth], // bottom left
ti_position: [-0.0, 1.0],
},
TextureVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
ti_position: [1.0, 1.0],
},
TextureVertex3D {
v_position: [ss_position.0, ss_position.1, depth], // top left
ti_position: [-0.0, -0.0],
},
TextureVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1 + ss_size.1, depth], // bottom right
ti_position: [1.0, 1.0],
},
TextureVertex3D {
v_position: [ss_position.0 + ss_size.0, ss_position.1, depth], // top right
ti_position: [1.0, -0.0],
},
]
}

@ -1,214 +1,25 @@
use winit::window::{WindowId, Theme};
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch, StartCause, Event};
use winit::window::WindowId;
use winit::event::{WindowEvent, DeviceId, DeviceEvent, KeyboardInput, ModifiersState, MouseScrollDelta, TouchPhase, ElementState, MouseButton, AxisId, Touch};
use std::path::PathBuf;
use winit::dpi::{PhysicalPosition, PhysicalSize};
use gilrs::Event as GilEvent;
use vulkano::pipeline::shader::GeometryShaderExecutionMode::TrianglesWithAdjacency;
#[derive(Clone)]
pub enum TrUIEvent<T> {
UIEvent(T)
}
#[derive(Clone)]
pub enum TrEventExtension {
/// Custom events here
MouseHeldEvent {},
KeyHeldEvent {},
GamepadEvent {
gil_event: GilEvent,
pub enum TrEvent {
MouseFocusEvent {
position : (f32, f32),
},
}
#[derive(Clone, Debug)]
pub enum TrEvent<T> {
/// Custom events here
MouseHeldEvent {},
KeyHeldEvent {},
GamepadEvent {
gil_event: GilEvent,
MouseClickEvent {
position : (f32, f32),
button : MouseButton,
},
MouseHeldEvent {
/// Winit events here
NewEvents(StartCause),
WindowEvent {
window_id: WindowId,
event: TrWindowEvent,
},
DeviceEvent {
device_id: DeviceId,
event: DeviceEvent,
},
UserEvent(T),
Suspended,
Resumed,
MainEventsCleared,
RedrawRequested(WindowId),
RedrawEventsCleared,
LoopDestroyed,
}
KeyHeldEvent {
impl<T> From<Event<'_, T>> for TrEvent<T> {
fn from(event: Event<T>) -> Self {
match event {
Event::NewEvents(cause) => {
TrEvent::NewEvents(cause)
},
Event::WindowEvent { window_id: window_id, event: event } => {
TrEvent::WindowEvent {
window_id: window_id,
event: match event {
WindowEvent::AxisMotion { device_id, axis, value } => {
TrWindowEvent::AxisMotion { device_id, axis, value }
},
WindowEvent::Resized(physical_size) => {
TrWindowEvent::Resized(physical_size)
}
WindowEvent::Moved(physical_position) => {
TrWindowEvent::Moved(physical_position)
}
WindowEvent::CloseRequested => {
TrWindowEvent::CloseRequested
}
WindowEvent::Destroyed => {
TrWindowEvent::Destroyed
}
WindowEvent::DroppedFile(path_buf) => {
TrWindowEvent::DroppedFile(path_buf)
}
WindowEvent::HoveredFile(path_buf) => {
TrWindowEvent::HoveredFile(path_buf)
}
WindowEvent::HoveredFileCancelled => {
TrWindowEvent::HoveredFileCancelled
}
WindowEvent::ReceivedCharacter(char) => {
TrWindowEvent::ReceivedCharacter(char)
}
WindowEvent::Focused(bool) => {
TrWindowEvent::Focused(bool)
}
WindowEvent::KeyboardInput { device_id: device_id, input: input, is_synthetic: is_synthetic } => {
TrWindowEvent::KeyboardInput { device_id, input, is_synthetic }
}
WindowEvent::ModifiersChanged(modifiers_state) => {
TrWindowEvent::ModifiersChanged(modifiers_state)
}
WindowEvent::CursorMoved { device_id: device_id, position: position, modifiers: modifiers } => {
TrWindowEvent::CursorMoved { device_id, position, modifiers }
}
WindowEvent::CursorEntered { device_id: device_id } => {
TrWindowEvent::CursorEntered { device_id }
}
WindowEvent::CursorLeft { device_id: device_id } => {
TrWindowEvent::CursorLeft { device_id }
}
WindowEvent::MouseWheel { device_id: device_id, delta: delta, phase: phase, modifiers: modifiers } => {
TrWindowEvent::MouseWheel { device_id, delta, phase, modifiers }
}
WindowEvent::MouseInput { device_id: device_id, state: state, button: button, modifiers: modifiers } => {
TrWindowEvent::MouseInput { device_id, state, button, modifiers }
}
WindowEvent::TouchpadPressure { device_id: device_id, pressure: pressure, stage: stage } => {
TrWindowEvent::TouchpadPressure { device_id, pressure, stage }
}
WindowEvent::Touch(touch) => {
TrWindowEvent::Touch(touch)
}
WindowEvent::ScaleFactorChanged { scale_factor: scale_factor, new_inner_size: new_inner_size } => {
TrWindowEvent::ScaleFactorChanged { scale_factor, new_inner_size: PhysicalSize { width: new_inner_size.width, height: new_inner_size.height } }
}
WindowEvent::ThemeChanged(theme) => {
TrWindowEvent::ThemeChanged(theme)
}
}
}
}
Event::DeviceEvent { device_id: device_id, event: event } => {
TrEvent::DeviceEvent { device_id, event }
}
Event::UserEvent(user_event) => {
TrEvent::UserEvent(user_event)
}
Event::Suspended => {
TrEvent::Suspended
}
Event::Resumed => {
TrEvent::Resumed
}
Event::MainEventsCleared => {
TrEvent::MainEventsCleared
}
Event::RedrawRequested(window_id) => {
TrEvent::RedrawRequested(window_id)
}
Event::RedrawEventsCleared => {
TrEvent::RedrawEventsCleared
}
Event::LoopDestroyed => {
TrEvent::LoopDestroyed
}
}
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum TrWindowEvent {
GamepadEvent {
gil_event: GilEvent,
Resized(PhysicalSize<u32>),
Moved(PhysicalPosition<i32>),
CloseRequested,
Destroyed,
DroppedFile(PathBuf),
HoveredFile(PathBuf),
HoveredFileCancelled,
ReceivedCharacter(char),
Focused(bool),
KeyboardInput {
device_id: DeviceId,
input: KeyboardInput,
is_synthetic: bool,
},
ModifiersChanged(ModifiersState),
CursorMoved {
device_id: DeviceId,
position: PhysicalPosition<f64>,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
CursorEntered { device_id: DeviceId },
CursorLeft { device_id: DeviceId },
MouseWheel {
device_id: DeviceId,
delta: MouseScrollDelta,
phase: TouchPhase,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
MouseInput {
device_id: DeviceId,
state: ElementState,
button: MouseButton,
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
modifiers: ModifiersState,
},
TouchpadPressure {
device_id: DeviceId,
pressure: f32,
stage: i64,
},
AxisMotion {
device_id: DeviceId,
axis: AxisId,
value: f64,
},
Touch(Touch),
ScaleFactorChanged {
scale_factor: f64,
new_inner_size: PhysicalSize<u32>,
},
ThemeChanged(Theme),
}
}

@ -51,12 +51,13 @@ vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size
// ==============================================================================
#[derive(Debug, Clone)]
pub enum VertexTypeContainer {
pub enum VertexType {
TextureType(Vec<TextureVertex3D>, Arc<CanvasTextureHandle>),
ImageType(Vec<ImageVertex3D>, Arc<CanvasImageHandle>),
ColorType(Vec<ColorVertex3D>),
ThreeDType(Vec<Vertex3D>),
TextType(Vec<ColorVertex3D>),
}
#[derive(Clone)]

@ -7,8 +7,9 @@ use vulkano::sync;
use std::sync::Arc;
use vulkano::swapchain::{Swapchain, PresentMode, SurfaceTransform, Surface, SwapchainCreationError, AcquireError, Capabilities, FullscreenExclusive, ColorSpace};
use vulkano::image::swapchain::SwapchainImage;
use crate::compute::compu_state::CompuState;
use vulkano::image::ImageUsage;
use crate::canvas::compu_frame::CompuFrame;
use crate::compute::compu_frame::CompuFrame;
use crate::canvas::canvas_frame::{CanvasFrame};
use std::time::Duration;
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
@ -17,26 +18,24 @@ use crate::canvas::canvas_state::CanvasState;
use crate::canvas::managed::shader::generic_shader::GenericShader;
use crate::canvas::managed::shader::text_shader::TextShader;
use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle};
use crate::canvas::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::util::vertex::{VertexTypeContainer, ColorVertex3D, TextVertex3D, TextureVertex3D, ImageVertex3D};
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
use crate::util::vertex::{VertexType, ColorVertex3D, TextVertex3D, TextureVertex3D, ImageVertex3D};
use vulkano_text::DrawText;
use winit::window::{Window, WindowBuilder};
use vulkano::instance::debug::DebugCallback;
use winit::dpi::LogicalSize;
use vulkano_win::VkSurfaceBuild;
use winit::event_loop::EventLoop;
use specs::prelude::Resource;
/// VKProcessor holds the vulkan instance information, the swapchain,
/// and the compute and canvas states
#[derive(Default)]
pub struct VkProcessor {
// Vulkan state fields
pub device: Option<Arc<Device>>,
pub queues: Option<QueuesIter>,
pub queue: Option<Arc<Queue>>,
//pub physical: PhysicalDevice<'a>,
pub device: Arc<Device>,
pub queues: QueuesIter,
pub queue: Arc<Queue>,
pub swapchain: Option<Arc<Swapchain<Window>>>,
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
@ -46,8 +45,12 @@ pub struct VkProcessor {
/// State holding textures, images, and their related vertex buffers
canvas_state: CanvasState,
}
/// State holding
compute_state: CompuState,
capabilities: Capabilities,
}
impl VkProcessor {
@ -75,12 +78,14 @@ impl VkProcessor {
let capabilities = surface.capabilities(physical).unwrap();
VkProcessor {
device: Some(device.clone()),
queue: Some(queue.clone()),
queues: Some(queues),
device: device.clone(),
queue: queue.clone(),
queues: queues,
swapchain: None,
swapchain_images: None,
swapchain_recreate_needed: false,
compute_state: CompuState::new(),
capabilities: capabilities.clone(),
canvas_state: CanvasState::new(queue, device, physical, capabilities),
}
}
@ -110,14 +115,14 @@ impl VkProcessor {
panic!("window closed");
};
Swapchain::new(self.device.clone().unwrap(),
Swapchain::new(self.device.clone(),
surface.clone(),
capabilities.min_image_count, // number of attachment images
format,
initial_dimensions,
1, // Layers
ImageUsage::color_attachment(),
(&self.queue).as_ref().unwrap(),
&self.queue,
SurfaceTransform::Identity,
alpha,
PresentMode::Immediate,
@ -163,16 +168,16 @@ impl VkProcessor {
/// A hardcoded list of kernels which can be preloaded from this function
pub fn preload_kernels(&mut self) {
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().unwrap());
self.compute_state.new_kernel(String::from("simple-homogenize.compute"), self.device.clone());
self.compute_state.new_kernel(String::from("simple-edge.compute"), self.device.clone());
}
/// A hardcoded list of shaders which can be preloaded from this function
pub fn preload_shaders(&mut self) {
self.canvas_state.load_shader::<GenericShader, ColorVertex3D>(String::from("color-passthrough"));
self.canvas_state.load_shader::<GenericShader, TextureVertex3D>(String::from("simple_texture"));
self.canvas_state.load_shader::<GenericShader, ImageVertex3D>(String::from("simple_image"));
self.canvas_state.load_shader::<TextShader, ColorVertex3D>(String::from("simple_text"));
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.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.capabilities.clone());
}
/// A hardcoded list of shaders which can be proloaded from this function
@ -187,7 +192,7 @@ impl VkProcessor {
/// O(n) Lookup for the matching kernel string
pub fn get_kernel_handle(&self, kernel_name: String) -> Option<Arc<CompuKernelHandle>> {
self.canvas_state.get_kernel_handle(kernel_name)
self.compute_state.get_kernel_handle(kernel_name)
}
/// O(n) Lookup for the matching shader string
@ -210,17 +215,17 @@ impl VkProcessor {
/// 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> {
self.canvas_state.new_compute_buffer(data, dimensions, stride, self.device.clone().unwrap())
self.compute_state.new_compute_buffer(data, dimensions, stride, self.device.clone())
}
/// Takes a compute buffer handle and returns the read data
pub fn read_compute_buffer(&mut self, handle: Arc<CompuBufferHandle>) -> Vec<u8> {
self.canvas_state.read_compute_buffer(handle)
self.compute_state.read_compute_buffer(handle)
}
/// Takes a compute buffer handle and writes the received data
pub fn write_compute_buffer(&self, handle: Arc<CompuBufferHandle>, data: Vec<u8>) {
self.canvas_state.write_compute_buffer(handle, data)
self.compute_state.write_compute_buffer(handle, data)
}
/// Run the VKprocessor for a single frame, consuming the Canvas/Compu Frames
@ -231,7 +236,7 @@ impl VkProcessor {
) {
{
let g = hprof::enter("Waiting at queue");
self.queue.as_ref().unwrap().wait();
self.queue.wait();
}
let g = hprof::enter("Frame buffer, future, swapchain recreate");
@ -278,11 +283,11 @@ impl VkProcessor {
// let mut draw_text = DrawText::new(self.device.clone(), self.queue.clone(), self.swapchain.unwrap().clone(), &self.swapchain_images.images);
let mut command_buffer =
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone().unwrap(), self.queue.as_ref().unwrap().family()).unwrap();
AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap();
let g = hprof::enter("Push compute commands to command buffer");
// Add the compute commands
self.canvas_state.compute_commands(compute_frame, &mut command_buffer);
self.compute_state.compute_commands(compute_frame, &mut command_buffer, &self.canvas_state);
drop(g);
let g = hprof::enter("Push draw commands to command buffer");
@ -298,15 +303,15 @@ impl VkProcessor {
// Wait on the previous frame, then execute the command buffer and present the image
{
let g = hprof::enter("Joining on the framebuffer");
let mut future = sync::now(self.device.clone().unwrap())
let mut future = sync::now(self.device.clone())
.join(acquire_future);
drop(g);
let g = hprof::enter("Running the kernel and waiting on the future");
let future = future
.then_execute(self.queue.clone().unwrap(), command_buffer).unwrap()
.then_swapchain_present(self.queue.clone().unwrap(), self.swapchain.clone().unwrap().clone(), image_num)
.then_execute(self.queue.clone(), command_buffer).unwrap()
.then_swapchain_present(self.queue.clone(), self.swapchain.clone().unwrap().clone(), image_num)
.then_signal_fence_and_flush();
match future {

Loading…
Cancel
Save