Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UsdImagingDelegate::PopulateSelection() adds too many instances to HdSelection #1240

Closed
williamkrick opened this issue Jun 10, 2020 · 1 comment

Comments

@williamkrick
Copy link

Description of Issue

A call to UsdImagingDelegate::PopulateSelection for a USDXform prim which is a parent to an instancer with N instances (that uses UsdImagingInstanceAdapter) will create an HdSelection which contains N^2 instances.

Steps to Reproduce

  1. Create a scene with a USDXform that is a parent to an instancer. The instancer should have N instances. In my case it has 11.
  2. Using for favorite USD app, call UsdImagingDelegate::PopulateSelection() on the USDXform that is the parent (or higher ancestor) or the instancer. The instanceIndex parameter should be UsdImagingDelegate::ALL_INSTANCES.
  3. Examine the resulting HdSelection for the instancer. Inside instanceIndices I find N^2 indices (121 rather than 11).

I noticed this when working on MayaUSD issue Autodesk/maya-usd#575. ProxyRenderDelegate::_FilterSelection() makes the call to PopulateSelection as I have described above, and we look at the resulting selection state at https://github.com/Autodesk/maya-usd/blob/dev/lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp#L1295.

What seems to be happening is the call to _GatherDependencies in PopulateSelection finds a path to all N instances. Then each call to PopulateSelection is on an UsdImagingInstanceAdapter. That gets the UsdImagingDelegate::ALL_INSTANCES parameter and adds N instances. The adding N instances happens N times, so N^2 instanceIndices.

hd.dll!pxrInternal_v0_20__pxrReserved__::HdSelection::AddInstance(const pxrInternal_v0_20__pxrReserved__::HdSelection::HighlightMode & mode, const pxrInternal_v0_20__pxrReserved__::SdfPath & path, const pxrInternal_v0_20__pxrReserved__::VtArray<int> & instanceIndices) Line 48 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\imaging\hd\selection.cpp:48)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingPrimAdapter::PopulateSelection(const pxrInternal_v0_20__pxrReserved__::HdSelection::HighlightMode & mode, const pxrInternal_v0_20__pxrReserved__::SdfPath & cachePath, const pxrInternal_v0_20__pxrReserved__::UsdPrim & usdPrim, const int hydraInstanceIndex, const pxrInternal_v0_20__pxrReserved__::VtArray<int> & parentInstanceIndices, const std::shared_ptr<pxrInternal_v0_20__pxrReserved__::HdSelection> & result) Line 420 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\primAdapter.cpp:420)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_PopulateInstanceSelectionFn::operator()(const std::vector<pxrInternal_v0_20__pxrReserved__::UsdPrim,std::allocator<pxrInternal_v0_20__pxrReserved__::UsdPrim> > & instanceContext, unsigned __int64 instanceIdx) Line 2204 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\instanceAdapter.cpp:2204)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_RunForAllInstancesToDrawImpl<pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_PopulateInstanceSelectionFn>(const pxrInternal_v0_20__pxrReserved__::UsdPrim & instancer, std::vector<pxrInternal_v0_20__pxrReserved__::UsdPrim,std::allocator<pxrInternal_v0_20__pxrReserved__::UsdPrim> > * instanceContext, unsigned __int64 * instanceIdx, pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_PopulateInstanceSelectionFn * fn) Line 591 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\instanceAdapter.cpp:591)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_RunForAllInstancesToDraw<pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_PopulateInstanceSelectionFn>(const pxrInternal_v0_20__pxrReserved__::UsdPrim & instancer, pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::_PopulateInstanceSelectionFn * fn) Line 556 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\instanceAdapter.cpp:556)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingInstanceAdapter::PopulateSelection(const pxrInternal_v0_20__pxrReserved__::HdSelection::HighlightMode & highlightMode, const pxrInternal_v0_20__pxrReserved__::SdfPath & cachePath, const pxrInternal_v0_20__pxrReserved__::UsdPrim & usdPrim, const int hydraInstanceIndex, const pxrInternal_v0_20__pxrReserved__::VtArray<int> & parentInstanceIndices, const std::shared_ptr<pxrInternal_v0_20__pxrReserved__::HdSelection> & result) Line 2354 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\instanceAdapter.cpp:2354)
usdImaging.dll!pxrInternal_v0_20__pxrReserved__::UsdImagingDelegate::PopulateSelection(const pxrInternal_v0_20__pxrReserved__::HdSelection::HighlightMode & highlightMode, const pxrInternal_v0_20__pxrReserved__::SdfPath & usdPath, int instanceIndex, const std::shared_ptr<pxrInternal_v0_20__pxrReserved__::HdSelection> & result) Line 2088 (c:\dev\ecg-usd-build\ecg-usd-build\usd\pxr\usdImaging\usdImaging\delegate.cpp:2088)
mayaUsd.dll!pxrInternal_v0_20__pxrReserved__::ProxyRenderDelegate::_FilterSelection() Line 717 (c:\dev\usd\ecg-maya-usd\maya-usd\lib\mayaUsd\render\vp2RenderDelegate

I would expect instanceIndices to contain each index only once. I would also expect the HdSelectionState to have fullySelected=true, but I don't get that either.

Maybe we are making the call to PopulateSelection incorrectly? Or maybe I am interpreting the instanceIndices buffer incorrectly? Any additional information would be helpful.

System Information (OS, Hardware)

Windows

Package Versions

USD v20.05, MayaUSD dev branch at 2164db46

Build Flags

@williamkrick
Copy link
Author

I just re-tested this in dev @ commit e7ff8e8 and I can't reproduce it there, so closing.

kohakukun added a commit to autodesk-forks/USD that referenced this issue Oct 21, 2024
…imationStudios#1240)

- Fix resource binding issue when multiple batches are executed but
one of them doesn't draw or submit work. The next batch will set
a new pipeline while still having the old resources bound incorrectly.
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

No branches or pull requests

1 participant