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 _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); } } }