Re: [Mesa-dev] [PATCH] st/dri: Add support for PIPE_FORMAT_RGBX8888_UNORM

2017-06-19 Thread Varad Gautam
On Mon, Jun 19, 2017 at 11:21 PM, Lepton Wu <lep...@google.com> wrote:
> The original dri2_format_to_pipe_format function just misses case branch
> for __DRI_IMAGE_FORMAT_XBGR. I discovered this when debugging one google
> map crash inside emulator.
>
> Signed-off-by: Lepton Wu <lep...@chromium.org>
> ---
>  src/gallium/state_trackers/dri/dri2.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/gallium/state_trackers/dri/dri2.c 
> b/src/gallium/state_trackers/dri/dri2.c
> index c5e69d639b..f02ef30dd7 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -186,6 +186,9 @@ static enum pipe_format dri2_format_to_pipe_format (int 
> format)
> case __DRI_IMAGE_FORMAT_ARGB:
>pf = PIPE_FORMAT_BGRA_UNORM;
>break;
> +   case __DRI_IMAGE_FORMAT_XBGR:
> +  pf = PIPE_FORMAT_RGBX_UNORM;
> +  break;
> case __DRI_IMAGE_FORMAT_ABGR8888:
>pf = PIPE_FORMAT_RGBA_UNORM;
>break;

Reviewed-by: Varad Gautam <varadgau...@gmail.com>

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


[Mesa-dev] [PATCH v2] i965: Add tiling mode to BO import

2017-06-06 Thread Varad Gautam
From: Daniel Stone <dani...@collabora.com>

When importing a dmabuf, verify that the tiling mode matches what was
expected.

v2: rebase to 'i965: Improve same-buffer restriction for imports' v2.

Signed-off-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varadgau...@gmail.com>
---
 src/mesa/drivers/dri/i965/brw_bufmgr.c   | 12 ++--
 src/mesa/drivers/dri/i965/brw_bufmgr.h   |  3 ++-
 src/mesa/drivers/dri/i965/intel_screen.c |  5 +++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c 
b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 2f17934..56cf979 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -1014,7 +1014,7 @@ brw_bo_get_tiling(struct brw_bo *bo, uint32_t 
*tiling_mode,
 
 struct brw_bo *
 brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd,
- int size)
+ int size, uint32_t tiling)
 {
int ret;
uint32_t handle;
@@ -1071,8 +1071,16 @@ brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, 
int prime_fd,
if (drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, _tiling))
   goto err;
 
-   bo->tiling_mode = get_tiling.tiling_mode;
bo->swizzle_mode = get_tiling.swizzle_mode;
+   bo->tiling_mode = get_tiling.tiling_mode;
+
+   /* If the import explicitly specifies a tiling mode, verify that it matches;
+* TILING_X is taken as the default where a mismatch is not fatal, and means
+* to infer the real tiling mode. */
+   if (tiling != I915_TILING_X &&
+   (bo->tiling_mode != tiling && bo->tiling_mode != I915_TILING_NONE))
+  goto err;
+
/* XXX stride is unknown */
 
 out:
diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h 
b/src/mesa/drivers/dri/i965/brw_bufmgr.h
index 56ec206..0a85d9d 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.h
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h
@@ -272,7 +272,8 @@ void brw_destroy_hw_context(struct brw_bufmgr *bufmgr, 
uint32_t ctx_id);
 
 int brw_bo_gem_export_to_prime(struct brw_bo *bo, int *prime_fd);
 struct brw_bo *brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr,
-int prime_fd, int size);
+int prime_fd, int size,
+uint32_t tiling);
 
 int brw_reg_read(struct brw_bufmgr *bufmgr, uint32_t offset,
  uint64_t *result);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index eaa7915..0469960 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -929,6 +929,7 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
struct intel_image_format *f;
__DRIimage *image;
struct brw_bo *bo;
+   uint32_t tiling = I915_TILING_X; /* default to X-tiling */
int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
@@ -946,7 +947,7 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
  size = end;
}
 
-   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
+   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size, tiling);
if (bo == NULL)
   return NULL;
 
@@ -955,7 +956,7 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
 * fds received here */
for (i = 1; i < num_fds; i++) {
   struct brw_bo *aux =
- brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size);
+ brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size, tiling);
   brw_bo_unreference(aux);
   if (aux != bo) {
  brw_bo_unreference(bo);
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] i965: Improve same-buffer restriction for imports

2017-06-06 Thread Varad Gautam
From: Daniel Stone <dani...@collabora.com>

Intel hardware requires that all planes of an image come from the same
buffer, which is currently implemented by testing that all FDs are
numerically the same.

However, when going through a winsys (e.g.) or anything which transits
FDs individually, the FDs may be different even if the underlying buffer
is the same.

Instead of checking the FDs for equality, we must check if they actually
point to the same buffer (Jason).

v2: stop leaking bo references (Daniel Stone). buildfix.

Signed-off-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 50 
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9842de6..f6bba8b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -815,20 +815,41 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
struct intel_screen *screen = dri_screen->driverPrivate;
struct intel_image_format *f;
__DRIimage *image;
-   int i, index;
+   struct brw_bo *bo;
+   int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
   return NULL;
 
-   /* We only support all planes from the same bo */
-   for (i = 0; i < num_fds; i++)
-  if (fds[0] != fds[i])
- return NULL;
-
f = intel_image_format_lookup(fourcc);
if (f == NULL)
   return NULL;
 
+   for (i = 0; i < f->nplanes; i++) {
+  index = f->planes[i].buffer_index;
+  const int plane_height = height >> f->planes[i].height_shift;
+  const int end = offsets[index] + plane_height * strides[index];
+  if (size < end)
+ size = end;
+   }
+
+   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
+   if (bo == NULL)
+  return NULL;
+
+   /* We only support all planes from the same bo.
+* brw_bo_gem_create_from_prime() should return the same pointer for all
+* fds received here */
+   for (i = 1; i < num_fds; i++) {
+  struct brw_bo *aux =
+ brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size);
+  brw_bo_unreference(aux);
+  if (aux != bo) {
+ brw_bo_unreference(bo);
+ return NULL;
+  }
+   }
+
if (f->nplanes == 1)
   image = intel_allocate_image(screen, f->planes[0].dri_format,
loaderPrivate);
@@ -836,32 +857,23 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
   image = intel_allocate_image(screen, __DRI_IMAGE_FORMAT_NONE,
loaderPrivate);
 
-   if (image == NULL)
+   if (image == NULL) {
+  brw_bo_unreference(bo);
   return NULL;
+   }
 
image->width = width;
image->height = height;
image->pitch = strides[0];
 
image->planar_format = f;
-   int size = 0;
for (i = 0; i < f->nplanes; i++) {
   index = f->planes[i].buffer_index;
   image->offsets[index] = offsets[index];
   image->strides[index] = strides[index];
-
-  const int plane_height = height >> f->planes[i].height_shift;
-  const int end = offsets[index] + plane_height * strides[index];
-  if (size < end)
- size = end;
}
 
-   image->bo = brw_bo_gem_create_from_prime(screen->bufmgr,
-  fds[0], size);
-   if (image->bo == NULL) {
-  free(image);
-  return NULL;
-   }
+   image->bo = bo;
image->modifier = tiling_to_modifier(image->bo->tiling_mode);
 
if (f->nplanes == 1) {
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] i965: Support dmabuf import with modifiers

2017-06-06 Thread Varad Gautam
Add support for createImageFromDmaBufs2, adding a modifier to the
original, and allow importing CCS resources with auxiliary data from
dmabufs.

v2: avoid DRIimageExtension version bump, pass single modifier to
createImageFromDmaBufs2.
v3: rebase to 'i965: Improve same-buffer restriction for imports' v2

Signed-off-by: Varad Gautam <varadgau...@gmail.com>
Signed-off-by: Daniel Stone <dani...@collabora.com>
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c |   6 ++
 src/mesa/drivers/dri/i965/intel_screen.c  | 114 +++---
 2 files changed, 107 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 962d220..0693b94 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -848,6 +848,12 @@ intel_miptree_create_for_image(struct brw_context *intel,
assert(mt->logical_depth0 == 1);
 
create_ccs_buf_for_image(intel, image, mt);
+   if (image->dma_buf_imported)
+  /* We have an imported image with aux data. Mark it unresolved.
+   */
+  intel_miptree_set_fast_clear_state(intel, mt, mt->first_level,
+ 0, mt->logical_depth0,
+ INTEL_FAST_CLEAR_STATE_UNRESOLVED);
 
return mt;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 0469960..30ec9d2 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -920,16 +920,19 @@ intel_create_image_from_names(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
-intel_create_image_from_fds(__DRIscreen *dri_screen,
-int width, int height, int fourcc,
-int *fds, int num_fds, int *strides, int *offsets,
-void *loaderPrivate)
+intel_create_image_from_fds_common(__DRIscreen *dri_screen,
+   int width, int height, int fourcc,
+   uint64_t modifier, int *fds,
+   int num_fds, int *strides,
+   int *offsets, void *loaderPrivate)
 {
struct intel_screen *screen = dri_screen->driverPrivate;
struct intel_image_format *f;
__DRIimage *image;
struct brw_bo *bo;
-   uint32_t tiling = I915_TILING_X; /* default to X-tiling */
+   uint32_t tiling;
+   unsigned tiled_height;
+   unsigned ccs_height;
int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
@@ -939,10 +942,26 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
if (f == NULL)
   return NULL;
 
+   switch (modifier) {
+   case fourcc_mod_code(INTEL, 4):
+  tiling = modifier_to_tiling(modifier);
+  ccs_height = get_aux_height(modifier, height);
+   case DRM_FORMAT_MOD_INVALID:
+  /* X-tiling is the default, and also allows us to infer the tiling
+   * mode from the BO */
+  tiling = I915_TILING_X;
+  ccs_height = 0;
+   default:
+  return NULL;
+   }
+   tiled_height = get_tiled_height(tiling, height);
+
for (i = 0; i < f->nplanes; i++) {
   index = f->planes[i].buffer_index;
-  const int plane_height = height >> f->planes[i].height_shift;
-  const int end = offsets[index] + plane_height * strides[index];
+  const int plane_height = tiled_height >> f->planes[i].height_shift;
+  const int end = offsets[index] +
+  (plane_height + ccs_height) * strides[index];
+
   if (size < end)
  size = end;
}
@@ -988,10 +1007,18 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
}
 
image->bo = bo;
-   image->modifier = tiling_to_modifier(image->bo->tiling_mode);
+
+   /* If we've explicitly specified a modifier, then we use that; else
+* we infer the modifier from the BO's tiling mode. */
+   if (modifier != DRM_FORMAT_MOD_INVALID)
+  image->modifier = modifier;
+   else
+  image->modifier = tiling_to_modifier(image->bo->tiling_mode);
 
if (f->nplanes == 1) {
   image->offset = image->offsets[0];
+  if (ccs_height)
+ image->aux_offset = tiled_height * image->pitch;
   intel_image_warn_if_unaligned(image, __func__);
}
 
@@ -999,9 +1026,21 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
-intel_create_image_from_dma_bufs(__DRIscreen *dri_screen,
+intel_create_image_from_fds(__DRIscreen *dri_screen,
+int width, int height, int fourcc,
+int *fds, int num_fds, int *strides, int *offsets,
+void *loaderPrivate)
+{
+   return intel_create_image_from_fds_common(dri_screen, width, height,
+ fourcc, D

Re: [Mesa-dev] [PATCH v14 15/36] i965: Improve same-buffer restriction for imports

2017-06-05 Thread Varad Gautam
Hi Daniel,

On Mon, 2017-06-05 at 14:53 +0100, Daniel Stone wrote:
> Hi Varad,
> 
> On 30 May 2017 at 12:53, Varad Gautam <varadgau...@gmail.com> wrote:
> > 
> > +   /* We only support all planes from the same bo.
> > +* brw_bo_gem_create_from_prime() should return the same pointer for all
> > +* fds received here */
> > +   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
> > +   for (i = 1; i < num_fds; i++) {
> > +  if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size))
> > + return NULL;
> 
> This above takes a ref, which gets leaked.
> 
>    struct brw_bo *aux =
> brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size);
>    brw_bo_unreference(aux);
>    if (aux != bo)

Thanks for spotting this. Can the unref(aux) happen before comparing against bo?
Or should this be something like:
   for (...) {
      struct brw_bo *aux = brw_bo_gem_create_from_prime(screen->bufmgr, fds[i],
size);
      if (aux != bo) {
         brw_bo_unreference(aux);
         return NULL;
      }
      brw_bo_unreference(aux);
   }
>   return NULL;
> 
> Thanks for the fix!
> 
> Cheers,
> Daniel
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v14 29/36] i965: Add new resolve hints full and partial

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

Upper layers of the code will have the need to specify full or partial
resolves (more on this in the next patch). This code simply adds the new
enums and plumbs it in as minimally as necessary.

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/brw_blorp.c | 3 ++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c 
b/src/mesa/drivers/dri/i965/brw_blorp.c
index e6f00bb..c3baf57 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.c
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c
@@ -1006,7 +1006,8 @@ brw_blorp_resolve_color(struct brw_context *brw, struct 
intel_mipmap_tree *mt,
 
enum blorp_fast_clear_op resolve_op;
if (brw->gen >= 9) {
-  if (surf.aux_usage == ISL_AUX_USAGE_CCS_E)
+  if (surf.aux_usage == ISL_AUX_USAGE_CCS_E &&
+  hint != INTEL_RESOLVE_HINT_CLEAR_COLOR)
  resolve_op = BLORP_FAST_CLEAR_OP_RESOLVE_FULL;
   else
  resolve_op = BLORP_FAST_CLEAR_OP_RESOLVE_PARTIAL;
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
index 9e15e6e..097486d 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
@@ -938,7 +938,9 @@ intel_miptree_used_for_rendering(const struct brw_context 
*brw,
  */
 enum intel_resolve_hint {
INTEL_RESOLVE_HINT_NO_HINT = 0,
-   INTEL_RESOLVE_HINT_IGNORE_CCS_E
+   INTEL_RESOLVE_HINT_IGNORE_CCS_E,
+   INTEL_RESOLVE_HINT_CLEAR_COLOR,
+   INTEL_RESOLVE_HINT_FULL,
 };
 
 bool
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 34/36] i965: Add tiling mode to BO import

2017-05-30 Thread Varad Gautam
From: Daniel Stone <dani...@collabora.com>

When importing a dmabuf, verify that the tiling mode matches what was
expected.

Signed-off-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varadgau...@gmail.com>
---
 src/mesa/drivers/dri/i965/brw_bufmgr.c   | 12 ++--
 src/mesa/drivers/dri/i965/brw_bufmgr.h   |  3 ++-
 src/mesa/drivers/dri/i965/intel_screen.c | 10 ++
 3 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c 
b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 2f17934..56cf979 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -1014,7 +1014,7 @@ brw_bo_get_tiling(struct brw_bo *bo, uint32_t 
*tiling_mode,
 
 struct brw_bo *
 brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd,
- int size)
+ int size, uint32_t tiling)
 {
int ret;
uint32_t handle;
@@ -1071,8 +1071,16 @@ brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, 
int prime_fd,
if (drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, _tiling))
   goto err;
 
-   bo->tiling_mode = get_tiling.tiling_mode;
bo->swizzle_mode = get_tiling.swizzle_mode;
+   bo->tiling_mode = get_tiling.tiling_mode;
+
+   /* If the import explicitly specifies a tiling mode, verify that it matches;
+* TILING_X is taken as the default where a mismatch is not fatal, and means
+* to infer the real tiling mode. */
+   if (tiling != I915_TILING_X &&
+   (bo->tiling_mode != tiling && bo->tiling_mode != I915_TILING_NONE))
+  goto err;
+
/* XXX stride is unknown */
 
 out:
diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h 
b/src/mesa/drivers/dri/i965/brw_bufmgr.h
index 56ec206..0a85d9d 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.h
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h
@@ -272,7 +272,8 @@ void brw_destroy_hw_context(struct brw_bufmgr *bufmgr, 
uint32_t ctx_id);
 
 int brw_bo_gem_export_to_prime(struct brw_bo *bo, int *prime_fd);
 struct brw_bo *brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr,
-int prime_fd, int size);
+int prime_fd, int size,
+uint32_t tiling);
 
 int brw_reg_read(struct brw_bufmgr *bufmgr, uint32_t offset,
  uint64_t *result);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 4fd6d17..857983d 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -929,6 +929,7 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
struct intel_image_format *f;
__DRIimage *image;
struct brw_bo *bo;
+   uint32_t tiling = I915_TILING_X; /* default to X-tiling */
int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
@@ -948,9 +949,10 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
/* We only support all planes from the same bo.
 * brw_bo_gem_create_from_prime() should return the same pointer for all
 * fds received here */
-   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
+   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size, tiling);
for (i = 1; i < num_fds; i++) {
-  if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size))
+  if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i],
+ size, tiling))
  return NULL;
}
 
@@ -981,8 +983,8 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
  size = end;
}
 
-   image->bo = brw_bo_gem_create_from_prime(screen->bufmgr,
-  fds[0], size);
+   image->bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size,
+tiling);
if (image->bo == NULL) {
   free(image);
   return NULL;
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 33/36] i965: Handle compression modifier

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

v2: Rename modifier to be more smart (Jason)

FINISHME: Use the kernel's final choice for the fb modifier

bwidawsk@norris2:~/intel-gfx/kmscube (modifiers $) 
~/scripts/measure_bandwidth.sh ./kmscube none
Read bandwidth: 603.91 MiB/s
Write bandwidth: 615.28 MiB/s
bwidawsk@norris2:~/intel-gfx/kmscube (modifiers $) 
~/scripts/measure_bandwidth.sh ./kmscube ytile
Read bandwidth: 571.13 MiB/s
Write bandwidth: 555.51 MiB/s
bwidawsk@norris2:~/intel-gfx/kmscube (modifiers $) 
~/scripts/measure_bandwidth.sh ./kmscube ccs
Read bandwidth: 259.34 MiB/s
Write bandwidth: 337.83 MiB/s

v2: Move all references to the new fourcc code(s) to this patch.
v3: Rebase, remove Yf_CCS (Daniel)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 86618d7..4fd6d17 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -306,6 +306,9 @@ static const struct {
  .height_align = 8 },
{ .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED,
  .height_align = 32 },
+   { .tiling = I915_TILING_Y, .modifier = /* I915_FORMAT_MOD_Y_TILED_CCS */ 
fourcc_mod_code(INTEL, 4),
+ .height_align = 32, .aux_w_block = 32, .aux_w_align = 128,
+ .aux_h_block = 16, .aux_h_align = 32 },
 };
 
 static uint32_t
@@ -633,6 +636,7 @@ enum modifier_priority {
MODIFIER_PRIORITY_LINEAR,
MODIFIER_PRIORITY_X,
MODIFIER_PRIORITY_Y,
+   MODIFIER_PRIORITY_Y_CCS,
 };
 
 const uint64_t priority_to_modifier[] = {
@@ -640,6 +644,7 @@ const uint64_t priority_to_modifier[] = {
[MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR,
[MODIFIER_PRIORITY_X] = I915_FORMAT_MOD_X_TILED,
[MODIFIER_PRIORITY_Y] = I915_FORMAT_MOD_Y_TILED,
+   [MODIFIER_PRIORITY_Y_CCS] =  /* I915_FORMAT_MOD_Y_TILED_CCS */ 
fourcc_mod_code(INTEL, 4),
 };
 
 static uint64_t
@@ -651,6 +656,9 @@ select_best_modifier(struct gen_device_info *devinfo,
 
for (int i = 0; i < count; i++) {
   switch (modifiers[i]) {
+  case /* I915_FORMAT_MOD_Y_TILED_CCS */ fourcc_mod_code(INTEL, 4):
+ prio = MAX2(prio, MODIFIER_PRIORITY_Y_CCS);
+ break;
   case I915_FORMAT_MOD_Y_TILED:
  prio = MAX2(prio, MODIFIER_PRIORITY_Y);
  break;
@@ -715,6 +723,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
}
tiling = modifier_to_tiling(modifier);
tiled_height = get_tiled_height(tiling, height);
+   ccs_height = get_aux_height(modifier, height);
 
image = intel_allocate_image(screen, format, loaderPrivate);
if (image == NULL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 36/36] i965: Add format/modifier advertising

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

v2: Rebase and reuse tiling/modifier map. (Daniel Stone)
v3: bump DRIimageExtension to version 15, fill external_only array.

Signed-off-by: Varad Gautam <varadgau...@gmail.com>
Signed-off-by: Daniel Stone <dani...@collabora.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 79 +---
 1 file changed, 73 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index ddbb43b..677c62a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -294,6 +294,7 @@ static struct intel_image_format intel_image_formats[] = {
 static const struct {
uint32_t tiling;
uint64_t modifier;
+   unsigned since_gen;
unsigned height_align;
unsigned aux_w_block;
unsigned aux_w_align;
@@ -301,13 +302,13 @@ static const struct {
unsigned aux_h_align;
 } tiling_modifier_map[] = {
{ .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR,
- .height_align = 1 },
+ .since_gen = 1, .height_align = 1 },
{ .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED,
- .height_align = 8 },
+ .since_gen = 1, .height_align = 8 },
{ .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED,
- .height_align = 32 },
+ .since_gen = 9, .height_align = 32 },
{ .tiling = I915_TILING_Y, .modifier = /* I915_FORMAT_MOD_Y_TILED_CCS */ 
fourcc_mod_code(INTEL, 4),
- .height_align = 32, .aux_w_block = 32, .aux_w_align = 128,
+ .since_gen = 9, .height_align = 32, .aux_w_block = 32, .aux_w_align = 128,
  .aux_h_block = 16, .aux_h_align = 32 },
 };
 
@@ -1125,6 +1126,71 @@ intel_create_image_from_dma_bufs2(__DRIscreen 
*dri_screen,
   loaderPrivate);
 }
 
+static GLboolean
+intel_query_dma_buf_formats(__DRIscreen *screen, int max,
+int *formats, int *count)
+{
+   int i, j = 0;
+
+   if (max == 0) {
+  *count = ARRAY_SIZE(intel_image_formats) - 1; /* not SARGB */
+  return true;
+   }
+
+   for (i = 0; i < (ARRAY_SIZE(intel_image_formats)) && j < max; i++) {
+ if (intel_image_formats[i].fourcc == __DRI_IMAGE_FOURCC_SARGB)
+   continue;
+ formats[j++] = intel_image_formats[i].fourcc;
+   }
+
+   *count = j;
+   return true;
+}
+
+static GLboolean
+intel_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+  uint64_t *modifiers,
+  unsigned int *external_only,
+  int *count)
+{
+   struct intel_screen *screen = _screen->driverPrivate;
+   struct intel_image_format *f;
+   int num_mods = 0, i;
+
+   f = intel_image_format_lookup(fourcc);
+   if (f == NULL)
+  return false;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+  if (screen->devinfo.gen < tiling_modifier_map[i].since_gen)
+ continue;
+
+  num_mods++;
+  if (num_mods >= max)
+ continue;
+
+  modifiers[num_mods] = tiling_modifier_map[i].modifier;
+   }
+
+   if (external_only != NULL) {
+  /* XXX: advertise multiplane YUV formats as for external textures only
+   * for now. */
+  for (i = 0; i < num_mods && i < max; i++) {
+ if (f->components == __DRI_IMAGE_COMPONENTS_Y_U_V ||
+ f->components == __DRI_IMAGE_COMPONENTS_Y_UV ||
+ f->components == __DRI_IMAGE_COMPONENTS_Y_XUXV) {
+external_only[i] = GL_TRUE;
+ }
+ else {
+external_only[i] = GL_FALSE;
+ }
+  }
+   }
+
+   *count = num_mods;
+   return true;
+}
+
 static __DRIimage *
 intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
 {
@@ -1185,8 +1251,7 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 }
 
 static const __DRIimageExtension intelImageExtension = {
-.base = { __DRI_IMAGE, 14 },
-
+.base = { __DRI_IMAGE, 15 },
 .createImageFromName= intel_create_image_from_name,
 .createImageFromRenderbuffer= intel_create_image_from_renderbuffer,
 .destroyImage   = intel_destroy_image,
@@ -1205,6 +1270,8 @@ static const __DRIimageExtension intelImageExtension = {
 .unmapImage = NULL,
 .createImageWithModifiers   = intel_create_image_with_modifiers,
 .createImageFromDmaBufs2= intel_create_image_from_dma_bufs2,
+.queryDmaBufFormats = intel_query_dma_buf_formats,
+.queryDmaBufModifiers   = intel_query_dma_buf_modifiers,
 };
 
 static uint64_t
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 35/36] i965: Support dmabuf import with modifiers

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

Add support for createImageFromDmaBufs2, adding a modifier to the
original, and allow importing CCS resources with auxiliary data from
dmabufs.

v2: avoid DRIimageExtension version bump, pass single modifier to
createImageFromDmaBufs2.

Signed-off-by: Varad Gautam <varadgau...@gmail.com>
Signed-off-by: Daniel Stone <dani...@collabora.com>
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c |   6 ++
 src/mesa/drivers/dri/i965/intel_screen.c  | 127 +-
 2 files changed, 111 insertions(+), 22 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 962d220..0693b94 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -848,6 +848,12 @@ intel_miptree_create_for_image(struct brw_context *intel,
assert(mt->logical_depth0 == 1);
 
create_ccs_buf_for_image(intel, image, mt);
+   if (image->dma_buf_imported)
+  /* We have an imported image with aux data. Mark it unresolved.
+   */
+  intel_miptree_set_fast_clear_state(intel, mt, mt->first_level,
+ 0, mt->logical_depth0,
+ INTEL_FAST_CLEAR_STATE_UNRESOLVED);
 
return mt;
 }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 857983d..ddbb43b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -920,16 +920,19 @@ intel_create_image_from_names(__DRIscreen *dri_screen,
 }
 
 static __DRIimage *
-intel_create_image_from_fds(__DRIscreen *dri_screen,
-int width, int height, int fourcc,
-int *fds, int num_fds, int *strides, int *offsets,
-void *loaderPrivate)
+intel_create_image_from_fds_common(__DRIscreen *dri_screen,
+   int width, int height, int fourcc,
+   uint64_t modifier, int *fds,
+   int num_fds, int *strides,
+   int *offsets, void *loaderPrivate)
 {
struct intel_screen *screen = dri_screen->driverPrivate;
struct intel_image_format *f;
__DRIimage *image;
struct brw_bo *bo;
-   uint32_t tiling = I915_TILING_X; /* default to X-tiling */
+   uint32_t tiling;
+   unsigned tiled_height;
+   unsigned ccs_height;
int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
@@ -939,16 +942,33 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
if (f == NULL)
   return NULL;
 
+   switch (modifier) {
+   case fourcc_mod_code(INTEL, 4):
+  tiling = modifier_to_tiling(modifier);
+  ccs_height = get_aux_height(modifier, height);
+   case DRM_FORMAT_MOD_INVALID:
+  /* X-tiling is the default, and also allows us to infer the tiling
+   * mode from the BO */
+  tiling = I915_TILING_X;
+  ccs_height = 0;
+   default:
+  return NULL;
+   }
+   tiled_height = get_tiled_height(tiling, height);
+
for (i = 0; i < f->nplanes; i++) {
   index = f->planes[i].buffer_index;
-  const int plane_height = height >> f->planes[i].height_shift;
-  const int end = offsets[index] + plane_height * strides[index];
+  const int plane_height = tiled_height >> f->planes[i].height_shift;
+  const int end = offsets[index] +
+  (plane_height + ccs_height) * strides[index];
+
   if (size < end)
  size = end;
}
-   /* We only support all planes from the same bo.
-* brw_bo_gem_create_from_prime() should return the same pointer for all
-* fds received here */
+
+   /* We only support all planes from the same bo. Check that
+* brw_bo_gem_create_from_prime() returns the same pointer for all
+* fds received here. */
bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size, tiling);
for (i = 1; i < num_fds; i++) {
   if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i],
@@ -971,16 +991,10 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
image->pitch = strides[0];
 
image->planar_format = f;
-   int size = 0;
for (i = 0; i < f->nplanes; i++) {
   index = f->planes[i].buffer_index;
   image->offsets[index] = offsets[index];
   image->strides[index] = strides[index];
-
-  const int plane_height = height >> f->planes[i].height_shift;
-  const int end = offsets[index] + plane_height * strides[index];
-  if (size < end)
- size = end;
}
 
image->bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size,
@@ -989,10 +1003,18 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
   free(image);
   return NULL;
}
-   image->modifier = tiling_to_modifi

[Mesa-dev] [PATCH v14 20/36] i965: Restructure CCS disabling

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

Make the code only disable CCS when it has to, unlike before where it
disabled CCS and enabled it when it could. This is much more inline with
how it should work in a few patches, where we have fewer restrictions as
to when we disable CCS.

v2: Change CCS disabling to an assertion in layout creation (Topi)

v3: Make sure to disable aux buffers when creating a miptree from a BO.
Today, this only happens via intel_update_image_buffer. At the end of
the modifier series, we should be able to undo this. Some fixes from
Topi in here as well.

v4: Split no_aux into a separate patch (Jason)

Cc: "Pohjolainen, Topi" 
Signed-off-by: Ben Widawsky 
Signed-off-by: Daniel Stone 
Cc: Jason Ekstrand 
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 20149c8..2e3225e 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -328,7 +328,6 @@ intel_miptree_create_layout(struct brw_context *brw,
mt->logical_depth0 = depth0;
mt->aux_disable = (layout_flags & MIPTREE_LAYOUT_DISABLE_AUX) != 0 ?
   INTEL_AUX_DISABLE_ALL : INTEL_AUX_DISABLE_NONE;
-   mt->aux_disable |= INTEL_AUX_DISABLE_CCS;
mt->is_scanout = (layout_flags & MIPTREE_LAYOUT_FOR_SCANOUT) != 0;
exec_list_make_empty(>hiz_map);
exec_list_make_empty(>color_resolve_map);
@@ -521,6 +520,8 @@ intel_miptree_create_layout(struct brw_context *brw,
} else if (brw->gen >= 9 && num_samples > 1) {
   layout_flags |= MIPTREE_LAYOUT_FORCE_HALIGN16;
} else {
+  mt->aux_disable |= INTEL_AUX_DISABLE_CCS;
+
   const UNUSED bool is_lossless_compressed_aux =
  brw->gen >= 9 && num_samples == 1 &&
  mt->format == MESA_FORMAT_R_UINT32;
@@ -696,7 +697,6 @@ intel_miptree_create(struct brw_context *brw,
 */
if (intel_tiling_supports_non_msrt_mcs(brw, mt->tiling) &&
intel_miptree_supports_non_msrt_fast_clear(brw, mt)) {
-  mt->aux_disable &= ~INTEL_AUX_DISABLE_CCS;
   assert(brw->gen < 8 || mt->halign == 16 || num_samples <= 1);
 
   /* On Gen9+ clients are not currently capable of consuming compressed
@@ -710,8 +710,11 @@ intel_miptree_create(struct brw_context *brw,
  intel_miptree_supports_lossless_compressed(brw, mt);
 
   if (is_lossless_compressed) {
+ assert(!(mt->aux_disable & INTEL_AUX_DISABLE_CCS));
  intel_miptree_alloc_non_msrt_mcs(brw, mt, is_lossless_compressed);
   }
+   } else {
+  mt->aux_disable |= INTEL_AUX_DISABLE_CCS;
}
 
return mt;
@@ -803,7 +806,7 @@ create_ccs_buf_for_image(struct brw_context *intel,
mt->mcs_buf->qpitch = isl_surf_get_array_pitch_sa_rows(_ccs_surf);
 
intel_miptree_init_mcs(intel, mt, 0);
-   mt->aux_disable &= ~INTEL_AUX_DISABLE_CCS;
+   assert(!(mt->aux_disable & INTEL_AUX_DISABLE_CCS));
mt->msaa_layout = INTEL_MSAA_LAYOUT_CMS;
 
return true;
@@ -899,14 +902,14 @@ intel_update_winsys_renderbuffer_miptree(struct 
brw_context *intel,
if (!singlesample_mt)
   goto fail;
 
-   /* If this miptree is capable of supporting fast color clears, set
-* mcs_state appropriately to ensure that fast clears will occur.
+   /* If this miptree is not capable of supporting fast color clears, flag
+* mcs allocation disabled.
 * Allocation of the MCS miptree will be deferred until the first fast
 * clear actually occurs.
 */
-   if (intel_tiling_supports_non_msrt_mcs(intel, singlesample_mt->tiling) &&
-   intel_miptree_supports_non_msrt_fast_clear(intel, singlesample_mt)) {
-  singlesample_mt->aux_disable &= ~INTEL_AUX_DISABLE_CCS;
+   if (!intel_tiling_supports_non_msrt_mcs(intel, singlesample_mt->tiling) ||
+   !intel_miptree_supports_non_msrt_fast_clear(intel, singlesample_mt)) {
+  singlesample_mt->aux_disable |= INTEL_AUX_DISABLE_CCS;
}
 
if (num_samples == 0) {
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 28/36] i965: Plumb resolve hints from miptrees to blorp

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/brw_blorp.c | 3 ++-
 src/mesa/drivers/dri/i965/brw_blorp.h | 3 ++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c 
b/src/mesa/drivers/dri/i965/brw_blorp.c
index a900a3f..e6f00bb 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.c
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c
@@ -989,7 +989,8 @@ brw_blorp_clear_color(struct brw_context *brw, struct 
gl_framebuffer *fb,
 
 void
 brw_blorp_resolve_color(struct brw_context *brw, struct intel_mipmap_tree *mt,
-unsigned level, unsigned layer)
+unsigned level, unsigned layer,
+enum intel_resolve_hint hint)
 {
DBG("%s to mt %p level %u layer %u\n", __FUNCTION__, mt, level, layer);
 
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h 
b/src/mesa/drivers/dri/i965/brw_blorp.h
index 8743d96..87ec1ff 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.h
+++ b/src/mesa/drivers/dri/i965/brw_blorp.h
@@ -66,7 +66,8 @@ brw_blorp_clear_color(struct brw_context *brw, struct 
gl_framebuffer *fb,
 void
 brw_blorp_resolve_color(struct brw_context *brw,
 struct intel_mipmap_tree *mt,
-unsigned level, unsigned layer);
+unsigned level, unsigned layer,
+enum intel_resolve_hint hint);
 
 void
 intel_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 1d707ad..6759859 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -2282,7 +2282,7 @@ intel_miptree_resolve_color(struct brw_context *brw,
   if (item) {
  assert(item->fast_clear_state != INTEL_FAST_CLEAR_STATE_RESOLVED);
 
- brw_blorp_resolve_color(brw, mt, level, start_layer);
+ brw_blorp_resolve_color(brw, mt, level, start_layer, hint);
  intel_resolve_map_remove(item);
  resolved = true;
   }
@@ -2303,7 +2303,7 @@ intel_miptree_all_slices_resolve_color(struct brw_context 
*brw,
>color_resolve_map) {
   assert(map->fast_clear_state != INTEL_FAST_CLEAR_STATE_RESOLVED);
 
-  brw_blorp_resolve_color(brw, mt, map->level, map->layer);
+  brw_blorp_resolve_color(brw, mt, map->level, map->layer, hint);
   intel_resolve_map_remove(map);
}
 }
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 30/36] i965: Use partial resolves for CCS buffers being scanned out

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

On Gen9 hardware, the display engine is able to scanout a compressed
framebuffer by providing an offset to auxiliary compression information.
Unfortunately, the hardware is incapable of doing the same thing for the
fast clear color.

To mitigate this, the hardware introduced a new resolve type called a
partial resolve. The partial resolve will only do a resolve of the fast
clear color and leave the rest of the compressed data alone.

This patch enables using this resolve type for cases where the
framebuffer will be passed along to the kernel for display.

v2: Add early exit from intel_miptree_make_shareable() when it's
scanout.
v3: Add another assert for mt->mcs_buf->offset. (Topi)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/brw_context.c   |  3 ++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 10 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 5a2a452..0c99e59 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1376,7 +1376,8 @@ intel_resolve_for_dri2_flush(struct brw_context *brw,
   if (rb->mt->num_samples <= 1) {
  assert(rb->mt_layer == 0 && rb->mt_level == 0 &&
 rb->layer_count == 1);
- intel_miptree_resolve_color(brw, rb->mt, 0, 0, 1, 0);
+ intel_miptree_resolve_color(brw, rb->mt, 0, 0, 1,
+ INTEL_RESOLVE_HINT_CLEAR_COLOR);
   } else {
  intel_renderbuffer_downsample(brw, rb);
   }
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 6759859..d5734d6 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -2330,7 +2330,15 @@ intel_miptree_make_shareable(struct brw_context *brw,
assert(mt->msaa_layout == INTEL_MSAA_LAYOUT_NONE || mt->num_samples <= 1);
 
if (mt->mcs_buf) {
-  intel_miptree_all_slices_resolve_color(brw, mt, 0);
+  intel_miptree_all_slices_resolve_color(brw, mt, mt->is_scanout ?
+ INTEL_RESOLVE_HINT_CLEAR_COLOR :
+ INTEL_RESOLVE_HINT_FULL);
+  if (mt->is_scanout) {
+ assert(!mt->hiz_buf);
+ assert(mt->mcs_buf->offset);
+ return;
+  }
+
   mt->aux_disable |= (INTEL_AUX_DISABLE_CCS | INTEL_AUX_DISABLE_MCS);
   brw_bo_unreference(mt->mcs_buf->bo);
   free(mt->mcs_buf);
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 26/36] i965: Pretend that CCS modified images are two planes

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

v2: move is_aux into if block. (Jason)
Use else block instead of goto (Jason)

v3: Fix up logic for is_aux (Ben)
Fix up size calculations and add FIXME (Ben)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 98 +++-
 1 file changed, 83 insertions(+), 15 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9509ba2..86618d7 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -295,6 +295,10 @@ static const struct {
uint32_t tiling;
uint64_t modifier;
unsigned height_align;
+   unsigned aux_w_block;
+   unsigned aux_w_align;
+   unsigned aux_h_block;
+   unsigned aux_h_align;
 } tiling_modifier_map[] = {
{ .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR,
  .height_align = 1 },
@@ -343,6 +347,57 @@ get_tiled_height(uint32_t tiling, unsigned height)
unreachable("get_tiled_height received unknown tiling mode");
 }
 
+static unsigned
+get_aux_width(uint64_t modifier, unsigned width)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+  if (tiling_modifier_map[i].modifier != modifier)
+ continue;
+  if (tiling_modifier_map[i].aux_w_block == 0)
+ return 0;
+  return ALIGN(DIV_ROUND_UP(width, tiling_modifier_map[i].aux_w_block),
+   tiling_modifier_map[i].aux_w_align);
+   }
+
+   unreachable("get_aux_width received unknown modifier");
+}
+
+static unsigned
+get_aux_stride(uint64_t modifier, unsigned stride)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+  if (tiling_modifier_map[i].modifier != modifier)
+ continue;
+  if (tiling_modifier_map[i].aux_w_block == 0)
+ return 0;
+  return ALIGN(stride / tiling_modifier_map[i].aux_w_block,
+   tiling_modifier_map[i].aux_w_align);
+   }
+
+   unreachable("get_aux_stride received unknown modifier");
+}
+
+static unsigned
+get_aux_height(uint64_t modifier, unsigned height)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+  if (tiling_modifier_map[i].modifier != modifier)
+ continue;
+  if (tiling_modifier_map[i].aux_h_block == 0)
+ return 0;
+  return ALIGN(DIV_ROUND_UP(height, tiling_modifier_map[i].aux_h_block),
+   tiling_modifier_map[i].aux_h_align);
+   }
+
+   unreachable("get_aux_height received unknown modifier");
+}
+
 static void
 intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
 {
@@ -760,7 +815,7 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
case __DRI_IMAGE_ATTRIB_FOURCC:
   return intel_lookup_fourcc(image->dri_format, value);
case __DRI_IMAGE_ATTRIB_NUM_PLANES:
-  *value = 1;
+  *value = image->aux_offset ? 2: 1;
   return true;
case __DRI_IMAGE_ATTRIB_OFFSET:
   *value = image->offset;
@@ -984,20 +1039,33 @@ intel_from_planar(__DRIimage *parent, int plane, void 
*loaderPrivate)
 struct intel_image_format *f;
 __DRIimage *image;
 
-if (parent == NULL || parent->planar_format == NULL)
-return NULL;
-
-f = parent->planar_format;
-
-if (plane >= f->nplanes)
-return NULL;
-
-width = parent->width >> f->planes[plane].width_shift;
-height = parent->height >> f->planes[plane].height_shift;
-dri_format = f->planes[plane].dri_format;
-index = f->planes[plane].buffer_index;
-offset = parent->offsets[index];
-stride = parent->strides[index];
+if (parent == NULL) {
+   return NULL;
+} else if (parent->planar_format == NULL) {
+   const bool is_aux = parent->aux_offset && plane == 1;
+   if (!is_aux)
+  return NULL;
+
+   width = get_aux_width(parent->modifier, parent->width);
+   height = get_aux_width(parent->modifier, parent->height);
+   stride = get_aux_stride(parent->modifier, parent->pitch);
+   dri_format = parent->dri_format;
+   offset = parent->aux_offset;
+} else {
+   /* Planar formats don't support aux buffers/images */
+   assert(!parent->aux_offset);
+   f = parent->planar_format;
+
+   if (plane >= f->nplanes)
+  return NULL;
+
+   width = parent->width >> f->planes[plane].width_shift;
+   height = parent->height >> f->planes[plane].height_shift;
+   dri_format = f->planes[plane].dri_format;
+   index = f->planes[plane].buffer_index;
+   offset = parent->offsets[index];
+   stride = parent->strides[index];
+}
 
 image = intel_allocate_image(parent->screen, dri_format, loaderPrivate);
 if (image == NULL)
-- 
2.10.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org

[Mesa-dev] [PATCH v14 31/36] i965/miptree: Remove dead code assertion

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

We no longer allocate a miptree for the mcs_buf, so this is not a useful
assertion.

Recommended-by: Topi Pohjolainen 
Signed-off-by: Ben Widawsky 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index d5734d6..e2d124b 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -521,14 +521,6 @@ intel_miptree_create_layout(struct brw_context *brw,
   layout_flags |= MIPTREE_LAYOUT_FORCE_HALIGN16;
} else {
   mt->aux_disable |= INTEL_AUX_DISABLE_CCS;
-
-  const UNUSED bool is_lossless_compressed_aux =
- brw->gen >= 9 && num_samples == 1 &&
- mt->format == MESA_FORMAT_R_UINT32;
-
-  /* For now, nothing else has this requirement */
-  assert(is_lossless_compressed_aux ||
- (layout_flags & MIPTREE_LAYOUT_FORCE_HALIGN16) == 0);
}
 
if (!brw_miptree_layout(brw, mt, layout_flags)) {
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 25/36] i965/miptree: Allocate mt earlier in update winsys

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

Allows us to continue utilizing common miptree creation using __DRIimage
without creating a new DRIimage (for the intel_process_dri2_buffer()
case).

This is a bit ugly, but I think it's the best one can do.

v2: This patch let's us remove the temporary no_aux variable since mt
allocation should work correctly now.
Unref the BO is miptree creation fails (Jason)
v3: Rebase (Daniel)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/brw_context.c   | 31 ++-
 src/mesa/drivers/dri/i965/intel_fbo.h |  7 --
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 17 ++-
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
 4 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 7af58cd..282fd7b 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1662,10 +1662,25 @@ intel_process_dri2_buffer(struct brw_context *brw,
   return;
}
 
-   if (!intel_update_winsys_renderbuffer_miptree(brw, rb, bo,
+   struct intel_mipmap_tree *mt = intel_miptree_create_for_bo(brw,
+  bo,
+  
intel_rb_format(rb),
+  0,
+  drawable->w,
+  drawable->h,
+  1,
+  buffer->pitch,
+  
MIPTREE_LAYOUT_FOR_SCANOUT);
+   if (!mt) {
+  brw_bo_unreference(bo);
+  return;
+   }
+
+   if (!intel_update_winsys_renderbuffer_miptree(brw, rb, mt,
  drawable->w, drawable->h,
  buffer->pitch)) {
   brw_bo_unreference(bo);
+  intel_miptree_release();
   return;
}
 
@@ -1723,13 +1738,19 @@ intel_update_image_buffer(struct brw_context *intel,
if (last_mt && last_mt->bo == buffer->bo)
   return;
 
-   if (!buffer->aux_offset)
-  rb->no_aux = true;
+   struct intel_mipmap_tree *mt = intel_miptree_create_for_image(intel,
+ buffer, 
intel_rb_format(rb), 0,
+ 
buffer->width, buffer->height,
+ 
buffer->pitch, MIPTREE_LAYOUT_FOR_SCANOUT);
+   if (!mt)
+  return;
 
-   if (!intel_update_winsys_renderbuffer_miptree(intel, rb, buffer->bo,
+   if (!intel_update_winsys_renderbuffer_miptree(intel, rb, mt,
  buffer->width, buffer->height,
- buffer->pitch))
+ buffer->pitch)) {
+  intel_miptree_release();
   return;
+   }
 
if (_mesa_is_front_buffer_drawing(fb) &&
buffer_type == __DRI_IMAGE_BUFFER_FRONT &&
diff --git a/src/mesa/drivers/dri/i965/intel_fbo.h 
b/src/mesa/drivers/dri/i965/intel_fbo.h
index 9265aab..08b82e8 100644
--- a/src/mesa/drivers/dri/i965/intel_fbo.h
+++ b/src/mesa/drivers/dri/i965/intel_fbo.h
@@ -111,13 +111,6 @@ struct intel_renderbuffer
 * for the duration of a mapping.
 */
bool singlesample_mt_is_tmp;
-
-   /**
-* Set to true if this buffer definitely does not have auxiliary data, like
-* CCS, associated with it. It's generally to be used when importing a
-* DRIimage, where that DRIimage had no modifier.
-*/
-   bool no_aux;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 7592df6..cf81ea2 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -874,11 +874,10 @@ intel_miptree_create_for_image(struct brw_context *intel,
 bool
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
  struct intel_renderbuffer *irb,
- struct brw_bo *bo,
+ struct intel_mipmap_tree 
*singlesample_mt,
  uint32_t width, uint32_t height,
  uint32_t pitch)
 {
-   struct intel_mipmap_tree *singlesample_mt = NULL;
struct intel_mipmap_tree *multisample_mt = NULL;
struct gl_renderbuffer *rb = >Base.Base;
mesa_format format = rb->Format;
@@ -890,18 +889,7 @@ 

[Mesa-dev] [PATCH v14 27/36] i965: Change resolve flags to enum

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

In the foreseeable future it doesn't seem to make sense to have multiple
resolve flags. What does make sense is to have the caller give an
indication to the lower layers what it things should be done for
resolve. The enum change distinguishes this binary selection.

v2: Make setting the hint more concise (Topi)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/brw_blorp.c |  8 
 src/mesa/drivers/dri/i965/brw_context.c   | 13 +++--
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 12 ++--
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h | 13 -
 4 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c 
b/src/mesa/drivers/dri/i965/brw_blorp.c
index 7ffe8b8..a900a3f 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.c
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c
@@ -220,12 +220,12 @@ blorp_surf_for_miptree(struct brw_context *brw,
 surf->aux_usage = ISL_AUX_USAGE_NONE;
  }
   } else if (!(safe_aux_usage & (1 << surf->aux_usage))) {
- uint32_t flags = 0;
- if (safe_aux_usage & (1 << ISL_AUX_USAGE_CCS_E))
-flags |= INTEL_MIPTREE_IGNORE_CCS_E;
+ const enum intel_resolve_hint hint =
+safe_aux_usage & (1 << ISL_AUX_USAGE_CCS_E) ?
+INTEL_RESOLVE_HINT_IGNORE_CCS_E : 0;
 
  intel_miptree_resolve_color(brw, mt,
- *level, start_layer, num_layers, flags);
+ *level, start_layer, num_layers, hint);
 
  assert(!intel_miptree_has_color_unresolved(mt, *level, 1,
 start_layer, num_layers));
diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index 282fd7b..5a2a452 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -259,9 +259,10 @@ intel_update_state(struct gl_context * ctx, GLuint 
new_state)
   /* Sampling engine understands lossless compression and resolving
* those surfaces should be skipped for performance reasons.
*/
-  const int flags = intel_texture_view_requires_resolve(brw, tex_obj) ?
-   0 : INTEL_MIPTREE_IGNORE_CCS_E;
-  intel_miptree_all_slices_resolve_color(brw, tex_obj->mt, flags);
+  const enum intel_resolve_hint hint =
+ intel_texture_view_requires_resolve(brw, tex_obj) ? 0 :
+ INTEL_RESOLVE_HINT_IGNORE_CCS_E;
+  intel_miptree_all_slices_resolve_color(brw, tex_obj->mt, hint);
   brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);
 
   if (tex_obj->base.StencilSampling ||
@@ -313,9 +314,9 @@ intel_update_state(struct gl_context * ctx, GLuint 
new_state)
 intel_renderbuffer(fb->_ColorDrawBuffers[i]);
 
  if (irb &&
- intel_miptree_resolve_color(
-brw, irb->mt, irb->mt_level, irb->mt_layer, irb->layer_count,
-INTEL_MIPTREE_IGNORE_CCS_E))
+ intel_miptree_resolve_color(brw, irb->mt, irb->mt_level,
+ irb->mt_layer, irb->layer_count,
+ INTEL_RESOLVE_HINT_IGNORE_CCS_E))
 brw_render_cache_set_check_flush(brw, irb->mt->bo);
   }
}
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index cf81ea2..1d707ad 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -2235,7 +2235,7 @@ intel_miptree_used_for_rendering(const struct brw_context 
*brw,
 static bool
 intel_miptree_needs_color_resolve(const struct brw_context *brw,
   const struct intel_mipmap_tree *mt,
-  int flags)
+  enum intel_resolve_hint hint)
 {
if (mt->aux_disable & INTEL_AUX_DISABLE_CCS)
   return false;
@@ -2247,7 +2247,7 @@ intel_miptree_needs_color_resolve(const struct 
brw_context *brw,
 * surfaces called "lossless compressed". These don't need to be always
 * resolved.
 */
-   if ((flags & INTEL_MIPTREE_IGNORE_CCS_E) && is_lossless_compressed)
+   if ((hint == INTEL_RESOLVE_HINT_IGNORE_CCS_E) && is_lossless_compressed)
   return false;
 
/* Fast color clear resolves only make sense for non-MSAA buffers. */
@@ -2261,11 +2261,11 @@ bool
 intel_miptree_resolve_color(struct brw_context *brw,
 struct intel_mipmap_tree *mt, unsigned level,
 unsigned start_layer, unsigned num_layers,
-int flags)
+enum intel_resolve_hint hint)
 {
intel_miptree_check_color_resolve(brw, mt, level, 

[Mesa-dev] [PATCH v14 32/36] i965: Remove scanout restriction from lossless compression

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

v2: Try to keep the assert as recommended by Topi. This requires
modifying the num_samples check to be <= 1 because internally created
buffers set num_samples = 0.

v3: Buffers are proactively marked as scanout, often, and so checking
is_scanout in whether or not the buffer supports non-msrt fast clears
will return false. To avoid this, only check buffers which are destined
to use ccs (is a scanout buffer, and has an "mcs" buffer). Chad found
this issue.

v4: Use a better assertion based off of change in last patch. (Topi)

v5: Remove the assert entirely

Cc: Topi Pohjolainen 
Cc: Chad Versace 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index e2d124b..962d220 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -698,8 +698,7 @@ intel_miptree_create(struct brw_context *brw,
   const bool lossless_compression_disabled = INTEL_DEBUG & DEBUG_NO_RBC;
   const bool is_lossless_compressed =
  unlikely(!lossless_compression_disabled) &&
- brw->gen >= 9 && !mt->is_scanout &&
- intel_miptree_supports_lossless_compressed(brw, mt);
+ brw->gen >= 9 && intel_miptree_supports_lossless_compressed(brw, mt);
 
   if (is_lossless_compressed) {
  assert(!(mt->aux_disable & INTEL_AUX_DISABLE_CCS));
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 19/36] i965/miptree: Allocate mcs_buf for an image's CCS_E

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

This code will disable actually creating these buffers for the scanout,
but it puts the allocation in place.

Primarily this patch is split out for review, it can be squashed in
later if preferred.

v2:
assert(mt->offset == 0) in ccs creation (as requested by Topi)
Remove bogus is_scanout check in miptree_release

v3:
Remove is_scanout assert in intel_miptree_create. It doesn't work with
latest codebase - not sure it ever should have worked.

v4:
assert(mt->last_level == 0) and assert(mt->first_level == 0) in ccs setup
(Topi)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 92 +++
 1 file changed, 81 insertions(+), 11 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 10e4a32..20149c8 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -58,6 +58,11 @@ intel_miptree_alloc_mcs(struct brw_context *brw,
 struct intel_mipmap_tree *mt,
 GLuint num_samples);
 
+static void
+intel_miptree_init_mcs(struct brw_context *brw,
+   struct intel_mipmap_tree *mt,
+   int init_value);
+
 /**
  * Determine which MSAA layout should be used by the MSAA surface being
  * created, based on the chip generation and the surface type.
@@ -765,6 +770,45 @@ intel_miptree_create_for_bo(struct brw_context *brw,
return mt;
 }
 
+static bool
+create_ccs_buf_for_image(struct brw_context *intel,
+ __DRIimage *image,
+ struct intel_mipmap_tree *mt)
+{
+
+   struct isl_surf temp_main_surf;
+   struct isl_surf temp_ccs_surf;
+
+   /* There isn't anything specifically wrong with there being an offset, in
+* which case, the CCS miptree's offset should be mt->offset +
+* image->aux_offset. However, the code today only will have an offset when
+* this miptree is pointing to a slice from another miptree, and in that 
case
+* we'd need to offset within the AUX CCS buffer properly. It's questionable
+* whether our code handles that case properly, and since it can never 
happen
+* for scanout, just use the assertion to prevent it.
+*/
+   assert(mt->offset == 0);
+
+   intel_miptree_get_isl_surf(intel, mt, _main_surf);
+   if (!isl_surf_get_ccs_surf(>isl_dev, _main_surf, 
_ccs_surf))
+  return false;
+
+   mt->mcs_buf = calloc(1, sizeof(*mt->mcs_buf));
+   mt->mcs_buf->bo = image->bo;
+   brw_bo_reference(image->bo);
+
+   mt->mcs_buf->offset = image->aux_offset;
+   mt->mcs_buf->size = temp_ccs_surf.size;
+   mt->mcs_buf->pitch = temp_ccs_surf.row_pitch;
+   mt->mcs_buf->qpitch = isl_surf_get_array_pitch_sa_rows(_ccs_surf);
+
+   intel_miptree_init_mcs(intel, mt, 0);
+   mt->aux_disable &= ~INTEL_AUX_DISABLE_CCS;
+   mt->msaa_layout = INTEL_MSAA_LAYOUT_CMS;
+
+   return true;
+}
+
 struct intel_mipmap_tree *
 intel_miptree_create_for_image(struct brw_context *intel,
__DRIimage *image,
@@ -775,17 +819,43 @@ intel_miptree_create_for_image(struct brw_context *intel,
uint32_t pitch,
uint32_t layout_flags)
 {
-   assert(layout_flags == 0);
-   layout_flags = MIPTREE_LAYOUT_DISABLE_AUX;
-   return intel_miptree_create_for_bo(intel,
-  image->bo,
-  format,
-  offset,
-  width,
-  height,
-  1,
-  pitch,
-  layout_flags);
+   struct intel_mipmap_tree *mt;
+
+   /* Other flags will be ignored, so make sure the caller didn't pass any. */
+   assert((layout_flags & ~MIPTREE_LAYOUT_FOR_SCANOUT) == 0);
+
+   if (!image->aux_offset)
+  layout_flags |= MIPTREE_LAYOUT_DISABLE_AUX;
+   else
+  layout_flags |= MIPTREE_LAYOUT_FORCE_HALIGN16;
+
+   mt = intel_miptree_create_for_bo(intel,
+image->bo,
+format,
+offset,
+width,
+height,
+1,
+pitch,
+layout_flags);
+
+   if (!intel_tiling_supports_non_msrt_mcs(intel, mt->tiling)) {
+  assert(image->aux_offset == 0);
+  return mt;
+   }
+
+   if (layout_flags & MIPTREE_LAYOUT_DISABLE_AUX)
+  return mt;
+
+   assert(image->aux_offset);
+   assert(mt->num_samples <= 1);
+   assert(mt->first_level == 0);
+   

[Mesa-dev] [PATCH v14 10/36] st/dri: implement createImageWithModifiers in DRIimage

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

adds a pscreen->resource_create_with_modifiers() to create textures
with modifier.

v2:
- stylefixes (Emil Velikov)
- don't return selected modifier from resource_create_with_modifiers. we can
  use the winsys_handle to get this.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Lucas Stach <l.st...@pengutronix.de> (v1)
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/include/pipe/p_screen.h   | 15 +
 src/gallium/state_trackers/dri/dri2.c | 58 ---
 2 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 8b4239c..5102827 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -328,6 +328,21 @@ struct pipe_screen {
 * driver doesn't support an on-disk shader cache.
 */
struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
+
+   /**
+* Create a new texture object from the given template info, taking
+* format modifiers into account. \p modifiers specifies a list of format
+* modifier tokens, as defined in drm_fourcc.h. The driver then picks the
+* best modifier among these and creates the resource. \p count must
+* contain the size of \p modifiers array.
+*
+* Returns NULL if an entry in \p modifiers is unsupported by the driver,
+* or if only DRM_FORMAT_MOD_INVALID is provided.
+*/
+   struct pipe_resource * (*resource_create_with_modifiers)(
+   struct pipe_screen *,
+   const struct pipe_resource *templat,
+   const uint64_t *modifiers, int count);
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index fb1c829..59e6261 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -971,9 +971,12 @@ dri2_create_image_from_renderbuffer(__DRIcontext *context,
 }
 
 static __DRIimage *
-dri2_create_image(__DRIscreen *_screen,
-   int width, int height, int format,
-   unsigned int use, void *loaderPrivate)
+dri2_create_image_common(__DRIscreen *_screen,
+ int width, int height,
+ int format, unsigned int use,
+ const uint64_t *modifiers,
+ const unsigned count,
+ void *loaderPrivate)
 {
struct dri_screen *screen = dri_screen(_screen);
__DRIimage *img;
@@ -981,7 +984,13 @@ dri2_create_image(__DRIscreen *_screen,
unsigned tex_usage;
enum pipe_format pf;
 
+   /* createImageWithModifiers doesn't supply usage, and we should not get
+* here with both modifiers and a usage flag.
+*/
+   assert(!(use && (modifiers != NULL)));
+
tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
if (use & __DRI_IMAGE_USE_SCANOUT)
   tex_usage |= PIPE_BIND_SCANOUT;
if (use & __DRI_IMAGE_USE_SHARE)
@@ -1012,7 +1021,16 @@ dri2_create_image(__DRIscreen *_screen,
templ.depth0 = 1;
templ.array_size = 1;
 
-   img->texture = screen->base.screen->resource_create(screen->base.screen, 
);
+   if (modifiers)
+  img->texture =
+ screen->base.screen
+->resource_create_with_modifiers(screen->base.screen,
+ ,
+ modifiers,
+ count);
+   else
+  img->texture =
+ screen->base.screen->resource_create(screen->base.screen, );
if (!img->texture) {
   FREE(img);
   return NULL;
@@ -1028,6 +1046,28 @@ dri2_create_image(__DRIscreen *_screen,
return img;
 }
 
+static __DRIimage *
+dri2_create_image(__DRIscreen *_screen,
+   int width, int height, int format,
+   unsigned int use, void *loaderPrivate)
+{
+   return dri2_create_image_common(_screen, width, height, format, use,
+   NULL /* modifiers */, 0 /* count */,
+   loaderPrivate);
+}
+
+static __DRIimage *
+dri2_create_image_with_modifiers(__DRIscreen *dri_screen,
+ int width, int height, int format,
+ const uint64_t *modifiers,
+ const unsigned count,
+ void *loaderPrivate)
+{
+   return dri2_create_image_common(dri_screen, width, height, format,
+   0 /* use */, modifiers, count,
+   loaderPrivate);
+}
+
 static GLboolean
 dri2_query_image(__DRIimage *image, int attrib, int *value)
 {
@@ -1414,7 +1454,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during 

[Mesa-dev] [PATCH v14 24/36] i965/miptree: Add a return for updating of winsys

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

There is nothing particularly useful to do currently if the update
fails, but there is no point carrying on either. As a result, this has a
behavior change.

v2: Make the return type a bool (Topi)

v3: Don't leak the bo if update_winsys_renderbuffer fails. (Jason)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen  (v2)
---
 src/mesa/drivers/dri/i965/brw_context.c   | 16 ++--
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c |  6 +++---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h |  2 +-
 3 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index e2fd7b8..7af58cd 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1662,9 +1662,12 @@ intel_process_dri2_buffer(struct brw_context *brw,
   return;
}
 
-   intel_update_winsys_renderbuffer_miptree(brw, rb, bo,
-drawable->w, drawable->h,
-buffer->pitch);
+   if (!intel_update_winsys_renderbuffer_miptree(brw, rb, bo,
+ drawable->w, drawable->h,
+ buffer->pitch)) {
+  brw_bo_unreference(bo);
+  return;
+   }
 
if (_mesa_is_front_buffer_drawing(fb) &&
(buffer->attachment == __DRI_BUFFER_FRONT_LEFT ||
@@ -1723,9 +1726,10 @@ intel_update_image_buffer(struct brw_context *intel,
if (!buffer->aux_offset)
   rb->no_aux = true;
 
-   intel_update_winsys_renderbuffer_miptree(intel, rb, buffer->bo,
-buffer->width, buffer->height,
-buffer->pitch);
+   if (!intel_update_winsys_renderbuffer_miptree(intel, rb, buffer->bo,
+ buffer->width, buffer->height,
+ buffer->pitch))
+  return;
 
if (_mesa_is_front_buffer_drawing(fb) &&
buffer_type == __DRI_IMAGE_BUFFER_FRONT &&
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index ce62b9a..7592df6 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -871,7 +871,7 @@ intel_miptree_create_for_image(struct brw_context *intel,
  * that will contain the actual rendering (which is lazily resolved to
  * irb->singlesample_mt).
  */
-void
+bool
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
  struct intel_renderbuffer *irb,
  struct brw_bo *bo,
@@ -938,12 +938,12 @@ intel_update_winsys_renderbuffer_miptree(struct 
brw_context *intel,
  irb->mt = multisample_mt;
   }
}
-   return;
+   return true;
 
 fail:
intel_miptree_release(>singlesample_mt);
intel_miptree_release(>mt);
-   return;
+   return false;
 }
 
 struct intel_mipmap_tree*
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
index 8ec1278..15e8130 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
@@ -717,7 +717,7 @@ intel_miptree_create_for_image(struct brw_context *intel,
uint32_t pitch,
uint32_t layout_flags);
 
-void
+bool
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
  struct intel_renderbuffer *irb,
  struct brw_bo *bo,
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 22/36] i965: Allocate tile aligned height

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

This patch shouldn't actually do anything because the libdrm function
should already do this alignment. However, it preps us for a future
patch where we add in the CCS AUX size, and in the process it serves as
a good place to find bisectable issues if libdrm or kernel does
something incorrectly.

v2: Do proper alignment for X tiling, and make sure non-tiled case is
handled (Jason)
v3: Rebase (Daniel)

Cc: Jason Ekstrand 
Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 27 +++
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 53c6182..bf723f6 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -294,10 +294,14 @@ static struct intel_image_format intel_image_formats[] = {
 static const struct {
uint32_t tiling;
uint64_t modifier;
+   unsigned height_align;
 } tiling_modifier_map[] = {
-   { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR },
-   { .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED },
-   { .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED },
+   { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR,
+ .height_align = 1 },
+   { .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED,
+ .height_align = 8 },
+   { .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED,
+ .height_align = 32 },
 };
 
 static uint32_t
@@ -326,6 +330,19 @@ tiling_to_modifier(uint32_t tiling)
unreachable("tiling_to_modifier received unknown tiling mode");
 }
 
+static unsigned
+get_tiled_height(uint32_t tiling, unsigned height)
+{
+   int i;
+
+   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+  if (tiling_modifier_map[i].tiling == tiling)
+ return ALIGN(height, tiling_modifier_map[i].height_align);
+   }
+
+   unreachable("get_tiled_height received unknown tiling mode");
+}
+
 static void
 intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
 {
@@ -609,6 +626,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
struct intel_screen *screen = dri_screen->driverPrivate;
uint32_t tiling;
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+   unsigned tiled_height;
int cpp;
 
/* Callers of this may specify a modifier, or a dri usage, but not both. The
@@ -640,6 +658,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
   }
}
tiling = modifier_to_tiling(modifier);
+   tiled_height = get_tiled_height(tiling, height);
 
image = intel_allocate_image(screen, format, loaderPrivate);
if (image == NULL)
@@ -647,7 +666,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
 
cpp = _mesa_get_format_bytes(image->format);
image->bo = brw_bo_alloc_tiled(screen->bufmgr, "image",
-  width, height, cpp, tiling,
+  width, tiled_height, cpp, tiling,
   >pitch, 0);
if (image->bo == NULL) {
   free(image);
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 21/36] i965: add a no_aux field to identify buffers without aux data

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

v2: split this into a separate patch (Jason)

Signed-off-by: Ben Widawsky <b...@bwidawsk.net>
Signed-off-by: Daniel Stone <dani...@collabora.com>
Cc: Jason Ekstrand <ja...@jlekstrand.net>
---
 src/mesa/drivers/dri/i965/brw_context.c   | 3 +++
 src/mesa/drivers/dri/i965/intel_fbo.h | 7 +++
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 3 ++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
b/src/mesa/drivers/dri/i965/brw_context.c
index c815a04..e2fd7b8 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -1720,6 +1720,9 @@ intel_update_image_buffer(struct brw_context *intel,
if (last_mt && last_mt->bo == buffer->bo)
   return;
 
+   if (!buffer->aux_offset)
+  rb->no_aux = true;
+
intel_update_winsys_renderbuffer_miptree(intel, rb, buffer->bo,
 buffer->width, buffer->height,
 buffer->pitch);
diff --git a/src/mesa/drivers/dri/i965/intel_fbo.h 
b/src/mesa/drivers/dri/i965/intel_fbo.h
index 08b82e8..9265aab 100644
--- a/src/mesa/drivers/dri/i965/intel_fbo.h
+++ b/src/mesa/drivers/dri/i965/intel_fbo.h
@@ -111,6 +111,13 @@ struct intel_renderbuffer
 * for the duration of a mapping.
 */
bool singlesample_mt_is_tmp;
+
+   /**
+* Set to true if this buffer definitely does not have auxiliary data, like
+* CCS, associated with it. It's generally to be used when importing a
+* DRIimage, where that DRIimage had no modifier.
+*/
+   bool no_aux;
 };
 
 
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 2e3225e..ce62b9a 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -898,7 +898,8 @@ intel_update_winsys_renderbuffer_miptree(struct brw_context 
*intel,
  height,
  1,
  pitch,
- MIPTREE_LAYOUT_FOR_SCANOUT);
+ MIPTREE_LAYOUT_FOR_SCANOUT |
+ irb->no_aux ? 
MIPTREE_LAYOUT_DISABLE_AUX: 0);
if (!singlesample_mt)
   goto fail;
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 23/36] i965: Add logic for allocating BO with CCS

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

This patch provides the support (and comments) for allocating the BO
with space for the CCS buffer just underneath it.

This patch was originally titled:
"i965: Create correctly sized mcs for an image"

In order to make things more bisectable, reviewable, and to have the
CCS_MODIFIER token saved for the last patch, this patch now does less so
it was renamed.

v2: Leave "image+mod" (Topi)

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
Reviewed-by: Topi Pohjolainen 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 35 
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index bf723f6..9509ba2 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -627,6 +627,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
uint32_t tiling;
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
unsigned tiled_height;
+   unsigned ccs_height = 0;
int cpp;
 
/* Callers of this may specify a modifier, or a dri usage, but not both. The
@@ -664,10 +665,33 @@ intel_create_image_common(__DRIscreen *dri_screen,
if (image == NULL)
   return NULL;
 
+   /*
+* CCS width is always going to be less than or equal to the image's width.
+* All we need to do is make sure we add extra rows (height) for the CCS.
+*
+* A pair of CCS bits correspond to 8x4 pixels, and must be cacheline
+* granularity. Each CCS tile is laid out in 8b strips, which corresponds to
+* 1024x512 pixel region. In memory, it looks like the following:
+*
+* ┌─┐
+* │ │
+* │ │
+* │ │
+* │  Image  │
+* │ │
+* │ │
+* │x│
+* ├─┬───┘
+* │ │   |
+* │ccs  │  unused   |
+* └─┘---┘
+* <--pitch-->
+*/
cpp = _mesa_get_format_bytes(image->format);
-   image->bo = brw_bo_alloc_tiled(screen->bufmgr, "image",
-  width, tiled_height, cpp, tiling,
-  >pitch, 0);
+   image->bo = brw_bo_alloc_tiled(screen->bufmgr,
+  ccs_height ? "image+ccs" : "image+mod",
+  width, tiled_height + ccs_height,
+  cpp, tiling, >pitch, 0);
if (image->bo == NULL) {
   free(image);
   return NULL;
@@ -676,7 +700,10 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->height = height;
image->modifier = modifier;
 
-   image->aux_offset = 0; /* y_tiled_height * pitch */
+   if (ccs_height)
+  image->aux_offset = tiled_height * image->pitch /* + mt->offset */;
+   else
+  image->aux_offset = 0;
 
return image;
 }
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 11/36] st/dri: implement DRIimage creation from dmabufs with modifiers

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

support importing dmabufs into DRIimage while taking format modifiers
in account, as per DRIimage extension version 15.

v2: initialize winsys modifier to DRM_FORMAT_MOD_INVALID (Daniel Stone)
v3: do not bump DRIimageExtension version. split out winsys changes.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/state_trackers/dri/dri2.c | 45 +++
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 59e6261..b29a8de 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -888,8 +888,8 @@ dri2_create_image_from_name(__DRIscreen *_screen,
 static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
   int width, int height, int fourcc,
-  int *fds, int num_fds, int *strides,
-  int *offsets, unsigned *error,
+  uint64_t modifier, int *fds, int num_fds,
+  int *strides, int *offsets, unsigned *error,
   int *dri_components, void *loaderPrivate)
 {
struct winsys_handle whandles[3];
@@ -934,7 +934,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
-  whandles[i].modifier = DRM_FORMAT_MOD_INVALID;
+  whandles[i].modifier = modifier;
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1311,7 +1311,8 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, NULL,
+   DRM_FORMAT_MOD_INVALID, fds, num_fds,
+   strides, offsets, NULL,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1336,7 +1337,8 @@ dri2_from_dma_bufs(__DRIscreen *screen,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, error,
+   DRM_FORMAT_MOD_INVALID, fds, num_fds,
+   strides, offsets, error,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1351,6 +1353,37 @@ dri2_from_dma_bufs(__DRIscreen *screen,
return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+int width, int height, int fourcc,
+uint64_t modifier, int *fds, int num_fds,
+int *strides, int *offsets,
+enum __DRIYUVColorSpace yuv_color_space,
+enum __DRISampleRange sample_range,
+enum __DRIChromaSiting horizontal_siting,
+enum __DRIChromaSiting vertical_siting,
+unsigned *error,
+void *loaderPrivate)
+{
+   __DRIimage *img;
+   int dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+   modifier, fds, num_fds, strides, offsets,
+   error, _components, loaderPrivate);
+   if (img == NULL)
+  return NULL;
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
 static void
 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
 int dstx0, int dsty0, int dstwidth, int dstheight,
@@ -2021,6 +2054,7 @@ dri2_init_screen(__DRIscreen * sPriv)
   (cap & DRM_PRIME_CAP_IMPORT)) {
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
+ dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   }
}
 
@@ -2097,6 +2131,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   (cap & DRM_PRIME_CAP_IMPORT)) {
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
+  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 12/36] st/dri: support format queries

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported dmabuf formats

v2: rebase to master.
v3: return false on failure.
v4: use pscreen->is_format_supported instead of adding a new query.
(Lucas Stach)
v5: stylefix to conform to formatting rules (Brian Paul). add fourcc list
here instead of using struct image_format from v4.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Lucas Stach <l.st...@pengutronix.de> (v4)
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/state_trackers/dri/dri2.c | 118 ++
 1 file changed, 118 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index b29a8de..864dbcd 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -56,6 +56,33 @@
 #define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
 #endif
 
+static const int fourcc_formats[] = {
+   __DRI_IMAGE_FOURCC_ARGB,
+   __DRI_IMAGE_FOURCC_ABGR,
+   __DRI_IMAGE_FOURCC_SARGB,
+   __DRI_IMAGE_FOURCC_XRGB,
+   __DRI_IMAGE_FOURCC_XBGR,
+   __DRI_IMAGE_FOURCC_ARGB1555,
+   __DRI_IMAGE_FOURCC_RGB565,
+   __DRI_IMAGE_FOURCC_R8,
+   __DRI_IMAGE_FOURCC_R16,
+   __DRI_IMAGE_FOURCC_GR88,
+   __DRI_IMAGE_FOURCC_GR1616,
+   __DRI_IMAGE_FOURCC_YUV410,
+   __DRI_IMAGE_FOURCC_YUV411,
+   __DRI_IMAGE_FOURCC_YUV420,
+   __DRI_IMAGE_FOURCC_YUV422,
+   __DRI_IMAGE_FOURCC_YUV444,
+   __DRI_IMAGE_FOURCC_YVU410,
+   __DRI_IMAGE_FOURCC_YVU411,
+   __DRI_IMAGE_FOURCC_YVU420,
+   __DRI_IMAGE_FOURCC_YVU422,
+   __DRI_IMAGE_FOURCC_YVU444,
+   __DRI_IMAGE_FOURCC_NV12,
+   __DRI_IMAGE_FOURCC_NV16,
+   __DRI_IMAGE_FOURCC_YUYV
+};
+
 static int convert_fourcc(int format, int *dri_components_p)
 {
int dri_components;
@@ -176,6 +203,70 @@ static enum pipe_format dri2_format_to_pipe_format (int 
format)
return pf;
 }
 
+static enum pipe_format fourcc_to_pipe_format(int fourcc)
+{
+   enum pipe_format pf;
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_R8:
+  pf = PIPE_FORMAT_R8_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_GR88:
+  pf = PIPE_FORMAT_RG88_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ARGB1555:
+  pf = PIPE_FORMAT_B5G5R5A1_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_R16:
+  pf = PIPE_FORMAT_R16_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_GR1616:
+  pf = PIPE_FORMAT_RG1616_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_RGB565:
+  pf = PIPE_FORMAT_B5G6R5_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ARGB:
+  pf = PIPE_FORMAT_BGRA_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_XRGB:
+  pf = PIPE_FORMAT_BGRX_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ABGR:
+  pf = PIPE_FORMAT_RGBA_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_XBGR:
+  pf = PIPE_FORMAT_RGBX_UNORM;
+  break;
+
+   case __DRI_IMAGE_FOURCC_NV12:
+  pf = PIPE_FORMAT_NV12;
+  break;
+   case __DRI_IMAGE_FOURCC_YUYV:
+  pf = PIPE_FORMAT_YUYV;
+  break;
+   case __DRI_IMAGE_FOURCC_YUV420:
+   case __DRI_IMAGE_FOURCC_YVU420:
+  pf = PIPE_FORMAT_YV12;
+  break;
+
+   case __DRI_IMAGE_FOURCC_SARGB:
+   case __DRI_IMAGE_FOURCC_YUV410:
+   case __DRI_IMAGE_FOURCC_YUV411:
+   case __DRI_IMAGE_FOURCC_YUV422:
+   case __DRI_IMAGE_FOURCC_YUV444:
+   case __DRI_IMAGE_FOURCC_NV16:
+   case __DRI_IMAGE_FOURCC_YVU410:
+   case __DRI_IMAGE_FOURCC_YVU411:
+   case __DRI_IMAGE_FOURCC_YVU422:
+   case __DRI_IMAGE_FOURCC_YVU444:
+   default:
+  pf = PIPE_FORMAT_NONE;
+   }
+
+   return pf;
+}
+
 /**
  * DRI2 flush extension.
  */
@@ -1321,6 +1412,31 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static boolean
+dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
+   int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   const unsigned bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+   int i, j;
+
+   for (i = 0, j = 0; (i < ARRAY_SIZE(fourcc_formats)) &&
+ (j < max || max == 0); i++) {
+  if (pscreen->is_format_supported(pscreen,
+   fourcc_to_pipe_format(
+  fourcc_formats[i]),
+   screen->target,
+   0, bind)) {
+ if (j < max)
+formats[j] = fourcc_formats[i];
+ j++;
+  }
+   }
+   *count = j;
+   return true;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -2055,6 +2171,7 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2I

[Mesa-dev] [PATCH v14 17/36] i965: Support images with offset aux buffers

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

Previously our aux buffers (MCS, and HiZ) never had an offset because
they were in their own buffer object. When using the CCS lossless
compression feature, it's desirable to store the data at an offset from
the main framebuffer, ie. share a buffer object. This patch just makes
having an aux offset possible.

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_image.h  | 3 +++
 src/mesa/drivers/dri/i965/intel_screen.c | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_image.h 
b/src/mesa/drivers/dri/i965/intel_image.h
index ad42691..7153b73 100644
--- a/src/mesa/drivers/dri/i965/intel_image.h
+++ b/src/mesa/drivers/dri/i965/intel_image.h
@@ -92,6 +92,9 @@ struct __DRIimageRec {
/** The image was created with EGL_EXT_image_dma_buf_import. */
bool dma_buf_imported;
 
+   /** The image has some ancillary data associated with it at offset. */
+   uint32_t aux_offset;
+
/**
 * Provided by EGL_EXT_image_dma_buf_import.
 * \{
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 028598b..53c6182 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -657,6 +657,8 @@ intel_create_image_common(__DRIscreen *dri_screen,
image->height = height;
image->modifier = modifier;
 
+   image->aux_offset = 0; /* y_tiled_height * pitch */
+
return image;
 }
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 13/36] gallium: introduce format modifier querying

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

format modifiers tokens are driver specific, and hence, need to come
in from the driver. this allows drivers to be queried for supported
format modifiers for EGL_EXT_image_dma_buf_import_modifiers.

v2: rebase to master.
v3: drivers must return false on query failure.
v4: use pscreen->is_format_supported instead of adding a separate
format query handle, remove PIPE_CAP_QUERY_DMABUF_ATTRIBS.
(Lucas Stach)
v5: add external_only parameter.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/include/pipe/p_screen.h | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 5102827..65e954a 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -343,6 +343,20 @@ struct pipe_screen {
struct pipe_screen *,
const struct pipe_resource *templat,
const uint64_t *modifiers, int count);
+
+   /**
+* Get supported modifiers for a format.
+* If \p max is 0, the total number of supported modifiers for the supplied
+* format is returned in \p count, with no modification to \p modifiers.
+* Otherwise, \p modifiers is filled with upto \p max supported modifier
+* codes, and \p count with the number of modifiers copied.
+* The \p external_only array is used to return whether the format and
+* modifier combination can only be used with an external texture target.
+*/
+   void (*query_dmabuf_modifiers)(struct pipe_screen *screen,
+  enum pipe_format format, int max,
+  uint64_t *modifiers,
+  unsigned int *external_only, int *count);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 18/36] i965/miptree: Add a helper function for image creation

2017-05-30 Thread Varad Gautam
From: Ben Widawsky 

This provides a common function or creating miptrees when there is an
existing DRIimage to use. That provides an easy way to add CCS
allocation.

v2: Make the new function assume there are always no layout flags. This
will be adjusted later.

Signed-off-by: Ben Widawsky 
Acked-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_fbo.c | 17 -
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 25 -
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h | 10 ++
 src/mesa/drivers/dri/i965/intel_tex_image.c   | 17 -
 4 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_fbo.c 
b/src/mesa/drivers/dri/i965/intel_fbo.c
index 60a6d0f..a4dbd2f 100644
--- a/src/mesa/drivers/dri/i965/intel_fbo.c
+++ b/src/mesa/drivers/dri/i965/intel_fbo.c
@@ -362,15 +362,14 @@ intel_image_target_renderbuffer_storage(struct gl_context 
*ctx,
 * buffer's content to the main buffer nor for invalidating the aux buffer's
 * content.
 */
-   irb->mt = intel_miptree_create_for_bo(brw,
- image->bo,
- image->format,
- image->offset,
- image->width,
- image->height,
- 1,
- image->pitch,
- MIPTREE_LAYOUT_DISABLE_AUX);
+   irb->mt = intel_miptree_create_for_image(brw,
+image,
+image->format,
+image->offset,
+image->width,
+image->height,
+image->pitch,
+0);
if (!irb->mt)
   return;
 
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
index 6acf48e..10e4a32 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
@@ -24,7 +24,6 @@
  */
 
 #include 
-#include 
 
 #include "intel_batchbuffer.h"
 #include "intel_mipmap_tree.h"
@@ -32,6 +31,7 @@
 #include "intel_tex.h"
 #include "intel_blit.h"
 #include "intel_fbo.h"
+#include "intel_image.h"
 
 #include "brw_blorp.h"
 #include "brw_context.h"
@@ -765,6 +765,29 @@ intel_miptree_create_for_bo(struct brw_context *brw,
return mt;
 }
 
+struct intel_mipmap_tree *
+intel_miptree_create_for_image(struct brw_context *intel,
+   __DRIimage *image,
+   mesa_format format,
+   uint32_t offset,
+   uint32_t width,
+   uint32_t height,
+   uint32_t pitch,
+   uint32_t layout_flags)
+{
+   assert(layout_flags == 0);
+   layout_flags = MIPTREE_LAYOUT_DISABLE_AUX;
+   return intel_miptree_create_for_bo(intel,
+  image->bo,
+  format,
+  offset,
+  width,
+  height,
+  1,
+  pitch,
+  layout_flags);
+}
+
 /**
  * For a singlesample renderbuffer, this simply wraps the given BO with a
  * miptree.
diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h 
b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
index 7aabac0..8ec1278 100644
--- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
+++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.h
@@ -707,6 +707,16 @@ intel_miptree_create_for_bo(struct brw_context *brw,
 int pitch,
 uint32_t layout_flags);
 
+struct intel_mipmap_tree *
+intel_miptree_create_for_image(struct brw_context *intel,
+   __DRIimage *image,
+   mesa_format format,
+   uint32_t offset,
+   uint32_t width,
+   uint32_t height,
+   uint32_t pitch,
+   uint32_t layout_flags);
+
 void
 intel_update_winsys_renderbuffer_miptree(struct brw_context *intel,
  struct intel_renderbuffer *irb,
diff --git a/src/mesa/drivers/dri/i965/intel_tex_image.c 
b/src/mesa/drivers/dri/i965/intel_tex_image.c
index 7208d8e..0906caa 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_image.c
+++ b/src/mesa/drivers/dri/i965/intel_tex_image.c

[Mesa-dev] [PATCH v14 08/36] gallium/winsys/drm: introduce modifier field to winsys_handle

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

we use this to import resources with format modifiers, and to support
per-resource modifier queries.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/include/state_tracker/drm_driver.h | 6 ++
 src/gallium/state_trackers/dri/dri2.c  | 7 +++
 2 files changed, 13 insertions(+)

diff --git a/src/gallium/include/state_tracker/drm_driver.h 
b/src/gallium/include/state_tracker/drm_driver.h
index c80fb09..88dda0a 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -45,6 +45,12 @@ struct winsys_handle
 * Output for texture_get_handle.
 */
unsigned offset;
+
+   /**
+* Input to resource_from_handle.
+* Output from resource_get_handle.
+*/
+   uint64_t modifier;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index ed6004f..f1794b7 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -52,6 +52,10 @@
 #include "dri_query_renderer.h"
 #include "dri2_buffer.h"
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
 static int convert_fourcc(int format, int *dri_components_p)
 {
int dri_components;
@@ -869,6 +873,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
memset(, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
whandle.handle = name;
+   whandle.modifier = DRM_FORMAT_MOD_INVALID;
 
pf = dri2_format_to_pipe_format (format);
if (pf == PIPE_FORMAT_NONE)
@@ -929,6 +934,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
+  whandles[i].modifier = DRM_FORMAT_MOD_INVALID;
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1143,6 +1149,7 @@ dri2_from_names(__DRIscreen *screen, int width, int 
height, int format,
whandle.handle = names[0];
whandle.stride = strides[0];
whandle.offset = offsets[0];
+   whandle.modifier = DRM_FORMAT_MOD_INVALID;
 
img = dri2_create_image_from_winsys(screen, width, height, format,
1, , loaderPrivate);
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 15/36] i965: Improve same-buffer restriction for imports

2017-05-30 Thread Varad Gautam
From: Daniel Stone <dani...@collabora.com>

Intel hardware requires that all planes of an image come from the same
buffer, which is currently implemented by testing that all FDs are
numerically the same.

However, when going through a winsys (e.g.) or anything which transits
FDs individually, the FDs may be different even if the underlying buffer
is the same.

Instead of checking the FDs for equality, we must check if they actually
point to the same buffer (Jason).

Signed-off-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index 9842de6..ddaa8cf 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -815,20 +815,32 @@ intel_create_image_from_fds(__DRIscreen *dri_screen,
struct intel_screen *screen = dri_screen->driverPrivate;
struct intel_image_format *f;
__DRIimage *image;
-   int i, index;
+   struct brw_bo *bo;
+   int i, index, size = 0;
 
if (fds == NULL || num_fds < 1)
   return NULL;
 
-   /* We only support all planes from the same bo */
-   for (i = 0; i < num_fds; i++)
-  if (fds[0] != fds[i])
- return NULL;
-
f = intel_image_format_lookup(fourcc);
if (f == NULL)
   return NULL;
 
+   for (i = 0; i < f->nplanes; i++) {
+  index = f->planes[i].buffer_index;
+  const int plane_height = height >> f->planes[i].height_shift;
+  const int end = offsets[index] + plane_height * strides[index];
+  if (size < end)
+ size = end;
+   }
+   /* We only support all planes from the same bo.
+* brw_bo_gem_create_from_prime() should return the same pointer for all
+* fds received here */
+   bo = brw_bo_gem_create_from_prime(screen->bufmgr, fds[0], size);
+   for (i = 1; i < num_fds; i++) {
+  if (bo != brw_bo_gem_create_from_prime(screen->bufmgr, fds[i], size))
+ return NULL;
+   }
+
if (f->nplanes == 1)
   image = intel_allocate_image(screen, f->planes[0].dri_format,
loaderPrivate);
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 14/36] st/dri: support format modifier queries

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.

v2: move to __DRIimageExtension v16.
v3: fail if the supplied format is not supported by driver.
v4: purge PIPE_CAP_QUERY_DMABUF_ATTRIBS.
v5:
- move to __DRIimageExtension v15, pass external_only to the driver.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Lucas Stach <l.st...@pengutronix.de> (v4)
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/state_trackers/dri/dri2.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 864dbcd..b864053 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1437,6 +1437,25 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int 
max, int *formats,
return true;
 }
 
+static boolean
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, unsigned int *external_only,
+ int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   enum pipe_format format = fourcc_to_pipe_format(fourcc);
+   const unsigned usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
+   if (pscreen->query_dmabuf_modifiers != NULL &&
+   pscreen->is_format_supported(pscreen, format, screen->target, 0, 
usage)) {
+  pscreen->query_dmabuf_modifiers(pscreen, format, max, modifiers,
+  external_only, count);
+  return true;
+   }
+   return false;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1603,7 +1622,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 14 },
+.base = { __DRI_IMAGE, 15 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -2172,6 +2191,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2250,6 +2271,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 16/36] i965: Invert image modifier/tiling inference

2017-05-30 Thread Varad Gautam
From: Daniel Stone 

When allocating images, we record a tiling mode and then work backwards
to infer the modifier. Unfortunately this is the wrong way around, since
it is a one:many mapping (e.g. TILING_Y can be plain Y-tiling, or
Y-tiling with CCS).

Invert the mapping, so we record a modifier first and then map this to a
tiling mode.

Signed-off-by: Daniel Stone 
---
 src/mesa/drivers/dri/i965/intel_screen.c | 35 
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c 
b/src/mesa/drivers/dri/i965/intel_screen.c
index ddaa8cf..028598b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -608,6 +608,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
uint32_t tiling;
+   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
int cpp;
 
/* Callers of this may specify a modifier, or a dri usage, but not both. The
@@ -616,29 +617,29 @@ intel_create_image_common(__DRIscreen *dri_screen,
 */
assert(!(use && count));
 
-   uint64_t modifier = select_best_modifier(>devinfo, modifiers, 
count);
-   if (modifier == DRM_FORMAT_MOD_INVALID) {
-  /* User requested specific modifiers, none of which work */
-  if (modifiers)
- return NULL;
-
-  /* Historically, X-tiled was the default, and so lack of modifier means
-   * X-tiled.
-   */
-  tiling = I915_TILING_X;
-   } else {
-  /* select_best_modifier has found a modifier we support */
-  tiling = modifier_to_tiling(modifier);
-   }
-
if (use & __DRI_IMAGE_USE_CURSOR) {
   if (width != 64 || height != 64)
 return NULL;
-  tiling = I915_TILING_NONE;
+  modifier = DRM_FORMAT_MOD_LINEAR;
}
 
if (use & __DRI_IMAGE_USE_LINEAR)
-  tiling = I915_TILING_NONE;
+  modifier = DRM_FORMAT_MOD_LINEAR;
+
+   if (modifier == DRM_FORMAT_MOD_INVALID) {
+  if (modifiers) {
+ /* User requested specific modifiers */
+ modifier = select_best_modifier(>devinfo, modifiers, count);
+ if (modifier == DRM_FORMAT_MOD_INVALID)
+return NULL;
+  } else {
+ /* Historically, X-tiled was the default, and so lack of modifier 
means
+  * X-tiled.
+  */
+ modifier = I915_FORMAT_MOD_X_TILED;
+  }
+   }
+   tiling = modifier_to_tiling(modifier);
 
image = intel_allocate_image(screen, format, loaderPrivate);
if (image == NULL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 06/36] egl: implement eglQueryDmaBufModifiersEXT

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

v2: move format check to the driver instead of making format queries
   here and then checking.
v3: Check DRIimageExtension version before query (Daniel Stone)
v4:
- move to DRIimageExtension version 15, check queryDmaBufModifiers before
  calling (Jason Ekstrand)
- pass external_only to the driver instead of setting as EGL_TRUE here
  (Emil Velikov, Daniel Stone)

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 33 +
 src/egl/main/eglapi.c   | 20 
 src/egl/main/eglapi.h   |  5 +
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 59 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c271552..bcafdf9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2178,6 +2178,38 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   if (dri2_dpy->image->base.version < 15 ||
+   dri2_dpy->image->queryDmaBufModifiers == NULL)
+  return EGL_FALSE;
+
+   if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
+ max, modifiers,
+ (unsigned int *) external_only,
+ count) == false) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3116,6 +3148,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index d613920..a4d5f89 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2404,6 +2404,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index c9f9896..cab3e96 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -202,6 +202,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *modifiers,
+  EGLBoolean *external_only,
+  EGLint *num_modifiers);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index 9153623..b9dca7c 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -57,6 +57,7 @@ 

[Mesa-dev] [PATCH v14 09/36] st/dri: enable DRIimage modifier queries

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

return the modifier selected by the driver when creating this image.

v2: since we can use winsys_handle->modifier to serve these, remove
DRIimage->modifier from v1.
use DRM_API_HANDLE_TYPE_KMS instead of DRM_API_HANDLE_TYPE_FD to avoid
ownership transfer. (Lucas)

Suggested-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Cc: Lucas Stach <l.st...@pengutronix.de>
---
 src/gallium/state_trackers/dri/dri2.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index f1794b7..fb1c829 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1088,6 +1088,18 @@ dri2_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_NUM_PLANES:
   *value = 1;
   return GL_TRUE;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  whandle.type = DRM_API_HANDLE_TYPE_KMS;
+  image->texture->screen->resource_get_handle(image->texture->screen,
+NULL, image->texture, , usage);
+  *value = (whandle.modifier >> 32) & 0x;
+  return GL_TRUE;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  whandle.type = DRM_API_HANDLE_TYPE_KMS;
+  image->texture->screen->resource_get_handle(image->texture->screen,
+NULL, image->texture, , usage);
+  *value = whandle.modifier & 0x;
+  return GL_TRUE;
default:
   return GL_FALSE;
}
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 02/36] egl/main: add support for fourth plane tokens

2017-05-30 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

The EGL_EXT_dma_buf_import_modifiers extension adds support for a
fourth plane, just like DRM KMS API does.

Bump maximum dma_buf plane count to four.

v2: prevent attribute tokens from being parsed if
EXT_image_dma_buf_import_modifiers is not suported. (Emil Velikov)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c |  2 +-
 src/egl/main/egldisplay.h   |  1 +
 src/egl/main/eglimage.c | 18 ++
 src/egl/main/eglimage.h |  5 +++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a2c9e41..8f0f1b3 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2090,7 +2090,7 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
 * "If  is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
 *  attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
 *  generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
-*  attributes are specified."
+*  or EGL_DMA_BUF_PLANE3_* attributes are specified."
 */
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 4d3d96e..9685bed 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -102,6 +102,7 @@ struct _egl_extensions
EGLBoolean EXT_buffer_age;
EGLBoolean EXT_create_context_robustness;
EGLBoolean EXT_image_dma_buf_import;
+   EGLBoolean EXT_image_dma_buf_import_modifiers;
EGLBoolean EXT_swap_buffers_with_damage;
 
EGLBoolean KHR_cl_event2;
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index d062cbf..fed390a 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -130,6 +130,24 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, 
_EGLDisplay *dpy,
  attrs->DMABufPlanePitches[2].Value = val;
  attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
  break;
+  case EGL_DMA_BUF_PLANE3_FD_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneFds[3].Value = val;
+ attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneOffsets[3].Value = val;
+ attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_PITCH_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlanePitches[3].Value = val;
+ attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
+ break;
   case EGL_YUV_COLOR_SPACE_HINT_EXT:
  if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
  val != EGL_ITU_REC2020_EXT) {
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 9a75d0c..a909d9b 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -46,7 +46,7 @@ struct _egl_image_attrib_int
EGLBoolean IsPresent;
 };
 
-#define DMA_BUF_MAX_PLANES 3
+#define DMA_BUF_MAX_PLANES 4
 
 struct _egl_image_attribs
 {
@@ -67,7 +67,8 @@ struct _egl_image_attribs
/* EGL_WL_bind_wayland_display */
EGLint PlaneWL;
 
-   /* EGL_EXT_image_dma_buf_import */
+   /* EGL_EXT_image_dma_buf_import and
+* EGL_EXT_image_dma_buf_import_modifiers */
struct _egl_image_attrib_int DMABufFourCC;
struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 00/36] EGL_EXT_image_dma_buf_import_modifiers with i915 CCS

2017-05-30 Thread Varad Gautam
Hi all,

Thanks for the reviews on v13, here's a new iteration of the egl modifiers
series.

The notable changes since v13 was sent by Daniel include:

* All dmabuf related functions in DRIimageExtension are now added under the
same version bump.

* Since modifier queries on a DRIimage can be handled via the winsys handle
on gallium, st/DRIimage no longer has a modifiers field, and
pscreen->resource_create_with_modifiers() does not need to return the
driver-selected modifier anymore. Thanks Lucas for suggesting this option.

* I have dropped the gallium multiplane import-refactor patch from this
series. Since not all gallium drivers would want to import a resource in the
same way (eg. etnaviv would rather sample a YUYV image as a single
pipe_resouce, while some other driver might consume it as multiple
overlapping resources with RG88/RGBA samplers), it is incorrect to
assume that we can get away with this without taking the driver's vote into
account, and we can move this out of the modifiers series.

* Stricter error checks all over, style fixes etc.

Ben Widawsky (16):
  i965: Support images with offset aux buffers
  i965/miptree: Add a helper function for image creation
  i965/miptree: Allocate mcs_buf for an image's CCS_E
  i965: Restructure CCS disabling
  i965: Allocate tile aligned height
  i965: Add logic for allocating BO with CCS
  i965/miptree: Add a return for updating of winsys
  i965/miptree: Allocate mt earlier in update winsys
  i965: Pretend that CCS modified images are two planes
  i965: Change resolve flags to enum
  i965: Plumb resolve hints from miptrees to blorp
  i965: Add new resolve hints full and partial
  i965: Use partial resolves for CCS buffers being scanned out
  i965/miptree: Remove dead code assertion
  i965: Remove scanout restriction from lossless compression
  i965: Handle compression modifier

Daniel Stone (3):
  i965: Improve same-buffer restriction for imports
  i965: Invert image modifier/tiling inference
  i965: Add tiling mode to BO import

Pekka Paalanen (2):
  egl: introduce DMA_BUF_MAX_PLANES
  egl/main: add support for fourth plane tokens

Varad Gautam (15):
  dri: introduce dmabuf format modifier related handles
  egl/dri2: Create EGLImages with dmabuf modifiers
  egl: implement eglQueryDmaBufFormatsEXT
  egl: implement eglQueryDmaBufModifiersEXT
  egl: advertise EGL_EXT_image_dma_buf_import_modifiers
  gallium/winsys/drm: introduce modifier field to winsys_handle
  st/dri: enable DRIimage modifier queries
  st/dri: implement createImageWithModifiers in DRIimage
  st/dri: implement DRIimage creation from dmabufs with modifiers
  st/dri: support format queries
  gallium: introduce format modifier querying
  st/dri: support format modifier queries
  i965: add a no_aux field to identify buffers without aux data
  i965: Support dmabuf import with modifiers
  i965: Add format/modifier advertising

 include/GL/internal/dri_interface.h|  63 +++-
 src/egl/drivers/dri2/egl_dri2.c| 179 ++-
 src/egl/main/eglapi.c  |  39 +++
 src/egl/main/eglapi.h  |   9 +
 src/egl/main/egldisplay.h  |   1 +
 src/egl/main/eglentrypoint.h   |   2 +
 src/egl/main/eglimage.c|  66 
 src/egl/main/eglimage.h|  13 +-
 src/gallium/include/pipe/p_screen.h|  29 ++
 src/gallium/include/state_tracker/drm_driver.h |   6 +
 src/gallium/state_trackers/dri/dri2.c  | 260 ++-
 src/mesa/drivers/dri/i965/brw_blorp.c  |  14 +-
 src/mesa/drivers/dri/i965/brw_blorp.h  |   3 +-
 src/mesa/drivers/dri/i965/brw_bufmgr.c |  12 +-
 src/mesa/drivers/dri/i965/brw_bufmgr.h |   3 +-
 src/mesa/drivers/dri/i965/brw_context.c|  56 +++-
 src/mesa/drivers/dri/i965/intel_fbo.c  |  17 +-
 src/mesa/drivers/dri/i965/intel_image.h|   3 +
 src/mesa/drivers/dri/i965/intel_mipmap_tree.c  | 175 ---
 src/mesa/drivers/dri/i965/intel_mipmap_tree.h  |  29 +-
 src/mesa/drivers/dri/i965/intel_screen.c   | 418 +
 src/mesa/drivers/dri/i965/intel_tex_image.c|  17 +-
 22 files changed, 1229 insertions(+), 185 deletions(-)

-- 
2.10.0

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


[Mesa-dev] [PATCH v14 07/36] egl: advertise EGL_EXT_image_dma_buf_import_modifiers

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

v2: check for DRIimageExtension version 15 (Jason Ekstrand)

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 6 ++
 src/egl/main/eglapi.c   | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bcafdf9..d31a0bf 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -726,6 +726,12 @@ dri2_setup_screen(_EGLDisplay *disp)
   dri2_dpy->image->createImageFromDmaBufs) {
  disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE;
   }
+  if (dri2_dpy->image->base.version >= 15 &&
+  dri2_dpy->image->createImageFromDmaBufs2 &&
+  dri2_dpy->image->queryDmaBufFormats &&
+  dri2_dpy->image->queryDmaBufModifiers) {
+ disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
+  }
 #endif
}
 }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index a4d5f89..e6355ac 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -488,6 +488,7 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
_EGL_CHECK_EXTENSION(EXT_buffer_age);
_EGL_CHECK_EXTENSION(EXT_create_context_robustness);
_EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
+   _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
_EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
 
_EGL_CHECK_EXTENSION(KHR_cl_event2);
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 03/36] dri: introduce dmabuf format modifier related handles

2017-05-30 Thread Varad Gautam
these allow dmabuf import with modifiers, and supported format and
modifier queries, which are used to implement
EGL_EXT_image_dma_buf_import_modifiers.

v2:
- squash dmabuf queries into DRIimage version 15 (Jason Ekstrand).
- add external_only param to queryDmaBufModifiers (Emil, Daniel Stone)
- pass a single modifier form createImageFromDmaBufs2 since all planes have
the same modifier (Jason Ekstrand)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
---
 include/GL/internal/dri_interface.h | 63 -
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index ffe9949..fc2d4bb 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1137,7 +1137,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 14
+#define __DRI_IMAGE_VERSION 15
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1494,6 +1494,67 @@ struct __DRIimageExtensionRec {
const uint64_t *modifiers,
const unsigned int modifier_count,
void *loaderPrivate);
+
+   /*
+* Like createImageFromDmaBufs, but takes also format modifiers.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 15
+*/
+   __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
+  int width, int height, int fourcc,
+  uint64_t modifier,
+  int *fds, int num_fds,
+  int *strides, int *offsets,
+  enum __DRIYUVColorSpace color_space,
+  enum __DRISampleRange sample_range,
+  enum __DRIChromaSiting horiz_siting,
+  enum __DRIChromaSiting vert_siting,
+  unsigned *error,
+  void *loaderPrivate);
+
+   /*
+* dmabuf format query to support EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param max  Maximum number of formats that can be accomodated into
+* \param formats. If zero, no formats are returned -
+* instead, the driver returns the total number of
+* supported dmabuf formats in \param count.
+* \param formats  Buffer to fill formats into.
+* \param countCount of formats returned, or, total number of
+* supported formats in case \param max is zero.
+*
+* Returns true on success.
+*
+* \since 15
+*/
+   GLboolean (*queryDmaBufFormats)(__DRIscreen *screen, int max,
+   int *formats, int *count);
+
+   /*
+* dmabuf format modifier query for a given format to support
+* EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param fourccThe format to query modifiers for. If this format
+*  is not supported by the driver, return false.
+* \param max   Maximum number of modifiers that can be accomodated in
+*  \param modifiers. If zero, no modifiers are returned -
+*  instead, the driver returns the total number of
+*  modifiers for \param format in \param count.
+* \param modifiers Buffer to fill modifiers into.
+* \param count Count of the modifiers returned, or, total number of
+*  supported modifiers for \param fourcc in case
+*  \param max is zero.
+*
+* Returns true upon success.
+*
+* \since 15
+*/
+   GLboolean (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc,
+ int max, uint64_t *modifiers,
+ unsigned int *external_only,
+ int *count);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 01/36] egl: introduce DMA_BUF_MAX_PLANES

2017-05-30 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

Rather than hardcoding 3, use a #define. Makes it easier to bump this
later to 4.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 8 
 src/egl/main/eglimage.h | 8 +---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 80d366d..a2c9e41 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2092,7 +2092,7 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
 *  generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
 *  attributes are specified."
 */
-   for (i = plane_n; i < 3; ++i) {
+   for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
   attrs->DMABufPlanePitches[i].IsPresent) {
@@ -2125,9 +2125,9 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
__DRIimage *dri_image;
unsigned num_fds;
unsigned i;
-   int fds[3];
-   int pitches[3];
-   int offsets[3];
+   int fds[DMA_BUF_MAX_PLANES];
+   int pitches[DMA_BUF_MAX_PLANES];
+   int offsets[DMA_BUF_MAX_PLANES];
unsigned error;
 
/**
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 0dd5e12..9a75d0c 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -46,6 +46,8 @@ struct _egl_image_attrib_int
EGLBoolean IsPresent;
 };
 
+#define DMA_BUF_MAX_PLANES 3
+
 struct _egl_image_attribs
 {
/* EGL_KHR_image_base */
@@ -67,9 +69,9 @@ struct _egl_image_attribs
 
/* EGL_EXT_image_dma_buf_import */
struct _egl_image_attrib_int DMABufFourCC;
-   struct _egl_image_attrib_int DMABufPlaneFds[3];
-   struct _egl_image_attrib_int DMABufPlaneOffsets[3];
-   struct _egl_image_attrib_int DMABufPlanePitches[3];
+   struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
+   struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
+   struct _egl_image_attrib_int DMABufPlanePitches[DMA_BUF_MAX_PLANES];
struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
struct _egl_image_attrib_int DMABufSampleRangeHint;
struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 05/36] egl: implement eglQueryDmaBufFormatsEXT

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow egl clients to query the dmabuf formats supported on this platform.

v2: return EGLBoolean.
v3: Check DRIimageExtension version before querying (Daniel Stone).
v4: move to DRIimageExtension version 15, error checking (Jason Ekstrand).

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 22 ++
 src/egl/main/eglapi.c   | 18 ++
 src/egl/main/eglapi.h   |  4 
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 45 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 177b547..c271552 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2157,6 +2157,27 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
return plane_n;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
+EGLint max, EGLint *formats, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (max < 0 || (max > 0 && formats == NULL)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (dri2_dpy->image->base.version < 15 ||
+   dri2_dpy->image->queryDmaBufFormats == NULL)
+  return EGL_FALSE;
+
+   if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max,
+formats, count))
+  return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3094,6 +3115,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+   dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 431678f..d613920 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2386,6 +2386,24 @@ _eglFunctionCompare(const void *key, const void *elem)
return strcmp(procname, entrypoint->name);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
+ EGLint *formats, EGLint *num_formats)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
+num_formats);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 710c5d8..c9f9896 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -198,6 +198,10 @@ struct _egl_api
int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
 struct mesa_glinterop_export_in *in,
 struct mesa_glinterop_export_out *out);
+
+   EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
+   EGLint max_formats, EGLint *formats,
+   EGLint *num_formats);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index e6318b9..9153623 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -56,6 +56,7 @@ EGL_ENTRYPOINT(eglPostSubBufferNV)
 EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
+EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v14 04/36] egl/dri2: Create EGLImages with dmabuf modifiers

2017-05-30 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

Allow creating EGLImages with dmabuf format modifiers when target is
EGL_LINUX_DMA_BUF_EXT for EGL_EXT_image_dma_buf_import_modifiers.

v2:
- clear modifier assembling and error label name (Eric Engestrom)
v3:
- remove goto jumps within switch-case (Emil Velikov)
- treat zero as valid modifier (Daniel Stone)
- ensure same modifier across all dmabuf planes (Emil Velikov)
v4:
- allow modifiers to add extra planes (Louis-Francis Ratté-Boulianne)
v5:
- fix error checking, some cleanups (Jason Ekstrand)
- pass single copy of the modifier to createImageFromDmaBufs2

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com> (v2)
Reviewed-by: Daniel Stone <dani...@collabora.com>
Reviewed-by: Emil Velikov <emil.veli...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 108 
 src/egl/main/eglimage.c |  48 ++
 src/egl/main/eglimage.h |   2 +
 3 files changed, 147 insertions(+), 11 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 8f0f1b3..177b547 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -87,6 +87,10 @@
 #define DRM_FORMAT_GR1616fourcc_code('G', 'R', '3', '2') /* [31:0] R:G 
16:16 little endian */
 #endif
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
 static void
 dri_set_background_context(void *loaderPrivate)
 {
@@ -1987,6 +1991,37 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
   }
}
 
+   /**
+* If  is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
+* attribute values may be given.
+*
+* This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
+* EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
+*/
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent !=
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
+ _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing");
+ return EGL_FALSE;
+  }
+   }
+
+   /* Although the EGL_EXT_image_dma_buf_import_modifiers spec doesn't
+* mandate it, we only accept the same modifier across all planes. */
+   for (i = 1; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneFds[i].IsPresent) {
+ if ((attrs->DMABufPlaneModifiersLo[0].IsPresent !=
+   attrs->DMABufPlaneModifiersLo[i].IsPresent) ||
+ (attrs->DMABufPlaneModifiersLo[0].Value !=
+   attrs->DMABufPlaneModifiersLo[i].Value) ||
+ (attrs->DMABufPlaneModifiersHi[0].Value !=
+   attrs->DMABufPlaneModifiersHi[i].Value)) {
+_eglError(EGL_BAD_PARAMETER, "modifier attributes not equal");
+return EGL_FALSE;
+ }
+  }
+   }
+
return EGL_TRUE;
 }
 
@@ -2095,7 +2130,25 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
-  attrs->DMABufPlanePitches[i].IsPresent) {
+  attrs->DMABufPlanePitches[i].IsPresent ||
+  attrs->DMABufPlaneModifiersLo[i].IsPresent ||
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
+
+ /**
+  * The modifiers extension spec says:
+  *
+  * "Modifiers may modify any attribute of a buffer import, including
+  *  but not limited to adding extra planes to a format which
+  *  otherwise does not have those planes. As an example, a modifier
+  *  may add a plane for an external compression buffer to a
+  *  single-plane format. The exact meaning and effect of any
+  *  modifier is canonically defined by drm_fourcc.h, not as part of
+  *  this extension."
+  */
+ if (attrs->DMABufPlaneModifiersLo[i].IsPresent &&
+ attrs->DMABufPlaneModifiersHi[i].IsPresent)
+continue;
+
  _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes");
  return 0;
   }
@@ -2128,6 +2181,8 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
int fds[DMA_BUF_MAX_PLANES];
int pitches[DMA_BUF_MAX_PLANES];
int offsets[DMA_BUF_MAX_PLANES];
+   uint64_t modifier;
+   bool has_modifier = false;
unsigned error;
 
/**
@@ -2160,16 +2215,47 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, 
_EGLContext *ctx,
   offsets[i] = attrs.DMABufPlaneOffsets[i].Value;
}
 
-   dri_image =
-  dri2_dpy-

Re: [Mesa-dev] [PATCH v3 01/15] st/dri: refactor multi-planar YUV import path

2017-05-24 Thread Varad Gautam
Hi Lucas,

On Tue, May 23, 2017 at 9:10 PM, Lucas Stach <l.st...@pengutronix.de> wrote:
> Hi Varad,
>
> Am Dienstag, den 23.05.2017, 14:40 +0530 schrieb Varad Gautam:
>> Hi Lucas,
>>
>> On Mon, May 22, 2017 at 11:16 PM, Lucas Stach <l.st...@pengutronix.de> wrote:
>> > Am Mittwoch, den 10.05.2017, 23:15 +0530 schrieb Varad Gautam:
>> >> From: Varad Gautam <varad.gau...@collabora.com>
>> >>
>> >> we currently ignore the plane count when converting from
>> >> __DRI_IMAGE_FORMAT* tokens to __DRI_IMAGE_FOURCC* for multiplanar
>> >> images, and only return the first plane's simplified fourcc.
>> >>
>> >> this adds a fourcc to __DRI_IMAGE_FORMAT_* mapping to dri, allowing
>> >> us to return the correct fourcc format from DRIimage queries, and
>> >> simplifies the multiplane import logic.
>> >>
>> >> Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
>> >> ---
>> >>  src/gallium/state_trackers/dri/dri2.c   | 288 
>> >> +++-
>> >>  src/gallium/state_trackers/dri/dri_screen.h |  13 ++
>> >>  2 files changed, 168 insertions(+), 133 deletions(-)
>> >>
>> >> diff --git a/src/gallium/state_trackers/dri/dri2.c 
>> >> b/src/gallium/state_trackers/dri/dri2.c
>> >> index ed6004f..0c5783c 100644
>> >> --- a/src/gallium/state_trackers/dri/dri2.c
>> >> +++ b/src/gallium/state_trackers/dri/dri2.c
>> >> @@ -52,93 +52,133 @@
>> >>  #include "dri_query_renderer.h"
>> >>  #include "dri2_buffer.h"
>> >>
>> >> -static int convert_fourcc(int format, int *dri_components_p)
>> >> +/* format list taken from intel_screen.c */
>> >> +static struct image_format image_formats[] = {
>> >> +   { __DRI_IMAGE_FOURCC_ARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_ABGR, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR, 4 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_SARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_XRGB, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB, 4 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_XBGR, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR, 4 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_ARGB1555, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_RGB565, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_R16, __DRI_IMAGE_COMPONENTS_R, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 1 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_GR88, __DRI_IMAGE_COMPONENTS_RG, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_GR1616, __DRI_IMAGE_COMPONENTS_RG, 1,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616, 2 }, } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> >> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
>> >> +   { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> >> +
>> >> +   { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> >> + { { 0, 0

Re: [Mesa-dev] [PATCH v13 07/36] egl: implement eglQueryDmaBufModifiersEXT

2017-05-23 Thread Varad Gautam
On Mon, 2017-05-22 at 14:03 +0100, Emil Velikov wrote:
> Hi Dan,
> 
> On 19 May 2017 at 10:37, Daniel Stone <dani...@collabora.com> wrote:
> > 
> > From: Varad Gautam <varadgau...@gmail.com>
> > 
> > query and return supported dmabuf format modifiers for
> > EGL_EXT_image_dma_buf_import_modifiers.
> > 
> > v2: move format check to the driver instead of making format queries
> > here and then checking.
> > v3: Check DRIimageExtension version before query (Daniel Stone)
> > 
> > Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
> > Reviewed-by: Daniel Stone <dani...@collabora.com>
> > Signed-off-by: Daniel Stone <dani...@collabora.com>
> > ---
> >  src/egl/drivers/dri2/egl_dri2.c | 36 
> >  src/egl/main/eglapi.c   | 20 
> >  src/egl/main/eglapi.h   |  5 +
> >  src/egl/main/eglentrypoint.h|  1 +
> >  4 files changed, 62 insertions(+)
> > 
> > diff --git a/src/egl/drivers/dri2/egl_dri2.c
> > b/src/egl/drivers/dri2/egl_dri2.c
> > index 55b6fcf1fc..1e0302359f 100644
> > --- a/src/egl/drivers/dri2/egl_dri2.c
> > +++ b/src/egl/drivers/dri2/egl_dri2.c
> > @@ -2131,6 +2131,41 @@ dri2_query_dma_buf_formats(_EGLDriver *drv,
> > _EGLDisplay *disp,
> > return EGL_TRUE;
> >  }
> > 
> > +static EGLBoolean
> > +dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint
> > format,
> > + EGLint max, EGLuint64KHR *modifiers,
> > + EGLBoolean *external_only, EGLint *count)
> > +{
> > +   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > +   EGLint i;
> > +
> > +   if (max < 0) {
> > +  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of
> > formats");
> > +  return EGL_FALSE;
> > +   }
> > +
> > +   if (max > 0 && modifiers == NULL) {
> > +  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
> > +  return EGL_FALSE;
> > +   }
> > +
> Thinking out loud: I'm split if these should be part of /dri2 or
> /main. Either way is fine I guess.
> 
> > 
> > +   if (dri2_dpy->image->base.version < 16)
> > +  return EGL_FALSE;
> > +
> > +   if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
> As Jason mentioned function pointer can be NULL.
> 
> > 
> > +   if (external_only != NULL) {
> > +  for (i = 0; i < *count && i < max; i++)
> > + external_only[i] = EGL_TRUE;
> 
> If I'm correctly understanding the spec, each bool represents if the
> respective format/modifier combo.
> Do we want to unconditionally enable all here?
> 

Yes, bool external_only[i] corresponds to <format, modifier[i]> combination.

I am uncertain on what using modifiers with non-external images would mean,
since modifiers are only specific to the dmabufs path, which bind as external
textures.

Would we ever have modifiers with non-GL_TEXTURE_EXTERNAL_OES images? (should
external_only be false perhaps for MOD_INVALID?)

Regards,
Varad

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


Re: [Mesa-dev] [PATCH v3 01/15] st/dri: refactor multi-planar YUV import path

2017-05-23 Thread Varad Gautam
Hi Lucas,

On Mon, May 22, 2017 at 11:16 PM, Lucas Stach <l.st...@pengutronix.de> wrote:
> Am Mittwoch, den 10.05.2017, 23:15 +0530 schrieb Varad Gautam:
>> From: Varad Gautam <varad.gau...@collabora.com>
>>
>> we currently ignore the plane count when converting from
>> __DRI_IMAGE_FORMAT* tokens to __DRI_IMAGE_FOURCC* for multiplanar
>> images, and only return the first plane's simplified fourcc.
>>
>> this adds a fourcc to __DRI_IMAGE_FORMAT_* mapping to dri, allowing
>> us to return the correct fourcc format from DRIimage queries, and
>> simplifies the multiplane import logic.
>>
>> Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
>> ---
>>  src/gallium/state_trackers/dri/dri2.c   | 288 
>> +++-
>>  src/gallium/state_trackers/dri/dri_screen.h |  13 ++
>>  2 files changed, 168 insertions(+), 133 deletions(-)
>>
>> diff --git a/src/gallium/state_trackers/dri/dri2.c 
>> b/src/gallium/state_trackers/dri/dri2.c
>> index ed6004f..0c5783c 100644
>> --- a/src/gallium/state_trackers/dri/dri2.c
>> +++ b/src/gallium/state_trackers/dri/dri2.c
>> @@ -52,93 +52,133 @@
>>  #include "dri_query_renderer.h"
>>  #include "dri2_buffer.h"
>>
>> -static int convert_fourcc(int format, int *dri_components_p)
>> +/* format list taken from intel_screen.c */
>> +static struct image_format image_formats[] = {
>> +   { __DRI_IMAGE_FOURCC_ARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_ABGR, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR, 4 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_SARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_XRGB, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB, 4 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_XBGR, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR, 4 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_ARGB1555, __DRI_IMAGE_COMPONENTS_RGBA, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_RGB565, __DRI_IMAGE_COMPONENTS_RGB, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_R16, __DRI_IMAGE_COMPONENTS_R, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 1 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_GR88, __DRI_IMAGE_COMPONENTS_RG, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_GR1616, __DRI_IMAGE_COMPONENTS_RG, 1,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616, 2 }, } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YVU410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> +
>> +   { __DRI_IMAGE_FOURCC_YVU411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
>> + { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
>> +   { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
>> 

Re: [Mesa-dev] [RFC] st/dri: implement createImageWithModifiers

2017-05-15 Thread Varad Gautam
Hi Lucas,

On Fri, May 12, 2017 at 4:22 PM, Lucas Stach <l.st...@pengutronix.de> wrote:
> Hi Varad,
>
> Am Freitag, den 12.05.2017, 15:11 +0530 schrieb Varad Gautam:
>> gallium doesn't have a way to pass modifiers to the driver when creating
>> resources. we require this to support
>> dri2ImageExtension->createImageWithModifiers() to get
>> gbm_bo_create_with_modifiers() to work.
>>
>> this adds a pscreen->resource_create_with_modifier() to pass the modifier
>> flags to the driver when allocating textures, and implements image creation
>> with modifiers.
>>
>> requires cherry-picking the following patches from the EGL modifiers series:
>> https://patchwork.freedesktop.org/patch/155308/
>> https://patchwork.freedesktop.org/patch/155309/
>> https://patchwork.freedesktop.org/patch/155312/
>>
>> complete tree, with the egl series:
>> https://git.collabora.com/cgit/user/varad/mesa.git/log/?h=egl-modifiers-v4
>>
>> Signed-off-by: Varad Gautam <varadgau...@gmail.com>
>> ---
>>  src/gallium/include/pipe/p_screen.h   | 13 ++
>>  src/gallium/state_trackers/dri/dri2.c | 80 
>> ---
>>  2 files changed, 77 insertions(+), 16 deletions(-)
>>
>> diff --git a/src/gallium/include/pipe/p_screen.h 
>> b/src/gallium/include/pipe/p_screen.h
>> index 8b4239c..7d248ec 100644
>> --- a/src/gallium/include/pipe/p_screen.h
>> +++ b/src/gallium/include/pipe/p_screen.h
>> @@ -328,6 +328,19 @@ struct pipe_screen {
>>  * driver doesn't support an on-disk shader cache.
>>  */
>> struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
>> +
>> +   /**
>> +* Create a new texture object from the given template info, taking
>> +* format modifier into account. \p modifier adheres to the format
>> +* modifier tokens specified in drm_fourcc.h.
>> +*
>> +* Returns NULL if the \p modifier is unsupported by the driver.
>> +*/
>> +   struct pipe_resource * (*resource_create_with_modifier)(
>> +   struct pipe_screen *,
>> +   const struct pipe_resource *templat,
>> +   uint64_t modifier);
>> +
>>  };
>>
>>
>> diff --git a/src/gallium/state_trackers/dri/dri2.c 
>> b/src/gallium/state_trackers/dri/dri2.c
>> index 42fa155..54ca5fe 100644
>> --- a/src/gallium/state_trackers/dri/dri2.c
>> +++ b/src/gallium/state_trackers/dri/dri2.c
>> @@ -977,9 +977,12 @@ dri2_create_image_from_renderbuffer(__DRIcontext 
>> *context,
>>  }
>>
>>  static __DRIimage *
>> -dri2_create_image(__DRIscreen *_screen,
>> -   int width, int height, int format,
>> -   unsigned int use, void *loaderPrivate)
>> +dri2_create_image_common(__DRIscreen *_screen,
>> + int width, int height,
>> + int format, unsigned int use,
>> + const uint64_t *modifiers,
>> + const unsigned count,
>> + void *loaderPrivate)
>>  {
>> struct dri_screen *screen = dri_screen(_screen);
>> __DRIimage *img;
>> @@ -987,17 +990,29 @@ dri2_create_image(__DRIscreen *_screen,
>> unsigned tex_usage;
>> enum pipe_format pf;
>>
>> +   /* createImageWithModifiers does not take a usage flag, the caller can
>> +* specify either modifiers or usage.
>> +*/
>> +   assert(!(use && (modifiers != NULL)));
>> +
>> +   /* XXX: it is probably a bad idea to assume that all drivers will support
>> +* usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW with all of
>> +* their modifiers. tex_usage must be determined in the driver instead
>> +* when modifiers are present.
>> +*/
>
> I don't think we can push this to the driver, because what we want is
> the driver to select a modifier, that is actually able to be used with a
> least RENDER_TARGET. Probably even SCANOUT also. At least the current
> use of the new entry point for GBM create_surface implies those 2
> usages.
>
>> tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
>> -   if (use & __DRI_IMAGE_USE_SCANOUT)
>> -  tex_usage |= PIPE_BIND_SCANOUT;
>> -   if (use & __DRI_IMAGE_USE_SHARE)
>> -  tex_usage |= PIPE_BIND_SHARED;
>> -   if (use & __DRI_IMAGE_USE_LINEAR)
>> -  tex_usage |= PIPE_BIND_LINEAR;
>> -   if (use & __DRI_IMAGE_USE_CURSOR) {
>> -  if (wid

[Mesa-dev] [RFC] st/dri: implement createImageWithModifiers

2017-05-12 Thread Varad Gautam
gallium doesn't have a way to pass modifiers to the driver when creating
resources. we require this to support
dri2ImageExtension->createImageWithModifiers() to get
gbm_bo_create_with_modifiers() to work.

this adds a pscreen->resource_create_with_modifier() to pass the modifier
flags to the driver when allocating textures, and implements image creation
with modifiers.

requires cherry-picking the following patches from the EGL modifiers series:
https://patchwork.freedesktop.org/patch/155308/
https://patchwork.freedesktop.org/patch/155309/
https://patchwork.freedesktop.org/patch/155312/

complete tree, with the egl series:
https://git.collabora.com/cgit/user/varad/mesa.git/log/?h=egl-modifiers-v4

Signed-off-by: Varad Gautam <varadgau...@gmail.com>
---
 src/gallium/include/pipe/p_screen.h   | 13 ++
 src/gallium/state_trackers/dri/dri2.c | 80 ---
 2 files changed, 77 insertions(+), 16 deletions(-)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 8b4239c..7d248ec 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -328,6 +328,19 @@ struct pipe_screen {
 * driver doesn't support an on-disk shader cache.
 */
struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
+
+   /**
+* Create a new texture object from the given template info, taking
+* format modifier into account. \p modifier adheres to the format
+* modifier tokens specified in drm_fourcc.h.
+*
+* Returns NULL if the \p modifier is unsupported by the driver.
+*/
+   struct pipe_resource * (*resource_create_with_modifier)(
+   struct pipe_screen *,
+   const struct pipe_resource *templat,
+   uint64_t modifier);
+
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 42fa155..54ca5fe 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -977,9 +977,12 @@ dri2_create_image_from_renderbuffer(__DRIcontext *context,
 }
 
 static __DRIimage *
-dri2_create_image(__DRIscreen *_screen,
-   int width, int height, int format,
-   unsigned int use, void *loaderPrivate)
+dri2_create_image_common(__DRIscreen *_screen,
+ int width, int height,
+ int format, unsigned int use,
+ const uint64_t *modifiers,
+ const unsigned count,
+ void *loaderPrivate)
 {
struct dri_screen *screen = dri_screen(_screen);
__DRIimage *img;
@@ -987,17 +990,29 @@ dri2_create_image(__DRIscreen *_screen,
unsigned tex_usage;
enum pipe_format pf;
 
+   /* createImageWithModifiers does not take a usage flag, the caller can
+* specify either modifiers or usage.
+*/
+   assert(!(use && (modifiers != NULL)));
+
+   /* XXX: it is probably a bad idea to assume that all drivers will support
+* usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW with all of
+* their modifiers. tex_usage must be determined in the driver instead
+* when modifiers are present.
+*/
tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
-   if (use & __DRI_IMAGE_USE_SCANOUT)
-  tex_usage |= PIPE_BIND_SCANOUT;
-   if (use & __DRI_IMAGE_USE_SHARE)
-  tex_usage |= PIPE_BIND_SHARED;
-   if (use & __DRI_IMAGE_USE_LINEAR)
-  tex_usage |= PIPE_BIND_LINEAR;
-   if (use & __DRI_IMAGE_USE_CURSOR) {
-  if (width != 64 || height != 64)
- return NULL;
-  tex_usage |= PIPE_BIND_CURSOR;
+   if (use) {
+  if (use & __DRI_IMAGE_USE_SCANOUT)
+ tex_usage |= PIPE_BIND_SCANOUT;
+  if (use & __DRI_IMAGE_USE_SHARE)
+ tex_usage |= PIPE_BIND_SHARED;
+  if (use & __DRI_IMAGE_USE_LINEAR)
+ tex_usage |= PIPE_BIND_LINEAR;
+  if (use & __DRI_IMAGE_USE_CURSOR) {
+ if (width != 64 || height != 64)
+return NULL;
+ tex_usage |= PIPE_BIND_CURSOR;
+  }
}
 
pf = dri2_format_to_pipe_format (format);
@@ -1018,7 +1033,18 @@ dri2_create_image(__DRIscreen *_screen,
templ.depth0 = 1;
templ.array_size = 1;
 
-   img->texture = screen->base.screen->resource_create(screen->base.screen, 
);
+   if (modifiers && screen->base.screen->resource_create_with_modifier)
+  /* pick the first modifier for alloc. */
+  img->texture = screen->base.screen
+->resource_create_with_modifier(screen->base.screen,
+,
+modifiers[0]);
+   else if (modifiers)
+  /* the driver doesn't support tex creation with modifiers, return */
+  img->texture = 

Re: [Mesa-dev] [PATCH v3 02/15] dri: Add an image creation with modifiers

2017-05-11 Thread Varad Gautam
On Thu, May 11, 2017 at 10:26 PM, Ben Widawsky <b...@bwidawsk.net> wrote:
> On 17-05-10 23:15:29, Varad Gautam wrote:
>>
>> From: Ben Widawsky <b...@bwidawsk.net>
>>
>> Modifiers will be obtained or guessed by the client and passed in during
>> image creation/import.
>>
>> As of this patch, the modifiers aren't plumbed all the way down, this
>> patch simply makes sure the interface level stuff is correct and keeps
>> interface versioning consistent.
>>
>> v2: Don't allow usage + modifiers
>> v3: Make NAND actually NAND. Bug introduced in v2. (Jason)
>> v4: Bump DRIimage version. (Varad)
>>
>> Cc: Kristian Høgsberg <k...@bitplanet.net>
>> Cc: Jason Ekstrand <ja...@jekstrand.net>
>> Signed-off-by: Ben Widawsky <b...@bwidawsk.net>
>> Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com> (v1)
>> Acked-by: Daniel Stone <dani...@collabora.com>
>> Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
>> ---
>> src/gallium/state_trackers/dri/dri2.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/gallium/state_trackers/dri/dri2.c
>> b/src/gallium/state_trackers/dri/dri2.c
>> index 0c5783c..d561fe8 100644
>> --- a/src/gallium/state_trackers/dri/dri2.c
>> +++ b/src/gallium/state_trackers/dri/dri2.c
>> @@ -1417,7 +1417,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
>>
>> /* The extension is modified during runtime if DRI_PRIME is detected */
>> static __DRIimageExtension dri2ImageExtension = {
>> -.base = { __DRI_IMAGE, 12 },
>> +.base = { __DRI_IMAGE, 14 },
>>
>> .createImageFromName  = dri2_create_image_from_name,
>> .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
>> @@ -1435,6 +1435,7 @@ static __DRIimageExtension dri2ImageExtension = {
>> .getCapabilities  = dri2_get_capabilities,
>> .mapImage = dri2_map_image,
>> .unmapImage   = dri2_unmap_image,
>> +.createImageWithModifiers = NULL,
>> };
>>
>>
>>
>
> I think we can discard this patch, it seems to be some leftover garbage. If
> someone wants to plumb a gallium driver to do this, they are welcome, but I
> am
> not doing it.

I've left it in as a placeholder just to avoid an abrupt version bump
when adding
createImageFromDmaBufs2 later.

The concern with implementing this under gallium is that we don't
really have a way
to specify the driver-specific metadata like modifiers when creating a
new pipe_resource.
I have considered adding a modifier field to struct pipe_resouce, but
that seems too
exaggerated as this is the only place it would ever be required. An
alternative is adding
a pscreen->resource_create_with_modifier(pscreen, tmpl, modifier) call
to transfer the
modifier.

I would appreciate some suggestions on going ahead with the implementation.

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


[Mesa-dev] [PATCH v3 15/15] egl: advertise EGL_EXT_image_dma_buf_import_modifiers

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 6 ++
 src/egl/main/eglapi.c   | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 7f0edf6..853b6e5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -690,6 +690,12 @@ dri2_setup_screen(_EGLDisplay *disp)
   dri2_dpy->image->createImageFromDmaBufs) {
  disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE;
   }
+  if (dri2_dpy->image->base.version >= 16 &&
+  dri2_dpy->image->createImageFromDmaBufs2 &&
+  dri2_dpy->image->queryDmaBufFormats &&
+  dri2_dpy->image->queryDmaBufModifiers) {
+ disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
+  }
 #endif
}
 }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 8ec8872..3427afa 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -488,6 +488,7 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
_EGL_CHECK_EXTENSION(EXT_buffer_age);
_EGL_CHECK_EXTENSION(EXT_create_context_robustness);
_EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
+   _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
_EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
 
_EGL_CHECK_EXTENSION(KHR_cl_event2);
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 14/15] egl: implement eglQueryDmaBufModifiersEXT

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

v2: rebase to master.
v3: move format check to the driver instead of making format queries
from here and then checking.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 33 +
 src/egl/main/eglapi.c   | 20 
 src/egl/main/eglapi.h   |  5 +
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 59 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index efafdfa..7f0edf6 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2112,6 +2112,38 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint i;
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
+ max, modifiers,
+ count) == false) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+   if (external_only != NULL) {
+  for (i = 0; i < *count && i < max; i++)
+ external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3045,6 +3077,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 62d4113..8ec8872 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2422,6 +2422,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index c9f9896..cab3e96 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -202,6 +202,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *modifiers,
+  EGLBoolean *external_only,
+  EGLint *num_modifiers);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index 9153623..b9dca7c 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -57,6 +57,7 @@ EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
 EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
+EGL_ENTRYPOINT(eglQueryDmaBufModifiersEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 12/15] gallium: introduce format modifier querying

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

format modifiers tokens are driver specific, and hence, need to come
in from the driver. this allows drivers to be queried for supported
format modifiers for EGL_EXT_image_dma_buf_import_modifiers.

v2: rebase to master.
v3: drivers must return false on query failure.
v4: use pscreen->is_format_supported instead of adding a separate
format query handle, remove PIPE_CAP_QUERY_DMABUF_ATTRIBS.
(Lucas Stach)

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/include/pipe/p_screen.h | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 8b4239c..276d126 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -328,6 +328,17 @@ struct pipe_screen {
 * driver doesn't support an on-disk shader cache.
 */
struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
+
+   /**
+* Get supported modifiers for a format.
+* If \p max is 0, the total number of supported modifiers for the supplied
+* format is returned in \p count, with no modification to \p modifiers.
+* Otherwise, \p modifiers is filled with upto \p max supported modifier
+* codes, and \p count with the number of modifiers copied.
+*/
+   void (*query_dmabuf_modifiers)(struct pipe_screen *screen,
+ enum pipe_format format, int max,
+ uint64_t *modifiers, int *count);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 13/15] st/dri: support format modifier queries

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.
bump __DRIimageExtension to 16.

v2: move to __DRIimageExtension v16.
v3: fail if the supplied format is not supported by driver.
v4: purge PIPE_CAP_QUERY_DMABUF_ATTRIBS.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 5578cb9..ce45f0a 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1389,6 +1389,24 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int 
max, int *formats,
return true;
 }
 
+static boolean
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   enum pipe_format format = fourcc_to_pipe_format(fourcc);
+   const unsigned usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
+   if (pscreen->query_dmabuf_modifiers != NULL &&
+   pscreen->is_format_supported(pscreen, format, screen->target, 0, 
usage)) {
+  pscreen->query_dmabuf_modifiers(pscreen, format, max, modifiers,
+ count);
+  return true;
+   }
+   return false;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1555,7 +1573,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 15 },
+.base = { __DRI_IMAGE, 16 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1576,6 +1594,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .createImageWithModifiers = NULL,
 .createImageFromDmaBufs2  = NULL,
 .queryDmaBufFormats   = NULL,
+.queryDmaBufModifiers = NULL,
 };
 
 
@@ -2123,6 +2142,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2197,6 +2218,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 09/15] dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

these allow querying the driver for supported dmabuf formats and
modifiers.

v2: move to __DRIimageExtension version 16.
v3: return GLBoolean for error reporting, document params better.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 42 -
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 53b95dd..37bd48b 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1137,7 +1137,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 15
+#define __DRI_IMAGE_VERSION 16
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1513,6 +1513,46 @@ struct __DRIimageExtensionRec {
   enum __DRIChromaSiting vert_siting,
   unsigned *error,
   void *loaderPrivate);
+
+   /*
+* dmabuf format query to support EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param max  Maximum number of formats that can be accomodated into
+* \param formats. If zero, no formats are returned -
+* instead, the driver returns the total number of
+* supported dmabuf formats in \param count.
+* \param formats  Buffer to fill formats into.
+* \param countCount of formats returned, or, total number of
+* supported formats in case \param max is zero.
+*
+* Returns true on success.
+*
+* \since 16
+*/
+   GLboolean (*queryDmaBufFormats)(__DRIscreen *screen, int max, int *formats,
+  int *count);
+
+   /*
+* dmabuf format modifier query for a given format to support
+* EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param fourccThe format to query modifiers for. If this format
+*  is not supported by the driver, return false.
+* \param max   Maximum number of modifiers that can be accomodated in
+*  \param modifiers. If zero, no modifiers are returned -
+*  instead, the driver returns the total number of
+*  modifiers for \param format in \param count.
+* \param modifiers Buffer to fill modifiers into.
+* \param count Count of the modifiers returned, or, total number of
+*  supported modifiers for \param fourcc in case
+*  \param max is zero.
+*
+* Returns true upon success.
+*
+* \since 16
+*/
+   GLboolean (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc, int max,
+uint64_t *modifiers, int *count);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 10/15] st/dri: support format queries

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported dmabuf formats

v2: rebase to master.
v3: return false on failure.
v4: use pscreen->is_format_supported instead of adding a new query.
(Lucas Stach)
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 91 +++
 1 file changed, 91 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 2668324..5578cb9 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -216,6 +216,69 @@ static enum pipe_format dri2_format_to_pipe_format (int 
format)
return pf;
 }
 
+static enum pipe_format fourcc_to_pipe_format(int fourcc) {
+   enum pipe_format pf;
+
+   switch (fourcc) {
+   case __DRI_IMAGE_FOURCC_R8:
+  pf = PIPE_FORMAT_R8_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_GR88:
+  pf = PIPE_FORMAT_RG88_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ARGB1555:
+  pf = PIPE_FORMAT_B5G5R5A1_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_R16:
+  pf = PIPE_FORMAT_R16_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_GR1616:
+  pf = PIPE_FORMAT_RG1616_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_RGB565:
+  pf = PIPE_FORMAT_B5G6R5_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ARGB:
+  pf = PIPE_FORMAT_BGRA_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_XRGB:
+  pf = PIPE_FORMAT_BGRX_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_ABGR:
+  pf = PIPE_FORMAT_RGBA_UNORM;
+  break;
+   case __DRI_IMAGE_FOURCC_XBGR:
+  pf = PIPE_FORMAT_RGBX_UNORM;
+  break;
+
+   case __DRI_IMAGE_FOURCC_NV12:
+  pf = PIPE_FORMAT_NV12;
+  break;
+   case __DRI_IMAGE_FOURCC_YUYV:
+  pf = PIPE_FORMAT_YUYV;
+  break;
+   case __DRI_IMAGE_FOURCC_YUV420:
+   case __DRI_IMAGE_FOURCC_YVU420:
+  pf = PIPE_FORMAT_YV12;
+  break;
+
+   case __DRI_IMAGE_FOURCC_SARGB:
+   case __DRI_IMAGE_FOURCC_YUV410:
+   case __DRI_IMAGE_FOURCC_YUV411:
+   case __DRI_IMAGE_FOURCC_YUV422:
+   case __DRI_IMAGE_FOURCC_YUV444:
+   case __DRI_IMAGE_FOURCC_NV16:
+   case __DRI_IMAGE_FOURCC_YVU410:
+   case __DRI_IMAGE_FOURCC_YVU411:
+   case __DRI_IMAGE_FOURCC_YVU422:
+   case __DRI_IMAGE_FOURCC_YVU444:
+   default:
+  pf = PIPE_FORMAT_NONE;
+   }
+
+   return pf;
+}
+
 /**
  * DRI2 flush extension.
  */
@@ -1301,6 +1364,31 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static boolean
+dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
+   int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   const unsigned bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+   int i, j;
+
+   for (i = 0, j = 0; (i < ARRAY_SIZE(image_formats)) &&
+ (j < max || max == 0); i++) {
+  if (pscreen->is_format_supported(pscreen,
+   fourcc_to_pipe_format(
+  image_formats[i].fourcc),
+   screen->target,
+   0, bind)) {
+ if (j < max)
+formats[j] = image_formats[i].fourcc;
+ j++;
+  }
+   }
+   *count = j;
+   return true;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1487,6 +1575,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .unmapImage   = dri2_unmap_image,
 .createImageWithModifiers = NULL,
 .createImageFromDmaBufs2  = NULL,
+.queryDmaBufFormats   = NULL,
 };
 
 
@@ -2033,6 +2122,7 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+ dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
   }
}
 
@@ -2106,6 +2196,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 11/15] egl: implement eglQueryDmaBufFormatsEXT

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow egl clients to query the dmabuf formats supported on this platform.

v2: rebase to master.
v3: return EGL_FALSE upon failure.

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 18 ++
 src/egl/main/eglapi.c   | 18 ++
 src/egl/main/eglapi.h   |  4 
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 41 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 9139bd4..efafdfa 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2095,6 +2095,23 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
return plane_n;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
+EGLint max, EGLint *formats, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (max < 0 || (max > 0 && formats == NULL)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max,
+formats, count))
+   return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3027,6 +3044,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+   dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index aa0eb94..62d4113 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2404,6 +2404,24 @@ _eglFunctionCompare(const void *key, const void *elem)
return strcmp(procname, entrypoint->name);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
+ EGLint *formats, EGLint *num_formats)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
+num_formats);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 710c5d8..c9f9896 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -198,6 +198,10 @@ struct _egl_api
int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
 struct mesa_glinterop_export_in *in,
 struct mesa_glinterop_export_out *out);
+
+   EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
+   EGLint max_formats, EGLint *formats,
+   EGLint *num_formats);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index e6318b9..9153623 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -56,6 +56,7 @@ EGL_ENTRYPOINT(eglPostSubBufferNV)
 EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
+EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 08/15] egl_dri2: add support for using modifier attributes in eglCreateImageKHR

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow creating EGLImages with dmabuf format modifiers when target is
EGL_LINUX_DMA_BUF_EXT for EGL_EXT_image_dma_buf_import_modifiers.

v2:
 - clear modifier assembling and error label name (Eric Engestrom)
v3:
 - remove goto jumps within switch-case (Emil Velikov)
 - treat zero as valid modifier (Daniel Stone)
 - ensure same modifier across all dmabuf planes (Emil Velikov)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 79 +++--
 src/egl/main/eglimage.c | 48 +
 src/egl/main/eglimage.h |  2 ++
 3 files changed, 118 insertions(+), 11 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index ceffd28..9139bd4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1949,6 +1949,33 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
   }
}
 
+   /**
+* If  is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
+* attribute values may be given.
+*
+* This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
+* EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
+*/
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent !=
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
+ _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing");
+ return EGL_FALSE;
+  }
+   }
+
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent) {
+ if ((attrs->DMABufPlaneModifiersLo[0].Value !=
+ attrs->DMABufPlaneModifiersLo[i].Value) ||
+ (attrs->DMABufPlaneModifiersHi[0].Value !=
+ attrs->DMABufPlaneModifiersHi[i].Value)) {
+_eglError(EGL_BAD_PARAMETER, "modifier attributes not equal");
+return EGL_FALSE;
+ }
+  }
+   }
+
return EGL_TRUE;
 }
 
@@ -2057,7 +2084,9 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
-  attrs->DMABufPlanePitches[i].IsPresent) {
+  attrs->DMABufPlanePitches[i].IsPresent ||
+  attrs->DMABufPlaneModifiersLo[i].IsPresent ||
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
  _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes");
  return 0;
   }
@@ -2090,6 +2119,8 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
int fds[DMA_BUF_MAX_PLANES];
int pitches[DMA_BUF_MAX_PLANES];
int offsets[DMA_BUF_MAX_PLANES];
+   uint64_t modifiers[DMA_BUF_MAX_PLANES];
+   bool has_modifier = false;
unsigned error;
 
/**
@@ -2120,18 +2151,44 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, 
_EGLContext *ctx,
   fds[i] = attrs.DMABufPlaneFds[i].Value;
   pitches[i] = attrs.DMABufPlanePitches[i].Value;
   offsets[i] = attrs.DMABufPlaneOffsets[i].Value;
+  if (attrs.DMABufPlaneModifiersLo[i].IsPresent) {
+ modifiers[i] =
+((uint64_t) attrs.DMABufPlaneModifiersHi[i].Value << 32) |
+attrs.DMABufPlaneModifiersLo[i].Value;
+ has_modifier = true;
+  } else {
+ modifiers[i] = 0;
+  }
}
 
-   dri_image =
-  dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
- attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
- fds, num_fds, pitches, offsets,
- attrs.DMABufYuvColorSpaceHint.Value,
- attrs.DMABufSampleRangeHint.Value,
- attrs.DMABufChromaHorizontalSiting.Value,
- attrs.DMABufChromaVerticalSiting.Value,
- ,
- NULL);
+   if (has_modifier && dri2_dpy->image->createImageFromDmaBufs2) {
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs2(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+fds, num_fds, pitches, offsets, modifiers,
+attrs.DMABufYuvColorSpaceHint.Value,
+attrs.DMABufSampleRangeHint.Value,
+attrs.DMABufChromaHorizontalSiting.Value,
+attrs.DMABufChromaVerticalSiting.Value,
+,
+NULL);
+   } else {
+  if (has_modifier) {
+ _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier");
+ return EGL_NO_IMAGE_KHR;
+  }
+
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DM

[Mesa-dev] [PATCH v3 05/15] st/dri: enable DRIimage modifier queries

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

introduce modifier field in DRIimage and set it to
DRM_FORMAT_MOD_INVALID for now. support DRIimage modifier
queries.

Suggested-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c   | 15 +++
 src/gallium/state_trackers/dri/dri_screen.h |  1 +
 2 files changed, 16 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index d561fe8..42fa155 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -52,6 +52,10 @@
 #include "dri_query_renderer.h"
 #include "dri2_buffer.h"
 
+#ifndef DRM_FORMAT_MOD_INVALID
+#define DRM_FORMAT_MOD_INVALID ((1ULL<<56) - 1)
+#endif
+
 /* format list taken from intel_screen.c */
 static struct image_format image_formats[] = {
{ __DRI_IMAGE_FOURCC_ARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
@@ -874,6 +878,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
img->layer = 0;
img->dri_format = format;
img->use = 0;
+   img->modifier = DRM_FORMAT_MOD_INVALID;
img->loader_private = loaderPrivate;
 
return img;
@@ -1024,6 +1029,7 @@ dri2_create_image(__DRIscreen *_screen,
img->dri_format = format;
img->dri_components = 0;
img->use = use;
+   img->modifier = DRM_FORMAT_MOD_INVALID;
 
img->loader_private = loaderPrivate;
return img;
@@ -1103,6 +1109,12 @@ dri2_query_image(__DRIimage *image, int attrib, int 
*value)
case __DRI_IMAGE_ATTRIB_NUM_PLANES:
   *value = 1;
   return GL_TRUE;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+  *value = ((image->modifier >> 32) & 0x);
+  return GL_TRUE;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+  *value = image->modifier & 0x;
+  return GL_TRUE;
default:
   return GL_FALSE;
}
@@ -1121,6 +1133,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
pipe_resource_reference(>texture, image->texture);
img->level = image->level;
img->layer = image->layer;
+   img->modifier = image->modifier;
img->dri_format = image->dri_format;
/* This should be 0 for sub images, but dup is also used for base images. */
img->dri_components = image->dri_components;
@@ -1250,6 +1263,8 @@ dri2_create_from_texture(__DRIcontext *context, int 
target, unsigned texture,
img->level = level;
img->layer = depth;
img->dri_format = 
driGLFormatToImageFormat(obj->Image[face][level]->TexFormat);
+   /* XXX: no way to retrieve modifier from tex here, we lose the modifier. */
+   img->modifier = DRM_FORMAT_MOD_INVALID;
 
img->loader_private = loaderPrivate;
 
diff --git a/src/gallium/state_trackers/dri/dri_screen.h 
b/src/gallium/state_trackers/dri/dri_screen.h
index de88cd2..0fae51b 100644
--- a/src/gallium/state_trackers/dri/dri_screen.h
+++ b/src/gallium/state_trackers/dri/dri_screen.h
@@ -123,6 +123,7 @@ struct __DRIimageRec {
uint32_t dri_format;
uint32_t dri_components;
unsigned use;
+   uint64_t modifier;
 
void *loader_private;
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 07/15] st/dri: implement DRIimage creation from dmabufs with modifiers

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

support importing dmabufs into DRIimage while taking format modifiers
in account, as per DRIimage extension version 15.

bump __DRIimageExtension to 15.

v2: initialize winsys modifier to DRM_FORMAT_MOD_INVALID (Daniel Stone)

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/include/state_tracker/drm_driver.h |  2 ++
 src/gallium/state_trackers/dri/dri2.c  | 48 +++---
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/src/gallium/include/state_tracker/drm_driver.h 
b/src/gallium/include/state_tracker/drm_driver.h
index c80fb09..8b9d6bc 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -45,6 +45,8 @@ struct winsys_handle
 * Output for texture_get_handle.
 */
unsigned offset;
+
+   uint64_t modifier;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 42fa155..2668324 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -878,7 +878,7 @@ dri2_create_image_from_winsys(__DRIscreen *_screen,
img->layer = 0;
img->dri_format = format;
img->use = 0;
-   img->modifier = DRM_FORMAT_MOD_INVALID;
+   img->modifier = whandle[0].modifier;
img->loader_private = loaderPrivate;
 
return img;
@@ -895,6 +895,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
memset(, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
whandle.handle = name;
+   whandle.modifier = DRM_FORMAT_MOD_INVALID;
 
pf = dri2_format_to_pipe_format (format);
if (pf == PIPE_FORMAT_NONE)
@@ -910,7 +911,7 @@ static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
   int width, int height, int fourcc,
   int *fds, int num_fds, int *strides,
-  int *offsets, unsigned *error,
+  int *offsets, uint64_t *modifiers, unsigned *error,
   int *dri_components, void *loaderPrivate)
 {
struct winsys_handle whandles[3];
@@ -941,6 +942,7 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
+  whandles[i].modifier = modifiers ? modifiers[i] : DRM_FORMAT_MOD_INVALID;
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1177,6 +1179,7 @@ dri2_from_names(__DRIscreen *screen, int width, int 
height, int format,
whandle.handle = names[0];
whandle.stride = strides[0];
whandle.offset = offsets[0];
+   whandle.modifier = DRM_FORMAT_MOD_INVALID;
 
img = dri2_create_image_from_winsys(screen, width, height,
f->planes[0].dri_format,
@@ -1289,7 +1292,7 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, NULL,
+   fds, num_fds, strides, offsets, NULL, NULL,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1314,7 +1317,7 @@ dri2_from_dma_bufs(__DRIscreen *screen,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, error,
+   fds, num_fds, strides, offsets, NULL, error,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1329,6 +1332,38 @@ dri2_from_dma_bufs(__DRIscreen *screen,
return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+int width, int height, int fourcc,
+int *fds, int num_fds,
+int *strides, int *offsets,
+uint64_t *modifiers,
+enum __DRIYUVColorSpace yuv_color_space,
+enum __DRISampleRange sample_range,
+enum __DRIChromaSiting horizontal_siting,
+enum __DRIChromaSiting vertical_siting,
+unsigned *error,
+void *loaderPrivate)
+{
+   __DRIimage *img;
+   int dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+   fds, num_fds, strides, offsets, modifiers,
+   error, _components, loaderPrivate);
+   if (img == NULL)
+  return NULL;
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *e

[Mesa-dev] [PATCH v3 00/15] EGL_EXT_image_dma_buf_import_modifiers v3

2017-05-10 Thread Varad Gautam
One more time, from the top!

Hi all,

The v3 diverges somewhat form v2 while building upon the suggestions
received on earlier patchsets, and hence warrants a resend. Here's a
breakdown of patches in this series, and the changes since v2.

01 slightly reworks the multi-plane YUV import path in st/dri from
ecd6fce2611e88ff8468a354cff8eda39f260a31 by adding a
DRI_IMAGE_FOURCC_* <-> DRI_IMAGE_FORMAT_* mapping (same as i965) and
associated helpers that let us do the format namespace conversion more
accurately, and are later useful when serving format queries for egl.

02 borrows Ben Widawsky's patch to add a placeholder createImageWithModifiers
to maintain DRIimage interface version consistency. This is needed by
gbm_bo_create_with_modifiers, but gallium doesn't yet have a way to send the
driver-specific modifiers to the driver via pscreen->resource_create.
(possibly through struct pipe_resource? suggestions welcome.).

03-04 bump the plane count. same as v2.

05 adds a modifier field to DRIimage, and allows modifier queries via
queryImage.

06-07 provide a createImageFromDmaBufs2 path in DRIimage to import dmabufs
with modifiers.

08 adds the modifiers related eglattr parsing and sanity checks. same as v2.

09-14 implement format and modifier queries. Format queries on gallium are
now handled via pscreen->is_format_supported() as opposed to a new 
pscreen->query_dmabuf_formats() added in v2. However, we still need a
separate hook to fetch hw specific modifiers supported for a format from
the driver. PIPE_CAP_QUERY_DMABUF_ATTRIBS from v2 is no longer used.

finally, 15 enables the extension.

Ben Widawsky (1):
  dri: Add an image creation with modifiers

Pekka Paalanen (3):
  egl: introduce DMA_BUF_MAX_PLANES
  egl/main: add support for fourth plane tokens
  dri: support DRIimage creation from dmabufs with modifiers

Varad Gautam (11):
  st/dri: refactor multi-planar YUV import path
  st/dri: enable DRIimage modifier queries
  st/dri: implement DRIimage creation from dmabufs with modifiers
  egl_dri2: add support for using modifier attributes in
eglCreateImageKHR
  dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage
  st/dri: support format queries
  egl: implement eglQueryDmaBufFormatsEXT
  gallium: introduce format modifier querying
  st/dri: support format modifier queries
  egl: implement eglQueryDmaBufModifiersEXT
  egl: advertise EGL_EXT_image_dma_buf_import_modifiers

 include/GL/internal/dri_interface.h|  61 +++-
 src/egl/drivers/dri2/egl_dri2.c| 146 +++-
 src/egl/main/eglapi.c  |  39 +++
 src/egl/main/eglapi.h  |   9 +
 src/egl/main/egldisplay.h  |   1 +
 src/egl/main/eglentrypoint.h   |   2 +
 src/egl/main/eglimage.c|  66 
 src/egl/main/eglimage.h|  13 +-
 src/gallium/include/pipe/p_screen.h|  11 +
 src/gallium/include/state_tracker/drm_driver.h |   2 +
 src/gallium/state_trackers/dri/dri2.c  | 463 +
 src/gallium/state_trackers/dri/dri_screen.h|  14 +
 12 files changed, 669 insertions(+), 158 deletions(-)

-- 
2.10.0

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


[Mesa-dev] [PATCH v3 03/15] egl: introduce DMA_BUF_MAX_PLANES

2017-05-10 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

Rather than hardcoding 3, use a #define. Makes it easier to bump this
later to 4.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 8 
 src/egl/main/eglimage.h | 8 +---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0be7132..c8044c2 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2054,7 +2054,7 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
 *  generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
 *  attributes are specified."
 */
-   for (i = plane_n; i < 3; ++i) {
+   for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
   attrs->DMABufPlanePitches[i].IsPresent) {
@@ -2087,9 +2087,9 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
__DRIimage *dri_image;
unsigned num_fds;
unsigned i;
-   int fds[3];
-   int pitches[3];
-   int offsets[3];
+   int fds[DMA_BUF_MAX_PLANES];
+   int pitches[DMA_BUF_MAX_PLANES];
+   int offsets[DMA_BUF_MAX_PLANES];
unsigned error;
 
/**
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 0dd5e12..9a75d0c 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -46,6 +46,8 @@ struct _egl_image_attrib_int
EGLBoolean IsPresent;
 };
 
+#define DMA_BUF_MAX_PLANES 3
+
 struct _egl_image_attribs
 {
/* EGL_KHR_image_base */
@@ -67,9 +69,9 @@ struct _egl_image_attribs
 
/* EGL_EXT_image_dma_buf_import */
struct _egl_image_attrib_int DMABufFourCC;
-   struct _egl_image_attrib_int DMABufPlaneFds[3];
-   struct _egl_image_attrib_int DMABufPlaneOffsets[3];
-   struct _egl_image_attrib_int DMABufPlanePitches[3];
+   struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
+   struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
+   struct _egl_image_attrib_int DMABufPlanePitches[DMA_BUF_MAX_PLANES];
struct _egl_image_attrib_int DMABufYuvColorSpaceHint;
struct _egl_image_attrib_int DMABufSampleRangeHint;
struct _egl_image_attrib_int DMABufChromaHorizontalSiting;
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 01/15] st/dri: refactor multi-planar YUV import path

2017-05-10 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

we currently ignore the plane count when converting from
__DRI_IMAGE_FORMAT* tokens to __DRI_IMAGE_FOURCC* for multiplanar
images, and only return the first plane's simplified fourcc.

this adds a fourcc to __DRI_IMAGE_FORMAT_* mapping to dri, allowing
us to return the correct fourcc format from DRIimage queries, and
simplifies the multiplane import logic.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c   | 288 +++-
 src/gallium/state_trackers/dri/dri_screen.h |  13 ++
 2 files changed, 168 insertions(+), 133 deletions(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index ed6004f..0c5783c 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -52,93 +52,133 @@
 #include "dri_query_renderer.h"
 #include "dri2_buffer.h"
 
-static int convert_fourcc(int format, int *dri_components_p)
+/* format list taken from intel_screen.c */
+static struct image_format image_formats[] = {
+   { __DRI_IMAGE_FOURCC_ARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB, 4 } } },
+
+   { __DRI_IMAGE_FOURCC_ABGR, __DRI_IMAGE_COMPONENTS_RGBA, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_ABGR, 4 } } },
+
+   { __DRI_IMAGE_FOURCC_SARGB, __DRI_IMAGE_COMPONENTS_RGBA, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_SARGB8, 4 } } },
+
+   { __DRI_IMAGE_FOURCC_XRGB, __DRI_IMAGE_COMPONENTS_RGB, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_XRGB, 4 }, } },
+
+   { __DRI_IMAGE_FOURCC_XBGR, __DRI_IMAGE_COMPONENTS_RGB, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_XBGR, 4 }, } },
+
+   { __DRI_IMAGE_FOURCC_ARGB1555, __DRI_IMAGE_COMPONENTS_RGBA, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_ARGB1555, 2 } } },
+
+   { __DRI_IMAGE_FOURCC_RGB565, __DRI_IMAGE_COMPONENTS_RGB, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_RGB565, 2 } } },
+
+   { __DRI_IMAGE_FOURCC_R8, __DRI_IMAGE_COMPONENTS_R, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 }, } },
+
+   { __DRI_IMAGE_FOURCC_R16, __DRI_IMAGE_COMPONENTS_R, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R16, 1 }, } },
+
+   { __DRI_IMAGE_FOURCC_GR88, __DRI_IMAGE_COMPONENTS_RG, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR88, 2 }, } },
+
+   { __DRI_IMAGE_FOURCC_GR1616, __DRI_IMAGE_COMPONENTS_RG, 1,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_GR1616, 2 }, } },
+
+   { __DRI_IMAGE_FOURCC_YUV410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YUV411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YUV420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YUV422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YUV444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YVU410, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 2, 2, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YVU411, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 2, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YVU420, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 1, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YVU422, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_YVU444, __DRI_IMAGE_COMPONENTS_Y_U_V, 3,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 2, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 } } },
+
+   { __DRI_IMAGE_FOURCC_NV12, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 1, __DRI_IMAGE_FORMAT_GR88, 2 } } },
+
+   { __DRI_IMAGE_FOURCC_NV16, __DRI_IMAGE_COMPONENTS_Y_UV, 2,
+ { { 0, 0, 0, __DRI_IMAGE_FORMAT_R8, 1 },
+   { 1, 1, 0, __DRI_IMAGE_FORMAT_GR88, 2 } } },
+
+   { __DRI_IMAGE_FOURCC_YUYV, __DRI_IMAGE_COMPONE

[Mesa-dev] [PATCH v3 06/15] dri: support DRIimage creation from dmabufs with modifiers

2017-05-10 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

add createImageFromDmaBufs2 function which accepts per-plane dmabuf
format modifiers.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index c83056a..53b95dd 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1137,7 +1137,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 14
+#define __DRI_IMAGE_VERSION 15
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1494,6 +1494,25 @@ struct __DRIimageExtensionRec {
const uint64_t *modifiers,
const unsigned int modifier_count,
void *loaderPrivate);
+
+   /*
+* Like createImageFromDmaBufs, but takes also format modifiers.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 15
+*/
+   __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
+  int width, int height, int fourcc,
+  int *fds, int num_fds,
+  int *strides, int *offsets,
+  uint64_t *modifiers,
+  enum __DRIYUVColorSpace color_space,
+  enum __DRISampleRange sample_range,
+  enum __DRIChromaSiting horiz_siting,
+  enum __DRIChromaSiting vert_siting,
+  unsigned *error,
+  void *loaderPrivate);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 02/15] dri: Add an image creation with modifiers

2017-05-10 Thread Varad Gautam
From: Ben Widawsky <b...@bwidawsk.net>

Modifiers will be obtained or guessed by the client and passed in during
image creation/import.

As of this patch, the modifiers aren't plumbed all the way down, this
patch simply makes sure the interface level stuff is correct and keeps
interface versioning consistent.

v2: Don't allow usage + modifiers
v3: Make NAND actually NAND. Bug introduced in v2. (Jason)
v4: Bump DRIimage version. (Varad)

Cc: Kristian Høgsberg <k...@bitplanet.net>
Cc: Jason Ekstrand <ja...@jekstrand.net>
Signed-off-by: Ben Widawsky <b...@bwidawsk.net>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com> (v1)
Acked-by: Daniel Stone <dani...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 0c5783c..d561fe8 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1417,7 +1417,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 12 },
+.base = { __DRI_IMAGE, 14 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1435,6 +1435,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageWithModifiers = NULL,
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3 04/15] egl/main: add support for fourth plane tokens

2017-05-10 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

The EGL_EXT_dma_buf_import_modifiers extension adds support for a
fourth plane, just like DRM KMS API does.

Bump maximum dma_buf plane count to four.

v2: prevent attribute tokens from being parsed if
EXT_image_dma_buf_import_modifiers is not suported. (Emil Velikov)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c |  2 +-
 src/egl/main/egldisplay.h   |  1 +
 src/egl/main/eglimage.c | 18 ++
 src/egl/main/eglimage.h |  5 +++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c8044c2..ceffd28 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2052,7 +2052,7 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
 * "If  is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
 *  attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
 *  generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
-*  attributes are specified."
+*  or EGL_DMA_BUF_PLANE3_* attributes are specified."
 */
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 4d3d96e..9685bed 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -102,6 +102,7 @@ struct _egl_extensions
EGLBoolean EXT_buffer_age;
EGLBoolean EXT_create_context_robustness;
EGLBoolean EXT_image_dma_buf_import;
+   EGLBoolean EXT_image_dma_buf_import_modifiers;
EGLBoolean EXT_swap_buffers_with_damage;
 
EGLBoolean KHR_cl_event2;
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index d062cbf..fed390a 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -130,6 +130,24 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, 
_EGLDisplay *dpy,
  attrs->DMABufPlanePitches[2].Value = val;
  attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
  break;
+  case EGL_DMA_BUF_PLANE3_FD_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneFds[3].Value = val;
+ attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneOffsets[3].Value = val;
+ attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_PITCH_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlanePitches[3].Value = val;
+ attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
+ break;
   case EGL_YUV_COLOR_SPACE_HINT_EXT:
  if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
  val != EGL_ITU_REC2020_EXT) {
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 9a75d0c..a909d9b 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -46,7 +46,7 @@ struct _egl_image_attrib_int
EGLBoolean IsPresent;
 };
 
-#define DMA_BUF_MAX_PLANES 3
+#define DMA_BUF_MAX_PLANES 4
 
 struct _egl_image_attribs
 {
@@ -67,7 +67,8 @@ struct _egl_image_attribs
/* EGL_WL_bind_wayland_display */
EGLint PlaneWL;
 
-   /* EGL_EXT_image_dma_buf_import */
+   /* EGL_EXT_image_dma_buf_import and
+* EGL_EXT_image_dma_buf_import_modifiers */
struct _egl_image_attrib_int DMABufFourCC;
struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] egl: implement eglQueryDmaBufModifiersEXT

2017-04-26 Thread Varad Gautam
query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

v2: rebase to master.
v3: move format check to the driver instead of making format queries
from here and then checking.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 33 +
 src/egl/main/eglapi.c   | 20 
 src/egl/main/eglapi.h   |  5 +
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 59 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1a9ea3b..af0b566 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2144,6 +2144,38 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint i;
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   if (dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format,
+ max, modifiers,
+ count) == false) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+   if (external_only != NULL) {
+  for (i = 0; i < *count && i < max; i++)
+ external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3077,6 +3109,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index e9d42a4..e58d832 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2386,6 +2386,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index c9f9896..cab3e96 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -202,6 +202,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *modifiers,
+  EGLBoolean *external_only,
+  EGLint *num_modifiers);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index 9153623..b9dca7c 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -57,6 +57,7 @@ EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
 EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
+EGL_ENTRYPOINT(eglQueryDmaBufModifiersEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] st/dri: support format modifier queries

2017-04-26 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.
bump __DRIimageExtension to 16.

v2: move to __DRIimageExtension v16.
v3: fail if the supplied format is not supported by driver.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 60ff089..c9f5544 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1275,6 +1275,24 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int 
max, int *formats,
return false;
 }
 
+static boolean
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   int dri_components;
+   enum pipe_format format = dri2_format_to_pipe_format(
+ convert_fourcc(fourcc,_components));
+   const unsigned usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS) &&
+   pscreen->is_format_supported(pscreen, format, screen->target, 0, usage))
+  return pscreen->query_dmabuf_modifiers(pscreen, format, max, modifiers,
+ count);
+   return false;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1441,7 +1459,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 15 },
+.base = { __DRI_IMAGE, 16 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1462,6 +1480,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .createImageWithModifiers = NULL,
 .createImageFromDmaBufs2  = NULL,
 .queryDmaBufFormats   = NULL,
+.queryDmaBufModifiers = NULL,
 };
 
 
@@ -2009,6 +2028,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2083,6 +2104,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] egl: implement eglQueryDmaBufFormatsEXT

2017-04-26 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow egl clients to query the dmabuf formats supported on this platform.

v2: rebase to master.
v3: return EGL_FALSE upon failure.

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 18 ++
 src/egl/main/eglapi.c   | 18 ++
 src/egl/main/eglapi.h   |  4 
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 41 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3b63300..1a9ea3b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2127,6 +2127,23 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
return plane_n;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
+EGLint max, EGLint *formats, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (max < 0 || (max > 0 && formats == NULL)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (!dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max,
+formats, count))
+   return EGL_FALSE;
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3059,6 +3076,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+   dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index fc243a5..e9d42a4 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2368,6 +2368,24 @@ _eglFunctionCompare(const void *key, const void *elem)
return strcmp(procname, entrypoint->name);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
+ EGLint *formats, EGLint *num_formats)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
+num_formats);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 710c5d8..c9f9896 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -198,6 +198,10 @@ struct _egl_api
int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
 struct mesa_glinterop_export_in *in,
 struct mesa_glinterop_export_out *out);
+
+   EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
+   EGLint max_formats, EGLint *formats,
+   EGLint *num_formats);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index e6318b9..9153623 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -56,6 +56,7 @@ EGL_ENTRYPOINT(eglPostSubBufferNV)
 EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
+EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] gallium: introduce dmabuf format and modifier querying

2017-04-26 Thread Varad Gautam
allows drivers to be queried for supported formats and format
modifiers for EGL_EXT_image_dma_buf_import_modifiers. drivers that
implement format/modifier queries must advertise these under
PIPE_CAP_QUERY_DMABUF_ATTRIBS.

v2: rebase to master.
v3: drivers must return false on query failure.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/docs/source/screen.rst   |  2 ++
 src/gallium/drivers/freedreno/freedreno_screen.c |  1 +
 src/gallium/drivers/i915/i915_screen.c   |  1 +
 src/gallium/drivers/llvmpipe/lp_screen.c |  1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |  1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |  1 +
 src/gallium/drivers/r300/r300_screen.c   |  1 +
 src/gallium/drivers/r600/r600_pipe.c |  1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |  1 +
 src/gallium/drivers/softpipe/sp_screen.c |  1 +
 src/gallium/drivers/svga/svga_screen.c   |  1 +
 src/gallium/drivers/swr/swr_screen.cpp   |  1 +
 src/gallium/drivers/vc4/vc4_screen.c |  1 +
 src/gallium/drivers/virgl/virgl_screen.c |  1 +
 src/gallium/include/pipe/p_defines.h |  1 +
 src/gallium/include/pipe/p_screen.h  | 21 +
 17 files changed, 38 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index bb2803a..c723c75 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -389,6 +389,8 @@ The integer capabilities:
 * ``PIPE_CAP_TGSI_TES_LAYER_VIEWPORT``: Whether ``TGSI_SEMANTIC_LAYER`` and
   ``TGSI_SEMANTIC_VIEWPORT_INDEX`` are supported as tessellation evaluation
   shader outputs.
+* ``PIPE_CAP_QUERY_DMABUF_ATTRIBS``: Whether the driver supports querying for
+  supported dmabuf formats and format modifiers.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 9b3ca4d..6b53e3f 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -307,6 +307,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index 139b5d8..3a05516 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -277,6 +277,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 85449ab..b98e448 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -352,6 +352,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
}
/* should only get here on unhandled cases */
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 24b6b60..7e98cb2 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -216,6 +216,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index f691b47..a098db6 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -268,6 +268,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
index 13acef5..56b375e 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
@@ -292,6 +292,7 @@ nvc0_screen_get_param(

[Mesa-dev] [PATCH v3] dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage

2017-04-26 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

these allow querying the driver for supported dmabuf formats and
modifiers.

v2: move to __DRIimageExtension version 16.
v3: return GLBoolean for error reporting, document params better.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 42 -
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index e330723..7e61455 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 15
+#define __DRI_IMAGE_VERSION 16
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1512,6 +1512,46 @@ struct __DRIimageExtensionRec {
   enum __DRIChromaSiting vert_siting,
   unsigned *error,
   void *loaderPrivate);
+
+   /*
+* dmabuf format query to support EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param max  Maximum number of formats that can be accomodated into
+* \param formats. If zero, no formats are returned -
+* instead, the driver returns the total number of
+* supported dmabuf formats in \param count.
+* \param formats  Buffer to fill formats into.
+* \param countCount of formats returned, or, total number of
+* supported formats in case \param max is zero.
+*
+* Returns true on success.
+*
+* \since 16
+*/
+   GLboolean (*queryDmaBufFormats)(__DRIscreen *screen, int max, int *formats,
+  int *count);
+
+   /*
+* dmabuf format modifier query for a given format to support
+* EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \param fourccThe format to query modifiers for. If this format
+*  is not supported by the driver, return false.
+* \param max   Maximum number of modifiers that can be accomodated in
+*  \param modifiers. If zero, no modifiers are returned -
+*  instead, the driver returns the total number of
+*  modifiers for \param format in \param count.
+* \param modifiers Buffer to fill modifiers into.
+* \param count Count of the modifiers returned, or, total number of
+*  supported modifiers for \param fourcc in case
+*  \param max is zero.
+*
+* Returns true upon success.
+*
+* \since 16
+*/
+   GLboolean (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc, int max,
+uint64_t *modifiers, int *count);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v3] st/dri: support format queries

2017-04-26 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported dmabuf formats

v2: rebase to master.
v3: return false on failure.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 8078e1e..60ff089 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1263,6 +1263,18 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static boolean
+dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
+   int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS))
+  return pscreen->query_dmabuf_formats(pscreen, max, formats, count);
+   return false;
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1449,6 +1461,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .unmapImage   = dri2_unmap_image,
 .createImageWithModifiers = NULL,
 .createImageFromDmaBufs2  = NULL,
+.queryDmaBufFormats   = NULL,
 };
 
 
@@ -1995,6 +2008,7 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+ dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
   }
}
 
@@ -2068,6 +2082,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] egl: implement eglQueryDmaBufModifiersEXT

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

v2: rebase to master.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 47 +
 src/egl/main/eglapi.c   | 20 ++
 src/egl/main/eglapi.h   |  5 +
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 73 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0cc0c66..bf8d613 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2143,6 +2143,52 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint* formats;
+   EGLint num_formats;
+   EGLint i;
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   /* query and check if the received format is supported */
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, 0, NULL,
+   _formats);
+   formats = calloc(num_formats, sizeof(EGLint));
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, num_formats,
+   formats, _formats);
+   for (i = 0; i < num_formats; i++) {
+  if (format == formats[i])
+ break;
+   }
+   if (i == num_formats) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, max,
+ modifiers, count);
+
+   if (external_only != NULL) {
+  for (i = 0; i < *count && i < max; i++)
+ external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3076,6 +3122,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index be16f03..7e4dca1 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2382,6 +2382,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index c9f9896..cab3e96 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -202,6 +202,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *modifiers,
+  EGLBoolean *external_only,
+  EGLint *num_modifiers);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index 9153623..b9dca7c 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -57,6 +57,7 @@ EGL_ENTRYPOINT(eglQueryAPI)
 EGL_E

[Mesa-dev] [PATCH v2] egl: advertise EGL_EXT_image_dma_buf_import_modifiers

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

v2: check for both queryDmaBufFormats and queryDmaBufModifiers,
rebase to master.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 6 ++
 src/egl/main/eglapi.c   | 1 +
 2 files changed, 7 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bf8d613..fcdac5b 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -722,6 +722,12 @@ dri2_setup_screen(_EGLDisplay *disp)
   dri2_dpy->image->createImageFromDmaBufs) {
  disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE;
   }
+  if (dri2_dpy->image->base.version >= 16 &&
+  dri2_dpy->image->createImageFromDmaBufs2 &&
+  dri2_dpy->image->queryDmaBufFormats &&
+  dri2_dpy->image->queryDmaBufModifiers) {
+ disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
+  }
 #endif
}
 }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 7e4dca1..c9f6191 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -488,6 +488,7 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
_EGL_CHECK_EXTENSION(EXT_buffer_age);
_EGL_CHECK_EXTENSION(EXT_create_context_robustness);
_EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
+   _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
_EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
 
_EGL_CHECK_EXTENSION(KHR_cl_event2);
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] dri: support DRIimage creation from dmabufs with modifiers

2017-04-14 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

add createImageFromDmaBufs2 function which accepts per-plane dmabuf
format modifiers.

v2: resolve DRIimage version conflict by moving
createImageFromDmaBufs2 to v15.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 86efd1b..e330723 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 14
+#define __DRI_IMAGE_VERSION 15
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1493,6 +1493,25 @@ struct __DRIimageExtensionRec {
const uint64_t *modifiers,
const unsigned int modifier_count,
void *loaderPrivate);
+
+   /*
+* Like createImageFromDmaBufs, but takes also format modifiers.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 15
+*/
+   __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
+  int width, int height, int fourcc,
+  int *fds, int num_fds,
+  int *strides, int *offsets,
+  uint64_t *modifiers,
+  enum __DRIYUVColorSpace color_space,
+  enum __DRISampleRange sample_range,
+  enum __DRIChromaSiting horiz_siting,
+  enum __DRIChromaSiting vert_siting,
+  unsigned *error,
+  void *loaderPrivate);
 };
 
 
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] gallium: introduce dmabuf format and modifier querying

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allows drivers to be queried for supported formats and format
modifiers for EGL_EXT_image_dma_buf_import_modifiers. drivers that
implement format/modifier queries must advertise these under
PIPE_CAP_QUERY_DMABUF_ATTRIBS.

v2: rebase to master.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/docs/source/screen.rst   |  2 ++
 src/gallium/drivers/freedreno/freedreno_screen.c |  1 +
 src/gallium/drivers/i915/i915_screen.c   |  1 +
 src/gallium/drivers/llvmpipe/lp_screen.c |  1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |  1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |  1 +
 src/gallium/drivers/r300/r300_screen.c   |  1 +
 src/gallium/drivers/r600/r600_pipe.c |  1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |  1 +
 src/gallium/drivers/softpipe/sp_screen.c |  1 +
 src/gallium/drivers/svga/svga_screen.c   |  1 +
 src/gallium/drivers/swr/swr_screen.cpp   |  1 +
 src/gallium/drivers/vc4/vc4_screen.c |  1 +
 src/gallium/drivers/virgl/virgl_screen.c |  1 +
 src/gallium/include/pipe/p_defines.h |  1 +
 src/gallium/include/pipe/p_screen.h  | 20 
 17 files changed, 37 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index c1b2982..9fbc5e7 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -386,6 +386,8 @@ The integer capabilities:
   most 64KB.
 * ``PIPE_CAP_TGSI_BALLOT``: Whether the BALLOT and READ_* opcodes as well as
   the SUBGROUP_* semantics are supported.
+* ``PIPE_CAP_QUERY_DMABUF_ATTRIBS``: Whether the driver supports querying for
+  supported dmabuf formats and format modifiers.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index cc6b148..51c98d9 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -306,6 +306,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index ce5348a..5b954dd 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -277,6 +277,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 5fe6ae5..b37ac7d 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -351,6 +351,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
}
/* should only get here on unhandled cases */
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 95464f7..95b7d77 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -215,6 +215,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 7699949..8a925f9 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -267,6 +267,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
case PIPE_CAP_TGSI_BALLOT:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
index 0a9ab29..92b66ca 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
@@ -291,6 +291,7 @@ nvc0_screen_get_param(struct pipe_scr

[Mesa-dev] [PATCH v2] st/dri: support format modifier queries

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.
bump __DRIimageExtension to 16.

v2: move to __DRIimageExtension v16.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 6dffb1d..650e611 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1274,6 +1274,21 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int 
max, int *formats,
   pscreen->query_dmabuf_formats(pscreen, max, formats, count);
 }
 
+static void
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   int dri_components;
+   enum pipe_format format = dri2_format_to_pipe_format(
+ convert_fourcc(fourcc,_components));
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS))
+  pscreen->query_dmabuf_modifiers(pscreen, format, max, modifiers,
+count);
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1440,7 +1455,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 15 },
+.base = { __DRI_IMAGE, 16 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1460,6 +1475,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .unmapImage   = dri2_unmap_image,
 .createImageFromDmaBufs2  = NULL,
 .queryDmaBufFormats   = NULL,
+.queryDmaBufModifiers = NULL,
 };
 
 
@@ -2007,6 +2023,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2081,6 +2099,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] st/dri: support format queries

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported dmabuf formats

v2: rebase to master.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index dcbd049..6dffb1d 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1263,6 +1263,17 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static void
+dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
+   int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS))
+  pscreen->query_dmabuf_formats(pscreen, max, formats, count);
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1448,6 +1459,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
 .createImageFromDmaBufs2  = NULL,
+.queryDmaBufFormats   = NULL,
 };
 
 
@@ -1994,6 +2006,7 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+ dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
   }
}
 
@@ -2067,6 +2080,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] st/dri: implement DRIimage creation from dmabufs with modifiers

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

support importing dmabufs into DRIimage while taking format modifiers
in account, and bump __DRIimageExtension on gallium to version 15.

v2: move to __DRIimageExtension v15.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/include/state_tracker/drm_driver.h |  2 ++
 src/gallium/state_trackers/dri/dri2.c  | 45 +++---
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/gallium/include/state_tracker/drm_driver.h 
b/src/gallium/include/state_tracker/drm_driver.h
index c80fb09..8b9d6bc 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -45,6 +45,8 @@ struct winsys_handle
 * Output for texture_get_handle.
 */
unsigned offset;
+
+   uint64_t modifier;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index ed6004f..dcbd049 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -884,7 +884,7 @@ static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
   int width, int height, int fourcc,
   int *fds, int num_fds, int *strides,
-  int *offsets, unsigned *error,
+  int *offsets, uint64_t *modifiers, unsigned *error,
   int *dri_components, void *loaderPrivate)
 {
struct winsys_handle whandles[3];
@@ -929,6 +929,8 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
+  if (modifiers)
+ whandles[i].modifier = modifiers[i];
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1252,7 +1254,7 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, NULL,
+   fds, num_fds, strides, offsets, NULL, NULL,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1277,7 +1279,7 @@ dri2_from_dma_bufs(__DRIscreen *screen,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, error,
+   fds, num_fds, strides, offsets, NULL, error,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1292,6 +1294,38 @@ dri2_from_dma_bufs(__DRIscreen *screen,
return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+int width, int height, int fourcc,
+int *fds, int num_fds,
+int *strides, int *offsets,
+uint64_t *modifiers,
+enum __DRIYUVColorSpace yuv_color_space,
+enum __DRISampleRange sample_range,
+enum __DRIChromaSiting horizontal_siting,
+enum __DRIChromaSiting vertical_siting,
+unsigned *error,
+void *loaderPrivate)
+{
+   __DRIimage *img;
+   int dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+   fds, num_fds, strides, offsets, modifiers,
+   error, _components, loaderPrivate);
+   if (img == NULL)
+  return NULL;
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
 static void
 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
 int dstx0, int dsty0, int dstwidth, int dstheight,
@@ -1395,7 +1429,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 12 },
+.base = { __DRI_IMAGE, 15 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1413,6 +1447,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageFromDmaBufs2  = NULL,
 };
 
 
@@ -1958,6 +1993,7 @@ dri2_init_screen(__DRIscreen * sPriv)
   (cap & DRM_PRIME_CAP_IMPORT)) {
  dri2ImageExtension.cre

[Mesa-dev] [PATCH v2] egl: implement eglQueryDmaBufFormatsEXT

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow egl clients to query the dmabuf formats supported on this platform.

v2: rebase to master.

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 17 +
 src/egl/main/eglapi.c   | 18 ++
 src/egl/main/eglapi.h   |  4 
 src/egl/main/eglentrypoint.h|  1 +
 4 files changed, 40 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3b63300..0cc0c66 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2127,6 +2127,22 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
return plane_n;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
+EGLint max, EGLint *formats, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (max < 0 || (max > 0 && formats == NULL)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max, formats,
+   count);
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3059,6 +3075,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+   dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 5694b5a..be16f03 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2364,6 +2364,24 @@ _eglFunctionCompare(const void *key, const void *elem)
return strcmp(procname, entrypoint->name);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
+ EGLint *formats, EGLint *num_formats)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
+num_formats);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 710c5d8..c9f9896 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -198,6 +198,10 @@ struct _egl_api
int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
 struct mesa_glinterop_export_in *in,
 struct mesa_glinterop_export_out *out);
+
+   EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
+   EGLint max_formats, EGLint *formats,
+   EGLint *num_formats);
 };
 
 #ifdef __cplusplus
diff --git a/src/egl/main/eglentrypoint.h b/src/egl/main/eglentrypoint.h
index e6318b9..9153623 100644
--- a/src/egl/main/eglentrypoint.h
+++ b/src/egl/main/eglentrypoint.h
@@ -56,6 +56,7 @@ EGL_ENTRYPOINT(eglPostSubBufferNV)
 EGL_ENTRYPOINT(eglQueryAPI)
 EGL_ENTRYPOINT(eglQueryContext)
 EGL_ENTRYPOINT(eglQueryDebugKHR)
+EGL_ENTRYPOINT(eglQueryDmaBufFormatsEXT)
 EGL_ENTRYPOINT(eglQueryString)
 EGL_ENTRYPOINT(eglQuerySurface)
 EGL_ENTRYPOINT(eglQueryWaylandBufferWL)
-- 
2.10.0

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


[Mesa-dev] [PATCH v2] dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage

2017-04-14 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

these allow querying the driver for supported dmabuf formats and
modifiers.

v2: move to __DRIimageExtension version 16.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index e330723..a4942db 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1136,7 +1136,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 15
+#define __DRI_IMAGE_VERSION 16
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1512,6 +1512,26 @@ struct __DRIimageExtensionRec {
   enum __DRIChromaSiting vert_siting,
   unsigned *error,
   void *loaderPrivate);
+
+   /*
+* Returns the dmabuf formats supported by the driver
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 16
+*/
+   void (*queryDmaBufFormats)(__DRIscreen *screen, int max, int *formats,
+  int *count);
+
+   /*
+* Returns modifiers supported by the driver for a given format.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 16
+*/
+   void (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc, int max,
+uint64_t *modifiers, int *count);
 };
 
 
-- 
2.10.0

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


Re: [Mesa-dev] [PATCH v2 00/14] implement EGL_EXT_image_dma_buf_import_modifiers v2

2017-01-04 Thread Varad Gautam
Hi Ben,

On Wed, Jan 4, 2017 at 3:25 AM, Ben Widawsky <b...@bwidawsk.net> wrote:
> On 16-11-24 20:50:37, Varad Gautam wrote:
>>
>> This is the second revision to the EGL_EXT_image_dma_buf_import_modifiers
>> [1]
>> series at [2], addressing the comments received. This diverges from v1 due
>> to
>> some reordered/squashed changes, hence the resend.
>
>
> 1-4 are Reviewed-by: Ben Widawsky <b...@bwidawsk.net>
> 5-9,12-13: See below
> 10: Not really my thing, and tied up with 9.
> 14: Acked-by: Ben Widawsky <b...@bwidawsk.net>
>
> I guess we need to decide whose patches we're going to use. Many of the
> patches
> overlap with the work I did for GBM support (v2 here:
> https://patchwork.freedesktop.org/series/16244/). While yours went to the
> list
> first, I had been working on mine for quite a while. I really would prefer
> to
> keep my patches only because the i965 hardware has proven really finicky
> over
> this stuff, and I want to avoid breakage, but I'll be as accommodating as
> possible.

sure, we can have createImageWithModifiers/gbm support go in first. I've
already got a rebase of dmabuf eglext patches on your series, and it's easy
enough for me to deal with the clashes (just a couple of version bumps /
slight tweaks).

Thanks,
Varad

>
> Thanks.
> Ben
>
> [snip]
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2 11/14] egl: implement eglQueryDmaBufFormatsEXT

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow egl clients to query the dmabuf formats supported on this platform.

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 17 +
 src/egl/main/eglapi.c   | 19 +++
 src/egl/main/eglapi.h   |  4 
 3 files changed, 40 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 4589d9f..bae7da8 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2081,6 +2081,22 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
return plane_n;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay *disp,
+EGLint max, EGLint *formats, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   if (max < 0 || (max > 0 && formats == NULL)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, max, formats,
+   count);
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -2964,6 +2980,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
+   dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 53340bf..53d34d8 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2257,6 +2257,24 @@ eglQueryDebugKHR(EGLint attribute, EGLAttrib *value)
return EGL_TRUE;
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint max_formats,
+ EGLint *formats, EGLint *num_formats)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufFormatsEXT(drv, disp, max_formats, formats,
+num_formats);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
@@ -2340,6 +2358,7 @@ eglGetProcAddress(const char *procname)
   { "eglLabelObjectKHR", (_EGLProc) eglLabelObjectKHR },
   { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
   { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
+  { "eglQueryDmaBufFormatsEXT", (_EGLProc) eglQueryDmaBufFormatsEXT },
   { NULL, NULL }
};
EGLint i;
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index b9bcc8e..13388b1 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -196,6 +196,10 @@ struct _egl_api
int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
 struct mesa_glinterop_export_in *in,
 struct mesa_glinterop_export_out *out);
+
+   EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
+   EGLint max_formats, EGLint *formats,
+   EGLint *num_formats);
 };
 
 EGLint _eglConvertIntsToAttribs(const EGLint *int_list,
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 13/14] egl: implement eglQueryDmaBufModifiersEXT

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 47 +
 src/egl/main/eglapi.c   | 21 ++
 src/egl/main/eglapi.h   |  5 +
 3 files changed, 73 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index bae7da8..d387e28 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2097,6 +2097,52 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint* formats;
+   EGLint num_formats;
+   EGLint i;
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   /* query and check if the received format is supported */
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, 0, NULL,
+   _formats);
+   formats = calloc(num_formats, sizeof(EGLint));
+   dri2_dpy->image->queryDmaBufFormats(dri2_dpy->dri_screen, num_formats,
+   formats, _formats);
+   for (i = 0; i < num_formats; i++) {
+  if (format == formats[i])
+ break;
+   }
+   if (i == num_formats) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, max,
+ modifiers, count);
+
+   if (external_only != NULL) {
+  for (i = 0; i < *count && i < max; i++)
+ external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -2981,6 +3027,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 53d34d8..cd65115 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2275,6 +2275,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
@@ -2359,6 +2379,7 @@ eglGetProcAddress(const char *procname)
   { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
   { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
   { "eglQueryDmaBufFormatsEXT", (_EGLProc) eglQueryDmaBufFormatsEXT },
+  { "eglQueryDmaBufModifiersEXT", (_EGLProc) eglQueryDmaBufModifiersEXT },
   { NULL, NULL }
};
EGLint i;
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 13388b1..3428195 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -200,6 +200,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *mod

[Mesa-dev] [PATCH v2 14/14] egl: advertise EGL_EXT_image_dma_buf_import_modifiers

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 5 +
 src/egl/main/eglapi.c   | 1 +
 2 files changed, 6 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index d387e28..e155801 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -692,6 +692,11 @@ dri2_setup_screen(_EGLDisplay *disp)
   dri2_dpy->image->createImageFromDmaBufs) {
  disp->Extensions.EXT_image_dma_buf_import = EGL_TRUE;
   }
+  if (dri2_dpy->image->base.version >= 15 &&
+  dri2_dpy->image->createImageFromDmaBufs2 &&
+  dri2_dpy->image->queryDmaBufModifiers) {
+ disp->Extensions.EXT_image_dma_buf_import_modifiers = EGL_TRUE;
+  }
 #endif
}
 }
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index cd65115..44d7935 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -481,6 +481,7 @@ _eglCreateExtensionsString(_EGLDisplay *dpy)
_EGL_CHECK_EXTENSION(EXT_buffer_age);
_EGL_CHECK_EXTENSION(EXT_create_context_robustness);
_EGL_CHECK_EXTENSION(EXT_image_dma_buf_import);
+   _EGL_CHECK_EXTENSION(EXT_image_dma_buf_import_modifiers);
_EGL_CHECK_EXTENSION(EXT_swap_buffers_with_damage);
 
_EGL_CHECK_EXTENSION(KHR_cl_event2);
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 06/14] st/dri: implement DRIimage creation from dmabufs with modifiers

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

support importing dmabufs into DRIimage taking format modifiers in
account, as per DRIimage extension version 14.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/include/state_tracker/drm_driver.h |  2 ++
 src/gallium/state_trackers/dri/dri2.c  | 45 +++---
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/gallium/include/state_tracker/drm_driver.h 
b/src/gallium/include/state_tracker/drm_driver.h
index c80fb09..8b9d6bc 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -45,6 +45,8 @@ struct winsys_handle
 * Output for texture_get_handle.
 */
unsigned offset;
+
+   uint64_t modifier;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a2b87a7 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -884,7 +884,7 @@ static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
   int width, int height, int fourcc,
   int *fds, int num_fds, int *strides,
-  int *offsets, unsigned *error,
+  int *offsets, uint64_t *modifiers, unsigned *error,
   int *dri_components, void *loaderPrivate)
 {
struct winsys_handle whandles[3];
@@ -929,6 +929,8 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
+  if (modifiers)
+ whandles[i].modifier = modifiers[i];
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1248,7 +1250,7 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, NULL,
+   fds, num_fds, strides, offsets, NULL, NULL,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1273,7 +1275,7 @@ dri2_from_dma_bufs(__DRIscreen *screen,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, error,
+   fds, num_fds, strides, offsets, NULL, error,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1288,6 +1290,38 @@ dri2_from_dma_bufs(__DRIscreen *screen,
return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+int width, int height, int fourcc,
+int *fds, int num_fds,
+int *strides, int *offsets,
+uint64_t *modifiers,
+enum __DRIYUVColorSpace yuv_color_space,
+enum __DRISampleRange sample_range,
+enum __DRIChromaSiting horizontal_siting,
+enum __DRIChromaSiting vertical_siting,
+unsigned *error,
+void *loaderPrivate)
+{
+   __DRIimage *img;
+   int dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+   fds, num_fds, strides, offsets, modifiers,
+   error, _components, loaderPrivate);
+   if (img == NULL)
+  return NULL;
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
 static void
 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
 int dstx0, int dsty0, int dstwidth, int dstheight,
@@ -1391,7 +1425,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 12 },
+.base = { __DRI_IMAGE, 14 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1409,6 +1443,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageFromDmaBufs2  = NULL,
 };
 
 
@@ -1902,6 +1937,7 @@ dri2_init_screen(__DRIscreen * sPriv)
   (cap & DRM_PRIME_CAP_IMPORT)) {
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageE

[Mesa-dev] [PATCH v2 10/14] st/dri: support format queries

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported dmabuf formats

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index a2b87a7..e12a064 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1259,6 +1259,17 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static void
+dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
+   int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS))
+  pscreen->query_dmabuf_formats(pscreen, max, formats, count);
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1444,6 +1455,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
 .createImageFromDmaBufs2  = NULL,
+.queryDmaBufFormats   = NULL,
 };
 
 
@@ -1938,6 +1950,7 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+ dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
   }
}
 
@@ -2011,6 +2024,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 12/14] st/dri: support format modifier queries

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.

bump __DRI_IMAGE implementation version to 15.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index e12a064..540b2dd 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1270,6 +1270,21 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int 
max, int *formats,
   pscreen->query_dmabuf_formats(pscreen, max, formats, count);
 }
 
+static void
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   int dri_components;
+   enum pipe_format format = dri2_format_to_pipe_format(
+ convert_fourcc(fourcc,_components));
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_ATTRIBS))
+  pscreen->query_dmabuf_modifiers(pscreen, format, max, modifiers,
+count);
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1436,7 +1451,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 14 },
+.base = { __DRI_IMAGE, 15 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1456,6 +1471,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .unmapImage   = dri2_unmap_image,
 .createImageFromDmaBufs2  = NULL,
 .queryDmaBufFormats   = NULL,
+.queryDmaBufModifiers = NULL,
 };
 
 
@@ -1951,6 +1967,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
  dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2025,6 +2043,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
   dri2ImageExtension.queryDmaBufFormats = dri2_query_dma_buf_formats;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.6.2

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


[Mesa-dev] [PATCH v3 07/14] egl_dri2: add support for using modifier attributes in eglCreateImageKHR

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

allow creating EGLImages with dmabuf format modifiers when target is
EGL_LINUX_DMA_BUF_EXT for EGL_EXT_image_dma_buf_import_modifiers.

v2:
 - clear modifier assembling and error label name (Eric Engestrom)
v3:
 - remove goto jumps within switch-case (Emil Velikov)
 - treat zero as valid modifier (Daniel Stone)
 - ensure same modifier across all dmabuf planes (Emil Velikov)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 79 +++--
 src/egl/main/eglimage.c | 48 +
 src/egl/main/eglimage.h |  2 ++
 3 files changed, 118 insertions(+), 11 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 58d16e1..4589d9f 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1937,6 +1937,33 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
   }
}
 
+   /**
+* If  is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
+* attribute values may be given.
+*
+* This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
+* EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
+*/
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent !=
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
+ _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing");
+ return EGL_FALSE;
+  }
+   }
+
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent) {
+ if ((attrs->DMABufPlaneModifiersLo[0].Value !=
+ attrs->DMABufPlaneModifiersLo[i].Value) ||
+ (attrs->DMABufPlaneModifiersHi[0].Value !=
+ attrs->DMABufPlaneModifiersHi[i].Value)) {
+_eglError(EGL_BAD_PARAMETER, "modifier attributes not equal");
+return EGL_FALSE;
+ }
+  }
+   }
+
return EGL_TRUE;
 }
 
@@ -2043,7 +2070,9 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
-  attrs->DMABufPlanePitches[i].IsPresent) {
+  attrs->DMABufPlanePitches[i].IsPresent ||
+  attrs->DMABufPlaneModifiersLo[i].IsPresent ||
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
  _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes");
  return 0;
   }
@@ -2076,6 +2105,8 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
int fds[DMA_BUF_MAX_PLANES];
int pitches[DMA_BUF_MAX_PLANES];
int offsets[DMA_BUF_MAX_PLANES];
+   uint64_t modifiers[DMA_BUF_MAX_PLANES];
+   bool has_modifier = false;
unsigned error;
 
/**
@@ -2106,18 +2137,44 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, 
_EGLContext *ctx,
   fds[i] = attrs.DMABufPlaneFds[i].Value;
   pitches[i] = attrs.DMABufPlanePitches[i].Value;
   offsets[i] = attrs.DMABufPlaneOffsets[i].Value;
+  if (attrs.DMABufPlaneModifiersLo[i].IsPresent) {
+ modifiers[i] =
+((uint64_t) attrs.DMABufPlaneModifiersHi[i].Value << 32) |
+attrs.DMABufPlaneModifiersLo[i].Value;
+ has_modifier = true;
+  } else {
+ modifiers[i] = 0;
+  }
}
 
-   dri_image =
-  dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
- attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
- fds, num_fds, pitches, offsets,
- attrs.DMABufYuvColorSpaceHint.Value,
- attrs.DMABufSampleRangeHint.Value,
- attrs.DMABufChromaHorizontalSiting.Value,
- attrs.DMABufChromaVerticalSiting.Value,
- ,
- NULL);
+   if (has_modifier && dri2_dpy->image->createImageFromDmaBufs2) {
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs2(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+fds, num_fds, pitches, offsets, modifiers,
+attrs.DMABufYuvColorSpaceHint.Value,
+attrs.DMABufSampleRangeHint.Value,
+attrs.DMABufChromaHorizontalSiting.Value,
+attrs.DMABufChromaVerticalSiting.Value,
+,
+NULL);
+   } else {
+  if (has_modifier) {
+ _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier");
+ return EGL_NO_IMAGE_KHR;
+  }
+
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DM

[Mesa-dev] [PATCH v2 08/14] dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

these allow querying the driver for supported dmabuf formats and
modifiers.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 4874e59..f4026a6 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1094,7 +1094,7 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 14
+#define __DRI_IMAGE_VERSION 15
 
 
 /**
@@ -1439,6 +1439,26 @@ struct __DRIimageExtensionRec {
   enum __DRIChromaSiting vert_siting,
   unsigned *error,
   void *loaderPrivate);
+
+   /*
+* Returns the dmabuf formats supported by the driver
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 15
+*/
+   void (*queryDmaBufFormats)(__DRIscreen *screen, int max, int *formats,
+  int *count);
+
+   /*
+* Returns modifiers supported by the driver for a given format.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 15
+*/
+   void (*queryDmaBufModifiers)(__DRIscreen *screen, int fourcc, int max,
+uint64_t *modifiers, int *count);
 };
 
 
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 09/14] gallium: introduce dmabuf format and modifier querying

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

this allows drivers to be queried for supported formats and format
modifiers. drivers that implement these queries must expose these under
PIPE_CAP_QUERY_DMABUF_ATTRIBS.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/docs/source/screen.rst   |  2 ++
 src/gallium/drivers/freedreno/freedreno_screen.c |  1 +
 src/gallium/drivers/i915/i915_screen.c   |  1 +
 src/gallium/drivers/ilo/ilo_screen.c |  1 +
 src/gallium/drivers/llvmpipe/lp_screen.c |  1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |  1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |  1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |  1 +
 src/gallium/drivers/r300/r300_screen.c   |  1 +
 src/gallium/drivers/r600/r600_pipe.c |  1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |  1 +
 src/gallium/drivers/softpipe/sp_screen.c |  1 +
 src/gallium/drivers/svga/svga_screen.c   |  1 +
 src/gallium/drivers/swr/swr_screen.cpp   |  1 +
 src/gallium/drivers/vc4/vc4_screen.c |  1 +
 src/gallium/drivers/virgl/virgl_screen.c |  1 +
 src/gallium/include/pipe/p_defines.h |  1 +
 src/gallium/include/pipe/p_screen.h  | 20 
 18 files changed, 38 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 6ad2bec..af78493 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -364,6 +364,8 @@ The integer capabilities:
 * ``PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS``: Whether interleaved stream
   output mode is able to interleave across buffers. This is required for
   ARB_transform_feedback3.
+* ``PIPE_CAP_QUERY_DMABUF_ATTRIBS``: Whether the driver supports querying for
+  supported dmabuf formats and format modifiers.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 97da0d7..da2348f 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -288,6 +288,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index bfadca3..c918092 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -278,6 +278,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
b/src/gallium/drivers/ilo/ilo_screen.c
index f3f182c..4b59bb9 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -517,6 +517,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
param)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 4b502f0..12b8a60 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -338,6 +338,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
}
/* should only get here on unhandled cases */
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 96708c0..b871537 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -203,6 +203,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_ATTRIBS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 50cdeda..f154ae5 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -255,6 +255,7 @@ nv50_screen_get_param(struct

[Mesa-dev] [PATCH v2 05/14] dri: support DRIimage creation from dmabufs with modifiers

2016-11-24 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

add createImageFromDmaBufs2 function which accepts per-plane dmabuf
format modifiers.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 include/GL/internal/dri_interface.h | 21 -
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index d0b1bc6..4874e59 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1094,7 +1094,8 @@ struct __DRIdri2ExtensionRec {
  * extensions.
  */
 #define __DRI_IMAGE "DRI_IMAGE"
-#define __DRI_IMAGE_VERSION 13
+#define __DRI_IMAGE_VERSION 14
+
 
 /**
  * These formats correspond to the similarly named MESA_FORMAT_*
@@ -1420,6 +1421,24 @@ struct __DRIimageExtensionRec {
 */
void (*unmapImage)(__DRIcontext *context, __DRIimage *image, void *data);
 
+   /*
+* Like createImageFromDmaBufs, but takes also format modifiers.
+*
+* For EGL_EXT_image_dma_buf_import_modifiers.
+*
+* \since 14
+*/
+   __DRIimage *(*createImageFromDmaBufs2)(__DRIscreen *screen,
+  int width, int height, int fourcc,
+  int *fds, int num_fds,
+  int *strides, int *offsets,
+  uint64_t *modifiers,
+  enum __DRIYUVColorSpace color_space,
+  enum __DRISampleRange sample_range,
+  enum __DRIChromaSiting horiz_siting,
+  enum __DRIChromaSiting vert_siting,
+  unsigned *error,
+  void *loaderPrivate);
 };
 
 
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 03/14] egl: update eglext.h

2016-11-24 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

update eglext.h to revision 33288 from Khronos

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 include/EGL/eglext.h | 60 ++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 4ccbab8..762b5a6 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -33,12 +33,12 @@ extern "C" {
 ** used to make the header, and the header can be found at
 **   http://www.opengl.org/registry/
 **
-** Khronos $Revision$ on $Date$
+** Khronos $Revision: 33288 $ on $Date: 2016-11-09 17:46:01 -0800 (Wed, 09 Nov 
2016) $
 */
 
 #include 
 
-#define EGL_EGLEXT_VERSION 20160809
+#define EGL_EGLEXT_VERSION 20161109
 
 /* Generated C header for:
  * API: egl
@@ -77,6 +77,13 @@ EGLAPI EGLSyncKHR EGLAPIENTRY eglCreateSync64KHR (EGLDisplay 
dpy, EGLenum type,
 #define EGL_VG_ALPHA_FORMAT_PRE_BIT_KHR   0x0040
 #endif /* EGL_KHR_config_attribs */
 
+#ifndef EGL_KHR_context_flush_control
+#define EGL_KHR_context_flush_control 1
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR 0
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_KHR  0x2097
+#define EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR 0x2098
+#endif /* EGL_KHR_context_flush_control */
+
 #ifndef EGL_KHR_create_context
 #define EGL_KHR_create_context 1
 #define EGL_CONTEXT_MAJOR_VERSION_KHR 0x3098
@@ -343,6 +350,24 @@ EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamu64KHR 
(EGLDisplay dpy, EGLStreamKHR
 #endif /* KHRONOS_SUPPORT_INT64 */
 #endif /* EGL_KHR_stream */
 
+#ifndef EGL_KHR_stream_attrib
+#define EGL_KHR_stream_attrib 1
+#ifdef KHRONOS_SUPPORT_INT64
+typedef EGLStreamKHR (EGLAPIENTRYP PFNEGLCREATESTREAMATTRIBKHRPROC) 
(EGLDisplay dpy, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSETSTREAMATTRIBKHRPROC) (EGLDisplay 
dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYSTREAMATTRIBKHRPROC) (EGLDisplay 
dpy, EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERACQUIREATTRIBKHRPROC) 
(EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLSTREAMCONSUMERRELEASEATTRIBKHRPROC) 
(EGLDisplay dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLStreamKHR EGLAPIENTRY eglCreateStreamAttribKHR (EGLDisplay dpy, 
const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglSetStreamAttribKHR (EGLDisplay dpy, 
EGLStreamKHR stream, EGLenum attribute, EGLAttrib value);
+EGLAPI EGLBoolean EGLAPIENTRY eglQueryStreamAttribKHR (EGLDisplay dpy, 
EGLStreamKHR stream, EGLenum attribute, EGLAttrib *value);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerAcquireAttribKHR (EGLDisplay 
dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+EGLAPI EGLBoolean EGLAPIENTRY eglStreamConsumerReleaseAttribKHR (EGLDisplay 
dpy, EGLStreamKHR stream, const EGLAttrib *attrib_list);
+#endif
+#endif /* KHRONOS_SUPPORT_INT64 */
+#endif /* EGL_KHR_stream_attrib */
+
 #ifndef EGL_KHR_stream_consumer_gltexture
 #define EGL_KHR_stream_consumer_gltexture 1
 #ifdef EGL_KHR_stream
@@ -520,6 +545,11 @@ EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE 
(EGLDisplay dpy, EGLSu
 #define EGL_FIXED_SIZE_ANGLE  0x3201
 #endif /* EGL_ANGLE_window_fixed_size */
 
+#ifndef EGL_ARM_implicit_external_sync
+#define EGL_ARM_implicit_external_sync 1
+#define EGL_SYNC_PRIOR_COMMANDS_IMPLICIT_EXTERNAL_ARM 0x328A
+#endif /* EGL_ARM_implicit_external_sync */
+
 #ifndef EGL_ARM_pixmap_multisample_discard
 #define EGL_ARM_pixmap_multisample_discard 1
 #define EGL_DISCARD_SAMPLES_ARM   0x3286
@@ -604,6 +634,27 @@ EGLAPI EGLBoolean EGLAPIENTRY eglQueryDisplayAttribEXT 
(EGLDisplay dpy, EGLint a
 #define EGL_YUV_CHROMA_SITING_0_5_EXT 0x3285
 #endif /* EGL_EXT_image_dma_buf_import */
 
+#ifndef EGL_EXT_image_dma_buf_import_modifiers
+#define EGL_EXT_image_dma_buf_import_modifiers 1
+#define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
+#define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
+#define EGL_DMA_BUF_PLANE3_PITCH_EXT  0x3442
+#define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
+#define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
+#define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
+#define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
+#define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
+#define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
+#define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
+#define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFFORMATSEXTPROC) (EGLDisplay 
dpy, EGLint max_formats, EGLint *formats, EGLint *num_formats);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLQUERYDMABUFMODIFIERSEXTPROC) 
(EGLDisplay dpy, EGLint format, EGLint max_modifiers, EGLuint64KHR *modifiers, 
EGLBo

[Mesa-dev] [PATCH v2 04/14] egl/main: add support for fourth plane tokens

2016-11-24 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

The EGL_EXT_dma_buf_import_modifiers extension adds support for a
fourth plane, just like DRM KMS API does.

Bump maximum dma_buf plane count to four.

v2: prevent attribute tokens from being parsed if
EXT_image_dma_buf_import_modifiers is not suported. (Emil Velikov)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c |  2 +-
 src/egl/main/egldisplay.h   |  1 +
 src/egl/main/eglimage.c | 18 ++
 src/egl/main/eglimage.h |  5 +++--
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 9a41ad0..58d16e1 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2038,7 +2038,7 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
 * "If  is EGL_LINUX_DMA_BUF_EXT, and the EGL_LINUX_DRM_FOURCC_EXT
 *  attribute indicates a single-plane format, EGL_BAD_ATTRIBUTE is
 *  generated if any of the EGL_DMA_BUF_PLANE1_* or EGL_DMA_BUF_PLANE2_*
-*  attributes are specified."
+*  or EGL_DMA_BUF_PLANE3_* attributes are specified."
 */
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 62d9a11..7a59dc5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -101,6 +101,7 @@ struct _egl_extensions
EGLBoolean EXT_buffer_age;
EGLBoolean EXT_create_context_robustness;
EGLBoolean EXT_image_dma_buf_import;
+   EGLBoolean EXT_image_dma_buf_import_modifiers;
EGLBoolean EXT_swap_buffers_with_damage;
 
EGLBoolean KHR_cl_event2;
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index 411d1ca..e339b3b 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -133,6 +133,24 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, 
_EGLDisplay *dpy,
  attrs->DMABufPlanePitches[2].Value = val;
  attrs->DMABufPlanePitches[2].IsPresent = EGL_TRUE;
  break;
+  case EGL_DMA_BUF_PLANE3_FD_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneFds[3].Value = val;
+ attrs->DMABufPlaneFds[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_OFFSET_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlaneOffsets[3].Value = val;
+ attrs->DMABufPlaneOffsets[3].IsPresent = EGL_TRUE;
+ break;
+  case EGL_DMA_BUF_PLANE3_PITCH_EXT:
+ if (!dpy->Extensions.EXT_image_dma_buf_import_modifiers)
+err = EGL_BAD_PARAMETER;
+ attrs->DMABufPlanePitches[3].Value = val;
+ attrs->DMABufPlanePitches[3].IsPresent = EGL_TRUE;
+ break;
   case EGL_YUV_COLOR_SPACE_HINT_EXT:
  if (val != EGL_ITU_REC601_EXT && val != EGL_ITU_REC709_EXT &&
  val != EGL_ITU_REC2020_EXT) {
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 9a75d0c..a909d9b 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -46,7 +46,7 @@ struct _egl_image_attrib_int
EGLBoolean IsPresent;
 };
 
-#define DMA_BUF_MAX_PLANES 3
+#define DMA_BUF_MAX_PLANES 4
 
 struct _egl_image_attribs
 {
@@ -67,7 +67,8 @@ struct _egl_image_attribs
/* EGL_WL_bind_wayland_display */
EGLint PlaneWL;
 
-   /* EGL_EXT_image_dma_buf_import */
+   /* EGL_EXT_image_dma_buf_import and
+* EGL_EXT_image_dma_buf_import_modifiers */
struct _egl_image_attrib_int DMABufFourCC;
struct _egl_image_attrib_int DMABufPlaneFds[DMA_BUF_MAX_PLANES];
struct _egl_image_attrib_int DMABufPlaneOffsets[DMA_BUF_MAX_PLANES];
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 01/14] egl: return error for unknown EGLImage attributes

2016-11-24 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

Commit 0135e5d6c83add5e539492a4899504e33f3f2434 "egl: Add support for
more EGLImage extensions to EGL core." removed an error code for unknown
EGLImage attributes without explaining why.

EGL_KHR_image_base says:

   * If an attribute specified in  is not one of the
 attributes listed in Table bbb, the error EGL_BAD_PARAMETER is
 generated.

Implement this.

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
CC: <mesa-sta...@lists.freedesktop.org>
---
 src/egl/main/eglimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index 818b597..411d1ca 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -170,7 +170,7 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, 
_EGLDisplay *dpy,
  break;
 
   default:
- /* unknown attrs are ignored */
+ err = EGL_BAD_PARAMETER;
  break;
   }
 
-- 
2.6.2

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


[Mesa-dev] [PATCH v2 00/14] implement EGL_EXT_image_dma_buf_import_modifiers v2

2016-11-24 Thread Varad Gautam
This is the second revision to the EGL_EXT_image_dma_buf_import_modifiers [1]
series at [2], addressing the comments received. This diverges from v1 due to
some reordered/squashed changes, hence the resend.

Major modifications include:
* Both format and modifier queries are now handled in the driver, instead of
advertising all formats as supported by all drivers, and exposed under a
common PIPE_CAP_QUERY_DMABUF_ATTRIBS flag.
* The implementation makes sure that the same modifier is passed for all planes
used for EGLImage creation.

[1] 
https://www.khronos.org/registry/egl/extensions/EXT/EGL_EXT_image_dma_buf_import_modifiers.txt
[2] https://patchwork.freedesktop.org/series/15348/

Pekka Paalanen (4):
  egl: return error for unknown EGLImage attributes
  egl: introduce DMA_BUF_MAX_PLANES
  egl/main: add support for fourth plane tokens
  dri: support DRIimage creation from dmabufs with modifiers

Varad Gautam (10):
  egl: update eglext.h
  st/dri: implement DRIimage creation from dmabufs with modifiers
  egl_dri2: add support for using modifier attributes in
eglCreateImageKHR
  dri: add queryDmaBufFormats and queryDmaBufModifiers to DRIimage
  gallium: introduce dmabuf format and modifier querying
  st/dri: support format queries
  egl: implement eglQueryDmaBufFormatsEXT
  st/dri: support format modifier queries
  egl: implement eglQueryDmaBufModifiersEXT
  egl: advertise EGL_EXT_image_dma_buf_import_modifiers

 include/EGL/eglext.h |  60 -
 include/GL/internal/dri_interface.h  |  41 +-
 src/egl/drivers/dri2/egl_dri2.c  | 158 ---
 src/egl/main/eglapi.c|  41 ++
 src/egl/main/eglapi.h|   9 ++
 src/egl/main/egldisplay.h|   1 +
 src/egl/main/eglimage.c  |  68 +-
 src/egl/main/eglimage.h  |  13 +-
 src/gallium/docs/source/screen.rst   |   2 +
 src/gallium/drivers/freedreno/freedreno_screen.c |   1 +
 src/gallium/drivers/i915/i915_screen.c   |   1 +
 src/gallium/drivers/ilo/ilo_screen.c |   1 +
 src/gallium/drivers/llvmpipe/lp_screen.c |   1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   |   1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   |   1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   |   1 +
 src/gallium/drivers/r300/r300_screen.c   |   1 +
 src/gallium/drivers/r600/r600_pipe.c |   1 +
 src/gallium/drivers/radeonsi/si_pipe.c   |   1 +
 src/gallium/drivers/softpipe/sp_screen.c |   1 +
 src/gallium/drivers/svga/svga_screen.c   |   1 +
 src/gallium/drivers/swr/swr_screen.cpp   |   1 +
 src/gallium/drivers/vc4/vc4_screen.c |   1 +
 src/gallium/drivers/virgl/virgl_screen.c |   1 +
 src/gallium/include/pipe/p_defines.h |   1 +
 src/gallium/include/pipe/p_screen.h  |  20 +++
 src/gallium/include/state_tracker/drm_driver.h   |   2 +
 src/gallium/state_trackers/dri/dri2.c|  78 ++-
 28 files changed, 481 insertions(+), 28 deletions(-)

-- 
2.6.2

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


Re: [Mesa-dev] [PATCH 10/13] gallium: introduce format modifier querying

2016-11-16 Thread Varad Gautam
On Wed, Nov 16, 2016 at 12:25 PM, Michel Dänzer <mic...@daenzer.net> wrote:
> On 15/11/16 11:24 PM, Varad Gautam wrote:
>> From: Varad Gautam <varad.gau...@collabora.com>
>>
>> drivers should implement pipe_screen->get_modifiers_for_format and
>> advertise it with PIPE_CAP_QUERY_DMABUF_MODIFIERS to support format
>> modifier queries.
>
> Is there any point in having the PIPE_CAP_QUERY_DMABUF_MODIFIERS cap, vs
> just testing if pipe_screen->get_modifiers_for_format != NULL ?

The PIPE_CAP is to convey that the driver supports modifier queries as
compatible with the egl ext (64b), as compared to drivers that wish to treat
modifiers differently. If this isn't a concern, I can replace it with the NULL
check.

Thanks,
Varad

>
>
> --
> Earthling Michel Dänzer   |   http://www.amd.com
> Libre software enthusiast | Mesa and X developer
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v2] egl_dri2: add support for using modifier attributes in eglCreateImageKHR

2016-11-16 Thread Varad Gautam
From: Pekka Paalanen <pekka.paala...@collabora.co.uk>

allow creating EGLImages with dmabuf format modifiers when target is
EGL_LINUX_DMA_BUF_EXT for EGL_EXT_image_dma_buf_import_modifiers.

v2: clear modifier assembling and error label name (Eric Engestrom)

Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
Reviewed-by: Eric Engestrom <eric.engest...@imgtec.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 67 ++---
 src/egl/main/egldisplay.h   |  1 +
 src/egl/main/eglimage.c | 49 ++
 src/egl/main/eglimage.h |  2 ++
 4 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 58d16e1..f98416c 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1937,6 +1937,21 @@ dri2_check_dma_buf_attribs(const _EGLImageAttribs *attrs)
   }
}
 
+   /**
+* If  is EGL_LINUX_DMA_BUF_EXT, both or neither of the following
+* attribute values may be given.
+*
+* This is referring to EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT and
+* EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, and the same for other planes.
+*/
+   for (i = 0; i < DMA_BUF_MAX_PLANES; ++i) {
+  if (attrs->DMABufPlaneModifiersLo[i].IsPresent !=
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
+ _eglError(EGL_BAD_PARAMETER, "modifier attribute lo or hi missing");
+ return EGL_FALSE;
+  }
+   }
+
return EGL_TRUE;
 }
 
@@ -2043,7 +2058,9 @@ dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
for (i = plane_n; i < DMA_BUF_MAX_PLANES; ++i) {
   if (attrs->DMABufPlaneFds[i].IsPresent ||
   attrs->DMABufPlaneOffsets[i].IsPresent ||
-  attrs->DMABufPlanePitches[i].IsPresent) {
+  attrs->DMABufPlanePitches[i].IsPresent ||
+  attrs->DMABufPlaneModifiersLo[i].IsPresent ||
+  attrs->DMABufPlaneModifiersHi[i].IsPresent) {
  _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes");
  return 0;
   }
@@ -2076,6 +2093,8 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, _EGLContext 
*ctx,
int fds[DMA_BUF_MAX_PLANES];
int pitches[DMA_BUF_MAX_PLANES];
int offsets[DMA_BUF_MAX_PLANES];
+   uint64_t modifiers[DMA_BUF_MAX_PLANES];
+   int nonzero_modifier_found = 0;
unsigned error;
 
/**
@@ -2106,18 +2125,44 @@ dri2_create_image_dma_buf(_EGLDisplay *disp, 
_EGLContext *ctx,
   fds[i] = attrs.DMABufPlaneFds[i].Value;
   pitches[i] = attrs.DMABufPlanePitches[i].Value;
   offsets[i] = attrs.DMABufPlaneOffsets[i].Value;
+  if (attrs.DMABufPlaneModifiersLo[i].IsPresent) {
+ modifiers[i] = (attrs.DMABufPlaneModifiersHi[i].Value << 32) |
+attrs.DMABufPlaneModifiersLo[i].Value;
+ if (modifiers[i] != 0)
+nonzero_modifier_found = EGL_TRUE;
+  } else {
+ modifiers[i] = 0;
+  }
}
 
-   dri_image =
-  dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
- attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
- fds, num_fds, pitches, offsets,
- attrs.DMABufYuvColorSpaceHint.Value,
- attrs.DMABufSampleRangeHint.Value,
- attrs.DMABufChromaHorizontalSiting.Value,
- attrs.DMABufChromaVerticalSiting.Value,
- ,
- NULL);
+   if (nonzero_modifier_found && dri2_dpy->image->createImageFromDmaBufs2) {
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs2(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+fds, num_fds, pitches, offsets, modifiers,
+attrs.DMABufYuvColorSpaceHint.Value,
+attrs.DMABufSampleRangeHint.Value,
+attrs.DMABufChromaHorizontalSiting.Value,
+attrs.DMABufChromaVerticalSiting.Value,
+,
+NULL);
+   } else {
+  if (nonzero_modifier_found) {
+ _eglError(EGL_BAD_MATCH, "unsupported dma_buf format modifier");
+ return EGL_NO_IMAGE_KHR;
+  }
+
+  dri_image =
+ dri2_dpy->image->createImageFromDmaBufs(dri2_dpy->dri_screen,
+attrs.Width, attrs.Height, attrs.DMABufFourCC.Value,
+fds, num_fds, pitches, offsets,
+attrs.DMABufYuvColorSpaceHint.Value,
+attrs.DMABufSampleRangeHint.Value,
+attrs.DMABufChromaHorizontalSiting.Value,
+attrs.DMABufChromaVerticalSiting.Value,
+,
+NULL);
+   }
dri2_create_image_khr_texture_error(error);
 
if (!dri_image)
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 62d9a11..7a59dc5 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -101,6 +101,7 @@ struct _egl_extensions
 

[Mesa-dev] [PATCH 11/13] st/dri: support format modifier queries

2016-11-15 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

ask the driver for supported modifiers for a given format.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/state_trackers/dri/dri2.c | 20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index a2b87a7..2684481 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1259,6 +1259,21 @@ dri2_from_fds(__DRIscreen *screen, int width, int 
height, int fourcc,
return img;
 }
 
+static void
+dri2_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
+ uint64_t *modifiers, int *count)
+{
+   struct dri_screen *screen = dri_screen(_screen);
+   struct pipe_screen *pscreen = screen->base.screen;
+   int dri_components;
+   enum pipe_format format = dri2_format_to_pipe_format(
+ convert_fourcc(fourcc,_components));
+
+   if (pscreen->get_param(pscreen, PIPE_CAP_QUERY_DMABUF_MODIFIERS))
+  pscreen->get_modifiers_for_format(pscreen, format, max, modifiers,
+count);
+}
+
 static __DRIimage *
 dri2_from_dma_bufs(__DRIscreen *screen,
int width, int height, int fourcc,
@@ -1425,7 +1440,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 14 },
+.base = { __DRI_IMAGE, 15 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1938,6 +1953,8 @@ dri2_init_screen(__DRIscreen * sPriv)
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
  dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+ dri2ImageExtension.queryDmaBufModifiers =
+dri2_query_dma_buf_modifiers;
   }
}
 
@@ -2011,6 +2028,7 @@ dri_kms_init_screen(__DRIscreen * sPriv)
   dri2ImageExtension.createImageFromFds = dri2_from_fds;
   dri2ImageExtension.createImageFromDmaBufs = dri2_from_dma_bufs;
   dri2ImageExtension.createImageFromDmaBufs2 = dri2_from_dma_bufs2;
+  dri2ImageExtension.queryDmaBufModifiers = dri2_query_dma_buf_modifiers;
}
 
sPriv->extensions = dri_screen_extensions;
-- 
2.6.2

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


[Mesa-dev] [PATCH 06/13] st/dri: implement DRIimage creation from dmabufs with modifiers

2016-11-15 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

support importing dmabufs into DRIimage taking format modifiers in
account, as per DRIimage extension version 14.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/include/state_tracker/drm_driver.h |  2 ++
 src/gallium/state_trackers/dri/dri2.c  | 45 +++---
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/gallium/include/state_tracker/drm_driver.h 
b/src/gallium/include/state_tracker/drm_driver.h
index c80fb09..8b9d6bc 100644
--- a/src/gallium/include/state_tracker/drm_driver.h
+++ b/src/gallium/include/state_tracker/drm_driver.h
@@ -45,6 +45,8 @@ struct winsys_handle
 * Output for texture_get_handle.
 */
unsigned offset;
+
+   uint64_t modifier;
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a2b87a7 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -884,7 +884,7 @@ static __DRIimage *
 dri2_create_image_from_fd(__DRIscreen *_screen,
   int width, int height, int fourcc,
   int *fds, int num_fds, int *strides,
-  int *offsets, unsigned *error,
+  int *offsets, uint64_t *modifiers, unsigned *error,
   int *dri_components, void *loaderPrivate)
 {
struct winsys_handle whandles[3];
@@ -929,6 +929,8 @@ dri2_create_image_from_fd(__DRIscreen *_screen,
   whandles[i].handle = (unsigned)fds[i];
   whandles[i].stride = (unsigned)strides[i];
   whandles[i].offset = (unsigned)offsets[i];
+  if (modifiers)
+ whandles[i].modifier = modifiers[i];
}
 
if (fourcc == __DRI_IMAGE_FOURCC_YVU420) {
@@ -1248,7 +1250,7 @@ dri2_from_fds(__DRIscreen *screen, int width, int height, 
int fourcc,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, NULL,
+   fds, num_fds, strides, offsets, NULL, NULL,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1273,7 +1275,7 @@ dri2_from_dma_bufs(__DRIscreen *screen,
int dri_components;
 
img = dri2_create_image_from_fd(screen, width, height, fourcc,
-   fds, num_fds, strides, offsets, error,
+   fds, num_fds, strides, offsets, NULL, error,
_components, loaderPrivate);
if (img == NULL)
   return NULL;
@@ -1288,6 +1290,38 @@ dri2_from_dma_bufs(__DRIscreen *screen,
return img;
 }
 
+static __DRIimage *
+dri2_from_dma_bufs2(__DRIscreen *screen,
+int width, int height, int fourcc,
+int *fds, int num_fds,
+int *strides, int *offsets,
+uint64_t *modifiers,
+enum __DRIYUVColorSpace yuv_color_space,
+enum __DRISampleRange sample_range,
+enum __DRIChromaSiting horizontal_siting,
+enum __DRIChromaSiting vertical_siting,
+unsigned *error,
+void *loaderPrivate)
+{
+   __DRIimage *img;
+   int dri_components;
+
+   img = dri2_create_image_from_fd(screen, width, height, fourcc,
+   fds, num_fds, strides, offsets, modifiers,
+   error, _components, loaderPrivate);
+   if (img == NULL)
+  return NULL;
+
+   img->yuv_color_space = yuv_color_space;
+   img->sample_range = sample_range;
+   img->horizontal_siting = horizontal_siting;
+   img->vertical_siting = vertical_siting;
+   img->dri_components = dri_components;
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
 static void
 dri2_blit_image(__DRIcontext *context, __DRIimage *dst, __DRIimage *src,
 int dstx0, int dsty0, int dstwidth, int dstheight,
@@ -1391,7 +1425,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-.base = { __DRI_IMAGE, 12 },
+.base = { __DRI_IMAGE, 14 },
 
 .createImageFromName  = dri2_create_image_from_name,
 .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1409,6 +1443,7 @@ static __DRIimageExtension dri2ImageExtension = {
 .getCapabilities  = dri2_get_capabilities,
 .mapImage = dri2_map_image,
 .unmapImage   = dri2_unmap_image,
+.createImageFromDmaBufs2  = NULL,
 };
 
 
@@ -1902,6 +1937,7 @@ dri2_init_screen(__DRIscreen * sPriv)
   (cap & DRM_PRIME_CAP_IMPORT)) {
  dri2ImageExtension.createImageFromFds = dri2_from_fds;
  dri2ImageE

[Mesa-dev] [PATCH 10/13] gallium: introduce format modifier querying

2016-11-15 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

drivers should implement pipe_screen->get_modifiers_for_format and
advertise it with PIPE_CAP_QUERY_DMABUF_MODIFIERS to support format
modifier queries.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/gallium/docs/source/screen.rst   | 2 ++
 src/gallium/drivers/freedreno/freedreno_screen.c | 1 +
 src/gallium/drivers/i915/i915_screen.c   | 1 +
 src/gallium/drivers/ilo/ilo_screen.c | 1 +
 src/gallium/drivers/llvmpipe/lp_screen.c | 1 +
 src/gallium/drivers/nouveau/nv30/nv30_screen.c   | 1 +
 src/gallium/drivers/nouveau/nv50/nv50_screen.c   | 1 +
 src/gallium/drivers/nouveau/nvc0/nvc0_screen.c   | 1 +
 src/gallium/drivers/r300/r300_screen.c   | 1 +
 src/gallium/drivers/r600/r600_pipe.c | 1 +
 src/gallium/drivers/radeonsi/si_pipe.c   | 1 +
 src/gallium/drivers/softpipe/sp_screen.c | 1 +
 src/gallium/drivers/svga/svga_screen.c   | 1 +
 src/gallium/drivers/swr/swr_screen.cpp   | 1 +
 src/gallium/drivers/vc4/vc4_screen.c | 1 +
 src/gallium/drivers/virgl/virgl_screen.c | 1 +
 src/gallium/include/pipe/p_defines.h | 1 +
 src/gallium/include/pipe/p_screen.h  | 7 +++
 18 files changed, 25 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 6ad2bec..1775fe3 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -364,6 +364,8 @@ The integer capabilities:
 * ``PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS``: Whether interleaved stream
   output mode is able to interleave across buffers. This is required for
   ARB_transform_feedback3.
+* ``PIPE_CAP_QUERY_DMABUF_MODIFIERS``: Whether the driver supports modifier
+  queries for a given format.
 
 
 .. _pipe_capf:
diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c 
b/src/gallium/drivers/freedreno/freedreno_screen.c
index 97da0d7..2786d45 100644
--- a/src/gallium/drivers/freedreno/freedreno_screen.c
+++ b/src/gallium/drivers/freedreno/freedreno_screen.c
@@ -288,6 +288,7 @@ fd_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_MODIFIERS:
return 0;
 
case PIPE_CAP_MAX_VIEWPORTS:
diff --git a/src/gallium/drivers/i915/i915_screen.c 
b/src/gallium/drivers/i915/i915_screen.c
index bfadca3..ce42e04 100644
--- a/src/gallium/drivers/i915/i915_screen.c
+++ b/src/gallium/drivers/i915/i915_screen.c
@@ -278,6 +278,7 @@ i915_get_param(struct pipe_screen *screen, enum pipe_cap 
cap)
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_MODIFIERS:
   return 0;
 
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
diff --git a/src/gallium/drivers/ilo/ilo_screen.c 
b/src/gallium/drivers/ilo/ilo_screen.c
index f3f182c..05fc906 100644
--- a/src/gallium/drivers/ilo/ilo_screen.c
+++ b/src/gallium/drivers/ilo/ilo_screen.c
@@ -517,6 +517,7 @@ ilo_get_param(struct pipe_screen *screen, enum pipe_cap 
param)
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_MODIFIERS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c 
b/src/gallium/drivers/llvmpipe/lp_screen.c
index 4b502f0..2a8fa76 100644
--- a/src/gallium/drivers/llvmpipe/lp_screen.c
+++ b/src/gallium/drivers/llvmpipe/lp_screen.c
@@ -338,6 +338,7 @@ llvmpipe_get_param(struct pipe_screen *screen, enum 
pipe_cap param)
case PIPE_CAP_MAX_WINDOW_RECTANGLES:
case PIPE_CAP_POLYGON_OFFSET_UNITS_UNSCALED:
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
+   case PIPE_CAP_QUERY_DMABUF_MODIFIERS:
   return 0;
}
/* should only get here on unhandled cases */
diff --git a/src/gallium/drivers/nouveau/nv30/nv30_screen.c 
b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
index 96708c0..6ba768b 100644
--- a/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nouveau/nv30/nv30_screen.c
@@ -203,6 +203,7 @@ nv30_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap param)
case PIPE_CAP_VIEWPORT_SUBPIXEL_BITS:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
+   case PIPE_CAP_QUERY_DMABUF_MODIFIERS:
   return 0;
 
case PIPE_CAP_VENDOR_ID:
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_screen.c 
b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
index 50cdeda..5c922ed 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_screen.c
@@ -255,6 +255,7 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum 
pipe_cap 

[Mesa-dev] [PATCH 12/13] egl: implement eglQueryDmaBufModifiersEXT

2016-11-15 Thread Varad Gautam
From: Varad Gautam <varad.gau...@collabora.com>

query and return supported dmabuf format modifiers for
EGL_EXT_image_dma_buf_import_modifiers.

Signed-off-by: Varad Gautam <varad.gau...@collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c | 39 +++
 src/egl/main/eglapi.c   | 21 +
 src/egl/main/eglapi.h   |  5 +
 3 files changed, 65 insertions(+)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index de2d4df..443e0a3 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -2155,6 +2155,44 @@ dri2_query_dma_buf_formats(_EGLDriver *drv, _EGLDisplay 
*disp,
return EGL_TRUE;
 }
 
+static EGLBoolean
+dri2_query_dma_buf_modifiers(_EGLDriver *drv, _EGLDisplay *disp, EGLint format,
+ EGLint max, EGLuint64KHR *modifiers,
+ EGLBoolean *external_only, EGLint *count)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   EGLint i;
+
+   if (max < 0) {
+  _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
+  return EGL_FALSE;
+   }
+
+   if (max > 0 && modifiers == NULL) {
+  _eglError(EGL_BAD_PARAMETER, "invalid modifiers array");
+  return EGL_FALSE;
+   }
+
+   for (i = 0; i < ARRAY_SIZE(dma_buf_formats); i++) {
+  if (format == dma_buf_formats[i])
+ break;
+   }
+   if (i == ARRAY_SIZE(dma_buf_formats)) {
+  _eglError(EGL_BAD_PARAMETER, "invalid format");
+  return EGL_FALSE;
+   }
+
+   dri2_dpy->image->queryDmaBufModifiers(dri2_dpy->dri_screen, format, max,
+ modifiers, count);
+
+   if (external_only != NULL) {
+  for (i = 0; i < *count && i < max; i++)
+ external_only[i] = EGL_TRUE;
+   }
+
+   return EGL_TRUE;
+}
+
 /**
  * The spec says:
  *
@@ -3040,6 +3078,7 @@ _eglBuiltInDriverDRI2(const char *args)
dri2_drv->base.API.ExportDMABUFImageQueryMESA = 
dri2_export_dma_buf_image_query_mesa;
dri2_drv->base.API.ExportDMABUFImageMESA = dri2_export_dma_buf_image_mesa;
dri2_drv->base.API.QueryDmaBufFormatsEXT = dri2_query_dma_buf_formats;
+   dri2_drv->base.API.QueryDmaBufModifiersEXT = dri2_query_dma_buf_modifiers;
 #endif
 #ifdef HAVE_WAYLAND_PLATFORM
dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 53d34d8..cd65115 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -2275,6 +2275,26 @@ eglQueryDmaBufFormatsEXT(EGLDisplay dpy, EGLint 
max_formats,
RETURN_EGL_EVAL(disp, ret);
 }
 
+static EGLBoolean EGLAPIENTRY
+eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers,
+   EGLuint64KHR *modifiers, EGLBoolean *external_only,
+   EGLint *num_modifiers)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   EGLBoolean ret;
+
+   _EGL_FUNC_START(NULL, EGL_NONE, NULL, EGL_FALSE);
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+
+   ret = drv->API.QueryDmaBufModifiersEXT(drv, disp, format, max_modifiers,
+  modifiers, external_only,
+  num_modifiers);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
 __eglMustCastToProperFunctionPointerType EGLAPIENTRY
 eglGetProcAddress(const char *procname)
 {
@@ -2359,6 +2379,7 @@ eglGetProcAddress(const char *procname)
   { "eglDebugMessageControlKHR", (_EGLProc) eglDebugMessageControlKHR },
   { "eglQueryDebugKHR", (_EGLProc) eglQueryDebugKHR },
   { "eglQueryDmaBufFormatsEXT", (_EGLProc) eglQueryDmaBufFormatsEXT },
+  { "eglQueryDmaBufModifiersEXT", (_EGLProc) eglQueryDmaBufModifiersEXT },
   { NULL, NULL }
};
EGLint i;
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 13388b1..3428195 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -200,6 +200,11 @@ struct _egl_api
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDriver *drv, _EGLDisplay *dpy,
EGLint max_formats, EGLint *formats,
EGLint *num_formats);
+   EGLBoolean (*QueryDmaBufModifiersEXT) (_EGLDriver *drv, _EGLDisplay *dpy,
+  EGLint format, EGLint max_modifiers,
+  EGLuint64KHR *modifiers,
+  EGLBoolean *external_only,
+  EGLint *num_modifiers);
 };
 
 EGLint _eglConvertIntsToAttribs(const EGLint *int_list,
-- 
2.6.2

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


  1   2   >