Skip to content

Commit

Permalink
CPU perf: do not upload static parts if gltf scene is present
Browse files Browse the repository at this point in the history
  • Loading branch information
vs-shirokii committed Jun 16, 2024
1 parent a478271 commit 2d7813f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/common/rendering/rt/rt_cvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace cvar
{

EXTERN_CVAR( Int, rt_cpu_cullmode )
EXTERN_CVAR( Float, rt_cpu_nocullradius )

EXTERN_CVAR( Float, rt_classic )
Expand Down Expand Up @@ -39,5 +38,6 @@ extern bool rt_firststart;

}

extern int rt_cullmode;
#define rt_only_one_side_wall true
#define rt_nocull_flat true
1 change: 1 addition & 0 deletions src/common/rendering/rt/rt_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
44 changes: 39 additions & 5 deletions src/common/rendering/rt/rt_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -3940,21 +3966,29 @@ 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 ];
}
}
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 )
Expand Down
46 changes: 40 additions & 6 deletions src/rendering/hwrenderer/scene/hw_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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);
Expand All @@ -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() ) )
Expand Down Expand Up @@ -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);
Expand All @@ -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()] =
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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() );
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand Down

0 comments on commit 2d7813f

Please sign in to comment.