[Mesa-dev] [PATCH 4/4] xa: reuse surfaces

Rob Clark robdclark at gmail.com
Tue Apr 1 08:04:30 PDT 2014


From: Rob Clark <robclark at freedesktop.org>

Otherwise it will trick the gallium driver into thinking that the render
target has actually changed (due to different pipe_surface pointing to
same underlying pipe_resource).  This is really badness for tiling GPUs
like adreno.

Signed-off-by: Rob Clark <robclark at freedesktop.org>
---
 src/gallium/state_trackers/xa/xa_context.c | 35 +++++++++++++++++++++++-------
 src/gallium/state_trackers/xa/xa_priv.h    |  3 ++-
 src/gallium/state_trackers/xa/xa_tracker.c |  1 +
 3 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/src/gallium/state_trackers/xa/xa_context.c b/src/gallium/state_trackers/xa/xa_context.c
index 867999a..18f0b85 100644
--- a/src/gallium/state_trackers/xa/xa_context.c
+++ b/src/gallium/state_trackers/xa/xa_context.c
@@ -179,6 +179,25 @@ xa_surface_unmap(struct xa_surface *srf)
     }
 }
 
+static int
+xa_srf_create(struct xa_context *ctx, struct xa_surface *srf)
+{
+    struct pipe_screen *screen = ctx->pipe->screen;
+    struct pipe_surface srf_templ;
+
+    if (!screen->is_format_supported(screen,  srf->tex->format,
+				     PIPE_TEXTURE_2D, 0,
+				     PIPE_BIND_RENDER_TARGET))
+	return -XA_ERR_INVAL;
+
+    u_surface_default_template(&srf_templ, srf->tex);
+    srf->srf = ctx->pipe->create_surface(ctx->pipe, srf->tex, &srf_templ);
+    if (!srf->srf)
+	return -XA_ERR_NORES;
+
+    return XA_ERR_NONE;
+}
+
 int
 xa_ctx_srf_create(struct xa_context *ctx, struct xa_surface *dst)
 {
@@ -188,15 +207,15 @@ xa_ctx_srf_create(struct xa_context *ctx, struct xa_surface *dst)
     if (ctx->srf)
 	return -XA_ERR_INVAL;
 
-    if (!screen->is_format_supported(screen,  dst->tex->format,
-				     PIPE_TEXTURE_2D, 0,
-				     PIPE_BIND_RENDER_TARGET))
-	return -XA_ERR_INVAL;
+    if (!dst->srf) {
+	int ret = xa_srf_create(ctx, dst);
+	if (ret != XA_ERR_NONE)
+	    return ret;
+    }
 
-    u_surface_default_template(&srf_templ, dst->tex);
-    ctx->srf = ctx->pipe->create_surface(ctx->pipe, dst->tex, &srf_templ);
-    if (!ctx->srf)
-	return -XA_ERR_NORES;
+    assert(dst->srf);
+
+    pipe_surface_reference(&ctx->srf, dst->srf);
 
     return XA_ERR_NONE;
 }
diff --git a/src/gallium/state_trackers/xa/xa_priv.h b/src/gallium/state_trackers/xa/xa_priv.h
index 7a43386..5ade6c1 100644
--- a/src/gallium/state_trackers/xa/xa_priv.h
+++ b/src/gallium/state_trackers/xa/xa_priv.h
@@ -46,7 +46,7 @@
 #define XA_EXPORT
 #endif
 
-#define XA_VB_SIZE (100 * 4 * 3 * 4)
+#define XA_VB_SIZE (170 * 4 * 3 * 4)
 #define XA_LAST_SURFACE_TYPE (xa_type_yuv_component + 1)
 #define XA_MAX_SAMPLERS 3
 
@@ -65,6 +65,7 @@ struct xa_surface {
     struct pipe_resource template;
     struct xa_tracker *xa;
     struct pipe_resource *tex;
+    struct pipe_surface *srf;
     struct pipe_transfer *transfer;
     unsigned int flags;
     struct xa_format_descriptor fdesc;
diff --git a/src/gallium/state_trackers/xa/xa_tracker.c b/src/gallium/state_trackers/xa/xa_tracker.c
index 9add584..7fed20a 100644
--- a/src/gallium/state_trackers/xa/xa_tracker.c
+++ b/src/gallium/state_trackers/xa/xa_tracker.c
@@ -474,6 +474,7 @@ xa_surface_unref(struct xa_surface *srf)
     if (srf == NULL || --srf->refcount) {
 	return;
     }
+    pipe_surface_reference(&srf->srf, NULL);
     pipe_resource_reference(&srf->tex, NULL);
     free(srf);
 }
-- 
1.8.5.3



More information about the mesa-dev mailing list