Skip to content

Change guards around ESRAM code #922

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 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public enum TextureSizeMode
Functor
}

#if UNITY_2020_2_OR_NEWER
/// <summary>
/// Subset of the texture desc containing information for fast memory allocation (when platform supports it)
/// </summary>
Expand All @@ -130,6 +131,7 @@ public struct FastMemoryDesc
///<summary>How much of the render target is to be switched into fast memory (between 0 and 1).</summary>
public float residencyFraction;
}
#endif

/// <summary>
/// Descriptor used to create texture resources
Expand Down Expand Up @@ -182,8 +184,10 @@ public struct TextureDesc
public RenderTextureMemoryless memoryless;
///<summary>Texture name.</summary>
public string name;
#if UNITY_2020_2_OR_NEWER
///<summary>Descriptor to determine how the texture will be in fast memory on platform that supports it.</summary>
public FastMemoryDesc fastMemoryDesc;
#endif

// Initial state. Those should not be used in the hash
///<summary>Texture needs to be cleared on first use.</summary>
Expand Down Expand Up @@ -642,11 +646,13 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, TextureHandle
{
CreateTextureForPass(ref resource);

#if UNITY_2020_2_OR_NEWER
var fastMemDesc = resource.desc.fastMemoryDesc;
if(fastMemDesc.inFastMemory)
{
resource.rt.SwitchToFastMemory(rgContext.cmd, fastMemDesc.residencyFraction, fastMemDesc.flags);
}
#endif

if (resource.desc.clearBuffer || m_RenderGraphDebug.clearRenderTargetsAtCreation)
{
Expand Down
7 changes: 3 additions & 4 deletions com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public Vector2Int GetScaledSize(Vector2Int refSize)
}
}

#if UNITY_2020_2_OR_NEWER
/// <summary>
/// Switch the render target to fast memory on platform that have it.
/// </summary>
Expand All @@ -160,10 +161,8 @@ public void SwitchToFastMemory(CommandBuffer cmd,
bool copyContents = false
)
{
#if UNITY_2020_2_OR_NEWER
residencyFraction = Mathf.Clamp01(residencyFraction);
cmd.SwitchIntoFastMemory(m_RT, flags, residencyFraction, copyContents);
#endif
}

/// <summary>
Expand All @@ -187,9 +186,9 @@ public void CopyToFastMemory(CommandBuffer cmd,
/// <param name="copyContents">Whether the content of render target are copied or not when switching out fast memory.</param>
public void SwitchOutFastMemory(CommandBuffer cmd, bool copyContents = true)
{
#if UNITY_2020_2_OR_NEWER
cmd.SwitchOutOfFastMemory(m_RT, copyContents);
#endif
}
#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,27 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass
passData.gbufferRT[0] = builder.UseColorBuffer(sssBuffer, 0);
passData.gbufferRT[1] = builder.UseColorBuffer(prepassOutput.normalBuffer, 1);

#if UNITY_2020_2_OR_NEWER
FastMemoryDesc gbufferFastMemDesc;
gbufferFastMemDesc.inFastMemory = true;
gbufferFastMemDesc.residencyFraction = 1.0f;
gbufferFastMemDesc.flags = FastMemoryFlags.SpillTop;
#endif

// If we are in deferred mode and the SSR is enabled, we need to make sure that the second gbuffer is cleared given that we are using that information for clear coat selection
bool clearGBuffer2 = clearGBuffer || hdCamera.IsSSREnabled();
passData.gbufferRT[2] = builder.UseColorBuffer(renderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2", fastMemoryDesc = gbufferFastMemDesc }, HDShaderIDs._GBufferTexture[2]), 2);
new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2"
#if UNITY_2020_2_OR_NEWER
, fastMemoryDesc = gbufferFastMemDesc
#endif
}, HDShaderIDs._GBufferTexture[2]), 2);
passData.gbufferRT[3] = builder.UseColorBuffer(renderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3", fastMemoryDesc = gbufferFastMemDesc }, HDShaderIDs._GBufferTexture[3]), 3);
new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3"
#if UNITY_2020_2_OR_NEWER
, fastMemoryDesc = gbufferFastMemDesc
#endif
}, HDShaderIDs._GBufferTexture[3]), 3);

prepassOutput.gbuffer.lightLayersTextureIndex = -1;
int currentIndex = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,13 @@ void RenderDistortion( RenderGraph renderGraph,

TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool msaa)
{

#if UNITY_2020_2_OR_NEWER
FastMemoryDesc colorFastMemDesc;
colorFastMemDesc.inFastMemory = true;
colorFastMemDesc.residencyFraction = 1.0f;
colorFastMemDesc.flags = FastMemoryFlags.SpillTop;
#endif

return renderGraph.CreateTexture(
new TextureDesc(Vector2.one, true, true)
Expand All @@ -997,8 +1000,10 @@ TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool
enableMSAA = msaa,
clearBuffer = NeedClearColorBuffer(hdCamera),
clearColor = GetColorBufferClearColor(hdCamera),
name = msaa ? "CameraColorMSAA" : "CameraColor",
fastMemoryDesc = colorFastMemDesc
name = msaa ? "CameraColorMSAA" : "CameraColor"
#if UNITY_2020_2_OR_NEWER
, fastMemoryDesc = colorFastMemDesc
#endif
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ void ValidateResources()

#endif

#if UNITY_2020_2_OR_NEWER
internal void SwitchRenderTargetsToFastMem(CommandBuffer cmd, HDCamera camera)
{
// Color and normal buffer will always be in fast memory
Expand All @@ -667,7 +668,7 @@ internal void SwitchRenderTargetsToFastMem(CommandBuffer cmd, HDCamera camera)
// Trying to fit the depth pyramid
m_SharedRTManager.GetDepthTexture().SwitchToFastMemory(cmd, residencyFraction: 1.0f, FastMemoryFlags.SpillTop, false);
}

#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.
Expand Down Expand Up @@ -2206,7 +2207,9 @@ AOVRequestData aovRequest
// Render graph deals with Fast memory support in an automatic way.
if(!m_EnableRenderGraph)
{
#if UNITY_2020_2_OR_NEWER
SwitchRenderTargetsToFastMem(cmd, hdCamera);
#endif
}

if (m_RayTracingSupported)
Expand Down Expand Up @@ -4855,6 +4858,7 @@ static void ResolveColorPickerDebug(in DebugParameters parameters,
HDUtils.DrawFullScreen(cmd, parameters.colorPickerMaterial, output);
}


static void RenderExposureDebug(in DebugParameters parameters,
RTHandle inputColorBuffer,
RTHandle postprocessedColorBuffer,
Expand Down