Skip to content

Commit

Permalink
Added AnnotatedRecordTraversal class to enable reaching Vulkan debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed Dec 4, 2023
1 parent 04ed4b8 commit 8671b7f
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/vsg/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#include <vsg/ui/WindowEvent.h>

// Application header files
#include <vsg/app/AnnotatedRecordTraversal.h>
#include <vsg/app/Camera.h>
#include <vsg/app/CloseHandler.h>
#include <vsg/app/CommandGraph.h>
Expand Down
91 changes: 91 additions & 0 deletions include/vsg/app/AnnotatedRecordTraversal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#pragma once

/* <editor-fold desc="MIT License">
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.
</editor-fold> */

#include <vsg/core/Inherit.h>
#include <vsg/vk/CommandBuffer.h>
#include <vsg/app/RecordTraversal.h>

namespace vsg
{

#if VSG_virtual_RecordTraversal_apply
class VSG_DECLSPEC AnnotatedRecordTraversal : public Inherit<RecordTraversal, AnnotatedRecordTraversal>
{
public:

explicit AnnotatedRecordTraversal(uint32_t in_maxSlot = 2, std::set<Bin*> in_bins = {});

vec4 debugColor = {.8, .8, .8, 1.0};

template<class T>
void annotate(const T& object)
{
auto* commandBuffer = getCommandBuffer();
auto extensions = commandBuffer->getDevice()->getInstance()->getExtensions();
if (extensions->vkCmdBeginDebugUtilsLabelEXT)
{
VkCommandBuffer cmdBuffer{*commandBuffer};
VkDebugUtilsLabelEXT markerInfo = {};
markerInfo.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT;
markerInfo.pLabelName = object.className();
std::copy(&debugColor.value[0], &debugColor.value[4], &markerInfo.color[0]);

extensions->vkCmdBeginDebugUtilsLabelEXT(cmdBuffer, &markerInfo);

RecordTraversal::apply(object);

extensions->vkCmdEndDebugUtilsLabelEXT(cmdBuffer);
}
else
{
RecordTraversal::apply(object);
}
}

void apply(const Object& object) override;

// scene graph nodes
void apply(const Group& group) override;
void apply(const QuadGroup& quadGroup) override;
void apply(const LOD& lod) override;
void apply(const PagedLOD& pagedLOD) override;
void apply(const CullGroup& cullGroup) override;
void apply(const CullNode& cullNode) override;
void apply(const DepthSorted& depthSorted) override;
void apply(const Switch& sw) override;

// positional state
void apply(const Light& light) override;
void apply(const AmbientLight& light) override;
void apply(const DirectionalLight& light) override;
void apply(const PointLight& light) override;
void apply(const SpotLight& light) override;

// Vulkan nodes
void apply(const Transform& transform) override;
void apply(const MatrixTransform& mt) override;
void apply(const StateGroup& sg) override;
void apply(const Commands& commands) override;
void apply(const Command& command) override;

// Viewer level nodes
void apply(const View& view) override;
void apply(const CommandGraph& commandGraph) override;
};

VSG_type_name(AnnotatedRecordTraversal);

#endif

} // namespace vsg
1 change: 1 addition & 0 deletions src/vsg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ set(SOURCES
app/ProjectionMatrix.cpp
app/UpdateOperations.cpp
app/RecordTraversal.cpp
app/AnnotatedRecordTraversal.cpp
app/CompileTraversal.cpp

raytracing/AccelerationGeometry.cpp
Expand Down
69 changes: 69 additions & 0 deletions src/vsg/app/AnnotatedRecordTraversal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* <editor-fold desc="MIT License">
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.
</editor-fold> */

#include <vsg/app/AnnotatedRecordTraversal.h>
#include <vsg/nodes/Group.h>
#include <vsg/nodes/QuadGroup.h>
#include <vsg/nodes/LOD.h>
#include <vsg/nodes/PagedLOD.h>
#include <vsg/nodes/MatrixTransform.h>
#include <vsg/nodes/Switch.h>
#include <vsg/nodes/Light.h>
#include <vsg/nodes/StateGroup.h>
#include <vsg/nodes/DepthSorted.h>
#include <vsg/nodes/CullNode.h>
#include <vsg/nodes/CullGroup.h>
#include <vsg/app/CommandGraph.h>
#include <vsg/app/View.h>
#include <vsg/commands/Commands.h>
#include <vsg/io/Options.h>

using namespace vsg;

#if VSG_virtual_RecordTraversal_apply

AnnotatedRecordTraversal::AnnotatedRecordTraversal(uint32_t in_maxSlot, std::set<Bin*> in_bins) :
Inherit(in_maxSlot, in_bins)
{
}

void AnnotatedRecordTraversal::apply(const vsg::Object& object) { annotate(object); }

// scene graph nodes
void AnnotatedRecordTraversal::apply(const vsg::Group& group) { annotate(group); }
void AnnotatedRecordTraversal::apply(const vsg::QuadGroup& quadGroup) { annotate(quadGroup); }
void AnnotatedRecordTraversal::apply(const vsg::LOD& lod) { annotate(lod); }
void AnnotatedRecordTraversal::apply(const vsg::PagedLOD& pagedLOD) { annotate(pagedLOD); }
void AnnotatedRecordTraversal::apply(const vsg::CullGroup& cullGroup) { annotate(cullGroup); }
void AnnotatedRecordTraversal::apply(const vsg::CullNode& cullNode) { annotate(cullNode); }
void AnnotatedRecordTraversal::apply(const vsg::DepthSorted& depthSorted) { annotate(depthSorted); }
void AnnotatedRecordTraversal::apply(const vsg::Switch& sw) { annotate(sw); }

// positional state
void AnnotatedRecordTraversal::apply(const vsg::Light& light) { annotate(light); }
void AnnotatedRecordTraversal::apply(const vsg::AmbientLight& light) { annotate(light); }
void AnnotatedRecordTraversal::apply(const vsg::DirectionalLight& light) { annotate(light); }
void AnnotatedRecordTraversal::apply(const vsg::PointLight& light) { annotate(light); }
void AnnotatedRecordTraversal::apply(const vsg::SpotLight& light) { annotate(light); }

// Vulkan nodes
void AnnotatedRecordTraversal::apply(const vsg::Transform& transform) { annotate(transform); }
void AnnotatedRecordTraversal::apply(const vsg::MatrixTransform& mt) { annotate(mt); }
void AnnotatedRecordTraversal::apply(const vsg::StateGroup& sg) { annotate(sg); }
void AnnotatedRecordTraversal::apply(const vsg::Commands& commands) { annotate(commands); }
void AnnotatedRecordTraversal::apply(const vsg::Command& command) { annotate(command); }

// Viewer level nodes
void AnnotatedRecordTraversal::apply(const vsg::View& view) { annotate(view); }
void AnnotatedRecordTraversal::apply(const vsg::CommandGraph& commandGraph) { annotate(commandGraph); }

#endif
16 changes: 15 additions & 1 deletion src/vsg/app/CommandGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

#include <vsg/app/CommandGraph.h>
#include <vsg/app/RenderGraph.h>
#include <vsg/app/AnnotatedRecordTraversal.h>
#include <vsg/app/View.h>
#include <vsg/io/DatabasePager.h>
#include <vsg/state/ViewDependentState.h>
Expand Down Expand Up @@ -49,7 +50,20 @@ CommandGraph::~CommandGraph()

ref_ptr<RecordTraversal> CommandGraph::getOrCreateRecordTraversal()
{
if (!recordTraversal) recordTraversal = RecordTraversal::create(maxSlot);
if (!recordTraversal)
{
#if VSG_virtual_RecordTraversal_apply
if (window && window->traits() && window->traits()->apiDumpLayer)
{
recordTraversal = AnnotatedRecordTraversal::create(maxSlot);
}
else
#endif
{
recordTraversal = RecordTraversal::create(maxSlot);
}
info("CommandGraph::getOrCreateRecordTraversal() ", recordTraversal);
}
return recordTraversal;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vsg/app/WindowTraits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 8671b7f

Please sign in to comment.