diff --git a/src/canvas.rs b/src/canvas.rs index bb73cab5..59caea58 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -238,8 +238,11 @@ impl CanvasState { } pub fn create_image(&mut self, dimensions: (u32, u32), usage: ImageUsage) -> Arc { + + let handle = Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32}); + let image = CanvasImage { - handle: Arc::new(CanvasImageHandle { handle: self.image_buffers.len() as u32 + 1 }), + handle: handle.clone(), buffer: AttachmentImage::with_usage( self.device.clone(), [dimensions.0, dimensions.1], @@ -247,8 +250,9 @@ impl CanvasState { usage).unwrap(), size: dimensions, }; - let handle = image.handle.clone(); + self.image_buffers.push(Arc::new(image)); + handle } @@ -303,7 +307,7 @@ impl CanvasState { let texture_buffer = self.get_texture_from_file(filename.clone()); let handle = Arc::new(CanvasTextureHandle { - handle: self.texture_buffers.len() as u32 + 1 + handle: self.texture_buffers.len() as u32 }); let texture = Arc::new(CanvasTexture { diff --git a/src/compu_kernel.rs b/src/compu_kernel.rs index fbbebb57..dccef7d2 100644 --- a/src/compu_kernel.rs +++ b/src/compu_kernel.rs @@ -23,6 +23,8 @@ pub struct CompuKernel { compute_pipeline: Option>>>, compute_kernel_path: PathBuf, + name: String, + shader: CompiledShaders, entry: Entry, shader_module: Arc, @@ -48,7 +50,7 @@ impl CompuKernel { pub fn new(filename: String, device: Arc, handle: Arc) -> CompuKernel { - let compute_path = CompuKernel::get_path(filename); + let compute_path = CompuKernel::get_path(filename.clone()); let mut options = CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(); @@ -64,6 +66,7 @@ impl CompuKernel { CompuKernel { + name: filename, handle: handle, device: device, shader: shader, @@ -120,6 +123,13 @@ impl CompuKernel { self.get_pipeline() } + + pub fn get_handle(&self) -> Arc { + self.handle.clone() + } + pub fn get_name(&self) -> String { + self.name.clone() + } } #[repr(C)] diff --git a/src/compu_state.rs b/src/compu_state.rs index 717d5843..d47eb91a 100644 --- a/src/compu_state.rs +++ b/src/compu_state.rs @@ -30,6 +30,7 @@ pub struct CompuState { } impl CompuState { + pub fn new() -> CompuState { CompuState { compute_buffers: vec![], @@ -44,11 +45,11 @@ impl CompuState { device: Arc) -> Arc { let handle = Arc::new(CompuBufferHandle { - handle: self.compute_buffers.len() as u32 + 1 + handle: self.compute_buffers.len() as u32 }); self.compute_buffers.push( - CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone())); + (CompuBuffers::new(device.clone(), data, dimensions, stride, handle.clone()))); handle } @@ -66,14 +67,23 @@ impl CompuState { device: Arc) -> Arc { let handle = Arc::new(CompuKernelHandle { - handle: self.kernels.len() as u32 + 1 + handle: self.kernels.len() as u32 }); - self.kernels.push(CompuKernel::new(filename, device.clone(), handle.clone())); + self.kernels.push((CompuKernel::new(filename, device.clone(), handle.clone()))); handle } + pub fn get_kernel_handle(&self, kernel_name: String) -> Option> { + 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: AutoCommandBufferBuilder, diff --git a/src/main.rs b/src/main.rs index d48c0c0a..6cbc06c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,6 +71,10 @@ fn main() { let mut processor = vkprocessor::VkProcessor::new(&instance, &surface); processor.create_swapchain(&surface); + processor.preload_kernels(); + processor.preload_shaders(); + processor.preload_textures(); + let mut timer = Timer::new(); let mut frame_future = Box::new(sync::now(processor.device.clone())) as Box; @@ -85,6 +89,7 @@ fn main() { + let sprite = Sprite::new_with_color((0.,0.), (0.1,0.1), (1.,0.,0.,1.)); let sprite2 = Sprite::new_with_color((-1.,-0.5), (0.1,0.1), (0.,1.,0.,1.)); @@ -93,7 +98,6 @@ fn main() { let image_data = load_raw(String::from("funky-bird.jpg")); let compute_buffer = processor.new_compute_buffer(image_data.0, image_data.1, 4); - // TODO need to implement let compute_kernel = processor.get_kernel_handle(String::from("simple-edge.compute")) .expect("Can't find that kernel"); diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 22725ab4..15f43196 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -133,8 +133,12 @@ impl<'a> VkProcessor<'a> { pub fn preload_textures(&mut self) { self.canvas.load_texture(String::from("funky-bird.jpg")); + self.canvas.load_texture(String::from("button.png")); + self.canvas.load_texture(String::from("background.jpg")); + self.canvas.load_texture(String::from("test2.png")); } pub fn preload_kernels(&mut self) { + 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()); } pub fn preload_shaders(&mut self) { @@ -145,7 +149,7 @@ impl<'a> VkProcessor<'a> { None } pub fn get_kernel_handle(&self, kernel_name: String) -> Option> { - None + self.compute_state.get_kernel_handle(kernel_name) } pub fn get_shader_handle(&self, shader_name: String) -> Option> { None