[Mesa-dev] [PATCH] anv: fix GetPhysicalDeviceProperties to return timestampPeriod in ns

2016-10-05 Thread Philipp Zabel
According to chapters 16.5. (Timestamp Queries) and 30.2 (Limits) of the
Vulkan Specification 1.0.29, the .limits.timestampPeriod field returned
by vkGetPhysicalDeviceProperties is measured in nanoseconds, not in
seconds.

Signed-off-by: Philipp Zabel 
---
 src/intel/vulkan/anv_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index f786ebe..c7b9979 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -572,7 +572,7 @@ void anv_GetPhysicalDeviceProperties(
   .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT,
   .maxSampleMaskWords   = 1,
   .timestampComputeAndGraphics  = false,
-  .timestampPeriod  = time_stamp_base / (1000 * 
1000 * 1000),
+  .timestampPeriod  = time_stamp_base,
   .maxClipDistances = 0 /* FIXME */,
   .maxCullDistances = 0 /* FIXME */,
   .maxCombinedClipAndCullDistances  = 0 /* FIXME */,
-- 
2.9.3

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


[Mesa-dev] [PATCH 2/4] st/dri: ask the driver to update its internal copies on reimport

2016-12-02 Thread Philipp Zabel
For imported buffers that can't be used directly as a source to the
texture samplers, the pipe driver might need to create an internal
copy, for example in a different tiling layout. When buffers are
reimported they may contain new image data, so the driver internal
copies need to be recreated.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a216e83 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1168,6 +1168,10 @@ dri2_from_planar(__DRIimage *image, int plane, void 
*loaderPrivate)
if (img == NULL)
   return NULL;
 
+   if (img->texture->screen->resource_changed)
+  img->texture->screen->resource_changed(img->texture->screen,
+ img->texture);
+
/* set this to 0 for sub images. */
img->dri_components = 0;
return img;
-- 
2.10.2

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


[Mesa-dev] [PATCH 3/4] etnaviv: initialize seqno of imported resources

2016-12-02 Thread Philipp Zabel
Imported resources already have contents that we want to be copied to
texture resources derived from them. Set initial seqno of imported
resources to 1, just as if they had already been rendered to.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index aefe65b..a8858c5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -325,6 +325,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->bo)
   goto fail;
 
+   rsc->seqno = 1;
+
level->width = tmpl->width0;
level->height = tmpl->height0;
 
-- 
2.10.2

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


[Mesa-dev] [PATCH 0/4] etnaviv: update derived texture resources of (re)imported buffers

2016-12-02 Thread Philipp Zabel
Hi,

to get weston / wayland_egl working on etnaviv, we need to update the texture
resources derived from imported buffers every time they are re-imported.

This patchset is based on the github-etnaviv/for_mainline_v1 branch and adds
a new pipe_screen::resource_changed callback that is called inside
dri2_from_planar and instructs the pipe driver to invalidate the internal
(texture) resources that are derived from the re-imported resource.

The etnaviv implementation of resource_changed just sets the texture seqno
to the resource seqno - 1. The initial seqno of imported resources is set to 1
so that texture resources created from them are actually older and trigger the
resolve on first use.

regards
Philipp

Philipp Zabel (4):
  gallium: add pipe_screen::resource_changed
  st/dri: ask the driver to update its internal copies on reimport
  etnaviv: initialize seqno of imported resources
  etnaviv: implement resource_changed to invalidate internal resources
derived from imported buffers

 src/gallium/drivers/etnaviv/etnaviv_resource.c | 15 +++
 src/gallium/include/pipe/p_screen.h|  6 ++
 src/gallium/state_trackers/dri/dri2.c  |  4 
 3 files changed, 25 insertions(+)

-- 
2.10.2

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


[Mesa-dev] [PATCH 1/4] gallium: add pipe_screen::resource_changed

2016-12-02 Thread Philipp Zabel
Add a hook to tell drivers that an imported resource may have changed
and they need to update their internal derived resources.

Signed-off-by: Philipp Zabel 
---
 src/gallium/include/pipe/p_screen.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 255647e..e21229e 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -224,6 +224,12 @@ struct pipe_screen {
  struct winsys_handle *handle,
  unsigned usage);
 
+   /**
+* Trigger recreation of derived internal resources. This can be used for
+* reimporting external images that can't be directly used as texture
+* sampler source.
+*/
+   void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
 
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
-- 
2.10.2

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


[Mesa-dev] [PATCH 4/4] etnaviv: implement resource_changed to invalidate internal resources derived from imported buffers

2016-12-02 Thread Philipp Zabel
Implement the new resource_changed pipe callback to invalidate internal
resources derived from imported buffers. This is needed to update the
texture for re-imported renderables that may contain new contents.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index a8858c5..20ec8f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -275,6 +275,18 @@ etna_resource_create(struct pipe_screen *pscreen,
 }
 
 static void
+etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc)
+{
+   struct etna_resource *res = etna_resource(prsc);
+
+   /* Make sure texture is older than the imported renderable buffer,
+* so etna_update_sampler_source will copy the pixel data again.
+*/
+   if (res->texture)
+  etna_resource(res->texture)->seqno = res->seqno - 1;
+}
+
+static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
struct etna_resource *rsc = etna_resource(prsc);
@@ -436,5 +448,6 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_create = etna_resource_create;
pscreen->resource_from_handle = etna_resource_from_handle;
pscreen->resource_get_handle = etna_resource_get_handle;
+   pscreen->resource_changed = etna_resource_changed;
pscreen->resource_destroy = etna_resource_destroy;
 }
-- 
2.10.2

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


Re: [Mesa-dev] [PATCH 1/4] gallium: add pipe_screen::resource_changed

2016-12-05 Thread Philipp Zabel
Hi Marek,

Am Freitag, den 02.12.2016, 23:10 +0100 schrieb Marek Olšák:
> Shouldn't this be in pipe_context if it does a copy? It's basically
> the opposite of flush_resource, right?

I tried this at first (actually, at first I misunderstood the meaning of
invalidate_resource and reused that, for GL_OES_EGL_image_external:

https://patchwork.freedesktop.org/patch/89097/
https://patchwork.freedesktop.org/patch/89098/

I should update these to use resource_changed instead). But for
WL_bind_wayland_display, resource_changed needs to be called in the

eglCreateImageKHR ->
  dri2_create_image ->
dri2_drm_create_image_khr ->
  dri2_create_image_khr ->
dri2_create_image_wayland_wl_buffer ->
  dri2_from_planar

path, though. eglCreateImageKHR is called without context for the
EGL_WAYLAND_BUFFER_WL target when attaching an EGL wl_buffer to a
wl_surface.

I see resource_changed as complementary to the resource_create /
resource_from_handle functionality, which already resides in
pipe_screen.

regards
Philipp

> Marek
> 
> On Fri, Dec 2, 2016 at 4:27 PM, Philipp Zabel  wrote:
> > Add a hook to tell drivers that an imported resource may have changed
> > and they need to update their internal derived resources.
> >
> > Signed-off-by: Philipp Zabel 
> > ---
> >  src/gallium/include/pipe/p_screen.h | 6 ++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/src/gallium/include/pipe/p_screen.h 
> > b/src/gallium/include/pipe/p_screen.h
> > index 255647e..e21229e 100644
> > --- a/src/gallium/include/pipe/p_screen.h
> > +++ b/src/gallium/include/pipe/p_screen.h
> > @@ -224,6 +224,12 @@ struct pipe_screen {
> >   struct winsys_handle *handle,
> >   unsigned usage);
> >
> > +   /**
> > +* Trigger recreation of derived internal resources. This can be used 
> > for
> > +* reimporting external images that can't be directly used as texture
> > +* sampler source.
> > +*/
> > +   void (*resource_changed)(struct pipe_screen *, struct pipe_resource 
> > *pt);
> >
> > void (*resource_destroy)(struct pipe_screen *,
> > struct pipe_resource *pt);
> > --
> > 2.10.2
> >
> > ___
> > 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


Re: [Mesa-dev] [PATCH 1/4] gallium: add pipe_screen::resource_changed

2016-12-05 Thread Philipp Zabel
Am Montag, den 05.12.2016, 11:19 +0100 schrieb Philipp Zabel:
> Hi Marek,
> 
> Am Freitag, den 02.12.2016, 23:10 +0100 schrieb Marek Olšák:
> > Shouldn't this be in pipe_context if it does a copy?

Actually, resource_changed is not supposed to create a copy immediately.
Maybe instead of "trigger recreation of derived internal resources" it
should be described as "mark resource as changed so derived internal
resources will be recreated on next use".

> > It's basically the opposite of flush_resource, right?

Contrary to flush_resource, which has an immediate, externally visible
effect for which a context may be needed, resource_changed can just
update some internal state. The changed resource should be marked as
changed for all contexts, which is why I saw no reason to call
resource_changed with any one specific context.

regards
Philipp

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


[Mesa-dev] [PATCH v2 0/6] etnaviv: update derived texture resources of (re)imported buffers

2016-12-05 Thread Philipp Zabel
Hi,

to get weston / wayland_egl working on etnaviv, we need to update the texture
resources derived from imported buffers every time they are re-imported.

This patchset is based on the github-etnaviv/for_mainline_v1 branch and adds
a new pipe_screen::resource_changed callback that is called inside
dri2_from_planar and instructs the pipe driver to invalidate the internal
(texture) resources that are derived from the re-imported resource.

I've also added an updated version of the earlier GL_OES_EGL_image_external
patches that now use resource_changed to invalidate internal derived resources
when an external texture is (re-)bound, to comply with the specification.

The etnaviv implementation of resource_changed just sets the texture seqno
to the resource seqno - 1. The initial seqno of imported resources is set to 1
so that texture resources created from them are actually older and trigger the
resolve on first use.

Changes since v1:
 - Clarify intended use of pipe_screen::resource_changed
 - Add updated GL_OES_EGL_image_external patches

regards
Philipp

Philipp Zabel (6):
  gallium: add pipe_screen::resource_changed
  st/dri: ask the driver to update its internal copies on reimport
  etnaviv: initialize seqno of imported resources
  etnaviv: implement resource_changed to invalidate internal resources
derived from imported buffers
  mesa: update external textures when (re-)binding
  st/mesa: ask pipe driver to recreate derived internal resources when
(re-)binding external textures

 src/gallium/drivers/etnaviv/etnaviv_resource.c | 15 +++
 src/gallium/include/pipe/p_screen.h|  8 
 src/gallium/state_trackers/dri/dri2.c  |  4 
 src/mesa/main/texobj.c |  5 +++--
 src/mesa/state_tracker/st_atom_texture.c   |  4 
 5 files changed, 34 insertions(+), 2 deletions(-)

-- 
2.1.4

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


[Mesa-dev] [PATCH v2 3/6] etnaviv: initialize seqno of imported resources

2016-12-05 Thread Philipp Zabel
Imported resources already have contents that we want to be copied to
texture resources derived from them. Set initial seqno of imported
resources to 1, just as if it had already been rendered to.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index aefe65b..a8858c5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -325,6 +325,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->bo)
   goto fail;
 
+   rsc->seqno = 1;
+
level->width = tmpl->width0;
level->height = tmpl->height0;
 
-- 
2.1.4

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


[Mesa-dev] [PATCH v2 6/6] st/mesa: ask pipe driver to recreate derived internal resources when (re-)binding external textures

2016-12-05 Thread Philipp Zabel
Use the resource_changed callback to invalidate internal resources
derived from external textures when they are (re-)bound. This is needed
to comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_atom_texture.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index a1b1b88..32d0201 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -91,6 +91,10 @@ update_single_texture(struct st_context *st,
   stObj->prev_sRGBDecode = samp->sRGBDecode;
}
 
+   if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
+   stObj->pt->screen->resource_changed)
+ stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
+
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp, glsl_version);
return GL_TRUE;
-- 
2.1.4

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


[Mesa-dev] [PATCH v2 2/6] st/dri: ask the driver to update its internal copies on reimport

2016-12-05 Thread Philipp Zabel
For imported buffers that can't be used directly as a source to the
texture samplers, the pipe driver might need to create an internal
copy, for example in a different tiling layout. When buffers are
reimported they may contain new image data, so the driver internal
copies need to be recreated.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a216e83 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1168,6 +1168,10 @@ dri2_from_planar(__DRIimage *image, int plane, void 
*loaderPrivate)
if (img == NULL)
   return NULL;
 
+   if (img->texture->screen->resource_changed)
+  img->texture->screen->resource_changed(img->texture->screen,
+ img->texture);
+
/* set this to 0 for sub images. */
img->dri_components = 0;
return img;
-- 
2.1.4

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


[Mesa-dev] [PATCH v2 5/6] mesa: update external textures when (re-)binding

2016-12-05 Thread Philipp Zabel
To comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called,
do not bail out early from mesa_BindTextures if the target is
external.
This will later allow the state tracker to instruct the pipe driver
to invalidate internal resources derived from the external texture.

Signed-off-by: Philipp Zabel 
---
 src/mesa/main/texobj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index e5b7070..25b959d 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1619,9 +1619,10 @@ bind_texture(struct gl_context *ctx,
assert(targetIndex < NUM_TEXTURE_TARGETS);
 
/* Check if this texture is only used by this context and is already bound.
-* If so, just return.
+* If so, just return. For GL_OES_image_external, rebinding the texture
+* always must invalidate cached resources.
 */
-   {
+   if (targetIndex != TEXTURE_EXTERNAL_INDEX) {
   bool early_out;
   mtx_lock(&ctx->Shared->Mutex);
   early_out = ((ctx->Shared->RefCount == 1)
-- 
2.1.4

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


[Mesa-dev] [PATCH v2 4/6] etnaviv: implement resource_changed to invalidate internal resources derived from imported buffers

2016-12-05 Thread Philipp Zabel
Implement the resource_changed pipe callback to invalidate internal
resources derived from imported buffers. This is needed to update the
texture for re-imported renderables.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index a8858c5..20ec8f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -275,6 +275,18 @@ etna_resource_create(struct pipe_screen *pscreen,
 }
 
 static void
+etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc)
+{
+   struct etna_resource *res = etna_resource(prsc);
+
+   /* Make sure texture is older than the imported renderable buffer,
+* so etna_update_sampler_source will copy the pixel data again.
+*/
+   if (res->texture)
+  etna_resource(res->texture)->seqno = res->seqno - 1;
+}
+
+static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
struct etna_resource *rsc = etna_resource(prsc);
@@ -436,5 +448,6 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_create = etna_resource_create;
pscreen->resource_from_handle = etna_resource_from_handle;
pscreen->resource_get_handle = etna_resource_get_handle;
+   pscreen->resource_changed = etna_resource_changed;
pscreen->resource_destroy = etna_resource_destroy;
 }
-- 
2.1.4

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


[Mesa-dev] [PATCH v2 1/6] gallium: add pipe_screen::resource_changed

2016-12-05 Thread Philipp Zabel
Add a hook to tell drivers that an imported resource may have changed
and they need to update their internal derived resources.

Signed-off-by: Philipp Zabel 
---
Changes since v1:
 - Clarified intended of pipe_screen::resource_changed
---
 src/gallium/include/pipe/p_screen.h | 8 
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 255647e..0d3e4b6 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -224,6 +224,14 @@ struct pipe_screen {
  struct winsys_handle *handle,
  unsigned usage);
 
+   /**
+* Mark the resource as changed so derived internal resources will be
+* recreated on next use.
+*
+* This is necessary when reimporting external images that can't be directly
+* used as texture sampler source, to avoid sampling from old copies.
+*/
+   void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
 
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
-- 
2.1.4

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


[Mesa-dev] [PATCH v3 0/6] etnaviv: update derived texture resources of (re)imported buffers

2016-12-06 Thread Philipp Zabel
Hi,

to get weston / wayland_egl working on etnaviv, we need to update the texture
resources derived from imported buffers every time they are re-imported.

This patchset is based on the github-etnaviv/for_mainline_v1 branch and adds
a new pipe_screen::resource_changed callback that is called inside
dri2_from_planar and instructs the pipe driver to invalidate the internal
(texture) resources that are derived from the re-imported resource.

I've also added an updated version of the earlier GL_OES_EGL_image_external
patches that now use resource_changed to invalidate internal derived resources
when an external texture is (re-)bound, to comply with the specification.

The etnaviv implementation of resource_changed just sets the texture seqno
to the resource seqno - 1. The initial seqno of imported resources is set to 1
so that texture resources created from them are actually older and trigger the
resolve on first use.

Changes since v2:
 - Added resource_changed paragraph to screen.rst

regards
Philipp

Philipp Zabel (6):
  gallium: add pipe_screen::resource_changed
  st/dri: ask the driver to update its internal copies on reimport
  etnaviv: initialize seqno of imported resources
  etnaviv: implement resource_changed to invalidate internal resources
derived from imported buffers
  mesa: update external textures when (re-)binding
  st/mesa: ask pipe driver to recreate derived internal resources when
(re-)binding external textures

 src/gallium/docs/source/screen.rst | 14 ++
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 15 +++
 src/gallium/include/pipe/p_screen.h|  8 
 src/gallium/state_trackers/dri/dri2.c  |  4 
 src/mesa/main/texobj.c |  5 +++--
 src/mesa/state_tracker/st_atom_texture.c   |  4 
 6 files changed, 48 insertions(+), 2 deletions(-)

-- 
2.10.2

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


[Mesa-dev] [PATCH v3 1/6] gallium: add pipe_screen::resource_changed

2016-12-06 Thread Philipp Zabel
Add a hook to tell drivers that an imported resource may have changed
and they need to update their internal derived resources.

Signed-off-by: Philipp Zabel 
---
Changes since v2:
 - Added resource_changed paragraph to screen.rst
---
 src/gallium/docs/source/screen.rst  | 14 ++
 src/gallium/include/pipe/p_screen.h |  8 
 2 files changed, 22 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 33f233a..209b97c 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -700,6 +700,20 @@ which isn't multisampled.
 
 
 
+resource_changed
+
+
+Mark a resource as changed so derived internal resources will be recreated
+on next use.
+
+When importing external images that can't be directly used as texture sampler
+source, internal copies may have to be created that the hardware can sample
+from. When those resources are reimported, the image data may have changed, and
+the previously derived internal resources must be invalidated to avoid sampling
+from old copies.
+
+
+
 resource_destroy
 
 
diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 255647e..0d3e4b6 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -224,6 +224,14 @@ struct pipe_screen {
  struct winsys_handle *handle,
  unsigned usage);
 
+   /**
+* Mark the resource as changed so derived internal resources will be
+* recreated on next use.
+*
+* This is necessary when reimporting external images that can't be directly
+* used as texture sampler source, to avoid sampling from old copies.
+*/
+   void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
 
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
-- 
2.10.2

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


[Mesa-dev] [PATCH v3 5/6] mesa: update external textures when (re-)binding

2016-12-06 Thread Philipp Zabel
To comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called,
do not bail out early from mesa_BindTextures if the target is
external.
This will later allow the state tracker to instruct the pipe driver
to invalidate internal resources derived from the external texture.

Signed-off-by: Philipp Zabel 
---
 src/mesa/main/texobj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index e5b7070..25b959d 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1619,9 +1619,10 @@ bind_texture(struct gl_context *ctx,
assert(targetIndex < NUM_TEXTURE_TARGETS);
 
/* Check if this texture is only used by this context and is already bound.
-* If so, just return.
+* If so, just return. For GL_OES_image_external, rebinding the texture
+* always must invalidate cached resources.
 */
-   {
+   if (targetIndex != TEXTURE_EXTERNAL_INDEX) {
   bool early_out;
   mtx_lock(&ctx->Shared->Mutex);
   early_out = ((ctx->Shared->RefCount == 1)
-- 
2.10.2

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


[Mesa-dev] [PATCH v3 4/6] etnaviv: implement resource_changed to invalidate internal resources derived from imported buffers

2016-12-06 Thread Philipp Zabel
Implement the resource_changed pipe callback to invalidate internal
resources derived from imported buffers. This is needed to update the
texture for re-imported renderables.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index a8858c5..20ec8f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -275,6 +275,18 @@ etna_resource_create(struct pipe_screen *pscreen,
 }
 
 static void
+etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc)
+{
+   struct etna_resource *res = etna_resource(prsc);
+
+   /* Make sure texture is older than the imported renderable buffer,
+* so etna_update_sampler_source will copy the pixel data again.
+*/
+   if (res->texture)
+  etna_resource(res->texture)->seqno = res->seqno - 1;
+}
+
+static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
struct etna_resource *rsc = etna_resource(prsc);
@@ -436,5 +448,6 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_create = etna_resource_create;
pscreen->resource_from_handle = etna_resource_from_handle;
pscreen->resource_get_handle = etna_resource_get_handle;
+   pscreen->resource_changed = etna_resource_changed;
pscreen->resource_destroy = etna_resource_destroy;
 }
-- 
2.10.2

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


[Mesa-dev] [PATCH v3 3/6] etnaviv: initialize seqno of imported resources

2016-12-06 Thread Philipp Zabel
Imported resources already have contents that we want to be copied to
texture resources derived from them. Set initial seqno of imported
resources to 1, just as if it had already been rendered to.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index aefe65b..a8858c5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -325,6 +325,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->bo)
   goto fail;
 
+   rsc->seqno = 1;
+
level->width = tmpl->width0;
level->height = tmpl->height0;
 
-- 
2.10.2

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


[Mesa-dev] [PATCH v3 6/6] st/mesa: ask pipe driver to recreate derived internal resources when (re-)binding external textures

2016-12-06 Thread Philipp Zabel
Use the resource_changed callback to invalidate internal resources
derived from external textures when they are (re-)bound. This is needed
to comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_atom_texture.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index a1b1b88..32d0201 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -91,6 +91,10 @@ update_single_texture(struct st_context *st,
   stObj->prev_sRGBDecode = samp->sRGBDecode;
}
 
+   if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
+   stObj->pt->screen->resource_changed)
+ stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
+
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp, glsl_version);
return GL_TRUE;
-- 
2.10.2

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


[Mesa-dev] [PATCH v3 2/6] st/dri: ask the driver to update its internal copies on reimport

2016-12-06 Thread Philipp Zabel
For imported buffers that can't be used directly as a source to the
texture samplers, the pipe driver might need to create an internal
copy, for example in a different tiling layout. When buffers are
reimported they may contain new image data, so the driver internal
copies need to be recreated.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a216e83 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1168,6 +1168,10 @@ dri2_from_planar(__DRIimage *image, int plane, void 
*loaderPrivate)
if (img == NULL)
   return NULL;
 
+   if (img->texture->screen->resource_changed)
+  img->texture->screen->resource_changed(img->texture->screen,
+ img->texture);
+
/* set this to 0 for sub images. */
img->dri_components = 0;
return img;
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 3/7] etnaviv: initialize seqno of imported resources

2016-12-06 Thread Philipp Zabel
Imported resources already have contents that we want to be copied to
texture resources derived from them. Set initial seqno of imported
resources to 1, just as if it had already been rendered to.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index aefe65b..a8858c5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -325,6 +325,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->bo)
   goto fail;
 
+   rsc->seqno = 1;
+
level->width = tmpl->width0;
level->height = tmpl->height0;
 
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 1/7] gallium: add pipe_screen::resource_changed

2016-12-06 Thread Philipp Zabel
Add a hook to tell drivers that an imported resource may have changed
and they need to update their internal derived resources.

Signed-off-by: Philipp Zabel 
Reviewed-by: Roland Scheidegger 
---
 src/gallium/docs/source/screen.rst  | 14 ++
 src/gallium/include/pipe/p_screen.h |  8 
 2 files changed, 22 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 33f233a..209b97c 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -700,6 +700,20 @@ which isn't multisampled.
 
 
 
+resource_changed
+
+
+Mark a resource as changed so derived internal resources will be recreated
+on next use.
+
+When importing external images that can't be directly used as texture sampler
+source, internal copies may have to be created that the hardware can sample
+from. When those resources are reimported, the image data may have changed, and
+the previously derived internal resources must be invalidated to avoid sampling
+from old copies.
+
+
+
 resource_destroy
 
 
diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index 255647e..0d3e4b6 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -224,6 +224,14 @@ struct pipe_screen {
  struct winsys_handle *handle,
  unsigned usage);
 
+   /**
+* Mark the resource as changed so derived internal resources will be
+* recreated on next use.
+*
+* This is necessary when reimporting external images that can't be directly
+* used as texture sampler source, to avoid sampling from old copies.
+*/
+   void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
 
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 5/7] mesa: update external textures when (re-)binding

2016-12-06 Thread Philipp Zabel
To comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called,
do not bail out early from mesa_BindTextures if the target is
external.
This will later allow the state tracker to instruct the pipe driver
to invalidate internal resources derived from the external texture.

Signed-off-by: Philipp Zabel 
---
 src/mesa/main/texobj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index e5b7070..25b959d 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1619,9 +1619,10 @@ bind_texture(struct gl_context *ctx,
assert(targetIndex < NUM_TEXTURE_TARGETS);
 
/* Check if this texture is only used by this context and is already bound.
-* If so, just return.
+* If so, just return. For GL_OES_image_external, rebinding the texture
+* always must invalidate cached resources.
 */
-   {
+   if (targetIndex != TEXTURE_EXTERNAL_INDEX) {
   bool early_out;
   mtx_lock(&ctx->Shared->Mutex);
   early_out = ((ctx->Shared->RefCount == 1)
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 0/7] etnaviv: update derived texture resources of (re)imported buffers

2016-12-06 Thread Philipp Zabel
Hi,

to get weston / wayland_egl working on etnaviv, we need to update the texture
resources derived from imported buffers every time they are re-imported.

This patchset is based on the github-etnaviv/for_mainline_v1 branch and adds
a new pipe_screen::resource_changed callback that is called inside
dri2_from_planar and instructs the pipe driver to invalidate the internal
(texture) resources that are derived from the re-imported resource.

I've also added an updated version of the earlier GL_OES_EGL_image_external
patches that now use resource_changed to invalidate internal derived resources
when an external texture is (re-)bound, to comply with the specification.

The etnaviv implementation of resource_changed just sets the texture seqno
to the resource seqno - 1. The initial seqno of imported resources is set to 1
so that texture resources created from them are actually older and trigger the
resolve on first use.

Changes since v3:
 - Added resource_changed to ddebug, rbug, and trace wrapper drivers

regards
Philipp

Philipp Zabel (7):
  gallium: add pipe_screen::resource_changed
  st/dri: ask the driver to update its internal copies on reimport
  etnaviv: initialize seqno of imported resources
  etnaviv: implement resource_changed to invalidate internal resources
derived from imported buffers
  mesa: update external textures when (re-)binding
  st/mesa: ask pipe driver to recreate derived internal resources when
(re-)binding external textures
  gallium: add pipe_screen::resource_changed callback wrappers

 src/gallium/docs/source/screen.rst | 14 ++
 src/gallium/drivers/ddebug/dd_screen.c | 10 ++
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 15 +++
 src/gallium/drivers/rbug/rbug_screen.c | 11 +++
 src/gallium/drivers/trace/tr_screen.c  | 20 
 src/gallium/include/pipe/p_screen.h|  8 
 src/gallium/state_trackers/dri/dri2.c  |  4 
 src/mesa/main/texobj.c |  5 +++--
 src/mesa/state_tracker/st_atom_texture.c   |  4 
 9 files changed, 89 insertions(+), 2 deletions(-)

-- 
2.10.2

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


[Mesa-dev] [PATCH v4 6/7] st/mesa: ask pipe driver to recreate derived internal resources when (re-)binding external textures

2016-12-06 Thread Philipp Zabel
Use the resource_changed callback to invalidate internal resources
derived from external textures when they are (re-)bound. This is needed
to comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_atom_texture.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index a1b1b88..32d0201 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -91,6 +91,10 @@ update_single_texture(struct st_context *st,
   stObj->prev_sRGBDecode = samp->sRGBDecode;
}
 
+   if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
+   stObj->pt->screen->resource_changed)
+ stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
+
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp, glsl_version);
return GL_TRUE;
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 4/7] etnaviv: implement resource_changed to invalidate internal resources derived from imported buffers

2016-12-06 Thread Philipp Zabel
Implement the resource_changed pipe callback to invalidate internal
resources derived from imported buffers. This is needed to update the
texture for re-imported renderables.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index a8858c5..20ec8f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -275,6 +275,18 @@ etna_resource_create(struct pipe_screen *pscreen,
 }
 
 static void
+etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc)
+{
+   struct etna_resource *res = etna_resource(prsc);
+
+   /* Make sure texture is older than the imported renderable buffer,
+* so etna_update_sampler_source will copy the pixel data again.
+*/
+   if (res->texture)
+  etna_resource(res->texture)->seqno = res->seqno - 1;
+}
+
+static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
struct etna_resource *rsc = etna_resource(prsc);
@@ -436,5 +448,6 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_create = etna_resource_create;
pscreen->resource_from_handle = etna_resource_from_handle;
pscreen->resource_get_handle = etna_resource_get_handle;
+   pscreen->resource_changed = etna_resource_changed;
pscreen->resource_destroy = etna_resource_destroy;
 }
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 7/7] gallium: add pipe_screen::resource_changed callback wrappers

2016-12-06 Thread Philipp Zabel
Add resource_changed to the ddebug, rbug, and trace wrappers. Since it
is optional, there is no need to add it to noop.

Signed-off-by: Philipp Zabel 
Suggested-by: Nicolai Hähnle 
---
 src/gallium/drivers/ddebug/dd_screen.c | 10 ++
 src/gallium/drivers/rbug/rbug_screen.c | 11 +++
 src/gallium/drivers/trace/tr_screen.c  | 20 
 3 files changed, 41 insertions(+)

diff --git a/src/gallium/drivers/ddebug/dd_screen.c 
b/src/gallium/drivers/ddebug/dd_screen.c
index a0c0dd0..3e20abe 100644
--- a/src/gallium/drivers/ddebug/dd_screen.c
+++ b/src/gallium/drivers/ddebug/dd_screen.c
@@ -227,6 +227,15 @@ dd_screen_resource_from_user_memory(struct pipe_screen 
*_screen,
 }
 
 static void
+dd_screen_resource_changed(struct pipe_screen *_screen,
+   struct pipe_resource *res)
+{
+   struct pipe_screen *screen = dd_screen(_screen)->screen;
+
+   screen->resource_changed(screen, res);
+}
+
+static void
 dd_screen_resource_destroy(struct pipe_screen *_screen,
struct pipe_resource *res)
 {
@@ -385,6 +394,7 @@ ddebug_screen_create(struct pipe_screen *screen)
dscreen->base.resource_from_handle = dd_screen_resource_from_handle;
SCR_INIT(resource_from_user_memory);
dscreen->base.resource_get_handle = dd_screen_resource_get_handle;
+   dscreen->base.resource_changed = dd_screen_resource_changed;
dscreen->base.resource_destroy = dd_screen_resource_destroy;
SCR_INIT(flush_frontbuffer);
SCR_INIT(fence_reference);
diff --git a/src/gallium/drivers/rbug/rbug_screen.c 
b/src/gallium/drivers/rbug/rbug_screen.c
index 3742c10..4889366 100644
--- a/src/gallium/drivers/rbug/rbug_screen.c
+++ b/src/gallium/drivers/rbug/rbug_screen.c
@@ -191,7 +191,17 @@ rbug_screen_resource_get_handle(struct pipe_screen 
*_screen,
   resource, handle, usage);
 }
 
+static void
+rbug_screen_resource_changed(struct pipe_screen *_screen,
+ struct pipe_resource *_resource)
+{
+   struct rbug_screen *rb_screen = rbug_screen(_screen);
+   struct rbug_resource *rb_resource = rbug_resource(_resource);
+   struct pipe_screen *screen = rb_screen->screen;
+   struct pipe_resource *resource = rb_resource->resource;
 
+   return screen->resource_changed(screen, resource);
+}
 
 static void
 rbug_screen_resource_destroy(struct pipe_screen *screen,
@@ -279,6 +289,7 @@ rbug_screen_create(struct pipe_screen *screen)
rb_screen->base.resource_create = rbug_screen_resource_create;
rb_screen->base.resource_from_handle = rbug_screen_resource_from_handle;
rb_screen->base.resource_get_handle = rbug_screen_resource_get_handle;
+   rb_screen->base.resource_changed = rbug_screen_resource_changed;
rb_screen->base.resource_destroy = rbug_screen_resource_destroy;
rb_screen->base.flush_frontbuffer = rbug_screen_flush_frontbuffer;
rb_screen->base.fence_reference = rbug_screen_fence_reference;
diff --git a/src/gallium/drivers/trace/tr_screen.c 
b/src/gallium/drivers/trace/tr_screen.c
index 493725c..062e131 100644
--- a/src/gallium/drivers/trace/tr_screen.c
+++ b/src/gallium/drivers/trace/tr_screen.c
@@ -350,7 +350,26 @@ trace_screen_resource_get_handle(struct pipe_screen 
*_screen,
   resource, handle, usage);
 }
 
+static void
+trace_screen_resource_changed(struct pipe_screen *_screen,
+  struct pipe_resource *_resource)
+{
+   struct trace_screen *tr_scr = trace_screen(_screen);
+   struct trace_resource *tr_res = trace_resource(_resource);
+   struct pipe_screen *screen = tr_scr->screen;
+   struct pipe_resource *resource = tr_res->resource;
+
+   assert(resource->screen == screen);
 
+   trace_dump_call_begin("pipe_screen", "resource_changed");
+
+   trace_dump_arg(ptr, screen);
+   trace_dump_arg(ptr, resource);
+
+   screen->resource_changed(screen, resource);
+
+   trace_dump_call_end();
+}
 
 static void
 trace_screen_resource_destroy(struct pipe_screen *_screen,
@@ -513,6 +532,7 @@ trace_screen_create(struct pipe_screen *screen)
tr_scr->base.resource_create = trace_screen_resource_create;
tr_scr->base.resource_from_handle = trace_screen_resource_from_handle;
tr_scr->base.resource_get_handle = trace_screen_resource_get_handle;
+   tr_scr->base.resource_changed = trace_screen_resource_changed;
tr_scr->base.resource_destroy = trace_screen_resource_destroy;
tr_scr->base.fence_reference = trace_screen_fence_reference;
tr_scr->base.fence_finish = trace_screen_fence_finish;
-- 
2.10.2

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


[Mesa-dev] [PATCH v4 2/7] st/dri: ask the driver to update its internal copies on reimport

2016-12-06 Thread Philipp Zabel
For imported buffers that can't be used directly as a source to the
texture samplers, the pipe driver might need to create an internal
copy, for example in a different tiling layout. When buffers are
reimported they may contain new image data, so the driver internal
copies need to be recreated.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 9ec069b..a216e83 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1168,6 +1168,10 @@ dri2_from_planar(__DRIimage *image, int plane, void 
*loaderPrivate)
if (img == NULL)
   return NULL;
 
+   if (img->texture->screen->resource_changed)
+  img->texture->screen->resource_changed(img->texture->screen,
+ img->texture);
+
/* set this to 0 for sub images. */
img->dri_components = 0;
return img;
-- 
2.10.2

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


Re: [Mesa-dev] [PATCH] nir: Optimize double-precision lower_round_even()

2019-01-29 Thread Philipp Zabel
On Tue, 2019-01-29 at 10:10 +0100, Erik Faye-Lund wrote:
> On Mon, 2019-01-28 at 09:31 -0800, Matt Turner wrote:
> > Use the trick of adding and then subtracting 2**52 (52 is the number
> > of
> > explicit mantissa bits a double-precision floating-point value has)
> > to
> > implement round-to-even.
> > 
> > Cuts the number of instructions on SKL of the piglit test
> > fs-roundEven-double.shader_test from 109 to 21.
> 
> Won't this approach only work for "small" values, that is values equal
> to or smaller than DBL_MAX - 2**52? Once you add 2**52, you'll get
> infinity, and you can't subtract 2**52 away again without being stuck
> with infinity, no...

2**52 is such a small value compared to anything close to DBL_MAX, it
will just be absorbed.

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


[Mesa-dev] [PATCH] anv: pCreateInfo->pApplicationInfo parameter to vkCreateInstance may be NULL

2016-02-16 Thread Philipp Zabel
Fix a NULL pointer dereference in anv_CreateInstance in case
the pApplicationInfo field of the supplied VkInstanceCreateInfo
structure is NULL [1].

[1] 
https://www.khronos.org/registry/vulkan/specs/1.0/apispec.html#VkInstanceCreateInfo

Signed-off-by: Philipp Zabel 
---
 src/vulkan/anv_device.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c
index a6ce176..6863906 100644
--- a/src/vulkan/anv_device.c
+++ b/src/vulkan/anv_device.c
@@ -214,7 +214,9 @@ VkResult anv_CreateInstance(
 
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);
 
-   uint32_t client_version = pCreateInfo->pApplicationInfo->apiVersion;
+   uint32_t client_version = pCreateInfo->pApplicationInfo ?
+ pCreateInfo->pApplicationInfo->apiVersion :
+ VK_MAKE_VERSION(1, 0, 0);
if (VK_MAKE_VERSION(1, 0, 0) > client_version ||
client_version > VK_MAKE_VERSION(1, 0, 3)) {
   return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER,
@@ -249,7 +251,7 @@ VkResult anv_CreateInstance(
else
   instance->alloc = default_alloc;
 
-   instance->apiVersion = pCreateInfo->pApplicationInfo->apiVersion;
+   instance->apiVersion = client_version;
instance->physicalDeviceCount = -1;
 
_mesa_locale_init();
-- 
2.7.0

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


[Mesa-dev] [PATCH 1/2] mesa: Allow to invalidate external textures when (re-)binding

2016-05-25 Thread Philipp Zabel
To comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called,
do not bail out early from mesa_BindTextures if the target is
external.

Signed-off-by: Philipp Zabel 
---
 src/mesa/main/texobj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index c9502bd..6219617 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1623,9 +1623,10 @@ bind_texture(struct gl_context *ctx,
assert(targetIndex < NUM_TEXTURE_TARGETS);
 
/* Check if this texture is only used by this context and is already bound.
-* If so, just return.
+* If so, just return. For GL_OES_image_external, rebinding the texture
+* always must invalidate cached resources.
 */
-   {
+   if (targetIndex != TEXTURE_EXTERNAL_INDEX) {
   bool early_out;
   mtx_lock(&ctx->Shared->Mutex);
   early_out = ((ctx->Shared->RefCount == 1)
-- 
2.8.1

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


[Mesa-dev] [PATCH 2/2] st/mesa: Invalidate external textures when (re-)binding

2016-05-25 Thread Philipp Zabel
Use the invalidate_resource pipe callback to invalidate external
textures when they are (re-)bound. This is needed to comply with the
requirement from the GL_OES_EGL_image_external extension that a call
to glBindTexture guarantees that all further sampling will return
values that correspond to the values in the external texture at or
after the time that glBindTexture was called.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_atom_texture.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index 4b7ad77..96be2b2 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -410,6 +410,10 @@ update_single_texture(struct st_context *st,
   }
}
 
+   if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
+   st->pipe->invalidate_resource)
+ st->pipe->invalidate_resource(st->pipe, stObj->pt);
+
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, view_format,
  glsl_version);
-- 
2.8.1

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


[Mesa-dev] [PATCH] st/dri: fix winsys handle stride calculation for block formats

2016-05-25 Thread Philipp Zabel
This fixes the stride calculation for pipe formats with a block width
larger than one.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 0c84baf..c0b0d21 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -804,7 +804,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
if (pf == PIPE_FORMAT_NONE)
   return NULL;
 
-   whandle.stride = pitch * util_format_get_blocksize(pf);
+   whandle.stride = util_format_get_stride(pf, pitch);
 
return dri2_create_image_from_winsys(_screen, width, height, format,
 &whandle, loaderPrivate);
-- 
2.8.1

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


Re: [Mesa-dev] [PATCH 2/2] st/mesa: Invalidate external textures when (re-)binding

2016-05-25 Thread Philipp Zabel
Am Mittwoch, den 25.05.2016, 09:23 -0400 schrieb Ilia Mirkin:
> Iirc invalidate_resource is to allow backend to discard the contents...

Thanks, I didn't know that. So this would need a new callback then?
Specifically I want to discard a copy in tiled layout that was derived
from a linear external texture previously.

regards
Philipp

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


Re: [Mesa-dev] [PATCH 1/2] gbm: Enable DRI2 fence extension in the GBM DRI backend

2016-05-25 Thread Philipp Zabel
Am Dienstag, den 10.05.2016, 17:35 +0200 schrieb Philipp Zabel:
> To support the EGL_KHR_fence_sync extension on the DRM EGL platform,
> add the DRI2 fence extension to the dri_core_extensions match table.
> 
> Signed-off-by: Philipp Zabel 

Gentle ping. Is this about the right way to enable the
EGL_KHR_fence_sync extension on DRM EGL platforms?

regards
Philipp

> ---
>  src/gbm/backends/dri/gbm_dri.c| 1 +
>  src/gbm/backends/dri/gbm_driint.h | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
> index 236f2ae..4241636 100644
> --- a/src/gbm/backends/dri/gbm_dri.c
> +++ b/src/gbm/backends/dri/gbm_dri.c
> @@ -243,6 +243,7 @@ struct dri_extension_match {
>  static struct dri_extension_match dri_core_extensions[] = {
> { __DRI2_FLUSH, 1, offsetof(struct gbm_dri_device, flush) },
> { __DRI_IMAGE, 1, offsetof(struct gbm_dri_device, image) },
> +   { __DRI2_FENCE, 1, offsetof(struct gbm_dri_device, fence) },
> { NULL, 0, 0 }
>  };
>  
> diff --git a/src/gbm/backends/dri/gbm_driint.h 
> b/src/gbm/backends/dri/gbm_driint.h
> index 3f46eff..4a6e28b 100644
> --- a/src/gbm/backends/dri/gbm_driint.h
> +++ b/src/gbm/backends/dri/gbm_driint.h
> @@ -52,6 +52,7 @@ struct gbm_dri_device {
> const __DRIswrastExtension *swrast;
> const __DRI2flushExtension *flush;
> const __DRIdri2LoaderExtension *loader;
> +   const __DRI2fenceExtension *fence;
>  
> const __DRIconfig   **driver_configs;
> const __DRIextension **extensions;


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


Re: [Mesa-dev] [PATCH 1/2] gbm: Enable DRI2 fence extension in the GBM DRI backend

2016-05-25 Thread Philipp Zabel
Am Mittwoch, den 25.05.2016, 16:01 +0200 schrieb Marek Olšák:
> On Wed, May 25, 2016 at 3:44 PM, Philipp Zabel  wrote:
> > Am Dienstag, den 10.05.2016, 17:35 +0200 schrieb Philipp Zabel:
> >> To support the EGL_KHR_fence_sync extension on the DRM EGL platform,
> >> add the DRI2 fence extension to the dri_core_extensions match table.
> >>
> >> Signed-off-by: Philipp Zabel 
> >
> > Gentle ping. Is this about the right way to enable the
> > EGL_KHR_fence_sync extension on DRM EGL platforms?
> 
> Unlikely. Where are the __DRI2fenceExtension callbacks implemented?

The callbacks are implemented and added to the dri_screen_extensions[]
array in src/gallium/state_trackers/dri/dri2.c. The array is assigned to
the __DRIscreen member "extensions" in dri2_init_screen().

dri_screen_create_dri2() in src/gbm/backends/dri/gbm_dri.c
then obtains the extensions array via dri->core->getExtensions() and
binds selected extensions to the gbm_dri_device according to the
placement information in the dri_core_extensions[] array.
This was already done for the flush and image extensions, so I have
similarly added a fence extension pointer to the gbm_dri_device and an
entry to dri_core_extensions to have it initialized from the dri2
extension array that already contained the fence extension.

dri2_initialize_drm() in src/egl/drivers/dri2/platform_drm.c
then copies the extension pointers from the gbm_dri_device
dri2_dpy->gbm_dri into the dri2_egl_display dri2_dpy proper.
This also was already done for a few other extensions, among them image
and flush, and the dri2_egl_display already has a fence pointer that I
used to assign to the gbm_dri_device's new fence pointer.

dri2_setup_screen() in src/egl/drivers/dri2/egl_dri2.c later checks
dri2_dpy->fence to enable the extension.

regards
Philipp

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


Re: [Mesa-dev] [PATCH 1/2] gbm: Enable DRI2 fence extension in the GBM DRI backend

2016-05-26 Thread Philipp Zabel
Hi Marek,

Am Mittwoch, den 25.05.2016, 20:52 +0200 schrieb Marek Olšák:
> On Wed, May 25, 2016 at 4:46 PM, Philipp Zabel  wrote:
> > Am Mittwoch, den 25.05.2016, 16:01 +0200 schrieb Marek Olšák:
> >> On Wed, May 25, 2016 at 3:44 PM, Philipp Zabel  
> >> wrote:
> >> > Am Dienstag, den 10.05.2016, 17:35 +0200 schrieb Philipp Zabel:
> >> >> To support the EGL_KHR_fence_sync extension on the DRM EGL platform,
> >> >> add the DRI2 fence extension to the dri_core_extensions match table.
> >> >>
> >> >> Signed-off-by: Philipp Zabel 
> >> >
> >> > Gentle ping. Is this about the right way to enable the
> >> > EGL_KHR_fence_sync extension on DRM EGL platforms?
> >>
> >> Unlikely. Where are the __DRI2fenceExtension callbacks implemented?
> >
> > The callbacks are implemented and added to the dri_screen_extensions[]
> > array in src/gallium/state_trackers/dri/dri2.c. The array is assigned to
> > the __DRIscreen member "extensions" in dri2_init_screen().
> >
> > dri_screen_create_dri2() in src/gbm/backends/dri/gbm_dri.c
> > then obtains the extensions array via dri->core->getExtensions() and
> > binds selected extensions to the gbm_dri_device according to the
> > placement information in the dri_core_extensions[] array.
> > This was already done for the flush and image extensions, so I have
> > similarly added a fence extension pointer to the gbm_dri_device and an
> > entry to dri_core_extensions to have it initialized from the dri2
> > extension array that already contained the fence extension.
> >
> > dri2_initialize_drm() in src/egl/drivers/dri2/platform_drm.c
> > then copies the extension pointers from the gbm_dri_device
> > dri2_dpy->gbm_dri into the dri2_egl_display dri2_dpy proper.
> > This also was already done for a few other extensions, among them image
> > and flush, and the dri2_egl_display already has a fence pointer that I
> > used to assign to the gbm_dri_device's new fence pointer.
> >
> > dri2_setup_screen() in src/egl/drivers/dri2/egl_dri2.c later checks
> > dri2_dpy->fence to enable the extension.
> 
> As you can see, I'm not very familiar with libgbm. Hopefully somebody
> else will take a look.

Ok, thanks. As you can see from my rambling reply versus Emil's succinct
summary, I am not either. Just followed the breadcrumbs and found you
two at the top of get_reviewer.pl output.

regards
Philipp

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


Re: [Mesa-dev] [PATCH 1/2] gbm: Enable DRI2 fence extension in the GBM DRI backend

2016-05-26 Thread Philipp Zabel
Hi Emil,

Am Mittwoch, den 25.05.2016, 23:42 +0100 schrieb Emil Velikov:
[...]
> Or in other words, in case of egl + gbm, egl inherits the screen from
> the gbm device. As such platform_gbm does not call the core egl setup
> function, dri2_create_screen (like everyone else does x11, wayland...)
> but only the follow-up dri2_setup_screen.

Thank you for the explanation. What is the reason for this indirection?

> That said this patch will break things when using old libgbm and new
> libEGL and vice-versa. Sadly there's no way around it atm.
> Thus can we get an ABI check so that in the future we printout a
> message and abort early, instead of crashing in spectacular ways down
> the line?

I didn't think of that. How do you envision this ABI check to look like?
gbm(_drm)_device currently don't have any version fields and I'm not
sure how a new gbm backend would check for an old libEGL.
The first thing that comes to mind is a simple ABI version number to be
incremented in lock-step between libgbm and libEGL.

regards
Philipp

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


Re: [Mesa-dev] [PATCH] st/dri: fix winsys handle stride calculation for block formats

2016-05-26 Thread Philipp Zabel
Hi Michel,

Am Donnerstag, den 26.05.2016, 17:59 +0900 schrieb Michel Dänzer:
> On 25.05.2016 22:20, Philipp Zabel wrote:
> > This fixes the stride calculation for pipe formats with a block width
> > larger than one.
> > 
> > Signed-off-by: Philipp Zabel 
> > ---
> >  src/gallium/state_trackers/dri/dri2.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/src/gallium/state_trackers/dri/dri2.c 
> > b/src/gallium/state_trackers/dri/dri2.c
> > index 0c84baf..c0b0d21 100644
> > --- a/src/gallium/state_trackers/dri/dri2.c
> > +++ b/src/gallium/state_trackers/dri/dri2.c
> > @@ -804,7 +804,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
> > if (pf == PIPE_FORMAT_NONE)
> >return NULL;
> >  
> > -   whandle.stride = pitch * util_format_get_blocksize(pf);
> > +   whandle.stride = util_format_get_stride(pf, pitch);
> >  
> > return dri2_create_image_from_winsys(_screen, width, height, format,
> >  &whandle, loaderPrivate);
> > 
> 
> Reviewed-by: Michel Dänzer 
> 
> Do you need somebody to push this patch for you?

Yes, thank you.

regards
Philipp

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


Re: [Mesa-dev] [PATCH] st/dri: fix winsys handle stride calculation for block formats

2016-05-26 Thread Philipp Zabel
Am Donnerstag, den 26.05.2016, 12:43 +0100 schrieb Emil Velikov:
> Hi gents,
> 
> On 26 May 2016 at 11:28, Philipp Zabel  wrote:
> > Hi Michel,
> >
> > Am Donnerstag, den 26.05.2016, 17:59 +0900 schrieb Michel Dänzer:
> >> On 25.05.2016 22:20, Philipp Zabel wrote:
> >> > This fixes the stride calculation for pipe formats with a block width
> >> > larger than one.
> >> >
> >> > Signed-off-by: Philipp Zabel 
> >> > ---
> >> >  src/gallium/state_trackers/dri/dri2.c | 2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/src/gallium/state_trackers/dri/dri2.c 
> >> > b/src/gallium/state_trackers/dri/dri2.c
> >> > index 0c84baf..c0b0d21 100644
> >> > --- a/src/gallium/state_trackers/dri/dri2.c
> >> > +++ b/src/gallium/state_trackers/dri/dri2.c
> >> > @@ -804,7 +804,7 @@ dri2_create_image_from_name(__DRIscreen *_screen,
> >> > if (pf == PIPE_FORMAT_NONE)
> >> >return NULL;
> >> >
> >> > -   whandle.stride = pitch * util_format_get_blocksize(pf);
> >> > +   whandle.stride = util_format_get_stride(pf, pitch);
> >> >
> >> > return dri2_create_image_from_winsys(_screen, width, height, format,
> >> >  &whandle, loaderPrivate);
> >> >
> >>
> >> Reviewed-by: Michel Dänzer 
> >>
> >> Do you need somebody to push this patch for you?
> >
> > Yes, thank you.
> >
> Can we add a note if this fixes a real world case (on which driver
> and/or format) ? Is it worth adding this patch in stable releases ?

I encountered this when trying to import YUYV buffers via
EGL_EXT_image_dma_buf_import into the (still out of tree) etnaviv
gallium driver. Since I currently still have the following patch
applied, I don't think this is a stable issue, at least regarding YUYV:

--8<--
Subject: [PATCH] WIP: st/dri: Allow YUYV import

Unclear whether this is the right way, but this allows to import
dma-buffers with YUYV pixel format.

Signed-off-by: Philipp Zabel 

diff --git a/src/gallium/state_trackers/dri/dri2.c
b/src/gallium/state_trackers/dri/dri2.c
index e07389c..bad1d90 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -70,6 +70,10 @@ static int convert_fourcc(int format, int
*dri_components_p)
   format = __DRI_IMAGE_FORMAT_XBGR;
   dri_components = __DRI_IMAGE_COMPONENTS_RGB;
   break;
+   case __DRI_IMAGE_FOURCC_YUYV:
+  format = __DRI_IMAGE_FOURCC_YUYV;
+  dri_components = __DRI_IMAGE_COMPONENTS_Y_XUXV;
+  break;
default:
   return -1;
}
@@ -118,6 +122,9 @@ static enum pipe_format dri2_format_to_pipe_format
(int format)
case __DRI_IMAGE_FORMAT_ABGR:
   pf = PIPE_FORMAT_RGBA_UNORM;
   break;
+   case __DRI_IMAGE_FOURCC_YUYV:
+  pf = PIPE_FORMAT_YUYV;
+  break;
default:
   pf = PIPE_FORMAT_NONE;
   break;
-->8--

While I have your attention, should the above be handled by adding a
__DRI_IMAGE_FORMAT_YUYV instead?

regards
Philipp

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


Re: [Mesa-dev] [PATCH 2/2] st/mesa: Invalidate external textures when (re-)binding

2016-05-26 Thread Philipp Zabel
Am Donnerstag, den 26.05.2016, 10:36 -0400 schrieb Ilia Mirkin:
> On Thu, May 26, 2016 at 10:31 AM, Marek Olšák  wrote:
> > On Wed, May 25, 2016 at 3:34 PM, Philipp Zabel  
> > wrote:
> >> Am Mittwoch, den 25.05.2016, 09:23 -0400 schrieb Ilia Mirkin:
> >>> Iirc invalidate_resource is to allow backend to discard the contents...
> >>
> >> Thanks, I didn't know that. So this would need a new callback then?
> >> Specifically I want to discard a copy in tiled layout that was derived
> >> from a linear external texture previously.
> >
> > FWIW, radeon drivers don't change the tile mode after a texture has
> > been exported. When the texture is exported, the tile mode is set in
> > stone, be it linear or tiled. There is no second copy.
> 
> I think what he's saying is that they have a shadow copy of the
> texture, and need to know when to update the shadow.

Yes, exactly. I'd like to import a linear dma-buf using
EGL_EXT_image_dma_buf_import and GL_OES_EGL_image_external with the
etnaviv gallium driver.

The linear source buffer needs to be transferred into a shadow copy in
tiled layout. The texture samplers can only read from the tiled copy.

After the linear source buffer has been modified, binding the texture
again must trigger a refresh of the tiled copy somehow.

regards
Philipp

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


[Mesa-dev] [PATCH] vulkan/wsi/wayland: Fix proxy wrappers for swapchain recreation

2017-05-19 Thread Philipp Zabel
Before the swapchain event queue is destroyed, all proxy objects that reference
it must be dropped. Otherwise we risk a use-after-free if a frame callback event
or buffer release events are received afterwards.
This happens when an application destroys and recreates a swapchain in FIFO
mode between two frames without using the VkSwapchainCreateInfoKHR::oldSwapchain
mechanism to keep the old swapchain until after the next redraw.

Fixes: 5034c615582a ("vulkan/wsi/wayland: Use proxy wrappers for swapchain")
Signed-off-by: Philipp Zabel 
Cc: mesa-sta...@lists.freedesktop.org
---
 src/vulkan/wsi/wsi_common_wayland.c | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/vulkan/wsi/wsi_common_wayland.c 
b/src/vulkan/wsi/wsi_common_wayland.c
index 8950798882..644ed62b41 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -537,6 +537,7 @@ struct wsi_wl_swapchain {
struct wl_surface *  surface;
uint32_t surface_version;
struct wl_drm *  drm_wrapper;
+   struct wl_callback * frame;
 
VkExtent2D   extent;
VkFormat vk_format;
@@ -616,6 +617,7 @@ frame_handle_done(void *data, struct wl_callback *callback, 
uint32_t serial)
 {
struct wsi_wl_swapchain *chain = data;
 
+   chain->frame = NULL;
chain->fifo_ready = true;
 
wl_callback_destroy(callback);
@@ -658,8 +660,8 @@ wsi_wl_swapchain_queue_present(struct wsi_swapchain 
*wsi_chain,
}
 
if (chain->base.present_mode == VK_PRESENT_MODE_FIFO_KHR) {
-  struct wl_callback *frame = wl_surface_frame(chain->surface);
-  wl_callback_add_listener(frame, &frame_listener, chain);
+  chain->frame = wl_surface_frame(chain->surface);
+  wl_callback_add_listener(chain->frame, &frame_listener, chain);
   chain->fifo_ready = false;
}
 
@@ -741,12 +743,16 @@ wsi_wl_swapchain_destroy(struct wsi_swapchain *wsi_chain,
struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain;
 
for (uint32_t i = 0; i < chain->base.image_count; i++) {
-  if (chain->images[i].buffer)
+  if (chain->images[i].buffer) {
+ wl_buffer_destroy(chain->images[i].buffer);
  chain->base.image_fns->free_wsi_image(chain->base.device, pAllocator,
chain->images[i].image,
chain->images[i].memory);
+  }
}
 
+   if (chain->frame)
+  wl_callback_destroy(chain->frame);
if (chain->surface)
   wl_proxy_wrapper_destroy(chain->surface);
if (chain->drm_wrapper)
@@ -791,6 +797,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase 
*icd_surface,
chain->queue = NULL;
chain->surface = NULL;
chain->drm_wrapper = NULL;
+   chain->frame = NULL;
 
bool alpha = pCreateInfo->compositeAlpha ==
   VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
-- 
2.11.0

___
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 Philipp Zabel
On Tue, 2017-05-23 at 14:40 +0530, Varad Gautam wrote:
> Hi Lucas,
> 
> On Mon, May 22, 2017 at 11:16 PM, Lucas Stach  wrote:
> > Am Mittwoch, den 10.05.2017, 23:15 +0530 schrieb Varad Gautam:
> >> From: Varad Gautam 
> >>
> >> 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 
> >> ---
> >>  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_IM

[Mesa-dev] [RFC] etnaviv: flush color cache and depth cache together before resolves

2017-05-30 Thread Philipp Zabel
Before resolving a rendertarget or a depth/stencil resource into a
texture, flush both the color cache and the depth cache together.

It is unclear whether this is necessary for the following stall to
work properly, or whether the depth flush just adds enough time
for the color cache flush to finish before the resolver is started,
but this change removes artifacts that otherwise appear if a texture
is sampled directly after rendering into it.

The test case is a simple QML scene graph with a QtWebEngine based
WebView rendered on top of a blue background:

import QtQuick 2.0
import QtQuick.Window 2.2
import QtWebView 1.1

Window {
Rectangle {
id: background
anchors.fill: parent
color: "blue"
}

WebView {
id: webView
anchors.fill: parent
}

Component.onCompleted: {
webView.url = ""
}
}

If the website is animated, the WebView renders the site contents into
texture tiles and immediately afterwards samples from them to draw the
tiles into the Qt renderbuffer. Without this patch, a small irregular
triangle in the lower right of each browser tile appears solid blue, as
if the texture sampler samples zeroes instead of the website contents,
and the previously rendered blue Rectangle shows through.

Other attempts such as adding a pipeline stall before the color flush or
a TS cache flush afterwards or flushing multiple times, with stalls
before and after each flush, have shown no effect.

Signed-off-by: Philipp Zabel 
---
 src/gallium/drivers/etnaviv/etnaviv_clear_blit.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c 
b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
index ae1c586288..faa6bd0436 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
@@ -455,15 +455,10 @@ etna_try_rs_blit(struct pipe_context *pctx,
   ts_mem_config |= VIVS_TS_MEM_CONFIG_MSAA | msaa_format;
}
 
-   uint32_t to_flush = 0;
-
-   if (src->base.bind & PIPE_BIND_RENDER_TARGET)
-  to_flush |= VIVS_GL_FLUSH_CACHE_COLOR;
-   if (src->base.bind & PIPE_BIND_DEPTH_STENCIL)
-  to_flush |= VIVS_GL_FLUSH_CACHE_DEPTH;
-
-   if (to_flush) {
-  etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, to_flush);
+   if (src->base.bind & PIPE_BIND_RENDER_TARGET ||
+   src->base.bind & PIPE_BIND_DEPTH_STENCIL) {
+  etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE,
+VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH);
   etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE);
}
 
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH 1/6] etnaviv: always do cpu_fini in transfer_unmap

2017-05-30 Thread Philipp Zabel
On Fri, 2017-05-19 at 11:41 +0200, Lucas Stach wrote:
> The cpu_fini() call pushes the buffer back into the GPU domain, which needs
> to be done for all buffers, not just the ones with CPU written content. The
> etnaviv kernel driver currently doesn't validate this, but may start to do
> so at a later point in time. If there is a temporary resource the fini needs
> to happen before the RS uses this one as the source for the upload.
> 
> Also remove an invalid comment about flushing CPU caches, cpu_fini takes
> care of everything involved in this.
> 
> Fixes: c9e8b49b885 ("etnaviv: gallium driver for Vivante GPUs")
> Cc: mesa-sta...@lists.freedesktop.org
> Signed-off-by: Lucas Stach 

Reviewed-by: Philipp Zabel 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_transfer.c | 9 ++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
> b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> index 1a5aa7fc043c..4809b04ff95f 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> @@ -70,6 +70,9 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
> pipe_transfer *ptrans)
> if (rsc->texture && !etna_resource_newer(rsc, 
> etna_resource(rsc->texture)))
>rsc = etna_resource(rsc->texture); /* switch to using the texture 
> resource */
>  
> +   if (trans->rsc)
> +  etna_bo_cpu_fini(etna_resource(trans->rsc)->bo);
> +
> if (ptrans->usage & PIPE_TRANSFER_WRITE) {
>if (trans->rsc) {
>   /* We have a temporary resource due to either tile status or
> @@ -105,15 +108,15 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
> pipe_transfer *ptrans)
>}
>  
>rsc->seqno++;
> -  etna_bo_cpu_fini(rsc->bo);
>  
>if (rsc->base.bind & PIPE_BIND_SAMPLER_VIEW) {
> - /* XXX do we need to flush the CPU cache too or start a write 
> barrier
> -  * to make sure the GPU sees it? */
>   ctx->dirty |= ETNA_DIRTY_TEXTURE_CACHES;
>}
> }
>  
> +   if (!trans->rsc)
> +  etna_bo_cpu_fini(rsc->bo);
> +
> pipe_resource_reference(&trans->rsc, NULL);
> pipe_resource_reference(&ptrans->resource, NULL);
> slab_free(&ctx->transfer_pool, trans);


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


Re: [Mesa-dev] [PATCH 3/6] etnaviv: honor PIPE_TRANSFER_UNSYNCHRONIZED flag

2017-05-30 Thread Philipp Zabel
On Fri, 2017-05-19 at 11:41 +0200, Lucas Stach wrote:
> This gets rid of quite a bit of CPU/GPU sync on frequent vertex buffer
> uploads and I haven't seen any of the issues mentioned in the comment,
> so this one seems stale.
> 
> Ignore the flag if there exists a temporary resource, as those ones are
> never busy.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_transfer.c | 22 ++
>  1 file changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_transfer.c 
> b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> index 269bd498f89f..a2cd4e6234dd 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_transfer.c
> @@ -114,7 +114,7 @@ etna_transfer_unmap(struct pipe_context *pctx, struct 
> pipe_transfer *ptrans)
>}
> }
>  
> -   if (!trans->rsc)
> +   if (!trans->rsc && !(ptrans->usage & PIPE_TRANSFER_UNSYNCHRONIZED))

As we just talked about, this looks like it should be '||' ...

>etna_bo_cpu_fini(rsc->bo);
>  
> pipe_resource_reference(&trans->rsc, NULL);
> @@ -260,19 +260,17 @@ etna_transfer_map(struct pipe_context *pctx, struct 
> pipe_resource *prsc,
> (rsc->layout == ETNA_LAYOUT_TILED &&
>  util_format_is_compressed(prsc->format));
>  
> -   /* Ignore PIPE_TRANSFER_UNSYNCHRONIZED and PIPE_TRANSFER_DONTBLOCK here.
> -* It appears that Gallium operates the index/vertex buffers in a
> -* circular fashion, and the CPU can catch up with the GPU and starts
> -* overwriting yet-to-be-processed entries, causing rendering corruption. 
> */
> -   uint32_t prep_flags = 0;
> +   if (trans->rsc || !(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {

... for symmetry with etna_bo_cpu_prep call below.

> +  uint32_t prep_flags = 0;
>  
> -   if (usage & PIPE_TRANSFER_READ)
> -  prep_flags |= DRM_ETNA_PREP_READ;
> -   if (usage & PIPE_TRANSFER_WRITE)
> -  prep_flags |= DRM_ETNA_PREP_WRITE;
> +  if (usage & PIPE_TRANSFER_READ)
> + prep_flags |= DRM_ETNA_PREP_READ;
> +  if (usage & PIPE_TRANSFER_WRITE)
> + prep_flags |= DRM_ETNA_PREP_WRITE;
>  
> -   if (etna_bo_cpu_prep(rsc->bo, prep_flags))
> -  goto fail_prep;
> +  if (etna_bo_cpu_prep(rsc->bo, prep_flags))
> + goto fail_prep;
> +   }
>  
> /* map buffer object */
> void *mapped = etna_bo_map(rsc->bo);

regards
Philipp

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


Re: [Mesa-dev] [libdrm 1/4] etnaviv: submit full struct drm_etnaviv_gem_submit

2017-06-09 Thread Philipp Zabel
Hi Christian,

On Fri, 2017-06-09 at 12:27 +0200, Christian Gmeiner wrote:
> It is safe to submit the full struct even on older kernels as such
> kernels do not process the full struct. Without this change it
> becomes quite challenging to extned the submit struct.
> 
> Freedreno has no special treatment too. See git commits
> - freedreno: sync uapi header
> - freedreno: add fence fd support

Reading drm_ioctl() closely, I can see that it is safe to submit a
struct larger than what the kernel expects. I have applied this patch
and reverted kernel commits 78ec187f64fa ("drm/etnaviv: submit support
for out-fences") and 9ad59fea162c ("drm/etnaviv: submit support for
in-fences") to test, without ill effects.

> Signed-off-by: Christian Gmeiner 

Reviewed-by: Philipp Zabel 
Tested-by: Philipp Zabel 

regards
Philipp

> ---
>  etnaviv/etnaviv_cmd_stream.c | 8 +---
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/etnaviv/etnaviv_cmd_stream.c b/etnaviv/etnaviv_cmd_stream.c
> index 3c7b0ed..8d0e813 100644
> --- a/etnaviv/etnaviv_cmd_stream.c
> +++ b/etnaviv/etnaviv_cmd_stream.c
> @@ -203,14 +203,8 @@ static void flush(struct etna_cmd_stream *stream, int 
> in_fence_fd,
>   if (out_fence_fd)
>   req.flags |= ETNA_SUBMIT_FENCE_FD_OUT;
>  
> - /*
> -  * Pass the complete submit structure only if flags are set. Otherwise,
> -  * only pass the fields up to, but not including the flags field for
> -  * backwards compatiblity with older kernels.
> -  */
>   ret = drmCommandWriteRead(gpu->dev->fd, DRM_ETNAVIV_GEM_SUBMIT,
> - &req, req.flags ? sizeof(req) :
> - offsetof(struct drm_etnaviv_gem_submit, flags));
> + &req, sizeof(req));
>  
>   if (ret)
>   ERROR_MSG("submit failed: %d (%s)", ret, strerror(errno));


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


Re: [Mesa-dev] [PATCH 1/2] etnaviv: fix varying interpolation

2017-06-09 Thread Philipp Zabel
On Thu, 2017-06-08 at 18:25 +0200, Lucas Stach wrote:
> It seems that newer cores don't use the PA_ATTRIBUTES to decide if the
> varying should bypass the flat shading, but derive this from the component
> use. This fixes flat shading on GC880+.
> 
> VARYING_COMPONENT_USE_POINTCOORD is a bit of a misnomer now, as it isn't
> only used for pointcoords, but missing a better name I left it as-is.
> 
> Signed-off-by: Lucas Stach 
>
> ---
>  src/gallium/drivers/etnaviv/etnaviv_compiler.c | 24 ++--
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c 
> b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> index eafb511bb813..2605924613c7 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> @@ -2552,6 +2552,7 @@ etna_link_shader(struct etna_shader_link_info *info,
>const struct etna_shader_inout *fsio = &fs->infile.reg[idx];
>const struct etna_shader_inout *vsio = etna_shader_vs_lookup(vs, fsio);
>struct etna_varying *varying;
> +  bool interpolate = fsio->semantic.Name != TGSI_SEMANTIC_COLOR;
>  
>assert(fsio->reg > 0 && fsio->reg <= ARRAY_SIZE(info->varyings));
>  
> @@ -2561,28 +2562,23 @@ etna_link_shader(struct etna_shader_link_info *info,
>varying = &info->varyings[fsio->reg - 1];
>varying->num_components = fsio->num_components;
>  
> -  if (fsio->semantic.Name == TGSI_SEMANTIC_COLOR) /* colors affected by 
> flat shading */
> +  if (!interpolate) /* colors affected by flat shading */
>   varying->pa_attributes = 0x200;
>else /* texture coord or other bypasses flat shading */
>   varying->pa_attributes = 0x2f1;
>  
> -  if (fsio->semantic.Name == TGSI_SEMANTIC_PCOORD) {
> - varying->use[0] = VARYING_COMPONENT_USE_POINTCOORD_X;
> - varying->use[1] = VARYING_COMPONENT_USE_POINTCOORD_Y;
> - varying->use[2] = VARYING_COMPONENT_USE_USED;
> - varying->use[3] = VARYING_COMPONENT_USE_USED;
> - varying->reg = 0; /* replaced by point coord -- doesn't matter */
> +  varying->use[0] = interpolate ? VARYING_COMPONENT_USE_POINTCOORD_X : 
> VARYING_COMPONENT_USE_USED;
> +  varying->use[1] = interpolate ? VARYING_COMPONENT_USE_POINTCOORD_Y : 
> VARYING_COMPONENT_USE_USED;
> +  varying->use[2] = VARYING_COMPONENT_USE_USED;
> +  varying->use[3] = VARYING_COMPONENT_USE_USED;

This only changins varying->use[0,1] to POINTCOORD in the
non-SEMANTIC_COLOR, non-SEMANTIC_PCOORD case, which is what the patch is
about.

> +  varying->reg = vsio->reg; /* replaced by point coord -- doesn't matter 
> */

This changes varying->vreg in the SEMANTIC_PCOORD case. As the comment
says, it shouldn't matter. But this also dereferences the vsio pointer,
which according to the check below could be NULL.

> +
> +
> +  if (fsio->semantic.Name == TGSI_SEMANTIC_PCOORD)
>   continue;
> -  }
> 
>if (vsio == NULL)
>   return true; /* not found -- link error */

regards
Philipp

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


Re: [Mesa-dev] [PATCH 2/2] etnaviv: remove flat shading workaround

2017-06-09 Thread Philipp Zabel
On Thu, 2017-06-08 at 18:25 +0200, Lucas Stach wrote:
> It turned out not to be a hardware bug, but the shader compiler
> emitting wrong varying component use information. With that fixed
> we can turn flat shading back on.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_rasterizer.c | 6 +-
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_rasterizer.c 
> b/src/gallium/drivers/etnaviv/etnaviv_rasterizer.c
> index 4990fd180257..56f2735e8a18 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_rasterizer.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_rasterizer.c
> @@ -38,10 +38,6 @@ etna_rasterizer_state_create(struct pipe_context *pctx,
> struct etna_rasterizer_state *cs;
> struct etna_context *ctx = etna_context(pctx);
>  
> -/* Disregard flatshading on GC880+, as a HW bug there seem to disable all
> - * varying interpolation if it's enabled */
> -   bool flatshade = ctx->screen->model < 880 ? so->flatshade : false;
> -
> if (so->fill_front != so->fill_back)
>DBG("Different front and back fill mode not supported");
>  
> @@ -51,7 +47,7 @@ etna_rasterizer_state_create(struct pipe_context *pctx,
>  
> cs->base = *so;
>  
> -   cs->PA_CONFIG = (flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : 
> VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) |
> +   cs->PA_CONFIG = (so->flatshade ? VIVS_PA_CONFIG_SHADE_MODEL_FLAT : 
> VIVS_PA_CONFIG_SHADE_MODEL_SMOOTH) |
> translate_cull_face(so->cull_face, so->front_ccw) |
>     translate_polygon_mode(so->fill_front) |
> COND(so->point_quad_rasterization, 
> VIVS_PA_CONFIG_POINT_SPRITE_ENABLE) |

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 05/19] etnaviv: Use only DRAW_INSTANCED on GC3000+

2017-11-01 Thread Philipp Zabel
On Mon, 2017-10-30 at 17:16 +0100, Wladimir J. van der Laan wrote:
> The blob does this, as DRAW_INSTANCED can replace fully all the other
> draw commands - the other path is only there for compatibility and
> will go away (or at least rot to become buggy due to dis-use) in newer
> hardware.
> 
> Preparation for GC7000 support.

This also changes behaviour for <= GC2000 in the indexed case, should
this be mentioned in the commit message?

> Signed-off-by: Wladimir J. van der Laan 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_context.c | 16 
>  src/gallium/drivers/etnaviv/etnaviv_emit.h| 21 +
>  2 files changed, 33 insertions(+), 4 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
> b/src/gallium/drivers/etnaviv/etnaviv_context.c
> index 65c20d2..5aa9c66 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_context.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
> @@ -188,6 +188,8 @@ etna_draw_vbo(struct pipe_context *pctx, const struct 
> pipe_draw_info *info)
>   BUG("Index buffer upload failed.");
>   return;
>}
> +  /* Add start to index offset, when rendering indexed */
> +  index_offset += info->start * info->index_size;
>  
>ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = 
> etna_resource(indexbuf)->bo;
>ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = index_offset;

So adding the start offset here makes up for always emitting a zero
start offset with DRAW_INDEXED_PRIMITIVES below.

> @@ -273,10 +275,16 @@ etna_draw_vbo(struct pipe_context *pctx, const struct 
> pipe_draw_info *info)
> /* First, sync state, then emit DRAW_PRIMITIVES or 
> DRAW_INDEXED_PRIMITIVES */
> etna_emit_state(ctx);
>  
> -   if (info->index_size)
> -  etna_draw_indexed_primitives(ctx->stream, draw_mode, info->start, 
> prims, info->index_bias);
> -   else
> -  etna_draw_primitives(ctx->stream, draw_mode, info->start, prims);
> +   if (ctx->specs.halti >= 2) {
> +  /* On HALTI2+ (GC3000 and higher) only use instanced drawing commands, 
> as the blob does */
> +  etna_draw_instanced(ctx->stream, info->index_size, draw_mode, 1,
> + info->count, info->index_size ? info->index_bias : info->start);
> +   } else {
> +  if (info->index_size)
> + etna_draw_indexed_primitives(ctx->stream, draw_mode, 0, prims, 
> info->index_bias);

Since this is the only place where etna_draw_indexed_primitives is
called, should the unused start parameter be removed from this
function?

> +  else
> + etna_draw_primitives(ctx->stream, draw_mode, info->start, prims);
> +   }
>  
> if (DBG_ENABLED(ETNA_DBG_DRAW_STALL)) {
>/* Stall the FE after every draw operation.  This allows better
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.h 
> b/src/gallium/drivers/etnaviv/etnaviv_emit.h
> index e0c0eda..3c3d129 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_emit.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_emit.h
> @@ -117,6 +117,27 @@ etna_draw_indexed_primitives(struct etna_cmd_stream 
> *stream,
> etna_cmd_stream_emit(stream, 0);
>  }
>  
> +/* important: this takes a vertex count, not a primitive count */
> +static inline void
> +etna_draw_instanced(struct etna_cmd_stream *stream,
> +uint32_t indexed, uint32_t primitive_type,
> +uint32_t instance_count,
> +uint32_t vertex_count, uint32_t offset)
> +{
> +   etna_cmd_stream_reserve(stream, 3 + 1);
> +   etna_cmd_stream_emit(stream,
> +  VIV_FE_DRAW_INSTANCED_HEADER_OP_DRAW_INSTANCED |
> +  COND(indexed, VIV_FE_DRAW_INSTANCED_HEADER_INDEXED) |
> +  VIV_FE_DRAW_INSTANCED_HEADER_TYPE(primitive_type) |
> +  VIV_FE_DRAW_INSTANCED_HEADER_INSTANCE_COUNT_LO(instance_count & 
> 0x));
> +   etna_cmd_stream_emit(stream,
> +  VIV_FE_DRAW_INSTANCED_COUNT_INSTANCE_COUNT_HI(instance_count >> 16) |
> +  VIV_FE_DRAW_INSTANCED_COUNT_VERTEX_COUNT(vertex_count));
> +   etna_cmd_stream_emit(stream,
> +  VIV_FE_DRAW_INSTANCED_START_INDEX(offset));
> +   etna_cmd_stream_emit(stream, 0);
> +}
> +
>  void
>  etna_emit_state(struct etna_context *ctx);

Reviewed-by: Philipp Zabel 

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


Re: [Mesa-dev] [PATCH 02/19] etnaviv: Const-correctness etnaviv_emit.h

2017-11-01 Thread Philipp Zabel
On Mon, 2017-10-30 at 17:16 +0100, Wladimir J. van der Laan wrote:
> The relocation structure is never changed by submitting it.
> 
> Signed-off-by: Wladimir J. van der Laan 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_emit.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_emit.h 
> b/src/gallium/drivers/etnaviv/etnaviv_emit.h
> index 6a3c772..e0c0eda 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_emit.h
> +++ b/src/gallium/drivers/etnaviv/etnaviv_emit.h
> @@ -59,7 +59,7 @@ etna_set_state(struct etna_cmd_stream *stream, uint32_t 
> address, uint32_t value)
>  
>  static inline void
>  etna_set_state_reloc(struct etna_cmd_stream *stream, uint32_t address,
> - struct etna_reloc *reloc)
> + const struct etna_reloc *reloc)
>  {
> etna_cmd_stream_reserve(stream, 2);
>     etna_emit_load_state(stream, address >> 2, 1, 0);

Reviewed-by: Philipp Zabel 

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


Re: [Mesa-dev] [PATCH] st/dri: allow direct YUYV import

2017-07-19 Thread Philipp Zabel
On Fri, 2017-06-23 at 18:48 +0200, Lucas Stach wrote:
> Push this format to the pipe driver unchanged.
> 
> Signed-off-by: Lucas Stach 
> ---
>  include/GL/internal/dri_interface.h   | 1 +
>  src/gallium/state_trackers/dri/dri2.c | 7 +++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/include/GL/internal/dri_interface.h 
> b/include/GL/internal/dri_interface.h
> index fc2d4bbe22ef..69188a2a0da3 100644
> --- a/include/GL/internal/dri_interface.h
> +++ b/include/GL/internal/dri_interface.h
> @@ -1167,6 +1167,7 @@ struct __DRIdri2ExtensionRec {
>  #define __DRI_IMAGE_FORMAT_ARGB1555 0x100c
>  #define __DRI_IMAGE_FORMAT_R16  0x100d
>  #define __DRI_IMAGE_FORMAT_GR1616   0x100e
> +#define __DRI_IMAGE_FORMAT_YUYV 0x100f
>  
>  #define __DRI_IMAGE_USE_SHARE0x0001
>  #define __DRI_IMAGE_USE_SCANOUT  0x0002
> diff --git a/src/gallium/state_trackers/dri/dri2.c 
> b/src/gallium/state_trackers/dri/dri2.c
> index c5e69d639b16..3119a396ce29 100644
> --- a/src/gallium/state_trackers/dri/dri2.c
> +++ b/src/gallium/state_trackers/dri/dri2.c
> @@ -115,6 +115,10 @@ static int convert_fourcc(int format, int 
> *dri_components_p)
>format = __DRI_IMAGE_FORMAT_GR88;
>dri_components = __DRI_IMAGE_COMPONENTS_RG;
>break;
> +   case __DRI_IMAGE_FOURCC_YUYV:
> +  format = __DRI_IMAGE_FORMAT_YUYV;
> +  dri_components = __DRI_IMAGE_COMPONENTS_Y_XUXV;
> +  break;
> /*
>  * For multi-planar YUV formats, we return the format of the first
>  * plane only.  Since there is only one caller which supports multi-
> @@ -195,6 +199,9 @@ static enum pipe_format dri2_format_to_pipe_format (int 
> format)
> case __DRI_IMAGE_FORMAT_GR88:
>pf = PIPE_FORMAT_RG88_UNORM;
>break;
> +   case __DRI_IMAGE_FORMAT_YUYV:
> +  pf = PIPE_FORMAT_YUYV;
> +  break;
> default:
>pf = PIPE_FORMAT_NONE;
>break;

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH] etnaviv: Add support for R8_UNORM textures

2017-07-28 Thread Philipp Zabel
On Fri, 2017-07-28 at 16:05 +0200, Wladimir J. van der Laan wrote:
> R8_UNORM textures can be emulated by means of L8 and a swizzle.
> 
> Signed-off-by: Wladimir J. van der Laan 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_format.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c 
> b/src/gallium/drivers/etnaviv/etnaviv_format.c
> index 69e07bc..a2e215b 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_format.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
> @@ -90,7 +90,7 @@ struct etna_format {
>  
>  static struct etna_format formats[PIPE_FORMAT_COUNT] = {
> /* 8-bit */
> -   V_(R8_UNORM,   UNSIGNED_BYTE, NONE),
> +   VT(R8_UNORM,   UNSIGNED_BYTE, L8, SWIZ(X, 0, 0, 1), NONE),
> V_(R8_SNORM,   BYTE,  NONE),
> V_(R8_UINT,UNSIGNED_BYTE, NONE),
> V_(R8_SINT,BYTE,  NONE),

Reviewed-by: Philipp Zabel 

regards
Philipp

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


[Mesa-dev] [PATCH 1/2] etnaviv: fix etna_bo_from_name

2017-08-04 Thread Philipp Zabel
Look up BOs from the name table using the name parameter instead of
req.handle (which at this point is always zero).

Signed-off-by: Philipp Zabel 
---
 etnaviv/etnaviv_bo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/etnaviv/etnaviv_bo.c b/etnaviv/etnaviv_bo.c
index 4ad0434..4fe877f 100644
--- a/etnaviv/etnaviv_bo.c
+++ b/etnaviv/etnaviv_bo.c
@@ -173,7 +173,7 @@ struct etna_bo *etna_bo_from_name(struct etna_device *dev, 
uint32_t name)
pthread_mutex_lock(&table_lock);
 
/* check name table first, to see if bo is already open: */
-   bo = lookup_bo(dev->name_table, req.handle);
+   bo = lookup_bo(dev->name_table, name);
if (bo)
goto out_unlock;
 
-- 
2.1.4

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


[Mesa-dev] [PATCH 2/2] etnaviv: add etna_bo_from_handle

2017-08-04 Thread Philipp Zabel
Although etnaviv_drmif.h declared etna_bo_from_handle from the start,
there was no implementation.

Signed-off-by: Philipp Zabel 
---
 etnaviv/etnaviv_bo.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/etnaviv/etnaviv_bo.c b/etnaviv/etnaviv_bo.c
index 4fe877f..7566957 100644
--- a/etnaviv/etnaviv_bo.c
+++ b/etnaviv/etnaviv_bo.c
@@ -135,6 +135,25 @@ struct etna_bo *etna_bo_new(struct etna_device *dev, 
uint32_t size,
return bo;
 }
 
+struct etna_bo *
+etna_bo_from_handle(struct etna_device *dev, uint32_t handle, uint32_t size)
+{
+   struct etna_bo *bo = NULL;
+
+   pthread_mutex_lock(&table_lock);
+
+   bo = lookup_bo(dev->handle_table, handle);
+   if (bo)
+   goto out_unlock;
+
+   bo = bo_from_handle(dev, size, handle, 0);
+
+out_unlock:
+   pthread_mutex_unlock(&table_lock);
+
+   return bo;
+}
+
 struct etna_bo *etna_bo_ref(struct etna_bo *bo)
 {
atomic_inc(&bo->refcnt);
-- 
2.1.4

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


Re: [Mesa-dev] [PATCH 1/2] etnaviv: fix etna_bo_from_name

2017-08-04 Thread Philipp Zabel
On Fri, 2017-08-04 at 18:15 +0200, Wladimir J. van der Laan wrote:
> On Fri, Aug 04, 2017 at 05:07:54PM +0200, Philipp Zabel wrote:
> > Look up BOs from the name table using the name parameter instead of
> > req.handle (which at this point is always zero).
> 
> Good catch.
> 
> Just out of interest: when is this used, what problems does this cause?

It is used by the etnaviv gallium driver in etna_screen_bo_from_handle
for DRM_API_HANDLE_TYPE_SHARED handles. Since this just falls back to
asking the kernel to DRM_IOCTL_GEM_OPEN if the BO is not found in the
name_table already, this bug caused no problems.

regards
Philipp

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


Re: [Mesa-dev] [PATCH] egl/dri2: Allow modifiers to add FDs to imports

2017-08-07 Thread Philipp Zabel
On Mon, 2017-07-31 at 18:35 +0100, Daniel Stone wrote:
> When using dmabuf import, make sure that the modifier is actually
> allowed to add planes to the base format, as implied by the comment.
> 
> Signed-off-by: Daniel Stone 
> ---
>  src/egl/drivers/dri2/egl_dri2.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index b73dcd72b6..76294897a5 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -2166,8 +2166,10 @@ dri2_check_dma_buf_format(const _EGLImageAttribs 
> *attrs)
>*  this extension."
>*/
>   if (attrs->DMABufPlaneModifiersLo[i].IsPresent &&
> - attrs->DMABufPlaneModifiersHi[i].IsPresent)
> + attrs->DMABufPlaneModifiersHi[i].IsPresent) {
> +plane_n = i + 1;

Since this increments plane_n, Should a check be added that the
corresponding DMABufPlanFds[i] is present?
What if there are holes in DMABufPlaneModifiersLo/Hi?

>  continue;
> + }
>  
>   _eglError(EGL_BAD_ATTRIBUTE, "too many plane attributes");
>   return 0;

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH] egl/dri2: Allow modifiers to add FDs to imports

2017-08-08 Thread Philipp Zabel
On Tue, 2017-08-08 at 07:29 +0300, Tapani Pälli wrote:
> 
> On 08/07/2017 03:05 PM, Philipp Zabel wrote:
> > On Mon, 2017-07-31 at 18:35 +0100, Daniel Stone wrote:
> >> When using dmabuf import, make sure that the modifier is actually
> >> allowed to add planes to the base format, as implied by the comment.
> >>
> >> Signed-off-by: Daniel Stone 
> >> ---
> >>   src/egl/drivers/dri2/egl_dri2.c | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/src/egl/drivers/dri2/egl_dri2.c 
> >> b/src/egl/drivers/dri2/egl_dri2.c
> >> index b73dcd72b6..76294897a5 100644
> >> --- a/src/egl/drivers/dri2/egl_dri2.c
> >> +++ b/src/egl/drivers/dri2/egl_dri2.c
> >> @@ -2166,8 +2166,10 @@ dri2_check_dma_buf_format(const _EGLImageAttribs 
> >> *attrs)
> >> *  this extension."
> >> */
> >>if (attrs->DMABufPlaneModifiersLo[i].IsPresent &&
> >> - attrs->DMABufPlaneModifiersHi[i].IsPresent)
> >> + attrs->DMABufPlaneModifiersHi[i].IsPresent) {
> >> +plane_n = i + 1;
> > 
> > Since this increments plane_n, Should a check be added that the
> > corresponding DMABufPlanFds[i] is present?
> 
> Check for the fd is right above this check.

I see this right above:

  if (attrs->DMABufPlaneFds[i].IsPresent || 
  attrs->DMABufPlaneOffsets[i].IsPresent ||
  attrs->DMABufPlanePitches[i].IsPresent ||
  attrs->DMABufPlaneModifiersLo[i].IsPresent ||
  attrs->DMABufPlaneModifiersHi[i].IsPresent) {

If modifiers are present, this is always true, regardless of whether the
fd is present.

The loop that checks for fd presence even before that only loops up to
the number of planes determined by the non-modified fourcc.

regards
Philipp

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


Re: [Mesa-dev] [PATCH v2] egl/dri2: Allow modifiers to add FDs to imports

2017-08-11 Thread Philipp Zabel
On Wed, 2017-08-09 at 11:53 +0100, Daniel Stone wrote:
> When using dmabuf import, make sure that the modifier is actually
> allowed to add planes to the base format, as implied by the comment.
> 
> Signed-off-by: Daniel Stone 
---
>  src/egl/drivers/dri2/egl_dri2.c | 38 +++---
>  1 file changed, 19 insertions(+), 19 deletions(-)
> 
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index f0d1ded408..14decfed99 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -2120,6 +2120,24 @@ dri2_check_dma_buf_format(const _EGLImageAttribs 
> *attrs)
>    return 0;
> }
>  
> +   for (unsigned i = plane_n; i < DMA_BUF_MAX_PLANES; i++) {
> +  /**
> +   * 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) {
> + plane_n = i + 1;
> +  }
> +   }
> +

Nice, this makes sure that all planes up to the last modifier have fds
present. And since all fds are guaranteed to be present, the modifier
equality check in dri2_check_dma_buf_attribs also makes sure that there
are no missing modifiers.

Reviewed-by: Philipp Zabel 

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


[Mesa-dev] [PATCH 2/2] renderonly: drop resources on destroy

2017-04-27 Thread Philipp Zabel
The renderonly_scanout holds a reference on its prime pipe resource,
which should be released when it is destroyed. If it was created by
renderonly_create_kms_dumb_buffer_for_resource, the dumb BO also has
to be destroyed.

Signed-off-by: Philipp Zabel 
---
 src/gallium/auxiliary/renderonly/renderonly.c  | 11 ++-
 src/gallium/auxiliary/renderonly/renderonly.h  |  3 ++-
 src/gallium/drivers/etnaviv/etnaviv_resource.c |  2 +-
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/gallium/auxiliary/renderonly/renderonly.c 
b/src/gallium/auxiliary/renderonly/renderonly.c
index e17c32886d..f377c368e5 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.c
+++ b/src/gallium/auxiliary/renderonly/renderonly.c
@@ -34,6 +34,7 @@
 
 #include "state_tracker/drm_driver.h"
 #include "pipe/p_screen.h"
+#include "util/u_inlines.h"
 #include "util/u_memory.h"
 
 struct renderonly *
@@ -65,8 +66,16 @@ renderonly_scanout_for_prime(struct pipe_resource *rsc, 
struct renderonly *ro)
 }
 
 void
-renderonly_scanout_destroy(struct renderonly_scanout *scanout)
+renderonly_scanout_destroy(struct renderonly_scanout *scanout,
+  struct renderonly *ro)
 {
+   struct drm_mode_destroy_dumb destroy_dumb = { };
+
+   pipe_resource_reference(&scanout->prime, NULL);
+   if (ro->kms_fd != -1) {
+  destroy_dumb.handle = scanout->handle;
+  ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+   }
FREE(scanout);
 }
 
diff --git a/src/gallium/auxiliary/renderonly/renderonly.h 
b/src/gallium/auxiliary/renderonly/renderonly.h
index 28989f202d..d543073298 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.h
+++ b/src/gallium/auxiliary/renderonly/renderonly.h
@@ -77,7 +77,8 @@ struct renderonly_scanout *
 renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly *ro);
 
 void
-renderonly_scanout_destroy(struct renderonly_scanout *scanout);
+renderonly_scanout_destroy(struct renderonly_scanout *scanout,
+  struct renderonly *ro);
 
 static inline boolean
 renderonly_get_handle(struct renderonly_scanout *scanout,
diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index 2c5e9298e5..0e37345c0c 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -305,7 +305,7 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
pipe_resource *prsc)
   etna_bo_del(rsc->ts_bo);
 
if (rsc->scanout)
-  renderonly_scanout_destroy(rsc->scanout);
+  renderonly_scanout_destroy(rsc->scanout, etna_screen(pscreen)->ro);
 
list_delinit(&rsc->list);
 
-- 
2.11.0

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


[Mesa-dev] [PATCH 1/2] renderonly: close transfer prime_fd

2017-04-27 Thread Philipp Zabel
prime_fd is only used to transfer the scanout buffer to the GPU inside
renderonly_create_kms_dumb_buffer_for_resource. It should be closed
immediately to avoid leaking the DMA-BUF file handle.

Signed-off-by: Philipp Zabel 
---
 src/gallium/auxiliary/renderonly/renderonly.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/auxiliary/renderonly/renderonly.c 
b/src/gallium/auxiliary/renderonly/renderonly.c
index 7e23769159..e17c32886d 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.c
+++ b/src/gallium/auxiliary/renderonly/renderonly.c
@@ -116,6 +116,8 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
scanout->prime = screen->resource_from_handle(screen, rsc,
  &handle, PIPE_HANDLE_USAGE_READ_WRITE);
 
+   close(prime_fd);
+
if (!scanout->prime) {
   fprintf(stderr, "failed to create resource_from_handle: %s\n", 
strerror(errno));
   goto free_dumb;
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH 2/2] renderonly: drop resources on destroy

2017-04-28 Thread Philipp Zabel
On Fri, 2017-04-28 at 11:19 +0100, Emil Velikov wrote:
> On 27 April 2017 at 17:44, Philipp Zabel  wrote:
> > The renderonly_scanout holds a reference on its prime pipe resource,
> > which should be released when it is destroyed. If it was created by
> > renderonly_create_kms_dumb_buffer_for_resource, the dumb BO also has
> > to be destroyed.
> >
> > Signed-off-by: Philipp Zabel 
> Fixes: 848b49b288f ("gallium: add renderonly library")
> Reviewed-by: Emil Velikov 
> 
> > +  ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
> This and there other two instances should be drmIoctl, but that can
> happen with a later patch.

Thanks, I'll send a follow-up.

regards
Philipp

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


[Mesa-dev] [PATCH] renderonly: use drmIoctl

2017-04-28 Thread Philipp Zabel
To restart interrupted system calls, use drmIoctl.

Suggested-by: Emil Velikov 
Signed-off-by: Philipp Zabel 
---
Applies on top of the "renderonly: drop resources on destroy" patch:
https://patchwork.freedesktop.org/patch/153274/
---
 src/gallium/auxiliary/renderonly/renderonly.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/renderonly/renderonly.c 
b/src/gallium/auxiliary/renderonly/renderonly.c
index f377c368e5..2fe1009016 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.c
+++ b/src/gallium/auxiliary/renderonly/renderonly.c
@@ -29,7 +29,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "state_tracker/drm_driver.h"
@@ -74,7 +73,7 @@ renderonly_scanout_destroy(struct renderonly_scanout *scanout,
pipe_resource_reference(&scanout->prime, NULL);
if (ro->kms_fd != -1) {
   destroy_dumb.handle = scanout->handle;
-  ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+  drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
}
FREE(scanout);
 }
@@ -99,7 +98,7 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
   return NULL;
 
/* create dumb buffer at scanout GPU */
-   err = ioctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
+   err = drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
if (err < 0) {
   fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n",
 strerror(errno));
@@ -136,7 +135,7 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
 
 free_dumb:
destroy_dumb.handle = scanout->handle;
-   ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+   drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
 
 free_scanout:
FREE(scanout);
-- 
2.11.0

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


[Mesa-dev] [PATCH] renderonly: use drmIoctl

2017-04-28 Thread Philipp Zabel
To restart interrupted system calls, use drmIoctl.

Suggested-by: Emil Velikov 
Signed-off-by: Philipp Zabel 
---
Applies on top of the "renderonly: drop resources on destroy" patch:
https://patchwork.freedesktop.org/patch/153274/
---
 src/gallium/auxiliary/renderonly/renderonly.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/renderonly/renderonly.c 
b/src/gallium/auxiliary/renderonly/renderonly.c
index f377c368e5..2fe1009016 100644
--- a/src/gallium/auxiliary/renderonly/renderonly.c
+++ b/src/gallium/auxiliary/renderonly/renderonly.c
@@ -29,7 +29,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 #include "state_tracker/drm_driver.h"
@@ -74,7 +73,7 @@ renderonly_scanout_destroy(struct renderonly_scanout *scanout,
pipe_resource_reference(&scanout->prime, NULL);
if (ro->kms_fd != -1) {
   destroy_dumb.handle = scanout->handle;
-  ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+  drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
}
FREE(scanout);
 }
@@ -99,7 +98,7 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
   return NULL;
 
/* create dumb buffer at scanout GPU */
-   err = ioctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
+   err = drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
if (err < 0) {
   fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n",
 strerror(errno));
@@ -136,7 +135,7 @@ renderonly_create_kms_dumb_buffer_for_resource(struct 
pipe_resource *rsc,
 
 free_dumb:
destroy_dumb.handle = scanout->handle;
-   ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+   drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
 
 free_scanout:
FREE(scanout);
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH] etnaviv: add L8A8_UNORM texture format

2017-05-03 Thread Philipp Zabel
On Tue, 2017-05-02 at 22:06 +0200, Christian Gmeiner wrote:
> No piglit regressions.
> 
> Signed-off-by: Christian Gmeiner 

Reviewed-by: Philipp Zabel 

> ---
>  src/gallium/drivers/etnaviv/etnaviv_format.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_format.c 
> b/src/gallium/drivers/etnaviv/etnaviv_format.c
> index 0794603..7c24386 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_format.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_format.c
> @@ -103,6 +103,8 @@ static struct etna_format formats[PIPE_FORMAT_COUNT] = {
> _T(B4G4R4A4_UNORM, A4R4G4B4, A4R4G4B4),
> _T(B4G4R4X4_UNORM, X4R4G4B4, X4R4G4B4),
>  
> +   _T(L8A8_UNORM, A8L8, NONE),
> +
> _T(Z16_UNORM,  D16,  A4R4G4B4),
> _T(B5G6R5_UNORM,   R5G6B5,   R5G6B5),
> _T(B5G5R5A1_UNORM, A1R5G5B5, A1R5G5B5),


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


Re: [Mesa-dev] Sampling DRM_FORMAT_YUYV in GLSL

2017-05-09 Thread Philipp Zabel
On Tue, 2017-05-09 at 12:31 +0300, Tapani Pälli wrote:
> 
> On 05/09/2017 12:29 PM, Tapani Pälli wrote:
> > 
> > 
> > On 05/09/2017 12:14 PM, Volker Vogelhuber wrote:
> >> Hi,
> >>
> >> first sorry, for missing the subject in my mail to the mailing list, 
> >> then thanks
> >> for the hint with the "ext_image_dma_buf_import-sample_yuv". 
> >> Unfortunately
> >> things don't become clearer. In the samples as far as I can see, there 
> >> is also
> >> only one sampler defined in the shader. So how are the different 
> >> planes accessed
> >> in the shader? In the example only a simple copy is done:
> >> gl_FragColor = texture2D(sampler, texcoords);
> >> In the comment in intel_screen.c it says:
> >>
> >> /* For YUYV buffers, we set up two overlapping DRI images and treat
> >>  * them as planar buffers in the compositors.  Plane 0 is GR88 and
> >>  * samples YU or YV pairs and places Y into the R component, while
> >>  * plane 1 is ARGB and samples YUYV clusters and places pairs and
> >>  * places U into the G component and V into A.  This lets the
> >>  * texture sampler interpolate the Y components correctly when
> >>  * sampling from plane 0, and interpolate U and V correctly when
> >>  * sampling from plane 1. */
> >>
> >> So how are the pixels transfered from the YUYV memory to the vec4 in 
> >> the shader?
> >> Do I have to calculate the chroma values by interpolating myself based 
> >> on the
> >> current texture coordinate? Or is it done automatically in some way? 
> >>  From my
> >> experience the texture call only returns the values from plane0 which 
> >> leads me to the
> >> suspicion that I have to interpolate myself. But why is there then the 
> >> plane 1 which
> >> don't seem to be accessible in the shader?
> >>
> >> BTW: I'm using the OES_EGL_image extension not the 
> >> OES_EGL_image_external, so my
> >> sampler is sampler2D not samplerExternalOES but that shouldn't make a 
> >> difference should it?
> > 
> > IMO that is a big difference as samplerExternalOES does the YUV2RGB 
> > conversion and returns RGB values for you.
> 
> I have to add that "this is how I think it works", I haven't tried this 
> myself :)

This is correct. The OES_EGL_image_external extension states:

   "Sampling an external texture will return an RGBA vector in the same
colorspace as the source image.  If the source image is stored in YUV
(or some other basis) then the YUV values will be transformed to RGB
values. (But these RGB values will be in the same colorspace as the
original image."

Whereas when using a GL_TEXTURE_2D target, you have to do the conversion
yourself, sampling from to separate textures specified from two
EGLImages (one RG88 for Y, and one ARGB for UV, as described above).

regards
Philipp

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


Re: [Mesa-dev] Sampling DRM_FORMAT_YUYV in GLSL

2017-05-09 Thread Philipp Zabel
On Tue, 2017-05-09 at 12:48 +0200, Volker Vogelhuber wrote:
[...]
> Ok thanks for the clarification. There is only one missing part for the
> GL_TEXTURE_2D case. The second EGLImage is created internally when
> calling eglCreateImage with EGL_LINUX_DMA_BUF_EXT, so I only
> have one return value I can bind to a texture using 
> glEGLImageTargetTexture2DOES.
> Is there any "get" function to access the ARGB eglimage to bind it to 
> another
> texture?

You create two separate EGLImages, calling eglCreateImage once for each
plane. See for example:

https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/gst-libs/gst/gl/gstglupload.c#n646

or

https://cgit.freedesktop.org/wayland/weston/tree/libweston/gl-renderer.c#n1536

regards
Philipp

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


[Mesa-dev] [PATCH] configure.ac: Fix help string for --disable-pwr8 configure option

2017-05-10 Thread Philipp Zabel
Signed-off-by: Philipp Zabel 
---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index df3eb6b29a..5c460f43d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -455,7 +455,7 @@ int main () {
 CFLAGS=$save_CFLAGS
 
 AC_ARG_ENABLE(pwr8,
-   [AS_HELP_STRING([--disable-pwr8-inst],
+   [AS_HELP_STRING([--disable-pwr8],
[disable POWER8-specific instructions])],
[enable_pwr8=$enableval], [enable_pwr8=auto])
 
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH 5/5] etnaviv: increment the resource seqno in resource_changed

2017-05-11 Thread Philipp Zabel
On Wed, 2017-05-10 at 20:14 +0200, Wladimir J. van der Laan wrote:
> Seems more straightforward, but I don't know the rationale
> why it was done the way it was.
> 
> Reviewed-By: Wladimir J. van der Laan  

The rationale essentially was "the texture must be older than the
imported renderable so it will be resolved after importing" and "we
increase renderable seqno when we _render_ into it". I initially didn't
make the connection that reimporting a renderable with new content is
effectively the same thing as rendering new content into it.

regards
Philipp

> 
> On Wed, May 10, 2017 at 06:01:08PM +0200, Lucas Stach wrote:
> > From: Philipp Zabel 
> > 
> > Just increment the resource seqno instead of setting the texture
> > seqno to be lower by one than the resource seqno.
> > 
> > Signed-off-by: Philipp Zabel 
> > Signed-off-by: Lucas Stach 
> > ---
> >  src/gallium/drivers/etnaviv/etnaviv_resource.c | 6 +-
> >  1 file changed, 1 insertion(+), 5 deletions(-)
> > 
> > diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> > b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > index 103b53c1c310..1341e1ea2314 100644
> > --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> > @@ -286,11 +286,7 @@ etna_resource_changed(struct pipe_screen *pscreen, 
> > struct pipe_resource *prsc)
> >  {
> > struct etna_resource *res = etna_resource(prsc);
> >  
> > -   /* Make sure texture is older than the imported renderable buffer,
> > -* so etna_update_sampler_source will copy the pixel data again.
> > -*/
> > -   if (res->texture)
> > -  etna_resource(res->texture)->seqno = res->seqno - 1;
> > +   res->seqno++;
> >  }
> >  
> >  static void
> > -- 
> > 2.11.0
> > 
> > ___
> > etnaviv mailing list
> > etna...@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/etnaviv
> 
> 


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


Re: [Mesa-dev] [PATCH 3/3] etnaviv: Check extended format availability on GPU

2017-05-16 Thread Philipp Zabel
Hi Wladimir,

On Tue, 2017-05-16 at 10:42 +0200, Wladimir J. van der Laan wrote:
> Current information shows that both extended texture/render formats
> and texture swizzling were introduced with the HALTI0 feature bit,
> available on GC2000/GC3000.

With this patch applied, trying to import R8_UNORM dma-buffers via
EGLImage results in an endless recursion:

etna_copy_resource -> etna_blit -> util_try_blit_via_copy_region ->
util_resource_copy_region -> etna_transfer_map -> etna_copy_resource ->
etna_blit -> ...

I think the problem is that etna_blit fails to blit via RS because of
missing compatible RS formats and falls through to call
util_blitter_blit, which in turn tries to map the resource to blit into
it in software using etna_transfer_map, which uses etna_copy_resource to
create a transfer copy, which calls etna_blit, and so on ...
I'm not exactly sure where the loop should be broken if the RS doesn't
support copying the format at all.

Is there any single-byte pixel format that could be returned from
etna_compatible_rs_format for PIPE_FORMAT_R8_UNORM ?

The only thing that looks remotely related is RS_FORMAT_R8I, but that is
marked as extended format in rnndb and doesn't fit into
RS_CONFIG_SOURCE/DEST_FORMAT. Is it even possible to tile R8/A8/L8
textures in hardware?

regards
Philipp

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


Re: [Mesa-dev] [PATCH] mesa/st: fix yuv EGLImage's

2017-05-17 Thread Philipp Zabel
On Tue, 2017-05-16 at 10:33 -0400, Rob Clark wrote:
> Don't reject YUV formats that the driver doesn't handle natively, since
> mesa/st already knows how to lower this in shader.
>
> Fixes: 83e9de2 ("st/mesa: EGLImageTarget* error handling")
> Cc: 17.1  Signed-off-by: Rob Clark 
> ---
>  src/mesa/state_tracker/st_cb_eglimage.c | 32 ++--
>  1 file changed, 30 insertions(+), 2 deletions(-)
> 
> diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
> b/src/mesa/state_tracker/st_cb_eglimage.c
> index 3a62ef7..a104b64 100644
> --- a/src/mesa/state_tracker/st_cb_eglimage.c
> +++ b/src/mesa/state_tracker/st_cb_eglimage.c
> @@ -39,6 +39,35 @@
>  #include "st_sampler_view.h"
>  #include "util/u_surface.h"
>  
> +static bool
> +is_format_supported(struct pipe_screen *screen, enum pipe_format format,
> +unsigned nr_samples, unsigned usage)
> +{
> +   bool supported = screen->is_format_supported(screen, format, 
> PIPE_TEXTURE_2D,
> +nr_samples, usage);
> +
> +   /* for sampling, some formats can be emulated.. it doesn't matter that
> +* the surface will have a format that the driver can't cope with because
> +* we'll give it sampler view formats that it can deal with and generate
> +* a shader variant that converts.
> +*/
> +   if ((usage == PIPE_BIND_SAMPLER_VIEW) && !supported) {
> +  if (format == PIPE_FORMAT_IYUV) {
> + supported = screen->is_format_supported(screen, 
> PIPE_FORMAT_R8_UNORM,
> + PIPE_TEXTURE_2D, nr_samples,
> + usage);
> +  } else if (format == PIPE_FORMAT_NV12) {
> + supported = screen->is_format_supported(screen, 
> PIPE_FORMAT_R8_UNORM,
> + PIPE_TEXTURE_2D, nr_samples,
> + usage) &&
> + screen->is_format_supported(screen, 
> PIPE_FORMAT_R8G8_UNORM,
> + PIPE_TEXTURE_2D, nr_samples,
> + usage);
> +  }
> +   }
> +
> +   return supported;
> +}

But this only works for target == GL_TEXTURE_EXTERNAL_OES, right?
If so, I think we would have to pass the target enum through
st_egl_image_get_surface to is_format_supported and make a decision
based on that.

regards
Philipp

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


[Mesa-dev] [RFC v2] etnaviv: flush color cache and depth cache together before resolves

2017-06-23 Thread Philipp Zabel
Before resolving a rendertarget or a depth/stencil resource into a
texture, flush both the color cache and the depth cache together.

It is unclear whether this is necessary for the following stall to
work properly, or whether the depth flush just adds enough time
for the color cache flush to finish before the resolver is started,
but this change removes artifacts that otherwise appear if a texture
is sampled directly after rendering into it.

The test case is a simple QML scene graph with a QtWebEngine based
WebView rendered on top of a blue background:

import QtQuick 2.0
import QtQuick.Window 2.2
import QtWebView 1.1

Window {
Rectangle {
id: background
anchors.fill: parent
color: "blue"
}

WebView {
id: webView
anchors.fill: parent
}

Component.onCompleted: {
webView.url = ""
}
}

If the website is animated, the WebView renders the site contents into
texture tiles and immediately afterwards samples from them to draw the
tiles into the Qt renderbuffer. Without this patch, a small irregular
triangle in the lower right of each browser tile appears solid blue, as
if the texture sampler samples zeroes instead of the website contents,
and the previously rendered blue Rectangle shows through.

Other attempts such as adding a pipeline stall before the color flush or
a TS cache flush afterwards or flushing multiple times, with stalls
before and after each flush, have shown no effect.

Signed-off-by: Philipp Zabel 
---
Changes since v1:
 - Add a comment explaining why we flush color and depth cache together.
---
 src/gallium/drivers/etnaviv/etnaviv_clear_blit.c | 22 +-
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c 
b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
index e4620a3015..d9538907fe 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
@@ -465,15 +465,19 @@ etna_try_rs_blit(struct pipe_context *pctx,
   ts_mem_config |= VIVS_TS_MEM_CONFIG_MSAA | msaa_format;
}
 
-   uint32_t to_flush = 0;
-
-   if (src->base.bind & PIPE_BIND_RENDER_TARGET)
-  to_flush |= VIVS_GL_FLUSH_CACHE_COLOR;
-   if (src->base.bind & PIPE_BIND_DEPTH_STENCIL)
-  to_flush |= VIVS_GL_FLUSH_CACHE_DEPTH;
-
-   if (to_flush) {
-  etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE, to_flush);
+   /* Always flush color and depth cache together before resolving. This works
+* around artifacts that appear in some cases when scanning out a texture
+* directly after it has been rendered to, such as rendering an animated web
+* page in a QtWebEngine based WebView on GC2000. The artifacts look like
+* the texture sampler samples zeroes instead of texture data in a small,
+* irregular triangle in the lower right of each browser tile quad. Other
+* attempts to avoid these artifacts, including a pipeline stall before the
+* color flush or a TS cache flush afterwards, or flushing multiple times,
+* with stalls before and after each flush, have shown no effect. */
+   if (src->base.bind & PIPE_BIND_RENDER_TARGET ||
+   src->base.bind & PIPE_BIND_DEPTH_STENCIL) {
+  etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE,
+VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH);
   etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE);
}
 
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH 03/11] renderonly/etnaviv: stop importing resource from renderonly

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> The current way of importing the resource from renderonly after allocation
> is opaque and is taking away control from the driver, which it needs in
> order to implement more advanced scenarios, than the simple linear
> scanout with matching stride alignments.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/auxiliary/renderonly/renderonly.c| 52 
> +++-
>  src/gallium/auxiliary/renderonly/renderonly.h| 20 -
>  src/gallium/drivers/etnaviv/etnaviv_clear_blit.c |  8 ++--
>  src/gallium/drivers/etnaviv/etnaviv_resource.c   | 23 +++
>  src/gallium/drivers/etnaviv/etnaviv_resource.h   |  5 +++
>  5 files changed, 49 insertions(+), 59 deletions(-)
> 
[...]
> diff --git a/src/gallium/auxiliary/renderonly/renderonly.h 
> b/src/gallium/auxiliary/renderonly/renderonly.h
> index 70641c45878a..6a89c29e2ef6 100644
> --- a/src/gallium/auxiliary/renderonly/renderonly.h
> +++ b/src/gallium/auxiliary/renderonly/renderonly.h
> @@ -34,8 +34,6 @@
>  struct renderonly_scanout {
> uint32_t handle;
> uint32_t stride;
> -
> -   struct pipe_resource *prime;
>  };
>  
>  struct renderonly {
> @@ -59,7 +57,8 @@ struct renderonly {
>  *   to be done in flush_resource(..) like a resolve to linear.
>  */
> struct renderonly_scanout *(*create_for_resource)(struct pipe_resource 
> *rsc,
> - struct renderonly *ro);
> + struct renderonly *ro,
> + struct winsys_handle 
> *out_handle);
> int kms_fd;
> int gpu_fd;
>  };
> @@ -68,14 +67,13 @@ struct renderonly *
>  renderonly_dup(const struct renderonly *ro);
>  
>  static inline struct renderonly_scanout *
> -renderonly_scanout_for_resource(struct pipe_resource *rsc, struct renderonly 
> *ro)
> +renderonly_scanout_for_resource(struct pipe_resource *rsc,
> +struct renderonly *ro,
> +struct winsys_handle *out_handle)
>  {
> -   return ro->create_for_resource(rsc, ro);
> +   return ro->create_for_resource(rsc, ro, out_handle);
>  }

This changes the signature for renderonly_scanout_for_resource, which is
also called at:

src/gallium/drivers/vc4/vc4_resource.c:601:
renderonly_scanout_for_resource(prsc, screen->ro);

since commit 7029ec05e2c7 ("gallium: Add renderonly-based support for
pl111+vc4.").

> -struct renderonly_scanout *
> -renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly 
> *ro);
> -
>  void
>  renderonly_scanout_destroy(struct renderonly_scanout *scanout,
>  struct renderonly *ro);
[...]
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 97e0a15597fa..c6e7e98837b6 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -214,8 +214,20 @@ etna_resource_alloc(struct pipe_screen *pscreen, 
> unsigned layout,
> rsc->bo = bo;
> rsc->ts_bo = 0; /* TS is only created when first bound to surface */
>  
> -   if (templat->bind & PIPE_BIND_SCANOUT)
> -  rsc->scanout = renderonly_scanout_for_resource(&rsc->base, screen->ro);
> +   if (templat->bind & PIPE_BIND_SCANOUT) {
> +  struct winsys_handle handle;
> +  rsc->scanout = renderonly_scanout_for_resource(&rsc->base, screen->ro,
> + &handle);
> +  if (!rsc->scanout)
> + goto free_rsc;
> +
> +  rsc->external = pscreen->resource_from_handle(pscreen, &rsc->base,
> +&handle,
> +PIPE_HANDLE_USAGE_WRITE);
> +  close(handle.handle);

Is the handle guaranteed to be DRM_API_HANDLE_TYPE_FD at this point?

> +  if (!rsc->external)
> + goto free_rsc;
> +   }
>  
> if (DBG_ENABLED(ETNA_DBG_ZERO)) {
>void *map = etna_bo_map(bo);
> @@ -310,6 +322,7 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct 
> pipe_resource *prsc)
> list_delinit(&rsc->list);
>  
> pipe_resource_reference(&rsc->texture, NULL);
> +   pipe_resource_reference(&rsc->external, NULL);
>  
> FREE(rsc);
>  }
> @@ -375,16 +388,12 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
>/* Render targets are linear in Xorg but must be tiled
>* here. It would be nice if dri_drawable_get_format()
>* set scanout for these buffers too. */
> -  struct etna_resource *tiled;
>  
>ptiled = etna_resource_create(pscreen, tmpl);
>if (!ptiled)
>   goto fail;
>  
> -  tiled = etna_resource(ptiled);
> -  tiled->scanout = renderonly_scanout_for_prime(prsc, screen->ro);
> -  if (!tiled->scanout)
> - goto fail;
> +  etna_resource(ptiled)->external = 

Re: [Mesa-dev] [PATCH 01/11] etnaviv: fill in layer_stride for imported resources

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> The layer stride information is used in various parts of the driver,
> so it needs to be present regardless if the driver allocated the
> buffer itself or merely imported it from an external source.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 1c098445b17a..dfd087071193 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -352,6 +352,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
>  
> level->padded_width = align(level->width, paddingX);
> level->padded_height = align(level->height, paddingY);
> +   level->layer_stride = level->stride * 
> util_format_get_nblocksy(prsc->format,
> +  
> level->padded_height);
>  
> /* The DDX must give us a BO which conforms to our padding size.
>  * The stride of the BO must be greater or equal to our padded

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 02/11] etnaviv: fix memory leak when BO allocation fails

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> The resource struct is already allocated at this point and should be
> free properly.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index dfd087071193..97e0a15597fa 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -208,7 +208,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned 
> layout,
> struct etna_bo *bo = etna_bo_new(screen->dev, size, flags);
> if (unlikely(bo == NULL)) {
>BUG("Problem allocating video memory for resource");
> -  return NULL;
> +  goto free_rsc;
> }
>  
> rsc->bo = bo;
> @@ -223,6 +223,10 @@ etna_resource_alloc(struct pipe_screen *pscreen, 
> unsigned layout,
> }
>  
> return &rsc->base;
> +
> +free_rsc:
> +   FREE(rsc);
> +   return NULL;
>  }
>  
>  static struct pipe_resource *

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 04/11] etnaviv: pad scanout buffer size to RS alignment

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> This fixes failures to import the scanout buffer with screen resolutions
> that don't satisfy teh RS alignment restrictions, like 1680x1050.
^^^ typo

> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index c6e7e98837b6..5cd20fafba49 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -215,9 +215,18 @@ etna_resource_alloc(struct pipe_screen *pscreen, 
> unsigned layout,
> rsc->ts_bo = 0; /* TS is only created when first bound to surface */
>  
> if (templat->bind & PIPE_BIND_SCANOUT) {
> +  struct pipe_resource scanout_templat = *templat;
>struct winsys_handle handle;
> -  rsc->scanout = renderonly_scanout_for_resource(&rsc->base, screen->ro,
> - &handle);
> +  unsigned padX, padY;
> +
> +  /* pad scanout buffer size to be compatible with the RS */
> +  padX = ETNA_RS_WIDTH_MASK + 1;
> +  padY = (ETNA_RS_HEIGHT_MASK + 1) * screen->specs.pixel_pipes;
> +  scanout_templat.width0 = align(scanout_templat.width0, padX);
> +  scanout_templat.height0 = align(scanout_templat.height0, padY);
> +
> +  rsc->scanout = renderonly_scanout_for_resource(&scanout_templat,
> +         screen->ro, &handle);
>if (!rsc->scanout)
>   goto free_rsc;

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 05/11] etnaviv: increment correct seqno for external resources

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> If we import a dma-buf with a sampler/pixel pipe incompatible modifier,
> the imported buffer will end up in an external resource view. As
> resource_changed signals the change of the imported resource, we need
> to update the external view seqno, instead of the base resource seqno.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_resource.c | 5 -
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
> b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> index 5cd20fafba49..43f63f8908a0 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
> @@ -311,7 +311,10 @@ etna_resource_changed(struct pipe_screen *pscreen, 
> struct pipe_resource *prsc)
>  {
> struct etna_resource *res = etna_resource(prsc);
>  
> -   res->seqno++;
> +   if (res->external)
> +  etna_resource(res->external)->seqno++;
> +   else
> +  res->seqno++;
>  }
>  
>  static void

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH] etnaviv: only flush resource to self if no scanout buffer exists

2017-06-26 Thread Philipp Zabel
On Mon, 2017-06-26 at 12:25 +0200, Lucas Stach wrote:
> Currently a resource flush may trigger a self resolve, even if a scanout 
> buffer
> exists, but is up to date. If a scanout buffer exists we only ever want to
> flush the resource to the scanout buffer. This fixes a performance regression.
> 
> Fixes: dda956340ce9 (etnaviv: resolve tile status when flushing resource)
> Cc: mesa-sta...@lists.freedesktop.org
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_clear_blit.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c 
> b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> index e4620a3015e9..80967be3f93d 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> @@ -602,10 +602,11 @@ etna_flush_resource(struct pipe_context *pctx, struct 
> pipe_resource *prsc)
>  {
> struct etna_resource *rsc = etna_resource(prsc);
>  
> -   if (rsc->scanout &&
> -   etna_resource_older(etna_resource(rsc->scanout->prime), rsc)) {
> -  etna_copy_resource(pctx, rsc->scanout->prime, prsc, 0, 0);
> -  etna_resource(rsc->scanout->prime)->seqno = rsc->seqno;
> +   if (rsc->scanout) {
> +  if (etna_resource_older(etna_resource(rsc->scanout->prime), rsc)) {
> + etna_copy_resource(pctx, rsc->scanout->prime, prsc, 0, 0);
> + etna_resource(rsc->scanout->prime)->seqno = rsc->seqno;
> +  }
> } else if (etna_resource_needs_flush(rsc)) {
>etna_copy_resource(pctx, prsc, prsc, 0, 0);
>rsc->flush_seqno = rsc->seqno;

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 06/11] etnaviv: also update textures from external resources

2017-06-26 Thread Philipp Zabel
On Fri, 2017-06-23 at 17:50 +0200, Lucas Stach wrote:
> This reworks the logic in etna_update_sampler_source to select the
> newest resource view for updating the texture view. This should make
> the logic easier to follow and fixes texture updates from imported
> dma-bufs.
> 
> Signed-off-by: Lucas Stach 
> ---
>  src/gallium/drivers/etnaviv/etnaviv_texture.c | 23 +++
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture.c 
> b/src/gallium/drivers/etnaviv/etnaviv_texture.c
> index df77829078c0..b7e424f89bba 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_texture.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_texture.c
> @@ -113,16 +113,23 @@ etna_delete_sampler_state(struct pipe_context *pctx, 
> void *ss)
>  static void
>  etna_update_sampler_source(struct pipe_sampler_view *view)
>  {
> -   struct etna_resource *res = etna_resource(view->texture);
> +   struct etna_resource *base = etna_resource(view->texture);
> +   struct etna_resource *to = base, *from = base;
>  
> -   if (res->texture && etna_resource_older(etna_resource(res->texture), 
> res)) {
> -  /* Texture is older than render buffer, copy the texture using RS */
> -  etna_copy_resource(view->context, res->texture, view->texture, 0,
> +   if (base->external && etna_resource_newer(etna_resource(base->external), 
> base))
> +  from = etna_resource(base->external);
> +
> +   if (base->texture)
> +  to = etna_resource(base->texture);
> +
> +   if ((to != from) && etna_resource_older(to, from)) {
> +  etna_copy_resource(view->context, &to->base, &from->base, 0,
> + view->texture->last_level);
> +  to->seqno = from->seqno;
> +   } else if ((to == from) && etna_resource_needs_flush(to)) {
> +  etna_copy_resource(view->context, &to->base, &from->base, 0,
>   view->texture->last_level);
> -  etna_resource(res->texture)->seqno = res->seqno;
> -   } else if (etna_resource_needs_flush(res)) {
> -  etna_copy_resource(view->context, view->texture, view->texture, 0, 0);
> -  res->flush_seqno = res->seqno;
> +  to->flush_seqno = from->seqno;
> }
>  }
>  

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH 07/11] etnaviv: implement resource import with modifier

2017-06-27 Thread Philipp Zabel
->external = pscreen->resource_from_handle(pscreen, &rsc->base,
> -&handle,
> -PIPE_HANDLE_USAGE_WRITE);
> -  close(handle.handle);
> -  if (!rsc->external)
> - goto free_rsc;
> -   }
> -
> if (DBG_ENABLED(ETNA_DBG_ZERO)) {
>void *map = etna_bo_map(bo);
>memset(map, 0, size);
> @@ -370,14 +398,21 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
>goto fail;
>  
> rsc->seqno = 1;
> +   rsc->layout = modifier_to_layout(handle->modifier);
> +   rsc->halign = TEXTURE_HALIGN_FOUR;
> +

Superfluous whitespace.
 
> level->width = tmpl->width0;
> level->height = tmpl->height0;
>  
> -   /* We will be using the RS to copy with this resource, so we must
> -* ensure that it is appropriately aligned for the RS requirements. */
> -   unsigned paddingX = ETNA_RS_WIDTH_MASK + 1;
> -   unsigned paddingY = (ETNA_RS_HEIGHT_MASK + 1) * screen->specs.pixel_pipes;
> +   /* Determine padding of the imported resource. */
> +   unsigned paddingX = 0, paddingY = 0;
> +   etna_layout_multiple(rsc->layout, screen->specs.pixel_pipes,
> +VIV_FEATURE(screen, chipMinorFeatures1, 
> TEXTURE_HALIGN),
> +&paddingX, &paddingY, &rsc->halign);
> +
> +   if (paddingY < 4 * screen->specs.pixel_pipes)
> +  paddingY = 4 * screen->specs.pixel_pipes;
>  
> level->padded_width = align(level->width, paddingX);
> level->padded_height = align(level->height, paddingY);
> @@ -396,12 +431,21 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
>goto fail;
> }
>  
> -   if (handle->type == DRM_API_HANDLE_TYPE_SHARED && tmpl->bind & 
> PIPE_BIND_RENDER_TARGET) {
> -  /* Render targets are linear in Xorg but must be tiled
> -  * here. It would be nice if dri_drawable_get_format()
> -  * set scanout for these buffers too. */
> +   if (rsc->layout == ETNA_LAYOUT_LINEAR) {
> +  /*
> +   * Both sampler and pixel pipes can't handle linear, create a 
> compatible
> +   * base resource, where we can attach the imported buffer as an 
> external
> +   * resource.
> +   */
> +  struct pipe_resource tiled_templat = *tmpl;
> +
> +  /*
> +   * Remove BIND_SCANOUT to avoid recursion, as etna_resource_create uses
> +   * this function to import the scanout buffer and get a tiled resource.
> +   */
> +  tiled_templat.bind &= ~PIPE_BIND_SCANOUT;
>  
> -  ptiled = etna_resource_create(pscreen, tmpl);
> +  ptiled = etna_resource_create(pscreen, &tiled_templat);
>if (!ptiled)
>   goto fail;
>  

Reviewed-by: Philipp Zabel 

regards
Philipp

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


Re: [Mesa-dev] [PATCH] etnaviv: flush source TS before resolve

2017-06-28 Thread Philipp Zabel
On Mon, 2017-06-26 at 18:24 +0200, Lucas Stach wrote:
> If we blit from a rendertarget or a depthstencil buffer there might still
> be dirty data in the TS buffer which needs to be flushed out.
> 
> Fixes missing shadow tiles in glmark2 shadow.
> 
> Signed-off-by: Lucas Stach 
> ---
> This is on top of "etnaviv: flush color cache and depth cache together
> before resolves". Without this commit flushing the TS is causing
> rendering corruption.

Glad to see that there's a more straightworward test case for this issue
than running an animated web page in Qt WebEngine.

> ---
>  src/gallium/drivers/etnaviv/etnaviv_clear_blit.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c 
> b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> index e967595f424c..40a6832f8785 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_clear_blit.c
> @@ -470,6 +470,10 @@ etna_try_rs_blit(struct pipe_context *pctx,
>etna_set_state(ctx->stream, VIVS_GL_FLUSH_CACHE,
>VIVS_GL_FLUSH_CACHE_COLOR | VIVS_GL_FLUSH_CACHE_DEPTH);
>etna_stall(ctx->stream, SYNC_RECIPIENT_RA, SYNC_RECIPIENT_PE);
> +
> +  if (src->levels[blit_info->src.level].ts_size &&
> +  src->levels[blit_info->src.level].ts_valid)
> + etna_set_state(ctx->stream, VIVS_TS_FLUSH_CACHE, 
> VIVS_TS_FLUSH_CACHE_FLUSH);
> }
>  
> /* Set up color TS to source surface before blit, if needed */

Reviewed-by: Philipp Zabel 

regards
Philipp

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


[Mesa-dev] [PATCH] st/mesa: release EGLImage on EGLImageTarget* error

2017-06-30 Thread Philipp Zabel
The smapi->get_egl_image() call in st_egl_image_get_surface() stores a
reference to the EGLImage's texture in stimg.texture. That reference is
released via pipe_resource_reference(&stimg.texture, NULL) before stimg
goes out of scope at the end of the function, but not in the error path
if !is_format_supported().

Fixes: 83e9de25f325 ("st/mesa: EGLImageTarget* error handling")
Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_cb_eglimage.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index 0f649f4ab4..4b7b85db70 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -96,6 +96,7 @@ st_egl_image_get_surface(struct gl_context *ctx, 
GLeglImageOES image_handle,
 
if (!is_format_supported(screen, stimg.format, stimg.texture->nr_samples, 
usage)) {
   /* unable to specify a texture object using the specified EGL image */
+  pipe_resource_reference(&stimg.texture, NULL);
   _mesa_error(ctx, GL_INVALID_OPERATION, "%s(format not supported)", 
error);
   return NULL;
}
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH v2 1/2] etnaviv: fix varying interpolation

2017-09-19 Thread Philipp Zabel
On Fri, 2017-09-15 at 18:04 +0200, Lucas Stach wrote:
> It seems that newer cores don't use the PA_ATTRIBUTES to decide if the
> varying should bypass the flat shading, but derive this from the
> component
> use. This fixes flat shading on GC880+.
> 
> VARYING_COMPONENT_USE_POINTCOORD is a bit of a misnomer now, as it
> isn't
> only used for pointcoords, but missing a better name I left it as-is.
> 
> Signed-off-by: Lucas Stach 
> ---
> v2: fix invalid vreg assignment
---
>  src/gallium/drivers/etnaviv/etnaviv_compiler.c | 23 ++-
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c 
> b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> index 165ab74298a4..d86d0561503a 100644
> --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c
> @@ -2607,6 +2607,7 @@ etna_link_shader(struct etna_shader_link_info *info,
>    const struct etna_shader_inout *fsio = &fs->infile.reg[idx];
>    const struct etna_shader_inout *vsio = etna_shader_vs_lookup(vs, fsio);
>    struct etna_varying *varying;
> +  bool interpolate = fsio->semantic.Name != TGSI_SEMANTIC_COLOR;
>  
>    assert(fsio->reg > 0 && fsio->reg <= ARRAY_SIZE(info->varyings));
>  
> @@ -2616,28 +2617,24 @@ etna_link_shader(struct etna_shader_link_info *info,
>    varying = &info->varyings[fsio->reg - 1];
>    varying->num_components = fsio->num_components;
>  
> -  if (fsio->semantic.Name == TGSI_SEMANTIC_COLOR) /* colors affected by 
> flat shading */
> +  if (interpolate) /* colors affected by flat shading */

This was (!interpolate) before, and looks like it should still be?
With that addressed,

Reviewed-by: Philipp Zabel 

>   varying->pa_attributes = 0x200;
>    else /* texture coord or other bypasses flat shading */
>   varying->pa_attributes = 0x2f1;
>  
> -  if (fsio->semantic.Name == TGSI_SEMANTIC_PCOORD) {
> - varying->use[0] = VARYING_COMPONENT_USE_POINTCOORD_X;
> - varying->use[1] = VARYING_COMPONENT_USE_POINTCOORD_Y;
> - varying->use[2] = VARYING_COMPONENT_USE_USED;
> - varying->use[3] = VARYING_COMPONENT_USE_USED;
> - varying->reg = 0; /* replaced by point coord -- doesn't matter */
> +  varying->use[0] = interpolate ? VARYING_COMPONENT_USE_POINTCOORD_X : 
> VARYING_COMPONENT_USE_USED;
> +  varying->use[1] = interpolate ? VARYING_COMPONENT_USE_POINTCOORD_Y : 
> VARYING_COMPONENT_USE_USED;
> +  varying->use[2] = VARYING_COMPONENT_USE_USED;
> +  varying->use[3] = VARYING_COMPONENT_USE_USED;
> +
> +
> +  if (fsio->semantic.Name == TGSI_SEMANTIC_PCOORD)
>   continue;

Since for point coord we just continue here without setting varying->reg 
at all ...

> -  }
>  
>    if (vsio == NULL)
>   return true; /* not found -- link error */
>  
> -  varying->use[0] = VARYING_COMPONENT_USE_USED;
> -  varying->use[1] = VARYING_COMPONENT_USE_USED;
> -  varying->use[2] = VARYING_COMPONENT_USE_USED;
> -  varying->use[3] = VARYING_COMPONENT_USE_USED;
> -  varying->reg = vsio->reg;
> +  varying->reg = vsio->reg; /* replaced by point coord -- doesn't matter 
> */

... is the comment still relevant here? Maybe this should be moved up
there.

> }
>  
> assert(info->num_varyings == fs->infile.num_reg);

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


[Mesa-dev] [PATCH v5 0/7] etnaviv: update derived texture resources of (re)imported buffers

2017-01-19 Thread Philipp Zabel
Hi,

this is a resend of the earlier series to get weston / wayland_egl
working on etnaviv, now using SCR_INIT to wrap resource_changed only
if it is implemented by the wrapped pipe_screen.

regards
Philipp

Changes since v4:
 - Added Christian's Reviewed-by tags
 - Use SCR_INIT to initialize the resource_changed wrapper only if
   resource_changed is implemented by the wrapped pipe_screen, add
   SCR_INIT macros to the rbug and trace wrappers.
 - Fix rbug_screen_resource_changed return value.

Philipp Zabel (7):
  gallium: add pipe_screen::resource_changed
  st/dri: ask the driver to update its internal copies on reimport
  etnaviv: initialize seqno of imported resources
  etnaviv: implement resource_changed to invalidate internal resources
derived from imported buffers
  mesa: update external textures when (re-)binding
  st/mesa: ask pipe driver to recreate derived internal resources when
(re-)binding external textures
  gallium: add pipe_screen::resource_changed callback wrappers

 src/gallium/docs/source/screen.rst | 14 ++
 src/gallium/drivers/ddebug/dd_screen.c | 10 ++
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 15 +++
 src/gallium/drivers/rbug/rbug_screen.c | 14 ++
 src/gallium/drivers/trace/tr_screen.c  | 23 +++
 src/gallium/include/pipe/p_screen.h|  8 
 src/gallium/state_trackers/dri/dri2.c  |  4 
 src/mesa/main/texobj.c |  5 +++--
 src/mesa/state_tracker/st_atom_texture.c   |  4 
 9 files changed, 95 insertions(+), 2 deletions(-)

-- 
2.1.4

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


[Mesa-dev] [PATCH v5 1/7] gallium: add pipe_screen::resource_changed

2017-01-19 Thread Philipp Zabel
Add a hook to tell drivers that an imported resource may have changed
and they need to update their internal derived resources.

Signed-off-by: Philipp Zabel 
Reviewed-by: Roland Scheidegger 
---
 src/gallium/docs/source/screen.rst  | 14 ++
 src/gallium/include/pipe/p_screen.h |  8 
 2 files changed, 22 insertions(+)

diff --git a/src/gallium/docs/source/screen.rst 
b/src/gallium/docs/source/screen.rst
index 64cb0bf..5ae2596 100644
--- a/src/gallium/docs/source/screen.rst
+++ b/src/gallium/docs/source/screen.rst
@@ -707,6 +707,20 @@ which isn't multisampled.
 
 
 
+resource_changed
+
+
+Mark a resource as changed so derived internal resources will be recreated
+on next use.
+
+When importing external images that can't be directly used as texture sampler
+source, internal copies may have to be created that the hardware can sample
+from. When those resources are reimported, the image data may have changed, and
+the previously derived internal resources must be invalidated to avoid sampling
+from old copies.
+
+
+
 resource_destroy
 
 
diff --git a/src/gallium/include/pipe/p_screen.h 
b/src/gallium/include/pipe/p_screen.h
index f04c2ed..b6203f1 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -224,6 +224,14 @@ struct pipe_screen {
  struct winsys_handle *handle,
  unsigned usage);
 
+   /**
+* Mark the resource as changed so derived internal resources will be
+* recreated on next use.
+*
+* This is necessary when reimporting external images that can't be directly
+* used as texture sampler source, to avoid sampling from old copies.
+*/
+   void (*resource_changed)(struct pipe_screen *, struct pipe_resource *pt);
 
void (*resource_destroy)(struct pipe_screen *,
struct pipe_resource *pt);
-- 
2.1.4

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


[Mesa-dev] [PATCH v5 4/7] etnaviv: implement resource_changed to invalidate internal resources derived from imported buffers

2017-01-19 Thread Philipp Zabel
Implement the resource_changed pipe callback to invalidate internal
resources derived from imported buffers. This is needed to update the
texture for re-imported renderables.

Signed-off-by: Philipp Zabel 
Reviewed-by: Reviewed-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index a8858c5..20ec8f8 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -275,6 +275,18 @@ etna_resource_create(struct pipe_screen *pscreen,
 }
 
 static void
+etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc)
+{
+   struct etna_resource *res = etna_resource(prsc);
+
+   /* Make sure texture is older than the imported renderable buffer,
+* so etna_update_sampler_source will copy the pixel data again.
+*/
+   if (res->texture)
+  etna_resource(res->texture)->seqno = res->seqno - 1;
+}
+
+static void
 etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc)
 {
struct etna_resource *rsc = etna_resource(prsc);
@@ -436,5 +448,6 @@ etna_resource_screen_init(struct pipe_screen *pscreen)
pscreen->resource_create = etna_resource_create;
pscreen->resource_from_handle = etna_resource_from_handle;
pscreen->resource_get_handle = etna_resource_get_handle;
+   pscreen->resource_changed = etna_resource_changed;
pscreen->resource_destroy = etna_resource_destroy;
 }
-- 
2.1.4

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


[Mesa-dev] [PATCH v5 7/7] gallium: add pipe_screen::resource_changed callback wrappers

2017-01-19 Thread Philipp Zabel
Add resource_changed to the ddebug, rbug, and trace wrappers. Since it
is optional, there is no need to add it to noop.

Signed-off-by: Philipp Zabel 
Suggested-by: Nicolai Hähnle 
---
Changes since v4:
 - Use SCR_INIT to initialize the resource_changed wrapper only if
   resource_changed is implemented by the wrapped pipe_screen, add
   SCR_INIT macros to the rbug and trace wrappers.
 - Fix rbug_screen_resource_changed return value.
---
 src/gallium/drivers/ddebug/dd_screen.c | 10 ++
 src/gallium/drivers/rbug/rbug_screen.c | 14 ++
 src/gallium/drivers/trace/tr_screen.c  | 23 +++
 3 files changed, 47 insertions(+)

diff --git a/src/gallium/drivers/ddebug/dd_screen.c 
b/src/gallium/drivers/ddebug/dd_screen.c
index a0c0dd0..58e496a 100644
--- a/src/gallium/drivers/ddebug/dd_screen.c
+++ b/src/gallium/drivers/ddebug/dd_screen.c
@@ -227,6 +227,15 @@ dd_screen_resource_from_user_memory(struct pipe_screen 
*_screen,
 }
 
 static void
+dd_screen_resource_changed(struct pipe_screen *_screen,
+   struct pipe_resource *res)
+{
+   struct pipe_screen *screen = dd_screen(_screen)->screen;
+
+   screen->resource_changed(screen, res);
+}
+
+static void
 dd_screen_resource_destroy(struct pipe_screen *_screen,
struct pipe_resource *res)
 {
@@ -385,6 +394,7 @@ ddebug_screen_create(struct pipe_screen *screen)
dscreen->base.resource_from_handle = dd_screen_resource_from_handle;
SCR_INIT(resource_from_user_memory);
dscreen->base.resource_get_handle = dd_screen_resource_get_handle;
+   SCR_INIT(resource_changed);
dscreen->base.resource_destroy = dd_screen_resource_destroy;
SCR_INIT(flush_frontbuffer);
SCR_INIT(fence_reference);
diff --git a/src/gallium/drivers/rbug/rbug_screen.c 
b/src/gallium/drivers/rbug/rbug_screen.c
index 3742c10..8fbbe73 100644
--- a/src/gallium/drivers/rbug/rbug_screen.c
+++ b/src/gallium/drivers/rbug/rbug_screen.c
@@ -191,7 +191,17 @@ rbug_screen_resource_get_handle(struct pipe_screen 
*_screen,
   resource, handle, usage);
 }
 
+static void
+rbug_screen_resource_changed(struct pipe_screen *_screen,
+ struct pipe_resource *_resource)
+{
+   struct rbug_screen *rb_screen = rbug_screen(_screen);
+   struct rbug_resource *rb_resource = rbug_resource(_resource);
+   struct pipe_screen *screen = rb_screen->screen;
+   struct pipe_resource *resource = rb_resource->resource;
 
+   screen->resource_changed(screen, resource);
+}
 
 static void
 rbug_screen_resource_destroy(struct pipe_screen *screen,
@@ -267,6 +277,9 @@ rbug_screen_create(struct pipe_screen *screen)
make_empty_list(&rb_screen->surfaces);
make_empty_list(&rb_screen->transfers);
 
+#define SCR_INIT(_member) \
+   rb_screen->base._member = screen->_member ? rbug_screen_##_member : NULL
+
rb_screen->base.destroy = rbug_screen_destroy;
rb_screen->base.get_name = rbug_screen_get_name;
rb_screen->base.get_vendor = rbug_screen_get_vendor;
@@ -279,6 +292,7 @@ rbug_screen_create(struct pipe_screen *screen)
rb_screen->base.resource_create = rbug_screen_resource_create;
rb_screen->base.resource_from_handle = rbug_screen_resource_from_handle;
rb_screen->base.resource_get_handle = rbug_screen_resource_get_handle;
+   SCR_INIT(resource_changed);
rb_screen->base.resource_destroy = rbug_screen_resource_destroy;
rb_screen->base.flush_frontbuffer = rbug_screen_flush_frontbuffer;
rb_screen->base.fence_reference = rbug_screen_fence_reference;
diff --git a/src/gallium/drivers/trace/tr_screen.c 
b/src/gallium/drivers/trace/tr_screen.c
index 493725c..aaf2e26 100644
--- a/src/gallium/drivers/trace/tr_screen.c
+++ b/src/gallium/drivers/trace/tr_screen.c
@@ -350,7 +350,26 @@ trace_screen_resource_get_handle(struct pipe_screen 
*_screen,
   resource, handle, usage);
 }
 
+static void
+trace_screen_resource_changed(struct pipe_screen *_screen,
+  struct pipe_resource *_resource)
+{
+   struct trace_screen *tr_scr = trace_screen(_screen);
+   struct trace_resource *tr_res = trace_resource(_resource);
+   struct pipe_screen *screen = tr_scr->screen;
+   struct pipe_resource *resource = tr_res->resource;
+
+   assert(resource->screen == screen);
 
+   trace_dump_call_begin("pipe_screen", "resource_changed");
+
+   trace_dump_arg(ptr, screen);
+   trace_dump_arg(ptr, resource);
+
+   screen->resource_changed(screen, resource);
+
+   trace_dump_call_end();
+}
 
 static void
 trace_screen_resource_destroy(struct pipe_screen *_screen,
@@ -499,6 +518,9 @@ trace_screen_create(struct pipe_screen *screen)
if (!tr_scr)
   goto error2;
 
+#define SCR_INIT(_member) \
+   tr_scr->base._member = screen->_member ? trace_screen_##_member : NULL
+
tr_scr->base.destroy = trace_screen_d

[Mesa-dev] [PATCH v5 2/7] st/dri: ask the driver to update its internal copies on reimport

2017-01-19 Thread Philipp Zabel
For imported buffers that can't be used directly as a source to the
texture samplers, the pipe driver might need to create an internal
copy, for example in a different tiling layout. When buffers are
reimported they may contain new image data, so the driver internal
copies need to be recreated.

Signed-off-by: Philipp Zabel 
---
 src/gallium/state_trackers/dri/dri2.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/gallium/state_trackers/dri/dri2.c 
b/src/gallium/state_trackers/dri/dri2.c
index 77523e9..c4f2c57 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -1168,6 +1168,10 @@ dri2_from_planar(__DRIimage *image, int plane, void 
*loaderPrivate)
if (img == NULL)
   return NULL;
 
+   if (img->texture->screen->resource_changed)
+  img->texture->screen->resource_changed(img->texture->screen,
+ img->texture);
+
/* set this to 0 for sub images. */
img->dri_components = 0;
return img;
-- 
2.1.4

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


[Mesa-dev] [PATCH v5 3/7] etnaviv: initialize seqno of imported resources

2017-01-19 Thread Philipp Zabel
Imported resources already have contents that we want to be copied to
texture resources derived from them. Set initial seqno of imported
resources to 1, just as if it had already been rendered to.

Signed-off-by: Philipp Zabel 
Reviewed-by: Christian Gmeiner 
---
 src/gallium/drivers/etnaviv/etnaviv_resource.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c 
b/src/gallium/drivers/etnaviv/etnaviv_resource.c
index aefe65b..a8858c5 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_resource.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c
@@ -325,6 +325,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen,
if (!rsc->bo)
   goto fail;
 
+   rsc->seqno = 1;
+
level->width = tmpl->width0;
level->height = tmpl->height0;
 
-- 
2.1.4

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


[Mesa-dev] [PATCH v5 5/7] mesa: update external textures when (re-)binding

2017-01-19 Thread Philipp Zabel
To comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called,
do not bail out early from mesa_BindTextures if the target is
external.
This will later allow the state tracker to instruct the pipe driver
to invalidate internal resources derived from the external texture.

Signed-off-by: Philipp Zabel 
---
 src/mesa/main/texobj.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index e5b7070..25b959d 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -1619,9 +1619,10 @@ bind_texture(struct gl_context *ctx,
assert(targetIndex < NUM_TEXTURE_TARGETS);
 
/* Check if this texture is only used by this context and is already bound.
-* If so, just return.
+* If so, just return. For GL_OES_image_external, rebinding the texture
+* always must invalidate cached resources.
 */
-   {
+   if (targetIndex != TEXTURE_EXTERNAL_INDEX) {
   bool early_out;
   mtx_lock(&ctx->Shared->Mutex);
   early_out = ((ctx->Shared->RefCount == 1)
-- 
2.1.4

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


[Mesa-dev] [PATCH v5 6/7] st/mesa: ask pipe driver to recreate derived internal resources when (re-)binding external textures

2017-01-19 Thread Philipp Zabel
Use the resource_changed callback to invalidate internal resources
derived from external textures when they are (re-)bound. This is needed
to comply with the requirement from the GL_OES_EGL_image_external
extension that a call to glBindTexture guarantees that all further
sampling will return values that correspond to the values in the
external texture at or after the time that glBindTexture was called.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_atom_texture.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/mesa/state_tracker/st_atom_texture.c 
b/src/mesa/state_tracker/st_atom_texture.c
index 76e512f..92023e0 100644
--- a/src/mesa/state_tracker/st_atom_texture.c
+++ b/src/mesa/state_tracker/st_atom_texture.c
@@ -91,6 +91,10 @@ update_single_texture(struct st_context *st,
   stObj->prev_sRGBDecode = samp->sRGBDecode;
}
 
+   if (texObj->TargetIndex == TEXTURE_EXTERNAL_INDEX &&
+   stObj->pt->screen->resource_changed)
+ stObj->pt->screen->resource_changed(stObj->pt->screen, stObj->pt);
+
*sampler_view =
   st_get_texture_sampler_view_from_stobj(st, stObj, samp, glsl_version);
return GL_TRUE;
-- 
2.1.4

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


[Mesa-dev] [PATCH 1/2] st/mesa: move st_manager_get_egl_image_surface into st_cb_eglimage.c

2017-03-27 Thread Philipp Zabel
The only callers are here, and we will add generation of GL errors in
the following patch.  Rename the function to st_egl_image_get_surface,
pass the gl_context instead of st_context, and move the cast from
GLeglImageOES to void* into st_egl_image_get_surface.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_cb_eglimage.c | 38 +
 src/mesa/state_tracker/st_manager.c | 30 --
 src/mesa/state_tracker/st_manager.h |  3 ---
 3 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index c425154ba9..e1fc9bff75 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -36,9 +36,41 @@
 #include "st_format.h"
 #include "st_manager.h"
 #include "st_sampler_view.h"
+#include "util/u_surface.h"
 
 
 /**
+ * Return the surface of an EGLImage.
+ * FIXME: I think this should operate on resources, not surfaces
+ */
+static struct pipe_surface *
+st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_manager *smapi =
+  (struct st_manager *) st->iface.st_context_private;
+   struct st_egl_image stimg;
+   struct pipe_surface *ps, surf_tmpl;
+
+   if (!smapi || !smapi->get_egl_image)
+  return NULL;
+
+   memset(&stimg, 0, sizeof(stimg));
+   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg))
+  return NULL;
+
+   u_surface_default_template(&surf_tmpl, stimg.texture);
+   surf_tmpl.format = stimg.format;
+   surf_tmpl.u.tex.level = stimg.level;
+   surf_tmpl.u.tex.first_layer = stimg.layer;
+   surf_tmpl.u.tex.last_layer = stimg.layer;
+   ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
+   pipe_resource_reference(&stimg.texture, NULL);
+
+   return ps;
+}
+
+/**
  * Return the base format just like _mesa_base_fbo_format does.
  */
 static GLenum
@@ -73,11 +105,10 @@ st_egl_image_target_renderbuffer_storage(struct gl_context 
*ctx,
 struct gl_renderbuffer *rb,
 GLeglImageOES image_handle)
 {
-   struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_surface *ps;
 
-   ps = st_manager_get_egl_image_surface(st, (void *) image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle);
if (ps) {
   strb->Base.Width = ps->width;
   strb->Base.Height = ps->height;
@@ -159,10 +190,9 @@ st_egl_image_target_texture_2d(struct gl_context *ctx, 
GLenum target,
   struct gl_texture_image *texImage,
   GLeglImageOES image_handle)
 {
-   struct st_context *st = st_context(ctx);
struct pipe_surface *ps;
 
-   ps = st_manager_get_egl_image_surface(st, (void *) image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle);
if (ps) {
   st_bind_surface(ctx, target, texObj, texImage, ps);
   pipe_surface_reference(&ps, NULL);
diff --git a/src/mesa/state_tracker/st_manager.c 
b/src/mesa/state_tracker/st_manager.c
index dad408a451..57c0ec4f86 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -858,36 +858,6 @@ st_manager_flush_frontbuffer(struct st_context *st)
 }
 
 /**
- * Return the surface of an EGLImage.
- * FIXME: I think this should operate on resources, not surfaces
- */
-struct pipe_surface *
-st_manager_get_egl_image_surface(struct st_context *st, void *eglimg)
-{
-   struct st_manager *smapi =
-  (struct st_manager *) st->iface.st_context_private;
-   struct st_egl_image stimg;
-   struct pipe_surface *ps, surf_tmpl;
-
-   if (!smapi || !smapi->get_egl_image)
-  return NULL;
-
-   memset(&stimg, 0, sizeof(stimg));
-   if (!smapi->get_egl_image(smapi, eglimg, &stimg))
-  return NULL;
-
-   u_surface_default_template(&surf_tmpl, stimg.texture);
-   surf_tmpl.format = stimg.format;
-   surf_tmpl.u.tex.level = stimg.level;
-   surf_tmpl.u.tex.first_layer = stimg.layer;
-   surf_tmpl.u.tex.last_layer = stimg.layer;
-   ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
-   pipe_resource_reference(&stimg.texture, NULL);
-
-   return ps;
-}
-
-/**
  * Re-validate the framebuffers.
  */
 void
diff --git a/src/mesa/state_tracker/st_manager.h 
b/src/mesa/state_tracker/st_manager.h
index bbb9b0f64d..65874b0040 100644
--- a/src/mesa/state_tracker/st_manager.h
+++ b/src/mesa/state_tracker/st_manager.h
@@ -34,9 +34,6 @@
 
 struct st_context;
 
-struct pipe_surface *
-st_manager_get_egl_image_surface(struct st_context *st, void *eglimg);
-
 void
 st_manager_flush_frontbuffer(struct st_context *st);
 
-- 
2.11.0

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


[Mesa-dev] [PATCH 2/2] st/mesa: EGLImageTarget* error handling

2017-03-27 Thread Philipp Zabel
Stop trying to specify texture or renderbuffer objects for unsupported
EGL images. Generate the error codes specified in the OES_EGL_image
extension.

EGLImageTargetTexture2D and EGLImageTargetRenderbuffer would call
the pipe driver's create_surface callback without ever checking that
the given EGL image is actually compatible with the chosen target
texture or renderbuffer. This patch adds a call to the pipe driver's
is_format_supported callback and generates an INVALID_OPERATION error
for unsupported EGL images. If the EGL image handle does not describe
a valid EGL image, an INVALID_VALUE error is generated.

Signed-off-by: Philipp Zabel 
---
 src/mesa/state_tracker/st_cb_eglimage.c | 24 
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index e1fc9bff75..30b177731e 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -25,6 +25,7 @@
  *Chia-I Wu 
  */
 
+#include "main/errors.h"
 #include "main/texobj.h"
 #include "main/teximage.h"
 #include "util/u_inlines.h"
@@ -44,9 +45,11 @@
  * FIXME: I think this should operate on resources, not surfaces
  */
 static struct pipe_surface *
-st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle)
+st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle,
+ unsigned usage, const char *error)
 {
struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
struct st_manager *smapi =
   (struct st_manager *) st->iface.st_context_private;
struct st_egl_image stimg;
@@ -56,8 +59,19 @@ st_egl_image_get_surface(struct gl_context *ctx, 
GLeglImageOES image_handle)
   return NULL;
 
memset(&stimg, 0, sizeof(stimg));
-   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg))
+   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg)) {
+  /* image_handle does not refer to a valid EGL image object */
+  _mesa_error(ctx, GL_INVALID_VALUE, error);
   return NULL;
+   }
+
+   if (!screen->is_format_supported(screen, stimg.format, PIPE_TEXTURE_2D,
+stimg.texture->nr_samples,
+PIPE_BIND_RENDER_TARGET)) {
+  /* unable to specify a texture object using the specified EGL image */
+  _mesa_error(ctx, GL_INVALID_OPERATION, 
"glEGLImageTargetRenderbufferStorage");
+  return NULL;
+   }
 
u_surface_default_template(&surf_tmpl, stimg.texture);
surf_tmpl.format = stimg.format;
@@ -108,7 +122,8 @@ st_egl_image_target_renderbuffer_storage(struct gl_context 
*ctx,
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_surface *ps;
 
-   ps = st_egl_image_get_surface(ctx, image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_RENDER_TARGET,
+"glEGLImageTargetRenderbufferStorage");
if (ps) {
   strb->Base.Width = ps->width;
   strb->Base.Height = ps->height;
@@ -192,7 +207,8 @@ st_egl_image_target_texture_2d(struct gl_context *ctx, 
GLenum target,
 {
struct pipe_surface *ps;
 
-   ps = st_egl_image_get_surface(ctx, image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW,
+"glEGLImageTargetTexture2D");
if (ps) {
   st_bind_surface(ctx, target, texObj, texImage, ps);
   pipe_surface_reference(&ps, NULL);
-- 
2.11.0

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


[Mesa-dev] [PATCH v2 2/2] st/mesa: EGLImageTarget* error handling

2017-03-29 Thread Philipp Zabel
Stop trying to specify texture or renderbuffer objects for unsupported
EGL images. Generate the error codes specified in the OES_EGL_image
extension.

EGLImageTargetTexture2D and EGLImageTargetRenderbuffer would call
the pipe driver's create_surface callback without ever checking that
the given EGL image is actually compatible with the chosen target
texture or renderbuffer. This patch adds a call to the pipe driver's
is_format_supported callback and generates an INVALID_OPERATION error
for unsupported EGL images. If the EGL image handle does not describe
a valid EGL image, an INVALID_VALUE error is generated.

Signed-off-by: Philipp Zabel 
Reviewed-by: Nicolai Hähnle 
---
v2: fixed get_surface to actually use the usage and error parameters
---
 src/mesa/state_tracker/st_cb_eglimage.c | 23 +++
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index e1fc9bff75..158a824e59 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -25,6 +25,7 @@
  *Chia-I Wu 
  */
 
+#include "main/errors.h"
 #include "main/texobj.h"
 #include "main/teximage.h"
 #include "util/u_inlines.h"
@@ -44,9 +45,11 @@
  * FIXME: I think this should operate on resources, not surfaces
  */
 static struct pipe_surface *
-st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle)
+st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle,
+ unsigned usage, const char *error)
 {
struct st_context *st = st_context(ctx);
+   struct pipe_screen *screen = st->pipe->screen;
struct st_manager *smapi =
   (struct st_manager *) st->iface.st_context_private;
struct st_egl_image stimg;
@@ -56,8 +59,18 @@ st_egl_image_get_surface(struct gl_context *ctx, 
GLeglImageOES image_handle)
   return NULL;
 
memset(&stimg, 0, sizeof(stimg));
-   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg))
+   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg)) {
+  /* image_handle does not refer to a valid EGL image object */
+  _mesa_error(ctx, GL_INVALID_VALUE, error);
   return NULL;
+   }
+
+   if (!screen->is_format_supported(screen, stimg.format, PIPE_TEXTURE_2D,
+stimg.texture->nr_samples, usage)) {
+  /* unable to specify a texture object using the specified EGL image */
+  _mesa_error(ctx, GL_INVALID_OPERATION, error);
+  return NULL;
+   }
 
u_surface_default_template(&surf_tmpl, stimg.texture);
surf_tmpl.format = stimg.format;
@@ -108,7 +121,8 @@ st_egl_image_target_renderbuffer_storage(struct gl_context 
*ctx,
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_surface *ps;
 
-   ps = st_egl_image_get_surface(ctx, image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_RENDER_TARGET,
+"glEGLImageTargetRenderbufferStorage");
if (ps) {
   strb->Base.Width = ps->width;
   strb->Base.Height = ps->height;
@@ -192,7 +206,8 @@ st_egl_image_target_texture_2d(struct gl_context *ctx, 
GLenum target,
 {
struct pipe_surface *ps;
 
-   ps = st_egl_image_get_surface(ctx, image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle, PIPE_BIND_SAMPLER_VIEW,
+"glEGLImageTargetTexture2D");
if (ps) {
   st_bind_surface(ctx, target, texObj, texImage, ps);
   pipe_surface_reference(&ps, NULL);
-- 
2.11.0

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


[Mesa-dev] [PATCH v2 1/2] st/mesa: move st_manager_get_egl_image_surface into st_cb_eglimage.c

2017-03-29 Thread Philipp Zabel
The only callers are here, and we will add generation of GL errors in
the following patch.  Rename the function to st_egl_image_get_surface,
pass the gl_context instead of st_context, and move the cast from
GLeglImageOES to void* into st_egl_image_get_surface.

Signed-off-by: Philipp Zabel 
Reviewed-by: Nicolai Hähnle 
---
 src/mesa/state_tracker/st_cb_eglimage.c | 38 +
 src/mesa/state_tracker/st_manager.c | 30 --
 src/mesa/state_tracker/st_manager.h |  3 ---
 3 files changed, 34 insertions(+), 37 deletions(-)

diff --git a/src/mesa/state_tracker/st_cb_eglimage.c 
b/src/mesa/state_tracker/st_cb_eglimage.c
index c425154ba9..e1fc9bff75 100644
--- a/src/mesa/state_tracker/st_cb_eglimage.c
+++ b/src/mesa/state_tracker/st_cb_eglimage.c
@@ -36,9 +36,41 @@
 #include "st_format.h"
 #include "st_manager.h"
 #include "st_sampler_view.h"
+#include "util/u_surface.h"
 
 
 /**
+ * Return the surface of an EGLImage.
+ * FIXME: I think this should operate on resources, not surfaces
+ */
+static struct pipe_surface *
+st_egl_image_get_surface(struct gl_context *ctx, GLeglImageOES image_handle)
+{
+   struct st_context *st = st_context(ctx);
+   struct st_manager *smapi =
+  (struct st_manager *) st->iface.st_context_private;
+   struct st_egl_image stimg;
+   struct pipe_surface *ps, surf_tmpl;
+
+   if (!smapi || !smapi->get_egl_image)
+  return NULL;
+
+   memset(&stimg, 0, sizeof(stimg));
+   if (!smapi->get_egl_image(smapi, (void *) image_handle, &stimg))
+  return NULL;
+
+   u_surface_default_template(&surf_tmpl, stimg.texture);
+   surf_tmpl.format = stimg.format;
+   surf_tmpl.u.tex.level = stimg.level;
+   surf_tmpl.u.tex.first_layer = stimg.layer;
+   surf_tmpl.u.tex.last_layer = stimg.layer;
+   ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
+   pipe_resource_reference(&stimg.texture, NULL);
+
+   return ps;
+}
+
+/**
  * Return the base format just like _mesa_base_fbo_format does.
  */
 static GLenum
@@ -73,11 +105,10 @@ st_egl_image_target_renderbuffer_storage(struct gl_context 
*ctx,
 struct gl_renderbuffer *rb,
 GLeglImageOES image_handle)
 {
-   struct st_context *st = st_context(ctx);
struct st_renderbuffer *strb = st_renderbuffer(rb);
struct pipe_surface *ps;
 
-   ps = st_manager_get_egl_image_surface(st, (void *) image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle);
if (ps) {
   strb->Base.Width = ps->width;
   strb->Base.Height = ps->height;
@@ -159,10 +190,9 @@ st_egl_image_target_texture_2d(struct gl_context *ctx, 
GLenum target,
   struct gl_texture_image *texImage,
   GLeglImageOES image_handle)
 {
-   struct st_context *st = st_context(ctx);
struct pipe_surface *ps;
 
-   ps = st_manager_get_egl_image_surface(st, (void *) image_handle);
+   ps = st_egl_image_get_surface(ctx, image_handle);
if (ps) {
   st_bind_surface(ctx, target, texObj, texImage, ps);
   pipe_surface_reference(&ps, NULL);
diff --git a/src/mesa/state_tracker/st_manager.c 
b/src/mesa/state_tracker/st_manager.c
index dad408a451..57c0ec4f86 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -858,36 +858,6 @@ st_manager_flush_frontbuffer(struct st_context *st)
 }
 
 /**
- * Return the surface of an EGLImage.
- * FIXME: I think this should operate on resources, not surfaces
- */
-struct pipe_surface *
-st_manager_get_egl_image_surface(struct st_context *st, void *eglimg)
-{
-   struct st_manager *smapi =
-  (struct st_manager *) st->iface.st_context_private;
-   struct st_egl_image stimg;
-   struct pipe_surface *ps, surf_tmpl;
-
-   if (!smapi || !smapi->get_egl_image)
-  return NULL;
-
-   memset(&stimg, 0, sizeof(stimg));
-   if (!smapi->get_egl_image(smapi, eglimg, &stimg))
-  return NULL;
-
-   u_surface_default_template(&surf_tmpl, stimg.texture);
-   surf_tmpl.format = stimg.format;
-   surf_tmpl.u.tex.level = stimg.level;
-   surf_tmpl.u.tex.first_layer = stimg.layer;
-   surf_tmpl.u.tex.last_layer = stimg.layer;
-   ps = st->pipe->create_surface(st->pipe, stimg.texture, &surf_tmpl);
-   pipe_resource_reference(&stimg.texture, NULL);
-
-   return ps;
-}
-
-/**
  * Re-validate the framebuffers.
  */
 void
diff --git a/src/mesa/state_tracker/st_manager.h 
b/src/mesa/state_tracker/st_manager.h
index bbb9b0f64d..65874b0040 100644
--- a/src/mesa/state_tracker/st_manager.h
+++ b/src/mesa/state_tracker/st_manager.h
@@ -34,9 +34,6 @@
 
 struct st_context;
 
-struct pipe_surface *
-st_manager_get_egl_image_surface(struct st_context *st, void *eglimg);
-
 void
 st_manager_flush_frontbuffer(struct st_context *st);
 
-- 
2.11.0

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


Re: [Mesa-dev] [PATCH v2 2/2] st/mesa: EGLImageTarget* error handling

2017-03-29 Thread Philipp Zabel
On Wed, 2017-03-29 at 13:01 +0200, Nicolai Hähnle wrote:
> On 29.03.2017 09:44, Philipp Zabel wrote:
> > Stop trying to specify texture or renderbuffer objects for unsupported
> > EGL images. Generate the error codes specified in the OES_EGL_image
> > extension.
> >
> > EGLImageTargetTexture2D and EGLImageTargetRenderbuffer would call
> > the pipe driver's create_surface callback without ever checking that
> > the given EGL image is actually compatible with the chosen target
> > texture or renderbuffer. This patch adds a call to the pipe driver's
> > is_format_supported callback and generates an INVALID_OPERATION error
> > for unsupported EGL images. If the EGL image handle does not describe
> > a valid EGL image, an INVALID_VALUE error is generated.
> >
> > Signed-off-by: Philipp Zabel 
> > Reviewed-by: Nicolai Hähnle 
> > ---
> > v2: fixed get_surface to actually use the usage and error parameters
> 
> The v2 usually goes above :)

Ok, I'll remember that next time.

> Do you need someone to commit this for you?

Yes, please.

regards
Philipp

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


[Mesa-dev] [RFC] etnaviv: native fence fd support

2017-04-05 Thread Philipp Zabel
This adds native fence fd support to etnaviv, similarly to commit
0b98e84e9ba0 ("freedreno: native fence fd"), enabled for kernel
driver version 1.1 or later.

Signed-off-by: Philipp Zabel 
---
This depends on libdrm patches [1][2] which may or may not make their
way into libdrm 2.4.78.
[1] https://patchwork.kernel.org/patch/9664401/
[2] https://patchwork.kernel.org/patch/9664403/
---
 configure.ac  |  2 +-
 src/gallium/drivers/etnaviv/etnaviv_context.c | 17 --
 src/gallium/drivers/etnaviv/etnaviv_context.h |  1 +
 src/gallium/drivers/etnaviv/etnaviv_fence.c   | 46 +--
 src/gallium/drivers/etnaviv/etnaviv_fence.h   | 14 +++-
 src/gallium/drivers/etnaviv/etnaviv_screen.c  | 10 +-
 src/gallium/drivers/etnaviv/etnaviv_screen.h  |  3 ++
 7 files changed, 86 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1c60a59823..a5e1d69912 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,7 +80,7 @@ LIBDRM_NVVIEUX_REQUIRED=2.4.66
 LIBDRM_NOUVEAU_REQUIRED=2.4.66
 LIBDRM_FREEDRENO_REQUIRED=2.4.74
 LIBDRM_VC4_REQUIRED=2.4.69
-LIBDRM_ETNAVIV_REQUIRED=2.4.74
+LIBDRM_ETNAVIV_REQUIRED=2.4.78
 
 dnl Versions for external dependencies
 DRI2PROTO_REQUIRED=2.8
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c 
b/src/gallium/drivers/etnaviv/etnaviv_context.c
index dfd9e1f73a..14170342ff 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
@@ -73,6 +73,9 @@ etna_context_destroy(struct pipe_context *pctx)
 
slab_destroy_child(&ctx->transfer_pool);
 
+   if (ctx->in_fence_fd != -1)
+  close(ctx->in_fence_fd);
+
FREE(pctx);
 }
 
@@ -230,11 +233,17 @@ etna_flush(struct pipe_context *pctx, struct 
pipe_fence_handle **fence,
enum pipe_flush_flags flags)
 {
struct etna_context *ctx = etna_context(pctx);
+   int out_fence_fd = -1;
 
-   etna_cmd_stream_flush(ctx->stream);
+   if (ctx->in_fence_fd != -1 || (flags & PIPE_FLUSH_FENCE_FD))
+  etna_cmd_stream_flush_explicit(ctx->stream, ctx->in_fence_fd,
+ (flags & PIPE_FLUSH_FENCE_FD) ?
+ &out_fence_fd : NULL);
+   else
+  etna_cmd_stream_flush(ctx->stream);
 
if (fence)
-  *fence = etna_fence_create(pctx);
+  *fence = etna_fence_create(pctx, out_fence_fd);
 }
 
 static void
@@ -308,10 +317,14 @@ etna_context_create(struct pipe_screen *pscreen, void 
*priv, unsigned flags)
/*  Set sensible defaults for state */
etna_cmd_stream_reset_notify(ctx->stream, ctx);
 
+   ctx->in_fence_fd = -1;
+
pctx->destroy = etna_context_destroy;
pctx->draw_vbo = etna_draw_vbo;
pctx->flush = etna_flush;
pctx->set_debug_callback = etna_set_debug_callback;
+   pctx->create_fence_fd = etna_create_fence_fd;
+   pctx->fence_server_sync = etna_fence_server_sync;
 
/* creation of compile states */
pctx->create_blend_state = etna_blend_state_create;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h 
b/src/gallium/drivers/etnaviv/etnaviv_context.h
index a9214034af..700a39c4cb 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -176,6 +176,7 @@ struct etna_context {
} stats;
 
struct pipe_debug_callback debug;
+   int in_fence_fd;
 };
 
 static inline struct etna_context *
diff --git a/src/gallium/drivers/etnaviv/etnaviv_fence.c 
b/src/gallium/drivers/etnaviv/etnaviv_fence.c
index 02f520b8b3..ff46e32863 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_fence.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_fence.c
@@ -25,6 +25,8 @@
  *Rob Clark 
  */
 
+#include 
+
 #include "etnaviv_fence.h"
 #include "etnaviv_context.h"
 #include "etnaviv_screen.h"
@@ -36,16 +38,25 @@ struct pipe_fence_handle {
struct pipe_reference reference;
struct etna_context *ctx;
struct etna_screen *screen;
+   int fence_fd;
uint32_t timestamp;
 };
 
 static void
+etna_fence_destroy(struct pipe_fence_handle *fence)
+{
+   if (fence->fence_fd != -1)
+  close(fence->fence_fd);
+   FREE(fence);
+}
+
+static void
 etna_screen_fence_reference(struct pipe_screen *pscreen,
 struct pipe_fence_handle **ptr,
 struct pipe_fence_handle *fence)
 {
if (pipe_reference(&(*ptr)->reference, &fence->reference))
-  FREE(*ptr);
+  etna_fence_destroy(*ptr);
 
*ptr = fence;
 }
@@ -54,14 +65,43 @@ static boolean
 etna_screen_fence_finish(struct pipe_screen *pscreen, struct pipe_context *ctx,
  struct pipe_fence_handle *fence, uint64_t timeout)
 {
+   if (fence->fence_fd != -1) {
+  int ret = sync_wait(fence->fence_fd, timeout / 100);
+  return ret == 0;
+   }
+
if (etna_pipe_wait_ns(fence->scre

Re: [Mesa-dev] [RFC] etnaviv: native fence fd support

2017-04-06 Thread Philipp Zabel
On Wed, 2017-04-05 at 13:12 -0400, Rob Clark wrote:
> On Wed, Apr 5, 2017 at 12:14 PM, Philipp Zabel  wrote:
> > +void
> > +etna_fence_server_sync(struct pipe_context *pctx,
> > +   struct pipe_fence_handle *pfence)
> > +{
> > +   struct etna_context *ctx = etna_context(pctx);
> > +
> > +   /* FIXME: where should in_fence_fd be stored? */
> > +   sync_accumulate("etnaviv", &ctx->in_fence_fd, pfence->fence_fd);
> > +}
> > +
> 
> 
> fwiw, sync_accumulate() gives you back a new fence that is signalled
> when both the original in_fence_fd and the new fence_fd are signalled.
> So you shouldn't need to track the old in_fence_fd.

Thanks, I've seen that sync_accumulate closes the old in_fence_fd.
This comment was about being unsure whether struct etna_context is the
right place for in_fence_fd. I'll just drop it.

regards
Philipp


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


  1   2   >