Browse Source

Combined color and depth into a single dispatch parameter, which makes it easier to follow what's going on at the various stages.

mac-autoexp
Nico de Poel 3 years ago
parent
commit
650e805af8
  1. 3
      Assets/Scripts/Fsr2.cs
  2. 8
      Assets/Scripts/Fsr2Context.cs
  3. 9
      Assets/Scripts/Fsr2Controller.cs
  4. 12
      Assets/Scripts/Fsr2Pipeline.cs

3
Assets/Scripts/Fsr2.cs

@ -136,7 +136,8 @@ namespace FidelityFX
public class DispatchDescription public class DispatchDescription
{ {
public Texture Color, Depth, MotionVectors;
public Texture ColorDepth;
public Texture MotionVectors;
public Texture Exposure; public Texture Exposure;
public Texture Reactive; public Texture Reactive;
public Texture TransparencyAndComposition; public Texture TransparencyAndComposition;

8
Assets/Scripts/Fsr2Context.cs

@ -247,7 +247,7 @@ namespace FidelityFX
} }
else else
{ {
_commandBuffer.Blit(dispatchParams.Color, dispatchParams.Output);
_commandBuffer.Blit(dispatchParams.ColorDepth, dispatchParams.Output);
} }
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;
@ -263,10 +263,10 @@ namespace FidelityFX
constants.jitterOffset = dispatchParams.JitterOffset; constants.jitterOffset = dispatchParams.JitterOffset;
constants.renderSize = new Vector2Int( constants.renderSize = new Vector2Int(
dispatchParams.RenderSize.x > 0 ? dispatchParams.RenderSize.x : dispatchParams.Color.width,
dispatchParams.RenderSize.y > 0 ? dispatchParams.RenderSize.y : dispatchParams.Color.height);
dispatchParams.RenderSize.x > 0 ? dispatchParams.RenderSize.x : dispatchParams.ColorDepth.width,
dispatchParams.RenderSize.y > 0 ? dispatchParams.RenderSize.y : dispatchParams.ColorDepth.height);
constants.maxRenderSize = _contextDescription.MaxRenderSize; constants.maxRenderSize = _contextDescription.MaxRenderSize;
constants.inputColorResourceDimensions = new Vector2Int(dispatchParams.Color.width, dispatchParams.Color.height);
constants.inputColorResourceDimensions = new Vector2Int(dispatchParams.ColorDepth.width, dispatchParams.ColorDepth.height);
// Compute the horizontal FOV for the shader from the vertical one // Compute the horizontal FOV for the shader from the vertical one
float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y;

9
Assets/Scripts/Fsr2Controller.cs

@ -109,14 +109,13 @@ public class Fsr2Controller : MonoBehaviour
// For legacy built-in render pipeline // For legacy built-in render pipeline
private void OnRenderImage(RenderTexture src, RenderTexture dest) private void OnRenderImage(RenderTexture src, RenderTexture dest)
{ {
var color = gameCamera.targetTexture;
var renderBuffer = gameCamera.targetTexture;
// I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address motion vectors from code // I hate having to allocate extra RTs just to duplicate already existing Unity render buffers, but AFAIK there is no way to directly address motion vectors from code
var motionVectors = RenderTexture.GetTemporary(color.width, color.height, 0, RenderTextureFormat.RGHalf);
Graphics.Blit(color, motionVectors, CopyMotionVectorsMaterial);
var motionVectors = RenderTexture.GetTemporary(renderBuffer.width, renderBuffer.height, 0, RenderTextureFormat.RGHalf);
Graphics.Blit(renderBuffer, motionVectors, CopyMotionVectorsMaterial);
_dispatchDescription.Color = color;
_dispatchDescription.Depth = color;
_dispatchDescription.ColorDepth = renderBuffer;
_dispatchDescription.MotionVectors = motionVectors; _dispatchDescription.MotionVectors = motionVectors;
_dispatchDescription.Output = _outputRT; _dispatchDescription.Output = _outputRT;
_dispatchDescription.Exposure = null; _dispatchDescription.Exposure = null;

12
Assets/Scripts/Fsr2Pipeline.cs

@ -173,7 +173,7 @@ namespace FidelityFX
// - How do we clear the resources that need to be cleared at dispatch? (SetBufferData) // - How do we clear the resources that need to be cleared at dispatch? (SetBufferData)
// - Shouldn't we use a ComputeBuffer for resources that are one-dimensional and clearly not image data? e.g. SPD atomic counter & Lanczos LUT data // - Shouldn't we use a ComputeBuffer for resources that are one-dimensional and clearly not image data? e.g. SPD atomic counter & Lanczos LUT data
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavAutoExposure, _autoExposure); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavAutoExposure, _autoExposure);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>());
@ -196,8 +196,8 @@ namespace FidelityFX
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{ {
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth, 0, RenderTextureSubElement.Depth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Depth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure);
@ -228,8 +228,8 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvTransparencyAndCompositionMask, dispatchParams.Reactive); // Default reactive mask, as we don't support TCR (yet) commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvTransparencyAndCompositionMask, dispatchParams.Reactive); // Default reactive mask, as we don't support TCR (yet)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvPrevDilatedMotionVectors, _dilatedMotionVectors[frameIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvPrevDilatedMotionVectors, _dilatedMotionVectors[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputMotionVectors, dispatchParams.MotionVectors);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.Color, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.Depth, 0, RenderTextureSubElement.Depth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputColor, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputDepth, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Depth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>());
@ -318,7 +318,7 @@ namespace FidelityFX
{ {
// Run the RCAS sharpening filter on the upscaled image // Run the RCAS sharpening filter on the upscaled image
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvRcasInput, dispatchParams.Color, 0, RenderTextureSubElement.Color); // TODO: should be output from accumulate pass
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvRcasInput, dispatchParams.ColorDepth, 0, RenderTextureSubElement.Color); // TODO: should be output from accumulate pass
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavUpscaledOutput, dispatchParams.Output); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, UavUpscaledOutput, dispatchParams.Output);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>());

Loading…
Cancel
Save