From 3a65d37c416845dc5936834804e7d0c59c5795a7 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 9 Jul 2024 22:42:58 +0200 Subject: [PATCH] Implemented debug view pass --- Assets/Fsr3UpscalerAssets.asset | 1 + Assets/Scripts/Core/Fsr3UpscalerAssets.cs | 14 ++++++++ Assets/Scripts/Core/Fsr3UpscalerContext.cs | 16 ++++++++- Assets/Scripts/Core/Fsr3UpscalerPass.cs | 28 +++++++++++++++ Assets/Scripts/Fsr3UpscalerImageEffect.cs | 7 +++- .../ffx_fsr3upscaler_debug_view_pass.compute | 35 +++++++++++++++++++ ..._fsr3upscaler_debug_view_pass.compute.meta | 8 +++++ 7 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute create mode 100644 Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute.meta diff --git a/Assets/Fsr3UpscalerAssets.asset b/Assets/Fsr3UpscalerAssets.asset index abc0b6d..dba6d13 100644 --- a/Assets/Fsr3UpscalerAssets.asset +++ b/Assets/Fsr3UpscalerAssets.asset @@ -23,3 +23,4 @@ MonoBehaviour: sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3} autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3} tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3} + debugViewPass: {fileID: 7200000, guid: cb24a71d54164c54eb5e86839acd48c5, type: 3} diff --git a/Assets/Scripts/Core/Fsr3UpscalerAssets.cs b/Assets/Scripts/Core/Fsr3UpscalerAssets.cs index 1167481..93a8177 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerAssets.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerAssets.cs @@ -46,6 +46,7 @@ namespace FidelityFX sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass"), autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass"), tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass"), + debugViewPass = FindComputeShader("ffx_fsr3upscaler_debug_view_pass"), }; } @@ -120,6 +121,13 @@ namespace FidelityFX /// The compute shader used to auto-generate a transparency & composition mask. /// public ComputeShader tcrAutoGenPass; + +#if UNITY_EDITOR || DEVELOPMENT_BUILD + /// + /// The compute shader used to display a debug view. + /// + public ComputeShader debugViewPass; +#endif /// /// Returns a copy of this class and its contents. @@ -148,6 +156,9 @@ namespace FidelityFX sharpenPass = Object.Instantiate(sharpenPass), autoGenReactivePass = Object.Instantiate(autoGenReactivePass), tcrAutoGenPass = Object.Instantiate(tcrAutoGenPass), +#if UNITY_EDITOR || DEVELOPMENT_BUILD + debugViewPass = Object.Instantiate(debugViewPass), +#endif }; } @@ -167,6 +178,9 @@ namespace FidelityFX Object.Destroy(sharpenPass); Object.Destroy(autoGenReactivePass); Object.Destroy(tcrAutoGenPass); +#if UNITY_EDITOR || DEVELOPMENT_BUILD + Object.Destroy(debugViewPass); +#endif } } } diff --git a/Assets/Scripts/Core/Fsr3UpscalerContext.cs b/Assets/Scripts/Core/Fsr3UpscalerContext.cs index 6b0b8f8..54fb83b 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerContext.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerContext.cs @@ -48,6 +48,9 @@ namespace FidelityFX private Fsr3UpscalerPass _sharpenPass; private Fsr3UpscalerPass _generateReactivePass; private Fsr3UpscalerPass _tcrAutogeneratePass; +#if UNITY_EDITOR || DEVELOPMENT_BUILD + private Fsr3UpscalerPass _debugViewPass; +#endif private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); @@ -110,10 +113,16 @@ namespace FidelityFX _sharpenPass = new Fsr3UpscalerSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer); _generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); _tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer); +#if UNITY_EDITOR || DEVELOPMENT_BUILD + _debugViewPass = new Fsr3UpscalerDebugViewPass(_contextDescription, _resources, _upscalerConstantsBuffer); +#endif } public void Destroy() { +#if UNITY_EDITOR || DEVELOPMENT_BUILD + DestroyPass(ref _debugViewPass); +#endif DestroyPass(ref _tcrAutogeneratePass); DestroyPass(ref _generateReactivePass); DestroyPass(ref _lumaPyramidPass); @@ -269,7 +278,12 @@ namespace FidelityFX _sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY); } - // TODO: debug view pass +#if UNITY_EDITOR || DEVELOPMENT_BUILD + if ((dispatchParams.Flags & Fsr3Upscaler.DispatchFlags.DrawDebugView) != 0) + { + _debugViewPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY); + } +#endif _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; diff --git a/Assets/Scripts/Core/Fsr3UpscalerPass.cs b/Assets/Scripts/Core/Fsr3UpscalerPass.cs index cfa2f0e..4576331 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerPass.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerPass.cs @@ -449,4 +449,32 @@ namespace FidelityFX commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); } } + +#if UNITY_EDITOR || DEVELOPMENT_BUILD + internal class Fsr3UpscalerDebugViewPass : Fsr3UpscalerPass + { + public Fsr3UpscalerDebugViewPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + : base(contextDescription, resources, constants) + { + InitComputeShader("Debug View", contextDescription.Shaders.debugViewPass); + } + + 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.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedVelocity); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedDepth, Resources.DilatedDepth); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex]); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + + ref var output = ref dispatchParams.Output; + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); + + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + } + } +#endif } diff --git a/Assets/Scripts/Fsr3UpscalerImageEffect.cs b/Assets/Scripts/Fsr3UpscalerImageEffect.cs index d22a336..08b13d8 100644 --- a/Assets/Scripts/Fsr3UpscalerImageEffect.cs +++ b/Assets/Scripts/Fsr3UpscalerImageEffect.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2023 Nico de Poel +// Copyright (c) 2024 Nico de Poel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -54,6 +54,10 @@ namespace FidelityFX [Tooltip("Optional 1x1 texture containing the exposure value for the current frame.")] public Texture exposure = null; + [Header("Debug")] + [Tooltip("Enable a debug view to analyze the upscaling process.")] + public bool enableDebugView = false; + [Header("Reactivity, Transparency & Composition")] [Tooltip("Optional texture to control the influence of the current frame on the reconstructed output. If unset, either an auto-generated or a default cleared reactive mask will be used.")] public Texture reactiveMask = null; @@ -332,6 +336,7 @@ namespace FidelityFX _dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity _dispatchDescription.Reset = _resetHistory; + _dispatchDescription.Flags = enableDebugView ? Fsr3Upscaler.DispatchFlags.DrawDebugView : 0; _resetHistory = false; // Set up the parameters for the optional experimental auto-TCR feature diff --git a/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute b/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute new file mode 100644 index 0000000..45225cc --- /dev/null +++ b/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute @@ -0,0 +1,35 @@ +// Copyright (c) 2024 Nico de Poel +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#pragma kernel CS + +#pragma multi_compile_local __ FFX_HALF +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH +#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP + +#include "ffx_fsr3upscaler_unity_common.cginc" + +#include "shaders/ffx_fsr3upscaler_debug_view_pass.hlsl" diff --git a/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute.meta b/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute.meta new file mode 100644 index 0000000..f90cac3 --- /dev/null +++ b/Assets/Shaders/FSR3/ffx_fsr3upscaler_debug_view_pass.compute.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cb24a71d54164c54eb5e86839acd48c5 +ComputeShaderImporter: + externalObjects: {} + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: