Development repository for FSR2 integration into Unity Post-Processing Stack V2.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.9 KiB

using System.Runtime.InteropServices;
using FidelityFX;
using UnityEngine.Experimental.Rendering;
namespace UnityEngine.Rendering.PostProcessing
{
internal abstract class SGSR2Upscaler: Upscaler
{
public static bool IsSupported => SystemInfo.supportsComputeShaders;
protected RenderTexture _colorLuma;
protected RenderTexture _motionDepthAlpha;
protected RenderTexture _motionDepthClipAlpha;
protected readonly RenderTexture[] _lumaHistory = new RenderTexture[2];
protected readonly RenderTexture[] _upscaleHistory = new RenderTexture[2];
protected readonly ConstantsBuffer<SGSR2.Params> _paramsBuffer = new();
protected uint _frameCount = 0;
public override void CreateContext(PostProcessRenderContext context, Upscaling config)
{
CreateRenderTexture(ref _colorLuma, "ColorLuma", config.MaxRenderSize, GraphicsFormat.R32_UInt, true);
CreateRenderTexture(ref _motionDepthAlpha, "MotionDepthAlpha", config.MaxRenderSize, GraphicsFormat.R16G16B16A16_SFloat, true);
CreateRenderTexture(ref _motionDepthClipAlpha, "MotionDepthClipAlpha", config.MaxRenderSize, GraphicsFormat.R16G16B16A16_SFloat, true);
CreateRenderTextureArray(_lumaHistory, "LumaHistory", config.MaxRenderSize, GraphicsFormat.R32_UInt, true);
CreateRenderTextureArray(_upscaleHistory, "History", config.UpscaleSize, context.sourceFormat, true);
_paramsBuffer.Init();
}
public override void DestroyContext()
{
base.DestroyContext();
_paramsBuffer.Destroy();
DestroyRenderTextureArray(_upscaleHistory);
DestroyRenderTextureArray(_lumaHistory);
DestroyRenderTexture(ref _motionDepthClipAlpha);
DestroyRenderTexture(ref _motionDepthAlpha);
DestroyRenderTexture(ref _colorLuma);
}
}
}