Re: [Mesa-dev] [PATCH 5/6][RFC] Gallium/dri2: implement blitImage

2014-01-06 Thread Marek Olšák
On Sun, Jan 5, 2014 at 10:26 PM, Axel Davy axel.d...@ens.fr wrote:
 Signed-off-by: Axel Davy axel.d...@ens.fr
 ---
  src/gallium/state_trackers/dri/drm/dri2.c | 49 
 +--
  1 file changed, 47 insertions(+), 2 deletions(-)

 diff --git a/src/gallium/state_trackers/dri/drm/dri2.c 
 b/src/gallium/state_trackers/dri/drm/dri2.c
 index 2a5b7b4..89d9040 100644
 --- a/src/gallium/state_trackers/dri/drm/dri2.c
 +++ b/src/gallium/state_trackers/dri/drm/dri2.c
 @@ -985,6 +985,49 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
 height, int fourcc,
  }

  static void
 +dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
 +int dstx0, int dsty0, int dstwidth, int dstheight,
 +int srcx0, int srcy0, int srcwidth, int srcheight,
 +int flags)
 +{
 +   struct dri_context *ctx = dri_context(context);
 +   struct pipe_context *pipe = ctx-st-pipe;
 +   struct pipe_screen* screen = dri_screen(ctx-sPriv)-base.screen;
 +   struct pipe_fence_handle *fence;
 +   struct pipe_blit_info blit;
 +
 +   if (!dst || !src)
 +  return;
 +
 +   memset(blit, 0, sizeof(blit));
 +   blit.dst.resource = dst-texture;
 +   blit.dst.box.x = dstx0;
 +   blit.dst.box.y = dsty0;
 +   blit.dst.box.width = dstwidth;
 +   blit.dst.box.height = dstheight;
 +   blit.dst.box.depth = 1;
 +   blit.dst.format = dst-texture-format;
 +   blit.src.resource = src-texture;
 +   blit.src.box.x = srcx0;
 +   blit.src.box.y = srcy0;
 +   blit.src.box.width = srcwidth;
 +   blit.src.box.height = srcheight;
 +   blit.src.box.depth = 1;
 +   blit.src.format = src-texture-format;
 +   blit.mask = PIPE_MASK_RGBA;
 +   blit.filter = PIPE_TEX_FILTER_NEAREST;
 +
 +   pipe-blit(pipe, blit);
 +
 +   pipe-flush_resource(pipe, dst-texture);
 +
 +   ctx-st-flush(ctx-st, 0, fence);
 +
 +   if (flags  __BLIT_FLAG_FINISH)
 +  (void) screen-fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
 +   screen-fence_reference(screen, fence, NULL);

Fences might not be implemented by some drivers. I recommend setting
the fence pointer to NULL, then calling flush and then checking if
it's not NULL. Also, getting a fence incurs some overhead, so if
__BLIT_FLAG_FINISH is not set, the last parameter of st-flush should
be NULL.

Who can call this function? The X server?

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


Re: [Mesa-dev] [PATCH 5/6][RFC] Gallium/dri2: implement blitImage

2014-01-06 Thread Axel Davy

On 06/01/2014, Marek Olšák wrote :

On Sun, Jan 5, 2014 at 10:26 PM, Axel Davy axel.d...@ens.fr wrote:

Signed-off-by: Axel Davy axel.d...@ens.fr
---
  src/gallium/state_trackers/dri/drm/dri2.c | 49 +--
  1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/dri/drm/dri2.c 
b/src/gallium/state_trackers/dri/drm/dri2.c
index 2a5b7b4..89d9040 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -985,6 +985,49 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
  }

  static void
+dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
+int dstx0, int dsty0, int dstwidth, int dstheight,
+int srcx0, int srcy0, int srcwidth, int srcheight,
+int flags)
+{
+   struct dri_context *ctx = dri_context(context);
+   struct pipe_context *pipe = ctx-st-pipe;
+   struct pipe_screen* screen = dri_screen(ctx-sPriv)-base.screen;
+   struct pipe_fence_handle *fence;
+   struct pipe_blit_info blit;
+
+   if (!dst || !src)
+  return;
+
+   memset(blit, 0, sizeof(blit));
+   blit.dst.resource = dst-texture;
+   blit.dst.box.x = dstx0;
+   blit.dst.box.y = dsty0;
+   blit.dst.box.width = dstwidth;
+   blit.dst.box.height = dstheight;
+   blit.dst.box.depth = 1;
+   blit.dst.format = dst-texture-format;
+   blit.src.resource = src-texture;
+   blit.src.box.x = srcx0;
+   blit.src.box.y = srcy0;
+   blit.src.box.width = srcwidth;
+   blit.src.box.height = srcheight;
+   blit.src.box.depth = 1;
+   blit.src.format = src-texture-format;
+   blit.mask = PIPE_MASK_RGBA;
+   blit.filter = PIPE_TEX_FILTER_NEAREST;
+
+   pipe-blit(pipe, blit);
+
+   pipe-flush_resource(pipe, dst-texture);
+
+   ctx-st-flush(ctx-st, 0, fence);
+
+   if (flags  __BLIT_FLAG_FINISH)
+  (void) screen-fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
+   screen-fence_reference(screen, fence, NULL);

Fences might not be implemented by some drivers. I recommend setting
the fence pointer to NULL, then calling flush and then checking if
it's not NULL. Also, getting a fence incurs some overhead, so if
__BLIT_FLAG_FINISH is not set, the last parameter of st-flush should
be NULL.

Who can call this function? The X server?

Marek


Thanks for the comment.

the __BLIT_FLAG_FINISH flag is to glFinish before exporting the buffer 
when rendering on a different card than the compositor. This use case 
will disappear with dma-buf fences.
I'm hesitating to remove this flag, and bet that dma-buf fences will 
land soon.


The blitImage function would be called for Wayland when on a different 
device than the Wayland compositor,

but it can be used fro X dri3 too (when on the dedicated device).
The work done for prime support for Wayland can be taken for X dri3.

About the flush done in the function: do you think it is ok to flush 
here, or that it sould be optional to flush?


Axel Davy
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 5/6][RFC] Gallium/dri2: implement blitImage

2014-01-06 Thread Michel Dänzer
On Mon, 2014-01-06 at 12:50 +0100, Marek Olšák wrote:
 
 Fences might not be implemented by some drivers. I recommend setting
 the fence pointer to NULL, then calling flush and then checking if
 it's not NULL.

That's not necessary, Gallium drivers have to implement the fence
interfaces.


-- 
Earthling Michel Dänzer|  http://www.amd.com
Libre software enthusiast  |Mesa and X developer

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


[Mesa-dev] [PATCH 5/6][RFC] Gallium/dri2: implement blitImage

2014-01-05 Thread Axel Davy
Signed-off-by: Axel Davy axel.d...@ens.fr
---
 src/gallium/state_trackers/dri/drm/dri2.c | 49 +--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/src/gallium/state_trackers/dri/drm/dri2.c 
b/src/gallium/state_trackers/dri/drm/dri2.c
index 2a5b7b4..89d9040 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -985,6 +985,49 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
 }
 
 static void
+dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
+int dstx0, int dsty0, int dstwidth, int dstheight,
+int srcx0, int srcy0, int srcwidth, int srcheight,
+int flags)
+{
+   struct dri_context *ctx = dri_context(context);
+   struct pipe_context *pipe = ctx-st-pipe;
+   struct pipe_screen* screen = dri_screen(ctx-sPriv)-base.screen;
+   struct pipe_fence_handle *fence;
+   struct pipe_blit_info blit;
+
+   if (!dst || !src)
+  return;
+
+   memset(blit, 0, sizeof(blit));
+   blit.dst.resource = dst-texture;
+   blit.dst.box.x = dstx0;
+   blit.dst.box.y = dsty0;
+   blit.dst.box.width = dstwidth;
+   blit.dst.box.height = dstheight;
+   blit.dst.box.depth = 1;
+   blit.dst.format = dst-texture-format;
+   blit.src.resource = src-texture;
+   blit.src.box.x = srcx0;
+   blit.src.box.y = srcy0;
+   blit.src.box.width = srcwidth;
+   blit.src.box.height = srcheight;
+   blit.src.box.depth = 1;
+   blit.src.format = src-texture-format;
+   blit.mask = PIPE_MASK_RGBA;
+   blit.filter = PIPE_TEX_FILTER_NEAREST;
+
+   pipe-blit(pipe, blit);
+
+   pipe-flush_resource(pipe, dst-texture);
+
+   ctx-st-flush(ctx-st, 0, fence);
+
+   if (flags  __BLIT_FLAG_FINISH)
+  (void) screen-fence_finish(screen, fence, PIPE_TIMEOUT_INFINITE);
+   screen-fence_reference(screen, fence, NULL);
+}
+static void
 dri2_destroy_image(__DRIimage *img)
 {
pipe_resource_reference(img-texture, NULL);
@@ -992,7 +1035,7 @@ dri2_destroy_image(__DRIimage *img)
 }
 
 static struct __DRIimageExtensionRec dri2ImageExtension = {
-{ __DRI_IMAGE, 6 },
+{ __DRI_IMAGE, 9 },
 dri2_create_image_from_name,
 dri2_create_image_from_renderbuffer,
 dri2_destroy_image,
@@ -1003,6 +1046,9 @@ static struct __DRIimageExtensionRec dri2ImageExtension = 
{
 dri2_from_names,
 dri2_from_planar,
 dri2_create_from_texture,
+NULL,
+NULL,
+dri2_blit_image
 };
 
 /*
@@ -1059,7 +1105,6 @@ dri2_init_screen(__DRIscreen * sPriv)
   if (drmGetCap(sPriv-fd, DRM_CAP_PRIME, cap) == 0 
   (cap  DRM_PRIME_CAP_IMPORT)) {
 
- dri2ImageExtension.base.version = 7;
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
   }
}
-- 
1.8.3.2

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