// TODO: this still crashes often due to race conditions between dispatch above and release here
// The main cause will be that the MFSR context is released before the already dispatched commands are executed on the GPU
// Just adding mutexes everywhere is not going to fix that
// A cheap but slightly dirty solution would be to run this code only at EndOfFrame from Unity
//
// Another issue is that we reuse the same static s_mfsrContext pointer when recreating the MFSR context, which can lead to situations where dispatch uses the wrong context object
// Multi-buffering those pointers will help with that
if(s_mfsrContext!=nullptr)
{
releaseMfsrContext(s_mfsrContext);
s_mfsrContext=nullptr;
}
if(s_mfsrMemoryBlocks!=nullptr)
{
delete[]s_mfsrMemoryBlocks;
s_mfsrMemoryBlocks=nullptr;
}
UNITY_LOG(s_Log,"Destroyed PSSR context");
}
// Plugin function to handle a specific rendering event
// TODO: how do get command buffer from PS5 graphics interface? :thinking:
// I guess we're hoping that s_GraphicsAgcPS5->SubmitGraphics is smart enough to add the submit pointer to the currently recording command list (which seems to be the case, phew!)
auto*params=(pssr_dispatch_params_t*)data;
// How we obtain a command buffer to dispatch to depends on which graphics API we're using in Unity
// TODO: this still crashes often due to race conditions between dispatch above and release here
// The main cause will be that the MFSR context is released before the already dispatched commands are executed on the GPU
// Just adding mutexes everywhere is not going to fix that
// A cheap but slightly dirty solution would be to run this code only at EndOfFrame from Unity
//
// Another issue is that we reuse the same static s_mfsrContext pointer when recreating the MFSR context, which can lead to situations where dispatch uses the wrong context object
// Multi-buffering those pointers will help with that