From 048aa1659961c8f4dcde4c24401dad5ec24c2960 Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Wed, 4 Jul 2018 09:50:09 -0700 Subject: [PATCH] feat(Metal): Support vsync enable / disable --- gfx/common/metal/Context.h | 3 +++ gfx/common/metal/Context.m | 11 +++++++++++ gfx/drivers/metal.m | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gfx/common/metal/Context.h b/gfx/common/metal/Context.h index d335e80510..eeb687fc10 100644 --- a/gfx/common/metal/Context.h +++ b/gfx/common/metal/Context.h @@ -29,6 +29,9 @@ typedef struct @property (nonatomic, readonly) id library; @property (nonatomic, readwrite) MTLClearColor clearColor; +/*! @brief Specifies whether rendering is synchronized with the display */ +@property (nonatomic, readwrite) bool displaySyncEnabled; + /*! @brief Returns the command buffer used for pre-render work, * such as mip maps for applying filters * */ diff --git a/gfx/common/metal/Context.m b/gfx/common/metal/Context.m index 1610d1c56a..91d5ac4c27 100644 --- a/gfx/common/metal/Context.m +++ b/gfx/common/metal/Context.m @@ -60,6 +60,7 @@ _inflightSemaphore = dispatch_semaphore_create(MAX_INFLIGHT); _device = d; _layer = layer; + _layer.displaySyncEnabled = YES; _library = l; _commandQueue = [_device newCommandQueue]; _clearColor = MTLClearColorMake(0, 0, 0, 1); @@ -99,6 +100,16 @@ return self; } +- (void)setDisplaySyncEnabled:(bool)displaySyncEnabled +{ + _layer.displaySyncEnabled = displaySyncEnabled; +} + +- (bool)displaySyncEnabled +{ + return _layer.displaySyncEnabled; +} + - (bool)_initMainState { return YES; diff --git a/gfx/drivers/metal.m b/gfx/drivers/metal.m index 8ba2ae7b5b..773848546e 100644 --- a/gfx/drivers/metal.m +++ b/gfx/drivers/metal.m @@ -75,8 +75,11 @@ static bool metal_frame(void *data, const void *frame, info:video_info]; } -static void metal_set_nonblock_state(void *data, bool state) +static void metal_set_nonblock_state(void *data, bool non_block) { + RARCH_LOG("[Metal]: set non block: %s\n", non_block ? "ON" : "OFF"); + MetalDriver *md = (__bridge MetalDriver *)data; + md.context.displaySyncEnabled = !non_block; } static bool metal_alive(void *data)