diff --git a/Assets/Scripts/Core/Fsr3UpscalerContext.cs b/Assets/Scripts/Core/Fsr3UpscalerContext.cs index be5955e..d7a86c3 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerContext.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerContext.cs @@ -38,12 +38,14 @@ namespace FidelityFX private Fsr3Upscaler.ContextDescription _contextDescription; private CommandBuffer _commandBuffer; - private Fsr3UpscalerPass _depthClipPass; - private Fsr3UpscalerPass _reconstructPreviousDepthPass; - private Fsr3UpscalerPass _lockPass; + private Fsr3UpscalerPass _prepareInputsPass; + private Fsr3UpscalerPass _lumaPyramidPass; + private Fsr3UpscalerPass _shadingChangePyramidPass; + private Fsr3UpscalerPass _shadingChangePass; + private Fsr3UpscalerPass _prepareReactivityPass; + private Fsr3UpscalerPass _lumaInstabilityPass; private Fsr3UpscalerPass _accumulatePass; private Fsr3UpscalerPass _sharpenPass; - private Fsr3UpscalerPass _computeLuminancePyramidPass; private Fsr3UpscalerPass _generateReactivePass; private Fsr3UpscalerPass _tcrAutogeneratePass; @@ -98,10 +100,12 @@ namespace FidelityFX private void CreatePasses() { - _computeLuminancePyramidPass = new Fsr3UpscalerComputeLuminancePyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer); - _reconstructPreviousDepthPass = new Fsr3UpscalerReconstructPreviousDepthPass(_contextDescription, _resources, _upscalerConstantsBuffer); - _depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer); - _lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _upscalerConstantsBuffer); + _prepareInputsPass = new Fsr3UpscalerPrepareInputsPass(_contextDescription, _resources, _upscalerConstantsBuffer); + _lumaPyramidPass = new Fsr3UpscalerLumaPyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer); + _shadingChangePyramidPass = new Fsr3UpscalerShadingChangePyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer); + _shadingChangePass = new Fsr3UpscalerShadingChangePass(_contextDescription, _resources, _upscalerConstantsBuffer); + _prepareReactivityPass = new Fsr3UpscalerPrepareReactivityPass(_contextDescription, _resources, _upscalerConstantsBuffer); + _lumaInstabilityPass = new Fsr3UpscalerLumaInstabilityPass(_contextDescription, _resources, _upscalerConstantsBuffer); _accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer); _sharpenPass = new Fsr3UpscalerSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer); _generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); @@ -112,12 +116,14 @@ namespace FidelityFX { DestroyPass(ref _tcrAutogeneratePass); DestroyPass(ref _generateReactivePass); - DestroyPass(ref _computeLuminancePyramidPass); + DestroyPass(ref _lumaPyramidPass); DestroyPass(ref _sharpenPass); DestroyPass(ref _accumulatePass); - DestroyPass(ref _lockPass); - DestroyPass(ref _reconstructPreviousDepthPass); - DestroyPass(ref _depthClipPass); + DestroyPass(ref _prepareReactivityPass); + DestroyPass(ref _shadingChangePass); + DestroyPass(ref _shadingChangePyramidPass); + DestroyPass(ref _lumaInstabilityPass); + DestroyPass(ref _prepareInputsPass); _resources.Destroy(); @@ -239,16 +245,16 @@ namespace FidelityFX } // Compute luminance pyramid - _computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); + _lumaPyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); // Reconstruct previous depth - _reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); + _prepareInputsPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); // Depth clip - _depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); + _prepareReactivityPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); // Create locks - _lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); + _lumaInstabilityPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); // Accumulate _accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY); diff --git a/Assets/Scripts/Core/Fsr3UpscalerPass.cs b/Assets/Scripts/Core/Fsr3UpscalerPass.cs index 3e90dbe..e06a724 100644 --- a/Assets/Scripts/Core/Fsr3UpscalerPass.cs +++ b/Assets/Scripts/Core/Fsr3UpscalerPass.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 @@ -93,17 +93,45 @@ namespace FidelityFX } } } + + internal class Fsr3UpscalerPrepareInputsPass : Fsr3UpscalerPass + { + public Fsr3UpscalerPrepareInputsPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + : base(contextDescription, resources, constants) + { + InitComputeShader("prepare_inputs_pass", contextDescription.Shaders.prepareInputsPass); + } - internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + { + ref var color = ref dispatchParams.Color; + ref var depth = ref dispatchParams.Depth; + ref var motionVectors = ref dispatchParams.MotionVectors; + ref var exposure = ref dispatchParams.Exposure; + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); + + commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); + + commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + } + } + + internal class Fsr3UpscalerLumaPyramidPass : Fsr3UpscalerPass { private readonly ComputeBuffer _spdConstants; - public Fsr3UpscalerComputeLuminancePyramidPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer spdConstants) + public Fsr3UpscalerLumaPyramidPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer spdConstants) : base(contextDescription, resources, constants) { _spdConstants = spdConstants; - InitComputeShader("compute_luminance_pyramid_pass", contextDescription.Shaders.lumaPyramidPass); + InitComputeShader("luma_pyramid_pass", contextDescription.Shaders.lumaPyramidPass); } public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) @@ -123,40 +151,44 @@ namespace FidelityFX } } - internal class Fsr3UpscalerReconstructPreviousDepthPass : Fsr3UpscalerPass + internal class Fsr3UpscalerShadingChangePyramidPass : Fsr3UpscalerPass { - public Fsr3UpscalerReconstructPreviousDepthPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + private readonly ComputeBuffer _spdConstants; + + public Fsr3UpscalerShadingChangePyramidPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer spdConstants) : base(contextDescription, resources, constants) { - InitComputeShader("reconstruct_previous_depth_pass", contextDescription.Shaders.prepareInputsPass); + _spdConstants = spdConstants; + + InitComputeShader("shading_change_pyramid_pass", contextDescription.Shaders.shadingChangePyramidPass); } public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { - ref var color = ref dispatchParams.Color; - ref var depth = ref dispatchParams.Depth; - ref var motionVectors = ref dispatchParams.MotionVectors; - ref var exposure = ref dispatchParams.Exposure; - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); - - commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); - - commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf()); - - commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); + throw new NotImplementedException(); } } - internal class Fsr3UpscalerDepthClipPass : Fsr3UpscalerPass + internal class Fsr3UpscalerShadingChangePass : Fsr3UpscalerPass + { + public Fsr3UpscalerShadingChangePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + : base(contextDescription, resources, constants) + { + InitComputeShader("shading_change_pass", contextDescription.Shaders.shadingChangePass); + } + + public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) + { + throw new NotImplementedException(); + } + } + + internal class Fsr3UpscalerPrepareReactivityPass : Fsr3UpscalerPass { - public Fsr3UpscalerDepthClipPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + public Fsr3UpscalerPrepareReactivityPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("depth_clip_pass", contextDescription.Shaders.prepareReactivityPass); + InitComputeShader("prepare_reactivity_pass", contextDescription.Shaders.prepareReactivityPass); } public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) @@ -186,12 +218,12 @@ namespace FidelityFX } } - internal class Fsr3UpscalerLockPass : Fsr3UpscalerPass + internal class Fsr3UpscalerLumaInstabilityPass : Fsr3UpscalerPass { - public Fsr3UpscalerLockPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) + public Fsr3UpscalerLumaInstabilityPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { - InitComputeShader("lock_pass", contextDescription.Shaders.lumaInstabilityPass); + InitComputeShader("luma_instability_pass", contextDescription.Shaders.lumaInstabilityPass); } public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)