Skip to content

Commit

Permalink
Precautions for stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob2309 committed Jan 26, 2022
1 parent 73719f4 commit 75cdb08
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
19 changes: 16 additions & 3 deletions examples/reflect-shader/main.rs
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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);
}
}
}
Expand All @@ -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 {
"<no-name>"
}
);
}

fn print_type(module: &Module, ty: &Type) {
match ty {
Type::Unknown => print!("<unknown> "),
Type::Void => print!("void "),
Type::Bool => print!("bool "),
Type::Int32 => print!("int "),
Expand Down Expand Up @@ -100,5 +112,6 @@ fn print_type(module: &Module, ty: &Type) {
print_type(module, module.get_type(*pointed_type_id).unwrap());
print!("* ");
}
_ => print!("<unknown> "),
}
}
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Module {
/// Stores information about all uniform variables that exist in the given SPIRV module.
uniforms: Vec<Variable>,
/// Stores information about all push constant variables that exist in the given SPIRV module.
push_constants: Vec<Variable>,
push_constants: Vec<PushConstantVariable>,
}

impl Module {
Expand Down Expand Up @@ -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(),
})
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -538,3 +538,9 @@ pub struct Variable {
/// The variables name (if known)
pub name: Option<String>,
}

#[derive(Debug, Clone)]
pub struct PushConstantVariable {
pub type_id: u32,
pub name: Option<String>,
}

0 comments on commit 75cdb08

Please sign in to comment.