mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-25 00:04:15 +00:00
Some work on better descriptor set API
This commit is contained in:
parent
6effb57f75
commit
cfca5c962c
@ -12,7 +12,8 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
name: String,
|
||||
desc_ty: String,
|
||||
bind_ty: String,
|
||||
bind: String,
|
||||
bind_start: String,
|
||||
bind_end: String,
|
||||
set: u32,
|
||||
binding: u32,
|
||||
}
|
||||
@ -42,13 +43,14 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
}).next().expect("A uniform is missing a binding");
|
||||
|
||||
// find informations about the kind of binding for this descriptor
|
||||
let (desc_ty, bind_ty, bind) = doc.instructions.iter().filter_map(|i| {
|
||||
let (desc_ty, bind_ty, bind_start, bind_end) = doc.instructions.iter().filter_map(|i| {
|
||||
match i {
|
||||
&parse::Instruction::TypeStruct { result_id, .. } if result_id == pointed_ty => {
|
||||
Some((
|
||||
"::vulkano::descriptor_set::DescriptorType::UniformBuffer",
|
||||
"::vulkano::buffer::AbstractBuffer",
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer"
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer { buffer: ",
|
||||
", offset: 0, size: 128 /* FIXME */ }"
|
||||
))
|
||||
},
|
||||
&parse::Instruction::TypeImage { result_id, sampled_type_id, ref dim, arrayed, ms,
|
||||
@ -58,7 +60,8 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
Some((
|
||||
"::vulkano::descriptor_set::DescriptorType::SampledImage",
|
||||
"::vulkano::image::AbstractImageView",
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer" // FIXME:
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer", // FIXME:
|
||||
""
|
||||
))
|
||||
},
|
||||
&parse::Instruction::TypeSampledImage { result_id, image_type_id }
|
||||
@ -67,7 +70,8 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
Some((
|
||||
"::vulkano::descriptor_set::DescriptorType::SampledImage",
|
||||
"::vulkano::image::AbstractImageView",
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer" // FIXME:
|
||||
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer", // FIXME:
|
||||
""
|
||||
))
|
||||
},
|
||||
_ => None, // TODO: other types
|
||||
@ -78,7 +82,8 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
name: name,
|
||||
desc_ty: desc_ty.to_owned(),
|
||||
bind_ty: bind_ty.to_owned(),
|
||||
bind: bind.to_owned(),
|
||||
bind_start: bind_start.to_owned(),
|
||||
bind_end: bind_end.to_owned(),
|
||||
set: descriptor_set,
|
||||
binding: binding,
|
||||
});
|
||||
@ -105,8 +110,9 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
format!("::vulkano::descriptor_set::DescriptorWrite {{
|
||||
binding: {binding},
|
||||
array_element: 0,
|
||||
content: {bind}(write{entry}),
|
||||
}}", binding = d.binding, bind = d.bind,
|
||||
content: {bind_start} data{entry} {bind_end},
|
||||
}}", binding = d.binding, bind_start = d.bind_start,
|
||||
bind_end = d.bind_end,
|
||||
entry = entry)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -136,10 +142,9 @@ unsafe impl ::vulkano::descriptor_set::SetLayout for Set{set} {{
|
||||
|
||||
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
|
||||
vec![
|
||||
{writes}
|
||||
]*/
|
||||
unimplemented!()
|
||||
]
|
||||
}}
|
||||
}}
|
||||
|
||||
|
@ -15,6 +15,9 @@ use std::os::windows::ffi::OsStrExt;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
mod vs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_vs.glsl")} }
|
||||
mod fs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_fs.glsl")} }
|
||||
|
||||
fn main() {
|
||||
// The start of this example is exactly the same as `triangle`. You should read the
|
||||
// `triangle` example if you haven't done so yet.
|
||||
@ -119,9 +122,7 @@ fn main() {
|
||||
mapping.proj = proj.into();
|
||||
}
|
||||
|
||||
mod vs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_vs.glsl")} }
|
||||
let vs = vs::Shader::load(&device).expect("failed to create shader module");
|
||||
mod fs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/teapot_fs.glsl")} }
|
||||
let fs = fs::Shader::load(&device).expect("failed to create shader module");
|
||||
|
||||
let images = images.into_iter().map(|image| {
|
||||
@ -154,24 +155,12 @@ fn main() {
|
||||
let renderpass = vulkano::framebuffer::RenderPass::new(&device, renderpass::Layout).unwrap();
|
||||
|
||||
let descriptor_pool = vulkano::descriptor_set::DescriptorPool::new(&device).unwrap();
|
||||
let descriptor_set_layout = {
|
||||
let desc = vulkano::descriptor_set::RuntimeDescriptorSetDesc {
|
||||
descriptors: vec![
|
||||
vulkano::descriptor_set::DescriptorDesc {
|
||||
binding: 0,
|
||||
ty: vulkano::descriptor_set::DescriptorType::UniformBuffer,
|
||||
array_count: 1,
|
||||
stages: vulkano::descriptor_set::ShaderStages::all_graphics(),
|
||||
}
|
||||
]
|
||||
};
|
||||
let descriptor_set_layout = vulkano::descriptor_set::DescriptorSetLayout::new(&device, vs::Set0).unwrap();
|
||||
|
||||
vulkano::descriptor_set::DescriptorSetLayout::new(&device, desc).unwrap()
|
||||
};
|
||||
|
||||
let pipeline_layout = vulkano::descriptor_set::PipelineLayout::new(&device, vulkano::descriptor_set::RuntimeDesc, vec![descriptor_set_layout.clone()]).unwrap();
|
||||
mod pipeline_layout { pipeline_from_sets!(::vs::Set0); }
|
||||
let pipeline_layout = vulkano::descriptor_set::PipelineLayout::new(&device, pipeline_layout::Layout, (descriptor_set_layout.clone(),)).unwrap();
|
||||
let set = vulkano::descriptor_set::DescriptorSet::new(&descriptor_pool, &descriptor_set_layout,
|
||||
vec![(0, vulkano::descriptor_set::DescriptorBind::UniformBuffer { buffer: uniform_buffer.clone(), offset: 0, size: uniform_buffer.size() })]).unwrap();
|
||||
uniform_buffer.clone() as std::sync::Arc<_>).unwrap();
|
||||
|
||||
|
||||
let pipeline = {
|
||||
|
@ -215,3 +215,38 @@ impl Into<vk::ShaderStageFlags> for ShaderStages {
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipeline_from_sets {
|
||||
($($set:ty),*) => {
|
||||
use std::sync::Arc;
|
||||
use $crate::descriptor_set::AbstractDescriptorSet;
|
||||
use $crate::descriptor_set::AbstractDescriptorSetLayout;
|
||||
use $crate::descriptor_set::DescriptorSet;
|
||||
use $crate::descriptor_set::DescriptorSetLayout;
|
||||
use $crate::descriptor_set::DescriptorSetsCollection;
|
||||
|
||||
pub struct Layout;
|
||||
|
||||
pub type DescriptorSets = ($(Arc<DescriptorSet<$set>>,)*);
|
||||
pub type DescriptorSetLayouts = ($(Arc<DescriptorSetLayout<$set>>,)*);
|
||||
|
||||
unsafe impl $crate::descriptor_set::Layout for Layout {
|
||||
type DescriptorSets = DescriptorSets;
|
||||
type DescriptorSetLayouts = DescriptorSetLayouts;
|
||||
type PushConstants = ();
|
||||
|
||||
fn decode_descriptor_sets(&self, sets: DescriptorSets) -> Vec<Arc<AbstractDescriptorSet>> {
|
||||
DescriptorSetsCollection::list(&sets).collect()
|
||||
}
|
||||
|
||||
/// Turns the `DescriptorSetLayouts` associated type into something vulkano can understand.
|
||||
fn decode_descriptor_set_layouts(&self, sets: DescriptorSetLayouts)
|
||||
-> Vec<Arc<AbstractDescriptorSetLayout>>
|
||||
{
|
||||
// FIXME:
|
||||
vec![sets.0.clone() as Arc<_>]
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -104,6 +104,24 @@ unsafe impl<T> DescriptorSetsCollection for Arc<DescriptorSet<T>>
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> DescriptorSetsCollection for (Arc<DescriptorSet<T>>,)
|
||||
where T: 'static + SetLayout
|
||||
{
|
||||
type Iter = OptionIntoIter<Arc<AbstractDescriptorSet>>;
|
||||
|
||||
#[inline]
|
||||
fn list(&self) -> Self::Iter {
|
||||
Some(self.0.clone() as Arc<_>).into_iter()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_compatible_with<P>(&self, pipeline_layout: &Arc<PipelineLayout<P>>) -> bool {
|
||||
// FIXME:
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
#[macro_export]
|
||||
macro_rules! pipeline_layout {
|
||||
|
Loading…
Reference in New Issue
Block a user