diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.h b/desmume/src/frontend/cocoa/cocoa_GPU.h index 0bca32163..9a72c806a 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.h +++ b/desmume/src/frontend/cocoa/cocoa_GPU.h @@ -103,7 +103,6 @@ typedef std::map DisplayLinkFlushTimeLimitMap; @property (assign) NSSize gpuDimensions; @property (assign) NSUInteger gpuScale; @property (assign) NSUInteger gpuColorFormat; -@property (readonly) pthread_rwlock_t *gpuFrameRWLock; @property (assign) BOOL layerMainGPU; @property (assign) BOOL layerMainBG0; diff --git a/desmume/src/frontend/cocoa/cocoa_GPU.mm b/desmume/src/frontend/cocoa/cocoa_GPU.mm index 559f099b9..d95d8ebd5 100644 --- a/desmume/src/frontend/cocoa/cocoa_GPU.mm +++ b/desmume/src/frontend/cocoa/cocoa_GPU.mm @@ -52,7 +52,7 @@ class GPUEventHandlerOSX : public GPUEventHandlerDefault private: GPUClientFetchObject *_fetchObject; - pthread_rwlock_t _rwlockFrame; + pthread_mutex_t _mutexFrame; pthread_mutex_t _mutex3DRender; pthread_mutex_t _mutexApplyGPUSettings; pthread_mutex_t _mutexApplyRender3DSettings; @@ -65,8 +65,7 @@ public: GPUClientFetchObject* GetFetchObject() const; void SetFetchObject(GPUClientFetchObject *fetchObject); - void FramebufferLockWrite(); - void FramebufferLockRead(); + void FramebufferLock(); void FramebufferUnlock(); void Render3DLock(); void Render3DUnlock(); @@ -75,7 +74,6 @@ public: void ApplyRender3DSettingsLock(); void ApplyRender3DSettingsUnlock(); - pthread_rwlock_t* GetFrameRWLock(); bool GetRender3DNeedsFinish(); virtual void DidFrameBegin(bool isFrameSkipRequested, const u8 targetBufferIndex, const size_t line); @@ -94,7 +92,6 @@ public: @dynamic gpuDimensions; @dynamic gpuScale; @dynamic gpuColorFormat; -@dynamic gpuFrameRWLock; @dynamic layerMainGPU; @dynamic layerMainBG0; @@ -256,7 +253,7 @@ public: - (void) setGpuDimensions:(NSSize)theDimensions { gpuEvent->Render3DLock(); - gpuEvent->FramebufferLockWrite(); + gpuEvent->FramebufferLock(); #ifdef ENABLE_SHARED_FETCH_OBJECT pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); @@ -278,7 +275,7 @@ public: - (NSSize) gpuDimensions { gpuEvent->Render3DLock(); - gpuEvent->FramebufferLockRead(); + gpuEvent->FramebufferLock(); const NSSize dimensions = NSMakeSize(GPU->GetCustomFramebufferWidth(), GPU->GetCustomFramebufferHeight()); gpuEvent->FramebufferUnlock(); gpuEvent->Render3DUnlock(); @@ -313,7 +310,7 @@ public: // Change the color format. gpuEvent->Render3DLock(); - gpuEvent->FramebufferLockWrite(); + gpuEvent->FramebufferLock(); #ifdef ENABLE_SHARED_FETCH_OBJECT pthread_rwlock_wrlock([[self sharedData] rwlockFramebufferAtIndex:0]); @@ -335,7 +332,7 @@ public: - (NSUInteger) gpuColorFormat { gpuEvent->Render3DLock(); - gpuEvent->FramebufferLockRead(); + gpuEvent->FramebufferLock(); const NSUInteger colorFormat = (NSUInteger)GPU->GetDisplayInfo().colorFormat; gpuEvent->FramebufferUnlock(); gpuEvent->Render3DUnlock(); @@ -343,11 +340,6 @@ public: return colorFormat; } -- (pthread_rwlock_t *) gpuFrameRWLock -{ - return gpuEvent->GetFrameRWLock(); -} - #ifdef ENABLE_SHARED_FETCH_OBJECT - (void) setOutputList:(NSMutableArray *)theOutputList mutexPtr:(pthread_mutex_t *)theMutex { @@ -868,7 +860,7 @@ public: - (void) clearWithColor:(const uint16_t)colorBGRA5551 { - gpuEvent->FramebufferLockWrite(); + gpuEvent->FramebufferLock(); #ifdef ENABLE_SHARED_FETCH_OBJECT const u8 bufferIndex = GPU->GetDisplayInfo().bufferIndex; @@ -1239,7 +1231,7 @@ GPUEventHandlerOSX::GPUEventHandlerOSX() { _fetchObject = nil; _render3DNeedsFinish = false; - pthread_rwlock_init(&_rwlockFrame, NULL); + pthread_mutex_init(&_mutexFrame, NULL); pthread_mutex_init(&_mutex3DRender, NULL); pthread_mutex_init(&_mutexApplyGPUSettings, NULL); pthread_mutex_init(&_mutexApplyRender3DSettings, NULL); @@ -1252,7 +1244,7 @@ GPUEventHandlerOSX::~GPUEventHandlerOSX() pthread_mutex_unlock(&this->_mutex3DRender); } - pthread_rwlock_destroy(&this->_rwlockFrame); + pthread_mutex_destroy(&this->_mutexFrame); pthread_mutex_destroy(&this->_mutex3DRender); pthread_mutex_destroy(&this->_mutexApplyGPUSettings); pthread_mutex_destroy(&this->_mutexApplyRender3DSettings); @@ -1270,7 +1262,7 @@ void GPUEventHandlerOSX::SetFetchObject(GPUClientFetchObject *fetchObject) void GPUEventHandlerOSX::DidFrameBegin(bool isFrameSkipRequested, const u8 targetBufferIndex, const size_t line) { - this->FramebufferLockWrite(); + this->FramebufferLock(); #ifdef ENABLE_SHARED_FETCH_OBJECT if (!isFrameSkipRequested) @@ -1334,19 +1326,14 @@ void GPUEventHandlerOSX::DidApplyRender3DSettingsEnd() this->ApplyRender3DSettingsUnlock(); } -void GPUEventHandlerOSX::FramebufferLockWrite() +void GPUEventHandlerOSX::FramebufferLock() { - pthread_rwlock_wrlock(&this->_rwlockFrame); -} - -void GPUEventHandlerOSX::FramebufferLockRead() -{ - pthread_rwlock_rdlock(&this->_rwlockFrame); + pthread_mutex_lock(&this->_mutexFrame); } void GPUEventHandlerOSX::FramebufferUnlock() { - pthread_rwlock_unlock(&this->_rwlockFrame); + pthread_mutex_unlock(&this->_mutexFrame); } void GPUEventHandlerOSX::Render3DLock() @@ -1384,11 +1371,6 @@ bool GPUEventHandlerOSX::GetRender3DNeedsFinish() return this->_render3DNeedsFinish; } -pthread_rwlock_t* GPUEventHandlerOSX::GetFrameRWLock() -{ - return &this->_rwlockFrame; -} - #pragma mark - CGLContextObj OSXOpenGLRendererContext = NULL; diff --git a/desmume/src/frontend/cocoa/cocoa_core.mm b/desmume/src/frontend/cocoa/cocoa_core.mm index bf9a88c49..4fb4b1727 100644 --- a/desmume/src/frontend/cocoa/cocoa_core.mm +++ b/desmume/src/frontend/cocoa/cocoa_core.mm @@ -901,7 +901,7 @@ volatile bool execute = true; if ([theOutput isKindOfClass:[CocoaDSDisplay class]]) { - [theOutput setRwlockProducer:[[self cdsGPU] gpuFrameRWLock]]; + [theOutput setRwlockProducer:NULL]; } else { diff --git a/desmume/src/frontend/cocoa/cocoa_output.mm b/desmume/src/frontend/cocoa/cocoa_output.mm index 52070fbe0..65d510e31 100644 --- a/desmume/src/frontend/cocoa/cocoa_output.mm +++ b/desmume/src/frontend/cocoa/cocoa_output.mm @@ -57,6 +57,8 @@ mutexConsume = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(mutexConsume, NULL); + rwlockProducer = NULL; + return self; } diff --git a/desmume/src/frontend/cocoa/userinterface/MacMetalDisplayView.mm b/desmume/src/frontend/cocoa/userinterface/MacMetalDisplayView.mm index 145168938..b9033447b 100644 --- a/desmume/src/frontend/cocoa/userinterface/MacMetalDisplayView.mm +++ b/desmume/src/frontend/cocoa/userinterface/MacMetalDisplayView.mm @@ -1299,16 +1299,16 @@ id cb = [self newCommandBuffer]; id cce = [cb computeCommandEncoder]; + if (needsFetchBuffersLock) + { + pthread_rwlock_rdlock([sharedData rwlockFramebufferAtIndex:bufferIndex]); + } + // Run the video source filters and the pixel scalers if (useDeposterize) { [cce setComputePipelineState:[sharedData deposterizePipeline]]; - if (needsFetchBuffersLock) - { - pthread_rwlock_rdlock([sharedData rwlockFramebufferAtIndex:bufferIndex]); - } - if (shouldProcessDisplay[NDSDisplayID_Main]) { [cce setTexture:texMain atIndex:0]; @@ -1348,16 +1348,19 @@ if (needsFetchBuffersLock) { + needsFetchBuffersLock = !isDisplayProcessedMain || !isDisplayProcessedTouch; + [cce endEncoding]; [cb addCompletedHandler:^(id block) { - pthread_rwlock_unlock([sharedData rwlockFramebufferAtIndex:bufferIndex]); + if (!needsFetchBuffersLock) + { + pthread_rwlock_unlock([sharedData rwlockFramebufferAtIndex:bufferIndex]); + } }]; [cb commit]; cb = [self newCommandBuffer]; cce = [cb computeCommandEncoder]; - - needsFetchBuffersLock = !isDisplayProcessedMain || !isDisplayProcessedTouch; } } @@ -1366,11 +1369,6 @@ { [cce setComputePipelineState:[self pixelScalePipeline]]; - if (needsFetchBuffersLock) - { - pthread_rwlock_rdlock([sharedData rwlockFramebufferAtIndex:bufferIndex]); - } - if (shouldProcessDisplay[NDSDisplayID_Main]) { [cce setTexture:texMain atIndex:0]; @@ -1400,6 +1398,8 @@ if (needsFetchBuffersLock) { + needsFetchBuffersLock = false; + [cce endEncoding]; [cb addCompletedHandler:^(id block) { pthread_rwlock_unlock([sharedData rwlockFramebufferAtIndex:bufferIndex]);