Enable/disable freesync when enter/exit fullscreen game
PATCH 1/1 Enable/disable freesync when enter/exit fullscreen game
The change add amdgpu specific x extension as the protocol for OGL driver to notify there is a freesync capable application/client DDX driver would rely on this to enable freesync before fullscreen flip and disable freesync before unflip or client exit.
--- src/Makefile.am | 2 + src/amdgpu_dri2.c | 30 ++++++++- src/amdgpu_drv.h | 5 ++ src/amdgpu_extension.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++ src/amdgpu_extension.h | 51 +++++++++++++++ src/amdgpu_kms.c | 4 ++ src/amdgpu_present.c | 21 ++++++ 7 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 src/amdgpu_extension.c create mode 100644 src/amdgpu_extension.h
src/Makefile.am +2 -0
@@ -46,6 +46,7 @@ amdgpu_drv_ladir = @moduledir@/drivers amdgpu_drv_la_SOURCES = \ amdgpu_video.c \ amdgpu_misc.c amdgpu_probe.c \ + amdgpu_extension.c \ $(AMDGPU_KMS_SRCS) AM_CFLAGS += @LIBGLAMOR_CFLAGS@ @XORG_CFLAGS@
@@ -64,6 +65,7 @@ EXTRA_DIST = \ amdgpu_list.h \ amdgpu_pixmap.h \ amdgpu_probe.h \ + amdgpu_extension.h \ amdgpu_version.h \ amdgpu_video.h \ simple_list.h \
src/amdgpu_dri2.c +29 -1
@@ -34,6 +34,7 @@#include "amdgpu_glamor.h" #include "amdgpu_video.h" #include "amdgpu_pixmap.h" +#include "amdgpu_extension.h" #ifdef DRI2
@@ -47,7 +48,6 @@#include "amdgpu_bo_helper.h" #include "amdgpu_version.h" -#include "amdgpu_list.h" #include <xf86Priv.h>
@@ -555,6 +555,15 @@ amdgpu_dri2_schedule_flip(xf86CrtcPtr crtc, ClientPtr client,xf86DrvMsgVerb (scrn->scrnIndex,X_INFO ,AMDGPU_LOGLEVEL_DEBUG ,"%s:%d fevent[%p]\n" , __func__, __LINE__, flip_info); +if ((info->fullscreen_client) && + (info->freesync_enabled == FALSE)) { +AMDGPUEntPtr pAMDGPUEnt =AMDGPUEntPriv (scrn); +int ret =-1 ; + ret =AMDGPUFreesyncControl (pAMDGPUEnt->fd, TRUE); +if (!ret) + info->freesync_enabled = TRUE; + } +/* Page flip the full screen buffer */ back_priv = back->driverPrivate; if (amdgpu_do_pageflip(scrn, client, back_priv->pixmap,
@@ -707,6 +716,8 @@ static void amdgpu_dri2_frame_event_handler(xf86CrtcPtr crtc, uint32_t seq, {DRI2FrameEventPtr event = event_data;ScrnInfoPtr scrn = crtc->scrn; +AMDGPUInfoPtr info =AMDGPUPTR (scrn); +AMDGPUEntPtr pAMDGPUEnt =AMDGPUEntPriv (scrn);DrawablePtr drawable;int status;int swap_type;
@@ -737,6 +748,14 @@ static void amdgpu_dri2_frame_event_handler(xf86CrtcPtr crtc, uint32_t seq, }/* else fall through to exchange/blit */ case DRI2_SWAP : +if ((info->fullscreen_client) && + (info->freesync_enabled == TRUE)) { +int ret =-1 ; + ret =AMDGPUFreesyncControl (pAMDGPUEnt->fd, FALSE); +if (!ret) + info->freesync_enabled = FALSE; + } +if (DRI2CanExchange (drawable) &&can_exchange (scrn, drawable, event->front, event->back)) { amdgpu_dri2_exchange_buffers(drawable, event->front,
@@ -1135,6 +1154,7 @@ static int amdgpu_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,ScreenPtr screen = draw->pScreen;ScrnInfoPtr scrn =xf86ScreenToScrn (screen);AMDGPUEntPtr pAMDGPUEnt =AMDGPUEntPriv (scrn); +AMDGPUInfoPtr info =AMDGPUPTR (scrn);xf86CrtcPtr crtc =amdgpu_dri2_drawable_crtc (draw, TRUE);uint32_t msc_delta;drmVBlank vbl;
@@ -1317,6 +1337,14 @@ static int amdgpu_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,return TRUE; blit_fallback: +if ((info->fullscreen_client) && + (info->freesync_enabled == TRUE)) { +int ret =-1 ; + ret =AMDGPUFreesyncControl (pAMDGPUEnt->fd, FALSE); +if (!ret) + info->freesync_enabled = FALSE; + } +if (swap_info) { swap_info->type =DRI2_SWAP ;amdgpu_dri2_schedule_event (FALLBACK_SWAP_DELAY , swap_info);
src/amdgpu_drv.h +5 -0
@@ -244,6 +244,11 @@ typedef struct {/* kms pageflipping */ Bool allowPageFlip; +/* fressync */ +ClientPtr fullscreen_client; +uint32_t client_resource_id; +Bool freesync_enabled; +/* cursor size */ int cursor_w;int cursor_h;
src/amdgpu_extension.c new file +173 -0
173 lines not on this page · raw message
src/amdgpu_extension.h new file +51 -0
51 lines not on this page · raw message
src/amdgpu_kms.c +4 -0
@@ -53,6 +53,7 @@#include "amdgpu_chipinfo_gen.h" #include "amdgpu_bo_helper.h" #include "amdgpu_pixmap.h" +#include "amdgpu_extension.h" #include <gbm.h>
@@ -1329,6 +1330,9 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)xf86DrvMsg (pScrn->scrnIndex,X_INFO ,"2D and 3D cceleration disabled\n" ); } +/* AMDGPU extension setup */ +AMDGPUExtensionSetup (); +/* Init DPMS */ xf86DrvMsgVerb (pScrn->scrnIndex,X_INFO ,AMDGPU_LOGLEVEL_DEBUG ,"Initializing DPMS\n" );
src/amdgpu_present.c +21 -0
@@ -45,6 +45,7 @@#include "amdgpu_glamor.h" #include "amdgpu_pixmap.h" #include "amdgpu_video.h" +#include "amdgpu_extension.h" #include "present.h"
@@ -324,6 +325,15 @@ amdgpu_present_flip(RRCrtcPtr crtc, uint64_t event_id, uint64_t target_msc,if (!amdgpu_present_check_flip (crtc, screen->root, pixmap, sync_flip))return FALSE; +if ((info->fullscreen_client) && + (info->freesync_enabled == FALSE)) { +AMDGPUEntPtr pAMDGPUEnt =AMDGPUEntPriv (scrn); +int ret =-1 ; + ret =AMDGPUFreesyncControl (pAMDGPUEnt->fd, TRUE); +if (!ret) + info->freesync_enabled = TRUE; + } + event =calloc (1 ,sizeof (struct amdgpu_present_vblank_event ));if (!event)return FALSE;
@@ -360,6 +370,17 @@ amdgpu_present_unflip(ScreenPtr screen, uint64_t event_id)if (!amdgpu_present_check_unflip (scrn)) goto modeset; +if ((info->fullscreen_client) && + (info->freesync_enabled == TRUE)) { +AMDGPUEntPtr pAMDGPUEnt =AMDGPUEntPriv (scrn); +int ret =-1 ; + ret =AMDGPUFreesyncControl (pAMDGPUEnt->fd, FALSE); +if (!ret) + info->freesync_enabled = FALSE; +if (info->client_resource_id) +AMDGPUFreeResourceByType (screen); + } + event =calloc (1 ,sizeof (struct amdgpu_present_vblank_event ));if (!event) {ErrorF ("%s: calloc failed, display might freeze\n" , __func__);
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1470104826-30668-1-git-send-email-Hawking.Zhang-5C7GfCeVMHo@public.gmane.org
Quoted 4 lines · Hawking Zhang
The change add amdgpu specific x extension as the protocol for OGL driver to notify there is a freesync capable application/client DDX driver would rely on this to enable freesync before fullscreen flip and disable freesync before unflip or client exit.
As discussed internally, this approach using a driver-specific X11 protocol extension isn't suitable for upstream for various reasons.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx