diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset index 8aa70bb..8ed7c12 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset @@ -129,6 +129,7 @@ MonoBehaviour: multiScaleAORender: {fileID: 7200000, guid: 34a460e8a2e66c243a9c12024e5a798d, type: 3} multiScaleAOUpsample: {fileID: 7200000, guid: 600d6212b59bb40409d19d750b5fd1e9, type: 3} gaussianDownsample: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3} + prepareInputs: {fileID: 7200000, guid: d27c88814f02b424088b06503e1bc9d5, type: 3} casSharpening: {fileID: 7200000, guid: 00e3ffafadd35564780d8a12adcbeff7, type: 3} fsr2Upscaler: computeLuminancePyramidPass: {fileID: 7200000, guid: 04c3480675e29a340808141e68d4cc8b, type: 3} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs index 1edb208..f18740e 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs @@ -186,6 +186,7 @@ namespace UnityEngine.Rendering.PostProcessing _upscaler = upscalerType switch { UpscalerType.FSR2 when FSR2Upscaler.IsSupported => new FSR2Upscaler(), + UpscalerType.FSR3 when FSR3NativeUpscaler.IsSupported => new FSR3NativeUpscaler(), UpscalerType.FSR3 when FSR3Upscaler.IsSupported => new FSR3Upscaler(), UpscalerType.ASR_Quality when ASRUpscaler.IsSupported => new ASRUpscaler_Quality(), UpscalerType.ASR_Balanced when ASRUpscaler.IsSupported => new ASRUpscaler_Balanced(), diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs new file mode 100644 index 0000000..88f0321 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs @@ -0,0 +1,176 @@ + +using UnityEngine.Experimental.Rendering; +#if UNITY_STANDALONE_WIN +using AMDUP = UnityEngine.AMD; +#endif + +namespace UnityEngine.Rendering.PostProcessing +{ + internal class FSR3NativeUpscaler: Upscaler + { +#if UNITY_STANDALONE_WIN + public static bool IsSupported => LoadNativePlugin(); + + private static bool _nativePluginLoaded; + + private AMDUP.FSR2Context _nativeContext; + + private RenderTexture _tempColorInput; + private RenderTexture _tempDepthInput; + private RenderTexture _tempMotionVectorInput; + private RenderTexture _tempColorOutput; + + public override void CreateContext(PostProcessRenderContext context, Upscaling config) + { + if (!LoadNativePlugin()) + return; + + // Initialize FSR3 Upscaler context + AMDUP.FfxFsr2InitializationFlags flags = 0; + if (context.camera.allowHDR) flags |= AMDUP.FfxFsr2InitializationFlags.EnableHighDynamicRange; + if (config.exposureSource == Upscaling.ExposureSource.Auto) flags |= AMDUP.FfxFsr2InitializationFlags.EnableAutoExposure; + if (RuntimeUtilities.IsDynamicResolutionEnabled(context.camera)) flags |= AMDUP.FfxFsr2InitializationFlags.EnableDynamicResolution; + if (SystemInfo.usesReversedZBuffer) flags |= AMDUP.FfxFsr2InitializationFlags.DepthInverted; + + AMDUP.FSR2CommandInitializationData initSettings = new() + { + maxRenderSizeWidth = (uint)config.MaxRenderSize.x, + maxRenderSizeHeight = (uint)config.MaxRenderSize.y, + displaySizeWidth = (uint)config.UpscaleSize.x, + displaySizeHeight = (uint)config.UpscaleSize.y, + ffxFsrFlags = flags, + }; + + CommandBuffer cmd = new(); + _nativeContext = AMDUP.GraphicsDevice.device.CreateFeature(cmd, in initSettings); + Graphics.ExecuteCommandBuffer(cmd); + cmd.Release(); + + CreateResources(context, config); + } + + public override void DestroyContext() + { + base.DestroyContext(); + + if (_nativeContext != null) + { + CommandBuffer cmd = new(); + AMDUP.GraphicsDevice.device.DestroyFeature(cmd, _nativeContext); + Graphics.ExecuteCommandBuffer(cmd); + cmd.Release(); + + _nativeContext = null; + } + + DestroyResources(); + } + + public override void Render(PostProcessRenderContext context, Upscaling config) + { + if (_nativeContext == null) + return; + + var camera = context.camera; + var cmd = context.command; + cmd.BeginSample("FSR 3.1"); + + var scaledRenderSize = config.GetScaledRenderSize(context.camera); + + ref var execData = ref _nativeContext.executeData; + execData.jitterOffsetX = config.JitterOffset.x; + execData.jitterOffsetY = config.JitterOffset.y; + execData.MVScaleX = -(float)scaledRenderSize.x; + execData.MVScaleY = -(float)scaledRenderSize.y; + execData.renderSizeWidth = (uint)scaledRenderSize.x; + execData.renderSizeHeight = (uint)scaledRenderSize.y; + execData.enableSharpening = config.performSharpenPass ? 1 : 0; + execData.sharpness = config.sharpness; + execData.frameTimeDelta = Time.unscaledDeltaTime * 1000f; + execData.preExposure = config.preExposure; + execData.reset = config.Reset ? 1 : 0; + execData.cameraNear = camera.nearClipPlane; + execData.cameraFar = camera.farClipPlane; + execData.cameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad; + + PrepareInputs(cmd, context, config, _tempColorInput, _tempDepthInput, _tempMotionVectorInput); + + AMDUP.FSR2TextureTable textureTable = new() + { + colorInput = _tempColorInput, + depth = _tempDepthInput, + motionVectors = _tempMotionVectorInput, + exposureTexture = config.exposureSource switch + { + Upscaling.ExposureSource.Manual when config.exposure != null => config.exposure, + Upscaling.ExposureSource.Unity => context.autoExposureTexture, + _ => null + }, + biasColorMask = null, + reactiveMask = null, + transparencyMask = config.transparencyAndCompositionMask, + colorOutput = _tempColorOutput, + }; + + if (config.autoGenerateReactiveMask || config.autoGenerateTransparencyAndComposition) + { + textureTable.biasColorMask = GenerateReactiveMask(cmd, context, config); + } + + AMDUP.GraphicsDevice.device.ExecuteFSR2(cmd, _nativeContext, in textureTable); + + cmd.CopyTexture(_tempColorOutput, context.destination); + + cmd.EndSample("FSR 3.1"); + } + + private void CreateResources(PostProcessRenderContext context, Upscaling config) + { + CreateRenderTexture(ref _tempColorInput, "FSR3 Color Input", config.MaxRenderSize, context.sourceFormat, true); + CreateRenderTexture(ref _tempDepthInput, "FSR3 Depth Input", config.MaxRenderSize, GraphicsFormat.R32_SFloat, true); + CreateRenderTexture(ref _tempMotionVectorInput, "FSR3 Motion Vector Input", config.MaxRenderSize, GraphicsFormat.R16G16_SFloat, true); + CreateRenderTexture(ref _tempColorOutput, "FSR3 Color Output", config.UpscaleSize, context.sourceFormat, true); + } + + private void DestroyResources() + { + DestroyRenderTexture(ref _tempColorOutput); + DestroyRenderTexture(ref _tempMotionVectorInput); + DestroyRenderTexture(ref _tempDepthInput); + DestroyRenderTexture(ref _tempColorInput); + } + + private static bool LoadNativePlugin() + { + if (_nativePluginLoaded) + return true; + + if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows && SystemInfo.graphicsDeviceType is GraphicsDeviceType.Direct3D12 or GraphicsDeviceType.Vulkan) + { + try + { + _nativePluginLoaded = AMDUP.GraphicsDevice.device != null || AMDUP.GraphicsDevice.CreateGraphicsDevice() != null; + if (_nativePluginLoaded) + return true; + } + catch (System.DllNotFoundException) + { + _nativePluginLoaded = false; + } + } + + return _nativePluginLoaded; + } +#else + public static bool IsSupported => false; + + public override void CreateContext(PostProcessRenderContext context, Upscaling config) + { + } + + public override void Render(PostProcessRenderContext context, Upscaling config) + { + } +#endif + } +} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs.meta new file mode 100644 index 0000000..ad10e5a --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fa0261d6a4df48eb9ccc25d3e1733577 +timeCreated: 1743696182 \ No newline at end of file diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins.meta new file mode 100644 index 0000000..fc071b3 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 45f59c1e6143458abad8c15761a90b67 +timeCreated: 1743695999 \ No newline at end of file diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin.meta new file mode 100644 index 0000000..2b6ba3c --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c4e6018ad3cf328408dfae05cabcde78 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs new file mode 100644 index 0000000..35c95bb --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs @@ -0,0 +1,196 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; +using Unity.Collections.LowLevel.Unsafe; + +namespace UnityEngine.AMD +{ + #region CmdData + + //Flags Verbatim from ffx_fsr.h + [Flags] + public enum FfxFsr2InitializationFlags + { + EnableHighDynamicRange = (1<<0), ///< A bit indicating if the input color data provided is using a high-dynamic range. + EnableDisplayResolutionMotionVectors = (1<<1), ///< A bit indicating if the motion vectors are rendered at display resolution. + EnableMotionVectorsJitterCancellation = (1<<2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them. + DepthInverted = (1<<3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0]. + EnableDepthInfinite = (1<<4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane. + EnableAutoExposure = (1<<5), ///< A bit indicating if automatic exposure should be applied to input color data. + EnableDynamicResolution = (1<<6), ///< A bit indicating that the application uses dynamic resolution scaling. + EnableTexture1DUsage = (1<<7) ///< A bit indicating that the backend should use 1D textures. + } + + //Quality mode verbatim from AMDCommands.h + public enum FSR2Quality + { + Quality = 0, + Balanced, + Performance, + UltraPerformance + } + + [StructLayout(LayoutKind.Sequential)] + public struct FSR2CommandInitializationData + { + //// These properties must match the code in AMDCommands.h in C++ //// + public uint maxRenderSizeWidth; + public uint maxRenderSizeHeight; + public uint displaySizeWidth; + public uint displaySizeHeight; + public FfxFsr2InitializationFlags ffxFsrFlags; + internal uint featureSlot; + //////////////////////////////////////////////////////////////////// + + public void SetFlag(FfxFsr2InitializationFlags flag, bool value) + { + if (value) + { + ffxFsrFlags |= flag; + } + else + { + ffxFsrFlags &= ~flag; + } + } + + public bool GetFlag(FfxFsr2InitializationFlags flag) + { + return (ffxFsrFlags & flag) != 0; + } + } + + public struct FSR2TextureTable + { + public Texture colorInput { set; get; } + public Texture colorOutput { set; get; } + public Texture depth { set; get; } + public Texture motionVectors { set; get; } + public Texture transparencyMask { set; get; } + public Texture exposureTexture { set; get; } + public Texture reactiveMask { set; get; } + public Texture biasColorMask { set; get; } + } + + [StructLayout(LayoutKind.Sequential)] + public struct FSR2CommandExecutionData + { + //// These properties must match the code in AMDCommands.h in C++ //// + internal enum Textures + { + ColorInput = 0, + ColorOutput, + Depth, + MotionVectors, + TransparencyMask, + ExposureTexture, + ReactiveMask, + BiasColorMask, + }; + + public float jitterOffsetX; + public float jitterOffsetY; + public float MVScaleX; + public float MVScaleY; + public uint renderSizeWidth; + public uint renderSizeHeight; + public int enableSharpening; + public float sharpness; + public float frameTimeDelta; + public float preExposure; + public int reset; + public float cameraNear; + public float cameraFar; + public float cameraFovAngleVertical; + internal uint featureSlot; + //////////////////////////////////////////////////////////////////// + } + + #endregion + + #region SerializationHelpers + + internal class NativeData + : IDisposable + where T : struct + { + private IntPtr m_MarshalledValue = IntPtr.Zero; + public T Value = new T(); + public IntPtr Ptr + { + get + { + unsafe { UnsafeUtility.CopyStructureToPtr(ref Value, m_MarshalledValue.ToPointer()); } + return m_MarshalledValue; + } + } + + public NativeData() + { + m_MarshalledValue = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(T))); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (m_MarshalledValue != IntPtr.Zero) + { + Marshal.FreeHGlobal(m_MarshalledValue); + m_MarshalledValue = IntPtr.Zero; + } + } + + ~NativeData() { Dispose(false); } + } + + #endregion + + #region DeviceCommands + + public class FSR2Context + { + private NativeData m_InitData = new NativeData(); + private NativeData m_ExecData = new NativeData(); + + public ref readonly FSR2CommandInitializationData initData { get { return ref m_InitData.Value; } } + public ref FSR2CommandExecutionData executeData { get { return ref m_ExecData.Value; } } + internal uint featureSlot { get { return initData.featureSlot; } } + + internal FSR2Context() + { + } + + internal void Init(FSR2CommandInitializationData initSettings, uint featureSlot) + { + m_InitData.Value = initSettings; + m_InitData.Value.featureSlot = featureSlot; + } + + internal void Reset() + { + m_InitData.Value = new FSR2CommandInitializationData(); + m_ExecData.Value = new FSR2CommandExecutionData(); + } + + internal IntPtr GetInitCmdPtr() + { + return m_InitData.Ptr; + } + + internal IntPtr GetExecuteCmdPtr() + { + m_ExecData.Value.featureSlot = featureSlot; + return m_ExecData.Ptr; + } + } + + #endregion +} // namespace AMD diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs.meta new file mode 100644 index 0000000..c7702ca --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 23265cc55be68924c80218c44d53b34d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs new file mode 100644 index 0000000..26bbda6 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs @@ -0,0 +1,203 @@ +using UnityEngine; +using UnityEngine.Rendering; +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using UnityEditor; + +#if UNITY_EDITOR_64 || UNITY_EDITOR_32 +using UnityEditor.Callbacks; +#endif + +namespace UnityEngine.AMD +{ + // ----------------------------------------------------------------------------------- + // Public Enums must match C++ enums found in AMDDevice.h + // ----------------------------------------------------------------------------------- + #region GraphicsDeviceEnums + internal enum PluginEvent + { + DestroyFeature = 0, + FSR2Execute = 1, + FSR2PostExecute = 2, + FSR2Init = 3 + } + #endregion + + // ----------------------------------------------------------------------------------- + // Main AMD device. Use to interact with AMD specific features on a unity SRP + // ----------------------------------------------------------------------------------- + public class GraphicsDevice + { + #region Private + + static private GraphicsDevice sGraphicsDeviceInstance = null; + private Stack s_ContextObjectPool = new Stack(); + + private GraphicsDevice() + { + } + + private bool Initialize() + { + return AMDUP_InitApi(); + } + + private void Shutdown() + { + AMDUP_ShutdownApi(); + } + + ~GraphicsDevice() + { + Shutdown(); + } + + private void InsertEventCall(CommandBuffer cmd, PluginEvent pluginEvent, IntPtr ptr) + { + cmd.IssuePluginEventAndData(AMDUP_GetRenderEventCallback(), (int)pluginEvent + AMDUP_GetBaseEventId(), ptr); + } + + private static GraphicsDevice InternalCreate() + { + if (sGraphicsDeviceInstance != null) + { + sGraphicsDeviceInstance.Shutdown(); + sGraphicsDeviceInstance.Initialize(); + return sGraphicsDeviceInstance; + } + + var newGraphicsDevice = new GraphicsDevice(); + if (newGraphicsDevice.Initialize()) + { + sGraphicsDeviceInstance = newGraphicsDevice; + return newGraphicsDevice; + } + + Debug.LogWarning("Unity has an invalid api for dvice. Init failed["); + return null; + } + + private static int CreateSetTextureUserData(int featureId, int textureSlot, bool clearTextureTable) + { + int featureIdMask = (featureId & 0xffff); //16 bits + int textureSlotMask = (textureSlot & 0x7fff); //15 bits; + int clearTableMask = clearTextureTable ? 0x1 : 0x0; //1 bit + return (featureIdMask << 16) | (textureSlotMask << 1) | clearTableMask; + } + + private void SetTexture(CommandBuffer cmd, FSR2Context fsr2Context, FSR2CommandExecutionData.Textures textureSlot, Texture texture, bool clearTextureTable = false) + { + if (texture == null) + return; + + uint userData = (uint)CreateSetTextureUserData((int)fsr2Context.featureSlot, (int)textureSlot, clearTextureTable); + cmd.IssuePluginCustomTextureUpdateV2( + AMDUP_GetSetTextureEventCallback(), texture, userData); + } + + #endregion + + // ----------------------------------------------------------------------------------- + // Public API to interact with AMD Features + // ----------------------------------------------------------------------------------- + #region PublicAPI + + public static GraphicsDevice CreateGraphicsDevice() + { + return GraphicsDevice.InternalCreate(); + } + + public static GraphicsDevice device { get { return sGraphicsDeviceInstance; } } + + public static uint version { get { return AMDUP_GetDeviceVersion();} } + + public FSR2Context CreateFeature(CommandBuffer cmd, in FSR2CommandInitializationData initSettings) + { + FSR2Context fsrContext = null; + if (s_ContextObjectPool.Count == 0) + { + fsrContext = new FSR2Context(); + } + else + { + fsrContext = s_ContextObjectPool.Pop(); + } + + fsrContext.Init(initSettings, AMDUP_CreateFeatureSlot()); + InsertEventCall(cmd, PluginEvent.FSR2Init, fsrContext.GetInitCmdPtr()); + return fsrContext; + } + + public bool GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint displayWidth, uint displayHeight, out uint renderWidth, out uint renderHeight) + { + return AMDUP_GetRenderResolutionFromQualityMode(qualityMode, displayWidth, displayHeight, out renderWidth, out renderHeight); + } + + public float GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode) + { + return AMDUP_GetUpscaleRatioFromQualityMode(qualityMode); + } + + public void DestroyFeature(CommandBuffer cmd, FSR2Context fsrContext) + { + InsertEventCall(cmd, PluginEvent.DestroyFeature, new IntPtr(fsrContext.featureSlot)); + fsrContext.Reset(); + s_ContextObjectPool.Push(fsrContext); + } + + public void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsr2Context, in FSR2TextureTable textures) + { + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.ColorInput, textures.colorInput, true); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.ColorOutput, textures.colorOutput); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.Depth, textures.depth); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.MotionVectors, textures.motionVectors); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.TransparencyMask, textures.transparencyMask); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.ExposureTexture, textures.exposureTexture); + SetTexture(cmd, fsr2Context, FSR2CommandExecutionData.Textures.BiasColorMask, textures.biasColorMask); + InsertEventCall(cmd, PluginEvent.FSR2Execute, fsr2Context.GetExecuteCmdPtr()); + + // D3D12 requires to pump submission into its own thread. + // this is caused by the current implementation of the plugin. + // this function is probably noop in other graphics APIs + InsertEventCall(cmd, PluginEvent.FSR2PostExecute, fsr2Context.GetExecuteCmdPtr()); + } + + #endregion + + // ----------------------------------------------------------------------------------- + // All required imports for the plugin + // ----------------------------------------------------------------------------------- + + #region Imports + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private extern static bool AMDUP_InitApi(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private extern static void AMDUP_ShutdownApi(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern uint AMDUP_GetDeviceVersion(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern IntPtr AMDUP_GetRenderEventCallback(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern IntPtr AMDUP_GetSetTextureEventCallback(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern uint AMDUP_CreateFeatureSlot(); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern bool AMDUP_GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint displayWidth, uint displayHeight, out uint renderWidth, out uint renderHeight); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern float AMDUP_GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode); + + [DllImport("AMDUnityPlugin", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] + private static extern int AMDUP_GetBaseEventId(); + + #endregion + }; +} // namespace AMD diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs.meta new file mode 100644 index 0000000..6c3e700 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f5fa42eb9e67ac94ca302c6778dabb24 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll new file mode 100644 index 0000000..fd7b59c --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:113848ace60157ccf832a1d6fe571a79eca6707d3ce951f204196db4dbd6a1b2 +size 2621440 diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll.meta new file mode 100644 index 0000000..0abf1ec --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll.meta @@ -0,0 +1,76 @@ +fileFormatVersion: 2 +guid: ff68a9be371cf104a8439d3166853ebe +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude GameCoreScarlett: 1 + Exclude GameCoreXboxOne: 1 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude PS4: 1 + Exclude PS5: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 0 + - first: + Android: Android + second: + enabled: 0 + settings: + AndroidSharedLibraryType: Executable + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb new file mode 100644 index 0000000..bc40890 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d1f9c9450b5fdebda10bf80187eeeb697efc45c486f59143dcec78f1fbc7325 +size 5001216 diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb.meta new file mode 100644 index 0000000..715e8ac --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8b07f539cd492b64d9bb8de42fd35b63 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll new file mode 100644 index 0000000..ee64d75 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5672ee4202aa5417e23369d548a140652367494299a7678b42aa5b3395f76ad7 +size 6647504 diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll.meta new file mode 100644 index 0000000..4343a03 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll.meta @@ -0,0 +1,76 @@ +fileFormatVersion: 2 +guid: 237ed550266b8db48ae9926cfe33d562 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude GameCoreScarlett: 1 + Exclude GameCoreXboxOne: 1 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude PS4: 1 + Exclude PS5: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 0 + - first: + Android: Android + second: + enabled: 0 + settings: + AndroidSharedLibraryType: Executable + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll new file mode 100644 index 0000000..5133485 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04a455bb7c01af1adc630f3be41bd85689b6a8565199e25b09696240750f6d1e +size 9284304 diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll.meta new file mode 100644 index 0000000..13563bc --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll.meta @@ -0,0 +1,76 @@ +fileFormatVersion: 2 +guid: 08f72ba69ea07724caabdc1487385a97 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude GameCoreScarlett: 1 + Exclude GameCoreXboxOne: 1 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude PS4: 1 + Exclude PS5: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 0 + - first: + Android: Android + second: + enabled: 0 + settings: + AndroidSharedLibraryType: Executable + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs index 496c4ca..6ba7d82 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs @@ -19,6 +19,35 @@ namespace UnityEngine.Rendering.PostProcessing public abstract void Render(PostProcessRenderContext context, Upscaling config); + protected bool PrepareInputs(CommandBuffer cmd, PostProcessRenderContext context, Upscaling config, RenderTexture rwColor = null, RenderTexture rwDepth = null, RenderTexture rwMotionVectors = null) + { + ComputeShader shader = context.resources.computeShaders.prepareInputs; + if (shader == null) + return false; + + Vector2Int scaledRenderSize = config.GetScaledRenderSize(context.camera); + + const int threadGroupWorkRegionDim = 8; + int dispatchSrcX = (scaledRenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; + int dispatchSrcY = (scaledRenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; + + cmd.BeginSample("Prepare Inputs"); + + int kernelIndex = shader.FindKernel("CS"); + cmd.SetComputeTextureParam(shader, kernelIndex, "InColor", context.source, 0, RenderTextureSubElement.Color); + cmd.SetComputeTextureParam(shader, kernelIndex, "InDepth", Upscaling.GetDepthTexture(context.camera), 0, RenderTextureSubElement.Depth); + cmd.SetComputeTextureParam(shader, kernelIndex, "InMotionVectors", BuiltinRenderTextureType.MotionVectors); + + cmd.SetComputeTextureParam(shader, kernelIndex, "OutColor", rwColor != null ? rwColor : BuiltinRenderTextureType.None); + cmd.SetComputeTextureParam(shader, kernelIndex, "OutDepth", rwDepth != null ? rwDepth : BuiltinRenderTextureType.None); + cmd.SetComputeTextureParam(shader, kernelIndex, "OutMotionVectors", rwMotionVectors != null ? rwMotionVectors : BuiltinRenderTextureType.None); + + cmd.DispatchCompute(shader, kernelIndex, dispatchSrcX, dispatchSrcY, 1); + + cmd.EndSample("Prepare Inputs"); + return true; + } + private ConstantsBuffer _reactiveMaskConstants; private RenderTexture _reactiveMask; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs index ef3feaa..80460be 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs @@ -222,6 +222,8 @@ namespace UnityEngine.Rendering.PostProcessing /// public ComputeShader gaussianDownsample; + public ComputeShader prepareInputs; + /// /// The compute shader used by the CAS sharpening filter. /// diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Unity.Postprocessing.Runtime.asmdef b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Unity.Postprocessing.Runtime.asmdef index 8220b4a..95b70a0 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Unity.Postprocessing.Runtime.asmdef +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Unity.Postprocessing.Runtime.asmdef @@ -6,7 +6,7 @@ ], "includePlatforms": [], "excludePlatforms": [], - "allowUnsafeCode": false, + "allowUnsafeCode": true, "overrideReferences": false, "precompiledReferences": [], "autoReferenced": true, diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute new file mode 100644 index 0000000..c1714f6 --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute @@ -0,0 +1,19 @@ +#pragma kernel CS + +Texture2D InColor: register(t0); +Texture2D InDepth: register(t1); +Texture2D InMotionVectors: register(t2); + +RWTexture2D OutColor: register(u0); +RWTexture2D OutDepth: register(u1); +RWTexture2D OutMotionVectors: register(u2); + +[numthreads(8, 8, 1)] +void CS(uint3 dtid : SV_DispatchThreadID) +{ + uint2 InputPos = dtid.xy; + + OutColor[InputPos] = InColor[InputPos]; + OutDepth[InputPos] = InDepth[InputPos]; + OutMotionVectors[InputPos] = InMotionVectors[InputPos]; +} diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute.meta b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute.meta new file mode 100644 index 0000000..301af0c --- /dev/null +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: d27c88814f02b424088b06503e1bc9d5 +ComputeShaderImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: