From 1d5ac95ec6007c6a7f39bbd8ec326d6aa243ccaa Mon Sep 17 00:00:00 2001 From: Jonathan Stone Date: Sat, 17 Feb 2024 15:14:43 -0800 Subject: [PATCH] Simplify render test suite (#1717) --- resources/Materials/TestSuite/_options.mtlx | 49 ------- .../pbrlib/bsdf/generalized_schlick.mtlx | 2 +- .../pbrlib/bsdf/wedge_conductor.mtlx | 25 ---- .../pbrlib/displacement/displacement.mtlx | 4 +- .../pbrlib/multioutput/multishaderoutput.mtlx | 4 +- .../surfacematerial_with_graph.mtlx | 52 +++---- .../MaterialXGenShader/GenShaderUtil.cpp | 66 --------- .../MaterialXGenShader/GenShaderUtil.h | 10 -- .../MaterialXRender/RenderUtil.cpp | 128 +----------------- .../MaterialXRender/RenderUtil.h | 4 - .../MaterialXRenderGlsl/RenderGlsl.cpp | 38 ------ .../MaterialXRenderMsl/RenderMsl.mm | 38 ------ 12 files changed, 33 insertions(+), 387 deletions(-) delete mode 100644 resources/Materials/TestSuite/pbrlib/bsdf/wedge_conductor.mtlx diff --git a/resources/Materials/TestSuite/_options.mtlx b/resources/Materials/TestSuite/_options.mtlx index 74bfe1eb35..99db2a9f50 100644 --- a/resources/Materials/TestSuite/_options.mtlx +++ b/resources/Materials/TestSuite/_options.mtlx @@ -11,23 +11,6 @@ can also be performed depending on the options enabled. --> - - - - - - - - - - - - - - - - - @@ -95,37 +78,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx b/resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx index cb36a8957d..a320dcda9a 100644 --- a/resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx +++ b/resources/Materials/TestSuite/pbrlib/bsdf/generalized_schlick.mtlx @@ -1,6 +1,6 @@ - + diff --git a/resources/Materials/TestSuite/pbrlib/bsdf/wedge_conductor.mtlx b/resources/Materials/TestSuite/pbrlib/bsdf/wedge_conductor.mtlx deleted file mode 100644 index 4e34fdc4a1..0000000000 --- a/resources/Materials/TestSuite/pbrlib/bsdf/wedge_conductor.mtlx +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/resources/Materials/TestSuite/pbrlib/displacement/displacement.mtlx b/resources/Materials/TestSuite/pbrlib/displacement/displacement.mtlx index 6ea8b7e90d..d0ef073583 100644 --- a/resources/Materials/TestSuite/pbrlib/displacement/displacement.mtlx +++ b/resources/Materials/TestSuite/pbrlib/displacement/displacement.mtlx @@ -1,6 +1,6 @@ - + @@ -21,7 +21,7 @@ - + diff --git a/resources/Materials/TestSuite/pbrlib/multioutput/multishaderoutput.mtlx b/resources/Materials/TestSuite/pbrlib/multioutput/multishaderoutput.mtlx index 7456b088d9..f6dacf6ed5 100644 --- a/resources/Materials/TestSuite/pbrlib/multioutput/multishaderoutput.mtlx +++ b/resources/Materials/TestSuite/pbrlib/multioutput/multishaderoutput.mtlx @@ -1,6 +1,6 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/resources/Materials/TestSuite/pbrlib/surfaceshader/surfacematerial_with_graph.mtlx b/resources/Materials/TestSuite/pbrlib/surfaceshader/surfacematerial_with_graph.mtlx index 203aae6be4..1ea487a503 100644 --- a/resources/Materials/TestSuite/pbrlib/surfaceshader/surfacematerial_with_graph.mtlx +++ b/resources/Materials/TestSuite/pbrlib/surfaceshader/surfacematerial_with_graph.mtlx @@ -1,10 +1,6 @@ - - - - - + @@ -12,42 +8,46 @@ - - - + + + - + + - - - - - - + + + + + + + + + + + + - + + + + + - - - - - - - - + + - - + diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp index aa6d084347..5aa1d7aa2d 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.cpp @@ -965,8 +965,6 @@ bool TestSuiteOptions::readOptions(const std::string& optionFile) const std::string EXTRA_LIBRARY_PATHS("extraLibraryPaths"); const std::string RENDER_TEST_PATHS("renderTestPaths"); const std::string ENABLE_REFERENCE_QUALITY("enableReferenceQuality"); - const std::string WEDGE_SETTING("wedgerender"); - const std::string BAKER_SETTINGS("baker"); overrideFiles.clear(); dumpGeneratedCode = false; @@ -983,70 +981,6 @@ bool TestSuiteOptions::readOptions(const std::string& optionFile) mx::NodeDefPtr optionDefs = doc->getNodeDef(RENDER_TEST_OPTIONS_STRING); if (optionDefs) { - // Read Wedge Render Settings - for (mx::ElementPtr p : optionDefs->getChildrenOfType(WEDGE_SETTING)) - { - WedgeSetting setting; - for (auto child : p->getChildren()) - { - mx::InputPtr input = child->asA(); - const std::string& name = input->getName(); - mx::ValuePtr val = input->getValue(); - - if (name == "file") - { - setting.wedgeFile = val->asA(); - } - else if (name == "parameter") - { - setting.parameter = val->asA(); - } - else if (name == "range") - { - setting.range = val->asA(); - } - else if (name == "steps") - { - setting.steps = val->asA(); - } - } - wedgeSettings.push_back(setting); - } - - // Read Baker Settings - for (mx::ElementPtr p : optionDefs->getChildrenOfType(BAKER_SETTINGS)) - { - BakeSetting setting; - for (auto child : p->getChildren()) - { - mx::InputPtr input = child->asA(); - const std::string& name = input->getName(); - mx::ValuePtr val = input->getValue(); - - if (name == "file") - { - setting.bakeFile = val->asA(); - } - else if (name == "resolution") - { - setting.resolution = val->asA(); - } - else if (name == "hdr") - { - setting.hdr = val->asA(); - } - else if (name == "uvmin") - { - setting.uvmin = val->asA(); - } - else if (name == "uvmax") - { - setting.uvmax = val->asA(); - } - } - bakeSettings.push_back(setting); - } - for (auto p : optionDefs->getInputs()) { const std::string& name = p->getName(); diff --git a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h index 9c471466aa..2bac14e435 100644 --- a/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h +++ b/source/MaterialXTest/MaterialXGenShader/GenShaderUtil.h @@ -131,16 +131,6 @@ class TestSuiteOptions // Enable reference quality rendering. Default is false. bool enableReferenceQuality; - // Wedge parameters - struct WedgeSetting - { - std::string wedgeFile; - std::string parameter; - mx::Vector2 range; - int steps; - }; - std::vector wedgeSettings; - // Bake parameters struct BakeSetting { diff --git a/source/MaterialXTest/MaterialXRender/RenderUtil.cpp b/source/MaterialXTest/MaterialXRender/RenderUtil.cpp index 0460f9282a..cabcaca9a4 100644 --- a/source/MaterialXTest/MaterialXRender/RenderUtil.cpp +++ b/source/MaterialXTest/MaterialXRender/RenderUtil.cpp @@ -256,22 +256,6 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath) mx::FilePath outputPath = mx::FilePath(dir) / file; outputPath.removeExtension(); - // Perform bake and use that file for rendering - if (canBake()) - { - for (auto& doctoBake : options.bakeSettings) - { - mx::FilePath outputBakeFile = file; - if (doctoBake.bakeFile == outputBakeFile.asString()) - { - outputBakeFile.removeExtension(); - outputBakeFile = outputPath / (outputBakeFile.asString() + "_baked.mtlx"); - runBake(doc, imageSearchPath, outputBakeFile, doctoBake, log); - break; - } - } - } - renderableSearchTimer.startTimer(); std::vector elements; try @@ -287,116 +271,8 @@ bool ShaderRenderTester::validate(const mx::FilePath optionsFilePath) for (const auto& element : elements) { - const mx::string elementName = mx::createValidName(mx::replaceSubstrings(element->getNamePath(), pathMap)); - - auto it = std::find_if(options.wedgeSettings.begin(), options.wedgeSettings.end(), - [&file] (const GenShaderUtil::TestSuiteOptions::WedgeSetting& setting) { - return (file.asString() == setting.wedgeFile); - }); - - const bool performWedge = (it != options.wedgeSettings.end()) ? true : false; - if (!performWedge) - { - runRenderer(elementName, element, context, doc, log, options, profileTimes, imageSearchPath, outputPath, nullptr); - } - else - { - for (auto &wedgesetting: options.wedgeSettings) - { - mx::ImageVec imageVec; - - const std::string& wedgeFile = wedgesetting.wedgeFile; - if (wedgeFile != file.asString()) - { - continue; - } - - // Make this a utility - std::string parameterPath = wedgesetting.parameter; - mx::ElementPtr uniformElement = doc->getDescendant(parameterPath); - if (!uniformElement) - { - std::string nodePath = mx::parentNamePath(parameterPath); - mx::ElementPtr uniformParent = doc->getDescendant(nodePath); - if (uniformParent) - { - mx::NodePtr uniformNode = uniformParent->asA(); - if (uniformNode) - { - mx::StringVec pathVec = mx::splitNamePath(parameterPath); - uniformNode->addInputFromNodeDef(pathVec[pathVec.size() - 1]); - } - } - } - uniformElement = doc->getDescendant(parameterPath); - mx::ValueElementPtr valueElement = uniformElement ? uniformElement->asA() : nullptr; - if (!valueElement) - { - continue; - } - - mx::ValuePtr origPropertyValue(valueElement ? valueElement->getValue() : nullptr); - mx::ValuePtr newValue = valueElement->getValue(); - - float wedgePropertyMin = wedgesetting.range[0]; - float wedgePropertyMax = wedgesetting.range[1]; - int wedgeImageCount = std::max(wedgesetting.steps, 2); - - float wedgePropertyStep = (wedgePropertyMax - wedgePropertyMin) / (wedgeImageCount - 1); - for (int w = 0; w < wedgeImageCount; w++) - { - bool setValue = false; - float propertyValue = (w == wedgeImageCount - 1) ? wedgePropertyMax : wedgePropertyMin + wedgePropertyStep * w; - if (origPropertyValue->isA()) - { - valueElement->setValue(static_cast(propertyValue)); - setValue = true; - } - else if (origPropertyValue->isA()) - { - valueElement->setValue(propertyValue); - setValue = true; - } - else if (origPropertyValue->isA()) - { - mx::Vector2 val(propertyValue, propertyValue); - valueElement->setValue(val); - setValue = true; - } - else if (origPropertyValue->isA() || - origPropertyValue->isA()) - { - mx::Vector3 val(propertyValue, propertyValue, propertyValue); - valueElement->setValue(val); - setValue = true; - } - else if (origPropertyValue->isA() || - origPropertyValue->isA()) - { - mx::Vector4 val(propertyValue, propertyValue, propertyValue, origPropertyValue->isA() ? 1.0f : propertyValue); - valueElement->setValue(val); - setValue = true; - } - - if (setValue) - { - runRenderer(elementName, element, context, doc, log, options, profileTimes, imageSearchPath, outputPath, &imageVec); - } - } - - if (!imageVec.empty()) - { - mx::ImagePtr wedgeImage = mx::createImageStrip(imageVec); - if (wedgeImage) - { - std::string wedgeFileName = mx::createValidName(mx::replaceSubstrings(parameterPath, pathMap)); - wedgeFileName += "_" + _shaderGenerator->getTarget() + ".bmp"; - mx::FilePath wedgePath = outputPath / wedgeFileName; - saveImage(wedgePath, wedgeImage, true); - } - } - } - } + mx::string elementName = mx::createValidName(mx::replaceSubstrings(element->getNamePath(), pathMap)); + runRenderer(elementName, element, context, doc, log, options, profileTimes, imageSearchPath, outputPath, nullptr); } } } diff --git a/source/MaterialXTest/MaterialXRender/RenderUtil.h b/source/MaterialXTest/MaterialXRender/RenderUtil.h index b29145dcb1..15eb5778f6 100644 --- a/source/MaterialXTest/MaterialXRender/RenderUtil.h +++ b/source/MaterialXTest/MaterialXRender/RenderUtil.h @@ -165,10 +165,6 @@ class ShaderRenderTester std::ostream& stream, mx::DocumentPtr dependLib); - virtual bool canBake() const { return false; } - virtual void runBake(mx::DocumentPtr /*doc*/, const mx::FileSearchPath& /*codeSearchPath*/, const mx::FilePath& /*outputFilename*/, - const GenShaderUtil::TestSuiteOptions::BakeSetting& /*bakeOptions*/, std::ostream& /*log*/) {}; - // If these streams don't exist add them for testing purposes void addAdditionalTestStreams(mx::MeshPtr mesh); diff --git a/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp b/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp index 719914a62e..01e0875727 100644 --- a/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp +++ b/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -54,14 +53,6 @@ class GlslShaderRenderTester : public RenderUtil::ShaderRenderTester bool saveImage(const mx::FilePath& filePath, mx::ConstImagePtr image, bool verticalFlip) const override; - bool canBake() const override - { - return true; - } - - void runBake(mx::DocumentPtr doc, const mx::FileSearchPath& imageSearchPath, const mx::FilePath& outputFilename, - const GenShaderUtil::TestSuiteOptions::BakeSetting& bakeOptions, std::ostream& log) override; - mx::GlslRendererPtr _renderer; mx::LightHandlerPtr _lightHandler; }; @@ -421,35 +412,6 @@ bool GlslShaderRenderTester::runRenderer(const std::string& shaderName, return true; } -void GlslShaderRenderTester::runBake(mx::DocumentPtr doc, const mx::FileSearchPath& imageSearchPath, const mx::FilePath& outputFileName, - const GenShaderUtil::TestSuiteOptions::BakeSetting& bakeOptions, std::ostream& log) -{ - mx::ImageVec imageVec = _renderer->getImageHandler()->getReferencedImages(doc); - auto maxImageSize = mx::getMaxDimensions(imageVec); - const unsigned bakeWidth = std::max(bakeOptions.resolution, maxImageSize.first); - const unsigned bakeHeight = std::max(bakeOptions.resolution, maxImageSize.second); - - mx::Image::BaseType baseType = bakeOptions.hdr ? mx::Image::BaseType::FLOAT : mx::Image::BaseType::UINT8; - mx::TextureBakerPtr baker = mx::TextureBakerGlsl::create(bakeWidth, bakeHeight, baseType); - baker->setupUnitSystem(doc); - baker->setImageHandler(_renderer->getImageHandler()); - baker->setOptimizeConstants(true); - baker->setHashImageNames(true); - baker->setTextureSpaceMin(bakeOptions.uvmin); - baker->setTextureSpaceMax(bakeOptions.uvmax); - - try - { - baker->setOutputStream(&log); - baker->bakeAllMaterials(doc, imageSearchPath, outputFileName); - } - catch (mx::Exception& e) - { - const mx::FilePath& sourceUri = doc->getSourceUri(); - log << sourceUri.asString() + " failed baking process: " + e.what() << std::endl; - } -} - TEST_CASE("Render: GLSL TestSuite", "[renderglsl]") { mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath(); diff --git a/source/MaterialXTest/MaterialXRenderMsl/RenderMsl.mm b/source/MaterialXTest/MaterialXRenderMsl/RenderMsl.mm index 248d458542..be5b8aa616 100644 --- a/source/MaterialXTest/MaterialXRenderMsl/RenderMsl.mm +++ b/source/MaterialXTest/MaterialXRenderMsl/RenderMsl.mm @@ -17,7 +17,6 @@ #endif #include -#include #include @@ -58,14 +57,6 @@ bool runRenderer(const std::string& shaderName, bool saveImage(const mx::FilePath& filePath, mx::ConstImagePtr image, bool verticalFlip) const override; - bool canBake() const override - { - return true; - } - - void runBake(mx::DocumentPtr doc, const mx::FileSearchPath& imageSearchPath, const mx::FilePath& outputFilename, - const GenShaderUtil::TestSuiteOptions::BakeSetting& bakeOptions, std::ostream& log) override; - mx::MslRendererPtr _renderer; mx::LightHandlerPtr _lightHandler; id _device; @@ -427,35 +418,6 @@ void runBake(mx::DocumentPtr doc, const mx::FileSearchPath& imageSearchPath, con return true; } -void MslShaderRenderTester::runBake(mx::DocumentPtr doc, const mx::FileSearchPath& imageSearchPath, const mx::FilePath& outputFileName, - const GenShaderUtil::TestSuiteOptions::BakeSetting& bakeOptions, std::ostream& log) -{ - mx::ImageVec imageVec = _renderer->getImageHandler()->getReferencedImages(doc); - auto maxImageSize = mx::getMaxDimensions(imageVec); - const unsigned bakeWidth = std::max(bakeOptions.resolution, maxImageSize.first); - const unsigned bakeHeight = std::max(bakeOptions.resolution, maxImageSize.second); - - mx::Image::BaseType baseType = bakeOptions.hdr ? mx::Image::BaseType::FLOAT : mx::Image::BaseType::UINT8; - mx::TextureBakerPtr baker = mx::TextureBakerMsl::create(bakeWidth, bakeHeight, baseType); - baker->setupUnitSystem(doc); - baker->setImageHandler(_renderer->getImageHandler()); - baker->setOptimizeConstants(true); - baker->setHashImageNames(true); - baker->setTextureSpaceMin(bakeOptions.uvmin); - baker->setTextureSpaceMax(bakeOptions.uvmax); - - try - { - baker->setOutputStream(&log); - baker->bakeAllMaterials(doc, imageSearchPath, outputFileName); - } - catch (mx::Exception& e) - { - const mx::FilePath& sourceUri = doc->getSourceUri(); - log << sourceUri.asString() + " failed baking process: " + e.what() << std::endl; - } -} - TEST_CASE("Render: MSL TestSuite", "[rendermsl]") { mx::FileSearchPath searchPath = mx::getDefaultDataSearchPath();