@ -22,6 +22,11 @@ namespace FidelityFX
protected static readonly int SrvInputMotionVectors = Shader . PropertyToID ( "r_input_motion_vectors" ) ;
protected static readonly int SrvInputMotionVectors = Shader . PropertyToID ( "r_input_motion_vectors" ) ;
protected static readonly int SrvInputDepth = Shader . PropertyToID ( "r_input_depth" ) ;
protected static readonly int SrvInputDepth = Shader . PropertyToID ( "r_input_depth" ) ;
protected static readonly int SrvInputExposure = Shader . PropertyToID ( "r_input_exposure" ) ;
protected static readonly int SrvInputExposure = Shader . PropertyToID ( "r_input_exposure" ) ;
protected static readonly int SrvDilatedMotionVectors = Shader . PropertyToID ( "r_dilated_motion_vectors" ) ;
protected static readonly int SrvDilatedDepth = Shader . PropertyToID ( "r_dilatedDepth" ) ;
protected static readonly int SrvReactiveMask = Shader . PropertyToID ( "r_reactive_mask" ) ;
protected static readonly int SrvTransparencyAndCompositionMask = Shader . PropertyToID ( "r_transparency_and_composition_mask" ) ;
protected static readonly int SrvPrevDilatedMotionVectors = Shader . PropertyToID ( "r_previous_dilated_motion_vectors" ) ;
protected static readonly int SrvRcasInput = Shader . PropertyToID ( "r_rcas_input" ) ;
protected static readonly int SrvRcasInput = Shader . PropertyToID ( "r_rcas_input" ) ;
// Unordered access views, i.e. random read/write bindings
// Unordered access views, i.e. random read/write bindings
@ -34,6 +39,8 @@ namespace FidelityFX
protected static readonly int UavDilatedMotionVectors = Shader . PropertyToID ( "rw_dilated_motion_vectors" ) ;
protected static readonly int UavDilatedMotionVectors = Shader . PropertyToID ( "rw_dilated_motion_vectors" ) ;
protected static readonly int UavDilatedDepth = Shader . PropertyToID ( "rw_dilatedDepth" ) ;
protected static readonly int UavDilatedDepth = Shader . PropertyToID ( "rw_dilatedDepth" ) ;
protected static readonly int UavLockInputLuma = Shader . PropertyToID ( "rw_lock_input_luma" ) ;
protected static readonly int UavLockInputLuma = Shader . PropertyToID ( "rw_lock_input_luma" ) ;
protected static readonly int UavDilatedReactiveMasks = Shader . PropertyToID ( "rw_dilated_reactive_masks" ) ;
protected static readonly int UavPreparedInputColor = Shader . PropertyToID ( "rw_prepared_input_color" ) ;
// Constant buffer bindings
// Constant buffer bindings
protected static readonly int CbFsr2 = Shader . PropertyToID ( "cbFSR2" ) ;
protected static readonly int CbFsr2 = Shader . PropertyToID ( "cbFSR2" ) ;
@ -77,7 +84,14 @@ namespace FidelityFX
commandBuffer . GetTemporaryRT ( UavDilatedDepth , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R32_SFloat , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavDilatedDepth , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R32_SFloat , 1 , true ) ;
// FSR2_LockInputLuma: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
// FSR2_LockInputLuma: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
// TODO: should be at render resolution according to the docs (at least when output from Reconstruct & Dilate)
commandBuffer . GetTemporaryRT ( UavLockInputLuma , displaySize . x , displaySize . y , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavLockInputLuma , displaySize . x , displaySize . y , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
// FSR2_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer . GetTemporaryRT ( UavDilatedReactiveMasks , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R8G8_UNorm , 1 , true ) ;
// FSR2_PreparedInputColor: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer . GetTemporaryRT ( UavPreparedInputColor , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R16G16B16A16_SFloat , 1 , true ) ;
}
}
public static void UnregisterResources ( CommandBuffer commandBuffer )
public static void UnregisterResources ( CommandBuffer commandBuffer )
@ -187,6 +201,35 @@ namespace FidelityFX
}
}
}
}
internal class Fsr2DepthClipPipeline : Fsr2Pipeline
{
private readonly RenderTexture [ ] _dilatedMotionVectors ;
public Fsr2DepthClipPipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants , RenderTexture [ ] dilatedMotionVectors )
: base ( contextDescription , constants )
{
_dilatedMotionVectors = dilatedMotionVectors ;
LoadComputeShader ( "FSR2/ffx_fsr2_depth_clip_pass" ) ;
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , _dilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvReactiveMask , dispatchParams . Reactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvTransparencyAndCompositionMask , dispatchParams . Reactive ) ; // Default reactive mask, as we don't support TCR (yet)
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvPrevDilatedMotionVectors , _dilatedMotionVectors [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputDepth , dispatchParams . Depth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
internal class Fsr2AccumulatePipeline : Fsr2Pipeline
internal class Fsr2AccumulatePipeline : Fsr2Pipeline
{
{
public Fsr2AccumulatePipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )
public Fsr2AccumulatePipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )