浏览代码

use pooling

/RenderPassXR_Sandbox
Tim Cooper 8 年前
当前提交
8b0f6d4c
共有 18 个文件被更改,包括 191 次插入112 次删除
  1. 1
      Assets/Editor/Tests/RenderloopTests/RenderPipelineTestFixture.cs
  2. 6
      Assets/ScriptableRenderPipeline/BasicRenderPipeline/BasicRenderPipeline.cs
  3. 18
      Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs
  4. 41
      Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs
  5. 4
      Assets/ScriptableRenderPipeline/Fptl/SkyboxHelper.cs
  6. 49
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  7. 3
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs
  8. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
  9. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs
  10. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  11. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  12. 12
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/RuntimeFilterIBL.cs
  13. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  14. 24
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs
  15. 21
      Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs
  16. 72
      Assets/ScriptableRenderPipeline/core/CommandBufferPool.cs
  17. 12
      Assets/ScriptableRenderPipeline/core/CommandBufferPool.cs.meta

1
Assets/Editor/Tests/RenderloopTests/RenderPipelineTestFixture.cs


}
renderContext.Submit();
CommandBufferPool.EndOfFrame();
}
public static void Run(TestDelegate renderCallback)

6
Assets/ScriptableRenderPipeline/BasicRenderPipeline/BasicRenderPipeline.cs


{
base.Render(renderContext, cameras);
BasicRendering.Render(renderContext, cameras);
CommandBufferPool.EndOfFrame();
}
}

context.SetupCameraProperties(camera);
// clear depth buffer
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.ClearRenderTarget(true, false, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Release();

GetShaderConstantsFromNormalizedSH(ref ambientSH, shConstants);
// setup global shader variables to contain all the data computed above
CommandBuffer cmd = new CommandBuffer();
CommandBuffer cmd = CommandBufferPool.Get();
cmd.SetGlobalVectorArray("globalLightColor", lightColors);
cmd.SetGlobalVectorArray("globalLightPos", lightPositions);
cmd.SetGlobalVectorArray("globalLightSpotDir", lightSpotDirections);

context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Prepare L2 spherical harmonics values for efficient evaluation in a shader

18
Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs


if (!string.IsNullOrEmpty( m_ShaderKeyword ) )
{
var cb = new CommandBuffer();
var cb = CommandBufferPool.Get();
cb.Dispose();
}
// loop for generating each individual shadowmap

if( !cullResults.GetShadowCasterBounds( m_EntryCache[i].key.visibleIdx, out bounds ) )
continue;
var cb = new CommandBuffer();
var cb = CommandBufferPool.Get();
uint entrySlice = m_EntryCache[i].current.slice;
if( entrySlice != curSlice )
{

cb.SetViewProjectionMatrices( m_EntryCache[i].current.view, m_EntryCache[i].current.proj );
cb.SetGlobalVector( "g_vLightDirWs", m_EntryCache[i].current.lightDir );
renderContext.ExecuteCommandBuffer( cb );
cb.Dispose();
dss.lightIndex = m_EntryCache[i].key.visibleIdx;
dss.splitData = m_EntryCache[i].current.splitData;

// post update
var cblast = new CommandBuffer();
var cblast = CommandBufferPool.Get();
PostUpdate( frameId, cblast, curSlice, lights );
if( !string.IsNullOrEmpty( m_ShaderKeyword ) )
{

renderContext.ExecuteCommandBuffer( cblast );
cblast.Dispose();
m_ActiveEntriesCount = 0;

override public void DisplayShadowMap(ScriptableRenderContext renderContext, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
{
CommandBuffer debugCB = new CommandBuffer();
CommandBuffer debugCB = CommandBufferPool.Get();
debugCB.name = "";
Vector4 validRange = new Vector4(minValue, 1.0f / (maxValue - minValue));

debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("REGULARSHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(debugCB);
debugCB.Dispose();
}
}

override public void DisplayShadowMap(ScriptableRenderContext renderContext, Vector4 scaleBias, uint slice, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue)
{
CommandBuffer debugCB = new CommandBuffer();
CommandBuffer debugCB = CommandBufferPool.Get();
debugCB.name = "";
Vector4 validRange = new Vector4(minValue, 1.0f / (maxValue - minValue));

debugCB.DrawProcedural(Matrix4x4.identity, m_DebugMaterial, m_DebugMaterial.FindPass("VARIANCESHADOW"), MeshTopology.Triangles, 3, 1, propertyBlock);
renderContext.ExecuteCommandBuffer(debugCB);
debugCB.Dispose();
}
}
// -------------------------------------------------------------------------------------------------------------------------------------------------

{
sm.Fill( m_ShadowCtxt );
}
CommandBuffer cb = new CommandBuffer(); // <- can we just keep this around or does this have to be newed every frame?
CommandBuffer cb = CommandBufferPool.Get(); // <- can we just keep this around or does this have to be newed every frame?
cb.Dispose();
}
// resets the shadow slot counters and returns the sum of all slots

41
Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs


{
base.Render(renderContext, cameras);
m_Owner.Render(renderContext, cameras);
CommandBufferPool.EndOfFrame();
}
}

static void RenderGBuffer(CullResults cull, Camera camera, ScriptableRenderContext loop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer { name = "Create G-Buffer" };
var cmd = CommandBufferPool.Get ("Create G-Buffer");
cmd.Dispose();
// render opaque objects using Deferred pass
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("Deferred"))

void RenderForward(CullResults cull, Camera camera, ScriptableRenderContext loop, bool opaquesOnly)
{
var cmd = new CommandBuffer { name = opaquesOnly ? "Prep Opaques Only Forward Pass" : "Prep Forward Pass" };
var cmd = CommandBufferPool.Get(opaquesOnly ? "Prep Opaques Only Forward Pass" : "Prep Forward Pass" );
bool useFptl = opaquesOnly && usingFptl; // requires depth pre-pass for forward opaques!

cmd.SetGlobalBuffer("g_vLightListGlobal", useFptl ? s_LightList : s_PerVoxelLightLists);
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// render opaque objects using Deferred pass
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("ForwardSinglePass"))

static void DepthOnlyForForwardOpaques(CullResults cull, Camera camera, ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "Forward Opaques - Depth Only" };
var cmd = CommandBufferPool.Get("Forward Opaques - Depth Only" );
cmd.Dispose();
// render opaque objects using Deferred pass
var settings = new DrawRendererSettings(cull, camera, new ShaderPassName("DepthOnly"))

static void CopyDepthAfterGBuffer(ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "Copy depth" };
var cmd = CommandBufferPool.Get("Copy depth");
cmd.Dispose();
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
m_DeferredMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");
m_DeferredReflectionMaterial.EnableKeyword(bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST");

cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraTarget), new RenderTargetIdentifier(s_CameraDepthTexture));
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
private static void SetMatrixCS(CommandBuffer cmd, ComputeShader shadercs, string name, Matrix4x4 mat)

void FinalPass(ScriptableRenderContext loop)
{
var cmd = new CommandBuffer { name = "FinalPass" };
var cmd = CommandBufferPool.Get("FinalPass");
cmd.Dispose();
}
void ExecuteRenderLoop(Camera camera, CullResults cullResults, ScriptableRenderContext loop)

// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
}
loop.Submit();
}

var cmd = new CommandBuffer { name = "DrawLightBoundsDebug" };
var cmd = CommandBufferPool.Get("DrawLightBoundsDebug");
cmd.Dispose();
}
void NewFrame()

var numBigTilesX = (w + 63) / 64;
var numBigTilesY = (h + 63) / 64;
var cmd = new CommandBuffer() { name = "Build light list" };
var cmd = CommandBufferPool.Get("Build light list" );
// generate screen-space AABBs (used for both fptl and clustered).
if (numLights != 0)

}
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
var cmd = new CommandBuffer { name = "Push Global Parameters" };
var cmd = CommandBufferPool.Get("Push Global Parameters");
cmd.SetGlobalFloat("g_widthRT", (float)camera.pixelWidth);
cmd.SetGlobalFloat("g_heightRT", (float)camera.pixelHeight);

cmd.SetGlobalVector("g_vShadow3x3PCFTerms3", m_Shadow3X3PCFTerms[3]);
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
private float PerceptualRoughnessToBlinnPhongPower(float perceptualRoughness)

4
Assets/ScriptableRenderPipeline/Fptl/SkyboxHelper.cs


return;
}
var cmd = new CommandBuffer { name = "Skybox" };
var cmd = CommandBufferPool.Get("Skybox");
var looksLikeSixSidedShader = true;
looksLikeSixSidedShader &= (mat.passCount == 6); // should have six passes

}
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
public static Matrix4x4 GetProjectionMatrix(Camera camera)

49
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext, SubsurfaceScatteringSettings sssParameters)
{
var cmd = new CommandBuffer {name = "Push Global Parameters"};
var cmd = CommandBufferPool.Get("Push Global Parameters");
cmd.SetGlobalVector("_ScreenSize", hdCamera.screenSize);
cmd.SetGlobalMatrix("_ViewProjMatrix", hdCamera.viewProjectionMatrix);

cmd.SetGlobalVectorArray("_TransmissionTints", sssParameters.transmissionTints);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
bool NeedDepthBufferCopy()

private void CopyDepthBufferIfNeeded(ScriptableRenderContext renderContext)
{
var cmd = new CommandBuffer() { name = NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer"};
var cmd = CommandBufferPool.Get(NeedDepthBufferCopy() ? "Copy DepthBuffer" : "Set DepthBuffer");
if (NeedDepthBufferCopy())
{

cmd.SetGlobalTexture("_MainDepthTexture", GetDepthTexture());
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
public void UpdateCommonSettings()

if (camera == null)
{
renderContext.Submit();
CommandBufferPool.EndOfFrame();
return;
}

if (!CullResults.GetCullingParameters(camera, out cullingParams))
{
renderContext.Submit();
CommandBufferPool.EndOfFrame();
return;
}

if (camera.cameraType == CameraType.Reflection)
{
// Simple blit
var cmd = new CommandBuffer { name = "Blit to final RT" };
var cmd = CommandBufferPool.Get("Blit to final RT" );
cmd.Dispose();
}
else
{

// bind depth surface for editor grid/gizmo/selection rendering
if (camera.cameraType == CameraType.SceneView)
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
CommandBufferPool.EndOfFrame();
}
void RenderOpaqueRenderList(CullResults cull, Camera camera, ScriptableRenderContext renderContext, string passName, RendererConfiguration rendererConfiguration = 0)

Utilities.SetupMaterialHDCamera(hdCamera, m_DebugViewMaterialGBuffer);
// TODO: Bind depth textures
var cmd = new CommandBuffer { name = "DebugViewMaterialGBuffer" };
var cmd = CommandBufferPool.Get("DebugViewMaterialGBuffer" );
cmd.Dispose();
}
// Render forward transparent

// Last blit
{
var cmd = new CommandBuffer { name = "Blit DebugView Material Debug" };
var cmd = CommandBufferPool.Get("Blit DebugView Material Debug");
cmd.Dispose();
}
}

if (!m_DebugDisplaySettings.renderingDebugSettings.enableSSSAndTransmission || m_Asset.renderingSettings.ShouldUseForwardRenderingOnly())
return;
var cmd = new CommandBuffer() { name = "Subsurface Scattering" };
var cmd = CommandBufferPool.Get("Subsurface Scattering");
if (sssSettings.useDisneySSS)
{

}
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext)

int w = camera.pixelWidth;
int h = camera.pixelHeight;
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get("");
cmd.Dispose();
RenderOpaqueRenderList(cullResults, camera, renderContext, "MotionVectors");
}

int w = camera.pixelWidth;
int h = camera.pixelHeight;
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get("");
cmd.Dispose();
// Only transparent object can render distortion vectors
RenderTransparentRenderList(cullResults, camera, renderContext, "DistortionVectors");

using (new Utilities.ProfilingSample("Post-processing", renderContext))
{
var postProcessLayer = camera.GetComponent<PostProcessLayer>();
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get("");
if (postProcessLayer != null && postProcessLayer.enabled)
{

}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}

// 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.
Utilities.SetRenderTarget(renderContext, BuiltinRenderTextureType.CameraTarget, m_CameraDepthStencilBufferRT);
CommandBuffer debugCB = new CommandBuffer();
CommandBuffer debugCB = CommandBufferPool.Get();
debugCB.name = "Render Debug";
// First render full screen debug texture

// Clear depth/stencil and init buffers
using (new Utilities.ProfilingSample("InitGBuffers and clear Depth/Stencil", renderContext))
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.name = "";
// Init buffer

}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
Utilities.SetRenderTarget(renderContext, m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, ClearFlag.ClearDepth);
}

3
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/AmbientOcclusion/ScreenSpaceAmbientOcclusion.cs


if (m_Command == null)
{
m_Command = new CommandBuffer { name = "Ambient Occlusion" };
m_Command = CommandBufferPool.Get("Ambient Occlusion");
}
else
{

public void Cleanup()
{
Utilities.Destroy(m_Material);
if (m_Command != null) m_Command.Dispose();
}
}
}

20
Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs


var projscr = temp * proj;
var invProjscr = projscr.inverse;
var cmd = new CommandBuffer() { name = "" };
var cmd = CommandBufferPool.Get("");
cmd.SetRenderTarget(new RenderTargetIdentifier((Texture)null));
// generate screen-space AABBs (used for both fptl and clustered).

}
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// This is a workaround for global properties not being accessible from compute.

private void PushGlobalParams(Camera camera, ScriptableRenderContext loop, ComputeShader computeShader, int kernelIndex)
{
var cmd = new CommandBuffer { name = "Push Global Parameters" };
var cmd = CommandBufferPool.Get("Push Global Parameters");
// Shadows
m_ShadowMgr.SyncData();

SetGlobalPropertyRedirect(null, 0, null);
loop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
#if UNITY_EDITOR

if (m_TileSettings.tileDebugByCategory == TileSettings.TileDebug.None)
return;
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.name = "Tiled Lighting Debug";
bool bUseClusteredForDeferred = !usingFptl;

SetGlobalPropertyRedirect(null, 0, null);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
public void RenderDeferredLighting( HDCamera hdCamera, ScriptableRenderContext renderContext,

using (new Utilities.ProfilingSample((m_TileSettings.enableTileAndCluster ? "TilePass - Deferred Lighting Pass" : "SinglePass - Deferred Lighting Pass") + (outputSplitLighting ? " MRT" : ""), renderContext))
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.name = bUseClusteredForDeferred ? "Clustered pass" : "Tiled pass";
var camera = hdCamera.camera;

SetGlobalPropertyRedirect(null, 0, null);
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
} // TilePass - Deferred Lighting Pass
}

bool useFptl = renderOpaque && usingFptl;
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
if (!m_TileSettings.enableTileAndCluster)
{

}
renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
public void RenderDebugOverlay(Camera camera, ScriptableRenderContext renderContext, DebugDisplaySettings debugDisplaySettings, ref float x, ref float y, float overlaySize, float width)

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.cs


if (m_isInit)
return;
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
m_isInit = true;
}

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


m_SkyHDRIMaterial.SetTexture("_Cubemap", m_HdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector("_SkyParam", new Vector4(m_HdriSkyParams.exposure, m_HdriSkyParams.multiplier, m_HdriSkyParams.rotation, 0.0f));
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get("");
cmd.Dispose();
}
public override bool IsSkyValid()

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


// Set shader constants.
SetUniforms(builtinParams, m_ProceduralSkySettings, renderForCubemap, ref properties);
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get("");
cmd.Dispose();
}
}
}

12
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/RuntimeFilterIBL.cs


m_ComputeGgxIblSampleDataCS.SetTexture(m_ComputeGgxIblSampleDataKernel, "output", m_GgxIblSampleData);
var cmd = new CommandBuffer() { name = "Compute GGX IBL Sample Data" };
var cmd = CommandBufferPool.Get("Compute GGX IBL Sample Data");
cmd.Dispose();
}
}

{
Utilities.SetRenderTarget(context, target, ClearFlag.ClearNone, mip, (CubemapFace)face);
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get();
cmd.Dispose();
}
}
}

int numRows = conditionalCdf.height;
var cmd = new CommandBuffer() { name = "Build Probability Tables" };
var cmd = CommandBufferPool.Get("Build Probability Tables");
cmd.Dispose();
m_GgxConvolveMaterial.EnableKeyword("USE_MIS");
m_GgxConvolveMaterial.SetTexture("_ConditionalDensities", conditionalCdf);

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


for (int i = 0; i < 6; ++i)
{
Utilities.SetRenderTarget(renderContext, dest, ClearFlag.ClearNone, 0, (CubemapFace)i);
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get();
cmd.Dispose();
}
}

}
// Copy the first mip
var cmd = new CommandBuffer { name = "" };
var cmd = CommandBufferPool.Get();
cmd.Dispose();
if (m_useMIS && m_iblFilterGgx.SupportMIS)
{

24
Assets/ScriptableRenderPipeline/HDRenderPipeline/Utilities.cs


public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
}
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.ClearNone, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)

public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
}
public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer)

public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
{
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.Dispose();
var cmd = new CommandBuffer();
var cmd = CommandBufferPool.Get();
cmd.name = "";
for(int i = 0 ; i < 6 ; ++i)

renderContext.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// Miscellanous

renderContext = _renderloop;
name = _name;
CommandBuffer cmd = new CommandBuffer();
CommandBuffer cmd = CommandBufferPool.Get();
cmd.Dispose();
}
~ProfilingSample()

if (disposing)
{
CommandBuffer cmd = new CommandBuffer();
CommandBuffer cmd = CommandBufferPool.Get();
cmd.Dispose();
}
disposed = true;

21
Assets/ScriptableRenderPipeline/LightweightPipeline/LightweightPipeline.cs


// Clear RenderTarget to avoid tile initialization on mobile GPUs
// https://community.arm.com/graphics/b/blog/posts/mali-performance-2-how-to-correctly-handle-framebuffers
var cmd = new CommandBuffer() { name = "Clear" };
var cmd = CommandBufferPool.Get("Clear");
cmd.Dispose();
// Setup light and shadow shader constants
SetupLightShaderVariables(visibleLights, ref cullResults, ref context, ref lightData);

context.DrawRenderers(ref litSettings);
// Release temporary RT
var discardRT = new CommandBuffer();
var discardRT = CommandBufferPool.Get();
discardRT.Dispose();
context.DrawRenderers(ref unlitSettings);

}
context.Submit();
CommandBufferPool.EndOfFrame();
}
private void BuildShadowSettings()

}
}
CommandBuffer cmd = new CommandBuffer() {name = "SetupShadowShaderConstants"};
CommandBuffer cmd = CommandBufferPool.Get("SetupShadowShaderConstants");
cmd.SetGlobalVectorArray("globalLightPos", m_LightPositions);
cmd.SetGlobalVectorArray("globalLightColor", m_LightColors);
cmd.SetGlobalVectorArray("globalLightAtten", m_LightAttenuations);

cmd.SetGlobalVector("globalLightData", new Vector4(lightData.pixelLightsCount, m_ShadowLightIndex, m_Asset.ShadowMinNormalBias, m_Asset.ShadowNormalBias));
SetShaderKeywords(cmd, lightData.isSingleDirectionalLight, lightData.vertexLightsCount > 0);
context.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
private bool RenderShadows(ref CullResults cullResults, ref VisibleLight shadowLight, ref ScriptableRenderContext context)

if (!cullResults.GetShadowCasterBounds(m_ShadowLightIndex, out bounds))
return false;
var setRenderTargetCommandBuffer = new CommandBuffer();
var setRenderTargetCommandBuffer = CommandBufferPool.Get();
setRenderTargetCommandBuffer.name = "Render packed shadows";
setRenderTargetCommandBuffer.GetTemporaryRT(m_ShadowMapProperty, m_ShadowSettings.shadowAtlasWidth,
m_ShadowSettings.shadowAtlasHeight, m_DepthBufferBits, FilterMode.Bilinear, RenderTextureFormat.Depth,

context.ExecuteCommandBuffer(setRenderTargetCommandBuffer);
setRenderTargetCommandBuffer.Dispose();
float shadowNearPlane = m_Asset.ShadowNearOffset;
Vector3 splitRatio = m_ShadowSettings.directionalLightCascades;

private void RenderShadowSlice(ref ScriptableRenderContext context, Vector3 lightDir, int cascadeIndex,
Matrix4x4 proj, Matrix4x4 view, DrawShadowsSettings settings)
{
var buffer = new CommandBuffer() {name = "Prepare Shadowmap Slice"};
var buffer = CommandBufferPool.Get("Prepare Shadowmap Slice");
buffer.Dispose();
context.DrawShadows(ref settings);
}

0.5f * invShadowResolution, -0.5f * invShadowResolution
};
var setupShadow = new CommandBuffer() {name = "SetupShadowShaderConstants"};
var setupShadow = CommandBufferPool.Get("SetupShadowShaderConstants");
setupShadow.Dispose();
}
private void SetShaderKeywords(CommandBuffer cmd, bool singleDirecitonal, bool vertexLightSupport)

72
Assets/ScriptableRenderPipeline/core/CommandBufferPool.cs


using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering
{
class ObjectPool<T> where T : new()
{
private readonly Stack<T> m_Stack = new Stack<T>();
private readonly List<T> m_Loaned = new List<T>();
private readonly UnityAction<T> m_ActionOnGet;
private readonly UnityAction<T> m_ActionOnRelease;
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
{
m_ActionOnGet = actionOnGet;
m_ActionOnRelease = actionOnRelease;
}
public T Get()
{
T element;
if (m_Stack.Count == 0)
{
element = new T();
}
else
{
element = m_Stack.Pop();
}
m_Loaned.Add(element);
if (m_ActionOnGet != null)
m_ActionOnGet(element);
return element;
}
public void ReleaseAll()
{
foreach (var element in m_Loaned)
{
if (m_ActionOnRelease != null)
m_ActionOnRelease(element);
m_Stack.Push(element);
}
m_Loaned.Clear();
}
}
public class CommandBufferPool
{
private static ObjectPool<CommandBuffer> m_BufferPool = new ObjectPool<CommandBuffer>(null, x => x.Clear());
public static CommandBuffer Get()
{
var cmd = m_BufferPool.Get();
cmd.name = "Unnamed Command Buffer";
return cmd;
}
public static CommandBuffer Get(string name)
{
var cmd = m_BufferPool.Get();
cmd.name = name;
return cmd;
}
public static void EndOfFrame()
{
m_BufferPool.ReleaseAll();
}
}
}

12
Assets/ScriptableRenderPipeline/core/CommandBufferPool.cs.meta


fileFormatVersion: 2
guid: bc85748f0cef607499e03b46e3846ebd
timeCreated: 1497364325
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存