using System; using UnityEngine; using UnityEngine.Profiling; using UnityEngine.Rendering; namespace FidelityFX { public abstract class FfxPassBase: IDisposable //where TDispatch: struct where TFlags: Enum { private readonly string _techName; protected ComputeShader ComputeShader; protected int KernelIndex; protected CustomSampler Sampler; protected FfxPassBase(string techName) { _techName = techName; } public void ScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ = 1) { commandBuffer.BeginSample(Sampler); DoScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchX, dispatchY, dispatchZ); commandBuffer.EndSample(Sampler); } protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int frameIndex, int dispatchX, int dispatchY, int dispatchZ); protected void InitComputeShader(string passName, ComputeShader shader, TFlags flags) { if (shader == null) { throw new MissingReferenceException($"Shader for {_techName} 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); SetupShaderKeywords(flags); } protected virtual void SetupShaderKeywords(TFlags flags) { } public virtual void Dispose() { } } }