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

Allow re-use of bind groups #33

Open
DCNick3 opened this issue Jul 18, 2024 · 5 comments
Open

Allow re-use of bind groups #33

DCNick3 opened this issue Jul 18, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@DCNick3
Copy link

DCNick3 commented Jul 18, 2024

Thank you very much for this project, I can see it improving QoL when using wgsl very much!

I have a question/feature request: can you re-use bind groups with same layouts between different shader entries?

For example, I want to have a bind group for a texture consisting of a texture binding and a sampler that I use in multiple shader entries. As I understand it, with current codegen, I will have to create a separate bind group object for each entry, as the newtype wrappers would be incompatible.

Ideally, I would have a common newtype TextureBindGroup (either defined in my or in the generated code) which I would just store in the same struct as my texture and re-use it whenever I need to pass it to a shader.

@Swoorup
Copy link
Owner

Swoorup commented Jul 18, 2024

Not quite sure since we use the naga oil syntax.

It seems you can choose only certain bind group entries in the current module. And also possibly override certain entries for the same group by using an import from another file?

If that weren't the case otherwise, it would have been a simple change.

@Swoorup Swoorup added the wontfix This will not be worked on label Jul 27, 2024
@Swoorup
Copy link
Owner

Swoorup commented Jul 28, 2024

Was thinking this, One way is to make all entries optional for the bond group that is common across modules. To support a mix match, could use enum. But it would make the code complex.

@Swoorup
Copy link
Owner

Swoorup commented Jul 28, 2024

I kinda need this ATM myself. It would be great if you could provide an example files for your use case.

@Swoorup Swoorup added enhancement New feature or request and removed wontfix This will not be worked on labels Jul 28, 2024
@bconnorwhite
Copy link
Contributor

You might need to handle wgsl files individually, rather than using entry points.

My solution to this was to build a .rs file for each .wgsl file, and mirror the import path in Rust so that each entry point for example has access to the same shared bind group: https://github.com/bconnorwhite/wgsl_to_wgpu/tree/import-modules

@Swoorup
Copy link
Owner

Swoorup commented Aug 16, 2024

You might need to handle wgsl files individually, rather than using entry points.

My solution to this was to build a .rs file for each .wgsl file, and mirror the import path in Rust so that each entry point for example has access to the same shared bind group: https://github.com/bconnorwhite/wgsl_to_wgpu/tree/import-modules

Think that should be fairly simple, if we just look up the mangled symbols. Just worried about the common bind group entry themselves being overridden, as that is allowed by naga_oil. That seems like a rare thing to do. I'll try to write up a prototype sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants