Skip to content
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

Zig and Sokol-Shdc #117

Closed
Interrupt opened this issue Feb 9, 2024 · 3 comments
Closed

Zig and Sokol-Shdc #117

Interrupt opened this issue Feb 9, 2024 · 3 comments
Labels
bug Something isn't working enhancement New feature or request zig

Comments

@Interrupt
Copy link
Contributor

Interrupt commented Feb 9, 2024

Two notes about using the Zig target for sokol-shdc when making a Material system:

  • Zig target does not seem to honor the --reflection argument - I'm not seeing any extra data get baked into the .zig output file.
  • Since Zig is already namespaced under the import name, it would be nice to have the function that builds the file to be named something more generic like pub fn getShaderDesc(backend: sg.Backend) sg.ShaderDesc { ... to work better with Zig reflection when making a Material system.
@floooh
Copy link
Owner

floooh commented Feb 10, 2024

Thanks! Yeah, not supporting --reflection is more or less an oversight.

The second one is a bit more tricky though, since there may be multiple shaders in the same .glsl file, and each generates its own getShaderDesc() function.

The solution is probably to add a nested per-shader namespace:

// per-shader namespace struct
pub const Bla = struct {
    pub fn shaderDesc(backend: sg.Backend) sg.ShaderDesc { ... }
}

...that way it should be possible to walk the imported toplevel struct and find all shaders (== nested namespace-structs) and their getShaderDesc() functions.

I wonder if the whole shader-reflection stuff could also be simplified when taking Zig's comptime features into account... e.g. instead of having runtime functions to query the reflection information just add constants to the per-shader-namespace struct which can then be discovered by inspecting the struct via Zig's comptime type reflection (or maybe both makes sense).

So far the language binding backends in sokol-shdc are more or less copies of the C backend. But it might be worth supporting language-specific features a bit more.

@floooh floooh added bug Something isn't working enhancement New feature or request zig labels Feb 10, 2024
@Interrupt
Copy link
Contributor Author

Having a per-shader namespace like that would help out a lot - that would make it way more usable from a Zig point of view.

As for the reflection, I think you're right in that adding constants to that namespace also makes a lot of sense.

@floooh
Copy link
Owner

floooh commented Sep 4, 2024

Closing this now as completed via #147 (thanks!).

If we want to change the way reflection works in the Zig codegen we should do this via new issues.

@floooh floooh closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request zig
Projects
None yet
Development

No branches or pull requests

2 participants