@ -40,8 +40,6 @@ namespace FidelityFX.FSR3
protected ComputeShader ComputeShader ;
protected int KernelIndex ;
protected CustomSampler Sampler ;
protected Fsr3UpscalerPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
{
ContextDescription = contextDescription ;
@ -55,9 +53,7 @@ namespace FidelityFX.FSR3
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
commandBuffer . BeginSample ( Sampler ) ;
DoScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchX , dispatchY ) ;
commandBuffer . EndSample ( Sampler ) ;
}
protected abstract void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY ) ;
@ -76,23 +72,6 @@ namespace FidelityFX.FSR3
ComputeShader = shader ;
KernelIndex = ComputeShader . FindKernel ( "CS" ) ;
Sampler = CustomSampler . Create ( passName ) ;
bool useLut = false ;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
if ( SystemInfo . computeSubGroupSize = = 6 4 )
{
useLut = true ;
}
#endif
// This matches the permutation rules from the CreatePipeline* functions
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" ) ;
}
}
@ -120,8 +99,6 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavCurrentLuma , Resources . Luma [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -151,9 +128,7 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . SpdConstants > ( ) ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFarthestDepthMip1 , Fsr3ShaderIDs . UavFarthestDepthMip1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -187,9 +162,7 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . SpdConstants > ( ) ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavShadingChange , Fsr3ShaderIDs . UavShadingChange ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -207,7 +180,7 @@ namespace FidelityFX.FSR3
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvSpdMips , Resources . SpdMips ) ;
commandBuffer . SetComputeConstantBuffer Param ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeTexture Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavShadingChange , Fsr3ShaderIDs . UavShadingChange ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
@ -237,10 +210,10 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavNewLocks , Fsr3ShaderIDs . UavNewLocks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAccumulation , Resources . Accumulation [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -268,8 +241,6 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaHistory , Resources . LumaHistory [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -329,11 +300,10 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavNewLocks , Fsr3ShaderIDs . UavNewLocks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavInternalUpscaled , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -359,9 +329,6 @@ namespace FidelityFX.FSR3
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . RcasConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -384,8 +351,6 @@ namespace FidelityFX.FSR3
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
{
commandBuffer . BeginSample ( Sampler ) ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var color = ref dispatchParams . ColorPreUpscale ;
ref var reactive = ref dispatchParams . OutReactive ;
@ -394,50 +359,6 @@ namespace FidelityFX.FSR3
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _generateReactiveConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . GenerateReactiveConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . EndSample ( Sampler ) ;
}
}
internal class Fsr3UpscalerTcrAutogeneratePass : Fsr3UpscalerPass
{
private readonly ComputeBuffer _tcrAutogenerateConstants ;
public Fsr3UpscalerTcrAutogeneratePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer tcrAutogenerateConstants )
: base ( contextDescription , resources , constants )
{
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
InitComputeShader ( "Auto-Generate Transparency & Composition Mask" , contextDescription . Shaders . tcrAutoGenPass ) ;
}
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
{
ref var color = ref dispatchParams . Color ;
ref var motionVectors = ref dispatchParams . MotionVectors ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var reactive = ref dispatchParams . Reactive ;
ref var tac = ref dispatchParams . TransparencyAndComposition ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , opaqueOnly . RenderTarget , opaqueOnly . MipLevel , opaqueOnly . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPreAlpha , Resources . PrevPreAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPostAlpha , Resources . PrevPostAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReactiveMask , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvTransparencyAndCompositionMask , tac . RenderTarget , tac . MipLevel , tac . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , Resources . AutoReactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoComposition , Resources . AutoComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPreAlpha , Resources . PrevPreAlpha [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPostAlpha , Resources . PrevPostAlpha [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _tcrAutogenerateConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . GenerateReactiveConstants2 > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
@ -463,8 +384,6 @@ namespace FidelityFX.FSR3
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}