@ -8,7 +8,6 @@ namespace FidelityFX.FrameGen
{
internal abstract class OpticalFlowPass : IDisposable
{
protected readonly OpticalFlow . ContextDescription ContextDescription ;
protected readonly OpticalFlowResources Resources ;
protected readonly ComputeBuffer Constants ;
@ -17,9 +16,8 @@ namespace FidelityFX.FrameGen
private CustomSampler _sampler ;
protected OpticalFlowPass ( OpticalFlow . ContextDescription contextDescription , OpticalFlow Resources resources , ComputeBuffer constants )
protected OpticalFlowPass ( OpticalFlowResources resources , ComputeBuffer constants )
{
ContextDescription = contextDescription ;
Resources = resources ;
Constants = constants ;
}
@ -52,20 +50,19 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowPrepareLumaPass : OpticalFlowPass
{
public OpticalFlowPrepareLumaPass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowPrepareLumaPass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Prepare Luma" , contextDescription . shaders . prepareLuma ) ;
}
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , OpticalFlow . DispatchDescription dispatchParams , int frameIndex , int level , int dispatchX , int dispatchY , int dispatchZ )
{
ref var color = ref dispatchParams . Color ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowInput , Resources . OpticalFlowInputLevels [ 0 ] [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -75,8 +72,8 @@ namespace FidelityFX.FrameGen
{
private ComputeBuffer _spdConstants ;
public OpticalFlowGenerateInputPyramidPass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
: base ( contextDescription , resources , constants )
public OpticalFlowGenerateInputPyramidPass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
: base ( resources , constants )
{
_spdConstants = spdConstants ;
InitComputeShader ( "Generate Optical Flow Input Pyramid" , contextDescription . shaders . generateOpticalFlowInputPyramid ) ;
@ -92,8 +89,8 @@ namespace FidelityFX.FrameGen
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowInputLevel5 , Resources . OpticalFlowInputLevels [ 5 ] [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowInputLevel6 , Resources . OpticalFlowInputLevels [ 6 ] [ frameIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < OpticalFlow . SpdConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . SpdConstants > ( ComputeShader , OpticalFlowShaderIDs . CbSpd , _spdConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -101,19 +98,18 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowGenerateSCDHistogramPass : OpticalFlowPass
{
public OpticalFlowGenerateSCDHistogramPass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowGenerateSCDHistogramPass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Generate SCD Histogram" , contextDescription . shaders . generateScdHistogram ) ;
}
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , OpticalFlow . DispatchDescription dispatchParams , int frameIndex , int level , int dispatchX , int dispatchY , int dispatchZ )
{
// TODO: probably needs to be input from this frame (result from previous passes), but double check to be sure
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlowInput , Resources . OpticalFlowInputLevels [ 0 ] [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdHistogram , Resources . OpticalFlowSCDHistogram ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -121,22 +117,20 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowComputeSCDDivergencePass : OpticalFlowPass
{
public OpticalFlowComputeSCDDivergencePass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowComputeSCDDivergencePass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Compute SCD Divergence" , contextDescription . shaders . computeScdDivergence ) ;
}
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , OpticalFlow . DispatchDescription dispatchParams , int frameIndex , int level , int dispatchX , int dispatchY , int dispatchZ )
{
ref var scdOutput = ref dispatchParams . OpticalFlowSCD ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdHistogram , Resources . OpticalFlowSCDHistogram ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdPreviousHistogram , Resources . OpticalFlowSCDPreviousHistogram ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdTemp , Resources . OpticalFlowSCDTemp ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , scdOutput . RenderTarget , scdOutput . MipLevel , scdOutput . SubElement ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , dispatchParams . OpticalFlowSCD ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -144,8 +138,8 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowComputePass : OpticalFlowPass
{
public OpticalFlowComputePass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowComputePass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Optical Flow Search" , contextDescription . shaders . computeOpticalFlow ) ;
}
@ -153,14 +147,13 @@ namespace FidelityFX.FrameGen
protected override void DoScheduleDispatch ( CommandBuffer commandBuffer , OpticalFlow . DispatchDescription dispatchParams , int frameIndex , int level , int dispatchX , int dispatchY , int dispatchZ )
{
int levelIndex = frameIndex ^ ( level & 1 ) ;
ref var scdOutput = ref dispatchParams . OpticalFlowSCD ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlowInput , Resources . OpticalFlowInputLevels [ level ] [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlowPreviousInput , Resources . OpticalFlowInputLevels [ level ] [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlow , Resources . OpticalFlowLevels [ level ] [ levelIndex ] ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , scdOutput . RenderTarget , scdOutput . MipLevel , scdOutput . SubElement ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , dispatchParams . OpticalFlowSCD ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -168,8 +161,8 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowFilterPass : OpticalFlowPass
{
public OpticalFlowFilterPass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowFilterPass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Optical Flow Filter" , contextDescription . shaders . filterOpticalFlow ) ;
}
@ -183,15 +176,14 @@ namespace FidelityFX.FrameGen
if ( level = = 0 )
{
// Final output (levels are counted in reverse)
ref var ofVector = ref dispatchParams . OpticalFlowVector ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlow , ofVector . RenderTarget , ofVector . MipLevel , ofVector . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlow , dispatchParams . OpticalFlowVector ) ;
}
else
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlow , Resources . OpticalFlowLevels [ level ] [ levelIndex ^ 1 ] ) ;
}
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
@ -199,8 +191,8 @@ namespace FidelityFX.FrameGen
internal class OpticalFlowScalePass : OpticalFlowPass
{
public OpticalFlowScalePass ( OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
public OpticalFlowScalePass ( in OpticalFlow . ContextDescription contextDescription , OpticalFlowResources resources , ComputeBuffer constants )
: base ( resources , constants )
{
InitComputeShader ( "Optical Flow Scale" , contextDescription . shaders . scaleOpticalFlow ) ;
}
@ -211,16 +203,15 @@ namespace FidelityFX.FrameGen
return ;
int levelIndex = frameIndex ^ ( level & 1 ) ;
ref var scdOutput = ref dispatchParams . OpticalFlowSCD ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlowInput , Resources . OpticalFlowInputLevels [ level ] [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlowPreviousInput , Resources . OpticalFlowInputLevels [ level ] [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . SrvOpticalFlow , Resources . OpticalFlowLevels [ level ] [ levelIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowNextLevel , Resources . OpticalFlowLevels [ level - 1 ] [ levelIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , scdOutput . RenderTarget , scdOutput . MipLevel , scdOutput . SubElement ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , OpticalFlowShaderIDs . UavOpticalFlowScdOutput , dispatchParams . OpticalFlowSCD ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants , 0 , Marshal . SizeOf < OpticalFlow . OpticalFlowConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < OpticalFlow . OpticalFlowConstants > ( ComputeShader , OpticalFlowShaderIDs . CbOpticalFlow , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}