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 create_shader_module to receive a Naga module as ShaderSource #2788

Closed
atadier opened this issue Jun 19, 2022 · 2 comments
Closed

Allow create_shader_module to receive a Naga module as ShaderSource #2788

atadier opened this issue Jun 19, 2022 · 2 comments
Labels
area: api Issues related to API surface good first issue Good for newcomers help required We need community help to make this happen. type: enhancement New feature or request

Comments

@atadier
Copy link
Contributor

atadier commented Jun 19, 2022

Is your feature request related to a problem? Please describe.
Ultimately, when creating a shader module on a native backend, the shader source is parsed into a naga::Module so that wgpu can serve different backends at once. This means no matter what shading language you pass as input, there will be an inevitable parsing step to an intermediate representation. This is wasting runtime performance when we could just be embedding the intermediate representation itself.

Describe the solution you'd like
To allow that, the ShaderSource API could be extended to allow a new variant: ShaderSource::Naga(naga::Module). The module provided by the user would be passed down as-is in wgc::pipeline::ShaderModuleSource::Naga(module) on native, where things like validation and runtime checks are already handled. On the web, it would be validated and written back to WGSL.

Describe alternatives you've considered
Embedding IR has the advantage of being platform-agnostic while reducing binary size, but it will still require a translation step to native shaders. It seems to be a fair trade-off with precompiled shaders when you need to retain the cross-platform aspect but still want the performance gains.

Additional context
naga::Module can be serialized, indicating it can be used as a shader data format like any other.

@cwfitzgerald cwfitzgerald added type: enhancement New feature or request help required We need community help to make this happen. area: api Issues related to API surface good first issue Good for newcomers labels Jun 20, 2022
@jimblandy
Copy link
Member

It's true that naga::Module can be serialized, but we change the IR pretty frequently. It would not be a stable storage format.

@atadier
Copy link
Contributor Author

atadier commented Jun 21, 2022

The main use case for this feature is to parse and use shaders in the same project, where compatibility issues are unlikely to occur unless different versions of naga are being used. In that case, it would be up to the library user to check compatibility with whichever version they are using until the IR is stabilized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: api Issues related to API surface good first issue Good for newcomers help required We need community help to make this happen. type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants