Skip to content

Commit

Permalink
Apply Clang formatting
Browse files Browse the repository at this point in the history
This changelist applies Clang formatting to source files in the MaterialX codebase, and includes no functional changes.
  • Loading branch information
jstone-lucasfilm committed Jul 16, 2024
1 parent a090c73 commit 81a851b
Show file tree
Hide file tree
Showing 33 changed files with 646 additions and 651 deletions.
14 changes: 6 additions & 8 deletions source/MaterialXCore/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ MATERIALX_NAMESPACE_BEGIN
const string Document::CMS_ATTRIBUTE = "cms";
const string Document::CMS_CONFIG_ATTRIBUTE = "cmsconfig";


//
// Document factory function
//
Expand Down Expand Up @@ -164,7 +163,7 @@ NodeDefPtr Document::addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& n
{
throw Exception("Cannot create duplicate nodegraph: " + newGraphName);
}

// Create a new functional nodegraph, and copy over the
// contents from the compound nodegraph
NodeGraphPtr graph = addNodeGraph(newGraphName);
Expand All @@ -174,19 +173,19 @@ NodeDefPtr Document::addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& n
{
graphChild->removeAttribute(Element::XPOS_ATTRIBUTE);
graphChild->removeAttribute(Element::YPOS_ATTRIBUTE);
}
}
graph->setNodeDefString(nodeDefName);

// Create a new nodedef and set its category
NodeDefPtr nodeDef = addNodeDef(nodeDefName, EMPTY_STRING);
nodeDef->setNodeString(category);

// Expose any existing interfaces from the graph.
// Any connection attributes ("nodegraph", "nodename", "interfacename") on the
// Any connection attributes ("nodegraph", "nodename", "interfacename") on the
// existing interface should be removed from the definition as well as any source URI.

// Attributes which should not be copied over
StringSet filterAttributes = { PortElement::NODE_GRAPH_ATTRIBUTE, PortElement::NODE_NAME_ATTRIBUTE,
StringSet filterAttributes = { PortElement::NODE_GRAPH_ATTRIBUTE, PortElement::NODE_NAME_ATTRIBUTE,
PortElement::INTERFACE_NAME_ATTRIBUTE, Element::XPOS_ATTRIBUTE, Element::YPOS_ATTRIBUTE };

// Transfer input interface from the graph to the nodedef
Expand All @@ -196,13 +195,13 @@ NodeDefPtr Document::addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& n
if (nodeDefInput)
{
nodeDefInput->copyContentFrom(input);
for (const string& filterAttribute : filterAttributes )
for (const string& filterAttribute : filterAttributes)
{
nodeDefInput->removeAttribute(filterAttribute);
}
nodeDefInput->setSourceUri(EMPTY_STRING);
input->setInterfaceName(nodeDefInput->getName());
}
}
}
// Remove interfaces from the nodegraph
for (InputPtr input : graph->getInputs())
Expand Down Expand Up @@ -412,5 +411,4 @@ NodeDefPtr Document::addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& n
return addNodeDefFromGraph(nodeGraph, nodeDefName, node, newGraphName);
}


MATERIALX_NAMESPACE_END
2 changes: 1 addition & 1 deletion source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class MX_CORE_API Document : public GraphElement

/// Create a NodeDef and Functional Graph based on a Compound NodeGraph
/// @param nodeGraph Compound NodeGraph.
/// @param newGraphName Name of new functional NodeGraph.
/// @param newGraphName Name of new functional NodeGraph.
/// @param nodeDefName Name of new NodeDef
/// @param category Category of the new NodeDef
/// @return New declaration if successful.
Expand Down
8 changes: 4 additions & 4 deletions source/MaterialXCore/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ int LinearUnitConverter::getUnitAsInteger(const string& unitName) const
string LinearUnitConverter::getUnitFromInteger(int index) const
{
auto it = std::find_if(_unitEnumeration.begin(), _unitEnumeration.end(),
[&index](const std::pair<string, int> &e)->bool
{
return (e.second == index);
});
[&index](const std::pair<string, int>& e) -> bool
{
return (e.second == index);
});

if (it != _unitEnumeration.end())
{
Expand Down
8 changes: 4 additions & 4 deletions source/MaterialXCore/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ void Document::upgradeVersion()
NodePtr base = node->getConnectedNode("base");
if (top && base && top->getCategory() == "thin_film_bsdf")
{
// Apply thin-film parameters to all supported BSDF's upstream.
// Apply thin-film parameters to all supported BSDF's upstream.
const StringSet BSDF_WITH_THINFILM = { "dielectric_bsdf", "conductor_bsdf", "generalized_schlick_bsdf" };
for (Edge edge : node->traverseGraph())
{
Expand Down Expand Up @@ -1171,9 +1171,9 @@ void Document::upgradeVersion()
string channelString = channelsInput ? channelsInput->getValueString() : EMPTY_STRING;
size_t sourceChannelCount = CHANNEL_COUNT_MAP.at(inInput->getType());
size_t destChannelCount = CHANNEL_COUNT_MAP.at(node->getType());

// Resolve the invalid case of having both a connection and a value
// by removing the value attribute.
// by removing the value attribute.
if (inInput->hasValue())
{
if (inInput->hasNodeName() || inInput->hasNodeGraphString() || inInput->hasInterfaceName())
Expand Down Expand Up @@ -1264,7 +1264,7 @@ void Document::upgradeVersion()
// Replace swizzle with separate and combine.
GraphElementPtr graph = node->getAncestorOfType<GraphElement>();
NodePtr separateNode = graph->addNode(std::string("separate") + std::to_string(sourceChannelCount),
graph->createValidChildName("separate"), MULTI_OUTPUT_TYPE_STRING);
graph->createValidChildName("separate"), MULTI_OUTPUT_TYPE_STRING);
int childIndex = graph->getChildIndex(node->getName());
if (childIndex != -1)
{
Expand Down
11 changes: 6 additions & 5 deletions source/MaterialXGenGlsl/GlslResourceBindingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ void GlslResourceBindingContext::emitStructuredResourceBindings(GenContext& cont
// Sort order from largest to smallest
std::sort(memberOrder.begin(), memberOrder.end(),
[](const std::pair<size_t, size_t>& a, const std::pair<size_t, size_t>& b)
{
return a.first > b.first;
});
{
return a.first > b.first;
});

// Emit the struct
generator.emitLine("struct " + uniforms.getName(), stage, false);
Expand All @@ -181,8 +181,9 @@ void GlslResourceBindingContext::emitStructuredResourceBindings(GenContext& cont
// Emit binding information
generator.emitLineBreak(stage);
generator.emitLine("layout (std140, binding=" + std::to_string(_hwUniformBindLocation++) +
") " + syntax.getUniformQualifier() + " " + uniforms.getName() + "_" +
stage.getName(), stage, false);
") " + syntax.getUniformQualifier() + " " + uniforms.getName() + "_" +
stage.getName(),
stage, false);
generator.emitScopeBegin(stage);
generator.emitLine(uniforms.getName() + " " + structInstanceName + arraySuffix, stage);
generator.emitScopeEnd(stage, true);
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenGlsl/VkResourceBindingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void VkResourceBindingContext::emitStructuredResourceBindings(GenContext& contex
// Sort order from largest to smallest
std::sort(memberOrder.begin(), memberOrder.end(),
[](const std::pair<size_t, size_t>& a, const std::pair<size_t, size_t>& b)
{
{
return a.first > b.first;
});

Expand Down
10 changes: 4 additions & 6 deletions source/MaterialXGenMdl/MdlShaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ const vector<string> DEFAULT_IMPORTS =
"using ::materialx::sampling import *",
};

const vector<string> DEFAULT_VERSIONED_IMPORTS = {
const vector<string> DEFAULT_VERSIONED_IMPORTS =
{
"using ::materialx::stdlib_",
"using ::materialx::pbrlib_",
};

const string IMPORT_ALL = " import *";


const string MDL_VERSION_1_6 = "1.6";
const string MDL_VERSION_1_7 = "1.7";
const string MDL_VERSION_1_8 = "1.8";
Expand Down Expand Up @@ -223,7 +223,8 @@ ShaderPtr MdlShaderGenerator::generate(const string& name, ElementPtr element, G
emitLine("color finalOutput__ = mk_color3("
"r: math::dot(displacement__, state::texture_tangent_u(0)),"
"g: math::dot(displacement__, state::texture_tangent_v(0)),"
"b: math::dot(displacement__, state::normal()))", stage);
"b: math::dot(displacement__, state::normal()))",
stage);
}
else
{
Expand Down Expand Up @@ -602,7 +603,6 @@ void emitInputAnnotations(const MdlShaderGenerator& _this, const DocumentPtr doc

} // anonymous namespace


void MdlShaderGenerator::emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, ShaderStage& stage) const
{
const string uniformPrefix = _syntax->getUniformQualifier() + " ";
Expand Down Expand Up @@ -641,7 +641,6 @@ void MdlShaderGenerator::emitShaderInputs(const DocumentPtr doc, const VariableB
}
}


void MdlShaderGenerator::emitMdlVersionNumber(GenContext& context, ShaderStage& stage) const
{
GenMdlOptionsPtr options = context.getUserData<GenMdlOptions>(GenMdlOptions::GEN_CONTEXT_USER_DATA_KEY);
Expand Down Expand Up @@ -684,7 +683,6 @@ const string& MdlShaderGenerator::getMdlVersionFilenameSuffix(GenContext& contex
}
}


void MdlShaderGenerator::emitMdlVersionFilenameSuffix(GenContext& context, ShaderStage& stage) const
{
emitString(getMdlVersionFilenameSuffix(context), stage);
Expand Down
5 changes: 3 additions & 2 deletions source/MaterialXGenMdl/Nodes/ClosureLayerNodeMdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ void ClosureLayerNodeMdl::emitFunctionCall(const ShaderNode& _node, GenContext&

// Join the BSDF and VDF into a single material.
shadergen.emitLine("material " + output->getVariable() +
" = material(surface: " + t + ".surface, backface: " + t +
".backface, ior: " + t + ".ior, volume: " + b + ".volume)", stage);
" = material(surface: " + t + ".surface, backface: " + t +
".backface, ior: " + t + ".ior, volume: " + b + ".volume)",
stage);

return;
}
Expand Down
40 changes: 20 additions & 20 deletions source/MaterialXGenMdl/Nodes/SourceCodeNodeMdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void SourceCodeNodeMdl::initialize(const InterfaceElement& element, GenContext&
const MdlShaderGenerator& shadergenMdl = static_cast<const MdlShaderGenerator&>(shadergen);
const string versionSuffix = shadergenMdl.getMdlVersionFilenameSuffix(context);
StringVec code = replaceSourceCodeMarkers(getName(), functionName, [&versionSuffix](const string& marker)
{
return marker == MARKER_MDL_VERSION_SUFFIX ? versionSuffix : EMPTY_STRING;
});
{
return marker == MARKER_MDL_VERSION_SUFFIX ? versionSuffix : EMPTY_STRING;
});
functionName = std::accumulate(code.begin(), code.end(), EMPTY_STRING);
_returnStruct = functionName + "__result";
}
Expand All @@ -105,26 +105,26 @@ void SourceCodeNodeMdl::emitFunctionCall(const ShaderNode& node, GenContext& con
{
const string versionSuffix = shadergenMdl.getMdlVersionFilenameSuffix(context);
StringVec code = replaceSourceCodeMarkers(node.getName(), _functionSource,
[&shadergenMdl, &context, &node, &versionSuffix](const string& marker)
[&shadergenMdl, &context, &node, &versionSuffix](const string& marker)
{
// Special handling for the version suffix of MDL source code modules.
if (marker == MARKER_MDL_VERSION_SUFFIX)
{
// Special handling for the version suffix of MDL source code modules.
if (marker == MARKER_MDL_VERSION_SUFFIX)
{
return versionSuffix;
}
// Insert inputs based on parameter names.
else
return versionSuffix;
}
// Insert inputs based on parameter names.
else
{
const ShaderInput* input = node.getInput(marker);
if (!input)
{
const ShaderInput* input = node.getInput(marker);
if (!input)
{
throw ExceptionShaderGenError("Could not find an input named '" + marker +
"' on node '" + node.getName() + "'");
}

return shadergenMdl.getUpstreamResult(input, context);
throw ExceptionShaderGenError("Could not find an input named '" + marker +
"' on node '" + node.getName() + "'");
}
});

return shadergenMdl.getUpstreamResult(input, context);
}
});

if (!_returnStruct.empty())
{
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXGenShader/GenContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class MX_GENSHADER_API GenContext
return _closureContexts.size() ? _closureContexts.back() : nullptr;
}

/// Push a parent node onto the stack
/// Push a parent node onto the stack
void pushParentNode(ConstNodePtr node)
{
_parentNodes.push_back(node);
Expand Down Expand Up @@ -292,7 +292,7 @@ class MX_GENSHADER_API ClosureContext
auto it = _suffix.find(nodeType);
return it != _suffix.end() ? it->second : EMPTY_STRING;
}
[[deprecated]] const string& getSuffix(const TypeDesc* nodeType) const { return getSuffix(*nodeType); }
[[deprecated]] const string& getSuffix(const TypeDesc* nodeType) const { return getSuffix(*nodeType); }

/// Set extra parameters to use for evaluating a closure.
void setClosureParams(const ShaderNode* closure, const ClosureParams* params)
Expand Down
4 changes: 2 additions & 2 deletions source/MaterialXGenShader/Nodes/BlurNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class MX_GENSHADER_API BlurNode : public ConvolutionNode
virtual void outputSampleArray(const ShaderGenerator& shadergen, ShaderStage& stage, TypeDesc inputType,
const string& sampleName, const StringVec& sampleStrings) const;
[[deprecated]] void outputSampleArray(const ShaderGenerator& shadergen, ShaderStage& stage, const TypeDesc* inputType,
const string& sampleName, const StringVec& sampleStrings) const
{
const string& sampleName, const StringVec& sampleStrings) const
{
return outputSampleArray(shadergen, stage, *inputType, sampleName, sampleStrings);
}

Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenShader/ShaderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class MX_GENSHADER_API ShaderGraph : public ShaderNode

/// Add output sockets
ShaderGraphOutputSocket* addOutputSocket(const string& name, TypeDesc type);
[[deprecated]] ShaderGraphOutputSocket* addOutputSocket(const string& name, const TypeDesc* type) { return addOutputSocket(name, *type); }
[[deprecated]] ShaderGraphOutputSocket* addOutputSocket(const string& name, const TypeDesc* type) { return addOutputSocket(name, *type); }

/// Add a default geometric node and connect to the given input.
void addDefaultGeomNode(ShaderInput* input, const GeomPropDef& geomprop, GenContext& context);
Expand Down
1 change: 0 additions & 1 deletion source/MaterialXGenShader/Syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ bool Syntax::remapEnumeration(const string&, TypeDesc, const string&, std::pair<
return false;
}


const StringVec TypeSyntax::EMPTY_MEMBERS;

TypeSyntax::TypeSyntax(const string& name, const string& defaultValue, const string& uniformDefaultValue,
Expand Down
35 changes: 18 additions & 17 deletions source/MaterialXGenShader/TypeDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ MATERIALX_NAMESPACE_BEGIN

namespace
{
using TypeDescMap = std::unordered_map<string, TypeDesc>;
using TypeDescNameMap = std::unordered_map<uint32_t, string>;

// Internal storage of registered type descriptors
TypeDescMap& typeMap()
{
static TypeDescMap map;
return map;
}

TypeDescNameMap& typeNameMap()
{
static TypeDescNameMap map;
return map;
}

using TypeDescMap = std::unordered_map<string, TypeDesc>;
using TypeDescNameMap = std::unordered_map<uint32_t, string>;

// Internal storage of registered type descriptors
TypeDescMap& typeMap()
{
static TypeDescMap map;
return map;
}

TypeDescNameMap& typeNameMap()
{
static TypeDescNameMap map;
return map;
}

} // anonymous namespace

Expand Down Expand Up @@ -56,7 +57,7 @@ TypeDescRegistry::TypeDescRegistry(TypeDesc type, const std::string& name)
namespace Type
{

///
///
/// Register type descriptors for standard types.
///
TYPEDESC_REGISTER_TYPE(NONE, "none")
Expand All @@ -83,6 +84,6 @@ TYPEDESC_REGISTER_TYPE(DISPLACEMENTSHADER, "displacementshader")
TYPEDESC_REGISTER_TYPE(LIGHTSHADER, "lightshader")
TYPEDESC_REGISTER_TYPE(MATERIAL, "material")

}
} // namespace Type

MATERIALX_NAMESPACE_END
Loading

0 comments on commit 81a851b

Please sign in to comment.