spirv-struct-layout

Crates.iospirv-struct-layout
lib.rsspirv-struct-layout
version0.1.2
sourcesrc
created_at2020-01-04 21:55:24.254581
updated_at2020-01-05 18:24:43.314907
descriptionCheck that the layout of a rust struct matches the layout of a given type in SPIRV
homepage
repositoryhttps://github.com/swiftcoder/spirv-struct-layout
max_upload_size
id195236
size17,383
Tristam MacDonald (swiftcoder)

documentation

https://docs.rs/spirv-struct-layout

README

spirv-struct-layout

Attempts to ensure that a rust struct used as a uniform buffer matches the layout of the struct declared in spirv.

Usage example:

use spirv_struct_layout::{CheckSpirvStruct, SpirvLayout};

#[repr(C)]
#[derive(SpirvLayout)]
struct Uniforms {
    model_view: [f32; 16],
    light_dir: [f32; 3],
    // _padding: f32, // uncomment this line, and the alignment will match the spirv
    position: [f32; 4],
}


fn main() {
    let spirv = Vec::from(cast_slice(include_bytes!("simple.frag.spv")));

    Uniforms::check_spirv_layout("buf", spirv);
}

Which fails like so, becuase SPIR-V mandates that vec3 is aligned to 16 bytes:

The application panicked (crashed).
Message:  assertion failed: `(left == right)`
  left: `80`,
 right: `76`: field buf.position should have an offset of 80 bytes, but was 76 bytes
Location: spirv_struct_layout/examples/simple/main.rs:19
Commit count: 15

cargo fmt