浏览代码

Improved ProfilingSample API

/stochastic_alpha_test
Thomas 7 年前
当前提交
895c04b2
共有 9 个文件被更改,包括 73 次插入54 次删除
  1. 23
      ScriptableRenderPipeline/Core/ProfilingSample.cs
  2. 4
      ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  3. 54
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs
  5. 18
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  6. 4
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  8. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
  9. 16
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs

23
ScriptableRenderPipeline/Core/ProfilingSample.cs


using System;
using System;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering

bool m_Disposed;
public ProfilingSample(string name, CommandBuffer cmd)
public ProfilingSample(CommandBuffer cmd, string name)
m_Disposed = false;
cmd.BeginSample(name);
}
// Shortcut to string.Format() using only one argument (reduces Gen0 GC pressure)
public ProfilingSample(CommandBuffer cmd, string format, object arg)
{
this.cmd = cmd;
name = string.Format(format, arg);
m_Disposed = false;
cmd.BeginSample(name);
}
// Shortcut to string.Format() with variable amount of arguments - for performance critical
// code you should pre-build & cache the marker name instead of using this
public ProfilingSample(CommandBuffer cmd, string format, params object[] args)
{
this.cmd = cmd;
name = string.Format(format, args);
m_Disposed = false;
cmd.BeginSample(name);
}

4
ScriptableRenderPipeline/Core/Shadow/Shadow.cs


if (m_ActiveEntriesCount == 0)
return;
var profilingSample = new ProfilingSample(string.Format("Shadowmap{0}",m_TexSlot), cmd);
var profilingSample = new ProfilingSample(cmd, "Shadowmap{0}", m_TexSlot);
string cbName = "";
if (!string.IsNullOrEmpty( m_ShaderKeyword ) )

public override void RenderShadows( FrameId frameId, ScriptableRenderContext renderContext, CommandBuffer cmd, CullResults cullResults, List<VisibleLight> lights)
{
using (new ProfilingSample("Render Shadows", cmd))
using (new ProfilingSample(cmd, "Render Shadows"))
{
foreach( var sm in m_Shadowmaps )
{

54
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


public void PushGlobalParams(HDCamera hdCamera, CommandBuffer cmd, SubsurfaceScatteringSettings sssParameters)
{
using (new ProfilingSample("Push Global Parameters", cmd))
using (new ProfilingSample(cmd, "Push Global Parameters"))
{
hdCamera.SetupGlobalParams(cmd);

private void CopyDepthBufferIfNeeded(CommandBuffer cmd)
{
using (new ProfilingSample(NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer", cmd))
using (new ProfilingSample(cmd, NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer"))
using (new ProfilingSample("Copy depth-stencil buffer", cmd))
using (new ProfilingSample(cmd, "Copy depth-stencil buffer"))
{
cmd.CopyTexture(m_CameraDepthStencilBufferRT, m_CameraDepthBufferCopyRT);
}

{
if (NeedStencilBufferCopy())
{
using (new ProfilingSample("Copy StencilBuffer", cmd))
using (new ProfilingSample(cmd, "Copy StencilBuffer"))
{
cmd.SetRandomWriteTarget(1, GetHTile());
// Our method of exporting the stencil requires one pass per unique stencil value.

// TODO: Add another path dedicated to planar reflection / real time cubemap that implement simpler lighting
// It is up to the users to only send unlit object for this camera path
using (new ProfilingSample("Forward", cmd))
using (new ProfilingSample(cmd, "Forward"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Color | ClearFlag.Depth);
ShaderPassName[] arrayShaderPassName = { HDShaderPassNames.m_ForwardName };

}
else
{
using (new ProfilingSample("Build Light list and render shadows", cmd))
using (new ProfilingSample(cmd, "Build Light list and render shadows"))
{
// TODO: Everything here (SSAO, Shadow, Build light list, deffered shadow, material and light classification can be parallelize with Async compute)
m_SsaoEffect.Render(ssaoSettingsToUse, this, hdCamera, renderContext, cmd, m_Asset.renderingSettings.useForwardRenderingOnly);

// Planar and real time cubemap doesn't need post process and render in FP16
if (camera.cameraType == CameraType.Reflection)
{
using (new ProfilingSample("Blit to final RT", cmd))
using (new ProfilingSample(cmd, "Blit to final RT"))
{
// Simple blit
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);

if (addDepthPrepass == false && addForwardOnlyOpaqueDepthPrepass == false)
return;
using (new ProfilingSample(addDepthPrepass ? "Depth Prepass" : "Depth Prepass forward opaque ", cmd))
using (new ProfilingSample(cmd, addDepthPrepass ? "Depth Prepass" : "Depth Prepass forward opaque"))
{
// Default depth prepass (forward and deferred) will render all opaque geometry.
RenderQueueRange renderQueueRange = RenderQueueRange.opaque;

if (m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
return;
using (new ProfilingSample(m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer", cmd))
using (new ProfilingSample(cmd, m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() ? "GBufferDebugDisplay" : "GBuffer"))
{
// setup GBuffer for rendering
CoreUtils.SetRenderTarget(cmd, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT);

void RenderDebugViewMaterial(CullResults cull, HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingSample("DisplayDebug ViewMaterial", cmd))
using (new ProfilingSample(cmd, "DisplayDebug ViewMaterial"))
using (new ProfilingSample("DebugViewMaterialGBuffer", cmd))
using (new ProfilingSample(cmd, "DebugViewMaterialGBuffer"))
{
CoreUtils.DrawFullScreen(cmd, m_DebugViewMaterialGBuffer, m_CameraColorBufferRT);
}

// Last blit
{
using (new ProfilingSample("Blit DebugView Material Debug", cmd))
using (new ProfilingSample(cmd, "Blit DebugView Material Debug"))
{
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
}

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission || m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
return;
using (new ProfilingSample("Subsurface Scattering", cmd))
using (new ProfilingSample(cmd, "Subsurface Scattering"))
{
if (sssSettings.useDisneySSS)
{

profileName = addForwardPass ? (renderOpaque ? "Forward Opaque" : "Forward Transparent") : "Forward Only Opaque";
}
using (new ProfilingSample(profileName, cmd))
using (new ProfilingSample(cmd, profileName))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);

// This is use to Display legacy shader with an error shader
void RenderForwardError(CullResults cullResults, Camera camera, ScriptableRenderContext renderContext, CommandBuffer cmd, bool renderOpaque)
{
using (new ProfilingSample("Render Forward Error", cmd))
using (new ProfilingSample(cmd, "Render Forward Error"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT);

void RenderVelocity(CullResults cullResults, HDCamera hdcam, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
using (new ProfilingSample("Velocity", cmd))
using (new ProfilingSample(cmd, "Velocity"))
{
// If opaque velocity have been render during GBuffer no need to render it here
// TODO: Currently we can't render velocity vector into GBuffer, neither during forward pass (in case of forward opaque), so it is always a separate pass

if (!m_CurrentDebugDisplaySettings.renderingDebugSettings.enableDistortion)
return;
using (new ProfilingSample("Distortion", cmd))
using (new ProfilingSample(cmd, "Distortion"))
{
int w = camera.pixelWidth;
int h = camera.pixelHeight;

void RenderPostProcesses(Camera camera, CommandBuffer cmd, PostProcessLayer layer)
{
using (new ProfilingSample("Post-processing", cmd))
using (new ProfilingSample(cmd, "Post-processing"))
{
if (CoreUtils.IsPostProcessingActive(layer))
{

if (camera.camera.cameraType == CameraType.Reflection || camera.camera.cameraType == CameraType.Preview)
return;
using (new ProfilingSample("Render Debug", cmd))
using (new ProfilingSample(cmd, "Render Debug"))
{
// We make sure the depth buffer is bound because we need it to write depth at near plane for overlays otherwise the editor grid end up visible in them.
CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, m_CameraDepthStencilBufferRT);

void InitAndClearBuffer(HDCamera camera, CommandBuffer cmd)
{
using (new ProfilingSample("InitAndClearBuffer", cmd))
using (new ProfilingSample(cmd, "InitAndClearBuffer"))
using (new ProfilingSample("InitGBuffers and clear Depth/Stencil", cmd))
using (new ProfilingSample(cmd, "InitGBuffers and clear Depth/Stencil"))
{
// Init buffer
// With scriptable render loop we must allocate ourself depth and color buffer (We must be independent of backbuffer for now, hope to fix that later).

}
// Clear the diffuse SSS lighting target
using (new ProfilingSample("Clear SSS diffuse target", cmd))
using (new ProfilingSample(cmd, "Clear SSS diffuse target"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraSssDiffuseLightingBufferRT, ClearFlag.Color, Color.black);
}

{
// Clear the SSS filtering target
using (new ProfilingSample("Clear SSS filtering target", cmd))
using (new ProfilingSample(cmd, "Clear SSS filtering target"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraFilteringBuffer, ClearFlag.Color, Color.black);
}

if (NeedStencilBufferCopy())
{
using (new ProfilingSample("Clear stencil texture", cmd))
using (new ProfilingSample(cmd, "Clear stencil texture"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraStencilBufferCopyRT, ClearFlag.Color, Color.black);
}

{
using (new ProfilingSample("Clear HTile", cmd))
using (new ProfilingSample(cmd, "Clear HTile"))
{
CoreUtils.SetRenderTarget(cmd, m_HTileRT, ClearFlag.Color, Color.black);
}

// TEMP: As we are in development and have not all the setup pass we still clear the color in emissive buffer and gbuffer, but this will be removed later.
// Clear the HDR target
using (new ProfilingSample("Clear HDR target", cmd))
using (new ProfilingSample(cmd, "Clear HDR target"))
{
CoreUtils.SetRenderTarget(cmd, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.Color, Color.black);
}

{
using (new ProfilingSample("Clear GBuffer", cmd))
using (new ProfilingSample(cmd, "Clear GBuffer"))
{
CoreUtils.SetRenderTarget(cmd, m_gbufferManager.GetGBuffers(), m_CameraDepthStencilBufferRT, ClearFlag.Color, Color.black);
}

2
ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs


m_Material.SetFloat(Uniforms._Downsample, 1.0f / downsize);
m_Material.SetFloat(Uniforms._SampleCount, settings.sampleCount);
using (new ProfilingSample("Screenspace ambient occlusion", cmd))
using (new ProfilingSample(cmd, "Screenspace ambient occlusion"))
{
// AO estimation.
cmd.GetTemporaryRT(Uniforms._TempTex1, width / downsize, height / downsize, 0, kFilter, kTempFormat, kRWMode);

18
ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


public void PushGlobalParams(Camera camera, CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, bool forceClustered = false)
{
using (new ProfilingSample("Push Global Parameters", cmd))
using (new ProfilingSample(cmd, "Push Global Parameters"))
{
// Shadows
m_ShadowMgr.SyncData();

if (lightingDebug.tileDebugByCategory == TileSettings.TileDebug.None)
return;
using (new ProfilingSample("Tiled Lighting Debug", cmd))
using (new ProfilingSample(cmd, "Tiled Lighting Debug"))
{
bool bUseClusteredForDeferred = !usingFptl;

if (m_CurrentSunLight == null)
return;
using (new ProfilingSample("Deferred Directional", cmd))
using (new ProfilingSample(cmd, "Deferred Directional"))
{
hdCamera.SetupComputeShader(deferredDirectionalShadowComputeShader, cmd);
m_ShadowMgr.BindResources(cmd, deferredDirectionalShadowComputeShader, s_deferredDirectionalShadowKernel);

string singlePassName = "SinglePass - Deferred Lighting Pass";
string SinglePassMRTName = "SinglePass - Deferred Lighting Pass MRT";
using (new ProfilingSample(m_TileSettings.enableTileAndCluster ?
(options.outputSplitLighting ? tilePassMRTName : tilePassName) :
(options.outputSplitLighting ? SinglePassMRTName : singlePassName), cmd))
using (new ProfilingSample(cmd, m_TileSettings.enableTileAndCluster ?
(options.outputSplitLighting ? tilePassMRTName : tilePassName) :
(options.outputSplitLighting ? SinglePassMRTName : singlePassName)))
{
var camera = hdCamera.camera;

// Note: if we use render opaque with deferred tiling we need to render a opaque depth pass for these opaque objects
if (!m_TileSettings.enableTileAndCluster)
{
using (new ProfilingSample("Forward pass", cmd))
using (new ProfilingSample(cmd, "Forward pass"))
{
cmd.EnableShaderKeyword("LIGHTLOOP_SINGLE_PASS");
cmd.DisableShaderKeyword("LIGHTLOOP_TILE_PASS");

// Only opaques can use FPTL, transparent must use clustered!
bool useFptl = renderOpaque && usingFptl;
using (new ProfilingSample(useFptl ? "Forward Tiled pass" : "Forward Clustered pass", cmd))
using (new ProfilingSample(cmd, useFptl ? "Forward Tiled pass" : "Forward Clustered pass"))
{
// say that we want to use tile of single loop
cmd.EnableShaderKeyword("LIGHTLOOP_TILE_PASS");

public void RenderDebugOverlay(Camera camera, CommandBuffer cmd, DebugDisplaySettings debugDisplaySettings, ref float x, ref float y, float overlaySize, float width)
{
LightingDebugSettings lightingDebug = debugDisplaySettings.lightingDebugSettings;
using (new ProfilingSample("Display Shadows", cmd))
using (new ProfilingSample(cmd, "Display Shadows"))
{
if (lightingDebug.shadowDebugMode == ShadowMapDebugMode.VisualizeShadowMap)
{

4
ScriptableRenderPipeline/HDRenderPipeline/Lighting/Volumetrics/VolumetricLighting.cs


void ClearVolumetricLightingBuffers(CommandBuffer cmd, bool isFirstFrame)
{
using (new ProfilingSample("Clear volumetric lighting buffers", cmd))
using (new ProfilingSample(cmd, "Clear volumetric lighting buffers"))
{
CoreUtils.SetRenderTarget(cmd, m_VolumetricLightingBufferCurrentFrameRT, ClearFlag.Color, Color.black);

{
if (!SetGlobalVolumeProperties(m_VolumetricLightingEnabled, cmd, m_VolumetricLightingCS)) { return; }
using (new ProfilingSample("VolumetricLighting", cmd))
using (new ProfilingSample(cmd, "VolumetricLighting"))
{
bool enableClustered = m_Asset.tileSettings.enableClustered && m_Asset.tileSettings.enableTileAndCluster;

2
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


if (m_isInit)
return;
using (new ProfilingSample("Init PreFGD", cmd))
using (new ProfilingSample(cmd, "Init PreFGD"))
{
CoreUtils.DrawFullScreen(cmd, m_InitPreFGD, new RenderTargetIdentifier(m_PreIntegratedFGD));
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/RuntimeFilterIBL.cs


m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeGgxIblSampleDataKernel, "output", m_GgxIblSampleData);
using (new ProfilingSample("Compute GGX IBL Sample Data", cmd))
using (new ProfilingSample(cmd, "Compute GGX IBL Sample Data"))
{
cmd.DispatchCompute(m_ComputeGgxIblSampleDataCS, m_ComputeGgxIblSampleDataKernel, 1, 1, 1);
}

int numRows = conditionalCdf.height;
using (new ProfilingSample("Build Probability Tables", cmd))
using (new ProfilingSample(cmd, "Build Probability Tables"))
{
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_ConditionalDensitiesKernel, numRows, 1, 1);
cmd.DispatchCompute(m_BuildProbabilityTablesCS, m_MarginalRowDensitiesKernel, 1, 1, 1);

16
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


private void RenderCubemapGGXConvolution(CommandBuffer cmd, BuiltinSkyParameters builtinParams, SkySettings skyParams, Texture input, RenderTexture target)
{
using (new ProfilingSample("Update Env: GGX Convolution", cmd))
using (new ProfilingSample(cmd, "Update Env: GGX Convolution"))
{
int mipCount = 1 + (int)Mathf.Log(input.width, 2.0f);
if (mipCount < ((int)EnvConstants.SpecCubeLodStep + 1))

}
// Copy the first mip
using (new ProfilingSample("Copy Original Mip", cmd))
using (new ProfilingSample(cmd, "Copy Original Mip"))
{
for (int f = 0; f < 6; f++)
{

using (new ProfilingSample("GGX Convolution", cmd))
using (new ProfilingSample(cmd, "GGX Convolution"))
{
if (m_useMIS && m_iblFilterGgx.SupportMIS)
{

// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed directly but the renderloop is not (so we need to wait for the sky texture to be rendered first)
if (m_NeedLowLevelUpdateEnvironment)
{
using (new ProfilingSample("DynamicGI.UpdateEnvironment", cmd))
using (new ProfilingSample(cmd, "DynamicGI.UpdateEnvironment"))
{
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
m_StandardSkyboxMaterial.SetTexture("_Tex", m_SkyboxCubemapRT);

(skySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skySettings.updatePeriod)
)
{
using (new ProfilingSample("Sky Environment Pass", cmd))
using (new ProfilingSample(cmd, "Sky Environment Pass"))
using (new ProfilingSample("Update Env: Generate Lighting Cubemap", cmd))
using (new ProfilingSample(cmd, "Update Env: Generate Lighting Cubemap"))
{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.

{
if (m_SkyParametersHash != 0)
{
using (new ProfilingSample("Reset Sky Environment", cmd))
using (new ProfilingSample(cmd, "Reset Sky Environment"))
{
// Clear temp cubemap and redo GGX from black and then feed it to enlighten for default light probe.
CoreUtils.ClearCubemap(cmd, m_SkyboxCubemapRT, Color.black);

public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
{
using (new ProfilingSample("Sky Pass", cmd))
using (new ProfilingSample(cmd, "Sky Pass"))
{
if (IsSkyValid())
{

正在加载...
取消
保存