@@ -422,8 +422,8 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau
422422
423423 // Initial state of the RTHandle system.
424424 // Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
425- // TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
426- RTHandles . Initialize ( 1 , 1 , m_Asset . currentPlatformRenderPipelineSettings . supportMSAA , m_Asset . currentPlatformRenderPipelineSettings . msaaSampleCount ) ;
425+ // We initialize to screen width/height to avoid multiple realloc that can lead to inflated memory usage (as releasing of memory is delayed).
426+ RTHandles . Initialize ( Screen . width , Screen . height , m_Asset . currentPlatformRenderPipelineSettings . supportMSAA , m_Asset . currentPlatformRenderPipelineSettings . msaaSampleCount ) ;
427427
428428 m_XRSystem = new XRSystem ( asset . renderPipelineResources . shaders ) ;
429429 m_GPUCopy = new GPUCopy ( defaultResources . shaders . copyChannelCS ) ;
@@ -2007,6 +2007,29 @@ ref _cullingResults
20072007
20082008 using ( new ProfilingScope ( null , ProfilingSampler . Get ( HDProfileId . HDRenderPipelineAllRenderRequest ) ) )
20092009 {
2010+
2011+ // Warm up the RTHandle system so that it gets init to the maximum resolution available (avoiding to call multiple resizes
2012+ // that can lead to high memory spike as the memory release is delayed while the creation is immediate).
2013+ {
2014+ Vector2Int maxSize = new Vector2Int ( 1 , 1 ) ;
2015+
2016+ for ( int i = renderRequestIndicesToRender . Count - 1 ; i >= 0 ; -- i )
2017+ {
2018+ var renderRequestIndex = renderRequestIndicesToRender [ i ] ;
2019+ var renderRequest = renderRequests [ renderRequestIndex ] ;
2020+ var hdCamera = renderRequest . hdCamera ;
2021+
2022+ maxSize . x = Math . Max ( ( int ) hdCamera . finalViewport . size . x , maxSize . x ) ;
2023+ maxSize . y = Math . Max ( ( int ) hdCamera . finalViewport . size . y , maxSize . y ) ;
2024+ }
2025+
2026+ // Here we use the non scaled resolution for the RTHandleSystem ref size because we assume that at some point we will need full resolution anyway.
2027+ // This is necessary because we assume that after post processes, we have the full size render target for debug rendering
2028+ // The only point of calling this here is to grow the render targets. The call in BeginRender will setup the current RTHandle viewport size.
2029+ RTHandles . SetReferenceSize ( maxSize . x , maxSize . y , m_MSAASamples ) ;
2030+ }
2031+
2032+
20102033 // Execute render request graph, in reverse order
20112034 for ( int i = renderRequestIndicesToRender . Count - 1 ; i >= 0 ; -- i )
20122035 {
0 commit comments