-
Notifications
You must be signed in to change notification settings - Fork 202
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
Lobe pruning shader optimization #4016
Lobe pruning shader optimization #4016
Conversation
Introduces the lobe pruning concept to MaterialX shaders generated by either MayaUSD or LookdevX. We look into shader graph implemnetation and find where we can cut the graph to simplify it based on the value of the main lobe attributes. This means a shader with a subsurface weight of zero will completely prune the evaluation of the subsurface, while a value of 1 will completely prune the evaluation of the dielectric base. This provides interesting performance values: ``` MayaUSD: Tumbling speed of a stage with a 11x11x11 set of cubes with a red OpenPBR shader initial optimized Default light 434fps 441fps Dome light 17fps 115fps LookdevX/MaterialX: Tumbling speed of a heavy geometry scene from MAYA-136105 using OpenPBR surface initial optimized Default light 192fps 476fps Dome light 7.6fps 65fps ``` Technical side: The code looks for nodes in the nodegraph implementation and checks any node that directly connects to the interface on a 0-1 slider: - Mix nodes: If the mix value if 0 or 1, forward the value/connection of the bg or fg port to the node directly upstream. Delete node. - Multiply nodes: If any value is zero, write zero to the corresponding port on the upstream node. Delete node. - PBR nodes: If the weight parameter is zero, substitute with a no-op PBR node. Delete node. This makes sure the ShaderGen works on a reduced codebase and greatly reduces code size and complexity by disconnecting unused subgraphs and skipping black PBR calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
I left a few comments, but they are mostly questions or very minor. Not sure if any of them are blocking. Please double check and make any changes you deem necessary. I'll approve after.
@@ -0,0 +1,606 @@ | |||
#include "LobePruner.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class can be copied to USD in HdStorm to allow the same optimizations for usdview or other Storm clients.
Requires the dark closure node as well in the USD shadergen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for the explanations!
class MAYAUSD_API_PUBLIC TopoNeutralGraph | ||
{ | ||
public: | ||
TopoNeutralGraph(const MaterialX::ElementPtr&); | ||
TopoNeutralGraph(const MaterialX::ElementPtr&, const LobePruner::Ptr& lobePruner); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JGamache-autodesk Can you confirm that adding this overload does not break binary compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm it does not break since it is not a virtual function.
* \return a string vector containing all paths to attibutes that were used to optimize nodes in | ||
* this graph. | ||
*/ | ||
const MaterialX::StringVec& getOptimizedAttributes() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Not virtual. And since the actual implementation is hidden underneath an Impl pointer, all changes to the core class are unexposed and non-breaking.
Introduces the lobe pruning concept to MaterialX shaders generated by either MayaUSD or LookdevX.
We look into shader graph implemnetation and find where we can cut the graph to simplify it based on the value of the main lobe attributes.
This means a shader with a subsurface weight of zero will completely prune the evaluation of the subsurface, while a value of 1 will completely prune the evaluation of the dielectric base.
This provides interesting performance values:
Technical side: The code looks for nodes in the nodegraph implementation and checks any node that directly connects to the interface on a 0-1 slider:
This makes sure the ShaderGen works on a reduced codebase and greatly reduces code size and complexity by disconnecting unused subgraphs and skipping black PBR calls.