compiles, slowly moving everything over to spec stuff

a-star
mitchellhansen 4 years ago
parent c52bdc1441
commit ccbd21d90b

@ -39,6 +39,14 @@ impl CanvasFrame {
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
pub fn draw(&mut self, drawable: &dyn Drawable) {
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 also contains logic for writing the stored buffers to the command_buffer
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct CanvasState {
/// Generated during new()
dynamic_state: DynamicState,
/// Generated during new()
sampler: Arc<Sampler>,
sampler: Option<Arc<Sampler>>,
/// hold the image, texture, and Fonts the same was as we do CompuState
image_buffers: Vec<Arc<CanvasImage>>,
@ -58,9 +58,9 @@ pub struct CanvasState {
shader_buffers: Vec<Arc<Box<dyn CompiledShader + Send + Sync>>>,
/// Looks like we gotta hold onto the queue for managing textures
queue: Arc<Queue>,
device: Arc<Device>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,
queue: Option<Arc<Queue>>,
device: Option<Arc<Device>>,
render_pass: Option<Arc<dyn RenderPassAbstract + Send + Sync>>,
compute_buffers: Vec<CompuBuffers>,
kernels: Vec<CompuKernel>,
@ -81,11 +81,11 @@ impl CanvasState {
}]);
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| {
Arc::new(
Framebuffer::start(self.render_pass.clone())
Framebuffer::start(self.render_pass.clone().unwrap())
.add(image.clone()).unwrap()
.add(depth_buffer.clone()).unwrap()
.build().unwrap()
@ -160,19 +160,19 @@ impl CanvasState {
value: 0xFF,
}),
},
sampler: Sampler::new(device.clone(),
sampler: Some(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: queue.clone(),
device: device.clone(),
render_pass: render_pass.clone(),
queue: Some(queue.clone()),
device: Some(device.clone()),
render_pass: Some(render_pass.clone()),
}
}
@ -310,7 +310,7 @@ impl CanvasState {
let image = CanvasImage {
handle: handle.clone(),
buffer: AttachmentImage::with_usage(
self.device.clone(),
self.device.clone().unwrap(),
[dimensions.0, dimensions.1],
Format::R8G8B8A8Uint,
usage).unwrap(),
@ -364,7 +364,7 @@ impl CanvasState {
image_buffer.iter().cloned(),
Dimensions::Dim2d { width: xy.0, height: xy.1 },
Format::R8G8B8A8Srgb,
self.queue.clone(),
self.queue.clone().unwrap(),
).unwrap();
texture
@ -391,8 +391,7 @@ 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,
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
filename: String) -> Option<Arc<CompiledShaderHandle>>
where T: CompiledShader + Send + Sync + 'static, V: Vertex {
let handle = Arc::new(CompiledShaderHandle {
@ -401,9 +400,9 @@ impl CanvasState {
let shader: Box<dyn CompiledShader + Send + Sync> = Box::new(T::new::<V>(
filename.clone(),
self.device.clone(),
self.device.clone().unwrap(),
handle.clone(),
self.render_pass.clone(),
self.render_pass.clone().unwrap(),
));
self.shader_buffers.push(Arc::new(shader));
@ -461,7 +460,7 @@ impl CanvasState {
name: name,
buffer: ImmutableBuffer::from_iter(
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(
colored_vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
self.queue.clone().unwrap(),
).unwrap().0);
}
@ -565,7 +564,7 @@ impl CanvasState {
allocated_text_buffer.push(ImmutableBuffer::from_iter(
text_vertex_buffer.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
self.queue.clone().unwrap(),
).unwrap().0);
}
@ -576,7 +575,7 @@ impl CanvasState {
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
self.queue.clone().unwrap(),
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
}).collect(),
image_vertex_buffer: image_vertex_buffer.into_iter().map(|(k, v)| {
@ -584,7 +583,7 @@ impl CanvasState {
ImmutableBuffer::from_iter(
v.iter().cloned(),
BufferUsage::vertex_buffer(),
self.queue.clone(),
self.queue.clone().unwrap(),
).unwrap().0 as Arc<(dyn BufferAccess + Send + Sync)>)
}).collect(),
text_instances: Default::default(),
@ -669,7 +668,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());
.get_descriptor_set(shader.get_pipeline(), self.sampler.clone().unwrap());
command_buffer = command_buffer.draw(
shader.get_pipeline().clone(),

@ -5,6 +5,7 @@ use crate::drawables::compu_sprite::CompuSprite;
use crate::canvas::canvas_frame::Drawable;
use crate::util::vertex::VertexTypeContainer;
#[derive(Default)]
pub struct CompuFrame {
// Vec<(Buffer, Kernel)>
pub pure_compute: Vec<(

@ -23,7 +23,7 @@ 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::WindowBuilder;
use winit::window::{WindowBuilder, Window};
use crate::canvas::canvas_frame::{CanvasFrame, Drawable, Eventable, Updatable};
use crate::canvas::canvas_state::CanvasState;
@ -50,16 +50,15 @@ pub mod canvas;
extern crate specs;
use specs::prelude::*;
use vulkano::swapchain::Surface;
struct Draws(VertexTypeContainer);
struct Draws(Sprite);
impl Component for Draws {
type Storage = VecStorage<Self>;
}
struct Renderer(u32);
struct Vel(f32);
impl Component for Vel {
@ -72,17 +71,33 @@ impl Component for Pos {
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 {
type SystemData = (
WriteStorage<'a, Pos>,
WriteStorage<'a, Vel>,
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,
// 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
// in parallel using rayon's `ParallelIterator`s.
// 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 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 mut elapsed_time: f32 = timer.elap_time();
@ -214,9 +239,13 @@ pub fn main() {
world.register::<Pos>();
world.register::<Vel>();
world.register::<Draws>();
world.insert::<Renderer>(Renderer(10));
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.
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(
(200.0, 200.0),
(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 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(q1);
let l = hprof::enter("Loop");
let event_loop_proxy = events_loop.create_proxy();
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...
@ -320,11 +344,8 @@ pub fn main() {
match event {
Event::NewEvents(cause) => {
if cause == StartCause::Init {
canvas_frame.draw(&funky_sprite);
canvas_frame.draw(&compu_sprite1);
canvas_frame.draw(&slider);
window_size = surface.window().inner_size().into();
world.write_resource::<PersistentState>()
.window_size = surface.window().inner_size().into();
}
elapsed_time = timer.elap_time();
delta_time = elapsed_time - current_time;
@ -338,7 +359,8 @@ pub fn main() {
*control_flow = ControlFlow::Exit
}
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);
}
Event::WindowEvent {
@ -373,25 +395,6 @@ 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");
world.write_resource::<VkProcessor>()
.run(&surface.clone(),
&canvas_frame,
&compu_frame);
}
// while (accumulator_time - step_size) >= step_size {
// accumulator_time -= step_size;

@ -30,12 +30,13 @@ 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 physical: PhysicalDevice<'a>,
pub device: Arc<Device>,
pub queues: QueuesIter,
pub queue: Arc<Queue>,
pub device: Option<Arc<Device>>,
pub queues: Option<QueuesIter>,
pub queue: Option<Arc<Queue>>,
pub swapchain: Option<Arc<Swapchain<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
canvas_state: CanvasState,
capabilities: Capabilities,
}
@ -76,13 +75,12 @@ impl VkProcessor {
let capabilities = surface.capabilities(physical).unwrap();
VkProcessor {
device: device.clone(),
queue: queue.clone(),
queues: queues,
device: Some(device.clone()),
queue: Some(queue.clone()),
queues: Some(queues),
swapchain: None,
swapchain_images: None,
swapchain_recreate_needed: false,
capabilities: capabilities.clone(),
canvas_state: CanvasState::new(queue, device, physical, capabilities),
}
}
@ -112,14 +110,14 @@ impl VkProcessor {
panic!("window closed");
};
Swapchain::new(self.device.clone(),
Swapchain::new(self.device.clone().unwrap(),
surface.clone(),
capabilities.min_image_count, // number of attachment images
format,
initial_dimensions,
1, // Layers
ImageUsage::color_attachment(),
&self.queue,
(&self.queue).as_ref().unwrap(),
SurfaceTransform::Identity,
alpha,
PresentMode::Immediate,
@ -165,16 +163,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());
self.canvas_state.new_kernel(String::from("simple-edge.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().unwrap());
}
/// 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.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());
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"));
}
/// 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
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
@ -233,7 +231,7 @@ impl VkProcessor {
) {
{
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");
@ -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 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");
// Add the compute commands
@ -300,15 +298,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())
let mut future = sync::now(self.device.clone().unwrap())
.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(), command_buffer).unwrap()
.then_swapchain_present(self.queue.clone(), self.swapchain.clone().unwrap().clone(), image_num)
.then_execute(self.queue.clone().unwrap(), command_buffer).unwrap()
.then_swapchain_present(self.queue.clone().unwrap(), self.swapchain.clone().unwrap().clone(), image_num)
.then_signal_fence_and_flush();
match future {

Loading…
Cancel
Save