浏览代码

Added explicit load and store actions to all SetRenderTarget commands.

/main
Aleksandr Kirillov 7 年前
当前提交
1f4e5415
共有 3 个文件被更改,包括 58 次插入23 次删除
  1. 20
      ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs
  2. 54
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs
  3. 7
      ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs

20
ScriptableRenderPipeline/Core/CoreRP/Utilities/CoreUtils.cs


ClearRenderTarget(cmd, clearFlag, clearColor);
}
// Explicit load and store actions
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag, Color clearColor)
{
cmd.SetRenderTarget(buffer, loadAction, storeAction);
ClearRenderTarget(cmd, clearFlag, clearColor);
}
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag)
{
SetRenderTarget(cmd, buffer, loadAction, storeAction, clearFlag, clearColorAllBlack);
}
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthBuffer, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction,
ClearFlag clearFlag, Color clearColor)
{
cmd.SetRenderTarget(colorBuffer, colorLoadAction, colorStoreAction, depthBuffer, depthLoadAction, depthStoreAction);
ClearRenderTarget(cmd, clearFlag, clearColor);
}
public static string GetRenderTargetAutoName(int width, int height, RenderTextureFormat format, string name = "", bool mips = false, bool enableMSAA = false, MSAASamples msaaSamples = MSAASamples.None)
{
string temp;

54
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightPipeline.cs


private void DepthPass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration)
{
CommandBuffer cmd = CommandBufferPool.Get("Depth Prepass");
SetRenderTarget(cmd, m_DepthRT, ClearFlag.Depth);
SetRenderTarget(cmd, m_DepthRT, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Depth);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

StopStereoRendering(m_CurrCamera, ref context, frameRenderingConfiguration);
}
private void OpaqueTexturePass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration)
private void OpaqueTexturePass(ref ScriptableRenderContext context, FrameRenderingConfiguration frameRenderingConfiguration, RenderTargetIdentifier depthRT)
{
var opaqueScaler = m_OpaqueScalerValues[(int)m_Asset.OpaqueDownsampling];
RenderTextureDescriptor opaqueDesc = CreateRTDesc(frameRenderingConfiguration, opaqueScaler);

cmd.Blit(m_CurrCameraColorRT, CameraRenderTargetID.opaque);
break;
}
SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);
SetRenderTarget(cmd, m_CurrCameraColorRT, depthRT, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);
}

private void AfterOpaque(ref ScriptableRenderContext context, FrameRenderingConfiguration config)
{
RenderTargetIdentifier depthRT = m_DepthRT;
bool doOpaqueCopy = m_Asset.RequireOpaqueTexture;
if (m_RequireDepthTexture)
{
CommandBuffer cmd = CommandBufferPool.Get("After Opaque");

RenderTargetIdentifier depthRT = m_DepthRT;
// TODO: There's currently an issue in the PostFX stack that has a one frame delay when an effect is enabled/disabled
// when an effect is disabled, HasOpaqueOnlyEffects returns true in the first frame, however inside render the effect

RenderPostProcess(cmd, m_CurrCameraColorRT, m_CurrCameraColorRT, true);
setRenderTarget = true;
SetRenderTarget(cmd, m_CurrCameraColorRT, m_DepthRT);
}
if (CoreUtils.HasFlag(config, FrameRenderingConfiguration.DepthCopy))

cmd.SetGlobalTexture(CameraRenderTargetID.depth, m_CopyDepth);
}
if (setRenderTarget)
SetRenderTarget(cmd, m_CurrCameraColorRT, depthRT);
if (setRenderTarget && !doOpaqueCopy)
SetRenderTarget(cmd, m_CurrCameraColorRT, depthRT, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store);
if (m_Asset.RequireOpaqueTexture)
if (doOpaqueCopy)
OpaqueTexturePass(ref context, config);
OpaqueTexturePass(ref context, config, depthRT);
}
}

clearFlag |= ClearFlag.Color;
}
SetRenderTarget(cmd, colorRT, depthRT, clearFlag);
SetRenderTarget(cmd, colorRT, depthRT, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag);
// If rendering to an intermediate RT we resolve viewport on blit due to offset not being supported
// while rendering to a RT.

return;
var cmd = CommandBufferPool.Get("Blit");
bool skipSetRT = false;
skipSetRT = true;
}
else if (CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.IntermediateTexture))
{

// If PostProcessing is enabled, it is already blit to CameraTarget.
if (!CoreUtils.HasFlag(renderingConfig, FrameRenderingConfiguration.PostProcess))
{
skipSetRT = true;
}
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
if (!skipSetRT)
SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store);
context.ExecuteCommandBuffer(cmd);
CommandBufferPool.Release(cmd);

m_CameraPostProcessLayer.Render(m_PostProcessRenderContext);
}
private void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, ClearFlag clearFlag = ClearFlag.None)
private void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag = ClearFlag.None)
int depthSlice = (m_IntermediateTextureArray) ? -1 : 0;
CoreUtils.SetRenderTarget(cmd, colorRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, depthSlice);
if (m_IntermediateTextureArray)
CoreUtils.SetRenderTarget(cmd, colorRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorRT, loadAction, storeAction, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor));
private void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderTargetIdentifier depthRT, ClearFlag clearFlag = ClearFlag.None)
private void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthRT, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction, ClearFlag clearFlag = ClearFlag.None)
SetRenderTarget(cmd, colorRT, clearFlag);
SetRenderTarget(cmd, colorRT, colorLoadAction, colorStoreAction, clearFlag);
int depthSlice = (m_IntermediateTextureArray) ? -1 : 0;
CoreUtils.SetRenderTarget(cmd, colorRT, depthRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, depthSlice);
if (m_IntermediateTextureArray)
CoreUtils.SetRenderTarget(cmd, colorRT, depthRT, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor), 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorRT, colorLoadAction, colorStoreAction, depthRT, depthLoadAction, depthStoreAction, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(m_CurrCamera.backgroundColor));
}
private void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorRT, RenderTargetIdentifier depthRT, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag = ClearFlag.None)
{
SetRenderTarget(cmd, colorRT, loadAction, storeAction, depthRT, loadAction, storeAction, clearFlag);
}
private void Blit(CommandBuffer cmd, FrameRenderingConfiguration renderingConfig, RenderTargetIdentifier sourceRT, RenderTargetIdentifier destRT, Material material = null)

{
// Viewport doesn't work when rendering to an RT
// We have to manually blit by rendering a fullscreen quad
SetRenderTarget(cmd, destRT);
SetRenderTarget(cmd, destRT, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
cmd.SetViewport(m_CurrCamera.pixelRect);
DrawFullScreen(cmd, m_BlitMaterial);

7
ScriptableRenderPipeline/LightweightPipeline/LWRP/LightweightShadowPass.cs


// stereo functionality, we use the screen-space shadow map as the source (until we have
// a better solution).
// An alternative would be DrawProcedural, but that would require further changes in the shader.
cmd.SetRenderTarget(m_ScreenSpaceShadowmapTexture);
cmd.ClearRenderTarget(true, true, Color.white);
CoreUtils.SetRenderTarget(cmd, m_ScreenSpaceShadowmapTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Color | ClearFlag.Depth, Color.white);
cmd.Blit(m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowmapTexture, m_ScreenSpaceShadowsMaterial);
LightweightPipeline.StartStereoRendering(camera, ref context, frameRenderingConfiguration);

m_DirectionalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_DirectionalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
CoreUtils.SetRenderTarget(cmd, m_DirectionalShadowmapTexture, ClearFlag.Depth);
CoreUtils.SetRenderTarget(cmd, m_DirectionalShadowmapTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Depth);
bool success = false;
for (int cascadeIndex = 0; cascadeIndex < m_ShadowCasterCascadesCount; ++cascadeIndex)

m_LocalShadowmapTexture.filterMode = FilterMode.Bilinear;
m_LocalShadowmapTexture.wrapMode = TextureWrapMode.Clamp;
CoreUtils.SetRenderTarget(cmd, m_LocalShadowmapTexture, ClearFlag.Depth);
CoreUtils.SetRenderTarget(cmd, m_LocalShadowmapTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Depth);
for (int i = 0; i < localLightsCount; ++i)
{

正在加载...
取消
保存