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

DYN-3896 Add support for geometry instancing in render pipeline #11914

Merged
merged 33 commits into from
May 18, 2022

Conversation

saintentropy
Copy link
Contributor

@saintentropy saintentropy commented Aug 5, 2021

Purpose

https://jira.autodesk.com/browse/DYN-3896

The purpose of this PR is to add geometry instancing support in the render pipeline for the 3D background preview. This work build on the PR where we modified the render pipeline to gather one RenderPackage per node. Instancing can be utilized to reduce tessellation overhead for symmetrical geometry types (cube, rectangle, sphere, circle, ellipse, cylinders, coordinate systems, and planes) as well as dramatically improve render time and memory usage required for the 3D Preview. Perf and memory testing will depend on the object type and size of tessellation data but an example of 30,000 spheres reduces the tessellation and render time from 23 to 2 sec and memory size of Dynamo from 5gig to 500 mb.

(500,000 Spheres)
Screen Shot 2021-08-01 at 6 24 12 PM

Specifically this PR adds to Dynamo:

  • Adds IInstanceableItem interface that follows the pattern of IGraphicItem where the interface is applied to object who can be rendered via instancing. The interface add a method to the object to define a base set of tessellation data and methods to set transformation matrices for any instance geometry. The transforms handle the transition, rotation, and scaling of the base tessellation data to the objects placement in 3D space
  • Adds IRenderInstances interface for extending RenderPackges to support storing base tessellation data and instance mtarices
  • Adds support the tessellation pass to gather instancing data if the object supports it before falling back to standard tessellation.
  • Adds support the HelixWatch3DViewModel to utilize the Helix instancing APIs to render geometry with associated instance matrices.

There will be an associated PR for LibG to utilize these new interfaces and new API's

Todo

  • discuss adding instance color setting optionally
  • update tests

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated

Reviewers

@aparajit-pratap @mjkkirschner

FYIs

@QilongTang @jasonstratton

@saintentropy saintentropy changed the title WIP DYN-3896 Add support for geometry instancing in render pipeline DYN-3896 Add support for geometry instancing in render pipeline Aug 19, 2021
@saintentropy saintentropy removed the WIP label Aug 23, 2021
Copy link
Member

@mjkkirschner mjkkirschner left a comment

Choose a reason for hiding this comment

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

I will need to continue reviewing this and the LibG changes - at the moment I don't yet understand the changes in the HelixWatch3dViewModel

src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
@mjkkirschner
Copy link
Member

mjkkirschner commented Nov 1, 2021

@saintentropy do you intend to add tests to cover your new functionality? For example a class that actually implements the new interfaces so this can be tested without LibG?

discussed with @saintentropy - I will work to add some tests for this repo for this functionality.

src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs Outdated Show resolved Hide resolved
src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs Outdated Show resolved Hide resolved
src/DynamoCore/Scheduler/UpdateRenderPackageAsyncTask.cs Outdated Show resolved Hide resolved
src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs Outdated Show resolved Hide resolved
src/DynamoCoreWpf/Rendering/HelixRenderPackage.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
/// <summary>
/// A flag used to indicate if the current geometrical configuration of an item has instance information.
/// </summary>
bool InstanceInfoAvailable { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

If something does not have instance information, it won't be an IInstanceableItem, right?

/// <param name="package">The render package, where graphics data to be
/// pushed.</param>
/// <param name="parameters"></param>
void AddBaseTessellation(IRenderPackage package, TessellationParameters parameters);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same q here.

src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
src/NodeServices/GraphicsDataInterfaces.cs Outdated Show resolved Hide resolved
@mjkkirschner
Copy link
Member

/// <returns></returns>
public bool ContainsTessellationId(Guid id)
{
return MeshVertexRangesAssociatedWithInstancing.ContainsKey(id) || LineVertexRangesAssociatedWithInstancing.ContainsKey(id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mjkkirschner Hmmmmm.... Not sure but we may need to handle a transform that has both mesh and line type tessellation data. Maybe when edges are on. I can't remember how that case was supported.

Copy link
Contributor Author

@saintentropy saintentropy May 17, 2022

Choose a reason for hiding this comment

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

It might be a bit of a hack but the LIbG portion could actually handle this ^^^ I think. I always wondered why we didn't handle the ShowEdges in the base tessellation call. Maybe puts too much ownership on those implementing IGraphicItem. In this case we are still internal so it may work to let the instanceableItem handle the data. In the case of a cube, AddBaseTessellation(instancingPackage, factory.TessellationParameters) could inspect the TessellationParameters and add only a mesh or a mesh and line data if edges are needed. They would have to have separate GUIDs. The subsequent call to AddInstance(instancingPackage, factory.TessellationParameters, labelKey) could also add the correct instance references fo either mesh only or mesh and line data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This may also be follow up task?

Copy link
Member

@mjkkirschner mjkkirschner May 17, 2022

Choose a reason for hiding this comment

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

⚠️ I'll take a quick look but ,if nothing obvious and simple I think I'll have to file a followup as the allotted time for this task is running out.

I wonder if we can just push the line data to the baseTessellation from this method:

if (factory.TessellationParameters.ShowEdges)

or always generate the edge data in baseTessellation but only using it (extracting it from the render package) if show edges is on.

For the current state of the PR, I think we need to decide the following:

  1. When show_edges is on, we don't use instancing OR -
  2. When show_edges is on, we use instancing but don't draw edges... OR
  3. When show_edges is on, we use instancing for the meshes, but push a bunch of non instanced edge data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be also...
4. Edges added within instancing implementation.

}

/// <summary>
/// A test class that creates a pyramid using instancing.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool :-)

add test that will fail until libG changes are merged
@@ -1276,6 +1276,28 @@ public void InstancedLinesAreAddedToBackGroundPreviewForEachMatrix()
Assert.AreEqual(6 * 6 * 6, BackgroundPreviewGeometry.TotalLineInstancesToRender());

}
[Test]
[Category("Failure")]
Copy link
Member

Choose a reason for hiding this comment

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

we can enable this after the LibG changes are merged, it will fail until then because the number of instances will be incorrect.

@saintentropy
Copy link
Contributor Author

Hey @mjkkirschner, the show edges implementation looks good. This PR LGTM

@mjkkirschner mjkkirschner merged commit 581b2ef into DynamoDS:master May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants