From 1ea95cdde48babb443edae59cd0ee8c34b0943bc Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 11 Dec 2017 16:17:02 -0800 Subject: [PATCH] Cocoa Port: Do some minor code cleanup. --- desmume/src/OGLRender.cpp | 11 ++++++++++- desmume/src/OGLRender_3_2.cpp | 14 +++++++++++--- desmume/src/frontend/cocoa/cocoa_GPU.h | 1 - desmume/src/frontend/cocoa/cocoa_GPU.mm | 14 ++++++++------ desmume/src/frontend/cocoa/cocoa_core.mm | 7 ++++--- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/desmume/src/OGLRender.cpp b/desmume/src/OGLRender.cpp index 4d19babd4..740247022 100755 --- a/desmume/src/OGLRender.cpp +++ b/desmume/src/OGLRender.cpp @@ -4818,6 +4818,8 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h) return OGLERROR_BEGINGL_FAILED; } + glFinish(); + const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor); if (this->isPBOSupported) @@ -4825,10 +4827,16 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h) if (this->_mappedFramebuffer != NULL) { glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); + glFinish(); } glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ_ARB); - this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); + + if (this->_mappedFramebuffer != NULL) + { + this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); + glFinish(); + } } if (this->isShaderSupported && this->isFBOSupported && this->isVBOSupported) @@ -4902,6 +4910,7 @@ Render3DError OpenGLRenderer_1_2::SetFramebufferSize(size_t w, size_t h) oglrender_framebufferDidResizeCallback(w, h); } + glFinish(); ENDGL(); return OGLERROR_NOERR; diff --git a/desmume/src/OGLRender_3_2.cpp b/desmume/src/OGLRender_3_2.cpp index bb4c92bfd..78f986dfa 100644 --- a/desmume/src/OGLRender_3_2.cpp +++ b/desmume/src/OGLRender_3_2.cpp @@ -1994,15 +1994,22 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h) return OGLERROR_BEGINGL_FAILED; } - const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor); - + glFinish(); + if (this->_mappedFramebuffer != NULL) { glUnmapBuffer(GL_PIXEL_PACK_BUFFER); + glFinish(); } + const size_t newFramebufferColorSizeBytes = w * h * sizeof(FragmentColor); glBufferData(GL_PIXEL_PACK_BUFFER, newFramebufferColorSizeBytes, NULL, GL_STREAM_READ); - this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); + + if (this->_mappedFramebuffer != NULL) + { + this->_mappedFramebuffer = (FragmentColor *__restrict)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); + glFinish(); + } glActiveTexture(GL_TEXTURE0 + OGLTextureUnitID_FinalColor); glBindTexture(GL_TEXTURE_2D, OGLRef.texFinalColorID); @@ -2065,6 +2072,7 @@ Render3DError OpenGLRenderer_3_2::SetFramebufferSize(size_t w, size_t h) oglrender_framebufferDidResizeCallback(w, h); } + glFinish(); ENDGL(); return OGLERROR_NOERR; diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.h b/desmume/src/frontend/cocoa/cocoa_GPU.h index 1c6e6621d..e0ab05a4f 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.h +++ b/desmume/src/frontend/cocoa/cocoa_GPU.h @@ -104,7 +104,6 @@ typedef std::map DisplayLinkFlushTimeLimitMap; UInt32 gpuStateFlags; uint8_t _gpuScale; BOOL isCPUCoreCountAuto; - BOOL _needRestoreFrameLock; BOOL _needRestoreRender3DLock; OSSpinLock spinlockGpuState; diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.mm b/desmume/src/frontend/cocoa/cocoa_GPU.mm index dda01a133..cfe9b0462 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.mm +++ b/desmume/src/frontend/cocoa/cocoa_GPU.mm @@ -30,10 +30,10 @@ #endif #include -#include "userinterface/MacOGLDisplayView.h" +#import "userinterface/MacOGLDisplayView.h" #ifdef ENABLE_APPLE_METAL -#include "userinterface/MacMetalDisplayView.h" +#import "userinterface/MacMetalDisplayView.h" #endif #ifdef BOOL @@ -149,7 +149,6 @@ public: GPUSTATE_SUB_OBJ_MASK; isCPUCoreCountAuto = NO; - _needRestoreFrameLock = NO; _needRestoreRender3DLock = NO; SetOpenGLRendererFunctions(&OSXOpenGLRendererInit, @@ -865,18 +864,21 @@ public: gpuEvent->FramebufferLock(); #ifdef ENABLE_SHARED_FETCH_OBJECT - const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex; - semaphore_wait([[self sharedData] semaphoreFramebufferAtIndex:bufferIndex]); + semaphore_wait([[self sharedData] semaphoreFramebufferAtIndex:0]); + semaphore_wait([[self sharedData] semaphoreFramebufferAtIndex:1]); #endif GPU->ClearWithColor(colorBGRA5551); #ifdef ENABLE_SHARED_FETCH_OBJECT - semaphore_signal([[self sharedData] semaphoreFramebufferAtIndex:bufferIndex]); + semaphore_signal([[self sharedData] semaphoreFramebufferAtIndex:1]); + semaphore_signal([[self sharedData] semaphoreFramebufferAtIndex:0]); #endif + gpuEvent->FramebufferUnlock(); #ifdef ENABLE_SHARED_FETCH_OBJECT + const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex; [[self sharedData] signalFetchAtIndex:bufferIndex message:MESSAGE_FETCH_AND_PUSH_VIDEO]; #endif } diff --git a/desmume/src/frontend/cocoa/cocoa_core.mm b/desmume/src/frontend/cocoa/cocoa_core.mm index e76b83c3d..e16ab048e 100644 --- a/desmume/src/frontend/cocoa/cocoa_core.mm +++ b/desmume/src/frontend/cocoa/cocoa_core.mm @@ -1121,8 +1121,8 @@ static void* RunCoreThread(void *arg) NSMutableArray *cdsOutputList = [cdsCore cdsOutputList]; const NDSFrameInfo &ndsFrameInfo = execControl->GetNDSFrameInfo(); - double startTime = 0; - double frameTime = 0; // The amount of time that is expected for the frame to run. + double startTime = 0.0; + double frameTime = 0.0; // The amount of time that is expected for the frame to run. const double standardNDSFrameTime = execControl->CalculateFrameAbsoluteTime(1.0); double executionSpeedAverage = 0.0; @@ -1302,7 +1302,8 @@ static void* RunCoreThread(void *arg) } } - const double currentExecutionSpeed = standardNDSFrameTime / (execControl->GetCurrentAbsoluteTime() - startTime); + const double endTime = execControl->GetCurrentAbsoluteTime(); + const double currentExecutionSpeed = standardNDSFrameTime / (endTime - startTime); executionSpeedAverage += currentExecutionSpeed; executionSpeedAverageFramesCollected += 1.0;