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

Ogs/selection #1831

Closed
Closed

Conversation

AdamFelt
Copy link

This submission adds deep selection capabilities to HdStorm. This allows for selection of all objects within a pick-point or frustum to be selected even if the objects are obscured by other objects drawn on top.

It uses a GPU rendering technique similar to ID based picking except that it accummulates all pick results into a one dimensional "pickBuffer" instead of storing a single selection per pixel like the ID buffer approach does.

It can be enabled by setting a new resolve mode defined as HdxPickTokens->resolveDeep.

A new helper function named TestIntersections (plural) has been added to UsdImagingGlEngine to exercise the new functionality. A new Unit test is included to test the new resolve mode and UsdImagingGLEngine helper function.

  • [x ] I have submitted a signed Contributor License Agreement

# Conflicts:
#	pxr/imaging/hdx/pickTask.cpp
#	pxr/imaging/hdx/pickTask.h
vlasovi and others added 6 commits April 7, 2022 11:04
Basic start to deep selection and rectangular selection in the Engine class.
Restore single pick functionality when picking, not rectangle selection
Fix merge conflicts
Drive deep selection through new methods on UsdImagingGLEngine
Add unit tests and baselines
…nto ogs/selection

# Conflicts:
#	pxr/imaging/hdx/pickTask.cpp
#	pxr/imaging/hdx/pickTask.h
@jilliene
Copy link

Filed as internal issue #USD-7330

@tcauchois
Copy link
Contributor

Hey all, we've finished looking at this internally and it looks good. I have some minor feedback on the code I'll post in a second, if you're up for addressing it.

We were wondering if, for the PR, you could squash the history a bit. Also, have you tried this on Metal at all?

@@ -56,6 +57,17 @@ PXR_NAMESPACE_OPEN_SCOPE

TF_DEFINE_PUBLIC_TOKENS(HdxPickTokens, HDX_PICK_TOKENS);

TF_DEFINE_PRIVATE_TOKENS(
HdxPickPrivateTokens,
Copy link
Contributor

Choose a reason for hiding this comment

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

Stylistic thing: we use "_tokens" to indicate private tokens.

(Picking)
);

static const int PICK_BUFFER_HEADER_SIZE = 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

A note indicating these are in units of "int" would be great!


// try to initialize the values and check if succeeded

primIdValue = atomicCompSwap(PickBuffer[primIdOffset], -9, primId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and elsewhere: this needs to be updated for metal support. See top-of-tree WriteOitLayersToBufferCommon, in this same file, for the layout section and the ATOMIC_EXCHANGE macro usage.

// add the item to the pick buffer, but only unique
#if defined(HD_HAS_PickBuffer)

// if the pick buffer is not initialized, we are done
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhere (here, pickTask.cpp, elsewhere?) it would be fantastic to have both a block comment about the buffer layout, and a block comment about the algorithm you're using to write the entry out, since they're both tricky to pick up from reading the code.

primId, instanceId, partId)) {
keepMoving = false;
}
else if(++entryNumber == subBufferCapacity) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not important, but if you move this into the while() condition, and make the "keepMoving" above a "break", it makes the loop code a bit smaller.

/// instancer (if applicable) of each gprim.
///
USDIMAGINGGL_API
bool TestIntersections(
Copy link
Contributor

Choose a reason for hiding this comment

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

We've been talking about a new TestIntersection API, unrelated to this change. If you want to do us a favor, if you call this "TestIntersection" and take a "const TfToken& resolveMode", and swap out the "const UsdPrim& root" for a "const SdfPathVector&" (like RenderBatch), we can call that the new intersection API, and I can mark the existing one as deprecated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also: if you can bump the version in usdImagingGL/version.h, that would be great.

bool res = lhsVector.size() == rhsVector.size();
if (!res) return false;

for (int i = 0; i < lhsVector.size(); ++i)
Copy link
Contributor

Choose a reason for hiding this comment

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

int -> size_t

params,
outResults)) {

for (int i = 0; i < outResults.size(); ++i)
Copy link
Contributor

Choose a reason for hiding this comment

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

int -> size_t

}

bool
compareOrSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed it before, but compareOrSet needs to be behind ifdef HD_HAS_PickBuffer as well.

@@ -238,6 +298,17 @@ My_TestGLDrawing::DrawTest(bool offscreen)
} else {
Draw();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Missed this before, but can you add an if (renderer == HdStormRendererPlugin) here? Or else add a command line flag to control whether we test deep selection.

@tcauchois
Copy link
Contributor

Adam: let me know if you need anything on this PR.

@erikaharrison-adsk
Copy link
Contributor

Feedback has been addressed in the new PR: #3044

@AdamFelt AdamFelt closed this Apr 16, 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.

None yet

5 participants