@ -28,6 +28,13 @@ namespace FidelityFX
protected static readonly int SrvReactiveMask = Shader . PropertyToID ( "r_reactive_mask" ) ;
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 SrvTransparencyAndCompositionMask = Shader . PropertyToID ( "r_transparency_and_composition_mask" ) ;
protected static readonly int SrvPrevDilatedMotionVectors = Shader . PropertyToID ( "r_previous_dilated_motion_vectors" ) ;
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" ) ;
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
@ -43,6 +50,9 @@ namespace FidelityFX
protected static readonly int UavDilatedReactiveMasks = Shader . PropertyToID ( "rw_dilated_reactive_masks" ) ;
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 UavPreparedInputColor = Shader . PropertyToID ( "rw_prepared_input_color" ) ;
protected static readonly int UavNewLocks = Shader . PropertyToID ( "rw_new_locks" ) ;
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" ) ;
// Constant buffer bindings
// Constant buffer bindings
protected static readonly int CbFsr2 = Shader . PropertyToID ( "cbFSR2" ) ;
protected static readonly int CbFsr2 = Shader . PropertyToID ( "cbFSR2" ) ;
@ -77,11 +87,6 @@ namespace FidelityFX
// Resource FSR2_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
// Resource FSR2_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer . GetTemporaryRT ( UavSpdAtomicCount , 1 , 1 , 0 , FilterMode . Point , GraphicsFormat . R32_UInt , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavSpdAtomicCount , 1 , 1 , 0 , FilterMode . Point , GraphicsFormat . R32_UInt , 1 , true ) ;
// Resource FSR2_ExposureMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE, has mipmap chain
const int lumaMip = ShadingChangeMipLevel + 1 ;
commandBuffer . GetTemporaryRT ( UavExposureMipLumaChange , maxRenderSize . x > > lumaMip , maxRenderSize . y > > lumaMip , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavExposureMip5 , maxRenderSize . x > > 6 , maxRenderSize . y > > 6 , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
// FSR2_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
// FSR2_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer . GetTemporaryRT ( UavReconstructedPrevNearestDepth , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R32_UInt , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavReconstructedPrevNearestDepth , maxRenderSize . x , maxRenderSize . y , 0 , FilterMode . Point , GraphicsFormat . R32_UInt , 1 , true ) ;
@ -106,8 +111,6 @@ namespace FidelityFX
{
{
// Release all of the aliasable resources used this frame
// Release all of the aliasable resources used this frame
commandBuffer . ReleaseTemporaryRT ( UavSpdAtomicCount ) ;
commandBuffer . ReleaseTemporaryRT ( UavSpdAtomicCount ) ;
commandBuffer . ReleaseTemporaryRT ( UavExposureMipLumaChange ) ;
commandBuffer . ReleaseTemporaryRT ( UavExposureMip5 ) ;
commandBuffer . ReleaseTemporaryRT ( UavReconstructedPrevNearestDepth ) ;
commandBuffer . ReleaseTemporaryRT ( UavReconstructedPrevNearestDepth ) ;
commandBuffer . ReleaseTemporaryRT ( UavDilatedDepth ) ;
commandBuffer . ReleaseTemporaryRT ( UavDilatedDepth ) ;
commandBuffer . ReleaseTemporaryRT ( UavLockInputLuma ) ;
commandBuffer . ReleaseTemporaryRT ( UavLockInputLuma ) ;
@ -175,7 +178,11 @@ namespace FidelityFX
// - Shouldn't we use a ComputeBuffer for resources that are one-dimensional and clearly not image data? e.g. SPD atomic counter & Lanczos LUT data
// - Shouldn't we use a ComputeBuffer for resources that are one-dimensional and clearly not image data? e.g. SPD atomic counter & Lanczos LUT data
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavExposureMipLumaChange , Resources . SceneLuminance , ShadingChangeMipLevel ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavExposureMip5 , Resources . SceneLuminance , 5 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavAutoExposure , Resources . AutoExposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavAutoExposure , Resources . AutoExposure ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr2 . SpdConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr2 . SpdConstants > ( ) ) ;
@ -218,7 +225,7 @@ namespace FidelityFX
{
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvReactiveMask , dispatchParams . Reactive ) ;
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 , SrvTransparencyAndCompositionMask , Resources . Default Reactive) ; // Default reactive mask, as we don't support TCR (yet)
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvPrevDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvPrevDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputColor , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ;
@ -257,7 +264,28 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
{
//throw new NotImplementedException();
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
if ( ( ContextDescription . Flags & Fsr2 . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 )
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvDilatedMotionVectors , Resources . DilatedMotionVectors [ frameIndex ] ) ;
else
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInternalUpscaled , Resources . InternalUpscaled [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvLockStatus , Resources . LockStatus [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvLanczosLut , Resources . LanczosLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvUpscaleMaximumBiasLut , Resources . MaximumBiasLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvSceneLuminanceMips , Resources . SceneLuminance ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvAutoExposure , Resources . AutoExposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvLumaHistory , Resources . LumaHistory [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavInternalUpscaled , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavLockStatus , Resources . LockStatus [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavLumaHistory , Resources . LumaHistory [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
}
}
@ -309,9 +337,8 @@ namespace FidelityFX
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
{
// Run the RCAS sharpening filter on the upscaled image
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvRcasInput , dispatchParams . ColorDepth , 0 , RenderTextureSubElement . Color ) ; // TODO: should be output from accumulate pass
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , SrvRcasInput , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , UavUpscaledOutput , dispatchParams . Output ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbFsr2 , Constants , 0 , Marshal . SizeOf < Fsr2 . Fsr2Constants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr2 . RcasConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr2 . RcasConstants > ( ) ) ;