Skip to content

Commit

Permalink
Add buffers_list and images_list methods to descriptor sets
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Mar 5, 2017
1 parent a690a63 commit a56e64c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
49 changes: 49 additions & 0 deletions vulkano/src/descriptor/descriptor_set/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
// notice may not be copied, modified, or distributed except
// according to those terms.

use std::iter;
use buffer::Buffer;
use descriptor::descriptor::DescriptorDesc;
use descriptor::descriptor_set::DescriptorSet;
use descriptor::descriptor_set::DescriptorSetDesc;
use descriptor::descriptor_set::UnsafeDescriptorSet;
use image::Image;

/// A collection of descriptor set objects.
pub unsafe trait DescriptorSetsCollection {
Expand All @@ -31,6 +34,12 @@ pub unsafe trait DescriptorSetsCollection {
///
/// Returns `None` if out of range.
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc>;

/// Returns the list of buffers used by this descriptor set. Includes buffer views.
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a>;

/// Returns the list of images used by this descriptor set. Includes image views.
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a>;
}

unsafe impl DescriptorSetsCollection for () {
Expand All @@ -53,6 +62,16 @@ unsafe impl DescriptorSetsCollection for () {
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
None
}

#[inline]
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
Box::new(iter::empty())
}

#[inline]
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
Box::new(iter::empty())
}
}

unsafe impl<T> DescriptorSetsCollection for T
Expand Down Expand Up @@ -86,6 +105,16 @@ unsafe impl<T> DescriptorSetsCollection for T
_ => None
}
}

#[inline]
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
DescriptorSet::buffers_list(self)
}

#[inline]
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
DescriptorSet::images_list(self)
}
}

macro_rules! impl_collection {
Expand Down Expand Up @@ -162,6 +191,26 @@ macro_rules! impl_collection {

None
}

#[inline]
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
let &(first, $(ref $others,)*) = self;
let iter = first.buffers_list();
$(
let iter = iter.chain($others.buffers_list());
)*
Box::new(iter)
}

#[inline]
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
let &(first, $(ref $others,)*) = self;
let iter = first.images_list();
$(
let iter = iter.chain($others.images_list());
)*
Box::new(iter)
}
}

impl_collection!($($others),*);
Expand Down
20 changes: 20 additions & 0 deletions vulkano/src/descriptor/descriptor_set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
//! - The `DescriptorSetsCollection` trait is implemented on collections of types that implement
//! `DescriptorSet`. It is what you pass to the draw functions.

use buffer::Buffer;
use descriptor::descriptor::DescriptorDesc;
use image::Image;
use SafeDeref;

pub use self::collection::DescriptorSetsCollection;
Expand Down Expand Up @@ -65,13 +67,31 @@ mod unsafe_layout;
pub unsafe trait DescriptorSet: DescriptorSetDesc {
/// Returns the inner `UnsafeDescriptorSet`.
fn inner(&self) -> &UnsafeDescriptorSet;

/// Returns the list of buffers used by this descriptor set. Includes buffer views.
// TODO: meh for boxing
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a>;

/// Returns the list of images used by this descriptor set. Includes image views.
// TODO: meh for boxing
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a>;
}

unsafe impl<T> DescriptorSet for T where T: SafeDeref, T::Target: DescriptorSet {
#[inline]
fn inner(&self) -> &UnsafeDescriptorSet {
(**self).inner()
}

#[inline]
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
(**self).buffers_list()
}

#[inline]
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
(**self).images_list()
}
}

/// Trait for objects that describe the layout of the descriptors of a set.
Expand Down
11 changes: 11 additions & 0 deletions vulkano/src/descriptor/descriptor_set/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use descriptor::descriptor_set::StdDescriptorPool;
use descriptor::pipeline_layout::PipelineLayoutAbstract;
use device::Device;
use device::DeviceOwned;
use image::Image;
use image::ImageView;
use image::sys::Layout;
use sampler::Sampler;
Expand Down Expand Up @@ -65,6 +66,16 @@ unsafe impl<R, P> DescriptorSet for SimpleDescriptorSet<R, P> where P: Descripto
fn inner(&self) -> &UnsafeDescriptorSet {
self.inner.inner()
}

#[inline]
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
unimplemented!()
}

#[inline]
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
unimplemented!()
}
}

unsafe impl<R, P> DescriptorSetDesc for SimpleDescriptorSet<R, P> where P: DescriptorPool {
Expand Down

0 comments on commit a56e64c

Please sign in to comment.