diff --git a/Runtime/FrameInterpolation/FrameInterpolation.cs b/Runtime/FrameInterpolation/FrameInterpolation.cs index 0b8bc23..5e36c67 100644 --- a/Runtime/FrameInterpolation/FrameInterpolation.cs +++ b/Runtime/FrameInterpolation/FrameInterpolation.cs @@ -16,10 +16,60 @@ namespace FidelityFX.FrameGen public FrameInterpolationShaders shaders; } + public class PrepareDescription + { + public DispatchFlags flags; + public Vector2Int renderSize; + public Vector2 jitterOffset; + public Vector2 motionVectorScale; + + public float frameTimeDelta; + public float cameraNear; + public float cameraFar; + public float viewSpaceToMetersFactor; + public float cameraFovAngleVertical; + + public ResourceView depth; + public ResourceView motionVectors; + public ulong frameID; + } + // TODO: turn all of these into structs public class DispatchDescription { - + public DispatchFlags flags; + public Vector2Int displaySize; + public Vector2Int renderSize; + public ResourceView currentBackBuffer; + public ResourceView currentBackBuffer_HUDLess; + public ResourceView output; + + public RectInt interpolationRect; + + public ResourceView opticalFlowVector; + public ResourceView opticalFlowSceneChangeDetection; + public Vector2Int opticalFlowBufferSize; + public Vector2 opticalFlowScale; + public int opticalFlowBlockSize; + + public float cameraNear; + public float cameraFar; + public float cameraFovAngleVertical; + public float viewSpaceToMetersFactor; + + public float frameTimeDelta; + public bool reset; + + public BackbufferTransferFunction backbufferTransferFunction; + public Vector2 minMaxLuminance; + public ulong frameID; + } + + public enum BackbufferTransferFunction + { + LDR_sRGB, + HDR_PQ, + HDR_scRGB, } [Flags] diff --git a/Runtime/FrameInterpolation/FrameInterpolationContext.cs b/Runtime/FrameInterpolation/FrameInterpolationContext.cs index fe1c017..4f06525 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationContext.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationContext.cs @@ -32,6 +32,7 @@ namespace FidelityFX.FrameGen private ref FrameInterpolation.InpaintingPyramidConstants SpdConstants => ref _spdConstantsArray[0]; private readonly CustomSampler _sampler = CustomSampler.Create("Frame Interpolation"); + private readonly CustomSampler _prepareSampler = CustomSampler.Create("Frame Interpolation - Prepare"); private bool _firstExecution; private bool _asyncSupported; @@ -94,6 +95,13 @@ namespace FidelityFX.FrameGen DestroyConstantBuffer(ref _frameInterpolationConstantsBuffer); } + public void Prepare(CommandBuffer commandBuffer, FrameInterpolation.PrepareDescription prepareDescription) + { + commandBuffer.BeginSample(_prepareSampler); + + commandBuffer.EndSample(_prepareSampler); + } + public void Dispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchDescription) { commandBuffer.BeginSample(_sampler); diff --git a/Runtime/FrameInterpolation/FrameInterpolationPass.cs b/Runtime/FrameInterpolation/FrameInterpolationPass.cs index 96ef007..fa1ed64 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationPass.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationPass.cs @@ -14,7 +14,7 @@ namespace FidelityFX.FrameGen protected ComputeShader ComputeShader; protected int KernelIndex; - private CustomSampler _sampler; + protected CustomSampler Sampler; protected FrameInterpolationPass(FrameInterpolation.ContextDescription contextDescription, FrameInterpolationResources resources, ComputeBuffer constants) { @@ -29,9 +29,9 @@ namespace FidelityFX.FrameGen public void ScheduleDispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ = 1) { - commandBuffer.BeginSample(_sampler); + commandBuffer.BeginSample(Sampler); DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY, dispatchZ); - commandBuffer.EndSample(_sampler); + commandBuffer.EndSample(Sampler); } protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ); @@ -50,7 +50,7 @@ namespace FidelityFX.FrameGen ComputeShader = shader; KernelIndex = ComputeShader.FindKernel("CS"); - _sampler = CustomSampler.Create(passName); + Sampler = CustomSampler.Create(passName); if ((flags & FrameInterpolation.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) ComputeShader.EnableKeyword("FFX_FRAMEINTERPOLATION_OPTION_LOW_RES_MOTION_VECTORS"); if ((flags & FrameInterpolation.InitializationFlags.EnableJitterMotionVectors) != 0) ComputeShader.EnableKeyword("FFX_FRAMEINTERPOLATION_OPTION_JITTERED_MOTION_VECTORS"); @@ -68,7 +68,13 @@ namespace FidelityFX.FrameGen protected override void DoScheduleDispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { - throw new NotImplementedException(); + } + + public void ScheduleDispatch(CommandBuffer commandBuffer, FrameInterpolation.PrepareDescription prepareParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) + { + commandBuffer.BeginSample(Sampler); + + commandBuffer.EndSample(Sampler); } } diff --git a/Runtime/FrameInterpolation/FrameInterpolationShaderIDs.cs b/Runtime/FrameInterpolation/FrameInterpolationShaderIDs.cs index 60eaf67..d5c4686 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationShaderIDs.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationShaderIDs.cs @@ -4,7 +4,54 @@ namespace FidelityFX.FrameGen { public static class FrameInterpolationShaderIDs { + // Shader resource views, i.e. read-only bindings public static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth"); public static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors"); + public static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilated_depth"); + public static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors"); + public static readonly int SrvReconstructedDepthPreviousFrame = Shader.PropertyToID("r_reconstructed_depth_previous_frame"); + public static readonly int SrvReconstructedDepthInterpolatedFrame = Shader.PropertyToID("r_reconstructed_depth_interpolated_frame"); + public static readonly int SrvPreviousInterpolationSource = Shader.PropertyToID("r_previous_interpolation_source"); + public static readonly int SrvDisocclusionMask = Shader.PropertyToID("r_disocclusion_mask"); + public static readonly int SrvGameMotionVectorFieldX = Shader.PropertyToID("r_game_motion_vector_field_x"); + public static readonly int SrvGameMotionVectorFieldY = Shader.PropertyToID("r_game_motion_vector_field_y"); + public static readonly int SrvOpticalFlowVector = Shader.PropertyToID("r_optical_flow"); + public static readonly int SrvOpticalFlowConfidence = Shader.PropertyToID("r_optical_flow_confidence"); + public static readonly int SrvOpticalFlowGlobalMotion = Shader.PropertyToID("r_optical_flow_global_motion"); + public static readonly int SrvOpticalFlowSceneChangeDetection = Shader.PropertyToID("r_optical_flow_scd"); + public static readonly int SrvOutput = Shader.PropertyToID("r_output"); + public static readonly int SrvInpaintingPyramid = Shader.PropertyToID("r_inpainting_pyramid"); + public static readonly int SrvPresentBackbuffer = Shader.PropertyToID("r_present_backbuffer"); + public static readonly int SrvCounters = Shader.PropertyToID("r_counters"); + + // Unordered access views, i.e. random read/write bindings + public static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilated_depth"); + public static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors"); + public static readonly int UavReconstructedDepthPreviousFrame = Shader.PropertyToID("rw_reconstructed_depth_previous_frame"); + public static readonly int UavReconstructedDepthInterpolatedFrame = Shader.PropertyToID("rw_reconstructed_depth_interpolated_frame"); + public static readonly int UavOutput = Shader.PropertyToID("rw_output"); + public static readonly int UavDisocclusionMask = Shader.PropertyToID("rw_disocclusion_mask"); + public static readonly int UavGameMotionVectorFieldX = Shader.PropertyToID("rw_game_motion_vector_field_x"); + public static readonly int UavGameMotionVectorFieldY = Shader.PropertyToID("rw_game_motion_vector_field_y"); + public static readonly int UavOpticalFlowMotionVectorFieldX = Shader.PropertyToID("rw_optical_flow_motion_vector_field_x"); + public static readonly int UavOpticalFlowMotionVectorFieldY = Shader.PropertyToID("rw_optical_flow_motion_vector_field_y"); + public static readonly int UavCounter = Shader.PropertyToID("rw_counters"); + public static readonly int UavInpaintingPyramidMipmap0 = Shader.PropertyToID("rw_inpainting_pyramid0"); + public static readonly int UavInpaintingPyramidMipmap1 = Shader.PropertyToID("rw_inpainting_pyramid1"); + public static readonly int UavInpaintingPyramidMipmap2 = Shader.PropertyToID("rw_inpainting_pyramid2"); + public static readonly int UavInpaintingPyramidMipmap3 = Shader.PropertyToID("rw_inpainting_pyramid3"); + public static readonly int UavInpaintingPyramidMipmap4 = Shader.PropertyToID("rw_inpainting_pyramid4"); + public static readonly int UavInpaintingPyramidMipmap5 = Shader.PropertyToID("rw_inpainting_pyramid5"); + public static readonly int UavInpaintingPyramidMipmap6 = Shader.PropertyToID("rw_inpainting_pyramid6"); + public static readonly int UavInpaintingPyramidMipmap7 = Shader.PropertyToID("rw_inpainting_pyramid7"); + public static readonly int UavInpaintingPyramidMipmap8 = Shader.PropertyToID("rw_inpainting_pyramid8"); + public static readonly int UavInpaintingPyramidMipmap9 = Shader.PropertyToID("rw_inpainting_pyramid9"); + public static readonly int UavInpaintingPyramidMipmap10 = Shader.PropertyToID("rw_inpainting_pyramid10"); + public static readonly int UavInpaintingPyramidMipmap11 = Shader.PropertyToID("rw_inpainting_pyramid11"); + public static readonly int UavInpaintingPyramidMipmap12 = Shader.PropertyToID("rw_inpainting_pyramid12"); + + // Constant buffer bindings + public static readonly int CbFrameInterpolation = Shader.PropertyToID("cbFI"); + public static readonly int CbInpaintingPyramid = Shader.PropertyToID("cbInpaintingPyramid"); } }