diff --git a/resources/Materials/TestSuite/_options.mtlx b/resources/Materials/TestSuite/_options.mtlx index 49b0b7cc39..382541d1db 100644 --- a/resources/Materials/TestSuite/_options.mtlx +++ b/resources/Materials/TestSuite/_options.mtlx @@ -79,7 +79,7 @@ --> - diff --git a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp index eb115fe97c..896e7809fb 100644 --- a/source/MaterialXGenGlsl/GlslShaderGenerator.cpp +++ b/source/MaterialXGenGlsl/GlslShaderGenerator.cpp @@ -31,6 +31,8 @@ #include #include +#include + MATERIALX_NAMESPACE_BEGIN const string GlslShaderGenerator::TARGET = "genglsl"; @@ -128,6 +130,9 @@ GlslShaderGenerator::GlslShaderGenerator(TypeSystemPtr typeSystem) : ShaderPtr GlslShaderGenerator::generate(const string& name, ElementPtr element, GenContext& context) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, name.c_str()); + ShaderPtr shader = createShader(name, element, context); // Request fixed floating-point notation for consistency across targets. diff --git a/source/MaterialXGenHw/HwShaderGenerator.cpp b/source/MaterialXGenHw/HwShaderGenerator.cpp index 87e9ff6be5..2ee6173f59 100644 --- a/source/MaterialXGenHw/HwShaderGenerator.cpp +++ b/source/MaterialXGenHw/HwShaderGenerator.cpp @@ -16,6 +16,8 @@ #include #include +#include + MATERIALX_NAMESPACE_BEGIN // @@ -97,6 +99,9 @@ void HwShaderGenerator::applyDefaultOptions(GenOptions& options) const ShaderPtr HwShaderGenerator::createShader(const string& name, ElementPtr element, GenContext& context) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, name.c_str()); + // Create the root shader graph ShaderGraphPtr graph = ShaderGraph::create(nullptr, name, element, context); ShaderPtr shader = std::make_shared(name, graph); diff --git a/source/MaterialXGenShader/CMakeLists.txt b/source/MaterialXGenShader/CMakeLists.txt index 07adb8a732..8a98ccdbb4 100644 --- a/source/MaterialXGenShader/CMakeLists.txt +++ b/source/MaterialXGenShader/CMakeLists.txt @@ -1,14 +1,18 @@ file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*") +set(GENSHADER_MTLX_MODULES MaterialXFormat MaterialXCore) +if(MATERIALX_BUILD_PERFETTO_TRACING) + list(APPEND GENSHADER_MTLX_MODULES MaterialXTrace) +endif() + mx_add_library(MaterialXGenShader SOURCE_FILES ${materialx_source} HEADER_FILES ${materialx_headers} MTLX_MODULES - MaterialXFormat - MaterialXCore + ${GENSHADER_MTLX_MODULES} EXPORT_DEFINE MATERIALX_GENSHADER_EXPORTS) diff --git a/source/MaterialXGenShader/Nodes/CompoundNode.cpp b/source/MaterialXGenShader/Nodes/CompoundNode.cpp index 78713d821f..f25dbbdf7b 100644 --- a/source/MaterialXGenShader/Nodes/CompoundNode.cpp +++ b/source/MaterialXGenShader/Nodes/CompoundNode.cpp @@ -12,6 +12,8 @@ #include #include +#include + MATERIALX_NAMESPACE_BEGIN ShaderNodeImplPtr CompoundNode::create() @@ -27,6 +29,9 @@ void CompoundNode::addClassification(ShaderNode& node) const void CompoundNode::initialize(const InterfaceElement& element, GenContext& context) { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, element.getName().c_str()); + ShaderNodeImpl::initialize(element, context); if (!element.isA()) @@ -62,6 +67,9 @@ void CompoundNode::createVariables(const ShaderNode&, GenContext& context, Shade void CompoundNode::emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, _functionName.c_str()); + DEFINE_SHADER_STAGE(stage, Stage::PIXEL) { const ShaderGenerator& shadergen = context.getShaderGenerator(); @@ -148,6 +156,9 @@ void CompoundNode::emitFunctionDefinition(const ShaderNode& node, GenContext& co void CompoundNode::emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, _functionName.c_str()); + const ShaderGenerator& shadergen = context.getShaderGenerator(); DEFINE_SHADER_STAGE(stage, Stage::VERTEX) diff --git a/source/MaterialXGenShader/ShaderGenerator.cpp b/source/MaterialXGenShader/ShaderGenerator.cpp index 577b7869f0..67d65cd734 100644 --- a/source/MaterialXGenShader/ShaderGenerator.cpp +++ b/source/MaterialXGenShader/ShaderGenerator.cpp @@ -17,6 +17,8 @@ #include #include +#include + #include MATERIALX_NAMESPACE_BEGIN @@ -116,6 +118,9 @@ void ShaderGenerator::emitFunctionDefinitionParameter(const ShaderPort* shaderPo void ShaderGenerator::emitFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, graph.getName().c_str()); + // Emit function definitions for all nodes in the graph. for (ShaderNode* node : graph.getNodes()) { @@ -140,6 +145,9 @@ void ShaderGenerator::emitFunctionCall(const ShaderNode& node, GenContext& conte void ShaderGenerator::emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage, uint32_t classification) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, graph.getName().c_str()); + for (ShaderNode* node : graph.getNodes()) { if (!classification || node->hasClassification(classification)) @@ -307,6 +315,9 @@ ShaderNodeImplPtr ShaderGenerator::createShaderNodeImplForImplementation(const I ShaderNodeImplPtr ShaderGenerator::getImplementation(const NodeDef& nodedef, GenContext& context) const { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, nodedef.getName().c_str()); + InterfaceElementPtr implElement = nodedef.getImplementation(getTarget()); if (!implElement) { diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp index 10c41b757f..1300f5e7a3 100644 --- a/source/MaterialXGenShader/ShaderGraph.cpp +++ b/source/MaterialXGenShader/ShaderGraph.cpp @@ -10,6 +10,8 @@ #include #include +#include + #include #include @@ -79,6 +81,8 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement, ElementPtr connectingElement, GenContext& context) { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + // Create the node if it doesn't exist. NodePtr upstreamNode = upstreamElement->asA(); if (!upstreamNode) @@ -170,6 +174,9 @@ void ShaderGraph::createConnectedNodes(const ElementPtr& downstreamElement, void ShaderGraph::addUpstreamDependencies(const Element& root, GenContext& context) { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, root.getName().c_str()); + std::set processedOutputs; for (Edge edge : root.traverseGraph()) @@ -698,6 +705,9 @@ void ShaderGraph::applyInputTransforms(ConstNodePtr node, ShaderNode* shaderNode ShaderNode* ShaderGraph::createNode(const string& name, const string& uniqueId, ConstNodeDefPtr nodeDef, GenContext& context) { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, name.c_str()); + if (!nodeDef) { throw ExceptionShaderGenError("Could not find a nodedef for node '" + name + "'"); diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp index 843cef071f..7c6b40ff7d 100644 --- a/source/MaterialXGenShader/ShaderNode.cpp +++ b/source/MaterialXGenShader/ShaderNode.cpp @@ -9,6 +9,8 @@ #include #include +#include + MATERIALX_NAMESPACE_BEGIN const string ShaderMetadataRegistry::USER_DATA_NAME = "ShaderMetadataRegistry"; @@ -172,6 +174,9 @@ ShaderNode::ShaderNode(const ShaderGraph* parent, const string& name) : ShaderNodePtr ShaderNode::create(const ShaderGraph* parent, const string& name, const NodeDef& nodeDef, GenContext& context) { + MX_TRACE_FUNCTION(Tracing::Category::ShaderGen); + MX_TRACE_SCOPE(Tracing::Category::ShaderGen, name.c_str()); + ShaderNodePtr newNode = std::make_shared(parent, name); const ShaderGenerator& shadergen = context.getShaderGenerator(); diff --git a/source/MaterialXRenderGlsl/GlslProgram.cpp b/source/MaterialXRenderGlsl/GlslProgram.cpp index 8626a43cd6..f3b0a6a469 100644 --- a/source/MaterialXRenderGlsl/GlslProgram.cpp +++ b/source/MaterialXRenderGlsl/GlslProgram.cpp @@ -13,6 +13,8 @@ #include +#include + #include MATERIALX_NAMESPACE_BEGIN @@ -82,6 +84,8 @@ const string& GlslProgram::getStageSourceCode(const string& stage) const void GlslProgram::build() { + MX_TRACE_FUNCTION(Tracing::Category::Render); + clearBuiltData(); GLint glStatus = GL_FALSE; diff --git a/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp b/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp index 419c18f694..e50810d925 100644 --- a/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp +++ b/source/MaterialXTest/MaterialXRenderGlsl/RenderGlsl.cpp @@ -232,6 +232,7 @@ bool GlslShaderRenderTester::runRenderer(const std::string& shaderName, if (testOptions.dumpGeneratedCode) { + MX_TRACE_SCOPE(mx::Tracing::Category::Render, "DumpGeneratedCode"); mx::ScopedTimer dumpTimer(&profileTimes.languageTimes.ioTime); std::ofstream file; file.open(shaderPath + "_vs.glsl"); @@ -291,6 +292,7 @@ bool GlslShaderRenderTester::runRenderer(const std::string& shaderName, if (testOptions.dumpUniformsAndAttributes) { + MX_TRACE_SCOPE(mx::Tracing::Category::Render, "DumpUniformsAndAttributes"); mx::ScopedTimer printTimer(&profileTimes.languageTimes.ioTime); log << "* Uniform:" << std::endl; program->printUniforms(log); @@ -356,10 +358,12 @@ bool GlslShaderRenderTester::runRenderer(const std::string& shaderName, unsigned int width = (unsigned int) testOptions.renderSize[0] * supersampleFactor; unsigned int height = (unsigned int) testOptions.renderSize[1] * supersampleFactor; _renderer->setSize(width, height); + _renderer->render(); } { + MX_TRACE_SCOPE(mx::Tracing::Category::Render, "CaptureAndSaveImage"); mx::ScopedTimer ioTimer(&profileTimes.languageTimes.imageSaveTime); std::string fileName = shaderPath + "_glsl.png"; mx::ImagePtr image = _renderer->captureImage();