You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

63 lines
2.2 KiB

using System;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
namespace FidelityFX
{
internal abstract class FfxPassBase<TDispatch>: IDisposable
//where TDispatch: struct
{
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 bufferIndex, int dispatchX, int dispatchY, int dispatchZ = 1)
{
commandBuffer.BeginSample(Sampler);
DoScheduleDispatch(commandBuffer, dispatchParams, bufferIndex, dispatchX, dispatchY, dispatchZ);
commandBuffer.EndSample(Sampler);
}
protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int bufferIndex, int dispatchX, int dispatchY, int dispatchZ);
protected void InitComputeShader(string passName, ComputeShader shader, string kernelName = "CS")
{
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(kernelName);
Sampler = CustomSampler.Create(passName);
}
public virtual void Dispose()
{
}
}
internal abstract class FfxPassWithFlags<TDispatch, TFlags> : FfxPassBase<TDispatch>
//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);
}
}