Browse Source
Created a simple wrapper around the native FSR2 plugin, by making use of namespace priority rules and the fact that FSR2Pass doesn't directly reference the absolute namespace of the original plugin code.
master
Created a simple wrapper around the native FSR2 plugin, by making use of namespace priority rules and the fact that FSR2Pass doesn't directly reference the absolute namespace of the original plugin code.
master
1 changed files with 208 additions and 0 deletions
@ -0,0 +1,208 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace UnityEngine.Rendering.HighDefinition.AMD |
||||
|
{ |
||||
|
public static class AMDUnityPlugin |
||||
|
{ |
||||
|
public static bool Load() => UnityEngine.AMD.AMDUnityPlugin.Load(); |
||||
|
|
||||
|
public static bool IsLoaded() => UnityEngine.AMD.AMDUnityPlugin.IsLoaded(); |
||||
|
} |
||||
|
|
||||
|
public class GraphicsDevice |
||||
|
{ |
||||
|
private readonly UnityEngine.AMD.GraphicsDevice _wrappedDevice; |
||||
|
|
||||
|
public static GraphicsDevice device => new(UnityEngine.AMD.GraphicsDevice.device); |
||||
|
|
||||
|
public static uint version => UnityEngine.AMD.GraphicsDevice.version; |
||||
|
|
||||
|
private GraphicsDevice(UnityEngine.AMD.GraphicsDevice wrappedDevice) |
||||
|
{ |
||||
|
_wrappedDevice = wrappedDevice; |
||||
|
} |
||||
|
|
||||
|
public static GraphicsDevice CreateGraphicsDevice() |
||||
|
{ |
||||
|
return new GraphicsDevice(UnityEngine.AMD.GraphicsDevice.CreateGraphicsDevice()); |
||||
|
} |
||||
|
|
||||
|
public FSR2Context CreateFeature(CommandBuffer cmd, in FSR2CommandInitializationData initSettings) |
||||
|
{ |
||||
|
var wrappedInitSettings = initSettings.ToWrapped(); |
||||
|
return new FSR2Context(_wrappedDevice.CreateFeature(cmd, in wrappedInitSettings)); |
||||
|
} |
||||
|
|
||||
|
public void DestroyFeature(CommandBuffer cmd, FSR2Context fsrContext) |
||||
|
{ |
||||
|
_wrappedDevice.DestroyFeature(cmd, fsrContext.WrappedContext); |
||||
|
} |
||||
|
|
||||
|
public void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsr2Context, in FSR2TextureTable textures) |
||||
|
{ |
||||
|
fsr2Context.SyncExecuteData(); |
||||
|
var wrappedTextures = textures.ToWrapped(); |
||||
|
_wrappedDevice.ExecuteFSR2(cmd, fsr2Context.WrappedContext, in wrappedTextures); |
||||
|
} |
||||
|
|
||||
|
public bool GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint displayWidth, uint displayHeight, out uint renderWidth, out uint renderHeight) |
||||
|
{ |
||||
|
return _wrappedDevice.GetRenderResolutionFromQualityMode((UnityEngine.AMD.FSR2Quality)(qualityMode - 2), displayWidth, displayHeight, out renderWidth, out renderHeight); |
||||
|
} |
||||
|
|
||||
|
public float GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode) |
||||
|
{ |
||||
|
return _wrappedDevice.GetUpscaleRatioFromQualityMode((UnityEngine.AMD.FSR2Quality)(qualityMode - 2)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class FSR2Context |
||||
|
{ |
||||
|
internal readonly UnityEngine.AMD.FSR2Context WrappedContext; |
||||
|
|
||||
|
private FSR2CommandExecutionData _executeData; |
||||
|
public ref FSR2CommandExecutionData executeData => ref _executeData; |
||||
|
|
||||
|
internal FSR2Context(UnityEngine.AMD.FSR2Context wrappedContext) |
||||
|
{ |
||||
|
WrappedContext = wrappedContext; |
||||
|
} |
||||
|
|
||||
|
internal void SyncExecuteData() |
||||
|
{ |
||||
|
WrappedContext.executeData.jitterOffsetX = _executeData.jitterOffsetX; |
||||
|
WrappedContext.executeData.jitterOffsetY = _executeData.jitterOffsetY; |
||||
|
WrappedContext.executeData.MVScaleX = _executeData.MVScaleX; |
||||
|
WrappedContext.executeData.MVScaleY = _executeData.MVScaleY; |
||||
|
WrappedContext.executeData.renderSizeWidth = _executeData.renderSizeWidth; |
||||
|
WrappedContext.executeData.renderSizeHeight = _executeData.renderSizeHeight; |
||||
|
WrappedContext.executeData.enableSharpening = _executeData.enableSharpening; |
||||
|
WrappedContext.executeData.sharpness = _executeData.sharpness; |
||||
|
WrappedContext.executeData.frameTimeDelta = _executeData.frameTimeDelta; |
||||
|
WrappedContext.executeData.preExposure = _executeData.preExposure; |
||||
|
WrappedContext.executeData.reset = _executeData.reset; |
||||
|
WrappedContext.executeData.cameraNear = _executeData.cameraNear; |
||||
|
WrappedContext.executeData.cameraFar = _executeData.cameraFar; |
||||
|
WrappedContext.executeData.cameraFovAngleVertical = _executeData.cameraFovAngleVertical; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public struct FSR2CommandInitializationData |
||||
|
{ |
||||
|
public uint displaySizeHeight; |
||||
|
|
||||
|
public uint displaySizeWidth; |
||||
|
|
||||
|
public FfxFsr2InitializationFlags ffxFsrFlags; |
||||
|
|
||||
|
public uint maxRenderSizeHeight; |
||||
|
|
||||
|
public uint maxRenderSizeWidth; |
||||
|
|
||||
|
public bool GetFlag(FfxFsr2InitializationFlags flag) |
||||
|
{ |
||||
|
return (ffxFsrFlags & flag) == flag; |
||||
|
} |
||||
|
|
||||
|
public void SetFlag(FfxFsr2InitializationFlags flag, bool value) |
||||
|
{ |
||||
|
if (value) |
||||
|
ffxFsrFlags |= flag; |
||||
|
else |
||||
|
ffxFsrFlags &= ~flag; |
||||
|
} |
||||
|
|
||||
|
internal readonly UnityEngine.AMD.FSR2CommandInitializationData ToWrapped() |
||||
|
{ |
||||
|
return new UnityEngine.AMD.FSR2CommandInitializationData |
||||
|
{ |
||||
|
displaySizeHeight = displaySizeHeight, |
||||
|
displaySizeWidth = displaySizeWidth, |
||||
|
ffxFsrFlags = (UnityEngine.AMD.FfxFsr2InitializationFlags)ffxFsrFlags, |
||||
|
maxRenderSizeHeight = maxRenderSizeHeight, |
||||
|
maxRenderSizeWidth = maxRenderSizeWidth, |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Flags] |
||||
|
public enum FfxFsr2InitializationFlags |
||||
|
{ |
||||
|
EnableHighDynamicRange = 1, |
||||
|
EnableDisplayResolutionMotionVectors = 2, |
||||
|
EnableMotionVectorsJitterCancellation = 4, |
||||
|
DepthInverted = 8, |
||||
|
EnableDepthInfinite = 16, // 0x00000010
|
||||
|
EnableAutoExposure = 32, // 0x00000020
|
||||
|
EnableDynamicResolution = 64, // 0x00000040
|
||||
|
EnableTexture1DUsage = 128, // 0x00000080
|
||||
|
} |
||||
|
|
||||
|
public struct FSR2TextureTable |
||||
|
{ |
||||
|
public Texture biasColorMask; |
||||
|
public Texture colorInput; |
||||
|
public Texture colorOutput; |
||||
|
public Texture depth; |
||||
|
public Texture exposureTexture; |
||||
|
public Texture motionVectors; |
||||
|
public Texture reactiveMask; |
||||
|
public Texture transparencyMask; |
||||
|
|
||||
|
internal readonly UnityEngine.AMD.FSR2TextureTable ToWrapped() |
||||
|
{ |
||||
|
return new UnityEngine.AMD.FSR2TextureTable |
||||
|
{ |
||||
|
biasColorMask = biasColorMask, |
||||
|
colorInput = colorInput, |
||||
|
colorOutput = colorOutput, |
||||
|
depth = depth, |
||||
|
exposureTexture = exposureTexture, |
||||
|
motionVectors = motionVectors, |
||||
|
reactiveMask = reactiveMask, |
||||
|
transparencyMask = transparencyMask, |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public enum FSR2Quality |
||||
|
{ |
||||
|
NativeAA, |
||||
|
UltraQuality, |
||||
|
Quality, |
||||
|
Balanced, |
||||
|
Performance, |
||||
|
UltraPerformance, |
||||
|
} |
||||
|
|
||||
|
public struct FSR2CommandExecutionData |
||||
|
{ |
||||
|
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; |
||||
|
|
||||
|
internal enum Textures |
||||
|
{ |
||||
|
ColorInput, |
||||
|
ColorOutput, |
||||
|
Depth, |
||||
|
MotionVectors, |
||||
|
TransparencyMask, |
||||
|
ExposureTexture, |
||||
|
ReactiveMask, |
||||
|
BiasColorMask, |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue