Browse Source

Added FSR 3.1 implementation and moved it plus FSR 2.2 into a separate package.

fsr3.1
Nico de Poel 2 years ago
parent
commit
de482efcbf
  1. 26
      Assets/FSR3 Upscaler Assets.asset
  2. 0
      Assets/FSR3 Upscaler Assets.asset.meta
  3. 23
      Assets/Fsr3UpscalerAssets.asset
  4. 80
      Assets/Scripts/Core/Fsr3ShaderIDs.cs
  5. 11
      Assets/Scripts/Fsr3UpscalerImageEffect.cs
  6. 7
      Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_depth_clip_pass.hlsl.meta
  7. 7
      Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_lock_pass.hlsl.meta
  8. 7
      Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_reconstruct_previous_depth_pass.hlsl.meta
  9. 338
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core_cpu.h
  10. 65
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_compute_luminance_pyramid.h.meta
  11. 65
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_depth_clip.h.meta
  12. 65
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_lock.h.meta
  13. 65
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_postprocess_lock_status.h.meta
  14. 65
      Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_reconstruct_dilated_velocity_and_previous_depth.h.meta
  15. 67
      Assets/Shaders/FSR3/shaders/fsr3upscaler/fsr1/ffx_fsr1.h.meta
  16. 67
      Assets/Shaders/FSR3/shaders/fsr3upscaler/spd/ffx_spd.h.meta
  17. 2
      Packages/fidelityfx.fsr/Runtime.meta
  18. 8
      Packages/fidelityfx.fsr/Runtime/Common.meta
  19. 55
      Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs
  20. 11
      Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs.meta
  21. 8
      Packages/fidelityfx.fsr/Runtime/FSR2.meta
  22. 302
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs
  23. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs.meta
  24. 41
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.cs
  25. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.cs.meta
  26. 81
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs
  27. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs.meta
  28. 618
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs
  29. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs.meta
  30. 380
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs
  31. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs.meta
  32. 38
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.cs
  33. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.cs.meta
  34. 80
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs
  35. 0
      Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs.meta
  36. 2
      Packages/fidelityfx.fsr/Runtime/FSR3.meta
  37. 91
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs
  38. 3
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs.meta
  39. 70
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.cs
  40. 3
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.cs.meta
  41. 177
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs
  42. 11
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs.meta
  43. 4
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.cs
  44. 11
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.cs.meta
  45. 166
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.cs
  46. 3
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.cs.meta
  47. 254
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerPass.cs
  48. 3
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerPass.cs.meta
  49. 245
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs
  50. 3
      Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs.meta
  51. 14
      Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef
  52. 7
      Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef.meta
  53. 2
      Packages/fidelityfx.fsr/Shaders.meta
  54. 41
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute
  55. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute.meta
  56. 14
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute
  57. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute.meta
  58. 14
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute
  59. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute.meta
  60. 32
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute
  61. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute.meta
  62. 32
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute
  63. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute.meta
  64. 31
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute
  65. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute.meta
  66. 33
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute
  67. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute.meta
  68. 32
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute
  69. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute.meta
  70. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute
  71. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute.meta
  72. 9
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute
  73. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute.meta
  74. 29
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute
  75. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute.meta
  76. 29
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute
  77. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute.meta
  78. 22
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute
  79. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute.meta
  80. 9
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute
  81. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute.meta
  82. 29
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute
  83. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute.meta
  84. 10
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute
  85. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute.meta
  86. 29
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute
  87. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute.meta
  88. 32
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute
  89. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute.meta
  90. 8
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute
  91. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute.meta
  92. 60
      Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc
  93. 0
      Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc.meta
  94. 2
      Packages/fidelityfx.fsr/Shaders/shaders.meta
  95. 54
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h
  96. 11
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h.meta
  97. 14
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h
  98. 11
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h.meta
  99. 318
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h
  100. 11
      Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h.meta

26
Assets/FSR3 Upscaler Assets.asset

@ -0,0 +1,26 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2dbcc608a4754d049a14a0bcce2eb40b, type: 3}
m_Name: FSR3 Upscaler Assets
m_EditorClassIdentifier:
shaders:
prepareInputsPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3}
lumaPyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3}
shadingChangePyramidPass: {fileID: 7200000, guid: 251e663738905fa4d8817001682d802f, type: 3}
shadingChangePass: {fileID: 7200000, guid: 9a2bff2f97619ed4989d9b0577ba0641, type: 3}
prepareReactivityPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3}
lumaInstabilityPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3}
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3}
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}

0
Assets/Fsr3UpscalerAssets.asset.meta → Assets/FSR3 Upscaler Assets.asset.meta

23
Assets/Fsr3UpscalerAssets.asset

@ -1,23 +0,0 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: db26e15a33db6ab42a38daab0ba2712f, type: 3}
m_Name: Fsr3UpscalerAssets
m_EditorClassIdentifier:
shaders:
computeLuminancePyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3}
reconstructPreviousDepthPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3}
depthClipPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3}
lockPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3}
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3}
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3}
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3}
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3}

80
Assets/Scripts/Core/Fsr3ShaderIDs.cs

@ -1,80 +0,0 @@
// Copyright (c) 2023 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.
using UnityEngine;
namespace FidelityFX
{
internal static class Fsr3ShaderIDs
{
// Shader resource views, i.e. read-only bindings
internal static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered");
internal static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only");
internal static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors");
internal static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth");
internal static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure");
internal static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure");
internal static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask");
internal static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask");
internal static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth");
internal static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors");
internal static readonly int SrvPrevDilatedMotionVectors = Shader.PropertyToID("r_previous_dilated_motion_vectors");
internal static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilated_depth");
internal static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color");
internal static readonly int SrvLockStatus = Shader.PropertyToID("r_lock_status");
internal static readonly int SrvLockInputLuma = Shader.PropertyToID("r_lock_input_luma");
internal static readonly int SrvPreparedInputColor = Shader.PropertyToID("r_prepared_input_color");
internal static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history");
internal static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input");
internal static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut");
internal static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips");
internal static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut");
internal static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks");
internal static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha");
internal static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha");
// Unordered access views, i.e. random read/write bindings
internal static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth");
internal static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors");
internal static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilated_depth");
internal static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color");
internal static readonly int UavLockStatus = Shader.PropertyToID("rw_lock_status");
internal static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma");
internal static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks");
internal static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color");
internal static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history");
internal static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output");
internal static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change");
internal static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5");
internal static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks");
internal static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure");
internal static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic");
internal static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive");
internal static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition");
internal static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha");
internal static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha");
// Constant buffer bindings
internal static readonly int CbFsr3Upscaler = Shader.PropertyToID("cbFSR3Upscaler");
internal static readonly int CbSpd = Shader.PropertyToID("cbSPD");
internal static readonly int CbRcas = Shader.PropertyToID("cbRCAS");
internal static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive");
}
}

11
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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // 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.")] [Tooltip("Optional 1x1 texture containing the exposure value for the current frame.")]
public Texture exposure = null; public Texture exposure = null;
[Header("Debug")]
[Tooltip("Enable a debug view to analyze the upscaling process.")]
public bool enableDebugView = false;
[Header("Reactivity, Transparency & Composition")] [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.")] [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; public Texture reactiveMask = null;
@ -326,12 +330,14 @@ namespace FidelityFX
_dispatchDescription.MotionVectorScale.x = -scaledRenderSize.x; _dispatchDescription.MotionVectorScale.x = -scaledRenderSize.x;
_dispatchDescription.MotionVectorScale.y = -scaledRenderSize.y; _dispatchDescription.MotionVectorScale.y = -scaledRenderSize.y;
_dispatchDescription.RenderSize = scaledRenderSize; _dispatchDescription.RenderSize = scaledRenderSize;
_dispatchDescription.UpscaleSize = _displaySize;
_dispatchDescription.FrameTimeDelta = Time.unscaledDeltaTime; _dispatchDescription.FrameTimeDelta = Time.unscaledDeltaTime;
_dispatchDescription.CameraNear = _renderCamera.nearClipPlane; _dispatchDescription.CameraNear = _renderCamera.nearClipPlane;
_dispatchDescription.CameraFar = _renderCamera.farClipPlane; _dispatchDescription.CameraFar = _renderCamera.farClipPlane;
_dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.CameraFovAngleVertical = _renderCamera.fieldOfView * Mathf.Deg2Rad;
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity _dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
_dispatchDescription.Reset = _resetHistory; _dispatchDescription.Reset = _resetHistory;
_dispatchDescription.Flags = enableDebugView ? Fsr3Upscaler.DispatchFlags.DrawDebugView : 0;
_resetHistory = false; _resetHistory = false;
// Set up the parameters for the optional experimental auto-TCR feature // Set up the parameters for the optional experimental auto-TCR feature
@ -390,9 +396,6 @@ namespace FidelityFX
_renderCamera.rect = _originalRect; _renderCamera.rect = _originalRect;
_renderCamera.ResetProjectionMatrix(); _renderCamera.ResetProjectionMatrix();
// Update the input resource descriptions
_dispatchDescription.InputResourceSize = new Vector2Int(src.width, src.height);
_dispatchCommandBuffer.Clear(); _dispatchCommandBuffer.Clear();
if (autoGenerateReactiveMask) if (autoGenerateReactiveMask)

7
Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_depth_clip_pass.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: da435b71cf57e2247b80ae0f0f86d1f8
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_lock_pass.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 98d2cbbda5e90dd4ebd1d70abbb63a09
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Assets/Shaders/FSR3/shaders/ffx_fsr3upscaler_reconstruct_previous_depth_pass.hlsl.meta

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: bafb3726a76b97a49bb343d8a4323754
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

338
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core_cpu.h

@ -1,338 +0,0 @@
// This file is part of the FidelityFX SDK.
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// 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.
/// A define for a true value in a boolean expression.
///
/// @ingroup CPUTypes
#define FFX_TRUE (1)
/// A define for a false value in a boolean expression.
///
/// @ingroup CPUTypes
#define FFX_FALSE (0)
#if !defined(FFX_STATIC)
/// A define to abstract declaration of static variables and functions.
///
/// @ingroup CPUTypes
#define FFX_STATIC static
#endif // #if !defined(FFX_STATIC)
/// @defgroup CPUCore CPU Core
/// Core CPU-side defines and functions
///
/// @ingroup ffxHost
#ifdef __clang__
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
/// Interpret the bit layout of an IEEE-754 floating point value as an unsigned integer.
///
/// @param [in] x A 32bit floating value.
///
/// @returns
/// An unsigned 32bit integer value containing the bit pattern of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxUInt32 ffxAsUInt32(FfxFloat32 x)
{
union
{
FfxFloat32 f;
FfxUInt32 u;
} bits;
bits.f = x;
return bits.u;
}
FFX_STATIC FfxFloat32 ffxDot2(FfxFloat32x2 a, FfxFloat32x2 b)
{
return a[0] * b[0] + a[1] * b[1];
}
FFX_STATIC FfxFloat32 ffxDot3(FfxFloat32x3 a, FfxFloat32x3 b)
{
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
FFX_STATIC FfxFloat32 ffxDot4(FfxFloat32x4 a, FfxFloat32x4 b)
{
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
}
/// Compute the linear interopation between two values.
///
/// Implemented by calling the GLSL <c><i>mix</i></c> instrinsic function. Implements the
/// following math:
///
/// (1 - t) * x + t * y
///
/// @param [in] x The first value to lerp between.
/// @param [in] y The second value to lerp between.
/// @param [in] t The value to determine how much of <c><i>x</i></c> and how much of <c><i>y</i></c>.
///
/// @returns
/// A linearly interpolated value between <c><i>x</i></c> and <c><i>y</i></c> according to <c><i>t</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 ffxLerp(FfxFloat32 x, FfxFloat32 y, FfxFloat32 t)
{
return y * t + (-x * t + x);
}
/// Compute the reciprocal of a value.
///
/// @param [in] x The value to compute the reciprocal for.
///
/// @returns
/// The reciprocal value of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 ffxReciprocal(FfxFloat32 x)
{
return 1.0f / x;
}
/// Compute the square root of a value.
///
/// @param [in] x The first value to compute the min of.
///
/// @returns
/// The the square root of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 ffxSqrt(FfxFloat32 x)
{
return sqrt(x);
}
FFX_STATIC FfxUInt32 AShrSU1(FfxUInt32 a, FfxUInt32 b)
{
return FfxUInt32(FfxInt32(a) >> FfxInt32(b));
}
/// Compute the factional part of a decimal value.
///
/// This function calculates <c><i>x - floor(x)</i></c>.
///
/// @param [in] x The value to compute the fractional part from.
///
/// @returns
/// The fractional part of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 ffxFract(FfxFloat32 x)
{
return x - floor(x);
}
/// Compute the reciprocal square root of a value.
///
/// @param [in] x The value to compute the reciprocal for.
///
/// @returns
/// The reciprocal square root value of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 rsqrt(FfxFloat32 x)
{
return ffxReciprocal(ffxSqrt(x));
}
FFX_STATIC FfxFloat32 ffxMin(FfxFloat32 x, FfxFloat32 y)
{
return x < y ? x : y;
}
FFX_STATIC FfxUInt32 ffxMin(FfxUInt32 x, FfxUInt32 y)
{
return x < y ? x : y;
}
FFX_STATIC FfxFloat32 ffxMax(FfxFloat32 x, FfxFloat32 y)
{
return x > y ? x : y;
}
FFX_STATIC FfxUInt32 ffxMax(FfxUInt32 x, FfxUInt32 y)
{
return x > y ? x : y;
}
/// Clamp a value to a [0..1] range.
///
/// @param [in] x The value to clamp to [0..1] range.
///
/// @returns
/// The clamped version of <c><i>x</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxFloat32 ffxSaturate(FfxFloat32 x)
{
return ffxMin(1.0f, ffxMax(0.0f, x));
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FFX_STATIC void opAAddOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b)
{
d[0] = a[0] + b;
d[1] = a[1] + b;
d[2] = a[2] + b;
return;
}
FFX_STATIC void opACpyF3(FfxFloat32x3 d, FfxFloat32x3 a)
{
d[0] = a[0];
d[1] = a[1];
d[2] = a[2];
return;
}
FFX_STATIC void opAMulF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32x3 b)
{
d[0] = a[0] * b[0];
d[1] = a[1] * b[1];
d[2] = a[2] * b[2];
return;
}
FFX_STATIC void opAMulOneF3(FfxFloat32x3 d, FfxFloat32x3 a, FfxFloat32 b)
{
d[0] = a[0] * b;
d[1] = a[1] * b;
d[2] = a[2] * b;
return;
}
FFX_STATIC void opARcpF3(FfxFloat32x3 d, FfxFloat32x3 a)
{
d[0] = ffxReciprocal(a[0]);
d[1] = ffxReciprocal(a[1]);
d[2] = ffxReciprocal(a[2]);
return;
}
/// Convert FfxFloat32 to half (in lower 16-bits of output).
///
/// This function implements the same fast technique that is documented here: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
///
/// The function supports denormals.
///
/// Some conversion rules are to make computations possibly "safer" on the GPU,
/// -INF & -NaN -> -65504
/// +INF & +NaN -> +65504
///
/// @param [in] f The 32bit floating point value to convert.
///
/// @returns
/// The closest 16bit floating point value to <c><i>f</i></c>.
///
/// @ingroup CPUCore
FFX_STATIC FfxUInt32 f32tof16(FfxFloat32 f)
{
static FfxUInt16 base[512] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400,
0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00, 0x2000, 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00, 0x4000, 0x4400, 0x4800, 0x4c00, 0x5000,
0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00, 0x7000, 0x7400, 0x7800, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff,
0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x7bff, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000,
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8001, 0x8002,
0x8004, 0x8008, 0x8010, 0x8020, 0x8040, 0x8080, 0x8100, 0x8200, 0x8400, 0x8800, 0x8c00, 0x9000, 0x9400, 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00,
0xb000, 0xb400, 0xb800, 0xbc00, 0xc000, 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400, 0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, 0xf000, 0xf400, 0xf800,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff,
0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff, 0xfbff
};
static FfxUInt8 shift[512] = {
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18
};
union
{
FfxFloat32 f;
FfxUInt32 u;
} bits;
bits.f = f;
FfxUInt32 u = bits.u;
FfxUInt32 i = u >> 23;
return (FfxUInt32)(base[i]) + ((u & 0x7fffff) >> shift[i]);
}
/// Pack 2x32-bit floating point values in a single 32bit value.
///
/// This function first converts each component of <c><i>value</i></c> into their nearest 16-bit floating
/// point representation, and then stores the X and Y components in the lower and upper 16 bits of the
/// 32bit unsigned integer respectively.
///
/// @param [in] x A 2-dimensional floating point value to convert and pack.
///
/// @returns
/// A packed 32bit value containing 2 16bit floating point values.
///
/// @ingroup CPUCore
FFX_STATIC FfxUInt32 packHalf2x16(FfxFloat32x2 x)
{
return f32tof16(x[0]) + (f32tof16(x[1]) << 16);
}

65
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_compute_luminance_pyramid.h.meta

@ -1,65 +0,0 @@
fileFormatVersion: 2
guid: 61bd10363d44ee2478461c9e9efbcb67
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

65
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_depth_clip.h.meta

@ -1,65 +0,0 @@
fileFormatVersion: 2
guid: 7c662249d70c4434da4f2da00e432c38
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

65
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_lock.h.meta

@ -1,65 +0,0 @@
fileFormatVersion: 2
guid: c7e9f53dd040b2645af5ccd936a94b0e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

65
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_postprocess_lock_status.h.meta

@ -1,65 +0,0 @@
fileFormatVersion: 2
guid: 67a8b72ceb93d634f883b086fdccb348
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

65
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_fsr3upscaler_reconstruct_dilated_velocity_and_previous_depth.h.meta

@ -1,65 +0,0 @@
fileFormatVersion: 2
guid: c8b3854bad30a8b40babc5a9805f294e
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

67
Assets/Shaders/FSR3/shaders/fsr3upscaler/fsr1/ffx_fsr1.h.meta

@ -1,67 +0,0 @@
fileFormatVersion: 2
guid: 628e23510f46ef44bbf0035ce9a63be0
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

67
Assets/Shaders/FSR3/shaders/fsr3upscaler/spd/ffx_spd.h.meta

@ -1,67 +0,0 @@
fileFormatVersion: 2
guid: face65176ee3b82498bd0b8fed0ddacd
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
: Any
second:
enabled: 0
settings:
Exclude Editor: 1
Exclude GameCoreScarlett: 1
Exclude GameCoreXboxOne: 1
Exclude Linux64: 1
Exclude OSXUniversal: 1
Exclude PS4: 1
Exclude PS5: 1
Exclude Win: 1
Exclude Win64: 1
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 0
settings:
CPU: None
userData:
assetBundleName:
assetBundleVariant:

2
Assets/Scripts/Core.meta → Packages/fidelityfx.fsr/Runtime.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 975411b519480574290d74d7e34d119d
guid: b64c5aa2a705139438e2bcc551a02b97
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

8
Packages/fidelityfx.fsr/Runtime/Common.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e87a0efd0d1d4644abdef16b5a28bd0f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

55
Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs

@ -0,0 +1,55 @@
// 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.
using UnityEngine.Rendering;
namespace FidelityFX
{
/// <summary>
/// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader.
/// </summary>
public readonly struct ResourceView
{
/// <summary>
/// This value is the equivalent of not setting any value at all; all struct fields will have their default values.
/// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader.
/// </summary>
public static readonly ResourceView Unassigned = new ResourceView(default);
/// <summary>
/// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture.
/// Binding this to a shader can be seen as setting the texture variable inside the shader to null.
/// </summary>
public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None);
public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
{
RenderTarget = renderTarget;
SubElement = subElement;
MipLevel = mipLevel;
}
public bool IsValid => !RenderTarget.Equals(default);
public readonly RenderTargetIdentifier RenderTarget;
public readonly RenderTextureSubElement SubElement;
public readonly int MipLevel;
}
}

11
Packages/fidelityfx.fsr/Runtime/Common/ResourceView.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eb9fdfac33a070740b66520d88f43ab7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Packages/fidelityfx.fsr/Runtime/FSR2.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cce3e495c6ece2145b041d0a6e43bb26
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

302
Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs

@ -0,0 +1,302 @@
// 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.
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
namespace FidelityFX
{
/// <summary>
/// A collection of helper functions and data structures required by the FSR2 process.
/// </summary>
public static class Fsr2
{
/// <summary>
/// Creates a new FSR2 context with standard parameters that are appropriate for the current platform.
/// </summary>
public static Fsr2Context CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, Fsr2Shaders shaders, InitializationFlags flags = 0)
{
if (SystemInfo.usesReversedZBuffer)
flags |= InitializationFlags.EnableDepthInverted;
else
flags &= ~InitializationFlags.EnableDepthInverted;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
flags |= InitializationFlags.EnableDebugChecking;
#endif
Debug.Log($"Setting up FSR2 with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, flags: {flags}");
var contextDescription = new ContextDescription
{
Flags = flags,
DisplaySize = displaySize,
MaxRenderSize = maxRenderSize,
Shaders = shaders,
};
var context = new Fsr2Context();
context.Create(contextDescription);
return context;
}
public static float GetUpscaleRatioFromQualityMode(QualityMode qualityMode)
{
switch (qualityMode)
{
case QualityMode.NativeAA:
return 1.0f;
case QualityMode.UltraQuality:
return 1.2f;
case QualityMode.Quality:
return 1.5f;
case QualityMode.Balanced:
return 1.7f;
case QualityMode.Performance:
return 2.0f;
case QualityMode.UltraPerformance:
return 3.0f;
default:
return 1.0f;
}
}
public static void GetRenderResolutionFromQualityMode(
out int renderWidth, out int renderHeight,
int displayWidth, int displayHeight, QualityMode qualityMode)
{
float ratio = GetUpscaleRatioFromQualityMode(qualityMode);
renderWidth = Mathf.RoundToInt(displayWidth / ratio);
renderHeight = Mathf.RoundToInt(displayHeight / ratio);
}
public static float GetMipmapBiasOffset(int renderWidth, int displayWidth)
{
return Mathf.Log((float)renderWidth / displayWidth, 2.0f) - 1.0f;
}
public static int GetJitterPhaseCount(int renderWidth, int displayWidth)
{
const float basePhaseCount = 8.0f;
int jitterPhaseCount = (int)(basePhaseCount * Mathf.Pow((float)displayWidth / renderWidth, 2.0f));
return jitterPhaseCount;
}
public static void GetJitterOffset(out float outX, out float outY, int index, int phaseCount)
{
outX = Halton((index % phaseCount) + 1, 2) - 0.5f;
outY = Halton((index % phaseCount) + 1, 3) - 0.5f;
}
// Calculate halton number for index and base.
private static float Halton(int index, int @base)
{
float f = 1.0f, result = 0.0f;
for (int currentIndex = index; currentIndex > 0;) {
f /= @base;
result += f * (currentIndex % @base);
currentIndex = (int)Mathf.Floor((float)currentIndex / @base);
}
return result;
}
public static float Lanczos2(float value)
{
return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value));
}
#if !UNITY_2021_1_OR_NEWER
internal static void SetBufferData(this CommandBuffer commandBuffer, ComputeBuffer computeBuffer, Array data)
{
commandBuffer.SetComputeBufferData(computeBuffer, data);
}
#endif
public enum QualityMode
{
NativeAA = 0,
UltraQuality = 1,
Quality = 2,
Balanced = 3,
Performance = 4,
UltraPerformance = 5,
}
[Flags]
public enum InitializationFlags
{
EnableHighDynamicRange = 1 << 0,
EnableDisplayResolutionMotionVectors = 1 << 1,
EnableMotionVectorsJitterCancellation = 1 << 2,
EnableDepthInverted = 1 << 3,
EnableDepthInfinite = 1 << 4,
EnableAutoExposure = 1 << 5,
EnableDynamicResolution = 1 << 6,
EnableFP16Usage = 1 << 7,
EnableDebugChecking = 1 << 8,
}
/// <summary>
/// A structure encapsulating the parameters required to initialize FidelityFX Super Resolution 2 upscaling.
/// </summary>
public struct ContextDescription
{
public InitializationFlags Flags;
public Vector2Int MaxRenderSize;
public Vector2Int DisplaySize;
public Fsr2Shaders Shaders;
}
/// <summary>
/// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2.
/// </summary>
public class DispatchDescription
{
public ResourceView Color;
public ResourceView Depth;
public ResourceView MotionVectors;
public ResourceView Exposure; // optional
public ResourceView Reactive; // optional
public ResourceView TransparencyAndComposition; // optional
public ResourceView Output;
public Vector2 JitterOffset;
public Vector2 MotionVectorScale;
public Vector2Int RenderSize;
public Vector2Int InputResourceSize;
public bool EnableSharpening;
public float Sharpness;
public float FrameTimeDelta; // in seconds
public float PreExposure;
public bool Reset;
public float CameraNear;
public float CameraFar;
public float CameraFovAngleVertical;
public float ViewSpaceToMetersFactor;
public bool UseTextureArrays; // Enable texture array bindings, primarily used for HDRP and XR
// EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive;
public ResourceView ColorOpaqueOnly;
public float AutoTcThreshold = 0.05f;
public float AutoTcScale = 1.0f;
public float AutoReactiveScale = 5.0f;
public float AutoReactiveMax = 0.9f;
}
/// <summary>
/// A structure encapsulating the parameters for automatic generation of a reactive mask.
/// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR2 demo project.
/// </summary>
public class GenerateReactiveDescription
{
public ResourceView ColorOpaqueOnly;
public ResourceView ColorPreUpscale;
public ResourceView OutReactive;
public Vector2Int RenderSize;
public float Scale = 0.5f;
public float CutoffThreshold = 0.2f;
public float BinaryValue = 0.9f;
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax;
}
[Flags]
public enum GenerateReactiveFlags
{
ApplyTonemap = 1 << 0,
ApplyInverseTonemap = 1 << 1,
ApplyThreshold = 1 << 2,
UseComponentsMax = 1 << 3,
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct UpscalerConstants
{
public Vector2Int renderSize;
public Vector2Int maxRenderSize;
public Vector2Int displaySize;
public Vector2Int inputColorResourceDimensions;
public Vector2Int lumaMipDimensions;
public int lumaMipLevelToUse;
public int frameIndex;
public Vector4 deviceToViewDepth;
public Vector2 jitterOffset;
public Vector2 motionVectorScale;
public Vector2 downscaleFactor;
public Vector2 motionVectorJitterCancellation;
public float preExposure;
public float previousFramePreExposure;
public float tanHalfFOV;
public float jitterPhaseCount;
public float deltaTime;
public float dynamicResChangeFactor;
public float viewSpaceToMetersFactor;
public float padding;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct SpdConstants
{
public uint mips;
public uint numWorkGroups;
public uint workGroupOffsetX, workGroupOffsetY;
public uint renderSizeX, renderSizeY;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct GenerateReactiveConstants
{
public float scale;
public float threshold;
public float binaryValue;
public uint flags;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct GenerateReactiveConstants2
{
public float autoTcThreshold;
public float autoTcScale;
public float autoReactiveScale;
public float autoReactiveMax;
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct RcasConstants
{
public RcasConstants(uint sharpness, uint halfSharp)
{
this.sharpness = sharpness;
this.halfSharp = halfSharp;
dummy0 = dummy1 = 0;
}
public readonly uint sharpness;
public readonly uint halfSharp;
public readonly uint dummy0;
public readonly uint dummy1;
}
}
}

0
Assets/Scripts/Core/Fsr3Upscaler.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2.cs.meta

41
Assets/Scripts/Core/Fsr3UpscalerAssets.cs → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -23,26 +23,27 @@ using UnityEngine;
namespace FidelityFX namespace FidelityFX
{ {
/// <summary> /// <summary>
/// Scriptable object containing all shader resources required by FidelityFX Super Resolution 3 (FSR3) Upscaler.
/// Scriptable object containing all shader resources required by FidelityFX Super Resolution 2 (FSR2).
/// These can be stored in an asset file and referenced from a scene or prefab, avoiding the need to load the shaders from a Resources folder. /// These can be stored in an asset file and referenced from a scene or prefab, avoiding the need to load the shaders from a Resources folder.
/// </summary> /// </summary>
public class Fsr3UpscalerAssets : ScriptableObject
[CreateAssetMenu(fileName = "FSR2 Assets", menuName = "FidelityFX/FSR2 Assets", order = 1102)]
public class Fsr2Assets : ScriptableObject
{ {
public Fsr3UpscalerShaders shaders;
public Fsr2Shaders shaders;
#if UNITY_EDITOR #if UNITY_EDITOR
private void Reset() private void Reset()
{ {
shaders = new Fsr3UpscalerShaders
shaders = new Fsr2Shaders
{ {
computeLuminancePyramidPass = FindComputeShader("ffx_fsr3upscaler_compute_luminance_pyramid_pass"),
reconstructPreviousDepthPass = FindComputeShader("ffx_fsr3upscaler_reconstruct_previous_depth_pass"),
depthClipPass = FindComputeShader("ffx_fsr3upscaler_depth_clip_pass"),
lockPass = FindComputeShader("ffx_fsr3upscaler_lock_pass"),
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass"),
sharpenPass = FindComputeShader("ffx_fsr3upscaler_rcas_pass"),
autoGenReactivePass = FindComputeShader("ffx_fsr3upscaler_autogen_reactive_pass"),
tcrAutoGenPass = FindComputeShader("ffx_fsr3upscaler_tcr_autogen_pass"),
computeLuminancePyramidPass = FindComputeShader("ffx_fsr2_compute_luminance_pyramid_pass"),
reconstructPreviousDepthPass = FindComputeShader("ffx_fsr2_reconstruct_previous_depth_pass"),
depthClipPass = FindComputeShader("ffx_fsr2_depth_clip_pass"),
lockPass = FindComputeShader("ffx_fsr2_lock_pass"),
accumulatePass = FindComputeShader("ffx_fsr2_accumulate_pass"),
sharpenPass = FindComputeShader("ffx_fsr2_rcas_pass"),
autoGenReactivePass = FindComputeShader("ffx_fsr2_autogen_reactive_pass"),
tcrAutoGenPass = FindComputeShader("ffx_fsr2_tcr_autogen_pass"),
}; };
} }
@ -59,10 +60,10 @@ namespace FidelityFX
} }
/// <summary> /// <summary>
/// All the compute shaders used by the FSR3 Upscaler.
/// All the compute shaders used by FSR2.
/// </summary> /// </summary>
[System.Serializable] [System.Serializable]
public class Fsr3UpscalerShaders
public class Fsr2Shaders
{ {
/// <summary> /// <summary>
/// The compute shader used by the luminance pyramid computation pass. /// The compute shader used by the luminance pyramid computation pass.
@ -107,19 +108,19 @@ namespace FidelityFX
/// <summary> /// <summary>
/// Returns a copy of this class and its contents. /// Returns a copy of this class and its contents.
/// </summary> /// </summary>
public Fsr3UpscalerShaders Clone()
public Fsr2Shaders Clone()
{ {
return (Fsr3UpscalerShaders)MemberwiseClone();
return (Fsr2Shaders)MemberwiseClone();
} }
/// <summary> /// <summary>
/// Returns a copy of this class with clones of all its shaders. /// Returns a copy of this class with clones of all its shaders.
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
/// This can be useful if you're running multiple FSR2 instances with different shader configurations.
/// Be sure to clean up these clones through Dispose once you're done with them. /// Be sure to clean up these clones through Dispose once you're done with them.
/// </summary> /// </summary>
public Fsr3UpscalerShaders DeepCopy()
public Fsr2Shaders DeepCopy()
{ {
return new Fsr3UpscalerShaders
return new Fsr2Shaders
{ {
computeLuminancePyramidPass = Object.Instantiate(computeLuminancePyramidPass), computeLuminancePyramidPass = Object.Instantiate(computeLuminancePyramidPass),
reconstructPreviousDepthPass = Object.Instantiate(reconstructPreviousDepthPass), reconstructPreviousDepthPass = Object.Instantiate(reconstructPreviousDepthPass),

0
Assets/Scripts/Core/Fsr3UpscalerAssets.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Assets.cs.meta

81
Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs

@ -0,0 +1,81 @@
// 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.
using UnityEngine;
namespace FidelityFX
{
/// <summary>
/// A collection of callbacks required by the FSR2 process.
/// This allows some customization by the game dev on how to integrate FSR2 upscaling into their own game setup.
/// </summary>
public interface IFsr2Callbacks
{
/// <summary>
/// Apply a mipmap bias to in-game textures to prevent them from becoming blurry as the internal rendering resolution lowers.
/// This will need to be customized on a per-game basis, as there is no clear universal way to determine what are "in-game" textures.
/// The default implementation will simply apply a mipmap bias to all 2D textures, which will include things like UI textures and which might miss things like terrain texture arrays.
///
/// Depending on how your game organizes its assets, you will want to create a filter that more specifically selects the textures that need to have this mipmap bias applied.
/// You may also want to store the bias offset value and apply it to any assets that are loaded in on demand.
/// </summary>
void ApplyMipmapBias(float biasOffset);
void UndoMipmapBias();
}
/// <summary>
/// Default implementation of IFsr2Callbacks.
/// These are fine for testing but a proper game will want to extend and override these methods.
/// </summary>
public class Fsr2CallbacksBase: IFsr2Callbacks
{
protected float CurrentBiasOffset = 0;
public virtual void ApplyMipmapBias(float biasOffset)
{
if (float.IsNaN(biasOffset) || float.IsInfinity(biasOffset))
return;
CurrentBiasOffset += biasOffset;
if (Mathf.Approximately(CurrentBiasOffset, 0f))
{
CurrentBiasOffset = 0f;
}
foreach (var texture in Resources.FindObjectsOfTypeAll<Texture2D>())
{
if (texture.mipmapCount <= 1)
continue;
texture.mipMapBias += biasOffset;
}
}
public virtual void UndoMipmapBias()
{
if (CurrentBiasOffset == 0f)
return;
ApplyMipmapBias(-CurrentBiasOffset);
}
}
}

0
Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Callbacks.cs.meta

618
Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs

@ -0,0 +1,618 @@
// 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.
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Rendering;
namespace FidelityFX
{
/// <summary>
/// This class loosely matches the FfxFsr2Context struct from the original FSR2 codebase.
/// It manages the various resources and compute passes required by the FSR2 process.
/// Note that this class does not know anything about Unity render pipelines; all it knows is CommandBuffers and RenderTargetIdentifiers.
/// This should make it suitable for integration with any of the available Unity render pipelines.
/// </summary>
public class Fsr2Context
{
private const int MaxQueuedFrames = 16;
private Fsr2.ContextDescription _contextDescription;
private CommandBuffer _commandBuffer;
private Fsr2Pass _computeLuminancePyramidPass;
private Fsr2Pass _reconstructPreviousDepthPass;
private Fsr2Pass _depthClipPass;
private Fsr2Pass _lockPass;
private Fsr2Pass _accumulatePass;
private Fsr2Pass _sharpenPass;
private Fsr2Pass _generateReactivePass;
private Fsr2Pass _tcrAutogeneratePass;
private readonly Fsr2Resources _resources = new Fsr2Resources();
private ComputeBuffer _upscalerConstantsBuffer;
private readonly Fsr2.UpscalerConstants[] _upscalerConstantsArray = { new Fsr2.UpscalerConstants() };
private ref Fsr2.UpscalerConstants UpscalerConsts => ref _upscalerConstantsArray[0];
private ComputeBuffer _spdConstantsBuffer;
private readonly Fsr2.SpdConstants[] _spdConstantsArray = { new Fsr2.SpdConstants() };
private ref Fsr2.SpdConstants SpdConsts => ref _spdConstantsArray[0];
private ComputeBuffer _rcasConstantsBuffer;
private readonly Fsr2.RcasConstants[] _rcasConstantsArray = new Fsr2.RcasConstants[1];
private ref Fsr2.RcasConstants RcasConsts => ref _rcasConstantsArray[0];
private ComputeBuffer _generateReactiveConstantsBuffer;
private readonly Fsr2.GenerateReactiveConstants[] _generateReactiveConstantsArray = { new Fsr2.GenerateReactiveConstants() };
private ref Fsr2.GenerateReactiveConstants GenReactiveConsts => ref _generateReactiveConstantsArray[0];
private ComputeBuffer _tcrAutogenerateConstantsBuffer;
private readonly Fsr2.GenerateReactiveConstants2[] _tcrAutogenerateConstantsArray = { new Fsr2.GenerateReactiveConstants2() };
private ref Fsr2.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0];
private bool _firstExecution;
private Vector2 _previousJitterOffset;
private int _resourceFrameIndex;
public void Create(Fsr2.ContextDescription contextDescription)
{
_contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "FSR2" };
_upscalerConstantsBuffer = CreateConstantBuffer<Fsr2.UpscalerConstants>();
_spdConstantsBuffer = CreateConstantBuffer<Fsr2.SpdConstants>();
_rcasConstantsBuffer = CreateConstantBuffer<Fsr2.RcasConstants>();
_generateReactiveConstantsBuffer = CreateConstantBuffer<Fsr2.GenerateReactiveConstants>();
_tcrAutogenerateConstantsBuffer = CreateConstantBuffer<Fsr2.GenerateReactiveConstants2>();
// Set defaults
_firstExecution = true;
_resourceFrameIndex = 0;
UpscalerConsts.displaySize = _contextDescription.DisplaySize;
_resources.Create(_contextDescription);
CreatePasses();
}
private void CreatePasses()
{
_computeLuminancePyramidPass = new Fsr2ComputeLuminancePyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer);
_reconstructPreviousDepthPass = new Fsr2ReconstructPreviousDepthPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_depthClipPass = new Fsr2DepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_lockPass = new Fsr2LockPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_accumulatePass = new Fsr2AccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer);
_sharpenPass = new Fsr2SharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer);
_generateReactivePass = new Fsr2GenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer);
_tcrAutogeneratePass = new Fsr2TcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer);
}
public void Destroy()
{
DestroyPass(ref _tcrAutogeneratePass);
DestroyPass(ref _generateReactivePass);
DestroyPass(ref _sharpenPass);
DestroyPass(ref _accumulatePass);
DestroyPass(ref _lockPass);
DestroyPass(ref _depthClipPass);
DestroyPass(ref _reconstructPreviousDepthPass);
DestroyPass(ref _computeLuminancePyramidPass);
_resources.Destroy();
DestroyConstantBuffer(ref _tcrAutogenerateConstantsBuffer);
DestroyConstantBuffer(ref _generateReactiveConstantsBuffer);
DestroyConstantBuffer(ref _rcasConstantsBuffer);
DestroyConstantBuffer(ref _spdConstantsBuffer);
DestroyConstantBuffer(ref _upscalerConstantsBuffer);
if (_commandBuffer != null)
{
_commandBuffer.Dispose();
_commandBuffer = null;
}
}
public void Dispatch(Fsr2.DispatchDescription dispatchParams)
{
_commandBuffer.Clear();
Dispatch(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer);
}
public void Dispatch(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer)
{
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableDebugChecking) != 0)
{
DebugCheckDispatch(dispatchParams);
}
if (dispatchParams.UseTextureArrays)
commandBuffer.EnableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY");
if (_firstExecution)
{
commandBuffer.SetRenderTarget(_resources.LockStatus[0]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
}
int frameIndex = _resourceFrameIndex % 2;
bool resetAccumulation = dispatchParams.Reset || _firstExecution;
_firstExecution = false;
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
dispatchParams.Exposure = new ResourceView(_resources.AutoExposure);
else if (!dispatchParams.Exposure.IsValid)
dispatchParams.Exposure = new ResourceView(_resources.DefaultExposure);
if (dispatchParams.EnableAutoReactive)
{
// Create the auto-TCR resources only when we need them
if (_resources.AutoReactive == null)
_resources.CreateTcrAutogenResources(_contextDescription);
if (resetAccumulation)
{
RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr2ShaderIDs.SrvOpaqueOnly;
commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly);
}
}
else if (_resources.AutoReactive != null)
{
// Destroy the auto-TCR resources if we don't use the feature
_resources.DestroyTcrAutogenResources();
}
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive);
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
SetupConstants(dispatchParams, resetAccumulation);
// Reactive mask bias
const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
// Clear reconstructed depth for max depth store
if (resetAccumulation)
{
commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.SceneLuminance);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
// Auto exposure always used to track luma changes in locking logic
commandBuffer.SetRenderTarget(_resources.AutoExposure);
commandBuffer.ClearRenderTarget(false, true, new Color(0f, 1e8f, 0f, 0f));
// Reset atomic counter to 0
commandBuffer.SetRenderTarget(_resources.SpdAtomicCounter);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
}
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
bool depthInverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) == Fsr2.InitializationFlags.EnableDepthInverted;
commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white);
// Auto exposure
SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount);
// Initialize constant buffers data
commandBuffer.SetBufferData(_upscalerConstantsBuffer, _upscalerConstantsArray);
commandBuffer.SetBufferData(_spdConstantsBuffer, _spdConstantsArray);
// Auto reactive
if (dispatchParams.EnableAutoReactive)
{
GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex);
dispatchParams.Reactive = new ResourceView(_resources.AutoReactive);
dispatchParams.TransparencyAndComposition = new ResourceView(_resources.AutoComposition);
}
// Compute luminance pyramid
_computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
// Reconstruct previous depth
_reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Depth clip
_depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Create locks
_lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Accumulate
_accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
if (dispatchParams.EnableSharpening)
{
// Compute the constants
SetupRcasConstants(dispatchParams);
commandBuffer.SetBufferData(_rcasConstantsBuffer, _rcasConstantsArray);
// Dispatch RCAS
const int threadGroupWorkRegionDimRcas = 16;
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
_sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
}
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;
Fsr2Resources.DestroyAliasableResources(commandBuffer);
commandBuffer.DisableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY");
}
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams)
{
_commandBuffer.Clear();
GenerateReactiveMask(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer);
}
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
{
const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (dispatchParams.RenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
GenReactiveConsts.scale = dispatchParams.Scale;
GenReactiveConsts.threshold = dispatchParams.CutoffThreshold;
GenReactiveConsts.binaryValue = dispatchParams.BinaryValue;
GenReactiveConsts.flags = (uint)dispatchParams.Flags;
commandBuffer.SetBufferData(_generateReactiveConstantsBuffer, _generateReactiveConstantsArray);
((Fsr2GenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
}
private void GenerateTransparencyCompositionReactive(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex)
{
const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (dispatchParams.RenderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
TcrAutoGenConsts.autoTcThreshold = dispatchParams.AutoTcThreshold;
TcrAutoGenConsts.autoTcScale = dispatchParams.AutoTcScale;
TcrAutoGenConsts.autoReactiveScale = dispatchParams.AutoReactiveScale;
TcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax;
commandBuffer.SetBufferData(_tcrAutogenerateConstantsBuffer, _tcrAutogenerateConstantsArray);
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
}
private void SetupConstants(Fsr2.DispatchDescription dispatchParams, bool resetAccumulation)
{
ref Fsr2.UpscalerConstants constants = ref UpscalerConsts;
constants.jitterOffset = dispatchParams.JitterOffset;
constants.renderSize = dispatchParams.RenderSize;
constants.maxRenderSize = _contextDescription.MaxRenderSize;
constants.inputColorResourceDimensions = dispatchParams.InputResourceSize;
// Compute the horizontal FOV for the shader from the vertical one
float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y;
float cameraAngleHorizontal = Mathf.Atan(Mathf.Tan(dispatchParams.CameraFovAngleVertical / 2.0f) * aspectRatio) * 2.0f;
constants.tanHalfFOV = Mathf.Tan(cameraAngleHorizontal * 0.5f);
constants.viewSpaceToMetersFactor = (dispatchParams.ViewSpaceToMetersFactor > 0.0f) ? dispatchParams.ViewSpaceToMetersFactor : 1.0f;
// Compute params to enable device depth to view space depth computation in shader
constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams);
// To be updated if resource is larger than the actual image size
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.DisplaySize.x, (float)constants.renderSize.y / _contextDescription.DisplaySize.y);
constants.previousFramePreExposure = constants.preExposure;
constants.preExposure = (dispatchParams.PreExposure != 0) ? dispatchParams.PreExposure : 1.0f;
// Motion vector data
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize;
constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize;
// Compute jitter cancellation
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0)
{
constants.motionVectorJitterCancellation = (_previousJitterOffset - constants.jitterOffset) / motionVectorsTargetSize;
_previousJitterOffset = constants.jitterOffset;
}
int jitterPhaseCount = Fsr2.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.DisplaySize.x);
if (resetAccumulation || constants.jitterPhaseCount == 0)
{
constants.jitterPhaseCount = jitterPhaseCount;
}
else
{
int jitterPhaseCountDelta = (int)(jitterPhaseCount - constants.jitterPhaseCount);
if (jitterPhaseCountDelta > 0)
constants.jitterPhaseCount++;
else if (jitterPhaseCountDelta < 0)
constants.jitterPhaseCount--;
}
// Convert delta time to seconds and clamp to [0, 1]
constants.deltaTime = Mathf.Clamp01(dispatchParams.FrameTimeDelta);
if (resetAccumulation)
constants.frameIndex = 0;
else
constants.frameIndex++;
// Shading change usage of the SPD mip levels
constants.lumaMipLevelToUse = Fsr2Pass.ShadingChangeMipLevel;
float mipDiv = 2 << constants.lumaMipLevelToUse;
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv);
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv);
}
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr2.DispatchDescription dispatchParams)
{
bool inverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0;
bool infinite = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0;
// make sure it has no impact if near and far plane values are swapped in dispatch params
// the flags "inverted" and "infinite" will decide what transform to use
float min = Mathf.Min(dispatchParams.CameraNear, dispatchParams.CameraFar);
float max = Mathf.Max(dispatchParams.CameraNear, dispatchParams.CameraFar);
if (inverted)
{
(min, max) = (max, min);
}
float q = max / (min - max);
float d = -1.0f;
Vector4 matrixElemC = new Vector4(q, -1.0f - Mathf.Epsilon, q, 0.0f + Mathf.Epsilon);
Vector4 matrixElemE = new Vector4(q * min, -min - Mathf.Epsilon, q * min, max);
// Revert x and y coords
float aspect = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y;
float cotHalfFovY = Mathf.Cos(0.5f * dispatchParams.CameraFovAngleVertical) / Mathf.Sin(0.5f * dispatchParams.CameraFovAngleVertical);
int matrixIndex = (inverted ? 2 : 0) + (infinite ? 1 : 0);
return new Vector4(
d * matrixElemC[matrixIndex],
matrixElemE[matrixIndex],
aspect / cotHalfFovY,
1.0f / cotHalfFovY);
}
private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams)
{
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1));
RcasConsts = RcasConfigs[sharpnessIndex];
}
private void SetupSpdConstants(Fsr2.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
{
RectInt rectInfo = new RectInt(0, 0, dispatchParams.RenderSize.x, dispatchParams.RenderSize.y);
SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips);
// Downsample
ref Fsr2.SpdConstants spdConstants = ref SpdConsts;
spdConstants.numWorkGroups = (uint)numWorkGroupsAndMips.x;
spdConstants.mips = (uint)numWorkGroupsAndMips.y;
spdConstants.workGroupOffsetX = (uint)workGroupOffset.x;
spdConstants.workGroupOffsetY = (uint)workGroupOffset.y;
spdConstants.renderSizeX = (uint)dispatchParams.RenderSize.x;
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y;
}
private static void SpdSetup(RectInt rectInfo, out Vector2Int dispatchThreadGroupCount, out Vector2Int workGroupOffset, out Vector2Int numWorkGroupsAndMips, int mips = -1)
{
workGroupOffset = new Vector2Int(rectInfo.x / 64, rectInfo.y / 64);
int endIndexX = (rectInfo.x + rectInfo.width - 1) / 64;
int endIndexY = (rectInfo.y + rectInfo.height - 1) / 64;
dispatchThreadGroupCount = new Vector2Int(endIndexX + 1 - workGroupOffset.x, endIndexY + 1 - workGroupOffset.y);
numWorkGroupsAndMips = new Vector2Int(dispatchThreadGroupCount.x * dispatchThreadGroupCount.y, mips);
if (mips < 0)
{
float resolution = Math.Max(rectInfo.width, rectInfo.height);
numWorkGroupsAndMips.y = Math.Min(Mathf.FloorToInt(Mathf.Log(resolution, 2.0f)), 12);
}
}
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams)
{
if (!dispatchParams.Color.IsValid)
{
Debug.LogError("Color resource is null");
}
if (!dispatchParams.Depth.IsValid)
{
Debug.LogError("Depth resource is null");
}
if (!dispatchParams.MotionVectors.IsValid)
{
Debug.LogError("MotionVectors resource is null");
}
if (!dispatchParams.Output.IsValid)
{
Debug.LogError("Output resource is null");
}
if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
{
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present");
}
if (Mathf.Abs(dispatchParams.JitterOffset.x) > 1.0f || Mathf.Abs(dispatchParams.JitterOffset.y) > 1.0f)
{
Debug.LogWarning("JitterOffset contains value outside of expected range [-1.0, 1.0]");
}
if (dispatchParams.MotionVectorScale.x > _contextDescription.MaxRenderSize.x || dispatchParams.MotionVectorScale.y > _contextDescription.MaxRenderSize.y)
{
Debug.LogWarning("MotionVectorScale contains scale value greater than MaxRenderSize");
}
if (dispatchParams.MotionVectorScale.x == 0.0f || dispatchParams.MotionVectorScale.y == 0.0f)
{
Debug.LogWarning("MotionVectorScale contains zero scale value");
}
if (dispatchParams.RenderSize.x > _contextDescription.MaxRenderSize.x || dispatchParams.RenderSize.y > _contextDescription.MaxRenderSize.y)
{
Debug.LogWarning("RenderSize is greater than context MaxRenderSize");
}
if (dispatchParams.RenderSize.x == 0 || dispatchParams.RenderSize.y == 0)
{
Debug.LogWarning("RenderSize contains zero dimension");
}
if (dispatchParams.FrameTimeDelta > 1.0f)
{
Debug.LogWarning("FrameTimeDelta is greater than 1.0f - this value should be seconds (~0.0166 for 60fps)");
}
if (dispatchParams.PreExposure == 0.0f)
{
Debug.LogError("PreExposure provided as 0.0f which is invalid");
}
bool infiniteDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInfinite) != 0;
bool inverseDepth = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0;
if (inverseDepth)
{
if (dispatchParams.CameraNear < dispatchParams.CameraFar)
{
Debug.LogWarning("EnableDepthInverted flag is present yet CameraNear is less than CameraFar");
}
if (infiniteDepth)
{
if (dispatchParams.CameraNear < float.MaxValue)
{
Debug.LogWarning("EnableDepthInfinite and EnableDepthInverted present, yet CameraNear != float.MaxValue");
}
}
if (dispatchParams.CameraFar < 0.075f)
{
Debug.LogWarning("EnableDepthInverted present, CameraFar value is very low which may result in depth separation artefacting");
}
}
else
{
if (dispatchParams.CameraNear > dispatchParams.CameraFar)
{
Debug.LogWarning("CameraNear is greater than CameraFar in non-inverted-depth context");
}
if (infiniteDepth)
{
if (dispatchParams.CameraFar < float.MaxValue)
{
Debug.LogWarning("EnableDepthInfinite present, yet CameraFar != float.MaxValue");
}
}
if (dispatchParams.CameraNear < 0.075f)
{
Debug.LogWarning("CameraNear value is very low which may result in depth separation artefacting");
}
}
if (dispatchParams.CameraFovAngleVertical <= 0.0f)
{
Debug.LogError("CameraFovAngleVertical is 0.0f - this value should be > 0.0f");
}
if (dispatchParams.CameraFovAngleVertical > Mathf.PI)
{
Debug.LogError("CameraFovAngleVertical is greater than 180 degrees/PI");
}
}
/// <summary>
/// The FSR2 C++ codebase uses floats bitwise converted to ints to pass sharpness parameters to the RCAS shader.
/// This is not possible in C# without enabling unsafe code compilation, so to avoid that we instead use a table of precomputed values.
/// </summary>
private static readonly Fsr2.RcasConstants[] RcasConfigs = new []
{
new Fsr2.RcasConstants(1048576000u, 872428544u),
new Fsr2.RcasConstants(1049178080u, 877212745u),
new Fsr2.RcasConstants(1049823372u, 882390168u),
new Fsr2.RcasConstants(1050514979u, 887895276u),
new Fsr2.RcasConstants(1051256227u, 893859143u),
new Fsr2.RcasConstants(1052050675u, 900216232u),
new Fsr2.RcasConstants(1052902144u, 907032080u),
new Fsr2.RcasConstants(1053814727u, 914306687u),
new Fsr2.RcasConstants(1054792807u, 922105590u),
new Fsr2.RcasConstants(1055841087u, 930494326u),
new Fsr2.RcasConstants(1056964608u, 939538432u),
new Fsr2.RcasConstants(1057566688u, 944322633u),
new Fsr2.RcasConstants(1058211980u, 949500056u),
new Fsr2.RcasConstants(1058903587u, 955005164u),
new Fsr2.RcasConstants(1059644835u, 960969031u),
new Fsr2.RcasConstants(1060439283u, 967326120u),
new Fsr2.RcasConstants(1061290752u, 974141968u),
new Fsr2.RcasConstants(1062203335u, 981416575u),
new Fsr2.RcasConstants(1063181415u, 989215478u),
new Fsr2.RcasConstants(1064229695u, 997604214u),
new Fsr2.RcasConstants(1065353216u, 1006648320),
};
private static ComputeBuffer CreateConstantBuffer<TConstants>() where TConstants: struct
{
return new ComputeBuffer(1, Marshal.SizeOf<TConstants>(), ComputeBufferType.Constant);
}
private static void DestroyConstantBuffer(ref ComputeBuffer bufferRef)
{
if (bufferRef == null)
return;
bufferRef.Release();
bufferRef = null;
}
private static void DestroyPass(ref Fsr2Pass pass)
{
if (pass == null)
return;
pass.Dispose();
pass = null;
}
}
}

0
Assets/Scripts/Core/Fsr3UpscalerContext.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Context.cs.meta

380
Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs

@ -0,0 +1,380 @@
// 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.
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
namespace FidelityFX
{
/// <summary>
/// Base class for all of the compute passes that make up the FSR2 process.
/// 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.
/// </summary>
internal abstract class Fsr2Pass: IDisposable
{
internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define
protected readonly Fsr2.ContextDescription ContextDescription;
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)
{
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)
{
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)
{
useLut = true;
}
#endif
// This matches the permutation rules from the CreatePipeline* functions
if ((flags & Fsr2.InitializationFlags.EnableHighDynamicRange) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_HDR_COLOR_INPUT");
if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS");
if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS");
if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_INVERTED_DEPTH");
if (useLut) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE");
if ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF");
}
}
internal class Fsr2ComputeLuminancePyramidPass : Fsr2Pass
{
private readonly ComputeBuffer _spdConstants;
public Fsr2ComputeLuminancePyramidPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer spdConstants)
: base(contextDescription, resources, constants)
{
_spdConstants = spdConstants;
InitComputeShader("Compute Luminance Pyramid", contextDescription.Shaders.computeLuminancePyramidPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
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);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2ReconstructPreviousDepthPass : Fsr2Pass
{
public Fsr2ReconstructPreviousDepthPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Reconstruct & Dilate", contextDescription.Shaders.reconstructPreviousDepthPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.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, 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);
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<Fsr2.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2DepthClipPass : Fsr2Pass
{
public Fsr2DepthClipPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Depth Clip", contextDescription.Shaders.depthClipPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.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;
ref var reactive = ref dispatchParams.Reactive;
ref var tac = ref dispatchParams.TransparencyAndComposition;
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);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
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);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2LockPass : Fsr2Pass
{
public Fsr2LockPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Create Locks", contextDescription.Shaders.lockPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2AccumulatePass : Fsr2Pass
{
private const string SharpeningKeyword = "FFX_FSR2_OPTION_APPLY_SHARPENING";
#if UNITY_2021_2_OR_NEWER
private readonly LocalKeyword _sharpeningKeyword;
#endif
public Fsr2AccumulatePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Reproject & Accumulate", contextDescription.Shaders.accumulatePass);
#if UNITY_2021_2_OR_NEWER
_sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword);
#endif
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
#if UNITY_2021_2_OR_NEWER
if (dispatchParams.EnableSharpening)
commandBuffer.EnableKeyword(ComputeShader, _sharpeningKeyword);
else
commandBuffer.DisableKeyword(ComputeShader, _sharpeningKeyword);
#else
if (dispatchParams.EnableSharpening)
commandBuffer.EnableShaderKeyword(SharpeningKeyword);
else
commandBuffer.DisableShaderKeyword(SharpeningKeyword);
#endif
if ((ContextDescription.Flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0)
{
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
}
else
{
ref var motionVectors = ref dispatchParams.MotionVectors;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
}
ref var exposure = ref dispatchParams.Exposure;
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]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPreparedInputColor, Fsr2ShaderIDs.UavPreparedInputColor);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLanczosLut, Resources.LanczosLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvAutoExposure, Resources.AutoExposure);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]);
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<Fsr2.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2SharpenPass : Fsr2Pass
{
private readonly ComputeBuffer _rcasConstants;
public Fsr2SharpenPass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer rcasConstants)
: base(contextDescription, resources, constants)
{
_rcasConstants = rcasConstants;
InitComputeShader("RCAS Sharpening", contextDescription.Shaders.sharpenPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
ref var exposure = ref dispatchParams.Exposure;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]);
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<Fsr2.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr2GenerateReactivePass : Fsr2Pass
{
private readonly ComputeBuffer _generateReactiveConstants;
public Fsr2GenerateReactivePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer generateReactiveConstants)
: base(contextDescription, resources, null)
{
_generateReactiveConstants = generateReactiveConstants;
InitComputeShader("Auto-Generate Reactive Mask", contextDescription.Shaders.autoGenReactivePass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
}
public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.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;
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<Fsr2.GenerateReactiveConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
commandBuffer.EndSample(Sampler);
}
}
internal class Fsr2TcrAutogeneratePass : Fsr2Pass
{
private readonly ComputeBuffer _tcrAutogenerateConstants;
public Fsr2TcrAutogeneratePass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants, ComputeBuffer tcrAutogenerateConstants)
: base(contextDescription, resources, constants)
{
_tcrAutogenerateConstants = tcrAutogenerateConstants;
InitComputeShader("Auto-Generate Transparency & Composition Mask", contextDescription.Shaders.tcrAutoGenPass);
}
protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
ref var color = ref dispatchParams.Color;
ref var motionVectors = ref dispatchParams.MotionVectors;
ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly;
ref var reactive = ref dispatchParams.Reactive;
ref var tac = ref dispatchParams.TransparencyAndComposition;
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.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]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
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);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants2>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
}

0
Assets/Scripts/Core/Fsr3UpscalerPass.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Pass.cs.meta

38
Assets/Scripts/Core/Fsr3UpscalerResources.cs → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -26,10 +26,10 @@ using UnityEngine.Rendering;
namespace FidelityFX namespace FidelityFX
{ {
/// <summary> /// <summary>
/// Helper class for bundling and managing persistent resources required by the FSR3 Upscaler process.
/// Helper class for bundling and managing persistent resources required by the FSR2 process.
/// This includes lookup tables, default fallback resources and double-buffered resources that get swapped between frames. /// This includes lookup tables, default fallback resources and double-buffered resources that get swapped between frames.
/// </summary> /// </summary>
internal class Fsr3UpscalerResources
internal class Fsr2Resources
{ {
public Texture2D DefaultExposure; public Texture2D DefaultExposure;
public Texture2D DefaultReactive; public Texture2D DefaultReactive;
@ -47,7 +47,7 @@ namespace FidelityFX
public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2];
public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2];
public void Create(Fsr3Upscaler.ContextDescription contextDescription)
public void Create(Fsr2.ContextDescription contextDescription)
{ {
// Generate the data for the LUT // Generate the data for the LUT
const int lanczos2LutWidth = 128; const int lanczos2LutWidth = 128;
@ -55,7 +55,7 @@ namespace FidelityFX
for (int currentLanczosWidthIndex = 0; currentLanczosWidthIndex < lanczos2LutWidth; ++currentLanczosWidthIndex) for (int currentLanczosWidthIndex = 0; currentLanczosWidthIndex < lanczos2LutWidth; ++currentLanczosWidthIndex)
{ {
float x = 2.0f * currentLanczosWidthIndex / (lanczos2LutWidth - 1); float x = 2.0f * currentLanczosWidthIndex / (lanczos2LutWidth - 1);
float y = Fsr3Upscaler.Lanczos2(x);
float y = Fsr2.Lanczos2(x);
lanczos2Weights[currentLanczosWidthIndex] = y; lanczos2Weights[currentLanczosWidthIndex] = y;
} }
@ -115,7 +115,7 @@ namespace FidelityFX
CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", contextDescription.DisplaySize, GraphicsFormat.R8G8B8A8_UNorm); CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", contextDescription.DisplaySize, GraphicsFormat.R8G8B8A8_UNorm);
} }
public void CreateTcrAutogenResources(Fsr3Upscaler.ContextDescription contextDescription)
public void CreateTcrAutogenResources(Fsr2.ContextDescription contextDescription)
{ {
// Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE // Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
AutoReactive = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoReactive", enableRandomWrite = true }; AutoReactive = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoReactive", enableRandomWrite = true };
@ -134,39 +134,39 @@ namespace FidelityFX
// Set up shared aliasable resources, i.e. temporary render textures // Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between passes // These do not need to persist between frames, but they do need to be available between passes
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr3Upscaler.ContextDescription contextDescription, Fsr3Upscaler.DispatchDescription dispatchParams)
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr2.ContextDescription contextDescription, Fsr2.DispatchDescription dispatchParams)
{ {
Vector2Int displaySize = contextDescription.DisplaySize; Vector2Int displaySize = contextDescription.DisplaySize;
Vector2Int maxRenderSize = contextDescription.MaxRenderSize; Vector2Int maxRenderSize = contextDescription.MaxRenderSize;
// FSR3UPSCALER_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true);
// FSR3UPSCALER_DilatedDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_DilatedDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_SFloat, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_SFloat, 1, true);
// FSR3UPSCALER_LockInputLuma: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_LockInputLuma: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavLockInputLuma, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true);
// FSR3UPSCALER_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8_UNorm, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8_UNorm, 1, true);
// FSR3UPSCALER_PreparedInputColor: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_PreparedInputColor: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavPreparedInputColor, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavPreparedInputColor, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16G16B16A16_SFloat, 1, true);
// FSR3UPSCALER_NewLocks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE // FSR3UPSCALER_NewLocks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavNewLocks, displaySize.x, displaySize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavNewLocks, displaySize.x, displaySize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
} }
public static void DestroyAliasableResources(CommandBuffer commandBuffer) public static void DestroyAliasableResources(CommandBuffer commandBuffer)
{ {
// Release all of the aliasable resources used this frame // Release all of the aliasable resources used this frame
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedDepth);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavLockInputLuma);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavPreparedInputColor);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavNewLocks);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavPreparedInputColor);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavNewLocks);
} }
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format) private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format)

0
Assets/Scripts/Core/Fsr3UpscalerResources.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2Resources.cs.meta

80
Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs

@ -0,0 +1,80 @@
// 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.
using UnityEngine;
namespace FidelityFX
{
public static class Fsr2ShaderIDs
{
// Shader resource views, i.e. read-only bindings
public static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered");
public static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only");
public static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors");
public static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth");
public static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure");
public static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure");
public static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask");
public static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask");
public static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth");
public static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors");
public static readonly int SrvPrevDilatedMotionVectors = Shader.PropertyToID("r_previous_dilated_motion_vectors");
public static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilatedDepth");
public static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color");
public static readonly int SrvLockStatus = Shader.PropertyToID("r_lock_status");
public static readonly int SrvLockInputLuma = Shader.PropertyToID("r_lock_input_luma");
public static readonly int SrvPreparedInputColor = Shader.PropertyToID("r_prepared_input_color");
public static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history");
public static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input");
public static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut");
public static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips");
public static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut");
public static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks");
public static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha");
public static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha");
// Unordered access views, i.e. random read/write bindings
public static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth");
public static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors");
public static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilatedDepth");
public static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color");
public static readonly int UavLockStatus = Shader.PropertyToID("rw_lock_status");
public static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma");
public static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks");
public static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color");
public static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history");
public static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output");
public static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change");
public static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5");
public static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks");
public static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure");
public static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic");
public static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive");
public static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition");
public static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha");
public static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha");
// Constant buffer bindings
public static readonly int CbFsr2 = Shader.PropertyToID("cbFSR2");
public static readonly int CbSpd = Shader.PropertyToID("cbSPD");
public static readonly int CbRcas = Shader.PropertyToID("cbRCAS");
public static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive");
}
}

0
Assets/Scripts/Core/Fsr3ShaderIDs.cs.meta → Packages/fidelityfx.fsr/Runtime/FSR2/Fsr2ShaderIDs.cs.meta

2
Assets/Shaders/FSR3.meta → Packages/fidelityfx.fsr/Runtime/FSR3.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 661ffc6dbd7389b4da99fb9f749745de
guid: 16d16ad51c3bc2a429d3da6788f65e07
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

91
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs

@ -0,0 +1,91 @@
// 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.
using UnityEngine;
namespace FidelityFX
{
public static class Fsr3ShaderIDs
{
// Shader resource views, i.e. read-only bindings
public static readonly int SrvInputColor = Shader.PropertyToID("r_input_color_jittered");
public static readonly int SrvOpaqueOnly = Shader.PropertyToID("r_input_opaque_only");
public static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors");
public static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth");
public static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure");
public static readonly int SrvFrameInfo = Shader.PropertyToID("r_frame_info");
public static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask");
public static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask");
public static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth");
public static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors");
public static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilated_depth");
public static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color");
public static readonly int SrvAccumulation = Shader.PropertyToID("r_accumulation");
public static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history");
public static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input");
public static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut");
public static readonly int SrvSpdMips = Shader.PropertyToID("r_spd_mips");
public static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks");
public static readonly int SrvNewLocks = Shader.PropertyToID("r_new_locks");
public static readonly int SrvFarthestDepth = Shader.PropertyToID("r_farthest_depth");
public static readonly int SrvFarthestDepthMip1 = Shader.PropertyToID("r_farthest_depth_mip1");
public static readonly int SrvShadingChange = Shader.PropertyToID("r_shading_change");
public static readonly int SrvCurrentLuma = Shader.PropertyToID("r_current_luma");
public static readonly int SrvPreviousLuma = Shader.PropertyToID("r_previous_luma");
public static readonly int SrvLumaInstability = Shader.PropertyToID("r_luma_instability");
public static readonly int SrvPrevColorPreAlpha = Shader.PropertyToID("r_input_prev_color_pre_alpha");
public static readonly int SrvPrevColorPostAlpha = Shader.PropertyToID("r_input_prev_color_post_alpha");
// Unordered access views, i.e. random read/write bindings
public static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth");
public static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors");
public static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilated_depth");
public static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color");
public static readonly int UavAccumulation = Shader.PropertyToID("rw_accumulation");
public static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history");
public static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output");
public static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks");
public static readonly int UavFrameInfo = Shader.PropertyToID("rw_frame_info");
public static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic");
public static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks");
public static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive");
public static readonly int UavShadingChange = Shader.PropertyToID("rw_shading_change");
public static readonly int UavFarthestDepth = Shader.PropertyToID("rw_farthest_depth");
public static readonly int UavFarthestDepthMip1 = Shader.PropertyToID("rw_farthest_depth_mip1");
public static readonly int UavCurrentLuma = Shader.PropertyToID("rw_current_luma");
public static readonly int UavLumaInstability = Shader.PropertyToID("rw_luma_instability");
public static readonly int UavIntermediate = Shader.PropertyToID("rw_intermediate_fp16x1");
public static readonly int UavSpdMip0 = Shader.PropertyToID("rw_spd_mip0");
public static readonly int UavSpdMip1 = Shader.PropertyToID("rw_spd_mip1");
public static readonly int UavSpdMip2 = Shader.PropertyToID("rw_spd_mip2");
public static readonly int UavSpdMip3 = Shader.PropertyToID("rw_spd_mip3");
public static readonly int UavSpdMip4 = Shader.PropertyToID("rw_spd_mip4");
public static readonly int UavSpdMip5 = Shader.PropertyToID("rw_spd_mip5");
public static readonly int UavAutoComposition = Shader.PropertyToID("rw_output_autocomposition");
public static readonly int UavPrevColorPreAlpha = Shader.PropertyToID("rw_output_prev_color_pre_alpha");
public static readonly int UavPrevColorPostAlpha = Shader.PropertyToID("rw_output_prev_color_post_alpha");
// Constant buffer bindings
public static readonly int CbFsr3Upscaler = Shader.PropertyToID("cbFSR3Upscaler");
public static readonly int CbSpd = Shader.PropertyToID("cbSPD");
public static readonly int CbRcas = Shader.PropertyToID("cbRCAS");
public static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive");
}
}

3
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3ShaderIDs.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a1e3e7c189594b94897510b4a20b8a00
timeCreated: 1679060863

70
Assets/Scripts/Core/Fsr3Upscaler.cs → Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -49,7 +49,7 @@ namespace FidelityFX
var contextDescription = new ContextDescription var contextDescription = new ContextDescription
{ {
Flags = flags, Flags = flags,
DisplaySize = displaySize,
MaxUpscaleSize = displaySize,
MaxRenderSize = maxRenderSize, MaxRenderSize = maxRenderSize,
Shaders = shaders, Shaders = shaders,
}; };
@ -158,6 +158,12 @@ namespace FidelityFX
EnableDebugChecking = 1 << 8, EnableDebugChecking = 1 << 8,
} }
[Flags]
public enum DispatchFlags
{
DrawDebugView = 1 << 0,
}
/// <summary> /// <summary>
/// A structure encapsulating the parameters required to initialize FidelityFX Super Resolution 3 upscaling. /// A structure encapsulating the parameters required to initialize FidelityFX Super Resolution 3 upscaling.
/// </summary> /// </summary>
@ -165,7 +171,7 @@ namespace FidelityFX
{ {
public InitializationFlags Flags; public InitializationFlags Flags;
public Vector2Int MaxRenderSize; public Vector2Int MaxRenderSize;
public Vector2Int DisplaySize;
public Vector2Int MaxUpscaleSize;
public Fsr3UpscalerShaders Shaders; public Fsr3UpscalerShaders Shaders;
} }
@ -184,7 +190,7 @@ namespace FidelityFX
public Vector2 JitterOffset; public Vector2 JitterOffset;
public Vector2 MotionVectorScale; public Vector2 MotionVectorScale;
public Vector2Int RenderSize; public Vector2Int RenderSize;
public Vector2Int InputResourceSize;
public Vector2Int UpscaleSize;
public bool EnableSharpening; public bool EnableSharpening;
public float Sharpness; public float Sharpness;
public float FrameTimeDelta; // in seconds public float FrameTimeDelta; // in seconds
@ -194,6 +200,8 @@ namespace FidelityFX
public float CameraFar; public float CameraFar;
public float CameraFovAngleVertical; public float CameraFovAngleVertical;
public float ViewSpaceToMetersFactor; public float ViewSpaceToMetersFactor;
public DispatchFlags Flags;
public bool UseTextureArrays; // Enable texture array bindings, primarily used for HDRP and XR
// EXPERIMENTAL reactive mask generation parameters // EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive; public bool EnableAutoReactive;
@ -233,27 +241,30 @@ namespace FidelityFX
internal struct UpscalerConstants internal struct UpscalerConstants
{ {
public Vector2Int renderSize; public Vector2Int renderSize;
public Vector2Int previousFrameRenderSize;
public Vector2Int upscaleSize;
public Vector2Int previousFrameUpscaleSize;
public Vector2Int maxRenderSize; public Vector2Int maxRenderSize;
public Vector2Int displaySize;
public Vector2Int inputColorResourceDimensions;
public Vector2Int lumaMipDimensions;
public int lumaMipLevelToUse;
public int frameIndex;
public Vector2Int maxUpscaleSize;
public Vector4 deviceToViewDepth; public Vector4 deviceToViewDepth;
public Vector2 jitterOffset; public Vector2 jitterOffset;
public Vector2 previousFrameJitterOffset;
public Vector2 motionVectorScale; public Vector2 motionVectorScale;
public Vector2 downscaleFactor; public Vector2 downscaleFactor;
public Vector2 motionVectorJitterCancellation; public Vector2 motionVectorJitterCancellation;
public float preExposure;
public float previousFramePreExposure;
public float tanHalfFOV; public float tanHalfFOV;
public float jitterPhaseCount; public float jitterPhaseCount;
public float deltaTime; public float deltaTime;
public float dynamicResChangeFactor;
public float deltaPreExposure;
public float viewSpaceToMetersFactor; public float viewSpaceToMetersFactor;
public int dummy;
public float frameIndex;
} }
[Serializable, StructLayout(LayoutKind.Sequential)] [Serializable, StructLayout(LayoutKind.Sequential)]
@ -299,35 +310,4 @@ namespace FidelityFX
public readonly uint dummy1; public readonly uint dummy1;
} }
} }
/// <summary>
/// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader.
/// </summary>
public readonly struct ResourceView
{
/// <summary>
/// This value is the equivalent of not setting any value at all; all struct fields will have their default values.
/// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader.
/// </summary>
public static readonly ResourceView Unassigned = new ResourceView(default);
/// <summary>
/// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture.
/// Binding this to a shader can be seen as setting the texture variable inside the shader to null.
/// </summary>
public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None);
public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
{
RenderTarget = renderTarget;
SubElement = subElement;
MipLevel = mipLevel;
}
public bool IsValid => !RenderTarget.Equals(default);
public readonly RenderTargetIdentifier RenderTarget;
public readonly RenderTextureSubElement SubElement;
public readonly int MipLevel;
}
} }

3
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3Upscaler.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7ee72b891c35d614eac306ca6154b66d
timeCreated: 1673441954

177
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs

@ -0,0 +1,177 @@
// 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.
using UnityEngine;
using UnityEngine.Serialization;
namespace FidelityFX
{
/// <summary>
/// Scriptable object containing all shader resources required by FidelityFX Super Resolution 3 (FSR3) Upscaler.
/// These can be stored in an asset file and referenced from a scene or prefab, avoiding the need to load the shaders from a Resources folder.
/// </summary>
[CreateAssetMenu(fileName = "FSR3 Upscaler Assets", menuName = "FidelityFX/FSR3 Upscaler Assets", order = 1103)]
public class Fsr3UpscalerAssets : ScriptableObject
{
public Fsr3UpscalerShaders shaders;
#if UNITY_EDITOR
private void Reset()
{
shaders = new Fsr3UpscalerShaders
{
prepareInputsPass = FindComputeShader("ffx_fsr3upscaler_prepare_inputs_pass"),
lumaPyramidPass = FindComputeShader("ffx_fsr3upscaler_luma_pyramid_pass"),
shadingChangePyramidPass = FindComputeShader("ffx_fsr3upscaler_shading_change_pyramid_pass"),
shadingChangePass = FindComputeShader("ffx_fsr3upscaler_shading_change_pass"),
prepareReactivityPass = FindComputeShader("ffx_fsr3upscaler_prepare_reactivity_pass"),
lumaInstabilityPass = FindComputeShader("ffx_fsr3upscaler_luma_instability_pass"),
accumulatePass = FindComputeShader("ffx_fsr3upscaler_accumulate_pass"),
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"),
};
}
private static ComputeShader FindComputeShader(string name)
{
string[] assetGuids = UnityEditor.AssetDatabase.FindAssets($"t:ComputeShader {name}");
if (assetGuids == null || assetGuids.Length == 0)
return null;
string assetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assetGuids[0]);
return UnityEditor.AssetDatabase.LoadAssetAtPath<ComputeShader>(assetPath);
}
#endif
}
/// <summary>
/// All the compute shaders used by the FSR3 Upscaler.
/// </summary>
[System.Serializable]
public class Fsr3UpscalerShaders
{
/// <summary>
/// The compute shader used by the prepare inputs pass.
/// </summary>
public ComputeShader prepareInputsPass;
/// <summary>
/// The compute shader used by the luminance pyramid computation pass.
/// </summary>
public ComputeShader lumaPyramidPass;
/// <summary>
/// The compute shader used by the shading change pyramid pass.
/// </summary>
public ComputeShader shadingChangePyramidPass;
/// <summary>
/// The compute shader used by the shading change pass.
/// </summary>
public ComputeShader shadingChangePass;
/// <summary>
/// The compute shader used by the prepare reactivity pass.
/// </summary>
public ComputeShader prepareReactivityPass;
/// <summary>
/// The compute shader used by the luma instability pass.
/// </summary>
public ComputeShader lumaInstabilityPass;
/// <summary>
/// The compute shader used by the accumulation pass.
/// </summary>
public ComputeShader accumulatePass;
/// <summary>
/// The compute shader used by the RCAS sharpening pass.
/// </summary>
public ComputeShader sharpenPass;
/// <summary>
/// The compute shader used to auto-generate a reactive mask.
/// </summary>
public ComputeShader autoGenReactivePass;
/// <summary>
/// The compute shader used to auto-generate a transparency & composition mask.
/// </summary>
public ComputeShader tcrAutoGenPass;
/// <summary>
/// The compute shader used to display a debug view.
/// </summary>
public ComputeShader debugViewPass;
/// <summary>
/// Returns a copy of this class and its contents.
/// </summary>
public Fsr3UpscalerShaders Clone()
{
return (Fsr3UpscalerShaders)MemberwiseClone();
}
/// <summary>
/// Returns a copy of this class with clones of all its shaders.
/// This can be useful if you're running multiple FSR3 Upscaler instances with different shader configurations.
/// Be sure to clean up these clones through Dispose once you're done with them.
/// </summary>
public Fsr3UpscalerShaders DeepCopy()
{
return new Fsr3UpscalerShaders
{
prepareInputsPass = Object.Instantiate(prepareInputsPass),
lumaPyramidPass = Object.Instantiate(lumaPyramidPass),
shadingChangePyramidPass = Object.Instantiate(shadingChangePyramidPass),
shadingChangePass = Object.Instantiate(shadingChangePass),
prepareReactivityPass = Object.Instantiate(prepareReactivityPass),
lumaInstabilityPass = Object.Instantiate(lumaInstabilityPass),
accumulatePass = Object.Instantiate(accumulatePass),
sharpenPass = Object.Instantiate(sharpenPass),
autoGenReactivePass = Object.Instantiate(autoGenReactivePass),
tcrAutoGenPass = Object.Instantiate(tcrAutoGenPass),
debugViewPass = Object.Instantiate(debugViewPass),
};
}
/// <summary>
/// Destroy all the shaders within this instance.
/// Use this only on clones created through DeepCopy.
/// </summary>
public void Dispose()
{
Object.Destroy(prepareInputsPass);
Object.Destroy(lumaPyramidPass);
Object.Destroy(shadingChangePyramidPass);
Object.Destroy(shadingChangePass);
Object.Destroy(prepareReactivityPass);
Object.Destroy(lumaInstabilityPass);
Object.Destroy(accumulatePass);
Object.Destroy(sharpenPass);
Object.Destroy(autoGenReactivePass);
Object.Destroy(tcrAutoGenPass);
Object.Destroy(debugViewPass);
}
}
}

11
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerAssets.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2dbcc608a4754d049a14a0bcce2eb40b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

4
Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs → Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -42,7 +42,7 @@ namespace FidelityFX
} }
/// <summary> /// <summary>
/// Default implementation of IFsr3UpscalerCallbacks using simple Resources calls.
/// Default implementation of IFsr3UpscalerCallbacks.
/// These are fine for testing but a proper game will want to extend and override these methods. /// These are fine for testing but a proper game will want to extend and override these methods.
/// </summary> /// </summary>
public class Fsr3UpscalerCallbacksBase: IFsr3UpscalerCallbacks public class Fsr3UpscalerCallbacksBase: IFsr3UpscalerCallbacks

11
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerCallbacks.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d52448255f58a6a42bfcf1634f4dd1a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

166
Assets/Scripts/Core/Fsr3UpscalerContext.cs → Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -38,14 +38,19 @@ namespace FidelityFX
private Fsr3Upscaler.ContextDescription _contextDescription; private Fsr3Upscaler.ContextDescription _contextDescription;
private CommandBuffer _commandBuffer; 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 _accumulatePass;
private Fsr3UpscalerPass _sharpenPass; private Fsr3UpscalerPass _sharpenPass;
private Fsr3UpscalerPass _computeLuminancePyramidPass;
private Fsr3UpscalerPass _generateReactivePass; private Fsr3UpscalerPass _generateReactivePass;
private Fsr3UpscalerPass _tcrAutogeneratePass; private Fsr3UpscalerPass _tcrAutogeneratePass;
#if UNITY_EDITOR || DEVELOPMENT_BUILD
private Fsr3UpscalerPass _debugViewPass;
#endif
private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources();
@ -70,8 +75,10 @@ namespace FidelityFX
private ref Fsr3Upscaler.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0]; private ref Fsr3Upscaler.GenerateReactiveConstants2 TcrAutoGenConsts => ref _tcrAutogenerateConstantsArray[0];
private bool _firstExecution; private bool _firstExecution;
private Vector2 _previousJitterOffset;
private int _resourceFrameIndex; private int _resourceFrameIndex;
private Vector2 _previousJitterOffset;
private float _preExposure;
private float _previousFramePreExposure;
public void Create(Fsr3Upscaler.ContextDescription contextDescription) public void Create(Fsr3Upscaler.ContextDescription contextDescription)
{ {
@ -88,7 +95,7 @@ namespace FidelityFX
_firstExecution = true; _firstExecution = true;
_resourceFrameIndex = 0; _resourceFrameIndex = 0;
UpscalerConsts.displaySize = _contextDescription.DisplaySize;
UpscalerConsts.maxUpscaleSize = _contextDescription.MaxUpscaleSize;
_resources.Create(_contextDescription); _resources.Create(_contextDescription);
CreatePasses(); CreatePasses();
@ -96,26 +103,36 @@ namespace FidelityFX
private void CreatePasses() 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); _accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer);
_sharpenPass = new Fsr3UpscalerSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer); _sharpenPass = new Fsr3UpscalerSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer);
_generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); _generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer);
_tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer); _tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer);
#if UNITY_EDITOR || DEVELOPMENT_BUILD
_debugViewPass = new Fsr3UpscalerDebugViewPass(_contextDescription, _resources, _upscalerConstantsBuffer);
#endif
} }
public void Destroy() public void Destroy()
{ {
#if UNITY_EDITOR || DEVELOPMENT_BUILD
DestroyPass(ref _debugViewPass);
#endif
DestroyPass(ref _tcrAutogeneratePass); DestroyPass(ref _tcrAutogeneratePass);
DestroyPass(ref _generateReactivePass); DestroyPass(ref _generateReactivePass);
DestroyPass(ref _computeLuminancePyramidPass);
DestroyPass(ref _lumaPyramidPass);
DestroyPass(ref _sharpenPass); DestroyPass(ref _sharpenPass);
DestroyPass(ref _accumulatePass); 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(); _resources.Destroy();
@ -145,12 +162,19 @@ namespace FidelityFX
{ {
DebugCheckDispatch(dispatchParams); DebugCheckDispatch(dispatchParams);
} }
if (dispatchParams.UseTextureArrays)
commandBuffer.EnableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY");
if (_firstExecution) if (_firstExecution)
{ {
commandBuffer.SetRenderTarget(_resources.LockStatus[0]);
commandBuffer.SetRenderTarget(_resources.Accumulation[0]);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[1]);
commandBuffer.SetRenderTarget(_resources.Accumulation[1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.Luma[0]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.Luma[1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
} }
@ -160,7 +184,7 @@ namespace FidelityFX
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0) if ((_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0)
dispatchParams.Exposure = new ResourceView(_resources.AutoExposure);
dispatchParams.Exposure = new ResourceView(_resources.FrameInfo);
else if (!dispatchParams.Exposure.IsValid) else if (!dispatchParams.Exposure.IsValid)
dispatchParams.Exposure = new ResourceView(_resources.DefaultExposure); dispatchParams.Exposure = new ResourceView(_resources.DefaultExposure);
@ -192,23 +216,22 @@ namespace FidelityFX
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstX = (UpscalerConsts.upscaleSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstY = (UpscalerConsts.upscaleSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchShadingChangePassX = ((UpscalerConsts.renderSize.x / 2) + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchShadingChangePassY = ((UpscalerConsts.renderSize.y / 2) + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
// Clear reconstructed depth for max depth store // Clear reconstructed depth for max depth store
if (resetAccumulation) if (resetAccumulation)
{ {
commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]);
commandBuffer.SetRenderTarget(_resources.Accumulation[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.SceneLuminance);
commandBuffer.SetRenderTarget(_resources.SpdMips);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
// Auto exposure always used to track luma changes in locking logic // Auto exposure always used to track luma changes in locking logic
commandBuffer.SetRenderTarget(_resources.AutoExposure);
commandBuffer.SetRenderTarget(_resources.FrameInfo);
commandBuffer.ClearRenderTarget(false, true, new Color(0f, 1e8f, 0f, 0f)); commandBuffer.ClearRenderTarget(false, true, new Color(0f, 1e8f, 0f, 0f));
// Reset atomic counter to 0 // Reset atomic counter to 0
@ -218,7 +241,7 @@ namespace FidelityFX
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option // FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) == Fsr3Upscaler.InitializationFlags.EnableDepthInverted; bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) == Fsr3Upscaler.InitializationFlags.EnableDepthInverted;
commandBuffer.SetRenderTarget(Fsr3ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth);
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white);
// Auto exposure // Auto exposure
@ -236,19 +259,13 @@ namespace FidelityFX
dispatchParams.TransparencyAndComposition = new ResourceView(_resources.AutoComposition); dispatchParams.TransparencyAndComposition = new ResourceView(_resources.AutoComposition);
} }
// Compute luminance pyramid
_computeLuminancePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
// Reconstruct previous depth
_reconstructPreviousDepthPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Depth clip
_depthClipPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Create locks
_lockPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Accumulate
_prepareInputsPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_lumaPyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
_shadingChangePyramidPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
_shadingChangePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchShadingChangePassX, dispatchShadingChangePassY);
_prepareReactivityPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_lumaInstabilityPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY); _accumulatePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
if (dispatchParams.EnableSharpening) if (dispatchParams.EnableSharpening)
@ -259,14 +276,23 @@ namespace FidelityFX
// Dispatch RCAS // Dispatch RCAS
const int threadGroupWorkRegionDimRcas = 16; const int threadGroupWorkRegionDimRcas = 16;
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsX = (UpscalerConsts.upscaleSize.x + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (UpscalerConsts.upscaleSize.y + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
_sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY); _sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
} }
#if UNITY_EDITOR || DEVELOPMENT_BUILD
if ((dispatchParams.Flags & Fsr3Upscaler.DispatchFlags.DrawDebugView) != 0)
{
_debugViewPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
}
#endif
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;
Fsr3UpscalerResources.DestroyAliasableResources(commandBuffer); Fsr3UpscalerResources.DestroyAliasableResources(commandBuffer);
commandBuffer.DisableShaderKeyword("UNITY_FSR_TEXTURE2D_X_ARRAY");
} }
public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams) public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams)
@ -309,11 +335,13 @@ namespace FidelityFX
private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation) private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation)
{ {
ref Fsr3Upscaler.UpscalerConstants constants = ref UpscalerConsts; ref Fsr3Upscaler.UpscalerConstants constants = ref UpscalerConsts;
constants.previousFrameJitterOffset = constants.jitterOffset;
constants.jitterOffset = dispatchParams.JitterOffset; constants.jitterOffset = dispatchParams.JitterOffset;
constants.previousFrameRenderSize = constants.renderSize;
constants.renderSize = dispatchParams.RenderSize; constants.renderSize = dispatchParams.RenderSize;
constants.maxRenderSize = _contextDescription.MaxRenderSize; constants.maxRenderSize = _contextDescription.MaxRenderSize;
constants.inputColorResourceDimensions = dispatchParams.InputResourceSize;
// Compute the horizontal FOV for the shader from the vertical one // Compute the horizontal FOV for the shader from the vertical one
float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y; float aspectRatio = (float)dispatchParams.RenderSize.x / dispatchParams.RenderSize.y;
@ -323,14 +351,32 @@ namespace FidelityFX
// Compute params to enable device depth to view space depth computation in shader // Compute params to enable device depth to view space depth computation in shader
constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams); constants.deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams(dispatchParams);
constants.previousFrameUpscaleSize = constants.upscaleSize;
if (dispatchParams.UpscaleSize.x == 0 && dispatchParams.UpscaleSize.y == 0)
{
constants.upscaleSize = _contextDescription.MaxUpscaleSize;
}
else
{
constants.upscaleSize = dispatchParams.UpscaleSize;
}
// To be updated if resource is larger than the actual image size // To be updated if resource is larger than the actual image size
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / _contextDescription.DisplaySize.x, (float)constants.renderSize.y / _contextDescription.DisplaySize.y);
constants.previousFramePreExposure = constants.preExposure;
constants.preExposure = (dispatchParams.PreExposure != 0) ? dispatchParams.PreExposure : 1.0f;
constants.downscaleFactor = new Vector2((float)constants.renderSize.x / constants.upscaleSize.x, (float)constants.renderSize.y / constants.upscaleSize.y);
// Calculate pre-exposure relevant factors
constants.deltaPreExposure = 1.0f;
_previousFramePreExposure = _preExposure;
_preExposure = dispatchParams.PreExposure != 0.0f ? dispatchParams.PreExposure : 1.0f;
if (_previousFramePreExposure > 0.0f)
{
constants.deltaPreExposure = _preExposure / _previousFramePreExposure;
}
// Motion vector data // Motion vector data
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.displaySize : constants.renderSize;
Vector2Int motionVectorsTargetSize = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) != 0 ? constants.upscaleSize : constants.renderSize;
constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize; constants.motionVectorScale = dispatchParams.MotionVectorScale / motionVectorsTargetSize;
// Compute jitter cancellation // Compute jitter cancellation
@ -340,7 +386,7 @@ namespace FidelityFX
_previousJitterOffset = constants.jitterOffset; _previousJitterOffset = constants.jitterOffset;
} }
int jitterPhaseCount = Fsr3Upscaler.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.DisplaySize.x);
int jitterPhaseCount = Fsr3Upscaler.GetJitterPhaseCount(dispatchParams.RenderSize.x, _contextDescription.MaxUpscaleSize.x);
if (resetAccumulation || constants.jitterPhaseCount == 0) if (resetAccumulation || constants.jitterPhaseCount == 0)
{ {
constants.jitterPhaseCount = jitterPhaseCount; constants.jitterPhaseCount = jitterPhaseCount;
@ -360,14 +406,7 @@ namespace FidelityFX
if (resetAccumulation) if (resetAccumulation)
constants.frameIndex = 0; constants.frameIndex = 0;
else else
constants.frameIndex++;
// Shading change usage of the SPD mip levels
constants.lumaMipLevelToUse = Fsr3UpscalerPass.ShadingChangeMipLevel;
float mipDiv = 2 << constants.lumaMipLevelToUse;
constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv);
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv);
constants.frameIndex += 1.0f;
} }
private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams) private Vector4 SetupDeviceDepthToViewSpaceDepthParams(Fsr3Upscaler.DispatchDescription dispatchParams)
@ -458,14 +497,14 @@ namespace FidelityFX
Debug.LogError("MotionVectors resource is null"); Debug.LogError("MotionVectors resource is null");
} }
if (!dispatchParams.Output.IsValid)
if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0)
{ {
Debug.LogError("Output resource is null");
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present");
} }
if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableAutoExposure) != 0)
if (!dispatchParams.Output.IsValid)
{ {
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present");
Debug.LogError("Output resource is null");
} }
if (Mathf.Abs(dispatchParams.JitterOffset.x) > 1.0f || Mathf.Abs(dispatchParams.JitterOffset.y) > 1.0f) if (Mathf.Abs(dispatchParams.JitterOffset.x) > 1.0f || Mathf.Abs(dispatchParams.JitterOffset.y) > 1.0f)
@ -493,6 +532,11 @@ namespace FidelityFX
Debug.LogWarning("RenderSize contains zero dimension"); Debug.LogWarning("RenderSize contains zero dimension");
} }
if (dispatchParams.Sharpness < 0.0f || dispatchParams.Sharpness > 1.0f)
{
Debug.LogWarning("Sharpness contains value outside of expected range [0.0, 1.0]");
}
if (dispatchParams.FrameTimeDelta > 1.0f) if (dispatchParams.FrameTimeDelta > 1.0f)
{ {
Debug.LogWarning("FrameTimeDelta is greater than 1.0f - this value should be seconds (~0.0166 for 60fps)"); Debug.LogWarning("FrameTimeDelta is greater than 1.0f - this value should be seconds (~0.0166 for 60fps)");

3
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerContext.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 742dda30b4604d5488e7eeda3cf04d56
timeCreated: 1673442225

254
Assets/Scripts/Core/Fsr3UpscalerPass.cs → Packages/fidelityfx.fsr/Runtime/FSR3/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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,6 +21,7 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using UnityEngine; using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering; using UnityEngine.Rendering;
namespace FidelityFX namespace FidelityFX
@ -32,14 +33,14 @@ namespace FidelityFX
/// </summary> /// </summary>
internal abstract class Fsr3UpscalerPass: IDisposable internal abstract class Fsr3UpscalerPass: IDisposable
{ {
internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR3UPSCALER_SHADING_CHANGE_MIP_LEVEL define
protected readonly Fsr3Upscaler.ContextDescription ContextDescription; protected readonly Fsr3Upscaler.ContextDescription ContextDescription;
protected readonly Fsr3UpscalerResources Resources; protected readonly Fsr3UpscalerResources Resources;
protected readonly ComputeBuffer Constants; protected readonly ComputeBuffer Constants;
protected ComputeShader ComputeShader; protected ComputeShader ComputeShader;
protected int KernelIndex; protected int KernelIndex;
protected CustomSampler Sampler;
protected Fsr3UpscalerPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) protected Fsr3UpscalerPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
{ {
@ -52,8 +53,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) protected void InitComputeShader(string passName, ComputeShader shader)
{ {
InitComputeShader(passName, shader, ContextDescription.Flags); InitComputeShader(passName, shader, ContextDescription.Flags);
@ -63,11 +71,12 @@ namespace FidelityFX
{ {
if (shader == null) if (shader == null)
{ {
throw new MissingReferenceException($"Shader for FSR3 Upscaler '{passName}' could not be loaded! Please ensure it is included in the project correctly.");
throw new MissingReferenceException($"Shader for FSR3 Upscaler pass '{passName}' could not be loaded! Please ensure it is included in the project correctly.");
} }
ComputeShader = shader; ComputeShader = shader;
KernelIndex = ComputeShader.FindKernel("CS"); KernelIndex = ComputeShader.FindKernel("CS");
Sampler = CustomSampler.Create(passName);
bool useLut = false; bool useLut = false;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ #if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
@ -84,37 +93,64 @@ namespace FidelityFX
if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH");
if (useLut) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE"); if (useLut) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF"); if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF");
}
}
internal class Fsr3UpscalerPrepareInputsPass : Fsr3UpscalerPass
{
public Fsr3UpscalerPrepareInputsPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Prepare Inputs", contextDescription.Shaders.prepareInputsPass);
}
// Inform the shader which render pipeline we're currently using
var pipeline = GraphicsSettings.currentRenderPipeline;
if (pipeline != null && pipeline.GetType().Name.Contains("HDRenderPipeline"))
{
ComputeShader.EnableKeyword("UNITY_FSR3UPSCALER_HDRP");
}
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;
ref var motionVectors = ref dispatchParams.MotionVectors;
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.UavDilatedMotionVectors, Resources.DilatedVelocity);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedDepth, Resources.DilatedDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavReconstructedPrevNearestDepth, Resources.ReconstructedPrevNearestDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavFarthestDepth, Fsr3ShaderIDs.UavIntermediate);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
} }
} }
internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass
internal class Fsr3UpscalerLumaPyramidPass : Fsr3UpscalerPass
{ {
private readonly ComputeBuffer _spdConstants; 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) : base(contextDescription, resources, constants)
{ {
_spdConstants = spdConstants; _spdConstants = spdConstants;
InitComputeShader("compute_luminance_pyramid_pass", contextDescription.Shaders.computeLuminancePyramidPass);
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)
{ {
ref var color = ref dispatchParams.Color;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFarthestDepth, Fsr3ShaderIDs.UavIntermediate);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoExposure, Resources.AutoExposure);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavFrameInfo, Resources.FrameInfo);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip0, Resources.SpdMips, 0);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip1, Resources.SpdMips, 1);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip2, Resources.SpdMips, 2);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip3, Resources.SpdMips, 3);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip4, Resources.SpdMips, 4);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip5, Resources.SpdMips, 5);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr3Upscaler.SpdConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr3Upscaler.SpdConstants>());
@ -123,62 +159,85 @@ 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) : base(contextDescription, resources, constants)
{ {
InitComputeShader("reconstruct_previous_depth_pass", contextDescription.Shaders.reconstructPreviousDepthPass);
_spdConstants = spdConstants;
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 color = ref dispatchParams.Color;
ref var depth = ref dispatchParams.Depth;
ref var motionVectors = ref dispatchParams.MotionVectors;
ref var exposure = ref dispatchParams.Exposure; 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.SrvCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPreviousLuma, Resources.Luma[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedVelocity);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip0, Resources.SpdMips, 0);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip1, Resources.SpdMips, 1);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip2, Resources.SpdMips, 2);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip3, Resources.SpdMips, 3);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip4, Resources.SpdMips, 4);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavSpdMip5, Resources.SpdMips, 5);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr3Upscaler.SpdConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
} }
} }
internal class Fsr3UpscalerDepthClipPass : Fsr3UpscalerPass
internal class Fsr3UpscalerShadingChangePass : Fsr3UpscalerPass
{ {
public Fsr3UpscalerDepthClipPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
public Fsr3UpscalerShadingChangePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
InitComputeShader("depth_clip_pass", contextDescription.Shaders.depthClipPass);
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);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
internal class Fsr3UpscalerPrepareReactivityPass : Fsr3UpscalerPass
{
public Fsr3UpscalerPrepareReactivityPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
InitComputeShader("Prepare Reactivity", contextDescription.Shaders.prepareReactivityPass);
}
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;
ref var motionVectors = ref dispatchParams.MotionVectors;
ref var exposure = ref dispatchParams.Exposure; ref var exposure = ref dispatchParams.Exposure;
ref var reactive = ref dispatchParams.Reactive; ref var reactive = ref dispatchParams.Reactive;
ref var tac = ref dispatchParams.TransparencyAndComposition; ref var tac = ref dispatchParams.TransparencyAndComposition;
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.SrvReconstructedPrevNearestDepth, Resources.ReconstructedPrevNearestDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedVelocity);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedDepth, Resources.DilatedDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvAccumulation, Resources.Accumulation[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvShadingChange, Fsr3ShaderIDs.UavShadingChange);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvReconstructedPrevNearestDepth, Fsr3ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedDepth, Fsr3ShaderIDs.UavDilatedDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAccumulation, Resources.Accumulation[frameIndex]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
@ -186,17 +245,29 @@ 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) : base(contextDescription, resources, constants)
{ {
InitComputeShader("lock_pass", contextDescription.Shaders.lockPass);
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)
{ {
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLockInputLuma, Fsr3ShaderIDs.UavLockInputLuma);
ref var exposure = ref dispatchParams.Exposure;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedVelocity);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFrameInfo, Resources.FrameInfo);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFarthestDepthMip1, Fsr3ShaderIDs.UavFarthestDepthMip1);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLumaInstability, Fsr3ShaderIDs.UavIntermediate);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
@ -214,13 +285,13 @@ namespace FidelityFX
public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
InitComputeShader("accumulate_pass", contextDescription.Shaders.accumulatePass);
InitComputeShader("Accumulate", contextDescription.Shaders.accumulatePass);
#if UNITY_2021_2_OR_NEWER #if UNITY_2021_2_OR_NEWER
_sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword); _sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword);
#endif #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 UNITY_2021_2_OR_NEWER
if (dispatchParams.EnableSharpening) if (dispatchParams.EnableSharpening)
@ -234,9 +305,16 @@ namespace FidelityFX
commandBuffer.DisableShaderKeyword(SharpeningKeyword); commandBuffer.DisableShaderKeyword(SharpeningKeyword);
#endif #endif
ref var color = ref dispatchParams.Color;
ref var exposure = ref dispatchParams.Exposure;
ref var output = ref dispatchParams.Output;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks);
if ((ContextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) if ((ContextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0)
{ {
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedVelocity);
} }
else else
{ {
@ -244,24 +322,14 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
} }
ref var exposure = ref dispatchParams.Exposure;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedReactiveMasks, Fsr3ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLockStatus, Resources.LockStatus[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPreparedInputColor, Fsr3ShaderIDs.UavPreparedInputColor);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLanczosLut, Resources.LanczosLut); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLanczosLut, Resources.LanczosLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvAutoExposure, Resources.AutoExposure);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvFarthestDepthMip1, Fsr3ShaderIDs.UavFarthestDepthMip1);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvCurrentLuma, Resources.Luma[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLumaInstability, Fsr3ShaderIDs.UavIntermediate);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
ref var output = ref dispatchParams.Output;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
@ -279,10 +347,10 @@ namespace FidelityFX
{ {
_rcasConstants = rcasConstants; _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; ref var exposure = ref dispatchParams.Exposure;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
@ -307,15 +375,17 @@ namespace FidelityFX
{ {
_generateReactiveConstants = generateReactiveConstants; _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) public void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.GenerateReactiveDescription dispatchParams, int dispatchX, int dispatchY)
{ {
commandBuffer.BeginSample(Sampler);
ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly; ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly;
ref var color = ref dispatchParams.ColorPreUpscale; ref var color = ref dispatchParams.ColorPreUpscale;
ref var reactive = ref dispatchParams.OutReactive; ref var reactive = ref dispatchParams.OutReactive;
@ -327,6 +397,8 @@ namespace FidelityFX
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf<Fsr3Upscaler.GenerateReactiveConstants>()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _generateReactiveConstants, 0, Marshal.SizeOf<Fsr3Upscaler.GenerateReactiveConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
commandBuffer.EndSample(Sampler);
} }
} }
@ -339,10 +411,10 @@ namespace FidelityFX
{ {
_tcrAutogenerateConstants = tcrAutogenerateConstants; _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 color = ref dispatchParams.Color;
ref var motionVectors = ref dispatchParams.MotionVectors; ref var motionVectors = ref dispatchParams.MotionVectors;
@ -369,4 +441,32 @@ namespace FidelityFX
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); 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<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
}
#endif
} }

3
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerPass.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9e0cf27d80d1d4d4c81450791a411ead
timeCreated: 1676885169

245
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs

@ -0,0 +1,245 @@
// 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.
using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
namespace FidelityFX
{
/// <summary>
/// Helper class for bundling and managing persistent resources required by the FSR3 Upscaler process.
/// This includes lookup tables, default fallback resources and double-buffered resources that get swapped between frames.
/// </summary>
internal class Fsr3UpscalerResources
{
public Texture2D LanczosLut;
public Texture2D DefaultExposure;
public Texture2D DefaultReactive;
public RenderTexture SpdAtomicCounter;
public RenderTexture SpdMips;
public RenderTexture DilatedVelocity;
public RenderTexture DilatedDepth;
public RenderTexture ReconstructedPrevNearestDepth;
public RenderTexture FrameInfo;
public RenderTexture AutoReactive;
public RenderTexture AutoComposition;
public readonly RenderTexture[] Accumulation = new RenderTexture[2];
public readonly RenderTexture[] Luma = new RenderTexture[2];
public readonly RenderTexture[] InternalUpscaled = new RenderTexture[2];
public readonly RenderTexture[] LumaHistory = new RenderTexture[2];
public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2];
public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2];
public void Create(Fsr3Upscaler.ContextDescription contextDescription)
{
// Generate the data for the LUT
const int lanczos2LutWidth = 128;
float[] lanczos2Weights = new float[lanczos2LutWidth];
for (int currentLanczosWidthIndex = 0; currentLanczosWidthIndex < lanczos2LutWidth; ++currentLanczosWidthIndex)
{
float x = 2.0f * currentLanczosWidthIndex / (lanczos2LutWidth - 1);
float y = Fsr3Upscaler.Lanczos2(x);
lanczos2Weights[currentLanczosWidthIndex] = y;
}
Vector2Int maxRenderSize = contextDescription.MaxRenderSize;
Vector2Int maxRenderSizeDiv2 = maxRenderSize / 2;
// Resource FSR3UPSCALER_LanczosLutData: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R16_SNORM, FFX_RESOURCE_FLAGS_NONE
// R16_SNorm textures are not supported by Unity on most platforms, strangely enough. So instead we use R32_SFloat and upload pre-normalized float data.
LanczosLut = new Texture2D(lanczos2LutWidth, 1, GraphicsFormat.R32_SFloat, TextureCreationFlags.None) { name = "FSR3UPSCALER_LanczosLutData" };
LanczosLut.SetPixelData(lanczos2Weights, 0);
LanczosLut.Apply();
// Resource FSR3UPSCALER_DefaultReactivityMask: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
DefaultReactive = new Texture2D(1, 1, GraphicsFormat.R8_UNorm, TextureCreationFlags.None) { name = "FSR3UPSCALER_DefaultReactivityMask" };
DefaultReactive.SetPixel(0, 0, Color.clear);
DefaultReactive.Apply();
// Resource FSR3UPSCALER_DefaultExposure: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE
DefaultExposure = new Texture2D(1, 1, GraphicsFormat.R32G32_SFloat, TextureCreationFlags.None) { name = "FSR3UPSCALER_DefaultExposure" };
DefaultExposure.SetPixel(0, 0, Color.clear);
DefaultExposure.Apply();
// Resource FSR3UPSCALER_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
// Despite what the original FSR3 codebase says, this resource really isn't aliasable. Resetting this counter to 0 every frame breaks auto-exposure on MacOS Metal.
SpdAtomicCounter = new RenderTexture(1, 1, 0, GraphicsFormat.R32_UInt) { name = "FSR3UPSCALER_SpdAtomicCounter", enableRandomWrite = true };
SpdAtomicCounter.Create();
// Resource FSR3UPSCALER_SpdMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
// This is a rather special case: it's an aliasable resource, but because we require a mipmap chain and bind specific mip levels per shader, we can't easily use temporary RTs for this.
int mipCount = 1 + Mathf.FloorToInt(Mathf.Log(Math.Max(maxRenderSizeDiv2.x, maxRenderSizeDiv2.y), 2.0f));
SpdMips = new RenderTexture(maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, GraphicsFormat.R16G16_SFloat, mipCount) { name = "FSR3UPSCALER_SpdMips", enableRandomWrite = true, useMipMap = true, autoGenerateMips = false };
SpdMips.Create();
// Resource FSR3UPSCALER_DilatedVelocity: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16_FLOAT, FFX_RESOURCE_FLAGS_NONE
DilatedVelocity = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R16G16_SFloat) { name = "FSR3UPSCALER_DilatedVelocity", enableRandomWrite = true };
DilatedVelocity.Create();
// Resource FSR3UPSCALER_DilatedDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_FLOAT, FFX_RESOURCE_FLAGS_NONE
DilatedDepth = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R32_SFloat) { name = "FSR3UPSCALER_DilatedDepth", enableRandomWrite = true };
DilatedDepth.Create();
// Resource FSR3UPSCALER_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_NONE
ReconstructedPrevNearestDepth = new RenderTexture(maxRenderSize.x, maxRenderSize.y, 0, GraphicsFormat.R32_UInt) { name = "FSR3UPSCALER_ReconstructedPrevNearestDepth", enableRandomWrite = true };
ReconstructedPrevNearestDepth.Create();
// Resource FSR3UPSCALER_FrameInfo: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT, FFX_RESOURCE_FLAGS_NONE
FrameInfo = new RenderTexture(1, 1, 0, GraphicsFormat.R32G32B32A32_SFloat) { name = "FSR3UPSCALER_FrameInfo", enableRandomWrite = true };
FrameInfo.Create();
// Resources FSR3UPSCALER_Accumulation1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(Accumulation, "FSR3UPSCALER_Accumulation", maxRenderSize, GraphicsFormat.R8_UNorm);
// Resources FSR3UPSCALER_Luma1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(Luma, "FSR3UPSCALER_Luma", maxRenderSize, GraphicsFormat.R16_SFloat);
// Resources FSR3UPSCALER_InternalUpscaled1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(InternalUpscaled, "FSR3UPSCALER_InternalUpscaled", contextDescription.MaxUpscaleSize, GraphicsFormat.R16G16B16A16_SFloat);
// Resources FSR3UPSCALER_LumaHistory1/2: FFX_RESOURCE_USAGE_RENDERTARGET | FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", maxRenderSize, GraphicsFormat.R16G16B16A16_SFloat);
}
public void CreateTcrAutogenResources(Fsr3Upscaler.ContextDescription contextDescription)
{
// Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
AutoReactive = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoReactive", enableRandomWrite = true };
AutoReactive.Create();
// Resource FSR3UPSCALER_AutoComposition: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
AutoComposition = new RenderTexture(contextDescription.MaxRenderSize.x, contextDescription.MaxRenderSize.y, 0, GraphicsFormat.R8_UNorm) { name = "FSR3UPSCALER_AutoComposition", enableRandomWrite = true };
AutoComposition.Create();
// Resources FSR3UPSCALER_PrevPreAlpha0/1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R11G11B10_FLOAT, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(PrevPreAlpha, "FSR3UPSCALER_PrevPreAlpha", contextDescription.MaxRenderSize, GraphicsFormat.B10G11R11_UFloatPack32);
// Resources FSR3UPSCALER_PrevPostAlpha0/1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R11G11B10_FLOAT, FFX_RESOURCE_FLAGS_NONE
CreateDoubleBufferedResource(PrevPostAlpha, "FSR3UPSCALER_PrevPostAlpha", contextDescription.MaxRenderSize, GraphicsFormat.B10G11R11_UFloatPack32);
}
// Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between passes
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr3Upscaler.ContextDescription contextDescription, Fsr3Upscaler.DispatchDescription dispatchParams)
{
Vector2Int maxUpscaleSize = contextDescription.MaxUpscaleSize;
Vector2Int maxRenderSize = contextDescription.MaxRenderSize;
Vector2Int maxRenderSizeDiv2 = maxRenderSize / 2;
// FSR3UPSCALER_IntermediateFp16x1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavIntermediate, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R16_SFloat, 1, true);
// FSR3UPSCALER_ShadingChange: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavShadingChange, maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
// FSR3UPSCALER_NewLocks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavNewLocks, maxUpscaleSize.x, maxUpscaleSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
// FSR3UPSCALER_FarthestDepthMip1: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavFarthestDepthMip1, maxRenderSizeDiv2.x, maxRenderSizeDiv2.y, 0, default, GraphicsFormat.R16_SFloat, 1, true);
// FSR3UPSCALER_DilatedReactiveMasks: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8G8B8A8_UNORM, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R8G8B8A8_UNorm, 1, true);
}
public static void DestroyAliasableResources(CommandBuffer commandBuffer)
{
// Release all of the aliasable resources used this frame
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavFarthestDepthMip1);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavNewLocks);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavShadingChange);
commandBuffer.ReleaseTemporaryRT(Fsr3ShaderIDs.UavIntermediate);
}
private static void CreateDoubleBufferedResource(RenderTexture[] resource, string name, Vector2Int size, GraphicsFormat format)
{
for (int i = 0; i < 2; ++i)
{
resource[i] = new RenderTexture(size.x, size.y, 0, format) { name = name + (i + 1), enableRandomWrite = true };
resource[i].Create();
}
}
public void Destroy()
{
DestroyTcrAutogenResources();
DestroyResource(LumaHistory);
DestroyResource(InternalUpscaled);
DestroyResource(Luma);
DestroyResource(Accumulation);
DestroyResource(ref FrameInfo);
DestroyResource(ref ReconstructedPrevNearestDepth);
DestroyResource(ref DilatedDepth);
DestroyResource(ref DilatedVelocity);
DestroyResource(ref SpdMips);
DestroyResource(ref SpdAtomicCounter);
DestroyResource(ref DefaultReactive);
DestroyResource(ref DefaultExposure);
DestroyResource(ref LanczosLut);
}
public void DestroyTcrAutogenResources()
{
DestroyResource(PrevPostAlpha);
DestroyResource(PrevPreAlpha);
DestroyResource(ref AutoComposition);
DestroyResource(ref AutoReactive);
}
private static void DestroyResource(ref Texture2D resource)
{
if (resource == null)
return;
#if UNITY_EDITOR
if (Application.isPlaying && !UnityEditor.EditorApplication.isPaused)
UnityEngine.Object.Destroy(resource);
else
UnityEngine.Object.DestroyImmediate(resource);
#else
UnityEngine.Object.Destroy(resource);
#endif
resource = null;
}
private static void DestroyResource(ref RenderTexture resource)
{
if (resource == null)
return;
resource.Release();
resource = null;
}
private static void DestroyResource(RenderTexture[] resource)
{
for (int i = 0; i < resource.Length; ++i)
DestroyResource(ref resource[i]);
}
}
}

3
Packages/fidelityfx.fsr/Runtime/FSR3/Fsr3UpscalerResources.cs.meta

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6749e0e55c9ac5a4f869bc73dfbb7163
timeCreated: 1677236102

14
Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef

@ -0,0 +1,14 @@
{
"name": "FidelityFX.FSR",
"rootNamespace": "FidelityFX",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

7
Packages/fidelityfx.fsr/Runtime/FidelityFX.FSR.asmdef.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: eb1f729ceec147d4a813e8e75b65dc12
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

2
Assets/Shaders.meta → Packages/fidelityfx.fsr/Shaders.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f1c65c7377a34fe41beb57484d87a08b
guid: af3a6660394230a4bb247808bbefe9f4
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

41
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute

@ -0,0 +1,41 @@
// 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_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE
#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
// Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions
#ifdef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE
#undef FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE
#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 1
#endif
#include "shaders/ffx_fsr2_accumulate_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_accumulate_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7e791d69a5be98247a93b63897bc64df
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

14
Assets/Shaders/FSR3/ffx_fsr3upscaler_depth_clip_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,12 +21,12 @@
#pragma kernel CS #pragma kernel CS
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_depth_clip_pass.hlsl"
#include "shaders/ffx_fsr2_autogen_reactive_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_autogen_reactive_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 67ee1b32ca5e4234db9f06984c783dee
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

14
Assets/Shaders/FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,13 +21,13 @@
#pragma kernel CS #pragma kernel CS
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
// Wave operations require shader model 6.0; this can only be enabled when using DXC on D3D12 // Wave operations require shader model 6.0; this can only be enabled when using DXC on D3D12
// These pragmas are commented out by default as Unity will sometimes ignore the #if's and try to enable these features anyway. // These pragmas are commented out by default as Unity will sometimes ignore the #if's and try to enable these features anyway.
@ -39,4 +39,4 @@
#define FFX_SPD_NO_WAVE_OPERATIONS #define FFX_SPD_NO_WAVE_OPERATIONS
//#endif //#endif
#include "shaders/ffx_fsr3upscaler_compute_luminance_pyramid_pass.hlsl"
#include "shaders/ffx_fsr2_compute_luminance_pyramid_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 04c3480675e29a340808141e68d4cc8b
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

32
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute

@ -0,0 +1,32 @@
// 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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr2_depth_clip_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_depth_clip_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b207de122e2c4b844b89dcd7c5c77c80
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

32
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute

@ -0,0 +1,32 @@
// 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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr2_lock_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_lock_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 20b7864a7e7258946aaf0f1996febad3
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

31
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute

@ -0,0 +1,31 @@
// 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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr2_rcas_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_rcas_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 40815651f0f5d994cb73da9816a7ff9b
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

33
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute

@ -0,0 +1,33 @@
// 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_FSR2_OPTION_HDR_COLOR_INPUT
#pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr2_reconstruct_previous_depth_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5060dfafe45aa67459629186ceb7464e
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

32
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute

@ -0,0 +1,32 @@
// 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_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr2_tcr_autogen_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr2_tcr_autogen_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f8b1c27fb6a544b43b38903592240500
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Shaders/FSR3/ffx_fsr3upscaler_accumulate_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -24,13 +24,11 @@
#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE #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_HDR_COLOR_INPUT
#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS #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 __ FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING
#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
// Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions // Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions
#ifdef FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE #ifdef FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_accumulate_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_accumulate_pass.compute.meta

9
Assets/Shaders/FSR3/ffx_fsr3upscaler_autogen_reactive_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,12 +21,9 @@
#pragma kernel CS #pragma kernel CS
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#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 __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_autogen_reactive_pass.hlsl" #include "shaders/ffx_fsr3upscaler_autogen_reactive_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_autogen_reactive_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute.meta

29
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute

@ -0,0 +1,29 @@
// 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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_debug_view_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_debug_view_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cb24a71d54164c54eb5e86839acd48c5
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

29
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute

@ -0,0 +1,29 @@
// 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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_luma_instability_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_lock_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute.meta

22
Assets/Shaders/FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,13 +21,19 @@
#pragma kernel CS #pragma kernel CS
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#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 __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_reconstruct_previous_depth_pass.hlsl"
// Wave operations require shader model 6.0; this can only be enabled when using DXC on D3D12
// These pragmas are commented out by default as Unity will sometimes ignore the #if's and try to enable these features anyway.
// Uncomment the below lines if you intend to try wave operations on DX12 with the DXC compiler.
//#if defined(UNITY_COMPILER_DXC) && defined(SHADER_API_D3D12)
//#pragma require WaveBasic // Required for WaveGetLaneIndex
//#pragma require WaveBallot // Required for WaveReadLaneAt
//#else
#define FFX_SPD_NO_WAVE_OPERATIONS
//#endif
#include "shaders/ffx_fsr3upscaler_luma_pyramid_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute.meta

9
Assets/Shaders/FSR3/ffx_fsr3upscaler_lock_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -22,9 +22,10 @@
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS #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_INVERTED_DEPTH
#include "ffx_fsr3upscaler_unity_common.cginc"
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "shaders/ffx_fsr3upscaler_lock_pass.hlsl"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_prepare_inputs_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute.meta

29
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute

@ -0,0 +1,29 @@
// 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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_prepare_reactivity_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_depth_clip_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute.meta

10
Assets/Shaders/FSR3/ffx_fsr3upscaler_rcas_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -20,12 +20,8 @@
#pragma kernel CS #pragma kernel CS
#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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_rcas_pass.hlsl" #include "shaders/ffx_fsr3upscaler_rcas_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_rcas_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_rcas_pass.compute.meta

29
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute

@ -0,0 +1,29 @@
// 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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_shading_change_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9a2bff2f97619ed4989d9b0577ba0641
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

32
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute

@ -0,0 +1,32 @@
// 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 __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr_unity_common.cginc"
// Wave operations require shader model 6.0; this can only be enabled when using DXC on D3D12
#define FFX_SPD_NO_WAVE_OPERATIONS
#include "shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.hlsl"

8
Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 251e663738905fa4d8817001682d802f
ComputeShaderImporter:
externalObjects: {}
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Shaders/FSR3/ffx_fsr3upscaler_tcr_autogen_pass.compute → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,12 +21,10 @@
#pragma kernel CS #pragma kernel CS
#pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_HALF
#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_JITTERED_MOTION_VECTORS
#pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH
#pragma multi_compile_local __ UNITY_FSR3UPSCALER_HDRP
#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY
#include "ffx_fsr3upscaler_unity_common.cginc"
#include "ffx_fsr_unity_common.cginc"
#include "shaders/ffx_fsr3upscaler_tcr_autogen_pass.hlsl" #include "shaders/ffx_fsr3upscaler_tcr_autogen_pass.hlsl"

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_tcr_autogen_pass.compute.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute.meta

60
Assets/Shaders/FSR3/ffx_fsr3upscaler_unity_common.cginc → Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc

@ -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 // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -21,6 +21,7 @@
// Suppress a few warnings produced by FFX's HLSL code // Suppress a few warnings produced by FFX's HLSL code
#pragma warning(disable: 3078) // Loop control variable conflicts #pragma warning(disable: 3078) // Loop control variable conflicts
#pragma warning(disable: 3203) // Signed/unsigned mismatch #pragma warning(disable: 3203) // Signed/unsigned mismatch
#pragma warning(disable: 3556) // Integer divides might be much slower, try using uints if possible
#define FFX_GPU // Compiling for GPU #define FFX_GPU // Compiling for GPU
#define FFX_HLSL // Compile for plain HLSL #define FFX_HLSL // Compile for plain HLSL
@ -45,38 +46,37 @@
#endif #endif
// Workaround for HDRP using texture arrays for its camera buffers on some platforms // Workaround for HDRP using texture arrays for its camera buffers on some platforms
// The below defines are copied from: Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl
#if defined(UNITY_FSR3UPSCALER_HDRP)
// Must be in sync with C# with property useTexArray in TextureXR.cs
#if ((defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_GAMECORE)) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN)
#define UNITY_TEXTURE2D_X_ARRAY_SUPPORTED
#endif
// Control if TEXTURE2D_X macros will expand to texture arrays
#if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && !defined(DISABLE_TEXTURE2D_X_ARRAY)
#define USE_TEXTURE2D_X_AS_ARRAY
#endif
// The below defines are adapted from: Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl
#if ((defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_GAMECORE)) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN)
#define UNITY_TEXTURE2D_X_ARRAY_SUPPORTED
#endif
// Early defines for single-pass instancing
#if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED)
#define UNITY_STEREO_INSTANCING_ENABLED
#endif
// Control if TEXTURE2D_X macros will expand to texture arrays
#if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && defined(UNITY_FSR_TEXTURE2D_X_ARRAY)
#define USE_TEXTURE2D_X_AS_ARRAY
#endif
// Helper macros to handle XR single-pass with Texture2DArray
#if defined(USE_TEXTURE2D_X_AS_ARRAY)
// Early defines for single-pass instancing
#if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED)
#define UNITY_STEREO_INSTANCING_ENABLED
#endif
// Only single-pass stereo instancing used array indexing
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
#define SLICE_ARRAY_INDEX unity_StereoEyeIndex
#else
#define SLICE_ARRAY_INDEX 0
#endif
// Helper macros to handle XR single-pass with Texture2DArray
#if defined(USE_TEXTURE2D_X_AS_ARRAY)
// Declare and sample camera buffers as texture arrays
#define UNITY_FSR3_TEX2D(type) Texture2DArray<type>
#define UNITY_FSR3_RWTEX2D(type) RWTexture2DArray<type>
#define UNITY_FSR3_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX)
#define UNITY_FSR3_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX)
// Only single-pass stereo instancing used array indexing
#if defined(UNITY_STEREO_INSTANCING_ENABLED)
static uint unity_StereoEyeIndex;
#define SLICE_ARRAY_INDEX unity_StereoEyeIndex
#else
#define SLICE_ARRAY_INDEX 0
#endif #endif
// Declare and sample camera buffers as texture arrays
#define UNITY_FSR_TEX2D(type) Texture2DArray<type>
#define UNITY_FSR_RWTEX2D(type) RWTexture2DArray<type>
#define UNITY_FSR_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX)
#define UNITY_FSR_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX)
#define UNITY_FSR_GETDIMS(tex, w, h) { FfxUInt32 uElements; (tex).GetDimensions((w), (h), uElements); }
#endif #endif

0
Assets/Shaders/FSR3/ffx_fsr3upscaler_unity_common.cginc.meta → Packages/fidelityfx.fsr/Shaders/ffx_fsr_unity_common.cginc.meta

2
Assets/Shaders/FSR3/shaders.meta → Packages/fidelityfx.fsr/Shaders/shaders.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8364d4f86c613ec4d999d062f5f773b8
guid: c3f8af1cab72f0e46acba11c5820d923
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

54
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_common_types.h → Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h

@ -1,16 +1,17 @@
// This file is part of the FidelityFX SDK. // This file is part of the FidelityFX SDK.
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -19,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
#ifndef FFX_COMMON_TYPES_H #ifndef FFX_COMMON_TYPES_H
#define FFX_COMMON_TYPES_H #define FFX_COMMON_TYPES_H
@ -106,7 +106,42 @@ typedef float FfxFloat32x3[3];
/// @ingroup CPUTypes /// @ingroup CPUTypes
typedef float FfxFloat32x4[4]; typedef float FfxFloat32x4[4];
/// A typedef for a 2-dimensional 32bit unsigned integer.
/// A typedef for a 2x2 floating point matrix.
///
/// @ingroup CPUTypes
typedef float FfxFloat32x2x2[4];
/// A typedef for a 3x3 floating point matrix.
///
/// @ingroup CPUTypes
typedef float FfxFloat32x3x3[9];
/// A typedef for a 3x4 floating point matrix.
///
/// @ingroup CPUTypes
typedef float FfxFloat32x3x4[12];
/// A typedef for a 4x4 floating point matrix.
///
/// @ingroup CPUTypes
typedef float FfxFloat32x4x4[16];
/// A typedef for a 2-dimensional 32bit signed integer.
///
/// @ingroup CPUTypes
typedef int32_t FfxInt32x2[2];
/// A typedef for a 3-dimensional 32bit signed integer.
///
/// @ingroup CPUTypes
typedef int32_t FfxInt32x3[3];
/// A typedef for a 4-dimensional 32bit signed integer.
///
/// @ingroup CPUTypes
typedef int32_t FfxInt32x4[4];
/// A typedef for a 2-dimensional 32bit usigned integer.
/// ///
/// @ingroup CPUTypes /// @ingroup CPUTypes
typedef uint32_t FfxUInt32x2[2]; typedef uint32_t FfxUInt32x2[2];
@ -161,6 +196,7 @@ typedef float32_t4 FfxFloat32x4;
/// A [cacao_placeholder] typedef for matrix type until confirmed. /// A [cacao_placeholder] typedef for matrix type until confirmed.
typedef float4x4 FfxFloat32x4x4; typedef float4x4 FfxFloat32x4x4;
typedef float3x4 FfxFloat32x3x4;
typedef float3x3 FfxFloat32x3x3; typedef float3x3 FfxFloat32x3x3;
typedef float2x2 FfxFloat32x2x2; typedef float2x2 FfxFloat32x2x2;
@ -218,6 +254,7 @@ typedef int32_t4 FfxInt32x4;
/// A [cacao_placeholder] typedef for matrix type until confirmed. /// A [cacao_placeholder] typedef for matrix type until confirmed.
#define FfxFloat32x4x4 float4x4 #define FfxFloat32x4x4 float4x4
#define FfxFloat32x3x4 float3x4
#define FfxFloat32x3x3 float3x3 #define FfxFloat32x3x3 float3x3
#define FfxFloat32x2x2 float2x2 #define FfxFloat32x2x2 float2x2
@ -334,6 +371,7 @@ typedef min16int4 FfxInt16x4;
/// A [cacao_placeholder] typedef for matrix type until confirmed. /// A [cacao_placeholder] typedef for matrix type until confirmed.
#define FfxFloat32x4x4 mat4 #define FfxFloat32x4x4 mat4
#define FfxFloat32x3x4 mat4x3
#define FfxFloat32x3x3 mat3 #define FfxFloat32x3x3 mat3
#define FfxFloat32x2x2 mat2 #define FfxFloat32x2x2 mat2

11
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_common_types.h.meta → Packages/fidelityfx.fsr/Shaders/shaders/ffx_common_types.h.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7974b728d5c1b6d4a8a8e3965d03f96d
guid: ec0f8c94ee9930b438b99b82735d181b
PluginImporter: PluginImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
@ -7,7 +7,7 @@ PluginImporter:
executionOrder: {} executionOrder: {}
defineConstraints: [] defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isOverridable: 1
isExplicitlyReferenced: 0 isExplicitlyReferenced: 0
validateReferences: 1 validateReferences: 1
platformData: platformData:
@ -23,6 +23,7 @@ PluginImporter:
Exclude OSXUniversal: 1 Exclude OSXUniversal: 1
Exclude PS4: 1 Exclude PS4: 1
Exclude PS5: 1 Exclude PS5: 1
Exclude WebGL: 1
Exclude Win: 1 Exclude Win: 1
Exclude Win64: 1 Exclude Win64: 1
- first: - first:
@ -42,12 +43,6 @@ PluginImporter:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first: - first:
Standalone: Win Standalone: Win
second: second:

14
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core.h → Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h

@ -1,16 +1,17 @@
// This file is part of the FidelityFX SDK. // This file is part of the FidelityFX SDK.
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -19,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
/// @defgroup FfxGPU GPU /// @defgroup FfxGPU GPU
/// The FidelityFX SDK GPU References /// The FidelityFX SDK GPU References
/// ///

11
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core.h.meta → Packages/fidelityfx.fsr/Shaders/shaders/ffx_core.h.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: b91c5f52b89ff554dacb51045a802ed8
guid: 223ad96bb47790e4d8658dd82ba950f3
PluginImporter: PluginImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
@ -7,7 +7,7 @@ PluginImporter:
executionOrder: {} executionOrder: {}
defineConstraints: [] defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isOverridable: 1
isExplicitlyReferenced: 0 isExplicitlyReferenced: 0
validateReferences: 1 validateReferences: 1
platformData: platformData:
@ -23,6 +23,7 @@ PluginImporter:
Exclude OSXUniversal: 1 Exclude OSXUniversal: 1
Exclude PS4: 1 Exclude PS4: 1
Exclude PS5: 1 Exclude PS5: 1
Exclude WebGL: 1
Exclude Win: 1 Exclude Win: 1
Exclude Win64: 1 Exclude Win64: 1
- first: - first:
@ -42,12 +43,6 @@ PluginImporter:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first: - first:
Standalone: Win Standalone: Win
second: second:

318
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core_gpu_common.h → Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h

@ -1,16 +1,17 @@
// This file is part of the FidelityFX SDK. // This file is part of the FidelityFX SDK.
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Copyright (C) 2024 Advanced Micro Devices, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights // in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is // copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -19,7 +20,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
/// A define for a true value in a boolean expression. /// A define for a true value in a boolean expression.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
@ -49,57 +49,7 @@ FFX_STATIC const FfxFloat32 FFX_FP16_MIN = 6.10e-05f;
FFX_STATIC const FfxFloat32 FFX_FP16_MAX = 65504.0f; FFX_STATIC const FfxFloat32 FFX_FP16_MAX = 65504.0f;
FFX_STATIC const FfxFloat32 FFX_TONEMAP_EPSILON = 1.0f / FFX_FP16_MAX; FFX_STATIC const FfxFloat32 FFX_TONEMAP_EPSILON = 1.0f / FFX_FP16_MAX;
/// Compute the reciprocal of <c><i>value</i></c>.
///
/// @param [in] value The value to compute the reciprocal of.
///
/// @returns
/// The 1 / <c><i>value</i></c>.
///
/// @ingroup GPUCore
FfxFloat32 ffxReciprocal(FfxFloat32 value)
{
return rcp(value);
}
/// Compute the reciprocal of <c><i>value</i></c>.
///
/// @param [in] value The value to compute the reciprocal of.
///
/// @returns
/// The 1 / <c><i>value</i></c>.
///
/// @ingroup GPUCore
FfxFloat32x2 ffxReciprocal(FfxFloat32x2 value)
{
return rcp(value);
}
/// Compute the reciprocal of <c><i>value</i></c>.
///
/// @param [in] value The value to compute the reciprocal of.
///
/// @returns
/// The 1 / <c><i>value</i></c>.
///
/// @ingroup GPUCore
FfxFloat32x3 ffxReciprocal(FfxFloat32x3 value)
{
return rcp(value);
}
/// Compute the reciprocal of <c><i>value</i></c>.
///
/// @param [in] value The value to compute the reciprocal of.
///
/// @returns
/// The 1 / <c><i>value</i></c>.
///
/// @ingroup GPUCore
FfxFloat32x4 ffxReciprocal(FfxFloat32x4 value)
{
return rcp(value);
}
#define FFX_HAS_FLAG(v, f) ((v & f) == f)
/// Compute the min of two values. /// Compute the min of two values.
/// ///
@ -782,7 +732,7 @@ FfxFloat32x4 ffxIsGreaterThanZero(FfxFloat32x4 m)
/// @ingroup GPUCore /// @ingroup GPUCore
FfxUInt32 ffxFloatToSortableInteger(FfxUInt32 value) FfxUInt32 ffxFloatToSortableInteger(FfxUInt32 value)
{ {
return value ^ ((AShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000));
return value ^ ((ffxAShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000));
} }
/// Convert a sortable integer to a 32bit floating point value. /// Convert a sortable integer to a 32bit floating point value.
@ -799,7 +749,7 @@ FfxUInt32 ffxFloatToSortableInteger(FfxUInt32 value)
/// @ingroup GPUCore /// @ingroup GPUCore
FfxUInt32 ffxSortableIntegerToFloat(FfxUInt32 value) FfxUInt32 ffxSortableIntegerToFloat(FfxUInt32 value)
{ {
return value ^ ((~AShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000));
return value ^ ((~ffxAShrSU1(value, FfxUInt32(31))) | FfxUInt32(0x80000000));
} }
/// Calculate a low-quality approximation for the square root of a value. /// Calculate a low-quality approximation for the square root of a value.
@ -2408,6 +2358,51 @@ FfxFloat32x3 ffxRec709FromLinear(FfxFloat32x3 color)
return clamp(j.xxx, color * j.yyy, pow(color, j.zzz) * k.xxx + k.yyy); return clamp(j.xxx, color * j.yyy, pow(color, j.zzz) * k.xxx + k.yyy);
} }
/// Compute a linear value from a REC.709 value.
///
/// @param [in] color The value to convert to linear from REC.709.
///
/// @returns
/// A value in linear space.
///
/// @ingroup GPUCore
FfxFloat32 ffxLinearFromRec709(FfxFloat32 color)
{
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.x), color * j.y, pow(color * k.x + k.y, j.z));
}
/// Compute a linear value from a REC.709 value.
///
/// @param [in] color The value to convert to linear from REC.709.
///
/// @returns
/// A value in linear space.
///
/// @ingroup GPUCore
FfxFloat32x2 ffxLinearFromRec709(FfxFloat32x2 color)
{
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xx), color * j.yy, pow(color * k.xx + k.yy, j.zz));
}
/// Compute a linear value from a REC.709 value.
///
/// @param [in] color The value to convert to linear from REC.709.
///
/// @returns
/// A value in linear space.
///
/// @ingroup GPUCore
FfxFloat32x3 ffxLinearFromRec709(FfxFloat32x3 color)
{
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xxx), color * j.yyy, pow(color * k.xxx + k.yyy, j.zzz));
}
/// Compute a gamma value from a linear value. /// Compute a gamma value from a linear value.
/// ///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
@ -2462,232 +2457,187 @@ FfxFloat32x3 ffxGammaFromLinear(FfxFloat32x3 value, FfxFloat32 power)
return pow(value, ffxBroadcast3(power)); return pow(value, ffxBroadcast3(power));
} }
/// Compute a PQ value from a linear value.
///
/// @param [in] value The value to convert to PQ from linear.
///
/// @returns
/// A value in linear space.
/// Compute a linear value from a value in a gamma space.
/// ///
/// @ingroup GPUCore
FfxFloat32 ffxPQToLinear(FfxFloat32 value)
{
FfxFloat32 p = pow(value, FfxFloat32(0.159302));
return pow((FfxFloat32(0.835938) + FfxFloat32(18.8516) * p) / (FfxFloat32(1.0) + FfxFloat32(18.6875) * p), FfxFloat32(78.8438));
}
/// Compute a PQ value from a linear value.
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] value The value to convert to PQ from linear.
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x2 ffxPQToLinear(FfxFloat32x2 value)
FfxFloat32 ffxLinearFromGamma(FfxFloat32 color, FfxFloat32 power)
{ {
FfxFloat32x2 p = pow(value, ffxBroadcast2(0.159302));
return pow((ffxBroadcast2(0.835938) + ffxBroadcast2(18.8516) * p) / (ffxBroadcast2(1.0) + ffxBroadcast2(18.6875) * p), ffxBroadcast2(78.8438));
return pow(color, FfxFloat32(power));
} }
/// Compute a PQ value from a linear value.
///
/// @param [in] value The value to convert to PQ from linear.
///
/// @returns
/// A value in linear space.
/// Compute a linear value from a value in a gamma space.
/// ///
/// @ingroup GPUCore
FfxFloat32x3 ffxPQToLinear(FfxFloat32x3 value)
{
FfxFloat32x3 p = pow(value, ffxBroadcast3(0.159302));
return pow((ffxBroadcast3(0.835938) + ffxBroadcast3(18.8516) * p) / (ffxBroadcast3(1.0) + ffxBroadcast3(18.6875) * p), ffxBroadcast3(78.8438));
}
/// Compute a linear value from a SRGB value.
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] value The value to convert to linear from SRGB.
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// ///
/// @returns /// @returns
/// A value in SRGB space.
/// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32 ffxSrgbToLinear(FfxFloat32 value)
FfxFloat32x2 ffxLinearFromGamma(FfxFloat32x2 color, FfxFloat32 power)
{ {
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.x, value * j.y, pow(value, j.z) * k.x + k.y);
return pow(color, ffxBroadcast2(power));
} }
/// Compute a linear value from a SRGB value.
///
/// @param [in] value The value to convert to linear from SRGB.
///
/// @returns
/// A value in SRGB space.
/// Compute a linear value from a value in a gamma space.
/// ///
/// @ingroup GPUCore
FfxFloat32x2 ffxSrgbToLinear(FfxFloat32x2 value)
{
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.xx, value * j.yy, pow(value, j.zz) * k.xx + k.yy);
}
/// Compute a linear value from a SRGB value.
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] value The value to convert to linear from SRGB.
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// ///
/// @returns /// @returns
/// A value in SRGB space.
/// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x3 ffxSrgbToLinear(FfxFloat32x3 value)
FfxFloat32x3 ffxLinearFromGamma(FfxFloat32x3 color, FfxFloat32 power)
{ {
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.xxx, value * j.yyy, pow(value, j.zzz) * k.xxx + k.yyy);
return pow(color, ffxBroadcast3(power));
} }
/// Compute a linear value from a REC.709 value.
/// Compute a PQ value from a linear value.
/// ///
/// @param [in] color The value to convert to linear from REC.709.
/// @param [in] value The value to convert to PQ from linear.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32 ffxLinearFromRec709(FfxFloat32 color)
FfxFloat32 ffxPQFromLinear(FfxFloat32 value)
{ {
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.x), color * j.y, pow(color * k.x + k.y, j.z));
FfxFloat32 p = pow(value, FfxFloat32(0.159302));
return pow((FfxFloat32(0.835938) + FfxFloat32(18.8516) * p) / (FfxFloat32(1.0) + FfxFloat32(18.6875) * p), FfxFloat32(78.8438));
} }
/// Compute a linear value from a REC.709 value.
/// Compute a PQ value from a linear value.
/// ///
/// @param [in] color The value to convert to linear from REC.709.
/// @param [in] value The value to convert to PQ from linear.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x2 ffxLinearFromRec709(FfxFloat32x2 color)
FfxFloat32x2 ffxPQFromLinear(FfxFloat32x2 value)
{ {
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xx), color * j.yy, pow(color * k.xx + k.yy, j.zz));
FfxFloat32x2 p = pow(value, ffxBroadcast2(0.159302));
return pow((ffxBroadcast2(0.835938) + ffxBroadcast2(18.8516) * p) / (ffxBroadcast2(1.0) + ffxBroadcast2(18.6875) * p), ffxBroadcast2(78.8438));
} }
/// Compute a linear value from a REC.709 value.
/// Compute a PQ value from a linear value.
/// ///
/// @param [in] color The value to convert to linear from REC.709.
/// @param [in] value The value to convert to PQ from linear.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x3 ffxLinearFromRec709(FfxFloat32x3 color)
FfxFloat32x3 ffxPQFromLinear(FfxFloat32x3 value)
{ {
FfxFloat32x3 j = FfxFloat32x3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45);
FfxFloat32x2 k = FfxFloat32x2(1.0 / 1.099, 0.099 / 1.099);
return ffxZeroOneSelect(ffxZeroOneIsSigned(color - j.xxx), color * j.yyy, pow(color * k.xxx + k.yyy, j.zzz));
FfxFloat32x3 p = pow(value, ffxBroadcast3(0.159302));
return pow((ffxBroadcast3(0.835938) + ffxBroadcast3(18.8516) * p) / (ffxBroadcast3(1.0) + ffxBroadcast3(18.6875) * p), ffxBroadcast3(78.8438));
} }
/// Compute a linear value from a value in a gamma space.
/// Compute a linear value from a value in a PQ space.
/// ///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// @param [in] value The value to convert to linear in PQ space.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32 ffxLinearFromGamma(FfxFloat32 color, FfxFloat32 power)
FfxFloat32 ffxLinearFromPQ(FfxFloat32 value)
{ {
return pow(color, FfxFloat32(power));
FfxFloat32 p = pow(value, FfxFloat32(0.0126833));
return pow(ffxSaturate(p - FfxFloat32(0.835938)) / (FfxFloat32(18.8516) - FfxFloat32(18.6875) * p), FfxFloat32(6.27739));
} }
/// Compute a linear value from a value in a gamma space.
/// Compute a linear value from a value in a PQ space.
/// ///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// @param [in] value The value to convert to linear in PQ space.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x2 ffxLinearFromGamma(FfxFloat32x2 color, FfxFloat32 power)
FfxFloat32x2 ffxLinearFromPQ(FfxFloat32x2 value)
{ {
return pow(color, ffxBroadcast2(power));
FfxFloat32x2 p = pow(value, ffxBroadcast2(0.0126833));
return pow(ffxSaturate(p - ffxBroadcast2(0.835938)) / (ffxBroadcast2(18.8516) - ffxBroadcast2(18.6875) * p), ffxBroadcast2(6.27739));
} }
/// Compute a linear value from a value in a gamma space.
/// Compute a linear value from a value in a PQ space.
/// ///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native. /// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// ///
/// @param [in] color The value to convert to linear in gamma space.
/// @param [in] power The power value used for the gamma curve.
/// @param [in] value The value to convert to linear in PQ space.
/// ///
/// @returns /// @returns
/// A value in linear space. /// A value in linear space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x3 ffxLinearFromGamma(FfxFloat32x3 color, FfxFloat32 power)
FfxFloat32x3 ffxLinearFromPQ(FfxFloat32x3 value)
{ {
return pow(color, ffxBroadcast3(power));
FfxFloat32x3 p = pow(value, ffxBroadcast3(0.0126833));
return pow(ffxSaturate(p - ffxBroadcast3(0.835938)) / (ffxBroadcast3(18.8516) - ffxBroadcast3(18.6875) * p), ffxBroadcast3(6.27739));
} }
/// Compute a linear value from a value in a PQ space.
/// Compute an SRGB value from a linear value.
/// ///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
///
/// @param [in] value The value to convert to linear in PQ space.
/// @param [in] value The value to convert to SRGB from linear.
/// ///
/// @returns /// @returns
/// A value in linear space.
/// A value in SRGB space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32 ffxLinearFromPQ(FfxFloat32 value)
FfxFloat32 ffxSrgbFromLinear(FfxFloat32 value)
{ {
FfxFloat32 p = pow(value, FfxFloat32(0.0126833));
return pow(ffxSaturate(p - FfxFloat32(0.835938)) / (FfxFloat32(18.8516) - FfxFloat32(18.6875) * p), FfxFloat32(6.27739));
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.x, value * j.y, pow(value, j.z) * k.x + k.y);
} }
/// Compute a linear value from a value in a PQ space.
///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// Compute an SRGB value from a linear value.
/// ///
/// @param [in] value The value to convert to linear in PQ space.
/// @param [in] value The value to convert to SRGB from linear.
/// ///
/// @returns /// @returns
/// A value in linear space.
/// A value in SRGB space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x2 ffxLinearFromPQ(FfxFloat32x2 value)
FfxFloat32x2 ffxSrgbFromLinear(FfxFloat32x2 value)
{ {
FfxFloat32x2 p = pow(value, ffxBroadcast2(0.0126833));
return pow(ffxSaturate(p - ffxBroadcast2(0.835938)) / (ffxBroadcast2(18.8516) - ffxBroadcast2(18.6875) * p), ffxBroadcast2(6.27739));
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.xx, value * j.yy, pow(value, j.zz) * k.xx + k.yy);
} }
/// Compute a linear value from a value in a PQ space.
///
/// Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native.
/// Compute an SRGB value from a linear value.
/// ///
/// @param [in] value The value to convert to linear in PQ space.
/// @param [in] value The value to convert to SRGB from linear.
/// ///
/// @returns /// @returns
/// A value in linear space.
/// A value in SRGB space.
/// ///
/// @ingroup GPUCore /// @ingroup GPUCore
FfxFloat32x3 ffxLinearFromPQ(FfxFloat32x3 value)
FfxFloat32x3 ffxSrgbFromLinear(FfxFloat32x3 value)
{ {
FfxFloat32x3 p = pow(value, ffxBroadcast3(0.0126833));
return pow(ffxSaturate(p - ffxBroadcast3(0.835938)) / (ffxBroadcast3(18.8516) - ffxBroadcast3(18.6875) * p), ffxBroadcast3(6.27739));
FfxFloat32x3 j = FfxFloat32x3(0.0031308 * 12.92, 12.92, 1.0 / 2.4);
FfxFloat32x2 k = FfxFloat32x2(1.055, -0.055);
return clamp(j.xxx, value * j.yyy, pow(value, j.zzz) * k.xxx + k.yyy);
} }
/// Compute a linear value from a value in a SRGB space. /// Compute a linear value from a value in a SRGB space.
@ -2742,11 +2692,13 @@ FfxFloat32x3 ffxLinearFromSrgb(FfxFloat32x3 value)
} }
/// A remapping of 64x1 to 8x8 imposing rotated 2x2 pixel quads in quad linear. /// A remapping of 64x1 to 8x8 imposing rotated 2x2 pixel quads in quad linear.
///
/// 543210
/// ======
/// ..xxx.
/// yy...y
///
/// Remap illustration:
///
/// 543210
/// ~~~~~~
/// ..xxx.
/// yy...y
/// ///
/// @param [in] a The input 1D coordinates to remap. /// @param [in] a The input 1D coordinates to remap.
/// ///
@ -2756,7 +2708,7 @@ FfxFloat32x3 ffxLinearFromSrgb(FfxFloat32x3 value)
/// @ingroup GPUCore /// @ingroup GPUCore
FfxUInt32x2 ffxRemapForQuad(FfxUInt32 a) FfxUInt32x2 ffxRemapForQuad(FfxUInt32 a)
{ {
return FfxUInt32x2(bitfieldExtract(a, 1u, 3u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), a, 1u));
return FfxUInt32x2(ffxBitfieldExtract(a, 1u, 3u), ffxBitfieldInsertMask(ffxBitfieldExtract(a, 3u, 3u), a, 1u));
} }
/// A helper function performing a remap 64x1 to 8x8 remapping which is necessary for 2D wave reductions. /// A helper function performing a remap 64x1 to 8x8 remapping which is necessary for 2D wave reductions.
@ -2780,5 +2732,5 @@ FfxUInt32x2 ffxRemapForQuad(FfxUInt32 a)
/// @ingroup GPUCore /// @ingroup GPUCore
FfxUInt32x2 ffxRemapForWaveReduction(FfxUInt32 a) FfxUInt32x2 ffxRemapForWaveReduction(FfxUInt32 a)
{ {
return FfxUInt32x2(bitfieldInsertMask(bitfieldExtract(a, 2u, 3u), a, 1u), bitfieldInsertMask(bitfieldExtract(a, 3u, 3u), bitfieldExtract(a, 1u, 2u), 2u));
return FfxUInt32x2(ffxBitfieldInsertMask(ffxBitfieldExtract(a, 2u, 3u), a, 1u), ffxBitfieldInsertMask(ffxBitfieldExtract(a, 3u, 3u), ffxBitfieldExtract(a, 1u, 2u), 2u));
} }

11
Assets/Shaders/FSR3/shaders/fsr3upscaler/ffx_core_gpu_common.h.meta → Packages/fidelityfx.fsr/Shaders/shaders/ffx_core_gpu_common.h.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 05b921699d1374a429e32afca13137e2
guid: 4950d6c78609df549a0ed96137bf3bf1
PluginImporter: PluginImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
@ -7,7 +7,7 @@ PluginImporter:
executionOrder: {} executionOrder: {}
defineConstraints: [] defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isOverridable: 1
isExplicitlyReferenced: 0 isExplicitlyReferenced: 0
validateReferences: 1 validateReferences: 1
platformData: platformData:
@ -23,6 +23,7 @@ PluginImporter:
Exclude OSXUniversal: 1 Exclude OSXUniversal: 1
Exclude PS4: 1 Exclude PS4: 1
Exclude PS5: 1 Exclude PS5: 1
Exclude WebGL: 1
Exclude Win: 1 Exclude Win: 1
Exclude Win64: 1 Exclude Win64: 1
- first: - first:
@ -42,12 +43,6 @@ PluginImporter:
enabled: 0 enabled: 0
settings: settings:
CPU: None CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first: - first:
Standalone: Win Standalone: Win
second: second:

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save