Skip to content

Commit 67b7678

Browse files
YOungchenyong2github
YOung
authored andcommitted
Support standalone temporal AA on mobile platforms.
1 parent cf11c82 commit 67b7678

File tree

8 files changed

+103
-3
lines changed

8 files changed

+103
-3
lines changed

Engine/Shaders/Private/PostProcessMobile.usf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,22 @@ void AaVS_Mobile(
11801180
OutUV[3] = InTexCoord.xy + (Aa1 + float2( 0.0, 0.75)) * BufferSizeAndInvSize.zw;
11811181
OutUV[4] = InTexCoord.xy + (Aa1 + float2( 0.75, 0.0)) * BufferSizeAndInvSize.zw;
11821182
OutUV[5] = InTexCoord.xy + Aa2 * BufferSizeAndInvSize.zw;
1183+
1184+
#if MOBILE_USE_STANDALONE_TAA
1185+
OutUV[2] = InTexCoord.xy;
1186+
#endif
11831187
}
11841188

11851189
void AaPS_Mobile(
11861190
float2 UV[6] : TEXCOORD0,
11871191
out half4 OutColor : SV_Target0
11881192
)
11891193
{
1194+
#if MOBILE_USE_STANDALONE_TAA
1195+
OutColor = SceneColorTexture.Sample(SceneColorSampler, UV[2].xy);
1196+
return;
1197+
#endif
1198+
11901199
// N
11911200
// w M E P = previous middle
11921201
// S

Engine/Shaders/Private/TemporalAA/TAAStandalone.usf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
#include "../Common.ush"
66
#include "../Random.ush"
7+
8+
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
79
#include "../EyeAdaptationCommon.ush"
10+
#endif
11+
812
#include "../TextureSampling.ush"
913
#include "../MonteCarlo.ush"
1014

@@ -2235,7 +2239,11 @@ void MainCS(
22352239
}
22362240
#endif
22372241

2242+
#if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
22382243
float FrameExposureScale = EyeAdaptationLookup();
2244+
#else
2245+
float FrameExposureScale = 1;
2246+
#endif
22392247
FTAAHistoryPayload OutputPayload = TemporalAASample(GroupId, GroupThreadId, GroupThreadIndex, ViewportUV, FrameExposureScale);
22402248

22412249
float4 OutColor0 = 0;

Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,12 @@ RENDERCORE_API bool MobileSupportVolumetricFog(const FStaticShaderPlatform Platf
10481048
return (CVar && CVar->GetValueOnAnyThread() != 0) ? true : false;
10491049
}
10501050

1051+
RENDERCORE_API bool MobileUseStandaloneTAA(const FStaticShaderPlatform Platform)
1052+
{
1053+
static TConsoleVariableData<int32>* CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.Mobile.UseStandaloneTAA"));
1054+
return (CVar && CVar->GetValueOnAnyThread() != 0) ? true : false;
1055+
}
1056+
10511057
RENDERCORE_API int32 GUseForwardShading = 0;
10521058
static FAutoConsoleVariableRef CVarForwardShading(
10531059
TEXT("r.ForwardShading"),

Engine/Source/Runtime/RenderCore/Public/RenderUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ RENDERCORE_API bool AllowScreenSpaceReflection(const FStaticShaderPlatform Platf
488488

489489
RENDERCORE_API bool MobileSupportVolumetricFog(const FStaticShaderPlatform Platform);
490490

491+
RENDERCORE_API bool MobileUseStandaloneTAA(const FStaticShaderPlatform Platform);
492+
491493
/** Returns if ForwardShading is enabled. Only valid for the current platform (otherwise call ITargetPlatform::UsesForwardShading()). */
492494
inline bool IsForwardShadingEnabled(const FStaticShaderPlatform Platform)
493495
{

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,9 @@ class FMobileTAAPS : public FGlobalShader
17431743
DECLARE_GLOBAL_SHADER(FMobileTAAPS);
17441744
SHADER_USE_PARAMETER_STRUCT(FMobileTAAPS, FGlobalShader);
17451745

1746+
class FUseStandaloneTAA : SHADER_PERMUTATION_BOOL("MOBILE_USE_STANDALONE_TAA");
1747+
using FPermutationDomain = TShaderPermutationDomain<FUseStandaloneTAA>;
1748+
17461749
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
17471750
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
17481751
SHADER_PARAMETER(float, AaBlendAmount)
@@ -1757,6 +1760,13 @@ class FMobileTAAPS : public FGlobalShader
17571760
{
17581761
return IsMobilePlatform(Parameters.Platform);
17591762
}
1763+
1764+
static FPermutationDomain BuildPermutationVector(bool bUseStandaloneTAA)
1765+
{
1766+
FPermutationDomain PermutationVector;
1767+
PermutationVector.Set<FUseStandaloneTAA>(bUseStandaloneTAA);
1768+
return PermutationVector;
1769+
}
17601770
};
17611771

17621772
IMPLEMENT_GLOBAL_SHADER(FMobileTAAPS, "/Engine/Private/PostProcessMobile.usf", "AaPS_Mobile", SF_Pixel);
@@ -1767,6 +1777,9 @@ class FMobileTAAVS : public FGlobalShader
17671777
DECLARE_GLOBAL_SHADER(FMobileTAAVS);
17681778
SHADER_USE_PARAMETER_STRUCT_WITH_LEGACY_BASE(FMobileTAAVS, FGlobalShader);
17691779

1780+
class FUseStandaloneTAA : SHADER_PERMUTATION_BOOL("MOBILE_USE_STANDALONE_TAA");
1781+
using FPermutationDomain = TShaderPermutationDomain<FUseStandaloneTAA>;
1782+
17701783
BEGIN_SHADER_PARAMETER_STRUCT(FParameters, )
17711784
SHADER_PARAMETER_STRUCT_REF(FViewUniformShaderParameters, View)
17721785
SHADER_PARAMETER(FVector4, BufferSizeAndInvSize)
@@ -1776,6 +1789,13 @@ class FMobileTAAVS : public FGlobalShader
17761789
{
17771790
return IsMobilePlatform(Parameters.Platform);
17781791
}
1792+
1793+
static FPermutationDomain BuildPermutationVector(bool bUseStandaloneTAA)
1794+
{
1795+
FPermutationDomain PermutationVector;
1796+
PermutationVector.Set<FUseStandaloneTAA>(bUseStandaloneTAA);
1797+
return PermutationVector;
1798+
}
17791799
};
17801800

17811801
IMPLEMENT_GLOBAL_SHADER(FMobileTAAVS, "/Engine/Private/PostProcessMobile.usf", "AaVS_Mobile", SF_Vertex);
@@ -1793,7 +1813,9 @@ FScreenPassTexture AddMobileTAAPass(FRDGBuilder& GraphBuilder, const FViewInfo&
17931813
TAAOutput = FScreenPassRenderTarget(GraphBuilder.CreateTexture(TAADesc, TEXT("TAA")), Inputs.SceneColor.ViewRect, View.IsFirstInFamily() ? ERenderTargetLoadAction::EClear : ERenderTargetLoadAction::ELoad);
17941814
}
17951815

1796-
TShaderMapRef<FMobileTAAVS> VertexShader(View.ShaderMap);
1816+
auto VSShaderPermutationVector = FMobileTAAVS::BuildPermutationVector(Inputs.bUseStandaloneTAA);
1817+
TShaderMapRef<FMobileTAAVS> VertexShader(View.ShaderMap, VSShaderPermutationVector);
1818+
17971819

17981820
FMobileTAAVS::FParameters VSShaderParameters;
17991821

@@ -1857,7 +1879,8 @@ FScreenPassTexture AddMobileTAAPass(FRDGBuilder& GraphBuilder, const FViewInfo&
18571879
}
18581880
}
18591881

1860-
TShaderMapRef<FMobileTAAPS> PixelShader(View.ShaderMap);
1882+
auto PSShaderPermutationVector = FMobileTAAPS::BuildPermutationVector(Inputs.bUseStandaloneTAA);
1883+
TShaderMapRef<FMobileTAAPS> PixelShader(View.ShaderMap, PSShaderPermutationVector);
18611884

18621885
FMobileTAAPS::FParameters* PSShaderParameters = GraphBuilder.AllocParameters<FMobileTAAPS::FParameters>();
18631886
PSShaderParameters->RenderTargets[0] = TAAOutput.GetRenderTargetBinding();

Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessMobile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ struct FMobileTAAInputs
165165
FScreenPassRenderTarget OverrideOutput;
166166
FScreenPassTexture SceneColor;
167167
FScreenPassTexture LastFrameSceneColor;
168+
169+
bool bUseStandaloneTAA = false;
168170
};
169171

170172
FScreenPassTexture AddMobileTAAPass(FRDGBuilder& GraphBuilder, const FViewInfo& View, const FMobileTAAInputs& Inputs);

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ TAutoConsoleVariable<int32> CVarPostProcessingForceAsyncDispatch(
9797
TEXT("Only available for testing in non-shipping builds."),
9898
ECVF_RenderThreadSafe);
9999
#endif
100+
101+
TAutoConsoleVariable<int32> CVarMobileUseStandaloneTAA(
102+
TEXT("r.Mobile.UseStandaloneTAA"),
103+
0,
104+
TEXT("Whether to use standalone temporal AA on mobile platforms."),
105+
ECVF_Scalability | ECVF_RenderThreadSafe
106+
);
107+
100108
} //! namespace
101109

102110
bool IsPostProcessingWithComputeEnabled(ERHIFeatureLevel::Type FeatureLevel)
@@ -1970,7 +1978,49 @@ void AddMobilePostProcessingPasses(FRDGBuilder& GraphBuilder, const FViewInfo& V
19701978
GraphBuilder.QueueTextureExtraction(SceneColor.Texture, &View.ViewState->PrevFrameViewInfo.MobileAaColor);
19711979
}
19721980

1981+
bool bUseStandaloneTAA = MobileUseStandaloneTAA(View.GetShaderPlatform());
1982+
if (bUseStandaloneTAA)
1983+
{
1984+
int32 UpscaleMode = ITemporalUpscaler::GetTemporalUpscalerMode();
1985+
1986+
const ITemporalUpscaler* DefaultTemporalUpscaler = ITemporalUpscaler::GetDefaultTemporalUpscaler();
1987+
const ITemporalUpscaler* UpscalerToUse = (UpscaleMode == 0 || !View.Family->GetTemporalUpscalerInterface()) ? DefaultTemporalUpscaler : View.Family->GetTemporalUpscalerInterface();
1988+
1989+
const TCHAR* UpscalerName = UpscalerToUse->GetDebugName();
1990+
1991+
// Standard event scope for temporal upscaler to have all profiling information not matter what, and with explicit detection of third party.
1992+
RDG_EVENT_SCOPE_CONDITIONAL(
1993+
GraphBuilder,
1994+
UpscalerToUse != DefaultTemporalUpscaler,
1995+
"ThirdParty %s %dx%d -> %dx%d",
1996+
UpscalerToUse->GetDebugName(),
1997+
View.ViewRect.Width(), View.ViewRect.Height(),
1998+
View.GetSecondaryViewRectSize().X, View.GetSecondaryViewRectSize().Y);
1999+
2000+
ITemporalUpscaler::FPassInputs UpscalerPassInputs;
2001+
2002+
UpscalerPassInputs.bAllowDownsampleSceneColor = false;
2003+
UpscalerPassInputs.DownsampleOverrideFormat = PF_FloatRGB;
2004+
UpscalerPassInputs.SceneColorTexture = SceneColor.Texture;
2005+
UpscalerPassInputs.SceneDepthTexture = SceneDepth.Texture;
2006+
UpscalerPassInputs.SceneVelocityTexture = GSystemTextures.GetBlackDummy(GraphBuilder);
2007+
UpscalerPassInputs.EyeAdaptationTexture = GetEyeAdaptationTexture(GraphBuilder, View);
2008+
2009+
FScreenPassTexture HalfResolutionSceneColor;
2010+
FIntRect SecondaryViewRect = View.ViewRect;
2011+
2012+
UpscalerToUse->AddPasses(
2013+
GraphBuilder,
2014+
View,
2015+
UpscalerPassInputs,
2016+
&SceneColor.Texture,
2017+
&SecondaryViewRect,
2018+
&HalfResolutionSceneColor.Texture,
2019+
&HalfResolutionSceneColor.ViewRect);
2020+
}
2021+
19732022
FMobileTAAInputs TAAInputs;
2023+
TAAInputs.bUseStandaloneTAA = bUseStandaloneTAA;
19742024
PassSequence.AcceptOverrideIfLastPass(EPass::TAA, TAAInputs.OverrideOutput);
19752025
TAAInputs.OverrideOutput.LoadAction = View.IsFirstInFamily() ? ERenderTargetLoadAction::EClear : ERenderTargetLoadAction::ELoad;
19762026
TAAInputs.SceneColor = SceneColor;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class FTAAStandaloneCS : public FGlobalShader
294294
return false;
295295
}
296296

297-
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5);
297+
return IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::ES3_1);
298298
}
299299

300300
static void ModifyCompilationEnvironment(const FGlobalShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)

0 commit comments

Comments
 (0)