Shader compilation overhead?


I replaced vertex and fragment shader code in my B3DM and I3DM files by material definitions using the KHR_materials_common GLTF extension.

Debugging the Cesium Code I noticed that the fragment and vertex shaders are assembled and comiled for each tile, even though the material definitions do not change across tiles.

What is the overhead of assembling and compiling shaders for each tile on the fly? Could the overhead be avoided using a common shader library?



Yeah, right now every tile will go through the modelMaterialsCommon shader creation. Possibly we could cache modelMaterialsCommon runs by material definitions…

Under the hood Cesium uses a shader cache so it shouldn’t be compiled multiple times. If you’re noticing that is is, definitely open an issue.

If your main motivation is to save bandwidth/space, one alternative solution is to use an external shader. The glb can reference external uri’s, so all the tiles can point to the same glsl files.

thanks for the hint,
createAndLinkProgram is only called once for each material in my tiles.
Only modelMaterialsCommon is called many times and converts the material definitions into techniques including the shader code each time. This looks like a complex process which could possibly be avoided by caching.
Shader code and technique generation was getting complicated due to the many options so that I want to leave it up to Cesium, thats one of my motivations