From 650e805af80399e88803adf0d47a78a94e155c58 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Thu, 23 Feb 2023 22:15:59 +0100 Subject: [PATCH] Combined color and depth into a single dispatch parameter, which makes it easier to follow what's going on at the various stages. --- Assets/Scripts/Fsr2.cs | 3 ++- Assets/Scripts/Fsr2Context.cs | 8 ++++---- Assets/Scripts/Fsr2Controller.cs | 9 ++++----- Assets/Scripts/Fsr2Pipeline.cs | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Fsr2.cs b/Assets/Scripts/Fsr2.cs index 15371a8..aae34ac 100644 --- a/Assets/Scripts/Fsr2.cs +++ b/Assets/Scripts/Fsr2.cs @@ -136,7 +136,8 @@ namespace FidelityFX public class DispatchDescription { - public Texture Color, Depth, MotionVectors; + public Texture ColorDepth; + public Texture MotionVectors; public Texture Exposure; public Texture Reactive; public Texture TransparencyAndComposition; diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs index 3310b55..4aee46b 100644 --- a/Assets/Scripts/Fsr2Context.cs +++ b/Assets/Scripts/Fsr2Context.cs @@ -247,7 +247,7 @@ namespace FidelityFX } else { - _commandBuffer.Blit(dispatchParams.Color, dispatchParams.Output); + _commandBuffer.Blit(dispatchParams.ColorDepth, dispatchParams.Output); } _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; @@ -263,10 +263,10 @@ namespace FidelityFX constants.jitterOffset = dispatchParams.JitterOffset; 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.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 float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index 2c1ac17..0a96bc7 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -109,14 +109,13 @@ public class Fsr2Controller : MonoBehaviour // For legacy built-in render pipeline 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 - 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.Output = _outputRT; _dispatchDescription.Exposure = null; diff --git a/Assets/Scripts/Fsr2Pipeline.cs b/Assets/Scripts/Fsr2Pipeline.cs index cbc3132..09125f1 100644 --- a/Assets/Scripts/Fsr2Pipeline.cs +++ b/Assets/Scripts/Fsr2Pipeline.cs @@ -173,7 +173,7 @@ namespace FidelityFX // - 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 - 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.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbSpd, _spdConstants, 0, Marshal.SizeOf()); @@ -196,8 +196,8 @@ namespace FidelityFX 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, 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, SrvPrevDilatedMotionVectors, _dilatedMotionVectors[frameIndex ^ 1]); 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.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); @@ -318,7 +318,7 @@ namespace FidelityFX { // Run the RCAS sharpening filter on the upscaled image 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.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbRcas, _rcasConstants, 0, Marshal.SizeOf());