Skip to content

Commit

Permalink
Added optional GpuAnnoation and TracyInstruemntation setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Jan 9, 2024
1 parent 22c99ca commit d73ec0b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions examples/threading/vsgdynamicload/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
56 changes: 52 additions & 4 deletions examples/threading/vsgdynamicload/vsgdynamicload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
# include <vsgXchange/all.h>
#endif

#ifdef Tracy_FOUND
# include <vsg/utils/TracyInstrumentation.h>
#endif

#include <algorithm>
#include <chrono>
#include <iostream>
#include <thread>

vsg::ref_ptr<vsg::Node> decorateWithInstrumentationNode(vsg::ref_ptr<vsg::Node> 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<vsg::Operation, Merge>
{
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):
Expand Down Expand Up @@ -53,7 +68,7 @@ struct LoadOperation : public vsg::Inherit<vsg::Operation, LoadOperation>

void run() override
{
vsg::ref_ptr<vsg::Viewer > ref_viewer = viewer;
vsg::ref_ptr<vsg::Viewer> ref_viewer = viewer;

// std::cout << "Loading " << filename << std::endl;
if (auto node = vsg::read_cast<vsg::Node>(filename, options))
Expand All @@ -66,11 +81,16 @@ struct LoadOperation : public vsg::Inherit<vsg::Operation, LoadOperation>
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<bool>(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));
}
}
};
Expand Down Expand Up @@ -110,7 +130,33 @@ int main(int argc, char** argv)
vsg::ref_ptr<vsg::ResourceHints> resourceHints;
if (vsg::Path resourceFile; arguments.read("--resource", resourceFile)) resourceHints = vsg::read_cast<vsg::ResourceHints>(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<vsg::Instrumentation> 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)
{
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit d73ec0b

Please sign in to comment.