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.
79 lines
2.2 KiB
79 lines
2.2 KiB
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.Profiling;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace FidelityFX
|
|
{
|
|
internal abstract class FfxPassBase: IDisposable
|
|
{
|
|
private readonly string _techName;
|
|
private string _passName;
|
|
|
|
protected ComputeShader ComputeShader;
|
|
protected int KernelIndex;
|
|
|
|
protected FfxPassBase(string techName)
|
|
{
|
|
_techName = techName;
|
|
}
|
|
|
|
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.");
|
|
}
|
|
|
|
_passName = passName;
|
|
ComputeShader = shader;
|
|
KernelIndex = ComputeShader.FindKernel(kernelName);
|
|
}
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
}
|
|
|
|
protected ProfilerSampler ProfilerSample(CommandBuffer commandBuffer)
|
|
{
|
|
return new ProfilerSampler(_passName, commandBuffer);
|
|
}
|
|
|
|
protected readonly struct ProfilerSampler : IDisposable
|
|
{
|
|
private readonly string _name;
|
|
private readonly CommandBuffer _commandBuffer;
|
|
|
|
public ProfilerSampler(string name, CommandBuffer commandBuffer)
|
|
{
|
|
_name = name;
|
|
_commandBuffer = commandBuffer;
|
|
_commandBuffer.BeginSample(_name);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_commandBuffer.EndSample(_name);
|
|
}
|
|
}
|
|
}
|
|
|
|
internal abstract class FfxPassWithFlags<TFlags> : FfxPassBase
|
|
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();
|
|
}
|
|
}
|