Rework the set binding code in the shader parser

This commit is contained in:
Pierre Krieger 2016-03-11 15:33:57 +01:00
parent b496f3b690
commit c376f3bd10

View File

@ -12,8 +12,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
name: String,
desc_ty: String,
bind_ty: String,
bind_start: String,
bind_end: String,
bind: String,
set: u32,
binding: u32,
}
@ -43,14 +42,13 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
}).next().expect(&format!("Uniform `{}` is missing a binding", name));
// find informations about the kind of binding for this descriptor
let (desc_ty, bind_ty, bind_start, bind_end) = doc.instructions.iter().filter_map(|i| {
let (desc_ty, bind_ty, bind) = 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 { buffer: ",
", offset: 0, size: 128 /* FIXME */ }"
"::vulkano::descriptor_set::DescriptorBind::UniformBuffer { buffer: data, offset: 0, size: 128 /* FIXME */ }"
))
},
&parse::Instruction::TypeImage { result_id, sampled_type_id, ref dim, arrayed, ms,
@ -58,10 +56,9 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
if result_id == pointed_ty && sampled == Some(true) =>
{
Some((
"::vulkano::descriptor_set::DescriptorType::SampledImage",
"::vulkano::descriptor_set::DescriptorType::CombinedImageSampler",
"::vulkano::image::AbstractImageView",
"::vulkano::descriptor_set::DescriptorBind::SampledImage(",
", ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::CombinedImageSampler(data.0, data.1, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
))
},
&parse::Instruction::TypeImage { result_id, sampled_type_id, ref dim, arrayed, ms,
@ -71,8 +68,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
Some((
"::vulkano::descriptor_set::DescriptorType::InputAttachment", // FIXME: can be `StorageImage`
"::vulkano::image::AbstractImageView",
"::vulkano::descriptor_set::DescriptorBind::InputAttachment(", // FIXME:
", ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::InputAttachment(data, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
))
},
&parse::Instruction::TypeSampledImage { result_id, image_type_id }
@ -81,8 +77,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
Some((
"::vulkano::descriptor_set::DescriptorType::SampledImage",
"::vulkano::image::AbstractImageView",
"::vulkano::descriptor_set::DescriptorBind::SampledImage(",
", ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
"::vulkano::descriptor_set::DescriptorBind::SampledImage(data, ::vulkano::image::Layout::ShaderReadOnlyOptimal)" // FIXME:
))
},
_ => None, // TODO: other types
@ -93,8 +88,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
name: name,
desc_ty: desc_ty.to_owned(),
bind_ty: bind_ty.to_owned(),
bind_start: bind_start.to_owned(),
bind_end: bind_end.to_owned(),
bind: bind.to_owned(),
set: descriptor_set,
binding: binding,
});
@ -118,13 +112,13 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
format!(".{}", entry)
};
format!("::vulkano::descriptor_set::DescriptorWrite {{
format!("{{ let data = data{entry};
::vulkano::descriptor_set::DescriptorWrite {{
binding: {binding},
array_element: 0,
content: {bind_start} data{entry} {bind_end},
}}", binding = d.binding, bind_start = d.bind_start,
bind_end = d.bind_end,
entry = entry)
content: {bind},
}} }}", binding = d.binding, bind = d.bind,
entry = entry)
})
.collect::<Vec<_>>();