Browse Source

Further abstracted base pass class to allow for passes without shader keyword flags, and to allow custom kernel names.

framework
Nico de Poel 2 years ago
parent
commit
c33ec9d4ed
  1. 24
      Runtime/Common/FfxPassBase.cs
  2. 2
      Runtime/FSR2/Fsr2Pass.cs
  3. 2
      Runtime/FSR3/Fsr3UpscalerPass.cs

24
Runtime/Common/FfxPassBase.cs

@ -5,9 +5,8 @@ using UnityEngine.Rendering;
namespace FidelityFX namespace FidelityFX
{ {
public abstract class FfxPassBase<TDispatch, TFlags>: IDisposable
internal abstract class FfxPassBase<TDispatch>: IDisposable
//where TDispatch: struct //where TDispatch: struct
where TFlags: Enum
{ {
private readonly string _techName; private readonly string _techName;
@ -30,7 +29,7 @@ namespace FidelityFX
protected abstract void DoScheduleDispatch(CommandBuffer commandBuffer, in TDispatch dispatchParams, int bufferIndex, int dispatchX, int dispatchY, int dispatchZ); 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)
protected void InitComputeShader(string passName, ComputeShader shader, string kernelName = "CS")
{ {
if (shader == null) if (shader == null)
{ {
@ -38,18 +37,27 @@ namespace FidelityFX
} }
ComputeShader = shader; ComputeShader = shader;
KernelIndex = ComputeShader.FindKernel("CS");
KernelIndex = ComputeShader.FindKernel(kernelName);
Sampler = CustomSampler.Create(passName); Sampler = CustomSampler.Create(passName);
SetupShaderKeywords(flags);
} }
protected virtual void SetupShaderKeywords(TFlags flags)
public virtual void Dispose()
{ {
} }
}
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);
} }
} }

2
Runtime/FSR2/Fsr2Pass.cs

@ -28,7 +28,7 @@ namespace FidelityFX.FSR2
/// This loosely matches the FfxPipelineState struct from the original FSR2 codebase, wrapped in an object-oriented blanket. /// This loosely matches the FfxPipelineState struct from the original FSR2 codebase, wrapped in an object-oriented blanket.
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders. /// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
/// </summary> /// </summary>
internal abstract class Fsr2Pass: FfxPassBase<Fsr2.DispatchDescription, Fsr2.InitializationFlags>
internal abstract class Fsr2Pass: FfxPassWithFlags<Fsr2.DispatchDescription, Fsr2.InitializationFlags>
{ {
internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define internal const int ShadingChangeMipLevel = 4; // This matches the FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define

2
Runtime/FSR3/Fsr3UpscalerPass.cs

@ -28,7 +28,7 @@ namespace FidelityFX.FSR3
/// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket. /// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket.
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders. /// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
/// </summary> /// </summary>
internal abstract class Fsr3UpscalerPass: FfxPassBase<Fsr3Upscaler.DispatchDescription, Fsr3Upscaler.InitializationFlags>
internal abstract class Fsr3UpscalerPass: FfxPassWithFlags<Fsr3Upscaler.DispatchDescription, Fsr3Upscaler.InitializationFlags>
{ {
protected readonly Fsr3Upscaler.ContextDescription ContextDescription; protected readonly Fsr3Upscaler.ContextDescription ContextDescription;
protected readonly Fsr3UpscalerResources Resources; protected readonly Fsr3UpscalerResources Resources;

Loading…
Cancel
Save