mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-21 22:34:43 +00:00
Implement PipelineLayoutDescNames for the generated layouts
This commit is contained in:
parent
32ebcaca1e
commit
5aec152fb5
@ -18,6 +18,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
// Finding all the descriptors.
|
||||
let mut descriptors = Vec::new();
|
||||
struct Descriptor {
|
||||
name: String,
|
||||
set: u32,
|
||||
binding: u32,
|
||||
desc_ty: String,
|
||||
@ -52,6 +53,7 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
let (desc_ty, readonly) = descriptor_infos(doc, pointed_ty, false).expect(&format!("Couldn't find relevant type for uniform `{}` (type {}, maybe unimplemented)", name, pointed_ty));
|
||||
|
||||
descriptors.push(Descriptor {
|
||||
name: name,
|
||||
desc_ty: desc_ty,
|
||||
set: descriptor_set,
|
||||
binding: binding,
|
||||
@ -83,6 +85,12 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
}).collect::<Vec<_>>().concat()
|
||||
};
|
||||
|
||||
// Writing the body of the `descriptor_by_name_body` method.
|
||||
let descriptor_by_name_body = descriptors.iter().map(|d| {
|
||||
format!(r#"{name:?} => Some(({set}, {binding})),"#,
|
||||
name = d.name, set = d.set, binding = d.binding)
|
||||
}).collect::<Vec<_>>().concat();
|
||||
|
||||
format!(r#"
|
||||
pub struct Layout(ShaderStages);
|
||||
|
||||
@ -115,8 +123,17 @@ pub fn write_descriptor_sets(doc: &parse::Spirv) -> String {
|
||||
}}
|
||||
}}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl PipelineLayoutDescNames for Layout {{
|
||||
fn descriptor_by_name(&self, name: &str) -> Option<(usize, usize)> {{
|
||||
match name {{
|
||||
{descriptor_by_name_body}
|
||||
_ => None
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
"#, max_set = max_set, num_bindings_in_set_body = num_bindings_in_set_body,
|
||||
descriptor_body = descriptor_body)
|
||||
descriptor_by_name_body = descriptor_by_name_body, descriptor_body = descriptor_body)
|
||||
}
|
||||
|
||||
/// Assumes that `variable` is a variable with a `TypePointer` and returns the id of the pointed
|
||||
|
@ -98,6 +98,8 @@ pub fn reflect<R>(name: &str, mut spirv: R) -> Result<String, Error>
|
||||
use vulkano::descriptor::pipeline_layout::PipelineLayout;
|
||||
#[allow(unused_imports)]
|
||||
use vulkano::descriptor::pipeline_layout::PipelineLayoutDesc;
|
||||
#[allow(unused_imports)]
|
||||
use vulkano::descriptor::pipeline_layout::PipelineLayoutDescNames;
|
||||
"#);
|
||||
|
||||
{
|
||||
|
@ -167,6 +167,13 @@ pub unsafe trait PipelineLayoutDescNames: PipelineLayoutDesc {
|
||||
fn descriptor_by_name(&self, name: &str) -> Option<(usize, usize)>;
|
||||
}
|
||||
|
||||
unsafe impl<T: ?Sized> PipelineLayoutDescNames for Box<T> where T: PipelineLayoutDescNames {
|
||||
#[inline]
|
||||
fn descriptor_by_name(&self, name: &str) -> Option<(usize, usize)> {
|
||||
(**self).descriptor_by_name(name)
|
||||
}
|
||||
}
|
||||
|
||||
/// Traits that allow determining whether a pipeline layout is a superset of another one.
|
||||
///
|
||||
/// This trait is automatically implemented on all types that implement `PipelineLayoutRef`.
|
||||
|
Loading…
Reference in New Issue
Block a user