Draft for descriptor sets

This commit is contained in:
Pierre Krieger 2016-02-19 13:43:28 +01:00
parent 3735fd0062
commit f7696b9f60
2 changed files with 23 additions and 6 deletions

View File

@ -81,6 +81,9 @@ impl {name} {{
output.push_str(&format!(r#"
}}
"#));
// descriptor sets
output.push_str(&write_descriptor_sets(&doc));
}
// TODO: remove
@ -221,6 +224,21 @@ fn write_entry_point(doc: &parse::Spirv, instruction: &parse::Instruction) -> St
f_call = f_call)
}
fn write_descriptor_sets(doc: &parse::Spirv) -> String {
// TODO: not implemented
for instruction in doc.instructions.iter() {
let (target_id, descriptor_set) = match instruction {
&parse::Instruction::Decorate { target_id, decoration: enums::Decoration::DecorationDescriptorSet, ref params } => {
(target_id, params[0])
},
_ => continue
};
}
return "".to_owned();
}
fn type_from_id(doc: &parse::Spirv, searched: u32) -> String {
for instruction in doc.instructions.iter() {
match instruction {
@ -265,12 +283,7 @@ fn type_from_id(doc: &parse::Spirv, searched: u32) -> String {
},
&parse::Instruction::TypeStruct { result_id, ref member_types } if result_id == searched => {
let name = name_from_id(doc, result_id);
let members = member_types.iter().enumerate().map(|(offset, &member)| {
let ty = type_from_id(doc, member);
let name = member_name_from_id(doc, result_id, offset as u32);
format!("\t{}: {}", name, ty)
}).collect::<Vec<_>>();
return format!("struct {} {{\n{}\n}}", name, members.join(",\n"));
return name;
},
&parse::Instruction::TypeOpaque { result_id, ref name } if result_id == searched => {
return "<opaque>".to_owned();

View File

@ -90,6 +90,7 @@ pub enum Instruction {
TypeInt { result_id: u32, width: u32, signedness: bool },
TypeFloat { result_id: u32, width: u32 },
TypeVector { result_id: u32, component_id: u32, count: u32 },
TypeMatrix { result_id: u32, column_type_id: u32, column_count: u32 },
TypeImage { result_id: u32, sampled_type_id: u32, dim: Dim, depth: Option<bool>, arrayed: bool, ms: bool, sampled: Option<bool>, format: ImageFormat, access: Option<AccessQualifier> },
TypeSampledImage { result_id: u32, image_type_id: u32 },
TypeArray { result_id: u32, type_id: u32, length_id: u32 },
@ -101,6 +102,7 @@ pub enum Instruction {
FunctionEnd,
Variable { result_type_id: u32, result_id: u32, storage_class: StorageClass, initializer: Option<u32> },
Decorate { target_id: u32, decoration: Decoration, params: Vec<u32> },
MemberDecorate { target_id: u32, member: u32, decoration: Decoration, params: Vec<u32> },
Label { result_id: u32 },
Branch { result_id: u32 },
Kill,
@ -147,6 +149,7 @@ fn decode_instruction(opcode: u16, operands: &[u32]) -> Result<Instruction, Pars
21 => Instruction::TypeInt { result_id: operands[0], width: operands[1], signedness: operands[2] != 0 },
22 => Instruction::TypeFloat { result_id: operands[0], width: operands[1] },
23 => Instruction::TypeVector { result_id: operands[0], component_id: operands[1], count: operands[2] },
24 => Instruction::TypeMatrix { result_id: operands[0], column_type_id: operands[1], column_count: operands[2] },
25 => Instruction::TypeImage {
result_id: operands[0],
sampled_type_id: operands[1],
@ -172,6 +175,7 @@ fn decode_instruction(opcode: u16, operands: &[u32]) -> Result<Instruction, Pars
initializer: operands.get(3).map(|&v| v)
},
71 => Instruction::Decorate { target_id: operands[0], decoration: try!(Decoration::from_num(operands[1])), params: operands[2..].to_owned() },
72 => Instruction::MemberDecorate { target_id: operands[0], member: operands[1], decoration: try!(Decoration::from_num(operands[2])), params: operands[3..].to_owned() },
248 => Instruction::Label { result_id: operands[0] },
249 => Instruction::Branch { result_id: operands[0] },
252 => Instruction::Kill,