Browse Source

Refactored loading of FSR3 compute shaders, using an aggregate object containing pre-loaded compute shaders instead of the old callbacks.

This gives more control to the application about how shaders are loaded/unloaded, and it fits in much more nicely with PPV2's resources.
fsr3
Nico de Poel 2 years ago
parent
commit
6b590b64af
  1. 26
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset
  2. 23
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
  3. 4
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs
  4. 13
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerCallbacks.cs
  5. 8
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs
  6. 64
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerPass.cs
  7. 60
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerShaders.cs
  8. 11
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerShaders.cs.meta
  9. 23
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs

26
Packages/com.unity.postprocessing@3.2.2/PostProcessing/PostProcessResources.asset

@ -127,20 +127,12 @@ MonoBehaviour:
multiScaleAORender: {fileID: 7200000, guid: 34a460e8a2e66c243a9c12024e5a798d, type: 3} multiScaleAORender: {fileID: 7200000, guid: 34a460e8a2e66c243a9c12024e5a798d, type: 3}
multiScaleAOUpsample: {fileID: 7200000, guid: 600d6212b59bb40409d19d750b5fd1e9, type: 3} multiScaleAOUpsample: {fileID: 7200000, guid: 600d6212b59bb40409d19d750b5fd1e9, type: 3}
gaussianDownsample: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3} gaussianDownsample: {fileID: 7200000, guid: 6dba4103d23a7904fbc49099355aff3e, type: 3}
namedShaders:
- name: FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass
shader: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3}
- name: FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass
shader: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3}
- name: FSR3/ffx_fsr3upscaler_depth_clip_pass
shader: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3}
- name: FSR3/ffx_fsr3upscaler_lock_pass
shader: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3}
- name: FSR3/ffx_fsr3upscaler_accumulate_pass
shader: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3}
- name: FSR3/ffx_fsr3upscaler_rcas_pass
shader: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3}
- name: FSR3/ffx_fsr3upscaler_autogen_reactive_pass
shader: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3}
- name: FSR3/ffx_fsr3upscaler_tcr_autogen_pass
shader: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3}
superResolution:
computeLuminancePyramidPass: {fileID: 7200000, guid: d253be05abcdc80428503d3e4cce3a36, type: 3}
reconstructPreviousDepthPass: {fileID: 7200000, guid: 4f59e5b9179d74844ae06a30ae1e0629, type: 3}
depthClipPass: {fileID: 7200000, guid: 20e44016ed34b0d4b8de499d1b566c69, type: 3}
lockPass: {fileID: 7200000, guid: a135306e6d1857e43a86ef20db2a47fe, type: 3}
accumulatePass: {fileID: 7200000, guid: c9b45f0ae7673694ba57a4aadfe212e9, type: 3}
sharpenPass: {fileID: 7200000, guid: 7aaf5cfff022de2499e9b0412f947f6c, type: 3}
autoGenReactivePass: {fileID: 7200000, guid: 5716b91fdaa4e9e439df6b96a796fe6e, type: 3}
tcrAutoGenPass: {fileID: 7200000, guid: 75cdc6ef23f08ed498d4da511923fcea, type: 3}

23
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

@ -31,7 +31,7 @@ namespace UnityEngine.Rendering.PostProcessing
[Serializable] [Serializable]
public class SuperResolution public class SuperResolution
{ {
public Func<PostProcessRenderContext, IFsr3UpscalerCallbacks> callbacksFactory { get; set; } = (context) => new Callbacks(context.resources);
public Func<PostProcessRenderContext, IFsr3UpscalerCallbacks> callbacksFactory { get; set; } = (context) => new Fsr3UpscalerCallbacksBase();
[Tooltip("Standard scaling ratio presets.")] [Tooltip("Standard scaling ratio presets.")]
public Fsr3Upscaler.QualityMode qualityMode = Fsr3Upscaler.QualityMode.Quality; public Fsr3Upscaler.QualityMode qualityMode = Fsr3Upscaler.QualityMode.Quality;
@ -211,7 +211,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (RuntimeUtilities.IsDynamicResolutionEnabled(context.camera)) flags |= Fsr3Upscaler.InitializationFlags.EnableDynamicResolution; if (RuntimeUtilities.IsDynamicResolutionEnabled(context.camera)) flags |= Fsr3Upscaler.InitializationFlags.EnableDynamicResolution;
_callbacks = callbacksFactory(context); _callbacks = callbacksFactory(context);
_fsrContext = Fsr3Upscaler.CreateContext(_displaySize, _maxRenderSize, _callbacks, flags);
_fsrContext = Fsr3Upscaler.CreateContext(_displaySize, _maxRenderSize, context.resources.computeShaders.superResolution, _callbacks, flags);
// Apply a mipmap bias so that textures retain their sharpness // Apply a mipmap bias so that textures retain their sharpness
float biasOffset = Fsr3Upscaler.GetMipmapBiasOffset(_maxRenderSize.x, _displaySize.x); float biasOffset = Fsr3Upscaler.GetMipmapBiasOffset(_maxRenderSize.x, _displaySize.x);
@ -330,24 +330,5 @@ namespace UnityEngine.Rendering.PostProcessing
return new Vector2Int(Mathf.CeilToInt(_maxRenderSize.x * ScalableBufferManager.widthScaleFactor), Mathf.CeilToInt(_maxRenderSize.y * ScalableBufferManager.heightScaleFactor)); return new Vector2Int(Mathf.CeilToInt(_maxRenderSize.x * ScalableBufferManager.widthScaleFactor), Mathf.CeilToInt(_maxRenderSize.y * ScalableBufferManager.heightScaleFactor));
} }
private class Callbacks : Fsr3UpscalerCallbacksBase
{
private readonly PostProcessResources _resources;
public Callbacks(PostProcessResources resources)
{
_resources = resources;
}
public override ComputeShader LoadComputeShader(string name)
{
return _resources.computeShaders.FindComputeShader(name);
}
public override void UnloadComputeShader(ComputeShader shader)
{
}
}
} }
} }

4
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3Upscaler.cs

@ -33,7 +33,7 @@ namespace FidelityFX
/// <summary> /// <summary>
/// Creates a new FSR3 Upscaler context with standard parameters that are appropriate for the current platform. /// Creates a new FSR3 Upscaler context with standard parameters that are appropriate for the current platform.
/// </summary> /// </summary>
public static Fsr3UpscalerContext CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, IFsr3UpscalerCallbacks callbacks, InitializationFlags flags = 0)
public static Fsr3UpscalerContext CreateContext(Vector2Int displaySize, Vector2Int maxRenderSize, Fsr3UpscalerShaders shaders, IFsr3UpscalerCallbacks callbacks, InitializationFlags flags = 0)
{ {
if (SystemInfo.usesReversedZBuffer) if (SystemInfo.usesReversedZBuffer)
flags |= InitializationFlags.EnableDepthInverted; flags |= InitializationFlags.EnableDepthInverted;
@ -51,6 +51,7 @@ namespace FidelityFX
Flags = flags, Flags = flags,
DisplaySize = displaySize, DisplaySize = displaySize,
MaxRenderSize = maxRenderSize, MaxRenderSize = maxRenderSize,
Shaders = shaders,
Callbacks = callbacks, Callbacks = callbacks,
}; };
@ -166,6 +167,7 @@ namespace FidelityFX
public InitializationFlags Flags; public InitializationFlags Flags;
public Vector2Int MaxRenderSize; public Vector2Int MaxRenderSize;
public Vector2Int DisplaySize; public Vector2Int DisplaySize;
public Fsr3UpscalerShaders Shaders;
public IFsr3UpscalerCallbacks Callbacks; public IFsr3UpscalerCallbacks Callbacks;
} }

13
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerCallbacks.cs

@ -28,9 +28,6 @@ namespace FidelityFX
/// </summary> /// </summary>
public interface IFsr3UpscalerCallbacks public interface IFsr3UpscalerCallbacks
{ {
ComputeShader LoadComputeShader(string name);
void UnloadComputeShader(ComputeShader shader);
/// <summary> /// <summary>
/// Apply a mipmap bias to in-game textures to prevent them from becoming blurry as the internal rendering resolution lowers. /// Apply a mipmap bias to in-game textures to prevent them from becoming blurry as the internal rendering resolution lowers.
/// This will need to be customized on a per-game basis, as there is no clear universal way to determine what are "in-game" textures. /// This will need to be customized on a per-game basis, as there is no clear universal way to determine what are "in-game" textures.
@ -52,16 +49,6 @@ namespace FidelityFX
{ {
protected float CurrentBiasOffset = 0; protected float CurrentBiasOffset = 0;
public virtual ComputeShader LoadComputeShader(string name)
{
return Resources.Load<ComputeShader>(name);
}
public virtual void UnloadComputeShader(ComputeShader shader)
{
Resources.UnloadAsset(shader);
}
public virtual void ApplyMipmapBias(float biasOffset) public virtual void ApplyMipmapBias(float biasOffset)
{ {
if (float.IsNaN(biasOffset) || float.IsInfinity(biasOffset)) if (float.IsNaN(biasOffset) || float.IsInfinity(biasOffset))

8
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerContext.cs

@ -42,7 +42,7 @@ namespace FidelityFX
private Fsr3UpscalerPass _reconstructPreviousDepthPass; private Fsr3UpscalerPass _reconstructPreviousDepthPass;
private Fsr3UpscalerPass _lockPass; private Fsr3UpscalerPass _lockPass;
private Fsr3UpscalerPass _accumulatePass; private Fsr3UpscalerPass _accumulatePass;
private Fsr3UpscalerPass _rcasPass;
private Fsr3UpscalerPass _sharpenPass;
private Fsr3UpscalerPass _computeLuminancePyramidPass; private Fsr3UpscalerPass _computeLuminancePyramidPass;
private Fsr3UpscalerPass _generateReactivePass; private Fsr3UpscalerPass _generateReactivePass;
private Fsr3UpscalerPass _tcrAutogeneratePass; private Fsr3UpscalerPass _tcrAutogeneratePass;
@ -101,7 +101,7 @@ namespace FidelityFX
_depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer); _depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _upscalerConstantsBuffer); _lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer); _accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer);
_rcasPass = new Fsr3UpscalerRcasPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer);
_sharpenPass = new Fsr3UpscalerSharpenPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer);
_generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer); _generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer);
_tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer); _tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer);
} }
@ -111,7 +111,7 @@ namespace FidelityFX
DestroyPass(ref _tcrAutogeneratePass); DestroyPass(ref _tcrAutogeneratePass);
DestroyPass(ref _generateReactivePass); DestroyPass(ref _generateReactivePass);
DestroyPass(ref _computeLuminancePyramidPass); DestroyPass(ref _computeLuminancePyramidPass);
DestroyPass(ref _rcasPass);
DestroyPass(ref _sharpenPass);
DestroyPass(ref _accumulatePass); DestroyPass(ref _accumulatePass);
DestroyPass(ref _lockPass); DestroyPass(ref _lockPass);
DestroyPass(ref _reconstructPreviousDepthPass); DestroyPass(ref _reconstructPreviousDepthPass);
@ -258,7 +258,7 @@ namespace FidelityFX
const int threadGroupWorkRegionDimRcas = 16; const int threadGroupWorkRegionDimRcas = 16;
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
_rcasPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
_sharpenPass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
} }
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; _resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;

64
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerPass.cs

@ -50,26 +50,24 @@ namespace FidelityFX
public virtual void Dispose() public virtual void Dispose()
{ {
UnloadComputeShader();
} }
public abstract void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY); public abstract void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY);
protected void LoadComputeShader(string name)
protected void InitComputeShader(string passName, ComputeShader shader)
{ {
LoadComputeShader(name, ContextDescription.Flags, ref ComputeShader, out KernelIndex);
InitComputeShader(passName, shader, ContextDescription.Flags);
} }
private void LoadComputeShader(string name, Fsr3Upscaler.InitializationFlags flags, ref ComputeShader shaderRef, out int kernelIndex)
private void InitComputeShader(string passName, ComputeShader shader, Fsr3Upscaler.InitializationFlags flags)
{ {
if (shaderRef == null)
if (shader == null)
{ {
shaderRef = ContextDescription.Callbacks.LoadComputeShader(name);
if (shaderRef == null)
throw new MissingReferenceException($"Shader '{name}' could not be loaded! Please ensure it is included in the project correctly.");
throw new MissingReferenceException($"Shader for FSR3 Upscaler '{passName}' could not be loaded! Please ensure it is included in the project correctly.");
} }
kernelIndex = shaderRef.FindKernel("CS");
ComputeShader = shader;
KernelIndex = ComputeShader.FindKernel("CS");
bool useLut = false; bool useLut = false;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ #if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
@ -80,34 +78,20 @@ namespace FidelityFX
#endif #endif
// This matches the permutation rules from the CreatePipeline* functions // This matches the permutation rules from the CreatePipeline* functions
if ((flags & Fsr3Upscaler.InitializationFlags.EnableHighDynamicRange) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH");
if (useLut) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) shaderRef.EnableKeyword("FFX_HALF");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableHighDynamicRange) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH");
if (useLut) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE");
if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF");
// Inform the shader which render pipeline we're currently using // Inform the shader which render pipeline we're currently using
var pipeline = GraphicsSettings.currentRenderPipeline; var pipeline = GraphicsSettings.currentRenderPipeline;
if (pipeline != null && pipeline.GetType().Name.Contains("HDRenderPipeline")) if (pipeline != null && pipeline.GetType().Name.Contains("HDRenderPipeline"))
{ {
shaderRef.EnableKeyword("UNITY_FSR3UPSCALER_HDRP");
ComputeShader.EnableKeyword("UNITY_FSR3UPSCALER_HDRP");
} }
} }
private void UnloadComputeShader()
{
UnloadComputeShader(ref ComputeShader);
}
private void UnloadComputeShader(ref ComputeShader shaderRef)
{
if (shaderRef == null)
return;
ContextDescription.Callbacks.UnloadComputeShader(shaderRef);
shaderRef = null;
}
} }
internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass internal class Fsr3UpscalerComputeLuminancePyramidPass : Fsr3UpscalerPass
@ -119,7 +103,7 @@ namespace FidelityFX
{ {
_spdConstants = spdConstants; _spdConstants = spdConstants;
LoadComputeShader("FSR3/ffx_fsr3upscaler_compute_luminance_pyramid_pass");
InitComputeShader("compute_luminance_pyramid_pass", contextDescription.Shaders.computeLuminancePyramidPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -144,7 +128,7 @@ namespace FidelityFX
public Fsr3UpscalerReconstructPreviousDepthPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) public Fsr3UpscalerReconstructPreviousDepthPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
LoadComputeShader("FSR3/ffx_fsr3upscaler_reconstruct_previous_depth_pass");
InitComputeShader("reconstruct_previous_depth_pass", contextDescription.Shaders.reconstructPreviousDepthPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -172,7 +156,7 @@ namespace FidelityFX
public Fsr3UpscalerDepthClipPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) public Fsr3UpscalerDepthClipPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
LoadComputeShader("FSR3/ffx_fsr3upscaler_depth_clip_pass");
InitComputeShader("depth_clip_pass", contextDescription.Shaders.depthClipPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -207,7 +191,7 @@ namespace FidelityFX
public Fsr3UpscalerLockPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) public Fsr3UpscalerLockPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
LoadComputeShader("FSR3/ffx_fsr3upscaler_lock_pass");
InitComputeShader("lock_pass", contextDescription.Shaders.lockPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -230,7 +214,7 @@ namespace FidelityFX
public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants) public Fsr3UpscalerAccumulatePass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
LoadComputeShader("FSR3/ffx_fsr3upscaler_accumulate_pass");
InitComputeShader("accumulate_pass", contextDescription.Shaders.accumulatePass);
#if UNITY_2021_2_OR_NEWER #if UNITY_2021_2_OR_NEWER
_sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword); _sharpeningKeyword = new LocalKeyword(ComputeShader, SharpeningKeyword);
#endif #endif
@ -286,16 +270,16 @@ namespace FidelityFX
} }
} }
internal class Fsr3UpscalerRcasPass : Fsr3UpscalerPass
internal class Fsr3UpscalerSharpenPass : Fsr3UpscalerPass
{ {
private readonly ComputeBuffer _rcasConstants; private readonly ComputeBuffer _rcasConstants;
public Fsr3UpscalerRcasPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer rcasConstants)
public Fsr3UpscalerSharpenPass(Fsr3Upscaler.ContextDescription contextDescription, Fsr3UpscalerResources resources, ComputeBuffer constants, ComputeBuffer rcasConstants)
: base(contextDescription, resources, constants) : base(contextDescription, resources, constants)
{ {
_rcasConstants = rcasConstants; _rcasConstants = rcasConstants;
LoadComputeShader("FSR3/ffx_fsr3upscaler_rcas_pass");
InitComputeShader("rcas_pass", contextDescription.Shaders.sharpenPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -323,7 +307,7 @@ namespace FidelityFX
{ {
_generateReactiveConstants = generateReactiveConstants; _generateReactiveConstants = generateReactiveConstants;
LoadComputeShader("FSR3/ffx_fsr3upscaler_autogen_reactive_pass");
InitComputeShader("autogen_reactive_pass", contextDescription.Shaders.autoGenReactivePass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
@ -355,7 +339,7 @@ namespace FidelityFX
{ {
_tcrAutogenerateConstants = tcrAutogenerateConstants; _tcrAutogenerateConstants = tcrAutogenerateConstants;
LoadComputeShader("FSR3/ffx_fsr3upscaler_tcr_autogen_pass");
InitComputeShader("tcr_autogen_pass", contextDescription.Shaders.tcrAutoGenPass);
} }
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)

60
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerShaders.cs

@ -0,0 +1,60 @@
using System;
using UnityEngine;
namespace FidelityFX
{
/// <summary>
/// All the compute shaders used by the FidelityFX Super Resolution 3 (FSR3) Upscaler.
/// </summary>
[Serializable]
public class Fsr3UpscalerShaders
{
/// <summary>
/// The compute shader used by the luminance pyramid computation pass.
/// </summary>
public ComputeShader computeLuminancePyramidPass;
/// <summary>
/// The compute shader used by the previous depth reconstruction pass.
/// </summary>
public ComputeShader reconstructPreviousDepthPass;
/// <summary>
/// The compute shader used by the depth clip pass.
/// </summary>
public ComputeShader depthClipPass;
/// <summary>
/// The compute shader used by the lock pass.
/// </summary>
public ComputeShader lockPass;
/// <summary>
/// The compute shader used by the accumulation pass.
/// </summary>
public ComputeShader accumulatePass;
/// <summary>
/// The compute shader used by the RCAS sharpening pass.
/// </summary>
public ComputeShader sharpenPass;
/// <summary>
/// The compute shader used to auto-generate a reactive mask.
/// </summary>
public ComputeShader autoGenReactivePass;
/// <summary>
/// The compute shader used to auto-generate a transparency & composition mask.
/// </summary>
public ComputeShader tcrAutoGenPass;
/// <summary>
/// Returns a copy of this class and its contents.
/// </summary>
public Fsr3UpscalerShaders Clone()
{
return (Fsr3UpscalerShaders)MemberwiseClone();
}
}
}

11
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR3/Fsr3UpscalerShaders.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cec8f68d6b0d9be4986fac65d3a2e1a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

23
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessResources.cs

@ -1,4 +1,5 @@
using System; using System;
using FidelityFX;
namespace UnityEngine.Rendering.PostProcessing namespace UnityEngine.Rendering.PostProcessing
{ {
@ -214,9 +215,9 @@ namespace UnityEngine.Rendering.PostProcessing
public ComputeShader gaussianDownsample; public ComputeShader gaussianDownsample;
/// <summary> /// <summary>
/// Compute shaders that need to be looked up by name.
/// Compute shaders used by the FidelityFX Super Resolution 3 (FSR3) Upscaler.
/// </summary> /// </summary>
public NamedComputeShader[] namedShaders;
public Fsr3UpscalerShaders superResolution;
/// <summary> /// <summary>
/// Returns a copy of this class and its content. /// Returns a copy of this class and its content.
@ -226,24 +227,6 @@ namespace UnityEngine.Rendering.PostProcessing
{ {
return (ComputeShaders)MemberwiseClone(); return (ComputeShaders)MemberwiseClone();
} }
public ComputeShader FindComputeShader(string name)
{
for (int i = 0; i < namedShaders.Length; ++i)
{
if (namedShaders[i].name == name)
return namedShaders[i].shader;
}
return null;
}
}
[Serializable]
public class NamedComputeShader
{
public string name;
public ComputeShader shader;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save