Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Catch2 to version 2.13.10 #1566

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ option(MATERIALX_BUILD_GEN_MSL "Build the MSL shader generator back-end." ON)
option(MATERIALX_BUILD_RENDER "Build the MaterialX Render modules." ON)
option(MATERIALX_BUILD_OIIO "Build OpenImageIO support for MaterialXRender." OFF)
option(MATERIALX_BUILD_TESTS "Build unit tests." ON)
option(MATERIALX_BUILD_BENCHMARK_TESTS "Build benchmark tests." OFF)

option(MATERIALX_BUILD_SHARED_LIBS "Build MaterialX libraries as shared rather than static." OFF)
option(MATERIALX_PYTHON_LTO "Enable link-time optimizations for MaterialX Python." ON)
Expand Down Expand Up @@ -131,6 +132,7 @@ mark_as_advanced(MATERIALX_BUILD_GEN_MSL)
mark_as_advanced(MATERIALX_BUILD_RENDER)
mark_as_advanced(MATERIALX_BUILD_OIIO)
mark_as_advanced(MATERIALX_BUILD_TESTS)
mark_as_advanced(MATERIALX_BUILD_BENCHMARK_TESTS)
mark_as_advanced(MATERIALX_BUILD_SHARED_LIBS)
mark_as_advanced(MATERIALX_NAMESPACE_SUFFIX)
mark_as_advanced(MATERIALX_LIBNAME_SUFFIX)
Expand Down Expand Up @@ -177,6 +179,12 @@ endif()
if(MATERIALX_TEST_RENDER)
add_definitions(-DMATERIALX_TEST_RENDER)
endif()
if (MATERIALX_DYNAMIC_ANALYSIS)
add_definitions(-DMATERIALX_DYNAMIC_ANALYSIS)
ashwinbhat marked this conversation as resolved.
Show resolved Hide resolved
endif()
if (MATERIALX_BUILD_BENCHMARK_TESTS)
add_definitions(-DMATERIALX_BUILD_BENCHMARK_TESTS)
endif()

if (MATERIALX_BUILD_GEN_MDL)
add_definitions(-DMATERIALX_MDLC_EXECUTABLE=\"${MATERIALX_MDLC_EXECUTABLE}\")
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ set_target_properties(
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")

# Enable Catch benchmarking
target_compile_definitions(MaterialXTest PRIVATE -DCATCH_CONFIG_ENABLE_BENCHMARKING)
ashwinbhat marked this conversation as resolved.
Show resolved Hide resolved

target_link_libraries(
MaterialXTest
${CMAKE_DL_LIBS})
28 changes: 17 additions & 11 deletions source/MaterialXTest/External/Catch/catch.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catch v2.13.9
* Generated: 2022-04-12 22:37:23.260201
* Catch v2.13.10
* Generated: 2022-10-16 11:01:23.452308
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2022 Two Blue Cubes Ltd. All rights reserved.
Expand All @@ -15,7 +15,7 @@

#define CATCH_VERSION_MAJOR 2
#define CATCH_VERSION_MINOR 13
#define CATCH_VERSION_PATCH 9
#define CATCH_VERSION_PATCH 10

#ifdef __clang__
# pragma clang system_header
Expand Down Expand Up @@ -7395,8 +7395,6 @@ namespace Catch {
template <typename T, bool Destruct>
struct ObjectStorage
{
using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type;

ObjectStorage() : data() {}

ObjectStorage(const ObjectStorage& other)
Expand Down Expand Up @@ -7439,7 +7437,7 @@ namespace Catch {
return *static_cast<T*>(static_cast<void*>(&data));
}

TStorage data;
struct { alignas(T) unsigned char data[sizeof(T)]; } data;
};
}

Expand Down Expand Up @@ -7949,7 +7947,7 @@ namespace Catch {
#if defined(__i386__) || defined(__x86_64__)
#define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
#elif defined(__aarch64__)
#define CATCH_TRAP() __asm__(".inst 0xd4200000")
#define CATCH_TRAP() __asm__(".inst 0xd43e0000")
#endif

#elif defined(CATCH_PLATFORM_IPHONE)
Expand Down Expand Up @@ -13558,7 +13556,7 @@ namespace Catch {

// Handle list request
if( Option<std::size_t> listed = list( m_config ) )
return static_cast<int>( *listed );
return (std::min) (MaxExitCode, static_cast<int>(*listed));

TestGroup tests { m_config };
auto const totals = tests.execute();
Expand Down Expand Up @@ -15391,7 +15389,7 @@ namespace Catch {
}

Version const& libraryVersion() {
static Version version( 2, 13, 9, "", 0 );
static Version version( 2, 13, 10, "", 0 );
return version;
}

Expand Down Expand Up @@ -17526,12 +17524,20 @@ namespace Catch {

#ifndef __OBJC__

#ifndef CATCH_INTERNAL_CDECL
#ifdef _MSC_VER
#define CATCH_INTERNAL_CDECL __cdecl
#else
#define CATCH_INTERNAL_CDECL
#endif
#endif

#if defined(CATCH_CONFIG_WCHAR) && defined(CATCH_PLATFORM_WINDOWS) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
// Standard C/C++ Win32 Unicode wmain entry point
extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
extern "C" int CATCH_INTERNAL_CDECL wmain (int argc, wchar_t * argv[], wchar_t * []) {
#else
// Standard C/C++ main entry point
int main (int argc, char * argv[]) {
int CATCH_INTERNAL_CDECL main (int argc, char * argv[]) {
#endif

return Catch::Session().run( argc, argv );
Expand Down
13 changes: 13 additions & 0 deletions source/MaterialXTest/MaterialXGenGlsl/GenGlsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ TEST_CASE("GenShader: Bind Light Shaders", "[genglsl]")
REQUIRE_NOTHROW(mx::HwShaderGenerator::bindLightShader(*spotLightShader, 66, context));
}

TEST_CASE("GenShader: Performance Test", "[genglsl]")
{
#ifdef MATERIALX_BUILD_BENCHMARK_TESTS
mx::GenContext context(mx::GlslShaderGenerator::create());
BENCHMARK("Load documents, validate and generate shader")
{
return GenShaderUtil::shaderGenPerformanceTest(context);
};
#else
SUCCEED("Performance tests are disabled");
#endif
}

enum class GlslType
{
Glsl400,
Expand Down
79 changes: 79 additions & 0 deletions source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,85 @@ void testUniqueNames(mx::GenContext& context, const std::string& stage)
REQUIRE(sgNode1->getOutput()->getVariable() == "unique_names_out");
}

// Test ShaderGen performance
void shaderGenPerformanceTest(mx::GenContext& context)
{
mx::DocumentPtr nodeLibrary = mx::createDocument();
mx::FilePath currentPath = mx::FilePath::getCurrentPath();
const mx::FileSearchPath libSearchPath(currentPath);

// Load the standard libraries.
loadLibraries({ "libraries" }, libSearchPath, nodeLibrary);
context.registerSourceCodeSearchPath(libSearchPath);

// Enable Color Management
mx::ColorManagementSystemPtr colorManagementSystem =
mx::DefaultColorManagementSystem::create(context.getShaderGenerator().getTarget());

REQUIRE(colorManagementSystem);
if (colorManagementSystem)
{
context.getShaderGenerator().setColorManagementSystem(colorManagementSystem);
colorManagementSystem->loadLibrary(nodeLibrary);
}

// Enable Unit System
mx::UnitSystemPtr unitSystem = mx::UnitSystem::create(context.getShaderGenerator().getTarget());
REQUIRE(unitSystem);
if (unitSystem)
{
context.getShaderGenerator().setUnitSystem(unitSystem);
unitSystem->loadLibrary(nodeLibrary);
// Setup Unit converters
unitSystem->setUnitConverterRegistry(mx::UnitConverterRegistry::create());
mx::UnitTypeDefPtr distanceTypeDef = nodeLibrary->getUnitTypeDef("distance");
unitSystem->getUnitConverterRegistry()->addUnitConverter(distanceTypeDef, mx::LinearUnitConverter::create(distanceTypeDef));
mx::UnitTypeDefPtr angleTypeDef = nodeLibrary->getUnitTypeDef("angle");
unitSystem->getUnitConverterRegistry()->addUnitConverter(angleTypeDef, mx::LinearUnitConverter::create(angleTypeDef));
context.getOptions().targetDistanceUnit = "meter";
}

// Read mtlx documents
mx::FilePathVec testRootPaths;
testRootPaths.push_back("resources/Materials/Examples/StandardSurface");

std::vector<mx::DocumentPtr> loadedDocuments;
mx::StringVec documentsPaths;
mx::StringVec errorLog;

for (const auto& testRoot : testRootPaths)
{
mx::loadDocuments(testRoot, libSearchPath, {}, {}, loadedDocuments, documentsPaths,
nullptr, &errorLog);
}

REQUIRE(loadedDocuments.size() > 0);
REQUIRE(loadedDocuments.size() == documentsPaths.size());

// Shuffle the order of documents and perform document library import validatation and shadergen
std::random_device random_dev;
std::mt19937 generator(random_dev());
std::shuffle(loadedDocuments.begin(), loadedDocuments.end(), generator);
for (const auto& doc : loadedDocuments)
{
doc->importLibrary(nodeLibrary);
std::vector<mx::TypedElementPtr> elements = mx::findRenderableElements(doc);

REQUIRE(elements.size() > 0);

std::string message;
bool docValid = doc->validate(&message);

REQUIRE(docValid == true);

mx::StringVec sourceCode;
mx::ShaderPtr shader = nullptr;
shader = context.getShaderGenerator().generate(elements[0]->getName(), elements[0], context);

REQUIRE(shader != nullptr);
REQUIRE(shader->getSourceCode(mx::Stage::PIXEL).length() > 0);
}
}

void ShaderGeneratorTester::checkImplementationUsage(const mx::StringSet& usedImpls,
const mx::GenContext& context,
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void checkImplementations(mx::GenContext& context,
// Utility test to check unique name generation on a shader generator
void testUniqueNames(mx::GenContext& context, const std::string& stage);

// Utility to perfrom simple performance test to load, validate and generate shaders
void shaderGenPerformanceTest(mx::GenContext& context);

//
// Render validation options. Reflects the _options.mtlx
// file in the test suite area.
Expand Down