浏览代码

Rework cluster kernel name gen to relieve GC pressure

Originally, I concatenated strings in order to generated the clustered light list generation kernel name.  But @chman pointed out this would be bad for the GC, since this code runs every frame.

So instead, I pre-generate the kernel names, and index into a 2D array to select the correct kernel string.  Heck, it may even look nicer this way.
/main
Robert Srinivasiah 7 年前
当前提交
8828b0b7
共有 1 个文件被更改,包括 27 次插入9 次删除
  1. 36
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs

36
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/LightLoop.cs


static ComputeBuffer s_PerVoxelOffset = null;
static ComputeBuffer s_PerTileLogBaseTweak = null;
static ComputeBuffer s_GlobalLightListAtomic = null;
public enum ClusterPrepassSource : int
{
None = 0,
BigTile = 1,
Count = 2,
}
public enum ClusterDepthSource : int
{
NoDepth = 0,
Depth = 1,
MSAA_Depth = 2,
Count = 3,
}
static string[,] s_ClusterKernelNames = new string[(int)ClusterPrepassSource.Count, (int)ClusterDepthSource.Count]
{
{ "TileLightListGen_NoDepthRT", "TileLightListGen_DepthRT", "TileLightListGen_DepthRT_MSAA" },
{ "TileLightListGen_NoDepthRT_SrcBigTile", "TileLightListGen_DepthRT_SrcBigTile", "TileLightListGen_DepthRT_MSAA_SrcBigTile" }
};
// clustered light list specific buffers and data end
static int[] s_TempIntArray = new int[2]; // Used to avoid GC stress when calling SetComputeIntParams

// Cluster
{
var kernelName = "TileLightListGen";
var clustPrepassSourceIdx = m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? ClusterPrepassSource.BigTile : ClusterPrepassSource.None;
var clustDepthSourceIdx = ClusterDepthSource.NoDepth;
kernelName += "_DepthRT";
kernelName += "_MSAA";
clustDepthSourceIdx = ClusterDepthSource.MSAA_Depth;
else
clustDepthSourceIdx = ClusterDepthSource.Depth;
else
{
kernelName += "_NoDepthRT";
}
if (m_FrameSettings.lightLoopSettings.enableBigTilePrepass)
kernelName += "_SrcBigTile";
var kernelName = s_ClusterKernelNames[(int)clustPrepassSourceIdx, (int)clustDepthSourceIdx];
s_GenListPerVoxelKernel = buildPerVoxelLightListShader.FindKernel(kernelName);
}

正在加载...
取消
保存