Added Swapchain functions (#1268)

* Derive PartialEq for DescriptorDesc and added examples

* Added an example

* Example improvements

* Formatting issue

* Added Swapchain::with_old_swapchain() and integrated ColorSpace into Swapchain::new()

* Updated Changelog

* More docs and small improvement

* Added Swapchain::surface
This commit is contained in:
Antonino Siena 2019-11-05 11:03:46 +01:00 committed by Austin Johnson
parent ea9aa8e95d
commit 1b2a39d3b0
11 changed files with 57 additions and 22 deletions

View File

@ -1,5 +1,9 @@
# Unreleased
- Added Swapchain::surface() - which returns the saved surface
- Added Swapchain::with_old_swapchain() - same as previous Swapchain::new(), if an oldswapchain needs to be used
- Swapchain::new() now doesnt need to have the old_swapchain parameter anymore but requires the ColorSpace
# Version 0.16.0 (2019-11-01)
- Fixed bug in examples causing OutOfHostMemory errors

View File

@ -28,7 +28,7 @@
use vulkano::device::{Device, DeviceExtensions};
use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -83,7 +83,7 @@ fn main() {
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format,
initial_dimensions, 1, usage, &queue, SurfaceTransform::Identity, alpha,
PresentMode::Fifo, true, None).unwrap()
PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};

View File

@ -18,7 +18,7 @@ use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::pipeline::GraphicsPipeline;
use vulkano::pipeline::viewport::Viewport;
use vulkano::sampler::{Sampler, SamplerAddressMode, Filter, MipmapMode};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -73,7 +73,7 @@ fn main() {
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format,
initial_dimensions, 1, usage, &queue, SurfaceTransform::Identity, alpha,
PresentMode::Fifo, true, None).unwrap()
PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};

View File

@ -39,7 +39,7 @@ use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::pipeline::{ComputePipeline, GraphicsPipeline};
use vulkano::pipeline::viewport::Viewport;
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -97,7 +97,7 @@ fn main() {
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format,
initial_dimensions, 1, usage, &queue, SurfaceTransform::Identity, alpha,
PresentMode::Fifo, true, None).unwrap()
PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};
mod vs {

View File

@ -27,7 +27,7 @@ use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::pipeline::GraphicsPipeline;
use vulkano::pipeline::vertex::OneVertexOneInstanceDefinition;
use vulkano::pipeline::viewport::Viewport;
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -96,7 +96,7 @@ fn main() {
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format,
initial_dimensions, 1, usage, &queue, SurfaceTransform::Identity, alpha,
PresentMode::Fifo, true, None).unwrap()
PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};
// We now create a buffer that will store the shape of our triangle.

View File

@ -37,7 +37,7 @@ use vulkano::pipeline::GraphicsPipeline;
use vulkano::pipeline::shader::{GraphicsShaderType, ShaderInterfaceDef, ShaderInterfaceDefEntry, ShaderModule};
use vulkano::pipeline::vertex::SingleBufferDefinition;
use vulkano::pipeline::viewport::Viewport;
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::GpuFuture;
use vulkano::sync;
@ -92,7 +92,7 @@ fn main() {
let format = caps.supported_formats[0].0;
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format, initial_dimensions,
1, usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, None).unwrap()
1, usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};
let render_pass = Arc::new(vulkano::single_pass_renderpass!(

View File

@ -21,7 +21,7 @@ use vulkano::instance::PhysicalDevice;
use vulkano::pipeline::vertex::TwoBuffersDefinition;
use vulkano::pipeline::viewport::Viewport;
use vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::GpuFuture;
use vulkano::sync;
@ -80,7 +80,7 @@ fn main() {
let alpha = caps.supported_composite_alpha.iter().next().unwrap();
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format, dimensions, 1,
usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, None).unwrap()
usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};
let vertices = VERTICES.iter().cloned();

View File

@ -26,7 +26,7 @@ use vulkano::image::SwapchainImage;
use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::pipeline::GraphicsPipeline;
use vulkano::pipeline::viewport::Viewport;
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -163,7 +163,7 @@ fn main() {
let format = caps.supported_formats[0].0;
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format, initial_dimensions,
1, usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, None).unwrap()
1, usage, &queue, SurfaceTransform::Identity, alpha, PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};
let vertex_buffer = {

View File

@ -24,7 +24,7 @@ use vulkano::image::SwapchainImage;
use vulkano::instance::{Instance, PhysicalDevice};
use vulkano::pipeline::GraphicsPipeline;
use vulkano::pipeline::viewport::Viewport;
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError};
use vulkano::swapchain::{AcquireError, PresentMode, SurfaceTransform, Swapchain, SwapchainCreationError, ColorSpace};
use vulkano::swapchain;
use vulkano::sync::{GpuFuture, FlushError};
use vulkano::sync;
@ -164,7 +164,7 @@ fn main() {
// Please take a look at the docs for the meaning of the parameters we didn't mention.
Swapchain::new(device.clone(), surface.clone(), caps.min_image_count, format,
initial_dimensions, 1, usage, &queue, SurfaceTransform::Identity, alpha,
PresentMode::Fifo, true, None).unwrap()
PresentMode::Fifo, true, ColorSpace::SrgbNonLinear).unwrap()
};

View File

@ -165,7 +165,7 @@
//! # use vulkano::image::ImageUsage;
//! # use vulkano::sync::SharingMode;
//! # use vulkano::format::Format;
//! # use vulkano::swapchain::{Surface, Swapchain, SurfaceTransform, PresentMode, CompositeAlpha};
//! # use vulkano::swapchain::{Surface, Swapchain, SurfaceTransform, PresentMode, CompositeAlpha, ColorSpace};
//! # fn create_swapchain(
//! # device: Arc<Device>, surface: Arc<Surface<()>>, present_queue: Arc<Queue>,
//! # buffers_count: u32, format: Format, dimensions: [u32; 2],
@ -206,7 +206,7 @@
//! // Clip the parts of the buffer which aren't visible.
//! true,
//! // No previous swapchain.
//! None
//! ColorSpace::SrgbNonLinear
//! )?;
//!
//! # Ok(())

View File

@ -217,15 +217,41 @@ impl <W> Swapchain<W> {
/// - Panics if the device and the surface don't belong to the same instance.
/// - Panics if `usage` is empty.
///
// TODO: remove `old_swapchain` parameter and add another function `with_old_swapchain`.
// TODO: add `ColorSpace` parameter
// TODO: isn't it unsafe to take the surface through an Arc when it comes to vulkano-win?
#[inline]
pub fn new<F, S>(
device: Arc<Device>, surface: Arc<Surface<W>>, num_images: u32, format: F,
dimensions: [u32; 2], layers: u32, usage: ImageUsage, sharing: S,
transform: SurfaceTransform, alpha: CompositeAlpha, mode: PresentMode, clipped: bool,
old_swapchain: Option<&Arc<Swapchain<W>>>)
color_space: ColorSpace)
-> Result<(Arc<Swapchain<W>>, Vec<Arc<SwapchainImage<W>>>), SwapchainCreationError>
where F: FormatDesc,
S: Into<SharingMode>
{
Swapchain::new_inner(device,
surface,
num_images,
format.format(),
color_space,
Some(dimensions),
layers,
usage,
sharing.into(),
transform,
alpha,
mode,
clipped,
None)
}
/// Same as Swapchain::new but requires an old swapchain for the creation
#[inline]
pub fn with_old_swapchain<F, S>(
device: Arc<Device>, surface: Arc<Surface<W>>, num_images: u32, format: F,
dimensions: [u32; 2], layers: u32, usage: ImageUsage, sharing: S,
transform: SurfaceTransform, alpha: CompositeAlpha, mode: PresentMode, clipped: bool,
color_space: ColorSpace, old_swapchain: Arc<Swapchain<W>>)
-> Result<(Arc<Swapchain<W>>, Vec<Arc<SwapchainImage<W>>>), SwapchainCreationError>
where F: FormatDesc,
S: Into<SharingMode>
@ -243,7 +269,7 @@ impl <W> Swapchain<W> {
alpha,
mode,
clipped,
old_swapchain.map(|s| &**s))
Some(&*old_swapchain))
}
/// Recreates the swapchain with current dimensions of corresponding surface.
@ -502,6 +528,11 @@ impl <W> Swapchain<W> {
Ok((swapchain, swapchain_images))
}
/// Returns the saved Surface, from the Swapchain creation
pub fn surface(&self) -> &Arc<Surface<W>>{
&self.surface
}
/// Returns of the images that belong to this swapchain.
#[inline]
pub fn raw_image(&self, offset: usize) -> Option<ImageInner> {