Scene index invalidation of custom prim types

Hi,

In our render delegate we have custom prim types with custom adapters that we want to port to hydra 2/scene index. I am not sure I understand correctly how the invalidation mechanism should work in that case.

Here is what I understand so far:

  • When a usd parameter is modified, there is a call to the function InvalidateImagingSubprim of its prim’s adapter. This function returns the hydra prim locator to invalidate knowing the modified usd parameter.

USD parameter change → Hydra locator to invalidate

  • Then the locators to invalidate are broadcasted via the SendPrimsDirtied callbacks and end up in the function which converts back the locators to a “dirtyBits” representation ,HdSceneIndexAdapterSceneDelegate::PrimsDirtied()

USD parameter change → Hydra locator to invalidate → Compute dirtyBits representation

  • Once and if a dirtyBit is found, the Rprim is marked dirty using the _MarkRprimDirty(dirtyBits) function.

USD parameter change → Hydra locator to invalidate → Compute dirtyBit representation → _MarkRprimDirty(dirtybit)

  • The dirtied Rprims are finally Synced with the found dirtyBits

USD parameter change → Hydra locator to invalidate → Compute dirtyBit representation → _MarkRprimDirty(dirtybit) → Sync dirty Rprims

Unfortunately the translation from the locators to the dirtyBit representation is harcoded: the function HdDirtyBitsTranslator::RprimLocatorSetToDirtyBits translates for only some known types and known locators, and it seems impossible to add a new custom prim type or custom locators.
What would be correct solution to convert custom prim types locators to dirtybits ?
I am thinking that may be adding an observer could work, would that be a solution that follows the design ? Or should we add a special case for the custom prims in HdDirtyBitsTranslator::RprimLocatorSetToDirtyBits ? like in SprimLocatorSetToDirtyBits which allows adding dynamic conversion function.

Thanks for any help,

In the long-term, I expect it’ll all be custom SceneIndexObservers that replace the SceneIndexAdapterSceneDelegate and Hydra1 render delegate APIs.

In the short-term, we have an end-of-chain SceneIndex that monitors for custom dirty locators and “remaps” the dirty calls into ones we know will trigger a Sync (by carefully inspecting HdDirtyBitsTranslator::RprimLocatorSetToDirtyBits)

Hi @robp_sidefx,
Thanks for the the tip !
I created a scene index like you did, remapping the affected attributes to primvars/attributes. As primvars as remapped in HdDirtyBitsTranslator::RprimLocatorSetToDirtyBits the prim is correctly resynced. It’s a bit hacky, but it works.

Cheers

If you find a cleaner/better way, share the love back in this direction :slight_smile:

Without access to the change tracker / render index or modifying the USD code, it looks like the best and simplest solution. An improvement could possibly be to add a “pluggable” conversion functions mechanism for custom Rprim types, like it’s done for Sprim here : OpenUSD/pxr/imaging/hd/dirtyBitsTranslator.cpp at c5a16c3fdde6045d7ed47eafbd5629e1102f28f0 · PixarAnimationStudios/OpenUSD · GitHub
So anyone providing custom Rprim would also be able to register their own conversions functions between dirtybits and locators, like it is already possible with Sprims. It would remove one ‘workaround’ scene index filter on our side and simplify the logic when debugging.
Would that be interesting for you?
I can cook a PR and see where it lands anyway.