Browse Source
Generalized the upscaler wrapper into a loose plugin structure, with the wrapper being one particular plugin implementation. Will make it relatively easy to swap in different, custom upscalers.
master
Generalized the upscaler wrapper into a loose plugin structure, with the wrapper being one particular plugin implementation. Will make it relatively easy to swap in different, custom upscalers.
master
5 changed files with 157 additions and 102 deletions
-
8com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers.meta
-
117com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs
-
2com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs.meta
-
130com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs
-
2com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs.meta
@ -0,0 +1,8 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: e69d73c34307b0749b260f667f9f9068 |
||||
|
folderAsset: yes |
||||
|
DefaultImporter: |
||||
|
externalObjects: {} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -0,0 +1,117 @@ |
|||||
|
namespace UnityEngine.Rendering.HighDefinition.AMD |
||||
|
{ |
||||
|
public class FSR2WrapperUpscaler: UpscalerPlugin |
||||
|
{ |
||||
|
public override bool Load() => UnityEngine.AMD.AMDUnityPlugin.Load(); |
||||
|
|
||||
|
public override bool IsLoaded() => UnityEngine.AMD.AMDUnityPlugin.IsLoaded(); |
||||
|
|
||||
|
public override GraphicsDevice CreateGraphicsDevice() => new FSR2WrappedGraphicsDevice(UnityEngine.AMD.GraphicsDevice.CreateGraphicsDevice()); |
||||
|
|
||||
|
public override GraphicsDevice device => new FSR2WrappedGraphicsDevice(UnityEngine.AMD.GraphicsDevice.device); |
||||
|
|
||||
|
public override uint version => UnityEngine.AMD.GraphicsDevice.version; |
||||
|
} |
||||
|
|
||||
|
public class FSR2WrappedGraphicsDevice: GraphicsDevice |
||||
|
{ |
||||
|
private readonly UnityEngine.AMD.GraphicsDevice _wrappedDevice; |
||||
|
|
||||
|
internal FSR2WrappedGraphicsDevice(UnityEngine.AMD.GraphicsDevice wrappedDevice) |
||||
|
{ |
||||
|
_wrappedDevice = wrappedDevice; |
||||
|
} |
||||
|
|
||||
|
public override FSR2Context CreateFeature(CommandBuffer cmd, in FSR2CommandInitializationData initSettings) |
||||
|
{ |
||||
|
var wrappedInitSettings = initSettings.ToWrapped(); |
||||
|
return new FSR2WrappedContext(_wrappedDevice.CreateFeature(cmd, in wrappedInitSettings)); |
||||
|
} |
||||
|
|
||||
|
public override void DestroyFeature(CommandBuffer cmd, FSR2Context fsrContext) |
||||
|
{ |
||||
|
_wrappedDevice.DestroyFeature(cmd, ((FSR2WrappedContext)fsrContext).WrappedContext); |
||||
|
} |
||||
|
|
||||
|
public override void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsr2Context, in FSR2TextureTable textures) |
||||
|
{ |
||||
|
((FSR2WrappedContext)fsr2Context).SyncExecuteData(); |
||||
|
var wrappedTextures = textures.ToWrapped(); |
||||
|
_wrappedDevice.ExecuteFSR2(cmd, ((FSR2WrappedContext)fsr2Context).WrappedContext, in wrappedTextures); |
||||
|
} |
||||
|
|
||||
|
public override 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 override float GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode) |
||||
|
{ |
||||
|
return _wrappedDevice.GetUpscaleRatioFromQualityMode((UnityEngine.AMD.FSR2Quality)(qualityMode - 2)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class FSR2WrappedContext : FSR2Context |
||||
|
{ |
||||
|
internal readonly UnityEngine.AMD.FSR2Context WrappedContext; |
||||
|
|
||||
|
private FSR2CommandInitializationData _initData; |
||||
|
public override ref FSR2CommandInitializationData initData => ref _initData; |
||||
|
|
||||
|
private FSR2CommandExecutionData _executeData; |
||||
|
public override ref FSR2CommandExecutionData executeData => ref _executeData; |
||||
|
|
||||
|
internal FSR2WrappedContext(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; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
internal static class FSR2WrapperExtensions |
||||
|
{ |
||||
|
public static UnityEngine.AMD.FSR2CommandInitializationData ToWrapped(this FSR2CommandInitializationData data) |
||||
|
{ |
||||
|
return new UnityEngine.AMD.FSR2CommandInitializationData |
||||
|
{ |
||||
|
displaySizeHeight = data.displaySizeHeight, |
||||
|
displaySizeWidth = data.displaySizeWidth, |
||||
|
ffxFsrFlags = (UnityEngine.AMD.FfxFsr2InitializationFlags)data.ffxFsrFlags, |
||||
|
maxRenderSizeHeight = data.maxRenderSizeHeight, |
||||
|
maxRenderSizeWidth = data.maxRenderSizeWidth, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
public static UnityEngine.AMD.FSR2TextureTable ToWrapped(this FSR2TextureTable table) |
||||
|
{ |
||||
|
return new UnityEngine.AMD.FSR2TextureTable |
||||
|
{ |
||||
|
biasColorMask = table.biasColorMask, |
||||
|
colorInput = table.colorInput, |
||||
|
colorOutput = table.colorOutput, |
||||
|
depth = table.depth, |
||||
|
exposureTexture = table.exposureTexture, |
||||
|
motionVectors = table.motionVectors, |
||||
|
reactiveMask = table.reactiveMask, |
||||
|
transparencyMask = table.transparencyMask, |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,2 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 72921e6a2e947eb43b60b785190094df |
||||
@ -0,0 +1,2 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 0728e601dda206546abc96b4076abf0a |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue