From c33ec9d4ed0fefd737619d3e3d9b86a11c37d901 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 3 Aug 2024 16:33:29 +0200 Subject: [PATCH] Further abstracted base pass class to allow for passes without shader keyword flags, and to allow custom kernel names. --- Runtime/Common/FfxPassBase.cs | 24 ++++++++++++++++-------- Runtime/FSR2/Fsr2Pass.cs | 2 +- Runtime/FSR3/Fsr3UpscalerPass.cs | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Runtime/Common/FfxPassBase.cs b/Runtime/Common/FfxPassBase.cs index a6c5380..3e9e4aa 100644 --- a/Runtime/Common/FfxPassBase.cs +++ b/Runtime/Common/FfxPassBase.cs @@ -5,9 +5,8 @@ using UnityEngine.Rendering; namespace FidelityFX { - public abstract class FfxPassBase: IDisposable + internal abstract class FfxPassBase: IDisposable //where TDispatch: struct - where TFlags: Enum { private readonly string _techName; @@ -30,7 +29,7 @@ namespace FidelityFX protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int bufferIndex, int dispatchX, int dispatchY, int dispatchZ); - protected void InitComputeShader(string passName, ComputeShader shader, TFlags flags) + protected void InitComputeShader(string passName, ComputeShader shader, string kernelName = "CS") { if (shader == null) { @@ -38,18 +37,27 @@ namespace FidelityFX } ComputeShader = shader; - KernelIndex = ComputeShader.FindKernel("CS"); + KernelIndex = ComputeShader.FindKernel(kernelName); Sampler = CustomSampler.Create(passName); - - SetupShaderKeywords(flags); } - protected virtual void SetupShaderKeywords(TFlags flags) + public virtual void Dispose() { } + } - public virtual void Dispose() + internal abstract class FfxPassWithFlags : FfxPassBase + //where TDispatch: struct + where TFlags: Enum + { + protected FfxPassWithFlags(string techName): base(techName) { } + + protected void InitComputeShader(string passName, ComputeShader shader, TFlags flags, string kernelName = "CS") { + InitComputeShader(passName, shader, kernelName); + SetupShaderKeywords(flags); } + + protected abstract void SetupShaderKeywords(TFlags flags); } } diff --git a/Runtime/FSR2/Fsr2Pass.cs b/Runtime/FSR2/Fsr2Pass.cs index 0132fc3..7384454 100644 --- a/Runtime/FSR2/Fsr2Pass.cs +++ b/Runtime/FSR2/Fsr2Pass.cs @@ -28,7 +28,7 @@ namespace FidelityFX.FSR2 /// 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. /// - internal abstract class Fsr2Pass: FfxPassBase + internal abstract class Fsr2Pass: FfxPassWithFlags { internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define diff --git a/Runtime/FSR3/Fsr3UpscalerPass.cs b/Runtime/FSR3/Fsr3UpscalerPass.cs index 9787ca6..941971c 100644 --- a/Runtime/FSR3/Fsr3UpscalerPass.cs +++ b/Runtime/FSR3/Fsr3UpscalerPass.cs @@ -28,7 +28,7 @@ namespace FidelityFX.FSR3 /// This loosely matches the FfxPipelineState struct from the original FSR3 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. /// - internal abstract class Fsr3UpscalerPass: FfxPassBase + internal abstract class Fsr3UpscalerPass: FfxPassWithFlags { protected readonly Fsr3Upscaler.ContextDescription ContextDescription; protected readonly Fsr3UpscalerResources Resources;