[Mesa-dev] [PATCH v2] egl/android: Implement the eglSwapinterval for Android.

2018-01-18 Thread Zhongmin Wu
Implement the eglSwapinterval for Android platform to
enable the async mode for some GFX benchmarks such as
Daimler C217, CityBench.

Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/platform_android.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index f6a24cd..3a64689 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -476,6 +476,20 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
return EGL_TRUE;
 }
 
+static EGLBoolean
+droid_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy,
+   _EGLSurface *surf, EGLint interval)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   struct ANativeWindow *window = dri2_surf->window;
+
+   if (window->setSwapInterval(window, interval))
+  return EGL_FALSE;
+
+   surf->SwapInterval = interval;
+   return EGL_TRUE;
+}
+
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
@@ -1300,6 +1314,7 @@ static const struct dri2_egl_display_vtbl 
droid_display_vtbl = {
.swap_buffers = droid_swap_buffers,
.swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, /* 
Android implements the function */
.swap_buffers_region = dri2_fallback_swap_buffers_region,
+   .swap_interval = droid_swap_interval,
 #if ANDROID_API_LEVEL >= 23
.set_damage_region = droid_set_damage_region,
 #else
@@ -1443,6 +1458,12 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay 
*dpy)
 
dri2_setup_screen(dpy);
 
+   /* we set the maximum swap interval as 1 for Android platform, Since
+   it is the maximum value supported by Android according to the
+   value of ANativeWindow::maxSwapInterval.
+   */
+   dri2_setup_swap_interval(dpy, 1);
+
if (!droid_add_configs_for_visuals(drv, dpy)) {
   err = "DRI2: failed to add configs";
   goto cleanup;
-- 
2.7.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v1] egl/android: Implement the eglSwapinterval for Android.

2018-01-15 Thread Zhongmin Wu
Implement the eglSwapinterval for Android platform to
enable the async mode for some GFX benchmarks.

Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/platform_android.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index f6a24cd..09f1159 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -476,6 +476,19 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
return EGL_TRUE;
 }
 
+static EGLBoolean
+droid_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy,
+   _EGLSurface *surf, EGLint interval)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   struct ANativeWindow *window = dri2_surf->window;
+   if (window->setSwapInterval(window, interval)) {
+  return EGL_FALSE;
+   }
+   surf->SwapInterval = interval;
+   return EGL_TRUE;
+}
+
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
@@ -1300,6 +1313,7 @@ static const struct dri2_egl_display_vtbl 
droid_display_vtbl = {
.swap_buffers = droid_swap_buffers,
.swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, /* 
Android implements the function */
.swap_buffers_region = dri2_fallback_swap_buffers_region,
+   .swap_interval = droid_swap_interval,
 #if ANDROID_API_LEVEL >= 23
.set_damage_region = droid_set_damage_region,
 #else
@@ -1443,6 +1457,8 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 
dri2_setup_screen(dpy);
 
+   dri2_setup_swap_interval(dpy, 1);
+
if (!droid_add_configs_for_visuals(drv, dpy)) {
   err = "DRI2: failed to add configs";
   goto cleanup;
-- 
2.7.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [egl/android: Implement the eglSwapinterval for Android] egl/android: Implement the eglSwapinterval for Android.

2018-01-02 Thread zhongmin . wu
From: Zhongmin Wu <zhongmin...@intel.com>

Implement the eglSwapinterval for Android platform to
enable the async mode for some GFX benchmarks.

Change-Id: I3576d8b92862719dae11c31e2adc2d77cb5a0b64
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/platform_android.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index f6a24cd..f9c74ee 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -476,6 +476,18 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
return EGL_TRUE;
 }
 
+static EGLBoolean droid_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy,
+_EGLSurface *surf, EGLint interval) {
+
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   struct ANativeWindow *window = dri2_surf->window;
+   if (window->setSwapInterval(window, interval)) {
+  return EGL_FALSE;
+   }
+   surf->SwapInterval = interval;
+   return EGL_TRUE;
+}
+
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
@@ -1300,6 +1312,7 @@ static const struct dri2_egl_display_vtbl 
droid_display_vtbl = {
.swap_buffers = droid_swap_buffers,
.swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, /* 
Android implements the function */
.swap_buffers_region = dri2_fallback_swap_buffers_region,
+   .swap_interval = droid_swap_interval,
 #if ANDROID_API_LEVEL >= 23
.set_damage_region = droid_set_damage_region,
 #else
@@ -1443,6 +1456,8 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 
dri2_setup_screen(dpy);
 
+   dri2_setup_swap_interval(dpy, 1);
+
if (!droid_add_configs_for_visuals(drv, dpy)) {
   err = "DRI2: failed to add configs";
   goto cleanup;
-- 
2.7.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [egl/android: Implement the eglSwapinterval for Android] egl/android: Implement the eglSwapinterval for Android.

2018-01-02 Thread zhongmin . wu
From: Zhongmin Wu <zhongmin...@intel.com>

Implement the eglSwapinterval for Android platform to
enable the async mode for some GFX benchmarks.

Change-Id: I3576d8b92862719dae11c31e2adc2d77cb5a0b64
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/platform_android.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index f6a24cd..f9c74ee 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -476,6 +476,18 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
return EGL_TRUE;
 }
 
+static EGLBoolean droid_swap_interval(_EGLDriver *drv, _EGLDisplay *dpy,
+_EGLSurface *surf, EGLint interval) {
+
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   struct ANativeWindow *window = dri2_surf->window;
+   if (window->setSwapInterval(window, interval)) {
+  return EGL_FALSE;
+   }
+   surf->SwapInterval = interval;
+   return EGL_TRUE;
+}
+
 static int
 update_buffers(struct dri2_egl_surface *dri2_surf)
 {
@@ -1300,6 +1312,7 @@ static const struct dri2_egl_display_vtbl 
droid_display_vtbl = {
.swap_buffers = droid_swap_buffers,
.swap_buffers_with_damage = dri2_fallback_swap_buffers_with_damage, /* 
Android implements the function */
.swap_buffers_region = dri2_fallback_swap_buffers_region,
+   .swap_interval = droid_swap_interval,
 #if ANDROID_API_LEVEL >= 23
.set_damage_region = droid_set_damage_region,
 #else
@@ -1443,6 +1456,8 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 
dri2_setup_screen(dpy);
 
+   dri2_setup_swap_interval(dpy, 1);
+
if (!droid_add_configs_for_visuals(drv, dpy)) {
   err = "DRI2: failed to add configs";
   goto cleanup;
-- 
2.7.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 2/2] i965: Queue the buffer with a sync fence for Android OS v4.2

2017-07-24 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

v3: a) Save the last fence fd in DRI Context object.
b) Return the last fence if the batch buffer is empty and
   nothing to be flushed when _intel_batchbuffer_flush_fence
c) Add the new interface in vbtl to set the retrieve fence

v3.1 a) close fd in the new vbtl interface on none Android platform

v4: a) The last fence is saved in brw context.
b) The retrieve fd is for all the platform but not just Android
c) Add a uniform dri2 interface to initialize the surface.

v4.1: a) make some changes of variable name.
  b) the patch is breaked into two patches.

v4.2: a) Add a deinit interface for surface to clear the out fence

Change-Id: Ided54d2e193cde73a6f0feb36ac1c0056e4958f2
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c |   51 +++
 src/egl/drivers/dri2/egl_dri2.h |8 +
 src/egl/drivers/dri2/platform_android.c |   12 ---
 src/egl/drivers/dri2/platform_drm.c |3 +-
 src/egl/drivers/dri2/platform_surfaceless.c |3 +-
 src/egl/drivers/dri2/platform_wayland.c |3 +-
 src/egl/drivers/dri2/platform_x11.c |3 +-
 src/egl/drivers/dri2/platform_x11_dri3.c|3 +-
 8 files changed, 77 insertions(+), 9 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 020a0bc..ffd3a8a 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1307,6 +1307,32 @@ dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLContext *ctx)
return EGL_TRUE;
 }
 
+EGLBoolean
+dri2_surf_init(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
+_EGLConfig *conf, const EGLint *attrib_list)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   dri2_surf->out_fence_fd = -1;
+   return _eglInitSurface(surf, dpy, type, conf, attrib_list);
+}
+
+static void
+dri2_surface_set_out_fence( _EGLSurface *surf, int fence_fd)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   if (dri2_surf->out_fence_fd >=0)
+  close(dri2_surf->out_fence_fd);
+
+   dri2_surf->out_fence_fd = fence_fd;
+}
+
+void
+dri2_surf_deinit(_EGLSurface *surf)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   dri2_surface_set_out_fence(surf, -1);
+}
+
 static EGLBoolean
 dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
@@ -1318,6 +1344,22 @@ dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf)
return dri2_dpy->vtbl->destroy_surface(drv, dpy, surf);
 }
 
+static void
+dri2_surf_get_fence_fd(_EGLContext *ctx,
+   _EGLDisplay *dpy, _EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   int fence_fd = -1;
+   __DRIcontext *dri_ctx = dri2_egl_context(ctx)->dri_context;
+   void * fence = dri2_dpy->fence->create_fence_fd(dri_ctx, -1);
+   if (fence) {
+  fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+   fence);
+  dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+   }
+   dri2_surface_set_out_fence(surf, fence_fd);
+}
+
 /**
  * Called via eglMakeCurrent(), drv->API.MakeCurrent().
  */
@@ -1352,8 +1394,11 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *dsurf,
rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
 
+   int fence_fd = -1;
if (old_ctx) {
   __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+  if (old_dsurf)
+ dri2_surf_get_fence_fd(old_ctx, disp, old_dsurf);
   dri2_dpy->core->unbindContext(old_cctx);
}
 
@@ -1490,6 +1535,9 @@ static EGLBoolean
 dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   if (ctx && surf)
+  dri2_surf_get_fence_fd(ctx, dpy, surf);
return dri2_dpy->vtbl->swap_buffers(drv, dpy, surf);
 }
 
@@ -1499,6 +1547,9 @@ dri2_swap_buffers_with_damage(_EGLDriver *drv, 
_EGLDisplay *dpy,
   const EGLint *rects, EGLint n_rects)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   if (ctx && surf)
+  dri2_surf_get_fence_fd(ctx, dpy, surf);
return dri2_dpy->vtbl->swap_buffers_with_damage(drv, dpy, surf,
  

[Mesa-dev] [EGL android: accquire fence implementation 2/2] i965: Queue the buffer with a sync fence for Android OS v4.1

2017-07-20 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

v3: a) Save the last fence fd in DRI Context object.
b) Return the last fence if the batch buffer is empty and
   nothing to be flushed when _intel_batchbuffer_flush_fence
c) Add the new interface in vbtl to set the retrieve fence

v3.1 a) close fd in the new vbtl interface on none Android platform

v4: a) The last fence is saved in brw context.
b) The retrieve fd is for all the platform but not just Android
c) Add a uniform dri2 interface to initialize the surface.

v4.1: a) make some changes of variable name.
  b) the patch is breaked into two patches.

Change-Id: Ided54d2e193cde73a6f0feb36ac1c0056e4958f2
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c |   45 +++
 src/egl/drivers/dri2/egl_dri2.h |5 +++
 src/egl/drivers/dri2/platform_android.c |   11 ---
 src/egl/drivers/dri2/platform_drm.c |2 +-
 src/egl/drivers/dri2/platform_surfaceless.c |2 +-
 src/egl/drivers/dri2/platform_wayland.c |2 +-
 src/egl/drivers/dri2/platform_x11.c |2 +-
 src/egl/drivers/dri2/platform_x11_dri3.c|2 +-
 8 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 020a0bc..df4e934 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1307,6 +1307,25 @@ dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLContext *ctx)
return EGL_TRUE;
 }
 
+EGLBoolean
+dri2_surf_init(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
+_EGLConfig *conf, const EGLint *attrib_list)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   dri2_surf->out_fence_fd = -1;
+   return _eglInitSurface(surf, dpy, type, conf, attrib_list);
+}
+
+static void
+dri2_surface_set_retrieve_fence( _EGLSurface *surf, int fence_fd)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   if (dri2_surf->out_fence_fd >=0)
+  close(dri2_surf->out_fence_fd);
+
+   dri2_surf->out_fence_fd = fence_fd;
+}
+
 static EGLBoolean
 dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
@@ -1315,9 +1334,26 @@ dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf)
if (!_eglPutSurface(surf))
   return EGL_TRUE;
 
+   dri2_surface_set_retrieve_fence(surf, -1);
return dri2_dpy->vtbl->destroy_surface(drv, dpy, surf);
 }
 
+static void
+dri2_surf_get_fence_fd(_EGLContext *ctx,
+   _EGLDisplay *dpy, _EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   int fence_fd = -1;
+   __DRIcontext *dri_ctx = dri2_egl_context(ctx)->dri_context;
+   void * fence = dri2_dpy->fence->create_fence_fd(dri_ctx, -1);
+   if (fence) {
+  fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+   fence);
+  dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+   }
+   dri2_surface_set_retrieve_fence(surf, fence_fd);
+}
+
 /**
  * Called via eglMakeCurrent(), drv->API.MakeCurrent().
  */
@@ -1352,8 +1388,11 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *dsurf,
rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
 
+   int fence_fd = -1;
if (old_ctx) {
   __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+  if (old_dsurf)
+ dri2_surf_get_fence_fd(old_ctx, disp, old_dsurf);
   dri2_dpy->core->unbindContext(old_cctx);
}
 
@@ -1490,6 +1529,9 @@ static EGLBoolean
 dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   if (ctx && surf)
+  dri2_surf_get_fence_fd(ctx, dpy, surf);
return dri2_dpy->vtbl->swap_buffers(drv, dpy, surf);
 }
 
@@ -1499,6 +1541,9 @@ dri2_swap_buffers_with_damage(_EGLDriver *drv, 
_EGLDisplay *dpy,
   const EGLint *rects, EGLint n_rects)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   if (ctx && surf)
+  dri2_surf_get_fence_fd(ctx, dpy, surf);
return dri2_dpy->vtbl->swap_buffers_with_damage(drv, dpy, surf,
rects, n_rects);
 }
diff --git a/src/egl/drivers/dri2/egl_dri2.

[Mesa-dev] [EGL android: accquire fence implementation 1/2] i965: Return the last fence if the batch buffer is empty and nothing to be flushed when _intel_batchbuffer_flush_fence.

2017-07-20 Thread Zhongmin Wu
Always save the last fence in the brw context when flushing
buffer. If the buffer is nothing to be flushed, then return
the last fence when asked for.

Change-Id: Ic47035bcd1a27e402609afd9e2d1e3972548b97d
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.c   |5 +
 src/mesa/drivers/dri/i965/brw_context.h   |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   16 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..ed0b056 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1086,6 +1086,8 @@ brwCreateContext(gl_api api,
ctx->VertexProgram._MaintainTnlProgram = true;
ctx->FragmentProgram._MaintainTexEnvProgram = true;
 
+   brw->out_fence_fd = -1;
+
brw_draw_init( brw );
 
if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
@@ -1169,6 +1171,9 @@ intelDestroyContext(__DRIcontext * driContextPriv)
brw->throttle_batch[1] = NULL;
brw->throttle_batch[0] = NULL;
 
+   if (brw->out_fence_fd >= 0)
+  close(brw->out_fence_fd);
+
driDestroyOptionCache(>optionCache);
 
/* free the Mesa context */
diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..692ea2c 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1217,6 +1217,7 @@ struct brw_context
 
__DRIcontext *driContext;
struct intel_screen *screen;
+   int out_fence_fd;
 };
 
 /* brw_clear.c */
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c 
b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 62d2fe8..d342e5d 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -648,9 +648,18 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, 
int *out_fence_fd)
  /* Add the batch itself to the end of the validation list */
  add_exec_bo(batch, batch->bo);
 
+ if (brw->out_fence_fd >= 0) {
+close(brw->out_fence_fd);
+brw->out_fence_fd = -1;
+ }
+
+ int fd = -1;
  ret = execbuffer(dri_screen->fd, batch, hw_ctx,
   4 * USED_BATCH(*batch),
-  in_fence_fd, out_fence_fd, flags);
+  in_fence_fd, , flags);
+ brw->out_fence_fd = fd;
+ if (out_fence_fd)
+*out_fence_fd = (fd >=0) ? dup(fd) : -1;
   }
 
   throttle(brw);
@@ -684,8 +693,11 @@ _intel_batchbuffer_flush_fence(struct brw_context *brw,
 {
int ret;
 
-   if (USED_BATCH(brw->batch) == 0)
+   if (USED_BATCH(brw->batch) == 0) {
+  if (out_fence_fd && brw->out_fence_fd >= 0)
+ *out_fence_fd = dup(brw->out_fence_fd);
   return 0;
+   }
 
if (brw->throttle_batch[0] == NULL) {
   brw->throttle_batch[0] = brw->batch.bo;
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [EGL android: accquire fence implementation 1/2] i965: Return the last fence if the batch buffer is empty and nothing to be flushed when _intel_batchbuffer_flush_fence.

2017-07-20 Thread Zhongmin Wu
Always save the last fence in the brw context when flushing
buffer. If the buffer is nothing to be flushed, then return
the last fence when asked for.

Change-Id: Ic47035bcd1a27e402609afd9e2d1e3972548b97d
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
---
 src/mesa/drivers/dri/i965/brw_context.c   |5 +
 src/mesa/drivers/dri/i965/brw_context.h   |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   16 ++--
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..ed0b056 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1086,6 +1086,8 @@ brwCreateContext(gl_api api,
ctx->VertexProgram._MaintainTnlProgram = true;
ctx->FragmentProgram._MaintainTexEnvProgram = true;
 
+   brw->out_fence_fd = -1;
+
brw_draw_init( brw );
 
if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
@@ -1169,6 +1171,9 @@ intelDestroyContext(__DRIcontext * driContextPriv)
brw->throttle_batch[1] = NULL;
brw->throttle_batch[0] = NULL;
 
+   if (brw->out_fence_fd >= 0)
+  close(brw->out_fence_fd);
+
driDestroyOptionCache(>optionCache);
 
/* free the Mesa context */
diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..692ea2c 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1217,6 +1217,7 @@ struct brw_context
 
__DRIcontext *driContext;
struct intel_screen *screen;
+   int out_fence_fd;
 };
 
 /* brw_clear.c */
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c 
b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 62d2fe8..d342e5d 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -648,9 +648,18 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, 
int *out_fence_fd)
  /* Add the batch itself to the end of the validation list */
  add_exec_bo(batch, batch->bo);
 
+ if (brw->out_fence_fd >= 0) {
+close(brw->out_fence_fd);
+brw->out_fence_fd = -1;
+ }
+
+ int fd = -1;
  ret = execbuffer(dri_screen->fd, batch, hw_ctx,
   4 * USED_BATCH(*batch),
-  in_fence_fd, out_fence_fd, flags);
+  in_fence_fd, , flags);
+ brw->out_fence_fd = fd;
+ if (out_fence_fd)
+*out_fence_fd = (fd >=0) ? dup(fd) : -1;
   }
 
   throttle(brw);
@@ -684,8 +693,11 @@ _intel_batchbuffer_flush_fence(struct brw_context *brw,
 {
int ret;
 
-   if (USED_BATCH(brw->batch) == 0)
+   if (USED_BATCH(brw->batch) == 0) {
+  if (out_fence_fd && brw->out_fence_fd >= 0)
+ *out_fence_fd = dup(brw->out_fence_fd);
   return 0;
+   }
 
if (brw->throttle_batch[0] == NULL) {
   brw->throttle_batch[0] = brw->batch.bo;
-- 
1.7.9.5

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS (v4)

2017-07-20 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

v3: a) Save the last fence fd in DRI Context object.
b) Return the last fence if the batch buffer is empty and
   nothing to be flushed when _intel_batchbuffer_flush_fence
c) Add the new interface in vbtl to set the retrieve fence
   in the egl surface. This is just for cancelBuffer.
d) For queueBuffer, the fence is get with DRI fence interface.
   For cancelBuffer, the fence is get before the context is
   reset, and the fence is then  moved to its surface.
v3.1 a) close fd in the new vbtl interface on none Android platform

v4: a) The last fence is saved in brw context.
b) The retrieve fd is for all the platform but not just Android
c) Add a uniform dri2 interface to initialize the surface.

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c   |   47 +
 src/egl/drivers/dri2/egl_dri2.h   |5 +++
 src/egl/drivers/dri2/platform_android.c   |   11 +++---
 src/egl/drivers/dri2/platform_drm.c   |2 +-
 src/egl/drivers/dri2/platform_surfaceless.c   |2 +-
 src/egl/drivers/dri2/platform_wayland.c   |2 +-
 src/egl/drivers/dri2/platform_x11.c   |2 +-
 src/egl/drivers/dri2/platform_x11_dri3.c  |2 +-
 src/mesa/drivers/dri/i965/brw_context.c   |5 +++
 src/mesa/drivers/dri/i965/brw_context.h   |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   17 +++--
 11 files changed, 85 insertions(+), 11 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 020a0bc..94ad360 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1307,6 +1307,26 @@ dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLContext *ctx)
return EGL_TRUE;
 }
 
+EGLBoolean
+dri2_surf_init(_EGLSurface *surf, _EGLDisplay *dpy, EGLint type,
+_EGLConfig *conf, const EGLint *attrib_list)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   dri2_surf->retrieve_fd = -1;
+   return _eglInitSurface(surf, dpy, type, conf, attrib_list);
+}
+
+void
+dri2_surface_set_retrieve_fence( _EGLSurface *surf, int fence_fd)
+{
+   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+   if (dri2_surf->retrieve_fd >=0)
+  close(dri2_surf->retrieve_fd);
+
+   dri2_surf->retrieve_fd = fence_fd;
+   return;
+}
+
 static EGLBoolean
 dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
@@ -1315,9 +1335,26 @@ dri2_destroy_surface(_EGLDriver *drv, _EGLDisplay *dpy, 
_EGLSurface *surf)
if (!_eglPutSurface(surf))
   return EGL_TRUE;
 
+   dri2_surface_set_retrieve_fence(surf, -1);
return dri2_dpy->vtbl->destroy_surface(drv, dpy, surf);
 }
 
+static void
+dri2_surf_get_fence_fd(_EGLContext *ctx,
+   _EGLDisplay *dpy, _EGLSurface *surf)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   int fence_fd = -1;
+   __DRIcontext *dri_ctx = dri2_egl_context(ctx)->dri_context;
+   void * fence = dri2_dpy->fence->create_fence_fd(dri_ctx, -1);
+   if (fence) {
+  fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+   fence);
+  dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+   }
+   dri2_surface_set_retrieve_fence(surf, fence_fd);
+}
+
 /**
  * Called via eglMakeCurrent(), drv->API.MakeCurrent().
  */
@@ -1352,8 +1389,12 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *dsurf,
rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
 
+   int fence_fd = -1;
if (old_ctx) {
   __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+  if (old_dsurf) {
+ dri2_surf_get_fence_fd(old_ctx, disp, old_dsurf);
+  }
   dri2_dpy->core->unbindContext(old_cctx);
}
 
@@ -1490,6 +1531,9 @@ static EGLBoolean
 dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 {
struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   _EGLContext *ctx = _eglGetCurrentContext();
+   if (ctx && surf)
+  dri2_surf_get_fence_fd(ct

[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS (v3.1)

2017-07-18 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

v3: a) Save the last fence fd in DRI Context object.
b) Return the last fence if the batch buffer is empty and
   nothing to be flushed when _intel_batchbuffer_flush_fence
c) Add the new interface in vbtl to set the retrieve fence
   in the egl surface. This is just for cancelBuffer.
d) For queueBuffer, the fence is get with DRI fence interface.
   For cancelBuffer, the fence is get before the context is
   reset, and the fence is then  moved to its surface.
v3.1 a) close fd in the new vbtl interface on none Android platform

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c   |   17 +-
 src/egl/drivers/dri2/egl_dri2.h   |3 +++
 src/egl/drivers/dri2/platform_android.c   |   30 ++---
 src/egl/drivers/dri2/platform_drm.c   |1 +
 src/egl/drivers/dri2/platform_surfaceless.c   |1 +
 src/egl/drivers/dri2/platform_wayland.c   |2 ++
 src/egl/drivers/dri2/platform_x11.c   |2 ++
 src/egl/drivers/dri2/platform_x11_dri3.c  |1 +
 src/mesa/drivers/dri/common/dri_util.c|3 +++
 src/mesa/drivers/dri/common/dri_util.h|2 ++
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   25 ++---
 11 files changed, 80 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 020a0bc..19d346d 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1351,9 +1351,17 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *dsurf,
ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL;
rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
-
+   int fence_fd = -1;
if (old_ctx) {
   __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+  if (old_dsurf) {
+ void * fence = dri2_dpy->fence->create_fence_fd(old_cctx, -1);
+ if (fence) {
+fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen, 
fence);
+dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+ }
+ dri2_dpy->vtbl->set_retrieve_fence(old_dsurf, fence_fd);
+  }
   dri2_dpy->core->unbindContext(old_cctx);
}
 
@@ -1403,6 +1411,13 @@ dri2_surface_get_dri_drawable(_EGLSurface *surf)
return dri2_surf->dri_drawable;
 }
 
+void
+dri2_set_retrieve_fence(_EGLSurface *surf, int fd)
+{
+   close(fd);
+   return;
+}
+
 /*
  * Called from eglGetProcAddress() via drv->API.GetProcAddress().
  */
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index bbba7c0..b097345 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -150,6 +150,8 @@ struct dri2_egl_display_vtbl {
  EGLuint64KHR *sbc);
 
__DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
+
+   void (*set_retrieve_fence)(_EGLSurface *surf, int fd);
 };
 
 struct dri2_egl_display
@@ -314,6 +316,7 @@ struct dri2_egl_surface
   struct ANativeWindowBuffer *buffer;
   int age;
} color_buffers[3], *back;
+   int retrieve_fd;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index cc2e4a6..b8d53b8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -306,9 +306,16 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 *is responsible for closing it.
 */
int fence_fd = -1;
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   void * fence = dri2_dpy->fence->create_fence_fd(dri2_ctx->dri_context, -1);
+   if (fence) {
+  fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+   fence);
+  dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+   }
dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,

[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS (v3)

2017-07-18 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

v3: a) Save the last fence fd in DRI Context object.
b) Return the last fence if the batch buffer is empty and
   nothing to be flushed when _intel_batchbuffer_flush_fence
c) Add the new interface in vbtl to set the retrieve fence
   in the egl surface. This is just for cancelBuffer.
d) For queueBuffer, the fence is get with DRI fence interface.
   For cancelBuffer, the fence is get before the context is
   reset, and the fence is then  moved to its surface.

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 src/egl/drivers/dri2/egl_dri2.c   |   16 -
 src/egl/drivers/dri2/egl_dri2.h   |3 +++
 src/egl/drivers/dri2/platform_android.c   |   30 ++---
 src/egl/drivers/dri2/platform_drm.c   |1 +
 src/egl/drivers/dri2/platform_surfaceless.c   |1 +
 src/egl/drivers/dri2/platform_wayland.c   |2 ++
 src/egl/drivers/dri2/platform_x11.c   |2 ++
 src/egl/drivers/dri2/platform_x11_dri3.c  |1 +
 src/mesa/drivers/dri/common/dri_util.c|3 +++
 src/mesa/drivers/dri/common/dri_util.h|2 ++
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   25 ++---
 11 files changed, 79 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 020a0bc..4c96c08 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1351,9 +1351,17 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *dsurf,
ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL;
rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL;
cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL;
-
+   int fence_fd = -1;
if (old_ctx) {
   __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+  if (old_dsurf) {
+ void * fence = dri2_dpy->fence->create_fence_fd(old_cctx, -1);
+ if (fence) {
+fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen, 
fence);
+dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+ }
+ dri2_dpy->vtbl->set_retrieve_fence(old_dsurf, fence_fd);
+  }
   dri2_dpy->core->unbindContext(old_cctx);
}
 
@@ -1403,6 +1411,12 @@ dri2_surface_get_dri_drawable(_EGLSurface *surf)
return dri2_surf->dri_drawable;
 }
 
+void
+dri2_set_retrieve_fence(_EGLSurface *surf, int fd)
+{
+   return;
+}
+
 /*
  * Called from eglGetProcAddress() via drv->API.GetProcAddress().
  */
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index bbba7c0..b097345 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -150,6 +150,8 @@ struct dri2_egl_display_vtbl {
  EGLuint64KHR *sbc);
 
__DRIdrawable *(*get_dri_drawable)(_EGLSurface *surf);
+
+   void (*set_retrieve_fence)(_EGLSurface *surf, int fd);
 };
 
 struct dri2_egl_display
@@ -314,6 +316,7 @@ struct dri2_egl_surface
   struct ANativeWindowBuffer *buffer;
   int age;
} color_buffers[3], *back;
+   int retrieve_fd;
 #endif
 
 #if defined(HAVE_SURFACELESS_PLATFORM)
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index cc2e4a6..b8d53b8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -306,9 +306,16 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 *is responsible for closing it.
 */
int fence_fd = -1;
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   void * fence = dri2_dpy->fence->create_fence_fd(dri2_ctx->dri_context, -1);
+   if (fence) {
+  fence_fd = dri2_dpy->fence->get_fence_fd(dri2_dpy->dri_screen,
+   fence);
+  dri2_dpy->fence->destroy_fence(dri2_dpy->dri_screen, fence);
+   }
dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
   fence_fd);
-
dri2_surf->buffer->common.decRef(_surf->buffer->commo

[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS (v2)

2017-07-14 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

v2: a) Also implement the fence in cancelBuffer.
b) The last sync fence is stored in drawable object
   rather than brw context.
c) format clear.

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 include/GL/internal/dri_interface.h   |9 +
 src/egl/drivers/dri2/platform_android.c   |   20 +---
 src/mesa/drivers/dri/common/dri_util.c|3 +++
 src/mesa/drivers/dri/common/dri_util.h|2 ++
 src/mesa/drivers/dri/i915/intel_screen.c  |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   18 +-
 src/mesa/drivers/dri/i965/intel_screen.c  |6 ++
 src/mesa/drivers/dri/nouveau/nouveau_screen.c |1 +
 src/mesa/drivers/dri/radeon/radeon_screen.c   |1 +
 9 files changed, 53 insertions(+), 8 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bb..7c6b08b 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -287,6 +287,15 @@ struct __DRI2flushExtensionRec {
 void (*flush)(__DRIdrawable *drawable);
 
 /**
+* This function enables retrieving fence during enqueue / cancel buffer 
operations
+*
+* \param drawable the drawable to invalidate
+*
+* \since 3
+*/
+int (*get_retrieve_fd)(__DRIdrawable *drawable);
+
+/**
  * Ask the driver to call getBuffers/getBuffersWithFormat before
  * it starts rendering again.
  *
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index cc2e4a6..aa99ed3 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -305,10 +305,11 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 *is passed to queueBuffer, and the ANativeWindow implementation
 *is responsible for closing it.
 */
-   int fence_fd = -1;
+   int fd = -1;
+   if (dri2_dpy->flush->get_retrieve_fd)
+  fd = dri2_dpy->flush->get_retrieve_fd(dri2_surf->dri_drawable);
dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
-  fence_fd);
-
+  fd);
dri2_surf->buffer->common.decRef(_surf->buffer->common);
dri2_surf->buffer = NULL;
dri2_surf->back = NULL;
@@ -324,11 +325,16 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 }
 
 static void
-droid_window_cancel_buffer(struct dri2_egl_surface *dri2_surf)
+droid_window_cancel_buffer(_EGLDisplay *disp,
+   struct dri2_egl_surface *dri2_surf)
 {
int ret;
-
-   ret = dri2_surf->window->cancelBuffer(dri2_surf->window, dri2_surf->buffer, 
-1);
+   int fd = -1;
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (dri2_dpy->flush->get_retrieve_fd)
+  fd = dri2_dpy->flush->get_retrieve_fd(dri2_surf->dri_drawable);
+   ret = dri2_surf->window->cancelBuffer(dri2_surf->window,
+ dri2_surf->buffer, fd);
if (ret < 0) {
   _eglLog(_EGL_WARNING, "ANativeWindow::cancelBuffer failed");
   dri2_surf->base.Lost = EGL_TRUE;
@@ -469,7 +475,7 @@ droid_destroy_surface(_EGLDriver *drv, _EGLDisplay *disp, 
_EGLSurface *surf)
 
if (dri2_surf->base.Type == EGL_WINDOW_BIT) {
   if (dri2_surf->buffer)
- droid_window_cancel_buffer(dri2_surf);
+ droid_window_cancel_buffer(disp, dri2_surf);
 
   dri2_surf->window->common.decRef(_surf->window->common);
}
diff --git a/src/mesa/drivers/dri/common/dri_util.c 
b/src/mesa/drivers/dri/common/dri_util.c
index f6df488..21ee6aa 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -636,6 +636,8 @@ static void dri_put_drawable(__DRIdrawable *pdp)
return;
 
pdp->driScreenPriv->driver->DestroyBuffer(pdp);
+if (pdp->retrieve_fd != -1)
+   close(pdp->retrieve_fd);
free(pdp);
 }
 }
@@ -661,6 +663,7 @@ driCreateNewDrawable(__DRIscreen *screen,
 pdraw->lastStamp = 0;
 pdraw->w = 0;
 pdraw->h = 0;
+pdraw->retrieve_fd = -1;
 
 dri_get_drawable(pdraw);
 
diff --git a/src/mesa/drivers/dri/common/dri_util.h 
b/src/mesa/drivers/dri/common/dri_util.h

[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS

2017-07-09 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 include/GL/internal/dri_interface.h   |2 ++
 src/egl/drivers/dri2/platform_android.c   |   10 +++---
 src/mesa/drivers/dri/i965/brw_context.c   |7 ++-
 src/mesa/drivers/dri/i965/brw_context.h   |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   15 ++-
 src/mesa/drivers/dri/i965/intel_screen.c  |7 +++
 6 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bb..8760aec 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -316,6 +316,8 @@ struct __DRI2flushExtensionRec {
  __DRIdrawable *drawable,
  unsigned flags,
  enum __DRI2throttleReason throttle_reason);
+
+int (*get_retrive_fd)(__DRIcontext *ctx);
 };
 
 
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index bfa20f8..844bb8d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -289,10 +289,14 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 *is passed to queueBuffer, and the ANativeWindow implementation
 *is responsible for closing it.
 */
-   int fence_fd = -1;
-   dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
-  fence_fd);
 
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+   int fd = -1;
+   fd = dri2_dpy->flush->get_retrive_fd(dri2_ctx->dri_context);
+   dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
+  fd);
dri2_surf->buffer->common.decRef(_surf->buffer->common);
dri2_surf->buffer = NULL;
dri2_surf->back = NULL;
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..f74ae91 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -940,6 +940,7 @@ brwCreateContext(gl_api api,
brw->screen = screen;
brw->bufmgr = screen->bufmgr;
 
+   brw->retrive_fd = -1;
brw->gen = devinfo->gen;
brw->gt = devinfo->gt;
brw->is_g4x = devinfo->is_g4x;
@@ -1176,8 +1177,12 @@ intelDestroyContext(__DRIcontext * driContextPriv)
 
ralloc_free(brw);
driContextPriv->driverPrivate = NULL;
-}
 
+   if(brw->retrive_fd != -1) {
+   close(brw->retrive_fd);
+   brw->retrive_fd = -1;
+   }
+}
 GLboolean
 intelUnbindContext(__DRIcontext * driContextPriv)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..8f277c3 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1217,6 +1217,7 @@ struct brw_context
 
__DRIcontext *driContext;
struct intel_screen *screen;
+   int retrive_fd;
 };
 
 /* brw_clear.c */
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c 
b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 62d2fe8..31515b2 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -648,9 +648,22 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, 
int *out_fence_fd)
  /* Add the batch itself to the end of the validation list */
  add_exec_bo(batch, batch->bo);
 
+ if(brw->retrive_fd != -1) {
+ close(brw->retrive_fd);
+ brw->retrive_fd = -1;
+ }
+
+ int fd = -1;
  ret = execbuffer(dri_screen->fd, batch, hw_ctx,
   4 * USED_BATCH(*batch),
-  in_fence_fd, out_fence_fd, flags);
+  in_fence_fd, , flags);
+
+ if(out_fence_fd != NULL) {
+ *out_fence_fd = fd;
+ brw->retrive_fd = dup(fd);
+ } else {
+ brw->retrive_fd = fd;
+ }
   }
 
   throttle(brw);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 7d320c0..2fd557b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/i

[Mesa-dev] [EGL android: accquire fence implementation] i965: Queue the buffer with a sync fence for Android OS

2017-07-07 Thread Zhongmin Wu
Before we queued the buffer with a invalid fence (-1), it will
make some benchmarks failed to test such as flatland.

Now we get the out fence during the flushing buffer and then pass
it to SurfaceFlinger in eglSwapbuffer function.

Change-Id: Ic0773c19788d612a98d1402f5b5619dab64c1bc2
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-43936
Reported-On: https://bugs.freedesktop.org/show_bug.cgi?id=101655
Signed-off-by: Zhongmin Wu <zhongmin...@intel.com>
Reported-by: Li, Guangli <guangli...@intel.com>
Tested-by: Marathe, Yogesh <yogesh.mara...@intel.com>
---
 include/GL/internal/dri_interface.h   |2 ++
 src/egl/drivers/dri2/platform_android.c   |   10 +++---
 src/mesa/drivers/dri/i965/brw_context.c   |7 ++-
 src/mesa/drivers/dri/i965/brw_context.h   |1 +
 src/mesa/drivers/dri/i965/intel_batchbuffer.c |   15 ++-
 src/mesa/drivers/dri/i965/intel_screen.c  |7 +++
 6 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index fc2d4bb..8760aec 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -316,6 +316,8 @@ struct __DRI2flushExtensionRec {
  __DRIdrawable *drawable,
  unsigned flags,
  enum __DRI2throttleReason throttle_reason);
+
+int (*get_retrive_fd)(__DRIcontext *ctx);
 };
 
 
diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index bfa20f8..844bb8d 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -289,10 +289,14 @@ droid_window_enqueue_buffer(_EGLDisplay *disp, struct 
dri2_egl_surface *dri2_sur
 *is passed to queueBuffer, and the ANativeWindow implementation
 *is responsible for closing it.
 */
-   int fence_fd = -1;
-   dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
-  fence_fd);
 
+   _EGLContext *ctx = _eglGetCurrentContext();
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+   int fd = -1;
+   fd = dri2_dpy->flush->get_retrive_fd(dri2_ctx->dri_context);
+   dri2_surf->window->queueBuffer(dri2_surf->window, dri2_surf->buffer,
+  fd);
dri2_surf->buffer->common.decRef(_surf->buffer->common);
dri2_surf->buffer = NULL;
dri2_surf->back = NULL;
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 5433f90..f74ae91 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -940,6 +940,7 @@ brwCreateContext(gl_api api,
brw->screen = screen;
brw->bufmgr = screen->bufmgr;
 
+   brw->retrive_fd = -1;
brw->gen = devinfo->gen;
brw->gt = devinfo->gt;
brw->is_g4x = devinfo->is_g4x;
@@ -1176,8 +1177,12 @@ intelDestroyContext(__DRIcontext * driContextPriv)
 
ralloc_free(brw);
driContextPriv->driverPrivate = NULL;
-}
 
+   if(brw->retrive_fd != -1) {
+   close(brw->retrive_fd);
+   brw->retrive_fd = -1;
+   }
+}
 GLboolean
 intelUnbindContext(__DRIcontext * driContextPriv)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_context.h 
b/src/mesa/drivers/dri/i965/brw_context.h
index dc4bc8f..8f277c3 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1217,6 +1217,7 @@ struct brw_context
 
__DRIcontext *driContext;
struct intel_screen *screen;
+   int retrive_fd;
 };
 
 /* brw_clear.c */
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c 
b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index 62d2fe8..31515b2 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -648,9 +648,22 @@ do_flush_locked(struct brw_context *brw, int in_fence_fd, 
int *out_fence_fd)
  /* Add the batch itself to the end of the validation list */
  add_exec_bo(batch, batch->bo);
 
+ if(brw->retrive_fd != -1) {
+ close(brw->retrive_fd);
+ brw->retrive_fd = -1;
+ }
+
+ int fd = -1;
  ret = execbuffer(dri_screen->fd, batch, hw_ctx,
   4 * USED_BATCH(*batch),
-  in_fence_fd, out_fence_fd, flags);
+  in_fence_fd, , flags);
+
+ if(out_fence_fd != NULL) {
+ *out_fence_fd = fd;
+ brw->retrive_fd = dup(fd);
+ } else {
+ brw->retrive_fd = fd;
+ }
   }
 
   throttle(brw);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 7d320c0..2fd557b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/i