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

Default transform<X> nodes can crash shader generation (GLSL) #1425

Closed
kwokcb opened this issue Jul 24, 2023 · 2 comments · Fixed by #1560
Closed

Default transform<X> nodes can crash shader generation (GLSL) #1425

kwokcb opened this issue Jul 24, 2023 · 2 comments · Fixed by #1560

Comments

@kwokcb
Copy link
Contributor

kwokcb commented Jul 24, 2023

Issue

There are no default "from" and "to" space values so they are left empty on creation.
If you try and generate code from them, then there are a few missing empty value checks missing and code gen can crash.

Setup

This is a simple example:

<?xml version="1.0"?>
<materialx version="1.38">
  <transformnormal name="transformnormal_vector3" type="vector3">
    <input name="in" type="vector3" value="0.0, 0.0, 1.0" />
    <input name="fromspace" type="string" value="" uniform="true" />
    <input name="tospace" type="string" value="" uniform="true" />
  </transformnormal>
  <convert name="shader_transformnormal_vector3_out" type="surfaceshader">
    <input name="in" type="vector3" nodename="transformnormal_vector3" />
  </convert>
  <surfacematerial name="material_transformnormal_vector3_out" type="material">
    <input name="surfaceshader" type="surfaceshader" nodename="shader_transformnormal_vector3_out" />
  </surfacematerial>
</materialx>

Initial Triage

Loading this in will crash the view and editor where only GLSL was tried out. The fix appears to be in TransformVectorNodeGLSL.cpp but didn't check other code generators, and it seems all of the "transform" nodes will need to be patched, so wondering if there is a higher level place ?

Proposed Fix

Add in firewall checks to see if there is a value and default to empty if none:

Secondary Proposal

Propose these nodes should have some reasonable default and be enumerations if it makes sense. Otherwise it's mostly
a guess as to what strings are required and documentation validation will fail if the string is incorrect.

@madmann91
Copy link
Contributor

Hello! I am going to work on this issue while the CLA agreement is being processed in my organization, if that's alright. I can suggest the following plan:

  • Group all the Msl/Glsl TransformXXXXNode into a parent HwTransformNode, and do most of the logic there (including the checks for whether the source or destination space are provided),
  • Make the individual TransformXXXXNodeGlsl/TransformNodeXXXXMsl inherit from that HwTransformNode.

Just like for the texcoord nodes, it seems there's a lot of code duplication in there, and functions mostly only differ by name, while their content is almost identical. Merging things this way would still open the door to further customization via virtual functions.

What do you think?

@kwokcb
Copy link
Contributor Author

kwokcb commented Oct 12, 2023

Hi @madmann91 ,

  • I would say that your secondary proposal should be done in any case as it makes no sense to leave them empty IMO. They should probably be enumerations as well so there is a set of available options to the user.
    • Note that implementations like OSL have inlined direct calls to intrinsic functions, so I'm not sure but guessing that these can handle empty strings properly and hence a possible reason to not have any defaults?
  • As for the firewall check, perhaps getMatrix() should have it's signature changed take an Input instead of 2 strings. Then the check for from/tospace can be done in one place there. You can add the inheritance if it's still useful.

madmann91 added a commit to madmann91/MaterialX that referenced this issue Oct 12, 2023
This merges the `TransformXXXNodeGlsl` and `TransformXXXNodeMsl` classes
into a `HwTransformNode` which has 3 subclasses,
`HwTransformVectorNode`, `HwTransformPointNode`, and
`HwTransformNormalNode`, all of which can be configured by overriding
the virtual methods of `HwTransformNode`.
madmann91 added a commit to madmann91/MaterialX that referenced this issue Oct 12, 2023
This merges the `TransformXXXNodeGlsl` and `TransformXXXNodeMsl` classes
into a `HwTransformNode` which has 3 subclasses,
`HwTransformVectorNode`, `HwTransformPointNode`, and
`HwTransformNormalNode`, all of which can be configured by overriding
the virtual methods of `HwTransformNode`.
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 a pull request may close this issue.

2 participants