From 77ccd415d000625f31da5a8a8ac9fad2d5c5d285 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sat, 27 Jul 2019 23:46:26 -0700 Subject: [PATCH] easiest solution there was just to remove the unclonable objects from ShaderKernels --- src/vkprocessor.rs | 8 ++++---- src/vkprocessor/shader_kernels.rs | 25 +++++++++++++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index d2d3369d..3f05f507 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -105,7 +105,7 @@ unsafe impl SpecializationConstants for SimpleSpecializationConstants { pub struct VkProcessor<'a> { - pub shader_kernels: Option>>, + pub shader_kernels: Option, pub compute_kernel: Option, pub vertex_shader_path: PathBuf, pub fragment_shader_path: PathBuf, @@ -185,17 +185,17 @@ impl<'a> VkProcessor<'a> { } pub fn compile_shaders(&mut self, filename: String, surface: &'a Arc>) { - self.shader_kernels = Some(Arc::new( + self.shader_kernels = Some( ShaderKernels::new(filename.clone(), surface, self.queue.clone(), self.physical, self.device.clone()) - )); + ); } // On resizes we have to recreate the swapchain pub fn recreate_swapchain(&mut self, surface: &'a Arc>) { - //self.shader_kernels.unwrap().recreate_swapchain(surface); + self.shader_kernels = Some(self.shader_kernels.take().unwrap().recreate_swapchain(surface)); } pub fn load_buffers(&mut self, image_filename: String) diff --git a/src/vkprocessor/shader_kernels.rs b/src/vkprocessor/shader_kernels.rs index 21683eae..41fee098 100644 --- a/src/vkprocessor/shader_kernels.rs +++ b/src/vkprocessor/shader_kernels.rs @@ -50,14 +50,15 @@ struct EntryPoint<'a> { #[derive(Default, Debug, Clone)] struct tVertex { position: [f32; 2] } -pub struct ShaderKernels<'a> { +#[derive(Clone)] +pub struct ShaderKernels { pub swapchain : Arc>, pub swapchain_images: Vec>>, // Surface which is drawn to - pub physical: PhysicalDevice<'a>, + //pub physical: PhysicalDevice<'a>, // shader: CompiledShaders, - options: CompileOptions<'a>, + //options: CompileOptions<'a>, pub render_pass: Arc, pub graphics_pipeline: Option>, @@ -74,7 +75,7 @@ window_size_dependent_setup(&self.images.clone().unwrap().clone(), self.render_pass.clone().unwrap().clone(), &mut self.dynamic_state); */ -impl<'a> ShaderKernels<'a> { +impl ShaderKernels { fn get_path(filename: String) -> (PathBuf, PathBuf) { @@ -108,12 +109,12 @@ impl<'a> ShaderKernels<'a> { } // On resizes we have to recreate the swapchain - pub fn recreate_swapchain(&mut self, surface: &'a Arc>) { + pub fn recreate_swapchain(mut self, surface: &Arc>) -> Self { let dimensions = if let Some(dimensions) = surface.window().get_inner_size() { let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into(); [dimensions.0, dimensions.1] } else { - return; + return self; }; let (new_swapchain, new_images) = match self.swapchain.clone().recreate_with_dimension(dimensions) { @@ -126,13 +127,14 @@ impl<'a> ShaderKernels<'a> { self.swapchain = new_swapchain; self.swapchain_images = new_images; + self } pub fn new(filename: String, - surface: &'a Arc>, + surface: &Arc>, queue: Arc, - physical: PhysicalDevice<'a>, - device: Arc) -> ShaderKernels<'a> { + physical: PhysicalDevice, + device: Arc) -> ShaderKernels { let (mut swapchain, images) = { let capabilities = surface.capabilities(physical).unwrap(); @@ -241,9 +243,8 @@ impl<'a> ShaderKernels<'a> { ShaderKernels { swapchain: swapchain, swapchain_images: images, - physical: physical, - - options: CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(), + //physical: physical, + //options: CompileOptions::new().ok_or(CompileError::CreateCompiler).unwrap(), graphics_pipeline: Some(Arc::new(GraphicsPipeline::start() // We need to indicate the layout of the vertices.