From 5d3c6a33921d6ee2b9bbc7c9b22911b883986bdd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 11:19:42 +0000 Subject: [PATCH 01/68] Initial experiment with Tracy style instrumentation --- include/vsg/utils/Instrumentation.h | 67 +++++++++++++++++++++++++++++ src/vsg/CMakeLists.txt | 1 + src/vsg/app/RecordTraversal.cpp | 50 +++++++++++++++++++++ src/vsg/utils/Instrumentation.cpp | 25 +++++++++++ 4 files changed, 143 insertions(+) create mode 100644 include/vsg/utils/Instrumentation.h create mode 100644 src/vsg/utils/Instrumentation.cpp diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h new file mode 100644 index 0000000000..3e5817535f --- /dev/null +++ b/include/vsg/utils/Instrumentation.h @@ -0,0 +1,67 @@ +#pragma once + +/* + +Copyright(c) 2023 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include + +namespace vsg +{ + + #if defined ( __clang__ ) || defined ( __GNUC__ ) + # define VsgFunctionName __PRETTY_FUNCTION__ + #elif defined ( _MSC_VER ) + # define VsgFunctionName __FUNCSIG__ + #endif + + +#if 1 + + /// SourceLocation structs mark the location in a source file when instrumentation is placed. + /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. + struct SourceLocation + { + const char* name; + const char* function; + const char* file; + uint32_t line; + ubvec4 color; + }; + + struct ScopedInstrumentation + { + const SourceLocation* sl; + inline ScopedInstrumentation(const SourceLocation* in_sl) : sl(in_sl) { info("enter ", sl, " : ", sl->file, ", ", sl->line, ", ", sl->function); } + inline ~ScopedInstrumentation() { info("leave ", sl); } + }; + + #define SCOPED_INSTRUMENTASTION static constexpr SourceLocation s_source_location_##__LINE__ { nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255) }; ScopedInstrumentation __scoped_instrumentation(&(s_source_location_##__LINE__)); +#endif + +#if 0 + class VSG_DECLSPEC Instrumentation : public Inherit + { + public: + + Instrumentation(); + + protected: + + virtual ~Instrumentation(); + + }; + VSG_type_name(vsg::Instrumentation); +#endif + +} // namespace vsg diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 6932475556..4c7320325c 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -223,6 +223,7 @@ set(SOURCES utils/ShaderCompiler.cpp utils/ComputeBounds.cpp utils/Intersector.cpp + utils/Instrumentation.cpp utils/LineSegmentIntersector.cpp utils/LoadPagedLOD.cpp ) diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index d2b57af527..b270464a4c 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -39,6 +39,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include + + using namespace vsg; #define INLINE_TRAVERSE 0 @@ -46,6 +49,8 @@ using namespace vsg; RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { + SCOPED_INSTRUMENTASTION + _minimumBinNumber = 0; int32_t maximumBinNumber = 0; for (auto& bin : in_bins) @@ -64,6 +69,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { + SCOPED_INSTRUMENTASTION } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -91,6 +97,8 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { + SCOPED_INSTRUMENTASTION + for (auto& bin : _bins) { if (bin) bin->clear(); @@ -99,12 +107,16 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { + SCOPED_INSTRUMENTASTION + //debug("Visiting Object"); object.traverse(*this); } void RecordTraversal::apply(const Group& group) { + SCOPED_INSTRUMENTASTION + //debug("Visiting Group"); #if INLINE_TRAVERSE vsg::Group::t_traverse(group, *this); @@ -115,6 +127,8 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { + SCOPED_INSTRUMENTASTION + //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE vsg::QuadGroup::t_traverse(quadGroup, *this); @@ -125,6 +139,8 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { + SCOPED_INSTRUMENTASTION + const auto& sphere = lod.bound; // check if lod bounding sphere is in view frustum. @@ -148,6 +164,8 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { + SCOPED_INSTRUMENTASTION + const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -226,6 +244,8 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { + SCOPED_INSTRUMENTASTION + if (_state->intersect(cullGroup.bound)) { // debug("Passed node"); @@ -235,6 +255,8 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { + SCOPED_INSTRUMENTASTION + if (_state->intersect(cullNode.bound)) { //debug("Passed node"); @@ -244,6 +266,8 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const DepthSorted& depthSorted) { + SCOPED_INSTRUMENTASTION + if (_state->intersect(depthSorted.bound)) { const auto& mv = _state->modelviewMatrixStack.top(); @@ -256,6 +280,8 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const Switch& sw) { + SCOPED_INSTRUMENTASTION + for (auto& child : sw.children) { if ((traversalMask & (overrideMask | child.mask)) != MASK_OFF) @@ -267,35 +293,47 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const Light& /*light*/) { + SCOPED_INSTRUMENTASTION + //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { + SCOPED_INSTRUMENTASTION + //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); } void RecordTraversal::apply(const DirectionalLight& light) { + SCOPED_INSTRUMENTASTION + //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); } void RecordTraversal::apply(const PointLight& light) { + SCOPED_INSTRUMENTASTION + //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); } void RecordTraversal::apply(const SpotLight& light) { + SCOPED_INSTRUMENTASTION + //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); } void RecordTraversal::apply(const StateGroup& stateGroup) { + SCOPED_INSTRUMENTASTION + //debug("Visiting StateGroup"); for (auto& command : stateGroup.stateCommands) @@ -315,6 +353,8 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { + SCOPED_INSTRUMENTASTION + _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -335,6 +375,8 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { + SCOPED_INSTRUMENTASTION + _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -356,6 +398,8 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { + SCOPED_INSTRUMENTASTION + _state->record(); for (auto& command : commands.children) { @@ -365,6 +409,8 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { + SCOPED_INSTRUMENTASTION + //debug("Visiting Command"); _state->record(); command.record(*(_state->_commandBuffer)); @@ -372,6 +418,8 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const View& view) { + SCOPED_INSTRUMENTASTION + // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; _state->_commandBuffer->traversalMask = traversalMask; @@ -459,6 +507,8 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { + SCOPED_INSTRUMENTASTION + if (recordedCommandBuffers) { auto cg = const_cast(&commandGraph); diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp new file mode 100644 index 0000000000..a98c750a66 --- /dev/null +++ b/src/vsg/utils/Instrumentation.cpp @@ -0,0 +1,25 @@ +/* + +Copyright(c) 2023 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include + +using namespace vsg; + +#if 0 +Instrumentation::Instrumentation() +{ +} + +Instrumentation::~Instrumentation() +{ +} +#endif From 92442bc90553d3c676b4479b7300997537b8ae05 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 11:36:54 +0000 Subject: [PATCH 02/68] Windows build fix --- src/vsg/utils/Instrumentation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index a98c750a66..cfb4f44f41 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include using namespace vsg; From a1e31cdec0367c64d7b305bf5a03c7efc2080c44 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 12:48:40 +0000 Subject: [PATCH 03/68] Created a vsg::Instrumentation base class --- include/vsg/app/RecordTraversal.h | 3 ++ include/vsg/utils/Instrumentation.h | 36 ++++++++++++--------- src/vsg/app/RecordTraversal.cpp | 50 +++++++++++++++-------------- src/vsg/utils/Instrumentation.cpp | 2 -- 4 files changed, 50 insertions(+), 41 deletions(-) diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index a120e7be97..b30ed53b5f 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -53,6 +53,7 @@ namespace vsg class SpotLight; class CommandGraph; class RecordedCommandBuffers; + class Instrumentation; VSG_type_name(vsg::RecordTraversal); @@ -128,6 +129,8 @@ namespace vsg // clear the bins to record a new frame. void clearBins(); + ref_ptr instrumentation; + protected: virtual ~RecordTraversal(); diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 3e5817535f..abd31f5165 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -25,9 +25,6 @@ namespace vsg # define VsgFunctionName __FUNCSIG__ #endif - -#if 1 - /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -39,29 +36,38 @@ namespace vsg ubvec4 color; }; - struct ScopedInstrumentation - { - const SourceLocation* sl; - inline ScopedInstrumentation(const SourceLocation* in_sl) : sl(in_sl) { info("enter ", sl, " : ", sl->file, ", ", sl->line, ", ", sl->function); } - inline ~ScopedInstrumentation() { info("leave ", sl); } - }; - - #define SCOPED_INSTRUMENTASTION static constexpr SourceLocation s_source_location_##__LINE__ { nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255) }; ScopedInstrumentation __scoped_instrumentation(&(s_source_location_##__LINE__)); -#endif - -#if 0 class VSG_DECLSPEC Instrumentation : public Inherit { public: Instrumentation(); + virtual void enter(const SourceLocation* sl) const + { + info("enter ", sl, " : ", sl->file, ", ", sl->line, ", ", sl->function); + } + + virtual void leave(const SourceLocation* sl) const + { + info("leave ", sl); + } + protected: virtual ~Instrumentation(); }; VSG_type_name(vsg::Instrumentation); -#endif + + struct ScopedInstrumentation + { + const SourceLocation* sl; + const Instrumentation* instr; + inline ScopedInstrumentation(const SourceLocation* in_sl, const Instrumentation* in_instr) : sl(in_sl), instr(in_instr) { if (instr) instr->enter(sl); } + inline ~ScopedInstrumentation() { if (instr) instr->leave(sl); } + }; + + #define SCOPED_INSTRUMENTASTION(instrumentation) static constexpr SourceLocation s_source_location_##__LINE__ { nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255) }; ScopedInstrumentation __scoped_instrumentation(&(s_source_location_##__LINE__), instrumentation); + } // namespace vsg diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index b270464a4c..f55b0c24af 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -49,7 +49,8 @@ using namespace vsg; RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { - SCOPED_INSTRUMENTASTION + // instrumentation = Instrumentation::create(); + SCOPED_INSTRUMENTASTION(instrumentation); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -65,11 +66,12 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : { _bins[bin->binNumber - _minimumBinNumber] = bin; } + } RecordTraversal::~RecordTraversal() { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -97,7 +99,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); for (auto& bin : _bins) { @@ -107,7 +109,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("Visiting Object"); object.traverse(*this); @@ -115,7 +117,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -127,7 +129,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -139,7 +141,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); const auto& sphere = lod.bound; @@ -164,7 +166,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -244,7 +246,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); if (_state->intersect(cullGroup.bound)) { @@ -255,7 +257,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); if (_state->intersect(cullNode.bound)) { @@ -266,7 +268,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -280,7 +282,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); for (auto& child : sw.children) { @@ -293,14 +295,14 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const Light& /*light*/) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -308,7 +310,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -316,7 +318,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -324,7 +326,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -332,7 +334,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("Visiting StateGroup"); @@ -353,7 +355,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -375,7 +377,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -398,7 +400,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); _state->record(); for (auto& command : commands.children) @@ -409,7 +411,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); //debug("Visiting Command"); _state->record(); @@ -418,7 +420,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const View& view) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -507,7 +509,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - SCOPED_INSTRUMENTASTION + SCOPED_INSTRUMENTASTION(instrumentation); if (recordedCommandBuffers) { diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index cfb4f44f41..458acbdf2d 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -15,7 +15,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -#if 0 Instrumentation::Instrumentation() { } @@ -23,4 +22,3 @@ Instrumentation::Instrumentation() Instrumentation::~Instrumentation() { } -#endif From 9d7178a72bf6ceeb69981f3e52aff2e3ac2eb6b6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 13:54:48 +0000 Subject: [PATCH 04/68] Made vsg::Instrumentation a pure virtual base class and added commandBuffer parameter. Added reference value to the Instrumentation::enter(..) & leave(..) methods --- include/vsg/utils/Instrumentation.h | 22 ++++++++++------------ src/vsg/utils/Instrumentation.cpp | 1 + 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index abd31f5165..342fb3da2e 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -25,6 +25,8 @@ namespace vsg # define VsgFunctionName __FUNCSIG__ #endif + class CommandBuffer; + /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -42,15 +44,10 @@ namespace vsg Instrumentation(); - virtual void enter(const SourceLocation* sl) const - { - info("enter ", sl, " : ", sl->file, ", ", sl->line, ", ", sl->function); - } + virtual void enter(const SourceLocation* sl, uint64_t& reference) const= 0; + virtual void leave(const SourceLocation* sl, uint64_t& reference) const = 0; - virtual void leave(const SourceLocation* sl) const - { - info("leave ", sl); - } + ref_ptr commandBuffer; protected: @@ -61,13 +58,14 @@ namespace vsg struct ScopedInstrumentation { - const SourceLocation* sl; const Instrumentation* instr; - inline ScopedInstrumentation(const SourceLocation* in_sl, const Instrumentation* in_instr) : sl(in_sl), instr(in_instr) { if (instr) instr->enter(sl); } - inline ~ScopedInstrumentation() { if (instr) instr->leave(sl); } + const SourceLocation* sl; + uint64_t reference; + inline ScopedInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : instr(in_instr), sl(in_sl) { if (instr) instr->enter(sl, reference); } + inline ~ScopedInstrumentation() { if (instr) instr->leave(sl, reference); } }; - #define SCOPED_INSTRUMENTASTION(instrumentation) static constexpr SourceLocation s_source_location_##__LINE__ { nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255) }; ScopedInstrumentation __scoped_instrumentation(&(s_source_location_##__LINE__), instrumentation); + #define SCOPED_INSTRUMENTASTION(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__)); } // namespace vsg diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 458acbdf2d..af2576d71c 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -11,6 +11,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include #include using namespace vsg; From 46870fb9e45a42b333c61584a8768a00a682a773 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 14:29:48 +0000 Subject: [PATCH 05/68] Added assignment of colours --- include/vsg/utils/Instrumentation.h | 4 +++- src/vsg/app/RecordTraversal.cpp | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 342fb3da2e..11d0c3c92c 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -66,6 +66,8 @@ namespace vsg }; #define SCOPED_INSTRUMENTASTION(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) 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) 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) static constexpr SourceLocation s_source_location_##__LINE__ { name, VsgFunctionName, __FILE__, __LINE__, color }; ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); } // namespace vsg diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index f55b0c24af..0c661578e1 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -50,7 +50,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { // instrumentation = Instrumentation::create(); - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -334,7 +334,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -400,7 +400,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 255, 0, 255)); _state->record(); for (auto& command : commands.children) @@ -411,7 +411,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 255, 0, 255)); //debug("Visiting Command"); _state->record(); @@ -420,7 +420,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const View& view) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -509,7 +509,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTASTION_C(instrumentation, ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { From ab2f0be3fbdfc579c6ba2523bb3a330968c5254c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 15:42:44 +0000 Subject: [PATCH 06/68] Implemented a VulkanAnnotation version of vsg::Instrumentation to enable population of Vulkan API layer/RenderDoc in a more useful way. --- include/vsg/app/CommandGraph.h | 6 +--- include/vsg/utils/Instrumentation.h | 19 +++++++++++++ src/vsg/app/CommandGraph.cpp | 30 ++++++++++++++++++++ src/vsg/app/WindowTraits.cpp | 2 +- src/vsg/utils/Instrumentation.cpp | 44 +++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 6 deletions(-) diff --git a/include/vsg/app/CommandGraph.h b/include/vsg/app/CommandGraph.h index f189b82e6d..428134e8b8 100644 --- a/include/vsg/app/CommandGraph.h +++ b/include/vsg/app/CommandGraph.h @@ -41,11 +41,7 @@ namespace vsg uint32_t maxSlot = 2; int submitOrder = 0; - inline ref_ptr getOrCreateRecordTraversal() - { - if (!recordTraversal) recordTraversal = RecordTraversal::create(maxSlot); - return recordTraversal; - } + ref_ptr getOrCreateRecordTraversal(); ref_ptr recordTraversal; diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 11d0c3c92c..9b25006cb0 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -38,6 +38,7 @@ namespace vsg ubvec4 color; }; + /// base class for Instrumentation implentations class VSG_DECLSPEC Instrumentation : public Inherit { public: @@ -56,6 +57,24 @@ namespace vsg }; VSG_type_name(vsg::Instrumentation); + /// Concrete Implementation that uses VK_debug_utils to emit annotation to scene graph traversal. + /// Provides tools like RenderDoc a way to report the source location associated with Vulkan calls. + class VSG_DECLSPEC VulkanAnnotation : public Inherit + { + public: + + VulkanAnnotation(); + + virtual void enter(const SourceLocation* sl, uint64_t& reference) const; + virtual void leave(const SourceLocation* sl, uint64_t& reference) const; + + protected: + + virtual ~VulkanAnnotation(); + + }; + VSG_type_name(vsg::VulkanAnnotation); + struct ScopedInstrumentation { const Instrumentation* instr; diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index dd4cf4b502..02b1c0b320 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -17,6 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include using namespace vsg; @@ -56,6 +57,22 @@ void CommandGraph::reset() { } +ref_ptr CommandGraph::getOrCreateRecordTraversal() +{ + if (!recordTraversal) + { + recordTraversal = RecordTraversal::create(maxSlot); + if (!recordTraversal->instrumentation && window && window->traits() && window->traits()->apiDumpLayer) + { + recordTraversal->instrumentation = VulkanAnnotation::create(); + } + + info("CommandGraph::getOrCreateRecordTraversal() ", recordTraversal); + } + return recordTraversal; +} + + void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { if (window && !window->visible()) @@ -100,6 +117,7 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers recordTraversal->getState()->_commandBuffer = commandBuffer; + // or select index when maps to a dormant CommandBuffer VkCommandBuffer vk_commandBuffer = *commandBuffer; @@ -112,10 +130,22 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); + if (recordTraversal->instrumentation) + { + // attach the commandBuffer to instrumentation so it can be recorded to if required. + recordTraversal->instrumentation->commandBuffer = commandBuffer; + } + traverse(*recordTraversal); vkEndCommandBuffer(vk_commandBuffer); + if (recordTraversal->instrumentation) + { + // disconnect the commandBuffer from instrumentation as it's no longer valid for recording commands to + recordTraversal->instrumentation->commandBuffer = {}; + } + recordedCommandBuffers->add(submitOrder, commandBuffer); } diff --git a/src/vsg/app/WindowTraits.cpp b/src/vsg/app/WindowTraits.cpp index 9103cf49db..011c197074 100644 --- a/src/vsg/app/WindowTraits.cpp +++ b/src/vsg/app/WindowTraits.cpp @@ -105,7 +105,7 @@ void WindowTraits::validate() { instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } - if (debugUtils && isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + if ((apiDumpLayer || debugUtils) && isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { instanceExtensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index af2576d71c..72eaef528d 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -16,6 +16,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Instrumentation base class +// Instrumentation::Instrumentation() { } @@ -23,3 +27,43 @@ Instrumentation::Instrumentation() Instrumentation::~Instrumentation() { } + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// VulkanAnnotation uses VK_debug_utils to pass annotation to Vulkan +// +VulkanAnnotation::VulkanAnnotation() +{ +} + +VulkanAnnotation::~VulkanAnnotation() +{ +} + + +void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&) const +{ + if (!commandBuffer) return; + + auto extensions = commandBuffer->getDevice()->getInstance()->getExtensions(); + + VkDebugUtilsLabelEXT markerInfo = {}; + markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + if (sl->name) markerInfo.pLabelName = sl->name; + else markerInfo.pLabelName = sl->function; + markerInfo.color[0] = static_cast(sl->color[0])/255.0; + markerInfo.color[1] = static_cast(sl->color[1])/255.0; + markerInfo.color[2] = static_cast(sl->color[2])/255.0; + markerInfo.color[3] = static_cast(sl->color[3])/255.0; + + extensions->vkCmdBeginDebugUtilsLabelEXT(*commandBuffer, &markerInfo); +} + +void VulkanAnnotation::leave(const SourceLocation*, uint64_t&) const +{ + if (!commandBuffer) return; + + auto extensions = commandBuffer->getDevice()->getInstance()->getExtensions(); + extensions->vkCmdEndDebugUtilsLabelEXT(*commandBuffer); +} From ff6487df9270c9d74db3d438b73345980407085c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 17:29:41 +0000 Subject: [PATCH 07/68] Added instrumentation hooks to Viewer, RecordAndSubmitTask & CommandGraph --- include/vsg/app/CommandGraph.h | 3 +++ include/vsg/app/RecordAndSubmitTask.h | 3 +++ include/vsg/app/RecordTraversal.h | 1 + include/vsg/app/Viewer.h | 3 +++ src/vsg/app/CommandGraph.cpp | 9 +++++++ src/vsg/app/RecordAndSubmitTask.cpp | 13 +++++++++ src/vsg/app/Viewer.cpp | 38 +++++++++++++++++++++++++++ 7 files changed, 70 insertions(+) diff --git a/include/vsg/app/CommandGraph.h b/include/vsg/app/CommandGraph.h index 428134e8b8..da10785949 100644 --- a/include/vsg/app/CommandGraph.h +++ b/include/vsg/app/CommandGraph.h @@ -49,6 +49,9 @@ namespace vsg virtual void reset(); virtual void record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp = {}, ref_ptr databasePager = {}); + /// hook for assigning Instrumentation to enable profiling of record traversal. + ref_ptr instrumentation; + protected: virtual ~CommandGraph(); diff --git a/include/vsg/app/RecordAndSubmitTask.h b/include/vsg/app/RecordAndSubmitTask.h index c8b2c5a4b4..36599d703e 100644 --- a/include/vsg/app/RecordAndSubmitTask.h +++ b/include/vsg/app/RecordAndSubmitTask.h @@ -59,6 +59,9 @@ namespace vsg ref_ptr databasePager; + /// hook for assigning Instrumentation to enable profiling of record traversal. + ref_ptr instrumentation; + protected: size_t _currentFrameIndex; std::vector _indices; diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index b30ed53b5f..db9747a406 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -129,6 +129,7 @@ namespace vsg // clear the bins to record a new frame. void clearBins(); + /// hook for assigning Instrumentation to enable profiling of record traversal. ref_ptr instrumentation; protected: diff --git a/include/vsg/app/Viewer.h b/include/vsg/app/Viewer.h index 513b6f9112..17fcb8dc80 100644 --- a/include/vsg/app/Viewer.h +++ b/include/vsg/app/Viewer.h @@ -133,6 +133,9 @@ namespace vsg /// Call vkDeviceWaitIdle on all the devices associated with this Viewer virtual void deviceWaitIdle() const; + /// hook for assigning Instrumentation to enable profiling of record traversal. + ref_ptr instrumentation; + protected: virtual ~Viewer(); diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 02b1c0b320..6a93d388dc 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -23,6 +23,7 @@ using namespace vsg; CommandGraph::CommandGraph() { + SCOPED_INSTRUMENTASTION(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_device, int family) : @@ -30,12 +31,15 @@ CommandGraph::CommandGraph(ref_ptr in_device, int family) : queueFamily(family), presentFamily(-1) { + SCOPED_INSTRUMENTASTION(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : window(in_window), device(in_window->getOrCreateDevice()) { + SCOPED_INSTRUMENTASTION(instrumentation); + VkQueueFlags queueFlags = VK_QUEUE_GRAPHICS_BIT; if (window->traits()) queueFlags = window->traits()->queueFlags; @@ -46,6 +50,7 @@ CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : CommandGraph::~CommandGraph() { + SCOPED_INSTRUMENTASTION(instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -59,6 +64,8 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (!recordTraversal) { recordTraversal = RecordTraversal::create(maxSlot); @@ -75,6 +82,8 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { + SCOPED_INSTRUMENTASTION(instrumentation); + if (window && !window->visible()) { return; diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 404188ae7b..6a49cbf6bf 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -15,12 +15,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include using namespace vsg; RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) : device(in_device) { + SCOPED_INSTRUMENTASTION(instrumentation); + _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) { @@ -42,6 +45,8 @@ RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) void RecordAndSubmitTask::advance() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (_currentFrameIndex >= _indices.size()) { // first frame so set to 0 @@ -80,6 +85,8 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { + SCOPED_INSTRUMENTASTION(instrumentation); + if (VkResult result = start(); result != VK_SUCCESS) return result; if (earlyTransferTask) @@ -96,6 +103,8 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (earlyTransferTask) earlyTransferTask->currentTransferCompletedSemaphore = {}; if (lateTransferTask) lateTransferTask->currentTransferCompletedSemaphore = {}; @@ -112,6 +121,8 @@ VkResult RecordAndSubmitTask::start() VkResult RecordAndSubmitTask::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp) { + SCOPED_INSTRUMENTASTION(instrumentation); + for (auto& commandGraph : commandGraphs) { commandGraph->record(recordedCommandBuffers, frameStamp, databasePager); @@ -122,6 +133,8 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { + SCOPED_INSTRUMENTASTION(instrumentation); + if (lateTransferTask) { if (VkResult result = lateTransferTask->transferDynamicData(); result != VK_SUCCESS) return result; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 987e7527ad..83735abfa6 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include @@ -32,10 +33,13 @@ Viewer::Viewer() : status(vsg::ActivityStatus::create()), _start_point(clock::now()) { + SCOPED_INSTRUMENTASTION(instrumentation); } Viewer::~Viewer() { + SCOPED_INSTRUMENTASTION(instrumentation); + stopThreading(); // don't destroy viewer while devices are still active @@ -44,6 +48,8 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { + SCOPED_INSTRUMENTASTION(instrumentation); + std::set devices; for (auto& window : _windows) { @@ -96,6 +102,8 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { + SCOPED_INSTRUMENTASTION(instrumentation); + _close = true; status->set(false); @@ -104,6 +112,8 @@ void Viewer::close() bool Viewer::active() const { + SCOPED_INSTRUMENTASTION(instrumentation); + bool viewerIsActive = !_close; if (viewerIsActive) { @@ -127,6 +137,8 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { + SCOPED_INSTRUMENTASTION(instrumentation); + bool result = false; if (discardPreviousEvents) _events.clear(); @@ -140,6 +152,8 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (!active()) return false; // poll all the windows for events. @@ -178,6 +192,8 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (_close) return false; VkResult result = VK_SUCCESS; @@ -216,6 +232,8 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { + SCOPED_INSTRUMENTASTION(instrumentation); + VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) { @@ -231,6 +249,8 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { + SCOPED_INSTRUMENTASTION(instrumentation); + for (auto& vsg_event : _events) { for (auto& handler : _eventHandlers) @@ -242,6 +262,8 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { + SCOPED_INSTRUMENTASTION(instrumentation); + if (recordAndSubmitTasks.empty()) { return; @@ -399,6 +421,8 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { + SCOPED_INSTRUMENTASTION(instrumentation); + // now remove any commandGraphs associated with window bool needToStartThreading = _threading; if (_threading) stopThreading(); @@ -554,6 +578,8 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { + SCOPED_INSTRUMENTASTION(instrumentation); + // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; for (auto& task : recordAndSubmitTasks) @@ -573,6 +599,8 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { + SCOPED_INSTRUMENTASTION(instrumentation); + debug("Viewer::setupThreading() "); stopThreading(); @@ -723,6 +751,8 @@ void Viewer::setupThreading() void Viewer::stopThreading() { + SCOPED_INSTRUMENTASTION(instrumentation); + if (!_threading) return; _threading = false; @@ -742,6 +772,8 @@ void Viewer::stopThreading() void Viewer::update() { + SCOPED_INSTRUMENTASTION(instrumentation); + for (auto& task : recordAndSubmitTasks) { if (task->databasePager) @@ -757,6 +789,8 @@ void Viewer::update() void Viewer::recordAndSubmit() { + SCOPED_INSTRUMENTASTION(instrumentation); + // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) { @@ -789,6 +823,8 @@ void Viewer::recordAndSubmit() void Viewer::present() { + SCOPED_INSTRUMENTASTION(instrumentation); + for (auto& presentation : presentations) { presentation->present(); @@ -797,5 +833,7 @@ void Viewer::present() void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { + SCOPED_INSTRUMENTASTION(viewer.instrumentation); + updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } From 6fece3f69c2106fba91013f2d10d17d977da356d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 7 Dec 2023 19:46:31 +0000 Subject: [PATCH 08/68] Moved include to address Windows build error --- include/vsg/app/CommandGraph.h | 1 + include/vsg/app/RecordAndSubmitTask.h | 1 + include/vsg/app/Viewer.h | 1 + src/vsg/app/CommandGraph.cpp | 1 - src/vsg/app/RecordAndSubmitTask.cpp | 1 - src/vsg/app/Viewer.cpp | 1 - 6 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/vsg/app/CommandGraph.h b/include/vsg/app/CommandGraph.h index da10785949..9d9c1c3cfa 100644 --- a/include/vsg/app/CommandGraph.h +++ b/include/vsg/app/CommandGraph.h @@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include namespace vsg { diff --git a/include/vsg/app/RecordAndSubmitTask.h b/include/vsg/app/RecordAndSubmitTask.h index 36599d703e..535cab4ae9 100644 --- a/include/vsg/app/RecordAndSubmitTask.h +++ b/include/vsg/app/RecordAndSubmitTask.h @@ -18,6 +18,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include namespace vsg { diff --git a/include/vsg/app/Viewer.h b/include/vsg/app/Viewer.h index 17fcb8dc80..211a230e19 100644 --- a/include/vsg/app/Viewer.h +++ b/include/vsg/app/Viewer.h @@ -19,6 +19,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 6a93d388dc..14a620f160 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -17,7 +17,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include using namespace vsg; diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 6a49cbf6bf..b07958bcc9 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -15,7 +15,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include using namespace vsg; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 83735abfa6..f351d5f550 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -16,7 +16,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include #include From 878a9444973d35bfa9cdedc8415c1bc03e5eb461 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Dec 2023 08:30:01 +0000 Subject: [PATCH 09/68] Ran clang-format --- include/vsg/app/CommandGraph.h | 2 +- include/vsg/app/RecordAndSubmitTask.h | 2 +- include/vsg/utils/Instrumentation.h | 45 ++++++++++++++++----------- src/vsg/app/CommandGraph.cpp | 2 -- src/vsg/app/RecordTraversal.cpp | 2 -- src/vsg/utils/Instrumentation.cpp | 18 +++++------ 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/include/vsg/app/CommandGraph.h b/include/vsg/app/CommandGraph.h index 9d9c1c3cfa..1dfb2a9171 100644 --- a/include/vsg/app/CommandGraph.h +++ b/include/vsg/app/CommandGraph.h @@ -17,8 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include +#include namespace vsg { diff --git a/include/vsg/app/RecordAndSubmitTask.h b/include/vsg/app/RecordAndSubmitTask.h index 535cab4ae9..4983e193e5 100644 --- a/include/vsg/app/RecordAndSubmitTask.h +++ b/include/vsg/app/RecordAndSubmitTask.h @@ -17,8 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include +#include namespace vsg { diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 9b25006cb0..79a43a7451 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -19,11 +19,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { - #if defined ( __clang__ ) || defined ( __GNUC__ ) - # define VsgFunctionName __PRETTY_FUNCTION__ - #elif defined ( _MSC_VER ) - # define VsgFunctionName __FUNCSIG__ - #endif +#if defined(__clang__) || defined(__GNUC__) +# define VsgFunctionName __PRETTY_FUNCTION__ +#elif defined(_MSC_VER) +# define VsgFunctionName __FUNCSIG__ +#endif class CommandBuffer; @@ -42,18 +42,15 @@ namespace vsg class VSG_DECLSPEC Instrumentation : public Inherit { public: - Instrumentation(); - virtual void enter(const SourceLocation* sl, uint64_t& reference) const= 0; + virtual void enter(const SourceLocation* sl, uint64_t& reference) const = 0; virtual void leave(const SourceLocation* sl, uint64_t& reference) const = 0; ref_ptr commandBuffer; protected: - virtual ~Instrumentation(); - }; VSG_type_name(vsg::Instrumentation); @@ -62,16 +59,13 @@ namespace vsg class VSG_DECLSPEC VulkanAnnotation : public Inherit { public: - VulkanAnnotation(); virtual void enter(const SourceLocation* sl, uint64_t& reference) const; virtual void leave(const SourceLocation* sl, uint64_t& reference) const; protected: - virtual ~VulkanAnnotation(); - }; VSG_type_name(vsg::VulkanAnnotation); @@ -80,13 +74,28 @@ namespace vsg const Instrumentation* instr; const SourceLocation* sl; uint64_t reference; - inline ScopedInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : instr(in_instr), sl(in_sl) { if (instr) instr->enter(sl, reference); } - inline ~ScopedInstrumentation() { if (instr) instr->leave(sl, reference); } + inline ScopedInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : + instr(in_instr), sl(in_sl) + { + if (instr) instr->enter(sl, reference); + } + inline ~ScopedInstrumentation() + { + if (instr) instr->leave(sl, reference); + } }; - #define SCOPED_INSTRUMENTASTION(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) 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) 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) static constexpr SourceLocation s_source_location_##__LINE__ { name, VsgFunctionName, __FILE__, __LINE__, color }; ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); +#define SCOPED_INSTRUMENTASTION(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) \ + 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) \ + 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) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color}; \ + ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); } // namespace vsg diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 14a620f160..f0d443c7c8 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -78,7 +78,6 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() return recordTraversal; } - void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { SCOPED_INSTRUMENTASTION(instrumentation); @@ -125,7 +124,6 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers recordTraversal->getState()->_commandBuffer = commandBuffer; - // or select index when maps to a dormant CommandBuffer VkCommandBuffer vk_commandBuffer = *commandBuffer; diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 0c661578e1..35706e8903 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -41,7 +41,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include - using namespace vsg; #define INLINE_TRAVERSE 0 @@ -66,7 +65,6 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : { _bins[bin->binNumber - _minimumBinNumber] = bin; } - } RecordTraversal::~RecordTraversal() diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 72eaef528d..7c3a7e4c71 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -10,9 +10,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ +#include #include #include -#include using namespace vsg; @@ -28,7 +28,6 @@ Instrumentation::~Instrumentation() { } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // VulkanAnnotation uses VK_debug_utils to pass annotation to Vulkan @@ -41,7 +40,6 @@ VulkanAnnotation::~VulkanAnnotation() { } - void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&) const { if (!commandBuffer) return; @@ -50,12 +48,14 @@ void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&) const VkDebugUtilsLabelEXT markerInfo = {}; markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - if (sl->name) markerInfo.pLabelName = sl->name; - else markerInfo.pLabelName = sl->function; - markerInfo.color[0] = static_cast(sl->color[0])/255.0; - markerInfo.color[1] = static_cast(sl->color[1])/255.0; - markerInfo.color[2] = static_cast(sl->color[2])/255.0; - markerInfo.color[3] = static_cast(sl->color[3])/255.0; + if (sl->name) + markerInfo.pLabelName = sl->name; + else + markerInfo.pLabelName = sl->function; + markerInfo.color[0] = static_cast(sl->color[0]) / 255.0; + markerInfo.color[1] = static_cast(sl->color[1]) / 255.0; + markerInfo.color[2] = static_cast(sl->color[2]) / 255.0; + markerInfo.color[3] = static_cast(sl->color[3]) / 255.0; extensions->vkCmdBeginDebugUtilsLabelEXT(*commandBuffer, &markerInfo); } From 0abb84d1487721948f54ccd718aec69f34423059 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 8 Dec 2023 10:00:48 +0100 Subject: [PATCH 10/68] Spelling fix --- include/vsg/utils/Instrumentation.h | 8 ++--- src/vsg/app/CommandGraph.cpp | 12 ++++---- src/vsg/app/RecordAndSubmitTask.cpp | 12 ++++---- src/vsg/app/RecordTraversal.cpp | 48 ++++++++++++++--------------- src/vsg/app/Viewer.cpp | 38 +++++++++++------------ 5 files changed, 59 insertions(+), 59 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 9b25006cb0..9994f5350e 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -84,9 +84,9 @@ namespace vsg inline ~ScopedInstrumentation() { if (instr) instr->leave(sl, reference); } }; - #define SCOPED_INSTRUMENTASTION(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) 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) 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) static constexpr SourceLocation s_source_location_##__LINE__ { name, VsgFunctionName, __FILE__, __LINE__, color }; ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + #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_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_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_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__)); } // namespace vsg diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 6a93d388dc..834043d197 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -23,7 +23,7 @@ using namespace vsg; CommandGraph::CommandGraph() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_device, int family) : @@ -31,14 +31,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; @@ -50,7 +50,7 @@ CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : CommandGraph::~CommandGraph() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -64,7 +64,7 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!recordTraversal) { @@ -82,7 +82,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 6a49cbf6bf..0095d689e4 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -22,7 +22,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) @@ -45,7 +45,7 @@ RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) void RecordAndSubmitTask::advance() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -85,7 +85,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; @@ -103,7 +103,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (earlyTransferTask) earlyTransferTask->currentTransferCompletedSemaphore = {}; if (lateTransferTask) lateTransferTask->currentTransferCompletedSemaphore = {}; @@ -121,7 +121,7 @@ VkResult RecordAndSubmitTask::start() VkResult RecordAndSubmitTask::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& commandGraph : commandGraphs) { @@ -133,7 +133,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 0c661578e1..8dcc5c046b 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -50,7 +50,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; @@ -71,7 +71,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -99,7 +99,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& bin : _bins) { @@ -109,7 +109,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); //debug("Visiting Object"); object.traverse(*this); @@ -117,7 +117,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 @@ -129,7 +129,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 @@ -141,7 +141,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); const auto& sphere = lod.bound; @@ -166,7 +166,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; @@ -246,7 +246,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(cullGroup.bound)) { @@ -257,7 +257,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(cullNode.bound)) { @@ -268,7 +268,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -282,7 +282,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& child : sw.children) { @@ -295,14 +295,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); @@ -310,7 +310,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); @@ -318,7 +318,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); @@ -326,7 +326,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); @@ -334,7 +334,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"); @@ -355,7 +355,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; @@ -377,7 +377,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; @@ -400,7 +400,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) @@ -411,7 +411,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(); @@ -420,7 +420,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; @@ -509,7 +509,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 83735abfa6..0ecefb0e77 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -33,12 +33,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(); @@ -48,7 +48,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); std::set devices; for (auto& window : _windows) @@ -102,7 +102,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); _close = true; status->set(false); @@ -112,7 +112,7 @@ void Viewer::close() bool Viewer::active() const { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); bool viewerIsActive = !_close; if (viewerIsActive) @@ -137,7 +137,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); bool result = false; @@ -152,7 +152,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!active()) return false; @@ -192,7 +192,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (_close) return false; @@ -232,7 +232,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) @@ -249,7 +249,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& vsg_event : _events) { @@ -262,7 +262,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (recordAndSubmitTasks.empty()) { @@ -421,7 +421,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; @@ -578,7 +578,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -599,7 +599,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); debug("Viewer::setupThreading() "); @@ -751,7 +751,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); if (!_threading) return; _threading = false; @@ -772,7 +772,7 @@ void Viewer::stopThreading() void Viewer::update() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& task : recordAndSubmitTasks) { @@ -789,7 +789,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -823,7 +823,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - SCOPED_INSTRUMENTASTION(instrumentation); + SCOPED_INSTRUMENTATION(instrumentation); for (auto& presentation : presentations) { @@ -833,7 +833,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); } From a1acda301e6f108f405439aede6edad23c016f0d Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Fri, 8 Dec 2023 10:01:11 +0100 Subject: [PATCH 11/68] Add rump API for initializing Tracy GPU profiling --- include/vsg/utils/Instrumentation.h | 4 ++++ src/vsg/app/Viewer.cpp | 10 ++++++++++ src/vsg/utils/Instrumentation.cpp | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 9994f5350e..79eb3b4d7c 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. @@ -45,6 +47,8 @@ namespace vsg 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; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 0ecefb0e77..12a5874665 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -571,6 +571,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(); diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 72eaef528d..8a1166dbac 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -12,6 +12,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() { } From b7be59a7a8df1a8366cfb76a01de042319d07dd2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Dec 2023 12:09:29 +0000 Subject: [PATCH 12/68] Added instrumentation support for TransferTask --- include/vsg/app/TransferTask.h | 3 +++ include/vsg/utils/Instrumentation.h | 4 ++-- src/vsg/app/TransferTask.cpp | 18 ++++++++++++++++++ src/vsg/utils/Instrumentation.cpp | 5 +++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/include/vsg/app/TransferTask.h b/include/vsg/app/TransferTask.h index 7ff1637b4c..b41f26df35 100644 --- a/include/vsg/app/TransferTask.h +++ b/include/vsg/app/TransferTask.h @@ -49,6 +49,9 @@ namespace vsg ref_ptr transferQueue; ref_ptr currentTransferCompletedSemaphore; + /// hook for assigning Instrumentation to enable profiling of record traversal. + ref_ptr instrumentation; + protected: using OffsetBufferInfoMap = std::map>; using BufferMap = std::map, OffsetBufferInfoMap>; diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index c901f41057..35995c0f17 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -65,8 +65,8 @@ namespace vsg public: VulkanAnnotation(); - virtual void enter(const SourceLocation* sl, uint64_t& reference) const; - virtual void leave(const SourceLocation* sl, uint64_t& reference) const; + virtual void enter(const SourceLocation* sl, uint64_t& reference) const override; + virtual void leave(const SourceLocation* sl, uint64_t& reference) const override; protected: virtual ~VulkanAnnotation(); diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index 78ec3b0a4f..3bcdb240e6 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -21,6 +21,8 @@ using namespace vsg; TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : device(in_device) { + SCOPED_INSTRUMENTATION(instrumentation); + _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) { @@ -32,6 +34,8 @@ TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : void TransferTask::advance() { + SCOPED_INSTRUMENTATION(instrumentation); + if (_currentFrameIndex >= _indices.size()) { // first frame so set to 0 @@ -65,12 +69,16 @@ bool TransferTask::containsDataToTransfer() const void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) { + SCOPED_INSTRUMENTATION(instrumentation); + assign(dynamicData.bufferInfos); assign(dynamicData.imageInfos); } void TransferTask::assign(const BufferInfoList& bufferInfoList) { + SCOPED_INSTRUMENTATION(instrumentation); + for (auto& bufferInfo : bufferInfoList) { _dynamicDataMap[bufferInfo->buffer][bufferInfo->offset] = bufferInfo; @@ -97,6 +105,8 @@ void TransferTask::assign(const BufferInfoList& bufferInfoList) void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { + SCOPED_INSTRUMENTATION(instrumentation); + Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -171,6 +181,8 @@ void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::assign(const ImageInfoList& imageInfoList) { + SCOPED_INSTRUMENTATION(instrumentation); + Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -203,6 +215,8 @@ void TransferTask::assign(const ImageInfoList& imageInfoList) void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { + SCOPED_INSTRUMENTATION(instrumentation); + Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -231,6 +245,8 @@ void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset, ImageInfo& imageInfo) { + SCOPED_INSTRUMENTATION(instrumentation); + Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -315,6 +331,8 @@ void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& f VkResult TransferTask::transferDynamicData() { + SCOPED_INSTRUMENTATION(instrumentation); + Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 61bcbd6726..99487ff681 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -25,12 +25,13 @@ Instrumentation::Instrumentation() { } -void Instrumentation::init(vsg::ref_ptr, vsg::ref_ptr, vsg::ref_ptr) +Instrumentation::~Instrumentation() { } -Instrumentation::~Instrumentation() +void Instrumentation::init(vsg::ref_ptr /*device*/, vsg::ref_ptr /*queue*/, vsg::ref_ptr cmd) { + commandBuffer = cmd; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// From 614be7587e719acc172574577500f158a71ce442 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 8 Dec 2023 17:14:50 +0000 Subject: [PATCH 13/68] Moved the Instrumentation::init() call to the Viewer::compile(). --- include/vsg/utils/Instrumentation.h | 2 +- src/vsg/app/Viewer.cpp | 21 +++++++++++---------- src/vsg/utils/Instrumentation.cpp | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 35995c0f17..72776655f0 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -47,7 +47,7 @@ namespace vsg Instrumentation(); // Conceived for the needs of Tracy - virtual void init(vsg::ref_ptr device, vsg::ref_ptr queue, vsg::ref_ptr cmd); + virtual void init(ref_ptr queue, 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; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index cc2f096433..1d795eba53 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -273,6 +273,17 @@ void Viewer::compile(ref_ptr hints) bool containsPagedLOD = false; ref_ptr databasePager; + for(auto task : recordAndSubmitTasks) + { + if (task->instrumentation) + { + // VK_COMMAND_POOL_CREATE_TRANSIENT_BIT might be appropriate too. + auto commandPool = CommandPool::create(task->device, task->queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto commandBuffer = commandPool->allocate(); + task->instrumentation->init(task->queue, commandBuffer); + } + } + struct DeviceResources { CollectResourceRequirements collectResources; @@ -570,16 +581,6 @@ 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(); diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 99487ff681..ccc972c795 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -29,7 +29,7 @@ Instrumentation::~Instrumentation() { } -void Instrumentation::init(vsg::ref_ptr /*device*/, vsg::ref_ptr /*queue*/, vsg::ref_ptr cmd) +void Instrumentation::init(ref_ptr /*queue*/, ref_ptr cmd) { commandBuffer = cmd; } From 55fe52118de10da0a8f02fa59c50478b299445ff Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 11 Dec 2023 15:19:01 +0000 Subject: [PATCH 14/68] Added support for signally the start and end of command buffer recording --- include/vsg/utils/Instrumentation.h | 50 ++++++++++++++++++++++++++--- include/vsg/vk/CommandPool.h | 5 ++- src/vsg/app/CommandGraph.cpp | 14 ++------ src/vsg/app/RecordTraversal.cpp | 32 +++++++++--------- src/vsg/app/Viewer.cpp | 11 ------- src/vsg/utils/Instrumentation.cpp | 17 ++++------ src/vsg/vk/CommandPool.cpp | 4 ++- 7 files changed, 77 insertions(+), 56 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 72776655f0..6f1da4217e 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -46,12 +46,14 @@ namespace vsg public: Instrumentation(); - // Conceived for the needs of Tracy - virtual void init(ref_ptr queue, ref_ptr cmd); + virtual void enterCommandBuffer(vsg::ref_ptr commandBuffer) = 0; + virtual void leaveCommandBuffer() = 0; + virtual void enter(const SourceLocation* sl, uint64_t& reference) const = 0; virtual void leave(const SourceLocation* sl, uint64_t& reference) const = 0; - ref_ptr commandBuffer; + virtual void enter(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const = 0; + virtual void leave(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const = 0; protected: virtual ~Instrumentation(); @@ -65,8 +67,14 @@ namespace vsg public: VulkanAnnotation(); - virtual void enter(const SourceLocation* sl, uint64_t& reference) const override; - virtual void leave(const SourceLocation* sl, uint64_t& reference) const override; + void enterCommandBuffer(vsg::ref_ptr) override {} + void leaveCommandBuffer() override {} + + void enter(const SourceLocation*, uint64_t&) const override {} + void leave(const SourceLocation*, uint64_t&) const override {} + + void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; + void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; protected: virtual ~VulkanAnnotation(); @@ -89,6 +97,24 @@ namespace vsg } }; + struct ScopedInstrumentationCG + { + const Instrumentation* instr; + const SourceLocation* sl; + uint64_t reference; + CommandBuffer& commandBuffer; + + inline ScopedInstrumentationCG(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer) : + instr(in_instr), sl(in_sl), commandBuffer(in_commandBuffer) + { + if (instr) instr->enter(sl, reference, commandBuffer); + } + inline ~ScopedInstrumentationCG() + { + if (instr) instr->leave(sl, reference, commandBuffer); + } + }; + #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__)); @@ -102,4 +128,18 @@ namespace vsg static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); +#define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); +#define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); +#define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); +#define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + + } // namespace vsg diff --git a/include/vsg/vk/CommandPool.h b/include/vsg/vk/CommandPool.h index 9c41a63007..2a68ba7b08 100644 --- a/include/vsg/vk/CommandPool.h +++ b/include/vsg/vk/CommandPool.h @@ -29,7 +29,10 @@ namespace vsg operator VkCommandPool() const { return _commandPool; } VkCommandPool vk() const { return _commandPool; } - void reset(VkCommandPoolResetFlags flags = VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT) const { vkResetCommandPool(*_device, _commandPool, flags); } + const uint32_t queueFamilyIndex; + const VkCommandPoolCreateFlags flags; + + void reset(VkCommandPoolResetFlags reset_flags = VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT) const { vkResetCommandPool(*_device, _commandPool, reset_flags); } /// allocate CommandBuffer from CommandPool ref_ptr allocate(VkCommandBufferLevel level = VK_COMMAND_BUFFER_LEVEL_PRIMARY); diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index e99d9c457e..60314128a9 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -136,21 +136,13 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); - if (recordTraversal->instrumentation) - { - // attach the commandBuffer to instrumentation so it can be recorded to if required. - recordTraversal->instrumentation->commandBuffer = commandBuffer; - } + if (instrumentation) instrumentation->enterCommandBuffer(commandBuffer); traverse(*recordTraversal); - vkEndCommandBuffer(vk_commandBuffer); + if (instrumentation) instrumentation->leaveCommandBuffer(); - if (recordTraversal->instrumentation) - { - // disconnect the commandBuffer from instrumentation as it's no longer valid for recording commands to - recordTraversal->instrumentation->commandBuffer = {}; - } + vkEndCommandBuffer(vk_commandBuffer); recordedCommandBuffers->add(submitOrder, commandBuffer); } diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 27b84aa103..dcc2f9c486 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -107,7 +107,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); //debug("Visiting Object"); object.traverse(*this); @@ -115,7 +115,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -127,7 +127,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -139,7 +139,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); const auto& sphere = lod.bound; @@ -164,7 +164,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); if (_state->intersect(cullGroup.bound)) { @@ -255,7 +255,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); if (_state->intersect(cullNode.bound)) { @@ -266,7 +266,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); if (_state->intersect(depthSorted.bound)) { @@ -280,7 +280,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); for (auto& child : sw.children) { @@ -332,7 +332,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(255, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -375,7 +375,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); _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_INSTRUMENTATION_C(instrumentation, ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), 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_INSTRUMENTATION_C(instrumentation, ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), 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_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), 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_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 1d795eba53..0f03e432ca 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -273,17 +273,6 @@ void Viewer::compile(ref_ptr hints) bool containsPagedLOD = false; ref_ptr databasePager; - for(auto task : recordAndSubmitTasks) - { - if (task->instrumentation) - { - // VK_COMMAND_POOL_CREATE_TRANSIENT_BIT might be appropriate too. - auto commandPool = CommandPool::create(task->device, task->queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); - auto commandBuffer = commandPool->allocate(); - task->instrumentation->init(task->queue, commandBuffer); - } - } - struct DeviceResources { CollectResourceRequirements collectResources; diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index ccc972c795..483564b466 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -29,11 +29,6 @@ Instrumentation::~Instrumentation() { } -void Instrumentation::init(ref_ptr /*queue*/, ref_ptr cmd) -{ - commandBuffer = cmd; -} - ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // VulkanAnnotation uses VK_debug_utils to pass annotation to Vulkan @@ -46,11 +41,11 @@ VulkanAnnotation::~VulkanAnnotation() { } -void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&) const +void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const { if (!commandBuffer) return; - auto extensions = commandBuffer->getDevice()->getInstance()->getExtensions(); + auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); VkDebugUtilsLabelEXT markerInfo = {}; markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; @@ -63,13 +58,13 @@ void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&) const markerInfo.color[2] = static_cast(sl->color[2]) / 255.0; markerInfo.color[3] = static_cast(sl->color[3]) / 255.0; - extensions->vkCmdBeginDebugUtilsLabelEXT(*commandBuffer, &markerInfo); + extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); } -void VulkanAnnotation::leave(const SourceLocation*, uint64_t&) const +void VulkanAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer) const { if (!commandBuffer) return; - auto extensions = commandBuffer->getDevice()->getInstance()->getExtensions(); - extensions->vkCmdEndDebugUtilsLabelEXT(*commandBuffer); + auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); + extensions->vkCmdEndDebugUtilsLabelEXT(commandBuffer); } diff --git a/src/vsg/vk/CommandPool.cpp b/src/vsg/vk/CommandPool.cpp index fc5520bbfe..1f8e9f7673 100644 --- a/src/vsg/vk/CommandPool.cpp +++ b/src/vsg/vk/CommandPool.cpp @@ -17,7 +17,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -CommandPool::CommandPool(Device* device, uint32_t queueFamilyIndex, VkCommandPoolCreateFlags flags) : +CommandPool::CommandPool(Device* device, uint32_t in_queueFamilyIndex, VkCommandPoolCreateFlags in_flags) : + queueFamilyIndex(in_queueFamilyIndex), + flags(in_flags), _device(device) { VkCommandPoolCreateInfo poolInfo = {}; From 662f62717228f0f035d3cede9dbccc6f575f4612 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 14 Dec 2023 17:12:08 +0000 Subject: [PATCH 15/68] Added instrumentation of Bin --- include/vsg/app/RecordTraversal.h | 1 + src/vsg/app/RecordTraversal.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index db9747a406..45cbab6165 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -123,6 +123,7 @@ namespace vsg void apply(const Command& command); // Viewer level nodes + void apply(const Bin& bin); void apply(const View& view); void apply(const CommandGraph& commandGraph); diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index dcc2f9c486..76d4f2a190 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -416,6 +416,14 @@ void RecordTraversal::apply(const Command& command) command.record(*(_state->_commandBuffer)); } +void RecordTraversal::apply(const Bin& object) +{ + SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + + //debug("Visiting Bin"); + object.traverse(*this); +} + void RecordTraversal::apply(const View& view) { SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); From 0bdfc500f5e99dddd65a86dd2a7c020d3cda7544 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 15 Dec 2023 16:58:40 +0000 Subject: [PATCH 16/68] Added VertexIndexDraw, VertexDraw and Geometry to list of RecordTraversal::apply() to enable more useful instrumentation --- include/vsg/app/RecordTraversal.h | 10 +++++++ src/vsg/app/RecordTraversal.cpp | 50 ++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index 45cbab6165..ab0181fb8d 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -35,6 +35,9 @@ namespace vsg class DepthSorted; class Transform; class MatrixTransform; + class VertexDraw; + class VertexIndexDraw; + class Geometry; class Command; class Commands; class CommandBuffer; @@ -108,6 +111,11 @@ namespace vsg void apply(const DepthSorted& depthSorted); void apply(const Switch& sw); + // leaf node + void apply(const VertexDraw& vid); + void apply(const VertexIndexDraw& vid); + void apply(const Geometry& vid); + // positional state void apply(const Light& light); void apply(const AmbientLight& light); @@ -119,6 +127,8 @@ namespace vsg void apply(const Transform& transform); void apply(const MatrixTransform& mt); void apply(const StateGroup& object); + + // Commands void apply(const Commands& commands); void apply(const Command& command); diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 76d4f2a190..a2b87d16d1 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -32,6 +32,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include +#include +#include #include #include #include @@ -264,10 +267,23 @@ void RecordTraversal::apply(const CullNode& cullNode) } } -void RecordTraversal::apply(const DepthSorted& depthSorted) +void RecordTraversal::apply(const Switch& sw) { SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + for (auto& child : sw.children) + { + if ((traversalMask & (overrideMask | child.mask)) != MASK_OFF) + { + child.node->accept(*this); + } + } +} + +void RecordTraversal::apply(const DepthSorted& depthSorted) +{ + SCOPED_INSTRUMENTATION(instrumentation); + if (_state->intersect(depthSorted.bound)) { const auto& mv = _state->modelviewMatrixStack.top(); @@ -278,17 +294,31 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) } } -void RecordTraversal::apply(const Switch& sw) +void RecordTraversal::apply(const VertexDraw& vd) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); - for (auto& child : sw.children) - { - if ((traversalMask & (overrideMask | child.mask)) != MASK_OFF) - { - child.node->accept(*this); - } - } + //debug("Visiting VertexDraw"); + _state->record(); + vd.record(*(_state->_commandBuffer)); +} + +void RecordTraversal::apply(const VertexIndexDraw& vid) +{ + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + + //debug("Visiting VertexIndexDraw"); + _state->record(); + vid.record(*(_state->_commandBuffer)); +} + +void RecordTraversal::apply(const Geometry& geometry) +{ + SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + + //debug("Visiting Geometry"); + _state->record(); + geometry.record(*(_state->_commandBuffer)); } void RecordTraversal::apply(const Light& /*light*/) From b8513ae98b88848e3ab42924c9bbabf00fac43f0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 15 Dec 2023 19:06:38 +0000 Subject: [PATCH 17/68] Added Viewer::assignInstrumentation(..) method to help with setting up the viewer and associated objects with Instrumentation --- include/vsg/app/Viewer.h | 5 ++++- src/vsg/app/Viewer.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/vsg/app/Viewer.h b/include/vsg/app/Viewer.h index 211a230e19..6e2b4462ff 100644 --- a/include/vsg/app/Viewer.h +++ b/include/vsg/app/Viewer.h @@ -134,9 +134,12 @@ namespace vsg /// Call vkDeviceWaitIdle on all the devices associated with this Viewer virtual void deviceWaitIdle() const; - /// hook for assigning Instrumentation to enable profiling of record traversal. + /// Hook for assigning Instrumentation to enable profiling of record traversal. ref_ptr instrumentation; + /// Convenience method for assigning Instrumentation to the viewer and any associated objects. + void assignInstrumentation(ref_ptr in_instrumentation); + protected: virtual ~Viewer(); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 0f03e432ca..0fec310290 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -830,6 +830,33 @@ void Viewer::present() } } +void Viewer::assignInstrumentation(ref_ptr in_instrumentation) +{ + bool previous_threading = _threading; + if (_threading) stopThreading(); + + // don't change Instrumentation while devices are still active + Viewer::deviceWaitIdle(); + + instrumentation = in_instrumentation; + + // assign instrumentation after settings up recordAndSubmitTasks, but before compile() to allow compile to initialize the Instrumentation with the approach queue etc. + for(auto& task : recordAndSubmitTasks) + { + task->instrumentation = instrumentation; + if (task->earlyTransferTask) task->earlyTransferTask->instrumentation = task->instrumentation; + if (task->lateTransferTask) task->lateTransferTask->instrumentation = task->instrumentation; + + for(auto cg : task->commandGraphs) + { + cg->instrumentation = task->instrumentation; + cg->getOrCreateRecordTraversal()->instrumentation = task->instrumentation; + } + } + + if (previous_threading) setupThreading(); +} + void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { SCOPED_INSTRUMENTATION(viewer.instrumentation); From 1dff3d83b7b73c4f1403a359d2ba33cd10cfd5dd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 16 Dec 2023 11:04:44 +0000 Subject: [PATCH 18/68] Added Instrumentation::enterFrame() and leaveFrame(). --- include/vsg/utils/Instrumentation.h | 6 ++++++ src/vsg/app/Viewer.cpp | 17 ++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 6f1da4217e..9e2a0f1e6f 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -46,6 +46,9 @@ namespace vsg public: Instrumentation(); + virtual void enterFrame(vsg::ref_ptr frameStamp) = 0; + virtual void leaveFrame(vsg::ref_ptr frameStamp) = 0; + virtual void enterCommandBuffer(vsg::ref_ptr commandBuffer) = 0; virtual void leaveCommandBuffer() = 0; @@ -67,6 +70,9 @@ namespace vsg public: VulkanAnnotation(); + void enterFrame(vsg::ref_ptr) override {}; + void leaveFrame(vsg::ref_ptr) override {}; + void enterCommandBuffer(vsg::ref_ptr) override {} void leaveCommandBuffer() override {} diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 0fec310290..410562c598 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -155,6 +155,8 @@ bool Viewer::advanceToNextFrame() if (!active()) return false; + if (instrumentation && _frameStamp) instrumentation->leaveFrame(_frameStamp); + // poll all the windows for events. pollEvents(true); @@ -166,23 +168,20 @@ bool Viewer::advanceToNextFrame() { // first frame, initialize to frame count and indices to 0 _frameStamp = FrameStamp::create(time, 0); - - for (auto& task : recordAndSubmitTasks) - { - task->advance(); - } } else { // after first frame so increment frame count and indices _frameStamp = FrameStamp::create(time, _frameStamp->frameCount + 1); + } - for (auto& task : recordAndSubmitTasks) - { - task->advance(); - } + for (auto& task : recordAndSubmitTasks) + { + task->advance(); } + if (instrumentation) instrumentation->enterFrame(_frameStamp); + // create an event for the new frame. _events.emplace_back(new FrameEvent(_frameStamp)); From b46f6cac0f20ee3bd64c6b49f24ecd9f32b72ff3 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 16 Dec 2023 11:15:45 +0000 Subject: [PATCH 19/68] Build fix for Windows --- include/vsg/utils/Instrumentation.h | 1 + src/vsg/utils/Instrumentation.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 9e2a0f1e6f..a0abbd75fa 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -28,6 +28,7 @@ namespace vsg class Device; class Queue; class CommandBuffer; + class FrameStamp; /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 483564b466..66f7a27361 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -14,6 +14,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include using namespace vsg; From fb192eaadf8bd09ff5422584dc05b5d32c54383c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 16 Dec 2023 12:28:03 +0000 Subject: [PATCH 20/68] Replaced ref_ptr<> with reference --- include/vsg/utils/Instrumentation.h | 13 +++++++------ src/vsg/app/CommandGraph.cpp | 2 +- src/vsg/app/Viewer.cpp | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index a0abbd75fa..8bbd276c7e 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -47,10 +47,10 @@ namespace vsg public: Instrumentation(); - virtual void enterFrame(vsg::ref_ptr frameStamp) = 0; - virtual void leaveFrame(vsg::ref_ptr frameStamp) = 0; + virtual void enterFrame(FrameStamp& frameStamp) = 0; + virtual void leaveFrame(FrameStamp& frameStamp) = 0; - virtual void enterCommandBuffer(vsg::ref_ptr commandBuffer) = 0; + virtual void enterCommandBuffer(CommandBuffer& commandBuffer) = 0; virtual void leaveCommandBuffer() = 0; virtual void enter(const SourceLocation* sl, uint64_t& reference) const = 0; @@ -71,10 +71,11 @@ namespace vsg public: VulkanAnnotation(); - void enterFrame(vsg::ref_ptr) override {}; - void leaveFrame(vsg::ref_ptr) override {}; - void enterCommandBuffer(vsg::ref_ptr) override {} + void enterFrame(FrameStamp&) override {}; + void leaveFrame(FrameStamp&) override {}; + + void enterCommandBuffer(CommandBuffer&) override {} void leaveCommandBuffer() override {} void enter(const SourceLocation*, uint64_t&) const override {} diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 60314128a9..12ddb23940 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -136,7 +136,7 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); - if (instrumentation) instrumentation->enterCommandBuffer(commandBuffer); + if (instrumentation) instrumentation->enterCommandBuffer(*commandBuffer); traverse(*recordTraversal); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 410562c598..2e1e722b45 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -155,7 +155,7 @@ bool Viewer::advanceToNextFrame() if (!active()) return false; - if (instrumentation && _frameStamp) instrumentation->leaveFrame(_frameStamp); + if (instrumentation && _frameStamp) instrumentation->leaveFrame(*_frameStamp); // poll all the windows for events. pollEvents(true); @@ -180,7 +180,7 @@ bool Viewer::advanceToNextFrame() task->advance(); } - if (instrumentation) instrumentation->enterFrame(_frameStamp); + if (instrumentation) instrumentation->enterFrame(*_frameStamp); // create an event for the new frame. _events.emplace_back(new FrameEvent(_frameStamp)); From b0b4814676b6fc54a536c3bdf4f5355a42297265 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 16 Dec 2023 18:09:01 +0000 Subject: [PATCH 21/68] Added VSG_MAX_INSTRUMENTATION_LEVEL cmake controlled #define for controlling what level of instrumentation is compiled into the VSG --- CMakeLists.txt | 3 ++ include/vsg/utils/Instrumentation.h | 76 +++++++++++++++++++---------- src/vsg/core/Version.h.in | 3 ++ 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64fe97cfcc..126e2afefc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,9 @@ find_package(Vulkan ${Vulkan_MIN_VERSION} REQUIRED) find_package(Threads REQUIRED) +# Set the instrumentation level to compile into sources +set(VSG_MAX_INSTRUMENTATION_LEVEL 1 CACHE STRING "Set the instrumentation level to build into the VSG ibrary, 0 for off, 1 coarse grained, 2 medium, 3 fine grained." ) + # Enable/disable shader compilation support that pulls in glslang set(VSG_SUPPORTS_ShaderCompiler 1 CACHE STRING "Optional shader compiler support, 0 for off, 1 for enabled." ) if (VSG_SUPPORTS_ShaderCompiler) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 8bbd276c7e..55aa2d81a0 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ +#include #include #include #include @@ -30,6 +31,11 @@ namespace vsg class CommandBuffer; class FrameStamp; + #define VSG_INSTUMENTATION_OFF 0 + #define VSG_INSTUMENTATION_COARSE 1 + #define VSG_INSTUMENTATION_MEDIUM 2 + #define VSG_INSTUMENTATION_FINE 3 + /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -39,6 +45,7 @@ namespace vsg const char* file; uint32_t line; ubvec4 color; + uint32_t level; }; /// base class for Instrumentation implentations @@ -123,31 +130,50 @@ namespace vsg } }; -#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_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_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_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__)); - -#define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); -#define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255)}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); -#define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); -#define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); +#if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 + + #define SCOPED_INSTRUMENTATION(instrumentation) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + + #define COARS_L1_INSTRUMENTATION_N(instrumentation, name) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + + #define SCOPED_INSTRUMENTATION_C(instrumentation, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ + ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + + #define SCOPED_INSTRUMENTATION_NC(instrumentation, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ + ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + + #define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + #define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + + #define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + + #define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ + ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + +#else + #define SCOPED_INSTRUMENTATION(instrumentation) + #define SCOPED_INSTRUMENTATION_N(instrumentation, name) + #define SCOPED_INSTRUMENTATION_C(instrumentation, color) + #define SCOPED_INSTRUMENTATION_NC(instrumentation, name, color) + + #define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) + #define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) + #define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) + #define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) +#endif } // namespace vsg diff --git a/src/vsg/core/Version.h.in b/src/vsg/core/Version.h.in index 1a341c9448..8dd94169c9 100644 --- a/src/vsg/core/Version.h.in +++ b/src/vsg/core/Version.h.in @@ -30,6 +30,9 @@ extern "C" /// maximum number of logical vkDevice supported #define VSG_MAX_DEVICES @VSG_MAX_DEVICES@ + /// Instrumentation level to built into the VSG ibrary, 0 for off, 1 coarse grained, 2 medium, 3 fine grained. + #define VSG_MAX_INSTRUMENTATION_LEVEL @VSG_MAX_INSTRUMENTATION_LEVEL@ + /// vsg::ShaderCompiler support enabled when 1, disabled when 0 #define VSG_SUPPORTS_ShaderCompiler @VSG_SUPPORTS_ShaderCompiler@ From 239ec20abcc25e86fbd956d9fcee52bc8f672b0d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 10:24:34 +0000 Subject: [PATCH 22/68] Added instrumentation laevel to marco usage --- include/vsg/utils/Instrumentation.h | 54 ++++++++++------------------ src/vsg/app/CommandGraph.cpp | 12 +++---- src/vsg/app/RecordAndSubmitTask.cpp | 12 +++---- src/vsg/app/RecordTraversal.cpp | 56 ++++++++++++++--------------- src/vsg/app/TransferTask.cpp | 18 +++++----- src/vsg/app/Viewer.cpp | 38 ++++++++++---------- 6 files changed, 87 insertions(+), 103 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 55aa2d81a0..e9830bd5c3 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -132,48 +132,32 @@ namespace vsg #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 - #define SCOPED_INSTRUMENTATION(instrumentation) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + #define SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - #define COARS_L1_INSTRUMENTATION_N(instrumentation, name) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ - ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - - #define SCOPED_INSTRUMENTATION_C(instrumentation, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ - ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - - #define SCOPED_INSTRUMENTATION_NC(instrumentation, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ - ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + #define SCOPED_INSTRUMENTATION(level, instrumentation) SCOPED_INSTRUMENTATION_NC(level, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) + #define SCOPED_INSTRUMENTATION_N(level, instrumentation, name) SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, ubvec4(255, 255, 255, 255)) + #define SCOPED_INSTRUMENTATION_C(level, instrumentation, color) SCOPED_INSTRUMENTATION_NC(level, instrumentation, nullptr, color) - #define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ + #define SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - #define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - - #define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{nullptr, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - - #define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, 1}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + #define SCOPED_INSTRUMENTATION_CG(level, instrumentation, cg) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #define SCOPED_INSTRUMENTATION_CG_N(level, instrumentation, cg, name) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) + #define SCOPED_INSTRUMENTATION_CG_C(level, instrumentation, cg, color) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, nullptr, color) #else - #define SCOPED_INSTRUMENTATION(instrumentation) - #define SCOPED_INSTRUMENTATION_N(instrumentation, name) - #define SCOPED_INSTRUMENTATION_C(instrumentation, color) - #define SCOPED_INSTRUMENTATION_NC(instrumentation, name, color) - - #define SCOPED_INSTRUMENTATION_CG(instrumentation, cg) - #define SCOPED_INSTRUMENTATION_CG_N(instrumentation, cg, name) - #define SCOPED_INSTRUMENTATION_CG_C(instrumentation, cg, color) - #define SCOPED_INSTRUMENTATION_CG_NC(instrumentation, cg, name, color) + #define SCOPED_INSTRUMENTATION(level, instrumentation) + #define SCOPED_INSTRUMENTATION_N(level, instrumentation, name) + #define SCOPED_INSTRUMENTATION_C(level, instrumentation, color) + #define SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, color) + + #define SCOPED_INSTRUMENTATION_CG(level, instrumentation, cg) + #define SCOPED_INSTRUMENTATION_CG_N(level, instrumentation, cg, name) + #define SCOPED_INSTRUMENTATION_CG_C(level, instrumentation, cg, color) + #define SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, color) #endif } // namespace vsg diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 12ddb23940..0f2374467c 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -22,7 +22,7 @@ using namespace vsg; CommandGraph::CommandGraph() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); } CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : window(in_window), device(in_window->getOrCreateDevice()) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -63,7 +63,7 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (!recordTraversal) { @@ -80,7 +80,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (window && !window->visible()) { diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 5a834ccb6b..bda239e6f6 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -84,7 +84,7 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (VkResult result = start(); result != VK_SUCCESS) return result; @@ -102,7 +102,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); for (auto& commandGraph : commandGraphs) { @@ -132,7 +132,7 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (lateTransferTask) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index a2b87d16d1..7dedd09532 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -52,7 +52,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { // instrumentation = Instrumentation::create(); - SCOPED_INSTRUMENTATION_C(instrumentation, ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_C(1, instrumentation, ubvec4(0, 0, 255, 255)); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -72,7 +72,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -100,7 +100,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); for (auto& bin : _bins) { @@ -110,7 +110,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); //debug("Visiting Object"); object.traverse(*this); @@ -118,7 +118,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -130,7 +130,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -142,7 +142,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); const auto& sphere = lod.bound; @@ -167,7 +167,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -247,7 +247,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); if (_state->intersect(cullGroup.bound)) { @@ -258,7 +258,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); if (_state->intersect(cullNode.bound)) { @@ -269,7 +269,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); for (auto& child : sw.children) { @@ -282,7 +282,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -296,7 +296,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const VertexDraw& vd) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexDraw"); _state->record(); @@ -305,7 +305,7 @@ void RecordTraversal::apply(const VertexDraw& vd) void RecordTraversal::apply(const VertexIndexDraw& vid) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexIndexDraw"); _state->record(); @@ -314,7 +314,7 @@ void RecordTraversal::apply(const VertexIndexDraw& vid) void RecordTraversal::apply(const Geometry& geometry) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Geometry"); _state->record(); @@ -323,14 +323,14 @@ void RecordTraversal::apply(const Geometry& geometry) void RecordTraversal::apply(const Light& /*light*/) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -338,7 +338,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -346,7 +346,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -354,7 +354,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -362,7 +362,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -383,7 +383,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -405,7 +405,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -428,7 +428,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); _state->record(); for (auto& command : commands.children) @@ -439,7 +439,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Command"); _state->record(); @@ -448,7 +448,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const Bin& object) { - SCOPED_INSTRUMENTATION_CG(instrumentation, *getCommandBuffer()); + SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); //debug("Visiting Bin"); object.traverse(*this); @@ -456,7 +456,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -545,7 +545,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - SCOPED_INSTRUMENTATION_CG_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index 3bcdb240e6..2d1a966cfc 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -21,7 +21,7 @@ using namespace vsg; TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : device(in_device) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) @@ -34,7 +34,7 @@ TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : void TransferTask::advance() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -69,7 +69,7 @@ bool TransferTask::containsDataToTransfer() const void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); assign(dynamicData.bufferInfos); assign(dynamicData.imageInfos); @@ -77,7 +77,7 @@ void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) void TransferTask::assign(const BufferInfoList& bufferInfoList) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); for (auto& bufferInfo : bufferInfoList) { @@ -105,7 +105,7 @@ void TransferTask::assign(const BufferInfoList& bufferInfoList) void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -181,7 +181,7 @@ void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::assign(const ImageInfoList& imageInfoList) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -215,7 +215,7 @@ void TransferTask::assign(const ImageInfoList& imageInfoList) void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -245,7 +245,7 @@ void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset, ImageInfo& imageInfo) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -331,7 +331,7 @@ void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& f VkResult TransferTask::transferDynamicData() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 2e1e722b45..c762586f10 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_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); } Viewer::~Viewer() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); stopThreading(); @@ -47,7 +47,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); std::set devices; for (auto& window : _windows) @@ -101,7 +101,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); _close = true; status->set(false); @@ -111,7 +111,7 @@ void Viewer::close() bool Viewer::active() const { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); bool viewerIsActive = !_close; if (viewerIsActive) @@ -136,7 +136,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); bool result = false; @@ -151,7 +151,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (!active()) return false; @@ -190,7 +190,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (_close) return false; @@ -230,7 +230,7 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) @@ -247,7 +247,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); for (auto& vsg_event : _events) { @@ -260,7 +260,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (recordAndSubmitTasks.empty()) { @@ -419,7 +419,7 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); // now remove any commandGraphs associated with window bool needToStartThreading = _threading; @@ -576,7 +576,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -597,7 +597,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); debug("Viewer::setupThreading() "); @@ -749,7 +749,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); if (!_threading) return; _threading = false; @@ -770,7 +770,7 @@ void Viewer::stopThreading() void Viewer::update() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); for (auto& task : recordAndSubmitTasks) { @@ -787,7 +787,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -821,7 +821,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - SCOPED_INSTRUMENTATION(instrumentation); + SCOPED_INSTRUMENTATION(1, instrumentation); for (auto& presentation : presentations) { @@ -858,7 +858,7 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { - SCOPED_INSTRUMENTATION(viewer.instrumentation); + SCOPED_INSTRUMENTATION(1, viewer.instrumentation); updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } From 9444521ab03d6d1cf7d80185b99ac2c1bb1ab03e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 10:30:18 +0000 Subject: [PATCH 23/68] Renamed instrumentation macros to better reflect that function --- include/vsg/utils/Instrumentation.h | 34 +++++++++--------- src/vsg/app/CommandGraph.cpp | 12 +++---- src/vsg/app/RecordAndSubmitTask.cpp | 12 +++---- src/vsg/app/RecordTraversal.cpp | 56 ++++++++++++++--------------- src/vsg/app/TransferTask.cpp | 18 +++++----- src/vsg/app/Viewer.cpp | 38 ++++++++++---------- 6 files changed, 85 insertions(+), 85 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index e9830bd5c3..f3c0811b0f 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -132,32 +132,32 @@ namespace vsg #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 - #define SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, color) \ + #define CPU_INSTRUMENTATION_NC(level, instrumentation, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - #define SCOPED_INSTRUMENTATION(level, instrumentation) SCOPED_INSTRUMENTATION_NC(level, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) - #define SCOPED_INSTRUMENTATION_N(level, instrumentation, name) SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, ubvec4(255, 255, 255, 255)) - #define SCOPED_INSTRUMENTATION_C(level, instrumentation, color) SCOPED_INSTRUMENTATION_NC(level, instrumentation, nullptr, color) + #define CPU_INSTRUMENTATION(level, instrumentation) CPU_INSTRUMENTATION_NC(level, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_N(level, instrumentation, name) CPU_INSTRUMENTATION_NC(level, instrumentation, name, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_C(level, instrumentation, color) CPU_INSTRUMENTATION_NC(level, instrumentation, nullptr, color) - #define SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, color) \ + #define GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - #define SCOPED_INSTRUMENTATION_CG(level, instrumentation, cg) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) - #define SCOPED_INSTRUMENTATION_CG_N(level, instrumentation, cg, name) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) - #define SCOPED_INSTRUMENTATION_CG_C(level, instrumentation, cg, color) SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, nullptr, color) + #define GPU_INSTRUMENTATION(level, instrumentation, cg) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_N(level, instrumentation, cg, name) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_C(level, instrumentation, cg, color) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, nullptr, color) #else - #define SCOPED_INSTRUMENTATION(level, instrumentation) - #define SCOPED_INSTRUMENTATION_N(level, instrumentation, name) - #define SCOPED_INSTRUMENTATION_C(level, instrumentation, color) - #define SCOPED_INSTRUMENTATION_NC(level, instrumentation, name, color) - - #define SCOPED_INSTRUMENTATION_CG(level, instrumentation, cg) - #define SCOPED_INSTRUMENTATION_CG_N(level, instrumentation, cg, name) - #define SCOPED_INSTRUMENTATION_CG_C(level, instrumentation, cg, color) - #define SCOPED_INSTRUMENTATION_CG_NC(level, instrumentation, cg, name, color) + #define CPU_INSTRUMENTATION(level, instrumentation) + #define CPU_INSTRUMENTATION_N(level, instrumentation, name) + #define CPU_INSTRUMENTATION_C(level, instrumentation, color) + #define CPU_INSTRUMENTATION_NC(level, instrumentation, name, color) + + #define GPU_INSTRUMENTATION(level, instrumentation, cg) + #define GPU_INSTRUMENTATION_N(level, instrumentation, cg, name) + #define GPU_INSTRUMENTATION_C(level, instrumentation, cg, color) + #define GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, color) #endif } // namespace vsg diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 0f2374467c..c483769ca9 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -22,7 +22,7 @@ using namespace vsg; CommandGraph::CommandGraph() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); } CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : window(in_window), device(in_window->getOrCreateDevice()) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -63,7 +63,7 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (!recordTraversal) { @@ -80,7 +80,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (window && !window->visible()) { diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index bda239e6f6..8d95b75889 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -84,7 +84,7 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (VkResult result = start(); result != VK_SUCCESS) return result; @@ -102,7 +102,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); for (auto& commandGraph : commandGraphs) { @@ -132,7 +132,7 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (lateTransferTask) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 7dedd09532..850123ac36 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -52,7 +52,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { // instrumentation = Instrumentation::create(); - SCOPED_INSTRUMENTATION_C(1, instrumentation, ubvec4(0, 0, 255, 255)); + CPU_INSTRUMENTATION_C(1, instrumentation, ubvec4(0, 0, 255, 255)); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -72,7 +72,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -100,7 +100,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); for (auto& bin : _bins) { @@ -110,7 +110,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); //debug("Visiting Object"); object.traverse(*this); @@ -118,7 +118,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -130,7 +130,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -142,7 +142,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); const auto& sphere = lod.bound; @@ -167,7 +167,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -247,7 +247,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); if (_state->intersect(cullGroup.bound)) { @@ -258,7 +258,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); if (_state->intersect(cullNode.bound)) { @@ -269,7 +269,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); for (auto& child : sw.children) { @@ -282,7 +282,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -296,7 +296,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const VertexDraw& vd) { - SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexDraw"); _state->record(); @@ -305,7 +305,7 @@ void RecordTraversal::apply(const VertexDraw& vd) void RecordTraversal::apply(const VertexIndexDraw& vid) { - SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexIndexDraw"); _state->record(); @@ -314,7 +314,7 @@ void RecordTraversal::apply(const VertexIndexDraw& vid) void RecordTraversal::apply(const Geometry& geometry) { - SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Geometry"); _state->record(); @@ -323,14 +323,14 @@ void RecordTraversal::apply(const Geometry& geometry) void RecordTraversal::apply(const Light& /*light*/) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -338,7 +338,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -346,7 +346,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -354,7 +354,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - SCOPED_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION(2, instrumentation); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -362,7 +362,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); + GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -383,7 +383,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -405,7 +405,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -428,7 +428,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); _state->record(); for (auto& command : commands.children) @@ -439,7 +439,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - SCOPED_INSTRUMENTATION_CG_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Command"); _state->record(); @@ -448,7 +448,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const Bin& object) { - SCOPED_INSTRUMENTATION_CG(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); //debug("Visiting Bin"); object.traverse(*this); @@ -456,7 +456,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -545,7 +545,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - SCOPED_INSTRUMENTATION_CG_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index 2d1a966cfc..6309b341e3 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -21,7 +21,7 @@ using namespace vsg; TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : device(in_device) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) @@ -34,7 +34,7 @@ TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : void TransferTask::advance() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -69,7 +69,7 @@ bool TransferTask::containsDataToTransfer() const void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); assign(dynamicData.bufferInfos); assign(dynamicData.imageInfos); @@ -77,7 +77,7 @@ void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) void TransferTask::assign(const BufferInfoList& bufferInfoList) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); for (auto& bufferInfo : bufferInfoList) { @@ -105,7 +105,7 @@ void TransferTask::assign(const BufferInfoList& bufferInfoList) void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -181,7 +181,7 @@ void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::assign(const ImageInfoList& imageInfoList) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -215,7 +215,7 @@ void TransferTask::assign(const ImageInfoList& imageInfoList) void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -245,7 +245,7 @@ void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset, ImageInfo& imageInfo) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -331,7 +331,7 @@ void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& f VkResult TransferTask::transferDynamicData() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index c762586f10..54bc580d7b 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_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); } Viewer::~Viewer() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); stopThreading(); @@ -47,7 +47,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); std::set devices; for (auto& window : _windows) @@ -101,7 +101,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); _close = true; status->set(false); @@ -111,7 +111,7 @@ void Viewer::close() bool Viewer::active() const { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); bool viewerIsActive = !_close; if (viewerIsActive) @@ -136,7 +136,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); bool result = false; @@ -151,7 +151,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (!active()) return false; @@ -190,7 +190,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (_close) return false; @@ -230,7 +230,7 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) @@ -247,7 +247,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); for (auto& vsg_event : _events) { @@ -260,7 +260,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (recordAndSubmitTasks.empty()) { @@ -419,7 +419,7 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); // now remove any commandGraphs associated with window bool needToStartThreading = _threading; @@ -576,7 +576,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -597,7 +597,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); debug("Viewer::setupThreading() "); @@ -749,7 +749,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); if (!_threading) return; _threading = false; @@ -770,7 +770,7 @@ void Viewer::stopThreading() void Viewer::update() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); for (auto& task : recordAndSubmitTasks) { @@ -787,7 +787,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -821,7 +821,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - SCOPED_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION(1, instrumentation); for (auto& presentation : presentations) { @@ -858,7 +858,7 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { - SCOPED_INSTRUMENTATION(1, viewer.instrumentation); + CPU_INSTRUMENTATION(1, viewer.instrumentation); updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } From 4db307fffa4a35fcb59a7303587d7707db0fb5a8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 11:26:55 +0000 Subject: [PATCH 24/68] Added CPU/GPU_INSTRUMENTATION_L1, _L2, _L3 marcros --- include/vsg/utils/Instrumentation.h | 92 +++++++++++++++++++++-------- src/vsg/app/CommandGraph.cpp | 12 ++-- src/vsg/app/RecordAndSubmitTask.cpp | 12 ++-- src/vsg/app/RecordTraversal.cpp | 57 +++++++++--------- src/vsg/app/TransferTask.cpp | 18 +++--- src/vsg/app/Viewer.cpp | 38 ++++++------ 6 files changed, 137 insertions(+), 92 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index f3c0811b0f..8446298d5c 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -130,34 +130,80 @@ namespace vsg } }; -#if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 - - #define CPU_INSTRUMENTATION_NC(level, instrumentation, name, color) \ + #define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - #define CPU_INSTRUMENTATION(level, instrumentation) CPU_INSTRUMENTATION_NC(level, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_N(level, instrumentation, name) CPU_INSTRUMENTATION_NC(level, instrumentation, name, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_C(level, instrumentation, color) CPU_INSTRUMENTATION_NC(level, instrumentation, nullptr, color) - - #define GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, color) \ + #define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - #define GPU_INSTRUMENTATION(level, instrumentation, cg) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_N(level, instrumentation, cg, name) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_C(level, instrumentation, cg, color) GPU_INSTRUMENTATION_NC(level, instrumentation, cg, nullptr, color) - -#else - #define CPU_INSTRUMENTATION(level, instrumentation) - #define CPU_INSTRUMENTATION_N(level, instrumentation, name) - #define CPU_INSTRUMENTATION_C(level, instrumentation, color) - #define CPU_INSTRUMENTATION_NC(level, instrumentation, name, color) - - #define GPU_INSTRUMENTATION(level, instrumentation, cg) - #define GPU_INSTRUMENTATION_N(level, instrumentation, cg, name) - #define GPU_INSTRUMENTATION_C(level, instrumentation, cg, color) - #define GPU_INSTRUMENTATION_NC(level, instrumentation, cg, name, color) -#endif + #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 + #define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) + #define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) + #define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) + #else + #define CPU_INSTRUMENTATION_L1(instrumentation) + #define CPU_INSTRUMENTATION_L1_N(instrumentation, name) + #define CPU_INSTRUMENTATION_L1_C(instrumentation, color) + #define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L1(instrumentation, cg) + #define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) + #define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) + #define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) + #endif + + + #if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 + #define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color) + #define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) + #define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) + #else + #define CPU_INSTRUMENTATION_L2(instrumentation) + #define CPU_INSTRUMENTATION_L2_N(instrumentation, name) + #define CPU_INSTRUMENTATION_L2_C(instrumentation, color) + #define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L2(instrumentation, cg) + #define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) + #define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) + #define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) + #endif + + + #if VSG_MAX_INSTRUMENTATION_LEVEL >= 3 + #define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, ubvec4(255, 255, 255, 255)) + #define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color) + #define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) + #define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) + #define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) + #else + #define CPU_INSTRUMENTATION_L3(instrumentation) + #define CPU_INSTRUMENTATION_L3_N(instrumentation, name) + #define CPU_INSTRUMENTATION_L3_C(instrumentation, color) + #define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) + + #define GPU_INSTRUMENTATION_L3(instrumentation, cg) + #define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) + #define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) + #define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) + #endif } // namespace vsg diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index c483769ca9..06e1533a2e 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -22,7 +22,7 @@ using namespace vsg; CommandGraph::CommandGraph() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(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) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); } CommandGraph::CommandGraph(ref_ptr in_window, ref_ptr child) : window(in_window), device(in_window->getOrCreateDevice()) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(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() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); } VkCommandBufferLevel CommandGraph::level() const @@ -63,7 +63,7 @@ void CommandGraph::reset() ref_ptr CommandGraph::getOrCreateRecordTraversal() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (!recordTraversal) { @@ -80,7 +80,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (window && !window->visible()) { diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 8d95b75889..ccca30d142 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) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(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() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -84,7 +84,7 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (VkResult result = start(); result != VK_SUCCESS) return result; @@ -102,7 +102,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(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) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); for (auto& commandGraph : commandGraphs) { @@ -132,7 +132,7 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (lateTransferTask) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 850123ac36..a0373c8771 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -51,8 +51,7 @@ using namespace vsg; RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { - // instrumentation = Instrumentation::create(); - CPU_INSTRUMENTATION_C(1, instrumentation, ubvec4(0, 0, 255, 255)); + CPU_INSTRUMENTATION_L1_C(instrumentation, ubvec4(0, 0, 255, 255)); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -72,7 +71,7 @@ RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : RecordTraversal::~RecordTraversal() { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); } CommandBuffer* RecordTraversal::getCommandBuffer() @@ -100,7 +99,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); for (auto& bin : _bins) { @@ -110,7 +109,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); //debug("Visiting Object"); object.traverse(*this); @@ -118,7 +117,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -130,7 +129,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -142,7 +141,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); const auto& sphere = lod.bound; @@ -167,7 +166,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -247,7 +246,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); if (_state->intersect(cullGroup.bound)) { @@ -258,7 +257,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); if (_state->intersect(cullNode.bound)) { @@ -269,7 +268,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); for (auto& child : sw.children) { @@ -282,7 +281,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); if (_state->intersect(depthSorted.bound)) { @@ -296,7 +295,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const VertexDraw& vd) { - GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexDraw"); _state->record(); @@ -305,7 +304,7 @@ void RecordTraversal::apply(const VertexDraw& vd) void RecordTraversal::apply(const VertexIndexDraw& vid) { - GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting VertexIndexDraw"); _state->record(); @@ -314,7 +313,7 @@ void RecordTraversal::apply(const VertexIndexDraw& vid) void RecordTraversal::apply(const Geometry& geometry) { - GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Geometry"); _state->record(); @@ -323,14 +322,14 @@ void RecordTraversal::apply(const Geometry& geometry) void RecordTraversal::apply(const Light& /*light*/) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); //debug("RecordTraversal::apply(Light) ", light.className()); } void RecordTraversal::apply(const AmbientLight& light) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -338,7 +337,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -346,7 +345,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -354,7 +353,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - CPU_INSTRUMENTATION(2, instrumentation); + CPU_INSTRUMENTATION_L2(instrumentation); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -362,7 +361,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); + GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -383,7 +382,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -405,7 +404,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -428,7 +427,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); _state->record(); for (auto& command : commands.children) @@ -439,7 +438,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - GPU_INSTRUMENTATION_C(3, instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); //debug("Visiting Command"); _state->record(); @@ -448,7 +447,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const Bin& object) { - GPU_INSTRUMENTATION(2, instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); //debug("Visiting Bin"); object.traverse(*this); @@ -456,7 +455,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -545,7 +544,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - GPU_INSTRUMENTATION_C(2, instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index 6309b341e3..04c2c72ca3 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -21,7 +21,7 @@ using namespace vsg; TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : device(in_device) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); _currentFrameIndex = numBuffers; // numBuffers is used to signify unset value for (uint32_t i = 0; i < numBuffers; ++i) @@ -34,7 +34,7 @@ TransferTask::TransferTask(Device* in_device, uint32_t numBuffers) : void TransferTask::advance() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (_currentFrameIndex >= _indices.size()) { @@ -69,7 +69,7 @@ bool TransferTask::containsDataToTransfer() const void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); assign(dynamicData.bufferInfos); assign(dynamicData.imageInfos); @@ -77,7 +77,7 @@ void TransferTask::assign(const ResourceRequirements::DynamicData& dynamicData) void TransferTask::assign(const BufferInfoList& bufferInfoList) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); for (auto& bufferInfo : bufferInfoList) { @@ -105,7 +105,7 @@ void TransferTask::assign(const BufferInfoList& bufferInfoList) void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -181,7 +181,7 @@ void TransferTask::_transferBufferInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::assign(const ImageInfoList& imageInfoList) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -215,7 +215,7 @@ void TransferTask::assign(const ImageInfoList& imageInfoList) void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -245,7 +245,7 @@ void TransferTask::_transferImageInfos(VkCommandBuffer vk_commandBuffer, Frame& void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& frame, VkDeviceSize& offset, ImageInfo& imageInfo) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -331,7 +331,7 @@ void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& f VkResult TransferTask::transferDynamicData() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 54bc580d7b..f0feb0c2ac 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()) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); } Viewer::~Viewer() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); stopThreading(); @@ -47,7 +47,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); std::set devices; for (auto& window : _windows) @@ -101,7 +101,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); _close = true; status->set(false); @@ -111,7 +111,7 @@ void Viewer::close() bool Viewer::active() const { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); bool viewerIsActive = !_close; if (viewerIsActive) @@ -136,7 +136,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); bool result = false; @@ -151,7 +151,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (!active()) return false; @@ -190,7 +190,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (_close) return false; @@ -230,7 +230,7 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) @@ -247,7 +247,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); for (auto& vsg_event : _events) { @@ -260,7 +260,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (recordAndSubmitTasks.empty()) { @@ -419,7 +419,7 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); // now remove any commandGraphs associated with window bool needToStartThreading = _threading; @@ -576,7 +576,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -597,7 +597,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); debug("Viewer::setupThreading() "); @@ -749,7 +749,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); if (!_threading) return; _threading = false; @@ -770,7 +770,7 @@ void Viewer::stopThreading() void Viewer::update() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); for (auto& task : recordAndSubmitTasks) { @@ -787,7 +787,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -821,7 +821,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - CPU_INSTRUMENTATION(1, instrumentation); + CPU_INSTRUMENTATION_L1(instrumentation); for (auto& presentation : presentations) { @@ -858,7 +858,7 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { - CPU_INSTRUMENTATION(1, viewer.instrumentation); + CPU_INSTRUMENTATION_L1(viewer.instrumentation); updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } From f96580c85d16f5dfc649a480b3bda4b1a87ee628 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 16:33:53 +0000 Subject: [PATCH 25/68] refined class naming and moved GpuAnnotation into it's own header/source --- include/vsg/utils/GpuAnnotation.h | 44 ++++++++++++++++++++++++ include/vsg/utils/Instrumentation.h | 42 +++++------------------ src/vsg/CMakeLists.txt | 1 + src/vsg/app/CommandGraph.cpp | 3 +- src/vsg/utils/GpuAnnotation.cpp | 53 +++++++++++++++++++++++++++++ src/vsg/utils/Instrumentation.cpp | 40 ---------------------- 6 files changed, 109 insertions(+), 74 deletions(-) create mode 100644 include/vsg/utils/GpuAnnotation.h create mode 100644 src/vsg/utils/GpuAnnotation.cpp diff --git a/include/vsg/utils/GpuAnnotation.h b/include/vsg/utils/GpuAnnotation.h new file mode 100644 index 0000000000..0c27806ee0 --- /dev/null +++ b/include/vsg/utils/GpuAnnotation.h @@ -0,0 +1,44 @@ +#pragma once + +/* + +Copyright(c) 2023 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include + +namespace vsg +{ + + /// GpuAnnotationo is a vsg::Instrumentation subclasses that uses VK_debug_utils to emit annotation of the scene graph traversal. + /// Provides tools like RenderDoc a way to report the source location associated with Vulkan calls. + class VSG_DECLSPEC GpuAnnotation : public Inherit + { + public: + GpuAnnotation(); + + void enterFrame(FrameStamp&) override {}; + void leaveFrame(FrameStamp&) override {}; + + void enterCommandBuffer(CommandBuffer&) override {} + void leaveCommandBuffer() override {} + + void enter(const SourceLocation*, uint64_t&) const override {} + void leave(const SourceLocation*, uint64_t&) const override {} + + void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; + void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; + + protected: + virtual ~GpuAnnotation(); + }; + VSG_type_name(vsg::GpuAnnotation); + +} // namespace vsg diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 8446298d5c..7b192dddf9 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -31,6 +31,7 @@ namespace vsg class CommandBuffer; class FrameStamp; + // Instrumentation uint32_t level defines/meanings #define VSG_INSTUMENTATION_OFF 0 #define VSG_INSTUMENTATION_COARSE 1 #define VSG_INSTUMENTATION_MEDIUM 2 @@ -71,60 +72,35 @@ namespace vsg }; VSG_type_name(vsg::Instrumentation); - /// Concrete Implementation that uses VK_debug_utils to emit annotation to scene graph traversal. - /// Provides tools like RenderDoc a way to report the source location associated with Vulkan calls. - class VSG_DECLSPEC VulkanAnnotation : public Inherit - { - public: - VulkanAnnotation(); - - - void enterFrame(FrameStamp&) override {}; - void leaveFrame(FrameStamp&) override {}; - - void enterCommandBuffer(CommandBuffer&) override {} - void leaveCommandBuffer() override {} - - void enter(const SourceLocation*, uint64_t&) const override {} - void leave(const SourceLocation*, uint64_t&) const override {} - - void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; - void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; - - protected: - virtual ~VulkanAnnotation(); - }; - VSG_type_name(vsg::VulkanAnnotation); - - struct ScopedInstrumentation + struct CpuInstrumentation { const Instrumentation* instr; const SourceLocation* sl; uint64_t reference; - inline ScopedInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : + inline CpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : instr(in_instr), sl(in_sl) { if (instr) instr->enter(sl, reference); } - inline ~ScopedInstrumentation() + inline ~CpuInstrumentation() { if (instr) instr->leave(sl, reference); } }; - struct ScopedInstrumentationCG + struct GpuInstrumentation { const Instrumentation* instr; const SourceLocation* sl; uint64_t reference; CommandBuffer& commandBuffer; - inline ScopedInstrumentationCG(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer) : + inline GpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer) : instr(in_instr), sl(in_sl), commandBuffer(in_commandBuffer) { if (instr) instr->enter(sl, reference, commandBuffer); } - inline ~ScopedInstrumentationCG() + inline ~GpuInstrumentation() { if (instr) instr->leave(sl, reference, commandBuffer); } @@ -132,11 +108,11 @@ namespace vsg #define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - ScopedInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); + CpuInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); #define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - ScopedInstrumentationCG __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); + GpuInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 #define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 4c7320325c..3aa163d002 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -224,6 +224,7 @@ set(SOURCES utils/ComputeBounds.cpp utils/Intersector.cpp utils/Instrumentation.cpp + utils/GpuAnnotation.cpp utils/LineSegmentIntersector.cpp utils/LoadPagedLOD.cpp ) diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 06e1533a2e..43e0776011 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -16,6 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include using namespace vsg; @@ -70,7 +71,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() recordTraversal = RecordTraversal::create(maxSlot); if (!recordTraversal->instrumentation && window && window->traits() && window->traits()->apiDumpLayer) { - recordTraversal->instrumentation = VulkanAnnotation::create(); + recordTraversal->instrumentation = GpuAnnotation::create(); } info("CommandGraph::getOrCreateRecordTraversal() ", recordTraversal); diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp new file mode 100644 index 0000000000..5de5f95aea --- /dev/null +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -0,0 +1,53 @@ +/* + +Copyright(c) 2023 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include + +using namespace vsg; + +GpuAnnotation::GpuAnnotation() +{ +} + +GpuAnnotation::~GpuAnnotation() +{ +} + +void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const +{ + if (!commandBuffer) return; + + auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); + + VkDebugUtilsLabelEXT markerInfo = {}; + markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + if (sl->name) + markerInfo.pLabelName = sl->name; + else + markerInfo.pLabelName = sl->function; + markerInfo.color[0] = static_cast(sl->color[0]) / 255.0; + markerInfo.color[1] = static_cast(sl->color[1]) / 255.0; + markerInfo.color[2] = static_cast(sl->color[2]) / 255.0; + markerInfo.color[3] = static_cast(sl->color[3]) / 255.0; + + extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); +} + +void GpuAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer) const +{ + if (!commandBuffer) return; + + auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); + extensions->vkCmdEndDebugUtilsLabelEXT(commandBuffer); +} diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 66f7a27361..d33de32f82 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -29,43 +29,3 @@ Instrumentation::Instrumentation() Instrumentation::~Instrumentation() { } - -////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// VulkanAnnotation uses VK_debug_utils to pass annotation to Vulkan -// -VulkanAnnotation::VulkanAnnotation() -{ -} - -VulkanAnnotation::~VulkanAnnotation() -{ -} - -void VulkanAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const -{ - if (!commandBuffer) return; - - auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); - - VkDebugUtilsLabelEXT markerInfo = {}; - markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - if (sl->name) - markerInfo.pLabelName = sl->name; - else - markerInfo.pLabelName = sl->function; - markerInfo.color[0] = static_cast(sl->color[0]) / 255.0; - markerInfo.color[1] = static_cast(sl->color[1]) / 255.0; - markerInfo.color[2] = static_cast(sl->color[2]) / 255.0; - markerInfo.color[3] = static_cast(sl->color[3]) / 255.0; - - extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); -} - -void VulkanAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer) const -{ - if (!commandBuffer) return; - - auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); - extensions->vkCmdEndDebugUtilsLabelEXT(commandBuffer); -} From 7e5040d36cb8607e430d01f40fe85f5a02240676 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 16:38:02 +0000 Subject: [PATCH 26/68] Added header online TracyInstrumentation header to eanble use of Tracy witout the the VSG itself being compiled against Tracy - only client applications that want to use need to. --- include/vsg/utils/TracyInstrumentation.h | 144 +++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 include/vsg/utils/TracyInstrumentation.h diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h new file mode 100644 index 0000000000..64fe453b10 --- /dev/null +++ b/include/vsg/utils/TracyInstrumentation.h @@ -0,0 +1,144 @@ +#pragma once + +/* + +Copyright(c) 2023 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include + +#include + +using namespace tracy; + +namespace vsg +{ + +class TracyInstrumentation : public vsg::Inherit +{ +public: + + TracyInstrumentation() + { + } + + mutable std::map ctxMap; + mutable VkCtx* ctx = nullptr; + + uint32_t cpu_instumentation_level = 3; + uint32_t gpu_instumentation_level = 3; + + void enterFrame(vsg::FrameStamp&) override {} + + void leaveFrame(vsg::FrameStamp&) override + { + FrameMark; + } + + void enterCommandBuffer(vsg::CommandBuffer& commandBuffer) override + { + auto device = commandBuffer.getDevice(); + ctx = ctxMap[device]; + if (!ctx) + { + auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); + auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto temporaryCommandBuffer = commandPool->allocate(); + ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + } + + if (ctx) + { + TracyVkCollect(ctx, commandBuffer.vk()); + } + } + + void leaveCommandBuffer() override + { + ctx = nullptr; + } + + void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override + { + if (!GetProfiler().IsConnected() || (slcloc->level > cpu_instumentation_level)) + { + reference = 0; + return; + } + + reference = GetProfiler().ConnectionId(); + + TracyQueuePrepare( QueueType::ZoneBegin ); + MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); + MemWrite( &item->zoneBegin.srcloc, (uint64_t)slcloc ); + TracyQueueCommit( zoneBeginThread ); + } + + void leave(const vsg::SourceLocation*, uint64_t& reference) const override + { + if( reference==0 || GetProfiler().ConnectionId() != reference ) return; + + TracyQueuePrepare( QueueType::ZoneEnd ); + MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); + TracyQueueCommit( zoneEndThread ); + } + + void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + { + if (!GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) + { + reference = 0; + return; + } + + reference = GetProfiler().ConnectionId(); + + const auto queryId = ctx->NextQueryId(); + CONTEXT_VK_FUNCTION_WRAPPER( vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId ) ); + + auto item = Profiler::QueueSerial(); + MemWrite( &item->hdr.type, QueueType::GpuZoneBeginSerial ); + MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); + MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)slcloc ); + MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() ); + MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); + MemWrite( &item->gpuZoneBegin.context, ctx->GetId() ); + Profiler::QueueSerialFinish(); + } + + void leave(const vsg::SourceLocation* /*slcloc*/, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + { + if( reference==0 || GetProfiler().ConnectionId() != reference ) return; + + const auto queryId = ctx->NextQueryId(); + CONTEXT_VK_FUNCTION_WRAPPER( vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId ) ); + + auto item = Profiler::QueueSerial(); + MemWrite( &item->hdr.type, QueueType::GpuZoneEndSerial ); + MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); + MemWrite( &item->gpuZoneEnd.thread, GetThreadHandle() ); + MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); + MemWrite( &item->gpuZoneEnd.context, ctx->GetId() ); + Profiler::QueueSerialFinish(); + } + +protected: + + ~TracyInstrumentation() + { + for(auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) + { + TracyVkDestroy(itr->second); + } + } +}; + +} From 862fdcf8172e14d31b439e9799297eb19df3efeb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 16:51:41 +0000 Subject: [PATCH 27/68] Removed unneccessary include --- src/vsg/utils/Instrumentation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index d33de32f82..d527c3cd85 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -12,7 +12,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include -#include #include #include From c94b53220c314acc4df9a66809e13304e3219f1b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 17 Dec 2023 16:52:03 +0000 Subject: [PATCH 28/68] Added an removal of TracyInstrumentation.h from the build_all_h to prevent the Tracy dependency spilling over into applications that don't use it. --- cmake/build_all_h.cmake | 3 +++ include/vsg/all.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/cmake/build_all_h.cmake b/cmake/build_all_h.cmake index 0623a3cc6a..6b86fa0bd9 100644 --- a/cmake/build_all_h.cmake +++ b/cmake/build_all_h.cmake @@ -26,6 +26,9 @@ macro(BUILD_ALL_H) file(GLOB RAYTRACING_HEADERS RELATIVE ${INCLUDE_DIR} ${INCLUDE_DIR}/vsg/raytracing/*.h ) file(GLOB MESHSHADERS_HEADERS RELATIVE ${INCLUDE_DIR} ${INCLUDE_DIR}/vsg/meshshaders/*.h ) + # remove items that are inapprorpiate to include in all.h as they are optional have external dependencies not provided by the VSG itself. + list (REMOVE_ITEM UTILS_HEADERS "vsg/utils/TracyInstrumentation.h") + file(READ ${VSG_SOURCE_DIR}/cmake/header_license_preamble.txt ALL_H_CONTENTS) APPEND_INCLUDES(ALL_H_CONTENTS CORE_HEADERS "// Core header files\n") APPEND_INCLUDES(ALL_H_CONTENTS MATHS_HEADERS "// Maths header files\n") diff --git a/include/vsg/all.h b/include/vsg/all.h index da7c22e2b7..efcd782171 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -257,7 +257,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include +#include #include #include #include From f7fded5ab9e768d2ca2019a659f796c921ae6766 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 07:55:56 +0000 Subject: [PATCH 29/68] Cleanup and ran clang-format --- include/vsg/utils/GpuAnnotation.h | 4 +- include/vsg/utils/Instrumentation.h | 170 ++++++++++---------- include/vsg/utils/TracyInstrumentation.h | 190 +++++++++++------------ src/vsg/app/RecordTraversal.cpp | 8 +- src/vsg/app/Viewer.cpp | 4 +- src/vsg/utils/Instrumentation.cpp | 2 +- 6 files changed, 183 insertions(+), 195 deletions(-) diff --git a/include/vsg/utils/GpuAnnotation.h b/include/vsg/utils/GpuAnnotation.h index 0c27806ee0..8856079e1f 100644 --- a/include/vsg/utils/GpuAnnotation.h +++ b/include/vsg/utils/GpuAnnotation.h @@ -24,8 +24,8 @@ namespace vsg public: GpuAnnotation(); - void enterFrame(FrameStamp&) override {}; - void leaveFrame(FrameStamp&) override {}; + void enterFrame(FrameStamp&) override{}; + void leaveFrame(FrameStamp&) override{}; void enterCommandBuffer(CommandBuffer&) override {} void leaveCommandBuffer() override {} diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 7b192dddf9..f8fa2f6473 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -12,31 +12,17 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ -#include #include +#include #include #include namespace vsg { -#if defined(__clang__) || defined(__GNUC__) -# define VsgFunctionName __PRETTY_FUNCTION__ -#elif defined(_MSC_VER) -# define VsgFunctionName __FUNCSIG__ -#endif - - class Device; - class Queue; class CommandBuffer; class FrameStamp; - // Instrumentation uint32_t level defines/meanings - #define VSG_INSTUMENTATION_OFF 0 - #define VSG_INSTUMENTATION_COARSE 1 - #define VSG_INSTUMENTATION_MEDIUM 2 - #define VSG_INSTUMENTATION_FINE 3 - /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -106,80 +92,84 @@ namespace vsg } }; - #define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - CpuInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__)); - - #define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - GpuInstrumentation __scoped_instrumentation(instrumentation, &(s_source_location_##__LINE__), cg); - - #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 - #define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) - #define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) - #define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) - #else - #define CPU_INSTRUMENTATION_L1(instrumentation) - #define CPU_INSTRUMENTATION_L1_N(instrumentation, name) - #define CPU_INSTRUMENTATION_L1_C(instrumentation, color) - #define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L1(instrumentation, cg) - #define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) - #define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) - #define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) - #endif - - - #if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 - #define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color) - #define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) - #define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) - #else - #define CPU_INSTRUMENTATION_L2(instrumentation) - #define CPU_INSTRUMENTATION_L2_N(instrumentation, name) - #define CPU_INSTRUMENTATION_L2_C(instrumentation, color) - #define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L2(instrumentation, cg) - #define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) - #define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) - #define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) - #endif - - - #if VSG_MAX_INSTRUMENTATION_LEVEL >= 3 - #define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, ubvec4(255, 255, 255, 255)) - #define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color) - #define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) - #define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) - #define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) - #else - #define CPU_INSTRUMENTATION_L3(instrumentation) - #define CPU_INSTRUMENTATION_L3_N(instrumentation, name) - #define CPU_INSTRUMENTATION_L3_C(instrumentation, color) - #define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) - - #define GPU_INSTRUMENTATION_L3(instrumentation, cg) - #define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) - #define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) - #define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) - #endif +#if defined(__clang__) || defined(__GNUC__) +# define VsgFunctionName __PRETTY_FUNCTION__ +#elif defined(_MSC_VER) +# define VsgFunctionName __FUNCSIG__ +#endif + +#define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ + CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_source_location_##__LINE__)); + +#define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ + static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ + GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_source_location_##__LINE__), cg); + +#if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 +# define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) +# define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) +# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) +#else +# define CPU_INSTRUMENTATION_L1(instrumentation) +# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) +# define CPU_INSTRUMENTATION_L1_C(instrumentation, color) +# define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L1(instrumentation, cg) +# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) +# define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) +# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) +#endif + +#if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 +# define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color) +# define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) +# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) +#else +# define CPU_INSTRUMENTATION_L2(instrumentation) +# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) +# define CPU_INSTRUMENTATION_L2_C(instrumentation, color) +# define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L2(instrumentation, cg) +# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) +# define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) +# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) +#endif + +#if VSG_MAX_INSTRUMENTATION_LEVEL >= 3 +# define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color) +# define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) +# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) +#else +# define CPU_INSTRUMENTATION_L3(instrumentation) +# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) +# define CPU_INSTRUMENTATION_L3_C(instrumentation, color) +# define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) + +# define GPU_INSTRUMENTATION_L3(instrumentation, cg) +# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) +# define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) +# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) +#endif } // namespace vsg diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 64fe453b10..ca31fa17d7 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -22,123 +22,121 @@ using namespace tracy; namespace vsg { -class TracyInstrumentation : public vsg::Inherit -{ -public: - - TracyInstrumentation() + class TracyInstrumentation : public vsg::Inherit { - } - - mutable std::map ctxMap; - mutable VkCtx* ctx = nullptr; + public: + TracyInstrumentation() + { + } - uint32_t cpu_instumentation_level = 3; - uint32_t gpu_instumentation_level = 3; + mutable std::map ctxMap; + mutable VkCtx* ctx = nullptr; - void enterFrame(vsg::FrameStamp&) override {} + uint32_t cpu_instumentation_level = 3; + uint32_t gpu_instumentation_level = 3; - void leaveFrame(vsg::FrameStamp&) override - { - FrameMark; - } + void enterFrame(vsg::FrameStamp&) override {} - void enterCommandBuffer(vsg::CommandBuffer& commandBuffer) override - { - auto device = commandBuffer.getDevice(); - ctx = ctxMap[device]; - if (!ctx) + void leaveFrame(vsg::FrameStamp&) override { - auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); - auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); - auto temporaryCommandBuffer = commandPool->allocate(); - ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + FrameMark; } - if (ctx) + void enterCommandBuffer(vsg::CommandBuffer& commandBuffer) override { - TracyVkCollect(ctx, commandBuffer.vk()); + auto device = commandBuffer.getDevice(); + ctx = ctxMap[device]; + if (!ctx) + { + auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); + auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto temporaryCommandBuffer = commandPool->allocate(); + ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + } + + if (ctx) + { + TracyVkCollect(ctx, commandBuffer.vk()); + } } - } - void leaveCommandBuffer() override - { - ctx = nullptr; - } - - void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override - { - if (!GetProfiler().IsConnected() || (slcloc->level > cpu_instumentation_level)) + void leaveCommandBuffer() override { - reference = 0; - return; + ctx = nullptr; } - reference = GetProfiler().ConnectionId(); - - TracyQueuePrepare( QueueType::ZoneBegin ); - MemWrite( &item->zoneBegin.time, Profiler::GetTime() ); - MemWrite( &item->zoneBegin.srcloc, (uint64_t)slcloc ); - TracyQueueCommit( zoneBeginThread ); - } - - void leave(const vsg::SourceLocation*, uint64_t& reference) const override - { - if( reference==0 || GetProfiler().ConnectionId() != reference ) return; - - TracyQueuePrepare( QueueType::ZoneEnd ); - MemWrite( &item->zoneEnd.time, Profiler::GetTime() ); - TracyQueueCommit( zoneEndThread ); - } - - void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override - { - if (!GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) + void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override { - reference = 0; - return; + if (!GetProfiler().IsConnected() || (slcloc->level > cpu_instumentation_level)) + { + reference = 0; + return; + } + + reference = GetProfiler().ConnectionId(); + + TracyQueuePrepare(QueueType::ZoneBegin); + MemWrite(&item->zoneBegin.time, Profiler::GetTime()); + MemWrite(&item->zoneBegin.srcloc, (uint64_t)slcloc); + TracyQueueCommit(zoneBeginThread); } - reference = GetProfiler().ConnectionId(); - - const auto queryId = ctx->NextQueryId(); - CONTEXT_VK_FUNCTION_WRAPPER( vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId ) ); - - auto item = Profiler::QueueSerial(); - MemWrite( &item->hdr.type, QueueType::GpuZoneBeginSerial ); - MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() ); - MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)slcloc ); - MemWrite( &item->gpuZoneBegin.thread, GetThreadHandle() ); - MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); - MemWrite( &item->gpuZoneBegin.context, ctx->GetId() ); - Profiler::QueueSerialFinish(); - } - - void leave(const vsg::SourceLocation* /*slcloc*/, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override - { - if( reference==0 || GetProfiler().ConnectionId() != reference ) return; + void leave(const vsg::SourceLocation*, uint64_t& reference) const override + { + if (reference == 0 || GetProfiler().ConnectionId() != reference) return; - const auto queryId = ctx->NextQueryId(); - CONTEXT_VK_FUNCTION_WRAPPER( vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId ) ); + TracyQueuePrepare(QueueType::ZoneEnd); + MemWrite(&item->zoneEnd.time, Profiler::GetTime()); + TracyQueueCommit(zoneEndThread); + } - auto item = Profiler::QueueSerial(); - MemWrite( &item->hdr.type, QueueType::GpuZoneEndSerial ); - MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); - MemWrite( &item->gpuZoneEnd.thread, GetThreadHandle() ); - MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); - MemWrite( &item->gpuZoneEnd.context, ctx->GetId() ); - Profiler::QueueSerialFinish(); - } + void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + { + if (!GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) + { + reference = 0; + return; + } + + reference = GetProfiler().ConnectionId(); + + const auto queryId = ctx->NextQueryId(); + CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); + + auto item = Profiler::QueueSerial(); + MemWrite(&item->hdr.type, QueueType::GpuZoneBeginSerial); + MemWrite(&item->gpuZoneBegin.cpuTime, Profiler::GetTime()); + MemWrite(&item->gpuZoneBegin.srcloc, (uint64_t)slcloc); + MemWrite(&item->gpuZoneBegin.thread, GetThreadHandle()); + MemWrite(&item->gpuZoneBegin.queryId, uint16_t(queryId)); + MemWrite(&item->gpuZoneBegin.context, ctx->GetId()); + Profiler::QueueSerialFinish(); + } -protected: + void leave(const vsg::SourceLocation* /*slcloc*/, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + { + if (reference == 0 || GetProfiler().ConnectionId() != reference) return; + + const auto queryId = ctx->NextQueryId(); + CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); + + auto item = Profiler::QueueSerial(); + MemWrite(&item->hdr.type, QueueType::GpuZoneEndSerial); + MemWrite(&item->gpuZoneEnd.cpuTime, Profiler::GetTime()); + MemWrite(&item->gpuZoneEnd.thread, GetThreadHandle()); + MemWrite(&item->gpuZoneEnd.queryId, uint16_t(queryId)); + MemWrite(&item->gpuZoneEnd.context, ctx->GetId()); + Profiler::QueueSerialFinish(); + } - ~TracyInstrumentation() - { - for(auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) + protected: + ~TracyInstrumentation() { - TracyVkDestroy(itr->second); + for (auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) + { + TracyVkDestroy(itr->second); + } } - } -}; + }; -} +} // namespace vsg diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index a0373c8771..3f0688a0b3 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -24,6 +24,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include @@ -34,7 +35,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include #include #include @@ -361,7 +361,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); + GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); //debug("Visiting StateGroup"); @@ -455,7 +455,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -544,7 +544,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - GPU_INSTRUMENTATION_L2_C( instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); if (recordedCommandBuffers) { diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index f0feb0c2ac..0a9339c017 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -840,13 +840,13 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) instrumentation = in_instrumentation; // assign instrumentation after settings up recordAndSubmitTasks, but before compile() to allow compile to initialize the Instrumentation with the approach queue etc. - for(auto& task : recordAndSubmitTasks) + for (auto& task : recordAndSubmitTasks) { task->instrumentation = instrumentation; if (task->earlyTransferTask) task->earlyTransferTask->instrumentation = task->instrumentation; if (task->lateTransferTask) task->lateTransferTask->instrumentation = task->instrumentation; - for(auto cg : task->commandGraphs) + for (auto cg : task->commandGraphs) { cg->instrumentation = task->instrumentation; cg->getOrCreateRecordTraversal()->instrumentation = task->instrumentation; diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index d527c3cd85..5faceca794 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -11,9 +11,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ #include +#include #include #include -#include using namespace vsg; From b85e1600d0327249a34667f37708346d76d600f7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 09:27:54 +0000 Subject: [PATCH 30/68] Removed debug message --- src/vsg/app/CommandGraph.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 43e0776011..c35f02027b 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -73,8 +73,6 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() { recordTraversal->instrumentation = GpuAnnotation::create(); } - - info("CommandGraph::getOrCreateRecordTraversal() ", recordTraversal); } return recordTraversal; } From 309dd9eaeea4535fabdeb8825b3fb07da1392634 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 10:06:14 +0000 Subject: [PATCH 31/68] Implemented support for compiling with/out TRACY_ON_DEMAND enabled --- include/vsg/utils/TracyInstrumentation.h | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index ca31fa17d7..3c479a9cf7 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -67,13 +67,21 @@ namespace vsg void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override { +#ifdef TRACY_ON_DEMAND if (!GetProfiler().IsConnected() || (slcloc->level > cpu_instumentation_level)) +#else + if (slcloc->level > cpu_instumentation_level) +#endif { reference = 0; return; } +#ifdef TRACY_ON_DEMAND reference = GetProfiler().ConnectionId(); +#else + reference = 1; +#endif TracyQueuePrepare(QueueType::ZoneBegin); MemWrite(&item->zoneBegin.time, Profiler::GetTime()); @@ -83,7 +91,11 @@ namespace vsg void leave(const vsg::SourceLocation*, uint64_t& reference) const override { +#ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; +#else + if (reference == 0) return; +#endif TracyQueuePrepare(QueueType::ZoneEnd); MemWrite(&item->zoneEnd.time, Profiler::GetTime()); @@ -92,13 +104,22 @@ namespace vsg void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override { +#ifdef TRACY_ON_DEMAND if (!GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) +#else + if (slcloc->level > gpu_instumentation_level) +#endif { reference = 0; return; } +#ifdef TRACY_ON_DEMAND reference = GetProfiler().ConnectionId(); +#else + reference = 1; +#endif + const auto queryId = ctx->NextQueryId(); CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); @@ -115,7 +136,11 @@ namespace vsg void leave(const vsg::SourceLocation* /*slcloc*/, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override { +#ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; +#else + if (reference == 0) return; +#endif const auto queryId = ctx->NextQueryId(); CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); From e9790c849ec82791b79857479ca28db71216f913 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 12:09:05 +0000 Subject: [PATCH 32/68] Added CommandBuffer instrumentation --- include/vsg/utils/GpuAnnotation.h | 10 +--- include/vsg/utils/Instrumentation.h | 56 +++++++++++++++++------ include/vsg/utils/TracyInstrumentation.h | 58 +++++++++++++----------- src/vsg/app/CommandGraph.cpp | 9 ++-- src/vsg/app/TransferTask.cpp | 9 ++-- src/vsg/app/Viewer.cpp | 9 ++-- src/vsg/utils/GpuAnnotation.cpp | 10 ++++ 7 files changed, 102 insertions(+), 59 deletions(-) diff --git a/include/vsg/utils/GpuAnnotation.h b/include/vsg/utils/GpuAnnotation.h index 8856079e1f..f09b170ef0 100644 --- a/include/vsg/utils/GpuAnnotation.h +++ b/include/vsg/utils/GpuAnnotation.h @@ -24,14 +24,8 @@ namespace vsg public: GpuAnnotation(); - void enterFrame(FrameStamp&) override{}; - void leaveFrame(FrameStamp&) override{}; - - void enterCommandBuffer(CommandBuffer&) override {} - void leaveCommandBuffer() override {} - - void enter(const SourceLocation*, uint64_t&) const override {} - void leave(const SourceLocation*, uint64_t&) const override {} + void enterCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; + void leaveCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index f8fa2f6473..86a917b6ea 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -41,17 +41,17 @@ namespace vsg public: Instrumentation(); - virtual void enterFrame(FrameStamp& frameStamp) = 0; - virtual void leaveFrame(FrameStamp& frameStamp) = 0; + virtual void enterFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; + virtual void leaveFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; - virtual void enterCommandBuffer(CommandBuffer& commandBuffer) = 0; - virtual void leaveCommandBuffer() = 0; + virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/) const {}; + virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/) const {}; - virtual void enter(const SourceLocation* sl, uint64_t& reference) const = 0; - virtual void leave(const SourceLocation* sl, uint64_t& reference) const = 0; + virtual void enterCommandBuffer(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; + virtual void leaveCommandBuffer(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; - virtual void enter(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const = 0; - virtual void leave(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const = 0; + virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; + virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; protected: virtual ~Instrumentation(); @@ -92,21 +92,44 @@ namespace vsg } }; -#if defined(__clang__) || defined(__GNUC__) + struct CommandBufferInstrumentation + { + const Instrumentation* instr; + const SourceLocation* sl; + uint64_t reference; + CommandBuffer& commandBuffer; + + inline CommandBufferInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer) : + instr(in_instr), sl(in_sl), commandBuffer(in_commandBuffer) + { + if (instr) instr->enterCommandBuffer(sl, reference, commandBuffer); + } + inline ~CommandBufferInstrumentation() + { + if (instr) instr->leaveCommandBuffer(sl, reference, commandBuffer); + } + }; + + #if defined(__clang__) || defined(__GNUC__) # define VsgFunctionName __PRETTY_FUNCTION__ #elif defined(_MSC_VER) # define VsgFunctionName __FUNCSIG__ #endif #define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_source_location_##__LINE__)); + static constexpr SourceLocation s_cpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ + CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_cpu_source_location_##__LINE__)); #define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ - static constexpr SourceLocation s_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_source_location_##__LINE__), cg); + static constexpr SourceLocation s_gpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ + GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_gpu_source_location_##__LINE__), cg); + +#define __COMMAND_BUFFER_INSTRUMENTATION(level, instrumentation, cg, name, color) \ + static constexpr SourceLocation s_cg_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ + CommandBufferInstrumentation __cb_scoped_instrumentation_##__LINE__(instrumentation, &(s_cg_source_location_##__LINE__), cg); #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 + # define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) # define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, ubvec4(255, 255, 255, 255)) # define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) @@ -116,7 +139,11 @@ namespace vsg # define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) # define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) + +# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg) __COMMAND_BUFFER_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) + #else + # define CPU_INSTRUMENTATION_L1(instrumentation) # define CPU_INSTRUMENTATION_L1_N(instrumentation, name) # define CPU_INSTRUMENTATION_L1_C(instrumentation, color) @@ -126,6 +153,9 @@ namespace vsg # define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) # define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) + +# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg) + #endif #if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 3c479a9cf7..c1adbc4c92 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -22,6 +22,7 @@ using namespace tracy; namespace vsg { + /// TracyInstrumentation provided integration between the vsg::Instrumentation system and the Tracy profiler class TracyInstrumentation : public vsg::Inherit { public: @@ -35,36 +36,13 @@ namespace vsg uint32_t cpu_instumentation_level = 3; uint32_t gpu_instumentation_level = 3; - void enterFrame(vsg::FrameStamp&) override {} + void enterFrame(const vsg::SourceLocation*, uint64_t&, vsg::FrameStamp&) const override {} - void leaveFrame(vsg::FrameStamp&) override + void leaveFrame(const vsg::SourceLocation*, uint64_t&, vsg::FrameStamp&) const override { FrameMark; } - void enterCommandBuffer(vsg::CommandBuffer& commandBuffer) override - { - auto device = commandBuffer.getDevice(); - ctx = ctxMap[device]; - if (!ctx) - { - auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); - auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); - auto temporaryCommandBuffer = commandPool->allocate(); - ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); - } - - if (ctx) - { - TracyVkCollect(ctx, commandBuffer.vk()); - } - } - - void leaveCommandBuffer() override - { - ctx = nullptr; - } - void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override { #ifdef TRACY_ON_DEMAND @@ -102,6 +80,33 @@ namespace vsg TracyQueueCommit(zoneEndThread); } + void enterCommandBuffer(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& commandBuffer) const override + { + auto device = commandBuffer.getDevice(); + ctx = ctxMap[device]; + if (!ctx) + { + auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); + auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto temporaryCommandBuffer = commandPool->allocate(); + ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + } + + if (ctx) + { + TracyVkCollect(ctx, commandBuffer.vk()); + + enter(slcloc, reference, commandBuffer); + } + } + + void leaveCommandBuffer(const vsg::SourceLocation* slcloc, uint64_t& reference, CommandBuffer& commandBuffer) const override + { + leave(slcloc, reference, commandBuffer); + + ctx = nullptr; + } + void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override { #ifdef TRACY_ON_DEMAND @@ -120,7 +125,6 @@ namespace vsg reference = 1; #endif - const auto queryId = ctx->NextQueryId(); CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); @@ -134,7 +138,7 @@ namespace vsg Profiler::QueueSerialFinish(); } - void leave(const vsg::SourceLocation* /*slcloc*/, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + void leave(const vsg::SourceLocation*, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override { #ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index c35f02027b..112ccd1fb3 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -135,11 +135,10 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); - if (instrumentation) instrumentation->enterCommandBuffer(*commandBuffer); - - traverse(*recordTraversal); - - if (instrumentation) instrumentation->leaveCommandBuffer(); + { + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) + traverse(*recordTraversal); + } vkEndCommandBuffer(vk_commandBuffer); diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index 04c2c72ca3..aea6c22c72 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -396,10 +396,13 @@ VkResult TransferTask::transferDynamicData() vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); VkDeviceSize offset = 0; + { + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) - // transfer the modified BufferInfo and ImageInfo - _transferBufferInfos(vk_commandBuffer, frame, offset); - _transferImageInfos(vk_commandBuffer, frame, offset); + // transfer the modified BufferInfo and ImageInfo + _transferBufferInfos(vk_commandBuffer, frame, offset); + _transferImageInfos(vk_commandBuffer, frame, offset); + } vkEndCommandBuffer(vk_commandBuffer); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 0a9339c017..d7f95a9e9b 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -151,11 +151,13 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - CPU_INSTRUMENTATION_L1(instrumentation); + static constexpr SourceLocation s_frame_source_location{"frame", VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; + uint64_t reference = 0; if (!active()) return false; - if (instrumentation && _frameStamp) instrumentation->leaveFrame(*_frameStamp); + // signal to instrumentation the end of the previous frame + if (instrumentation && _frameStamp) instrumentation->leaveFrame(&s_frame_source_location, reference, *_frameStamp); // poll all the windows for events. pollEvents(true); @@ -180,7 +182,8 @@ bool Viewer::advanceToNextFrame() task->advance(); } - if (instrumentation) instrumentation->enterFrame(*_frameStamp); + // signal to instrumentation the start of frame + if (instrumentation) instrumentation->enterFrame(&s_frame_source_location, reference, *_frameStamp); // create an event for the new frame. _events.emplace_back(new FrameEvent(_frameStamp)); diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index 5de5f95aea..1cc0f9e0e8 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -24,6 +24,16 @@ GpuAnnotation::~GpuAnnotation() { } +void GpuAnnotation::enterCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const +{ + enter(sl, reference, commandBuffer); +} + +void GpuAnnotation::leaveCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const +{ + leave(sl, reference, commandBuffer); +} + void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const { if (!commandBuffer) return; From 2605b938a5c48d19b1ca4a9702b7d201c43fb843 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 14:12:51 +0000 Subject: [PATCH 33/68] Added instrumentation to CompileManager/CompileTraversal/Context --- include/vsg/app/CompileManager.h | 3 ++ include/vsg/app/CompileTraversal.h | 7 +++++ include/vsg/utils/TracyInstrumentation.h | 9 ++++-- include/vsg/vk/Context.h | 5 +++- src/vsg/app/CompileManager.cpp | 11 ++++++++ src/vsg/app/CompileTraversal.cpp | 35 ++++++++++++++++++++++++ src/vsg/app/Viewer.cpp | 2 ++ src/vsg/vk/Context.cpp | 26 ++++++++++-------- 8 files changed, 82 insertions(+), 16 deletions(-) diff --git a/include/vsg/app/CompileManager.h b/include/vsg/app/CompileManager.h index 13b3850030..1d6a092710 100644 --- a/include/vsg/app/CompileManager.h +++ b/include/vsg/app/CompileManager.h @@ -58,6 +58,9 @@ namespace vsg /// add a compile Context for all the Views assigned to a Viewer void add(const Viewer& viewer, const ResourceRequirements& resourceRequirements = {}); + /// assign Instrumentation to all CompileTraversal and their associated Context + void assignInstrumentation(ref_ptr in_instrumentation); + using ContextSelectionFunction = std::function; /// compile object diff --git a/include/vsg/app/CompileTraversal.h b/include/vsg/app/CompileTraversal.h index f8aa26ee67..bb1a72f344 100644 --- a/include/vsg/app/CompileTraversal.h +++ b/include/vsg/app/CompileTraversal.h @@ -24,6 +24,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include namespace vsg { @@ -45,6 +46,9 @@ namespace vsg /// list of Context that Vulkan objects should be compiled for. std::list> contexts; + /// Hook for assigning Instrumentation to enable profiling + ref_ptr instrumentation; + /// add a compile Context for device void add(ref_ptr device, const ResourceRequirements& resourceRequirements = {}); @@ -60,6 +64,9 @@ namespace vsg /// add a compile Context for all the Views assigned to a Viewer void add(const Viewer& viewer, const ResourceRequirements& resourceRequirements = {}); + /// assign Instrumentation to all Context + void assignInstrumentation(ref_ptr in_instrumentation); + virtual bool record(); virtual void waitForCompletion(); diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index c1adbc4c92..81b7b090c7 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -102,7 +102,10 @@ namespace vsg void leaveCommandBuffer(const vsg::SourceLocation* slcloc, uint64_t& reference, CommandBuffer& commandBuffer) const override { - leave(slcloc, reference, commandBuffer); + if (ctx) + { + leave(slcloc, reference, commandBuffer); + } ctx = nullptr; } @@ -110,9 +113,9 @@ namespace vsg void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override { #ifdef TRACY_ON_DEMAND - if (!GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) + if (!ctx || !GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) #else - if (slcloc->level > gpu_instumentation_level) + if (!ctx || slcloc->level > gpu_instumentation_level) #endif { reference = 0; diff --git a/include/vsg/vk/Context.h b/include/vsg/vk/Context.h index 0e3e15118b..088bba99dc 100644 --- a/include/vsg/vk/Context.h +++ b/include/vsg/vk/Context.h @@ -26,7 +26,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include - +#include #include #include #include @@ -119,6 +119,9 @@ namespace vsg // ShaderCompiler ref_ptr shaderCompiler; + /// Hook for assigning Instrumentation to enable profiling + ref_ptr instrumentation; + // transfer data settings ref_ptr graphicsQueue; ref_ptr commandPool; diff --git a/src/vsg/app/CompileManager.cpp b/src/vsg/app/CompileManager.cpp index f52cfd70c3..038a9c0a05 100644 --- a/src/vsg/app/CompileManager.cpp +++ b/src/vsg/app/CompileManager.cpp @@ -150,6 +150,17 @@ void CompileManager::add(const Viewer& viewer, const ResourceRequirements& resou } } +void CompileManager::assignInstrumentation(ref_ptr in_instrumentation) +{ + auto cts = takeCompileTraversals(numCompileTraversals); + for (auto& ct : cts) + { + ct->assignInstrumentation(in_instrumentation); + + compileTraversals->add(ct); + } +} + CompileResult CompileManager::compile(ref_ptr object, ContextSelectionFunction contextSelection) { CollectResourceRequirements collectRequirements; diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index f0fb9f1ce2..ec8a6effc0 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -63,6 +63,7 @@ void CompileTraversal::add(ref_ptr device, const ResourceRequirements& r { auto queueFamily = device->getPhysicalDevice()->getQueueFamily(queueFlags); auto context = Context::create(device, resourceRequirements); + context->instrumentation = instrumentation; context->commandPool = CommandPool::create(device, queueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); context->graphicsQueue = device->getQueue(queueFamily, queueFamilyIndex); contexts.push_back(context); @@ -74,6 +75,7 @@ void CompileTraversal::add(Window& window, ref_ptr viewport, cons auto renderPass = window.getOrCreateRenderPass(); auto queueFamily = device->getPhysicalDevice()->getQueueFamily(queueFlags); auto context = Context::create(device, resourceRequirements); + context->instrumentation = instrumentation; context->renderPass = renderPass; context->commandPool = CommandPool::create(device, queueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); context->graphicsQueue = device->getQueue(queueFamily, queueFamilyIndex); @@ -94,6 +96,7 @@ void CompileTraversal::add(Window& window, ref_ptr view, const ResourceReq auto renderPass = window.getOrCreateRenderPass(); auto queueFamily = device->getPhysicalDevice()->getQueueFamily(queueFlags); auto context = Context::create(device, resourceRequirements); + context->instrumentation = instrumentation; context->renderPass = renderPass; context->commandPool = vsg::CommandPool::create(device, queueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); context->graphicsQueue = device->getQueue(queueFamily, queueFamilyIndex); @@ -122,6 +125,7 @@ void CompileTraversal::add(Framebuffer& framebuffer, ref_ptr view, const R auto renderPass = framebuffer.getRenderPass(); auto queueFamily = device->getPhysicalDevice()->getQueueFamily(VK_QUEUE_GRAPHICS_BIT); auto context = Context::create(device, resourceRequirements); + context->instrumentation = instrumentation; context->renderPass = renderPass; context->commandPool = vsg::CommandPool::create(device, queueFamily, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); context->graphicsQueue = device->getQueue(queueFamily, queueFamilyIndex); @@ -146,6 +150,8 @@ void CompileTraversal::add(Framebuffer& framebuffer, ref_ptr view, const R void CompileTraversal::add(const Viewer& viewer, const ResourceRequirements& resourceRequirements) { + if (viewer.instrumentation) instrumentation = viewer.instrumentation; + struct AddViews : public Visitor { CompileTraversal* ct = nullptr; @@ -208,13 +214,26 @@ void CompileTraversal::addViewDependentState(ViewDependentState& viewDependentSt } } +void CompileTraversal::assignInstrumentation(ref_ptr in_instrumentation) +{ + instrumentation = in_instrumentation; + for(auto& context : contexts) + { + context->instrumentation = instrumentation; + } +} + void CompileTraversal::apply(Object& object) { + CPU_INSTRUMENTATION_L2(instrumentation); + object.traverse(*this); } void CompileTraversal::apply(Compilable& node) { + CPU_INSTRUMENTATION_L3(instrumentation); + for (auto& context : contexts) { node.compile(*context); @@ -223,6 +242,8 @@ void CompileTraversal::apply(Compilable& node) void CompileTraversal::apply(Commands& commands) { + CPU_INSTRUMENTATION_L3(instrumentation); + for (auto& context : contexts) { commands.compile(*context); @@ -231,6 +252,8 @@ void CompileTraversal::apply(Commands& commands) void CompileTraversal::apply(StateGroup& stateGroup) { + CPU_INSTRUMENTATION_L2(instrumentation); + for (auto& context : contexts) { stateGroup.compile(*context); @@ -240,6 +263,8 @@ void CompileTraversal::apply(StateGroup& stateGroup) void CompileTraversal::apply(Geometry& geometry) { + CPU_INSTRUMENTATION_L3(instrumentation); + for (auto& context : contexts) { geometry.compile(*context); @@ -249,6 +274,8 @@ void CompileTraversal::apply(Geometry& geometry) void CompileTraversal::apply(CommandGraph& commandGraph) { + CPU_INSTRUMENTATION_L1(instrumentation); + for (auto& context : contexts) { if (context->resourceRequirements.maxSlot > commandGraph.maxSlot) @@ -262,6 +289,8 @@ void CompileTraversal::apply(CommandGraph& commandGraph) void CompileTraversal::apply(RenderGraph& renderGraph) { + CPU_INSTRUMENTATION_L1(instrumentation); + for (auto& context : contexts) { context->renderPass = renderGraph.getRenderPass(); @@ -294,6 +323,8 @@ void CompileTraversal::apply(RenderGraph& renderGraph) void CompileTraversal::apply(View& view) { + CPU_INSTRUMENTATION_L1(instrumentation); + for (auto& context : contexts) { // if context is associated with a view make sure we only apply it if it matches with view, otherwise we skip this context @@ -333,6 +364,8 @@ void CompileTraversal::apply(View& view) bool CompileTraversal::record() { + CPU_INSTRUMENTATION_L1(instrumentation); + bool recorded = false; for (auto& context : contexts) { @@ -343,6 +376,8 @@ bool CompileTraversal::record() void CompileTraversal::waitForCompletion() { + CPU_INSTRUMENTATION_L1(instrumentation); + for (auto& context : contexts) { context->waitForCompletion(); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index d7f95a9e9b..6df6dedeee 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -856,6 +856,8 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) } } + if (compileManager) compileManager->assignInstrumentation(instrumentation); + if (previous_threading) setupThreading(); } diff --git a/src/vsg/vk/Context.cpp b/src/vsg/vk/Context.cpp index 2de0b6cd9f..99f143160d 100644 --- a/src/vsg/vk/Context.cpp +++ b/src/vsg/vk/Context.cpp @@ -316,22 +316,24 @@ bool Context::record() vkBeginCommandBuffer(*commandBuffer, &beginInfo); - // issue commands of interest { - for (auto& command : commands) command->record(*commandBuffer); - } + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) - // create scratch buffer and issue build acceleration structure commands - ref_ptr scratchBuffer; - ref_ptr scratchBufferMemory; - if (scratchBufferSize > 0) - { - scratchBuffer = vsg::createBufferAndMemory(device, scratchBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, VK_SHARING_MODE_EXCLUSIVE, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + // issue commands of interest + { + for (auto& command : commands) command->record(*commandBuffer); + } - for (auto& command : buildAccelerationStructureCommands) + // create scratch buffer and issue build acceleration structure commands + if (scratchBufferSize > 0) { - command->setScratchBuffer(scratchBuffer); - command->record(*commandBuffer); + ref_ptr scratchBuffer = vsg::createBufferAndMemory(device, scratchBufferSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, VK_SHARING_MODE_EXCLUSIVE, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + + for (auto& command : buildAccelerationStructureCommands) + { + command->setScratchBuffer(scratchBuffer); + command->record(*commandBuffer); + } } } From 6e74b09b7dab8a009eb7bd026cfa5b067bfca3b8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 18 Dec 2023 15:16:37 +0000 Subject: [PATCH 34/68] Added vsg::Instrumentation support to DatabasePager --- include/vsg/app/RecordAndSubmitTask.h | 3 +++ include/vsg/io/DatabasePager.h | 12 +++++++----- src/vsg/app/RecordAndSubmitTask.cpp | 15 +++++++++++++++ src/vsg/app/Viewer.cpp | 22 ++++++++++++---------- src/vsg/io/DatabasePager.cpp | 10 ++++++++++ 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/include/vsg/app/RecordAndSubmitTask.h b/include/vsg/app/RecordAndSubmitTask.h index 4983e193e5..aed0570534 100644 --- a/include/vsg/app/RecordAndSubmitTask.h +++ b/include/vsg/app/RecordAndSubmitTask.h @@ -63,6 +63,9 @@ namespace vsg /// hook for assigning Instrumentation to enable profiling of record traversal. ref_ptr instrumentation; + /// Convenience method for assigning Instrumentation to the viewer and any associated objects. + void assignInstrumentation(ref_ptr in_instrumentation); + protected: size_t _currentFrameIndex; std::vector _indices; diff --git a/include/vsg/io/DatabasePager.h b/include/vsg/io/DatabasePager.h index fb669843f5..ab728107b2 100644 --- a/include/vsg/io/DatabasePager.h +++ b/include/vsg/io/DatabasePager.h @@ -16,12 +16,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include - #include - #include - #include +#include #include #include @@ -96,8 +94,6 @@ namespace vsg virtual void updateSceneGraph(FrameStamp* frameStamp, CompileResult& cr); - ref_ptr options; - ref_ptr compileManager; std::atomic_uint numActiveRequests{0}; @@ -112,6 +108,12 @@ namespace vsg ref_ptr pagedLODContainer; + /// Hook for assigning Instrumentation to enable profiling + ref_ptr instrumentation; + + /// assign Instrumentation to all CompileTraversal and their associated Context + void assignInstrumentation(ref_ptr in_instrumentation); + protected: virtual ~DatabasePager(); diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index ccca30d142..50923becc6 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -221,6 +221,21 @@ VkResult RecordAndSubmitTask::finish(ref_ptr recordedCom return queue->submit(submitInfo, current_fence); } +void RecordAndSubmitTask::assignInstrumentation(ref_ptr in_instrumentation) +{ + instrumentation = in_instrumentation; + + if (databasePager) databasePager->assignInstrumentation(instrumentation); + if (earlyTransferTask) earlyTransferTask->instrumentation = instrumentation; + if (lateTransferTask) lateTransferTask->instrumentation = instrumentation; + + for (auto cg : commandGraphs) + { + cg->instrumentation = instrumentation; + cg->getOrCreateRecordTraversal()->instrumentation = instrumentation; + } +} + void vsg::updateTasks(RecordAndSubmitTasks& tasks, ref_ptr compileManager, const CompileResult& compileResult) { //info("vsg::updateTasks(RecordAndSubmitTasks& tasks..) compileResult.maxSlot = ", compileResult.maxSlot); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 6df6dedeee..13bf9c4d9c 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -345,7 +345,11 @@ void Viewer::compile(ref_ptr hints) } } - if (containsPagedLOD && !databasePager) databasePager = DatabasePager::create(); + if (containsPagedLOD && !databasePager) + { + databasePager = DatabasePager::create(); + if (instrumentation) databasePager->assignInstrumentation(instrumentation); + } // create the Vulkan objects for (auto& task : recordAndSubmitTasks) @@ -553,6 +557,9 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr recordAndSubmitTask->earlyTransferTask->transferQueue = transferQueue; recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue; + // assign instrumentation + recordAndSubmitTask->assignInstrumentation(instrumentation); + auto presentation = vsg::Presentation::create(); presentation->waitSemaphores.emplace_back(renderFinishedSemaphore); presentation->windows = windows; @@ -571,6 +578,9 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr recordAndSubmitTask->earlyTransferTask->transferQueue = transferQueue; recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue; + + // assign instrumentation + recordAndSubmitTask->assignInstrumentation(instrumentation); } } @@ -845,15 +855,7 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) // assign instrumentation after settings up recordAndSubmitTasks, but before compile() to allow compile to initialize the Instrumentation with the approach queue etc. for (auto& task : recordAndSubmitTasks) { - task->instrumentation = instrumentation; - if (task->earlyTransferTask) task->earlyTransferTask->instrumentation = task->instrumentation; - if (task->lateTransferTask) task->lateTransferTask->instrumentation = task->instrumentation; - - for (auto cg : task->commandGraphs) - { - cg->instrumentation = task->instrumentation; - cg->getOrCreateRecordTraversal()->instrumentation = task->instrumentation; - } + task->assignInstrumentation(instrumentation); } if (compileManager) compileManager->assignInstrumentation(instrumentation); diff --git a/src/vsg/io/DatabasePager.cpp b/src/vsg/io/DatabasePager.cpp index d9f991f54a..b0f3594774 100644 --- a/src/vsg/io/DatabasePager.cpp +++ b/src/vsg/io/DatabasePager.cpp @@ -126,6 +126,12 @@ DatabasePager::~DatabasePager() } } + +void DatabasePager::assignInstrumentation(ref_ptr in_instrumentation) +{ + instrumentation = in_instrumentation; +} + void DatabasePager::start() { int numReadThreads = 4; @@ -141,6 +147,8 @@ void DatabasePager::start() auto plod = requestQueue->take_when_available(); if (plod) { + CPU_INSTRUMENTATION_L1(databasePager.instrumentation); + uint64_t frameDelta = databasePager.frameCount - plod->frameHighResLastUsed.load(); if (frameDelta > 1 || !compare_exchange(plod->requestStatus, PagedLOD::ReadRequest, PagedLOD::Reading)) { @@ -233,6 +241,8 @@ void DatabasePager::requestDiscarded(PagedLOD* plod) void DatabasePager::updateSceneGraph(FrameStamp* frameStamp, CompileResult& cr) { + CPU_INSTRUMENTATION_L1(instrumentation); + frameCount.exchange(frameStamp ? frameStamp->frameCount : 0); auto nodes = _toMergeQueue->take_all(cr); From 29080312dfad9250a21cdc01f494c839482b63ba Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 19 Dec 2023 15:09:06 +0000 Subject: [PATCH 35/68] Added support for duplicating Instrumentation when required to enable multi-threaded instrumentation via multiple Instrumentation objects --- include/vsg/utils/Instrumentation.h | 5 + include/vsg/utils/TracyInstrumentation.h | 112 +++++++++++++++-------- src/vsg/app/CompileTraversal.cpp | 2 +- src/vsg/app/RecordAndSubmitTask.cpp | 8 +- src/vsg/io/DatabasePager.cpp | 2 + src/vsg/utils/Instrumentation.cpp | 6 ++ 6 files changed, 93 insertions(+), 42 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 86a917b6ea..5141505836 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -41,6 +41,8 @@ namespace vsg public: Instrumentation(); + virtual ref_ptr shareOrDuplicateForThreadSafety() { return ref_ptr(this); } + virtual void enterFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; virtual void leaveFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; @@ -58,6 +60,9 @@ namespace vsg }; VSG_type_name(vsg::Instrumentation); + /// convinience static method for sharing or duplicating Instrumentation if a valid Instrumentation object is provided + extern ref_ptr shareOrDuplicateForThreadSafety(ref_ptr instrumentation); + struct CpuInstrumentation { const Instrumentation* instr; diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 81b7b090c7..07c0e30718 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -22,33 +22,89 @@ using namespace tracy; namespace vsg { - /// TracyInstrumentation provided integration between the vsg::Instrumentation system and the Tracy profiler - class TracyInstrumentation : public vsg::Inherit + /// thread safe helper class for creating the Tracy VkCtx objects per Device. + class TracyContexts : public Inherit { public: - TracyInstrumentation() + + VkCtx* getOrCreateContext(CommandBuffer& commandBuffer) const { + std::scoped_lock lock(mutex); + + auto device = commandBuffer.getDevice(); + auto& ctx = ctxMap[device]; + if (!ctx) + { + auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); + auto commandPool = CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); + auto temporaryCommandBuffer = commandPool->allocate(); + ctx = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + } + return ctx; } - mutable std::map ctxMap; - mutable VkCtx* ctx = nullptr; + protected: + ~TracyContexts() + { + for (auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) + { + TracyVkDestroy(itr->second); + } + } + mutable std::mutex mutex; + mutable std::map ctxMap; + }; + VSG_type_name(vsg::TracyContexts); + + class TracySettings : public Inherit + { + public: uint32_t cpu_instumentation_level = 3; uint32_t gpu_instumentation_level = 3; + }; + VSG_type_name(vsg::TracySettings); + + /// TracyInstrumentation provides integration between the Instrumentation system and the Tracy profiler + class TracyInstrumentation : public Inherit + { + public: + TracyInstrumentation() : + settings(TracySettings::create()), + contexts(TracyContexts::create()) + { + vsg::info("creating TracyInstrumentation", this, ", ", settings, ", ", contexts); + } - void enterFrame(const vsg::SourceLocation*, uint64_t&, vsg::FrameStamp&) const override {} + TracyInstrumentation(TracyInstrumentation& parent): + settings(parent.settings), + contexts(parent.contexts) + { + vsg::info("duplicating TracyInstrumentation", this, ", ", settings, ", ", contexts); + } - void leaveFrame(const vsg::SourceLocation*, uint64_t&, vsg::FrameStamp&) const override + ref_ptr settings; + ref_ptr contexts; + mutable VkCtx* ctx = nullptr; + + ref_ptr shareOrDuplicateForThreadSafety() override + { + return TracyInstrumentation::create(*this); + } + + void enterFrame(const SourceLocation*, uint64_t&, FrameStamp&) const override {} + + void leaveFrame(const SourceLocation*, uint64_t&, FrameStamp&) const override { FrameMark; } - void enter(const vsg::SourceLocation* slcloc, uint64_t& reference) const override + void enter(const SourceLocation* slcloc, uint64_t& reference) const override { #ifdef TRACY_ON_DEMAND - if (!GetProfiler().IsConnected() || (slcloc->level > cpu_instumentation_level)) + if (!GetProfiler().IsConnected() || (slcloc->level > settings->cpu_instumentation_level)) #else - if (slcloc->level > cpu_instumentation_level) + if (slcloc->level > settings->cpu_instumentation_level) #endif { reference = 0; @@ -67,7 +123,7 @@ namespace vsg TracyQueueCommit(zoneBeginThread); } - void leave(const vsg::SourceLocation*, uint64_t& reference) const override + void leave(const SourceLocation*, uint64_t& reference) const override { #ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; @@ -80,19 +136,9 @@ namespace vsg TracyQueueCommit(zoneEndThread); } - void enterCommandBuffer(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& commandBuffer) const override + void enterCommandBuffer(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& commandBuffer) const override { - auto device = commandBuffer.getDevice(); - ctx = ctxMap[device]; - if (!ctx) - { - auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); - auto commandPool = vsg::CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); - auto temporaryCommandBuffer = commandPool->allocate(); - ctx = ctxMap[device] = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); - } - - if (ctx) + if (ctx = contexts->getOrCreateContext(commandBuffer)) { TracyVkCollect(ctx, commandBuffer.vk()); @@ -100,7 +146,7 @@ namespace vsg } } - void leaveCommandBuffer(const vsg::SourceLocation* slcloc, uint64_t& reference, CommandBuffer& commandBuffer) const override + void leaveCommandBuffer(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& commandBuffer) const override { if (ctx) { @@ -110,12 +156,12 @@ namespace vsg ctx = nullptr; } - void enter(const vsg::SourceLocation* slcloc, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + void enter(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& cmdbuf) const override { #ifdef TRACY_ON_DEMAND - if (!ctx || !GetProfiler().IsConnected() || (slcloc->level > gpu_instumentation_level)) + if (!ctx || !GetProfiler().IsConnected() || (slcloc->level > settings->gpu_instumentation_level)) #else - if (!ctx || slcloc->level > gpu_instumentation_level) + if (!ctx || slcloc->level > settings->gpu_instumentation_level) #endif { reference = 0; @@ -141,7 +187,7 @@ namespace vsg Profiler::QueueSerialFinish(); } - void leave(const vsg::SourceLocation*, uint64_t& reference, vsg::CommandBuffer& cmdbuf) const override + void leave(const SourceLocation*, uint64_t& reference, CommandBuffer& cmdbuf) const override { #ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; @@ -160,15 +206,7 @@ namespace vsg MemWrite(&item->gpuZoneEnd.context, ctx->GetId()); Profiler::QueueSerialFinish(); } - - protected: - ~TracyInstrumentation() - { - for (auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) - { - TracyVkDestroy(itr->second); - } - } }; + VSG_type_name(vsg::TracyInstrumentation); } // namespace vsg diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index ec8a6effc0..99648e5bee 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -219,7 +219,7 @@ void CompileTraversal::assignInstrumentation(ref_ptr in_instrum instrumentation = in_instrumentation; for(auto& context : contexts) { - context->instrumentation = instrumentation; + context->instrumentation = shareOrDuplicateForThreadSafety(instrumentation); } } diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 50923becc6..9645336499 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -226,13 +226,13 @@ void RecordAndSubmitTask::assignInstrumentation(ref_ptr in_inst instrumentation = in_instrumentation; if (databasePager) databasePager->assignInstrumentation(instrumentation); - if (earlyTransferTask) earlyTransferTask->instrumentation = instrumentation; - if (lateTransferTask) lateTransferTask->instrumentation = instrumentation; + if (earlyTransferTask) earlyTransferTask->instrumentation = shareOrDuplicateForThreadSafety(instrumentation); + if (lateTransferTask) lateTransferTask->instrumentation = shareOrDuplicateForThreadSafety(instrumentation); for (auto cg : commandGraphs) { - cg->instrumentation = instrumentation; - cg->getOrCreateRecordTraversal()->instrumentation = instrumentation; + cg->instrumentation = shareOrDuplicateForThreadSafety(instrumentation); + cg->getOrCreateRecordTraversal()->instrumentation = cg->instrumentation; } } diff --git a/src/vsg/io/DatabasePager.cpp b/src/vsg/io/DatabasePager.cpp index b0f3594774..efd0d27442 100644 --- a/src/vsg/io/DatabasePager.cpp +++ b/src/vsg/io/DatabasePager.cpp @@ -142,6 +142,8 @@ void DatabasePager::start() auto read = [](ref_ptr requestQueue, ref_ptr status, DatabasePager& databasePager) { debug("Started DatabaseThread read thread"); + auto local_instrumentation = shareOrDuplicateForThreadSafety(databasePager.instrumentation); + while (status->active()) { auto plod = requestQueue->take_when_available(); diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 5faceca794..8aca45a694 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -28,3 +28,9 @@ Instrumentation::Instrumentation() Instrumentation::~Instrumentation() { } + +ref_ptr vsg::shareOrDuplicateForThreadSafety(ref_ptr instrumentation) +{ + return instrumentation ? instrumentation->shareOrDuplicateForThreadSafety() : instrumentation; +} + From 2be17d64e93652e4dcf0c2aa324dddb919c7bb76 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 08:45:03 +0000 Subject: [PATCH 36/68] Ran clang-format --- include/vsg/app/CompileTraversal.h | 2 +- include/vsg/io/DatabasePager.h | 2 +- include/vsg/utils/Instrumentation.h | 8 ++++---- include/vsg/utils/TracyInstrumentation.h | 3 +-- include/vsg/vk/Context.h | 8 ++++---- src/vsg/app/CompileTraversal.cpp | 2 +- src/vsg/io/DatabasePager.cpp | 1 - src/vsg/utils/Instrumentation.cpp | 1 - 8 files changed, 12 insertions(+), 15 deletions(-) diff --git a/include/vsg/app/CompileTraversal.h b/include/vsg/app/CompileTraversal.h index bb1a72f344..63876dd3d1 100644 --- a/include/vsg/app/CompileTraversal.h +++ b/include/vsg/app/CompileTraversal.h @@ -19,12 +19,12 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include #include #include -#include namespace vsg { diff --git a/include/vsg/io/DatabasePager.h b/include/vsg/io/DatabasePager.h index ab728107b2..36407dc983 100644 --- a/include/vsg/io/DatabasePager.h +++ b/include/vsg/io/DatabasePager.h @@ -12,13 +12,13 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ +#include #include #include #include #include #include #include -#include #include #include diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 5141505836..a2dcdfb704 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -115,21 +115,21 @@ namespace vsg } }; - #if defined(__clang__) || defined(__GNUC__) +#if defined(__clang__) || defined(__GNUC__) # define VsgFunctionName __PRETTY_FUNCTION__ #elif defined(_MSC_VER) # define VsgFunctionName __FUNCSIG__ #endif -#define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ +#define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ static constexpr SourceLocation s_cpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_cpu_source_location_##__LINE__)); -#define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ +#define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_gpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_gpu_source_location_##__LINE__), cg); -#define __COMMAND_BUFFER_INSTRUMENTATION(level, instrumentation, cg, name, color) \ +#define __COMMAND_BUFFER_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_cg_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ CommandBufferInstrumentation __cb_scoped_instrumentation_##__LINE__(instrumentation, &(s_cg_source_location_##__LINE__), cg); diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 07c0e30718..505557e16f 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -26,7 +26,6 @@ namespace vsg class TracyContexts : public Inherit { public: - VkCtx* getOrCreateContext(CommandBuffer& commandBuffer) const { std::scoped_lock lock(mutex); @@ -76,7 +75,7 @@ namespace vsg vsg::info("creating TracyInstrumentation", this, ", ", settings, ", ", contexts); } - TracyInstrumentation(TracyInstrumentation& parent): + TracyInstrumentation(TracyInstrumentation& parent) : settings(parent.settings), contexts(parent.contexts) { diff --git a/include/vsg/vk/Context.h b/include/vsg/vk/Context.h index 088bba99dc..51bf078176 100644 --- a/include/vsg/vk/Context.h +++ b/include/vsg/vk/Context.h @@ -15,21 +15,21 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include +#include +#include #include #include #include #include #include +#include #include #include #include #include #include #include -#include -#include -#include -#include namespace vsg { diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index 99648e5bee..bac74df94d 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -217,7 +217,7 @@ void CompileTraversal::addViewDependentState(ViewDependentState& viewDependentSt void CompileTraversal::assignInstrumentation(ref_ptr in_instrumentation) { instrumentation = in_instrumentation; - for(auto& context : contexts) + for (auto& context : contexts) { context->instrumentation = shareOrDuplicateForThreadSafety(instrumentation); } diff --git a/src/vsg/io/DatabasePager.cpp b/src/vsg/io/DatabasePager.cpp index efd0d27442..e9ce19eb4e 100644 --- a/src/vsg/io/DatabasePager.cpp +++ b/src/vsg/io/DatabasePager.cpp @@ -126,7 +126,6 @@ DatabasePager::~DatabasePager() } } - void DatabasePager::assignInstrumentation(ref_ptr in_instrumentation) { instrumentation = in_instrumentation; diff --git a/src/vsg/utils/Instrumentation.cpp b/src/vsg/utils/Instrumentation.cpp index 8aca45a694..143ecda4fd 100644 --- a/src/vsg/utils/Instrumentation.cpp +++ b/src/vsg/utils/Instrumentation.cpp @@ -33,4 +33,3 @@ ref_ptr vsg::shareOrDuplicateForThreadSafety(ref_ptrshareOrDuplicateForThreadSafety() : instrumentation; } - From 06b9aace66e07a6c4314a9ed69590ac4bd8fe3d6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 10:11:44 +0000 Subject: [PATCH 37/68] Fixed overrriding of locally assign Instrumentation when is not assigned --- src/vsg/app/Viewer.cpp | 4 ++-- src/vsg/utils/GpuAnnotation.cpp | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 13bf9c4d9c..0c40b36cc8 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -558,7 +558,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue; // assign instrumentation - recordAndSubmitTask->assignInstrumentation(instrumentation); + if (instrumentation) recordAndSubmitTask->assignInstrumentation(instrumentation); auto presentation = vsg::Presentation::create(); presentation->waitSemaphores.emplace_back(renderFinishedSemaphore); @@ -580,7 +580,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr recordAndSubmitTask->lateTransferTask->transferQueue = transferQueue; // assign instrumentation - recordAndSubmitTask->assignInstrumentation(instrumentation); + if (instrumentation) recordAndSubmitTask->assignInstrumentation(instrumentation); } } diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index 1cc0f9e0e8..b8b57b89ad 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -36,8 +36,6 @@ void GpuAnnotation::leaveCommandBuffer(const SourceLocation* sl, uint64_t& refer void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const { - if (!commandBuffer) return; - auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); VkDebugUtilsLabelEXT markerInfo = {}; @@ -56,8 +54,6 @@ void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffe void GpuAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer) const { - if (!commandBuffer) return; - auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); extensions->vkCmdEndDebugUtilsLabelEXT(commandBuffer); } From 76a8018d55c4e7d0040674baec36f4b7dfb2b10c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 10:37:48 +0000 Subject: [PATCH 38/68] Added instumentation to vsg::Options --- include/vsg/io/Options.h | 4 ++++ src/vsg/io/Options.cpp | 3 ++- src/vsg/io/read.cpp | 8 ++++++++ src/vsg/io/write.cpp | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/vsg/io/Options.h b/include/vsg/io/Options.h index 27e351d027..caa3982d29 100644 --- a/include/vsg/io/Options.h +++ b/include/vsg/io/Options.h @@ -17,6 +17,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include namespace vsg { @@ -96,6 +97,9 @@ namespace vsg /// scene graph creation routines can use the inherited state information to avoid setting state in the local subgraph. StateCommands inheritedState; + /// Hook for assigning Instrumentation to enable profiling of record traversal. + ref_ptr instrumentation; + protected: virtual ~Options(); }; diff --git a/src/vsg/io/Options.cpp b/src/vsg/io/Options.cpp index b121a77749..be74e6ee1a 100644 --- a/src/vsg/io/Options.cpp +++ b/src/vsg/io/Options.cpp @@ -45,7 +45,8 @@ Options::Options(const Options& options) : sceneCoordinateConvention(options.sceneCoordinateConvention), formatCoordinateConventions(options.formatCoordinateConventions), shaderSets(options.shaderSets), - inheritedState(options.inheritedState) + inheritedState(options.inheritedState), + instrumentation(options.instrumentation) { getOrCreateAuxiliary(); // copy any meta data. diff --git a/src/vsg/io/read.cpp b/src/vsg/io/read.cpp index d4424327c5..a9577f4749 100644 --- a/src/vsg/io/read.cpp +++ b/src/vsg/io/read.cpp @@ -23,6 +23,8 @@ using namespace vsg; ref_ptr vsg::read(const Path& filename, ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto read_file = [&]() -> ref_ptr { if (options && !options->readerWriters.empty()) { @@ -81,6 +83,8 @@ ref_ptr vsg::read(const Path& filename, ref_ptr options) PathObjects vsg::read(const Paths& filenames, ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + ref_ptr operationThreads; if (options) operationThreads = options->operationThreads; @@ -150,6 +154,8 @@ PathObjects vsg::read(const Paths& filenames, ref_ptr options) ref_ptr vsg::read(std::istream& fin, ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (options && !options->readerWriters.empty()) { for (auto& readerWriter : options->readerWriters) @@ -164,6 +170,8 @@ ref_ptr vsg::read(std::istream& fin, ref_ptr options) ref_ptr vsg::read(const uint8_t* ptr, size_t size, ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (options && !options->readerWriters.empty()) { for (auto& readerWriter : options->readerWriters) diff --git a/src/vsg/io/write.cpp b/src/vsg/io/write.cpp index 9e8bc552a2..72b77e28f2 100644 --- a/src/vsg/io/write.cpp +++ b/src/vsg/io/write.cpp @@ -20,6 +20,8 @@ using namespace vsg; bool vsg::write(ref_ptr object, const Path& filename, ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + bool fileWritten = false; if (options) { From b4b25addf6f4beff0937044d2700bbbec9f63c6b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 11:03:11 +0000 Subject: [PATCH 39/68] Added Instrumentation support to IO operations --- src/vsg/io/VSG.cpp | 10 ++++++++++ src/vsg/io/glsl.cpp | 10 ++++++++++ src/vsg/io/spirv.cpp | 8 ++++++++ src/vsg/io/tile.cpp | 9 ++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/vsg/io/VSG.cpp b/src/vsg/io/VSG.cpp index 5a46a72647..9077349a94 100644 --- a/src/vsg/io/VSG.cpp +++ b/src/vsg/io/VSG.cpp @@ -93,6 +93,8 @@ void VSG::writeHeader(std::ostream& fout, const FormatInfo& formatInfo) const vsg::ref_ptr VSG::read(const vsg::Path& filename, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (!compatibleExtension(filename, options, ".vsgb", ".vsgt")) return {}; vsg::Path filenameToUse = findFile(filename, options); @@ -123,6 +125,8 @@ vsg::ref_ptr VSG::read(const vsg::Path& filename, ref_ptr VSG::read(std::istream& fin, vsg::ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; auto [type, version] = readHeader(fin); @@ -144,6 +148,8 @@ vsg::ref_ptr VSG::read(std::istream& fin, vsg::ref_ptr VSG::read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; mem_stream fin(ptr, size); @@ -152,6 +158,8 @@ vsg::ref_ptr VSG::read(const uint8_t* ptr, size_t size, vsg::ref_pt bool VSG::write(const vsg::Object* object, const vsg::Path& filename, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto version = vsgGetVersion(); if (options) @@ -192,6 +200,8 @@ bool VSG::write(const vsg::Object* object, const vsg::Path& filename, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; auto version = vsgGetVersion(); diff --git a/src/vsg/io/glsl.cpp b/src/vsg/io/glsl.cpp index 3802c3ed5a..71edc3a75b 100644 --- a/src/vsg/io/glsl.cpp +++ b/src/vsg/io/glsl.cpp @@ -48,6 +48,8 @@ bool glsl::extensionSupported(const Path& ext) ref_ptr glsl::createShader(const Path& found_filename, std::string& source, VkShaderStageFlagBits stageFlagBits, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + // handle any #includes in the source if (source.find("include") != std::string::npos) { @@ -66,6 +68,8 @@ ref_ptr glsl::createShader(const Path& found_filename, std::string& sour ref_ptr glsl::read(const Path& filename, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) stage_itr = s_extensionToStage.find(lowerCaseFileExtension(filename)); if (stage_itr == s_extensionToStage.end()) return {}; @@ -88,6 +92,8 @@ ref_ptr glsl::read(const Path& filename, ref_ptr options) ref_ptr glsl::read(std::istream& fin, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) return {}; @@ -104,6 +110,8 @@ ref_ptr glsl::read(std::istream& fin, ref_ptr option ref_ptr glsl::read(const uint8_t* ptr, size_t size, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) return {}; @@ -114,6 +122,8 @@ ref_ptr glsl::read(const uint8_t* ptr, size_t size, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) stage_itr = s_extensionToStage.find(lowerCaseFileExtension(filename)); if (stage_itr == s_extensionToStage.end()) return false; diff --git a/src/vsg/io/spirv.cpp b/src/vsg/io/spirv.cpp index e1a50f7312..06943c5210 100644 --- a/src/vsg/io/spirv.cpp +++ b/src/vsg/io/spirv.cpp @@ -45,6 +45,8 @@ spirv::spirv() vsg::ref_ptr spirv::read(const vsg::Path& filename, vsg::ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (!compatibleExtension(filename, options, ".spv")) return {}; vsg::Path found_filename = vsg::findFile(filename, options); @@ -57,6 +59,8 @@ vsg::ref_ptr spirv::read(const vsg::Path& filename, vsg::ref_ptr spirv::read(std::istream& fin, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (!compatibleExtension(options, ".spv")) return {}; fin.seekg(0, fin.end); @@ -77,6 +81,8 @@ ref_ptr spirv::read(std::istream& fin, ref_ptr optio ref_ptr spirv::read(const uint8_t* ptr, size_t size, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (!compatibleExtension(options, ".spv")) return {}; using value_type = vsg::ShaderModule::SPIRV::value_type; @@ -91,6 +97,8 @@ ref_ptr spirv::read(const uint8_t* ptr, size_t size, ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (!compatibleExtension(filename, options, ".spv")) return false; const vsg::ShaderStage* ss = dynamic_cast(object); diff --git a/src/vsg/io/tile.cpp b/src/vsg/io/tile.cpp index 83d983c3d0..92ad334d32 100644 --- a/src/vsg/io/tile.cpp +++ b/src/vsg/io/tile.cpp @@ -117,6 +117,8 @@ vsg::Path tile::getTilePath(const vsg::Path& src, uint32_t x, uint32_t y, uint32 vsg::ref_ptr tile::read(const vsg::Path& filename, vsg::ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto extension = vsg::lowerCaseFileExtension(filename); if (extension != ".tile") return {}; @@ -140,6 +142,8 @@ vsg::ref_ptr tile::read(const vsg::Path& filename, vsg::ref_ptr tile::read_root(vsg::ref_ptr options) const { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + auto group = createRoot(); uint32_t lod = 0; @@ -199,8 +203,9 @@ vsg::ref_ptr tile::read_root(vsg::ref_ptr optio vsg::ref_ptr tile::read_subtile(uint32_t x, uint32_t y, uint32_t lod, vsg::ref_ptr options) const { - // need to load subtile x y lod + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + // need to load subtile x y lod vsg::time_point start_read = vsg::clock::now(); auto group = vsg::Group::create(); @@ -294,6 +299,8 @@ vsg::ref_ptr tile::read_subtile(uint32_t x, uint32_t y, uint32_t lo void tile::init(vsg::ref_ptr options) { + CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + if (settings->shaderSet) { _shaderSet = settings->shaderSet; From 569ec135db1676c0e0b721b1845c6a681c30c94e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 12:08:48 +0000 Subject: [PATCH 40/68] Added timestamp calaibrartion extensions and prelimnary support in TracyInstrumentation. --- include/vsg/utils/TracyInstrumentation.h | 13 ++++++++++++- include/vsg/vk/InstanceExtensions.h | 4 ++++ src/vsg/vk/InstanceExtensions.cpp | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 505557e16f..0efb29eefb 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -37,7 +37,18 @@ namespace vsg auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); auto commandPool = CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); auto temporaryCommandBuffer = commandPool->allocate(); - ctx = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + + auto extensions = device->getInstance()->getExtensions(); + if (extensions->vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) + { + ctx = TracyVkContextCalibrated(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk(), + extensions->vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, extensions->vkGetCalibratedTimestampsEXT); + } + else + { + ctx = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); + } + } return ctx; } diff --git a/include/vsg/vk/InstanceExtensions.h b/include/vsg/vk/InstanceExtensions.h index e1df36d658..d0d81e802d 100644 --- a/include/vsg/vk/InstanceExtensions.h +++ b/include/vsg/vk/InstanceExtensions.h @@ -37,6 +37,10 @@ namespace vsg PFN_vkCreateDebugUtilsMessengerEXT vkCreateDebugUtilsMessengerEXT = nullptr; PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr; PFN_vkSubmitDebugUtilsMessageEXT vkSubmitDebugUtilsMessageEXT = nullptr; + + // VK_EXT_calibrated_timestamps + PFN_vkGetPhysicalDeviceCalibrateableTimeDomainsEXT vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = nullptr; + PFN_vkGetCalibratedTimestampsEXT vkGetCalibratedTimestampsEXT = nullptr; }; VSG_type_name(vsg::InstanceExtensions); diff --git a/src/vsg/vk/InstanceExtensions.cpp b/src/vsg/vk/InstanceExtensions.cpp index 14f85b8fe6..4be6c43fcb 100644 --- a/src/vsg/vk/InstanceExtensions.cpp +++ b/src/vsg/vk/InstanceExtensions.cpp @@ -37,4 +37,11 @@ InstanceExtensions::InstanceExtensions(Instance* instance) instance->getProcAddr(vkCreateDebugUtilsMessengerEXT, "vkCreateDebugUtilsMessengerEXT"); instance->getProcAddr(vkDestroyDebugUtilsMessengerEXT, "vkDestroyDebugUtilsMessengerEXT"); instance->getProcAddr(vkSubmitDebugUtilsMessageEXT, "vkSubmitDebugUtilsMessageEXT"); + + // VK_EXT_calibrated_timestamps + instance->getProcAddr(vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR", "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"); + instance->getProcAddr(vkGetCalibratedTimestampsEXT, "vkGetCalibratedTimestampsKHR", "vkGetCalibratedTimestampsEXT"); + + info("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = ", vkGetPhysicalDeviceCalibrateableTimeDomainsEXT); + info("vkGetCalibratedTimestampsEXT = ", vkGetCalibratedTimestampsEXT); } From 03d22b75fd4c75d18f6aaf450694f8883e776257 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 12:41:38 +0000 Subject: [PATCH 41/68] Removed debug messages --- src/vsg/vk/InstanceExtensions.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vsg/vk/InstanceExtensions.cpp b/src/vsg/vk/InstanceExtensions.cpp index 4be6c43fcb..2dc586f9bf 100644 --- a/src/vsg/vk/InstanceExtensions.cpp +++ b/src/vsg/vk/InstanceExtensions.cpp @@ -41,7 +41,4 @@ InstanceExtensions::InstanceExtensions(Instance* instance) // VK_EXT_calibrated_timestamps instance->getProcAddr(vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, "vkGetPhysicalDeviceCalibrateableTimeDomainsKHR", "vkGetPhysicalDeviceCalibrateableTimeDomainsEXT"); instance->getProcAddr(vkGetCalibratedTimestampsEXT, "vkGetCalibratedTimestampsKHR", "vkGetCalibratedTimestampsEXT"); - - info("vkGetPhysicalDeviceCalibrateableTimeDomainsEXT = ", vkGetPhysicalDeviceCalibrateableTimeDomainsEXT); - info("vkGetCalibratedTimestampsEXT = ", vkGetCalibratedTimestampsEXT); } From 5ff94ec1862830431c601e80902c5bc2fcb259ee Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 12:41:54 +0000 Subject: [PATCH 42/68] Added support for TRACY_ENABLE being defined/or not. --- include/vsg/utils/TracyInstrumentation.h | 29 +++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 0efb29eefb..e7cc237788 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -22,6 +22,15 @@ using namespace tracy; namespace vsg { + class TracySettings : public Inherit + { + public: + uint32_t cpu_instumentation_level = 3; + uint32_t gpu_instumentation_level = 3; + }; + VSG_type_name(vsg::TracySettings); + +#ifdef TRACY_ENABLE /// thread safe helper class for creating the Tracy VkCtx objects per Device. class TracyContexts : public Inherit { @@ -67,14 +76,6 @@ namespace vsg }; VSG_type_name(vsg::TracyContexts); - class TracySettings : public Inherit - { - public: - uint32_t cpu_instumentation_level = 3; - uint32_t gpu_instumentation_level = 3; - }; - VSG_type_name(vsg::TracySettings); - /// TracyInstrumentation provides integration between the Instrumentation system and the Tracy profiler class TracyInstrumentation : public Inherit { @@ -218,5 +219,17 @@ namespace vsg } }; VSG_type_name(vsg::TracyInstrumentation); +#else + class TracyInstrumentation : public Inherit + { + public: + TracyInstrumentation() + { + vsg::info("TracyInstrumentation not supported and the tracy's TRACY_ENABLE is set to OFF."); + } + ref_ptr settings; + }; + VSG_type_name(vsg::TracyInstrumentation); +#endif } // namespace vsg From 057361927a352e8928aec55c0ee9f1e6613ea8b8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 14:06:37 +0000 Subject: [PATCH 43/68] Replaced Device* with ref_ptr<> to prevent Instrumentation not keepig the vk/vsg::Device around long enough to clean up the VkXtx related Vulkan objects --- include/vsg/utils/TracyInstrumentation.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index e7cc237788..86651d6ac4 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -39,7 +39,7 @@ namespace vsg { std::scoped_lock lock(mutex); - auto device = commandBuffer.getDevice(); + ref_ptr device(commandBuffer.getDevice()); auto& ctx = ctxMap[device]; if (!ctx) { @@ -72,7 +72,7 @@ namespace vsg } mutable std::mutex mutex; - mutable std::map ctxMap; + mutable std::map, VkCtx*> ctxMap; }; VSG_type_name(vsg::TracyContexts); From 9d923ea40d654bad166d1299c635c5cc630a6887 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 14:07:42 +0000 Subject: [PATCH 44/68] Removed debug messages --- include/vsg/utils/TracyInstrumentation.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 86651d6ac4..9ce7d372a3 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -84,14 +84,12 @@ namespace vsg settings(TracySettings::create()), contexts(TracyContexts::create()) { - vsg::info("creating TracyInstrumentation", this, ", ", settings, ", ", contexts); } TracyInstrumentation(TracyInstrumentation& parent) : settings(parent.settings), contexts(parent.contexts) { - vsg::info("duplicating TracyInstrumentation", this, ", ", settings, ", ", contexts); } ref_ptr settings; From 3d346cf707cc0c476dc6221233fa4a16dc798aa9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Dec 2023 17:49:44 +0000 Subject: [PATCH 45/68] Added Instrumentation::setThreadName(const std::string&) support. --- include/vsg/utils/Instrumentation.h | 5 ++- include/vsg/utils/TracyInstrumentation.h | 5 +++ src/vsg/app/Viewer.cpp | 41 ++++++++++++++++++------ src/vsg/io/DatabasePager.cpp | 5 +-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index a2dcdfb704..bddf5d5764 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -43,6 +43,8 @@ namespace vsg virtual ref_ptr shareOrDuplicateForThreadSafety() { return ref_ptr(this); } + virtual void setThreadName(const std::string& /*name*/) const {}; + virtual void enterFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; virtual void leaveFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; @@ -55,6 +57,7 @@ namespace vsg virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; + protected: virtual ~Instrumentation(); }; @@ -131,7 +134,7 @@ namespace vsg #define __COMMAND_BUFFER_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_cg_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - CommandBufferInstrumentation __cb_scoped_instrumentation_##__LINE__(instrumentation, &(s_cg_source_location_##__LINE__), cg); + CommandBufferInstrumentation __cg_scoped_instrumentation_##__LINE__(instrumentation, &(s_cg_source_location_##__LINE__), cg); #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 9ce7d372a3..a422411b84 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -101,6 +101,11 @@ namespace vsg return TracyInstrumentation::create(*this); } + void setThreadName(const std::string& name) const override + { + tracy::SetThreadName(name.c_str()); + } + void enterFrame(const SourceLocation*, uint64_t&, FrameStamp&) const override {} void leaveFrame(const SourceLocation*, uint64_t&, FrameStamp&) const override diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 0c40b36cc8..1f9826b998 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -610,8 +610,6 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - CPU_INSTRUMENTATION_L1(instrumentation); - debug("Viewer::setupThreading() "); stopThreading(); @@ -643,19 +641,24 @@ void Viewer::setupThreading() if (task->commandGraphs.size() == 1 && !task->earlyTransferTask) { // task only contains a single CommandGraph so keep thread simple - auto run = [](ref_ptr viewer_task, ref_ptr viewer_frameBlock, ref_ptr submissionCompleted) { + auto run = [](ref_ptr viewer_task, ref_ptr viewer_frameBlock, ref_ptr submissionCompleted, const std::string& threadName) { + auto local_instrumentation = shareOrDuplicateForThreadSafety(viewer_task->instrumentation); + if (local_instrumentation) local_instrumentation->setThreadName(threadName); + auto frameStamp = viewer_frameBlock->initial_value; // wait for this frame to be signaled while (viewer_frameBlock->wait_for_change(frameStamp)) { + CPU_INSTRUMENTATION_L1(local_instrumentation); + viewer_task->submit(frameStamp); submissionCompleted->arrive_and_drop(); } }; - threads.emplace_back(run, task, _frameBlock, _submissionCompleted); + threads.emplace_back(run, task, _frameBlock, _submissionCompleted, make_string("Viewer run thread")); } else if (!task->commandGraphs.empty()) { @@ -688,12 +691,18 @@ void Viewer::setupThreading() ref_ptr sharedData = SharedData::create(task, _frameBlock, _submissionCompleted, numThreads); - auto run_primary = [](ref_ptr data, ref_ptr commandGraph) { + auto run_primary = [](ref_ptr data, ref_ptr commandGraph, const std::string& threadName) { + + auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); + if (local_instrumentation) local_instrumentation->setThreadName(threadName); + auto frameStamp = data->frameBlock->initial_value; // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { + CPU_INSTRUMENTATION_L1(local_instrumentation); + // primary thread starts the task data->task->start(); @@ -714,12 +723,18 @@ void Viewer::setupThreading() } }; - auto run_secondary = [](ref_ptr data, ref_ptr commandGraph) { + auto run_secondary = [](ref_ptr data, ref_ptr commandGraph, const std::string& threadName) { + + auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); + if (local_instrumentation) local_instrumentation->setThreadName(threadName); + auto frameStamp = data->frameBlock->initial_value; // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { + CPU_INSTRUMENTATION_L1(local_instrumentation); + data->recordStartBarrier->arrive_and_wait(); commandGraph->record(data->recordedCommandBuffers, frameStamp, data->task->databasePager); @@ -728,12 +743,18 @@ void Viewer::setupThreading() } }; - auto run_transfer = [](ref_ptr data, ref_ptr transferTask) { + auto run_transfer = [](ref_ptr data, ref_ptr transferTask, const std::string& threadName) { + + auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); + if (local_instrumentation) local_instrumentation->setThreadName(threadName); + auto frameStamp = data->frameBlock->initial_value; // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { + CPU_INSTRUMENTATION_L1(local_instrumentation); + data->recordStartBarrier->arrive_and_wait(); //vsg::info("run_transfer"); @@ -747,14 +768,14 @@ void Viewer::setupThreading() for (uint32_t i = 0; i < task->commandGraphs.size(); ++i) { if (i == 0) - threads.emplace_back(run_primary, sharedData, task->commandGraphs[i]); + threads.emplace_back(run_primary, sharedData, task->commandGraphs[i], make_string("Viewer primary thread")); else - threads.emplace_back(run_secondary, sharedData, task->commandGraphs[i]); + threads.emplace_back(run_secondary, sharedData, task->commandGraphs[i], make_string("Viewer seconary thread ", i)); } if (task->earlyTransferTask) { - threads.emplace_back(run_transfer, sharedData, task->earlyTransferTask); + threads.emplace_back(run_transfer, sharedData, task->earlyTransferTask, make_string("Viewer earlyDynamicData thread")); } } } diff --git a/src/vsg/io/DatabasePager.cpp b/src/vsg/io/DatabasePager.cpp index e9ce19eb4e..bd45445d3f 100644 --- a/src/vsg/io/DatabasePager.cpp +++ b/src/vsg/io/DatabasePager.cpp @@ -138,10 +138,11 @@ void DatabasePager::start() // // set up read thread(s) // - auto read = [](ref_ptr requestQueue, ref_ptr status, DatabasePager& databasePager) { + auto read = [](ref_ptr requestQueue, ref_ptr status, DatabasePager& databasePager, const std::string& threadName) { debug("Started DatabaseThread read thread"); auto local_instrumentation = shareOrDuplicateForThreadSafety(databasePager.instrumentation); + if (local_instrumentation) local_instrumentation->setThreadName(threadName); while (status->active()) { @@ -198,7 +199,7 @@ void DatabasePager::start() for (int i = 0; i < numReadThreads; ++i) { - _readThreads.emplace_back(read, std::ref(_requestQueue), std::ref(_status), std::ref(*this)); + _readThreads.emplace_back(read, std::ref(_requestQueue), std::ref(_status), std::ref(*this), make_string("DatabasePager thread ", i)); } } From 05834c5e861513d736570ca51097831e5b450409 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 11:13:56 +0000 Subject: [PATCH 46/68] Added name and colour entries for main operations --- include/vsg/utils/Instrumentation.h | 19 ++++++++---- src/vsg/app/CommandGraph.cpp | 4 +-- src/vsg/app/CompileTraversal.cpp | 20 ++++++------- src/vsg/app/RecordAndSubmitTask.cpp | 10 +++---- src/vsg/app/RecordTraversal.cpp | 44 +++++++++++++-------------- src/vsg/app/TransferTask.cpp | 4 +-- src/vsg/app/Viewer.cpp | 46 ++++++++++++++--------------- src/vsg/io/DatabasePager.cpp | 2 +- src/vsg/io/VSG.cpp | 10 +++---- src/vsg/io/glsl.cpp | 10 +++---- src/vsg/io/read.cpp | 8 ++--- src/vsg/io/spirv.cpp | 6 ++-- src/vsg/io/tile.cpp | 8 ++--- src/vsg/io/write.cpp | 2 +- src/vsg/vk/Context.cpp | 18 ++++++++++- 15 files changed, 118 insertions(+), 93 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index bddf5d5764..0d5d526d99 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -23,6 +23,15 @@ namespace vsg class CommandBuffer; class FrameStamp; + #define COLOR_VIEWER ubvec4(128, 249, 240, 255) + #define COLOR_UPDATE ubvec4(0, 255, 0, 255) + #define COLOR_RECORD ubvec4(0, 255, 255, 255) + #define COLOR_GPU ubvec4(255, 127, 0, 255) + #define COLOR_COMPILE ubvec4(255, 249, 64, 255) + #define COLOR_READ ubvec4(128, 255, 0, 255) + #define COLOR_WRITE ubvec4(255, 128, 0, 255) + #define COLOR_PAGER ubvec4(240, 255, 64, 255) + /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -146,9 +155,9 @@ namespace vsg # define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) +# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, color) -# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg) __COMMAND_BUFFER_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) +# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg, name, color) __COMMAND_BUFFER_INSTRUMENTATION(1, instrumentation, cg, name, color) #else @@ -162,7 +171,7 @@ namespace vsg # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) # define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) -# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg) +# define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg, name, color) #endif @@ -175,7 +184,7 @@ namespace vsg # define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) +# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, color) #else # define CPU_INSTRUMENTATION_L2(instrumentation) # define CPU_INSTRUMENTATION_L2_N(instrumentation, name) @@ -197,7 +206,7 @@ namespace vsg # define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) +# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, color) #else # define CPU_INSTRUMENTATION_L3(instrumentation) # define CPU_INSTRUMENTATION_L3_N(instrumentation, name) diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 112ccd1fb3..4b70283aae 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -79,7 +79,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CommandGraph record", COLOR_RECORD); if (window && !window->visible()) { @@ -136,7 +136,7 @@ void CommandGraph::record(ref_ptr recordedCommandBuffers vkBeginCommandBuffer(vk_commandBuffer, &beginInfo); { - COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer, "CommandGraph record", COLOR_RECORD) traverse(*recordTraversal); } diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index bac74df94d..13c11ca66f 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -225,14 +225,14 @@ void CompileTraversal::assignInstrumentation(ref_ptr in_instrum void CompileTraversal::apply(Object& object) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_NC(instrumentation,"CompileTraversal Object", COLOR_COMPILE); object.traverse(*this); } void CompileTraversal::apply(Compilable& node) { - CPU_INSTRUMENTATION_L3(instrumentation); + CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Compilable", COLOR_COMPILE); for (auto& context : contexts) { @@ -242,7 +242,7 @@ void CompileTraversal::apply(Compilable& node) void CompileTraversal::apply(Commands& commands) { - CPU_INSTRUMENTATION_L3(instrumentation); + CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Commands", COLOR_COMPILE); for (auto& context : contexts) { @@ -252,7 +252,7 @@ void CompileTraversal::apply(Commands& commands) void CompileTraversal::apply(StateGroup& stateGroup) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_NC(instrumentation,"CompileTraversal StateGroup", COLOR_COMPILE); for (auto& context : contexts) { @@ -263,7 +263,7 @@ void CompileTraversal::apply(StateGroup& stateGroup) void CompileTraversal::apply(Geometry& geometry) { - CPU_INSTRUMENTATION_L3(instrumentation); + CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Geometry", COLOR_COMPILE); for (auto& context : contexts) { @@ -274,7 +274,7 @@ void CompileTraversal::apply(Geometry& geometry) void CompileTraversal::apply(CommandGraph& commandGraph) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal CommandGraph", COLOR_COMPILE); for (auto& context : contexts) { @@ -289,7 +289,7 @@ void CompileTraversal::apply(CommandGraph& commandGraph) void CompileTraversal::apply(RenderGraph& renderGraph) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal RenderGraph", COLOR_COMPILE); for (auto& context : contexts) { @@ -323,7 +323,7 @@ void CompileTraversal::apply(RenderGraph& renderGraph) void CompileTraversal::apply(View& view) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal View", COLOR_COMPILE); for (auto& context : contexts) { @@ -364,7 +364,7 @@ void CompileTraversal::apply(View& view) bool CompileTraversal::record() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal record", COLOR_COMPILE); bool recorded = false; for (auto& context : contexts) @@ -376,7 +376,7 @@ bool CompileTraversal::record() void CompileTraversal::waitForCompletion() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal waitForCompletion", COLOR_COMPILE); for (auto& context : contexts) { diff --git a/src/vsg/app/RecordAndSubmitTask.cpp b/src/vsg/app/RecordAndSubmitTask.cpp index 9645336499..890e87f12a 100644 --- a/src/vsg/app/RecordAndSubmitTask.cpp +++ b/src/vsg/app/RecordAndSubmitTask.cpp @@ -44,7 +44,7 @@ RecordAndSubmitTask::RecordAndSubmitTask(Device* in_device, uint32_t numBuffers) void RecordAndSubmitTask::advance() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "RecordAndSubmitTask advance", COLOR_VIEWER); if (_currentFrameIndex >= _indices.size()) { @@ -84,7 +84,7 @@ Fence* RecordAndSubmitTask::fence(size_t relativeFrameIndex) VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "RecordAndSubmitTask submit", COLOR_RECORD); if (VkResult result = start(); result != VK_SUCCESS) return result; @@ -102,7 +102,7 @@ VkResult RecordAndSubmitTask::submit(ref_ptr frameStamp) VkResult RecordAndSubmitTask::start() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "RecordAndSubmitTask start", COLOR_RECORD); if (earlyTransferTask) earlyTransferTask->currentTransferCompletedSemaphore = {}; if (lateTransferTask) lateTransferTask->currentTransferCompletedSemaphore = {}; @@ -120,7 +120,7 @@ VkResult RecordAndSubmitTask::start() VkResult RecordAndSubmitTask::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "RecordAndSubmitTask record", COLOR_RECORD); for (auto& commandGraph : commandGraphs) { @@ -132,7 +132,7 @@ VkResult RecordAndSubmitTask::record(ref_ptr recordedCom VkResult RecordAndSubmitTask::finish(ref_ptr recordedCommandBuffers) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "RecordAndSubmitTask finish", COLOR_RECORD); if (lateTransferTask) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 3f0688a0b3..6c945093f8 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -51,7 +51,7 @@ using namespace vsg; RecordTraversal::RecordTraversal(uint32_t in_maxSlot, std::set in_bins) : _state(new State(in_maxSlot)) { - CPU_INSTRUMENTATION_L1_C(instrumentation, ubvec4(0, 0, 255, 255)); + CPU_INSTRUMENTATION_L1_C(instrumentation, COLOR_RECORD); _minimumBinNumber = 0; int32_t maximumBinNumber = 0; @@ -99,7 +99,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "RecordTraversal clearBins", COLOR_RECORD); for (auto& bin : _bins) { @@ -109,7 +109,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD); //debug("Visiting Object"); object.traverse(*this); @@ -117,7 +117,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Group", COLOR_RECORD); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -129,7 +129,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "QuadGroup", COLOR_RECORD); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -141,7 +141,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "LOD", COLOR_RECORD); const auto& sphere = lod.bound; @@ -166,7 +166,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_PAGER); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -246,7 +246,7 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const CullGroup& cullGroup) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD); if (_state->intersect(cullGroup.bound)) { @@ -257,7 +257,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_RECORD); if (_state->intersect(cullNode.bound)) { @@ -268,7 +268,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Switch", COLOR_RECORD); for (auto& child : sw.children) { @@ -281,7 +281,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "DepthSorted", COLOR_RECORD); if (_state->intersect(depthSorted.bound)) { @@ -295,7 +295,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const VertexDraw& vd) { - GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "VertexDraw", COLOR_GPU); //debug("Visiting VertexDraw"); _state->record(); @@ -304,7 +304,7 @@ void RecordTraversal::apply(const VertexDraw& vd) void RecordTraversal::apply(const VertexIndexDraw& vid) { - GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "VertexIndexDraw", COLOR_GPU); //debug("Visiting VertexIndexDraw"); _state->record(); @@ -313,7 +313,7 @@ void RecordTraversal::apply(const VertexIndexDraw& vid) void RecordTraversal::apply(const Geometry& geometry) { - GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Geometry", COLOR_GPU); //debug("Visiting Geometry"); _state->record(); @@ -361,7 +361,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(255, 255, 0, 255)); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "StateGroup", COLOR_RECORD); //debug("Visiting StateGroup"); @@ -382,7 +382,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Transform", COLOR_RECORD); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -404,7 +404,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "MatrixTransform", COLOR_RECORD); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -427,7 +427,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Commands", COLOR_RECORD); _state->record(); for (auto& command : commands.children) @@ -438,7 +438,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - GPU_INSTRUMENTATION_L3_C(instrumentation, *getCommandBuffer(), ubvec4(0, 255, 0, 255)); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Command", COLOR_RECORD); //debug("Visiting Command"); _state->record(); @@ -447,7 +447,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const Bin& object) { - GPU_INSTRUMENTATION_L2(instrumentation, *getCommandBuffer()); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Bin", COLOR_RECORD); //debug("Visiting Bin"); object.traverse(*this); @@ -455,7 +455,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "View", COLOR_RECORD); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -544,7 +544,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - GPU_INSTRUMENTATION_L2_C(instrumentation, *getCommandBuffer(), ubvec4(0, 0, 255, 255)); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "RecordTraversal CommandGraph", COLOR_RECORD); if (recordedCommandBuffers) { diff --git a/src/vsg/app/TransferTask.cpp b/src/vsg/app/TransferTask.cpp index aea6c22c72..efb089a4a3 100644 --- a/src/vsg/app/TransferTask.cpp +++ b/src/vsg/app/TransferTask.cpp @@ -331,7 +331,7 @@ void TransferTask::_transferImageInfo(VkCommandBuffer vk_commandBuffer, Frame& f VkResult TransferTask::transferDynamicData() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "transferDynamicData", COLOR_RECORD); Logger::Level level = Logger::LOGGER_DEBUG; //level = Logger::LOGGER_INFO; @@ -397,7 +397,7 @@ VkResult TransferTask::transferDynamicData() VkDeviceSize offset = 0; { - COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer, "transferDynamicData", COLOR_GPU) // transfer the modified BufferInfo and ImageInfo _transferBufferInfos(vk_commandBuffer, frame, offset); diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 1f9826b998..d82eaab311 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()) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer costructor", COLOR_VIEWER); } Viewer::~Viewer() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer destructor", COLOR_VIEWER); stopThreading(); @@ -47,7 +47,7 @@ Viewer::~Viewer() void Viewer::deviceWaitIdle() const { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer deviceWaitIdle", COLOR_VIEWER); std::set devices; for (auto& window : _windows) @@ -101,7 +101,7 @@ void Viewer::removeWindow(ref_ptr window) void Viewer::close() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer close", COLOR_VIEWER); _close = true; status->set(false); @@ -111,7 +111,7 @@ void Viewer::close() bool Viewer::active() const { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer active", COLOR_VIEWER); bool viewerIsActive = !_close; if (viewerIsActive) @@ -136,7 +136,7 @@ bool Viewer::active() const bool Viewer::pollEvents(bool discardPreviousEvents) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer pollEvents", COLOR_UPDATE); bool result = false; @@ -151,7 +151,7 @@ bool Viewer::pollEvents(bool discardPreviousEvents) bool Viewer::advanceToNextFrame() { - static constexpr SourceLocation s_frame_source_location{"frame", VsgFunctionName, __FILE__, __LINE__, ubvec4(255, 255, 255, 255), 1}; + static constexpr SourceLocation s_frame_source_location{"Viewer advanceToNextFrame", VsgFunctionName, __FILE__, __LINE__, COLOR_VIEWER, 1}; uint64_t reference = 0; if (!active()) return false; @@ -193,7 +193,7 @@ bool Viewer::advanceToNextFrame() bool Viewer::acquireNextFrame() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer acquireNextFrame", COLOR_VIEWER); if (_close) return false; @@ -233,7 +233,7 @@ bool Viewer::acquireNextFrame() VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer waitForFences", COLOR_VIEWER); VkResult result = VK_SUCCESS; for (auto& task : recordAndSubmitTasks) @@ -250,7 +250,7 @@ VkResult Viewer::waitForFences(size_t relativeFrameIndex, uint64_t timeout) void Viewer::handleEvents() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer handle events", COLOR_UPDATE); for (auto& vsg_event : _events) { @@ -263,7 +263,7 @@ void Viewer::handleEvents() void Viewer::compile(ref_ptr hints) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer compile", COLOR_COMPILE); if (recordAndSubmitTasks.empty()) { @@ -426,7 +426,7 @@ void Viewer::compile(ref_ptr hints) void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGraphs) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer assignRecordAndSubmitTaskAndPresentation", COLOR_VIEWER); // now remove any commandGraphs associated with window bool needToStartThreading = _threading; @@ -589,7 +589,7 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer addRecordAndSubmitTaskAndPresentation", COLOR_VIEWER); // collect the existing CommandGraphs CommandGraphs combinedCommandGraphs; @@ -610,7 +610,7 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - debug("Viewer::setupThreading() "); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer setupThreading", COLOR_VIEWER); stopThreading(); @@ -650,7 +650,7 @@ void Viewer::setupThreading() // wait for this frame to be signaled while (viewer_frameBlock->wait_for_change(frameStamp)) { - CPU_INSTRUMENTATION_L1(local_instrumentation); + CPU_INSTRUMENTATION_L1_NC(local_instrumentation, "Viewer run", COLOR_RECORD); viewer_task->submit(frameStamp); @@ -701,7 +701,7 @@ void Viewer::setupThreading() // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { - CPU_INSTRUMENTATION_L1(local_instrumentation); + CPU_INSTRUMENTATION_L1_NC(local_instrumentation, "Viewer primary", COLOR_RECORD); // primary thread starts the task data->task->start(); @@ -733,7 +733,7 @@ void Viewer::setupThreading() // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { - CPU_INSTRUMENTATION_L1(local_instrumentation); + CPU_INSTRUMENTATION_L1_NC(local_instrumentation, "Viewer secondary", COLOR_RECORD); data->recordStartBarrier->arrive_and_wait(); @@ -753,7 +753,7 @@ void Viewer::setupThreading() // wait for this frame to be signaled while (data->frameBlock->wait_for_change(frameStamp)) { - CPU_INSTRUMENTATION_L1(local_instrumentation); + CPU_INSTRUMENTATION_L1_NC(local_instrumentation, "Viewer transfer", COLOR_RECORD); data->recordStartBarrier->arrive_and_wait(); @@ -783,7 +783,7 @@ void Viewer::setupThreading() void Viewer::stopThreading() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer stopThreading", COLOR_VIEWER); if (!_threading) return; _threading = false; @@ -804,7 +804,7 @@ void Viewer::stopThreading() void Viewer::update() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer update", COLOR_UPDATE); for (auto& task : recordAndSubmitTasks) { @@ -821,7 +821,7 @@ void Viewer::update() void Viewer::recordAndSubmit() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer recordAndSubmitTask", COLOR_VIEWER); // reset connected ExecuteCommands for (auto& recordAndSubmitTask : recordAndSubmitTasks) @@ -855,7 +855,7 @@ void Viewer::recordAndSubmit() void Viewer::present() { - CPU_INSTRUMENTATION_L1(instrumentation); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer present", COLOR_VIEWER); for (auto& presentation : presentations) { @@ -886,7 +886,7 @@ void Viewer::assignInstrumentation(ref_ptr in_instrumentation) void vsg::updateViewer(Viewer& viewer, const CompileResult& compileResult) { - CPU_INSTRUMENTATION_L1(viewer.instrumentation); + CPU_INSTRUMENTATION_L1_NC(viewer.instrumentation, "updateViewer", COLOR_VIEWER); updateTasks(viewer.recordAndSubmitTasks, viewer.compileManager, compileResult); } diff --git a/src/vsg/io/DatabasePager.cpp b/src/vsg/io/DatabasePager.cpp index bd45445d3f..54ef1c3e3f 100644 --- a/src/vsg/io/DatabasePager.cpp +++ b/src/vsg/io/DatabasePager.cpp @@ -149,7 +149,7 @@ void DatabasePager::start() auto plod = requestQueue->take_when_available(); if (plod) { - CPU_INSTRUMENTATION_L1(databasePager.instrumentation); + CPU_INSTRUMENTATION_L1_NC(databasePager.instrumentation, "DatabasePager read", COLOR_PAGER); uint64_t frameDelta = databasePager.frameCount - plod->frameHighResLastUsed.load(); if (frameDelta > 1 || !compare_exchange(plod->requestStatus, PagedLOD::ReadRequest, PagedLOD::Reading)) diff --git a/src/vsg/io/VSG.cpp b/src/vsg/io/VSG.cpp index 9077349a94..0096498fc0 100644 --- a/src/vsg/io/VSG.cpp +++ b/src/vsg/io/VSG.cpp @@ -93,7 +93,7 @@ void VSG::writeHeader(std::ostream& fout, const FormatInfo& formatInfo) const vsg::ref_ptr VSG::read(const vsg::Path& filename, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "VSG read", COLOR_READ); if (!compatibleExtension(filename, options, ".vsgb", ".vsgt")) return {}; @@ -125,7 +125,7 @@ vsg::ref_ptr VSG::read(const vsg::Path& filename, ref_ptr VSG::read(std::istream& fin, vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "VSG read", COLOR_READ); if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; @@ -148,7 +148,7 @@ vsg::ref_ptr VSG::read(std::istream& fin, vsg::ref_ptr VSG::read(const uint8_t* ptr, size_t size, vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "VSG read", COLOR_READ); if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; @@ -158,7 +158,7 @@ vsg::ref_ptr VSG::read(const uint8_t* ptr, size_t size, vsg::ref_pt bool VSG::write(const vsg::Object* object, const vsg::Path& filename, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "VSG write", COLOR_READ); auto version = vsgGetVersion(); @@ -200,7 +200,7 @@ bool VSG::write(const vsg::Object* object, const vsg::Path& filename, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "VSG write", COLOR_WRITE); if (options && !compatibleExtension(options, ".vsgb", ".vsgt")) return {}; diff --git a/src/vsg/io/glsl.cpp b/src/vsg/io/glsl.cpp index 71edc3a75b..c12eeb3e27 100644 --- a/src/vsg/io/glsl.cpp +++ b/src/vsg/io/glsl.cpp @@ -48,7 +48,7 @@ bool glsl::extensionSupported(const Path& ext) ref_ptr glsl::createShader(const Path& found_filename, std::string& source, VkShaderStageFlagBits stageFlagBits, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L2_NC(options ? options->instrumentation.get() : nullptr, "glsl createShader", COLOR_READ); // handle any #includes in the source if (source.find("include") != std::string::npos) @@ -68,7 +68,7 @@ ref_ptr glsl::createShader(const Path& found_filename, std::string& sour ref_ptr glsl::read(const Path& filename, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "glsl read", COLOR_READ); auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) stage_itr = s_extensionToStage.find(lowerCaseFileExtension(filename)); @@ -92,7 +92,7 @@ ref_ptr glsl::read(const Path& filename, ref_ptr options) ref_ptr glsl::read(std::istream& fin, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "glsl read", COLOR_READ); auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) return {}; @@ -110,7 +110,7 @@ ref_ptr glsl::read(std::istream& fin, ref_ptr option ref_ptr glsl::read(const uint8_t* ptr, size_t size, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "glsl read", COLOR_READ); auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) return {}; @@ -122,7 +122,7 @@ ref_ptr glsl::read(const uint8_t* ptr, size_t size, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "glsl write", COLOR_READ); auto stage_itr = (options && options->extensionHint) ? s_extensionToStage.find(options->extensionHint) : s_extensionToStage.end(); if (stage_itr == s_extensionToStage.end()) stage_itr = s_extensionToStage.find(lowerCaseFileExtension(filename)); diff --git a/src/vsg/io/read.cpp b/src/vsg/io/read.cpp index a9577f4749..4c469c6e42 100644 --- a/src/vsg/io/read.cpp +++ b/src/vsg/io/read.cpp @@ -23,7 +23,7 @@ using namespace vsg; ref_ptr vsg::read(const Path& filename, ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "read", COLOR_READ); auto read_file = [&]() -> ref_ptr { if (options && !options->readerWriters.empty()) @@ -83,7 +83,7 @@ ref_ptr vsg::read(const Path& filename, ref_ptr options) PathObjects vsg::read(const Paths& filenames, ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "read", COLOR_READ); ref_ptr operationThreads; if (options) operationThreads = options->operationThreads; @@ -154,7 +154,7 @@ PathObjects vsg::read(const Paths& filenames, ref_ptr options) ref_ptr vsg::read(std::istream& fin, ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "read", COLOR_READ); if (options && !options->readerWriters.empty()) { @@ -170,7 +170,7 @@ ref_ptr vsg::read(std::istream& fin, ref_ptr options) ref_ptr vsg::read(const uint8_t* ptr, size_t size, ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "read", COLOR_READ); if (options && !options->readerWriters.empty()) { diff --git a/src/vsg/io/spirv.cpp b/src/vsg/io/spirv.cpp index 06943c5210..249b80027c 100644 --- a/src/vsg/io/spirv.cpp +++ b/src/vsg/io/spirv.cpp @@ -45,7 +45,7 @@ spirv::spirv() vsg::ref_ptr spirv::read(const vsg::Path& filename, vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "spirv read", COLOR_READ); if (!compatibleExtension(filename, options, ".spv")) return {}; @@ -59,7 +59,7 @@ vsg::ref_ptr spirv::read(const vsg::Path& filename, vsg::ref_ptr spirv::read(std::istream& fin, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "spirv read", COLOR_READ); if (!compatibleExtension(options, ".spv")) return {}; @@ -97,7 +97,7 @@ ref_ptr spirv::read(const uint8_t* ptr, size_t size, ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "spirv write", COLOR_WRITE); if (!compatibleExtension(filename, options, ".spv")) return false; diff --git a/src/vsg/io/tile.cpp b/src/vsg/io/tile.cpp index 92ad334d32..32a90086df 100644 --- a/src/vsg/io/tile.cpp +++ b/src/vsg/io/tile.cpp @@ -117,7 +117,7 @@ vsg::Path tile::getTilePath(const vsg::Path& src, uint32_t x, uint32_t y, uint32 vsg::ref_ptr tile::read(const vsg::Path& filename, vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "tile read", COLOR_READ); auto extension = vsg::lowerCaseFileExtension(filename); if (extension != ".tile") return {}; @@ -142,7 +142,7 @@ vsg::ref_ptr tile::read(const vsg::Path& filename, vsg::ref_ptr tile::read_root(vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L2_NC(options ? options->instrumentation.get() : nullptr, "tile read_root", COLOR_READ); auto group = createRoot(); @@ -203,7 +203,7 @@ vsg::ref_ptr tile::read_root(vsg::ref_ptr optio vsg::ref_ptr tile::read_subtile(uint32_t x, uint32_t y, uint32_t lod, vsg::ref_ptr options) const { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L2_NC(options ? options->instrumentation.get() : nullptr, "tile read_subtile", COLOR_READ); // need to load subtile x y lod vsg::time_point start_read = vsg::clock::now(); @@ -299,7 +299,7 @@ vsg::ref_ptr tile::read_subtile(uint32_t x, uint32_t y, uint32_t lo void tile::init(vsg::ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L2_NC(options ? options->instrumentation.get() : nullptr, "tile init", COLOR_READ); if (settings->shaderSet) { diff --git a/src/vsg/io/write.cpp b/src/vsg/io/write.cpp index 72b77e28f2..52ca16bee3 100644 --- a/src/vsg/io/write.cpp +++ b/src/vsg/io/write.cpp @@ -20,7 +20,7 @@ using namespace vsg; bool vsg::write(ref_ptr object, const Path& filename, ref_ptr options) { - CPU_INSTRUMENTATION_L1(options ? options->instrumentation.get() : nullptr); + CPU_INSTRUMENTATION_L1_NC(options ? options->instrumentation.get() : nullptr, "write", COLOR_WRITE); bool fileWritten = false; if (options) diff --git a/src/vsg/vk/Context.cpp b/src/vsg/vk/Context.cpp index 99f143160d..b07a517ba2 100644 --- a/src/vsg/vk/Context.cpp +++ b/src/vsg/vk/Context.cpp @@ -157,6 +157,8 @@ ShaderCompiler* Context::getOrCreateShaderCompiler() void Context::getDescriptorPoolSizesToUse(uint32_t& maxSets, DescriptorPoolSizes& descriptorPoolSizes) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context getDescriptorPoolSizesToUse", COLOR_COMPILE) + if (minimum_maxSets > maxSets) { maxSets = minimum_maxSets; @@ -183,6 +185,8 @@ void Context::getDescriptorPoolSizesToUse(uint32_t& maxSets, DescriptorPoolSizes ref_ptr Context::allocateDescriptorSet(DescriptorSetLayout* descriptorSetLayout) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context allocateDescriptorSet", COLOR_COMPILE) + for (auto itr = descriptorPools.rbegin(); itr != descriptorPools.rend(); ++itr) { auto dsi = (*itr)->allocateDescriptorSet(descriptorSetLayout); @@ -204,6 +208,8 @@ ref_ptr Context::allocateDescriptorSet(Descriptor void Context::reserve(const ResourceRequirements& requirements) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context reserve", COLOR_COMPILE) + if (requirements.maxSlot > resourceRequirements.maxSlot) { resourceRequirements.maxSlot = requirements.maxSlot; @@ -262,6 +268,8 @@ void Context::reserve(const ResourceRequirements& requirements) void Context::copy(ref_ptr data, ref_ptr dest) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context copy", COLOR_COMPILE) + if (!copyImageCmd) { copyImageCmd = CopyAndReleaseImage::create(stagingMemoryBufferPools); @@ -273,6 +281,8 @@ void Context::copy(ref_ptr data, ref_ptr dest) void Context::copy(ref_ptr data, ref_ptr dest, uint32_t numMipMapLevels) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context copy", COLOR_COMPILE) + if (!copyImageCmd) { copyImageCmd = CopyAndReleaseImage::create(stagingMemoryBufferPools); @@ -284,6 +294,8 @@ void Context::copy(ref_ptr data, ref_ptr dest, uint32_t numMipM void Context::copy(ref_ptr src, ref_ptr dest) { + CPU_INSTRUMENTATION_L2_NC(instrumentation, "Context copy", COLOR_COMPILE) + if (!copyBufferCmd) { copyBufferCmd = CopyAndReleaseBuffer::create(); @@ -295,6 +307,8 @@ void Context::copy(ref_ptr src, ref_ptr dest) bool Context::record() { + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Context record", COLOR_COMPILE) + if (commands.empty() && buildAccelerationStructureCommands.empty()) return false; //auto before_compile = std::chrono::steady_clock::now(); @@ -317,7 +331,7 @@ bool Context::record() vkBeginCommandBuffer(*commandBuffer, &beginInfo); { - COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer) + COMMAND_BUFFER_INSTRUMENTATION(instrumentation, *commandBuffer, "Context record", COLOR_COMPILE) // issue commands of interest { @@ -364,6 +378,8 @@ bool Context::record() void Context::waitForCompletion() { + CPU_INSTRUMENTATION_L1_NC(instrumentation, "Context waitForCompletion", COLOR_COMPILE) + if (!commandBuffer || !fence) { return; From 2b86036108e59d1f42b590d8015492d13910ed31 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 12:13:49 +0000 Subject: [PATCH 47/68] Fixed name --- src/vsg/app/RecordTraversal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 6c945093f8..e08106e944 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -166,7 +166,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_PAGER); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "PagedLOD", COLOR_PAGER); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; From 5629cb43d85024b4db058e45354639b1b35b5815 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 12:14:09 +0000 Subject: [PATCH 48/68] Changed to using more efficient VertexIndexDraw --- src/vsg/io/tile.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/vsg/io/tile.cpp b/src/vsg/io/tile.cpp index 32a90086df..78875d0f84 100644 --- a/src/vsg/io/tile.cpp +++ b/src/vsg/io/tile.cpp @@ -23,6 +23,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include @@ -476,13 +477,13 @@ vsg::ref_ptr tile::createECEFTile(const vsg::dbox& tile_extents, vsg: } // setup geometry - auto drawCommands = vsg::Commands::create(); - drawCommands->addChild(vsg::BindVertexBuffers::create(0, vsg::DataList{vertices, normals, texcoords, colors})); - drawCommands->addChild(vsg::BindIndexBuffer::create(indices)); - drawCommands->addChild(vsg::DrawIndexed::create(static_cast(indices->size()), 1, 0, 0, 0)); + auto vid = vsg::VertexIndexDraw::create(); + vid->assignArrays(vsg::DataList{vertices, normals, texcoords, colors}); + vid->assignIndices(indices); + vid->indexCount = indices->size(); + vid->instanceCount = 1; - // add drawCommands to transform - transform->addChild(drawCommands); + transform->addChild(vid); return scenegraph; } From ecf588415c5b90ea9c747a0f29787a05890a3f8b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 12:41:15 +0000 Subject: [PATCH 49/68] Removed hardwired enabling of GpuAnnotation. --- src/vsg/app/CommandGraph.cpp | 5 ----- src/vsg/app/WindowTraits.cpp | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 4b70283aae..3acdc19bc4 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -16,7 +16,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include -#include #include using namespace vsg; @@ -69,10 +68,6 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() if (!recordTraversal) { recordTraversal = RecordTraversal::create(maxSlot); - if (!recordTraversal->instrumentation && window && window->traits() && window->traits()->apiDumpLayer) - { - recordTraversal->instrumentation = GpuAnnotation::create(); - } } return recordTraversal; } diff --git a/src/vsg/app/WindowTraits.cpp b/src/vsg/app/WindowTraits.cpp index 011c197074..9103cf49db 100644 --- a/src/vsg/app/WindowTraits.cpp +++ b/src/vsg/app/WindowTraits.cpp @@ -105,7 +105,7 @@ void WindowTraits::validate() { instanceExtensionNames.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); } - if ((apiDumpLayer || debugUtils) && isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) + if (debugUtils && isExtensionSupported(VK_EXT_DEBUG_UTILS_EXTENSION_NAME)) { instanceExtensionNames.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } From bbf02065b63ca8b240850d84f25b59f33de6dfca Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 15:03:02 +0000 Subject: [PATCH 50/68] Introduce a uint_color helper struct to make it easier to manage colours that work with Tracy and with the VSG/Vulkan. --- include/vsg/utils/Instrumentation.h | 57 ++++++++++++++++++----------- src/vsg/app/Viewer.cpp | 2 - src/vsg/utils/GpuAnnotation.cpp | 8 ++-- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 0d5d526d99..3e3b185669 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -23,14 +23,29 @@ namespace vsg class CommandBuffer; class FrameStamp; - #define COLOR_VIEWER ubvec4(128, 249, 240, 255) - #define COLOR_UPDATE ubvec4(0, 255, 0, 255) - #define COLOR_RECORD ubvec4(0, 255, 255, 255) - #define COLOR_GPU ubvec4(255, 127, 0, 255) - #define COLOR_COMPILE ubvec4(255, 249, 64, 255) - #define COLOR_READ ubvec4(128, 255, 0, 255) - #define COLOR_WRITE ubvec4(255, 128, 0, 255) - #define COLOR_PAGER ubvec4(240, 255, 64, 255) + /// uint_color struct used to provide a {r, g, b, a} interface a colors assigned as uint32_t + struct uint_color + { +#if 0 + // RGBA order standard with VSG/Vulkan + uint8_t r = 255, g = 255, b = 255, a = 255; + constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : r(red), g(green), b(blue), a(alpha) {} +#else + // BGRA order required to map to Tracy's uint32_t color value + uint8_t b = 255, g = 255, r = 255, a = 255; + constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : b(blue), g(green), r(red), a(alpha) {} +#endif + }; + + // standard colours specified in {r, g, b, a} ordering + #define COLOR_VIEWER uint_color(128, 249, 240, 255) + #define COLOR_UPDATE uint_color(0, 255, 0, 255) + #define COLOR_RECORD uint_color(0, 255, 255, 255) + #define COLOR_GPU uint_color(255, 127, 0, 255) + #define COLOR_COMPILE uint_color(255, 249, 64, 255) + #define COLOR_READ uint_color(128, 255, 0, 255) + #define COLOR_WRITE uint_color(255, 128, 0, 255) + #define COLOR_PAGER uint_color(240, 255, 64, 255) /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. @@ -40,7 +55,7 @@ namespace vsg const char* function; const char* file; uint32_t line; - ubvec4 color; + uint_color color; uint32_t level; }; @@ -147,13 +162,13 @@ namespace vsg #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 -# define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, uint_color(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, uint_color(255, 255, 255, 255)) # define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) # define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) -# define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, uint_color(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) # define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, color) @@ -176,13 +191,13 @@ namespace vsg #endif #if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 -# define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, uint_color(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, uint_color(255, 255, 255, 255)) # define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color) # define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) -# define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, uint_color(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) # define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, color) #else @@ -198,13 +213,13 @@ namespace vsg #endif #if VSG_MAX_INSTRUMENTATION_LEVEL >= 3 -# define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, ubvec4(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, ubvec4(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, uint_color(255, 255, 255, 255)) +# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, uint_color(255, 255, 255, 255)) # define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color) # define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) -# define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, ubvec4(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, ubvec4(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) +# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, uint_color(255, 255, 255, 255)) # define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) # define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, color) #else diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index d82eaab311..437d55ba5a 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -610,8 +610,6 @@ void Viewer::addRecordAndSubmitTaskAndPresentation(CommandGraphs commandGraphs) void Viewer::setupThreading() { - CPU_INSTRUMENTATION_L1_NC(instrumentation, "Viewer setupThreading", COLOR_VIEWER); - stopThreading(); // check how many valid tasks there are. diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index b8b57b89ad..b3efecf636 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -44,10 +44,10 @@ void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffe markerInfo.pLabelName = sl->name; else markerInfo.pLabelName = sl->function; - markerInfo.color[0] = static_cast(sl->color[0]) / 255.0; - markerInfo.color[1] = static_cast(sl->color[1]) / 255.0; - markerInfo.color[2] = static_cast(sl->color[2]) / 255.0; - markerInfo.color[3] = static_cast(sl->color[3]) / 255.0; + markerInfo.color[0] = static_cast(sl->color.r) / 255.0; + markerInfo.color[1] = static_cast(sl->color.g) / 255.0; + markerInfo.color[2] = static_cast(sl->color.b) / 255.0; + markerInfo.color[3] = static_cast(sl->color.a) / 255.0; extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); } From ac7e1d58883f6ea859baf9c16c1fdccb562c53e0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 15:17:08 +0000 Subject: [PATCH 51/68] Ran clang-format --- include/vsg/utils/Instrumentation.h | 22 +++++++------- include/vsg/utils/TracyInstrumentation.h | 37 ++++++++++++------------ src/vsg/app/CompileTraversal.cpp | 20 ++++++------- src/vsg/app/Viewer.cpp | 3 -- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 3e3b185669..c46723f339 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -33,19 +33,20 @@ namespace vsg #else // BGRA order required to map to Tracy's uint32_t color value uint8_t b = 255, g = 255, r = 255, a = 255; - constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : b(blue), g(green), r(red), a(alpha) {} + constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : + b(blue), g(green), r(red), a(alpha) {} #endif }; - // standard colours specified in {r, g, b, a} ordering - #define COLOR_VIEWER uint_color(128, 249, 240, 255) - #define COLOR_UPDATE uint_color(0, 255, 0, 255) - #define COLOR_RECORD uint_color(0, 255, 255, 255) - #define COLOR_GPU uint_color(255, 127, 0, 255) - #define COLOR_COMPILE uint_color(255, 249, 64, 255) - #define COLOR_READ uint_color(128, 255, 0, 255) - #define COLOR_WRITE uint_color(255, 128, 0, 255) - #define COLOR_PAGER uint_color(240, 255, 64, 255) +// standard colours specified in {r, g, b, a} ordering +#define COLOR_VIEWER uint_color(128, 249, 240, 255) +#define COLOR_UPDATE uint_color(0, 255, 0, 255) +#define COLOR_RECORD uint_color(0, 255, 255, 255) +#define COLOR_GPU uint_color(255, 127, 0, 255) +#define COLOR_COMPILE uint_color(255, 249, 64, 255) +#define COLOR_READ uint_color(128, 255, 0, 255) +#define COLOR_WRITE uint_color(255, 128, 0, 255) +#define COLOR_PAGER uint_color(240, 255, 64, 255) /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. @@ -81,7 +82,6 @@ namespace vsg virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; - protected: virtual ~Instrumentation(); }; diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index a422411b84..e81953fcd0 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -57,7 +57,6 @@ namespace vsg { ctx = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); } - } return ctx; } @@ -115,21 +114,21 @@ namespace vsg void enter(const SourceLocation* slcloc, uint64_t& reference) const override { -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND if (!GetProfiler().IsConnected() || (slcloc->level > settings->cpu_instumentation_level)) -#else +# else if (slcloc->level > settings->cpu_instumentation_level) -#endif +# endif { reference = 0; return; } -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND reference = GetProfiler().ConnectionId(); -#else +# else reference = 1; -#endif +# endif TracyQueuePrepare(QueueType::ZoneBegin); MemWrite(&item->zoneBegin.time, Profiler::GetTime()); @@ -139,11 +138,11 @@ namespace vsg void leave(const SourceLocation*, uint64_t& reference) const override { -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; -#else +# else if (reference == 0) return; -#endif +# endif TracyQueuePrepare(QueueType::ZoneEnd); MemWrite(&item->zoneEnd.time, Profiler::GetTime()); @@ -172,21 +171,21 @@ namespace vsg void enter(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& cmdbuf) const override { -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND if (!ctx || !GetProfiler().IsConnected() || (slcloc->level > settings->gpu_instumentation_level)) -#else +# else if (!ctx || slcloc->level > settings->gpu_instumentation_level) -#endif +# endif { reference = 0; return; } -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND reference = GetProfiler().ConnectionId(); -#else +# else reference = 1; -#endif +# endif const auto queryId = ctx->NextQueryId(); CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); @@ -203,11 +202,11 @@ namespace vsg void leave(const SourceLocation*, uint64_t& reference, CommandBuffer& cmdbuf) const override { -#ifdef TRACY_ON_DEMAND +# ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; -#else +# else if (reference == 0) return; -#endif +# endif const auto queryId = ctx->NextQueryId(); CONTEXT_VK_FUNCTION_WRAPPER(vkCmdWriteTimestamp(cmdbuf, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, ctx->GetQueryPool(), queryId)); diff --git a/src/vsg/app/CompileTraversal.cpp b/src/vsg/app/CompileTraversal.cpp index 13c11ca66f..042e0f8ef7 100644 --- a/src/vsg/app/CompileTraversal.cpp +++ b/src/vsg/app/CompileTraversal.cpp @@ -225,14 +225,14 @@ void CompileTraversal::assignInstrumentation(ref_ptr in_instrum void CompileTraversal::apply(Object& object) { - CPU_INSTRUMENTATION_L2_NC(instrumentation,"CompileTraversal Object", COLOR_COMPILE); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "CompileTraversal Object", COLOR_COMPILE); object.traverse(*this); } void CompileTraversal::apply(Compilable& node) { - CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Compilable", COLOR_COMPILE); + CPU_INSTRUMENTATION_L3_NC(instrumentation, "CompileTraversal Compilable", COLOR_COMPILE); for (auto& context : contexts) { @@ -242,7 +242,7 @@ void CompileTraversal::apply(Compilable& node) void CompileTraversal::apply(Commands& commands) { - CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Commands", COLOR_COMPILE); + CPU_INSTRUMENTATION_L3_NC(instrumentation, "CompileTraversal Commands", COLOR_COMPILE); for (auto& context : contexts) { @@ -252,7 +252,7 @@ void CompileTraversal::apply(Commands& commands) void CompileTraversal::apply(StateGroup& stateGroup) { - CPU_INSTRUMENTATION_L2_NC(instrumentation,"CompileTraversal StateGroup", COLOR_COMPILE); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "CompileTraversal StateGroup", COLOR_COMPILE); for (auto& context : contexts) { @@ -263,7 +263,7 @@ void CompileTraversal::apply(StateGroup& stateGroup) void CompileTraversal::apply(Geometry& geometry) { - CPU_INSTRUMENTATION_L3_NC(instrumentation,"CompileTraversal Geometry", COLOR_COMPILE); + CPU_INSTRUMENTATION_L3_NC(instrumentation, "CompileTraversal Geometry", COLOR_COMPILE); for (auto& context : contexts) { @@ -274,7 +274,7 @@ void CompileTraversal::apply(Geometry& geometry) void CompileTraversal::apply(CommandGraph& commandGraph) { - CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal CommandGraph", COLOR_COMPILE); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CompileTraversal CommandGraph", COLOR_COMPILE); for (auto& context : contexts) { @@ -289,7 +289,7 @@ void CompileTraversal::apply(CommandGraph& commandGraph) void CompileTraversal::apply(RenderGraph& renderGraph) { - CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal RenderGraph", COLOR_COMPILE); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CompileTraversal RenderGraph", COLOR_COMPILE); for (auto& context : contexts) { @@ -323,7 +323,7 @@ void CompileTraversal::apply(RenderGraph& renderGraph) void CompileTraversal::apply(View& view) { - CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal View", COLOR_COMPILE); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CompileTraversal View", COLOR_COMPILE); for (auto& context : contexts) { @@ -364,7 +364,7 @@ void CompileTraversal::apply(View& view) bool CompileTraversal::record() { - CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal record", COLOR_COMPILE); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CompileTraversal record", COLOR_COMPILE); bool recorded = false; for (auto& context : contexts) @@ -376,7 +376,7 @@ bool CompileTraversal::record() void CompileTraversal::waitForCompletion() { - CPU_INSTRUMENTATION_L1_NC(instrumentation,"CompileTraversal waitForCompletion", COLOR_COMPILE); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CompileTraversal waitForCompletion", COLOR_COMPILE); for (auto& context : contexts) { diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 437d55ba5a..125dc9beb0 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -690,7 +690,6 @@ void Viewer::setupThreading() ref_ptr sharedData = SharedData::create(task, _frameBlock, _submissionCompleted, numThreads); auto run_primary = [](ref_ptr data, ref_ptr commandGraph, const std::string& threadName) { - auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); if (local_instrumentation) local_instrumentation->setThreadName(threadName); @@ -722,7 +721,6 @@ void Viewer::setupThreading() }; auto run_secondary = [](ref_ptr data, ref_ptr commandGraph, const std::string& threadName) { - auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); if (local_instrumentation) local_instrumentation->setThreadName(threadName); @@ -742,7 +740,6 @@ void Viewer::setupThreading() }; auto run_transfer = [](ref_ptr data, ref_ptr transferTask, const std::string& threadName) { - auto local_instrumentation = shareOrDuplicateForThreadSafety(data->task->instrumentation); if (local_instrumentation) local_instrumentation->setThreadName(threadName); From e9094ed5d58af5b466fb1f0d5de6d6e209345800 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 15:34:09 +0000 Subject: [PATCH 52/68] Added GpuAnnotation::labelType to hint which member of SourceLocation to use as the VK_debug_utils label. --- include/vsg/utils/GpuAnnotation.h | 8 ++++++++ src/vsg/utils/GpuAnnotation.cpp | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/vsg/utils/GpuAnnotation.h b/include/vsg/utils/GpuAnnotation.h index f09b170ef0..d0d0caaeb3 100644 --- a/include/vsg/utils/GpuAnnotation.h +++ b/include/vsg/utils/GpuAnnotation.h @@ -24,6 +24,14 @@ namespace vsg public: GpuAnnotation(); + enum LabelType + { + SourceLocation_name, + SourceLocation_function, + }; + + LabelType labelType = SourceLocation_name; + void enterCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; void leaveCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index b3efecf636..8e2006e42d 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -40,10 +40,11 @@ void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffe VkDebugUtilsLabelEXT markerInfo = {}; markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - if (sl->name) + if (sl->name && labelType == SourceLocation_name) markerInfo.pLabelName = sl->name; else markerInfo.pLabelName = sl->function; + markerInfo.color[0] = static_cast(sl->color.r) / 255.0; markerInfo.color[1] = static_cast(sl->color.g) / 255.0; markerInfo.color[2] = static_cast(sl->color.b) / 255.0; From 7b2d7d55d37f96c545ec0509433cef0ed3fba72f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 15:35:37 +0000 Subject: [PATCH 53/68] Moved the #define COLOR to sit before the rest of the #define --- include/vsg/utils/Instrumentation.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index c46723f339..e94ac28924 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -20,6 +20,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI namespace vsg { + // forward declare class CommandBuffer; class FrameStamp; @@ -38,16 +39,6 @@ namespace vsg #endif }; -// standard colours specified in {r, g, b, a} ordering -#define COLOR_VIEWER uint_color(128, 249, 240, 255) -#define COLOR_UPDATE uint_color(0, 255, 0, 255) -#define COLOR_RECORD uint_color(0, 255, 255, 255) -#define COLOR_GPU uint_color(255, 127, 0, 255) -#define COLOR_COMPILE uint_color(255, 249, 64, 255) -#define COLOR_READ uint_color(128, 255, 0, 255) -#define COLOR_WRITE uint_color(255, 128, 0, 255) -#define COLOR_PAGER uint_color(240, 255, 64, 255) - /// SourceLocation structs mark the location in a source file when instrumentation is placed. /// Memory layout was chosen to be compatible to Tracy's SourceLocationData object. struct SourceLocation @@ -142,6 +133,16 @@ namespace vsg } }; +// standard colours specified in {r, g, b, a} ordering +#define COLOR_VIEWER uint_color(128, 249, 240, 255) +#define COLOR_UPDATE uint_color(0, 255, 0, 255) +#define COLOR_RECORD uint_color(0, 255, 255, 255) +#define COLOR_GPU uint_color(255, 127, 0, 255) +#define COLOR_COMPILE uint_color(255, 249, 64, 255) +#define COLOR_READ uint_color(128, 255, 0, 255) +#define COLOR_WRITE uint_color(255, 128, 0, 255) +#define COLOR_PAGER uint_color(240, 255, 64, 255) + #if defined(__clang__) || defined(__GNUC__) # define VsgFunctionName __PRETTY_FUNCTION__ #elif defined(_MSC_VER) From c733719edfe5d42a6869da60438221875df36371 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 15:45:24 +0000 Subject: [PATCH 54/68] Added instrumentation of TileDatabase to RecordTraversal. --- include/vsg/app/RecordTraversal.h | 2 ++ src/vsg/app/RecordTraversal.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index ab0181fb8d..f2c74eac3a 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -35,6 +35,7 @@ namespace vsg class DepthSorted; class Transform; class MatrixTransform; + class TileDatabase; class VertexDraw; class VertexIndexDraw; class Geometry; @@ -106,6 +107,7 @@ namespace vsg void apply(const QuadGroup& quadGroup); void apply(const LOD& lod); void apply(const PagedLOD& pagedLOD); + void apply(const TileDatabase& tileDatabase); void apply(const CullGroup& cullGroup); void apply(const CullNode& cullNode); void apply(const DepthSorted& depthSorted); diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index e08106e944..65d2ac4c3c 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -33,6 +33,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include @@ -244,6 +245,13 @@ void RecordTraversal::apply(const PagedLOD& plod) } } +void RecordTraversal::apply(const TileDatabase& tileDatabase) +{ + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "TileDatabase", COLOR_RECORD); + + tileDatabase.traverse(*this); +} + void RecordTraversal::apply(const CullGroup& cullGroup) { GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD); From ea899d35169f1c522ee7fe72adb31c4261c46311 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Dec 2023 16:00:07 +0000 Subject: [PATCH 55/68] Refined colours --- include/vsg/utils/Instrumentation.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index e94ac28924..7816275e3e 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -134,14 +134,14 @@ namespace vsg }; // standard colours specified in {r, g, b, a} ordering -#define COLOR_VIEWER uint_color(128, 249, 240, 255) +#define COLOR_VIEWER uint_color(127, 240, 240, 255) #define COLOR_UPDATE uint_color(0, 255, 0, 255) -#define COLOR_RECORD uint_color(0, 255, 255, 255) +#define COLOR_RECORD uint_color(128, 255, 0, 255) #define COLOR_GPU uint_color(255, 127, 0, 255) #define COLOR_COMPILE uint_color(255, 249, 64, 255) -#define COLOR_READ uint_color(128, 255, 0, 255) -#define COLOR_WRITE uint_color(255, 128, 0, 255) #define COLOR_PAGER uint_color(240, 255, 64, 255) +#define COLOR_READ uint_color(0, 255, 128, 255) +#define COLOR_WRITE uint_color(0, 128, 255, 255) #if defined(__clang__) || defined(__GNUC__) # define VsgFunctionName __PRETTY_FUNCTION__ From ced4238eaec8abb88db537a89c11f5ca510d08ad Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Dec 2023 09:52:23 +0000 Subject: [PATCH 56/68] Added more colour differentiation --- include/vsg/utils/Instrumentation.h | 5 +++- src/vsg/app/CommandGraph.cpp | 2 +- src/vsg/app/RecordTraversal.cpp | 36 ++++++++++++++--------------- src/vsg/app/RenderGraph.cpp | 2 ++ 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 7816275e3e..d5cb0203c4 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -136,8 +136,11 @@ namespace vsg // standard colours specified in {r, g, b, a} ordering #define COLOR_VIEWER uint_color(127, 240, 240, 255) #define COLOR_UPDATE uint_color(0, 255, 0, 255) -#define COLOR_RECORD uint_color(128, 255, 0, 255) #define COLOR_GPU uint_color(255, 127, 0, 255) +#define COLOR_RECORD_L1 uint_color(140, 247, 0, 255) +#define COLOR_RECORD_L2 uint_color(176, 176, 0, 255) +#define COLOR_RECORD_L3 COLOR_GPU +#define COLOR_RECORD COLOR_RECORD_L1 #define COLOR_COMPILE uint_color(255, 249, 64, 255) #define COLOR_PAGER uint_color(240, 255, 64, 255) #define COLOR_READ uint_color(0, 255, 128, 255) diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index 3acdc19bc4..cf6df713fa 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -74,7 +74,7 @@ ref_ptr CommandGraph::getOrCreateRecordTraversal() void CommandGraph::record(ref_ptr recordedCommandBuffers, ref_ptr frameStamp, ref_ptr databasePager) { - CPU_INSTRUMENTATION_L1_NC(instrumentation, "CommandGraph record", COLOR_RECORD); + CPU_INSTRUMENTATION_L1_NC(instrumentation, "CommandGraph record", COLOR_RECORD_L1); if (window && !window->visible()) { diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 65d2ac4c3c..a4d66bca5b 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -100,7 +100,7 @@ void RecordTraversal::setDatabasePager(DatabasePager* dp) void RecordTraversal::clearBins() { - CPU_INSTRUMENTATION_L2_NC(instrumentation, "RecordTraversal clearBins", COLOR_RECORD); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "RecordTraversal clearBins", COLOR_RECORD_L2); for (auto& bin : _bins) { @@ -110,7 +110,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD_L2); //debug("Visiting Object"); object.traverse(*this); @@ -118,7 +118,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Group", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Group", COLOR_RECORD_L2); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -130,7 +130,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "QuadGroup", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "QuadGroup", COLOR_RECORD_L2); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -142,7 +142,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "LOD", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "LOD", COLOR_RECORD_L2); const auto& sphere = lod.bound; @@ -247,14 +247,14 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const TileDatabase& tileDatabase) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "TileDatabase", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "TileDatabase", COLOR_RECORD_L2); tileDatabase.traverse(*this); } void RecordTraversal::apply(const CullGroup& cullGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD_L2); if (_state->intersect(cullGroup.bound)) { @@ -265,7 +265,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_RECORD_L2); if (_state->intersect(cullNode.bound)) { @@ -276,7 +276,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Switch", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Switch", COLOR_RECORD_L2); for (auto& child : sw.children) { @@ -289,7 +289,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - CPU_INSTRUMENTATION_L2_NC(instrumentation, "DepthSorted", COLOR_RECORD); + CPU_INSTRUMENTATION_L2_NC(instrumentation, "DepthSorted", COLOR_RECORD_L2); if (_state->intersect(depthSorted.bound)) { @@ -369,7 +369,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "StateGroup", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "StateGroup", COLOR_RECORD_L2); //debug("Visiting StateGroup"); @@ -390,7 +390,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Transform", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Transform", COLOR_RECORD_L2); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -412,7 +412,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "MatrixTransform", COLOR_RECORD); + GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "MatrixTransform", COLOR_RECORD_L2); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -435,7 +435,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Commands", COLOR_RECORD); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Commands", COLOR_GPU); _state->record(); for (auto& command : commands.children) @@ -446,7 +446,7 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Command", COLOR_RECORD); + GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Command", COLOR_GPU); //debug("Visiting Command"); _state->record(); @@ -455,7 +455,7 @@ void RecordTraversal::apply(const Command& command) void RecordTraversal::apply(const Bin& object) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Bin", COLOR_RECORD); + GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "Bin", COLOR_RECORD_L1); //debug("Visiting Bin"); object.traverse(*this); @@ -463,7 +463,7 @@ void RecordTraversal::apply(const Bin& object) void RecordTraversal::apply(const View& view) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "View", COLOR_RECORD); + GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "View", COLOR_RECORD_L1); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -552,7 +552,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "RecordTraversal CommandGraph", COLOR_RECORD); + GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "RecordTraversal CommandGraph", COLOR_RECORD_L1); if (recordedCommandBuffers) { diff --git a/src/vsg/app/RenderGraph.cpp b/src/vsg/app/RenderGraph.cpp index 43a05b6e21..7166518ed8 100644 --- a/src/vsg/app/RenderGraph.cpp +++ b/src/vsg/app/RenderGraph.cpp @@ -102,6 +102,8 @@ VkExtent2D RenderGraph::getExtent() const void RenderGraph::accept(RecordTraversal& recordTraversal) const { + GPU_INSTRUMENTATION_L1_NC(recordTraversal.instrumentation, *recordTraversal.getCommandBuffer(), "RenderGraph", COLOR_RECORD_L1); + auto extent = getExtent(); if (previous_extent.width == invalid_dimension || previous_extent.height == invalid_dimension || !windowResizeHandler) { From 3859051d1a5021ea0234b2734a011166dcc321db Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Dec 2023 09:53:00 +0000 Subject: [PATCH 57/68] Added instrumentation to ViewDependentState --- src/vsg/state/ViewDependentState.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/vsg/state/ViewDependentState.cpp b/src/vsg/state/ViewDependentState.cpp index 7d1e280075..7a83a32624 100644 --- a/src/vsg/state/ViewDependentState.cpp +++ b/src/vsg/state/ViewDependentState.cpp @@ -375,6 +375,8 @@ void ViewDependentState::update(ResourceRequirements& requirements) void ViewDependentState::compile(Context& context) { + CPU_INSTRUMENTATION_L1_NC(context.instrumentation, "ViewDependentState compile", COLOR_COMPILE); + descriptorSet->compile(context); if ((view->features & RECORD_SHADOW_MAPS) != 0 && preRenderCommandGraph && !preRenderCommandGraph->device) @@ -484,6 +486,9 @@ void ViewDependentState::clear() void ViewDependentState::traverse(RecordTraversal& rt) const { + //GPU_INSTRUMENTATION_L1_NC(rt.instrumentation, *rt.getCommandBuffer(), "ViewDependentState", COLOR_RECORD_L1); + CPU_INSTRUMENTATION_L1_NC(rt.instrumentation, "ViewDependentState", COLOR_RECORD_L1); + if ((view->features & RECORD_SHADOW_MAPS) == 0) return; // useful reference : https://learn.microsoft.com/en-us/windows/win32/dxtecharts/cascaded-shadow-maps @@ -702,6 +707,11 @@ void ViewDependentState::traverse(RecordTraversal& rt) const if (requiresPerRenderShadowMaps && preRenderCommandGraph) { + if (rt.instrumentation && !preRenderCommandGraph->instrumentation) + { + preRenderCommandGraph->instrumentation = shareOrDuplicateForThreadSafety(rt.instrumentation); + } + // info("ViewDependentState::traverse(RecordTraversal&) doing pre render command graph. shadowMapIndex = ", shadowMapIndex); preRenderCommandGraph->accept(rt); } From 3708b72eefc00b1b149958a5f0c36e89126b142f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Dec 2023 14:38:29 +0000 Subject: [PATCH 58/68] Resutrctured the TracyVkCollect call so it's done once per frame as the on the first command buffer record of a frame. --- include/vsg/utils/TracyInstrumentation.h | 31 +++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index e81953fcd0..20db2f1073 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -40,7 +40,7 @@ namespace vsg std::scoped_lock lock(mutex); ref_ptr device(commandBuffer.getDevice()); - auto& ctx = ctxMap[device]; + auto& [ctx, requiresCollection] = ctxMap[device]; if (!ctx) { auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); @@ -57,21 +57,39 @@ namespace vsg { ctx = TracyVkContext(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk()); } + requiresCollection = false; } + + if (ctx && requiresCollection) + { + TracyVkCollect(ctx, commandBuffer.vk()); + requiresCollection = false; + } + return ctx; } + void frameComplete() + { + std::scoped_lock lock(mutex); + for (auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) + { + itr->second.second = true; + } + } + + mutable std::mutex mutex; + mutable std::map, std::pair> ctxMap; + protected: ~TracyContexts() { for (auto itr = ctxMap.begin(); itr != ctxMap.end(); ++itr) { - TracyVkDestroy(itr->second); + TracyVkDestroy(itr->second.first); } } - mutable std::mutex mutex; - mutable std::map, VkCtx*> ctxMap; }; VSG_type_name(vsg::TracyContexts); @@ -94,6 +112,7 @@ namespace vsg ref_ptr settings; ref_ptr contexts; mutable VkCtx* ctx = nullptr; + bool requiresCollection = false; ref_ptr shareOrDuplicateForThreadSafety() override { @@ -109,6 +128,8 @@ namespace vsg void leaveFrame(const SourceLocation*, uint64_t&, FrameStamp&) const override { + contexts->frameComplete(); + FrameMark; } @@ -153,8 +174,6 @@ namespace vsg { if (ctx = contexts->getOrCreateContext(commandBuffer)) { - TracyVkCollect(ctx, commandBuffer.vk()); - enter(slcloc, reference, commandBuffer); } } From 3644555e90f0debc8375113af3317cd1c42c08e6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2024 14:27:34 +0000 Subject: [PATCH 59/68] Updated version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 126e2afefc..30f9de5878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.7) project(vsg - VERSION 1.1.0 + VERSION 1.1.1 DESCRIPTION "VulkanSceneGraph library" LANGUAGES CXX ) From 381ac20bbd36f6f4946399f321668fc1e81c3588 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2024 16:27:42 +0000 Subject: [PATCH 60/68] Added const Object* to Instrumentation::enter()/leave() methods --- include/vsg/utils/GpuAnnotation.h | 5 +- include/vsg/utils/Instrumentation.h | 155 +++++++++++++++++------ include/vsg/utils/TracyInstrumentation.h | 12 +- src/vsg/app/RecordTraversal.cpp | 56 ++++---- src/vsg/utils/GpuAnnotation.cpp | 12 +- 5 files changed, 157 insertions(+), 83 deletions(-) diff --git a/include/vsg/utils/GpuAnnotation.h b/include/vsg/utils/GpuAnnotation.h index d0d0caaeb3..8c4d08c486 100644 --- a/include/vsg/utils/GpuAnnotation.h +++ b/include/vsg/utils/GpuAnnotation.h @@ -28,6 +28,7 @@ namespace vsg { SourceLocation_name, SourceLocation_function, + Object_className, }; LabelType labelType = SourceLocation_name; @@ -35,8 +36,8 @@ namespace vsg void enterCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; void leaveCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; - void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; - void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const override; + void enter(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer, const Object* object) const override; + void leave(const vsg::SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer, const Object* object) const override; protected: virtual ~GpuAnnotation(); diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index d5cb0203c4..0cf48bb088 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -64,14 +64,14 @@ namespace vsg virtual void enterFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; virtual void leaveFrame(const SourceLocation* /*sl*/, uint64_t& /*reference*/, FrameStamp& /*frameStamp*/) const {}; - virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/) const {}; - virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/) const {}; + virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, const Object* /*object*/ = nullptr) const {}; + virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, const Object* /*object*/ = nullptr) const {}; virtual void enterCommandBuffer(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; virtual void leaveCommandBuffer(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; - virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; - virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/) const {}; + virtual void enter(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/, const Object* /*object*/ = nullptr) const {}; + virtual void leave(const SourceLocation* /*sl*/, uint64_t& /*reference*/, CommandBuffer& /*commandBuffer*/, const Object* /*object*/ = nullptr) const {}; protected: virtual ~Instrumentation(); @@ -86,14 +86,16 @@ namespace vsg const Instrumentation* instr; const SourceLocation* sl; uint64_t reference; - inline CpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl) : - instr(in_instr), sl(in_sl) + const Object* object; + + inline CpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl, const Object* in_object = nullptr) : + instr(in_instr), sl(in_sl), object(in_object) { - if (instr) instr->enter(sl, reference); + if (instr) instr->enter(sl, reference, object); } inline ~CpuInstrumentation() { - if (instr) instr->leave(sl, reference); + if (instr) instr->leave(sl, reference, object); } }; @@ -103,15 +105,16 @@ namespace vsg const SourceLocation* sl; uint64_t reference; CommandBuffer& commandBuffer; + const Object* object; - inline GpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer) : - instr(in_instr), sl(in_sl), commandBuffer(in_commandBuffer) + inline GpuInstrumentation(const Instrumentation* in_instr, const SourceLocation* in_sl, CommandBuffer& in_commandBuffer, const Object* in_object = nullptr) : + instr(in_instr), sl(in_sl), commandBuffer(in_commandBuffer), object(in_object) { - if (instr) instr->enter(sl, reference, commandBuffer); + if (instr) instr->enter(sl, reference, commandBuffer, object); } inline ~GpuInstrumentation() { - if (instr) instr->leave(sl, reference, commandBuffer); + if (instr) instr->leave(sl, reference, commandBuffer, object); } }; @@ -152,13 +155,13 @@ namespace vsg # define VsgFunctionName __FUNCSIG__ #endif -#define __CPU_INSTRUMENTATION(level, instrumentation, name, color) \ +#define __CPU_INSTRUMENTATION(level, instrumentation, name, color, object) \ static constexpr SourceLocation s_cpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_cpu_source_location_##__LINE__)); + CpuInstrumentation __cpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_cpu_source_location_##__LINE__), object); -#define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color) \ +#define __GPU_INSTRUMENTATION(level, instrumentation, cg, name, color, object) \ static constexpr SourceLocation s_gpu_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ - GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_gpu_source_location_##__LINE__), cg); + GpuInstrumentation __gpu_scoped_instrumentation_##__LINE__(instrumentation, &(s_gpu_source_location_##__LINE__), cg, object); #define __COMMAND_BUFFER_INSTRUMENTATION(level, instrumentation, cg, name, color) \ static constexpr SourceLocation s_cg_source_location_##__LINE__{name, VsgFunctionName, __FILE__, __LINE__, color, level}; \ @@ -166,15 +169,25 @@ namespace vsg #if VSG_MAX_INSTRUMENTATION_LEVEL >= 1 -# define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color) -# define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color) +# define CPU_INSTRUMENTATION_L1(instrumentation) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L1_N(instrumentation, name) __CPU_INSTRUMENTATION(1, instrumentation, name, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L1_C(instrumentation, color) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color, nullptr) +# define CPU_INSTRUMENTATION_L1_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(1, instrumentation, name, color, nullptr) + +# define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color, nullptr) +# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, color, nullptr) -# define GPU_INSTRUMENTATION_L1(instrumentation, cg) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L1_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, color) +# define CPU_INSTRUMENTATION_L1_O(instrumentation, object) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L1_NO(instrumentation, name, object) __CPU_INSTRUMENTATION(1, instrumentation, name, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L1_CO(instrumentation, color, object) __CPU_INSTRUMENTATION(1, instrumentation, nullptr, color, object) +# define CPU_INSTRUMENTATION_L1_NCO(instrumentation, name, color, object) __CPU_INSTRUMENTATION(1, instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L1_O(instrumentation, cg, object) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L1_NO(instrumentation, cg, name, object) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L1_CO(instrumentation, cg, color, object) __GPU_INSTRUMENTATION(1, instrumentation, cg, nullptr, color, object) +# define GPU_INSTRUMENTATION_L1_NCO(instrumentation, cg, name, color, object) __GPU_INSTRUMENTATION(1, instrumentation, cg, name, color, object) # define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg, name, color) __COMMAND_BUFFER_INSTRUMENTATION(1, instrumentation, cg, name, color) @@ -190,21 +203,44 @@ namespace vsg # define GPU_INSTRUMENTATION_L1_C(instrumentation, cg, color) # define GPU_INSTRUMENTATION_L1_NC(instrumentation, cg, name, color) +# define CPU_INSTRUMENTATION_L1_O(instrumentation, object) +# define CPU_INSTRUMENTATION_L1_NO(instrumentation, name, object) +# define CPU_INSTRUMENTATION_L1_CO(instrumentation, color, object) +# define CPU_INSTRUMENTATION_L1_NCO(instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L1_O(instrumentation, cg, object) +# define GPU_INSTRUMENTATION_L1_NO(instrumentation, cg, name, object) +# define GPU_INSTRUMENTATION_L1_CO(instrumentation, cg, color, object) +# define GPU_INSTRUMENTATION_L1_NCO(instrumentation, cg, name, color, object) + # define COMMAND_BUFFER_INSTRUMENTATION(instrumentation, cg, name, color) #endif #if VSG_MAX_INSTRUMENTATION_LEVEL >= 2 -# define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color) -# define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color) - -# define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, color) + +# define CPU_INSTRUMENTATION_L2(instrumentation) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L2_N(instrumentation, name) __CPU_INSTRUMENTATION(2, instrumentation, name, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L2_C(instrumentation, color) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color, nullptr) +# define CPU_INSTRUMENTATION_L2_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(2, instrumentation, name, color, nullptr) + +# define GPU_INSTRUMENTATION_L2(instrumentation, cg) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color, nullptr) +# define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, color, nullptr) + +# define CPU_INSTRUMENTATION_L2_O(instrumentation, object) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L2_NO(instrumentation, name, object) __CPU_INSTRUMENTATION(2, instrumentation, name, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L2_CO(instrumentation, color, object) __CPU_INSTRUMENTATION(2, instrumentation, nullptr, color, object) +# define CPU_INSTRUMENTATION_L2_NCO(instrumentation, name, color, object) __CPU_INSTRUMENTATION(2, instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L2_O(instrumentation, cg, object) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L2_NO(instrumentation, cg, name, object) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L2_CO(instrumentation, cg, color, object) __GPU_INSTRUMENTATION(2, instrumentation, cg, nullptr, color, object) +# define GPU_INSTRUMENTATION_L2_NCO(instrumentation, cg, name, color, object) __GPU_INSTRUMENTATION(2, instrumentation, cg, name, color, object) + #else + # define CPU_INSTRUMENTATION_L2(instrumentation) # define CPU_INSTRUMENTATION_L2_N(instrumentation, name) # define CPU_INSTRUMENTATION_L2_C(instrumentation, color) @@ -214,19 +250,43 @@ namespace vsg # define GPU_INSTRUMENTATION_L2_N(instrumentation, cg, name) # define GPU_INSTRUMENTATION_L2_C(instrumentation, cg, color) # define GPU_INSTRUMENTATION_L2_NC(instrumentation, cg, name, color) + +# define CPU_INSTRUMENTATION_L2_O(instrumentation, object) +# define CPU_INSTRUMENTATION_L2_NO(instrumentation, name, object) +# define CPU_INSTRUMENTATION_L2_CO(instrumentation, color, object) +# define CPU_INSTRUMENTATION_L2_NCO(instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L2_O(instrumentation, cg, object) +# define GPU_INSTRUMENTATION_L2_NO(instrumentation, cg, name, object) +# define GPU_INSTRUMENTATION_L2_CO(instrumentation, cg, color, object) +# define GPU_INSTRUMENTATION_L2_NCO(instrumentation, cg, name, color, object) + #endif #if VSG_MAX_INSTRUMENTATION_LEVEL >= 3 -# define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, uint_color(255, 255, 255, 255)) -# define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color) -# define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color) - -# define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, uint_color(255, 255, 255, 255)) -# define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color) -# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, color) + +# define CPU_INSTRUMENTATION_L3(instrumentation) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L3_N(instrumentation, name) __CPU_INSTRUMENTATION(3, instrumentation, name, uint_color(255, 255, 255, 255), nullptr) +# define CPU_INSTRUMENTATION_L3_C(instrumentation, color) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color, nullptr) +# define CPU_INSTRUMENTATION_L3_NC(instrumentation, name, color) __CPU_INSTRUMENTATION(3, instrumentation, name, color, nullptr) + +# define GPU_INSTRUMENTATION_L3(instrumentation, cg) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, uint_color(255, 255, 255, 255), nullptr) +# define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color, nullptr) +# define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, color, nullptr) + +# define CPU_INSTRUMENTATION_L3_O(instrumentation, object) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L3_NO(instrumentation, name, object) __CPU_INSTRUMENTATION(3, instrumentation, name, uint_color(255, 255, 255, 255), object) +# define CPU_INSTRUMENTATION_L3_CO(instrumentation, color, object) __CPU_INSTRUMENTATION(3, instrumentation, nullptr, color, object) +# define CPU_INSTRUMENTATION_L3_NCO(instrumentation, name, color, object) __CPU_INSTRUMENTATION(3, instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L3_O(instrumentation, cg, object) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L3_NO(instrumentation, cg, name, object) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, uint_color(255, 255, 255, 255), object) +# define GPU_INSTRUMENTATION_L3_CO(instrumentation, cg, color, object) __GPU_INSTRUMENTATION(3, instrumentation, cg, nullptr, color, object) +# define GPU_INSTRUMENTATION_L3_NCO(instrumentation, cg, name, color, object) __GPU_INSTRUMENTATION(3, instrumentation, cg, name, color, object) + #else + # define CPU_INSTRUMENTATION_L3(instrumentation) # define CPU_INSTRUMENTATION_L3_N(instrumentation, name) # define CPU_INSTRUMENTATION_L3_C(instrumentation, color) @@ -236,6 +296,17 @@ namespace vsg # define GPU_INSTRUMENTATION_L3_N(instrumentation, cg, name) # define GPU_INSTRUMENTATION_L3_C(instrumentation, cg, color) # define GPU_INSTRUMENTATION_L3_NC(instrumentation, cg, name, color) + +# define CPU_INSTRUMENTATION_L3_O(instrumentation, object) +# define CPU_INSTRUMENTATION_L3_NO(instrumentation, name, object) +# define CPU_INSTRUMENTATION_L3_CO(instrumentation, color, object) +# define CPU_INSTRUMENTATION_L3_NCO(instrumentation, name, color, object) + +# define GPU_INSTRUMENTATION_L3_O(instrumentation, cg, object) +# define GPU_INSTRUMENTATION_L3_NO(instrumentation, cg, name, object) +# define GPU_INSTRUMENTATION_L3_CO(instrumentation, cg, color, object) +# define GPU_INSTRUMENTATION_L3_NCO(instrumentation, cg, name, color, object) + #endif } // namespace vsg diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 20db2f1073..177fed11ef 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -133,7 +133,7 @@ namespace vsg FrameMark; } - void enter(const SourceLocation* slcloc, uint64_t& reference) const override + void enter(const SourceLocation* slcloc, uint64_t& reference, const Object*) const override { # ifdef TRACY_ON_DEMAND if (!GetProfiler().IsConnected() || (slcloc->level > settings->cpu_instumentation_level)) @@ -157,7 +157,7 @@ namespace vsg TracyQueueCommit(zoneBeginThread); } - void leave(const SourceLocation*, uint64_t& reference) const override + void leave(const SourceLocation*, uint64_t& reference, const Object*) const override { # ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; @@ -174,7 +174,7 @@ namespace vsg { if (ctx = contexts->getOrCreateContext(commandBuffer)) { - enter(slcloc, reference, commandBuffer); + enter(slcloc, reference, commandBuffer, nullptr); } } @@ -182,13 +182,13 @@ namespace vsg { if (ctx) { - leave(slcloc, reference, commandBuffer); + leave(slcloc, reference, commandBuffer, nullptr); } ctx = nullptr; } - void enter(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& cmdbuf) const override + void enter(const SourceLocation* slcloc, uint64_t& reference, CommandBuffer& cmdbuf, const Object*) const override { # ifdef TRACY_ON_DEMAND if (!ctx || !GetProfiler().IsConnected() || (slcloc->level > settings->gpu_instumentation_level)) @@ -219,7 +219,7 @@ namespace vsg Profiler::QueueSerialFinish(); } - void leave(const SourceLocation*, uint64_t& reference, CommandBuffer& cmdbuf) const override + void leave(const SourceLocation*, uint64_t& reference, CommandBuffer& cmdbuf, const Object*) const override { # ifdef TRACY_ON_DEMAND if (reference == 0 || GetProfiler().ConnectionId() != reference) return; diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index a4d66bca5b..5049f2d15a 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -110,7 +110,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD_L2, &object); //debug("Visiting Object"); object.traverse(*this); @@ -118,7 +118,7 @@ void RecordTraversal::apply(const Object& object) void RecordTraversal::apply(const Group& group) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Group", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Group", COLOR_RECORD_L2, &group); //debug("Visiting Group"); #if INLINE_TRAVERSE @@ -130,7 +130,7 @@ void RecordTraversal::apply(const Group& group) void RecordTraversal::apply(const QuadGroup& quadGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "QuadGroup", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "QuadGroup", COLOR_RECORD_L2, &quadGroup); //debug("Visiting QuadGroup"); #if INLINE_TRAVERSE @@ -142,7 +142,7 @@ void RecordTraversal::apply(const QuadGroup& quadGroup) void RecordTraversal::apply(const LOD& lod) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "LOD", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "LOD", COLOR_RECORD_L2, &lod); const auto& sphere = lod.bound; @@ -167,7 +167,7 @@ void RecordTraversal::apply(const LOD& lod) void RecordTraversal::apply(const PagedLOD& plod) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "PagedLOD", COLOR_PAGER); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "PagedLOD", COLOR_PAGER, &plod); const auto& sphere = plod.bound; auto frameCount = _frameStamp->frameCount; @@ -247,14 +247,14 @@ void RecordTraversal::apply(const PagedLOD& plod) void RecordTraversal::apply(const TileDatabase& tileDatabase) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "TileDatabase", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "TileDatabase", COLOR_RECORD_L2, &tileDatabase); tileDatabase.traverse(*this); } void RecordTraversal::apply(const CullGroup& cullGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "CullGroup", COLOR_RECORD_L2, &cullGroup); if (_state->intersect(cullGroup.bound)) { @@ -265,7 +265,7 @@ void RecordTraversal::apply(const CullGroup& cullGroup) void RecordTraversal::apply(const CullNode& cullNode) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "CullNode", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "CullNode", COLOR_RECORD_L2, &cullNode); if (_state->intersect(cullNode.bound)) { @@ -276,7 +276,7 @@ void RecordTraversal::apply(const CullNode& cullNode) void RecordTraversal::apply(const Switch& sw) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Switch", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Switch", COLOR_RECORD_L2, &sw); for (auto& child : sw.children) { @@ -289,7 +289,7 @@ void RecordTraversal::apply(const Switch& sw) void RecordTraversal::apply(const DepthSorted& depthSorted) { - CPU_INSTRUMENTATION_L2_NC(instrumentation, "DepthSorted", COLOR_RECORD_L2); + CPU_INSTRUMENTATION_L2_NCO(instrumentation, "DepthSorted", COLOR_RECORD_L2, &depthSorted); if (_state->intersect(depthSorted.bound)) { @@ -303,7 +303,7 @@ void RecordTraversal::apply(const DepthSorted& depthSorted) void RecordTraversal::apply(const VertexDraw& vd) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "VertexDraw", COLOR_GPU); + GPU_INSTRUMENTATION_L3_NCO(instrumentation, *getCommandBuffer(), "VertexDraw", COLOR_GPU, &vd); //debug("Visiting VertexDraw"); _state->record(); @@ -312,7 +312,7 @@ void RecordTraversal::apply(const VertexDraw& vd) void RecordTraversal::apply(const VertexIndexDraw& vid) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "VertexIndexDraw", COLOR_GPU); + GPU_INSTRUMENTATION_L3_NCO(instrumentation, *getCommandBuffer(), "VertexIndexDraw", COLOR_GPU, &vid); //debug("Visiting VertexIndexDraw"); _state->record(); @@ -321,14 +321,14 @@ void RecordTraversal::apply(const VertexIndexDraw& vid) void RecordTraversal::apply(const Geometry& geometry) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Geometry", COLOR_GPU); + GPU_INSTRUMENTATION_L3_NCO(instrumentation, *getCommandBuffer(), "Geometry", COLOR_GPU, &geometry); //debug("Visiting Geometry"); _state->record(); geometry.record(*(_state->_commandBuffer)); } -void RecordTraversal::apply(const Light& /*light*/) +void RecordTraversal::apply(const Light&) { CPU_INSTRUMENTATION_L2(instrumentation); @@ -337,7 +337,7 @@ void RecordTraversal::apply(const Light& /*light*/) void RecordTraversal::apply(const AmbientLight& light) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_O(instrumentation, &light); //debug("RecordTraversal::apply(AmbientLight) ", light.className()); if (_viewDependentState) _viewDependentState->ambientLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -345,7 +345,7 @@ void RecordTraversal::apply(const AmbientLight& light) void RecordTraversal::apply(const DirectionalLight& light) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_O(instrumentation, &light); //debug("RecordTraversal::apply(DirectionalLight) ", light.className()); if (_viewDependentState) _viewDependentState->directionalLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -353,7 +353,7 @@ void RecordTraversal::apply(const DirectionalLight& light) void RecordTraversal::apply(const PointLight& light) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_O(instrumentation, &light); //debug("RecordTraversal::apply(PointLight) ", light.className()); if (_viewDependentState) _viewDependentState->pointLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -361,7 +361,7 @@ void RecordTraversal::apply(const PointLight& light) void RecordTraversal::apply(const SpotLight& light) { - CPU_INSTRUMENTATION_L2(instrumentation); + CPU_INSTRUMENTATION_L2_O(instrumentation, &light); //debug("RecordTraversal::apply(SpotLight) ", light.className()); if (_viewDependentState) _viewDependentState->spotLights.emplace_back(_state->modelviewMatrixStack.top(), &light); @@ -369,7 +369,7 @@ void RecordTraversal::apply(const SpotLight& light) void RecordTraversal::apply(const StateGroup& stateGroup) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "StateGroup", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "StateGroup", COLOR_RECORD_L2, &stateGroup); //debug("Visiting StateGroup"); @@ -390,7 +390,7 @@ void RecordTraversal::apply(const StateGroup& stateGroup) void RecordTraversal::apply(const Transform& transform) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "Transform", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Transform", COLOR_RECORD_L2, &transform); _state->modelviewMatrixStack.push(transform); _state->dirty = true; @@ -412,7 +412,7 @@ void RecordTraversal::apply(const Transform& transform) void RecordTraversal::apply(const MatrixTransform& mt) { - GPU_INSTRUMENTATION_L2_NC(instrumentation, *getCommandBuffer(), "MatrixTransform", COLOR_RECORD_L2); + GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "MatrixTransform", COLOR_RECORD_L2, &mt); _state->modelviewMatrixStack.push(mt); _state->dirty = true; @@ -435,7 +435,7 @@ void RecordTraversal::apply(const MatrixTransform& mt) // Vulkan nodes void RecordTraversal::apply(const Commands& commands) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Commands", COLOR_GPU); + GPU_INSTRUMENTATION_L3_NCO(instrumentation, *getCommandBuffer(), "Commands", COLOR_GPU, &commands); _state->record(); for (auto& command : commands.children) @@ -446,24 +446,24 @@ void RecordTraversal::apply(const Commands& commands) void RecordTraversal::apply(const Command& command) { - GPU_INSTRUMENTATION_L3_NC(instrumentation, *getCommandBuffer(), "Command", COLOR_GPU); + GPU_INSTRUMENTATION_L3_NCO(instrumentation, *getCommandBuffer(), "Command", COLOR_GPU, &command); //debug("Visiting Command"); _state->record(); command.record(*(_state->_commandBuffer)); } -void RecordTraversal::apply(const Bin& object) +void RecordTraversal::apply(const Bin& bin) { - GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "Bin", COLOR_RECORD_L1); + GPU_INSTRUMENTATION_L1_NCO(instrumentation, *getCommandBuffer(), "Bin", COLOR_RECORD_L1, &bin); //debug("Visiting Bin"); - object.traverse(*this); + bin.traverse(*this); } void RecordTraversal::apply(const View& view) { - GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "View", COLOR_RECORD_L1); + GPU_INSTRUMENTATION_L1_NCO(instrumentation, *getCommandBuffer(), "View", COLOR_RECORD_L1, &view); // note, View::accept() updates the RecordTraversal's traversalMask auto cached_traversalMask = _state->_commandBuffer->traversalMask; @@ -552,7 +552,7 @@ void RecordTraversal::apply(const View& view) void RecordTraversal::apply(const CommandGraph& commandGraph) { - GPU_INSTRUMENTATION_L1_NC(instrumentation, *getCommandBuffer(), "RecordTraversal CommandGraph", COLOR_RECORD_L1); + GPU_INSTRUMENTATION_L1_NCO(instrumentation, *getCommandBuffer(), "RecordTraversal CommandGraph", COLOR_RECORD_L1, &commandGraph); if (recordedCommandBuffers) { diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index 8e2006e42d..8ac6d4b666 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -26,21 +26,23 @@ GpuAnnotation::~GpuAnnotation() void GpuAnnotation::enterCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const { - enter(sl, reference, commandBuffer); + enter(sl, reference, commandBuffer, nullptr); } void GpuAnnotation::leaveCommandBuffer(const SourceLocation* sl, uint64_t& reference, CommandBuffer& commandBuffer) const { - leave(sl, reference, commandBuffer); + leave(sl, reference, commandBuffer, nullptr); } -void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer) const +void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffer& commandBuffer, const Object* object) const { auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); VkDebugUtilsLabelEXT markerInfo = {}; markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - if (sl->name && labelType == SourceLocation_name) + if (labelType == Object_className && object) + markerInfo.pLabelName = object->className(); + else if (sl->name && labelType == SourceLocation_name) markerInfo.pLabelName = sl->name; else markerInfo.pLabelName = sl->function; @@ -53,7 +55,7 @@ void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffe extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); } -void GpuAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer) const +void GpuAnnotation::leave(const SourceLocation*, uint64_t&, vsg::CommandBuffer& commandBuffer, const Object*) const { auto extensions = commandBuffer.getDevice()->getInstance()->getExtensions(); extensions->vkCmdEndDebugUtilsLabelEXT(commandBuffer); From 5b0ae002baf73bb8428a4e3c2a5d4da7e7f42b5b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2024 17:05:43 +0000 Subject: [PATCH 61/68] Added explict --- include/vsg/maths/vec4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vsg/maths/vec4.h b/include/vsg/maths/vec4.h index da7a0647b3..35db054e0f 100644 --- a/include/vsg/maths/vec4.h +++ b/include/vsg/maths/vec4.h @@ -62,7 +62,7 @@ namespace vsg constexpr t_vec4(value_type in_x, value_type in_y, value_type in_z, value_type in_w) : value{in_x, in_y, in_z, in_w} {} - constexpr t_vec4(const VkClearColorValue& v) : + constexpr explicit t_vec4(const VkClearColorValue& v) : value{ static_cast(v.float32[0]), static_cast(v.float32[1]), static_cast(v.float32[2]), static_cast(v.float32[3])} {} template From d47764b2f1d9f0225bcea23d31f3b345e83b3426 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 4 Jan 2024 19:40:44 +0000 Subject: [PATCH 62/68] Improved doxygen comments --- include/vsg/vk/DeviceExtensions.h | 2 +- include/vsg/vk/InstanceExtensions.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vsg/vk/DeviceExtensions.h b/include/vsg/vk/DeviceExtensions.h index 1bc914431d..0c07b42ff4 100644 --- a/include/vsg/vk/DeviceExtensions.h +++ b/include/vsg/vk/DeviceExtensions.h @@ -23,7 +23,7 @@ namespace vsg extern VSG_DECLSPEC bool isExtensionListSupported(const Names& extensionList); /// Extensions manages a set of Vulkan extension function pointers. - /// The vsg::Device "has a" Extensions object that can be accessed via device->getExtensions(). + /// The vsg::Device "has a" DeviceExtensions object that can be accessed via device->getExtensions(). class VSG_DECLSPEC DeviceExtensions : public Inherit { public: diff --git a/include/vsg/vk/InstanceExtensions.h b/include/vsg/vk/InstanceExtensions.h index d0d81e802d..c94bd17f32 100644 --- a/include/vsg/vk/InstanceExtensions.h +++ b/include/vsg/vk/InstanceExtensions.h @@ -19,7 +19,7 @@ namespace vsg class Instance; /// Extensions manages a set of Vulkan extension function pointers. - /// The vsg::Device "has a" Extensions object that can be accessed via device->getExtensions(). + /// The vsg::Instance "has a" InstanceExtensions object that can be accessed via instance->getExtensions(). class VSG_DECLSPEC InstanceExtensions : public Inherit { public: From d995cb4e6019d75b7459c3c075da249494b35c6f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Jan 2024 19:01:29 +0000 Subject: [PATCH 63/68] Added enabledExtensions to vsg::Device and cleaned up placement of extensions functions --- include/vsg/vk/Device.h | 6 ++++++ include/vsg/vk/DeviceExtensions.h | 4 ---- include/vsg/vk/Instance.h | 8 ++++++-- include/vsg/vk/PhysicalDevice.h | 2 +- src/vsg/vk/Device.cpp | 7 +++++++ src/vsg/vk/DeviceExtensions.cpp | 20 -------------------- src/vsg/vk/Instance.cpp | 31 +++++++++++++++++++------------ 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/vsg/vk/Device.h b/include/vsg/vk/Device.h index 7595473d7a..be78f4b989 100644 --- a/include/vsg/vk/Device.h +++ b/include/vsg/vk/Device.h @@ -76,6 +76,12 @@ namespace vsg /// device-level core functionality can be used if both VkInstance and VkPhysicalDevice support the Vulkan version that provides it. bool supportsApiVersion(uint32_t version) const; + /// list of enabled extensions when the Device was created + const Names enabledExtensions; + + /// return true if Device was created with specified extension + bool supportsDeviceExtension(const char* extensionName) const; + protected: virtual ~Device(); diff --git a/include/vsg/vk/DeviceExtensions.h b/include/vsg/vk/DeviceExtensions.h index 0c07b42ff4..7868f63540 100644 --- a/include/vsg/vk/DeviceExtensions.h +++ b/include/vsg/vk/DeviceExtensions.h @@ -18,10 +18,6 @@ namespace vsg { class Device; - extern VSG_DECLSPEC bool isExtensionSupported(const char* extensionName); - - extern VSG_DECLSPEC bool isExtensionListSupported(const Names& extensionList); - /// Extensions manages a set of Vulkan extension function pointers. /// The vsg::Device "has a" DeviceExtensions object that can be accessed via device->getExtensions(). class VSG_DECLSPEC DeviceExtensions : public Inherit diff --git a/include/vsg/vk/Instance.h b/include/vsg/vk/Instance.h index 30ac17c9ac..4d4bb345f8 100644 --- a/include/vsg/vk/Instance.h +++ b/include/vsg/vk/Instance.h @@ -25,12 +25,16 @@ namespace vsg class Surface; using Names = std::vector; + using ExtensionProperties = std::vector; using PhysicalDeviceTypes = std::vector; using InstanceLayerProperties = std::vector; - using InstanceExtensionProperties = std::vector; + /// wrapper for vkEnumerateInstanceExtensionProperties - extern VSG_DECLSPEC InstanceExtensionProperties enumerateInstanceExtensionProperties(const char* pLayerName = nullptr); + extern VSG_DECLSPEC ExtensionProperties enumerateInstanceExtensionProperties(const char* pLayerName = nullptr); + + /// return true if the specified instance extension is supported + extern VSG_DECLSPEC bool isExtensionSupported(const char* extensionName, const char* pLayerName = nullptr); /// wrapper for vkEnumerateInstanceLayerProperties extern VSG_DECLSPEC InstanceLayerProperties enumerateInstanceLayerProperties(); diff --git a/include/vsg/vk/PhysicalDevice.h b/include/vsg/vk/PhysicalDevice.h index 36fbb7e12d..b5f27f805e 100644 --- a/include/vsg/vk/PhysicalDevice.h +++ b/include/vsg/vk/PhysicalDevice.h @@ -73,7 +73,7 @@ namespace vsg } /// Call vkEnumerateDeviceExtensionProperties to enumerate extension properties. - std::vector enumerateDeviceExtensionProperties(const char* pLayerName = nullptr); + ExtensionProperties enumerateDeviceExtensionProperties(const char* pLayerName = nullptr); /// return true if the extension is supported by physicalDevice bool supportsDeviceExtension(const char* extensionName); diff --git a/src/vsg/vk/Device.cpp b/src/vsg/vk/Device.cpp index 570c6571cb..85ae23ab81 100644 --- a/src/vsg/vk/Device.cpp +++ b/src/vsg/vk/Device.cpp @@ -52,6 +52,7 @@ static void releaseDeviceID(uint32_t deviceID) Device::Device(PhysicalDevice* physicalDevice, const QueueSettings& queueSettings, Names layers, Names deviceExtensions, const DeviceFeatures* deviceFeatures, AllocationCallbacks* allocator) : deviceID(getUniqueDeviceID()), + enabledExtensions(deviceExtensions), _instance(physicalDevice->getInstance()), _physicalDevice(physicalDevice), _allocator(allocator) @@ -197,3 +198,9 @@ bool Device::supportsApiVersion(uint32_t version) const { return getInstance()->apiVersion >= version && _physicalDevice->getProperties().apiVersion >= version; } + +bool Device::supportsDeviceExtension(const char* extensionName) const +{ + auto compare = [&](const char* rhs) { return strcmp(extensionName, rhs) == 0; }; + return (std::find_if(enabledExtensions.begin(), enabledExtensions.end(), compare) != enabledExtensions.end()); +} diff --git a/src/vsg/vk/DeviceExtensions.cpp b/src/vsg/vk/DeviceExtensions.cpp index 00ce8a0042..54abf3ce82 100644 --- a/src/vsg/vk/DeviceExtensions.cpp +++ b/src/vsg/vk/DeviceExtensions.cpp @@ -19,26 +19,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -bool vsg::isExtensionSupported(const char* extensionName) -{ - auto extProps = enumerateInstanceExtensionProperties(); - for (const auto& prop : extProps) - { - if (strncmp(prop.extensionName, extensionName, VK_MAX_EXTENSION_NAME_SIZE) == 0) return true; - } - return false; -} - -bool vsg::isExtensionListSupported(const Names& extensionList) -{ - auto extProps = enumerateInstanceExtensionProperties(); - for (const auto& ext : extensionList) - { - auto compare = [&](const VkExtensionProperties& rhs) { return strcmp(ext, rhs.extensionName) == 0; }; - if (std::find_if(extProps.begin(), extProps.end(), compare) == extProps.end()) return false; - } - return true; -} DeviceExtensions::DeviceExtensions(Device* device) { diff --git a/src/vsg/vk/Instance.cpp b/src/vsg/vk/Instance.cpp index 730b27ea54..c26e28b3b4 100644 --- a/src/vsg/vk/Instance.cpp +++ b/src/vsg/vk/Instance.cpp @@ -23,17 +23,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI using namespace vsg; -InstanceLayerProperties vsg::enumerateInstanceLayerProperties() -{ - uint32_t layerCount; - vkEnumerateInstanceLayerProperties(&layerCount, nullptr); - - std::vector availableLayers(layerCount); - vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); - return availableLayers; -} - -InstanceExtensionProperties vsg::enumerateInstanceExtensionProperties(const char* pLayerName) +ExtensionProperties vsg::enumerateInstanceExtensionProperties(const char* pLayerName) { uint32_t extCount = 0; VkResult result = vkEnumerateInstanceExtensionProperties(pLayerName, &extCount, nullptr); @@ -43,7 +33,7 @@ InstanceExtensionProperties vsg::enumerateInstanceExtensionProperties(const char return {}; } - InstanceExtensionProperties extensionProperties(extCount); + ExtensionProperties extensionProperties(extCount); result = vkEnumerateInstanceExtensionProperties(pLayerName, &extCount, extensionProperties.data()); if (result != VK_SUCCESS) { @@ -53,6 +43,23 @@ InstanceExtensionProperties vsg::enumerateInstanceExtensionProperties(const char return extensionProperties; } +bool vsg::isExtensionSupported(const char* extensionName, const char* pLayerName) +{ + auto extProps = enumerateInstanceExtensionProperties(pLayerName); + auto compare = [&](const VkExtensionProperties& rhs) { return strcmp(extensionName, rhs.extensionName) == 0; }; + return std::find_if(extProps.begin(), extProps.end(), compare) != extProps.end(); +} + +InstanceLayerProperties vsg::enumerateInstanceLayerProperties() +{ + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, nullptr); + + std::vector availableLayers(layerCount); + vkEnumerateInstanceLayerProperties(&layerCount, availableLayers.data()); + return availableLayers; +} + Names vsg::validateInstancelayerNames(const Names& names) { if (names.empty()) return names; From 5bbbac845123f299c1d3ec99465bcd8d5b9856fe Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 5 Jan 2024 19:02:34 +0000 Subject: [PATCH 64/68] Changed to using the new Device::supportsDeviceExtensions(..) --- include/vsg/utils/TracyInstrumentation.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vsg/utils/TracyInstrumentation.h b/include/vsg/utils/TracyInstrumentation.h index 177fed11ef..dadaf2bdcb 100644 --- a/include/vsg/utils/TracyInstrumentation.h +++ b/include/vsg/utils/TracyInstrumentation.h @@ -46,9 +46,9 @@ namespace vsg auto queue = device->getQueue(commandBuffer.getCommandPool()->queueFamilyIndex, 0); auto commandPool = CommandPool::create(device, queue->queueFamilyIndex(), VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT); auto temporaryCommandBuffer = commandPool->allocate(); - auto extensions = device->getInstance()->getExtensions(); - if (extensions->vkGetPhysicalDeviceCalibrateableTimeDomainsEXT) + + if (device->supportsDeviceExtension("VK_EXT_calibrated_timestamps")) { ctx = TracyVkContextCalibrated(device->getPhysicalDevice()->vk(), device->vk(), queue->vk(), temporaryCommandBuffer->vk(), extensions->vkGetPhysicalDeviceCalibrateableTimeDomainsEXT, extensions->vkGetCalibratedTimestampsEXT); From 5f9deb259f0c0c4f6e21ee5f12645e81f12ba57a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Jan 2024 14:22:49 +0000 Subject: [PATCH 65/68] Added vsg::InstrumentationNode --- include/vsg/nodes/InstrumentationNode.h | 61 ++++++++++++ src/vsg/nodes/InstrumentationNode.cpp | 120 ++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 include/vsg/nodes/InstrumentationNode.h create mode 100644 src/vsg/nodes/InstrumentationNode.cpp diff --git a/include/vsg/nodes/InstrumentationNode.h b/include/vsg/nodes/InstrumentationNode.h new file mode 100644 index 0000000000..ca1fd81eca --- /dev/null +++ b/include/vsg/nodes/InstrumentationNode.h @@ -0,0 +1,61 @@ +#pragma once + +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include + +namespace vsg +{ + + /// InstrumentationNode enables instrumentation of a subgraph + class VSG_DECLSPEC InstrumentationNode : public Inherit + { + public: + InstrumentationNode(); + InstrumentationNode(ref_ptr in_child); + + void traverse(Visitor& visitor) override; + void traverse(ConstVisitor& visitor) const override; + void traverse(RecordTraversal& visitor) const override; + + void read(Input& input) override; + void write(Output& output) const override; + + void setColor(uint_color color); + uint_color getColor() const { return _color; } + + void setName(const std::string& name); + const std::string& getName() const { return _name; } + + void setLevel(uint32_t level); + uint32_t getLevel() const { return _level; } + + ref_ptr child; + + protected: + virtual ~InstrumentationNode(); + + uint32_t _level = 1; + uint_color _color; + std::string _name; + + // local caches of setting for passing to Instrumentation + SourceLocation _sl_Visitor; + SourceLocation _sl_ConstVisitor; + SourceLocation _sl_RecordTraversal; + }; + VSG_type_name(vsg::InstrumentationNode); + +} // namespace vsg diff --git a/src/vsg/nodes/InstrumentationNode.cpp b/src/vsg/nodes/InstrumentationNode.cpp new file mode 100644 index 0000000000..1771fbdc4e --- /dev/null +++ b/src/vsg/nodes/InstrumentationNode.cpp @@ -0,0 +1,120 @@ +/* + +Copyright(c) 2018 Robert Osfield + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + */ + +#include +#include +#include +#include + +using namespace vsg; + +InstrumentationNode::InstrumentationNode(): + _level(1), + _color(255, 255, 255, 255), + _name("InstrumentationNode"), + _sl_Visitor{_name.c_str(), "InstrumentationNode::traverse(Visitor& rt)", __FILE__, 42, _color, _level}, + _sl_ConstVisitor{_name.c_str(), "InstrumentationNode::traverse(Visitor& rt)", __FILE__, 48, _color, _level}, + _sl_RecordTraversal{_name.c_str(), "InstrumentationNode::traverse(Visitor& rt)", __FILE__, 54, _color, _level} +{ +} + +InstrumentationNode::InstrumentationNode(ref_ptr in_child) : + InstrumentationNode() +{ + child = in_child; +} + +InstrumentationNode::~InstrumentationNode() +{ +} + +void InstrumentationNode::traverse(Visitor& visitor) +{ + CpuInstrumentation cpuInst(visitor.getInstrumentation(), &_sl_Visitor, child.get()); + child->accept(visitor); +} + +void InstrumentationNode::traverse(ConstVisitor& visitor) const +{ + CpuInstrumentation cpuInst(visitor.getInstrumentation(), &_sl_ConstVisitor, child.get()); + child->accept(visitor); +} + +void InstrumentationNode::traverse(RecordTraversal& rt) const +{ + GpuInstrumentation cpuInst(rt.instrumentation, &_sl_RecordTraversal, *rt.getCommandBuffer(), child.get()); + child->accept(rt); +} + +void InstrumentationNode::setColor(uint_color color) +{ + _color = color; + _sl_Visitor.color = _color; + _sl_ConstVisitor.color = _color; + _sl_RecordTraversal.color = _color; +} + +void InstrumentationNode::setName(const std::string& name) +{ + _name = name; + if (_name.empty()) + { + _sl_Visitor.name = nullptr; + _sl_ConstVisitor.name = nullptr; + _sl_RecordTraversal.name = nullptr; + } + else + { + _sl_Visitor.name = _name.c_str(); + _sl_ConstVisitor.name = _name.c_str(); + _sl_RecordTraversal.name = _name.c_str(); + } +} + +void InstrumentationNode::setLevel(uint32_t level) +{ + _level = level; + _sl_Visitor.level = _level; + _sl_ConstVisitor.level = _level; + _sl_RecordTraversal.level = _level; +} + +void InstrumentationNode::read(Input& input) +{ + Node::read(input); + + uint32_t level = 0; + uint_color color; + std::string name; + + input.read("Level", level); + input.read("Color", color); + input.read("Name", name); + + setLevel(level); + setColor(color); + setName(name); + + input.read("child", child); + +} + +void InstrumentationNode::write(Output& output) const +{ + Node::write(output); + + output.write("Level", _level); + output.write("Color", _color); + output.write("Name", _name); + + output.write("child", child); +} From 91d36d5b8dc80ed4389679d3166b2be9a3842417 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Jan 2024 15:02:14 +0000 Subject: [PATCH 66/68] Added InstrumentationNode support and warning fixes --- include/vsg/all.h | 1 + include/vsg/app/CompileTraversal.h | 2 ++ include/vsg/app/RecordTraversal.h | 4 ++-- include/vsg/core/ConstVisitor.h | 5 +++++ include/vsg/core/Visitor.h | 5 +++++ include/vsg/maths/color.h | 8 ++++---- include/vsg/utils/Instrumentation.h | 7 +------ src/vsg/CMakeLists.txt | 1 + src/vsg/app/RecordTraversal.cpp | 2 +- src/vsg/core/ConstVisitor.cpp | 4 ++++ src/vsg/core/Visitor.cpp | 4 ++++ src/vsg/io/ObjectFactory.cpp | 1 + src/vsg/io/tile.cpp | 2 +- src/vsg/utils/GpuAnnotation.cpp | 14 +++++++------- 14 files changed, 39 insertions(+), 21 deletions(-) diff --git a/include/vsg/all.h b/include/vsg/all.h index efcd782171..585b2f7ffd 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -64,6 +64,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include #include +#include #include #include #include diff --git a/include/vsg/app/CompileTraversal.h b/include/vsg/app/CompileTraversal.h index 63876dd3d1..2dd3f24758 100644 --- a/include/vsg/app/CompileTraversal.h +++ b/include/vsg/app/CompileTraversal.h @@ -67,6 +67,8 @@ namespace vsg /// assign Instrumentation to all Context void assignInstrumentation(ref_ptr in_instrumentation); + Instrumentation* getInstrumentation() override { return instrumentation.get(); } + virtual bool record(); virtual void waitForCompletion(); diff --git a/include/vsg/app/RecordTraversal.h b/include/vsg/app/RecordTraversal.h index f2c74eac3a..51a78ad3df 100644 --- a/include/vsg/app/RecordTraversal.h +++ b/include/vsg/app/RecordTraversal.h @@ -82,6 +82,8 @@ namespace vsg Mask traversalMask = MASK_ALL; Mask overrideMask = MASK_OFF; + ref_ptr instrumentation; + /// Container for CommandBuffers that have been recorded in current frame ref_ptr recordedCommandBuffers; @@ -142,8 +144,6 @@ namespace vsg // clear the bins to record a new frame. void clearBins(); - /// hook for assigning Instrumentation to enable profiling of record traversal. - ref_ptr instrumentation; protected: virtual ~RecordTraversal(); diff --git a/include/vsg/core/ConstVisitor.h b/include/vsg/core/ConstVisitor.h index 17696c3fef..379ba0dcae 100644 --- a/include/vsg/core/ConstVisitor.h +++ b/include/vsg/core/ConstVisitor.h @@ -47,6 +47,7 @@ namespace vsg class DirectionalLight; class PointLight; class SpotLight; + class InstrumentationNode; // forward declare text classes class Text; @@ -142,6 +143,7 @@ namespace vsg // forward declare general classes class FrameStamp; + class Instrumentation; class VSG_DECLSPEC ConstVisitor : public Object { @@ -151,6 +153,8 @@ namespace vsg Mask traversalMask = MASK_ALL; Mask overrideMask = MASK_OFF; + virtual Instrumentation* getInstrumentation() { return nullptr; } + virtual void apply(const Object&); virtual void apply(const Objects&); virtual void apply(const External&); @@ -302,6 +306,7 @@ namespace vsg virtual void apply(const DirectionalLight&); virtual void apply(const PointLight&); virtual void apply(const SpotLight&); + virtual void apply(const InstrumentationNode&); // text virtual void apply(const Text&); diff --git a/include/vsg/core/Visitor.h b/include/vsg/core/Visitor.h index 4a0d0909a5..9c67e2a978 100644 --- a/include/vsg/core/Visitor.h +++ b/include/vsg/core/Visitor.h @@ -47,6 +47,7 @@ namespace vsg class DirectionalLight; class PointLight; class SpotLight; + class InstrumentationNode; // forward declare text classes class Text; @@ -142,6 +143,7 @@ namespace vsg // forward declare general classes class FrameStamp; + class Instrumentation; class VSG_DECLSPEC Visitor : public Object { @@ -151,6 +153,8 @@ namespace vsg Mask traversalMask = MASK_ALL; Mask overrideMask = MASK_OFF; + virtual Instrumentation* getInstrumentation() { return nullptr; } + virtual void apply(Object&); virtual void apply(Objects&); virtual void apply(External&); @@ -302,6 +306,7 @@ namespace vsg virtual void apply(DirectionalLight&); virtual void apply(PointLight&); virtual void apply(SpotLight&); + virtual void apply(InstrumentationNode&); // text virtual void apply(Text&); diff --git a/include/vsg/maths/color.h b/include/vsg/maths/color.h index 7d18d8fd6e..7db673fd5c 100644 --- a/include/vsg/maths/color.h +++ b/include/vsg/maths/color.h @@ -99,28 +99,28 @@ namespace vsg template constexpr t_vec4 linear_to_sRGB(const t_vec4& src) { - const T exponent = 2.2; + const T exponent = static_cast(2.2); return t_vec4(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a); } template constexpr t_vec4 linear_to_sRGB(T r, T g, T b, T a) { - const T exponent = 2.2; + const T exponent = static_cast(2.2); return t_vec4(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a); } template constexpr t_vec4 sRGB_to_linear(const t_vec4& src) { - const T exponent = 1.0 / 2.2; + const T exponent = static_cast(1.0 / 2.2); return t_vec4(std::pow(src.r, exponent), std::pow(src.g, exponent), std::pow(src.b, exponent), src.a); } template constexpr t_vec4 sRGB_to_linear(T r, T g, T b, T a) { - const T exponent = 1.0 / 2.2; + const T exponent = static_cast(1.0 / 2.2); return t_vec4(std::pow(r, exponent), std::pow(g, exponent), std::pow(b, exponent), a); } diff --git a/include/vsg/utils/Instrumentation.h b/include/vsg/utils/Instrumentation.h index 0cf48bb088..6ee2bc4ffd 100644 --- a/include/vsg/utils/Instrumentation.h +++ b/include/vsg/utils/Instrumentation.h @@ -27,16 +27,11 @@ namespace vsg /// uint_color struct used to provide a {r, g, b, a} interface a colors assigned as uint32_t struct uint_color { -#if 0 - // RGBA order standard with VSG/Vulkan - uint8_t r = 255, g = 255, b = 255, a = 255; - constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : r(red), g(green), b(blue), a(alpha) {} -#else // BGRA order required to map to Tracy's uint32_t color value uint8_t b = 255, g = 255, r = 255, a = 255; + constexpr uint_color() = default; constexpr uint_color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) : b(blue), g(green), r(red), a(alpha) {} -#endif }; /// SourceLocation structs mark the location in a source file when instrumentation is placed. diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 3aa163d002..6ee22bb697 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -42,6 +42,7 @@ set(SOURCES nodes/StateGroup.cpp nodes/Light.cpp nodes/TileDatabase.cpp + nodes/InstrumentationNode.cpp commands/BindIndexBuffer.cpp commands/BindVertexBuffers.cpp diff --git a/src/vsg/app/RecordTraversal.cpp b/src/vsg/app/RecordTraversal.cpp index 5049f2d15a..993eec3f12 100644 --- a/src/vsg/app/RecordTraversal.cpp +++ b/src/vsg/app/RecordTraversal.cpp @@ -110,7 +110,7 @@ void RecordTraversal::clearBins() void RecordTraversal::apply(const Object& object) { - GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD_L2, &object); + // GPU_INSTRUMENTATION_L2_NCO(instrumentation, *getCommandBuffer(), "Object", COLOR_RECORD_L2, &object); //debug("Visiting Object"); object.traverse(*this); diff --git a/src/vsg/core/ConstVisitor.cpp b/src/vsg/core/ConstVisitor.cpp index a5a25c6496..e2f99d1990 100644 --- a/src/vsg/core/ConstVisitor.cpp +++ b/src/vsg/core/ConstVisitor.cpp @@ -609,6 +609,10 @@ void ConstVisitor::apply(const SpotLight& value) { apply(static_cast(value)); } +void ConstVisitor::apply(const InstrumentationNode& value) +{ + apply(static_cast(value)); +} //////////////////////////////////////////////////////////////////////////////// // diff --git a/src/vsg/core/Visitor.cpp b/src/vsg/core/Visitor.cpp index 2994805254..a8468a8b7e 100644 --- a/src/vsg/core/Visitor.cpp +++ b/src/vsg/core/Visitor.cpp @@ -609,6 +609,10 @@ void Visitor::apply(SpotLight& value) { apply(static_cast(value)); } +void Visitor::apply(InstrumentationNode& value) +{ + apply(static_cast(value)); +} //////////////////////////////////////////////////////////////////////////////// // diff --git a/src/vsg/io/ObjectFactory.cpp b/src/vsg/io/ObjectFactory.cpp index f0f39cf3f4..73fed680ae 100644 --- a/src/vsg/io/ObjectFactory.cpp +++ b/src/vsg/io/ObjectFactory.cpp @@ -189,6 +189,7 @@ ObjectFactory::ObjectFactory() add(); add(); add(); + add(); // vulkan objects add(); diff --git a/src/vsg/io/tile.cpp b/src/vsg/io/tile.cpp index 78875d0f84..02663237bc 100644 --- a/src/vsg/io/tile.cpp +++ b/src/vsg/io/tile.cpp @@ -480,7 +480,7 @@ vsg::ref_ptr tile::createECEFTile(const vsg::dbox& tile_extents, vsg: auto vid = vsg::VertexIndexDraw::create(); vid->assignArrays(vsg::DataList{vertices, normals, texcoords, colors}); vid->assignIndices(indices); - vid->indexCount = indices->size(); + vid->indexCount = static_cast(indices->size()); vid->instanceCount = 1; transform->addChild(vid); diff --git a/src/vsg/utils/GpuAnnotation.cpp b/src/vsg/utils/GpuAnnotation.cpp index 8ac6d4b666..e73c1f7f59 100644 --- a/src/vsg/utils/GpuAnnotation.cpp +++ b/src/vsg/utils/GpuAnnotation.cpp @@ -40,17 +40,17 @@ void GpuAnnotation::enter(const SourceLocation* sl, uint64_t&, vsg::CommandBuffe VkDebugUtilsLabelEXT markerInfo = {}; markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - if (labelType == Object_className && object) - markerInfo.pLabelName = object->className(); - else if (sl->name && labelType == SourceLocation_name) + if (sl->name && labelType == SourceLocation_name) markerInfo.pLabelName = sl->name; + else if (labelType == Object_className && object) + markerInfo.pLabelName = object->className(); else markerInfo.pLabelName = sl->function; - markerInfo.color[0] = static_cast(sl->color.r) / 255.0; - markerInfo.color[1] = static_cast(sl->color.g) / 255.0; - markerInfo.color[2] = static_cast(sl->color.b) / 255.0; - markerInfo.color[3] = static_cast(sl->color.a) / 255.0; + markerInfo.color[0] = static_cast(sl->color.r) / 255.0f; + markerInfo.color[1] = static_cast(sl->color.g) / 255.0f; + markerInfo.color[2] = static_cast(sl->color.b) / 255.0f; + markerInfo.color[3] = static_cast(sl->color.a) / 255.0f; extensions->vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &markerInfo); } From 1b357336cef8a4513497ea1eeb9af66e83de0b7b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Jan 2024 15:17:18 +0000 Subject: [PATCH 67/68] Fixed copyright date --- include/vsg/nodes/InstrumentationNode.h | 2 +- src/vsg/nodes/InstrumentationNode.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/vsg/nodes/InstrumentationNode.h b/include/vsg/nodes/InstrumentationNode.h index ca1fd81eca..c752e0fffc 100644 --- a/include/vsg/nodes/InstrumentationNode.h +++ b/include/vsg/nodes/InstrumentationNode.h @@ -2,7 +2,7 @@ /* -Copyright(c) 2018 Robert Osfield +Copyright(c) 2024 Robert Osfield Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/src/vsg/nodes/InstrumentationNode.cpp b/src/vsg/nodes/InstrumentationNode.cpp index 1771fbdc4e..cfd24d6d3c 100644 --- a/src/vsg/nodes/InstrumentationNode.cpp +++ b/src/vsg/nodes/InstrumentationNode.cpp @@ -1,6 +1,6 @@ /* -Copyright(c) 2018 Robert Osfield +Copyright(c) 2024 Robert Osfield Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 8b16b361549365088d441acd6a24db74810c01f6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 8 Jan 2024 15:18:44 +0000 Subject: [PATCH 68/68] Improved comment --- include/vsg/nodes/InstrumentationNode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vsg/nodes/InstrumentationNode.h b/include/vsg/nodes/InstrumentationNode.h index c752e0fffc..8fe34342b9 100644 --- a/include/vsg/nodes/InstrumentationNode.h +++ b/include/vsg/nodes/InstrumentationNode.h @@ -51,7 +51,7 @@ namespace vsg uint_color _color; std::string _name; - // local caches of setting for passing to Instrumentation + // SourceLocation variants for passing to Instrumentation that adapt the level, color and name to work with SourceLocation usad by Instrumentation SourceLocation _sl_Visitor; SourceLocation _sl_ConstVisitor; SourceLocation _sl_RecordTraversal;