23 changed files with 918 additions and 1 deletions
-
1Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset
-
1Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling.cs
-
176Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs
-
3Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/FSR3NativeUpscaler.cs.meta
-
3Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins.meta
-
8Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin.meta
-
196Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs
-
11Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDCommands.cs.meta
-
203Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs
-
11Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDDevice.cs.meta
-
BINPackages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll
-
76Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.dll.meta
-
BINPackages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb
-
7Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/AMDUnityPlugin.pdb.meta
-
BINPackages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll
-
76Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_dx12.dll.meta
-
BINPackages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll
-
76Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Plugins/AMDUnityPlugin/amd_fidelityfx_vk.dll.meta
-
29Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/Upscaler.cs
-
2Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs
-
2Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Unity.Postprocessing.Runtime.asmdef
-
19Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute
-
7Packages/com.unity.postprocessing@3.2.2/PostProcessing/Shaders/Builtins/PrepareInputs.compute.meta
@ -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
|
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
fileFormatVersion: 2 |
|||
guid: fa0261d6a4df48eb9ccc25d3e1733577 |
|||
timeCreated: 1743696182 |
|||
@ -0,0 +1,3 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 45f59c1e6143458abad8c15761a90b67 |
|||
timeCreated: 1743695999 |
|||
@ -0,0 +1,8 @@ |
|||
fileFormatVersion: 2 |
|||
guid: c4e6018ad3cf328408dfae05cabcde78 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -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<T> |
|||
: 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<FSR2CommandInitializationData> m_InitData = new NativeData<FSR2CommandInitializationData>(); |
|||
private NativeData<FSR2CommandExecutionData> m_ExecData = new NativeData<FSR2CommandExecutionData>(); |
|||
|
|||
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
|
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 23265cc55be68924c80218c44d53b34d |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -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<FSR2Context> s_ContextObjectPool = new Stack<FSR2Context>(); |
|||
|
|||
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
|
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: f5fa42eb9e67ac94ca302c6778dabb24 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
size 2621440 |
@ -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: |
|||
size 5001216 |
@ -0,0 +1,7 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 8b07f539cd492b64d9bb8de42fd35b63 |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
size 6647504 |
@ -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: |
|||
size 9284304 |
@ -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: |
|||
@ -0,0 +1,19 @@ |
|||
#pragma kernel CS |
|||
|
|||
Texture2D InColor: register(t0); |
|||
Texture2D<float> InDepth: register(t1); |
|||
Texture2D<float2> InMotionVectors: register(t2); |
|||
|
|||
RWTexture2D<float4> OutColor: register(u0); |
|||
RWTexture2D<float> OutDepth: register(u1); |
|||
RWTexture2D<float2> 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]; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
fileFormatVersion: 2 |
|||
guid: d27c88814f02b424088b06503e1bc9d5 |
|||
ComputeShaderImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue