This is a patch that fixes an issue with uninitialized uniforms for me. The issue happens rarely, but it does happen. Please let me know if there's a better way to fix it and I will be happy to rework the CL.
Merge pull request #6 from p3/master
update from latest upstream
Merge pull request #7 from p3/master
pull latest upstream code
Force uniform update on first use.
In most new programs "ver" is updated through UpdateMatrixVer().
However, when that does not happen a program may end up being
unusable as uniforms are not set correctly.
I was very curious about that as well. However, not knowing how versions are supposed to be updated and synchronized, there was very little I could investigate. Could you give some update on how versions are supposed to be updated and synchronized? They appear to be on quite a few levels and a few of them may get assigned at the same time.
Cass, should these unsigned 64-bit integers be wrapped into a struct that will default-construct to -1 instead of 0?
There's one instance of Version in the Iff class. It is sort of a timestamp. Its goal is to be monotonically increasing as state settings occur, but no more frequently than draw calls that use that state. (With a 64b counter, it's unnecessary to limit the increments this way, and maybe we shouldn't bother.) Fixed-function state is in a single hierarchical structure that has timestamps at various levels of the hierarchy. The idea is when you update some state, you capture the timestamp at that time and you propagate that timestamp up to the root. This all goes on independent of shaders that actually reference the state.
There can be many shaders, both fixed-function and user-specified, that reference this state as program uniforms. Because program uniforms are program-local (until UBO is ubiquitous), each program has a cached copy of each piece of uniform state it references along with the version timestamp when it was captured. At draw time, each fixed-function uniform is checked to see if it is out of date. If the version numbers match, it is not out of date and no update occurs. If the version numbers don't match, the uniform and its version number updated immediately before the draw.
Yes, Nigel, that's probably a good idea.
I'll merge this patch as-is. But I'm concerned that initializing all the timestamps to -1 will put us back where we started, in terms of detecting when uniforms need to be sent. Can we change the logic from == to < ?