Browse Source

Rotate between PSSR contexts to further reduce risk of race conditions between destroy & create

pssr
Nico de Poel 1 year ago
parent
commit
efd7240f94
  1. 14
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/PSSRUpscaler.cs

14
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/PSSRUpscaler.cs

@ -10,6 +10,7 @@ namespace UnityEngine.Rendering.PostProcessing
public static bool IsSupported => UnityEngine.PS5.Utility.isTrinityMode && PluginInitialized; public static bool IsSupported => UnityEngine.PS5.Utility.isTrinityMode && PluginInitialized;
private static readonly bool PluginInitialized; private static readonly bool PluginInitialized;
private static uint _currentContext;
private PSSRPlugin.DispatchParams _dispatchParams; private PSSRPlugin.DispatchParams _dispatchParams;
private IntPtr _dispatchParamsBuffer; private IntPtr _dispatchParamsBuffer;
@ -32,7 +33,8 @@ namespace UnityEngine.Rendering.PostProcessing
} }
PluginInitialized = true; PluginInitialized = true;
}
_currentContext = 0;
}
public override void CreateContext(PostProcessRenderContext context, Upscaling config) public override void CreateContext(PostProcessRenderContext context, Upscaling config)
{ {
@ -43,7 +45,7 @@ namespace UnityEngine.Rendering.PostProcessing
} }
PSSRPlugin.InitParams initParams; PSSRPlugin.InitParams initParams;
initParams.contextIndex = 0;
initParams.contextIndex = _currentContext;
initParams.displayWidth = (uint)config.UpscaleSize.x; initParams.displayWidth = (uint)config.UpscaleSize.x;
initParams.displayHeight = (uint)config.UpscaleSize.y; initParams.displayHeight = (uint)config.UpscaleSize.y;
initParams.maxRenderWidth = (uint)config.MaxRenderSize.x; initParams.maxRenderWidth = (uint)config.MaxRenderSize.x;
@ -71,8 +73,10 @@ namespace UnityEngine.Rendering.PostProcessing
if (_contextInitialized) if (_contextInitialized)
{ {
_dispatchParams.contextIndex = 0;
_dispatchParams.contextIndex = _currentContext;
Marshal.StructureToPtr(_dispatchParams, _dispatchParamsBuffer, false); Marshal.StructureToPtr(_dispatchParams, _dispatchParamsBuffer, false);
_currentContext = (_currentContext + 1) % PSSRPlugin.MaxNumContexts;
// Destroying the context from the render thread reduces the risk of race conditions causing crashes // Destroying the context from the render thread reduces the risk of race conditions causing crashes
var cmd = new CommandBuffer(); var cmd = new CommandBuffer();
@ -139,7 +143,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (SystemInfo.usesReversedZBuffer) flags |= PSSRPlugin.OptionFlags.ReverseDepth; if (SystemInfo.usesReversedZBuffer) flags |= PSSRPlugin.OptionFlags.ReverseDepth;
if (config.exposureSource == Upscaling.ExposureSource.Auto) flags |= PSSRPlugin.OptionFlags.AutoExposure; if (config.exposureSource == Upscaling.ExposureSource.Auto) flags |= PSSRPlugin.OptionFlags.AutoExposure;
_dispatchParams.contextIndex = 0;
_dispatchParams.contextIndex = _currentContext;
_dispatchParams.color = ToNativePtr(_inputColor); _dispatchParams.color = ToNativePtr(_inputColor);
_dispatchParams.depth = ToNativePtr(_inputDepth[frameIndex]); _dispatchParams.depth = ToNativePtr(_inputDepth[frameIndex]);
_dispatchParams.prevDepth = ToNativePtr(_inputDepth[frameIndex ^ 1]); _dispatchParams.prevDepth = ToNativePtr(_inputDepth[frameIndex ^ 1]);
@ -191,6 +195,8 @@ namespace UnityEngine.Rendering.PostProcessing
private static class PSSRPlugin private static class PSSRPlugin
{ {
public static readonly uint MaxNumContexts = 4;
private const string LibraryName = "PSSRPlugin.prx"; private const string LibraryName = "PSSRPlugin.prx";
[DllImport(LibraryName)] [DllImport(LibraryName)]

Loading…
Cancel
Save