Force uniform update on first use #57

Merged
merged 3 commits into from Mar 22, 2013

3 participants

@igor-c

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.

igor-c and others added some commits Mar 20, 2013
@igor-c igor-c Merge pull request #6 from p3/master
update from latest upstream
622feb1
@igor-c igor-c Merge pull request #7 from p3/master
pull latest upstream code
ad0522c
Igor Chernyshev 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.
c051c05
@casseveritt
p3 member
@igor-c

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.

@nigels-com

Cass, should these unsigned 64-bit integers be wrapped into a struct that will default-construct to -1 instead of 0?

  • Nigel
@casseveritt
p3 member

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.

@casseveritt
p3 member

Yes, Nigel, that's probably a good idea.

@nigels-com

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 < ?

@nigels-com nigels-com merged commit c051c05 into p3:master Mar 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment