Remove binding from DescriptorDesc

This commit is contained in:
Pierre Krieger 2016-10-16 16:56:51 +02:00
parent 5aec152fb5
commit 199295afd3
4 changed files with 17 additions and 13 deletions

View File

@ -64,7 +64,6 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
// Writing the body of the `descriptor` method.
let descriptor_body = descriptors.iter().map(|d| {
format!("({set}, {binding}) => Some(DescriptorDesc {{
binding: {binding},
ty: {desc_ty},
array_count: 1,
stages: stages.clone(),

View File

@ -13,10 +13,6 @@ use vk;
/// Describes a single descriptor.
#[derive(Debug, Copy, Clone)]
pub struct DescriptorDesc {
/// Offset of the binding within the descriptor.
// TODO: remove?
pub binding: u32,
/// Describes the content and layout of each array element of a descriptor.
pub ty: DescriptorDescTy,
@ -37,7 +33,7 @@ impl DescriptorDesc {
/// array elements count, or it is the same with more shader stages.
#[inline]
pub fn is_superset_of(&self, other: &DescriptorDesc) -> bool {
self.binding == other.binding && self.ty.is_superset_of(&other.ty) &&
self.ty.is_superset_of(&other.ty) &&
self.array_count >= other.array_count && self.stages.is_superset_of(&other.stages) &&
(!self.readonly || other.readonly)
}

View File

@ -39,16 +39,21 @@ impl<P> UnsafeDescriptorSetLayout<P> where P: SafeDeref<Target = Device> {
/// See the docs of new().
pub fn raw<I>(device: P, descriptors: I)
-> Result<UnsafeDescriptorSetLayout<P>, OomError>
where I: IntoIterator<Item = DescriptorDesc>
where I: IntoIterator<Item = Option<DescriptorDesc>>
{
let bindings = descriptors.into_iter().map(|desc| {
vk::DescriptorSetLayoutBinding {
binding: desc.binding,
let bindings = descriptors.into_iter().enumerate().filter_map(|(binding, desc)| {
let desc = match desc {
Some(d) => d,
None => return None
};
Some(vk::DescriptorSetLayoutBinding {
binding: binding as u32,
descriptorType: desc.ty.ty().unwrap() /* TODO: shouldn't panic */ as u32,
descriptorCount: desc.array_count,
stageFlags: desc.stages.into(),
pImmutableSamplers: ptr::null(), // FIXME: not yet implemented
}
})
}).collect::<SmallVec<[_; 32]>>();
let layout = unsafe {
@ -75,13 +80,17 @@ impl<P> UnsafeDescriptorSetLayout<P> where P: SafeDeref<Target = Device> {
/// Builds a new `UnsafeDescriptorSetLayout` with the given descriptors.
///
/// The descriptors must be passed in the order of the bindings. In order words, descriptor
/// at bind point 0 first, then descriptor at bind point 1, and so on. If a binding must remain
/// empty, you can make the iterator yield `None` for an element.
///
/// # Panic
///
/// - Panics if the device or host ran out of memory.
///
#[inline]
pub fn new<I>(device: P, descriptors: I) -> Arc<UnsafeDescriptorSetLayout<P>>
where I: IntoIterator<Item = DescriptorDesc>
where I: IntoIterator<Item = Option<DescriptorDesc>>
{
Arc::new(UnsafeDescriptorSetLayout::raw(device, descriptors).unwrap())
}

View File

@ -55,7 +55,7 @@ impl<L> PipelineLayout<L> where L: PipelineLayoutDesc {
Some(l) => l,
None => {
let sets_iter = 0 .. desc.num_bindings_in_set(num).unwrap_or(0);
let desc_iter = sets_iter.filter_map(|d| desc.descriptor(num, d));
let desc_iter = sets_iter.map(|d| desc.descriptor(num, d));
Arc::new(try!(UnsafeDescriptorSetLayout::raw(device.clone(), desc_iter)))
},
});