Skip to content

Commit a56e64c

Browse files
committed
Add buffers_list and images_list methods to descriptor sets
1 parent a690a63 commit a56e64c

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

vulkano/src/descriptor/descriptor_set/collection.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
// notice may not be copied, modified, or distributed except
88
// according to those terms.
99

10+
use std::iter;
11+
use buffer::Buffer;
1012
use descriptor::descriptor::DescriptorDesc;
1113
use descriptor::descriptor_set::DescriptorSet;
1214
use descriptor::descriptor_set::DescriptorSetDesc;
1315
use descriptor::descriptor_set::UnsafeDescriptorSet;
16+
use image::Image;
1417

1518
/// A collection of descriptor set objects.
1619
pub unsafe trait DescriptorSetsCollection {
@@ -31,6 +34,12 @@ pub unsafe trait DescriptorSetsCollection {
3134
///
3235
/// Returns `None` if out of range.
3336
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc>;
37+
38+
/// Returns the list of buffers used by this descriptor set. Includes buffer views.
39+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a>;
40+
41+
/// Returns the list of images used by this descriptor set. Includes image views.
42+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a>;
3443
}
3544

3645
unsafe impl DescriptorSetsCollection for () {
@@ -53,6 +62,16 @@ unsafe impl DescriptorSetsCollection for () {
5362
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
5463
None
5564
}
65+
66+
#[inline]
67+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
68+
Box::new(iter::empty())
69+
}
70+
71+
#[inline]
72+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
73+
Box::new(iter::empty())
74+
}
5675
}
5776

5877
unsafe impl<T> DescriptorSetsCollection for T
@@ -86,6 +105,16 @@ unsafe impl<T> DescriptorSetsCollection for T
86105
_ => None
87106
}
88107
}
108+
109+
#[inline]
110+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
111+
DescriptorSet::buffers_list(self)
112+
}
113+
114+
#[inline]
115+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
116+
DescriptorSet::images_list(self)
117+
}
89118
}
90119

91120
macro_rules! impl_collection {
@@ -162,6 +191,26 @@ macro_rules! impl_collection {
162191

163192
None
164193
}
194+
195+
#[inline]
196+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
197+
let &(first, $(ref $others,)*) = self;
198+
let iter = first.buffers_list();
199+
$(
200+
let iter = iter.chain($others.buffers_list());
201+
)*
202+
Box::new(iter)
203+
}
204+
205+
#[inline]
206+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
207+
let &(first, $(ref $others,)*) = self;
208+
let iter = first.images_list();
209+
$(
210+
let iter = iter.chain($others.images_list());
211+
)*
212+
Box::new(iter)
213+
}
165214
}
166215

167216
impl_collection!($($others),*);

vulkano/src/descriptor/descriptor_set/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
//! - The `DescriptorSetsCollection` trait is implemented on collections of types that implement
3636
//! `DescriptorSet`. It is what you pass to the draw functions.
3737
38+
use buffer::Buffer;
3839
use descriptor::descriptor::DescriptorDesc;
40+
use image::Image;
3941
use SafeDeref;
4042

4143
pub use self::collection::DescriptorSetsCollection;
@@ -65,13 +67,31 @@ mod unsafe_layout;
6567
pub unsafe trait DescriptorSet: DescriptorSetDesc {
6668
/// Returns the inner `UnsafeDescriptorSet`.
6769
fn inner(&self) -> &UnsafeDescriptorSet;
70+
71+
/// Returns the list of buffers used by this descriptor set. Includes buffer views.
72+
// TODO: meh for boxing
73+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a>;
74+
75+
/// Returns the list of images used by this descriptor set. Includes image views.
76+
// TODO: meh for boxing
77+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a>;
6878
}
6979

7080
unsafe impl<T> DescriptorSet for T where T: SafeDeref, T::Target: DescriptorSet {
7181
#[inline]
7282
fn inner(&self) -> &UnsafeDescriptorSet {
7383
(**self).inner()
7484
}
85+
86+
#[inline]
87+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
88+
(**self).buffers_list()
89+
}
90+
91+
#[inline]
92+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
93+
(**self).images_list()
94+
}
7595
}
7696

7797
/// Trait for objects that describe the layout of the descriptors of a set.

vulkano/src/descriptor/descriptor_set/simple.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use descriptor::descriptor_set::StdDescriptorPool;
2424
use descriptor::pipeline_layout::PipelineLayoutAbstract;
2525
use device::Device;
2626
use device::DeviceOwned;
27+
use image::Image;
2728
use image::ImageView;
2829
use image::sys::Layout;
2930
use sampler::Sampler;
@@ -65,6 +66,16 @@ unsafe impl<R, P> DescriptorSet for SimpleDescriptorSet<R, P> where P: Descripto
6566
fn inner(&self) -> &UnsafeDescriptorSet {
6667
self.inner.inner()
6768
}
69+
70+
#[inline]
71+
fn buffers_list<'a>(&'a self) -> Box<Iterator<Item = &'a Buffer> + 'a> {
72+
unimplemented!()
73+
}
74+
75+
#[inline]
76+
fn images_list<'a>(&'a self) -> Box<Iterator<Item = &'a Image> + 'a> {
77+
unimplemented!()
78+
}
6879
}
6980

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

0 commit comments

Comments
 (0)