From b7b3842b95aecdb4437373695a82ce9230e28bc1 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 16 Dec 2023 13:41:06 +0100 Subject: [PATCH] Moved ResourceView out of the Fsr3Upscaler class and into the FidelityFX namespace, making usages of ResourceView a lot cleaner. ResourceView is also generic enough that it could/should be reused for any other FidelityFX effects, so this move makes sense. --- .../Runtime/Effects/SuperResolution.cs | 34 +++++----- .../Runtime/FSR3/Fsr3Upscaler.cs | 67 ++++++++++--------- .../Runtime/FSR3/Fsr3UpscalerContext.cs | 12 ++-- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs index 8e8c890..c0e49c3 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs @@ -187,7 +187,7 @@ namespace UnityEngine.Rendering.PostProcessing var scaledRenderSize = _genReactiveDescription.RenderSize; cmd.GetTemporaryRT(Fsr3ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); _fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd); - _dispatchDescription.Reactive = new Fsr3Upscaler.ResourceView(Fsr3ShaderIDs.UavAutoReactive); + _dispatchDescription.Reactive = new ResourceView(Fsr3ShaderIDs.UavAutoReactive); } _fsrContext.Dispatch(_dispatchDescription, cmd); @@ -263,21 +263,21 @@ namespace UnityEngine.Rendering.PostProcessing var camera = context.camera; // Set up the main FSR3 Upscaler dispatch parameters - _dispatchDescription.Color = new Fsr3Upscaler.ResourceView(context.source); - _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 (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr3Upscaler.ResourceView(exposure); - if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr3Upscaler.ResourceView(context.autoExposureTexture); - if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr3Upscaler.ResourceView(reactiveMask); - if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(transparencyAndCompositionMask); + _dispatchDescription.Color = new ResourceView(context.source); + _dispatchDescription.Depth = new ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); + _dispatchDescription.MotionVectors = new ResourceView(BuiltinRenderTextureType.MotionVectors); + _dispatchDescription.Exposure = ResourceView.Unassigned; + _dispatchDescription.Reactive = ResourceView.Unassigned; + _dispatchDescription.TransparencyAndComposition = ResourceView.Unassigned; + + if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new ResourceView(exposure); + if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new ResourceView(context.autoExposureTexture); + if (reactiveMask != null) _dispatchDescription.Reactive = new ResourceView(reactiveMask); + if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new ResourceView(transparencyAndCompositionMask); var scaledRenderSize = GetScaledRenderSize(context.camera); - _dispatchDescription.Output = new Fsr3Upscaler.ResourceView(context.destination); + _dispatchDescription.Output = new ResourceView(context.destination); _dispatchDescription.PreExposure = preExposure; _dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.Sharpness = sharpness; @@ -296,7 +296,7 @@ namespace UnityEngine.Rendering.PostProcessing _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; if (autoGenerateTransparencyAndComposition) { - _dispatchDescription.ColorOpaqueOnly = new Fsr3Upscaler.ResourceView(colorOpaqueOnly); + _dispatchDescription.ColorOpaqueOnly = new ResourceView(colorOpaqueOnly); _dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold; _dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale; _dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale; @@ -313,9 +313,9 @@ namespace UnityEngine.Rendering.PostProcessing private void SetupAutoReactiveDescription(PostProcessRenderContext context) { // Set up the parameters to auto-generate a reactive mask - _genReactiveDescription.ColorOpaqueOnly = new Fsr3Upscaler.ResourceView(colorOpaqueOnly); - _genReactiveDescription.ColorPreUpscale = new Fsr3Upscaler.ResourceView(context.source); - _genReactiveDescription.OutReactive = new Fsr3Upscaler.ResourceView(Fsr3ShaderIDs.UavAutoReactive); + _genReactiveDescription.ColorOpaqueOnly = new ResourceView(colorOpaqueOnly); + _genReactiveDescription.ColorPreUpscale = new ResourceView(context.source); + _genReactiveDescription.OutReactive = new ResourceView(Fsr3ShaderIDs.UavAutoReactive); _genReactiveDescription.RenderSize = GetScaledRenderSize(context.camera); _genReactiveDescription.Scale = generateReactiveParameters.scale; _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs index d31a82e..4c5dc51 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs @@ -158,6 +158,9 @@ namespace FidelityFX EnableDebugChecking = 1 << 8, } + /// + /// A structure encapsulating the parameters required to initialize FidelityFX Super Resolution 3 upscaling. + /// public struct ContextDescription { public InitializationFlags Flags; @@ -165,40 +168,9 @@ namespace FidelityFX public Vector2Int DisplaySize; public IFsr3UpscalerCallbacks Callbacks; } - - /// - /// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader. - /// - public readonly struct ResourceView - { - /// - /// This value is the equivalent of not setting any value at all; all struct fields will have their default values. - /// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader. - /// - public static readonly ResourceView Unassigned = new ResourceView(default); - - /// - /// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture. - /// Binding this to a shader can be seen as setting the texture variable inside the shader to null. - /// - public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None); - - public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) - { - RenderTarget = renderTarget; - SubElement = subElement; - MipLevel = mipLevel; - } - - public bool IsValid => !RenderTarget.Equals(default); - - public readonly RenderTargetIdentifier RenderTarget; - public readonly RenderTextureSubElement SubElement; - public readonly int MipLevel; - } /// - /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2. + /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 3. /// public class DispatchDescription { @@ -327,4 +299,35 @@ namespace FidelityFX public readonly uint dummy1; } } + + /// + /// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader. + /// + public readonly struct ResourceView + { + /// + /// This value is the equivalent of not setting any value at all; all struct fields will have their default values. + /// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader. + /// + public static readonly ResourceView Unassigned = new ResourceView(default); + + /// + /// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture. + /// Binding this to a shader can be seen as setting the texture variable inside the shader to null. + /// + public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None); + + public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) + { + RenderTarget = renderTarget; + SubElement = subElement; + MipLevel = mipLevel; + } + + public bool IsValid => !RenderTarget.Equals(default); + + public readonly RenderTargetIdentifier RenderTarget; + public readonly RenderTextureSubElement SubElement; + public readonly int MipLevel; + } } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs index 0f3b99d..61722d5 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs @@ -157,9 +157,9 @@ namespace FidelityFX // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0) - dispatchParams.Exposure = new Fsr3Upscaler.ResourceView(_resources.AutoExposure); + dispatchParams.Exposure = new ResourceView(_resources.AutoExposure); else if (!dispatchParams.Exposure.IsValid) - dispatchParams.Exposure = new Fsr3Upscaler.ResourceView(_resources.DefaultExposure); + dispatchParams.Exposure = new ResourceView(_resources.DefaultExposure); if (dispatchParams.EnableAutoReactive) { @@ -179,8 +179,8 @@ namespace FidelityFX _resources.DestroyTcrAutogenResources(); } - if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new Fsr3Upscaler.ResourceView(_resources.DefaultReactive); - if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(_resources.DefaultReactive); + if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); + if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -229,8 +229,8 @@ namespace FidelityFX if (dispatchParams.EnableAutoReactive) { GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); - dispatchParams.Reactive = new Fsr3Upscaler.ResourceView(_resources.AutoReactive); - dispatchParams.TransparencyAndComposition = new Fsr3Upscaler.ResourceView(_resources.AutoComposition); + dispatchParams.Reactive = new ResourceView(_resources.AutoReactive); + dispatchParams.TransparencyAndComposition = new ResourceView(_resources.AutoComposition); } // Compute luminance pyramid