Browse Source

Changed all dispatch descriptions into structs, renamed some fields, cleaned up some unused code.

Changing to lowercase field names for public struct members now, which follows the C# naming conventions. FSR2/3 won't follow suit for now, because too much code already makes use of the capitalized names.
fsr3framegen
Nico de Poel 2 years ago
parent
commit
76d0ee5425
  1. 11
      Runtime/FrameInterpolation/FrameInterpolation.cs
  2. 18
      Runtime/FrameInterpolation/FrameInterpolationContext.cs
  3. 14
      Runtime/OpticalFlow/OpticalFlow.cs
  4. 23
      Runtime/OpticalFlow/OpticalFlowContext.cs
  5. 10
      Runtime/OpticalFlow/OpticalFlowPass.cs

11
Runtime/FrameInterpolation/FrameInterpolation.cs

@ -39,7 +39,7 @@ namespace FidelityFX.FrameGen
public FrameInterpolationShaders shaders; public FrameInterpolationShaders shaders;
} }
public class PrepareDescription
public struct PrepareDescription
{ {
public DispatchFlags flags; public DispatchFlags flags;
public Vector2Int renderSize; public Vector2Int renderSize;
@ -57,8 +57,7 @@ namespace FidelityFX.FrameGen
public ulong frameID; public ulong frameID;
} }
// TODO: turn all of these into structs
public class DispatchDescription
public struct DispatchDescription
{ {
public DispatchFlags flags; public DispatchFlags flags;
public Vector2Int displaySize; public Vector2Int displaySize;
@ -87,14 +86,14 @@ namespace FidelityFX.FrameGen
public Vector2 minMaxLuminance; public Vector2 minMaxLuminance;
public ulong frameID; public ulong frameID;
public ref ResourceView InterpolationSource
public ResourceView InterpolationSource
{ {
get get
{ {
if (currentBackBuffer_HUDLess.IsValid) if (currentBackBuffer_HUDLess.IsValid)
return ref currentBackBuffer_HUDLess;
return currentBackBuffer_HUDLess;
return ref currentBackBuffer;
return currentBackBuffer;
} }
} }
} }

18
Runtime/FrameInterpolation/FrameInterpolationContext.cs

@ -93,7 +93,7 @@ namespace FidelityFX.FrameGen
_frameInterpolationConstants.Destroy(); _frameInterpolationConstants.Destroy();
} }
public void Prepare(CommandBuffer commandBuffer, FrameInterpolation.PrepareDescription prepareDescription)
public void Prepare(CommandBuffer commandBuffer, in FrameInterpolation.PrepareDescription prepareDescription)
{ {
commandBuffer.BeginSample(_prepareSampler); commandBuffer.BeginSample(_prepareSampler);
@ -125,7 +125,7 @@ namespace FidelityFX.FrameGen
commandBuffer.EndSample(_prepareSampler); commandBuffer.EndSample(_prepareSampler);
} }
public void Dispatch(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchDescription)
public void Dispatch(CommandBuffer commandBuffer, in FrameInterpolation.DispatchDescription dispatchDescription)
{ {
commandBuffer.BeginSample(_sampler); commandBuffer.BeginSample(_sampler);
@ -226,13 +226,12 @@ namespace FidelityFX.FrameGen
} }
// Store current buffer // Store current buffer
ref var backBuf = ref dispatchDescription.InterpolationSource;
commandBuffer.CopyTexture(backBuf.RenderTarget, _resources.PreviousInterpolationSource);
commandBuffer.CopyTexture(dispatchDescription.InterpolationSource.RenderTarget, _resources.PreviousInterpolationSource);
commandBuffer.EndSample(_sampler); commandBuffer.EndSample(_sampler);
} }
private void DispatchGameVectorFieldInpaintingPyramid(CommandBuffer commandBuffer, FrameInterpolation.DispatchDescription dispatchDescription, int doubleBufferId)
private void DispatchGameVectorFieldInpaintingPyramid(CommandBuffer commandBuffer, in FrameInterpolation.DispatchDescription dispatchDescription, int doubleBufferId)
{ {
SetupSpdConstants(dispatchDescription.renderSize, out var dispatchThreadGroupCount); SetupSpdConstants(dispatchDescription.renderSize, out var dispatchThreadGroupCount);
_spdConstants.UpdateBufferData(commandBuffer); _spdConstants.UpdateBufferData(commandBuffer);
@ -257,14 +256,5 @@ namespace FidelityFX.FrameGen
0.0f, 1.0f, 0.1f, // green 0.0f, 1.0f, 0.1f, // green
1.0f, 1.0f, 0.48f // bright yellow 1.0f, 1.0f, 0.48f // bright yellow
}; };
private static void DestroyPass(ref FrameInterpolationPass pass)
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
} }
} }

14
Runtime/OpticalFlow/OpticalFlow.cs

@ -33,15 +33,15 @@ namespace FidelityFX.FrameGen
public OpticalFlowShaders shaders; public OpticalFlowShaders shaders;
} }
public class DispatchDescription
public struct DispatchDescription
{ {
public ResourceView Color;
public ResourceView OpticalFlowVector;
public ResourceView OpticalFlowSCD;
public bool Reset;
public ResourceView color;
public ResourceView opticalFlowVector;
public ResourceView opticalFlowSCD;
public bool reset;
public BackbufferTransferFunction BackbufferTransferFunction;
public Vector2 MinMaxLuminance;
public BackbufferTransferFunction backbufferTransferFunction;
public Vector2 minMaxLuminance;
} }
internal static Vector2Int GetOpticalFlowTextureSize(Vector2Int displaySize, int opticalFlowBlockSize) internal static Vector2Int GetOpticalFlowTextureSize(Vector2Int displaySize, int opticalFlowBlockSize)

23
Runtime/OpticalFlow/OpticalFlowContext.cs

@ -82,11 +82,11 @@ namespace FidelityFX.FrameGen
const int opticalFlowBlockSize = 8; const int opticalFlowBlockSize = 8;
ref var constants = ref _opticalFlowConstants.Value; ref var constants = ref _opticalFlowConstants.Value;
constants.backbufferTransferFunction = (uint)dispatchDescription.BackbufferTransferFunction;
constants.minMaxLuminance = dispatchDescription.MinMaxLuminance;
constants.backbufferTransferFunction = (uint)dispatchDescription.backbufferTransferFunction;
constants.minMaxLuminance = dispatchDescription.minMaxLuminance;
int frameIndex = _resourceFrameIndex % 2; int frameIndex = _resourceFrameIndex % 2;
bool resetAccumulation = dispatchDescription.Reset || _firstExecution;
bool resetAccumulation = dispatchDescription.reset || _firstExecution;
_firstExecution = false; _firstExecution = false;
if (resetAccumulation) if (resetAccumulation)
@ -100,7 +100,7 @@ namespace FidelityFX.FrameGen
{ {
commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDTemp); commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDTemp);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(dispatchDescription.OpticalFlowSCD.RenderTarget);
commandBuffer.SetRenderTarget(dispatchDescription.opticalFlowSCD.RenderTarget);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDHistogram); commandBuffer.SetRenderTarget(_resources.OpticalFlowSCDHistogram);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
@ -135,7 +135,7 @@ namespace FidelityFX.FrameGen
{ {
const int threadGroupSizeX = 32; const int threadGroupSizeX = 32;
const int threadGroupSizeY = 8;
//const int threadGroupSizeY = 8;
int strataWidth = (_contextDescription.resolution.x / 4) / OpticalFlow.HistogramsPerDim; int strataWidth = (_contextDescription.resolution.x / 4) / OpticalFlow.HistogramsPerDim;
int strataHeight = _contextDescription.resolution.y / OpticalFlow.HistogramsPerDim; int strataHeight = _contextDescription.resolution.y / OpticalFlow.HistogramsPerDim;
int dispatchX = (strataWidth + threadGroupSizeX - 1) / threadGroupSizeX; int dispatchX = (strataWidth + threadGroupSizeX - 1) / threadGroupSizeX;
@ -173,7 +173,7 @@ namespace FidelityFX.FrameGen
const int threadPixels = 4; const int threadPixels = 4;
Assert.IsTrue(opticalFlowBlockSize >= threadPixels); Assert.IsTrue(opticalFlowBlockSize >= threadPixels);
const int threadGroupSizeX = 4;
//const int threadGroupSizeX = 4;
const int threadGroupSizeY = 16; const int threadGroupSizeY = 16;
const int threadGroupSize = 64; const int threadGroupSize = 64;
int dispatchX = ((inputLumaWidth + threadPixels - 1) / threadPixels * threadGroupSizeY + (threadGroupSize - 1)) / threadGroupSize; int dispatchX = ((inputLumaWidth + threadPixels - 1) / threadPixels * threadGroupSizeY + (threadGroupSize - 1)) / threadGroupSize;
@ -201,7 +201,7 @@ namespace FidelityFX.FrameGen
const int threadGroupSizeX = opticalFlowBlockSize / 2; const int threadGroupSizeX = opticalFlowBlockSize / 2;
const int threadGroupSizeY = opticalFlowBlockSize / 2; const int threadGroupSizeY = opticalFlowBlockSize / 2;
const int threadGroupSizeZ = 4;
//const int threadGroupSizeZ = 4;
int dispatchX = (nextLevelWidth + threadGroupSizeX - 1) / threadGroupSizeX; int dispatchX = (nextLevelWidth + threadGroupSizeX - 1) / threadGroupSizeX;
int dispatchY = (nextLevelHeight + threadGroupSizeY - 1) / threadGroupSizeY; int dispatchY = (nextLevelHeight + threadGroupSizeY - 1) / threadGroupSizeY;
const int dispatchZ = 1; const int dispatchZ = 1;
@ -223,14 +223,5 @@ namespace FidelityFX.FrameGen
FfxSpd.SetupSpdConstants(_contextDescription.resolution * resolutionMultiplier, ref spdConstants.spd, out dispatchThreadGroupCount); FfxSpd.SetupSpdConstants(_contextDescription.resolution * resolutionMultiplier, ref spdConstants.spd, out dispatchThreadGroupCount);
spdConstants.numWorkGroupsOpticalFlowInputPyramid = spdConstants.spd.numWorkGroups; spdConstants.numWorkGroupsOpticalFlowInputPyramid = spdConstants.spd.numWorkGroups;
} }
private static void DestroyPass(ref OpticalFlowPass pass)
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
} }
} }

10
Runtime/OpticalFlow/OpticalFlowPass.cs

@ -43,7 +43,7 @@ namespace FidelityFX.FrameGen
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in OpticalFlow.DispatchDescription dispatchParams, int bufferIndex, int level, int dispatchX, int dispatchY, int dispatchZ) protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in OpticalFlow.DispatchDescription dispatchParams, int bufferIndex, int level, int dispatchX, int dispatchY, int dispatchZ)
{ {
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvInputColor, dispatchParams.Color);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvInputColor, dispatchParams.color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowInput, Resources.OpticalFlowInputLevels[0][bufferIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowInput, Resources.OpticalFlowInputLevels[0][bufferIndex]);
@ -113,7 +113,7 @@ namespace FidelityFX.FrameGen
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdHistogram, Resources.OpticalFlowSCDHistogram); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdHistogram, Resources.OpticalFlowSCDHistogram);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdPreviousHistogram, Resources.OpticalFlowSCDPreviousHistogram); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdPreviousHistogram, Resources.OpticalFlowSCDPreviousHistogram);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdTemp, Resources.OpticalFlowSCDTemp); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdTemp, Resources.OpticalFlowSCDTemp);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD);
commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants); commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants);
@ -136,7 +136,7 @@ namespace FidelityFX.FrameGen
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowInput, Resources.OpticalFlowInputLevels[level][bufferIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowInput, Resources.OpticalFlowInputLevels[level][bufferIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowPreviousInput, Resources.OpticalFlowInputLevels[level][bufferIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlowPreviousInput, Resources.OpticalFlowInputLevels[level][bufferIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, Resources.OpticalFlowLevels[level][levelIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, Resources.OpticalFlowLevels[level][levelIndex]);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD);
commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants); commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants);
@ -161,7 +161,7 @@ namespace FidelityFX.FrameGen
if (level == 0) if (level == 0)
{ {
// Final output (levels are counted in reverse) // Final output (levels are counted in reverse)
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, dispatchParams.OpticalFlowVector);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlow, dispatchParams.opticalFlowVector);
} }
else else
{ {
@ -194,7 +194,7 @@ namespace FidelityFX.FrameGen
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.SrvOpticalFlow, Resources.OpticalFlowLevels[level][levelIndex ^ 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.SetComputeTextureParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowNextLevel, Resources.OpticalFlowLevels[level - 1][levelIndex ^ 1]);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.OpticalFlowSCD);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, OpticalFlowShaderIDs.UavOpticalFlowScdOutput, dispatchParams.opticalFlowSCD);
commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants); commandBuffer.SetComputeConstantBufferParam<OpticalFlow.OpticalFlowConstants>(ComputeShader, OpticalFlowShaderIDs.CbOpticalFlow, Constants);

Loading…
Cancel
Save