diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
index c8a1b3a32ae..700251d73a0 100644
--- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
+++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs
@@ -33,6 +33,8 @@ public ref struct RenderGraphContext
public RenderGraphObjectPool renderGraphPool;
///Render Graph Resource Registry used for accessing resources.
public RenderGraphResourceRegistry resources;
+ ///Render Graph default resources.
+ public RenderGraphDefaultResources defaultResources;
}
///
@@ -50,7 +52,6 @@ public struct RenderGraphExecuteParams
class RenderGraphDebugParams
{
- public bool enableRenderGraph = false; // TODO: TEMP TO REMOVE
public bool tagResourceNamesWithRG;
public bool clearRenderTargetsAtCreation;
public bool clearRenderTargetsAtRelease;
@@ -61,7 +62,6 @@ class RenderGraphDebugParams
public void RegisterDebug()
{
var list = new List();
- list.Add(new DebugUI.BoolField { displayName = "Enable Render Graph", getter = () => enableRenderGraph, setter = value => enableRenderGraph = value });
list.Add(new DebugUI.BoolField { displayName = "Tag Resources with RG", getter = () => tagResourceNamesWithRG, setter = value => tagResourceNamesWithRG = value });
list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at creation", getter = () => clearRenderTargetsAtCreation, setter = value => clearRenderTargetsAtCreation = value });
list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at release", getter = () => clearRenderTargetsAtRelease, setter = value => clearRenderTargetsAtRelease = value });
@@ -69,8 +69,8 @@ public void RegisterDebug()
list.Add(new DebugUI.Button { displayName = "Log Frame Information", action = () => logFrameInformation = true });
list.Add(new DebugUI.Button { displayName = "Log Resources", action = () => logResources = true });
- var testPanel = DebugManager.instance.GetPanel("Render Graph", true);
- testPanel.children.Add(list.ToArray());
+ var panel = DebugManager.instance.GetPanel("Render Graph", true);
+ panel.children.Add(list.ToArray());
}
public void UnRegisterDebug()
@@ -194,20 +194,25 @@ internal override bool HasRenderFunc()
List m_RendererLists = new List();
RenderGraphDebugParams m_DebugParameters = new RenderGraphDebugParams();
RenderGraphLogger m_Logger = new RenderGraphLogger();
+ RenderGraphDefaultResources m_DefaultResources = new RenderGraphDefaultResources();
#region Public Interface
- ///
- /// Returns true if rendering with Render Graph is enabled.
- ///
- public bool enabled { get { return m_DebugParameters.enableRenderGraph; } }
-
// TODO: Currently only needed by SSAO to sample correctly depth texture mips. Need to figure out a way to hide this behind a proper formalization.
///
/// Gets the RTHandleProperties structure associated with the Render Graph's RTHandle System.
///
public RTHandleProperties rtHandleProperties { get { return m_Resources.GetRTHandleProperties(); } }
+ public RenderGraphDefaultResources defaultResources
+ {
+ get
+ {
+ m_DefaultResources.InitializeForRendering(this);
+ return m_DefaultResources;
+ }
+ }
+
///
/// Render Graph constructor.
///
@@ -224,6 +229,7 @@ public RenderGraph(bool supportMSAA, MSAASamples initialSampleCount)
public void Cleanup()
{
m_Resources.Cleanup();
+ m_DefaultResources.Cleanup();
}
///
@@ -231,7 +237,7 @@ public void Cleanup()
///
public void RegisterDebug()
{
- //m_DebugParameters.RegisterDebug();
+ m_DebugParameters.RegisterDebug();
}
///
@@ -239,7 +245,7 @@ public void RegisterDebug()
///
public void UnRegisterDebug()
{
- //m_DebugParameters.UnRegisterDebug();
+ m_DebugParameters.UnRegisterDebug();
}
///
@@ -391,6 +397,7 @@ public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, in
rgContext.renderContext = renderContext;
rgContext.renderGraphPool = m_RenderGraphPool;
rgContext.resources = m_Resources;
+ rgContext.defaultResources = m_DefaultResources;
try
{
@@ -424,6 +431,7 @@ public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, in
{
ClearRenderPasses();
m_Resources.Clear();
+ m_DefaultResources.Clear();
m_RendererLists.Clear();
if (m_DebugParameters.logFrameInformation || m_DebugParameters.logResources)
diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs
new file mode 100644
index 00000000000..05f8ad1c2d8
--- /dev/null
+++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs
@@ -0,0 +1,71 @@
+using UnityEngine.Rendering;
+
+namespace UnityEngine.Experimental.Rendering.RenderGraphModule
+{
+ ///
+ /// Helper class allowing access to default resources (black or white texture, etc.) during render passes.
+ ///
+ public class RenderGraphDefaultResources
+ {
+ bool m_IsValid;
+
+ // We need to keep around a RTHandle version of default regular 2D textures since RenderGraph API is all RTHandle.
+ RTHandle m_BlackTexture2D;
+ RTHandle m_WhiteTexture2D;
+
+ /// Default black 2D texture.
+ public TextureHandle blackTexture { get; private set; }
+ /// Default white 2D texture.
+ public TextureHandle whiteTexture { get; private set; }
+ /// Default clear color XR 2D texture.
+ public TextureHandle clearTextureXR { get; private set; }
+ /// Default magenta XR 2D texture.
+ public TextureHandle magentaTextureXR { get; private set; }
+ /// Default black XR 2D texture.
+ public TextureHandle blackTextureXR { get; private set; }
+ /// Default black (UInt) XR 2D texture.
+ public TextureHandle blackUIntTextureXR { get; private set; }
+ /// Default black XR 3D texture.
+ public TextureHandle blackTexture3DXR { get; private set; }
+ /// Default white XR 2D texture.
+ public TextureHandle whiteTextureXR { get; private set; }
+
+ internal RenderGraphDefaultResources()
+ {
+ m_BlackTexture2D = RTHandles.Alloc(Texture2D.blackTexture);
+ m_WhiteTexture2D = RTHandles.Alloc(Texture2D.whiteTexture);
+ }
+
+ internal void Cleanup()
+ {
+ m_BlackTexture2D.Release();
+ m_WhiteTexture2D.Release();
+ }
+
+ internal void InitializeForRendering(RenderGraph renderGraph)
+ {
+ if (!m_IsValid)
+ {
+ blackTexture = renderGraph.ImportTexture(m_BlackTexture2D);
+ whiteTexture = renderGraph.ImportTexture(m_WhiteTexture2D);
+
+ clearTextureXR = renderGraph.ImportTexture(TextureXR.GetClearTexture());
+ magentaTextureXR = renderGraph.ImportTexture(TextureXR.GetMagentaTexture());
+ blackTextureXR = renderGraph.ImportTexture(TextureXR.GetBlackTexture());
+ blackUIntTextureXR = renderGraph.ImportTexture(TextureXR.GetBlackUIntTexture());
+ blackTexture3DXR = renderGraph.ImportTexture(TextureXR.GetBlackTexture3D());
+ whiteTextureXR = renderGraph.ImportTexture(TextureXR.GetWhiteTexture());
+
+ m_IsValid = true;
+ }
+ }
+
+ // Imported resources are cleared everytime the Render Graph is executed, so we need to know if that happens
+ // so that we can re-import all default resources if needed.
+ internal void Clear()
+ {
+ m_IsValid = false;
+ }
+ }
+}
+
diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs.meta b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs.meta
new file mode 100644
index 00000000000..16bf971686f
--- /dev/null
+++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: d9929b63696b16c4ca41927306959897
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
index 80b43911efb..6977801efaf 100644
--- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
+++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandleSystem.cs
@@ -96,7 +96,15 @@ public void Dispose()
/// Number of MSAA samples for automatically scaled RTHandles.
public void Initialize(int width, int height, bool scaledRTsupportsMSAA, MSAASamples scaledRTMSAASamples)
{
- Debug.Assert(m_AutoSizedRTs.Count == 0, "RTHandle.Initialize should only be called once before allocating any Render Texture. This may be caused by an unreleased RTHandle resource.");
+ if (m_AutoSizedRTs.Count != 0)
+ {
+ string leakingResources = "Unreleased RTHandles:";
+ foreach (var rt in m_AutoSizedRTs)
+ {
+ leakingResources = string.Format("{0}\n {1}", leakingResources, rt.name);
+ }
+ Debug.LogError(string.Format("RTHandle.Initialize should only be called once before allocating any Render Texture. This may be caused by an unreleased RTHandle resource.\n{0}\n", leakingResources));
+ }
m_MaxWidths = width;
m_MaxHeights = height;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs
index cc057ec6d07..2c960245d8e 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs
@@ -1436,6 +1436,8 @@ void RegisterRenderingDebug()
widgetList.Add(new DebugUI.BoolField { displayName = "XR single-pass test mode", getter = () => data.xrSinglePassTestMode, setter = value => data.xrSinglePassTestMode = value });
}
+ //widgetList.Add(new DebugUI.BoolField { displayName = "Enable Render Graph", getter = () => HDRenderPipeline.currentPipeline.IsRenderGraphEnabled(), setter = value => HDRenderPipeline.currentPipeline.EnableRenderGraph(value) });
+
m_DebugRenderingItems = widgetList.ToArray();
var panel = DebugManager.instance.GetPanel(k_PanelRendering, true);
panel.children.Add(m_DebugRenderingItems);
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugLightVolumes.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugLightVolumes.cs
index 6f09825a3dc..a47709bdaaf 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugLightVolumes.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugLightVolumes.cs
@@ -55,6 +55,19 @@ public void InitData(RenderPipelineResources renderPipelineResources)
m_Blit = CoreUtils.CreateEngineMaterial(renderPipelineResources.shaders.blitPS);
+ InitializeNonRenderGraphResources();
+ }
+
+ public void ReleaseData()
+ {
+ CoreUtils.Destroy(m_Blit);
+ CoreUtils.Destroy(m_DebugLightVolumeMaterial);
+
+ CleanupNonRenderGraphResources();
+ }
+
+ public void InitializeNonRenderGraphResources()
+ {
m_LightCountBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R32_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeCount");
m_ColorAccumulationBuffer = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: false, useMipMap: false, name: "LightVolumeColorAccumulation");
m_DebugLightVolumesTexture = RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, enableRandomWrite: true, useMipMap: false, name: "LightVolumeDebugLightVolumesTexture");
@@ -64,16 +77,12 @@ public void InitData(RenderPipelineResources renderPipelineResources)
m_RTIDs[1] = m_ColorAccumulationBuffer;
}
- public void ReleaseData()
+ public void CleanupNonRenderGraphResources()
{
- CoreUtils.Destroy(m_Blit);
-
RTHandles.Release(m_DepthBuffer);
RTHandles.Release(m_DebugLightVolumesTexture);
RTHandles.Release(m_ColorAccumulationBuffer);
RTHandles.Release(m_LightCountBuffer);
-
- CoreUtils.Destroy(m_DebugLightVolumeMaterial);
}
public struct RenderLightVolumesParameters
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl
index 17e092d4f3f..8d916005488 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl
@@ -57,7 +57,7 @@ float GetPunctualShadowClosestDistance(HDShadowContext shadowContext, SamplerSta
// Note: Here we assume that all the shadow map cube faces have been added contiguously in the buffer to retreive the shadow information
// TODO: if on the light type to retrieve the good shadow data
HDShadowData sd = shadowContext.shadowDatas[shadowDataIndex];
-
+
if (pointLight)
{
sd.shadowToWorld = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].shadowToWorld;
@@ -66,14 +66,14 @@ float GetPunctualShadowClosestDistance(HDShadowContext shadowContext, SamplerSta
sd.rot1 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot1;
sd.rot2 = shadowContext.shadowDatas[shadowDataIndex + CubeMapFaceID(-L)].rot2;
}
-
+
return EvalShadow_SampleClosestDistance_Punctual(sd, _ShadowmapAtlas, sampl, positionWS, L, lightPositionWS);
}
float GetAreaLightAttenuation(HDShadowContext shadowContext, float2 positionSS, float3 positionWS, float3 normalWS, int shadowDataIndex, float3 L, float L_dist)
{
HDShadowData sd = shadowContext.shadowDatas[shadowDataIndex];
- return EvalShadow_AreaDepth(sd, _AreaShadowmapMomentAtlas, positionSS, positionWS, normalWS, L, L_dist, true);
+ return EvalShadow_AreaDepth(sd, _ShadowmapAreaAtlas, positionSS, positionWS, normalWS, L, L_dist, true);
}
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
index a502c37133c..be91c0a9a6c 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
@@ -2717,6 +2717,7 @@ bool PrepareLightsForGPU(CommandBuffer cmd, HDCamera hdCamera, CullingResults cu
}
PushLightDataGlobalParams(cmd);
+ PushShadowGlobalParams(cmd);
}
m_EnableBakeShadowMask = m_EnableBakeShadowMask && hdCamera.frameSettings.IsEnabled(FrameSettingsField.Shadowmask);
@@ -3402,20 +3403,6 @@ HDAdditionalLightData GetHDAdditionalLightData(Light light)
return add;
}
- struct ShadowGlobalParameters
- {
- public HDCamera hdCamera;
- public HDShadowManager shadowManager;
- }
-
- ShadowGlobalParameters PrepareShadowGlobalParameters(HDCamera hdCamera)
- {
- ShadowGlobalParameters parameters = new ShadowGlobalParameters();
- parameters.hdCamera = hdCamera;
- parameters.shadowManager = m_ShadowManager;
- return parameters;
- }
-
struct LightLoopGlobalParameters
{
public HDCamera hdCamera;
@@ -3510,16 +3497,9 @@ void PushLightDataGlobalParams(CommandBuffer cmd)
cmd.SetGlobalBuffer(HDShaderIDs._DirectionalLightDatas, m_LightLoopLightData.directionalLightData);
}
- static void PushShadowGlobalParams(in ShadowGlobalParameters param, CommandBuffer cmd)
+ void PushShadowGlobalParams(CommandBuffer cmd)
{
- using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.PushShadowGlobalParameters)))
- {
- Camera camera = param.hdCamera.camera;
-
- // Shadows
- param.shadowManager.SyncData();
- param.shadowManager.BindResources(cmd);
- }
+ m_ShadowManager.PushGlobalParameters(cmd);
}
static void PushLightLoopGlobalParams(in LightLoopGlobalParameters param, CommandBuffer cmd)
@@ -3550,8 +3530,7 @@ void RenderShadowMaps(ScriptableRenderContext renderContext, CommandBuffer cmd,
m_ShadowManager.RenderShadows(renderContext, cmd, globalCB, cullResults, hdCamera);
// Bind the shadow data
- var globalParams = PrepareShadowGlobalParameters(hdCamera);
- PushShadowGlobalParams(globalParams, cmd);
+ m_ShadowManager.BindResources(cmd);
}
bool WillRenderContactShadow()
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs
index a5f2607b370..40bf78c2e80 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs
@@ -234,6 +234,17 @@ internal void Cleanup()
ReleaseRT();
}
+ internal void InitializeNonRenderGraphResources()
+ {
+ float scaleFactor = m_RunningFullRes ? 1.0f : 0.5f;
+ AllocRT(scaleFactor);
+ }
+
+ internal void CleanupNonRenderGraphResources()
+ {
+ ReleaseRT();
+ }
+
internal void InitRaytracing(HDRenderPipeline renderPipeline)
{
m_RaytracingAmbientOcclusion.Init(renderPipeline);
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAtlas.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAtlas.cs
index f83708478b2..2a747077acd 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAtlas.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowAtlas.cs
@@ -31,7 +31,6 @@ public enum BlurAlgorithm
RenderTextureFormat m_Format;
string m_Name;
int m_AtlasShaderID;
- int m_MomentAtlasShaderID;
RenderPipelineResources m_RenderPipelineResources;
// Moment shadow data
@@ -52,7 +51,7 @@ public enum BlurAlgorithm
bool m_HasResizedAtlas = false;
int frameCounter = 0;
- public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "", int momentAtlasShaderID = 0)
+ public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width, int height, int atlasShaderID, Material clearMaterial, int maxShadowRequests, BlurAlgorithm blurAlgorithm = BlurAlgorithm.None, FilterMode filterMode = FilterMode.Bilinear, DepthBits depthBufferBits = DepthBits.Depth16, RenderTextureFormat format = RenderTextureFormat.Shadowmap, string name = "")
{
this.width = width;
this.height = height;
@@ -61,7 +60,6 @@ public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width,
m_Format = format;
m_Name = name;
m_AtlasShaderID = atlasShaderID;
- m_MomentAtlasShaderID = momentAtlasShaderID;
m_ClearMaterial = clearMaterial;
m_BlurAlgorithm = blurAlgorithm;
m_RenderPipelineResources = renderPipelineResources;
@@ -76,7 +74,7 @@ public HDShadowAtlas(RenderPipelineResources renderPipelineResources, int width,
AllocateRenderTexture();
}
- void AllocateRenderTexture()
+ public void AllocateRenderTexture()
{
if (m_Atlas != null)
m_Atlas.Release();
@@ -109,7 +107,7 @@ public void BindResources(CommandBuffer cmd)
cmd.SetGlobalTexture(m_AtlasShaderID, m_Atlas);
if (m_BlurAlgorithm == BlurAlgorithm.EVSM)
{
- cmd.SetGlobalTexture(m_MomentAtlasShaderID, m_AtlasMoments[0]);
+ cmd.SetGlobalTexture(m_AtlasShaderID, m_AtlasMoments[0]);
}
}
@@ -471,7 +469,6 @@ struct RenderShadowsParameters
// EVSM
public ComputeShader evsmShadowBlurMomentsCS;
- public int momentAtlasShaderID;
// IM
public ComputeShader imShadowBlurMomentsCS;
@@ -489,7 +486,6 @@ RenderShadowsParameters PrepareRenderShadowsParameters(in ShaderVariablesGlobal
// EVSM
parameters.evsmShadowBlurMomentsCS = m_RenderPipelineResources.shaders.evsmBlurCS;
- parameters.momentAtlasShaderID = m_MomentAtlasShaderID;
// IM
parameters.imShadowBlurMomentsCS = m_RenderPipelineResources.shaders.momentShadowsCS;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowContext.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowContext.hlsl
index dfee6ffa597..3dfe1536d2a 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowContext.hlsl
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowContext.hlsl
@@ -19,8 +19,7 @@ struct HDShadowContext
TEXTURE2D(_ShadowmapAtlas);
TEXTURE2D(_ShadowmapCascadeAtlas);
-TEXTURE2D(_AreaShadowmapAtlas);
-TEXTURE2D(_AreaShadowmapMomentAtlas);
+TEXTURE2D(_ShadowmapAreaAtlas);
StructuredBuffer _HDShadowDatas;
// Only the first element is used since we only support one directional light
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs
index f3bf3abfe3b..52738760492 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs
@@ -12,7 +12,7 @@ internal struct ShadowResult
partial class HDShadowManager
{
- internal static ShadowResult ReadShadowResult(ShadowResult shadowResult, RenderGraphBuilder builder)
+ internal static ShadowResult ReadShadowResult(in ShadowResult shadowResult, RenderGraphBuilder builder)
{
var result = new ShadowResult();
@@ -30,15 +30,49 @@ internal ShadowResult RenderShadows(RenderGraph renderGraph, in ShaderVariablesG
{
var result = new ShadowResult();
// Avoid to do any commands if there is no shadow to draw
- if (m_ShadowRequestCount == 0)
- return result;
+ if (m_ShadowRequestCount != 0)
+ {
+ result.punctualShadowResult = m_Atlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Punctual Lights Shadows rendering");
+ result.directionalShadowResult = m_CascadeAtlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Directional Light Shadows rendering");
+ result.areaShadowResult = m_AreaLightShadowAtlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Area Light Shadows rendering");
+ }
- result.punctualShadowResult = m_Atlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Punctual Lights Shadows rendering");
- result.directionalShadowResult = m_CascadeAtlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Directional Light Shadows rendering");
- result.areaShadowResult = m_AreaLightShadowAtlas.RenderShadows(renderGraph, cullResults, globalCB, hdCamera.frameSettings, "Area Light Shadows rendering");
+ // TODO RENDERGRAPH
+ // Not really good to bind things globally here (makes lifecycle of the textures fuzzy)
+ // Probably better to bind it explicitly where needed (deferred lighting and forward/debug passes)
+ BindShadowGlobalResources(renderGraph, result);
return result;
}
+
+ class BindShadowGlobalResourcesPassData
+ {
+ public ShadowResult shadowResult;
+ }
+
+
+ static void BindAtlasTexture(RenderGraphContext ctx, TextureHandle texture, int shaderId)
+ {
+ if (texture.IsValid())
+ ctx.cmd.SetGlobalTexture(shaderId, ctx.resources.GetTexture(texture));
+ else
+ ctx.cmd.SetGlobalTexture(shaderId, ctx.resources.GetTexture(ctx.defaultResources.blackTexture));
+ }
+
+ void BindShadowGlobalResources(RenderGraph renderGraph, in ShadowResult shadowResult)
+ {
+ using (var builder = renderGraph.AddRenderPass("BindShadowGlobalResources", out var passData))
+ {
+ passData.shadowResult = ReadShadowResult(shadowResult, builder);
+ builder.SetRenderFunc(
+ (BindShadowGlobalResourcesPassData data, RenderGraphContext ctx) =>
+ {
+ BindAtlasTexture(ctx, data.shadowResult.punctualShadowResult, HDShaderIDs._ShadowmapAtlas);
+ BindAtlasTexture(ctx, data.shadowResult.directionalShadowResult, HDShaderIDs._ShadowmapCascadeAtlas);
+ BindAtlasTexture(ctx, data.shadowResult.areaShadowResult, HDShaderIDs._ShadowmapAreaAtlas);
+ });
+ }
+ }
}
partial class HDShadowAtlas
@@ -76,13 +110,13 @@ internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cul
passData.shadowDrawSettings.useRenderingLayerMaskTest = frameSettings.IsEnabled(FrameSettingsField.LightLayers);
passData.atlasTexture = builder.WriteTexture(
renderGraph.CreateTexture( new TextureDesc(width, height)
- { filterMode = m_FilterMode, depthBufferBits = m_DepthBufferBits, isShadowMap = true, name = m_Name, clearBuffer = passData.parameters.debugClearAtlas }, passData.parameters.atlasShaderID));
+ { filterMode = m_FilterMode, depthBufferBits = m_DepthBufferBits, isShadowMap = true, name = m_Name, clearBuffer = passData.parameters.debugClearAtlas }));
result = passData.atlasTexture;
if (passData.parameters.blurAlgorithm == BlurAlgorithm.EVSM)
{
- passData.momentAtlasTexture1 = builder.WriteTexture(AllocateMomentAtlas(renderGraph, string.Format("{0}Moment", m_Name), passData.parameters.momentAtlasShaderID));
+ passData.momentAtlasTexture1 = builder.WriteTexture(AllocateMomentAtlas(renderGraph, string.Format("{0}Moment", m_Name)));
passData.momentAtlasTexture2 = builder.WriteTexture(AllocateMomentAtlas(renderGraph, string.Format("{0}MomentCopy", m_Name)));
result = passData.momentAtlasTexture1;
@@ -90,11 +124,11 @@ internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cul
else if (passData.parameters.blurAlgorithm == BlurAlgorithm.IM)
{
passData.momentAtlasTexture1 = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
- { colorFormat = GraphicsFormat.R32G32B32A32_SFloat, name = string.Format("{0}Moment", m_Name), enableRandomWrite = true }, passData.parameters.momentAtlasShaderID));
+ { colorFormat = GraphicsFormat.R32G32B32A32_SFloat, name = string.Format("{0}Moment", m_Name), enableRandomWrite = true }));
passData.intermediateSummedAreaTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
- { colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}IntermediateSummedArea", m_Name), enableRandomWrite = true }, passData.parameters.momentAtlasShaderID));
+ { colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}IntermediateSummedArea", m_Name), enableRandomWrite = true }));
passData.summedAreaTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
- { colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}SummedArea", m_Name), enableRandomWrite = true }, passData.parameters.momentAtlasShaderID));
+ { colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}SummedArea", m_Name), enableRandomWrite = true }));
result = passData.momentAtlasTexture1;
}
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs
index baca84547a9..ef50ee78de8 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs
@@ -290,7 +290,7 @@ public void InitShadowManager(RenderPipelineResources renderPipelineResources, D
m_CascadeAtlas = new HDShadowAtlas(renderPipelineResources, 1, 1, HDShaderIDs._ShadowmapCascadeAtlas, m_ClearShadowMaterial, maxShadowRequests, cascadeBlur, depthBufferBits: directionalShadowDepthBits, name: "Cascade Shadow Map Atlas");
if (ShaderConfig.s_AreaLights == 1)
- m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._AreaLightShadowmapAtlas, m_ClearShadowMaterial, maxShadowRequests, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas", momentAtlasShaderID: HDShaderIDs._AreaShadowmapMomentAtlas);
+ m_AreaLightShadowAtlas = new HDShadowAtlas(renderPipelineResources, areaLightAtlasInfo.shadowAtlasResolution, areaLightAtlasInfo.shadowAtlasResolution, HDShaderIDs._ShadowmapAreaAtlas, m_ClearShadowMaterial, maxShadowRequests, HDShadowAtlas.BlurAlgorithm.EVSM, depthBufferBits: areaLightAtlasInfo.shadowAtlasDepthBits, name: "Area Light Shadow Map Atlas");
m_ShadowDataBuffer = new ComputeBuffer(maxShadowRequests, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDShadowData)));
m_DirectionalShadowDataBuffer = new ComputeBuffer(1, System.Runtime.InteropServices.Marshal.SizeOf(typeof(HDDirectionalShadowData)));
@@ -298,6 +298,22 @@ public void InitShadowManager(RenderPipelineResources renderPipelineResources, D
m_MaxShadowRequests = maxShadowRequests;
}
+ public void InitializeNonRenderGraphResources()
+ {
+ m_Atlas.AllocateRenderTexture();
+ m_CascadeAtlas.AllocateRenderTexture();
+ if (ShaderConfig.s_AreaLights == 1)
+ m_AreaLightShadowAtlas.AllocateRenderTexture();
+ }
+
+ public void CleanupNonRenderGraphResources()
+ {
+ m_Atlas.Release();
+ m_CascadeAtlas.Release();
+ if (ShaderConfig.s_AreaLights == 1)
+ m_AreaLightShadowAtlas.Release();
+ }
+
// Keep in sync with both HDShadowSampling.hlsl
public static DirectionalShadowAlgorithm GetDirectionalShadowAlgorithm()
{
@@ -686,6 +702,14 @@ unsafe public void PrepareGPUShadowDatas(CullingResults cullResults, HDCamera ca
m_DirectionalShadowData.cascadeDirection = Vector4.zero;
m_DirectionalShadowData.cascadeDirection.w = camera.volumeStack.GetComponent().cascadeShadowSplitCount.value;
+
+ if (m_ShadowRequestCount > 0)
+ {
+ // Upload the shadow buffers to GPU
+ m_ShadowDataBuffer.SetData(m_ShadowDatas);
+ m_CachedDirectionalShadowData[0] = m_DirectionalShadowData;
+ m_DirectionalShadowDataBuffer.SetData(m_CachedDirectionalShadowData);
+ }
}
public void RenderShadows(ScriptableRenderContext renderContext, CommandBuffer cmd, in ShaderVariablesGlobal globalCB, CullingResults cullResults, HDCamera hdCamera)
@@ -712,18 +736,6 @@ public void RenderShadows(ScriptableRenderContext renderContext, CommandBuffer c
}
}
- public void SyncData()
- {
- // Avoid to upload datas which will not be used
- if (m_ShadowRequestCount == 0)
- return;
-
- // Upload the shadow buffers to GPU
- m_ShadowDataBuffer.SetData(m_ShadowDatas);
- m_CachedDirectionalShadowData[0] = m_DirectionalShadowData;
- m_DirectionalShadowDataBuffer.SetData(m_CachedDirectionalShadowData);
- }
-
public void PushGlobalParameters(CommandBuffer cmd)
{
// This code must be in sync with HDShadowContext.hlsl
@@ -733,8 +745,6 @@ public void PushGlobalParameters(CommandBuffer cmd)
public void BindResources(CommandBuffer cmd)
{
- PushGlobalParameters(cmd);
-
m_Atlas.BindResources(cmd);
m_CascadeAtlas.BindResources(cmd);
if (ShaderConfig.s_AreaLights == 1)
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs
index 3dfd208c165..9d6428cc704 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs
@@ -63,7 +63,7 @@ static RTHandle ShadowHistoryBufferAllocatorFunction(string viewName, int frameI
HDRenderPipeline hdrp = (RenderPipelineManager.currentPipeline as HDRenderPipeline);
int numShadowSlices = Math.Max((int)Math.Ceiling(hdrp.m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadowSlots / 4.0f), 1);
return rtHandleSystem.Alloc(Vector2.one, slices: numShadowSlices * TextureXR.slices, dimension: TextureDimension.Tex2DArray, filterMode: FilterMode.Point, colorFormat: graphicsFormat,
- enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("ScreenSpaceShadowHistoryBuffer{0}", frameIndex));
+ enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("{0}_ScreenSpaceShadowHistoryBuffer{1}", viewName, frameIndex));
}
@@ -77,7 +77,7 @@ static RTHandle ShadowHistoryValidityBufferAllocatorFunction(string viewName, in
GraphicsFormat graphicsFormat = (GraphicsFormat)hdPipelineAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.screenSpaceShadowBufferFormat;
int numShadowSlices = Math.Max((int)Math.Ceiling(hdrp.m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadowSlots / 4.0f), 1);
return rtHandleSystem.Alloc(Vector2.one, slices: numShadowSlices * TextureXR.slices, dimension: TextureDimension.Tex2DArray, filterMode: FilterMode.Point, colorFormat: graphicsFormat,
- enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("ShadowHistoryValidityBuffer{0}", frameIndex));
+ enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("{0}_ShadowHistoryValidityBuffer{1}", viewName, frameIndex));
}
static RTHandle ShadowHistoryDistanceBufferAllocatorFunction(string viewName, int frameIndex, RTHandleSystem rtHandleSystem)
@@ -87,7 +87,7 @@ static RTHandle ShadowHistoryDistanceBufferAllocatorFunction(string viewName, in
GraphicsFormat graphicsFormat = (GraphicsFormat)hdPipelineAsset.currentPlatformRenderPipelineSettings.hdShadowInitParams.screenSpaceShadowBufferFormat;
int numShadowSlices = Math.Max((int)Math.Ceiling(hdrp.m_Asset.currentPlatformRenderPipelineSettings.hdShadowInitParams.maxScreenSpaceShadowSlots / 4.0f), 1);
return rtHandleSystem.Alloc(Vector2.one, slices: numShadowSlices * TextureXR.slices, dimension: TextureDimension.Tex2DArray, filterMode: FilterMode.Point, colorFormat: graphicsFormat,
- enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("ShadowHistoryDistanceBuffer{0}", frameIndex));
+ enableRandomWrite: true, useDynamicScale: true, useMipMap: false, name: string.Format("{0}_ShadowHistoryDistanceBuffer{1}", viewName, frameIndex));
}
// The three types of shadows that we currently support
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs
index a0746c77003..eaafd5edd74 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs
@@ -214,6 +214,7 @@ public partial class HDRenderPipeline
// These two buffers do not depend on the frameID and are therefore shared by all views.
RTHandle m_DensityBuffer;
RTHandle m_LightingBuffer;
+ Vector3Int m_CurrentVolumetricBufferSize;
ShaderVariablesVolumetric m_ShaderVariablesVolumetricCB = new ShaderVariablesVolumetric();
@@ -451,7 +452,7 @@ internal void CreateVolumetricLightingBuffers()
// We will perform rescaling manually, in a custom manner, based on volume parameters.
const int minSize = 4;
- m_DensityBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
+ m_DensityBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
dimension: TextureDimension.Tex3D, enableRandomWrite: true, name: "VBufferDensity");
m_LightingBuffer = RTHandles.Alloc(minSize, minSize, minSize, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
@@ -466,7 +467,7 @@ internal void DestroyVolumetricLightingBuffers()
CoreUtils.SafeRelease(m_VisibleVolumeDataBuffer);
CoreUtils.SafeRelease(m_VisibleVolumeBoundsBuffer);
- m_VisibleVolumeData = null; // free()
+ m_VisibleVolumeData = null; // free()
m_VisibleVolumeBounds = null; // free()
}
@@ -492,12 +493,17 @@ internal void ResizeVolumetricLightingBuffers(HDCamera hdCamera, int frameIndex)
var currentParams = hdCamera.vBufferParams[currIdx];
- ResizeVolumetricBuffer(ref m_DensityBuffer, "VBufferDensity", currentParams.viewportSize.x,
+ ResizeVolumetricBuffer(ref m_DensityBuffer, "VBufferDensity", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
ResizeVolumetricBuffer(ref m_LightingBuffer, "VBufferLighting", currentParams.viewportSize.x,
currentParams.viewportSize.y,
currentParams.viewportSize.z);
+
+ // TODO RENDERGRAPH: For now those texture are not handled by render graph.
+ // When they are we won't have the m_DensityBuffer handy for getting the current size in UpdateShaderVariablesGlobalVolumetrics
+ // So we store the size here and in time we'll fill this vector differently.
+ m_CurrentVolumetricBufferSize = new Vector3Int(m_DensityBuffer.rt.width, m_DensityBuffer.rt.height, m_DensityBuffer.rt.volumeDepth);
}
void InitializeVolumetricLighting()
@@ -539,7 +545,7 @@ static float CornetteShanksPhasePartConstant(float anisotropy)
return (3.0f / (8.0f * Mathf.PI)) * (1.0f - g * g) / (2.0f + g * g);
}
- void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTHandleProperties sharedRTHandleProperties, HDCamera hdCamera)
+ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, HDCamera hdCamera)
{
if (!Fog.IsVolumetricFogEnabled(hdCamera))
{
@@ -557,11 +563,6 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTH
// The history & feedback buffers are specific to the camera.
// These 2 types of buffers can have different sizes.
// Additionally, history buffers can have different sizes, since they are not resized at the same time.
- Vector3Int lightingBufferSize = new Vector3Int(m_LightingBuffer.rt.width, m_LightingBuffer.rt.height, m_LightingBuffer.rt.volumeDepth);
-
- Debug.Assert(m_LightingBuffer.rt.width == m_DensityBuffer.rt.width);
- Debug.Assert(m_LightingBuffer.rt.height == m_DensityBuffer.rt.height);
-
var cvp = currParams.viewportSize;
// Adjust slices for XR rendering: VBuffer is shared for all single-pass views
@@ -570,26 +571,14 @@ void UpdateShaderVariablesGlobalVolumetrics(ref ShaderVariablesGlobal cb, in RTH
cb._VBufferViewportSize = new Vector4(cvp.x, cvp.y, 1.0f / cvp.x, 1.0f / cvp.y);
cb._VBufferSliceCount = sliceCount;
cb._VBufferRcpSliceCount = 1.0f / sliceCount;
- cb._VBufferLightingViewportScale = currParams.ComputeViewportScale(lightingBufferSize);
- cb._VBufferLightingViewportLimit = currParams.ComputeViewportLimit(lightingBufferSize);
+ cb._VBufferLightingViewportScale = currParams.ComputeViewportScale(m_CurrentVolumetricBufferSize);
+ cb._VBufferLightingViewportLimit = currParams.ComputeViewportLimit(m_CurrentVolumetricBufferSize);
cb._VBufferDistanceEncodingParams = currParams.depthEncodingParams;
cb._VBufferDistanceDecodingParams = currParams.depthDecodingParams;
cb._VBufferLastSliceDist = currParams.ComputeLastSliceDistance(sliceCount);
cb._VBufferRcpInstancedViewCount = 1.0f / hdCamera.viewCount;
}
- void PushVolumetricLightingGlobalParams(HDCamera hdCamera, CommandBuffer cmd, int frameIndex)
- {
- if (!Fog.IsVolumetricFogEnabled(hdCamera))
- {
- cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, HDUtils.clearTexture3D);
- }
- else
- {
- cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, m_LightingBuffer);
- }
- }
-
DensityVolumeList PrepareVisibleDensityVolumeList(HDCamera hdCamera, CommandBuffer cmd, float time)
{
DensityVolumeList densityVolumes = new DensityVolumeList();
@@ -724,24 +713,12 @@ unsafe void UpdateShaderVariableslVolumetrics(ref ShaderVariablesVolumetric cb,
// The history & feedback buffers are specific to the camera.
// These 2 types of buffers can have different sizes.
// Additionally, history buffers can have different sizes, since they are not resized at the same time.
- Vector3Int lightingBufferSize = new Vector3Int(m_LightingBuffer.rt.width, m_LightingBuffer.rt.height, m_LightingBuffer.rt.volumeDepth);
-
- Debug.Assert(m_LightingBuffer.rt.width == m_DensityBuffer.rt.width);
- Debug.Assert(m_LightingBuffer.rt.height == m_DensityBuffer.rt.height);
-
Vector3Int historyBufferSize = Vector3Int.zero;
if (hdCamera.IsVolumetricReprojectionEnabled())
{
RTHandle historyRT = hdCamera.volumetricHistoryBuffers[prevIdx];
-
historyBufferSize = new Vector3Int(historyRT.rt.width, historyRT.rt.height, historyRT.rt.volumeDepth);
-
- // Handle case of first frame. When we are on the first frame, we reuse the value of original frame.
- if (historyBufferSize.x == 0.0f && historyBufferSize.y == 0.0f)
- {
- historyBufferSize = lightingBufferSize;
- }
}
cb._VBufferVoxelSize = currParams.voxelSize;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DBufferManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DBufferManager.cs
index 5a30edd2afe..e9bcf7e2ea9 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DBufferManager.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DBufferManager.cs
@@ -3,7 +3,7 @@
namespace UnityEngine.Rendering.HighDefinition
{
class DBufferManager : MRTBufferManager
- {
+ {
ComputeBuffer m_PropertyMaskBuffer;
int m_PropertyMaskBufferSize;
ComputeShader m_ClearPropertyMaskBufferShader;
@@ -79,7 +79,7 @@ public void ReleaseResolutionDependentBuffers()
}
public void AllocResolutionDependentBuffers(HDCamera hdCamera, int width, int height)
- {
+ {
m_PropertyMaskBufferSize = ((width + 7) / 8) * ((height + 7) / 8);
m_PropertyMaskBufferSize = ((m_PropertyMaskBufferSize + 63) / 64) * 64; // round off to nearest multiple of 64 for ease of use in CS
m_PropertyMaskBuffer = new ComputeBuffer(m_PropertyMaskBufferSize, 4);
@@ -88,7 +88,6 @@ public void AllocResolutionDependentBuffers(HDCamera hdCamera, int width, int he
override public void DestroyBuffers()
{
base.DestroyBuffers();
- ReleaseResolutionDependentBuffers();
}
public void BindBlackTextures(CommandBuffer cmd)
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/SharedRTManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/SharedRTManager.cs
index aaf3e2390c2..46c94318f0f 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Material/SharedRTManager.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Material/SharedRTManager.cs
@@ -100,8 +100,6 @@ public void InitSharedBuffers(GBufferManager gbufferManager, RenderPipelineSetti
CoreUtils.SetKeyword(m_DepthResolveMaterial, "_HAS_MOTION_VECTORS", m_MotionVectorsSupport);
}
- AllocateCoarseStencilBuffer(RTHandles.maxWidth, RTHandles.maxHeight, TextureXR.slices);
-
// If we are in the forward only mode
if (!m_ReuseGBufferMemory)
{
@@ -298,7 +296,6 @@ public void Cleanup()
RTHandles.Release(m_CameraDepthStencilBuffer);
RTHandles.Release(m_CameraDepthBufferMipChain);
RTHandles.Release(m_CameraHalfResDepthBuffer);
- DisposeCoarseStencilBuffer();
if (m_MSAASupported)
{
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
index 1d0c61a2653..59b7da33195 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Material/SubsurfaceScattering/SubsurfaceScatteringManager.cs
@@ -80,6 +80,16 @@ void InitSSSBuffers()
m_SSSSetDiffusionProfiles = new DiffusionProfileSettings[DiffusionProfileConstants.DIFFUSION_PROFILE_COUNT];
}
+ void DestroySSSBuffers()
+ {
+ RTHandles.Release(m_SSSColorMSAA);
+ RTHandles.Release(m_SSSCameraFilteringBuffer);
+ if (!m_SSSReuseGBufferMemory)
+ {
+ RTHandles.Release(m_SSSColor);
+ }
+ }
+
RTHandle GetSSSBuffer()
{
return m_SSSColor;
@@ -111,12 +121,7 @@ void CleanupSubsurfaceScattering()
{
CoreUtils.Destroy(m_CombineLightingPass);
CoreUtils.Destroy(m_SSSCopyStencilForSplitLighting);
- if (!m_SSSReuseGBufferMemory)
- {
- RTHandles.Release(m_SSSColor);
- }
- RTHandles.Release(m_SSSColorMSAA);
- RTHandles.Release(m_SSSCameraFilteringBuffer);
+ DestroySSSBuffers();
}
void UpdateCurrentDiffusionProfileSettings(HDCamera hdCamera)
@@ -265,7 +270,7 @@ static RTHandle SubSurfaceHistoryBufferAllocatorFunction(string viewName, int fr
{
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
- name: string.Format("SubSurfaceHistoryBuffer{0}", frameIndex));
+ name: string.Format("{0}_SubSurfaceHistoryBuffer{1}", viewName, frameIndex));
}
void RenderSubsurfaceScattering(HDCamera hdCamera, CommandBuffer cmd, RTHandle colorBufferRT,
diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs
index 498cd19d8fb..5b55edea50a 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs
@@ -237,7 +237,7 @@ public void Render( RenderGraph renderGraph,
passData.parameters = PrepareFinalPass(hdCamera, blueNoise, flipY);
passData.source = builder.ReadTexture(source);
passData.afterPostProcessTexture = builder.ReadTexture(afterPostProcessTexture);
- passData.alphaTexture = builder.ReadTexture(m_KeepAlpha ? alphaTexture : renderGraph.ImportTexture(TextureXR.GetWhiteTexture()));
+ passData.alphaTexture = builder.ReadTexture(m_KeepAlpha ? alphaTexture : renderGraph.defaultResources.whiteTextureXR);
passData.destination = builder.WriteTexture(finalRT);
builder.SetRenderFunc(
diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs
index 53acbb6240e..af115aa692b 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.cs
@@ -126,6 +126,8 @@ private enum SMAAStage
bool m_MotionBlurSupportsScattering;
+ bool m_NonRenderGraphResourcesAvailable;
+
// Max guard band size is assumed to be 8 pixels
const int k_RTGuardBandSize = 4;
@@ -155,14 +157,81 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
m_UseSafePath = SystemInfo.graphicsDeviceVendor
.ToLowerInvariant().Contains("intel");
- // Project-wise LUT size for all grading operations - meaning that internal LUTs and
- // user-provided LUTs will have to be this size
- var settings = hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings;
- m_LutSize = settings.lutSize;
- var lutFormat = (GraphicsFormat)settings.lutFormat;
+ var postProcessSettings = hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings;
+ m_LutSize = postProcessSettings.lutSize;
// Grading specific
m_HableCurve = new HableCurve();
+
+ m_MotionBlurSupportsScattering = SystemInfo.IsFormatSupported(GraphicsFormat.R32_UInt, FormatUsage.LoadStore) && SystemInfo.IsFormatSupported(GraphicsFormat.R16_UInt, FormatUsage.LoadStore);
+ // TODO: Remove this line when atomic bug in HLSLcc is fixed.
+ m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan);
+ // TODO: Write a version that uses structured buffer instead of texture to do atomic as Metal doesn't support atomics on textures.
+ m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Metal);
+
+ // Initialize our target pool to ease RT management
+ m_Pool = new TargetPool();
+
+ // Use a custom RNG, we don't want to mess with the Unity one that the users might be
+ // relying on (breaks determinism in their code)
+ m_Random = new System.Random();
+
+ m_ColorFormat = (GraphicsFormat)postProcessSettings.bufferFormat;
+ m_KeepAlpha = false;
+
+ // if both rendering and post-processing support an alpha channel, then post-processing will process (or copy) the alpha
+ m_EnableAlpha = hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha && postProcessSettings.supportsAlpha;
+
+ if (m_EnableAlpha == false)
+ {
+ // if only rendering has an alpha channel (and not post-processing), then we just copy the alpha to the output (but we don't process it).
+ m_KeepAlpha = hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha;
+ }
+
+ // Call after initializing m_LutSize and m_KeepAlpha as it's needed for render target allocation.
+ InitializeNonRenderGraphResources(hdAsset);
+ }
+
+ public void Cleanup()
+ {
+ CleanupNonRenderGraphResources();
+
+ CoreUtils.Destroy(m_ExposureCurveTexture);
+ CoreUtils.Destroy(m_InternalSpectralLut);
+ CoreUtils.Destroy(m_FinalPassMaterial);
+ CoreUtils.Destroy(m_ClearBlackMaterial);
+ CoreUtils.Destroy(m_SMAAMaterial);
+ CoreUtils.Destroy(m_TemporalAAMaterial);
+ CoreUtils.SafeRelease(m_BokehNearKernel);
+ CoreUtils.SafeRelease(m_BokehFarKernel);
+ CoreUtils.SafeRelease(m_BokehIndirectCmd);
+ CoreUtils.SafeRelease(m_NearBokehTileList);
+ CoreUtils.SafeRelease(m_FarBokehTileList);
+ CoreUtils.SafeRelease(m_ContrastAdaptiveSharpen);
+
+ m_ExposureCurveTexture = null;
+ m_InternalSpectralLut = null;
+ m_FinalPassMaterial = null;
+ m_ClearBlackMaterial = null;
+ m_SMAAMaterial = null;
+ m_TemporalAAMaterial = null;
+ m_BokehNearKernel = null;
+ m_BokehFarKernel = null;
+ m_BokehIndirectCmd = null;
+ m_NearBokehTileList = null;
+ m_FarBokehTileList = null;
+ }
+
+ public void InitializeNonRenderGraphResources(HDRenderPipelineAsset hdAsset)
+ {
+ m_NonRenderGraphResourcesAvailable = true;
+
+ var settings = hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings;
+
+ // Project-wide LUT size for all grading operations - meaning that internal LUTs and
+ // user-provided LUTs will have to be this size
+ var lutFormat = (GraphicsFormat)settings.lutFormat;
+
m_InternalLogLut = RTHandles.Alloc(
name: "Color Grading Log Lut",
dimension: TextureDimension.Tex3D,
@@ -186,21 +255,8 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
enableRandomWrite: true, name: "Empty EV100 Exposure"
);
- m_MotionBlurSupportsScattering = SystemInfo.IsFormatSupported(GraphicsFormat.R32_UInt, FormatUsage.LoadStore) && SystemInfo.IsFormatSupported(GraphicsFormat.R16_UInt, FormatUsage.LoadStore);
- // TODO: Remove this line when atomic bug in HLSLcc is fixed.
- m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Vulkan);
- // TODO: Write a version that uses structured buffer instead of texture to do atomic as Metal doesn't support atomics on textures.
- m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && (SystemInfo.graphicsDeviceType != GraphicsDeviceType.Metal);
-
FillEmptyExposureTexture();
- // Initialize our target pool to ease RT management
- m_Pool = new TargetPool();
-
- // Use a custom RNG, we don't want to mess with the Unity one that the users might be
- // relying on (breaks determinism in their code)
- m_Random = new System.Random();
-
// Misc targets
m_TempTexture1024 = RTHandles.Alloc(
1024, 1024, colorFormat: GraphicsFormat.R16G16_SFloat,
@@ -212,18 +268,6 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
enableRandomWrite: true, name: "Average Luminance Temp 32"
);
- m_ColorFormat = (GraphicsFormat)hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings.bufferFormat;
- m_KeepAlpha = false;
-
- // if both rendering and post-processing support an alpha channel, then post-processing will process (or copy) the alpha
- m_EnableAlpha = hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha && hdAsset.currentPlatformRenderPipelineSettings.postProcessSettings.supportsAlpha;
-
- if (m_EnableAlpha == false)
- {
- // if only rendering has an alpha channel (and not post-processing), then we just copy the alpha to the output (but we don't process it).
- m_KeepAlpha = hdAsset.currentPlatformRenderPipelineSettings.supportsAlpha;
- }
-
if (m_KeepAlpha)
{
m_AlphaTexture = RTHandles.Alloc(
@@ -233,44 +277,23 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
}
}
- public void Cleanup()
+ public void CleanupNonRenderGraphResources()
{
+ m_NonRenderGraphResourcesAvailable = false;
+
m_Pool.Cleanup();
RTHandles.Release(m_EmptyExposureTexture);
RTHandles.Release(m_TempTexture1024);
RTHandles.Release(m_TempTexture32);
RTHandles.Release(m_AlphaTexture);
- CoreUtils.Destroy(m_ExposureCurveTexture);
- CoreUtils.Destroy(m_InternalSpectralLut);
RTHandles.Release(m_InternalLogLut);
- CoreUtils.Destroy(m_FinalPassMaterial);
- CoreUtils.Destroy(m_ClearBlackMaterial);
- CoreUtils.Destroy(m_SMAAMaterial);
- CoreUtils.Destroy(m_TemporalAAMaterial);
- CoreUtils.SafeRelease(m_BokehNearKernel);
- CoreUtils.SafeRelease(m_BokehFarKernel);
- CoreUtils.SafeRelease(m_BokehIndirectCmd);
- CoreUtils.SafeRelease(m_NearBokehTileList);
- CoreUtils.SafeRelease(m_FarBokehTileList);
- CoreUtils.SafeRelease(m_ContrastAdaptiveSharpen);
- m_EmptyExposureTexture = null;
- m_TempTexture1024 = null;
- m_TempTexture32 = null;
- m_AlphaTexture = null;
- m_ExposureCurveTexture = null;
- m_InternalSpectralLut = null;
- m_InternalLogLut = null;
- m_FinalPassMaterial = null;
- m_ClearBlackMaterial = null;
- m_SMAAMaterial = null;
- m_TemporalAAMaterial = null;
- m_BokehNearKernel = null;
- m_BokehFarKernel = null;
- m_BokehIndirectCmd = null;
- m_NearBokehTileList = null;
- m_FarBokehTileList = null;
+ m_EmptyExposureTexture = null;
+ m_TempTexture1024 = null;
+ m_TempTexture32 = null;
+ m_AlphaTexture = null;
+ m_InternalLogLut = null;
}
// In some cases, the internal buffer of render textures might be invalid.
@@ -278,6 +301,9 @@ public void Cleanup()
// This is not the case when these textures are used exclusively with Compute Shaders. So to make sure they work in this case, we recreate them here.
void CheckRenderTexturesValidity()
{
+ if (!m_NonRenderGraphResourcesAvailable)
+ return;
+
if (!m_EmptyExposureTexture.rt.IsCreated())
FillEmptyExposureTexture();
@@ -799,7 +825,7 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
// r: multiplier, g: EV100
return rtHandleSystem.Alloc(1, 1, colorFormat: k_ExposureFormat,
- enableRandomWrite: true, name: $"Exposure Texture ({id}) {frameIndex}"
+ enableRandomWrite: true, name: $"{id} Exposure Texture {frameIndex}"
);
}
@@ -1031,7 +1057,7 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
return rtHandleSystem.Alloc(
Vector2.one, TextureXR.slices, DepthBits.None, dimension: TextureXR.dimension,
filterMode: FilterMode.Bilinear, colorFormat: m_ColorFormat,
- enableRandomWrite: true, useDynamicScale: true, name: "TAA History"
+ enableRandomWrite: true, useDynamicScale: true, name: $"{id} TAA History"
);
}
@@ -1047,7 +1073,7 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
return rtHandleSystem.Alloc(
Vector2.one, TextureXR.slices, DepthBits.None, dimension: TextureXR.dimension,
filterMode: FilterMode.Bilinear, colorFormat: GraphicsFormat.R16_SFloat,
- enableRandomWrite: true, useDynamicScale: true, name: "Velocity magnitude"
+ enableRandomWrite: true, useDynamicScale: true, name: $"{id} Velocity magnitude"
);
}
@@ -1673,7 +1699,7 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
return rtHandleSystem.Alloc(
Vector2.one, TextureXR.slices, DepthBits.None, GraphicsFormat.R16_SFloat,
- dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, name: "CoC History"
+ dimension: TextureXR.dimension, enableRandomWrite: true, useDynamicScale: true, name: $"{id} CoC History"
);
}
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 9151820d743..86d303bc716 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
@@ -816,7 +816,7 @@ struct AmbientOcclusionAllocator
public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
- return rtHandleSystem.Alloc(Vector2.one * scaleFactor, TextureXR.slices, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32_UInt, dimension: TextureXR.dimension, useDynamicScale: true, enableRandomWrite: true, name: string.Format("AO Packed history_{0}", frameIndex));
+ return rtHandleSystem.Alloc(Vector2.one * scaleFactor, TextureXR.slices, filterMode: FilterMode.Point, colorFormat: GraphicsFormat.R32_UInt, dimension: TextureXR.dimension, useDynamicScale: true, enableRandomWrite: true, name: string.Format("{0}_AO Packed history_{1}", id, frameIndex));
}
}
@@ -1265,7 +1265,7 @@ static RTHandle HistoryBufferAllocatorFunction(string viewName, int frameIndex,
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: (GraphicsFormat)hdPipeline.currentPlatformRenderPipelineSettings.colorBufferFormat,
dimension: TextureXR.dimension, enableRandomWrite: true, useMipMap: true, autoGenerateMips: false, useDynamicScale: true,
- name: string.Format("CameraColorBufferMipChain{0}", frameIndex));
+ name: string.Format("{0}_CameraColorBufferMipChain{1}", viewName, frameIndex));
}
void ReleaseHistoryBuffer()
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs
index 73b9af844f4..e7ccc9ab262 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs
@@ -121,7 +121,6 @@ internal enum HDProfileId
PrepareLightsForGPU,
// Profile sampler for shadow
- PushShadowGlobalParameters,
RenderShadowMaps,
RenderMomentShadowMaps,
RenderPunctualShadowMaps,
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs
index 695f1f899a7..a1e33784e5b 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs
@@ -27,7 +27,6 @@ static void ReadLightingBuffers(LightingBuffers buffers, RenderGraphBuilder buil
class BuildGPULightListPassData
{
- public ShadowGlobalParameters shadowGlobalParameters;
public LightLoopGlobalParameters lightLoopGlobalParameters;
public BuildGPULightListParameters buildGPULightListParameters;
@@ -93,7 +92,6 @@ BuildGPULightListOutput BuildGPULightList(RenderGraph renderGraph, HDCamera hdCa
{
builder.EnableAsyncCompute(hdCamera.frameSettings.BuildLightListRunsAsync());
- passData.shadowGlobalParameters = PrepareShadowGlobalParameters(hdCamera);
passData.lightLoopGlobalParameters = PrepareLightLoopGlobalParameters(hdCamera, m_TileAndClusterData);
passData.buildGPULightListParameters = PrepareBuildGPULightListParameters(hdCamera, m_TileAndClusterData, ref m_ShaderVariablesLightListCB, m_TotalLightCount);
passData.depthBuffer = builder.ReadTexture(depthStencilBuffer);
@@ -135,7 +133,6 @@ BuildGPULightListOutput BuildGPULightList(RenderGraph renderGraph, HDCamera hdCa
BuildDispatchIndirectArguments(data.buildGPULightListParameters, buildLightListResources, tileFlagsWritten, context.cmd);
// TODO RENDERGRAPH WARNING: Note that the three sets of variables are bound here, but it should be handled differently.
- PushShadowGlobalParams(data.shadowGlobalParameters, context.cmd);
PushLightLoopGlobalParams(data.lightLoopGlobalParameters, context.cmd);
});
@@ -411,7 +408,6 @@ class RenderContactShadowPassData
public TextureHandle depthTexture;
public TextureHandle contactShadowsTexture;
public ComputeBufferHandle lightList;
- public HDShadowManager shadowManager;
}
TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthTexture, BuildGPULightListOutput lightLists, int firstMipOffsetY)
@@ -431,7 +427,6 @@ TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, T
passData.lightLoopLightData = m_LightLoopLightData;
passData.lightList = builder.ReadComputeBuffer(lightLists.lightList);
passData.depthTexture = builder.ReadTexture(depthTexture);
- passData.shadowManager = m_ShadowManager;
passData.contactShadowsTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true)
{ colorFormat = GraphicsFormat.R32_UInt, enableRandomWrite = true, clearBuffer = clearBuffer, clearColor = Color.clear, name = "ContactShadowsBuffer" }, HDShaderIDs._ContactShadowTexture));
@@ -441,8 +436,6 @@ TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, T
(RenderContactShadowPassData data, RenderGraphContext context) =>
{
var res = context.resources;
- data.shadowManager.PushGlobalParameters(context.cmd);
-
RenderContactShadows(data.parameters, res.GetTexture(data.contactShadowsTexture), res.GetTexture(data.depthTexture), data.lightLoopLightData, res.GetComputeBuffer(data.lightList), context.cmd);
});
}
@@ -481,15 +474,7 @@ TextureHandle VolumeVoxelizationPass( RenderGraph renderGraph,
float tileSize = 0;
Vector3Int viewportSize = ComputeVolumetricViewportSize(hdCamera, ref tileSize);
- passData.densityBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(viewportSize.x, viewportSize.y, false, false)
- {
- dimension = TextureDimension.Tex3D,
- colorFormat = GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
- enableRandomWrite = true,
- slices = viewportSize.z,
- /* useDynamicScale: true, // <- TODO ,*/
- name = "VBufferDensity"
- }));
+ passData.densityBuffer = builder.WriteTexture(renderGraph.ImportTexture(m_DensityBuffer));
builder.SetRenderFunc(
(VolumeVoxelizationPassData data, RenderGraphContext ctx) =>
@@ -536,15 +521,9 @@ TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera,
float tileSize = 0;
Vector3Int viewportSize = ComputeVolumetricViewportSize(hdCamera, ref tileSize);
- passData.lightingBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(viewportSize.x, viewportSize.y, false, false)
- {
- dimension = TextureDimension.Tex3D,
- colorFormat = GraphicsFormat.R16G16B16A16_SFloat, // 8888_sRGB is not precise enough
- enableRandomWrite = true,
- slices = viewportSize.z,
- /* useDynamicScale: true, // <- TODO ,*/
- name = "VBufferLighting"
- }, HDShaderIDs._VBufferLighting));
+ // TODO RENDERGRAPH: Auto-scale of 3D RTs is not supported yet so we need to find a better solution for this. Or keep it as is?
+ passData.lightingBuffer = builder.WriteTexture(renderGraph.ImportTexture(m_LightingBuffer, HDShaderIDs._VBufferLighting));
+
if (passData.parameters.enableReprojection)
{
var currIdx = (frameIndex + 0) & 1;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs
index 0198ccdcf73..2c6aac34fb9 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs
@@ -23,7 +23,7 @@ TextureHandle RenderPostProcess( RenderGraph renderGraph,
{
PostProcessParameters parameters = PreparePostProcess(cullResults, hdCamera);
- TextureHandle afterPostProcessBuffer = renderGraph.ImportTexture(TextureXR.GetBlackTexture());
+ TextureHandle afterPostProcessBuffer = renderGraph.defaultResources.blackTextureXR;
TextureHandle dest = HDUtils.PostProcessIsFinalPass(parameters.hdCamera) ? backBuffer : renderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true) { colorFormat = GetColorBufferFormat(), name = "Intermediate Postprocess buffer" });
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs
index a2ce07399c5..ffb4c42da01 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs
@@ -584,7 +584,7 @@ void RenderDBuffer(RenderGraph renderGraph, HDCamera hdCamera, ref PrepassOutput
if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.Decals))
{
// Return all black textures for default values.
- var blackTexture = renderGraph.ImportTexture(TextureXR.GetBlackTexture());
+ var blackTexture = renderGraph.defaultResources.blackTextureXR;
output.dbuffer.dBufferCount = use4RTs ? 4 : 3;
for (int i = 0; i < output.dbuffer.dBufferCount; ++i)
output.dbuffer.mrt[i] = blackTexture;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
index 00657624e74..74384efdf78 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
@@ -70,7 +70,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest,
PushFullScreenDebugTexture(m_RenderGraph, lightingBuffers.ambientOcclusionBuffer, FullScreenDebugMode.SSAO);
// Evaluate the clear coat mask texture based on the lit shader mode
- var clearCoatMask = hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred ? prepassOutput.gbuffer.mrt[2] : m_RenderGraph.ImportTexture(TextureXR.GetBlackTexture());
+ var clearCoatMask = hdCamera.frameSettings.litShaderMode == LitShaderMode.Deferred ? prepassOutput.gbuffer.mrt[2] : m_RenderGraph.defaultResources.blackTextureXR;
lightingBuffers.ssrLightingBuffer = RenderSSR(m_RenderGraph,
hdCamera,
prepassOutput.resolvedNormalBuffer,
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 7e061b6aec1..00752f0bb2d 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
@@ -328,7 +328,8 @@ internal bool showCascade
}
// RENDER GRAPH
- RenderGraph m_RenderGraph;
+ RenderGraph m_RenderGraph;
+ bool m_EnableRenderGraph;
// MSAA resolve materials
Material m_ColorResolveMaterial = null;
@@ -527,10 +528,6 @@ public HDRenderPipeline(HDRenderPipelineAsset asset, HDRenderPipelineAsset defau
CameraCaptureBridge.enabled = true;
- // Render Graph
- m_RenderGraph = new RenderGraph(m_Asset.currentPlatformRenderPipelineSettings.supportMSAA, m_MSAASamples);
- m_RenderGraph.RegisterDebug();
-
InitializePrepass(m_Asset);
m_ColorResolveMaterial = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.shaders.colorResolvePS);
m_MotionVectorResolve = CoreUtils.CreateEngineMaterial(asset.renderPipelineResources.shaders.resolveMotionVecPS);
@@ -665,6 +662,9 @@ void InitializeRenderTextures()
void GetOrCreateDebugTextures()
{
+ if (m_EnableRenderGraph)
+ return;
+
//Debug.isDebugBuild can be changed during DoBuildPlayer, these allocation has to be check on every frames
//TODO : Clean this with the RenderGraph system
if (Debug.isDebugBuild && m_DebugColorPickerBuffer == null && m_DebugFullScreenTempBuffer == null)
@@ -688,15 +688,18 @@ void DestroyRenderTextures()
#if ENABLE_VIRTUALTEXTURES
m_VtBufferManager.DestroyBuffers();
#endif
- m_MipGenerator.Release();
+
+ DestroySSSBuffers();
+ m_SharedRTManager.Cleanup();
RTHandles.Release(m_CameraColorBuffer);
+ RTHandles.Release(m_OpaqueAtmosphericScatteringBuffer);
+ RTHandles.Release(m_CameraSssDiffuseLightingBuffer);
+
if (m_CustomPassColorBuffer.IsValueCreated)
RTHandles.Release(m_CustomPassColorBuffer.Value);
if (m_CustomPassDepthBuffer.IsValueCreated)
RTHandles.Release(m_CustomPassDepthBuffer.Value);
- RTHandles.Release(m_OpaqueAtmosphericScatteringBuffer);
- RTHandles.Release(m_CameraSssDiffuseLightingBuffer);
RTHandles.Release(m_DistortionBuffer);
RTHandles.Release(m_ContactShadowBuffer);
@@ -707,13 +710,17 @@ void DestroyRenderTextures()
RTHandles.Release(m_SsrHitPointTexture);
RTHandles.Release(m_SsrLightingTexture);
- RTHandles.Release(m_DebugColorPickerBuffer);
- RTHandles.Release(m_DebugFullScreenTempBuffer);
- RTHandles.Release(m_IntermediateAfterPostProcessBuffer);
-
RTHandles.Release(m_CameraColorMSAABuffer);
RTHandles.Release(m_OpaqueAtmosphericScatteringMSAABuffer);
RTHandles.Release(m_CameraSssDiffuseLightingMSAABuffer);
+
+ // Those buffer are initialized lazily so we need to null them for this to work after deallocation.
+ RTHandles.Release(m_DebugColorPickerBuffer);
+ RTHandles.Release(m_DebugFullScreenTempBuffer);
+ RTHandles.Release(m_IntermediateAfterPostProcessBuffer);
+ m_DebugColorPickerBuffer = null;
+ m_DebugFullScreenTempBuffer = null;
+ m_IntermediateAfterPostProcessBuffer = null;
}
void SetRenderingFeatures()
@@ -871,6 +878,65 @@ void UnsetRenderingFeatures()
#endif
}
+ void InitializeRenderGraph()
+ {
+ m_RenderGraph = new RenderGraph(m_Asset.currentPlatformRenderPipelineSettings.supportMSAA, m_MSAASamples);
+ m_RenderGraph.RegisterDebug();
+ }
+
+ void CleanupRenderGraph()
+ {
+ if (m_EnableRenderGraph)
+ {
+ m_RenderGraph.Cleanup();
+ m_RenderGraph.UnRegisterDebug();
+ m_RenderGraph = null;
+ }
+ }
+
+ internal bool IsRenderGraphEnabled()
+ {
+ return m_EnableRenderGraph;
+ }
+
+ internal void EnableRenderGraph(bool value)
+ {
+ bool changed = value != m_EnableRenderGraph;
+ if (changed)
+ {
+ if (value)
+ {
+ CleanupNonRenderGraphResources();
+ InitializeRenderGraph();
+ m_EnableRenderGraph = true;
+ }
+ else
+ {
+ CleanupRenderGraph();
+ InitializeNonRenderGraphResources();
+ m_EnableRenderGraph = false;
+ }
+ }
+ }
+
+ void InitializeNonRenderGraphResources()
+ {
+ InitializeRenderTextures();
+ m_ShadowManager.InitializeNonRenderGraphResources();
+ m_AmbientOcclusionSystem.InitializeNonRenderGraphResources();
+ m_PostProcessSystem.InitializeNonRenderGraphResources(asset);
+ s_lightVolumes.InitializeNonRenderGraphResources();
+ }
+
+ void CleanupNonRenderGraphResources()
+ {
+ DestroyRenderTextures();
+ m_ShadowManager.CleanupNonRenderGraphResources();
+ m_AmbientOcclusionSystem.CleanupNonRenderGraphResources();
+ m_PostProcessSystem.CleanupNonRenderGraphResources();
+ s_lightVolumes.CleanupNonRenderGraphResources();
+ }
+
void InitializeDebugMaterials()
{
m_DebugViewMaterialGBuffer = CoreUtils.CreateEngineMaterial(defaultResources.shaders.debugViewMaterialGBufferPS);
@@ -974,8 +1040,6 @@ protected override void Dispose(bool disposing)
CoreUtils.Destroy(m_ApplyDistortionMaterial);
CoreUtils.Destroy(m_ClearStencilBufferMaterial);
- CleanupSubsurfaceScattering();
- m_SharedRTManager.Cleanup();
m_XRSystem.Cleanup();
m_SkyManager.Cleanup();
CleanupVolumetricLighting();
@@ -992,16 +1056,18 @@ protected override void Dispose(bool disposing)
HDCamera.ClearAll();
+ m_MipGenerator.Release();
+
DestroyRenderTextures();
CullingGroupManager.instance.Cleanup();
+ m_DbufferManager.ReleaseResolutionDependentBuffers();
+ m_SharedRTManager.DisposeCoarseStencilBuffer();
+
CoreUtils.SafeRelease(m_DepthPyramidMipLevelOffsetsBuffer);
CustomPassVolume.Cleanup();
- // RenderGraph
- m_RenderGraph.Cleanup();
- m_RenderGraph.UnRegisterDebug();
CleanupPrepass();
CoreUtils.Destroy(m_ColorResolveMaterial);
CoreUtils.Destroy(m_MotionVectorResolve);
@@ -1088,7 +1154,7 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd)
Fog.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB, hdCamera);
UpdateShaderVariablesGlobalSubsurface(ref m_ShaderVariablesGlobalCB, hdCamera);
UpdateShaderVariablesGlobalDecal(ref m_ShaderVariablesGlobalCB, hdCamera);
- UpdateShaderVariablesGlobalVolumetrics(ref m_ShaderVariablesGlobalCB, RTHandles.rtHandleProperties, hdCamera);
+ UpdateShaderVariablesGlobalVolumetrics(ref m_ShaderVariablesGlobalCB, hdCamera);
m_ShadowManager.UpdateShaderVariablesGlobalCB(ref m_ShaderVariablesGlobalCB);
UpdateShaderVariablesGlobalLightLoop(ref m_ShaderVariablesGlobalCB, hdCamera);
UpdateShaderVariablesGlobalProbeVolumes(ref m_ShaderVariablesGlobalCB, hdCamera);
@@ -2130,7 +2196,7 @@ AOVRequestData aovRequest
return;
}
- if (m_RenderGraph.enabled)
+ if (m_EnableRenderGraph)
{
ExecuteWithRenderGraph(renderRequest, aovRequest, aovBuffers, renderContext, cmd);
return;
@@ -4921,7 +4987,7 @@ void SendGeometryGraphicsBuffers(CommandBuffer cmd, HDCamera hdCamera)
RTHandle mainNormalBuffer = m_SharedRTManager.GetNormalBuffer();
RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
- return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: mainNormalBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainNormalBuffer.rt.enableRandomWrite, name: $"Normal History Buffer"
+ return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: mainNormalBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainNormalBuffer.rt.enableRandomWrite, name: $"{id}_Normal History Buffer"
);
}
@@ -4936,7 +5002,7 @@ RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
RTHandle mainDepthBuffer = m_SharedRTManager.GetDepthTexture();
RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSystem)
{
- return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: mainDepthBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainDepthBuffer.rt.enableRandomWrite, name: $"Depth History Buffer"
+ return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: mainDepthBuffer.rt.graphicsFormat, dimension: TextureXR.dimension, enableRandomWrite: mainDepthBuffer.rt.enableRandomWrite, name: $"{id}_Depth History Buffer"
);
}
depthBuffer = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.Depth) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.Depth, Allocator, 1);
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs
index 51bb0335eaa..fedfb18049a 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs
@@ -80,8 +80,7 @@ static class HDShaderIDs
public static readonly int _HDShadowDatas = Shader.PropertyToID("_HDShadowDatas");
public static readonly int _HDDirectionalShadowData = Shader.PropertyToID("_HDDirectionalShadowData");
public static readonly int _ShadowmapAtlas = Shader.PropertyToID("_ShadowmapAtlas");
- public static readonly int _AreaLightShadowmapAtlas = Shader.PropertyToID("_AreaShadowmapAtlas");
- public static readonly int _AreaShadowmapMomentAtlas = Shader.PropertyToID("_AreaShadowmapMomentAtlas");
+ public static readonly int _ShadowmapAreaAtlas = Shader.PropertyToID("_ShadowmapAreaAtlas");
public static readonly int _ShadowmapCascadeAtlas = Shader.PropertyToID("_ShadowmapCascadeAtlas");
// Moment shadow map data
@@ -346,7 +345,7 @@ static class HDShaderIDs
public static readonly int _InputCubemap = Shader.PropertyToID("_InputCubemap");
public static readonly int _Mipmap = Shader.PropertyToID("_Mipmap");
- public static readonly int _ApplyExposure = Shader.PropertyToID("_ApplyExposure");
+ public static readonly int _ApplyExposure = Shader.PropertyToID("_ApplyExposure");
public static readonly int _DiffusionProfileHash = Shader.PropertyToID("_DiffusionProfileHash");
public static readonly int _MaxRadius = Shader.PropertyToID("_MaxRadius");
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
index be059b353ca..a99363991e8 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
@@ -207,7 +207,7 @@ static RTHandle PathTracingHistoryBufferAllocatorFunction(string viewName, int f
{
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R32G32B32A32_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
- name: string.Format("PathTracingHistoryBuffer{0}", frameIndex));
+ name: string.Format("{0}_PathTracingHistoryBuffer{1}", viewName, frameIndex));
}
void RenderPathTracing(HDCamera hdCamera, CommandBuffer cmd, RTHandle outputTexture)
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs
index c295d1ae076..ebd651e95a9 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingAmbientOcclusion.cs
@@ -52,7 +52,7 @@ static RTHandle AmbientOcclusionHistoryBufferAllocatorFunction(string viewName,
{
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
- name: string.Format("AmbientOcclusionHistoryBuffer{0}", frameIndex));
+ name: string.Format("{0}_AmbientOcclusionHistoryBuffer{1}", viewName, frameIndex));
}
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs
index bf6a56d012f..3c3dc7b7c5e 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingIndirectDiffuse.cs
@@ -28,7 +28,7 @@ RTHandle IndirectDiffuseHistoryBufferAllocatorFunction(string viewName, int fram
{
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
- name: string.Format("IndirectDiffuseHistoryBuffer{0}", frameIndex));
+ name: string.Format("{0}_IndirectDiffuseHistoryBuffer{1}", viewName, frameIndex));
}
void RenderRayTracedIndirectDiffuse(HDCamera hdCamera, CommandBuffer cmd, ScriptableRenderContext renderContext, int frameCount)
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs
index 675731ceef5..d246bfdf661 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingReflection.cs
@@ -27,7 +27,7 @@ static RTHandle ReflectionHistoryBufferAllocatorFunction(string viewName, int fr
{
return rtHandleSystem.Alloc(Vector2.one, TextureXR.slices, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, dimension: TextureXR.dimension,
enableRandomWrite: true, useMipMap: false, autoGenerateMips: false,
- name: string.Format("ReflectionHistoryBuffer{0}", frameIndex));
+ name: string.Format("{0}_ReflectionHistoryBuffer{1}", viewName, frameIndex));
}
void ReleaseRayTracedReflections()