diff --git a/include/vsg/all.h b/include/vsg/all.h index da7c22e2b7..04aa7a1959 100644 --- a/include/vsg/all.h +++ b/include/vsg/all.h @@ -176,6 +176,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include // Application header files +#include #include #include #include diff --git a/include/vsg/app/AnnotatedRecordTraversal.h b/include/vsg/app/AnnotatedRecordTraversal.h new file mode 100644 index 0000000000..36161ddf5c --- /dev/null +++ b/include/vsg/app/AnnotatedRecordTraversal.h @@ -0,0 +1,91 @@ +#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 VSG_virtual_RecordTraversal_apply +class VSG_DECLSPEC AnnotatedRecordTraversal : public Inherit +{ +public: + + explicit AnnotatedRecordTraversal(uint32_t in_maxSlot = 2, std::set in_bins = {}); + + vec4 debugColor = {.8, .8, .8, 1.0}; + + template + 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 diff --git a/src/vsg/CMakeLists.txt b/src/vsg/CMakeLists.txt index 6932475556..cef44724af 100644 --- a/src/vsg/CMakeLists.txt +++ b/src/vsg/CMakeLists.txt @@ -163,6 +163,7 @@ set(SOURCES app/ProjectionMatrix.cpp app/UpdateOperations.cpp app/RecordTraversal.cpp + app/AnnotatedRecordTraversal.cpp app/CompileTraversal.cpp raytracing/AccelerationGeometry.cpp diff --git a/src/vsg/app/AnnotatedRecordTraversal.cpp b/src/vsg/app/AnnotatedRecordTraversal.cpp new file mode 100644 index 0000000000..498e37f037 --- /dev/null +++ b/src/vsg/app/AnnotatedRecordTraversal.cpp @@ -0,0 +1,69 @@ +/* + +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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace vsg; + +#if VSG_virtual_RecordTraversal_apply + +AnnotatedRecordTraversal::AnnotatedRecordTraversal(uint32_t in_maxSlot, std::set 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 diff --git a/src/vsg/app/CommandGraph.cpp b/src/vsg/app/CommandGraph.cpp index ebbbc9b9ff..a376613730 100644 --- a/src/vsg/app/CommandGraph.cpp +++ b/src/vsg/app/CommandGraph.cpp @@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include #include +#include #include #include #include @@ -49,7 +50,20 @@ CommandGraph::~CommandGraph() ref_ptr 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; } 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); }