Skip to content

Added a function to reset the reference size of RTHandle systems. #299

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 3 commits into from
May 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
11 changes: 11 additions & 0 deletions com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ public void UnRegisterDebug()
//m_DebugParameters.UnRegisterDebug();
}

/// <summary>
/// Resets the reference size of the internal RTHandle System.
/// This allows users to reduce the memory footprint of render textures after doing a super sampled rendering pass for example.
/// </summary>
/// <param name="width">New width of the internal RTHandle System.</param>
/// <param name="height">New height of the internal RTHandle System.</param>
public void ResetRTHandleReferenceSize(int width, int height)
{
m_Resources.ResetRTHandleReferenceSize(width, height);
}

/// <summary>
/// Import an external texture to the Render Graph.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,11 @@ internal void Clear()
#endif
}

internal void ResetRTHandleReferenceSize(int width, int height)
{
m_RTHandleSystem.ResetReferenceSize(width, height);
}

internal void Cleanup()
{
foreach (var value in m_TexturePool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public void SwapAndSetReferenceSize(int width, int height, MSAASamples msaaSampl
m_RTHandleSystem.SetReferenceSize(width, height, msaaSamples);
}

/// <summary>
/// Reset the reference size of the system and reallocate all textures.
/// </summary>
/// <param name="width">New width.</param>
/// <param name="height">New height.</param>
public void ResetReferenceSize(int width, int height)
{
m_RTHandleSystem.ResetReferenceSize(width, height);
}


void Swap()
{
foreach (var item in m_RTHandles)
Expand Down
16 changes: 14 additions & 2 deletions com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,25 @@ internal void Remove(RTHandle rth)
m_AutoSizedRTs.Remove(rth);
}

/// <summary>
/// Reset the reference size of the system and reallocate all textures.
/// </summary>
/// <param name="width">New width.</param>
/// <param name="height">New height.</param>
public void ResetReferenceSize(int width, int height)
{
m_MaxWidths = width;
m_MaxHeights = height;
SetReferenceSize(width, height, m_ScaledRTCurrentMSAASamples, reset: true);
}

/// <summary>
/// Sets the reference rendering size for subsequent rendering for the RTHandle System
/// </summary>
/// <param name="width">Reference rendering width for subsequent rendering.</param>
/// <param name="height">Reference rendering height for subsequent rendering.</param>
/// <param name="msaaSamples">Number of MSAA samples for multisampled textures for subsequent rendering.</param>
public void SetReferenceSize(int width, int height, MSAASamples msaaSamples)
public void SetReferenceSize(int width, int height, MSAASamples msaaSamples, bool reset = false)
{
m_RTHandleProperties.previousViewportSize = m_RTHandleProperties.currentViewportSize;
m_RTHandleProperties.previousRenderTargetSize = m_RTHandleProperties.currentRenderTargetSize;
Expand All @@ -140,7 +152,7 @@ public void SetReferenceSize(int width, int height, MSAASamples msaaSamples)
width = Mathf.Max(width, 1);
height = Mathf.Max(height, 1);

bool sizeChanged = width > GetMaxWidth() || height > GetMaxHeight();
bool sizeChanged = width > GetMaxWidth() || height > GetMaxHeight() || reset;
bool msaaSamplesChanged = (msaaSamples != m_ScaledRTCurrentMSAASamples);

if (sizeChanged || msaaSamplesChanged)
Expand Down
10 changes: 10 additions & 0 deletions com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,15 @@ MSAASamples msaaSamples
msaaSamples
);
}

/// <summary>
/// Reset the reference size of the system and reallocate all textures.
/// </summary>
/// <param name="width">New width.</param>
/// <param name="height">New height.</param>
public static void ResetReferenceSize(int width, int height)
{
s_DefaultInstance.ResetReferenceSize(width, height);
}
}
}
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 @@ -119,6 +119,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added Min distance to contact shadows.
- Added support for Depth of Field in path tracing (by sampling the lens aperture).
- Added an API in HDRP to override the camera within the rendering of a frame (mainly for custom pass).
- Added a function (HDRenderPipeline.ResetRTHandleReferenceSize) to reset the reference size of RTHandle systems.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,20 @@ internal static void CleanUnused()
s_Cleanup.Clear();
}

internal static void ResetAllHistoryRTHandleSystems(int width, int height)
{
foreach (var kvp in s_Cameras)
{
var hdCamera = kvp.Value;
var currentHistorySize = hdCamera.m_HistoryRTSystem.rtHandleProperties.currentRenderTargetSize;
// We only reset if the new size if smaller than current reference (otherwise we might increase the size of off screen camera with lower resolution than the new reference.
if (width < currentHistorySize.x || height < currentHistorySize.y)
{
hdCamera.m_HistoryRTSystem.ResetReferenceSize(width, height);
}
}
}

unsafe internal void UpdateShaderVariablesGlobalCB(ref ShaderVariablesGlobal cb, int frameCount)
{
bool taaEnabled = frameSettings.IsEnabled(FrameSettingsField.Postprocess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,20 @@ void ValidateResources()

#endif

/// <summary>
/// Resets the reference size of the internal RTHandle System.
/// This allows users to reduce the memory footprint of render textures after doing a super sampled rendering pass for example.
/// </summary>
/// <param name="width">New width of the internal RTHandle System.</param>
/// <param name="height">New height of the internal RTHandle System.</param>
public void ResetRTHandleReferenceSize(int width, int height)
{
RTHandles.ResetReferenceSize(width, height);
HDCamera.ResetAllHistoryRTHandleSystems(width, height);
if (m_RenderGraph != null)
m_RenderGraph.ResetRTHandleReferenceSize(width, height);
}

void InitializeRenderTextures()
{
RenderPipelineSettings settings = m_Asset.currentPlatformRenderPipelineSettings;
Expand Down Expand Up @@ -1005,7 +1019,7 @@ void DisposeProbeCameraPool()
// Dispose of Render Pipeline can be call either by OnValidate() or by OnDisable().
// Inside an OnValidate() call we can't call a DestroyImmediate().
// Here we are releasing our singleton to not leak while doing a domain reload.
// However this is doing a call to DestroyImmediate().
// However this is doing a call to DestroyImmediate().
// To workaround this, and was we only leak with Singleton while doing domain reload (and not in OnValidate)
// we are detecting if we are in an OnValidate call and releasing the Singleton only if it is not the case.
if (!m_Asset.isInOnValidateCall)
Expand Down Expand Up @@ -3219,7 +3233,7 @@ void RenderDBuffer(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext
{
// We still bind black textures to make sure that something is bound (can be a problem on some platforms)
m_DbufferManager.BindBlackTextures(cmd);

// Bind buffer to make sure that something is bound .
cmd.SetGlobalBuffer(HDShaderIDs._DecalPropertyMaskBufferSRV, m_DbufferManager.propertyMaskBuffer);

Expand Down