Backlog/lib/spirv-reflect-zig
Peter Li 641f38f295 Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
..
build_test Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
glslTypes Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
shaders Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
src Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
.gitignore Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
LICENSE Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
README.md Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
build.zig Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
build.zig.zon Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
example.zig Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00

README.md

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

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

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

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