Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robust view resize via modification counting #1265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/vsg/app/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace vsg
class VSG_DECLSPEC View : public Inherit<Group, View>
{
public:
static ModifiedCount modifiedCount(uint32_t viewID);

View(ViewFeatures in_features = RECORD_ALL);

// share the specified view's children, viewID, mask and camera ViewportState
Expand Down Expand Up @@ -63,6 +65,10 @@ namespace vsg
/// share the specified view's viewID, mask, camera ViewportState, with this View
void share(const View& view);

/// incremented when the pipeline state for the viewID is invalidated
ModifiedCount modifiedCount();
void modified();

/// camera controls the viewport state and projection and view matrices
ref_ptr<Camera> camera;

Expand Down
2 changes: 2 additions & 0 deletions include/vsg/state/GraphicsPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace vsg

virtual ~Implementation();

ModifiedCount viewModifiedCount;

VkPipeline _pipeline;

ref_ptr<Device> _device;
Expand Down
19 changes: 19 additions & 0 deletions src/vsg/app/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ using namespace vsg;
// thread safe container for managing the deviceID for each vsg::View
static std::mutex s_ViewCountMutex;
static std::vector<uint32_t> s_ActiveViews;
// these must not be reset to zero when a view ID is reused
static std::vector<ModifiedCount> s_ViewIDModifiedCounts;

static uint32_t getUniqueViewID()
{
Expand All @@ -38,6 +40,7 @@ static uint32_t getUniqueViewID()
}

s_ActiveViews.push_back(1);
s_ViewIDModifiedCounts.emplace_back();

return viewID;
}
Expand All @@ -62,6 +65,12 @@ static void releaseViewID(uint32_t viewID)
{
std::scoped_lock<std::mutex> guard(s_ViewCountMutex);
--s_ActiveViews[viewID];
++s_ViewIDModifiedCounts[viewID];
}

ModifiedCount vsg::View::modifiedCount(uint32_t viewID)
{
return s_ViewIDModifiedCounts[viewID];
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -125,3 +134,13 @@ void View::share(const View& view)
camera->viewportState = view.camera->viewportState;
}
}

ModifiedCount vsg::View::modifiedCount()
{
return s_ViewIDModifiedCounts[viewID];
}

void vsg::View::modified()
{
++s_ViewIDModifiedCounts[viewID];
}
7 changes: 5 additions & 2 deletions src/vsg/app/WindowResizeHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void UpdateGraphicsPipelines::apply(vsg::BindGraphicsPipeline& bindPipeline)
auto pipeline = bindPipeline.pipeline;
if (pipeline)
{
pipeline->release(context->viewID);
pipeline->compile(*context);
}
}
Expand Down Expand Up @@ -118,7 +117,6 @@ void WindowResizeHandler::apply(vsg::BindGraphicsPipeline& bindPipeline)
bool needToRegenerateGraphicsPipeline = !containsViewport(*graphicsPipeline);
if (needToRegenerateGraphicsPipeline)
{
graphicsPipeline->release(context->viewID);
graphicsPipeline->compile(*context);
}
}
Expand All @@ -144,11 +142,13 @@ void WindowResizeHandler::apply(vsg::View& view)
{
if (!visit(&view)) return;

auto previous_viewID = context->viewID;
context->viewID = view.viewID;

if (!view.camera)
{
view.traverse(*this);
context->viewID = previous_viewID;
return;
}

Expand Down Expand Up @@ -178,9 +178,12 @@ void WindowResizeHandler::apply(vsg::View& view)
}
}

view.modified();

context->defaultPipelineStates.emplace_back(viewportState);

view.traverse(*this);

context->defaultPipelineStates.pop_back();
context->viewID = previous_viewID;
}
4 changes: 3 additions & 1 deletion src/vsg/state/GraphicsPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

</editor-fold> */

#include <vsg/app/View.h>
#include <vsg/core/Exception.h>
#include <vsg/core/compare.h>
#include <vsg/io/Logger.h>
Expand Down Expand Up @@ -138,7 +139,7 @@ void GraphicsPipeline::compile(Context& context)
_implementation.resize(viewID + 1);
}

if (!_implementation[viewID])
if (!_implementation[viewID] || _implementation[viewID]->viewModifiedCount != View::modifiedCount(context.viewID))
{
// compile shaders if required
bool requiresShaderCompiler = false;
Expand Down Expand Up @@ -189,6 +190,7 @@ void GraphicsPipeline::compile(Context& context)
// GraphicsPipeline::Implementation
//
GraphicsPipeline::Implementation::Implementation(Context& context, Device* device, const RenderPass* renderPass, const PipelineLayout* pipelineLayout, const ShaderStages& shaderStages, const GraphicsPipelineStates& pipelineStates, uint32_t subpass) :
viewModifiedCount(View::modifiedCount(context.viewID)),
_device(device)
{
VkGraphicsPipelineCreateInfo pipelineInfo = {};
Expand Down
Loading