-
Notifications
You must be signed in to change notification settings - Fork 0
Shader Diffing
- Scene is updated immutably and rendered as a pure function
- Every primitive requires knowing which shader to use
- Changes to the scene affect what the shader code should be
- Generating and uploading a new shader is expensive
-
A plain object called
shaderConfig
is derived for each scene + primitive combo. -
This object is hashed, resulting in a
shaderHash
(just a plain string). This hash is used to lookup in a global map for a compiled shader. -
If the shader is not found for that hash, it is compiled and stored. Compiling a shader requires passing the
shaderConfig
object (and nothing else)
All of this happens every tick (though of course cache misses are typically only on the first tick). Therefore, creating shaderConfig
and hashing it must be very fast (and they are - setting shaderConfig
is mostly unrolled settings of flags, and the hash is a hand-tuned approach that was tested against several other approaches).
This is one of the reasons why extensions are hardcoded rather than an open and flexible api (though conceptually they could be dynamically loaded and just append the hash string).
At this point from some minimal tests - it seems to support a few thousand gltf objects no problem. At that point the bottleneck is almost definitely somewhere else in the system rather than diffing/hashing. Since it's all pure data, this work could be offloaded to a separate thread as well.