Resource transition fixes

#codereview Nick.Penwarden

[CL 2749347 by Marcus Wassmer in Main branch]
This commit is contained in:
Marcus Wassmer
2015-10-31 14:47:30 -04:00
committed by Marcus.Wassmer@epicgames.com
parent 15d40d9562
commit eb11aa516e
4 changed files with 93 additions and 59 deletions

View File

@@ -1279,7 +1279,7 @@ void FDeferredShadingSceneRenderer::Render(FRHICommandListImmediate& RHICmdList)
GetRendererModule().RenderPostOpaqueExtensions(View, RHICmdList, SceneContext);
}
SceneContext.FinishRenderingSceneColor(RHICmdList, false);
SceneContext.FinishRenderingSceneColor(RHICmdList, true);
}
// No longer needed, release
@@ -1904,4 +1904,6 @@ void FDeferredShadingSceneRenderer::DownsampleDepthSurface(FRHICommandList& RHIC
SceneContext.GetBufferSizeXY(),
*ScreenVertexShader,
EDRF_UseTriangleOptimization);
RHICmdList.TransitionResource(EResourceTransitionAccess::EReadable, RenderTarget);
}

View File

@@ -991,7 +991,7 @@ void FSceneRenderer::RenderDistortion(FRHICommandListImmediate& RHICmdList)
RHICmdList.SetDepthStencilState(TStaticDepthStencilState<false, CF_DepthNearOrEqual>::GetRHI());
// Distortions RT is no longer needed, buffer can be reused by the pool, see BeginRenderingDistortionAccumulation() call above
SceneContext.FinishRenderingSceneColor(RHICmdList, false);
SceneContext.FinishRenderingSceneColor(RHICmdList, true);
}
}

View File

@@ -734,44 +734,59 @@ void FDeferredShadingSceneRenderer::RenderLightShaftOcclusion(FRHICommandListImm
if (bEnableOcclusion && LightSceneInfo->Proxy->GetLightType() == LightType_Directional)
{
// Allocate light shaft render targets on demand, using the pool
// Need two targets to ping pong between
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts0, TEXT("LightShafts0"));
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts1, TEXT("LightShafts1"));
bool bWillRenderLightShafts = false;
for (int ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++)
for (int ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
FViewInfo& View = Views[ViewIndex];
SCOPED_DRAW_EVENTF(RHICmdList, RenderLightShaftOcclusion, TEXT("RenderLightShaftOcclusion %dx%d (multiple passes)"), View.ViewRect.Width(), View.ViewRect.Height());
if (ShouldRenderLightShaftsForLight(View, LightSceneInfo))
{
INC_DWORD_STAT(STAT_LightShaftsLights);
// Create a downsampled occlusion mask from scene depth, result will be in LightShafts0
DownsamplePass<true>(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
FSceneViewState* ViewState = (FSceneViewState*)View.State;
// Find the previous frame's occlusion mask
TRefCountPtr<IPooledRenderTarget>* HistoryState = ViewState ? &ViewState->LightShaftOcclusionHistoryRT : NULL;
TRefCountPtr<IPooledRenderTarget> HistoryOutput;
// Apply temporal AA to the occlusion mask
// Result will be in HistoryOutput
ApplyTemporalAA(RHICmdList, View, TEXT("LSOcclusionHistory"), HistoryState, LightShafts0, HistoryOutput);
// Apply radial blur passes
// Send HistoryOutput in as the first pass input only, so it will not be overwritten by any subsequent passes, since it is needed for next frame
ApplyRadialBlurPasses(RHICmdList, View, LightSceneInfo, HistoryOutput, LightShafts0, LightShafts1);
// Apply post-blur masking
FinishOcclusionTerm(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
//@todo - different views could have different result render targets
Output.LightShaftOcclusion = LightShafts1;
bWillRenderLightShafts = true;
}
}
if (bWillRenderLightShafts)
{
// Allocate light shaft render targets on demand, using the pool
// Need two targets to ping pong between
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts0, TEXT("LightShafts0"));
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts1, TEXT("LightShafts1"));
for (int ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
FViewInfo& View = Views[ViewIndex];
SCOPED_DRAW_EVENTF(RHICmdList, RenderLightShaftOcclusion, TEXT("RenderLightShaftOcclusion %dx%d (multiple passes)"), View.ViewRect.Width(), View.ViewRect.Height());
if (ShouldRenderLightShaftsForLight(View, LightSceneInfo))
{
INC_DWORD_STAT(STAT_LightShaftsLights);
// Create a downsampled occlusion mask from scene depth, result will be in LightShafts0
DownsamplePass<true>(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
FSceneViewState* ViewState = (FSceneViewState*)View.State;
// Find the previous frame's occlusion mask
TRefCountPtr<IPooledRenderTarget>* HistoryState = ViewState ? &ViewState->LightShaftOcclusionHistoryRT : NULL;
TRefCountPtr<IPooledRenderTarget> HistoryOutput;
// Apply temporal AA to the occlusion mask
// Result will be in HistoryOutput
ApplyTemporalAA(RHICmdList, View, TEXT("LSOcclusionHistory"), HistoryState, LightShafts0, HistoryOutput);
// Apply radial blur passes
// Send HistoryOutput in as the first pass input only, so it will not be overwritten by any subsequent passes, since it is needed for next frame
ApplyRadialBlurPasses(RHICmdList, View, LightSceneInfo, HistoryOutput, LightShafts0, LightShafts1);
// Apply post-blur masking
FinishOcclusionTerm(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
//@todo - different views could have different result render targets
Output.LightShaftOcclusion = LightShafts1;
}
}
}
}
}
}
@@ -909,44 +924,59 @@ void FDeferredShadingSceneRenderer::RenderLightShaftBloom(FRHICommandListImmedia
if (LightSceneInfo->bEnableLightShaftBloom)
{
// Allocate light shaft render targets on demand, using the pool
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts0, TEXT("LightShafts0"));
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts1, TEXT("LightShafts1"));
bool bWillRenderLightShafts = false;
for (int ViewIndex = 0;ViewIndex < Views.Num();ViewIndex++)
for (int ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
FViewInfo& View = Views[ViewIndex];
SCOPED_DRAW_EVENTF(RHICmdList, RenderLightShaftBloom, TEXT("RenderLightShaftBloom %dx%d"), View.ViewRect.Width(), View.ViewRect.Height());
if (ShouldRenderLightShaftsForLight(View, LightSceneInfo))
{
INC_DWORD_STAT(STAT_LightShaftsLights);
bWillRenderLightShafts = true;
}
}
// Generate the bloom source from scene color, masked by depth and downsampled
DownsamplePass<false>(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
if (bWillRenderLightShafts)
{
// Allocate light shaft render targets on demand, using the pool
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts0, TEXT("LightShafts0"));
AllocateOrReuseLightShaftRenderTarget(RHICmdList, LightShafts1, TEXT("LightShafts1"));
FSceneViewState* ViewState = (FSceneViewState*)View.State;
TRefCountPtr<IPooledRenderTarget>* HistoryState = NULL;
for (int ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
{
FViewInfo& View = Views[ViewIndex];
if (ViewState)
SCOPED_DRAW_EVENTF(RHICmdList, RenderLightShaftBloom, TEXT("RenderLightShaftBloom %dx%d"), View.ViewRect.Width(), View.ViewRect.Height());
if (ShouldRenderLightShaftsForLight(View, LightSceneInfo))
{
// Find the previous frame's bloom source for this light
HistoryState = &ViewState->LightShaftBloomHistoryRTs.FindOrAdd(LightSceneInfo->Proxy->GetLightComponent());
INC_DWORD_STAT(STAT_LightShaftsLights);
// Generate the bloom source from scene color, masked by depth and downsampled
DownsamplePass<false>(RHICmdList, View, LightSceneInfo, LightShafts0, LightShafts1);
FSceneViewState* ViewState = (FSceneViewState*)View.State;
TRefCountPtr<IPooledRenderTarget>* HistoryState = NULL;
if (ViewState)
{
// Find the previous frame's bloom source for this light
HistoryState = &ViewState->LightShaftBloomHistoryRTs.FindOrAdd(LightSceneInfo->Proxy->GetLightComponent());
}
TRefCountPtr<IPooledRenderTarget> HistoryOutput;
// Apply temporal AA to the occlusion mask
// Result will be in HistoryOutput
ApplyTemporalAA(RHICmdList, View, TEXT("LSBloomHistory"), HistoryState, LightShafts0, HistoryOutput);
// Apply radial blur passes
// Send HistoryOutput in as the first pass input only, so it will not be overwritten by any subsequent passes, since it is needed for next frame
ApplyRadialBlurPasses(RHICmdList, View, LightSceneInfo, HistoryOutput, LightShafts0, LightShafts1);
// Add light shaft bloom to scene color in full res
ApplyLightShaftBloom(RHICmdList, View, LightSceneInfo, LightShafts0);
}
TRefCountPtr<IPooledRenderTarget> HistoryOutput;
// Apply temporal AA to the occlusion mask
// Result will be in HistoryOutput
ApplyTemporalAA(RHICmdList, View, TEXT("LSBloomHistory"), HistoryState, LightShafts0, HistoryOutput);
// Apply radial blur passes
// Send HistoryOutput in as the first pass input only, so it will not be overwritten by any subsequent passes, since it is needed for next frame
ApplyRadialBlurPasses(RHICmdList, View, LightSceneInfo, HistoryOutput, LightShafts0, LightShafts1);
// Add light shaft bloom to scene color in full res
ApplyLightShaftBloom(RHICmdList, View, LightSceneInfo, LightShafts0);
}
}
}

View File

@@ -461,6 +461,8 @@ void RenderHitProxies(FRHICommandListImmediate& RHICmdList, const FSceneRenderer
// Finish drawing to the hit proxy render target.
RHICmdList.CopyToResolveTarget(HitProxyRT->GetRenderTargetItem().TargetableTexture, HitProxyRT->GetRenderTargetItem().ShaderResourceTexture, false, FResolveParams());
RHICmdList.CopyToResolveTarget(SceneContext.GetSceneDepthSurface(), SceneContext.GetSceneDepthSurface(), true, FResolveParams());
// to be able to observe results with VisualizeTexture
GRenderTargetPool.VisualizeTexture.SetCheckPoint(RHICmdList, HitProxyRT);