#spir-v #layout #struct #matches #spirv-layout

spirv-struct-layout

检查 Rust 结构体的布局是否与 SPIRV 中指定的类型布局相匹配

3 个版本

0.1.2 2020年1月5日
0.1.1 2020年1月4日
0.1.0 2020年1月4日

#943 in 图形 API

Apache-2.0

6KB

spirv-struct-layout

尝试确保用作统一缓冲区的 Rust 结构体与 SPIRV 中声明的结构体布局相匹配。

使用示例

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);
}

如下失败,因为 SPIR-V 命令 vec3 对齐到 16 字节

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

依赖项

~2MB
~46K SLoC