Browse Source

Destroy context by directly calling into the library instead of using a plugin event. Seems perfectly stable in testing and fixes an issue where occasionally the wrong context index would come through in native code.

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

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

@ -71,16 +71,11 @@ namespace UnityEngine.Rendering.PostProcessing
if (_contextInitialized)
{
_dispatchParams.contextIndex = _currentContext;
Marshal.StructureToPtr(_dispatchParams, _dispatchParamsBuffer, false);
// Rotate between contexts to reduce the risk of race conditions between old and new contexts
uint previousContext = _currentContext;
_currentContext = (_currentContext + 1) % PSSRPlugin.MaxNumContexts;
// Destroying the context from the render thread reduces the risk of race conditions causing crashes
var cmd = new CommandBuffer();
cmd.IssuePluginEventAndData(PSSRPlugin.GetRenderEventAndDataFunc(), 2, _dispatchParamsBuffer);
Graphics.ExecuteCommandBuffer(cmd);
cmd.Release();
PSSRPlugin.DestroyPssrContext(previousContext);
_contextInitialized = false;
}
@ -206,7 +201,7 @@ namespace UnityEngine.Rendering.PostProcessing
public static extern int CreatePssrContext(ref InitParams initParams, out IntPtr outputColorTexturePtr);
[DllImport(LibraryName)]
public static extern void DestroyPssrContext();
public static extern void DestroyPssrContext(uint contextIndex);
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct InitParams

Loading…
Cancel
Save