Extract Init and Write from SetLayout

This commit is contained in:
Pierre Krieger 2016-02-29 14:15:57 +01:00
parent e392bfaed3
commit c0152c1a04
5 changed files with 40 additions and 34 deletions

View File

@ -384,26 +384,25 @@ fn write_descriptor_sets(doc: &parse::Spirv) -> String {
pub struct Set{set};
unsafe impl ::vulkano::descriptor_set::SetLayout for Set{set} {{
type Write = {write_ty};
type Init = {write_ty};
fn descriptors(&self) -> Vec<::vulkano::descriptor_set::DescriptorDesc> {{
vec![
{descr}
]
}}
}}
fn decode_write(&self, write: Self::Write) -> Vec<::vulkano::descriptor_set::DescriptorWrite> {{
unsafe impl ::vulkano::descriptor_set::SetLayoutWrite<{write_ty}> for Set{set} {{
fn decode(&self, data: {write_ty}) -> Vec<::vulkano::descriptor_set::DescriptorWrite> {{
/*vec![ // FIXME: disabled, not compiling
{writes}
]*/
unimplemented!()
}}
}}
#[inline]
fn decode_init(&self, init: Self::Init) -> Vec<::vulkano::descriptor_set::DescriptorWrite> {{
self.decode_write(init)
unsafe impl ::vulkano::descriptor_set::SetLayoutInit<{write_ty}> for Set{set} {{
fn decode(&self, data: {write_ty}) -> Vec<::vulkano::descriptor_set::DescriptorWrite> {{
::vulkano::descriptor_set::SetLayoutWrite::decode(self, data)
}}
}}

View File

@ -35,27 +35,25 @@ pub unsafe trait PipelineLayoutDesc {
/// Types that describe a single descriptor set.
pub unsafe trait SetLayout {
/// Represents a modification of a descriptor set. A parameter of this type must be passed
/// when you modify a descriptor set.
type Write;
/// Contains the list of attachments that must be passed at the initialization of a
/// descriptor set object.
type Init;
/// Returns the list of descriptors contained in this set.
fn descriptors(&self) -> Vec<DescriptorDesc>; // TODO: better perfs
/// Turns the `Write` associated type into something vulkano can understand.
fn decode_write(&self, Self::Write) -> Vec<DescriptorWrite>; // TODO: better perfs
/// Turns the `Init` associated type into something vulkano can understand.
fn decode_init(&self, Self::Init) -> Vec<DescriptorWrite>; // TODO: better perfs
// FIXME: implement this correctly
fn is_compatible_with<S>(&self, _: &S) -> bool where S: SetLayout { true }
}
/// Extension for the `SetLayout` trait.
pub unsafe trait SetLayoutWrite<Data>: SetLayout {
/// Turns the data into something vulkano can understand.
fn decode(&self, Data) -> Vec<DescriptorWrite>; // TODO: better perfs
}
/// Extension for the `SetLayout` trait.
pub unsafe trait SetLayoutInit<Data>: SetLayout {
/// Turns the data into something vulkano can understand.
fn decode(&self, Data) -> Vec<DescriptorWrite>; // TODO: better perfs
}
// FIXME: shoud allow multiple array binds at once
pub struct DescriptorWrite {
pub binding: u32,

View File

@ -37,6 +37,8 @@ use std::sync::Arc;
pub use self::layout_def::PipelineLayoutDesc;
pub use self::layout_def::SetLayout;
pub use self::layout_def::SetLayoutWrite;
pub use self::layout_def::SetLayoutInit;
pub use self::layout_def::DescriptorWrite;
pub use self::layout_def::DescriptorBind;
pub use self::layout_def::DescriptorDesc;

View File

@ -5,6 +5,8 @@ use descriptor_set::AbstractDescriptorSetLayout;
use descriptor_set::DescriptorBind;
use descriptor_set::DescriptorDesc;
use descriptor_set::SetLayout;
use descriptor_set::SetLayoutInit;
use descriptor_set::SetLayoutWrite;
use descriptor_set::DescriptorWrite;
use descriptor_set::PipelineLayoutDesc;
@ -51,15 +53,13 @@ pub struct RuntimeDescriptorSetDesc {
}
unsafe impl SetLayout for RuntimeDescriptorSetDesc {
type Write = Vec<(u32, DescriptorBind)>;
type Init = Vec<(u32, DescriptorBind)>;
fn descriptors(&self) -> Vec<DescriptorDesc> {
self.descriptors.clone()
}
}
fn decode_write(&self, data: Self::Write) -> Vec<DescriptorWrite> {
unsafe impl SetLayoutWrite<Vec<(u32, DescriptorBind)>> for RuntimeDescriptorSetDesc {
fn decode(&self, data: Vec<(u32, DescriptorBind)>) -> Vec<DescriptorWrite> {
data.into_iter().map(|(binding, bind)| {
// TODO: check correctness?
@ -70,8 +70,10 @@ unsafe impl SetLayout for RuntimeDescriptorSetDesc {
}
}).collect()
}
}
fn decode_init(&self, data: Self::Init) -> Vec<DescriptorWrite> {
self.decode_write(data)
unsafe impl SetLayoutInit<Vec<(u32, DescriptorBind)>> for RuntimeDescriptorSetDesc {
fn decode(&self, data: Vec<(u32, DescriptorBind)>) -> Vec<DescriptorWrite> {
SetLayoutWrite::decode(self, data)
}
}

View File

@ -5,6 +5,8 @@ use std::sync::Arc;
use buffer::AbstractBuffer;
use descriptor_set::layout_def::PipelineLayoutDesc;
use descriptor_set::layout_def::SetLayout;
use descriptor_set::layout_def::SetLayoutWrite;
use descriptor_set::layout_def::SetLayoutInit;
use descriptor_set::layout_def::DescriptorWrite;
use descriptor_set::layout_def::DescriptorBind;
use descriptor_set::pool::DescriptorPool;
@ -38,12 +40,13 @@ impl<S> DescriptorSet<S> where S: SetLayout {
///
/// - Panicks if the pool and the layout were not created from the same `Device`.
///
pub fn new(pool: &Arc<DescriptorPool>, layout: &Arc<DescriptorSetLayout<S>>, init: S::Init)
pub fn new<I>(pool: &Arc<DescriptorPool>, layout: &Arc<DescriptorSetLayout<S>>, init: I)
-> Result<Arc<DescriptorSet<S>>, OomError>
where S: SetLayoutInit<I>
{
unsafe {
let mut set = try!(DescriptorSet::uninitialized(pool, layout));
Arc::get_mut(&mut set).unwrap().unchecked_write(layout.description().decode_init(init));
Arc::get_mut(&mut set).unwrap().unchecked_write(layout.description().decode(init));
Ok(set)
}
}
@ -95,8 +98,10 @@ impl<S> DescriptorSet<S> where S: SetLayout {
///
/// This function trusts the implementation of `SetLayout` when it comes to making sure
/// that the correct resource type is written to the correct descriptor.
pub fn write(&mut self, write: S::Write) {
let write = self.layout.description().decode_write(write);
pub fn write<W>(&mut self, write: W)
where S: SetLayoutWrite<W>
{
let write = self.layout.description().decode(write);
unsafe { self.unchecked_write(write); }
}