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.
68 lines
2.2 KiB
68 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 virtual 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 readonly TFlags Flags;
|
|
|
|
protected FfxPassWithFlags(string techName, TFlags flags) : base(techName)
|
|
{
|
|
Flags = flags;
|
|
}
|
|
|
|
protected override void InitComputeShader(string passName, ComputeShader shader, string kernelName = "CS")
|
|
{
|
|
base.InitComputeShader(passName, shader, kernelName);
|
|
SetupShaderKeywords();
|
|
}
|
|
|
|
protected abstract void SetupShaderKeywords();
|
|
}
|
|
}
|