Repository navigation
VDBObject : Register HalfGrid type - #1573
Merged
Merged
Conversation
This is available out of the box in OpenVDB 13, but not in our current OpenVDB 12. Also moved initialisation out of VDBObject constructor and into a static initialiser. Otherwise we'd have to use another mutex around our `isRegistered()/registerGrid()` calls - while each call is threadsafe in itself, there is a race condition in calling them both, which could lead to multiple registration errors. VDBObject constructors could be called concurrently, but static initialisation only happens once.
This made lots of interesting sequences of events possible - here's one : 1. Thread A sees `m_hashValid == false` and starts to compute the hash. 2. Thread B also sees `m_hashValid == false` and also starts to compute the hash. 3. Threads A and B merrily stomp over `m_hash` concurrently, so the result won't be deterministic. There are further problems though... 4. Thread A finishes stomping and sets `m_hashValid = true`. Thread B continues stomping. 5. Threads C, D, E etc see `m_hashValid == true` and read whatever the current value of `m_hash` is - all getting different values from different stages of thread B's stomping. This was causing instanced in-memory VDBS to lose their instancing when exported to Arnold, because each instance got a different random version of the hash. This is mitigated by computing the hash in a temporary variable before assigning it. This isn't a full fix though, because the compiler _could_ reorder `m_hashValid = true` before `m_hash = h` from the point of view of a reading thread. Solving that needs some form of synchronisation (mutex, call_once etc), which we can't do without an ABI break.
Member
Author
|
Added a bonus commit for a bug I discovered in testing GafferHQ/gaffer#7209. |
Member
Author
|
@lucienfostier, I think you'll be interested in the second commit here - perhaps needs backporting to 10.6 for IE? |
lucienfostier
approved these changes
Oct 22, 2026
murraystevenson
approved these changes
Oct 22, 2026
murraystevenson
left a comment
Collaborator
There was a problem hiding this comment.
Thanks John. IE would require the second commit backported to 10.5, so they'll do some testing and consider a backport next week while we merge this as-is.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is available out of the box in OpenVDB 13, but not in our current OpenVDB 12. Also moved initialisation out of VDBObject constructor and into a static initialiser. Otherwise we'd have to use another mutex around our
isRegistered()/registerGrid()calls - while each call is threadsafe in itself, there is a race condition in calling them both, which could lead to multiple registration errors. VDBObject constructors could be called concurrently, but static initialisation only happens once.Would be good to get this into the next Cortex release - I'll have a Gaffer PR depending on it shortly.