diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs index aec822fa..db35fd5a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR2WrapperUpscaler.cs @@ -1,6 +1,6 @@ using System; -namespace UnityEngine.Rendering.HighDefinition.AMD +namespace UnityEngine.Rendering.HighDefinition.AMD.FSR2Wrapper { public class FSR2WrapperUpscaler: UpscalerPlugin { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs new file mode 100644 index 00000000..58341a82 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs @@ -0,0 +1,107 @@ +using System.Collections.Generic; + +namespace UnityEngine.Rendering.HighDefinition.AMD.FSR3 +{ + public class FSR3Upscaler: UpscalerPlugin + { + private static FSR3GraphicsDevice sGraphicsDeviceInstance; + + public override bool Load() => true; + + public override bool IsLoaded() => true; + + public override GraphicsDevice CreateGraphicsDevice() + { + if (sGraphicsDeviceInstance != null) + { + sGraphicsDeviceInstance.Shutdown(); + sGraphicsDeviceInstance.Initialize(); + return sGraphicsDeviceInstance; + } + + var graphicsDevice = new FSR3GraphicsDevice(); + if (graphicsDevice.Initialize()) + { + sGraphicsDeviceInstance = graphicsDevice; + return graphicsDevice; + } + + Debug.LogWarning("Failed to initialize FSR3 Graphics Device"); + return null; + } + + public override GraphicsDevice device => sGraphicsDeviceInstance; + } + + public class FSR3GraphicsDevice : GraphicsDevice + { + private static readonly Stack sContextPool = new(); + + internal bool Initialize() + { + // TODO + return false; + } + + internal void Shutdown() + { + // TODO + } + + public override FSR2Context CreateFeature(CommandBuffer cmd, in FSR2CommandInitializationData initSettings) + { + var context = sContextPool.Count != 0 ? sContextPool.Pop() : new FSR3Context(); + context.Init(initSettings); // TODO might need some way to distinguish between contexts (see featureSlot) + return context; + } + + public override void DestroyFeature(CommandBuffer cmd, FSR2Context fsrContext) + { + var context = (FSR3Context)fsrContext; + context.Reset(); + sContextPool.Push(context); + } + + public override void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsrContext, in FSR2TextureTable textures) + { + ((FSR3Context)fsrContext).Draw(cmd, in textures); + } + + public override bool GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint displayWidth, uint displayHeight, out uint renderWidth, out uint renderHeight) + { + throw new System.NotImplementedException(); + } + + public override float GetUpscaleRatioFromQualityMode(FSR2Quality qualityMode) + { + throw new System.NotImplementedException(); + } + } + + public class FSR3Context : FSR2Context + { + private FSR2CommandInitializationData _initData; + public override ref FSR2CommandInitializationData initData => ref _initData; + + private FSR2CommandExecutionData _executeData; + public override ref FSR2CommandExecutionData executeData => ref _executeData; + + internal void Init(in FSR2CommandInitializationData initSettings) + { + // TODO: create internal context data + _initData = initSettings; + } + + internal void Reset() + { + // TODO: destroy internal context data + _initData = new FSR2CommandInitializationData(); + _executeData = new FSR2CommandExecutionData(); + } + + internal void Draw(CommandBuffer cmd, in FSR2TextureTable textures) + { + + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs.meta new file mode 100644 index 00000000..2370edcb --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/FSR3Upscaler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 2bc3842c136ac0b4f8e140ea29ad7761 \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs index 00afaf8b..5d0bc15f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/Upscalers/UpscalerPlugin.cs @@ -4,7 +4,8 @@ namespace UnityEngine.Rendering.HighDefinition.AMD { public static class AMDUnityPlugin { - internal static readonly UpscalerPlugin ActivePlugin = new FSR2WrapperUpscaler(); + // TODO: allow dynamic switching between plugins (including shutdown of previous plugin) + internal static readonly UpscalerPlugin ActivePlugin = new FSR2Wrapper.FSR2WrapperUpscaler(); public static bool Load() => ActivePlugin.Load(); @@ -20,8 +21,8 @@ namespace UnityEngine.Rendering.HighDefinition.AMD public abstract GraphicsDevice CreateGraphicsDevice(); public abstract GraphicsDevice device { get; } - - public abstract uint version { get; } + + public virtual uint version => 0x00; } public abstract class GraphicsDevice @@ -39,7 +40,7 @@ namespace UnityEngine.Rendering.HighDefinition.AMD public abstract void DestroyFeature(CommandBuffer cmd, FSR2Context fsrContext); - public abstract void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsr2Context, in FSR2TextureTable textures); + public abstract void ExecuteFSR2(CommandBuffer cmd, FSR2Context fsrContext, in FSR2TextureTable textures); public abstract bool GetRenderResolutionFromQualityMode(FSR2Quality qualityMode, uint displayWidth, uint displayHeight, out uint renderWidth, out uint renderHeight);