浏览代码

Merge pull request #397 from Unity-Technologies/fptl-asyncfence-changes

Removed all use of GPUFences if async compute is not in use. Fixed a …
/main
GitHub 7 年前
当前提交
60b5ff01
共有 1 个文件被更改,包括 68 次插入26 次删除
  1. 94
      TestbedPipelines/Fptl/FptlLighting.cs

94
TestbedPipelines/Fptl/FptlLighting.cs


// build per tile light lists
var numLights = GenerateSourceLightBuffers(camera, cullResults);
CommandBuffer cmdPreShadows = CommandBufferPool.Get();
GPUFence preShadowsFence = cmdPreShadows.CreateGPUFence();
loop.ExecuteCommandBuffer(cmdPreShadows);
CommandBufferPool.Release(cmdPreShadows);
GPUFence postLightListFence;
if (k_UseAsyncCompute)
{
CommandBuffer cmdPreShadows = CommandBufferPool.Get();
GPUFence preShadowsFence = cmdPreShadows.CreateGPUFence();
loop.ExecuteCommandBuffer(cmdPreShadows);
CommandBufferPool.Release(cmdPreShadows);
GPUFence postLightListFence = BuildPerTileLightLists(camera, loop, numLights, projscr, invProjscr, preShadowsFence);
postLightListFence = BuildPerTileLightListsAsync(camera, loop, numLights, projscr, invProjscr, preShadowsFence);
}
else
{
BuildPerTileLightLists(camera, loop, numLights, projscr, invProjscr);
}
CommandBuffer cmdShadow = CommandBufferPool.Get();
m_ShadowMgr.RenderShadows( m_FrameId, loop, cmdShadow, cullResults, cullResults.visibleLights );

// Push all global params
var numDirLights = UpdateDirectionalLights(camera, cullResults.visibleLights, m_ShadowIndices);
PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights, postLightListFence);
if (k_UseAsyncCompute)
{
PushGlobalParamsWithFence(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights, postLightListFence);
}
else
{
PushGlobalParams(camera, loop, CameraToWorld(camera), projscr, invProjscr, numDirLights);
}
// do deferred lighting
DoTiledDeferredLighting(camera, loop, numLights, numDirLights);

cmd.DispatchCompute(buildPerVoxelLightListShader, s_GenListPerVoxelKernel, nrTilesClustX, nrTilesClustY, 1);
}
GPUFence BuildPerTileLightLists(Camera camera, ScriptableRenderContext loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr, GPUFence startFence)
void BuildPerTileLightLists(Camera camera, ScriptableRenderContext loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr)
{
var cmd = CommandBufferPool.Get("Build light list");
BuildPerTileLightListsCommon(camera, loop, numLights, projscr, invProjscr, cmd);
loop.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}
GPUFence BuildPerTileLightListsAsync(Camera camera, ScriptableRenderContext loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr, GPUFence startFence)
{
var cmd = CommandBufferPool.Get("Build light list");
cmd.WaitOnGPUFence(startFence);
BuildPerTileLightListsCommon(camera, loop, numLights, projscr, invProjscr, cmd);
GPUFence completeFence = cmd.CreateGPUFence();
loop.ExecuteCommandBufferAsync(cmd, ComputeQueueType.Default);
CommandBufferPool.Release(cmd);
return completeFence;
}
void BuildPerTileLightListsCommon(Camera camera, ScriptableRenderContext loop, int numLights, Matrix4x4 projscr, Matrix4x4 invProjscr, CommandBuffer cmd)
{
var w = camera.pixelWidth;
var h = camera.pixelHeight;

var numBigTilesY = (h + 63) / 64;
var cmd = CommandBufferPool.Get("Build light list" );
cmd.WaitOnGPUFence(startFence);
bool isOrthographic = camera.orthographic;

VoxelLightListGeneration(cmd, camera, numLights, projscr, invProjscr);
}
GPUFence completeFence = cmd.CreateGPUFence();
}
if (k_UseAsyncCompute)
{
loop.ExecuteCommandBufferAsync(cmd, ComputeQueueType.Default);
}
else
{
loop.ExecuteCommandBuffer(cmd);
}
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights)
{
var cmd = CommandBufferPool.Get("Push Global Parameters");
PushGlobalParamsCommon(camera, loop, viewToWorld, scrProj, incScrProj, numDirLights, cmd);
return completeFence;
void PushGlobalParams(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights, GPUFence startFence)
void PushGlobalParamsWithFence(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights, GPUFence startFence)
PushGlobalParamsCommon(camera, loop, viewToWorld, scrProj, incScrProj, numDirLights, cmd);
CommandBufferPool.Release(cmd);
}
void PushGlobalParamsCommon(Camera camera, ScriptableRenderContext loop, Matrix4x4 viewToWorld, Matrix4x4 scrProj, Matrix4x4 incScrProj, int numDirLights, CommandBuffer cmd)
{
cmd.SetGlobalFloat("g_isOrthographic", (float) (isOrthographic ? 1 : 0));
cmd.SetGlobalFloat("g_isOrthographic", (float)(isOrthographic ? 1 : 0));
cmd.SetGlobalFloat("g_widthRT", (float)camera.pixelWidth);
cmd.SetGlobalFloat("g_heightRT", (float)camera.pixelHeight);

cmd.SetGlobalVector("g_vShadow3x3PCFTerms3", m_Shadow3X3PCFTerms[3]);
loop.ExecuteCommandBuffer(cmd);
}
}
}
正在加载...
取消
保存