diff --git a/python/MaterialXTest/genshader.py b/python/MaterialXTest/genshader.py
index 0b541df24d..c5f669c422 100644
--- a/python/MaterialXTest/genshader.py
+++ b/python/MaterialXTest/genshader.py
@@ -54,6 +54,7 @@ def test_ShaderInterface(self):
self.assertTrue(foundTarget)
context = mx_gen_shader.GenContext(shadergen)
context.registerSourceCodeSearchPath(searchPath)
+ shadergen.registerTypeDefs(doc, context)
# Test generator with complete mode
context.getOptions().shaderInterfaceType = mx_gen_shader.ShaderInterfaceType.SHADER_INTERFACE_COMPLETE;
diff --git a/python/Scripts/generateshader.py b/python/Scripts/generateshader.py
index b00311eb2e..c40356db89 100644
--- a/python/Scripts/generateshader.py
+++ b/python/Scripts/generateshader.py
@@ -107,6 +107,7 @@ def main():
codeSearchPath.append(os.path.dirname(inputFilename))
context = mx_gen_shader.GenContext(shadergen)
context.registerSourceCodeSearchPath(codeSearchPath)
+ shadergen.registerTypeDefs(doc, context)
# If we're generating Vulkan-compliant GLSL then set the binding context
if opts.vulkanCompliantGlsl:
diff --git a/resources/Materials/TestSuite/stdlib/structs/struct_texcoord.mtlx b/resources/Materials/TestSuite/stdlib/structs/struct_texcoord.mtlx
new file mode 100644
index 0000000000..3b1c69832e
--- /dev/null
+++ b/resources/Materials/TestSuite/stdlib/structs/struct_texcoord.mtlx
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/Materials/TestSuite/stdlib/structs/struct_texcoordGroup.mtlx b/resources/Materials/TestSuite/stdlib/structs/struct_texcoordGroup.mtlx
new file mode 100644
index 0000000000..e86afa9c3d
--- /dev/null
+++ b/resources/Materials/TestSuite/stdlib/structs/struct_texcoordGroup.mtlx
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/source/JsMaterialX/JsMaterialXGenShader/JsTypeDesc.cpp b/source/JsMaterialX/JsMaterialXGenShader/JsTypeDesc.cpp
index 92e1c27b69..4b7bf55bb2 100644
--- a/source/JsMaterialX/JsMaterialXGenShader/JsTypeDesc.cpp
+++ b/source/JsMaterialX/JsMaterialXGenShader/JsTypeDesc.cpp
@@ -4,6 +4,7 @@
//
#include
+#include
#include
diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
index c648441c7e..2fc64ba7f1 100644
--- a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
+++ b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp
@@ -614,7 +614,7 @@ void GlslShaderGenerator::emitPixelStage(const ShaderGraph& graph, GenContext& c
else
{
string outputValue = outputSocket->getValue() ?
- _syntax->getValue(outputSocket->getType(), *outputSocket->getValue()) :
+ _syntax->getValue(outputSocket->getType(), *outputSocket->getValue(), context) :
_syntax->getDefaultValue(outputSocket->getType());
if (!outputSocket->getType().isFloat4())
{
@@ -689,7 +689,7 @@ void GlslShaderGenerator::toVec4(TypeDesc type, string& variable)
}
void GlslShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, const string& qualifier,
- GenContext&, ShaderStage& stage,
+ GenContext& context, ShaderStage& stage,
bool assignValue) const
{
// A file texture input needs special handling on GLSL
@@ -724,7 +724,7 @@ void GlslShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, co
if (assignValue)
{
const string valueStr = (variable->getValue() ?
- _syntax->getValue(variable->getType(), *variable->getValue(), true) :
+ _syntax->getValue(variable->getType(), *variable->getValue(), context, true) :
_syntax->getDefaultValue(variable->getType(), true));
str += valueStr.empty() ? EMPTY_STRING : " = " + valueStr;
}
@@ -756,7 +756,7 @@ ShaderNodeImplPtr GlslShaderGenerator::getImplementation(const NodeDef& nodedef,
throw ExceptionShaderGenError("NodeDef '" + nodedef.getName() + "' has no outputs defined");
}
- const TypeDesc outputType = TypeDesc::get(outputs[0]->getType());
+ const TypeDesc outputType = context.getTypeDesc(outputs[0]->getType());
if (implElement->isA())
{
diff --git a/source/MaterialXGenGlsl/GlslSyntax.cpp b/source/MaterialXGenGlsl/GlslSyntax.cpp
index 7054725b76..6768df51b6 100644
--- a/source/MaterialXGenGlsl/GlslSyntax.cpp
+++ b/source/MaterialXGenGlsl/GlslSyntax.cpp
@@ -5,6 +5,7 @@
#include
+#include
#include
MATERIALX_NAMESPACE_BEGIN
@@ -20,7 +21,7 @@ class GlslStringTypeSyntax : public StringTypeSyntax
GlslStringTypeSyntax() :
StringTypeSyntax("int", "0", "0") { }
- string getValue(const Value& /*value*/, bool /*uniform*/) const override
+ string getValue(const Value& /*value*/, const GenContext& /*context*/, bool /*uniform*/) const override
{
return "0";
}
@@ -34,7 +35,7 @@ class GlslArrayTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
size_t arraySize = getSize(value);
if (arraySize > 0)
@@ -388,7 +389,7 @@ StructTypeSyntaxPtr GlslSyntax::createStructSyntax(const string& structTypeName,
typeDefinition);
}
-string GlslStructTypeSyntax::getValue(const Value& value, bool /* uniform */) const
+string GlslStructTypeSyntax::getValue(const Value& value, const GenContext& context, bool /*uniform*/) const
{
const AggregateValue& aggValue = static_cast(value);
@@ -401,10 +402,10 @@ string GlslStructTypeSyntax::getValue(const Value& value, bool /* uniform */) co
separator = ",";
const string& memberTypeName = memberValue->getTypeString();
- TypeDesc memberTypeDesc = TypeDesc::get(memberTypeName);
+ TypeDesc memberTypeDesc = context.getTypeDesc(memberTypeName);
// Recursively use the syntax to generate the output, so we can supported nested structs.
- result += _parentSyntax->getValue(memberTypeDesc, *memberValue, true);
+ result += _parentSyntax->getValue(memberTypeDesc, *memberValue, context, true);
}
result += ")";
diff --git a/source/MaterialXGenGlsl/GlslSyntax.h b/source/MaterialXGenGlsl/GlslSyntax.h
index 1e82e354bd..d6874073be 100644
--- a/source/MaterialXGenGlsl/GlslSyntax.h
+++ b/source/MaterialXGenGlsl/GlslSyntax.h
@@ -58,7 +58,7 @@ class MX_GENGLSL_API GlslStructTypeSyntax : public StructTypeSyntax
public:
using StructTypeSyntax::StructTypeSyntax;
- string getValue(const Value& value, bool uniform) const override;
+ string getValue(const Value& value, const GenContext& context, bool uniform) const override;
};
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXGenGlsl/Nodes/LightCompoundNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/LightCompoundNodeGlsl.cpp
index 6f005766fd..ecfd2ac793 100644
--- a/source/MaterialXGenGlsl/Nodes/LightCompoundNodeGlsl.cpp
+++ b/source/MaterialXGenGlsl/Nodes/LightCompoundNodeGlsl.cpp
@@ -34,7 +34,7 @@ void LightCompoundNodeGlsl::initialize(const InterfaceElement& element, GenConte
NodeDefPtr nodeDef = graph.getNodeDef();
for (InputPtr input : nodeDef->getActiveInputs())
{
- _lightUniforms.add(TypeDesc::get(input->getType()), input->getName());
+ _lightUniforms.add(context.getTypeDesc(input->getType()), input->getName());
}
}
diff --git a/source/MaterialXGenGlsl/Nodes/LightShaderNodeGlsl.cpp b/source/MaterialXGenGlsl/Nodes/LightShaderNodeGlsl.cpp
index c7b4df2bb6..e79a5d39bf 100644
--- a/source/MaterialXGenGlsl/Nodes/LightShaderNodeGlsl.cpp
+++ b/source/MaterialXGenGlsl/Nodes/LightShaderNodeGlsl.cpp
@@ -44,7 +44,7 @@ void LightShaderNodeGlsl::initialize(const InterfaceElement& element, GenContext
NodeDefPtr nodeDef = impl.getNodeDef();
for (InputPtr input : nodeDef->getActiveInputs())
{
- _lightUniforms.add(TypeDesc::get(input->getType()), input->getName(), input->getValue());
+ _lightUniforms.add(context.getTypeDesc(input->getType()), input->getName(), input->getValue());
}
}
diff --git a/source/MaterialXGenMdl/MdlShaderGenerator.cpp b/source/MaterialXGenMdl/MdlShaderGenerator.cpp
index 71db0d7cf4..97041f9702 100644
--- a/source/MaterialXGenMdl/MdlShaderGenerator.cpp
+++ b/source/MaterialXGenMdl/MdlShaderGenerator.cpp
@@ -176,7 +176,7 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
emitScopeBegin(stage, Syntax::PARENTHESES);
// Emit shader inputs
- emitShaderInputs(element->getDocument(), stage.getInputBlock(MDL::INPUTS), stage);
+ emitShaderInputs(element->getDocument(), stage.getInputBlock(MDL::INPUTS), context, stage);
// End shader signature
emitScopeEnd(stage);
@@ -333,7 +333,7 @@ ShaderNodeImplPtr MdlShaderGenerator::getImplementation(const NodeDef& nodedef,
throw ExceptionShaderGenError("NodeDef '" + nodedef.getName() + "' has no outputs defined");
}
- const TypeDesc outputType = TypeDesc::get(outputs[0]->getType());
+ const TypeDesc outputType = context.getTypeDesc(outputs[0]->getType());
if (implElement->isA())
{
@@ -658,7 +658,7 @@ void emitInputAnnotations(const MdlShaderGenerator& _this, const DocumentPtr doc
} // anonymous namespace
-void MdlShaderGenerator::emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, ShaderStage& stage) const
+void MdlShaderGenerator::emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, const GenContext& context, ShaderStage& stage) const
{
const string uniformPrefix = _syntax->getUniformQualifier() + " ";
for (size_t i = 0; i < inputs.size(); ++i)
@@ -668,7 +668,7 @@ void MdlShaderGenerator::emitShaderInputs(const DocumentPtr doc, const VariableB
const string& qualifier = input->isUniform() || input->getType() == Type::FILENAME ? uniformPrefix : EMPTY_STRING;
const string& type = _syntax->getTypeName(input->getType());
- string value = input->getValue() ? _syntax->getValue(input->getType(), *input->getValue(), true) : EMPTY_STRING;
+ string value = input->getValue() ? _syntax->getValue(input->getType(), *input->getValue(), context, true) : EMPTY_STRING;
const string& geomprop = input->getGeomProp();
if (!geomprop.empty())
{
@@ -753,6 +753,19 @@ void MdlShaderGenerator::emitMdlVersionFilenameSuffix(GenContext& context, Shade
emitString(getMdlVersionFilenameSuffix(context), stage);
}
+void MdlShaderGenerator::registerBuiltinTypes(GenContext& context)
+{
+ ShaderGenerator::registerBuiltinTypes(context);
+
+ // Custom types to handle enumeration output
+ context.registerTypeDesc(Type::MDL_COORDINATESPACE);
+ context.registerTypeDesc(Type::MDL_ADDRESSMODE);
+ context.registerTypeDesc(Type::MDL_FILTERLOOKUPMODE);
+ context.registerTypeDesc(Type::MDL_FILTERTYPE);
+ context.registerTypeDesc(Type::MDL_DISTRIBUTIONTYPE);
+ context.registerTypeDesc(Type::MDL_SCATTER_MODE);
+}
+
namespace MDL
{
// Identifiers for MDL variable blocks
diff --git a/source/MaterialXGenMdl/MdlShaderGenerator.h b/source/MaterialXGenMdl/MdlShaderGenerator.h
index ef88fbc453..090aa81c46 100644
--- a/source/MaterialXGenMdl/MdlShaderGenerator.h
+++ b/source/MaterialXGenMdl/MdlShaderGenerator.h
@@ -90,12 +90,14 @@ class MX_GENMDL_API MdlShaderGenerator : public ShaderGenerator
/// Get the version number suffix appended to MDL modules that use versions.
const string& getMdlVersionFilenameSuffix(GenContext& context) const;
+ void registerBuiltinTypes(GenContext& context) override;
+
protected:
// Create and initialize a new MDL shader for shader generation.
ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
// Emit a block of shader inputs.
- void emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, ShaderStage& stage) const;
+ void emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, const GenContext& context, ShaderStage& stage) const;
};
namespace MDL
diff --git a/source/MaterialXGenMdl/MdlSyntax.cpp b/source/MaterialXGenMdl/MdlSyntax.cpp
index 0244a8352f..1369abf129 100644
--- a/source/MaterialXGenMdl/MdlSyntax.cpp
+++ b/source/MaterialXGenMdl/MdlSyntax.cpp
@@ -13,19 +13,6 @@
MATERIALX_NAMESPACE_BEGIN
-// Custom types to handle enumeration output
-namespace Type
-{
-
-TYPEDESC_REGISTER_TYPE(MDL_COORDINATESPACE, "coordinatespace")
-TYPEDESC_REGISTER_TYPE(MDL_ADDRESSMODE, "addressmode")
-TYPEDESC_REGISTER_TYPE(MDL_FILTERLOOKUPMODE, "filterlookup")
-TYPEDESC_REGISTER_TYPE(MDL_FILTERTYPE, "filtertype")
-TYPEDESC_REGISTER_TYPE(MDL_DISTRIBUTIONTYPE, "distributiontype")
-TYPEDESC_REGISTER_TYPE(MDL_SCATTER_MODE, "scatter_mode")
-
-} // namespace Type
-
namespace
{
@@ -37,7 +24,7 @@ class MdlFilenameTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
const string outputValue = value.getValueString();
if (outputValue.empty() || outputValue == "/")
@@ -84,7 +71,7 @@ class MdlArrayTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
if (!isEmpty(value))
{
@@ -145,7 +132,7 @@ class MdlColor4TypeSyntax : public AggregateTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
StringStream ss;
@@ -171,7 +158,7 @@ class MdlEnumSyntax : public AggregateTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
return _name + "_" + value.getValueString();
}
diff --git a/source/MaterialXGenMdl/Nodes/BlurNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/BlurNodeMdl.cpp
index ae10ca3fa8..31dad20f7a 100644
--- a/source/MaterialXGenMdl/Nodes/BlurNodeMdl.cpp
+++ b/source/MaterialXGenMdl/Nodes/BlurNodeMdl.cpp
@@ -153,7 +153,7 @@ void BlurNodeMdl::emitFunctionCall(const ShaderNode& node, GenContext& context,
string emitValue = "\"" + GAUSSIAN_FILTER + "\"";
if (syntax.remapEnumeration(GAUSSIAN_FILTER, Type::STRING, FILTER_LIST, result))
{
- emitValue = syntax.getValue(result.first, *(result.second));
+ emitValue = syntax.getValue(result.first, *(result.second), context);
}
shadergen.emitString(" == " + emitValue + " ? ", stage);
{
diff --git a/source/MaterialXGenMdl/Nodes/ClosureLayerNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/ClosureLayerNodeMdl.cpp
index 5b187f80aa..d49f9f573f 100644
--- a/source/MaterialXGenMdl/Nodes/ClosureLayerNodeMdl.cpp
+++ b/source/MaterialXGenMdl/Nodes/ClosureLayerNodeMdl.cpp
@@ -197,7 +197,7 @@ ShaderNodeImplPtr LayerableNodeMdl::create()
return std::make_shared();
}
-void LayerableNodeMdl::addInputs(ShaderNode& node, GenContext& /*context*/) const
+void LayerableNodeMdl::addInputs(ShaderNode& node, GenContext&) const
{
// Add the input to hold base layer BSDF.
node.addInput(StringConstantsMdl::BASE, Type::BSDF);
diff --git a/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp b/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp
index 80c449e507..f981090d2b 100644
--- a/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp
+++ b/source/MaterialXGenMdl/Nodes/CompoundNodeMdl.cpp
@@ -236,7 +236,7 @@ void CompoundNodeMdl::emitFunctionSignature(const ShaderNode&, GenContext& conte
const string& qualifier = input->isUniform() || input->getType() == Type::FILENAME ? uniformPrefix : EMPTY_STRING;
const string& type = syntax.getTypeName(input->getType());
- string value = input->getValue() ? syntax.getValue(input->getType(), *input->getValue(), true) : EMPTY_STRING;
+ string value = input->getValue() ? syntax.getValue(input->getType(), *input->getValue(), context, true) : EMPTY_STRING;
const string& geomprop = input->getGeomProp();
if (!geomprop.empty())
{
diff --git a/source/MaterialXGenMsl/MslShaderGenerator.cpp b/source/MaterialXGenMsl/MslShaderGenerator.cpp
index 9511fac7ba..b206b480ed 100644
--- a/source/MaterialXGenMsl/MslShaderGenerator.cpp
+++ b/source/MaterialXGenMsl/MslShaderGenerator.cpp
@@ -1094,7 +1094,7 @@ void MslShaderGenerator::emitPixelStage(const ShaderGraph& graph, GenContext& co
else
{
string outputValue = outputSocket->getValue() ?
- _syntax->getValue(outputSocket->getType(), *outputSocket->getValue()) :
+ _syntax->getValue(outputSocket->getType(), *outputSocket->getValue(), context) :
_syntax->getDefaultValue(outputSocket->getType());
if (!outputSocket->getType().isFloat4())
{
@@ -1201,7 +1201,7 @@ void MslShaderGenerator::toVec4(TypeDesc type, string& variable)
}
void MslShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, const string& qualifier,
- GenContext&, ShaderStage& stage,
+ GenContext& context, ShaderStage& stage,
bool assignValue) const
{
// A file texture input needs special handling on MSL
@@ -1238,7 +1238,7 @@ void MslShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, con
if (assignValue)
{
const string valueStr = (variable->getValue() ?
- _syntax->getValue(variable->getType(), *variable->getValue(), true) :
+ _syntax->getValue(variable->getType(), *variable->getValue(), context, true) :
_syntax->getDefaultValue(variable->getType(), true));
str += valueStr.empty() ? EMPTY_STRING : " = " + valueStr;
}
@@ -1270,7 +1270,7 @@ ShaderNodeImplPtr MslShaderGenerator::getImplementation(const NodeDef& nodedef,
throw ExceptionShaderGenError("NodeDef '" + nodedef.getName() + "' has no outputs defined");
}
- const TypeDesc outputType = TypeDesc::get(outputs[0]->getType());
+ const TypeDesc outputType = context.getTypeDesc(outputs[0]->getType());
if (implElement->isA())
{
diff --git a/source/MaterialXGenMsl/MslSyntax.cpp b/source/MaterialXGenMsl/MslSyntax.cpp
index 30f44c5d1c..ed7800912a 100644
--- a/source/MaterialXGenMsl/MslSyntax.cpp
+++ b/source/MaterialXGenMsl/MslSyntax.cpp
@@ -20,7 +20,7 @@ class MslStringTypeSyntax : public StringTypeSyntax
MslStringTypeSyntax() :
StringTypeSyntax("int", "0", "0") { }
- string getValue(const Value& /*value*/, bool /*uniform*/) const override
+ string getValue(const Value& /*value*/, const GenContext& /*context*/, bool /*uniform*/) const override
{
return "0";
}
@@ -34,7 +34,7 @@ class MslArrayTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
size_t arraySize = getSize(value);
if (arraySize > 0)
diff --git a/source/MaterialXGenMsl/Nodes/LightCompoundNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/LightCompoundNodeMsl.cpp
index 1e5bd787a8..e801b543c2 100644
--- a/source/MaterialXGenMsl/Nodes/LightCompoundNodeMsl.cpp
+++ b/source/MaterialXGenMsl/Nodes/LightCompoundNodeMsl.cpp
@@ -34,7 +34,7 @@ void LightCompoundNodeMsl::initialize(const InterfaceElement& element, GenContex
NodeDefPtr nodeDef = graph.getNodeDef();
for (InputPtr input : nodeDef->getActiveInputs())
{
- _lightUniforms.add(TypeDesc::get(input->getType()), input->getName());
+ _lightUniforms.add(context.getTypeDesc(input->getType()), input->getName());
}
}
diff --git a/source/MaterialXGenMsl/Nodes/LightShaderNodeMsl.cpp b/source/MaterialXGenMsl/Nodes/LightShaderNodeMsl.cpp
index b556415dae..0ccf1cd349 100644
--- a/source/MaterialXGenMsl/Nodes/LightShaderNodeMsl.cpp
+++ b/source/MaterialXGenMsl/Nodes/LightShaderNodeMsl.cpp
@@ -44,7 +44,7 @@ void LightShaderNodeMsl::initialize(const InterfaceElement& element, GenContext&
NodeDefPtr nodeDef = impl.getNodeDef();
for (InputPtr input : nodeDef->getActiveInputs())
{
- _lightUniforms.add(TypeDesc::get(input->getType()), input->getName(), input->getValue());
+ _lightUniforms.add(context.getTypeDesc(input->getType()), input->getName(), input->getValue());
}
}
diff --git a/source/MaterialXGenOsl/OslShaderGenerator.cpp b/source/MaterialXGenOsl/OslShaderGenerator.cpp
index ff8cad36f5..08e59a1e37 100644
--- a/source/MaterialXGenOsl/OslShaderGenerator.cpp
+++ b/source/MaterialXGenOsl/OslShaderGenerator.cpp
@@ -123,7 +123,7 @@ ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, G
const ShaderMetadata& data = metadata->at(j);
const string& delim = (j == metadata->size() - 1) ? EMPTY_STRING : Syntax::COMMA;
const string& dataType = _syntax->getTypeName(data.type);
- const string dataValue = _syntax->getValue(data.type, *data.value, true);
+ const string dataValue = _syntax->getValue(data.type, *data.value, context, true);
emitLine(dataType + " " + data.name + " = " + dataValue + delim, stage, false);
}
}
@@ -133,8 +133,8 @@ ShaderPtr OslShaderGenerator::generate(const string& name, ElementPtr element, G
emitScopeBegin(stage, Syntax::PARENTHESES);
// Emit shader inputs
- emitShaderInputs(stage.getInputBlock(OSL::INPUTS), stage);
- emitShaderInputs(stage.getUniformBlock(OSL::UNIFORMS), stage);
+ emitShaderInputs(stage.getInputBlock(OSL::INPUTS), context, stage);
+ emitShaderInputs(stage.getUniformBlock(OSL::UNIFORMS), context, stage);
// Emit shader output
const VariableBlock& outputs = stage.getOutputBlock(OSL::OUTPUTS);
@@ -372,7 +372,7 @@ void OslShaderGenerator::emitLibraryIncludes(ShaderStage& stage, GenContext& con
emitLineBreak(stage);
}
-void OslShaderGenerator::emitShaderInputs(const VariableBlock& inputs, ShaderStage& stage) const
+void OslShaderGenerator::emitShaderInputs(const VariableBlock& inputs, const GenContext& context, ShaderStage& stage) const
{
static const std::unordered_map GEOMPROP_DEFINITIONS =
{
@@ -407,7 +407,7 @@ void OslShaderGenerator::emitShaderInputs(const VariableBlock& inputs, ShaderSta
// Add the file string input
emitLineBegin(stage);
emitString("string " + input->getVariable() + " = \"" + valueStr + "\"", stage);
- emitMetadata(input, stage);
+ emitMetadata(input, context, stage);
emitString(",", stage);
emitLineEnd(stage, false);
@@ -424,7 +424,7 @@ void OslShaderGenerator::emitShaderInputs(const VariableBlock& inputs, ShaderSta
emitLineBegin(stage);
emitString(type + " " + input->getVariable(), stage);
- string value = _syntax->getValue(input, true);
+ string value = _syntax->getValue(input, context, true);
const string& geomprop = input->getGeomProp();
if (!geomprop.empty())
{
@@ -440,7 +440,7 @@ void OslShaderGenerator::emitShaderInputs(const VariableBlock& inputs, ShaderSta
}
emitString(" = " + value, stage);
- emitMetadata(input, stage);
+ emitMetadata(input, context, stage);
}
if (i < inputs.size())
@@ -465,7 +465,7 @@ void OslShaderGenerator::emitShaderOutputs(const VariableBlock& outputs, ShaderS
}
}
-void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage) const
+void OslShaderGenerator::emitMetadata(const ShaderPort* port, const GenContext& context, ShaderStage& stage) const
{
static const std::unordered_map UI_WIDGET_METADATA =
{
@@ -500,7 +500,7 @@ void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage
{
const string& delim = (widgetMetadata || j < metadata->size() - 1) ? Syntax::COMMA : EMPTY_STRING;
const string& dataType = _syntax->getTypeName(data.type);
- const string dataValue = _syntax->getValue(data.type, *data.value, true);
+ const string dataValue = _syntax->getValue(data.type, *data.value, context, true);
metadataLines.push_back(dataType + " " + data.name + " = " + dataValue + delim);
}
}
@@ -508,7 +508,7 @@ void OslShaderGenerator::emitMetadata(const ShaderPort* port, ShaderStage& stage
if (widgetMetadata)
{
const string& dataType = _syntax->getTypeName(widgetMetadata->type);
- const string dataValue = _syntax->getValue(widgetMetadata->type, *widgetMetadata->value, true);
+ const string dataValue = _syntax->getValue(widgetMetadata->type, *widgetMetadata->value, context, true);
metadataLines.push_back(dataType + " " + widgetMetadata->name + " = " + dataValue);
}
if (metadataLines.size())
diff --git a/source/MaterialXGenOsl/OslShaderGenerator.h b/source/MaterialXGenOsl/OslShaderGenerator.h
index e5cf13977e..95bda2dd8c 100644
--- a/source/MaterialXGenOsl/OslShaderGenerator.h
+++ b/source/MaterialXGenOsl/OslShaderGenerator.h
@@ -55,13 +55,13 @@ class MX_GENOSL_API OslShaderGenerator : public ShaderGenerator
virtual void emitLibraryIncludes(ShaderStage& stage, GenContext& context) const;
/// Emit a block of shader inputs.
- virtual void emitShaderInputs(const VariableBlock& inputs, ShaderStage& stage) const;
+ virtual void emitShaderInputs(const VariableBlock& inputs, const GenContext& context, ShaderStage& stage) const;
/// Emit a block of shader outputs.
virtual void emitShaderOutputs(const VariableBlock& inputs, ShaderStage& stage) const;
/// Emit metadata for a shader parameter.
- virtual void emitMetadata(const ShaderPort* port, ShaderStage& stage) const;
+ virtual void emitMetadata(const ShaderPort* port, const GenContext& context, ShaderStage& stage) const;
};
namespace OSL
diff --git a/source/MaterialXGenOsl/OslSyntax.cpp b/source/MaterialXGenOsl/OslSyntax.cpp
index a85821c4fd..75a6da9707 100644
--- a/source/MaterialXGenOsl/OslSyntax.cpp
+++ b/source/MaterialXGenOsl/OslSyntax.cpp
@@ -22,7 +22,7 @@ class OslBooleanTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
return value.asA() ? "1" : "0";
}
@@ -36,7 +36,7 @@ class OslArrayTypeSyntax : public ScalarTypeSyntax
{
}
- string getValue(const Value& value, bool uniform) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool uniform) const override
{
if (!isEmpty(value))
{
@@ -98,7 +98,7 @@ class OslStructTypeSyntax : public AggregateTypeSyntax
{
}
- string getValue(const Value& value, bool uniform) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool uniform) const override
{
if (uniform)
{
@@ -126,7 +126,7 @@ class OslColor4TypeSyntax : public OslStructTypeSyntax
{
}
- string getValue(const Value& value, bool uniform) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool uniform) const override
{
StringStream ss;
@@ -162,7 +162,7 @@ class OSLMatrix3TypeSyntax : public AggregateTypeSyntax
{
}
- string getValue(const Value& value, bool /*uniform*/) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool /*uniform*/) const override
{
StringVec values = splitString(value.getValueString(), ",");
if (values.empty())
@@ -200,7 +200,7 @@ class OSLFilenameTypeSyntax : public AggregateTypeSyntax
{
}
- string getValue(const ShaderPort* port, bool uniform) const override
+ string getValue(const ShaderPort* port, const GenContext& /*context*/, bool uniform) const override
{
if (!port)
{
@@ -213,7 +213,7 @@ class OSLFilenameTypeSyntax : public AggregateTypeSyntax
return prefix + "\"" + filename + "\", \"" + port->getColorSpace() + "\"" + suffix;
}
- string getValue(const Value& value, bool uniform) const override
+ string getValue(const Value& value, const GenContext& /*context*/, bool uniform) const override
{
const string prefix = uniform ? "{" : getName() + "(";
const string suffix = uniform ? "}" : ")";
diff --git a/source/MaterialXGenShader/GenContext.cpp b/source/MaterialXGenShader/GenContext.cpp
index b197246d8c..3e323c9208 100644
--- a/source/MaterialXGenShader/GenContext.cpp
+++ b/source/MaterialXGenShader/GenContext.cpp
@@ -109,6 +109,63 @@ void GenContext::getOutputSuffix(const ShaderOutput* output, string& suffix) con
}
}
+//
+// TypeDesc storage methods
+//
+
+void GenContext::registerTypeDefs(const DocumentPtr doc)
+{
+ getShaderGenerator().registerTypeDefs(doc, *this);
+}
+
+void GenContext::registerTypeDesc(TypeDesc typeDesc)
+{
+ const string& name = typeDesc.getName();
+ _typeDescMap[name] = typeDesc;
+
+ // TODO - decide if we need to make this more threadsafe
+ // typeID is just a hash of the string value - so while
+ // we might set this entry multiple times - it's always going to be
+ // the same value...
+ // TODO - consider using OIIO::ustring?
+
+ // TODO - decide what it means to re-register the same type over again.
+ // We could...
+ // 1) Just blindly register this type on top of the existing type name.
+ // 2) Ignore any types where the names are already registered
+ // 3) When a type is re-registered we could go compare the existing registered type against the
+ // new candidate type, and raise an error if they differ.
+
+ // It's important to record the order of the struct types and register their syntax entries in the order
+ // they were added (this is reflected in the struct index). This ensures that any struct
+ // types used for members of another struct are declared in the correct order in the
+ // generated shader code.
+ if (typeDesc.isStruct())
+ {
+ _structTypeDescOrder.emplace_back(name);
+ }
+}
+
+void GenContext::registerTypeDesc(const string& name, uint8_t basetype, uint8_t semantic, uint8_t size, ConstStructMemberDescVecPtr structMembers)
+{
+ ConstStringPtr typeNamePtr = std::make_shared(name);
+ _typeDescNameStorage.push_back(typeNamePtr);
+
+ const TypeDesc typeDesc(typeNamePtr.get(), basetype, semantic, size, structMembers);
+ registerTypeDesc(typeDesc);
+}
+
+TypeDesc GenContext::getTypeDesc(const string& name) const
+{
+ auto it = _typeDescMap.find(name);
+ return it != _typeDescMap.end() ? it->second : Type::NONE;
+}
+
+const vector& GenContext::getStructTypeDescNames() const
+{
+ return _structTypeDescOrder;
+}
+
ScopedSetClosureParams::ScopedSetClosureParams(const ClosureContext::ClosureParams* params, const ShaderNode* node, ClosureContext* cct) :
_cct(cct),
_node(node),
diff --git a/source/MaterialXGenShader/GenContext.h b/source/MaterialXGenShader/GenContext.h
index 0f565ded6e..45426fdaa6 100644
--- a/source/MaterialXGenShader/GenContext.h
+++ b/source/MaterialXGenShader/GenContext.h
@@ -21,6 +21,9 @@ MATERIALX_NAMESPACE_BEGIN
class ClosureContext;
+class Document;
+using DocumentPtr = shared_ptr;
+
/// A standard function to allow for handling of application variables for a given node
using ApplicationVariableHandler = std::function;
@@ -220,6 +223,24 @@ class MX_GENSHADER_API GenContext
return _applicationVariableHandler;
}
+ //
+ // TypeDesc methods
+ //
+
+ void registerTypeDefs(const DocumentPtr doc);
+
+ /// Register an existing TypeDesc for this context.
+ void registerTypeDesc(TypeDesc typeDesc);
+
+ /// Create and register a new TypeDesc with the given configuration.
+ void registerTypeDesc(const string& name, uint8_t basetype, uint8_t semantic = TypeDesc::SEMANTIC_NONE, uint8_t size = 1, ConstStructMemberDescVecPtr structMembers = nullptr);
+
+ /// Return a TypeDesc for the given type name.
+ /// The TypeDesc must be registered in the context first.
+ TypeDesc getTypeDesc(const string& name) const;
+
+ const StringVec& getStructTypeDescNames() const;
+
protected:
GenContext() = delete;
@@ -237,6 +258,22 @@ class MX_GENSHADER_API GenContext
vector _parentNodes;
ApplicationVariableHandler _applicationVariableHandler;
+
+ private:
+ // Internal storage of registered type descriptors
+ using TypeDescMap = std::unordered_map;
+ TypeDescMap _typeDescMap;
+
+ // Internal storage of name strings for type descriptors
+ // that are created by this context.
+ using ConstStringPtr = std::shared_ptr;
+ vector _typeDescNameStorage;
+
+ // It's important to record the order of the struct types and register their syntax entries in the order
+ // they were added (this is reflected in the struct index). This ensures that any struct
+ // types used for members of another struct are declared in the correct order in the
+ // generated shader code.
+ StringVec _structTypeDescOrder;
};
/// @class ClosureContext
diff --git a/source/MaterialXGenShader/HwShaderGenerator.cpp b/source/MaterialXGenShader/HwShaderGenerator.cpp
index 20f91d6985..b32a28755f 100644
--- a/source/MaterialXGenShader/HwShaderGenerator.cpp
+++ b/source/MaterialXGenShader/HwShaderGenerator.cpp
@@ -544,7 +544,7 @@ void HwShaderGenerator::emitFunctionCall(const ShaderNode& node, GenContext& con
void HwShaderGenerator::bindLightShader(const NodeDef& nodeDef, unsigned int lightTypeId, GenContext& context)
{
- if (TypeDesc::get(nodeDef.getType()) != Type::LIGHTSHADER)
+ if (context.getTypeDesc(nodeDef.getType()) != Type::LIGHTSHADER)
{
throw ExceptionShaderGenError("Error binding light shader. Given nodedef '" + nodeDef.getName() + "' is not of lightshader type");
}
diff --git a/source/MaterialXGenShader/Nodes/BlurNode.cpp b/source/MaterialXGenShader/Nodes/BlurNode.cpp
index 5826370fd0..61d61ea27f 100644
--- a/source/MaterialXGenShader/Nodes/BlurNode.cpp
+++ b/source/MaterialXGenShader/Nodes/BlurNode.cpp
@@ -167,7 +167,7 @@ void BlurNode::emitFunctionCall(const ShaderNode& node, GenContext& context, Sha
string emitValue = "\"" + GAUSSIAN_FILTER + "\"";
if (syntax.remapEnumeration(GAUSSIAN_FILTER, Type::STRING, FILTER_LIST, result))
{
- emitValue = syntax.getValue(result.first, *(result.second));
+ emitValue = syntax.getValue(result.first, *(result.second), context);
}
shadergen.emitString(" == " + emitValue + ")", stage);
shadergen.emitLineEnd(stage, false);
diff --git a/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp b/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp
index 936edf9b46..eb0e87264d 100644
--- a/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp
+++ b/source/MaterialXGenShader/Nodes/SourceCodeNode.cpp
@@ -136,7 +136,7 @@ void SourceCodeNode::emitFunctionCall(const ShaderNode& node, GenContext& contex
ShaderPort v(nullptr, input->getType(), variableName, input->getValue());
shadergen.emitLineBegin(stage);
const Syntax& syntax = shadergen.getSyntax();
- const string valueStr = (v.getValue() ? syntax.getValue(v.getType(), *v.getValue()) : syntax.getDefaultValue(v.getType()));
+ const string valueStr = (v.getValue() ? syntax.getValue(v.getType(), *v.getValue(), context) : syntax.getDefaultValue(v.getType()));
const string& qualifier = syntax.getConstantQualifier();
string str = qualifier.empty() ? EMPTY_STRING : qualifier + " ";
str += syntax.getTypeName(v.getType()) + " " + v.getVariable();
diff --git a/source/MaterialXGenShader/ShaderGenerator.cpp b/source/MaterialXGenShader/ShaderGenerator.cpp
index 398232bf39..b078372cfb 100644
--- a/source/MaterialXGenShader/ShaderGenerator.cpp
+++ b/source/MaterialXGenShader/ShaderGenerator.cpp
@@ -164,7 +164,7 @@ void ShaderGenerator::emitTypeDefinitions(GenContext&, ShaderStage& stage) const
}
void ShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, const string& qualifier,
- GenContext&, ShaderStage& stage,
+ GenContext& context, ShaderStage& stage,
bool assignValue) const
{
string str = qualifier.empty() ? EMPTY_STRING : qualifier + " ";
@@ -187,7 +187,7 @@ void ShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, const
if (assignValue)
{
const string valueStr = (variable->getValue() ?
- _syntax->getValue(variable->getType(), *variable->getValue(), true) :
+ _syntax->getValue(variable->getType(), *variable->getValue(), context, true) :
_syntax->getDefaultValue(variable->getType(), true));
str += valueStr.empty() ? EMPTY_STRING : " = " + valueStr;
}
@@ -243,7 +243,7 @@ string ShaderGenerator::getUpstreamResult(const ShaderInput* input, GenContext&
{
if (!input->getConnection())
{
- return input->getValue() ? _syntax->getValue(input->getType(), *input->getValue()) : _syntax->getDefaultValue(input->getType());
+ return input->getValue() ? _syntax->getValue(input->getType(), *input->getValue(), context) : _syntax->getDefaultValue(input->getType());
}
string variable = input->getConnection()->getVariable();
@@ -300,7 +300,7 @@ ShaderNodeImplPtr ShaderGenerator::getImplementation(const NodeDef& nodedef, Gen
throw ExceptionShaderGenError("NodeDef '" + nodedef.getName() + "' has no outputs defined");
}
- const TypeDesc outputType = TypeDesc::get(outputs[0]->getType());
+ const TypeDesc outputType = context.getTypeDesc(outputs[0]->getType());
if (implElement->isA())
{
@@ -344,8 +344,48 @@ ShaderNodeImplPtr ShaderGenerator::getImplementation(const NodeDef& nodedef, Gen
return impl;
}
+void ShaderGenerator::registerTypeDefs(const DocumentPtr& doc, GenContext& context)
+{
+ registerBuiltinTypes(context);
+ registerStructTypeDefs(doc, context);
+}
+
+void ShaderGenerator::registerBuiltinTypes(GenContext& context)
+{
+ // TODO - revisit this once this is merged and make this list of types
+ // dynamically loaded from what is present in the document - making MaterialX
+ // more data driven. Initially this can just be a name matching against the
+ // in the document against the TypeDesc object in Type::, later
+ // we may consider fully specifying the type in the
+
+ // Register type descriptors for standard types.
+ context.registerTypeDesc(Type::NONE);
+ context.registerTypeDesc(Type::BOOLEAN);
+ context.registerTypeDesc(Type::INTEGER);
+ context.registerTypeDesc(Type::INTEGERARRAY);
+ context.registerTypeDesc(Type::FLOAT);
+ context.registerTypeDesc(Type::FLOATARRAY);
+ context.registerTypeDesc(Type::VECTOR2);
+ context.registerTypeDesc(Type::VECTOR3);
+ context.registerTypeDesc(Type::VECTOR4);
+ context.registerTypeDesc(Type::COLOR3);
+ context.registerTypeDesc(Type::COLOR4);
+ context.registerTypeDesc(Type::MATRIX33);
+ context.registerTypeDesc(Type::MATRIX44);
+ context.registerTypeDesc(Type::STRING);
+ context.registerTypeDesc(Type::FILENAME);
+ context.registerTypeDesc(Type::BSDF);
+ context.registerTypeDesc(Type::EDF);
+ context.registerTypeDesc(Type::VDF);
+ context.registerTypeDesc(Type::SURFACESHADER);
+ context.registerTypeDesc(Type::VOLUMESHADER);
+ context.registerTypeDesc(Type::DISPLACEMENTSHADER);
+ context.registerTypeDesc(Type::LIGHTSHADER);
+ context.registerTypeDesc(Type::MATERIAL);
+}
+
/// Load any struct type definitions from the document in to the type cache.
-void ShaderGenerator::loadStructTypeDefs(const DocumentPtr& doc)
+void ShaderGenerator::registerStructTypeDefs(const DocumentPtr& doc, GenContext& context)
{
for (const auto& mxTypeDef : doc->getTypeDefs())
{
@@ -356,33 +396,23 @@ void ShaderGenerator::loadStructTypeDefs(const DocumentPtr& doc)
if (members.empty())
continue;
- StructTypeDesc newStructTypeDesc;
+ auto structMemberDescs = std::make_shared();
for (const auto& member : members)
{
auto memberName = member->getName();
auto memberTypeName = member->getType();
- auto memberType = TypeDesc::get(memberTypeName);
+ auto memberType = context.getTypeDesc(memberTypeName);
auto memberDefaultValue = member->getValueString();
- newStructTypeDesc.addMember(memberName, memberType, memberDefaultValue);
+ // If the member type is a struct itself - then we need to collect the submember information
+ // this is to ensure we can access it later in a context where the GenContext isn't available,
+ // such as the MaterialXRender.
+ structMemberDescs->emplace_back( StructMemberDesc(memberName, memberType, memberTypeName, memberDefaultValue) );
}
-
- auto structIndex = StructTypeDesc::emplace_back(newStructTypeDesc);
-
- TypeDesc structTypeDesc(typeDefName, TypeDesc::BASETYPE_STRUCT, TypeDesc::SEMANTIC_NONE, 1, structIndex);
-
- TypeDescRegistry(structTypeDesc, typeDefName);
-
- StructTypeDesc::get(structIndex).setTypeDesc(TypeDesc::get(typeDefName));
+ context.registerTypeDesc(typeDefName, TypeDesc::BASETYPE_STRUCT, TypeDesc::SEMANTIC_NONE, 1, structMemberDescs);
}
- _syntax->registerStructTypeDescSyntax();
-}
-
-/// Clear any struct type definitions loaded
-void ShaderGenerator::clearStructTypeDefs()
-{
- StructTypeDesc::clear();
+ _syntax->registerStructTypeDescSyntax(context);
}
namespace
@@ -436,7 +466,7 @@ void ShaderGenerator::registerShaderMetadata(const DocumentPtr& doc, GenContext&
if (def->getExportable())
{
const string& attrName = def->getAttrName();
- const TypeDesc type = TypeDesc::get(def->getType());
+ const TypeDesc type = context.getTypeDesc(def->getType());
if (!attrName.empty() && type != Type::NONE)
{
registry->addMetadata(attrName, type, def->getValue());
diff --git a/source/MaterialXGenShader/ShaderGenerator.h b/source/MaterialXGenShader/ShaderGenerator.h
index a2f54fec2e..1d8573374d 100644
--- a/source/MaterialXGenShader/ShaderGenerator.h
+++ b/source/MaterialXGenShader/ShaderGenerator.h
@@ -191,11 +191,9 @@ class MX_GENSHADER_API ShaderGenerator
return _tokenSubstitutions;
}
- /// Load any struct type definitions from the document in to the type cache.
- void loadStructTypeDefs(const DocumentPtr& doc);
-
- /// Clear any struct type definitions loaded
- void clearStructTypeDefs();
+ // TODO - revist const-ness here - i don't think we really mean "const DocumentPtr" I think we mean "ConstDocumentPtr"
+ // or perhaps even just "const Document&"
+ void registerTypeDefs(const DocumentPtr& doc, GenContext& context);
/// Register metadata that should be exported to the generated shaders.
/// Supported metadata includes standard UI attributes like "uiname", "uifolder",
@@ -208,6 +206,14 @@ class MX_GENSHADER_API ShaderGenerator
/// export of metadata.
virtual void registerShaderMetadata(const DocumentPtr& doc, GenContext& context) const;
+ private:
+ /// Load any struct type definitions from the document in to the type cache.
+ void registerStructTypeDefs(const DocumentPtr& doc, GenContext& context);
+
+ protected:
+ /// protected so that subclasses can add additional builtin types. (MDL needs this).
+ virtual void registerBuiltinTypes(GenContext& context);
+
protected:
/// Protected constructor
ShaderGenerator(SyntaxPtr syntax);
diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp
index e9a3b50b79..c616c0b2fd 100644
--- a/source/MaterialXGenShader/ShaderGraph.cpp
+++ b/source/MaterialXGenShader/ShaderGraph.cpp
@@ -38,7 +38,7 @@ void ShaderGraph::addInputSockets(const InterfaceElement& elem, GenContext& cont
const string& portValueString = portValue ? portValue->getValueString() : EMPTY_STRING;
std::pair enumResult;
const string& enumNames = input->getAttribute(ValueElement::ENUM_ATTRIBUTE);
- const TypeDesc portType = TypeDesc::get(input->getType());
+ const TypeDesc portType = context.getTypeDesc(input->getType());
if (context.getShaderGenerator().getSyntax().remapEnumeration(portValueString, portType, enumNames, enumResult))
{
inputSocket = addInputSocket(input->getName(), enumResult.first);
@@ -64,15 +64,15 @@ void ShaderGraph::addInputSockets(const InterfaceElement& elem, GenContext& cont
}
}
-void ShaderGraph::addOutputSockets(const InterfaceElement& elem)
+void ShaderGraph::addOutputSockets(const InterfaceElement& elem, const GenContext& context)
{
for (const OutputPtr& output : elem.getActiveOutputs())
{
- addOutputSocket(output->getName(), TypeDesc::get(output->getType()));
+ addOutputSocket(output->getName(), context.getTypeDesc(output->getType()));
}
if (numOutputSockets() == 0)
{
- addOutputSocket("out", TypeDesc::get(elem.getType()));
+ addOutputSocket("out", context.getTypeDesc(elem.getType()));
}
}
@@ -238,7 +238,7 @@ void ShaderGraph::addDefaultGeomNode(ShaderInput* input, const GeomPropDef& geom
{
std::pair enumResult;
const string& enumNames = nodeDefSpaceInput->getAttribute(ValueElement::ENUM_ATTRIBUTE);
- const TypeDesc portType = TypeDesc::get(nodeDefSpaceInput->getType());
+ const TypeDesc portType = context.getTypeDesc(nodeDefSpaceInput->getType());
if (context.getShaderGenerator().getSyntax().remapEnumeration(space, portType, enumNames, enumResult))
{
spaceInput->setValue(enumResult.second);
@@ -444,7 +444,7 @@ ShaderGraphPtr ShaderGraph::create(const ShaderGraph* parent, const NodeGraph& n
graph->addInputSockets(*nodeDef, context);
// Create output sockets from the nodegraph
- graph->addOutputSockets(nodeGraph);
+ graph->addOutputSockets(nodeGraph, context);
// Traverse all outputs and create all internal nodes
for (OutputPtr graphOutput : nodeGraph.getActiveOutputs())
@@ -503,7 +503,7 @@ ShaderGraphPtr ShaderGraph::create(const ShaderGraph* parent, const string& name
graph->addInputSockets(*interface, context);
// Create the given output socket
- ShaderGraphOutputSocket* outputSocket = graph->addOutputSocket(output->getName(), TypeDesc::get(output->getType()));
+ ShaderGraphOutputSocket* outputSocket = graph->addOutputSocket(output->getName(), context.getTypeDesc(output->getType()));
outputSocket->setPath(output->getNamePath());
const string& outputUnit = output->getUnit();
if (!outputUnit.empty())
@@ -535,7 +535,7 @@ ShaderGraphPtr ShaderGraph::create(const ShaderGraph* parent, const string& name
graph->addInputSockets(*nodeDef, context);
// Create output sockets
- graph->addOutputSockets(*nodeDef);
+ graph->addOutputSockets(*nodeDef, context);
// Create this shader node in the graph.
ShaderNodePtr newNode = ShaderNode::create(graph.get(), node->getName(), *nodeDef, context);
@@ -571,7 +571,7 @@ ShaderGraphPtr ShaderGraph::create(const ShaderGraph* parent, const string& name
{
const string& valueString = value->getValueString();
std::pair enumResult;
- const TypeDesc type = TypeDesc::get(nodedefInput->getType());
+ const TypeDesc type = context.getTypeDesc(nodedefInput->getType());
const string& enumNames = nodedefInput->getAttribute(ValueElement::ENUM_ATTRIBUTE);
if (context.getShaderGenerator().getSyntax().remapEnumeration(valueString, type, enumNames, enumResult))
{
diff --git a/source/MaterialXGenShader/ShaderGraph.h b/source/MaterialXGenShader/ShaderGraph.h
index 6320d04296..bf38c1a6dc 100644
--- a/source/MaterialXGenShader/ShaderGraph.h
+++ b/source/MaterialXGenShader/ShaderGraph.h
@@ -136,7 +136,7 @@ class MX_GENSHADER_API ShaderGraph : public ShaderNode
void addInputSockets(const InterfaceElement& elem, GenContext& context);
/// Add output sockets from an interface element (nodedef, nodegraph or node)
- void addOutputSockets(const InterfaceElement& elem);
+ void addOutputSockets(const InterfaceElement& elem, const GenContext& context);
/// Traverse from the given root element and add all dependencies upstream.
/// The traversal is done in the context of a material, if given, to include
diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp
index d52810ffc4..ddede9b79e 100644
--- a/source/MaterialXGenShader/ShaderNode.cpp
+++ b/source/MaterialXGenShader/ShaderNode.cpp
@@ -179,7 +179,7 @@ ShaderNodePtr ShaderNode::create(const ShaderGraph* parent, const string& name,
// Create interface from nodedef
for (const ValueElementPtr& port : nodeDef.getActiveValueElements())
{
- const TypeDesc portType = TypeDesc::get(port->getType());
+ const TypeDesc portType = context.getTypeDesc(port->getType());
if (port->isA