From e6e65aff9aeb3215020d68ab47667671fbb9aa57 Mon Sep 17 00:00:00 2001 From: Exverge Date: Thu, 11 Jul 2024 22:32:19 -0400 Subject: [PATCH] gx2: Use atomic pointers for GX2WriteGatherPipeState --- src/Cafe/OS/libs/gx2/GX2_Command.cpp | 22 +++++++++++----------- src/Cafe/OS/libs/gx2/GX2_Command.h | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Cafe/OS/libs/gx2/GX2_Command.cpp b/src/Cafe/OS/libs/gx2/GX2_Command.cpp index ec96a4ff..0779cbb1 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Command.cpp +++ b/src/Cafe/OS/libs/gx2/GX2_Command.cpp @@ -17,28 +17,28 @@ GX2WriteGatherPipeState gx2WriteGatherPipe = { 0 }; void gx2WriteGather_submitU32AsBE(uint32 v) { uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); - if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) + if (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; - *(uint32*)(*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) = _swapEndianU32(v); - (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) += 4; + *(uint32*)(gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]->load()) = _swapEndianU32(v); + *gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] += 4; } void gx2WriteGather_submitU32AsLE(uint32 v) { uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); - if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) + if (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; - *(uint32*)(*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) = v; - (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) += 4; + *(uint32*)(gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]->load()) = v; + *gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] += 4; } void gx2WriteGather_submitU32AsLEArray(uint32* v, uint32 numValues) { uint32 coreIndex = PPCInterpreter_getCoreIndex(PPCInterpreter_getCurrentInstance()); - if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) + if (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == NULL) return; - memcpy_dwords((*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]), v, numValues); - (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]) += 4 * numValues; + memcpy_dwords(gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]->load(), v, numValues); + *gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] += 4 * numValues; } namespace GX2 @@ -121,7 +121,7 @@ namespace GX2 if (sGX2MainCoreIndex == coreIndex) gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] = &gx2WriteGatherPipe.writeGatherPtrGxBuffer[coreIndex]; else - gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] = NULL; + *gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] = NULL; // return size of (written) display list return currentWriteSize; } @@ -217,7 +217,7 @@ namespace GX2 cemu_assert_debug(coreIndex == sGX2MainCoreIndex); coreIndex = sGX2MainCoreIndex; // always submit to main queue which is owned by GX2 main core (TCLSubmitToRing does not need this workaround) - uint32be* cmdStream = (uint32be*)(gx2WriteGatherPipe.writeGatherPtrGxBuffer[coreIndex]); + uint32be* cmdStream = (uint32be*)(gx2WriteGatherPipe.writeGatherPtrGxBuffer[coreIndex].load()); cmdStream[0] = pm4HeaderType3(IT_INDIRECT_BUFFER_PRIV, 3); cmdStream[1] = memory_virtualToPhysical(MEMPTR(addr).GetMPTR()); cmdStream[2] = 0; diff --git a/src/Cafe/OS/libs/gx2/GX2_Command.h b/src/Cafe/OS/libs/gx2/GX2_Command.h index 51c04928..fb9bb65e 100644 --- a/src/Cafe/OS/libs/gx2/GX2_Command.h +++ b/src/Cafe/OS/libs/gx2/GX2_Command.h @@ -6,9 +6,9 @@ struct GX2WriteGatherPipeState { uint8* gxRingBuffer; // each core has it's own write gatherer and display list state (writing) - uint8* writeGatherPtrGxBuffer[Espresso::CORE_COUNT]; - uint8** writeGatherPtrWrite[Espresso::CORE_COUNT]; - uint8* writeGatherPtrDisplayList[Espresso::CORE_COUNT]; + std::atomic writeGatherPtrGxBuffer[Espresso::CORE_COUNT]; + std::atomic* writeGatherPtrWrite[Espresso::CORE_COUNT]; + std::atomic writeGatherPtrDisplayList[Espresso::CORE_COUNT]; MPTR displayListStart[Espresso::CORE_COUNT]; uint32 displayListMaxSize[Espresso::CORE_COUNT]; }; @@ -75,10 +75,10 @@ template inline void gx2WriteGather_submit(Targs... args) { uint32 coreIndex = PPCInterpreter_getCurrentCoreIndex(); - if (gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == nullptr) + if (*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex] == nullptr) return; - uint32be* writePtr = (uint32be*)(*gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]); + uint32be* writePtr = (uint32be*)gx2WriteGatherPipe.writeGatherPtrWrite[coreIndex]->load(); gx2WriteGather_submit_(coreIndex, writePtr, std::forward(args)...); }