# spirv-reflect-zig

This is a small program meant to reflect out zig compatible data structures from compiled spirv modules.
You can use the program in standalone or use it as part of your build.zig build system.


## As part of a build system

```zig
var spirvCompile = SpirvGenerator.init(b, .{.target = target, .optimize = optimize, .repoPath = "src"});
var myShader = spirvCompile.shader("path/to/shader.glsl", "myShader");

...

myExe.addModule("myShaderTypes", myShader);
```

In your program you can now access all the types defined in the shader
from your zig program via a simple zig import

```zig
const myShaderTypes = @import("myShaderTypes");
const ImageRenderData = myShaderTypes.ImageRenderData; // ImageRenderData conforms to the data layout specified 
const gl = myShaderTypes.gl; // glsl base types are available through this node in the module
```

```zig

var mappedBuffer = SomeGpuApi.mapBuffer(...);

var typedBuffer = @ptrCast([*]ImageRenderData, mappedBuffer);
typedBuffer[0] = .{.someXYField = gl.vec2{.x = 42, .y = 42} };

```


## As a standalone CLI

You can generate the standalone CLI from this folder by calling `zig build install`.

This will create `spirv-reflect-zig` in `zig-out/bin`. This will be able to reflect the 
contents of a json file generated by `spirv-cross --reflect` into a .zig file

`spirv-cross myshader.glsl --reflect --output myshader.json &&\
    spirv-reflect-zig myshader.json -o myshader.zig`
