https://github.com/swiftcoder/spirv-struct-layout
https://github.com/swiftcoder/spirv-struct-layout
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/swiftcoder/spirv-struct-layout
- Owner: swiftcoder
- License: apache-2.0
- Created: 2019-12-27T23:57:16.000Z (about 6 years ago)
- Default Branch: trunk
- Last Pushed: 2020-08-01T18:22:50.000Z (over 5 years ago)
- Last Synced: 2025-02-05T21:00:18.910Z (11 months ago)
- Language: Rust
- Homepage: https://crates.io/crates/spirv-struct-layout
- Size: 22.5 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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
```