@ -42,8 +42,6 @@ namespace FidelityFX.FSR2
protected ComputeShader ComputeShader ;
protected int KernelIndex ;
protected CustomSampler Sampler ;
protected Fsr2Pass ( Fsr2 . ContextDescription contextDescription , Fsr2Resources resources , ComputeBuffer constants )
{
ContextDescription = contextDescription ;
@ -57,9 +55,7 @@ namespace FidelityFX.FSR2
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . BeginSample ( Sampler ) ;
DoScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchX , dispatchY ) ;
commandBuffer . EndSample ( Sampler ) ;
}
protected abstract void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY ) ;
@ -78,23 +74,6 @@ namespace FidelityFX.FSR2
ComputeShader = shader ;
KernelIndex = ComputeShader . FindKernel ( "CS" ) ;
Sampler = CustomSampler . Create ( passName ) ;
bool useLut = false ;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
if ( SystemInfo . computeSubGroupSize = = 6 4 )
{
useLut = true ;
}
#endif
// This matches the permutation rules from the CreatePipeline* functions
if ( ( flags & Fsr2 . InitializationFlags . EnableHighDynamicRange ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR2_OPTION_HDR_COLOR_INPUT" ) ;
if ( ( flags & Fsr2 . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS" ) ;
if ( ( flags & Fsr2 . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS" ) ;
if ( ( flags & Fsr2 . InitializationFlags . EnableDepthInverted ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR2_OPTION_INVERTED_DEPTH" ) ;
if ( useLut ) ComputeShader . EnableKeyword ( "FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE" ) ;
if ( ( flags & Fsr2 . InitializationFlags . EnableFP16Usage ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_HALF" ) ;
}
}
@ -120,9 +99,6 @@ namespace FidelityFX.FSR2
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavExposureMip5 , Resources . SceneLuminance , 5 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavAutoExposure , Resources . AutoExposure ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr2 . SpdConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -147,9 +123,10 @@ namespace FidelityFX.FSR2
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBuffer Param ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTexture Param ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavLockInputLuma , Resources . LockInputLuma ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -179,12 +156,13 @@ namespace FidelityFX.FSR2
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvReactiveMask , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvTransparencyAndCompositionMask , tac . RenderTarget , tac . MipLevel , tac . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvReconstructedPrevNearestDepth , Fsr2ShaderIDs . Uav ReconstructedPrevNearestDepth) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvDilatedDepth , Fsr2ShaderIDs . Uav DilatedDepth) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvPrevDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavDilatedReactiveMasks , Resources . DilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavPreparedInputColor , Resources . PreparedInputColor ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -200,8 +178,10 @@ namespace FidelityFX.FSR2
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvLockInputLuma , Fsr2ShaderIDs . UavLockInputLuma ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvLockInputLuma , Resources . LockInputLuma ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavNewLocks , Resources . NewLocks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -251,10 +231,10 @@ namespace FidelityFX.FSR2
ref var exposure = ref dispatchParams . Exposure ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvDilatedReactiveMasks , Fsr2ShaderIDs . Uav DilatedReactiveMasks) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvDilatedReactiveMasks , Resources . DilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInternalUpscaled , Resources . InternalUpscaled [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvLockStatus , Resources . LockStatus [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvPreparedInputColor , Fsr2ShaderIDs . Uav PreparedInputColor) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvPreparedInputColor , Resources . PreparedInputColor ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvLanczosLut , Resources . LanczosLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvUpscaleMaximumBiasLut , Resources . MaximumBiasLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvSceneLuminanceMips , Resources . SceneLuminance ) ;
@ -264,12 +244,11 @@ namespace FidelityFX.FSR2
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavInternalUpscaled , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavLockStatus , Resources . LockStatus [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavLumaHistory , Resources . LumaHistory [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavNewLocks , Resources . NewLocks ) ;
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -295,9 +274,6 @@ namespace FidelityFX.FSR2
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr2 . RcasConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -320,8 +296,6 @@ namespace FidelityFX.FSR2
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
{
commandBuffer . BeginSample ( Sampler ) ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var color = ref dispatchParams . ColorPreUpscale ;
ref var reactive = ref dispatchParams . OutReactive ;
@ -329,51 +303,7 @@ namespace FidelityFX.FSR2
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvOpaqueOnly , opaqueOnly . RenderTarget , opaqueOnly . MipLevel , opaqueOnly . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavAutoReactive , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbGenReactive , _generateReactiveConstants , 0 , Marshal . SizeOf < Fsr2 . GenerateReactiveConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . EndSample ( Sampler ) ;
}
}
internal class Fsr2TcrAutogeneratePass : Fsr2Pass
{
private readonly ComputeBuffer _tcrAutogenerateConstants ;
public Fsr2TcrAutogeneratePass ( Fsr2 . ContextDescription contextDescription , Fsr2Resources resources , ComputeBuffer constants , ComputeBuffer tcrAutogenerateConstants )
: base ( contextDescription , resources , constants )
{
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
InitComputeShader ( "Auto-Generate Transparency & Composition Mask" , contextDescription . Shaders . tcrAutoGenPass ) ;
}
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
ref var color = ref dispatchParams . Color ;
ref var motionVectors = ref dispatchParams . MotionVectors ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var reactive = ref dispatchParams . Reactive ;
ref var tac = ref dispatchParams . TransparencyAndComposition ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvOpaqueOnly , opaqueOnly . RenderTarget , opaqueOnly . MipLevel , opaqueOnly . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvPrevColorPreAlpha , Resources . PrevPreAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvPrevColorPostAlpha , Resources . PrevPostAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvReactiveMask , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . SrvTransparencyAndCompositionMask , tac . RenderTarget , tac . MipLevel , tac . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavAutoReactive , Resources . AutoReactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavAutoComposition , Resources . AutoComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavPrevColorPreAlpha , Resources . PrevPreAlpha [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr2ShaderIDs . UavPrevColorPostAlpha , Resources . PrevPostAlpha [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr2ShaderIDs . CbGenReactive , _tcrAutogenerateConstants , 0 , Marshal . SizeOf < Fsr2 . GenerateReactiveConstants2 > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}