From 2d7813f658e70039d416b559c226c817b63faae5 Mon Sep 17 00:00:00 2001 From: "V. Shirokii" Date: Sun, 16 Jun 2024 09:19:39 +0100 Subject: [PATCH] CPU perf: do not upload static parts if gltf scene is present --- src/common/rendering/rt/rt_cvars.h | 2 +- src/common/rendering/rt/rt_helpers.h | 1 + src/common/rendering/rt/rt_main.cpp | 44 +++++++++++++++++++--- src/rendering/hwrenderer/scene/hw_bsp.cpp | 46 ++++++++++++++++++++--- 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/common/rendering/rt/rt_cvars.h b/src/common/rendering/rt/rt_cvars.h index d08f9785d..35b595463 100644 --- a/src/common/rendering/rt/rt_cvars.h +++ b/src/common/rendering/rt/rt_cvars.h @@ -5,7 +5,6 @@ namespace cvar { -EXTERN_CVAR( Int, rt_cpu_cullmode ) EXTERN_CVAR( Float, rt_cpu_nocullradius ) EXTERN_CVAR( Float, rt_classic ) @@ -39,5 +38,6 @@ extern bool rt_firststart; } +extern int rt_cullmode; #define rt_only_one_side_wall true #define rt_nocull_flat true diff --git a/src/common/rendering/rt/rt_helpers.h b/src/common/rendering/rt/rt_helpers.h index 4219184d0..b3e97093e 100644 --- a/src/common/rendering/rt/rt_helpers.h +++ b/src/common/rendering/rt/rt_helpers.h @@ -7,6 +7,7 @@ struct seg_t; void RT_BakeExportables( const std::vector< bool >& animatedTexnums ); bool RT_IsSectorExportable( const sector_t* sector, bool ceiling ); +bool RT_IsSectorExportable2( int sectornum, bool ceiling ); bool RT_IsWallExportable( const seg_t* seg ); void RT_RequestMelt(); diff --git a/src/common/rendering/rt/rt_main.cpp b/src/common/rendering/rt/rt_main.cpp index 5d95ba391..cc56da375 100644 --- a/src/common/rendering/rt/rt_main.cpp +++ b/src/common/rendering/rt/rt_main.cpp @@ -263,6 +263,7 @@ const char* g_rt_cutscenename = nullptr; bool g_rt_showfirststartscene = false; int g_rt_skipinitframes = -10; // to prevent flashing when starting the game bool g_rt_forcenofocuschange = true; +int rt_cullmode = 2; // 0 -- balanced, 1 -- original gzdoom, 2 -- none extern void RT_CloseLauncherWindow(); @@ -2927,6 +2928,8 @@ void RTFrameBuffer::RT_BeginFrame() .particleRadius = cvar::rt_fluid_pradius, }; + RgStaticSceneStatusFlags staticscene_status = 0; + auto info = RgStartFrameInfo{ .sType = RG_STRUCTURE_TYPE_START_FRAME_INFO, .pNext = &fluid_params, @@ -2938,11 +2941,34 @@ void RTFrameBuffer::RT_BeginFrame() .lightmapScreenCoverage = RT_ForceNoClassicMode() ? 0.0f : cvar::rt_classic, .lightstyleValuesCount = uint32_t( g_sectorlightlevels.size() ), .pLightstyleValues8 = g_sectorlightlevels.data(), + .pResultStaticSceneStatus = &staticscene_status, }; g_resetfluid = false; RgResult r = rt.rgStartFrame( &info ); RG_CHECK( r ); + + + if( staticscene_status & RG_STATIC_SCENE_STATUS_LOADED ) + { + if( staticscene_status & RG_STATIC_SCENE_STATUS_NEW_SCENE_STARTED ) + { + rt_cullmode = 2; // no cull as we need to upload all geometry for the first time + } + else + { + switch( int( cvar::rt_cpu_cullmode ) ) + { + case 1: rt_cullmode = 1; break; + case 2: rt_cullmode = 2; break; + default: rt_cullmode = 0; break; + } + } + } + else + { + rt_cullmode = 2; // no static scene, upload everything + } } void RTFrameBuffer::RT_DrawFrame() @@ -3940,14 +3966,13 @@ void RT_BakeExportables( const std::vector< bool >& animatedTexnums ) } } -bool RT_IsSectorExportable( const sector_t* sector, bool ceiling ) +bool RT_IsSectorExportable2( int sectornum, bool ceiling ) { - if( sector && sector->sectornum >= 0 ) + if( sectornum >= 0 ) { - const auto& arr = ceiling ? rt_sectorCeilingExportable : rt_sectorFloorExportable; - const auto sectornum = static_cast< uint32_t >( sector->sectornum ); + const auto& arr = ceiling ? rt_sectorCeilingExportable : rt_sectorFloorExportable; - if( sectornum < arr.size() ) + if( sectornum < int( arr.size() ) ) { return arr[ sectornum ]; } @@ -3955,6 +3980,15 @@ bool RT_IsSectorExportable( const sector_t* sector, bool ceiling ) return false; } +bool RT_IsSectorExportable( const sector_t* sector, bool ceiling ) +{ + if( sector ) + { + return RT_IsSectorExportable2( sector->sectornum, ceiling ); + } + return false; +} + bool RT_IsWallExportable( const seg_t* seg ) { if( seg && seg->segnum >= 0 ) diff --git a/src/rendering/hwrenderer/scene/hw_bsp.cpp b/src/rendering/hwrenderer/scene/hw_bsp.cpp index 0b11aacd6..3b114fed8 100644 --- a/src/rendering/hwrenderer/scene/hw_bsp.cpp +++ b/src/rendering/hwrenderer/scene/hw_bsp.cpp @@ -54,6 +54,7 @@ EXTERN_CVAR(Float, r_actorspriteshadowdist) #if HAVE_RT #include "rt/rt_cvars.h" +#include "rt/rt_helpers.h" static bool rt_nocull = false; static std::vector< bool > rt_segdrawn = {}; @@ -376,6 +377,19 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip) if (gl_render_walls) { +#if HAVE_RT + bool needupload = true; + if( rt_cullmode == 0 ) + { + if( RT_IsWallExportable( seg ) ) + { + needupload = false; + } + } + + if( needupload ) + { +#endif if (multithread) { jobQueue.AddJob(RenderJob::WallJob, seg->Subsector, seg); @@ -390,6 +404,9 @@ void HWDrawInfo::AddLine (seg_t *seg, bool portalclip) rendered_lines++; SetupWall.Unclock(); } +#if HAVE_RT + } // if( needupload ) +#endif #if HAVE_RT if( seg->segnum >= 0 && seg->segnum < int( rt_segdrawn.size() ) ) @@ -800,6 +817,20 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) { srf |= SSRF_PROCESSED; +#if HAVE_RT + bool needupload = true; + if( rt_cullmode == 0 ) + { + if( RT_IsSectorExportable2( sector->sectornum, false ) && + RT_IsSectorExportable2( sector->sectornum, true ) ) + { + needupload = false; + } + } + + if( needupload ) + { +#endif if (multithread) { jobQueue.AddJob(RenderJob::FlatJob, sub); @@ -812,6 +843,9 @@ void HWDrawInfo::DoSubsector(subsector_t * sub) flat.ProcessSector(this, fakesector); SetupFlat.Unclock(); } +#if HAVE_RT + } // if( needupload ) +#endif } // mark subsector as processed - but mark for rendering only if it has an actual area. ss_renderflags[sub->Index()] = @@ -877,7 +911,7 @@ void HWDrawInfo::RenderBSPNode (void *node) } #if HAVE_RT - if( cvar::rt_cpu_cullmode == 2 ) + if( rt_cullmode == 2 ) { for( subsector_t& s : Level->subsectors ) { @@ -888,7 +922,7 @@ void HWDrawInfo::RenderBSPNode (void *node) if( rt_nocull ) { - assert( cvar::rt_cpu_cullmode != 1 && cvar::rt_cpu_cullmode != 2 ); + assert( rt_cullmode != 1 && rt_cullmode != 2 ); static auto rt_sectorvis = std::vector< bool >{}; rt_sectorvis.resize( Level->sectors.size() ); @@ -1106,12 +1140,12 @@ void HWDrawInfo::RenderBSP(void *node, bool drawpsprites) #if !HAVE_RT RenderBSPNode(node); #else - if( cvar::rt_cpu_cullmode != 2 ) + if( rt_cullmode != 2 ) { rt_nocull = false; RenderBSPNode( node ); } - if( cvar::rt_cpu_cullmode != 1 ) + if( rt_cullmode != 1 ) { rt_nocull = true; RenderBSPNode( node ); @@ -1129,12 +1163,12 @@ void HWDrawInfo::RenderBSP(void *node, bool drawpsprites) #if !HAVE_RT RenderBSPNode(node); #else - if( cvar::rt_cpu_cullmode != 2 ) + if( rt_cullmode != 2 ) { rt_nocull = false; RenderBSPNode( node ); } - if( cvar::rt_cpu_cullmode != 1 ) + if( rt_cullmode != 1 ) { rt_nocull = true; RenderBSPNode( node );