diff --git a/examples/threading/vsgdynamicload/CMakeLists.txt b/examples/threading/vsgdynamicload/CMakeLists.txt index 4dc55312..e6d7a65d 100644 --- a/examples/threading/vsgdynamicload/CMakeLists.txt +++ b/examples/threading/vsgdynamicload/CMakeLists.txt @@ -11,4 +11,9 @@ if (vsgXchange_FOUND) target_link_libraries(vsgdynamicload vsgXchange::vsgXchange) endif() +if (Tracy_FOUND) + target_compile_definitions(vsgdynamicload PRIVATE Tracy_FOUND) + target_link_libraries(vsgdynamicload Tracy::TracyClient) +endif() + install(TARGETS vsgdynamicload RUNTIME DESTINATION bin) diff --git a/examples/threading/vsgdynamicload/vsgdynamicload.cpp b/examples/threading/vsgdynamicload/vsgdynamicload.cpp index e249af4f..417cf9cf 100644 --- a/examples/threading/vsgdynamicload/vsgdynamicload.cpp +++ b/examples/threading/vsgdynamicload/vsgdynamicload.cpp @@ -4,11 +4,26 @@ # include #endif +#ifdef Tracy_FOUND +# include +#endif + #include #include #include #include +vsg::ref_ptr decorateWithInstrumentationNode(vsg::ref_ptr node, const std::string& name, vsg::uint_color color) +{ + auto instrumentationNode = vsg::InstrumentationNode::create(node); + instrumentationNode->setName(name); + instrumentationNode->setColor(color); + + vsg::info("decorateWithInstrumentationNode(", node, ", ", name, ", {", int(color.r), ", ", int(color.g), ", ", int(color.b), ", ", int(color.a), "})"); + + return instrumentationNode; +} + struct Merge : public vsg::Inherit { Merge(const vsg::Path& in_path, vsg::observer_ptr in_viewer, vsg::ref_ptr in_attachmentPoint, vsg::ref_ptr in_node, const vsg::CompileResult& in_compileResult): @@ -53,7 +68,7 @@ struct LoadOperation : public vsg::Inherit void run() override { - vsg::ref_ptr ref_viewer = viewer; + vsg::ref_ptr ref_viewer = viewer; // std::cout << "Loading " << filename << std::endl; if (auto node = vsg::read_cast(filename, options)) @@ -66,11 +81,16 @@ struct LoadOperation : public vsg::Inherit vsg::dvec3 centre = (computeBounds.bounds.min + computeBounds.bounds.max) * 0.5; double radius = vsg::length(computeBounds.bounds.max - computeBounds.bounds.min) * 0.5; auto scale = vsg::MatrixTransform::create(vsg::scale(1.0 / radius, 1.0 / radius, 1.0 / radius) * vsg::translate(-centre)); - scale->addChild(node); + node = scale; + + if (vsg::value(false, "decorate", options)) + { + node = decorateWithInstrumentationNode(node, filename.string(), vsg::uint_color(255, 255, 64, 255)); + } auto result = ref_viewer->compileManager->compile(node); - if (result) ref_viewer->addUpdateOperation(Merge::create(filename, viewer, attachmentPoint, scale, result)); + if (result) ref_viewer->addUpdateOperation(Merge::create(filename, viewer, attachmentPoint, node, result)); } } }; @@ -110,7 +130,33 @@ int main(int argc, char** argv) vsg::ref_ptr resourceHints; if (vsg::Path resourceFile; arguments.read("--resource", resourceFile)) resourceHints = vsg::read_cast(resourceFile); - if (arguments.errors()) return arguments.writeErrorMessages(std::cerr); + // Use --decorate command line option to set "decorate" user Options value. + // this will be checked by the MergeOperation to decide wither to decorate the loaded subgraph with a InstrumentationNode + options->setValue("decorate", arguments.read("--decorate")); + + vsg::ref_ptr instrumentation; + if (arguments.read({"--gpu-annotation", "--ga"}) && vsg::isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + { + windowTraits->debugUtils = true; + + auto gpu_instrumentation = vsg::GpuAnnotation::create(); + if (arguments.read("--func")) gpu_instrumentation->labelType = vsg::GpuAnnotation::SourceLocation_function; + + instrumentation = gpu_instrumentation; + } +#ifdef Tracy_FOUND + else if (arguments.read("--tracy")) + { + windowTraits->deviceExtensionNames.push_back(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME); + + auto tracy_instrumentation = vsg::TracyInstrumentation::create(); + arguments.read("--cpu", tracy_instrumentation->settings->cpu_instumentation_level); + arguments.read("--gpu", tracy_instrumentation->settings->gpu_instumentation_level); + instrumentation = tracy_instrumentation; + } +#endif + + if (arguments.errors()) return arguments.writeErrorMessages(std::cerr); if (argc <= 1) { @@ -162,6 +208,8 @@ int main(int argc, char** argv) auto commandGraph = vsg::createCommandGraphForView(window, camera, vsg_scene); viewer->assignRecordAndSubmitTaskAndPresentation({commandGraph}); + if (instrumentation) viewer->assignInstrumentation(instrumentation); + if (!resourceHints) { // To help reduce the number of vsg::DescriptorPool that need to be allocated we'll provide a minimum requirement via ResourceHints.