Allow create_shader_module to receive a Naga module as ShaderSource #2788
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
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 inwgc::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.The text was updated successfully, but these errors were encountered: