44# include < vsgXchange/all.h>
55#endif
66
7+ #ifdef Tracy_FOUND
8+ # include < vsg/utils/TracyInstrumentation.h>
9+ #endif
10+
711#include < algorithm>
812#include < chrono>
913#include < iostream>
1014#include < thread>
1115
16+ vsg::ref_ptr<vsg::Node> decorateWithInstrumentationNode (vsg::ref_ptr<vsg::Node> node, const std::string& name, vsg::uint_color color)
17+ {
18+ auto instrumentationNode = vsg::InstrumentationNode::create (node);
19+ instrumentationNode->setName (name);
20+ instrumentationNode->setColor (color);
21+
22+ vsg::info (" decorateWithInstrumentationNode(" , node, " , " , name, " , {" , int (color.r ), " , " , int (color.g ), " , " , int (color.b ), " , " , int (color.a ), " })" );
23+
24+ return instrumentationNode;
25+ }
26+
1227struct Merge : public vsg ::Inherit<vsg::Operation, Merge>
1328{
1429 Merge (const vsg::Path& in_path, vsg::observer_ptr<vsg::Viewer> in_viewer, vsg::ref_ptr<vsg::Group> in_attachmentPoint, vsg::ref_ptr<vsg::Node> in_node, const vsg::CompileResult& in_compileResult):
@@ -53,7 +68,7 @@ struct LoadOperation : public vsg::Inherit<vsg::Operation, LoadOperation>
5368
5469 void run () override
5570 {
56- vsg::ref_ptr<vsg::Viewer > ref_viewer = viewer;
71+ vsg::ref_ptr<vsg::Viewer> ref_viewer = viewer;
5772
5873 // std::cout << "Loading " << filename << std::endl;
5974 if (auto node = vsg::read_cast<vsg::Node>(filename, options))
@@ -66,11 +81,16 @@ struct LoadOperation : public vsg::Inherit<vsg::Operation, LoadOperation>
6681 vsg::dvec3 centre = (computeBounds.bounds .min + computeBounds.bounds .max ) * 0.5 ;
6782 double radius = vsg::length (computeBounds.bounds .max - computeBounds.bounds .min ) * 0.5 ;
6883 auto scale = vsg::MatrixTransform::create (vsg::scale (1.0 / radius, 1.0 / radius, 1.0 / radius) * vsg::translate (-centre));
69-
7084 scale->addChild (node);
85+ node = scale;
86+
87+ if (vsg::value<bool >(false , " decorate" , options))
88+ {
89+ node = decorateWithInstrumentationNode (node, filename.string (), vsg::uint_color (255 , 255 , 64 , 255 ));
90+ }
7191
7292 auto result = ref_viewer->compileManager ->compile (node);
73- if (result) ref_viewer->addUpdateOperation (Merge::create (filename, viewer, attachmentPoint, scale , result));
93+ if (result) ref_viewer->addUpdateOperation (Merge::create (filename, viewer, attachmentPoint, node , result));
7494 }
7595 }
7696};
@@ -110,7 +130,33 @@ int main(int argc, char** argv)
110130 vsg::ref_ptr<vsg::ResourceHints> resourceHints;
111131 if (vsg::Path resourceFile; arguments.read (" --resource" , resourceFile)) resourceHints = vsg::read_cast<vsg::ResourceHints>(resourceFile);
112132
113- if (arguments.errors ()) return arguments.writeErrorMessages (std::cerr);
133+ // Use --decorate command line option to set "decorate" user Options value.
134+ // this will be checked by the MergeOperation to decide wither to decorate the loaded subgraph with a InstrumentationNode
135+ options->setValue (" decorate" , arguments.read (" --decorate" ));
136+
137+ vsg::ref_ptr<vsg::Instrumentation> instrumentation;
138+ if (arguments.read ({" --gpu-annotation" , " --ga" }) && vsg::isExtensionSupported (VK_EXT_DEBUG_UTILS_EXTENSION_NAME))
139+ {
140+ windowTraits->debugUtils = true ;
141+
142+ auto gpu_instrumentation = vsg::GpuAnnotation::create ();
143+ if (arguments.read (" --func" )) gpu_instrumentation->labelType = vsg::GpuAnnotation::SourceLocation_function;
144+
145+ instrumentation = gpu_instrumentation;
146+ }
147+ #ifdef Tracy_FOUND
148+ else if (arguments.read (" --tracy" ))
149+ {
150+ windowTraits->deviceExtensionNames .push_back (VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME);
151+
152+ auto tracy_instrumentation = vsg::TracyInstrumentation::create ();
153+ arguments.read (" --cpu" , tracy_instrumentation->settings ->cpu_instumentation_level );
154+ arguments.read (" --gpu" , tracy_instrumentation->settings ->gpu_instumentation_level );
155+ instrumentation = tracy_instrumentation;
156+ }
157+ #endif
158+
159+ if (arguments.errors ()) return arguments.writeErrorMessages (std::cerr);
114160
115161 if (argc <= 1 )
116162 {
@@ -162,6 +208,8 @@ int main(int argc, char** argv)
162208 auto commandGraph = vsg::createCommandGraphForView (window, camera, vsg_scene);
163209 viewer->assignRecordAndSubmitTaskAndPresentation ({commandGraph});
164210
211+ if (instrumentation) viewer->assignInstrumentation (instrumentation);
212+
165213 if (!resourceHints)
166214 {
167215 // To help reduce the number of vsg::DescriptorPool that need to be allocated we'll provide a minimum requirement via ResourceHints.
0 commit comments