diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
index a9f9c22b96c..aeeb5986e1a 100644
--- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
+++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
@@ -236,6 +236,17 @@ public void UnRegisterDebug()
//m_DebugParameters.UnRegisterDebug();
}
+ ///
+ /// 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.
+ ///
+ /// New width of the internal RTHandle System.
+ /// New height of the internal RTHandle System.
+ public void ResetRTHandleReferenceSize(int width, int height)
+ {
+ m_Resources.ResetRTHandleReferenceSize(width, height);
+ }
+
///
/// Import an external texture to the Render Graph.
///
diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs
index 292d96b51b4..f8b5fc64097 100644
--- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs
+++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs
@@ -659,6 +659,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)
diff --git a/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs
index 7d10f4fe881..51888e2e4aa 100644
--- a/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs
+++ b/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs
@@ -134,6 +134,17 @@ public void SwapAndSetReferenceSize(int width, int height, MSAASamples msaaSampl
m_RTHandleSystem.SetReferenceSize(width, height, msaaSamples);
}
+ ///
+ /// Reset the reference size of the system and reallocate all textures.
+ ///
+ /// New width.
+ /// New height.
+ public void ResetReferenceSize(int width, int height)
+ {
+ m_RTHandleSystem.ResetReferenceSize(width, height);
+ }
+
+
void Swap()
{
foreach (var item in m_RTHandles)
diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
index 155686bc188..2f75277b5af 100644
--- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
+++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
@@ -125,13 +125,25 @@ internal void Remove(RTHandle rth)
m_AutoSizedRTs.Remove(rth);
}
+ ///
+ /// Reset the reference size of the system and reallocate all textures.
+ ///
+ /// New width.
+ /// New height.
+ public void ResetReferenceSize(int width, int height)
+ {
+ m_MaxWidths = width;
+ m_MaxHeights = height;
+ SetReferenceSize(width, height, m_ScaledRTCurrentMSAASamples, reset: true);
+ }
+
///
/// Sets the reference rendering size for subsequent rendering for the RTHandle System
///
/// Reference rendering width for subsequent rendering.
/// Reference rendering height for subsequent rendering.
/// Number of MSAA samples for multisampled textures for subsequent rendering.
- 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;
@@ -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)
diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs
index 4b748445f94..8ad0ff6c6a3 100644
--- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs
+++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandles.cs
@@ -294,5 +294,15 @@ MSAASamples msaaSamples
msaaSamples
);
}
+
+ ///
+ /// Reset the reference size of the system and reallocate all textures.
+ ///
+ /// New width.
+ /// New height.
+ public static void ResetReferenceSize(int width, int height)
+ {
+ s_DefaultInstance.ResetReferenceSize(width, height);
+ }
}
}
diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md
index ce4de18c909..a3889a21019 100644
--- a/com.unity.render-pipelines.high-definition/CHANGELOG.md
+++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
+### Added
+- Added a function (HDRenderPipeline.ResetRTHandleReferenceSize) to reset the reference size of RTHandle systems.
+
### Fixed
- Fixed shadowmask UI now correctly showing shadowmask disable
- Fixed the indirect diffuse texture not being ignored when it should (ray tracing disabled).
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs
index f935ef4e77a..3c15fd2be24 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs
@@ -555,6 +555,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);
+ }
+ }
+ }
+
// Set up UnityPerView CBuffer.
internal void SetupGlobalParams(CommandBuffer cmd, int frameCount)
{
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
index bbdf5c69be5..cfd9915aa6e 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
@@ -567,6 +567,20 @@ void ValidateResources()
#endif
+ ///
+ /// 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.
+ ///
+ /// New width of the internal RTHandle System.
+ /// New height of the internal RTHandle System.
+ 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;
@@ -971,7 +985,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)
@@ -3142,7 +3156,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);