-
Notifications
You must be signed in to change notification settings - Fork 927
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
Precompiled Shaders #3103
Comments
We definitely would be interested in having this feature! A couple considerations to keep in mind:
As such I would propose an api that looks something like this: // Replaces ShaderModuleDescriptorSpirv
pub struct ShaderModuleDescriptorRaw<'a> {
pub label: Label<'a>,
/// Raw data of whatever type the backend needs - likely Vec<u32> or a string. Maybe something fancier like a MTLLibrary wrapper.
pub source: Box<dyn Any>, // Maybe a custom trait?
}
// Replaces create_shader_module_spirv
//
// Note the taking of the descriptor by value.
pub unsafe fn create_shader_module_raw(&self, desc: ShaderModuleDescriptorRaw) -> ShaderModule Then inside each wgpu-hal backend we can properly document how bindings get mapped based on all possible arguments to a pipeline creation. |
@cwfitzgerald, what about the web backend? Does this proposal respect webgl? |
@Wandalen sure - the webgl/gles backend could accept raw glsl shaders with string as it's type. |
See also: #1464 According to some basic stats from |
I am working with @raphlinus on piet-gpu and we're considering replacing our internal HAL with wgpu-hal but we would like to retain the ability to use precompiled shaders to reduce both binary size and startup cost.
After some investigation, it seems the least invasive solution would be to add variants to
ShaderInput
for MSL source (or potentially aMTLLibrary
instance) and DXIL and feed those through to pipeline creation in the same way thatSpirV
works for Vulkan today. This would require the user to assign bindings that are compatible with those generated by wgpu-hal during pipeline layout creation. For our purposes, this would be an acceptable constraint.Alternatively, we've also considered a more sophisticated approach that would allow the user to provide a bind mapping during shader module creation. This seems to require deferring native resource binding until the whole pipeline state is known so that discrepancies between the pipeline layout and the expected binding slots for the entry point can be reconciled.
My understanding is that the project is amenable to such a change, and we're willing to do the work, but wanted to provide an opportunity for other potential users who are interested in this feature to weigh in and develop a consensus on the best path forward.
The text was updated successfully, but these errors were encountered: