|
|
|
@ -125,10 +125,8 @@ pub struct VkProcessor<'a> {
|
|
|
|
|
pub image_buffer: Vec<u8>,
|
|
|
|
|
pub compute_image_buffers: Vec<Arc<CpuAccessibleBuffer<[u8]>>>,
|
|
|
|
|
pub settings_buffer: Option<Arc<CpuAccessibleBuffer<[u32]>>>,
|
|
|
|
|
// pub swapchain: Option<Arc<Swapchain<Window>>>,
|
|
|
|
|
// pub images: Option<Vec<Arc<SwapchainImage<Window>>>>,
|
|
|
|
|
|
|
|
|
|
pub xy: (u32, u32),
|
|
|
|
|
pub render_pass: Option<Arc<RenderPassAbstract + Send + Sync>>,
|
|
|
|
|
pub vertex_buffer: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
pub vertex_buffer2: Option<Arc<(dyn BufferAccess + std::marker::Send + std::marker::Sync + 'static)>>,
|
|
|
|
|
pub dynamic_state: DynamicState,
|
|
|
|
@ -139,8 +137,9 @@ pub struct VkProcessor<'a> {
|
|
|
|
|
pub image_buffer_store : Vec<Box<ImageAccess + Send + Sync>>,
|
|
|
|
|
pub compute_image: Option<ComputeImage>,
|
|
|
|
|
|
|
|
|
|
pub swapchain: Option<Arc<Swapchain<Window>>>,
|
|
|
|
|
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
|
|
|
|
|
|
|
|
|
|
// pub image_buffers_obj : ImageBuffers,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -183,7 +182,6 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
compute_image_buffers: Vec::new(),
|
|
|
|
|
settings_buffer: Option::None,
|
|
|
|
|
xy: (0, 0),
|
|
|
|
|
render_pass: Option::None,
|
|
|
|
|
|
|
|
|
|
vertex_buffer: Option::None,
|
|
|
|
|
vertex_buffer2: None,
|
|
|
|
@ -193,7 +191,10 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
textures: vec![],
|
|
|
|
|
image_buffer_store: vec![],
|
|
|
|
|
compute_image: None
|
|
|
|
|
compute_image: None,
|
|
|
|
|
|
|
|
|
|
swapchain: None,
|
|
|
|
|
swapchain_images: None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -212,9 +213,64 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn create_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
|
|
|
|
|
|
|
|
|
let (mut swapchain, images) = {
|
|
|
|
|
let capabilities = surface.capabilities(self.physical).unwrap();
|
|
|
|
|
let usage = capabilities.supported_usage_flags;
|
|
|
|
|
let alpha = capabilities.supported_composite_alpha.iter().next().unwrap();
|
|
|
|
|
// Choosing the internal format that the images will have.
|
|
|
|
|
let format = capabilities.supported_formats[0].0;
|
|
|
|
|
|
|
|
|
|
// Set the swapchains window dimensions
|
|
|
|
|
let initial_dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
|
|
|
|
// convert to physical pixels
|
|
|
|
|
let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
|
|
|
|
[dimensions.0, dimensions.1]
|
|
|
|
|
} else {
|
|
|
|
|
// The window no longer exists so exit the application.
|
|
|
|
|
panic!("window closed");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Swapchain::new(self.device.clone(),
|
|
|
|
|
surface.clone(),
|
|
|
|
|
capabilities.min_image_count,
|
|
|
|
|
format,
|
|
|
|
|
initial_dimensions,
|
|
|
|
|
1, // Layers
|
|
|
|
|
usage,
|
|
|
|
|
&self.queue,
|
|
|
|
|
SurfaceTransform::Identity,
|
|
|
|
|
alpha,
|
|
|
|
|
PresentMode::Fifo, true, None).unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.swapchain = Some(swapchain);
|
|
|
|
|
self.swapchain_images = Some(images);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// On resizes we have to recreate the swapchain
|
|
|
|
|
pub fn recreate_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
|
|
|
|
self.shader_kernels = Some(self.shader_kernels.take().unwrap().recreate_swapchain(surface));
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let (new_swapchain, new_images) = match self.swapchain.clone().unwrap().clone().recreate_with_dimension(dimensions) {
|
|
|
|
|
Ok(r) => r,
|
|
|
|
|
// This error tends to happen when the user is manually resizing the window.
|
|
|
|
|
// Simply restarting the loop is the easiest way to fix this issue.
|
|
|
|
|
Err(SwapchainCreationError::UnsupportedDimensions) => panic!("Uh oh"),
|
|
|
|
|
Err(err) => panic!("{:?}", err)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.swapchain = Some(new_swapchain);
|
|
|
|
|
self.swapchain_images = Some(new_images);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn get_texture_from_file(image_filename: String, queue: Arc<Queue>) -> Arc<ImmutableImage<Format>> {
|
|
|
|
@ -376,7 +432,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
pub fn run(&mut self, surface: &'a Arc<Surface<Window>>, mut frame_future: Box<dyn GpuFuture>) -> Box<dyn GpuFuture> {
|
|
|
|
|
|
|
|
|
|
let mut framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
|
|
|
|
|
let mut framebuffers = window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone(),
|
|
|
|
|
self.shader_kernels.clone().unwrap().render_pass.clone(),
|
|
|
|
|
&mut self.dynamic_state);
|
|
|
|
|
|
|
|
|
@ -388,8 +444,8 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
// Whenever the window resizes we need to recreate everything dependent on the window size.
|
|
|
|
|
// In this example that includes the swapchain, the framebuffers and the dynamic state viewport.
|
|
|
|
|
if recreate_swapchain {
|
|
|
|
|
self.shader_kernels = Some(self.shader_kernels.clone().unwrap().recreate_swapchain(surface));
|
|
|
|
|
framebuffers = window_size_dependent_setup(&self.shader_kernels.clone().unwrap().swapchain_images.clone(),
|
|
|
|
|
self.recreate_swapchain(surface);
|
|
|
|
|
framebuffers = window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone(),
|
|
|
|
|
self.shader_kernels.clone().unwrap().render_pass.clone(),
|
|
|
|
|
//self.render_pass.clone().unwrap().clone(),
|
|
|
|
|
&mut self.dynamic_state);
|
|
|
|
@ -398,7 +454,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
// This function can block if no image is available. The parameter is an optional timeout
|
|
|
|
|
// after which the function call will return an error.
|
|
|
|
|
let (image_num, acquire_future) = match vulkano::swapchain::acquire_next_image(self.shader_kernels.clone().unwrap().swapchain.clone(), None) {
|
|
|
|
|
let (image_num, acquire_future) = match vulkano::swapchain::acquire_next_image(self.swapchain.clone().unwrap().clone(), None) {
|
|
|
|
|
Ok(r) => r,
|
|
|
|
|
Err(AcquireError::OutOfDate) => {
|
|
|
|
|
recreate_swapchain = true;
|
|
|
|
@ -450,7 +506,7 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
// Wait on the previous frame, then execute the command buffer and present the image
|
|
|
|
|
let future = frame_future.join(acquire_future)
|
|
|
|
|
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
|
|
|
|
.then_swapchain_present(self.queue.clone(), self.shader_kernels.clone().unwrap().swapchain.clone(), image_num)
|
|
|
|
|
.then_swapchain_present(self.queue.clone(), self.swapchain.clone().unwrap().clone(), image_num)
|
|
|
|
|
.then_signal_fence_and_flush();
|
|
|
|
|
|
|
|
|
|
match future {
|
|
|
|
|