Browse Source

Cleanup and comments

pssr
Nico de Poel 1 year ago
parent
commit
e856979480
  1. 22
      Tools/PSSRPlugin/pssrplugin.cpp

22
Tools/PSSRPlugin/pssrplugin.cpp

@ -2,7 +2,6 @@
#include <libsysmodule.h> #include <libsysmodule.h>
#include <agc.h> #include <agc.h>
#include <agc/core/sync.h>
#include <agc/gnmp/gnmp.h> #include <agc/gnmp/gnmp.h>
#include <psml_mfsr.h> #include <psml_mfsr.h>
@ -27,9 +26,6 @@ static bool s_mfsrInitialized = false;
static MfsrPhysicalMemoryBlock* s_mfsrSharedResourcesMemoryBlocks = nullptr; static MfsrPhysicalMemoryBlock* s_mfsrSharedResourcesMemoryBlocks = nullptr;
static MfsrSharedResources s_mfsrSharedResources = nullptr; static MfsrSharedResources s_mfsrSharedResources = nullptr;
// "Multiple contexts (up to 4) can be generated to perform multiple MFSR processes within an application."
static const int MaxNumContexts = 4;
struct PssrContext struct PssrContext
{ {
Core::BasicContext agcContext; Core::BasicContext agcContext;
@ -37,6 +33,9 @@ struct PssrContext
MfsrContext mfsrContext = nullptr; MfsrContext mfsrContext = nullptr;
Core::Texture outputColorTexture; Core::Texture outputColorTexture;
}; };
// "Multiple contexts (up to 4) can be generated to perform multiple MFSR processes within an application."
static const int MaxNumContexts = 4;
static PssrContext s_contexts[MaxNumContexts]; static PssrContext s_contexts[MaxNumContexts];
static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType); static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType eventType);
@ -99,12 +98,10 @@ static void UNITY_INTERFACE_API OnGraphicsDeviceEvent(UnityGfxDeviceEventType ev
} }
case kUnityGfxDeviceEventBeforeReset: case kUnityGfxDeviceEventBeforeReset:
{ {
//TODO: user Direct3D 9 code
break; break;
} }
case kUnityGfxDeviceEventAfterReset: case kUnityGfxDeviceEventAfterReset:
{ {
//TODO: user Direct3D 9 code
break; break;
} }
}; };
@ -190,12 +187,14 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API ReleasePssr()
{ {
s_mfsrInitialized = false; s_mfsrInitialized = false;
// Destroy the MFSR shared resources
if (s_mfsrSharedResources != nullptr) if (s_mfsrSharedResources != nullptr)
{ {
releaseMfsrSharedResources(s_mfsrSharedResources); releaseMfsrSharedResources(s_mfsrSharedResources);
s_mfsrSharedResources = nullptr; s_mfsrSharedResources = nullptr;
} }
// Free the memory used for MFSR shared resource data
if (s_mfsrSharedResourcesMemoryBlocks != nullptr) if (s_mfsrSharedResourcesMemoryBlocks != nullptr)
{ {
delete[] s_mfsrSharedResourcesMemoryBlocks; delete[] s_mfsrSharedResourcesMemoryBlocks;
@ -375,25 +374,21 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API DestroyPssrContext(ui
PssrContext& context = s_contexts[contextIndex]; PssrContext& context = s_contexts[contextIndex];
// 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
// Destroy the MFSR context
if (context.mfsrContext != nullptr) if (context.mfsrContext != nullptr)
{ {
releaseMfsrContext(context.mfsrContext); releaseMfsrContext(context.mfsrContext);
context.mfsrContext = nullptr; context.mfsrContext = nullptr;
} }
// Destroy the NGGC command buffer
if (s_GraphicsAgcPS5 != nullptr && context.agcContext.m_dcb.m_bottom != nullptr) if (s_GraphicsAgcPS5 != nullptr && context.agcContext.m_dcb.m_bottom != nullptr)
{ {
s_GraphicsAgcPS5->ReleaseGPUMemory(context.agcContext.m_dcb.m_bottom); s_GraphicsAgcPS5->ReleaseGPUMemory(context.agcContext.m_dcb.m_bottom);
context.agcContext.m_dcb.clear(); context.agcContext.m_dcb.clear();
} }
// Destroy the output color texture
if (context.outputColorTexture.getDataAddress()) if (context.outputColorTexture.getDataAddress())
{ {
if (s_GraphicsPS5 != nullptr) if (s_GraphicsPS5 != nullptr)
@ -408,6 +403,7 @@ extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API DestroyPssrContext(ui
context.outputColorTexture.init(); context.outputColorTexture.init();
} }
// Free the memory used for MFSR context data
if (context.mfsrMemoryBlocks != nullptr) if (context.mfsrMemoryBlocks != nullptr)
{ {
delete[] context.mfsrMemoryBlocks; delete[] context.mfsrMemoryBlocks;

Loading…
Cancel
Save