From 6bbad2ab13c0d89001e9d076265cbaa48667a22c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 4 Sep 2023 12:41:32 +0100 Subject: [PATCH 1/5] Added View copy constructor that shares viewID and common state. --- include/vsg/app/View.h | 3 +++ src/vsg/app/View.cpp | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/include/vsg/app/View.h b/include/vsg/app/View.h index d1c4b97a0..f4d06b8c7 100644 --- a/include/vsg/app/View.h +++ b/include/vsg/app/View.h @@ -26,6 +26,9 @@ namespace vsg public: View(); + View(const View& view); + + // share the viewID, mask and camera's ViewportState explicit View(ref_ptr in_camera, ref_ptr in_scenegraph = {}); template diff --git a/src/vsg/app/View.cpp b/src/vsg/app/View.cpp index 6e17e1417..db2044a74 100644 --- a/src/vsg/app/View.cpp +++ b/src/vsg/app/View.cpp @@ -18,7 +18,7 @@ using namespace vsg; // thread safe container for managing the deviceID for each vsg::View static std::mutex s_ViewCountMutex; -static std::vector s_ActiveViews; +static std::vector s_ActiveViews; static uint32_t getUniqueViewID() { @@ -27,14 +27,30 @@ static uint32_t getUniqueViewID() uint32_t viewID = 0; for (viewID = 0; viewID < static_cast(s_ActiveViews.size()); ++viewID) { - if (!s_ActiveViews[viewID]) + if (s_ActiveViews[viewID]==0) { - s_ActiveViews[viewID] = true; + ++s_ActiveViews[viewID]; return viewID; } } - s_ActiveViews.push_back(true); + s_ActiveViews.push_back(1); + + return viewID; +} + +static uint32_t sharedViewID(uint32_t viewID) +{ + std::scoped_lock guard(s_ViewCountMutex); + + if (viewID < static_cast(s_ActiveViews.size())) + { + ++s_ActiveViews[viewID]; + return viewID; + } + + viewID = static_cast(s_ActiveViews.size()); + s_ActiveViews.push_back(1); return viewID; } @@ -42,7 +58,7 @@ static uint32_t getUniqueViewID() static void releaseViewID(uint32_t viewID) { std::scoped_lock guard(s_ViewCountMutex); - s_ActiveViews[viewID] = false; + --s_ActiveViews[viewID]; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -55,6 +71,18 @@ View::View() : { } +View::View(const View& view): + Inherit(view), + viewID(sharedViewID(view.viewID)), + mask(view.mask) +{ + if (view.camera) + { + camera = vsg::Camera::create(); + camera->viewportState = view.camera->viewportState; + } +} + View::View(ref_ptr in_camera, ref_ptr in_scenegraph) : camera(in_camera), viewID(getUniqueViewID()), From d38b434951365c27b6df10e48f70e98b6235f8d1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 4 Sep 2023 12:43:08 +0100 Subject: [PATCH 2/5] Fixed position of comment --- include/vsg/app/View.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/vsg/app/View.h b/include/vsg/app/View.h index f4d06b8c7..72ce9b819 100644 --- a/include/vsg/app/View.h +++ b/include/vsg/app/View.h @@ -26,9 +26,9 @@ namespace vsg public: View(); + // share the viewID, mask and camera's ViewportState View(const View& view); - // share the viewID, mask and camera's ViewportState explicit View(ref_ptr in_camera, ref_ptr in_scenegraph = {}); template From 57cdf984a0c3d7d901ea57c3d0f15f339b445a62 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 Sep 2023 13:35:58 +0100 Subject: [PATCH 3/5] Added support for nested CommandGraph with their own Windows --- src/vsg/app/Viewer.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/vsg/app/Viewer.cpp b/src/vsg/app/Viewer.cpp index 4e273d01f..ade554c29 100644 --- a/src/vsg/app/Viewer.cpp +++ b/src/vsg/app/Viewer.cpp @@ -432,23 +432,31 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr } }; - // assign windows used in the commandGraphs to the window to be tracked - _windows.clear(); - for (auto& commandGraph : in_commandGraphs) + + // find all the windows + struct FindWindows : public Visitor { - if (commandGraph->window && std::find(_windows.begin(), _windows.end(), commandGraph->window) == _windows.end()) + std::set> windows; + + void apply(Object& object) override { object.traverse(*this); } + void apply(CommandGraph& cg) override { - _windows.push_back(commandGraph->window); + if (cg.window) windows.insert(cg.window); + cg.traverse(*this); } - } + } findWindows; // place the input CommandGraphs into separate groups associated with each device and queue family combination std::map deviceCommandGraphsMap; for (auto& commandGraph : in_commandGraphs) { + commandGraph->accept(findWindows); deviceCommandGraphsMap[DeviceQueueFamily{commandGraph->device.get(), commandGraph->queueFamily, commandGraph->presentFamily}].emplace_back(commandGraph); } + // assign the windows found in the CommandGraphs so that the Viewer can track them. + _windows.assign(findWindows.windows.begin(), findWindows.windows.end()); + // create the required RecordAndSubmitTask and any Presentation objects that are required for each set of CommandGraphs for (auto& [deviceQueueFamily, commandGraphs] : deviceCommandGraphsMap) { @@ -497,14 +505,14 @@ void Viewer::assignRecordAndSubmitTaskAndPresentation(CommandGraphs in_commandGr if (deviceQueueFamily.presentFamily >= 0) { - // collate all the unique Windows associated with these commandGraphs - std::set uniqueWindows; - for (auto& commanGraph : commandGraphs) + // collate all the unique Windows associated with this device's commandGraphs + findWindows.windows.clear(); + for (auto& commandGraph : commandGraphs) { - uniqueWindows.insert(commanGraph->window); + commandGraph->accept(findWindows); } - Windows windows(uniqueWindows.begin(), uniqueWindows.end()); + Windows windows(findWindows.windows.begin(), findWindows.windows.end()); auto renderFinishedSemaphore = vsg::Semaphore::create(device); From 85d2982a295d7ff8bfbf931efb0c27bb84b02c8c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Sep 2023 13:04:29 +0100 Subject: [PATCH 4/5] Added View::share(const View&) method --- include/vsg/app/View.h | 5 ++++- src/vsg/app/View.cpp | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/vsg/app/View.h b/include/vsg/app/View.h index 72ce9b819..a2393da8d 100644 --- a/include/vsg/app/View.h +++ b/include/vsg/app/View.h @@ -26,7 +26,7 @@ namespace vsg public: View(); - // share the viewID, mask and camera's ViewportState + // share the specified view's children, viewID, mask and camera ViewportState View(const View& view); explicit View(ref_ptr in_camera, ref_ptr in_scenegraph = {}); @@ -49,6 +49,9 @@ namespace vsg void accept(ConstVisitor& visitor) const override { t_accept(*this, visitor); } void accept(RecordTraversal& visitor) const override { t_accept(*this, visitor); } + /// share the specified view's viewID, mask, camera ViewportState, with this View + void share(const View& view); + /// camera controls the viewport state and projection and view matrices ref_ptr camera; diff --git a/src/vsg/app/View.cpp b/src/vsg/app/View.cpp index db2044a74..d54373d73 100644 --- a/src/vsg/app/View.cpp +++ b/src/vsg/app/View.cpp @@ -76,7 +76,7 @@ View::View(const View& view): viewID(sharedViewID(view.viewID)), mask(view.mask) { - if (view.camera) + if (view.camera && view.camera->viewportState) { camera = vsg::Camera::create(); camera->viewportState = view.camera->viewportState; @@ -95,3 +95,19 @@ View::~View() { releaseViewID(viewID); } + +void View::share(const View& view) +{ + if (viewID != view.viewID) + { + releaseViewID(viewID); + const_cast(viewID) = sharedViewID(view.viewID); + } + + mask = view.mask; + if (view.camera && view.camera->viewportState) + { + if (!camera) camera = vsg::Camera::create(); + camera->viewportState = view.camera->viewportState; + } +} From 67c96c0c4a7312ef7e6601ff97d5f05c5f10ac6f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Sep 2023 13:09:01 +0100 Subject: [PATCH 5/5] Added GraphicsPipeline::validate_vk() method to make it possible to query the Vulkan pipeline with add check against the validity of the viewID for that pipeline. --- include/vsg/state/GraphicsPipeline.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/vsg/state/GraphicsPipeline.h b/include/vsg/state/GraphicsPipeline.h index f9323e1e1..b8a7583d2 100644 --- a/include/vsg/state/GraphicsPipeline.h +++ b/include/vsg/state/GraphicsPipeline.h @@ -58,8 +58,12 @@ namespace vsg GraphicsPipeline(PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass = 0); + /// return the Vukan Pipeline for specified viewID. VkPipeline vk(uint32_t viewID) const { return _implementation[viewID]->_pipeline; } + /// variant of vk(viewID) method that is slower but adds validation of the viewID parameter + VkPipeline validated_vk(uint32_t viewID) const { return (viewID < _implementation.size()) ? (_implementation[viewID] ? _implementation[viewID]->_pipeline : 0) : 0; } + /// VkGraphicsPipelineCreateInfo settings ShaderStages stages; GraphicsPipelineStates pipelineStates;