@@ -377,8 +377,8 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau
377377
378378 // Initial state of the RTHandle system.
379379 // Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
380- // TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
381- RTHandles . Initialize ( 1 , 1 , m_Asset . currentPlatformRenderPipelineSettings . supportMSAA , m_Asset . currentPlatformRenderPipelineSettings . msaaSampleCount ) ;
380+ // We initialize to screen width/height to avoid multiple realloc that can lead to inflated memory usage (as releasing of memory is delayed).
381+ RTHandles . Initialize ( Screen . width , Screen . height , m_Asset . currentPlatformRenderPipelineSettings . supportMSAA , m_Asset . currentPlatformRenderPipelineSettings . msaaSampleCount ) ;
382382
383383 m_XRSystem = new XRSystem ( asset . renderPipelineResources . shaders ) ;
384384 m_GPUCopy = new GPUCopy ( defaultResources . shaders . copyChannelCS ) ;
@@ -1811,6 +1811,29 @@ ref _cullingResults
18111811
18121812 using ( new ProfilingScope ( null , ProfilingSampler . Get ( HDProfileId . HDRenderPipelineAllRenderRequest ) ) )
18131813 {
1814+
1815+ // Warm up the RTHandle system so that it gets init to the maximum resolution available (avoiding to call multiple resizes
1816+ // that can lead to high memory spike as the memory release is delayed while the creation is immediate).
1817+ {
1818+ Vector2Int maxSize = new Vector2Int ( 1 , 1 ) ;
1819+
1820+ for ( int i = renderRequestIndicesToRender . Count - 1 ; i >= 0 ; -- i )
1821+ {
1822+ var renderRequestIndex = renderRequestIndicesToRender [ i ] ;
1823+ var renderRequest = renderRequests [ renderRequestIndex ] ;
1824+ var hdCamera = renderRequest . hdCamera ;
1825+
1826+ maxSize . x = Math . Max ( ( int ) hdCamera . finalViewport . size . x , maxSize . x ) ;
1827+ maxSize . y = Math . Max ( ( int ) hdCamera . finalViewport . size . y , maxSize . y ) ;
1828+ }
1829+
1830+ // 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.
1831+ // This is necessary because we assume that after post processes, we have the full size render target for debug rendering
1832+ // The only point of calling this here is to grow the render targets. The call in BeginRender will setup the current RTHandle viewport size.
1833+ RTHandles . SetReferenceSize ( maxSize . x , maxSize . y , m_MSAASamples ) ;
1834+ }
1835+
1836+
18141837 // Execute render request graph, in reverse order
18151838 for ( int i = renderRequestIndicesToRender . Count - 1 ; i >= 0 ; -- i )
18161839 {
0 commit comments