Browse Source

Backported safety fixes from Isonzo

pssr
Nico de Poel 10 months ago
parent
commit
f3fcfec801
  1. 3
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/PSSRUpscaler.cs
  2. 5
      Packages/com.ww1gameseries.pssr/Runtime/PSSRPlugin.cs
  3. 11
      Packages/com.ww1gameseries.pssr/Source~/pssrplugin.cpp

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

@ -89,8 +89,7 @@ namespace UnityEngine.Rendering.PostProcessing
_currentContext = (_currentContext + 1) % PSSRPlugin.MaxNumContexts; _currentContext = (_currentContext + 1) % PSSRPlugin.MaxNumContexts;
CommandBuffer cmd = new(); CommandBuffer cmd = new();
_destroyParams.Value.contextIndex = previousContext;
PSSRPlugin.IssuePluginEvent(cmd, PSSRPlugin.Event.Destroy, _destroyParams);
PSSRPlugin.IssuePluginEvent(cmd, PSSRPlugin.Event.Destroy, new IntPtr(previousContext));
Graphics.ExecuteCommandBuffer(cmd); Graphics.ExecuteCommandBuffer(cmd);
cmd.Release(); cmd.Release();

5
Packages/com.ww1gameseries.pssr/Runtime/PSSRPlugin.cs

@ -22,6 +22,11 @@ namespace WW1.PlayStation
cmd.IssuePluginEventAndData(GetRenderEventAndDataFunc(), (int)pluginEvent, data.GetPointer()); cmd.IssuePluginEventAndData(GetRenderEventAndDataFunc(), (int)pluginEvent, data.GetPointer());
} }
public static void IssuePluginEvent(CommandBuffer cmd, Event pluginEvent, IntPtr data)
{
cmd.IssuePluginEventAndData(GetRenderEventAndDataFunc(), (int)pluginEvent, data);
}
[DllImport(LibraryInfo.LibraryName)] [DllImport(LibraryInfo.LibraryName)]
public static extern IntPtr GetRenderEventAndDataFunc(); public static extern IntPtr GetRenderEventAndDataFunc();

11
Packages/com.ww1gameseries.pssr/Source~/pssrplugin.cpp

@ -288,6 +288,8 @@ static bool IsInitialized()
return true; return true;
} }
extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API PSSR_DestroyContext(uint32_t contextIndex);
extern "C" int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API PSSR_CreateContext(const pssr_init_params_t* params, Core::Texture** outputColorTexture) extern "C" int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API PSSR_CreateContext(const pssr_init_params_t* params, Core::Texture** outputColorTexture)
{ {
if (!IsInitialized()) if (!IsInitialized())
@ -305,6 +307,11 @@ extern "C" int32_t UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API PSSR_CreateContext
} }
PssrContext& context = s_contexts[params->contextIndex]; PssrContext& context = s_contexts[params->contextIndex];
if (context.mfsrContext != nullptr)
{
// If for some reason this context wasn't properly destroyed previously, make sure we do that now
PSSR_DestroyContext(params->contextIndex);
}
MfsrContextInitParameters initParams = {}; MfsrContextInitParameters initParams = {};
initParams.init(); initParams.init();
@ -592,8 +599,8 @@ static void UNITY_INTERFACE_API OnRenderEventAndData(int eventID, void* data)
} }
case 2: // Destroy PSSR context case 2: // Destroy PSSR context
{ {
auto* params = (pssr_destroy_params_t*)data;
PSSR_DestroyContext(params->contextIndex);
uint32_t contextIndex = (uint32_t)(intptr_t)data;
PSSR_DestroyContext(contextIndex);
break; break;
} }
case 3: // Request PSSR capture case 3: // Request PSSR capture

Loading…
Cancel
Save