From 75cdb08d8d90b082decba824dd27998ca0592c7f Mon Sep 17 00:00:00 2001 From: Robin Quint Date: Wed, 26 Jan 2022 10:48:26 +0100 Subject: [PATCH] Precautions for stable release --- Cargo.toml | 2 +- examples/reflect-shader/main.rs | 19 ++++++++++++++++--- src/lib.rs | 16 +++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b842084..f9d128b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spirv-layout" -version = "0.2.1" +version = "1.0.0" authors = [ "Robin Quint" ] edition = "2021" description = "SPIRV reflection utility for deriving Vulkan DescriptorSetLayouts" diff --git a/examples/reflect-shader/main.rs b/examples/reflect-shader/main.rs index 24ef6e8..12f21e3 100644 --- a/examples/reflect-shader/main.rs +++ b/examples/reflect-shader/main.rs @@ -1,6 +1,6 @@ use core::slice; -use spirv_layout::{Module, Type, Variable}; +use spirv_layout::{Module, PushConstantVariable, Type, Variable}; const PATH: &str = concat!( env!("CARGO_MANIFEST_DIR"), @@ -20,7 +20,7 @@ fn main() { println!("=== PUSH CONSTANTS ==="); for var in module.get_push_constants() { - print_var(&module, var); + print_pc_var(&module, var); } } } @@ -44,9 +44,21 @@ fn print_var(module: &Module, var: &Variable) { ); } +fn print_pc_var(module: &Module, var: &PushConstantVariable) { + print_type(module, module.get_type(var.type_id).unwrap()); + + println!( + "{};", + if let Some(name) = &var.name { + name + } else { + "" + } + ); +} + fn print_type(module: &Module, ty: &Type) { match ty { - Type::Unknown => print!(" "), Type::Void => print!("void "), Type::Bool => print!("bool "), Type::Int32 => print!("int "), @@ -100,5 +112,6 @@ fn print_type(module: &Module, ty: &Type) { print_type(module, module.get_type(*pointed_type_id).unwrap()); print!("* "); } + _ => print!(" "), } } diff --git a/src/lib.rs b/src/lib.rs index 2166e5c..89a522c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ pub struct Module { /// Stores information about all uniform variables that exist in the given SPIRV module. uniforms: Vec, /// Stores information about all push constant variables that exist in the given SPIRV module. - push_constants: Vec, + push_constants: Vec, } impl Module { @@ -104,9 +104,7 @@ impl Module { pointed_type_id, }) = types.get(&var.type_id) { - Some(Variable { - set: None, - binding: None, + Some(PushConstantVariable { type_id: *pointed_type_id, name: var.name.clone(), }) @@ -134,7 +132,7 @@ impl Module { } /// Returns all push-constant variables declared in the given SPIR-V module. - pub fn get_push_constants(&self) -> &[Variable] { + pub fn get_push_constants(&self) -> &[PushConstantVariable] { &self.push_constants } @@ -445,6 +443,7 @@ impl Module { /// /// Types are declared in a hierarchy, with e.g. pointers relying on previously declared types as pointed-to types. #[derive(Debug)] +#[non_exhaustive] pub enum Type { /// An unsupported type Unknown, @@ -516,6 +515,7 @@ pub struct StructMember { /// Describes what type of storage a pointer points to #[derive(Debug)] +#[non_exhaustive] pub enum StorageClass { Unknown, /// The pointer is a uniform variable (Uniform blocks) @@ -538,3 +538,9 @@ pub struct Variable { /// The variables name (if known) pub name: Option, } + +#[derive(Debug, Clone)] +pub struct PushConstantVariable { + pub type_id: u32, + pub name: Option, +}