Permalink
Browse files

Cocoa Port: Fix a bug in Metal display views where the internal V-syn…

…c would cause the total frame rate to be divided amongst multiple visible display views.
  • Loading branch information...
rogerman committed Aug 23, 2018
1 parent 5c85bcd commit 5d384f9eae1e1c0b7f5738431ac58043dde870cf
@@ -1,5 +1,5 @@
/*
Copyright (C) 2017 DeSmuME team
Copyright (C) 2017-2018 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1290,12 +1290,23 @@ void ClientDisplayViewInterface::SetAllowViewFlushes(bool allowFlushes)
this->_allowViewFlushes = allowFlushes;
}
void ClientDisplayViewInterface::FlushView()
void ClientDisplayViewInterface::FlushView(void *userData)
{
// Do nothing. This is implementation dependent.
this->_viewNeedsFlush = false;
}
void ClientDisplayViewInterface::FinalizeFlush(void *userData)
{
// Do nothing. This is implementation dependent.
}
void ClientDisplayViewInterface::FlushAndFinalizeImmediate()
{
this->FlushView(NULL);
this->FinalizeFlush(NULL);
}
// Touch screen input handling
void ClientDisplayViewInterface::GetNDSPoint(const ClientDisplayPresenterProperties &props,
const double logicalClientWidth, const double logicalClientHeight,
@@ -1,5 +1,5 @@
/*
Copyright (C) 2017 DeSmuME team
Copyright (C) 2017-2018 DeSmuME team
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -355,7 +355,9 @@ class ClientDisplayViewInterface
bool GetAllowViewFlushes() const;
virtual void SetAllowViewFlushes(bool allowFlushes);
virtual void FlushView();
virtual void FlushView(void *userData);
virtual void FinalizeFlush(void *userData);
virtual void FlushAndFinalizeImmediate();
// Touch screen input handling
void GetNDSPoint(const ClientDisplayPresenterProperties &props,
@@ -23,6 +23,7 @@
#include <mach/semaphore.h>
#include <mach/sync_policy.h>
#include <map>
#include <vector>
#import "cocoa_util.h"
#include "../../GPU.h"
@@ -57,6 +58,7 @@ enum ClientDisplayBufferState
};
class GPUEventHandlerOSX;
class ClientDisplay3DView;
#ifdef ENABLE_SHARED_FETCH_OBJECT
@@ -102,7 +104,10 @@ typedef std::map<CGDirectDisplayID, int64_t> DisplayLinkFlushTimeLimitMap;
- (void) incrementViewsUsingDirectToCPUFiltering;
- (void) decrementViewsUsingDirectToCPUFiltering;
- (void) pushVideoDataToAllDisplayViews;
- (void) flushAllDisplaysOnDisplayLink:(CVDisplayLinkRef)displayLink timeStamp:(const CVTimeStamp *)timeStamp;
- (void) flushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList;
- (void) finalizeFlushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList;
- (void) displayLinkStartUsingID:(CGDirectDisplayID)displayID;
- (void) displayLinkListUpdate;
@@ -24,16 +24,16 @@
#include "../../rasterize.h"
#ifdef MAC_OS_X_VERSION_10_7
#include "../../OGLRender_3_2.h"
#include "../../OGLRender_3_2.h"
#else
#include "../../OGLRender.h"
#include "../../OGLRender.h"
#endif
#include <OpenGL/OpenGL.h>
#import "userinterface/MacOGLDisplayView.h"
#ifdef ENABLE_APPLE_METAL
#import "userinterface/MacMetalDisplayView.h"
#import "userinterface/MacMetalDisplayView.h"
#endif
#ifdef BOOL
@@ -1219,6 +1219,8 @@ - (void) flushAllDisplaysOnDisplayLink:(CVDisplayLinkRef)displayLink timeStamp:(
CGDirectDisplayID displayID = CVDisplayLinkGetCurrentCGDisplay(displayLink);
bool didFlushOccur = false;
std::vector<ClientDisplay3DView *> cdvFlushList;
if (currentRWLock != NULL)
{
pthread_rwlock_rdlock(currentRWLock);
@@ -1234,13 +1236,21 @@ - (void) flushAllDisplaysOnDisplayLink:(CVDisplayLinkRef)displayLink timeStamp:(
if (cdv->GetViewNeedsFlush())
{
cdv->FlushView();
didFlushOccur = true;
cdvFlushList.push_back(cdv);
}
}
}
}
const size_t listSize = cdvFlushList.size();
if (listSize > 0)
{
[self flushMultipleViews:cdvFlushList];
[self finalizeFlushMultipleViews:cdvFlushList];
didFlushOccur = true;
}
if (currentRWLock != NULL)
{
pthread_rwlock_unlock(currentRWLock);
@@ -1257,6 +1267,28 @@ - (void) flushAllDisplaysOnDisplayLink:(CVDisplayLinkRef)displayLink timeStamp:(
}
}
- (void) flushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList
{
const size_t listSize = cdvFlushList.size();
for (size_t i = 0; i < listSize; i++)
{
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FlushView(NULL);
}
}
- (void) finalizeFlushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList
{
const size_t listSize = cdvFlushList.size();
for (size_t i = 0; i < listSize; i++)
{
ClientDisplay3DView *cdv = (ClientDisplay3DView *)cdvFlushList[i];
cdv->FinalizeFlush(NULL);
}
}
- (void) displayLinkStartUsingID:(CGDirectDisplayID)displayID
{
CVDisplayLinkRef displayLink = NULL;
@@ -2128,7 +2128,7 @@ - (void) setupLayer
// If localOGLContext isn't nil, then we will not assign the local layer
// directly to the view, since the OpenGL context will already be what
// is assigned.
cdv->FlushView();
cdv->FlushAndFinalizeImmediate();
return;
}
@@ -2144,7 +2144,7 @@ - (void) setupLayer
if (isMetalLayer)
{
cdv->FlushView();
cdv->FlushAndFinalizeImmediate();
}
else
{
@@ -2226,12 +2226,12 @@ - (BOOL)wantsUpdateLayer
- (void)updateLayer
{
[self clientDisplayView]->FlushView();
[self clientDisplayView]->FlushAndFinalizeImmediate();
}
- (void)drawRect:(NSRect)dirtyRect
{
[self clientDisplayView]->FlushView();
[self clientDisplayView]->FlushAndFinalizeImmediate();
}
- (void)setFrame:(NSRect)rect
@@ -168,6 +168,9 @@ typedef DisplayViewShaderProperties DisplayViewShaderProperties;
- (void) fetchNativeDisplayByID:(const NDSDisplayID)displayID bufferIndex:(const u8)bufferIndex blitCommandEncoder:(id<MTLBlitCommandEncoder>)bce;
- (void) fetchCustomDisplayByID:(const NDSDisplayID)displayID bufferIndex:(const u8)bufferIndex blitCommandEncoder:(id<MTLBlitCommandEncoder>)bce;
- (void) flushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList;;
- (void) finalizeFlushMultipleViews:(const std::vector<ClientDisplay3DView *> &)cdvFlushList;
@end
@interface MacMetalDisplayPresenterObject : NSObject
@@ -261,13 +264,17 @@ typedef DisplayViewShaderProperties DisplayViewShaderProperties;
MacDisplayLayeredView *_cdv;
MacMetalDisplayPresenterObject *presenterObject;
dispatch_semaphore_t _semDrawable;
id<CAMetalDrawable> layerDrawable;
}
@property (readonly, nonatomic) MacMetalDisplayPresenterObject *presenterObject;
@property (retain) id<CAMetalDrawable> layerDrawable;
- (id) initWithDisplayPresenterObject:(MacMetalDisplayPresenterObject *)thePresenterObject;
- (void) setupLayer;
- (void) renderToDrawable;
- (void) renderToDrawableUsingCommandBuffer:(id<MTLCommandBuffer>)cb;
- (void) presentDrawableWithCommandBuffer:(id<MTLCommandBuffer>)cb;
- (void) renderAndPresentDrawableImmediate;
@end
@@ -360,7 +367,9 @@ class MacMetalDisplayView : public MacDisplayLayeredView
virtual void SetAllowViewFlushes(bool allowFlushes);
// Client view interface
virtual void FlushView();
virtual void FlushView(void *userData);
virtual void FinalizeFlush(void *userData);
virtual void FlushAndFinalizeImmediate();
};
#pragma mark -
Oops, something went wrong.

0 comments on commit 5d384f9

Please sign in to comment.