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

Elide dot nodes to avoid local sampler creation #1152

Merged

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Nov 22, 2022

Fix

Implementation

  • Adds "dot" node classification which can be checked at optimization time to bypass.

Example

This will generate properly now

<?xml version="1.0"?>
<materialx version="1.38">
  <nodedef name="nd_px_mx_test" node="px_mx_test">
    <input name="SD_CustomTexture" type="filename" value="some/texture/path.dds" />
  <output name="Color" type="color3" />
  </nodedef>
  <nodegraph name="ng_px_mx_test" nodedef="nd_px_mx_test">
    <dot name="hlsl_Sampler2D_v2_274" type="filename">
      <input name="in" type="filename" interfacename="SD_CustomTexture" />
    </dot>
    <image name="hlsl_SampleTexture2_294" type="color3">
      <input name="file" type="filename" nodename="hlsl_Sampler2D_v2_274" />
      <output name="out" type="color3" />
    </image>
    <output name="Color" type="color3" nodename="hlsl_SampleTexture2_294" />
  </nodegraph>
  <px_mx_test name="n_px_mx_test" type="color3">
    <input name="SD_CustomTexture" type="filename" value="some/texture/path.dds" />
  </px_mx_test>
  <standard_surface name="n_standard_surface" type="surfaceshader">
    <input name="base_color" type="color3" nodename="n_px_mx_test" />
  </standard_surface>
  <surfacematerial name="m_px_mx_test" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="n_standard_surface" />
  </surfacematerial>
</materialx>

@kwokcb
Copy link
Contributor Author

kwokcb commented Nov 23, 2022

@niklasharrysson, I added in dot category recognition and add these nodes as part of the bypass logic since they are pass-through nodes. I didn't reuse constant categorization since it's checked in specific places for other logic branching.

@jstone-lucasfilm jstone-lucasfilm changed the title Optimize out "dot" nodes to avoid local sampler creation. Elide dot nodes to avoid local sampler creation Jan 6, 2023
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks @kwokcb!

@jstone-lucasfilm jstone-lucasfilm merged commit 9005e11 into AcademySoftwareFoundation:main Jan 14, 2023
jstone-lucasfilm added a commit that referenced this pull request Feb 18, 2023
This changelist fixes a bug in the elision of dot nodes (#1152), where dot nodes with channels attributes would be incorrectly bypassed, causing the shader generator to produce incorrect code.
@kwokcb kwokcb deleted the dot_optimization branch September 6, 2023 11:47
jstone-lucasfilm pushed a commit that referenced this pull request Sep 8, 2023
Dot nodes were elided in #1152 to prevent creating extra samplers in rasterized shadergen.

This preserves the change written by @kwokcb while keeping the distinction between a topological constant node and a non-topological dot node.

In scenarios where you want to feed a single color to multiple shader nodes in a complex material, using a constant node will force recompilation every time the color is tweaked, we want users to be able to use a dot node to feed the graph, which should allow tweaking the color without having to recompile the shader. Also allows re-using the shader code for material instances differing on this input color.
JGamache-autodesk added a commit to Autodesk/maya-usd that referenced this pull request Sep 11, 2023
The MaterialX topological node list was in need of an update:

For MaterialX 1.38.7:

"dot" nodes are now topological.
    Via AcademySoftwareFoundation/MaterialX#1152

For upcoming MaterialX 1.38.8:

"dot" node no longer elided (except for filenames)
"switch" node no longer elided
    Via AcademySoftwareFoundation/MaterialX#1522
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
…ation#1152)

A dot node is equivalent to a pass-through so bypass it during shader optimization. This fixes the issue of dot nodes
creating intermediate samplers within functions for GLSL which is disallowed.
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
This changelist fixes a bug in the elision of dot nodes (AcademySoftwareFoundation#1152), where dot nodes with channels attributes would be incorrectly bypassed, causing the shader generator to produce incorrect code.
Michaelredaa pushed a commit to Michaelredaa/MaterialX that referenced this pull request Oct 21, 2023
…tion#1522)

Dot nodes were elided in AcademySoftwareFoundation#1152 to prevent creating extra samplers in rasterized shadergen.

This preserves the change written by @kwokcb while keeping the distinction between a topological constant node and a non-topological dot node.

In scenarios where you want to feed a single color to multiple shader nodes in a complex material, using a constant node will force recompilation every time the color is tweaked, we want users to be able to use a dot node to feed the graph, which should allow tweaking the color without having to recompile the shader. Also allows re-using the shader code for material instances differing on this input color.
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.

2 participants