diff --git a/vulkano/src/command_buffer/inner.rs b/vulkano/src/command_buffer/inner.rs index 3e5e8ae7..0fe4b2cb 100644 --- a/vulkano/src/command_buffer/inner.rs +++ b/vulkano/src/command_buffer/inner.rs @@ -27,7 +27,6 @@ use image::AbstractImageView; use image::Image; use image::ImageTypeMarker; use memory::MemorySource; -use memory::MemorySourceChunk; use pipeline::GenericPipeline; use pipeline::ComputePipeline; use pipeline::GraphicsPipeline; @@ -340,7 +339,7 @@ impl InnerCommandBufferBuilder { /// pub unsafe fn clear_color_image<'a, Ty, F, M>(self, image: &Arc>, color: F::ClearValue) -> InnerCommandBufferBuilder - where Ty: ImageTypeMarker, F: PossibleFloatFormatDesc // FIXME: should accept uint and int images too + where Ty: ImageTypeMarker, F: PossibleFloatFormatDesc, M: MemorySource // FIXME: should accept uint and int images too { assert!(image.format().is_float()); // FIXME: should accept uint and int images too @@ -381,7 +380,7 @@ impl InnerCommandBufferBuilder { -> InnerCommandBufferBuilder where S: Into>, F: StrongStorage + 'static + PossibleFloatOrCompressedFormatDesc, // FIXME: wrong trait Ty: ImageTypeMarker + 'static, Sm: MemorySource + 'static, So: 'static, - Im: MemorySourceChunk + 'static + Im: MemorySource + 'static { assert!(image.format().is_float_or_compressed()); diff --git a/vulkano/src/command_buffer/outer.rs b/vulkano/src/command_buffer/outer.rs index da2beac9..4459bd95 100644 --- a/vulkano/src/command_buffer/outer.rs +++ b/vulkano/src/command_buffer/outer.rs @@ -24,7 +24,6 @@ use framebuffer::Subpass; use image::Image; use image::ImageTypeMarker; use memory::MemorySource; -use memory::MemorySourceChunk; use pipeline::ComputePipeline; use pipeline::GraphicsPipeline; use pipeline::input_assembly::Index; @@ -129,7 +128,7 @@ impl PrimaryCommandBufferBuilder { where S: Into>, F: StrongStorage + PossibleFloatOrCompressedFormatDesc + 'static, Ty: ImageTypeMarker + 'static, So: 'static, Sm: MemorySource + 'static, - Im: MemorySourceChunk + 'static + Im: MemorySource + 'static { unsafe { PrimaryCommandBufferBuilder { @@ -142,7 +141,7 @@ impl PrimaryCommandBufferBuilder { /// Note that compressed formats are not supported. pub fn clear_color_image<'a, Ty, F, M>(self, image: &Arc>, color: F::ClearValue) -> PrimaryCommandBufferBuilder - where Ty: ImageTypeMarker, F: PossibleFloatFormatDesc + where Ty: ImageTypeMarker, F: PossibleFloatFormatDesc, M: MemorySource { unsafe { PrimaryCommandBufferBuilder { diff --git a/vulkano/src/image.rs b/vulkano/src/image.rs index ba84df19..062dac1b 100644 --- a/vulkano/src/image.rs +++ b/vulkano/src/image.rs @@ -209,10 +209,10 @@ impl From for MipmapsCount { } /// A storage for pixels or arbitrary data. -pub struct Image where Ty: ImageTypeMarker { +pub struct Image where Ty: ImageTypeMarker, M: MemorySource { device: Arc, image: vk::Image, - memory: M, + memory: M::Chunk, usage: vk::ImageUsageFlagBits, format: F, dimensions: Ty::Dimensions, @@ -236,7 +236,7 @@ pub struct Image where Ty: ImageTypeMarker { } impl Image - where M: MemorySourceChunk, Ty: ImageTypeMarker, F: FormatDesc + where M: MemorySource, Ty: ImageTypeMarker, F: FormatDesc { /// Creates a new image and allocates memory for it. /// @@ -246,10 +246,10 @@ impl Image /// - Panicks if the number of mipmaps is 0. /// - Panicks if the number of samples is 0. /// - pub fn new(device: &Arc, usage: &Usage, memory: S, sharing: Sh, - format: F, dimensions: Ty::Dimensions, num_samples: Ty::NumSamples, mipmaps: Mi) - -> Result, OomError> - where S: MemorySource, Mi: Into, Sh: Into + pub fn new(device: &Arc, usage: &Usage, memory: M, sharing: Sh, + format: F, dimensions: Ty::Dimensions, num_samples: Ty::NumSamples, mipmaps: Mi) + -> Result, OomError> + where Mi: Into, Sh: Into { let vk = device.pointers(); @@ -361,7 +361,7 @@ impl Image /// Creates an image from a raw handle. The image won't be destroyed. /// /// This function is for example used at the swapchain's initialization. - pub unsafe fn from_raw_unowned(device: &Arc, handle: u64, memory: M, + pub unsafe fn from_raw_unowned(device: &Arc, handle: u64, memory: M::Chunk, sharing: SharingMode, usage: u32, format: F, dimensions: Ty::Dimensions, samples: Ty::NumSamples, mipmaps: u32) @@ -386,7 +386,7 @@ impl Image } impl Image - where Ty: ImageTypeMarker, F: FormatDesc + where Ty: ImageTypeMarker, F: FormatDesc, M: MemorySource { /// Returns the dimensions of this image. #[inline] @@ -422,7 +422,7 @@ impl Image } unsafe impl VulkanObject for Image - where Ty: ImageTypeMarker + where Ty: ImageTypeMarker, M: MemorySource { type Object = vk::Image; @@ -433,7 +433,7 @@ unsafe impl VulkanObject for Image } unsafe impl Resource for Image - where Ty: ImageTypeMarker, M: MemorySourceChunk + where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn requires_fence(&self) -> bool { @@ -452,7 +452,7 @@ unsafe impl Resource for Image } unsafe impl AbstractImage for Image - where Ty: ImageTypeMarker, M: MemorySourceChunk + where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn default_layout(&self) -> Layout { @@ -469,7 +469,7 @@ unsafe impl AbstractImage for Image } impl Drop for Image - where Ty: ImageTypeMarker + where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn drop(&mut self) { @@ -487,12 +487,12 @@ impl Drop for Image /// Prototype of an image. /// /// Needs to be transitionned to a proper layout in order to be turned into a regular `Image`. -pub struct ImagePrototype where Ty: ImageTypeMarker { +pub struct ImagePrototype where Ty: ImageTypeMarker, M: MemorySource { image: Image, } impl ImagePrototype - where M: MemorySourceChunk, Ty: ImageTypeMarker, F: FormatDesc + where M: MemorySource, Ty: ImageTypeMarker, F: FormatDesc { /// Returns the dimensions of this image. #[inline] @@ -713,14 +713,14 @@ impl Usage { /// Accessing an image from within a shader can only be done through an `ImageView`. An `ImageView` /// represents a region of an image. You can also do things like creating a 2D view of a 3D /// image, swizzle the channels, or change the format of the texture (with some restrictions). -pub struct ImageView where Ty: ImageTypeMarker { +pub struct ImageView where Ty: ImageTypeMarker, M: MemorySource { image: Arc>, view: vk::ImageView, /// The view was created with identity swizzling. identity_swizzle: bool, } -impl ImageView where Ty: ImageTypeMarker { +impl ImageView where Ty: ImageTypeMarker, M: MemorySource { /// Creates a new view from an image. /// /// Note that you must create the view with identity swizzling if you want to use this view @@ -784,14 +784,14 @@ impl ImageView where Ty: ImageTypeMarker { } } -impl ImageView where Ty: ImageTypeMarker { +impl ImageView where Ty: ImageTypeMarker, M: MemorySource { // TODO: hack, remove #[doc(hidden)] pub fn id(&self) -> u64 { self.view } } unsafe impl VulkanObject for ImageView - where Ty: ImageTypeMarker + where Ty: ImageTypeMarker, M: MemorySource { type Object = vk::ImageView; @@ -802,7 +802,7 @@ unsafe impl VulkanObject for ImageView } unsafe impl Resource for ImageView - where Ty: ImageTypeMarker, M: MemorySourceChunk + where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn requires_fence(&self) -> bool { @@ -821,7 +821,7 @@ unsafe impl Resource for ImageView } unsafe impl AbstractImageView for ImageView - where Ty: ImageTypeMarker, M: MemorySourceChunk + where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn default_layout(&self) -> Layout { @@ -877,11 +877,11 @@ unsafe impl AbstractImageView for ImageView } unsafe impl AbstractTypedImageView for ImageView - where Ty: ImageTypeMarker, F: FormatDesc, M: MemorySourceChunk + where Ty: ImageTypeMarker, F: FormatDesc, M: MemorySource { } -impl Drop for ImageView where Ty: ImageTypeMarker { +impl Drop for ImageView where Ty: ImageTypeMarker, M: MemorySource { #[inline] fn drop(&mut self) { unsafe { @@ -1258,7 +1258,7 @@ unsafe impl MultisampleType for TypeCubeArrayMultisample { /// This object doesn't correspond to any Vulkan object. It exists for the programmer's /// convenience. pub struct ImageSubresourceRange<'a, Ty: 'a, F: 'a, M: 'a> - where Ty: ImageTypeMarker, F: FormatDesc + where Ty: ImageTypeMarker, F: FormatDesc, M: MemorySource { image: &'a Arc>, base_mip_level: u32, @@ -1268,7 +1268,7 @@ pub struct ImageSubresourceRange<'a, Ty: 'a, F: 'a, M: 'a> } impl<'a, Ty: 'a, F: 'a, M: 'a> From<&'a Arc>> for ImageSubresourceRange<'a, Ty, F, M> - where Ty: ImageTypeMarker, F: FormatDesc + where Ty: ImageTypeMarker, F: FormatDesc, M: MemorySource { #[inline] fn from(image: &'a Arc>) -> ImageSubresourceRange<'a, Ty, F, M> { diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index a39cb473..dcc5193a 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -50,6 +50,7 @@ pub use self::surface::SurfaceTransform; pub use self::surface::CompositeAlpha; pub use self::surface::ColorSpace; pub use self::swapchain::Swapchain; +pub use self::swapchain::SwapchainAllocated; pub use self::swapchain::SwapchainAllocatedChunk; pub use self::swapchain::AcquireError; diff --git a/vulkano/src/swapchain/swapchain.rs b/vulkano/src/swapchain/swapchain.rs index ea421e9b..e9d72b99 100644 --- a/vulkano/src/swapchain/swapchain.rs +++ b/vulkano/src/swapchain/swapchain.rs @@ -14,6 +14,7 @@ use image::Type2d; use image::Usage as ImageUsage; use memory::ChunkProperties; use memory::ChunkRange; +use memory::MemorySource; use memory::MemorySourceChunk; use swapchain::CompositeAlpha; use swapchain::PresentMode; @@ -65,7 +66,7 @@ impl Swapchain { pub fn new(device: &Arc, surface: &Arc, num_images: u32, format: F, dimensions: [u32; 2], layers: u32, usage: &ImageUsage, sharing: S, transform: SurfaceTransform, alpha: CompositeAlpha, mode: PresentMode, - clipped: bool) -> Result<(Arc, Vec>), OomError> + clipped: bool) -> Result<(Arc, Vec>), OomError> where F: FormatDesc + Clone, S: Into { Swapchain::new_inner(device, surface, num_images, format, dimensions, layers, usage, @@ -80,7 +81,7 @@ impl Swapchain { fn new_inner(device: &Arc, surface: &Arc, num_images: u32, format: F, dimensions: [u32; 2], layers: u32, usage: &ImageUsage, sharing: S, transform: SurfaceTransform, alpha: CompositeAlpha, mode: PresentMode, - clipped: bool) -> Result<(Arc, Vec>), OomError> + clipped: bool) -> Result<(Arc, Vec>), OomError> where F: FormatDesc + Clone, S: Into { // FIXME: check that the parameters are supported @@ -289,6 +290,23 @@ impl From for AcquireError { } } +/// "Dummy" object used for images that indicates that they were allocated as part of a swapchain. +pub struct SwapchainAllocated; + +unsafe impl MemorySource for SwapchainAllocated { + type Chunk = SwapchainAllocatedChunk; + + #[inline] + fn is_sparse(&self) -> bool { false } + + #[inline] + fn allocate(self, _: &Arc, _: usize, _: usize, _: u32) + -> Result + { + panic!() + } +} + /// "Dummy" object used for images that indicates that they were allocated as part of a swapchain. pub struct SwapchainAllocatedChunk { swapchain: Arc,