Skip to content

Pre warm RT Handle system so that reallocations are reduced. #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ private RenderGraphResourceRegistry()

internal RenderGraphResourceRegistry(bool supportMSAA, MSAASamples initialSampleCount, RenderGraphDebugParams renderGraphDebug, RenderGraphLogger logger)
{
m_RTHandleSystem.Initialize(1, 1, supportMSAA, initialSampleCount);
// We initialize to screen width/height to avoid multiple realloc that can lead to inflated memory usage (as releasing of memory is delayed).
m_RTHandleSystem.Initialize(Screen.width, Screen.height, supportMSAA, initialSampleCount);
m_RenderGraphDebug = renderGraphDebug;
m_Logger = logger;
}
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Removed experimental namespace for ray tracing code.
- Increase limit for max numbers of lights in UX
- Removed direct use of BSDFData in the path tracing pass, delegated to the material instead.
- Pre-warm the RTHandle system to reduce the amount of memory allocations and the total memory needed at all points.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,6 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp,

HDRenderPipeline.UpdateVolumetricBufferParams(this, hdrp.GetFrameCount());
HDRenderPipeline.ResizeVolumetricHistoryBuffers(this, hdrp.GetFrameCount());

// 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.
// This is necessary because we assume that after post processes, we have the full size render target for debug rendering
// The only point of calling this here is to grow the render targets. The call in BeginRender will setup the current RTHandle viewport size.
RTHandles.SetReferenceSize(nonScaledViewport.x, nonScaledViewport.y, msaaSamples);
}

/// <summary>Set the RTHandle scale to the actual camera size (can be scaled)</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau

// Initial state of the RTHandle system.
// Tells the system that we will require MSAA or not so that we can avoid wasteful render texture allocation.
// TODO: Might want to initialize to at least the window resolution to avoid un-necessary re-alloc in the player
RTHandles.Initialize(1, 1, m_Asset.currentPlatformRenderPipelineSettings.supportMSAA, m_Asset.currentPlatformRenderPipelineSettings.msaaSampleCount);
// We initialize to screen width/height to avoid multiple realloc that can lead to inflated memory usage (as releasing of memory is delayed).
RTHandles.Initialize(Screen.width, Screen.height, m_Asset.currentPlatformRenderPipelineSettings.supportMSAA, m_Asset.currentPlatformRenderPipelineSettings.msaaSampleCount);

m_XRSystem = new XRSystem(asset.renderPipelineResources.shaders);
m_GPUCopy = new GPUCopy(defaultResources.shaders.copyChannelCS);
Expand Down Expand Up @@ -2007,6 +2007,29 @@ ref _cullingResults

using (new ProfilingScope(null, ProfilingSampler.Get(HDProfileId.HDRenderPipelineAllRenderRequest)))
{

// Warm up the RTHandle system so that it gets init to the maximum resolution available (avoiding to call multiple resizes
// that can lead to high memory spike as the memory release is delayed while the creation is immediate).
{
Vector2Int maxSize = new Vector2Int(1, 1);

for (int i = renderRequestIndicesToRender.Count - 1; i >= 0; --i)
{
var renderRequestIndex = renderRequestIndicesToRender[i];
var renderRequest = renderRequests[renderRequestIndex];
var hdCamera = renderRequest.hdCamera;

maxSize.x = Math.Max((int)hdCamera.finalViewport.size.x, maxSize.x);
maxSize.y = Math.Max((int)hdCamera.finalViewport.size.y, maxSize.y);
}

// 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.
// This is necessary because we assume that after post processes, we have the full size render target for debug rendering
// The only point of calling this here is to grow the render targets. The call in BeginRender will setup the current RTHandle viewport size.
RTHandles.SetReferenceSize(maxSize.x, maxSize.y, m_MSAASamples);
}


// Execute render request graph, in reverse order
for (int i = renderRequestIndicesToRender.Count - 1; i >= 0; --i)
{
Expand Down