From d583c750d25a522c94486b88bd5b7c72250bcbf0 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 3 Aug 2024 17:34:43 +0200 Subject: [PATCH] Moved SPD setup method into a separate common FfxSpd class --- Runtime/Common/FfxSpd.cs | 25 +++++++++++++++++++++++++ Runtime/Common/FfxSpd.cs.meta | 11 +++++++++++ Runtime/FSR2/Fsr2Context.cs | 19 +------------------ Runtime/FSR3/Fsr3UpscalerContext.cs | 19 +------------------ 4 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 Runtime/Common/FfxSpd.cs create mode 100644 Runtime/Common/FfxSpd.cs.meta diff --git a/Runtime/Common/FfxSpd.cs b/Runtime/Common/FfxSpd.cs new file mode 100644 index 0000000..41882ac --- /dev/null +++ b/Runtime/Common/FfxSpd.cs @@ -0,0 +1,25 @@ +using System; +using UnityEngine; + +namespace FidelityFX +{ + public static class FfxSpd + { + public 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); + } + } + } +} diff --git a/Runtime/Common/FfxSpd.cs.meta b/Runtime/Common/FfxSpd.cs.meta new file mode 100644 index 0000000..bf34fa1 --- /dev/null +++ b/Runtime/Common/FfxSpd.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aee0f42dc1676ab4db5c01520b0b925a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/FSR2/Fsr2Context.cs b/Runtime/FSR2/Fsr2Context.cs index 51da4dd..6a7cf19 100644 --- a/Runtime/FSR2/Fsr2Context.cs +++ b/Runtime/FSR2/Fsr2Context.cs @@ -410,7 +410,7 @@ namespace FidelityFX.FSR2 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); + FfxSpd.SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips); // Downsample ref Fsr2.SpdConstants spdConstants = ref _spdConstants.Value; @@ -422,23 +422,6 @@ namespace FidelityFX.FSR2 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) diff --git a/Runtime/FSR3/Fsr3UpscalerContext.cs b/Runtime/FSR3/Fsr3UpscalerContext.cs index 2630be1..3cda429 100644 --- a/Runtime/FSR3/Fsr3UpscalerContext.cs +++ b/Runtime/FSR3/Fsr3UpscalerContext.cs @@ -447,7 +447,7 @@ namespace FidelityFX.FSR3 private void SetupSpdConstants(Fsr3Upscaler.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); + FfxSpd.SpdSetup(rectInfo, out dispatchThreadGroupCount, out var workGroupOffset, out var numWorkGroupsAndMips); // Downsample ref Fsr3Upscaler.SpdConstants spdConstants = ref _spdConstants.Value; @@ -459,23 +459,6 @@ namespace FidelityFX.FSR3 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(Fsr3Upscaler.DispatchDescription dispatchParams) { if (!dispatchParams.Color.IsValid)