-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding reflection functions to Zig output #147
Conversation
I'm just stepping through the code, and I think we should change the return value, since these are all 'native' Zig functions (no C-exported functions):
For instance the function pub fn defaultAttrSlot(attr_name: []const u8) ?usize {
if (std.mem.eql(u8, attr_name, "pos")) {
return 0;
}
if (std.mem.eql(u8, attr_name, "color0")) {
return 1;
}
if (std.mem.eql(u8, attr_name, "texcoord0")) {
return 2;
}
return null;
} |
Updated to return optional values, the functions now look something like:
|
Looks good now IMHO. I'll play around a bit with the reflection functions in sokol-zig later today to make sure that the generated Zig code is valid. |
A couple of minor issues when trying in sokol-zig: Unused local variable pub fn quadUniformDesc(stage: sg.ShaderStage, ub_name: []const u8, u_name: []const u8) ?sg.ShaderUniformDesc {
var desc: sg.ShaderUniformDesc = .{};
_ = stage;
_ = ub_name;
_ = u_name;
return null;
} ... pub fn vertexpullAttrSlot(attr_name: []const u8) ?usize {
return null;
} To try this for yourself, clone https://github.com/floooh/sokol-zig, and then in build.zig add a new parameter ...then run |
Oh that was quick :) The sokol-zig samples build fine now, I'll try to call some of the generated functions and then merge. |
Ok, did a couple of calls into the generated functions and looking good. Once the CI pipeline goes green I'll merge, add a little blurb to the changelog and then build new binaries. Thanks! |
Just was going to comment, you're quick too! The samples built and ran fine with these latest changes. Zig's unused variables makes codegen a pain - maybe the more Ziggy way to do this someday would be to write out a const struct with the shader description in the file and then do compile time reflection against it for these functions. |
Yeah indeed. I was running into similar issues in my Z80 emulator where I'm code-generating the instruction decoder.
Yep, good idea. But I think the runtime functions will do for now :) |
PS: The next big sokol-gfx feature I'll tackle (after catching up with some issues and PRs) will be a rewrite/cleanup of the resource binding to make it more flexible. This will also affect the sokol-shdc code generation parts. Maybe I'll experiment a bit with the Zig code generator then. |
...and merged. |
Ok, binaries are building: https://github.com/floooh/sokol-tools/actions/runs/10706385602 |
Example output for a program called 'default' looks like: