@ -10,7 +10,7 @@ namespace FidelityFX
{
{
internal const int ShadingChangeMipLevel = 4 ; // Corresponds to FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define
internal const int ShadingChangeMipLevel = 4 ; // Corresponds to FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define
private readonly Fsr2Callbacks _callbacks ;
protected readonly Fsr2 . ContextDescription ContextDescription ;
protected readonly ComputeBuffer Constants ;
protected readonly ComputeBuffer Constants ;
protected ComputeShader ComputeShader ;
protected ComputeShader ComputeShader ;
@ -37,9 +37,9 @@ namespace FidelityFX
protected static readonly int CbRcas = Shader . PropertyToID ( "cbRCAS" ) ;
protected static readonly int CbRcas = Shader . PropertyToID ( "cbRCAS" ) ;
protected static readonly int CbGenReactive = Shader . PropertyToID ( "cbGenerateReactive" ) ;
protected static readonly int CbGenReactive = Shader . PropertyToID ( "cbGenerateReactive" ) ;
protected Fsr2Pipeline ( Fsr2Callbacks callbacks , ComputeBuffer constants )
protected Fsr2Pipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )
{
{
_callbacks = callbacks ;
ContextDescription = contextDescription ;
Constants = constants ;
Constants = constants ;
}
}
@ -50,17 +50,21 @@ namespace FidelityFX
public abstract void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY ) ;
public abstract void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY ) ;
public static void RegisterResources ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams )
public static void RegisterResources ( CommandBuffer commandBuffer , Fsr2 . ContextDescription contextDescription , Fsr2 . DispatchDescription dispatchParams )
{
{
Vector2Int displaySize = contextDescription . DisplaySize ;
Vector2Int maxRenderSize = contextDescription . MaxRenderSize ;
// Set up shared aliasable resources, i.e. temporary render textures
// Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between compute stages
// These do not need to persist between frames, but they do need to be available between pass es
// 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
// Resource FSR2_ExposureMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE, has mipmap chain
commandBuffer . GetTemporaryRT ( UavExposureMipLumaChange , dispatchParams . RenderSize . x > > ( ShadingChangeMipLevel + 1 ) , dispatchParams . RenderSize . y > > ( ShadingChangeMipLevel + 1 ) , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
commandBuffer . GetTemporaryRT ( UavExposureMip5 , dispatchParams . RenderSize . x > > 6 , dispatchParams . RenderSize . y > > 6 , 0 , FilterMode . Point , GraphicsFormat . R16_SFloat , 1 , true ) ;
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 ) ;
}
}
public static void UnregisterResources ( CommandBuffer commandBuffer )
public static void UnregisterResources ( CommandBuffer commandBuffer )
@ -71,15 +75,15 @@ namespace FidelityFX
commandBuffer . ReleaseTemporaryRT ( UavExposureMip5 ) ;
commandBuffer . ReleaseTemporaryRT ( UavExposureMip5 ) ;
}
}
protected void LoadComputeShader ( string name , Fsr2 . InitializationFlags flags )
protected void LoadComputeShader ( string name )
{
{
LoadComputeShader ( name , f lags, ref ComputeShader , out KernelIndex ) ;
LoadComputeShader ( name , ContextDescription . F lags, ref ComputeShader , out KernelIndex ) ;
}
}
private void LoadComputeShader ( string name , Fsr2 . InitializationFlags flags , ref ComputeShader shaderRef , out int kernelIndex )
private void LoadComputeShader ( string name , Fsr2 . InitializationFlags flags , ref ComputeShader shaderRef , out int kernelIndex )
{
{
if ( shaderRef = = null )
if ( shaderRef = = null )
shaderRef = _c allbacks. LoadComputeShader ( name ) ;
shaderRef = ContextDescription . C allbacks. LoadComputeShader ( name ) ;
kernelIndex = shaderRef . FindKernel ( "CS" ) ;
kernelIndex = shaderRef . FindKernel ( "CS" ) ;
@ -104,7 +108,7 @@ namespace FidelityFX
if ( shaderRef = = null )
if ( shaderRef = = null )
return ;
return ;
_c allbacks. UnloadComputeShader ( shaderRef ) ;
ContextDescription . C allbacks. UnloadComputeShader ( shaderRef ) ;
shaderRef = null ;
shaderRef = null ;
}
}
}
}
@ -114,13 +118,13 @@ namespace FidelityFX
private readonly ComputeBuffer _spdConstants ;
private readonly ComputeBuffer _spdConstants ;
private readonly RenderTexture _autoExposure ;
private readonly RenderTexture _autoExposure ;
public Fsr2ComputeLuminancePyramidPipeline ( Fsr2Callbacks callbacks , Fsr2 . InitializationFlags flags , ComputeBuffer constants , ComputeBuffer spdConstants , RenderTexture autoExposure )
: base ( callbacks , constants )
public Fsr2ComputeLuminancePyramidPipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants , ComputeBuffer spdConstants , RenderTexture autoExposure )
: base ( contextDescription , constants )
{
{
_spdConstants = spdConstants ;
_spdConstants = spdConstants ;
_autoExposure = autoExposure ;
_autoExposure = autoExposure ;
LoadComputeShader ( "FSR2/ffx_fsr2_compute_luminance_pyramid_pass" , flags ) ;
LoadComputeShader ( "FSR2/ffx_fsr2_compute_luminance_pyramid_pass" ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
@ -140,12 +144,42 @@ namespace FidelityFX
}
}
}
}
internal class Fsr2ReconstructPreviousDepthPipeline : Fsr2Pipeline
{
public Fsr2ReconstructPreviousDepthPipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )
: base ( contextDescription , constants )
{
LoadComputeShader ( "FSR2/ffx_fsr2_reconstruct_previous_depth_pass" ) ;
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
{
/ *
#define FSR2_BIND_SRV_INPUT_MOTION_VECTORS 0
#define FSR2_BIND_SRV_INPUT_DEPTH 1
#define FSR2_BIND_SRV_INPUT_COLOR 2
#define FSR2_BIND_SRV_INPUT_EXPOSURE 3
#define FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH 0
#define FSR2_BIND_UAV_DILATED_MOTION_VECTORS 1
#define FSR2_BIND_UAV_DILATED_DEPTH 2
#define FSR2_BIND_UAV_LOCK_INPUT_LUMA 3
#define FSR2_BIND_CB_FSR2 0
* /
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 ( Fsr2Callbacks callbacks , Fsr2 . InitializationFlags flags , ComputeBuffer constants )
: base ( callbacks , constants )
public Fsr2AccumulatePipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )
: base ( contextDescription , constants )
{
{
LoadComputeShader ( "FSR2/ffx_fsr2_accumulate_pass" , flags ) ;
LoadComputeShader ( "FSR2/ffx_fsr2_accumulate_pass" ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
@ -158,8 +192,8 @@ namespace FidelityFX
{
{
private readonly ComputeShader _shaderCopy ;
private readonly ComputeShader _shaderCopy ;
public Fsr2AccumulateSharpenPipeline ( Fsr2Callbacks callbacks , Fsr2 . InitializationFlags flags , ComputeBuffer constants )
: base ( callbacks , flags , constants )
public Fsr2AccumulateSharpenPipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants )
: base ( contextDescription , constants )
{
{
// Simply loading the accumulate_pass compute shader will give us the same instance as the non-sharpen pipeline
// Simply loading the accumulate_pass compute shader will give us the same instance as the non-sharpen pipeline
// So we have to clone the shader instance and set the extra keyword on the new copy
// So we have to clone the shader instance and set the extra keyword on the new copy
@ -192,12 +226,12 @@ namespace FidelityFX
{
{
private readonly ComputeBuffer _rcasConstants ;
private readonly ComputeBuffer _rcasConstants ;
public Fsr2RcasPipeline ( Fsr2Callbacks callbacks , Fsr2 . InitializationFlags flags , ComputeBuffer constants , ComputeBuffer rcasConstants )
: base ( callbacks , constants )
public Fsr2RcasPipeline ( Fsr2 . ContextDescription contextDescription , ComputeBuffer constants , ComputeBuffer rcasConstants )
: base ( contextDescription , constants )
{
{
_rcasConstants = rcasConstants ;
_rcasConstants = rcasConstants ;
LoadComputeShader ( "FSR2/ffx_fsr2_rcas_pass" , flags ) ;
LoadComputeShader ( "FSR2/ffx_fsr2_rcas_pass" ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr2 . DispatchDescription dispatchParams , int dispatchX , int dispatchY )