Skip to content

VDBObject : Register HalfGrid type - #1573

Merged
murraystevenson merged 2 commits into
ImageEngine:RB-10.7from
johnhaddon:halfGrids
Oct 22, 2026
Merged

murraystevenson merged 2 commits into
ImageEngine:RB-10.7from
johnhaddon:halfGrids

Conversation

@johnhaddon

Copy link
Copy Markdown
Member

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.

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.
@johnhaddon johnhaddon self-assigned this Oct 22, 2026
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.
@johnhaddon

Copy link
Copy Markdown
Member Author

Added a bonus commit for a bug I discovered in testing GafferHQ/gaffer#7209.

@johnhaddon

Copy link
Copy Markdown
Member Author

@lucienfostier, I think you'll be interested in the second commit here - perhaps needs backporting to 10.6 for IE?

@murraystevenson murraystevenson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@murraystevenson
murraystevenson merged commit 0b660e1 into ImageEngine:RB-10.7 Oct 22, 2026
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants