diff --git a/Assets/Scripts/Core/Fsr3UpscalerPass.cs b/Assets/Scripts/Core/Fsr3UpscalerPass.cs index f92c280..ba1ee0a 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerPass.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerPass.cs @@ -21,6 +21,7 @@ using System; using System.Runtime.InteropServices; using UnityEngine; +using UnityEngine.Profiling; using UnityEngine.Rendering; namespace FidelityFX @@ -40,6 +41,8 @@ namespace FidelityFX protected ComputeShader ComputeShader; protected int KernelIndex; + + protected CustomSampler Sampler; protected Fsr3UpscalerPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) { @@ -52,8 +55,15 @@ namespace FidelityFX { } - public abstract void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); + 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); @@ -68,6 +78,7 @@ namespace FidelityFX 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+ @@ -99,10 +110,10 @@ namespace FidelityFX public Fsr3UpscalerPrepareInputsPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("prepare_inputs_pass", contextDescription.Shaders.prepareInputsPass); + InitComputeShader("Prepare Inputs", contextDescription.Shaders.prepareInputsPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; ref var depth = ref dispatchParams.Depth; @@ -132,10 +143,10 @@ namespace FidelityFX { _spdConstants = spdConstants; - InitComputeShader("luma_pyramid_pass", contextDescription.Shaders.lumaPyramidPass); + InitComputeShader("Compute Luminance Pyramid", contextDescription.Shaders.lumaPyramidPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFarthestDepth, Fsr3ShaderIDs.UavFarthestDepth); @@ -165,10 +176,10 @@ namespace FidelityFX { _spdConstants = spdConstants; - InitComputeShader("shading_change_pyramid_pass", contextDescription.Shaders.shadingChangePyramidPass); + InitComputeShader("Compute Shading Change Pyramid", contextDescription.Shaders.shadingChangePyramidPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var exposure = ref dispatchParams.Exposure; @@ -199,10 +210,10 @@ namespace FidelityFX public Fsr3UpscalerShadingChangePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("shading_change_pass", contextDescription.Shaders.shadingChangePass); + InitComputeShader("Compute Shading Change", contextDescription.Shaders.shadingChangePass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvSpdMips, Resources.SpdMips); @@ -217,10 +228,10 @@ namespace FidelityFX public Fsr3UpscalerPrepareReactivityPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("prepare_reactivity_pass", contextDescription.Shaders.prepareReactivityPass); + InitComputeShader("Prepare Reactivity", contextDescription.Shaders.prepareReactivityPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var exposure = ref dispatchParams.Exposure; ref var reactive = ref dispatchParams.Reactive; @@ -249,10 +260,10 @@ namespace FidelityFX public Fsr3UpscalerLumaInstabilityPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("luma_instability_pass", contextDescription.Shaders.lumaInstabilityPass); + InitComputeShader("Compute Luminance Instability", contextDescription.Shaders.lumaInstabilityPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var exposure = ref dispatchParams.Exposure; @@ -283,13 +294,13 @@ namespace FidelityFX public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("accumulate_pass", contextDescription.Shaders.accumulatePass); + InitComputeShader("Accumulate", contextDescription.Shaders.accumulatePass); #if UNITY_2021_2_OR_NEWER _sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword); #endif } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { #if UNITY_2021_2_OR_NEWER if (dispatchParams.EnableSharpening) @@ -344,10 +355,10 @@ namespace FidelityFX { _rcasConstants = rcasConstants; - InitComputeShader("rcas_pass", contextDescription.Shaders.sharpenPass); + InitComputeShader("RCAS Sharpening", contextDescription.Shaders.sharpenPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var exposure = ref dispatchParams.Exposure; commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); @@ -372,15 +383,17 @@ namespace FidelityFX { _generateReactiveConstants = generateReactiveConstants; - InitComputeShader("autogen_reactive_pass", contextDescription.Shaders.autoGenReactivePass); + InitComputeShader("Auto-Generate Reactive Mask", contextDescription.Shaders.autoGenReactivePass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { } public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY) { + commandBuffer.BeginSample(Sampler); + ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; ref var color = ref dispatchParams.ColorPreUpscale; ref var reactive = ref dispatchParams.OutReactive; @@ -392,6 +405,8 @@ namespace FidelityFX commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf()); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + + commandBuffer.EndSample(Sampler); } } @@ -404,10 +419,10 @@ namespace FidelityFX { _tcrAutogenerateConstants = tcrAutogenerateConstants; - InitComputeShader("tcr_autogen_pass", contextDescription.Shaders.tcrAutoGenPass); + InitComputeShader("Auto-Generate Transparency & Composition Mask", contextDescription.Shaders.tcrAutoGenPass); } - public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { ref var color = ref dispatchParams.Color; ref var motionVectors = ref dispatchParams.MotionVectors;