Flush USD StageCache

   2563   6   1
User Avatar
Member
15 posts
Joined: Dec. 2019
Offline
Hi,

We are running into issues when switching between different shot context that are sharing USD layers, where we want to Resolve to different version of the layer.
Is there a way to release/flush the USD Stage Cache in Solaris through Python? Similar to Maya that flushes all caches when closing a Maya scene.
Edited by jacobvfx - May 16, 2022 11:42:59
User Avatar
Member
15 posts
Joined: Dec. 2019
Offline
I tried the StageCache() method from UsdUtils, but that doesn't seem connected to the layers loaded in Solaris.
User Avatar
Staff
4444 posts
Joined: July 2005
Offline
As I asked on usd-interest (though this is probably a better place to continue the conversation), are you trying to flush just the USD data or the Houdini cache that is used for creating USD packed primitives in SOPs?

If you're just talking about native USD data (and really SOP cached stages as well), in theory you should never need to force-flush any caches unless you are modifying USD files on disk, and forcing them to reload. In that case the SdfLayer.Reload method is the way to let USD know that the file on disk needs to be reloaded.

If you are instead using an asset resolver, and using env vars or something to drive the asset resolver behavior, that's a completely different problem...
User Avatar
Staff
4444 posts
Joined: July 2005
Offline
I should add specifically that Houdini does not make any use of the UsdUtils.StageCache.
User Avatar
Member
15 posts
Joined: Dec. 2019
Offline
Let's continue the conversation here.

The issue I'm running into is when I'm switching between different shots that are sharing the same underlying layers.

Let's say I have shotA.usda that's sublayering "sharedLayout_v001.usda". The resolve context for shotA tells it to resolve that layer up to v003.
Then I switch to shotB.usda that's also sublayering that same "sharedLayout_v001.usda" file. In the resolve context for shotB it should resolve the layer to v002. But since the layer is already loaded it doesn't get re-resolved.

What I'm looking for is a way to flush/clear the StageCache for all loaded layers when I'm switching context/shot to make sure I get the correct result.
Edited by jacobvfx - May 17, 2022 15:58:58
User Avatar
Staff
4444 posts
Joined: July 2005
Offline
I think the correct answer here came from Colin over on usd-interest: https://groups.google.com/g/usd-interest/c/5x5p_bRxobk/m/Qvh_ly_jBQAJ [groups.google.com]

To summarize: this is a limitation of the LayerRegistry deep inside the USD library, and you really have no access to it. The workaround sugested was to have your asset resolver manipulate the layer identifier to incorporate a hash of the resolver context.

The next major version of Houdini will be shipping with Ar2.0. But looking at that library, and the layer registry code, I'm not sure that Ar2.0 has actually fixed this issue.
User Avatar
Member
14 posts
Joined: Nov. 2022
Offline
this issue becomes really obvious if you simply use `UsdUtils.ModifyAssetPaths` and then open another hip file. it will contain modified paths that were changed via the Python call in your previous hip. This makes any usd path manipulation (through AR or python) very dangerous as you cannot trust what you see in the viewport.

that resets everything:

root_layer = stage.GetRootLayer()
for layer in root_layer.GetCompositionAssetDependencies():
    hou.lop.reloadLayer(layer)
Edited by pawel-fin - April 12, 2023 23:28:44
  • Quick Links