@ -18,41 +18,41 @@ namespace FidelityFX
protected int KernelIndex ;
// Shader resource views, i.e. read-only bindings
protected static readonly int SrvInputColor = Shader . PropertyToID ( "r_input_color_jittered" ) ;
protected static readonly int SrvOpaqueOnly = Shader . PropertyToID ( "r_input_opaque_only" ) ;
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 SrvInputExposure = Shader . PropertyToID ( "r_input_exposure" ) ;
protected static readonly int SrvDilatedMotionVectors = Shader . PropertyToID ( "r_dilated_motion_vectors" ) ;
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 SrvInternalUpscaled = Shader . PropertyToID ( "r_internal_upscaled_color" ) ;
protected static readonly int SrvLockStatus = Shader . PropertyToID ( "r_lock_status" ) ;
protected static readonly int SrvLanczosLut = Shader . PropertyToID ( "r_lanczos_lut" ) ;
protected static readonly int SrvUpscaleMaximumBiasLut = Shader . PropertyToID ( "r_upsample_maximum_bias_lut" ) ;
protected static readonly int SrvSceneLuminanceMips = Shader . PropertyToID ( "r_imgMips" ) ;
protected static readonly int SrvAutoExposure = Shader . PropertyToID ( "r_auto_exposure" ) ;
protected static readonly int SrvLumaHistory = Shader . PropertyToID ( "r_luma_history" ) ;
protected static readonly int SrvRcasInput = Shader . PropertyToID ( "r_rcas_input" ) ;
internal static readonly int SrvInputColor = Shader . PropertyToID ( "r_input_color_jittered" ) ;
internal static readonly int SrvOpaqueOnly = Shader . PropertyToID ( "r_input_opaque_only" ) ;
internal static readonly int SrvInputMotionVectors = Shader . PropertyToID ( "r_input_motion_vectors" ) ;
internal static readonly int SrvInputDepth = Shader . PropertyToID ( "r_input_depth" ) ;
internal static readonly int SrvInputExposure = Shader . PropertyToID ( "r_input_exposure" ) ;
internal static readonly int SrvDilatedMotionVectors = Shader . PropertyToID ( "r_dilated_motion_vectors" ) ;
internal static readonly int SrvReactiveMask = Shader . PropertyToID ( "r_reactive_mask" ) ;
internal static readonly int SrvTransparencyAndCompositionMask = Shader . PropertyToID ( "r_transparency_and_composition_mask" ) ;
internal static readonly int SrvPrevDilatedMotionVectors = Shader . PropertyToID ( "r_previous_dilated_motion_vectors" ) ;
internal static readonly int SrvInternalUpscaled = Shader . PropertyToID ( "r_internal_upscaled_color" ) ;
internal static readonly int SrvLockStatus = Shader . PropertyToID ( "r_lock_status" ) ;
internal static readonly int SrvLanczosLut = Shader . PropertyToID ( "r_lanczos_lut" ) ;
internal static readonly int SrvUpscaleMaximumBiasLut = Shader . PropertyToID ( "r_upsample_maximum_bias_lut" ) ;
internal static readonly int SrvSceneLuminanceMips = Shader . PropertyToID ( "r_imgMips" ) ;
internal static readonly int SrvAutoExposure = Shader . PropertyToID ( "r_auto_exposure" ) ;
internal static readonly int SrvLumaHistory = Shader . PropertyToID ( "r_luma_history" ) ;
internal static readonly int SrvRcasInput = Shader . PropertyToID ( "r_rcas_input" ) ;
// Unordered access views, i.e. random read/write bindings
protected static readonly int UavUpscaledOutput = Shader . PropertyToID ( "rw_upscaled_output" ) ;
protected static readonly int UavExposureMipLumaChange = Shader . PropertyToID ( "rw_img_mip_shading_change" ) ;
protected static readonly int UavExposureMip5 = Shader . PropertyToID ( "rw_img_mip_5" ) ;
protected static readonly int UavAutoExposure = Shader . PropertyToID ( "rw_auto_exposure" ) ;
protected static readonly int UavSpdAtomicCount = Shader . PropertyToID ( "rw_spd_global_atomic" ) ;
protected static readonly int UavReconstructedPrevNearestDepth = Shader . PropertyToID ( "rw_reconstructed_previous_nearest_depth" ) ;
protected static readonly int UavDilatedMotionVectors = Shader . PropertyToID ( "rw_dilated_motion_vectors" ) ;
protected static readonly int UavDilatedDepth = Shader . PropertyToID ( "rw_dilatedDepth" ) ;
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" ) ;
protected static readonly int UavNewLocks = Shader . PropertyToID ( "rw_new_locks" ) ;
protected static readonly int UavInternalUpscaled = Shader . PropertyToID ( "rw_internal_upscaled_color" ) ;
protected static readonly int UavLockStatus = Shader . PropertyToID ( "rw_lock_status" ) ;
protected static readonly int UavLumaHistory = Shader . PropertyToID ( "rw_luma_history" ) ;
protected static readonly int UavAutoReactive = Shader . PropertyToID ( "rw_output_autoreactive" ) ;
internal static readonly int UavUpscaledOutput = Shader . PropertyToID ( "rw_upscaled_output" ) ;
internal static readonly int UavExposureMipLumaChange = Shader . PropertyToID ( "rw_img_mip_shading_change" ) ;
internal static readonly int UavExposureMip5 = Shader . PropertyToID ( "rw_img_mip_5" ) ;
internal static readonly int UavAutoExposure = Shader . PropertyToID ( "rw_auto_exposure" ) ;
internal static readonly int UavSpdAtomicCount = Shader . PropertyToID ( "rw_spd_global_atomic" ) ;
internal static readonly int UavReconstructedPrevNearestDepth = Shader . PropertyToID ( "rw_reconstructed_previous_nearest_depth" ) ;
internal static readonly int UavDilatedMotionVectors = Shader . PropertyToID ( "rw_dilated_motion_vectors" ) ;
internal static readonly int UavDilatedDepth = Shader . PropertyToID ( "rw_dilatedDepth" ) ;
internal static readonly int UavLockInputLuma = Shader . PropertyToID ( "rw_lock_input_luma" ) ;
internal static readonly int UavDilatedReactiveMasks = Shader . PropertyToID ( "rw_dilated_reactive_masks" ) ;
internal static readonly int UavPreparedInputColor = Shader . PropertyToID ( "rw_prepared_input_color" ) ;
internal static readonly int UavNewLocks = Shader . PropertyToID ( "rw_new_locks" ) ;
internal static readonly int UavInternalUpscaled = Shader . PropertyToID ( "rw_internal_upscaled_color" ) ;
internal static readonly int UavLockStatus = Shader . PropertyToID ( "rw_lock_status" ) ;
internal static readonly int UavLumaHistory = Shader . PropertyToID ( "rw_luma_history" ) ;
internal static readonly int UavAutoReactive = Shader . PropertyToID ( "rw_output_autoreactive" ) ;
// Constant buffer bindings
protected static readonly int CbFsr2 = Shader . PropertyToID ( "cbFSR2" ) ;
@ -181,10 +181,8 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
if ( dispatchParams . ColorDepth ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
}
if ( dispatchParams . Color . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . Color . Value , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavExposureMipLumaChange , Resources . SceneLuminance , ShadingChangeMipLevel ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavExposureMip5 , Resources . SceneLuminance , 5 ) ;
@ -207,16 +205,17 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
if ( dispatchParams . ColorDepth ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputDepth , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Depth ) ;
}
if ( dispatchParams . MotionVectors ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
}
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
if ( dispatchParams . Color . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . Color . Value , 0 , RenderTextureSubElement . Color ) ;
if ( dispatchParams . Depth . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputDepth , dispatchParams . Depth . Value , 0 , RenderTextureSubElement . Depth ) ;
if ( dispatchParams . MotionVectors . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors . Value ) ;
if ( dispatchParams . Exposure . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure . Value ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
@ -236,20 +235,24 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
if ( dispatchParams . Color . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . Color . Value , 0 , RenderTextureSubElement . Color ) ;
if ( dispatchParams . Depth . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputDepth , dispatchParams . Depth . Value , 0 , RenderTextureSubElement . Depth ) ;
if ( dispatchParams . MotionVectors . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors . Value ) ;
if ( dispatchParams . Exposure . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure . Value ) ;
if ( dispatchParams . Reactive . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvReactiveMask , dispatchParams . Reactive . Value ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvReactiveMask , dispatchParams . Reactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvTransparencyAndCompositionMask , Resources . DefaultReactive ) ; // Default reactive mask, as we don't support TCR (yet)
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvPrevDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ^ 1 ] ) ;
if ( dispatchParams . MotionVectors ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
}
if ( dispatchParams . ColorDepth ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputDepth , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Depth ) ;
}
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
@ -286,11 +289,13 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
if ( ( ContextDescription . Flags & Fsr2 . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
else if ( dispatchParams . MotionVectors ! = null )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
else if ( dispatchParams . MotionVectors . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors . Value ) ;
if ( dispatchParams . Exposure . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure . Value ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInternalUpscaled , Resources . InternalUpscaled [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvLockStatus , Resources . LockStatus [ frameIndex ^ 1 ] ) ;
@ -302,11 +307,10 @@ namespace FidelityFX
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavInternalUpscaled , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavLockStatus , Resources . LockStatus [ frameIndex ] ) ;
if ( dispatchParams . Output ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output ) ;
}
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavLumaHistory , Resources . LumaHistory [ frameIndex ] ) ;
if ( dispatchParams . Output . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output . Value ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
@ -362,12 +366,14 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
if ( dispatchParams . Exposure . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure . Value ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvRcasInput , Resources . InternalUpscaled [ frameIndex ] ) ;
if ( dispatchParams . Output ! = null )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output ) ;
}
if ( dispatchParams . Output . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output . Value ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr2 . RcasConstants > ( ) ) ;
@ -393,9 +399,14 @@ namespace FidelityFX
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorPreUpscale ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavAutoExposure , dispatchParams . OutReactive ) ;
if ( dispatchParams . ColorOpaqueOnly . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly . Value , 0 , RenderTextureSubElement . Color ) ;
if ( dispatchParams . ColorPreUpscale . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorPreUpscale . Value , 0 , RenderTextureSubElement . Color ) ;
if ( dispatchParams . OutReactive . HasValue )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavAutoExposure , dispatchParams . OutReactive . Value ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbGenReactive , _generateReactiveConstants , 0 , Marshal . SizeOf < Fsr2 . GenerateReactiveConstants > ( ) ) ;