Skip to content

Commit 78c3963

Browse files
Merge branch 'main' into patch_js_packages
2 parents 0892d2e + 0fd40b1 commit 78c3963

23 files changed

Lines changed: 115 additions & 252 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ if(MSVC)
287287
add_compile_options(/WX)
288288
endif()
289289
else()
290-
add_compile_options(-Wall -Wno-missing-braces)
290+
add_compile_options(-Wall -Wunused-parameter -Wno-missing-braces)
291291
if(MATERIALX_WARNINGS_AS_ERRORS)
292292
add_compile_options(-Werror)
293293
endif()

source/MaterialXCore/Library.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#pragma warning(disable : 4661)
3636
#define MATERIALX_SYMBOL_EXPORT __declspec(dllexport)
3737
#define MATERIALX_SYMBOL_IMPORT __declspec(dllimport)
38-
#define MATERIALX_EXPORT_EXTERN_TEMPLATE(...) template class MATERIALX_SYMBOL_EXPORT __VA_ARGS__
39-
#define MATERIALX_IMPORT_EXTERN_TEMPLATE(...) extern template class MATERIALX_SYMBOL_IMPORT __VA_ARGS__
38+
#define MATERIALX_EXPORT_EXTERN_TEMPLATE(...) template class __VA_ARGS__
39+
#define MATERIALX_IMPORT_EXTERN_TEMPLATE(...) extern template class __VA_ARGS__
4040
#else
4141
#define MATERIALX_SYMBOL_EXPORT __attribute__((__visibility__("default")))
4242
#define MATERIALX_SYMBOL_IMPORT __attribute__((__visibility__("default")))

source/MaterialXCore/Value.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,15 @@ template <class T> class ValueRegistry
425425
// Template instantiations
426426
//
427427

428-
#define INSTANTIATE_TYPE(T, name) \
429-
template <> const string TypedValue<T>::TYPE = name; \
430-
template <> const string& TypedValue<T>::getTypeString() const { return TYPE; } \
431-
template <> string TypedValue<T>::getValueString() const { return toValueString<T>(_data); } \
432-
template MX_CORE_API bool Value::isA<T>() const; \
433-
template MX_CORE_API const T& Value::asA<T>() const; \
434-
template MX_CORE_API const string& getTypeString<T>(); \
435-
template MX_CORE_API string toValueString(const T& data); \
436-
template MX_CORE_API T fromValueString(const string& value); \
428+
#define INSTANTIATE_TYPE(T, name) \
429+
template <> MX_CORE_API const string TypedValue<T>::TYPE = name; \
430+
template <> MX_CORE_API const string& TypedValue<T>::getTypeString() const { return TYPE; } \
431+
template <> MX_CORE_API string TypedValue<T>::getValueString() const { return toValueString<T>(_data); } \
432+
template MX_CORE_API bool Value::isA<T>() const; \
433+
template MX_CORE_API const T& Value::asA<T>() const; \
434+
template MX_CORE_API const string& getTypeString<T>(); \
435+
template MX_CORE_API string toValueString(const T& data); \
436+
template MX_CORE_API T fromValueString(const string& value); \
437437
ValueRegistry<T> registry##T;
438438

439439
// Base types

source/MaterialXCore/Value.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,51 +124,51 @@ class MX_CORE_API Value
124124
};
125125

126126
/// The class template for typed subclasses of Value
127-
template <class T> class MX_CORE_API TypedValue : public Value
127+
template <class T> class TypedValue : public Value
128128
{
129129
public:
130-
TypedValue() :
130+
MX_CORE_API TypedValue() :
131131
_data{}
132132
{
133133
}
134-
explicit TypedValue(const T& value) :
134+
MX_CORE_API explicit TypedValue(const T& value) :
135135
_data(value)
136136
{
137137
}
138-
virtual ~TypedValue() { }
138+
MX_CORE_API virtual ~TypedValue() { }
139139

140140
/// Create a deep copy of the value.
141-
ValuePtr copy() const override
141+
MX_CORE_API ValuePtr copy() const override
142142
{
143143
return Value::createValue<T>(_data);
144144
}
145145

146146
/// Set stored data object.
147-
void setData(const T& value)
147+
MX_CORE_API void setData(const T& value)
148148
{
149149
_data = value;
150150
}
151151

152152
/// Set stored data object.
153-
void setData(const TypedValue<T>& value)
153+
MX_CORE_API void setData(const TypedValue<T>& value)
154154
{
155155
_data = value._data;
156156
}
157157

158158
/// Return stored data object.
159-
const T& getData() const
159+
MX_CORE_API const T& getData() const
160160
{
161161
return _data;
162162
}
163163

164164
/// Return type string.
165-
const string& getTypeString() const override;
165+
MX_CORE_API const string& getTypeString() const override;
166166

167167
/// Return value string.
168-
string getValueString() const override;
168+
MX_CORE_API string getValueString() const override;
169169

170170
// Returns true if value data matches.
171-
bool isEqual(ConstValuePtr other) const override
171+
MX_CORE_API bool isEqual(ConstValuePtr other) const override
172172
{
173173
if (!other || !other->isA<T>())
174174
{
@@ -184,10 +184,10 @@ template <class T> class MX_CORE_API TypedValue : public Value
184184
/// Create a new value of this type from a value string.
185185
/// @return A shared pointer to a typed value, or an empty shared pointer
186186
/// if the conversion to the given data type cannot be performed.
187-
static ValuePtr createFromString(const string& value);
187+
MX_CORE_API static ValuePtr createFromString(const string& value);
188188

189189
public:
190-
static const string TYPE;
190+
MX_CORE_API static const string TYPE;
191191

192192
private:
193193
T _data;

source/MaterialXGenGlsl/GlslShaderGenerator.cpp

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <MaterialXGenGlsl/GlslSyntax.h>
99

10+
#include <MaterialXGenShader/Shader.h>
1011
#include <MaterialXGenShader/Nodes/MaterialNode.h>
1112
#include <MaterialXGenShader/Nodes/HwImageNode.h>
1213
#include <MaterialXGenShader/Nodes/HwGeomColorNode.h>
@@ -20,7 +21,6 @@
2021
#include <MaterialXGenShader/Nodes/HwFrameNode.h>
2122
#include <MaterialXGenShader/Nodes/HwTimeNode.h>
2223
#include <MaterialXGenShader/Nodes/HwViewDirectionNode.h>
23-
#include <MaterialXGenShader/Nodes/HwLightCompoundNode.h>
2424
#include <MaterialXGenShader/Nodes/HwLightNode.h>
2525
#include <MaterialXGenShader/Nodes/HwLightSamplerNode.h>
2626
#include <MaterialXGenShader/Nodes/HwLightShaderNode.h>
@@ -692,70 +692,4 @@ void GlslShaderGenerator::emitVariableDeclaration(const ShaderPort* variable, co
692692
}
693693
}
694694

695-
ShaderNodeImplPtr GlslShaderGenerator::getImplementation(const NodeDef& nodedef, GenContext& context) const
696-
{
697-
InterfaceElementPtr implElement = nodedef.getImplementation(getTarget());
698-
if (!implElement)
699-
{
700-
return nullptr;
701-
}
702-
703-
const string& name = implElement->getName();
704-
705-
// Check if it's created and cached already.
706-
ShaderNodeImplPtr impl = context.findNodeImplementation(name);
707-
if (impl)
708-
{
709-
return impl;
710-
}
711-
712-
vector<OutputPtr> outputs = nodedef.getActiveOutputs();
713-
if (outputs.empty())
714-
{
715-
throw ExceptionShaderGenError("NodeDef '" + nodedef.getName() + "' has no outputs defined");
716-
}
717-
718-
const TypeDesc outputType = context.getTypeDesc(outputs[0]->getType());
719-
720-
if (implElement->isA<NodeGraph>())
721-
{
722-
// Use a compound implementation.
723-
if (outputType == Type::LIGHTSHADER)
724-
{
725-
impl = HwLightCompoundNode::create();
726-
}
727-
else
728-
{
729-
impl = CompoundNode::create();
730-
}
731-
}
732-
else if (implElement->isA<Implementation>())
733-
{
734-
if (getColorManagementSystem() && getColorManagementSystem()->hasImplementation(name))
735-
{
736-
impl = getColorManagementSystem()->createImplementation(name);
737-
}
738-
else
739-
{
740-
// Try creating a new in the factory.
741-
impl = _implFactory.create(name);
742-
}
743-
if (!impl)
744-
{
745-
impl = SourceCodeNode::create();
746-
}
747-
}
748-
if (!impl)
749-
{
750-
return nullptr;
751-
}
752-
753-
impl->initialize(*implElement, context);
754-
755-
// Cache it.
756-
context.addNodeImplementation(name, impl);
757-
758-
return impl;
759-
}
760-
761695
MATERIALX_NAMESPACE_END

source/MaterialXGenGlsl/GlslShaderGenerator.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
4949
void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
5050
bool assignValue = true) const override;
5151

52-
/// Return a registered shader node implementation given an implementation element.
53-
/// The element must be an Implementation or a NodeGraph acting as implementation.
54-
ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;
55-
5652
/// Determine the prefix of vertex data variables.
5753
string getVertexDataPrefix(const VariableBlock& vertexData) const override;
5854

source/MaterialXGenMdl/MdlShaderGenerator.cpp

Lines changed: 27 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -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

415376
string MdlShaderGenerator::getUpstreamResult(const ShaderInput* input, GenContext& context) const

source/MaterialXGenMdl/MdlShaderGenerator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ class MX_GENMDL_API MdlShaderGenerator : public ShaderGenerator
7474
/// the element and all dependencies upstream into shader code.
7575
ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
7676

77-
/// Return a registered shader node implementation given an implementation element.
78-
/// The element must be an Implementation or a NodeGraph acting as implementation.
79-
ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;
77+
/// Create the shader node implementation for a nodedef that has a NodeGraph implementation.
78+
ShaderNodeImplPtr createShaderNodeImplForNodeGraph(const NodeDef& nodedef) const override;
79+
80+
/// Create the shader node implementation for a nodedef that has a Implementation implementation.
81+
ShaderNodeImplPtr createShaderNodeImplForImplementation(const NodeDef& nodedef) const override;
8082

8183
/// Return the result of an upstream connection or value for an input.
8284
string getUpstreamResult(const ShaderInput* input, GenContext& context) const override;

0 commit comments

Comments
 (0)