CPU friendly texture loading / acquire texture multithreading? #1943
-
Hi, I am doing experiment in maya-usd to see if we can load textures in multithreading way, the first problem I encountered is that when calling
I am not familiar with
Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments
-
Hi @csyshing,
The crash occurs when trying to clean up some temporary targets created when loading the tiled texture. A CPU friendly version of Is this work an effort to improve the performance of loading ALab? |
Beta Was this translation helpful? Give feedback.
-
Yes @williamkrick , I was trying to improve the performance of loading ALab, the trace shows that most of the time is on running |
Beta Was this translation helpful? Give feedback.
-
Unfortunately we don't have a simple answer for #1624. Working on this is near the top of our priority list so I'm hopefully we can spend some time on it soon. There is a related issue I logged against USD PixarAnimationStudios/OpenUSD#1597 which would alleviate some of the problem loading the scene. Loading the textures for the render materials will still be slow but we'd only have to load those textures when the user chooses to see the render version of the objects. |
Beta Was this translation helpful? Give feedback.
-
@williamkrick , I am doing tests that run |
Beta Was this translation helpful? Give feedback.
-
That is a great idea and it should work fine. The main thing to watch out for would be if the interactive session modifies the scene while the low priority task is still running then don't crash. For example if a |
Beta Was this translation helpful? Give feedback.
-
I implemented a prototype like this:
sceneDelegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(sprimId, HdMaterial::DirtyResource)
But it does not seem to render the prims as expected: When I switch the purpose to "render" (around 0:38 second in the GIF above), I do see the textures showing up correctly, switching back to "proxy" does not seem to trigger any redrawing. Then I realized that, ALab put the prims as instances, e.g.
I manually edited the usda to turn off the instanceable scene to be false: The textures once finished loading, seem to show up one by one as expected (starting around 0:21 second in GIF above). So looks like there is a step missing to inform maya-usd to refresh/reload the material for instances but I am not sure where it could be, @williamkrick , do you have any hints I could look into? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Cool! What version of Maya are you working with? Assuming you are using 2022, my first guess would be that there is a breakdown in communication between the instancer and the instance prototype. The Do we need the rprim sync for the drawing to correctly update? Something simple like modifying the diffuse color of a material shouldn't require an rprim sync, but I'm sure we could create a shader where changing a parameter did require a sync. If you are using 2023 there is a system in place in Maya which, after a call to I guess my advice is focus on |
Beta Was this translation helpful? Give feedback.
-
Hi @williamkrick , I am using Maya 2022, I think I found the bug that instances do not get updated: maya-usd/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp Lines 1862 to 1865 in 14b93b8 The if condition tests against the drawItemData._shader but I believe the intention is to reset both drawItemData._shader (L1863) and stateToCommit._shader = shader (L1865), so it's better to count in stateToCommit._shader , I created a draft PR-1980 for discussion, please have a look and let me know!
|
Beta Was this translation helpful? Give feedback.
-
I think I see what you are saying. Is it true that when we hit line 1862 the state is drawItemData._shader matches shader, but stateToCommit._shader has something in it which doesn't match, and so we end up with unexpected behavior? If that is the case then your change makes sense. I'm looking at the rest of the draft review now. |
Beta Was this translation helpful? Give feedback.
Hi @csyshing,
MHWRender::MTextureManager::acquireTiledTexture()
is not thread safe. In general none of Maya's API functions are thread safe, and this particular function is especially not thread safe. I don't think there is a way to safely load textures in parallel through Maya's API.The crash occurs when trying to clean up some temporary targets created when loading the tiled texture.
A CPU friendly version of
acquireTiledTexture()
would remove a major source of thread-unsafety from the code, accessing the underlying graphics API, so it would be a step towards a multithreaded texture load. However, speculating about that hypothetical API is not really possible because of how different i…