Skip to content

Commit 1a24cb3

Browse files
YOungchenyong2github
YOung
authored andcommitted
Support standalone temporal AA on mobile platforms. WITH VELOCITY PASS
1 parent 67b7678 commit 1a24cb3

File tree

7 files changed

+177
-3
lines changed

7 files changed

+177
-3
lines changed

Engine/Source/Runtime/Renderer/Private/MobileShadingRenderer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,15 @@ void FMobileSceneRenderer::InitViews(FRHICommandListImmediate& RHICmdList)
386386
// See CVarMobileForceDepthResolve use in ConditionalResolveSceneDepth.
387387
const bool bForceDepthResolve = (CVarMobileForceDepthResolve.GetValueOnRenderThread() == 1);
388388
const bool bSeparateTranslucencyActive = IsMobileSeparateTranslucencyActive(Views.GetData(), Views.Num());
389+
const bool bShouldRenderVelocities = ShouldRenderVelocities();
389390
bRequiresMultiPass = RequiresMultiPass(RHICmdList, Views[0]);
390391
bKeepDepthContent =
391392
bRequiresMultiPass ||
392393
bForceDepthResolve ||
393394
bRequriesAmbientOcclusionPass ||
394395
bRequiresPixelProjectedPlanarRelfectionPass ||
395396
bSeparateTranslucencyActive ||
397+
bShouldRenderVelocities ||
396398
Views[0].bIsReflectionCapture;
397399
// never keep MSAA depth
398400
bKeepDepthContent = (NumMSAASamples > 1 ? false : bKeepDepthContent);
@@ -843,6 +845,10 @@ void FMobileSceneRenderer::Render(FRHICommandListImmediate& RHICmdList)
843845
RenderOcclusion(GraphBuilder, MobileSceneTexturesPerView[ViewIndex]);
844846

845847
RenderScreenSpaceReflection(GraphBuilder, Views[ViewIndex], SceneContext);
848+
849+
FRDGTextureRef SceneDepthTexture = TryRegisterExternalTexture(GraphBuilder, SceneContext.SceneDepthZ);
850+
FRDGTextureRef VelocityTexture = TryRegisterExternalTexture(GraphBuilder, SceneContext.SceneVelocity);
851+
RenderVelocities(GraphBuilder, SceneDepthTexture, VelocityTexture, MobileSceneTexturesPerView[ViewIndex], EVelocityPass::Opaque, false);
846852
}
847853

848854
RDG_EVENT_SCOPE(GraphBuilder, "PostProcessing");

Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ void AddMobilePostProcessingPasses(FRDGBuilder& GraphBuilder, const FViewInfo& V
13311331
const FScreenPassTexture SceneDepth((*Inputs.SceneTextures)->SceneDepthTexture, FinalOutputViewRect);
13321332
const FScreenPassTexture CustomDepth((*Inputs.SceneTextures)->CustomDepthTexture, FinalOutputViewRect);
13331333
const FScreenPassTexture BlackAlphaOneDummy(GSystemTextures.GetBlackAlphaOneDummy(GraphBuilder));
1334+
const FScreenPassTexture SceneVelocity((*Inputs.SceneTextures)->VelocityTexture, FinalOutputViewRect);
13341335

13351336
// Scene color is updated incrementally through the post process pipeline.
13361337
FScreenPassTexture SceneColor((*Inputs.SceneTextures)->SceneColorTexture, FinalOutputViewRect);
@@ -2003,7 +2004,7 @@ void AddMobilePostProcessingPasses(FRDGBuilder& GraphBuilder, const FViewInfo& V
20032004
UpscalerPassInputs.DownsampleOverrideFormat = PF_FloatRGB;
20042005
UpscalerPassInputs.SceneColorTexture = SceneColor.Texture;
20052006
UpscalerPassInputs.SceneDepthTexture = SceneDepth.Texture;
2006-
UpscalerPassInputs.SceneVelocityTexture = GSystemTextures.GetBlackDummy(GraphBuilder);
2007+
UpscalerPassInputs.SceneVelocityTexture = SceneVelocity.Texture;
20072008
UpscalerPassInputs.EyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
20082009

20092010
FScreenPassTexture HalfResolutionSceneColor;

Engine/Source/Runtime/Renderer/Private/PostProcess/SceneRenderTargets.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,12 @@ static void SetupMobileSceneTextureUniformParameters(
25412541
SceneTextureParameters.WorldNormalRoughnessTextureSampler = TStaticSamplerState<>::GetRHI();
25422542
}
25432543

2544+
// Velocity
2545+
{
2546+
SceneTextureParameters.VelocityTexture = SceneContext.SceneVelocity ? GetRDG(SceneContext.SceneVelocity) : BlackDefault2D;
2547+
SceneTextureParameters.VelocityTextureSampler = TStaticSamplerState<>::GetRHI();
2548+
}
2549+
25442550
// Mobile GBuffer
25452551
{
25462552
const bool bCanReadGBufferUniforms = IsMobileDeferredShadingEnabled(GMaxRHIShaderPlatform);

Engine/Source/Runtime/Renderer/Private/SceneRendering.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "GpuDebugRendering.h"
3434
#include "PostProcess/PostProcessAmbientOcclusionMobile.h"
3535

36+
enum class EVelocityPass : uint32;
37+
3638
// Forward declarations.
3739
class FScene;
3840
class FSceneViewState;
@@ -2085,6 +2087,16 @@ class FMobileSceneRenderer : public FSceneRenderer
20852087
void SetupVolumetricFog();
20862088
void ComputeVolumetricFog(FRDGBuilder& GraphBuilder, FSceneRenderTargets& SceneContext);
20872089

2090+
bool ShouldRenderVelocities() const;
2091+
2092+
void RenderVelocities(
2093+
FRDGBuilder& GraphBuilder,
2094+
FRDGTextureRef SceneDepthTexture,
2095+
FRDGTextureRef& VelocityTexture,
2096+
TRDGUniformBufferRef<FMobileSceneTextureUniformParameters> SceneTexturesUniformBuffer,
2097+
EVelocityPass VelocityPass,
2098+
bool bForceVelocity);
2099+
20882100
/** Before SetupMobileBasePassAfterShadowInit, we need to update the uniform buffer and shadow info for all movable point lights.*/
20892101
void UpdateMovablePointLightUniformBufferAndShadowInfo();
20902102
private:

Engine/Source/Runtime/Renderer/Private/VelocityRendering.cpp

Lines changed: 145 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class FVelocityVS : public FMeshMaterialShader
8181
const bool bMayModifyMeshes = Parameters.MaterialParameters.bMaterialMayModifyMeshPosition;
8282

8383
// Compile if supported by the hardware.
84-
const bool bIsFeatureSupported = IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
84+
const bool bIsFeatureSupported = IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::ES3_1);
8585

8686
/**
8787
* Any material with a vertex factory incompatible with base pass velocity generation must generate
@@ -207,6 +207,26 @@ bool FDeferredShadingSceneRenderer::ShouldRenderVelocities() const
207207
return bNeedsVelocity;
208208
}
209209

210+
bool FMobileSceneRenderer::ShouldRenderVelocities() const
211+
{
212+
if (!FVelocityRendering::IsSeparateVelocityPassSupported(ShaderPlatform) || ViewFamily.UseDebugViewPS())
213+
{
214+
return false;
215+
}
216+
217+
bool bNeedsVelocity = false;
218+
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
219+
{
220+
const FViewInfo& View = Views[ViewIndex];
221+
222+
bool bTemporalAA = (View.AntiAliasingMethod == AAM_TemporalAA) && !View.bCameraCut;
223+
224+
bNeedsVelocity |= bTemporalAA && MobileUseStandaloneTAA((ShaderPlatform));
225+
}
226+
227+
return bNeedsVelocity;
228+
}
229+
210230
BEGIN_SHADER_PARAMETER_STRUCT(FVelocityPassParameters, )
211231
SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FSceneTextureUniformParameters, SceneTextures)
212232
RENDER_TARGET_BINDING_SLOTS()
@@ -331,9 +351,131 @@ void FDeferredShadingSceneRenderer::RenderVelocities(
331351
}
332352
}
333353

354+
BEGIN_SHADER_PARAMETER_STRUCT(FMobileVelocityPassParameters, )
355+
SHADER_PARAMETER_RDG_UNIFORM_BUFFER(FMobileSceneTextureUniformParameters, SceneTextures)
356+
RENDER_TARGET_BINDING_SLOTS()
357+
END_SHADER_PARAMETER_STRUCT()
358+
359+
void FMobileSceneRenderer::RenderVelocities(
360+
FRDGBuilder& GraphBuilder,
361+
FRDGTextureRef DepthTexture,
362+
FRDGTextureRef& InOutVelocityTexture,
363+
TRDGUniformBufferRef<FMobileSceneTextureUniformParameters> SceneTexturesUniformBuffer,
364+
EVelocityPass VelocityPass,
365+
bool bForceVelocity)
366+
{
367+
if (!ShouldRenderVelocities())
368+
{
369+
return;
370+
}
371+
372+
RDG_CSV_STAT_EXCLUSIVE_SCOPE(GraphBuilder, RenderVelocities);
373+
SCOPED_NAMED_EVENT(FMobileSceneRenderer_RenderVelocities, FColor::Emerald);
374+
SCOPE_CYCLE_COUNTER(STAT_RenderVelocities);
375+
376+
ERenderTargetLoadAction VelocityLoadAction = ERenderTargetLoadAction::EClear;
377+
FRDGTextureRef VelocityTexture = InOutVelocityTexture;
378+
bool bVelocityRendered = false;
379+
380+
if (!VelocityTexture)
381+
{
382+
VelocityTexture = GraphBuilder.CreateTexture(FVelocityRendering::GetRenderTargetDesc(ShaderPlatform), TEXT("Velocity"));
383+
VelocityLoadAction = ERenderTargetLoadAction::EClear;
384+
}
385+
386+
RDG_GPU_STAT_SCOPE(GraphBuilder, RenderVelocities);
387+
RDG_WAIT_FOR_TASKS_CONDITIONAL(GraphBuilder, IsVelocityWaitForTasksEnabled());
388+
389+
const EMeshPass::Type MeshPass = GetMeshPassFromVelocityPass(VelocityPass);
390+
391+
for (int32 ViewIndex = 0; ViewIndex < Views.Num(); ViewIndex++)
392+
{
393+
const FViewInfo& View = Views[ViewIndex];
394+
395+
if (View.ShouldRenderView())
396+
{
397+
const FParallelMeshDrawCommandPass& ParallelMeshPass = View.ParallelMeshDrawCommandPasses[MeshPass];
398+
399+
const bool bHasAnyDraw = ParallelMeshPass.HasAnyDraw();
400+
if (!bHasAnyDraw && !bForceVelocity)
401+
{
402+
continue;
403+
}
404+
405+
RDG_GPU_MASK_SCOPE(GraphBuilder, View.GPUMask);
406+
407+
if (VelocityLoadAction == ERenderTargetLoadAction::EClear)
408+
{
409+
AddClearRenderTargetPass(GraphBuilder, VelocityTexture);
410+
411+
if (!View.Family->bMultiGPUForkAndJoin)
412+
{
413+
VelocityLoadAction = ERenderTargetLoadAction::ELoad;
414+
}
415+
}
416+
bVelocityRendered = true;
417+
418+
if (!bHasAnyDraw)
419+
{
420+
continue;
421+
}
422+
423+
FMobileVelocityPassParameters* PassParameters = GraphBuilder.AllocParameters<FMobileVelocityPassParameters>();
424+
PassParameters->SceneTextures = SceneTexturesUniformBuffer;
425+
PassParameters->RenderTargets.DepthStencil = FDepthStencilBinding(
426+
DepthTexture,
427+
ERenderTargetLoadAction::ELoad,
428+
ERenderTargetLoadAction::ELoad,
429+
VelocityPass == EVelocityPass::Opaque
430+
? FExclusiveDepthStencil::DepthRead_StencilWrite
431+
: FExclusiveDepthStencil::DepthWrite_StencilWrite);
432+
433+
if (IsParallelVelocity())
434+
{
435+
PassParameters->RenderTargets[0] = FRenderTargetBinding(VelocityTexture, ERenderTargetLoadAction::ELoad);
436+
437+
GraphBuilder.AddPass(
438+
RDG_EVENT_NAME("VelocityParallel"),
439+
PassParameters,
440+
ERDGPassFlags::Raster | ERDGPassFlags::SkipRenderPass,
441+
[this, &View, &ParallelMeshPass, VelocityPass, PassParameters](FRHICommandListImmediate& RHICmdList)
442+
{
443+
Scene->UniformBuffers.UpdateViewUniformBuffer(View);
444+
FRDGParallelCommandListSet ParallelCommandListSet(RHICmdList, GET_STATID(STAT_CLP_Velocity), *this, View, FParallelCommandListBindings(PassParameters));
445+
ParallelMeshPass.DispatchDraw(&ParallelCommandListSet, RHICmdList);
446+
});
447+
}
448+
else
449+
{
450+
PassParameters->RenderTargets[0] = FRenderTargetBinding(VelocityTexture, ERenderTargetLoadAction::ELoad);
451+
452+
GraphBuilder.AddPass(
453+
RDG_EVENT_NAME("Velocity"),
454+
PassParameters,
455+
ERDGPassFlags::Raster,
456+
[this, &View, &ParallelMeshPass](FRHICommandListImmediate& RHICmdList)
457+
{
458+
Scene->UniformBuffers.UpdateViewUniformBuffer(View);
459+
SetStereoViewport(RHICmdList, View);
460+
461+
ParallelMeshPass.DispatchDraw(nullptr, RHICmdList);
462+
});
463+
}
464+
465+
}
466+
}
467+
468+
if (!InOutVelocityTexture && bVelocityRendered)
469+
{
470+
FSceneRenderTargets& SceneContext = FSceneRenderTargets::Get(GraphBuilder.RHICmdList);
471+
ConvertToExternalTexture(GraphBuilder, VelocityTexture, SceneContext.SceneVelocity);
472+
InOutVelocityTexture = VelocityTexture;
473+
}
474+
}
475+
334476
EPixelFormat FVelocityRendering::GetFormat(EShaderPlatform ShaderPlatform)
335477
{
336-
return FDataDrivenShaderPlatformInfo::GetSupportsRayTracing(ShaderPlatform) ? PF_A16B16G16R16 : PF_G16R16;
478+
return FDataDrivenShaderPlatformInfo::GetSupportsRayTracing(ShaderPlatform) ? PF_A16B16G16R16 : PF_G16R16F;
337479
}
338480

339481
FRDGTextureDesc FVelocityRendering::GetRenderTargetDesc(EShaderPlatform ShaderPlatform)
@@ -671,6 +813,7 @@ FMeshPassProcessor* CreateVelocityPassProcessor(const FScene* Scene, const FScen
671813
}
672814

673815
FRegisterPassProcessorCreateFunction RegisterVelocityPass(&CreateVelocityPassProcessor, EShadingPath::Deferred, EMeshPass::Velocity, EMeshPassFlags::CachedMeshCommands | EMeshPassFlags::MainView);
816+
FRegisterPassProcessorCreateFunction RegisterMobileVelocityPass(&CreateVelocityPassProcessor, EShadingPath::Mobile, EMeshPass::Velocity, EMeshPassFlags::CachedMeshCommands | EMeshPassFlags::MainView);
674817
FTranslucentVelocityMeshProcessor::FTranslucentVelocityMeshProcessor(const FScene* Scene, const FSceneView* InViewIfDynamicMeshCommand, const FMeshPassProcessorRenderState& InPassDrawRenderState, FMeshPassDrawListContext* InDrawListContext)
675818
: FVelocityMeshProcessor(Scene, InViewIfDynamicMeshCommand, InPassDrawRenderState, InDrawListContext)
676819
{}

Engine/Source/Runtime/Renderer/Private/VelocityRendering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ enum class EVelocityPass : uint32
2929

3030
EMeshPass::Type GetMeshPassFromVelocityPass(EVelocityPass VelocityPass);
3131

32+
// Returns whether velocity is enabled and there primitives to draw in the view
33+
bool IsMobileVelocityActive(const FViewInfo& View);
34+
bool IsMobileVelocityActive(const FViewInfo* Views, int32 NumViews);
35+
3236
// Group Velocity Rendering accessors, types, etc.
3337
struct FVelocityRendering
3438
{

Engine/Source/Runtime/Renderer/Public/SceneRenderTargetParameters.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FMobileSceneTextureUniformParameters, RENDE
8888
SHADER_PARAMETER_UAV(RWBuffer<uint>, VirtualTextureFeedbackUAV)
8989
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, WorldNormalRoughnessTexture)
9090
SHADER_PARAMETER_SAMPLER(SamplerState, WorldNormalRoughnessTextureSampler)
91+
SHADER_PARAMETER_RDG_TEXTURE(Texture2D, VelocityTexture)
92+
SHADER_PARAMETER_SAMPLER(SamplerState, VelocityTextureSampler)
9193
// GBuffer
9294
SHADER_PARAMETER_TEXTURE(Texture2D, GBufferATexture)
9395
SHADER_PARAMETER_TEXTURE(Texture2D, GBufferBTexture)

0 commit comments

Comments
 (0)