From 15b380eebf693ac866d8ab695ec83eb3a201606a Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 3 Aug 2024 15:51:37 +0200 Subject: [PATCH] Abstracted some of the common pass code into a new base class for passes. --- Runtime/Common/FfxPassBase.cs | 55 ++++++++++++++++++++++ Runtime/Common/FfxPassBase.cs.meta | 11 +++++ Runtime/FSR2/Fsr2Pass.cs | 62 ++++++++----------------- Runtime/FSR3/Fsr3UpscalerPass.cs | 74 ++++++++++-------------------- 4 files changed, 108 insertions(+), 94 deletions(-) create mode 100644 Runtime/Common/FfxPassBase.cs create mode 100644 Runtime/Common/FfxPassBase.cs.meta diff --git a/Runtime/Common/FfxPassBase.cs b/Runtime/Common/FfxPassBase.cs new file mode 100644 index 0000000..9a0aec2 --- /dev/null +++ b/Runtime/Common/FfxPassBase.cs @@ -0,0 +1,55 @@ +using System; +using UnityEngine; +using UnityEngine.Profiling; +using UnityEngine.Rendering; + +namespace FidelityFX +{ + public abstract class FfxPassBase: IDisposable + //where TDispatch: struct + where TFlags: Enum + { + private readonly string _techName; + + protected ComputeShader ComputeShader; + protected int KernelIndex; + + protected CustomSampler Sampler; + + protected FfxPassBase(string techName) + { + _techName = techName; + } + + public void ScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ = 1) + { + commandBuffer.BeginSample(Sampler); + DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY, dispatchZ); + commandBuffer.EndSample(Sampler); + } + + protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ); + + protected void InitComputeShader(string passName, ComputeShader shader, TFlags flags) + { + if (shader == null) + { + throw new MissingReferenceException($"Shader for {_techName} pass '{passName}' could not be loaded! Please ensure it is included in the project correctly."); + } + + ComputeShader = shader; + KernelIndex = ComputeShader.FindKernel("CS"); + Sampler = CustomSampler.Create(passName); + + SetupShaderKeywords(flags); + } + + protected virtual void SetupShaderKeywords(TFlags flags) + { + } + + public virtual void Dispose() + { + } + } +} diff --git a/Runtime/Common/FfxPassBase.cs.meta b/Runtime/Common/FfxPassBase.cs.meta new file mode 100644 index 0000000..f89a6b8 --- /dev/null +++ b/Runtime/Common/FfxPassBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: deac9cc5a4c6df64db05956030e79425 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/FSR2/Fsr2Pass.cs b/Runtime/FSR2/Fsr2Pass.cs index bda5092..e42ff97 100644 --- a/Runtime/FSR2/Fsr2Pass.cs +++ b/Runtime/FSR2/Fsr2Pass.cs @@ -31,7 +31,7 @@ namespace FidelityFX.FSR2 /// This loosely matches the FfxPipelineState struct from the original FSR2 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 Fsr2Pass: FfxPassBase { internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define @@ -39,47 +39,21 @@ namespace FidelityFX.FSR2 protected readonly Fsr2Resources Resources; protected readonly ComputeBuffer Constants; - protected ComputeShader ComputeShader; - protected int KernelIndex; - - protected CustomSampler Sampler; - protected Fsr2Pass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) + : base("FSR2") { ContextDescription = contextDescription; Resources = resources; Constants = constants; } - public virtual void Dispose() - { - } - - public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) - { - commandBuffer.BeginSample(Sampler); - DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY); - commandBuffer.EndSample(Sampler); - } - - protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); - protected void InitComputeShader(string passName, ComputeShader shader) { InitComputeShader(passName, shader, ContextDescription.Flags); } - private void InitComputeShader(string passName, ComputeShader shader, Fsr2.InitializationFlags flags) + protected override void SetupShaderKeywords(Fsr2.InitializationFlags flags) { - if (shader == null) - { - throw new MissingReferenceException($"Shader for FSR2 pass '{passName}' could not be loaded! Please ensure it is included in the project correctly."); - } - - ComputeShader = shader; - KernelIndex = ComputeShader.FindKernel("CS"); - Sampler = CustomSampler.Create(passName); - bool useLut = false; #if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ if (SystemInfo.computeSubGroupSize == 64) @@ -110,7 +84,7 @@ namespace FidelityFX.FSR2 InitComputeShader("Compute Luminance Pyramid", contextDescription.Shaders.computeLuminancePyramidPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); @@ -123,7 +97,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -135,7 +109,7 @@ namespace FidelityFX.FSR2 InitComputeShader("Reconstruct & Dilate", contextDescription.Shaders.reconstructPreviousDepthPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; @@ -151,7 +125,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -163,7 +137,7 @@ namespace FidelityFX.FSR2 InitComputeShader("Depth Clip", contextDescription.Shaders.depthClipPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; @@ -186,7 +160,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -198,12 +172,12 @@ namespace FidelityFX.FSR2 InitComputeShader("Create Locks", contextDescription.Shaders.lockPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -224,7 +198,7 @@ namespace FidelityFX.FSR2 #endif } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { #if UNITY_2021_2_OR_NEWER if (dispatchParams.EnableSharpening) @@ -270,7 +244,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -286,7 +260,7 @@ namespace FidelityFX.FSR2 InitComputeShader("RCAS Sharpening", contextDescription.Shaders.sharpenPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); @@ -298,7 +272,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -314,7 +288,7 @@ namespace FidelityFX.FSR2 InitComputeShader("Auto-Generate Reactive Mask", contextDescription.Shaders.autoGenReactivePass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { } @@ -350,7 +324,7 @@ namespace FidelityFX.FSR2 InitComputeShader("Auto-Generate Transparency & Composition Mask", contextDescription.Shaders.tcrAutoGenPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; ref var motionVectors = ref dispatchParams.MotionVectors; @@ -374,7 +348,7 @@ namespace FidelityFX.FSR2 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } } diff --git a/Runtime/FSR3/Fsr3UpscalerPass.cs b/Runtime/FSR3/Fsr3UpscalerPass.cs index 3b76eb4..c9b45af 100644 --- a/Runtime/FSR3/Fsr3UpscalerPass.cs +++ b/Runtime/FSR3/Fsr3UpscalerPass.cs @@ -31,53 +31,27 @@ namespace FidelityFX.FSR3 /// 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 Fsr3UpscalerPass: IDisposable + internal abstract class Fsr3UpscalerPass: FfxPassBase { protected readonly Fsr3Upscaler.ContextDescription ContextDescription; protected readonly Fsr3UpscalerResources Resources; protected readonly ComputeBuffer Constants; - protected ComputeShader ComputeShader; - protected int KernelIndex; - - protected CustomSampler Sampler; - protected Fsr3UpscalerPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + : base("FSR3 Upscaler") { ContextDescription = contextDescription; Resources = resources; Constants = constants; } - - public virtual void Dispose() - { - } - - public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) - { - commandBuffer.BeginSample(Sampler); - DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY); - commandBuffer.EndSample(Sampler); - } - - protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); protected void InitComputeShader(string passName, ComputeShader shader) { InitComputeShader(passName, shader, ContextDescription.Flags); } - private void InitComputeShader(string passName, ComputeShader shader, Fsr3Upscaler.InitializationFlags flags) + protected override void SetupShaderKeywords(Fsr3Upscaler.InitializationFlags flags) { - if (shader == null) - { - throw new MissingReferenceException($"Shader for FSR3 Upscaler pass '{passName}' could not be loaded! Please ensure it is included in the project correctly."); - } - - ComputeShader = shader; - KernelIndex = ComputeShader.FindKernel("CS"); - Sampler = CustomSampler.Create(passName); - bool useLut = false; #if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ if (SystemInfo.computeSubGroupSize == 64) @@ -104,7 +78,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Prepare Inputs", contextDescription.Shaders.prepareInputsPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; @@ -122,7 +96,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -138,7 +112,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Compute Luminance Pyramid", contextDescription.Shaders.lumaPyramidPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFarthestDepth, Fsr3ShaderIDs.UavIntermediate); @@ -155,7 +129,7 @@ namespace FidelityFX.FSR3 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); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -171,7 +145,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Compute Shading Change Pyramid", contextDescription.Shaders.shadingChangePyramidPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; @@ -191,7 +165,7 @@ namespace FidelityFX.FSR3 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); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -203,13 +177,13 @@ namespace FidelityFX.FSR3 InitComputeShader("Compute Shading Change", contextDescription.Shaders.shadingChangePass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvSpdMips, Resources.SpdMips); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -221,7 +195,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Prepare Reactivity", contextDescription.Shaders.prepareReactivityPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; ref var reactive = ref dispatchParams.Reactive; @@ -241,7 +215,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -253,7 +227,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Compute Luminance Instability", contextDescription.Shaders.lumaInstabilityPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; @@ -270,7 +244,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -291,7 +265,7 @@ namespace FidelityFX.FSR3 #endif } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { #if UNITY_2021_2_OR_NEWER if (dispatchParams.EnableSharpening) @@ -334,7 +308,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -350,7 +324,7 @@ namespace FidelityFX.FSR3 InitComputeShader("RCAS Sharpening", contextDescription.Shaders.sharpenPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); @@ -362,7 +336,7 @@ namespace FidelityFX.FSR3 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); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -378,7 +352,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Auto-Generate Reactive Mask", contextDescription.Shaders.autoGenReactivePass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { } @@ -414,7 +388,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Auto-Generate Transparency & Composition Mask", contextDescription.Shaders.tcrAutoGenPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var color = ref dispatchParams.Color; ref var motionVectors = ref dispatchParams.MotionVectors; @@ -438,7 +412,7 @@ namespace FidelityFX.FSR3 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); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } @@ -451,7 +425,7 @@ namespace FidelityFX.FSR3 InitComputeShader("Debug View", contextDescription.Shaders.debugViewPass); } - protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, in Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ) { ref var exposure = ref dispatchParams.Exposure; commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks); @@ -465,7 +439,7 @@ namespace FidelityFX.FSR3 commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, dispatchZ); } } #endif