@@ -329,23 +329,8 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
329329 return shader;
330330}
331331
332- ShaderNodeImplPtr MdlShaderGenerator::getImplementation (const NodeDef& nodedef, GenContext& context ) const
332+ ShaderNodeImplPtr MdlShaderGenerator::createShaderNodeImplForNodeGraph (const NodeDef& nodedef) const
333333{
334- InterfaceElementPtr implElement = nodedef.getImplementation (getTarget ());
335- if (!implElement)
336- {
337- return nullptr ;
338- }
339-
340- const string& name = implElement->getName ();
341-
342- // Check if it's created and cached already.
343- ShaderNodeImplPtr impl = context.findNodeImplementation (name);
344- if (impl)
345- {
346- return impl;
347- }
348-
349334 vector<OutputPtr> outputs = nodedef.getActiveOutputs ();
350335 if (outputs.empty ())
351336 {
@@ -354,62 +339,38 @@ ShaderNodeImplPtr MdlShaderGenerator::getImplementation(const NodeDef& nodedef,
354339
355340 const TypeDesc outputType = _typeSystem->getType (outputs[0 ]->getType ());
356341
357- if (implElement->isA <NodeGraph>())
342+ ShaderNodeImplPtr impl;
343+ // Use a compound implementation.
344+ if (outputType.isClosure ())
358345 {
359- // Use a compound implementation.
360- if (outputType.isClosure ())
361- {
362- impl = ClosureCompoundNodeMdl::create ();
363- }
364- else
365- {
366- impl = CompoundNodeMdl::create ();
367- }
368- }
369- else if (implElement->isA <Implementation>())
370- {
371- if (getColorManagementSystem () && getColorManagementSystem ()->hasImplementation (name))
372- {
373- impl = getColorManagementSystem ()->createImplementation (name);
374- }
375- else
376- {
377- // Try creating a new in the factory.
378- impl = _implFactory.create (name);
379- }
380- if (!impl)
381- {
382- // When `file` and `function` are provided we consider this node a user node
383- const string file = implElement->getTypedAttribute <string>(" file" );
384- const string function = implElement->getTypedAttribute <string>(" function" );
385- // Or, if `sourcecode` is provided we consider this node a user node with inline implementation
386- // inline implementations are not supposed to have replacement markers
387- const string sourcecode = implElement->getTypedAttribute <string>(" sourcecode" );
388- if ((!file.empty () && !function.empty ()) || (!sourcecode.empty () && sourcecode.find (" {{" ) == string::npos))
389- {
390- impl = CustomCodeNodeMdl::create ();
391- }
392- else if (file.empty () && sourcecode.empty ())
393- {
394- throw ExceptionShaderGenError (" No valid MDL implementation found for '" + name + " '" );
395- }
396- else
397- {
398- impl = SourceCodeNodeMdl::create ();
399- }
400- }
346+ return ClosureCompoundNodeMdl::create ();
401347 }
402- if (!impl)
348+ return CompoundNodeMdl::create ();
349+ }
350+
351+ ShaderNodeImplPtr MdlShaderGenerator::createShaderNodeImplForImplementation (const NodeDef& nodedef) const
352+ {
353+ InterfaceElementPtr implElement = nodedef.getImplementation (getTarget ());
354+ if (!implElement)
403355 {
404356 return nullptr ;
405357 }
406358
407- impl->initialize (*implElement, context);
408-
409- // Cache it.
410- context.addNodeImplementation (name, impl);
411-
412- return impl;
359+ // When `file` and `function` are provided we consider this node a user node
360+ const string file = implElement->getTypedAttribute <string>(" file" );
361+ const string function = implElement->getTypedAttribute <string>(" function" );
362+ // Or, if `sourcecode` is provided we consider this node a user node with inline implementation
363+ // inline implementations are not supposed to have replacement markers
364+ const string sourcecode = implElement->getTypedAttribute <string>(" sourcecode" );
365+ if ((!file.empty () && !function.empty ()) || (!sourcecode.empty () && sourcecode.find (" {{" ) == string::npos))
366+ {
367+ return CustomCodeNodeMdl::create ();
368+ }
369+ if (file.empty () && sourcecode.empty ())
370+ {
371+ throw ExceptionShaderGenError (" No valid MDL implementation found for '" + implElement->getName () + " '" );
372+ }
373+ return SourceCodeNodeMdl::create ();
413374}
414375
415376string MdlShaderGenerator::getUpstreamResult (const ShaderInput* input, GenContext& context) const
0 commit comments