Skip to content

Commit

Permalink
Addressing notes and refactor 'experimental' files to unit test locat…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
ld-kerley committed Jun 11, 2024
1 parent aece2c8 commit 42b3e6d
Show file tree
Hide file tree
Showing 27 changed files with 67 additions and 174 deletions.
10 changes: 0 additions & 10 deletions libraries/experimental/experimental_ng.mtlx

This file was deleted.

2 changes: 1 addition & 1 deletion resources/Materials/TestSuite/_options.mtlx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<input name="irradianceIBLPath" type="string" value="resources/Lights/irradiance/san_giuseppe_bridge.hdr" />

<!-- List of extra library paths for generator and render tests -->
<input name="extraLibraryPaths" type="string" value="" />
<input name="extraLibraryPaths" type="string" value="resources/Materials/TestSuite/library" />

<!-- List of document paths for render tests -->
<input name="renderTestPaths" type="string" value="resources/Materials/Examples/StandardSurface,resources/Materials/TestSuite/stdlib/color_management,resources/Materials/TestSuite/stdlib/convolution,resources/Materials/TestSuite/stdlib/geometric,resources/Materials/TestSuite/stdlib/procedural,resources/Materials/TestSuite/pbrlib,resources/Materials/TestSuite/nprlib" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0"?>
<materialx version="1.38">



<nodegraph name="test_struct_texcoord">

<extracts name="extracts" type="float">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0"?>
<materialx version="1.38">


<nodegraph name="test_struct_texcoord">

<extractsgroup name="extracts_group" type="float">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?xml version="1.0"?>
<materialx version="1.38">
<!--
Copyright Contributors to the MaterialX Project
SPDX-License-Identifier: Apache-2.0
Declarations of experimental data types and nodes
-->

<!-- name clashes with variable names will hopefully be resolved by
recommending struct type names be suffixed with `_struct` -->
recommending struct type names be suffixed with `_struct` -->

<typedef name="texcoord_struct">
<member name="ss" type="float" value="0.5"/>
<member name="tt" type="float" value="0.5"/>
</typedef>

<nodedef name="ND_extract_s_texcoord" node="extracts" nodegroup="shader" >
<input name="in" type="texcoord_struct" value="{0.1;0.1}" />
<output name="out" type="float" value="0.0" />
</nodedef>


<!-- name clashes with variable names will hopefully be resolved by
recommending struct type names be suffixed with `_struct` -->

<typedef name="texcoordGroup_struct">
<member name="st_0" type="texcoord_struct" value="{0.1;0.1}"/>
<member name="st_1" type="texcoord_struct" value="{0.5;0.5}"/>
<member name="st_2" type="texcoord_struct" value="{0.9;0.9}"/>
</typedef>

<nodedef name="ND_extract_s_texcoord" node="extracts" nodegroup="shader" >
<input name="in" type="texcoord_struct" value="{0.1;0.1}" />
<output name="out" type="float" value="0.0" />
</nodedef>

<nodedef name="ND_extract_s_texcoordGroup" node="extractsgroup" nodegroup="shader" >
<input name="in" type="texcoordGroup_struct" value="{{0.1;0.2};{0.3;0.4};{0.5;0.6}}"/>
<input name="index" type="integer" value="0"/>
<output name="out" type="float" value="0.0" />
</nodedef>



</materialx>
56 changes: 1 addition & 55 deletions source/MaterialXCore/Definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,12 @@
#include <MaterialXCore/Export.h>

#include <MaterialXCore/Interface.h>
#include <MaterialXCore/MaterialXCore_fwd.h>

MATERIALX_NAMESPACE_BEGIN

extern MX_CORE_API const string COLOR_SEMANTIC;
extern MX_CORE_API const string SHADER_SEMANTIC;
//
//class NodeDef;
//class Implementation;
//class TypeDef;
//class TargetDef;
//class Member;
//class Unit;
//class UnitDef;
//class UnitTypeDef;
//class AttributeDef;
//
///// A shared pointer to a NodeDef
//using NodeDefPtr = shared_ptr<NodeDef>;
///// A shared pointer to a const NodeDef
//using ConstNodeDefPtr = shared_ptr<const NodeDef>;
//
///// A shared pointer to an Implementation
//using ImplementationPtr = shared_ptr<Implementation>;
///// A shared pointer to a const Implementation
//using ConstImplementationPtr = shared_ptr<const Implementation>;
//
///// A shared pointer to a TypeDef
//using TypeDefPtr = shared_ptr<TypeDef>;
///// A shared pointer to a const TypeDef
//using ConstTypeDefPtr = shared_ptr<const TypeDef>;
//
///// A shared pointer to a TargetDef
//using TargetDefPtr = shared_ptr<TargetDef>;
///// A shared pointer to a const TargetDef
//using ConstTargetDefPtr = shared_ptr<const TargetDef>;
//
///// A shared pointer to a Member
//using MemberPtr = shared_ptr<Member>;
///// A shared pointer to a const Member
//using ConstMemberPtr = shared_ptr<const Member>;
//
///// A shared pointer to a Unit
//using UnitPtr = shared_ptr<Unit>;
///// A shared pointer to a const Unit
//using ConstUnitPtr = shared_ptr<const Unit>;
//
///// A shared pointer to a UnitDef
//using UnitDefPtr = shared_ptr<UnitDef>;
///// A shared pointer to a const UnitDef
//using ConstUnitDefPtr = shared_ptr<const UnitDef>;
//
///// A shared pointer to a UnitTypeDef
//using UnitTypeDefPtr = shared_ptr<UnitTypeDef>;
///// A shared pointer to a const UnitTypeDef
//using ConstUnitTypeDefPtr = shared_ptr<const UnitTypeDef>;
//
///// A shared pointer to an AttributeDef
//using AttributeDefPtr = shared_ptr<AttributeDef>;
///// A shared pointer to a const AttributeDef
//using AttributeDefDefPtr = shared_ptr<const AttributeDef>;

/// @class NodeDef
/// A node definition element within a Document.
Expand Down
16 changes: 9 additions & 7 deletions source/MaterialXCore/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ StringVec splitListInitializer(const string& str)
if (str.empty())
return StringVec();

// validate the string is correctly formatted - must be atleast 2 characters long and start and end with braces
// validate the string is correctly formatted - must be at least 2 characters long and start and end with braces
if (str.size() < 2 || (str[0] != OPEN_BRACE || str[str.size()-1] != CLOSE_BRACE))
{
// TODO - whats the best way to report this error?
printf("ERROR2");
return StringVec();
}

Expand All @@ -126,17 +124,21 @@ StringVec splitListInitializer(const string& str)
// sequentially examine each character to parse the list initializer.
string part = "";
int braceDepth = 0;
for (const char c : substring) {
if (c == OPEN_BRACE) {
for (const char c : substring)
{
if (c == OPEN_BRACE)
{
// we've already trimmed the starting brace, so any additional braces indicate members that are themselves list initializers.
// we will just return this as a string of the list initializer.
braceDepth += 1;
}
if (braceDepth > 0 && c == CLOSE_BRACE) {
if (braceDepth > 0 && c == CLOSE_BRACE)
{
braceDepth -= 1;
}

if (braceDepth == 0 && c == SEPARATOR) {
if (braceDepth == 0 && c == SEPARATOR)
{
// when we hit a separator we store the currently accumlated part, and clear to start collecting the next.
split.emplace_back(part);
part = "";
Expand Down
5 changes: 3 additions & 2 deletions source/MaterialXCore/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ AggregateValuePtr AggregateValue::createAggregateValueFromString(const string& v

if (subValues.size() != members.size())
{
printf("ERROR wrong number of initializers - expect %zu\n", members.size());
return nullptr;
std::stringstream ss;
ss << "Wrong number of initializers - expect " << members.size();
throw Exception(ss.str());
}

auto doc = typeDefPtr->getDocument();
Expand Down
20 changes: 0 additions & 20 deletions source/MaterialXGenGlsl/GlslSyntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,24 +411,4 @@ string GlslStructTypeSyntax::getValue(const Value& value, bool uniform) const
return result;
}

string GlslStructTypeSyntax::getValue(const StringVec& values, bool /*uniform*/) const
{
if (values.empty())
{
throw ExceptionShaderGenError("No values given to construct a value");
}

// Write the value using a stream to maintain any float formatting set
// using Value::setFloatFormat() and Value::setFloatPrecision()
StringStream ss;
ss << getTypeDefinition() << "(" << values[0];
for (size_t i = 1; i < values.size(); ++i)
{
ss << ";" << values[i];
}
ss << "}";

return ss.str();
}

MATERIALX_NAMESPACE_END
4 changes: 0 additions & 4 deletions source/MaterialXGenGlsl/GlslSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class MX_GENGLSL_API GlslSyntax : public Syntax
StructTypeSyntaxPtr createStructSyntax(const string& structTypeName, const string& defaultValue,
const string& uniformDefaultValue, const string& typeAlias,
const string& typeDefinition) const override;

};

/// Specialization of TypeSyntax for aggregate types.
Expand All @@ -62,9 +61,6 @@ class MX_GENSHADER_API GlslStructTypeSyntax : public StructTypeSyntax
using StructTypeSyntax::StructTypeSyntax;

string getValue(const Value& value, bool uniform) const override;
string getValue(const StringVec& values, bool uniform) const override;


};

MATERIALX_NAMESPACE_END
Expand Down
2 changes: 1 addition & 1 deletion source/MaterialXGenShader/Syntax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ StructTypeSyntax::StructTypeSyntax(const Syntax* parentSyntax, const string& nam

string StructTypeSyntax::getValue(const Value& value, bool /*uniform*/) const
{
const AggregateValue& aggValue = dynamic_cast<const AggregateValue&>(value);
const AggregateValue& aggValue = static_cast<const AggregateValue&>(value);

auto typeDesc = TypeDesc::get(aggValue.getTypeString());
auto structTypeDesc = StructTypeDesc::get(typeDesc.getStructIndex());
Expand Down
1 change: 0 additions & 1 deletion source/MaterialXGenShader/Syntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ class MX_GENSHADER_API StructTypeSyntax : public TypeSyntax
const StringVec& members = EMPTY_MEMBERS);

string getValue(const Value& value, bool uniform) const override;
string getValue(const StringVec& values, bool uniform) const override;

protected:

Expand Down
21 changes: 7 additions & 14 deletions source/MaterialXGenShader/TypeDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

using StructTypeDescStorage = std::vector<StructTypeDesc>;
using StructTypeDescStorage = vector<StructTypeDesc>;
StructTypeDescStorage& structTypeStorage()
{
static StructTypeDescStorage storage;
Expand Down Expand Up @@ -81,13 +81,6 @@ ValuePtr TypeDesc::createValueFromStrings(const string& value) const
if (!isStruct())
return newValue;

//
// if (newValue == nullptr || newValue->getTypeString() != "string" || getName() == "string" ) {
// // if newValue isn't the fallback to a string, or is really string type, then we
// // are done and we can use this value
// return newValue;
// }

// otherwise we are a struct type - and need to create a new aggregate value
StringVec subValues = splitListInitializer(value);

Expand All @@ -107,7 +100,7 @@ ValuePtr TypeDesc::createValueFromStrings(const string& value) const
return result;
}

TypeDescRegistry::TypeDescRegistry(TypeDesc type, const std::string& name)
TypeDescRegistry::TypeDescRegistry(TypeDesc type, const string& name)
{
TypeDescMap& types = typeMap();
TypeDescNameMap& typenames = typeNameMap();
Expand Down Expand Up @@ -153,15 +146,15 @@ TYPEDESC_REGISTER_TYPE(MATERIAL, "material")
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

void StructTypeDesc::addMember(const std::string& name, TypeDesc type, std::string defaultValueStr)
void StructTypeDesc::addMember(const string& name, TypeDesc type, string defaultValueStr)
{
_members.emplace_back( StructTypeDesc::StructMemberTypeDesc(name, type, defaultValueStr) );
}

std::vector<std::string> StructTypeDesc::getStructTypeNames()
vector<string> StructTypeDesc::getStructTypeNames()
{
StructTypeDescStorage& structs = structTypeStorage();
std::vector<std::string> structNames;
vector<string> structNames;
for (const auto& x : structs) {
structNames.emplace_back( x.typeDesc().getName() );
}
Expand Down Expand Up @@ -197,7 +190,7 @@ const string& StructTypeDesc::getName() const
return _typedesc.getName();
}

const std::vector<StructTypeDesc::StructMemberTypeDesc>& StructTypeDesc::getMembers() const
const vector<StructTypeDesc::StructMemberTypeDesc>& StructTypeDesc::getMembers() const
{
return _members;
}
Expand All @@ -210,7 +203,7 @@ TypeDesc createStructTypeDesc(std::string_view name)
void registerStructTypeDesc(std::string_view name)
{
auto structTypeDesc = createStructTypeDesc(name);
TypeDescRegistry register_struct(structTypeDesc, std::string(name));
TypeDescRegistry register_struct(structTypeDesc, string(name));
}

MATERIALX_NAMESPACE_END
Loading

0 comments on commit 42b3e6d

Please sign in to comment.