13
\$\begingroup\$

Having an application that uses shaders that have been wrote in GLSL, what is the best strategy for the distribution in the real world and for the desktop and mobile?

I'm aiming to distribute this in a binary form or as plain serialized text, i would like a good suggestion on this.

\$\endgroup\$

1 Answer 1

15
\$\begingroup\$

The main rationale for using binary shaders is if compiling the text shaders is too big of a workload for your target device. Binary GLSL shaders don't have a standardized format, so you'd need different ones for each GPU/driver you plan to support. I'd recommend you distribute the shaders in source form and then on the first run cache them into binary form and subsequently load from there. Then again I'd first test if you really have a performance bottleneck there to justify using the binaries at all.

One thing to consider is also an offline text shader optimizer that can have a great effect with crappy mobile shader compilers.

\$\endgroup\$
4
  • \$\begingroup\$ I'd actually be surprised if you could find any device where shader compilation is a bottleneck. The amount of code, even in large shaders, is a trivial amount of code in terms of compilation. \$\endgroup\$ Aug 27, 2012 at 9:44
  • 1
    \$\begingroup\$ The big engines out there usually compile shaders offline, and/or cache them on the first run, as Tapio suggests. Maybe there's a trivial amount of code per shader, but you can have a lot of them. \$\endgroup\$ Aug 27, 2012 at 10:44
  • \$\begingroup\$ so i have to buy a random ATI videocard and another random one from Nvidia, compile my shaders and distribute only the compiled version? How i can check at runtime what is the brand of the targeted video card? There is something reliable for that? \$\endgroup\$
    – user827992
    Aug 27, 2012 at 14:17
  • 1
    \$\begingroup\$ @user827992 The binary format may be different for different generations of GPUs/drivers even if the vendor is the same. And don't forget there's also lot's of Intel GPUs out there, let alone all the mobile ones, like Qualcomm and PowerVR. So again: I suggest you don't distribute compiled shaders, but rather cache them on first run on the user's device. Regarding GPU detection, you could try parsing GL_VENDOR, GL_VERSION and GL_RENDERER strings form glGetString(), but their format varies from vendor to vendor. \$\endgroup\$
    – Tapio
    Aug 27, 2012 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .