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.
55 lines
1.8 KiB
55 lines
1.8 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Profiling;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace FidelityFX
|
|
{
|
|
public abstract class FfxPassBase<TDispatch, TFlags>: 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 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, 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()
|
|
{
|
|
}
|
|
}
|
|
}
|