Split Culling into it's own thread

This commit is contained in:
2024-02-23 02:53:57 -05:00
parent 74352d68f1
commit 34ceb1a43d
4 changed files with 53 additions and 20 deletions

View File

@@ -149,15 +149,6 @@ namespace fgl::engine
camera_controller.moveInPlaneXZ( m_window.window(), delta_time, viewer );
camera.setView( viewer.transform.translation, viewer.transform.rotation );
{
constexpr WorldCoordinate center { 0.0f, 0.0f, 0.0f };
//debug::world::drawVector( center, camera.getForward(), camera, { 0.0f, 0.0f, 0.0f } );
{
debug::world::drawFrustum( camera );
}
}
if ( auto command_buffer = m_renderer.beginFrame(); command_buffer )
{
ZoneScopedN( "Render" );
@@ -400,9 +391,16 @@ namespace fgl::engine
}
#endif
m_culling_system.startPass( frame_info );
#if TRACY_ENABLE
TracyVkCollect( frame_info.tracy_ctx, command_buffer );
#endif
m_culling_system.wait();
m_renderer.beginSwapchainRendererPass( command_buffer );
m_culling_system.pass( frame_info );
m_entity_renderer.pass( frame_info );
#if ENABLE_IMGUI
@@ -424,14 +422,8 @@ namespace fgl::engine
m_renderer.endSwapchainRendererPass( command_buffer );
#if TRACY_ENABLE
TracyVkCollect( frame_info.tracy_ctx, command_buffer );
#endif
m_renderer.endFrame();
std::this_thread::sleep_until( new_time + std::chrono::milliseconds( 16 ) );
FrameMark;
}
}
@@ -471,6 +463,8 @@ namespace fgl::engine
m_entity_renderer.getVertexBuffer(),
m_entity_renderer.getIndexBuffer() ) };
model->syncBuffers( command_buffer );
for ( int x = 0; x < 32; ++x )
{
for ( int y = 0; y < 32; ++y )
@@ -481,8 +475,6 @@ namespace fgl::engine
sponza.transform.scale = { 0.007f, 0.007f, 0.007f };
sponza.transform.rotation = { 0.0f, 0.0f, 0.0f };
sponza.model->syncBuffers( command_buffer );
game_objects.emplace( sponza.getId(), std::move( sponza ) );
}
}

View File

@@ -4,6 +4,8 @@
#include "CullingSystem.hpp"
#include <tracy/TracyC.h>
#include "engine/debug/drawers.hpp"
#include "engine/model/BoundingBox.hpp"
#include "engine/model/Model.hpp"
@@ -13,7 +15,7 @@ namespace fgl::engine
void CullingSystem::pass( FrameInfo& info )
{
ZoneScoped;
ZoneScopedN( "Culling pass" );
const auto frustum { info.camera_frustum };
@@ -39,4 +41,26 @@ namespace fgl::engine
}
}
void CullingSystem::runner()
{
TracyCSetThreadName( "Culling thread" );
while ( !m_stop_token.stop_requested() )
{
m_start_sem.acquire();
pass( *m_info.value() );
m_end_sem.release();
}
}
void CullingSystem::startPass( FrameInfo& info )
{
m_info = &info;
m_start_sem.release();
}
void CullingSystem::wait()
{
m_end_sem.acquire();
}
} // namespace fgl::engine

View File

@@ -11,9 +11,26 @@ namespace fgl::engine
class CullingSystem
{
std::thread m_thread;
std::optional< FrameInfo* > m_info;
std::stop_token m_stop_token;
void runner();
//Semaphore to signal the thread to start
std::binary_semaphore m_start_sem { 0 };
std::binary_semaphore m_end_sem { 0 };
public:
CullingSystem() : m_thread( &CullingSystem::runner, this ) {}
void pass( FrameInfo& info );
void startPass( FrameInfo& info );
void wait();
};
} // namespace fgl::engine

View File

@@ -77,7 +77,7 @@ namespace fgl::engine
void EntityRendererSystem::pass( FrameInfo& info )
{
ZoneScoped;
ZoneScopedN( "Entity pass" );
auto& command_buffer { info.command_buffer };
{
TracyVkZone( info.tracy_ctx, command_buffer, "Render game objects" );