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 d87b99f..9a8b187 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 @@ -178,10 +178,6 @@ namespace UnityEngine.Rendering.PostProcessing CreateFsrContext(context); } - cmd.SetGlobalTexture(Fsr2ShaderIDs.SrvInputColor, context.source); - cmd.SetGlobalTexture(Fsr2ShaderIDs.SrvInputDepth, BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); - cmd.SetGlobalTexture(Fsr2ShaderIDs.SrvInputMotionVectors, BuiltinRenderTextureType.MotionVectors); - SetupDispatchDescription(context); if (autoGenerateReactiveMask) @@ -191,7 +187,7 @@ namespace UnityEngine.Rendering.PostProcessing var scaledRenderSize = _genReactiveDescription.RenderSize; cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); _fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd); - _dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive; + _dispatchDescription.Reactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.UavAutoReactive); } _fsrContext.Dispatch(_dispatchDescription, cmd); @@ -267,22 +263,21 @@ namespace UnityEngine.Rendering.PostProcessing var camera = context.camera; // Set up the main FSR2 dispatch parameters - // The input textures are left blank here, as they get bound directly through SetGlobalTexture elsewhere in this source file - _dispatchDescription.Color = null; - _dispatchDescription.Depth = null; - _dispatchDescription.MotionVectors = null; + _dispatchDescription.Color = new Fsr2.RenderTargetView(context.source); + _dispatchDescription.Depth = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); + _dispatchDescription.MotionVectors = new Fsr2.RenderTargetView(BuiltinRenderTextureType.MotionVectors); _dispatchDescription.Exposure = null; _dispatchDescription.Reactive = null; _dispatchDescription.TransparencyAndComposition = null; - if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = exposure; - if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = context.autoExposureTexture; - if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask; - if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask; + if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(exposure); + if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(context.autoExposureTexture); + if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.RenderTargetView(reactiveMask); + if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.RenderTargetView(transparencyAndCompositionMask); var scaledRenderSize = GetScaledRenderSize(context.camera); - _dispatchDescription.Output = context.destination; + _dispatchDescription.Output = new Fsr2.RenderTargetView(context.destination); _dispatchDescription.PreExposure = preExposure; _dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.Sharpness = sharpness; @@ -301,7 +296,7 @@ namespace UnityEngine.Rendering.PostProcessing _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; if (autoGenerateTransparencyAndComposition) { - _dispatchDescription.ColorOpaqueOnly = colorOpaqueOnly; + _dispatchDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly); _dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold; _dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale; _dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale; @@ -318,9 +313,9 @@ namespace UnityEngine.Rendering.PostProcessing private void SetupAutoReactiveDescription(PostProcessRenderContext context) { // Set up the parameters to auto-generate a reactive mask - _genReactiveDescription.ColorOpaqueOnly = colorOpaqueOnly; - _genReactiveDescription.ColorPreUpscale = null; - _genReactiveDescription.OutReactive = null; + _genReactiveDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly); + _genReactiveDescription.ColorPreUpscale = new Fsr2.RenderTargetView(context.source); + _genReactiveDescription.OutReactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.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/FSR2/Fsr2.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs index 772cfc3..59cb113 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs @@ -155,6 +155,23 @@ namespace FidelityFX public Vector2Int DisplaySize; public IFsr2Callbacks Callbacks; } + + /// + /// A structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader. + /// + public struct RenderTargetView + { + public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) + { + RenderTarget = renderTarget; + SubElement = subElement; + MipLevel = mipLevel; + } + + public readonly RenderTargetIdentifier RenderTarget; + public readonly RenderTextureSubElement SubElement; + public readonly int MipLevel; + } /// /// The input and output resources are all optional. If they are null, the Fsr2Context won't try to bind them to any shaders. @@ -162,13 +179,13 @@ namespace FidelityFX /// public class DispatchDescription { - public RenderTargetIdentifier? Color; - public RenderTargetIdentifier? Depth; - public RenderTargetIdentifier? MotionVectors; - public RenderTargetIdentifier? Exposure; - public RenderTargetIdentifier? Reactive; - public RenderTargetIdentifier? TransparencyAndComposition; - public RenderTargetIdentifier? Output; + public RenderTargetView Color; + public RenderTargetView Depth; + public RenderTargetView MotionVectors; + public RenderTargetView? Exposure; + public RenderTargetView? Reactive; + public RenderTargetView? TransparencyAndComposition; + public RenderTargetView Output; public Vector2 JitterOffset; public Vector2 MotionVectorScale; public Vector2Int RenderSize; @@ -185,7 +202,7 @@ namespace FidelityFX // EXPERIMENTAL reactive mask generation parameters public bool EnableAutoReactive; - public RenderTargetIdentifier? ColorOpaqueOnly; + public RenderTargetView? ColorOpaqueOnly; public float AutoTcThreshold = 0.05f; public float AutoTcScale = 1.0f; public float AutoReactiveScale = 5.0f; @@ -197,9 +214,9 @@ namespace FidelityFX /// public class GenerateReactiveDescription { - public RenderTargetIdentifier? ColorOpaqueOnly; - public RenderTargetIdentifier? ColorPreUpscale; - public RenderTargetIdentifier? OutReactive; + public RenderTargetView ColorOpaqueOnly; + public RenderTargetView ColorPreUpscale; + public RenderTargetView OutReactive; public Vector2Int RenderSize; public float Scale = 0.5f; public float CutoffThreshold = 0.2f; diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs index b1d9a17..867b002 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs @@ -158,9 +158,9 @@ namespace FidelityFX // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) - dispatchParams.Exposure = _resources.AutoExposure; + dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.AutoExposure); else if (dispatchParams.Exposure == null) - dispatchParams.Exposure = _resources.DefaultExposure; + dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.DefaultExposure); if (dispatchParams.EnableAutoReactive) { @@ -169,7 +169,7 @@ namespace FidelityFX _resources.CreateTcrAutogenResources(_contextDescription); if (resetAccumulation) - commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], dispatchParams.ColorOpaqueOnly ?? Fsr2ShaderIDs.SrvOpaqueOnly); + commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], (dispatchParams.ColorOpaqueOnly ?? new Fsr2.RenderTargetView(Fsr2ShaderIDs.SrvOpaqueOnly)).RenderTarget); } else if (_resources.AutoReactive != null) { @@ -177,8 +177,8 @@ namespace FidelityFX _resources.DestroyTcrAutogenResources(); } - if (dispatchParams.Reactive == null) dispatchParams.Reactive = _resources.DefaultReactive; - if (dispatchParams.TransparencyAndComposition == null) dispatchParams.TransparencyAndComposition = _resources.DefaultReactive; + if (dispatchParams.Reactive == null) dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.DefaultReactive); + if (dispatchParams.TransparencyAndComposition == null) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive); Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -222,8 +222,8 @@ namespace FidelityFX if (dispatchParams.EnableAutoReactive) { GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); - dispatchParams.Reactive = _resources.AutoReactive; - dispatchParams.TransparencyAndComposition = _resources.AutoComposition; + dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.AutoReactive); + dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.AutoComposition); } // Compute luminance pyramid @@ -433,30 +433,6 @@ namespace FidelityFX private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams) { - // Global texture binding may be queued as part of the command list, which is why we check these after running the process at least once - if (!_firstExecution && !dispatchParams.Reset) - { - if (!dispatchParams.Color.HasValue && Shader.GetGlobalTexture(Fsr2ShaderIDs.SrvInputColor) == null) - { - Debug.LogError("Color resource is null"); - } - - if (!dispatchParams.Depth.HasValue && Shader.GetGlobalTexture(Fsr2ShaderIDs.SrvInputDepth) == null) - { - Debug.LogError("Depth resource is null"); - } - - if (!dispatchParams.MotionVectors.HasValue && Shader.GetGlobalTexture(Fsr2ShaderIDs.SrvInputMotionVectors) == null) - { - Debug.LogError("MotionVectors resource is null"); - } - - if (!dispatchParams.Output.HasValue && Shader.GetGlobalTexture(Fsr2ShaderIDs.UavUpscaledOutput) == null) - { - Debug.LogError("Output resource is null"); - } - } - if (dispatchParams.Exposure.HasValue && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) { Debug.LogWarning("Exposure resource provided, however auto exposure flag is present"); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs index 5b963f0..4b00278 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs @@ -129,8 +129,8 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - if (dispatchParams.Color.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color); + ref var color = ref dispatchParams.Color; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel); @@ -154,18 +154,20 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - if (dispatchParams.Color.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color); - - if (dispatchParams.Depth.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, dispatchParams.Depth.Value, 0, RenderTextureSubElement.Depth); - - if (dispatchParams.MotionVectors.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors.Value); + ref var color = ref dispatchParams.Color; + ref var depth = ref dispatchParams.Depth; + ref var motionVectors = ref dispatchParams.MotionVectors; + 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); + if (dispatchParams.Exposure.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, dispatchParams.Exposure.Value); - + { + var exposure = dispatchParams.Exposure.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + } + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); @@ -184,24 +186,32 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - if (dispatchParams.Color.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color); + ref var color = ref dispatchParams.Color; + ref var depth = ref dispatchParams.Depth; + ref var motionVectors = ref dispatchParams.MotionVectors; - if (dispatchParams.Depth.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, dispatchParams.Depth.Value, 0, RenderTextureSubElement.Depth); - - if (dispatchParams.MotionVectors.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors.Value); + 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); if (dispatchParams.Exposure.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, dispatchParams.Exposure.Value); + { + var exposure = dispatchParams.Exposure.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + } if (dispatchParams.Reactive.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, dispatchParams.Reactive.Value); - + { + var reactive = dispatchParams.Reactive.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); + } + if (dispatchParams.TransparencyAndComposition.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, dispatchParams.TransparencyAndComposition.Value); - + { + var tac = dispatchParams.TransparencyAndComposition.Value; + 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); @@ -265,13 +275,21 @@ namespace FidelityFX #endif if ((ContextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) + { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); - else if (dispatchParams.MotionVectors.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors.Value); - + } + else + { + ref var motionVectors = ref dispatchParams.MotionVectors; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + } + if (dispatchParams.Exposure.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, dispatchParams.Exposure.Value); - + { + var exposure = dispatchParams.Exposure.Value; + 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]); @@ -286,8 +304,8 @@ namespace FidelityFX commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]); - if (dispatchParams.Output.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, dispatchParams.Output.Value); + ref var output = ref dispatchParams.Output; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); @@ -310,12 +328,15 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { if (dispatchParams.Exposure.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, dispatchParams.Exposure.Value); + { + var exposure = dispatchParams.Exposure.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + } commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]); - if (dispatchParams.Output.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, dispatchParams.Output.Value); + ref var output = ref dispatchParams.Output; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf()); @@ -342,14 +363,13 @@ namespace FidelityFX public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY) { - if (dispatchParams.ColorOpaqueOnly.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, dispatchParams.ColorOpaqueOnly.Value, 0, RenderTextureSubElement.Color); + ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; + ref var color = ref dispatchParams.ColorPreUpscale; + ref var reactive = ref dispatchParams.OutReactive; - if (dispatchParams.ColorPreUpscale.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.ColorPreUpscale.Value, 0, RenderTextureSubElement.Color); - - if (dispatchParams.OutReactive.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, dispatchParams.OutReactive.Value); + 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.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf()); @@ -372,22 +392,30 @@ namespace FidelityFX public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { if (dispatchParams.ColorOpaqueOnly.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, dispatchParams.ColorOpaqueOnly.Value, 0, RenderTextureSubElement.Color); - - if (dispatchParams.Color.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color); - - if (dispatchParams.MotionVectors.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors.Value); + { + var opaqueOnly = dispatchParams.ColorOpaqueOnly.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement); + } + + ref var color = ref dispatchParams.Color; + ref var motionVectors = ref dispatchParams.MotionVectors; + 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]); if (dispatchParams.Reactive.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, dispatchParams.Reactive.Value); + { + var reactive = dispatchParams.Reactive.Value; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); + } if (dispatchParams.TransparencyAndComposition.HasValue) - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, dispatchParams.TransparencyAndComposition.Value); + { + var tac = dispatchParams.TransparencyAndComposition.Value; + 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);