From d6a43278dbea4160e60e6a7b29078e1cfde0eb23 Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Fri, 1 Apr 2022 13:55:34 +0200 Subject: [PATCH] Don't use atlas for interactions that didn't fit into the atlas --- neo/framework/Common_local.h | 5 +++++ neo/framework/Console.cpp | 12 +++++++----- neo/idlib/RectAllocator.cpp | 3 ++- neo/renderer/Image_load.cpp | 13 +++++++++---- neo/renderer/RenderBackend.cpp | 26 +++++++++++++++++--------- neo/renderer/RenderCommon.h | 5 +++++ neo/renderer/RenderLog.cpp | 4 ++++ neo/renderer/RenderSystem.h | 1 + 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/neo/framework/Common_local.h b/neo/framework/Common_local.h index b19e0724..123a7d24 100644 --- a/neo/framework/Common_local.h +++ b/neo/framework/Common_local.h @@ -353,6 +353,11 @@ public: return stats_backend.gpuAmbientPassMicroSec; } + uint64 GetRendererGpuShadowAtlasPassMicroseconds() const + { + return stats_backend.gpuShadowAtlasPassMicroSec; + } + uint64 GetRendererGpuInteractionsMicroseconds() const { return stats_backend.gpuInteractionsMicroSec; diff --git a/neo/framework/Console.cpp b/neo/framework/Console.cpp index f3b9c8d6..c83e8292 100644 --- a/neo/framework/Console.cpp +++ b/neo/framework/Console.cpp @@ -288,6 +288,7 @@ float idConsoleLocal::DrawFPS( float y ) const uint64 rendererGPU_SSAOTime = commonLocal.GetRendererGpuSSAOMicroseconds(); const uint64 rendererGPU_SSRTime = commonLocal.GetRendererGpuSSRMicroseconds(); const uint64 rendererGPUAmbientPassTime = commonLocal.GetRendererGpuAmbientPassMicroseconds(); + const uint64 rendererGPUShadowAtlasPassTime = commonLocal.GetRendererGpuShadowAtlasPassMicroseconds(); const uint64 rendererGPUInteractionsTime = commonLocal.GetRendererGpuInteractionsMicroseconds(); const uint64 rendererGPUShaderPassesTime = commonLocal.GetRendererGpuShaderPassMicroseconds(); const uint64 rendererGPUPostProcessingTime = commonLocal.GetRendererGpuPostProcessingMicroseconds(); @@ -308,12 +309,12 @@ float idConsoleLocal::DrawFPS( float y ) { // start smaller int32 statsWindowWidth = 320; - int32 statsWindowHeight = 260; + int32 statsWindowHeight = 270; if( com_showFPS.GetInteger() > 2 ) { - statsWindowWidth = 550; - statsWindowHeight = 370; + statsWindowWidth += 230; + statsWindowHeight += 110; } ImVec2 pos; @@ -429,9 +430,10 @@ float idConsoleLocal::DrawFPS( float y ) ImGui::TextColored( gameThreadTotalTime > maxTime ? colorRed : colorWhite, "Game+RF: %5llu us EarlyZ: %5llu us", gameThreadTotalTime, rendererGPUEarlyZTime ); ImGui::TextColored( gameThreadGameTime > maxTime ? colorRed : colorWhite, "Game: %5llu us SSAO: %5llu us", gameThreadGameTime, rendererGPU_SSAOTime ); ImGui::TextColored( gameThreadRenderTime > maxTime ? colorRed : colorWhite, "RF: %5llu us SSR: %5llu us", gameThreadRenderTime, rendererGPU_SSRTime ); - ImGui::TextColored( rendererBackEndTime > maxTime ? colorRed : colorWhite, "RB: %5llu us AmbientPass: %5llu us", rendererBackEndTime, rendererGPUAmbientPassTime ); + ImGui::TextColored( rendererBackEndTime > maxTime ? colorRed : colorWhite, "RB: %5llu us Ambient Pass: %5llu us", rendererBackEndTime, rendererGPUAmbientPassTime ); + ImGui::TextColored( rendererShadowsTime > maxTime ? colorRed : colorWhite, " Shadow Atlas: %5llu us", rendererGPUShadowAtlasPassTime ); ImGui::TextColored( rendererShadowsTime > maxTime ? colorRed : colorWhite, "Shadows: %5llu us Interactions: %5llu us", rendererShadowsTime, rendererGPUInteractionsTime ); - ImGui::TextColored( rendererGPUShaderPassesTime > maxTime ? colorRed : colorWhite, " ShaderPass: %5llu us", rendererGPUShaderPassesTime ); + ImGui::TextColored( rendererGPUShaderPassesTime > maxTime ? colorRed : colorWhite, " Shader Pass: %5llu us", rendererGPUShaderPassesTime ); ImGui::TextColored( rendererGPUPostProcessingTime > maxTime ? colorRed : colorWhite, " PostFX: %5llu us", rendererGPUPostProcessingTime ); ImGui::TextColored( totalCPUTime > maxTime || rendererGPUTime > maxTime ? colorRed : colorWhite, "Total: %5llu us Total: %5llu us", totalCPUTime, rendererGPUTime ); diff --git a/neo/idlib/RectAllocator.cpp b/neo/idlib/RectAllocator.cpp index 8520edf5..c3659c7d 100644 --- a/neo/idlib/RectAllocator.cpp +++ b/neo/idlib/RectAllocator.cpp @@ -293,7 +293,7 @@ void RectAllocatorBinPack2D( const idList& inputSizes, const idStrList& #endif } - +#if 0 for( binpack2d_iterator itor = remainder.Get().begin(); itor != remainder.Get().end(); itor++ ) { const BinPack2D::Content& content = *itor; @@ -309,4 +309,5 @@ void RectAllocatorBinPack2D( const idList& inputSizes, const idStrList& content.size.w, content.size.h ); } +#endif } \ No newline at end of file diff --git a/neo/renderer/Image_load.cpp b/neo/renderer/Image_load.cpp index 2a698bb7..f883f569 100644 --- a/neo/renderer/Image_load.cpp +++ b/neo/renderer/Image_load.cpp @@ -759,20 +759,22 @@ StorageSize */ int idImage::StorageSize() const { - if( !IsLoaded() ) { return 0; } - int baseSize = opts.width * opts.height; - if( opts.numLevels > 1 ) + + size_t baseSize = opts.width * opts.height; + if( opts.numLevels > 1 && !opts.isRenderTarget ) { baseSize *= 4; baseSize /= 3; } + baseSize *= BitsForFormat( opts.format ); baseSize /= 8; - return baseSize; + + return int( baseSize ); } /* @@ -835,11 +837,14 @@ void idImage::Print() const NAME_FORMAT( RGBA16F ); NAME_FORMAT( RGBA32F ); NAME_FORMAT( R32F ); + NAME_FORMAT( R8 ); NAME_FORMAT( R11G11B10F ); // RB end NAME_FORMAT( DEPTH ); + NAME_FORMAT( DEPTH_STENCIL ); NAME_FORMAT( X16 ); NAME_FORMAT( Y16_X16 ); + NAME_FORMAT( SRGB8 ); default: common->Printf( "<%3i>", opts.format ); break; diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index b8b71e14..bbeee7ba 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -1229,7 +1229,7 @@ void idRenderBackend::DrawSingleInteraction( drawInteraction_t* din, bool useFas } else { - if( r_useShadowMapping.GetBool() && din->vLight->globalShadows ) + if( r_useShadowMapping.GetBool() && din->vLight->globalShadows && din->vLight->ImageAtlasPlaced() ) { // RB: we have shadow mapping enabled and shadow maps so do a shadow compare @@ -1297,7 +1297,7 @@ void idRenderBackend::DrawSingleInteraction( drawInteraction_t* din, bool useFas } else { - if( r_useShadowMapping.GetBool() && din->vLight->globalShadows ) + if( r_useShadowMapping.GetBool() && din->vLight->globalShadows && din->vLight->ImageAtlasPlaced() ) { // RB: we have shadow mapping enabled and shadow maps so do a shadow compare @@ -1498,7 +1498,7 @@ void idRenderBackend::RenderInteractions( const drawSurf_t* surfList, const view bool lightDepthBoundsDisabled = false; // RB begin - if( r_useShadowMapping.GetBool() ) + if( r_useShadowMapping.GetBool() && vLight->ImageAtlasPlaced() ) { const static int JITTER_SIZE = 128; @@ -1736,7 +1736,7 @@ void idRenderBackend::RenderInteractions( const drawSurf_t* surfList, const view SetVertexParm( RENDERPARM_LIGHTFALLOFF_S, lightProjection[3].ToFloatPtr() ); // RB begin - if( r_useShadowMapping.GetBool() ) + if( r_useShadowMapping.GetBool() && vLight->ImageAtlasPlaced() ) { if( vLight->parallel ) { @@ -3380,7 +3380,7 @@ void idRenderBackend::ShadowMapPassFast( const drawSurf_t* drawSurfs, viewLight_ if( atlas ) { - //globalFramebuffers.shadowAtlasFBO->Bind(); + globalFramebuffers.shadowAtlasFBO->Bind(); // TODO light offset in atlas @@ -3434,7 +3434,7 @@ void idRenderBackend::ShadowMapPassFast( const drawSurf_t* drawSurfs, viewLight_ for( const drawSurf_t* drawSurf = drawSurfs; drawSurf != NULL; drawSurf = drawSurf->nextOnLight ) { -#if 1 +#if 0 // make sure the shadow occluder geometry is done if( drawSurf->shadowVolumeState != SHADOWVOLUME_DONE ) { @@ -3945,8 +3945,8 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef ) continue; } - const idMaterial* lightShader = vLight->lightShader; - renderLog.OpenBlock( lightShader->GetName(), colorMdGrey ); + //const idMaterial* lightShader = vLight->lightShader; + //renderLog.OpenBlock( lightShader->GetName(), colorMdGrey ); // set the depth bounds for the whole light if( useLightDepthBounds ) @@ -3983,6 +3983,8 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef ) vLight->imageSize.x = shadowMapResolutions[ vLight->shadowLOD ]; vLight->imageSize.y = shadowMapResolutions[ vLight->shadowLOD ]; + bool imageFitsIntoAtlas = true; + for( ; side < sideStop ; side++ ) { int slice = Max( 0, side ); @@ -3995,13 +3997,19 @@ void idRenderBackend::ShadowAtlasPass( const viewDef_t* _viewDef ) if( vLight->imageAtlasOffset[ slice ].x == -1 || vLight->imageAtlasOffset[ slice ].y == -1 ) { // didn't fit into atlas anymore + imageFitsIntoAtlas = false; continue; } ShadowMapPassFast( vLight->globalShadows, vLight, side, true ); } - renderLog.CloseBlock(); + if( !imageFitsIntoAtlas ) + { + vLight->imageSize.x = -1; + } + + //renderLog.CloseBlock(); } // go back to main render target diff --git a/neo/renderer/RenderCommon.h b/neo/renderer/RenderCommon.h index b49ca699..aa695800 100644 --- a/neo/renderer/RenderCommon.h +++ b/neo/renderer/RenderCommon.h @@ -434,6 +434,11 @@ struct viewLight_t // R_AddSingleLight will build a chain of parameters here to setup shadow volumes preLightShadowVolumeParms_t* preLightShadowVolumes; + + bool ImageAtlasPlaced() const + { + return ( imageSize.x != -1 ) && ( imageSize.y != -1 ); + } }; // a viewEntity is created whenever a idRenderEntityLocal is considered for inclusion diff --git a/neo/renderer/RenderLog.cpp b/neo/renderer/RenderLog.cpp index 1f15bac5..315f8106 100644 --- a/neo/renderer/RenderLog.cpp +++ b/neo/renderer/RenderLog.cpp @@ -490,6 +490,10 @@ void idRenderLog::FetchGPUTimers( backEndCounters_t& pc ) { pc.gpuAmbientPassMicroSec = time; } + else if( i == MRB_SHADOW_ATLAS_PASS ) + { + pc.gpuShadowAtlasPassMicroSec = time; + } else if( i == MRB_DRAW_INTERACTIONS ) { pc.gpuInteractionsMicroSec = time; diff --git a/neo/renderer/RenderSystem.h b/neo/renderer/RenderSystem.h index 9aec1a04..d15a9d97 100644 --- a/neo/renderer/RenderSystem.h +++ b/neo/renderer/RenderSystem.h @@ -161,6 +161,7 @@ struct backEndCounters_t uint64 gpuScreenSpaceAmbientOcclusionMicroSec; uint64 gpuScreenSpaceReflectionsMicroSec; uint64 gpuAmbientPassMicroSec; + uint64 gpuShadowAtlasPassMicroSec; uint64 gpuInteractionsMicroSec; uint64 gpuShaderPassMicroSec; uint64 gpuPostProcessingMicroSec;