From 4b675d285e9259d15ff1305bbd1cb047c962c962 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 27 Jul 2024 13:03:29 +0200 Subject: [PATCH] Modified inpainting pyramid passes to use a maximum of 7 mip levels. This allows the shaders to stay within the limit of 8 UAV bindings required by DX11.0, and gets rid of Unity's warnings and errors about breaking this limit. --- .../FrameInterpolationContext.cs | 2 +- .../FrameInterpolationPass.cs | 12 --------- ..._vector_field_inpainting_pyramid_pass.hlsl | 6 ----- ...ation_compute_inpainting_pyramid_pass.hlsl | 6 ----- .../ffx_frameinterpolation_callbacks_hlsl.h | 27 +------------------ .../ffx_frameinterpolation_inpainting.h | 4 +-- 6 files changed, 4 insertions(+), 53 deletions(-) diff --git a/Runtime/FrameInterpolation/FrameInterpolationContext.cs b/Runtime/FrameInterpolation/FrameInterpolationContext.cs index fdb751f..876d108 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationContext.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationContext.cs @@ -286,7 +286,7 @@ namespace FidelityFX.FrameGen ref FrameInterpolation.InpaintingPyramidConstants spdConstants = ref SpdConstants; spdConstants.numWorkGroups = (uint)numWorkGroupsAndMips.x; - spdConstants.mips = (uint)numWorkGroupsAndMips.y; + spdConstants.mips = (uint)Math.Min(numWorkGroupsAndMips.y, 7); spdConstants.workGroupOffsetX = (uint)workGroupOffset.x; spdConstants.workGroupOffsetY = (uint)workGroupOffset.y; } diff --git a/Runtime/FrameInterpolation/FrameInterpolationPass.cs b/Runtime/FrameInterpolation/FrameInterpolationPass.cs index 2817c02..f9a6a87 100644 --- a/Runtime/FrameInterpolation/FrameInterpolationPass.cs +++ b/Runtime/FrameInterpolation/FrameInterpolationPass.cs @@ -293,12 +293,6 @@ namespace FidelityFX.FrameGen BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap4, Resources.InpaintingPyramid, 4); BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap5, Resources.InpaintingPyramid, 5); BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap6, Resources.InpaintingPyramid, 6); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap7, Resources.InpaintingPyramid, 7); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap8, Resources.InpaintingPyramid, 8); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap9, Resources.InpaintingPyramid, 9); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap10, Resources.InpaintingPyramid, 10); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap11, Resources.InpaintingPyramid, 11); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap12, Resources.InpaintingPyramid, 12); commandBuffer.SetComputeConstantBufferParam(ComputeShader, FrameInterpolationShaderIDs.CbFrameInterpolation, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, FrameInterpolationShaderIDs.CbInpaintingPyramid, _spdConstants, 0, Marshal.SizeOf()); @@ -359,12 +353,6 @@ namespace FidelityFX.FrameGen BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap4, Resources.InpaintingPyramid, 4); BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap5, Resources.InpaintingPyramid, 5); BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap6, Resources.InpaintingPyramid, 6); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap7, Resources.InpaintingPyramid, 7); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap8, Resources.InpaintingPyramid, 8); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap9, Resources.InpaintingPyramid, 9); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap10, Resources.InpaintingPyramid, 10); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap11, Resources.InpaintingPyramid, 11); - BindMipmap(commandBuffer, FrameInterpolationShaderIDs.UavInpaintingPyramidMipmap12, Resources.InpaintingPyramid, 12); commandBuffer.SetComputeConstantBufferParam(ComputeShader, FrameInterpolationShaderIDs.CbFrameInterpolation, Constants, 0, Marshal.SizeOf()); commandBuffer.SetComputeConstantBufferParam(ComputeShader, FrameInterpolationShaderIDs.CbInpaintingPyramid, _spdConstants, 0, Marshal.SizeOf()); diff --git a/Shaders/shaders/ffx_frameinterpolation_compute_game_vector_field_inpainting_pyramid_pass.hlsl b/Shaders/shaders/ffx_frameinterpolation_compute_game_vector_field_inpainting_pyramid_pass.hlsl index 8f75361..d804d2a 100644 --- a/Shaders/shaders/ffx_frameinterpolation_compute_game_vector_field_inpainting_pyramid_pass.hlsl +++ b/Shaders/shaders/ffx_frameinterpolation_compute_game_vector_field_inpainting_pyramid_pass.hlsl @@ -31,12 +31,6 @@ #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_4 5 #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_5 6 #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_6 7 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_7 8 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_8 9 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_9 10 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_10 11 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_11 12 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_12 13 #define FFX_FRAMEINTERPOLATION_BIND_CB_FRAMEINTERPOLATION 0 diff --git a/Shaders/shaders/ffx_frameinterpolation_compute_inpainting_pyramid_pass.hlsl b/Shaders/shaders/ffx_frameinterpolation_compute_inpainting_pyramid_pass.hlsl index d2686d7..5e8e62e 100644 --- a/Shaders/shaders/ffx_frameinterpolation_compute_inpainting_pyramid_pass.hlsl +++ b/Shaders/shaders/ffx_frameinterpolation_compute_inpainting_pyramid_pass.hlsl @@ -30,12 +30,6 @@ #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_4 5 #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_5 6 #define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_6 7 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_7 8 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_8 9 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_9 10 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_10 11 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_11 12 -#define FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_12 13 #define FFX_FRAMEINTERPOLATION_BIND_CB_FRAMEINTERPOLATION 0 diff --git a/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_callbacks_hlsl.h b/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_callbacks_hlsl.h index a25b66b..2e4c706 100644 --- a/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_callbacks_hlsl.h +++ b/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_callbacks_hlsl.h @@ -701,13 +701,7 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos) defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_3) && \ defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_4) && \ defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_5) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_6) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_7) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_8) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_9) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_10) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_11) && \ - defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_12) + defined(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_6) RWTexture2D rw_inpainting_pyramid0 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_0); RWTexture2D rw_inpainting_pyramid1 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_1); @@ -716,13 +710,6 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos) RWTexture2D rw_inpainting_pyramid4 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_4); globallycoherent RWTexture2D rw_inpainting_pyramid5 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_5); RWTexture2D rw_inpainting_pyramid6 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_6); - RWTexture2D rw_inpainting_pyramid7 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_7); - RWTexture2D rw_inpainting_pyramid8 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_8); - RWTexture2D rw_inpainting_pyramid9 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_9); - RWTexture2D rw_inpainting_pyramid10 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_10); - RWTexture2D rw_inpainting_pyramid11 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_11); - RWTexture2D rw_inpainting_pyramid12 : FFX_DECLARE_UAV(FFX_FRAMEINTERPOLATION_BIND_UAV_INPAINTING_PYRAMID_MIPMAP_12); - FfxFloat32x4 RWLoadInpaintingPyramid(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxUInt32 index) { @@ -738,12 +725,6 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos) LOAD(4); LOAD(5); LOAD(6); - LOAD(7); - LOAD(8); - LOAD(9); - LOAD(10); - LOAD(11); - LOAD(12); return 0; #undef LOAD @@ -764,12 +745,6 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos) STORE(4); STORE(5); STORE(6); - STORE(7); - STORE(8); - STORE(9); - STORE(10); - STORE(11); - STORE(12); #undef STORE } diff --git a/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_inpainting.h b/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_inpainting.h index 7ad3630..7e45f63 100644 --- a/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_inpainting.h +++ b/Shaders/shaders/frameinterpolation/ffx_frameinterpolation_inpainting.h @@ -55,7 +55,7 @@ FfxFloat32x3 ComputeInpainting(FfxInt32x2 iPxPos) FfxFloat32 fWeightSum = 0.0f; FfxInt32x2 iTexSize = DisplaySize(); - for (FfxInt32 iMipLevel = 0; iMipLevel < 10; iMipLevel++) { + for (FfxInt32 iMipLevel = 0; iMipLevel < 7; iMipLevel++) { iTexSize /= 2; @@ -63,7 +63,7 @@ FfxFloat32x3 ComputeInpainting(FfxInt32x2 iPxPos) if (fMipColor.w > 0.0f) { const FfxFloat32x3 fNormalizedMipColor = fMipColor.rgb / fMipColor.w; - const FfxFloat32 fMipWeight = ffxPow(1.0f - iMipLevel / 10.0f, 3.0f) * fMipColor.w; + const FfxFloat32 fMipWeight = ffxPow(1.0f - iMipLevel / 7.0f, 3.0f) * fMipColor.w; fColor += FfxFloat32x4(fNormalizedMipColor, 1.0f) * fMipWeight; }