Re: [Mesa-dev] [PATCH V2 kmscube] cube-tex: make use of modifiers

2018-04-02 Thread Daniel Stone
Hi Christian,

On 2 April 2018 at 12:49, Christian Gmeiner  wrote:
> Fixes rendering issues with mode rgba on etnaviv. I have applied
> the same change for nv12 variants but they are not supported on
> etnaviv.
>
> [...]
>
> +   EGLint attr[] = {
> EGL_WIDTH, texw,
> EGL_HEIGHT, texh,
> EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ABGR,
> EGL_DMA_BUF_PLANE0_FD_EXT, fd,
> EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
> EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
> +   EGL_NONE, EGL_NONE, /* modifier lo */
> +   EGL_NONE, EGL_NONE, /* modifier hi */
> EGL_NONE
> };
> +
> +   if (egl->modifiers_supported) {
> +   unsigned size =  ARRAY_SIZE(attr);
> +   attr[size - 5] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
> +   attr[size - 4] = modifier & 0x;
> +   attr[size - 3] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
> +   attr[size - 2] = modifier >> 32;
> +   }

All these checks should be 'if (egl->modifiers_supported && modifier
!= DRM_FORMAT_MOD_INVALID)'.

With that fixed, and I suppose with the same weak-symbol handling as
the others, this is:
Reviewed-by: Daniel Stone 

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


[Mesa-dev] [PATCH V2 kmscube] cube-tex: make use of modifiers

2018-04-02 Thread Christian Gmeiner
Fixes rendering issues with mode rgba on etnaviv. I have applied
the same change for nv12 variants but they are not supported on
etnaviv.

Signed-off-by: Christian Gmeiner 
---
 common.c   |  3 +++
 common.h   | 19 +
 cube-tex.c | 91 +-
 3 files changed, 101 insertions(+), 12 deletions(-)

diff --git a/common.c b/common.c
index 1d97c91..faecd42 100644
--- a/common.c
+++ b/common.c
@@ -216,6 +216,9 @@ int init_egl(struct egl *egl, const struct gbm *gbm)
get_proc_dpy(EGL_KHR_fence_sync, eglClientWaitSyncKHR);
get_proc_dpy(EGL_ANDROID_native_fence_sync, eglDupNativeFenceFDANDROID);
 
+   egl->modifiers_supported = has_ext(egl_exts_dpy,
+  
"EGL_EXT_image_dma_buf_import_modifiers");
+
printf("Using display %p with EGL version %d.%d\n",
egl->display, major, minor);
 
diff --git a/common.h b/common.h
index 42eb236..898010d 100644
--- a/common.h
+++ b/common.h
@@ -31,6 +31,7 @@
 
 #include 
 #include 
+#include 
 
 #ifndef DRM_FORMAT_MOD_LINEAR
 #define DRM_FORMAT_MOD_LINEAR 0
@@ -59,6 +60,22 @@ EGLAPI EGLSurface EGLAPIENTRY 
eglCreatePlatformPixmapSurfaceEXT (EGLDisplay dpy,
 
 #define WEAK __attribute__((weak))
 
+/* Define tokens from EGL_EXT_image_dma_buf_import_modifiers */
+#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
+#endif
+
 struct gbm {
struct gbm_device *dev;
struct gbm_surface *surface;
@@ -85,6 +102,8 @@ struct egl {
PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR;
PFNEGLDUPNATIVEFENCEFDANDROIDPROC eglDupNativeFenceFDANDROID;
 
+   bool modifiers_supported;
+
void (*draw)(unsigned i);
 };
 
diff --git a/cube-tex.c b/cube-tex.c
index 9e38ae8..71916e3 100644
--- a/cube-tex.c
+++ b/cube-tex.c
@@ -29,6 +29,7 @@
 #include "common.h"
 #include "esUtil.h"
 
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
 struct {
struct egl egl;
@@ -213,7 +214,10 @@ static const char *fragment_shader_source_2img =
 
 static const uint32_t texw = 512, texh = 512;
 
-static int get_fd_rgba(uint32_t *pstride)
+WEAK uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo);
+
+static int get_fd_rgba(uint32_t *pstride, uint64_t *modifier)
 {
struct gbm_bo *bo;
void *map_data = NULL;
@@ -235,6 +239,11 @@ static int get_fd_rgba(uint32_t *pstride)
 
fd = gbm_bo_get_fd(bo);
 
+   if (gbm_bo_get_modifier)
+   *modifier = gbm_bo_get_modifier(bo);
+   else
+   *modifier = DRM_FORMAT_MOD_LINEAR;
+
/* we have the fd now, no longer need the bo: */
gbm_bo_destroy(bo);
 
@@ -243,7 +252,7 @@ static int get_fd_rgba(uint32_t *pstride)
return fd;
 }
 
-static int get_fd_y(uint32_t *pstride)
+static int get_fd_y(uint32_t *pstride, uint64_t *modifier)
 {
struct gbm_bo *bo;
void *map_data = NULL;
@@ -265,6 +274,11 @@ static int get_fd_y(uint32_t *pstride)
 
fd = gbm_bo_get_fd(bo);
 
+   if (gbm_bo_get_modifier)
+   *modifier = gbm_bo_get_modifier(bo);
+   else
+   *modifier = DRM_FORMAT_MOD_LINEAR;
+
/* we have the fd now, no longer need the bo: */
gbm_bo_destroy(bo);
 
@@ -273,7 +287,7 @@ static int get_fd_y(uint32_t *pstride)
return fd;
 }
 
-static int get_fd_uv(uint32_t *pstride)
+static int get_fd_uv(uint32_t *pstride, uint64_t *modifier)
 {
struct gbm_bo *bo;
void *map_data = NULL;
@@ -295,6 +309,11 @@ static int get_fd_uv(uint32_t *pstride)
 
fd = gbm_bo_get_fd(bo);
 
+   if (gbm_bo_get_modifier)
+   *modifier = gbm_bo_get_modifier(bo);
+   else
+   *modifier = DRM_FORMAT_MOD_LINEAR;
+
/* we have the fd now, no longer need the bo: */
gbm_bo_destroy(bo);
 
@@ -306,16 +325,27 @@ static int get_fd_uv(uint32_t *pstride)
 static int init_tex_rgba(void)
 {
uint32_t stride;
-   int fd = get_fd_rgba();
-   const EGLint attr[] = {
+   uint64_t modifier;
+   int fd = get_fd_rgba(, );
+   EGLint attr[] = {
EGL_WIDTH, texw,
EGL_HEIGHT, texh,
EGL_LINUX_DRM_FOURCC_EXT, DRM_FORMAT_ABGR,
EGL_DMA_BUF_PLANE0_FD_EXT, fd,
EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,