@ -50,26 +50,24 @@ namespace FidelityFX
public virtual void Dispose ( )
public virtual void Dispose ( )
{
{
UnloadComputeShader ( ) ;
}
}
public abstract void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY ) ;
public abstract void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY ) ;
protected void Load ComputeShader( string na me)
protected void Init ComputeShader( string passName , Co mput eShader shader )
{
{
LoadComputeShader ( name , ContextDescription . Flags , ref ComputeShader , out KernelIndex ) ;
InitComputeShader ( passName , shader , ContextDescription . Flags ) ;
}
}
private void LoadComputeShader ( string name , Fsr3Upscaler . InitializationFlags flags , ref ComputeShader shaderRef , out int kernelIndex )
private void InitComputeShader ( string passName , ComputeShader shader , Fsr3Upscaler . InitializationFlags flags )
{
{
if ( shaderRef = = null )
if ( shader = = null )
{
{
shaderRef = ContextDescription . Callbacks . LoadComputeShader ( name ) ;
if ( shaderRef = = null )
throw new MissingReferenceException ( $"Shader '{name}' could not be loaded! Please ensure it is included in the project correctly." ) ;
throw new MissingReferenceException ( $"Shader for FSR3 Upscaler '{passName}' could not be loaded! Please ensure it is included in the project correctly." ) ;
}
}
kernelIndex = shaderRef . FindKernel ( "CS" ) ;
ComputeShader = shader ;
KernelIndex = ComputeShader . FindKernel ( "CS" ) ;
bool useLut = false ;
bool useLut = false ;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
@ -80,34 +78,20 @@ namespace FidelityFX
#endif
#endif
// This matches the permutation rules from the CreatePipeline* functions
// This matches the permutation rules from the CreatePipeline* functions
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableHighDynamicRange ) ! = 0 ) shaderRef . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 ) shaderRef . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 ) shaderRef . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableDepthInverted ) ! = 0 ) shaderRef . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH" ) ;
if ( useLut ) shaderRef . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableFP16Usage ) ! = 0 ) shaderRef . EnableKeyword ( "FFX_HALF" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableHighDynamicRange ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableDepthInverted ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH" ) ;
if ( useLut ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE" ) ;
if ( ( flags & Fsr3Upscaler . InitializationFlags . EnableFP16Usage ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_HALF" ) ;
// Inform the shader which render pipeline we're currently using
// Inform the shader which render pipeline we're currently using
var pipeline = GraphicsSettings . currentRenderPipeline ;
var pipeline = GraphicsSettings . currentRenderPipeline ;
if ( pipeline ! = null & & pipeline . GetType ( ) . Name . Contains ( "HDRenderPipeline" ) )
if ( pipeline ! = null & & pipeline . GetType ( ) . Name . Contains ( "HDRenderPipeline" ) )
{
{
shaderRef . EnableKeyword ( "UNITY_FSR3UPSCALER_HDRP" ) ;
ComputeShader . EnableKeyword ( "UNITY_FSR3UPSCALER_HDRP" ) ;
}
}
}
}
private void UnloadComputeShader ( )
{
UnloadComputeShader ( ref ComputeShader ) ;
}
private void UnloadComputeShader ( ref ComputeShader shaderRef )
{
if ( shaderRef = = null )
return ;
ContextDescription . Callbacks . UnloadComputeShader ( shaderRef ) ;
shaderRef = null ;
}
}
}
internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass
internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass
@ -119,7 +103,7 @@ namespace FidelityFX
{
{
_spdConstants = spdConstants ;
_spdConstants = spdConstants ;
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass" ) ;
InitComputeShader ( "compute_luminance_pyramid_pass" , contextDescription . Shaders . computeLuminancePyramidPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -144,7 +128,7 @@ namespace FidelityFX
public Fsr3UpscalerReconstructPreviousDepthPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerReconstructPreviousDepthPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass" ) ;
InitComputeShader ( "reconstruct_previous_depth_pass" , contextDescription . Shaders . reconstructPreviousDepthPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -172,7 +156,7 @@ namespace FidelityFX
public Fsr3UpscalerDepthClipPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerDepthClipPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_depth_clip_pass" ) ;
InitComputeShader ( "depth_clip_pass" , contextDescription . Shaders . depthClipPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -207,7 +191,7 @@ namespace FidelityFX
public Fsr3UpscalerLockPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerLockPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_lock_pass" ) ;
InitComputeShader ( "lock_pass" , contextDescription . Shaders . lockPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -230,7 +214,7 @@ namespace FidelityFX
public Fsr3UpscalerAccumulatePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerAccumulatePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_accumulate_pass" ) ;
InitComputeShader ( "accumulate_pass" , contextDescription . Shaders . accumulatePass ) ;
#if UNITY_2021_2_OR_NEWER
#if UNITY_2021_2_OR_NEWER
_sharpeningKeyword = new LocalKeyword ( ComputeShader , SharpeningKeyword ) ;
_sharpeningKeyword = new LocalKeyword ( ComputeShader , SharpeningKeyword ) ;
#endif
#endif
@ -286,16 +270,16 @@ namespace FidelityFX
}
}
}
}
internal class Fsr3UpscalerRcas Pass : Fsr3UpscalerPass
internal class Fsr3UpscalerSharpen Pass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _rcasConstants ;
private readonly ComputeBuffer _rcasConstants ;
public Fsr3UpscalerRcas Pass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer rcasConstants )
public Fsr3UpscalerSharpen Pass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer rcasConstants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
_rcasConstants = rcasConstants ;
_rcasConstants = rcasConstants ;
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_rcas_pass" ) ;
InitComputeShader ( "rcas_pass" , contextDescription . Shaders . sharpenPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -323,7 +307,7 @@ namespace FidelityFX
{
{
_generateReactiveConstants = generateReactiveConstants ;
_generateReactiveConstants = generateReactiveConstants ;
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_autogen_reactive_pass" ) ;
InitComputeShader ( "autogen_reactive_pass" , contextDescription . Shaders . autoGenReactivePass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
@ -355,7 +339,7 @@ namespace FidelityFX
{
{
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
LoadComputeShader ( "FSR3/ffx_fsr3upscaler_tcr_autogen_pass" ) ;
InitComputeShader ( "tcr_autogen_pass" , contextDescription . Shaders . tcrAutoGenPass ) ;
}
}
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
public override void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )