PDA

View Full Version : GLSL Performance vs Maintainability



SharkByte
05-05-2016, 10:51 AM
Hello, so I've been going back and forth between many shader files and constantly have to change, tweak and remove parameters in that order.

I've already modified my parser to allow #include support so common functionality can be in one file which is just great but wondered if I'd get a performance hit by doing the same to my uniform (UBO's) because it would mean that some shader files will include UBO's it never uses?

Furthermore, if you have any optimisation tips I'd LOVE to hear them ;)

Alfonse Reinheart
05-05-2016, 10:56 AM
Well, if they're std140 UBOs, and they have bindings specified in-shader, then that could cause the implementation to reserve space for them even if they go unused. Then again, maybe not.

If you want to be more certain about these things, declare structs in your included files, but define the actual UBOs in the sources that use them. So your UBO would just be `layout(...) uniform Name {StructName data;};`, with all of the parameter modifications happening in the structs.

SharkByte
05-05-2016, 11:12 AM
Well, if they're std140 UBOs, and they have bindings specified in-shader, then that could cause the implementation to reserve space for them even if they go unused. Then again, maybe not.

If you want to be more certain about these things, declare structs in your included files, but define the actual UBOs in the sources that use them. So your UBO would just be `layout(...) uniform Name {StructName data;};`, with all of the parameter modifications happening in the structs.

Yes I'm using both qualifiers. That's exactly what I was looking for thank you, works like a charm :D