From 9854cd12794c60bc2bcdaf039d82257e902d259a Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 15 Dec 2023 16:37:21 +0100 Subject: [PATCH] Rename FSR2 to FSR3 Upscaler, part 2: class and file names. --- .../{Fsr2ShaderIDs.cs => Fsr3ShaderIDs.cs} | 2 +- ...haderIDs.cs.meta => Fsr3ShaderIDs.cs.meta} | 0 .../Scripts/Core/{Fsr2.cs => Fsr3Upscaler.cs} | 8 +- .../{Fsr2.cs.meta => Fsr3Upscaler.cs.meta} | 0 ...2Callbacks.cs => Fsr3UpscalerCallbacks.cs} | 16 +- ....cs.meta => Fsr3UpscalerCallbacks.cs.meta} | 0 ...{Fsr2Context.cs => Fsr3UpscalerContext.cs} | 188 +++++++-------- ...xt.cs.meta => Fsr3UpscalerContext.cs.meta} | 0 .../Core/{Fsr2Pass.cs => Fsr3UpscalerPass.cs} | 216 +++++++++--------- ...2Pass.cs.meta => Fsr3UpscalerPass.cs.meta} | 0 ...2Resources.cs => Fsr3UpscalerResources.cs} | 34 +-- ....cs.meta => Fsr3UpscalerResources.cs.meta} | 0 Assets/Scripts/Debug/DebugDumper.cs | 8 +- ...aHelper.cs => Fsr3UpscalerCameraHelper.cs} | 10 +- ....meta => Fsr3UpscalerCameraHelper.cs.meta} | 0 ...geEffect.cs => Fsr3UpscalerImageEffect.cs} | 84 +++---- ...s.meta => Fsr3UpscalerImageEffect.cs.meta} | 0 ...er.cs => Fsr3UpscalerImageEffectHelper.cs} | 10 +- ... => Fsr3UpscalerImageEffectHelper.cs.meta} | 0 19 files changed, 282 insertions(+), 294 deletions(-) rename Assets/Scripts/Core/{Fsr2ShaderIDs.cs => Fsr3ShaderIDs.cs} (99%) rename Assets/Scripts/Core/{Fsr2ShaderIDs.cs.meta => Fsr3ShaderIDs.cs.meta} (100%) rename Assets/Scripts/Core/{Fsr2.cs => Fsr3Upscaler.cs} (97%) rename Assets/Scripts/Core/{Fsr2.cs.meta => Fsr3Upscaler.cs.meta} (100%) rename Assets/Scripts/Core/{Fsr2Callbacks.cs => Fsr3UpscalerCallbacks.cs} (90%) rename Assets/Scripts/Core/{Fsr2Callbacks.cs.meta => Fsr3UpscalerCallbacks.cs.meta} (100%) rename Assets/Scripts/Core/{Fsr2Context.cs => Fsr3UpscalerContext.cs} (74%) rename Assets/Scripts/Core/{Fsr2Context.cs.meta => Fsr3UpscalerContext.cs.meta} (100%) rename Assets/Scripts/Core/{Fsr2Pass.cs => Fsr3UpscalerPass.cs} (63%) rename Assets/Scripts/Core/{Fsr2Pass.cs.meta => Fsr3UpscalerPass.cs.meta} (100%) rename Assets/Scripts/Core/{Fsr2Resources.cs => Fsr3UpscalerResources.cs} (93%) rename Assets/Scripts/Core/{Fsr2Resources.cs.meta => Fsr3UpscalerResources.cs.meta} (100%) rename Assets/Scripts/{Fsr2CameraHelper.cs => Fsr3UpscalerCameraHelper.cs} (91%) rename Assets/Scripts/{Fsr2CameraHelper.cs.meta => Fsr3UpscalerCameraHelper.cs.meta} (100%) rename Assets/Scripts/{Fsr2ImageEffect.cs => Fsr3UpscalerImageEffect.cs} (83%) rename Assets/Scripts/{Fsr2ImageEffect.cs.meta => Fsr3UpscalerImageEffect.cs.meta} (100%) rename Assets/Scripts/{Fsr2ImageEffectHelper.cs => Fsr3UpscalerImageEffectHelper.cs} (87%) rename Assets/Scripts/{Fsr2ImageEffectHelper.cs.meta => Fsr3UpscalerImageEffectHelper.cs.meta} (100%) diff --git a/Assets/Scripts/Core/Fsr2ShaderIDs.cs b/Assets/Scripts/Core/Fsr3ShaderIDs.cs similarity index 99% rename from Assets/Scripts/Core/Fsr2ShaderIDs.cs rename to Assets/Scripts/Core/Fsr3ShaderIDs.cs index 52a80fe..3a28843 100644 --- a/Assets/Scripts/Core/Fsr2ShaderIDs.cs +++ b/Assets/Scripts/Core/Fsr3ShaderIDs.cs @@ -22,7 +22,7 @@ using UnityEngine; namespace FidelityFX { - internal static class Fsr2ShaderIDs + internal static class Fsr3ShaderIDs { // Shader resource views, i.e. read-only bindings internal static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered"); diff --git a/Assets/Scripts/Core/Fsr2ShaderIDs.cs.meta b/Assets/Scripts/Core/Fsr3ShaderIDs.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2ShaderIDs.cs.meta rename to Assets/Scripts/Core/Fsr3ShaderIDs.cs.meta diff --git a/Assets/Scripts/Core/Fsr2.cs b/Assets/Scripts/Core/Fsr3Upscaler.cs similarity index 97% rename from Assets/Scripts/Core/Fsr2.cs rename to Assets/Scripts/Core/Fsr3Upscaler.cs index 7822067..ef35ad1 100644 --- a/Assets/Scripts/Core/Fsr2.cs +++ b/Assets/Scripts/Core/Fsr3Upscaler.cs @@ -28,12 +28,12 @@ namespace FidelityFX /// /// A collection of helper functions and data structures required by the FSR3 Upscaler process. /// - public static class Fsr2 + public static class Fsr3Upscaler { /// /// Creates a new FSR3 Upscaler context with standard parameters that are appropriate for the current platform. /// - public static Fsr2Context CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, IFsr2Callbacks callbacks, InitializationFlags flags = 0) + public static Fsr3UpscalerContext CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, IFsr3UpscalerCallbacks callbacks, InitializationFlags flags = 0) { if (SystemInfo.usesReversedZBuffer) flags |= InitializationFlags.EnableDepthInverted; @@ -54,7 +54,7 @@ namespace FidelityFX Callbacks = callbacks, }; - var context = new Fsr2Context(); + var context = new Fsr3UpscalerContext(); context.Create(contextDescription); return context; } @@ -163,7 +163,7 @@ namespace FidelityFX public InitializationFlags Flags; public Vector2Int MaxRenderSize; public Vector2Int DisplaySize; - public IFsr2Callbacks Callbacks; + public IFsr3UpscalerCallbacks Callbacks; } /// diff --git a/Assets/Scripts/Core/Fsr2.cs.meta b/Assets/Scripts/Core/Fsr3Upscaler.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2.cs.meta rename to Assets/Scripts/Core/Fsr3Upscaler.cs.meta diff --git a/Assets/Scripts/Core/Fsr2Callbacks.cs b/Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs similarity index 90% rename from Assets/Scripts/Core/Fsr2Callbacks.cs rename to Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs index 31014b0..075579c 100644 --- a/Assets/Scripts/Core/Fsr2Callbacks.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs @@ -26,10 +26,8 @@ namespace FidelityFX /// A collection of callbacks required by the FSR3 Upscaler process. /// This allows some customization by the game dev on how to integrate FSR3 upscaling into their own game setup. /// - public interface IFsr2Callbacks + public interface IFsr3UpscalerCallbacks { - Shader LoadShader(string name); - void UnloadShader(Shader shader); ComputeShader LoadComputeShader(string name); void UnloadComputeShader(ComputeShader shader); @@ -50,19 +48,9 @@ namespace FidelityFX /// Default implementation of IFsr2Callbacks using simple Resources calls. /// These are fine for testing but a proper game will want to extend and override these methods. /// - public class Fsr2CallbacksBase: IFsr2Callbacks + public class Fsr3UpscalerCallbacksBase: IFsr3UpscalerCallbacks { protected float CurrentBiasOffset = 0; - - public virtual Shader LoadShader(string name) - { - return Resources.Load(name); - } - - public virtual void UnloadShader(Shader shader) - { - Resources.UnloadAsset(shader); - } public virtual ComputeShader LoadComputeShader(string name) { diff --git a/Assets/Scripts/Core/Fsr2Callbacks.cs.meta b/Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2Callbacks.cs.meta rename to Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs.meta diff --git a/Assets/Scripts/Core/Fsr2Context.cs b/Assets/Scripts/Core/Fsr3UpscalerContext.cs similarity index 74% rename from Assets/Scripts/Core/Fsr2Context.cs rename to Assets/Scripts/Core/Fsr3UpscalerContext.cs index 6738633..f2285f4 100644 --- a/Assets/Scripts/Core/Fsr2Context.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerContext.cs @@ -26,63 +26,63 @@ using UnityEngine.Rendering; namespace FidelityFX { /// - /// This class loosely matches the FfxFsr2Context struct from the original FSR3 Upscaler codebase. + /// This class loosely matches the FfxFsr3UpscalerContext struct from the original FSR3 codebase. /// It manages the various resources and compute passes required by the FSR3 Upscaler process. /// Note that this class does not know anything about Unity render pipelines; all it knows is CommandBuffers and RenderTargetIdentifiers. /// This should make it suitable for integration with any of the available Unity render pipelines. /// - public class Fsr2Context + public class Fsr3UpscalerContext { private const int MaxQueuedFrames = 16; - private Fsr2.ContextDescription _contextDescription; + private Fsr3Upscaler.ContextDescription _contextDescription; private CommandBuffer _commandBuffer; - private Fsr2Pass _depthClipPass; - private Fsr2Pass _reconstructPreviousDepthPass; - private Fsr2Pass _lockPass; - private Fsr2Pass _accumulatePass; - private Fsr2Pass _rcasPass; - private Fsr2Pass _computeLuminancePyramidPass; - private Fsr2Pass _generateReactivePass; - private Fsr2Pass _tcrAutogeneratePass; + private Fsr3UpscalerPass _depthClipPass; + private Fsr3UpscalerPass _reconstructPreviousDepthPass; + private Fsr3UpscalerPass _lockPass; + private Fsr3UpscalerPass _accumulatePass; + private Fsr3UpscalerPass _rcasPass; + private Fsr3UpscalerPass _computeLuminancePyramidPass; + private Fsr3UpscalerPass _generateReactivePass; + private Fsr3UpscalerPass _tcrAutogeneratePass; - private readonly Fsr2Resources _resources = new Fsr2Resources(); + private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); private ComputeBuffer _fsr2ConstantsBuffer; - private readonly Fsr2.Fsr2Constants[] _fsr2ConstantsArray = { new Fsr2.Fsr2Constants() }; - private ref Fsr2.Fsr2Constants Constants => ref _fsr2ConstantsArray[0]; + private readonly Fsr3Upscaler.Fsr2Constants[] _fsr2ConstantsArray = { new Fsr3Upscaler.Fsr2Constants() }; + private ref Fsr3Upscaler.Fsr2Constants Constants => ref _fsr2ConstantsArray[0]; private ComputeBuffer _spdConstantsBuffer; - private readonly Fsr2.SpdConstants[] _spdConstantsArray = { new Fsr2.SpdConstants() }; - private ref Fsr2.SpdConstants SpdConsts => ref _spdConstantsArray[0]; + private readonly Fsr3Upscaler.SpdConstants[] _spdConstantsArray = { new Fsr3Upscaler.SpdConstants() }; + private ref Fsr3Upscaler.SpdConstants SpdConsts => ref _spdConstantsArray[0]; private ComputeBuffer _rcasConstantsBuffer; - private readonly Fsr2.RcasConstants[] _rcasConstantsArray = new Fsr2.RcasConstants[1]; - private ref Fsr2.RcasConstants RcasConsts => ref _rcasConstantsArray[0]; + private readonly Fsr3Upscaler.RcasConstants[] _rcasConstantsArray = new Fsr3Upscaler.RcasConstants[1]; + private ref Fsr3Upscaler.RcasConstants RcasConsts => ref _rcasConstantsArray[0]; private ComputeBuffer _generateReactiveConstantsBuffer; - private readonly Fsr2.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Fsr2.GenerateReactiveConstants() }; - private ref Fsr2.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0]; + private readonly Fsr3Upscaler.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Fsr3Upscaler.GenerateReactiveConstants() }; + private ref Fsr3Upscaler.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0]; private ComputeBuffer _tcrAutogenerateConstantsBuffer; - private readonly Fsr2.GenerateReactiveConstants2[] _tcrAutogenerateConstantsArray = { new Fsr2.GenerateReactiveConstants2() }; - private ref Fsr2.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0]; + private readonly Fsr3Upscaler.GenerateReactiveConstants2[] _tcrAutogenerateConstantsArray = { new Fsr3Upscaler.GenerateReactiveConstants2() }; + private ref Fsr3Upscaler.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0]; private bool _firstExecution; private Vector2 _previousJitterOffset; private int _resourceFrameIndex; - public void Create(Fsr2.ContextDescription contextDescription) + public void Create(Fsr3Upscaler.ContextDescription contextDescription) { _contextDescription = contextDescription; _commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" }; - _fsr2ConstantsBuffer = CreateConstantBuffer(); - _spdConstantsBuffer = CreateConstantBuffer(); - _rcasConstantsBuffer = CreateConstantBuffer(); - _generateReactiveConstantsBuffer = CreateConstantBuffer(); - _tcrAutogenerateConstantsBuffer = CreateConstantBuffer(); + _fsr2ConstantsBuffer = CreateConstantBuffer(); + _spdConstantsBuffer = CreateConstantBuffer(); + _rcasConstantsBuffer = CreateConstantBuffer(); + _generateReactiveConstantsBuffer = CreateConstantBuffer(); + _tcrAutogenerateConstantsBuffer = CreateConstantBuffer(); // Set defaults _firstExecution = true; @@ -96,14 +96,14 @@ namespace FidelityFX private void CreatePasses() { - _computeLuminancePyramidPass = new Fsr2ComputeLuminancePyramidPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _spdConstantsBuffer); - _reconstructPreviousDepthPass = new Fsr2ReconstructPreviousDepthPass(_contextDescription, _resources, _fsr2ConstantsBuffer); - _depthClipPass = new Fsr2DepthClipPass(_contextDescription, _resources, _fsr2ConstantsBuffer); - _lockPass = new Fsr2LockPass(_contextDescription, _resources, _fsr2ConstantsBuffer); - _accumulatePass = new Fsr2AccumulatePass(_contextDescription, _resources, _fsr2ConstantsBuffer); - _rcasPass = new Fsr2RcasPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _rcasConstantsBuffer); - _generateReactivePass = new Fsr2GenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); - _tcrAutogeneratePass = new Fsr2TcrAutogeneratePass(_contextDescription, _resources, _fsr2ConstantsBuffer, _tcrAutogenerateConstantsBuffer); + _computeLuminancePyramidPass = new Fsr3UpscalerComputeLuminancePyramidPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _spdConstantsBuffer); + _reconstructPreviousDepthPass = new Fsr3UpscalerReconstructPreviousDepthPass(_contextDescription, _resources, _fsr2ConstantsBuffer); + _depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _fsr2ConstantsBuffer); + _lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _fsr2ConstantsBuffer); + _accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _fsr2ConstantsBuffer); + _rcasPass = new Fsr3UpscalerRcasPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _rcasConstantsBuffer); + _generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); + _tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _fsr2ConstantsBuffer, _tcrAutogenerateConstantsBuffer); } public void Destroy() @@ -129,16 +129,16 @@ namespace FidelityFX _commandBuffer = null; } - public void Dispatch(Fsr2.DispatchDescription dispatchParams) + public void Dispatch(Fsr3Upscaler.DispatchDescription dispatchParams) { _commandBuffer.Clear(); Dispatch(dispatchParams, _commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer); } - public void Dispatch(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer) + public void Dispatch(Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer) { - if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableDebugChecking) != 0) + if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDebugChecking) != 0) { DebugCheckDispatch(dispatchParams); } @@ -156,10 +156,10 @@ namespace FidelityFX _firstExecution = false; // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends - if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) - dispatchParams.Exposure = new Fsr2.ResourceView(_resources.AutoExposure); + if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0) + dispatchParams.Exposure = new Fsr3Upscaler.ResourceView(_resources.AutoExposure); else if (!dispatchParams.Exposure.IsValid) - dispatchParams.Exposure = new Fsr2.ResourceView(_resources.DefaultExposure); + dispatchParams.Exposure = new Fsr3Upscaler.ResourceView(_resources.DefaultExposure); if (dispatchParams.EnableAutoReactive) { @@ -169,7 +169,7 @@ namespace FidelityFX if (resetAccumulation) { - RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr2ShaderIDs.SrvOpaqueOnly; + RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr3ShaderIDs.SrvOpaqueOnly; commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly); } } @@ -179,9 +179,9 @@ namespace FidelityFX _resources.DestroyTcrAutogenResources(); } - if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new Fsr2.ResourceView(_resources.DefaultReactive); - if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.DefaultReactive); - Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); + if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new Fsr3Upscaler.ResourceView(_resources.DefaultReactive); + if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(_resources.DefaultReactive); + Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -214,8 +214,8 @@ namespace FidelityFX } // FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option - bool depthInverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) == Fsr2.InitializationFlags.EnableDepthInverted; - commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); + bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) == Fsr3Upscaler.InitializationFlags.EnableDepthInverted; + commandBuffer.SetRenderTarget(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); // Auto exposure @@ -229,8 +229,8 @@ namespace FidelityFX if (dispatchParams.EnableAutoReactive) { GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); - dispatchParams.Reactive = new Fsr2.ResourceView(_resources.AutoReactive); - dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.AutoComposition); + dispatchParams.Reactive = new Fsr3Upscaler.ResourceView(_resources.AutoReactive); + dispatchParams.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(_resources.AutoComposition); } // Compute luminance pyramid @@ -263,17 +263,17 @@ namespace FidelityFX _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; - Fsr2Resources.DestroyAliasableResources(commandBuffer); + Fsr3UpscalerResources.DestroyAliasableResources(commandBuffer); } - public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams) + public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams) { _commandBuffer.Clear(); GenerateReactiveMask(dispatchParams, _commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer); } - public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) + public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) { const int threadGroupWorkRegionDim = 8; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; @@ -285,10 +285,10 @@ namespace FidelityFX GenReactiveConsts.flags = (uint)dispatchParams.Flags; commandBuffer.SetBufferData(_generateReactiveConstantsBuffer, _generateReactiveConstantsArray); - ((Fsr2GenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY); + ((Fsr3UpscalerGenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY); } - private void GenerateTransparencyCompositionReactive(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex) + private void GenerateTransparencyCompositionReactive(Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex) { const int threadGroupWorkRegionDim = 8; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; @@ -303,9 +303,9 @@ namespace FidelityFX _tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); } - private void SetupConstants(Fsr2.DispatchDescription dispatchParams, bool resetAccumulation) + private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation) { - ref Fsr2.Fsr2Constants constants = ref Constants; + ref Fsr3Upscaler.Fsr2Constants constants = ref Constants; constants.jitterOffset = dispatchParams.JitterOffset; constants.renderSize = dispatchParams.RenderSize; @@ -327,17 +327,17 @@ namespace FidelityFX constants.preExposure = (dispatchParams.PreExposure != 0) ? dispatchParams.PreExposure : 1.0f; // Motion vector data - Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize; + Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize; constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize; // Compute jitter cancellation - if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) + if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) { constants.motionVectorJitterCancellation = (_previousJitterOffset - constants.jitterOffset) / motionVectorsTargetSize; _previousJitterOffset = constants.jitterOffset; } - int jitterPhaseCount = Fsr2.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.DisplaySize.x); + int jitterPhaseCount = Fsr3Upscaler.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.DisplaySize.x); if (resetAccumulation || constants.jitterPhaseCount == 0) { constants.jitterPhaseCount = jitterPhaseCount; @@ -360,17 +360,17 @@ namespace FidelityFX constants.frameIndex++; // Shading change usage of the SPD mip levels - constants.lumaMipLevelToUse = Fsr2Pass.ShadingChangeMipLevel; + constants.lumaMipLevelToUse = Fsr3UpscalerPass.ShadingChangeMipLevel; float mipDiv = 2 << constants.lumaMipLevelToUse; constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv); constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); } - private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr2.DispatchDescription dispatchParams) + private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams) { - bool inverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; - bool infinite = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; + bool inverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0; + bool infinite = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInfinite) != 0; // make sure it has no impact if near and far plane values are swapped in dispatch params // the flags "inverted" and "infinite" will decide what transform to use @@ -400,19 +400,19 @@ namespace FidelityFX 1.0f / cotHalfFovY); } - private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams) + private void SetupRcasConstants(Fsr3Upscaler.DispatchDescription dispatchParams) { int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); RcasConsts = RcasConfigs[sharpnessIndex]; } - private void SetupSpdConstants(Fsr2.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount) + private void SetupSpdConstants(Fsr3Upscaler.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount) { RectInt rectInfo = new RectInt(0, 0, dispatchParams.RenderSize.x, dispatchParams.RenderSize.y); SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips); // Downsample - ref Fsr2.SpdConstants spdConstants = ref SpdConsts; + ref Fsr3Upscaler.SpdConstants spdConstants = ref SpdConsts; spdConstants.numWorkGroups = (uint)numWorkGroupsAndMips.x; spdConstants.mips = (uint)numWorkGroupsAndMips.y; spdConstants.workGroupOffsetX = (uint)workGroupOffset.x; @@ -438,7 +438,7 @@ namespace FidelityFX } } - private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams) + private void DebugCheckDispatch(Fsr3Upscaler.DispatchDescription dispatchParams) { if (!dispatchParams.Color.IsValid) { @@ -460,7 +460,7 @@ namespace FidelityFX Debug.LogError("Output resource is null"); } - if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) + if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0) { Debug.LogWarning("Exposure resource provided, however auto exposure flag is present"); } @@ -500,8 +500,8 @@ namespace FidelityFX Debug.LogError("PreExposure provided as 0.0f which is invalid"); } - bool infiniteDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0; - bool inverseDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0; + bool infiniteDepth = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInfinite) != 0; + bool inverseDepth = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0; if (inverseDepth) { @@ -559,29 +559,29 @@ namespace FidelityFX /// The FSR3 C++ codebase uses floats bitwise converted to ints to pass sharpness parameters to the RCAS shader. /// This is not possible in C# without enabling unsafe code compilation, so to avoid that we instead use a table of precomputed values. /// - private static readonly Fsr2.RcasConstants[] RcasConfigs = new [] + private static readonly Fsr3Upscaler.RcasConstants[] RcasConfigs = new [] { - new Fsr2.RcasConstants(1048576000u, 872428544u), - new Fsr2.RcasConstants(1049178080u, 877212745u), - new Fsr2.RcasConstants(1049823372u, 882390168u), - new Fsr2.RcasConstants(1050514979u, 887895276u), - new Fsr2.RcasConstants(1051256227u, 893859143u), - new Fsr2.RcasConstants(1052050675u, 900216232u), - new Fsr2.RcasConstants(1052902144u, 907032080u), - new Fsr2.RcasConstants(1053814727u, 914306687u), - new Fsr2.RcasConstants(1054792807u, 922105590u), - new Fsr2.RcasConstants(1055841087u, 930494326u), - new Fsr2.RcasConstants(1056964608u, 939538432u), - new Fsr2.RcasConstants(1057566688u, 944322633u), - new Fsr2.RcasConstants(1058211980u, 949500056u), - new Fsr2.RcasConstants(1058903587u, 955005164u), - new Fsr2.RcasConstants(1059644835u, 960969031u), - new Fsr2.RcasConstants(1060439283u, 967326120u), - new Fsr2.RcasConstants(1061290752u, 974141968u), - new Fsr2.RcasConstants(1062203335u, 981416575u), - new Fsr2.RcasConstants(1063181415u, 989215478u), - new Fsr2.RcasConstants(1064229695u, 997604214u), - new Fsr2.RcasConstants(1065353216u, 1006648320), + new Fsr3Upscaler.RcasConstants(1048576000u, 872428544u), + new Fsr3Upscaler.RcasConstants(1049178080u, 877212745u), + new Fsr3Upscaler.RcasConstants(1049823372u, 882390168u), + new Fsr3Upscaler.RcasConstants(1050514979u, 887895276u), + new Fsr3Upscaler.RcasConstants(1051256227u, 893859143u), + new Fsr3Upscaler.RcasConstants(1052050675u, 900216232u), + new Fsr3Upscaler.RcasConstants(1052902144u, 907032080u), + new Fsr3Upscaler.RcasConstants(1053814727u, 914306687u), + new Fsr3Upscaler.RcasConstants(1054792807u, 922105590u), + new Fsr3Upscaler.RcasConstants(1055841087u, 930494326u), + new Fsr3Upscaler.RcasConstants(1056964608u, 939538432u), + new Fsr3Upscaler.RcasConstants(1057566688u, 944322633u), + new Fsr3Upscaler.RcasConstants(1058211980u, 949500056u), + new Fsr3Upscaler.RcasConstants(1058903587u, 955005164u), + new Fsr3Upscaler.RcasConstants(1059644835u, 960969031u), + new Fsr3Upscaler.RcasConstants(1060439283u, 967326120u), + new Fsr3Upscaler.RcasConstants(1061290752u, 974141968u), + new Fsr3Upscaler.RcasConstants(1062203335u, 981416575u), + new Fsr3Upscaler.RcasConstants(1063181415u, 989215478u), + new Fsr3Upscaler.RcasConstants(1064229695u, 997604214u), + new Fsr3Upscaler.RcasConstants(1065353216u, 1006648320), }; private static ComputeBuffer CreateConstantBuffer() where TConstants: struct @@ -598,7 +598,7 @@ namespace FidelityFX bufferRef = null; } - private static void DestroyPass(ref Fsr2Pass pass) + private static void DestroyPass(ref Fsr3UpscalerPass pass) { if (pass == null) return; diff --git a/Assets/Scripts/Core/Fsr2Context.cs.meta b/Assets/Scripts/Core/Fsr3UpscalerContext.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2Context.cs.meta rename to Assets/Scripts/Core/Fsr3UpscalerContext.cs.meta diff --git a/Assets/Scripts/Core/Fsr2Pass.cs b/Assets/Scripts/Core/Fsr3UpscalerPass.cs similarity index 63% rename from Assets/Scripts/Core/Fsr2Pass.cs rename to Assets/Scripts/Core/Fsr3UpscalerPass.cs index 7cbf2ea..fb1c32c 100644 --- a/Assets/Scripts/Core/Fsr2Pass.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerPass.cs @@ -27,21 +27,21 @@ namespace FidelityFX { /// /// Base class for all of the compute passes that make up the FSR3 Upscaler process. - /// This loosely matches the FfxPipelineState struct from the original FSR3 Upscaler codebase, wrapped in an object-oriented blanket. + /// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket. /// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders. /// - internal abstract class Fsr2Pass: IDisposable + internal abstract class Fsr3UpscalerPass: IDisposable { internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR3UPSCALER_SHADING_CHANGE_MIP_LEVEL define - protected readonly Fsr2.ContextDescription ContextDescription; - protected readonly Fsr2Resources Resources; + protected readonly Fsr3Upscaler.ContextDescription ContextDescription; + protected readonly Fsr3UpscalerResources Resources; protected readonly ComputeBuffer Constants; protected ComputeShader ComputeShader; protected int KernelIndex; - protected Fsr2Pass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + protected Fsr3UpscalerPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) { ContextDescription = contextDescription; Resources = resources; @@ -53,14 +53,14 @@ namespace FidelityFX UnloadComputeShader(); } - public abstract void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); + public abstract void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); protected void LoadComputeShader(string name) { LoadComputeShader(name, ContextDescription.Flags, ref ComputeShader, out KernelIndex); } - private void LoadComputeShader(string name, Fsr2.InitializationFlags flags, ref ComputeShader shaderRef, out int kernelIndex) + private void LoadComputeShader(string name, Fsr3Upscaler.InitializationFlags flags, ref ComputeShader shaderRef, out int kernelIndex) { if (shaderRef == null) { @@ -80,12 +80,12 @@ namespace FidelityFX #endif // This matches the permutation rules from the CreatePipeline* functions - if ((flags & Fsr2.InitializationFlags.EnableHighDynamicRange) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT"); - if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); - if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS"); - if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); + if ((flags & Fsr3Upscaler.InitializationFlags.EnableHighDynamicRange) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT"); + if ((flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); + if ((flags & Fsr3Upscaler.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS"); + if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); if (useLut) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE"); - if ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0) shaderRef.EnableKeyword("FFX_HALF"); + if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) shaderRef.EnableKeyword("FFX_HALF"); // Inform the shader which render pipeline we're currently using var pipeline = GraphicsSettings.currentRenderPipeline; @@ -110,11 +110,11 @@ namespace FidelityFX } } - internal class Fsr2ComputeLuminancePyramidPass : Fsr2Pass + internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass { private readonly ComputeBuffer _spdConstants; - public Fsr2ComputeLuminancePyramidPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer spdConstants) + public Fsr3UpscalerComputeLuminancePyramidPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer spdConstants) : base(contextDescription, resources, constants) { _spdConstants = spdConstants; @@ -122,60 +122,60 @@ namespace FidelityFX LoadComputeShader("FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoExposure, Resources.AutoExposure); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2ReconstructPreviousDepthPass : Fsr2Pass + internal class Fsr3UpscalerReconstructPreviousDepthPass : Fsr3UpscalerPass { - public Fsr2ReconstructPreviousDepthPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + public Fsr3UpscalerReconstructPreviousDepthPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { LoadComputeShader("FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; ref var motionVectors = ref dispatchParams.MotionVectors; ref var exposure = ref dispatchParams.Exposure; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2DepthClipPass : Fsr2Pass + internal class Fsr3UpscalerDepthClipPass : Fsr3UpscalerPass { - public Fsr2DepthClipPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + public Fsr3UpscalerDepthClipPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { LoadComputeShader("FSR3/ffx_fsr3upscaler_depth_clip_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; @@ -184,42 +184,42 @@ namespace FidelityFX ref var reactive = ref dispatchParams.Reactive; ref var tac = ref dispatchParams.TransparencyAndComposition; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReconstructedPrevNearestDepth, Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedDepth, Fsr2ShaderIDs.UavDilatedDepth); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); - - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReconstructedPrevNearestDepth, Fsr3ShaderIDs.UavReconstructedPrevNearestDepth); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedDepth, Fsr3ShaderIDs.UavDilatedDepth); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); + + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2LockPass : Fsr2Pass + internal class Fsr3UpscalerLockPass : Fsr3UpscalerPass { - public Fsr2LockPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + public Fsr3UpscalerLockPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { LoadComputeShader("FSR3/ffx_fsr3upscaler_lock_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLockInputLuma, Fsr3ShaderIDs.UavLockInputLuma); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2AccumulatePass : Fsr2Pass + internal class Fsr3UpscalerAccumulatePass : Fsr3UpscalerPass { private const string SharpeningKeyword = "FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING"; @@ -227,7 +227,7 @@ namespace FidelityFX private readonly LocalKeyword _sharpeningKeyword; #endif - public Fsr2AccumulatePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { LoadComputeShader("FSR3/ffx_fsr3upscaler_accumulate_pass"); @@ -236,7 +236,7 @@ namespace FidelityFX #endif } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { #if UNITY_2021_2_OR_NEWER if (dispatchParams.EnableSharpening) @@ -250,47 +250,47 @@ namespace FidelityFX commandBuffer.DisableShaderKeyword(SharpeningKeyword); #endif - if ((ContextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) + if ((ContextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) { - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); } else { ref var motionVectors = ref dispatchParams.MotionVectors; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); } ref var exposure = ref dispatchParams.Exposure; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedReactiveMasks, Fsr2ShaderIDs.UavDilatedReactiveMasks); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockStatus, Resources.LockStatus[frameIndex ^ 1]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPreparedInputColor, Fsr2ShaderIDs.UavPreparedInputColor); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLanczosLut, Resources.LanczosLut); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvAutoExposure, Resources.AutoExposure); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLockStatus, Resources.LockStatus[frameIndex ^ 1]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPreparedInputColor, Fsr3ShaderIDs.UavPreparedInputColor); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLanczosLut, Resources.LanczosLut); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvAutoExposure, Resources.AutoExposure); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]); ref var output = ref dispatchParams.Output; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2RcasPass : Fsr2Pass + internal class Fsr3UpscalerRcasPass : Fsr3UpscalerPass { private readonly ComputeBuffer _rcasConstants; - public Fsr2RcasPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer rcasConstants) + public Fsr3UpscalerRcasPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer rcasConstants) : base(contextDescription, resources, constants) { _rcasConstants = rcasConstants; @@ -298,27 +298,27 @@ namespace FidelityFX LoadComputeShader("FSR3/ffx_fsr3upscaler_rcas_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var exposure = ref dispatchParams.Exposure; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]); ref var output = ref dispatchParams.Output; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2GenerateReactivePass : Fsr2Pass + internal class Fsr3UpscalerGenerateReactivePass : Fsr3UpscalerPass { private readonly ComputeBuffer _generateReactiveConstants; - public Fsr2GenerateReactivePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer generateReactiveConstants) + public Fsr3UpscalerGenerateReactivePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer generateReactiveConstants) : base(contextDescription, resources, null) { _generateReactiveConstants = generateReactiveConstants; @@ -326,31 +326,31 @@ namespace FidelityFX LoadComputeShader("FSR3/ffx_fsr3upscaler_autogen_reactive_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { } - public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY) + public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY) { ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; ref var color = ref dispatchParams.ColorPreUpscale; ref var reactive = ref dispatchParams.OutReactive; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoReactive, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } - internal class Fsr2TcrAutogeneratePass : Fsr2Pass + internal class Fsr3UpscalerTcrAutogeneratePass : Fsr3UpscalerPass { private readonly ComputeBuffer _tcrAutogenerateConstants; - public Fsr2TcrAutogeneratePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer tcrAutogenerateConstants) + public Fsr3UpscalerTcrAutogeneratePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer tcrAutogenerateConstants) : base(contextDescription, resources, constants) { _tcrAutogenerateConstants = tcrAutogenerateConstants; @@ -358,7 +358,7 @@ namespace FidelityFX LoadComputeShader("FSR3/ffx_fsr3upscaler_tcr_autogen_pass"); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; ref var motionVectors = ref dispatchParams.MotionVectors; @@ -366,21 +366,21 @@ namespace FidelityFX ref var reactive = ref dispatchParams.Reactive; ref var tac = ref dispatchParams.TransparencyAndComposition; - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex ^ 1]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex ^ 1]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, Resources.AutoReactive); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoComposition, Resources.AutoComposition); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex ^ 1]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex ^ 1]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoReactive, Resources.AutoReactive); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoComposition, Resources.AutoComposition); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } diff --git a/Assets/Scripts/Core/Fsr2Pass.cs.meta b/Assets/Scripts/Core/Fsr3UpscalerPass.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2Pass.cs.meta rename to Assets/Scripts/Core/Fsr3UpscalerPass.cs.meta diff --git a/Assets/Scripts/Core/Fsr2Resources.cs b/Assets/Scripts/Core/Fsr3UpscalerResources.cs similarity index 93% rename from Assets/Scripts/Core/Fsr2Resources.cs rename to Assets/Scripts/Core/Fsr3UpscalerResources.cs index ce2596a..676867b 100644 --- a/Assets/Scripts/Core/Fsr2Resources.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerResources.cs @@ -29,7 +29,7 @@ namespace FidelityFX /// Helper class for bundling and managing persistent resources required by the FSR3 Upscaler process. /// This includes lookup tables, default fallback resources and double-buffered resources that get swapped between frames. /// - internal class Fsr2Resources + internal class Fsr3UpscalerResources { public Texture2D DefaultExposure; public Texture2D DefaultReactive; @@ -47,7 +47,7 @@ namespace FidelityFX public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2]; - public void Create(Fsr2.ContextDescription contextDescription) + public void Create(Fsr3Upscaler.ContextDescription contextDescription) { // Generate the data for the LUT const int lanczos2LutWidth = 128; @@ -55,7 +55,7 @@ namespace FidelityFX for (int currentLanczosWidthIndex = 0; currentLanczosWidthIndex < lanczos2LutWidth; ++currentLanczosWidthIndex) { float x = 2.0f * currentLanczosWidthIndex / (lanczos2LutWidth - 1); - float y = Fsr2.Lanczos2(x); + float y = Fsr3Upscaler.Lanczos2(x); lanczos2Weights[currentLanczosWidthIndex] = y; } @@ -115,7 +115,7 @@ namespace FidelityFX CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", contextDescription.DisplaySize, GraphicsFormat.R8G8B8A8_UNorm); } - public void CreateTcrAutogenResources(Fsr2.ContextDescription contextDescription) + public void CreateTcrAutogenResources(Fsr3Upscaler.ContextDescription contextDescription) { // Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE AutoReactive = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoReactive", enableRandomWrite = true }; @@ -134,39 +134,39 @@ namespace FidelityFX // Set up shared aliasable resources, i.e. temporary render textures // These do not need to persist between frames, but they do need to be available between passes - public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr2.ContextDescription contextDescription, Fsr2.DispatchDescription dispatchParams) + public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr3Upscaler.ContextDescription contextDescription, Fsr3Upscaler.DispatchDescription dispatchParams) { Vector2Int displaySize = contextDescription.DisplaySize; Vector2Int maxRenderSize = contextDescription.MaxRenderSize; // FSR3UPSCALER_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true); // FSR3UPSCALER_DilatedDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_SFloat, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_SFloat, 1, true); // FSR3UPSCALER_LockInputLuma: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavLockInputLuma, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true); // FSR3UPSCALER_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8_UNorm, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8_UNorm, 1, true); // FSR3UPSCALER_PreparedInputColor: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavPreparedInputColor, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavPreparedInputColor, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true); // FSR3UPSCALER_NewLocks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE - commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavNewLocks, displaySize.x, displaySize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); + commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavNewLocks, displaySize.x, displaySize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); } public static void DestroyAliasableResources(CommandBuffer commandBuffer) { // Release all of the aliasable resources used this frame - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth); - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma); - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedReactiveMasks); - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavPreparedInputColor); - commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavNewLocks); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedDepth); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavLockInputLuma); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavPreparedInputColor); + commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavNewLocks); } private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format) diff --git a/Assets/Scripts/Core/Fsr2Resources.cs.meta b/Assets/Scripts/Core/Fsr3UpscalerResources.cs.meta similarity index 100% rename from Assets/Scripts/Core/Fsr2Resources.cs.meta rename to Assets/Scripts/Core/Fsr3UpscalerResources.cs.meta diff --git a/Assets/Scripts/Debug/DebugDumper.cs b/Assets/Scripts/Debug/DebugDumper.cs index a1ae610..8064e5e 100644 --- a/Assets/Scripts/Debug/DebugDumper.cs +++ b/Assets/Scripts/Debug/DebugDumper.cs @@ -29,7 +29,7 @@ using UnityEngine; public class DebugDumper : MonoBehaviour { - private Fsr2ImageEffect _fsr; + private Fsr3UpscalerImageEffect _fsr; private float _scaleFactor = 1.0f; private float _lastScaleTime = 0f; @@ -44,7 +44,7 @@ public class DebugDumper : MonoBehaviour Debug.Log(sb); - _fsr = GetComponent(); + _fsr = GetComponent(); } void OnEnable() @@ -77,8 +77,8 @@ public class DebugDumper : MonoBehaviour if (Input.GetButtonDown("Fire2")) { int quality = (int)_fsr.qualityMode; - quality = (quality + 1) % Enum.GetValues(typeof(Fsr2.QualityMode)).Length; - _fsr.qualityMode = (Fsr2.QualityMode)quality; + quality = (quality + 1) % Enum.GetValues(typeof(Fsr3Upscaler.QualityMode)).Length; + _fsr.qualityMode = (Fsr3Upscaler.QualityMode)quality; } if (Input.GetButtonDown("Fire3")) diff --git a/Assets/Scripts/Fsr2CameraHelper.cs b/Assets/Scripts/Fsr3UpscalerCameraHelper.cs similarity index 91% rename from Assets/Scripts/Fsr2CameraHelper.cs rename to Assets/Scripts/Fsr3UpscalerCameraHelper.cs index 969c372..75c9fe1 100644 --- a/Assets/Scripts/Fsr2CameraHelper.cs +++ b/Assets/Scripts/Fsr3UpscalerCameraHelper.cs @@ -30,10 +30,10 @@ namespace FidelityFX /// /// [RequireComponent(typeof(Camera))] - public class Fsr2CameraHelper : MonoBehaviour + public class Fsr3UpscalerCameraHelper : MonoBehaviour { [Tooltip("Standard scaling ratio presets.")] - public Fsr2.QualityMode qualityMode = Fsr2.QualityMode.Quality; + public Fsr3Upscaler.QualityMode qualityMode = Fsr3Upscaler.QualityMode.Quality; private Vector2Int _maxRenderSize; private Vector2Int _displaySize; @@ -60,7 +60,7 @@ namespace FidelityFX { // Determine the desired rendering and display resolutions _displaySize = GetDisplaySize(); - Fsr2.GetRenderResolutionFromQualityMode(out var maxRenderWidth, out var maxRenderHeight, _displaySize.x, _displaySize.y, qualityMode); + Fsr3Upscaler.GetRenderResolutionFromQualityMode(out var maxRenderWidth, out var maxRenderHeight, _displaySize.x, _displaySize.y, qualityMode); _maxRenderSize = new Vector2Int(maxRenderWidth, maxRenderHeight); if (_maxRenderSize.x == 0 || _maxRenderSize.y == 0) @@ -87,8 +87,8 @@ namespace FidelityFX var scaledRenderSize = GetScaledRenderSize(); // Perform custom jittering of the camera's projection matrix according to FSR3's recipe - int jitterPhaseCount = Fsr2.GetJitterPhaseCount(scaledRenderSize.x, _displaySize.x); - Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); + int jitterPhaseCount = Fsr3Upscaler.GetJitterPhaseCount(scaledRenderSize.x, _displaySize.x); + Fsr3Upscaler.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); jitterX = 2.0f * jitterX / scaledRenderSize.x; jitterY = 2.0f * jitterY / scaledRenderSize.y; diff --git a/Assets/Scripts/Fsr2CameraHelper.cs.meta b/Assets/Scripts/Fsr3UpscalerCameraHelper.cs.meta similarity index 100% rename from Assets/Scripts/Fsr2CameraHelper.cs.meta rename to Assets/Scripts/Fsr3UpscalerCameraHelper.cs.meta diff --git a/Assets/Scripts/Fsr2ImageEffect.cs b/Assets/Scripts/Fsr3UpscalerImageEffect.cs similarity index 83% rename from Assets/Scripts/Fsr2ImageEffect.cs rename to Assets/Scripts/Fsr3UpscalerImageEffect.cs index ea5bb9e..a3efcca 100644 --- a/Assets/Scripts/Fsr2ImageEffect.cs +++ b/Assets/Scripts/Fsr3UpscalerImageEffect.cs @@ -32,12 +32,12 @@ namespace FidelityFX /// This component also exposes various FSR3 Upscaler parameters to the Unity inspector. /// [RequireComponent(typeof(Camera))] - public class Fsr2ImageEffect : MonoBehaviour + public class Fsr3UpscalerImageEffect : MonoBehaviour { - public IFsr2Callbacks Callbacks { get; set; } = new Fsr2CallbacksBase(); + public IFsr3UpscalerCallbacks Callbacks { get; set; } = new Fsr3UpscalerCallbacksBase(); [Tooltip("Standard scaling ratio presets.")] - public Fsr2.QualityMode qualityMode = Fsr2.QualityMode.Quality; + public Fsr3Upscaler.QualityMode qualityMode = Fsr3Upscaler.QualityMode.Quality; [Tooltip("Apply RCAS sharpening to the image after upscaling.")] public bool performSharpenPass = true; @@ -76,7 +76,7 @@ namespace FidelityFX [Tooltip("A value to set for the binary reactive mask")] [Range(0, 1)] public float binaryValue = 0.9f; [Tooltip("Flags to determine how to generate the reactive mask")] - public Fsr2.GenerateReactiveFlags flags = Fsr2.GenerateReactiveFlags.ApplyTonemap | Fsr2.GenerateReactiveFlags.ApplyThreshold | Fsr2.GenerateReactiveFlags.UseComponentsMax; + public Fsr3Upscaler.GenerateReactiveFlags flags = Fsr3Upscaler.GenerateReactiveFlags.ApplyTonemap | Fsr3Upscaler.GenerateReactiveFlags.ApplyThreshold | Fsr3Upscaler.GenerateReactiveFlags.UseComponentsMax; } [Tooltip("(Experimental) Automatically generate and use Reactive mask and Transparency & composition mask internally.")] @@ -99,24 +99,24 @@ namespace FidelityFX } [Header("Slave cameras")] - public Fsr2CameraHelper[] cameraStack; + public Fsr3UpscalerCameraHelper[] cameraStack; - private Fsr2Context _context; + private Fsr3UpscalerContext _context; private Vector2Int _maxRenderSize; private Vector2Int _displaySize; private bool _resetHistory; - private readonly Fsr2.DispatchDescription _dispatchDescription = new Fsr2.DispatchDescription(); - private readonly Fsr2.GenerateReactiveDescription _genReactiveDescription = new Fsr2.GenerateReactiveDescription(); + private readonly Fsr3Upscaler.DispatchDescription _dispatchDescription = new Fsr3Upscaler.DispatchDescription(); + private readonly Fsr3Upscaler.GenerateReactiveDescription _genReactiveDescription = new Fsr3Upscaler.GenerateReactiveDescription(); - private Fsr2ImageEffectHelper _helper; + private Fsr3UpscalerImageEffectHelper _helper; private Camera _renderCamera; private RenderTexture _originalRenderTarget; private DepthTextureMode _originalDepthTextureMode; private Rect _originalRect; - private Fsr2.QualityMode _prevQualityMode; + private Fsr3Upscaler.QualityMode _prevQualityMode; private Vector2Int _prevDisplaySize; private bool _prevAutoExposure; @@ -137,7 +137,7 @@ namespace FidelityFX // Determine the desired rendering and display resolutions _displaySize = GetDisplaySize(); - Fsr2.GetRenderResolutionFromQualityMode(out var maxRenderWidth, out var maxRenderHeight, _displaySize.x, _displaySize.y, qualityMode); + Fsr3Upscaler.GetRenderResolutionFromQualityMode(out var maxRenderWidth, out var maxRenderHeight, _displaySize.x, _displaySize.y, qualityMode); _maxRenderSize = new Vector2Int(maxRenderWidth, maxRenderHeight); if (!SystemInfo.supportsComputeShaders) @@ -154,7 +154,7 @@ namespace FidelityFX return; } - _helper = GetComponent(); + _helper = GetComponent(); _copyWithDepthMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth")); CreateFsrContext(); @@ -196,13 +196,13 @@ namespace FidelityFX private void CreateFsrContext() { // Initialize FSR3 Upscaler context - Fsr2.InitializationFlags flags = 0; - if (_renderCamera.allowHDR) flags |= Fsr2.InitializationFlags.EnableHighDynamicRange; - if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage; - if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure; - if (UsingDynamicResolution()) flags |= Fsr2.InitializationFlags.EnableDynamicResolution; + Fsr3Upscaler.InitializationFlags flags = 0; + if (_renderCamera.allowHDR) flags |= Fsr3Upscaler.InitializationFlags.EnableHighDynamicRange; + if (enableFP16) flags |= Fsr3Upscaler.InitializationFlags.EnableFP16Usage; + if (enableAutoExposure) flags |= Fsr3Upscaler.InitializationFlags.EnableAutoExposure; + if (UsingDynamicResolution()) flags |= Fsr3Upscaler.InitializationFlags.EnableDynamicResolution; - _context = Fsr2.CreateContext(_displaySize, _maxRenderSize, Callbacks, flags); + _context = Fsr3Upscaler.CreateContext(_displaySize, _maxRenderSize, Callbacks, flags); _prevDisplaySize = _displaySize; _prevQualityMode = qualityMode; @@ -248,7 +248,7 @@ namespace FidelityFX private void ApplyMipmapBias() { // Apply a mipmap bias so that textures retain their sharpness - float biasOffset = Fsr2.GetMipmapBiasOffset(_maxRenderSize.x, _displaySize.x); + float biasOffset = Fsr3Upscaler.GetMipmapBiasOffset(_maxRenderSize.x, _displaySize.x); if (!float.IsNaN(biasOffset) && !float.IsInfinity(biasOffset)) { Callbacks.ApplyMipmapBias(biasOffset); @@ -325,20 +325,20 @@ namespace FidelityFX private void SetupDispatchDescription() { // Set up the main FSR3 Upscaler dispatch parameters - _dispatchDescription.Color = new Fsr2.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color); - _dispatchDescription.Depth = new Fsr2.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); - _dispatchDescription.MotionVectors = new Fsr2.ResourceView(BuiltinRenderTextureType.MotionVectors); - _dispatchDescription.Exposure = Fsr2.ResourceView.Unassigned; - _dispatchDescription.Reactive = Fsr2.ResourceView.Unassigned; - _dispatchDescription.TransparencyAndComposition = Fsr2.ResourceView.Unassigned; + _dispatchDescription.Color = new Fsr3Upscaler.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color); + _dispatchDescription.Depth = new Fsr3Upscaler.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); + _dispatchDescription.MotionVectors = new Fsr3Upscaler.ResourceView(BuiltinRenderTextureType.MotionVectors); + _dispatchDescription.Exposure = Fsr3Upscaler.ResourceView.Unassigned; + _dispatchDescription.Reactive = Fsr3Upscaler.ResourceView.Unassigned; + _dispatchDescription.TransparencyAndComposition = Fsr3Upscaler.ResourceView.Unassigned; - if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = new Fsr2.ResourceView(exposure); - if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.ResourceView(reactiveMask); - if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.ResourceView(transparencyAndCompositionMask); + if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = new Fsr3Upscaler.ResourceView(exposure); + if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr3Upscaler.ResourceView(reactiveMask); + if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(transparencyAndCompositionMask); var scaledRenderSize = GetScaledRenderSize(); - _dispatchDescription.Output = new Fsr2.ResourceView(Fsr2ShaderIDs.UavUpscaledOutput); + _dispatchDescription.Output = new Fsr3Upscaler.ResourceView(Fsr3ShaderIDs.UavUpscaledOutput); _dispatchDescription.PreExposure = preExposure; _dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.Sharpness = sharpness; @@ -357,7 +357,7 @@ namespace FidelityFX _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; if (autoGenerateTransparencyAndComposition) { - _dispatchDescription.ColorOpaqueOnly = new Fsr2.ResourceView(_colorOpaqueOnly); + _dispatchDescription.ColorOpaqueOnly = new Fsr3Upscaler.ResourceView(_colorOpaqueOnly); _dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold; _dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale; _dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale; @@ -374,9 +374,9 @@ namespace FidelityFX private void SetupAutoReactiveDescription() { // Set up the parameters to auto-generate a reactive mask - _genReactiveDescription.ColorOpaqueOnly = new Fsr2.ResourceView(_colorOpaqueOnly); - _genReactiveDescription.ColorPreUpscale = new Fsr2.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color); - _genReactiveDescription.OutReactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive); + _genReactiveDescription.ColorOpaqueOnly = new Fsr3Upscaler.ResourceView(_colorOpaqueOnly); + _genReactiveDescription.ColorPreUpscale = new Fsr3Upscaler.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color); + _genReactiveDescription.OutReactive = new Fsr3Upscaler.ResourceView(Fsr3ShaderIDs.UavAutoReactive); _genReactiveDescription.RenderSize = GetScaledRenderSize(); _genReactiveDescription.Scale = generateReactiveParameters.scale; _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; @@ -389,8 +389,8 @@ namespace FidelityFX var scaledRenderSize = GetScaledRenderSize(); // Perform custom jittering of the camera's projection matrix according to FSR3's recipe - int jitterPhaseCount = Fsr2.GetJitterPhaseCount(scaledRenderSize.x, _displaySize.x); - Fsr2.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); + int jitterPhaseCount = Fsr3Upscaler.GetJitterPhaseCount(scaledRenderSize.x, _displaySize.x); + Fsr3Upscaler.GetJitterOffset(out float jitterX, out float jitterY, Time.frameCount, jitterPhaseCount); _dispatchDescription.JitterOffset = new Vector2(jitterX, jitterY); @@ -418,13 +418,13 @@ namespace FidelityFX { // The auto-reactive mask pass is executed separately from the main FSR3 Upscaler passes var scaledRenderSize = GetScaledRenderSize(); - _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); + _dispatchCommandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); _context.GenerateReactiveMask(_genReactiveDescription, _dispatchCommandBuffer); - _dispatchDescription.Reactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive); + _dispatchDescription.Reactive = new Fsr3Upscaler.ResourceView(Fsr3ShaderIDs.UavAutoReactive); } // The backbuffer is not set up to allow random-write access, so we need a temporary render texture for FSR3 to output to - _dispatchCommandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GetDefaultFormat(), default, 1, true); + _dispatchCommandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, GetDefaultFormat(), default, 1, true); _context.Dispatch(_dispatchDescription, _dispatchCommandBuffer); @@ -433,16 +433,16 @@ namespace FidelityFX { // Output to the camera target texture, passing through depth and motion vectors _dispatchCommandBuffer.SetGlobalTexture("_DepthTex", BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); - _dispatchCommandBuffer.Blit(Fsr2ShaderIDs.UavUpscaledOutput, _originalRenderTarget, _copyWithDepthMaterial); + _dispatchCommandBuffer.Blit(Fsr3ShaderIDs.UavUpscaledOutput, _originalRenderTarget, _copyWithDepthMaterial); } else { // Output directly to the backbuffer - _dispatchCommandBuffer.Blit(Fsr2ShaderIDs.UavUpscaledOutput, dest); + _dispatchCommandBuffer.Blit(Fsr3ShaderIDs.UavUpscaledOutput, dest); } - _dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput); - _dispatchCommandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavAutoReactive); + _dispatchCommandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavUpscaledOutput); + _dispatchCommandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavAutoReactive); Graphics.ExecuteCommandBuffer(_dispatchCommandBuffer); diff --git a/Assets/Scripts/Fsr2ImageEffect.cs.meta b/Assets/Scripts/Fsr3UpscalerImageEffect.cs.meta similarity index 100% rename from Assets/Scripts/Fsr2ImageEffect.cs.meta rename to Assets/Scripts/Fsr3UpscalerImageEffect.cs.meta diff --git a/Assets/Scripts/Fsr2ImageEffectHelper.cs b/Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs similarity index 87% rename from Assets/Scripts/Fsr2ImageEffectHelper.cs rename to Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs index 5eca3ee..f443548 100644 --- a/Assets/Scripts/Fsr2ImageEffectHelper.cs +++ b/Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs @@ -31,16 +31,16 @@ namespace FidelityFX /// When combining FSR3 upscaling with other post-processing effects (most notably Unity's Post-Processing Stack V2), /// this script should be added to the same camera and moved up above any other scripts that have an OnPreCull method. /// - [RequireComponent(typeof(Camera), typeof(Fsr2ImageEffect))] - public class Fsr2ImageEffectHelper : MonoBehaviour + [RequireComponent(typeof(Camera), typeof(Fsr3UpscalerImageEffect))] + public class Fsr3UpscalerImageEffectHelper : MonoBehaviour { private Camera _renderCamera; - private Fsr2ImageEffect _imageEffect; + private Fsr3UpscalerImageEffect _imageEffect; private void OnEnable() { _renderCamera = GetComponent(); - _imageEffect = GetComponent(); + _imageEffect = GetComponent(); } private void OnPreCull() @@ -49,7 +49,7 @@ namespace FidelityFX return; var originalRect = _renderCamera.rect; - float upscaleRatio = Fsr2.GetUpscaleRatioFromQualityMode(_imageEffect.qualityMode); + float upscaleRatio = Fsr3Upscaler.GetUpscaleRatioFromQualityMode(_imageEffect.qualityMode); // Render to a smaller portion of the screen by manipulating the camera's viewport rect _renderCamera.aspect = (_renderCamera.pixelWidth * originalRect.width) / (_renderCamera.pixelHeight * originalRect.height); diff --git a/Assets/Scripts/Fsr2ImageEffectHelper.cs.meta b/Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs.meta similarity index 100% rename from Assets/Scripts/Fsr2ImageEffectHelper.cs.meta rename to Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs.meta