I am using static const variables based on uniform variables. For example:

uniform uint uSampleCount;

static const float invSampleCount = 1.0 / float(uSampleCount);

Is this static recalculated for every vertex and fragment, or are shader frameworks smart enough to initialize this once before the shader starts processing? Does using or not using static and/or const make a difference?

  • 2
    \$\begingroup\$ Have you tried profiling your shader with and without these keywords to find out for sure? I'd trust direct reproducible measurement over "someone on the Internet said...." any day. ;) \$\endgroup\$
    – DMGregory
    Nov 26 '18 at 17:49
  • \$\begingroup\$ Yes, haven't seen a difference. Was hoping someone had some documentation link or something that I haven't been able to find in a few hours of Google searching. I am considering moving a lot more into these kind of statics but want to be sure of the performance characteristics moving forward. \$\endgroup\$
    – jjxtra
    Nov 26 '18 at 18:49
  • 1
    \$\begingroup\$ Try moving a lot into that style now, with very expensive operations, to stress test it. I'd bet you could complete such a test faster than waiting for an answer, and be more confident in the conclusion as a bonus. \$\endgroup\$
    – DMGregory
    Nov 26 '18 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.