diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 79a43a7451..c901f41057 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -25,6 +25,8 @@ namespace vsg # define VsgFunctionName __FUNCSIG__ #endif + class Device; + class Queue; class CommandBuffer; /// SourceLocation structs mark the location in a source file when instrumentation is placed. @@ -44,6 +46,8 @@ namespace vsg public: Instrumentation(); + // Conceived for the needs of Tracy + virtual void init(vsg::ref_ptr device, vsg::ref_ptr queue, vsg::ref_ptr cmd); virtual void enter(const SourceLocation* sl, uint64_t& reference) const = 0; virtual void leave(const SourceLocation* sl, uint64_t& reference) const = 0; @@ -85,16 +89,16 @@ namespace vsg } }; -#define SCOPED_INSTRUMENTASTION(instrumentation) \ +#define SCOPED_INSTRUMENTATION(instrumentation) \ static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); -#define SCOPED_INSTRUMENTASTION_N(instrumentation, name) \ +#define SCOPED_INSTRUMENTATION_N(instrumentation, name) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); -#define SCOPED_INSTRUMENTASTION_C(instrumentation, color) \ +#define SCOPED_INSTRUMENTATION_C(instrumentation, color) \ static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); -#define SCOPED_INSTRUMENTASTION_NC(instrumentation, name, color) \ +#define SCOPED_INSTRUMENTATION_NC(instrumentation, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index f0d443c7c8..e99d9c457e 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -22,7 +22,7 @@ using namespace vsg; CommandGraph::CommandGraph() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_device, int family) : @@ -30,14 +30,14 @@ CommandGraph::CommandGraph(ref_ptr in_device, int family) : queueFamily(family), presentFamily(-1) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : window(in_window), device(in_window->getOrCreateDevice()) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); VkQueueFlags queueFlags = VK_QUEUE_GRAPHICS_BIT; if (window->traits()) queueFlags = window->traits()->queueFlags; @@ -49,7 +49,7 @@ CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : CommandGraph::~CommandGraph() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -63,7 +63,7 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!recordTraversal) { @@ -80,7 +80,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (window && !window->visible()) { diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index b07958bcc9..5a834ccb6b 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -21,7 +21,7 @@ using namespace vsg; RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) : device(in_device) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) @@ -44,7 +44,7 @@ RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) void RecordAndSubmitTask::advance() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -84,7 +84,7 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (VkResult result = start(); result != VK_SUCCESS) return result; @@ -102,7 +102,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (earlyTransferTask) earlyTransferTask->currentTransferCompletedSemaphore = {}; if (lateTransferTask) lateTransferTask->currentTransferCompletedSemaphore = {}; @@ -120,7 +120,7 @@ VkResult RecordAndSubmitTask::start() VkResult RecordAndSubmitTask::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& commandGraph : commandGraphs) { @@ -132,7 +132,7 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (lateTransferTask) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 35706e8903..27b84aa103 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -49,7 +49,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { // instrumentation = Instrumentation::create(); - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -69,7 +69,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -97,7 +97,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& bin : _bins) { @@ -107,7 +107,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("Visiting Object"); object.traverse(*this); @@ -115,7 +115,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -127,7 +127,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -139,7 +139,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); const auto& sphere = lod.bound; @@ -164,7 +164,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -244,7 +244,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(cullGroup.bound)) { @@ -255,7 +255,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(cullNode.bound)) { @@ -266,7 +266,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -280,7 +280,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& child : sw.children) { @@ -293,14 +293,14 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const Light& /*light*/) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -308,7 +308,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -316,7 +316,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -324,7 +324,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -332,7 +332,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(255, 255, 0, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -353,7 +353,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -375,7 +375,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -398,7 +398,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 255, 0, 255)); _state->record(); for (auto& command : commands.children) @@ -409,7 +409,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 255, 0, 255)); //debug("Visiting Command"); _state->record(); @@ -418,7 +418,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const View& view) { - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -507,7 +507,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index f351d5f550..cc2f096433 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -32,12 +32,12 @@ Viewer::Viewer() : status(vsg::ActivityStatus::create()), _start_point(clock::now()) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } Viewer::~Viewer() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); stopThreading(); @@ -47,7 +47,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); std::set devices; for (auto& window : _windows) @@ -101,7 +101,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); _close = true; status->set(false); @@ -111,7 +111,7 @@ void Viewer::close() bool Viewer::active() const { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); bool viewerIsActive = !_close; if (viewerIsActive) @@ -136,7 +136,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); bool result = false; @@ -151,7 +151,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!active()) return false; @@ -191,7 +191,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_close) return false; @@ -231,7 +231,7 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) @@ -248,7 +248,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& vsg_event : _events) { @@ -261,7 +261,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (recordAndSubmitTasks.empty()) { @@ -420,7 +420,7 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); // now remove any commandGraphs associated with window bool needToStartThreading = _threading; @@ -570,6 +570,16 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr recordAndSubmitTask->earlyTransferTask->transferQueue = transferQueue; recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue; } + if (instrumentation) + { + auto queueFamily = device->getPhysicalDevice()->getQueueFamily(VK_QUEUE_GRAPHICS_BIT); + // VK_COMMAND_POOL_CREATE_TRANSIENT_BIT might be appropriate too. + auto commandPool = CommandPool::create(device, queueFamily, + VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto cmd = commandPool->allocate(); + ref_ptr ref_device(device); + instrumentation->init(ref_device, mainQueue, cmd); + } } if (needToStartThreading) setupThreading(); @@ -577,7 +587,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -598,7 +608,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); debug("Viewer::setupThreading() "); @@ -750,7 +760,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!_threading) return; _threading = false; @@ -771,7 +781,7 @@ void Viewer::stopThreading() void Viewer::update() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& task : recordAndSubmitTasks) { @@ -788,7 +798,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -822,7 +832,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& presentation : presentations) { @@ -832,7 +842,7 @@ void Viewer::present() void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { - SCOPED_INSTRUMENTASTION(viewer.instrumentation); + SCOPED_INSTRUMENTATION(viewer.instrumentation); updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 7c3a7e4c71..61bcbd6726 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -13,6 +13,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include using namespace vsg; @@ -24,6 +25,10 @@ Instrumentation::Instrumentation() { } +void Instrumentation::init(vsg::ref_ptr, vsg::ref_ptr, vsg::ref_ptr) +{ +} + Instrumentation::~Instrumentation() { }