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

Compare HdPrimvarDesrciptor equality by name and role #2096

Conversation

tylerm-nv
Copy link
Contributor

@tylerm-nv tylerm-nv commented Nov 16, 2022

Description of Change(s)

Removes interpolation from the HdPrimvarDescriptor == overload.

Fixes Issue(s)

Fixes an issue where UsdImagingPrimAdapter::_MergePrimvar will insert a duplicate descriptor into the vector if the interpolation is changed.

We observe this issue when calling SetWidthsInterpolation on basis curves after the widths attribute has been created. The equality check always returns false because the interpolation was changed, so it inserts a duplicate. Our delegate queries each interpolation type, and the last one found wins. This often results in the wrong type, and we can't proceed with some logic.

I tried to write tests for this, but could not reproduce with testusdview. The shader used for curves requires the primvar to be defined, it emits a shader compilation error if only the WidthsAttr is present. And it will render in some invalid states, but error in others, like this:

Initial render state:

  • widths value [3, 3, 5]
  • widths interp varying

Storm renders the expected image

Second render state:

  • widths value [1]
  • widths interpolation varying

Storm renders the expected image despite not changing interpolation.

If you reverse that order, so that it starts with a valid constant state and change to varying, it will fail with a shader error. Even with the operations in a changeblock.

  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

@sunyab
Copy link
Contributor

sunyab commented Nov 19, 2022

Filed as internal issue #USD-7781

@tcauchois
Copy link
Contributor

Hi!

Thanks for the submission but I don't think changing the equality operator here is safe. Is there a way to fix the bug by changing UsdImagingPrimAdapter::_MergePrimvar instead?

Thanks,
Tom

@tylerm-nv
Copy link
Contributor Author

tylerm-nv commented May 5, 2023

It could be fixed with a custom HdPrimvarDescriptor equality comparison exclusively used by the std::find in UsdImagingPrimAdapter::_MergePrimvar, is that an acceptable fix? The comparison for that function would be just name and role.

@tcauchois
Copy link
Contributor

Yeah, that sounds good. Although maybe we only want to check name? Unique name = unique primvar, and "interpolation" and "role" are just modifiers on how we access that information. Thanks!

@tcauchois
Copy link
Contributor

New version looks a lot better! On github it looks like the PR still has the sceneDelegate.h changes but I'm not sure if I'm just looking at the wrong thing.

Anyway, we'll pull this down and run it through the test suite and then we can merge it!

@tylerm-nv
Copy link
Contributor Author

Oops, I forgot to revert the original changes. Pushed a commit for that.

else
*it = primvar;

for (HdPrimvarDescriptorVector::iterator it = vec->begin();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you're open to the suggestion, I think you can preserve the existing structure and the usage of the STL with std::find_if.

Either way, it's great to see this fix!

@pixar-oss pixar-oss merged commit 566225c into PixarAnimationStudios:dev Jun 4, 2024
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.

5 participants