Skip to content

Commit

Permalink
use less blocking sync
Browse files Browse the repository at this point in the history
  • Loading branch information
stohrendorf committed Oct 9, 2021
1 parent cec2985 commit 18d8da0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/engine/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ void Presenter::renderWorld(const ObjectManager& objectManager,

for(const auto& texture : m_csm->getDepthTextures())
texture->clear(gl::ScalarDepth{1.0f});
gl::FenceSync::block();

for(size_t i = 0; i < render::scene::CSMBuffer::NSplits; ++i)
{
SOGLB_DEBUGGROUP("csm-pass/" + std::to_string(i));
Expand All @@ -147,24 +145,32 @@ void Presenter::renderWorld(const ObjectManager& objectManager,
visitor.visit(*child);
}
}
m_csm->beginActiveSync();
}
gl::FenceSync::block();

for(size_t i = 0; i < render::scene::CSMBuffer::NSplits; ++i)
{
SOGLB_DEBUGGROUP("csm-pass-square/" + std::to_string(i));
m_csm->setActiveSplit(i);
m_csm->waitActiveSync();
m_csm->renderSquare();
m_csm->beginActiveSync();
}
gl::FenceSync::block();

for(size_t i = 0; i < render::scene::CSMBuffer::NSplits; ++i)
{
SOGLB_DEBUGGROUP("csm-pass-blur/" + std::to_string(i));
m_csm->setActiveSplit(i);
m_csm->waitActiveSync();
m_csm->renderBlur();
m_csm->beginActiveSync();
}

for(size_t i = 0; i < render::scene::CSMBuffer::NSplits; ++i)
{
m_csm->setActiveSplit(i);
m_csm->waitActiveSync();
}
gl::FenceSync::block();
}

{
Expand Down
17 changes: 17 additions & 0 deletions src/render/scene/csm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstddef>
#include <cstdint>
#include <gl/buffer.h>
#include <gl/fencesync.h>
#include <gl/pixel.h>
#include <gl/renderstate.h>
#include <gl/soglb_fwd.h>
Expand Down Expand Up @@ -49,6 +50,7 @@ class CSM final
std::shared_ptr<Material> squareMaterial{};
std::shared_ptr<Mesh> squareMesh{};
std::shared_ptr<SeparableBlur<gl::RG16F>> squareBlur;
mutable std::unique_ptr<gl::FenceSync> sync;

void init(int32_t resolution, size_t idx, MaterialManager& materialManager);
void renderSquare();
Expand All @@ -74,6 +76,21 @@ class CSM final
return m_splits.at(m_activeSplit).depthFramebuffer;
}

void beginActiveSync() const
{
m_splits.at(m_activeSplit).sync = std::make_unique<gl::FenceSync>();
}

void waitActiveSync() const
{
auto& sync = m_splits.at(m_activeSplit).sync;
if(sync == nullptr)
return;

sync->wait();
sync.reset();
}

void setActiveSplit(size_t idx)
{
Expects(idx < m_splits.size());
Expand Down

0 comments on commit 18d8da0

Please sign in to comment.