Skip to content

Commit a690a63

Browse files
committed
Rework DescriptorSetDesc and require it
1 parent bbe1d33 commit a690a63

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

vulkano/src/descriptor/descriptor_set/collection.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,18 @@ unsafe impl<T> DescriptorSetsCollection for T
7373

7474
#[inline]
7575
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
76-
unimplemented!()
76+
match set {
77+
0 => Some(self.num_bindings()),
78+
_ => None
79+
}
7780
}
7881

7982
#[inline]
8083
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
81-
unimplemented!()
84+
match set {
85+
0 => self.descriptor(binding),
86+
_ => None
87+
}
8288
}
8389
}
8490

@@ -116,13 +122,45 @@ macro_rules! impl_collection {
116122
}
117123

118124
#[inline]
119-
fn num_bindings_in_set(&self, set: usize) -> Option<usize> {
120-
unimplemented!()
125+
fn num_bindings_in_set(&self, mut set: usize) -> Option<usize> {
126+
#![allow(non_snake_case)]
127+
#![allow(unused_mut)] // For the `set` parameter.
128+
129+
if set == 0 {
130+
return Some(self.0.num_bindings());
131+
}
132+
133+
let &(_, $(ref $others,)*) = self;
134+
135+
$(
136+
set -= 1;
137+
if set == 0 {
138+
return Some($others.num_bindings());
139+
}
140+
)*
141+
142+
None
121143
}
122144

123145
#[inline]
124-
fn descriptor(&self, set: usize, binding: usize) -> Option<DescriptorDesc> {
125-
unimplemented!()
146+
fn descriptor(&self, mut set: usize, binding: usize) -> Option<DescriptorDesc> {
147+
#![allow(non_snake_case)]
148+
#![allow(unused_mut)] // For the `set` parameter.
149+
150+
if set == 0 {
151+
return self.0.descriptor(binding);
152+
}
153+
154+
let &(_, $(ref $others,)*) = self;
155+
156+
$(
157+
set -= 1;
158+
if set == 0 {
159+
return $others.descriptor(binding);
160+
}
161+
)*
162+
163+
None
126164
}
127165
}
128166

vulkano/src/descriptor/descriptor_set/mod.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ mod unsafe_layout;
6262
/// Trait for objects that contain a collection of resources that will be accessible by shaders.
6363
///
6464
/// Objects of this type can be passed when submitting a draw command.
65-
pub unsafe trait DescriptorSet {
65+
pub unsafe trait DescriptorSet: DescriptorSetDesc {
6666
/// Returns the inner `UnsafeDescriptorSet`.
6767
fn inner(&self) -> &UnsafeDescriptorSet;
6868
}
@@ -76,18 +76,21 @@ unsafe impl<T> DescriptorSet for T where T: SafeDeref, T::Target: DescriptorSet
7676

7777
/// Trait for objects that describe the layout of the descriptors of a set.
7878
pub unsafe trait DescriptorSetDesc {
79-
/// Iterator that describes individual descriptors.
80-
type Iter: ExactSizeIterator<Item = DescriptorDesc>;
79+
/// Returns the number of binding slots in the set.
80+
fn num_bindings(&self) -> usize;
8181

82-
/// Describes the layout of the descriptors of the pipeline.
83-
fn desc(&self) -> Self::Iter;
82+
/// Returns a description of a descriptor, or `None` if out of range.
83+
fn descriptor(&self, binding: usize) -> Option<DescriptorDesc>;
8484
}
8585

8686
unsafe impl<T> DescriptorSetDesc for T where T: SafeDeref, T::Target: DescriptorSetDesc {
87-
type Iter = <T::Target as DescriptorSetDesc>::Iter;
87+
#[inline]
88+
fn num_bindings(&self) -> usize {
89+
(**self).num_bindings()
90+
}
8891

8992
#[inline]
90-
fn desc(&self) -> Self::Iter {
91-
(**self).desc()
93+
fn descriptor(&self, binding: usize) -> Option<DescriptorDesc> {
94+
(**self).descriptor(binding)
9295
}
9396
}

vulkano/src/descriptor/descriptor_set/simple.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use std::sync::Arc;
1111

1212
use buffer::Buffer;
1313
use buffer::BufferViewRef;
14+
use descriptor::descriptor::DescriptorDesc;
1415
use descriptor::descriptor::DescriptorType;
1516
use descriptor::descriptor_set::DescriptorSet;
17+
use descriptor::descriptor_set::DescriptorSetDesc;
1618
use descriptor::descriptor_set::UnsafeDescriptorSetLayout;
1719
use descriptor::descriptor_set::DescriptorPool;
1820
use descriptor::descriptor_set::DescriptorPoolAlloc;
@@ -65,6 +67,18 @@ unsafe impl<R, P> DescriptorSet for SimpleDescriptorSet<R, P> where P: Descripto
6567
}
6668
}
6769

70+
unsafe impl<R, P> DescriptorSetDesc for SimpleDescriptorSet<R, P> where P: DescriptorPool {
71+
#[inline]
72+
fn num_bindings(&self) -> usize {
73+
unimplemented!() // FIXME:
74+
}
75+
76+
#[inline]
77+
fn descriptor(&self, binding: usize) -> Option<DescriptorDesc> {
78+
unimplemented!() // FIXME:
79+
}
80+
}
81+
6882
/// Builds a descriptor set in the form of a `SimpleDescriptorSet` object.
6983
// TODO: more doc
7084
#[macro_export]

0 commit comments

Comments
 (0)