@ -28,7 +28,7 @@ namespace FidelityFX.FSR3
/// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket.
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
/// </summary>
internal abstract class Fsr3UpscalerPass : FfxPassWithFlags < Fsr3Upscaler . DispatchDescription , Fsr3Upscaler . InitializationFlags >
internal abstract class Fsr3UpscalerPass : FfxPassWithFlags < Fsr3Upscaler . InitializationFlags >
{
protected readonly Fsr3UpscalerResources Resources ;
protected readonly ComputeBuffer Constants ;
@ -39,6 +39,16 @@ namespace FidelityFX.FSR3
Resources = resources ;
Constants = constants ;
}
public void ScheduleDispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ = 1 )
{
using ( ProfilerSample ( commandBuffer ) )
{
Dispatch ( commandBuffer , dispatchParams , bufferIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
protected abstract void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ ) ;
protected override void SetupShaderKeywords ( )
{
@ -68,7 +78,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Prepare Inputs" , contextDescription . Shaders . prepareInputsPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputDepth , dispatchParams . Depth ) ;
@ -98,7 +108,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Luminance Pyramid" , contextDescription . Shaders . lumaPyramidPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bufferIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
@ -131,7 +141,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Shading Change Pyramid" , contextDescription . Shaders . shadingChangePyramidPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bufferIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPreviousLuma , Resources . Luma [ bufferIndex ^ 1 ] ) ;
@ -161,7 +171,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Shading Change" , contextDescription . Shaders . shadingChangePass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvSpdMips , Resources . SpdMips ) ;
@ -179,7 +189,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Prepare Reactivity" , contextDescription . Shaders . prepareReactivityPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
@ -207,7 +217,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Luminance Instability" , contextDescription . Shaders . lumaInstabilityPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
@ -243,7 +253,7 @@ namespace FidelityFX.FSR3
#endif
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
#if UNITY_2021_2_OR_NEWER
if ( dispatchParams . EnableSharpening )
@ -297,7 +307,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "RCAS Sharpening" , contextDescription . Shaders . sharpenPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvRcasInput , Resources . InternalUpscaled [ bufferIndex ] ) ;
@ -323,23 +333,22 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Auto-Generate Reactive Mask" , contextDescription . Shaders . autoGenReactivePass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
}
public void ScheduleDispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
{
commandBuffer . BeginSample ( Sampler ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . ColorPreUpscale ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , dispatchParams . OutReactive ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . GenerateReactiveConstants > ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _generateReactiveConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . EndSample ( Sampler ) ;
using ( ProfilerSample ( commandBuffer ) )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . ColorPreUpscale ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , dispatchParams . OutReactive ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . GenerateReactiveConstants > ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _generateReactiveConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
}
}
}
@ -355,7 +364,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Auto-Generate Transparency & Composition Mask" , contextDescription . Shaders . tcrAutoGenPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . Color ) ;
@ -386,7 +395,7 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Debug View" , contextDescription . Shaders . debugViewPass ) ;
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ )
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;