st/dri: do not create a new context for msaa copy
authorMaarten Lankhorst <maarten.lankhorst@canonical.com>
Mon, 9 Sep 2013 11:02:08 +0000 (13:02 +0200)
committerMaarten Lankhorst <maarten.lankhorst@canonical.com>
Wed, 11 Sep 2013 07:03:44 +0000 (09:03 +0200)
Commit b77316ad7594f
    st/dri: always copy new DRI front and back buffers to corresponding MSAA buffers

introduced creating a pipe_context for every call to validate, which is not required
because the callers have a context anyway.

Only exception is egl_g3d_create_pbuffer_from_client_buffer, can someone test if it
still works with NULL passed as context for validate? From examining the code I
believe it does, but I didn't thoroughly test it.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
Cc: 9.2 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
12 files changed:
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/common/dri_drawable.c
src/gallium/state_trackers/dri/common/dri_drawable.h
src/gallium/state_trackers/dri/drm/dri2.c
src/gallium/state_trackers/dri/sw/drisw.c
src/gallium/state_trackers/egl/common/egl_g3d_api.c
src/gallium/state_trackers/egl/common/egl_g3d_st.c
src/gallium/state_trackers/glx/xlib/xm_st.c
src/gallium/state_trackers/osmesa/osmesa.c
src/gallium/state_trackers/vega/vg_manager.c
src/gallium/state_trackers/wgl/stw_st.c
src/mesa/state_tracker/st_manager.c

index 3ecd12e91af1445e76d28863743d8e54aa0e3145..9dcb76fadec1177aad9bc754654a61bb9e5fb93f 100644 (file)
@@ -342,7 +342,8 @@ struct st_framebuffer_iface
     * the last call might be destroyed.  This behavior might change in the
     * future.
     */
-   boolean (*validate)(struct st_framebuffer_iface *stfbi,
+   boolean (*validate)(struct st_context_iface *stctx,
+                       struct st_framebuffer_iface *stfbi,
                        const enum st_attachment_type *statts,
                        unsigned count,
                        struct pipe_resource **out);
index 18d8d8988a965bb08f38c09bd054cbccaf82df71..ddf940048cfd6288dddf7ce04ec260476f48a94e 100644 (file)
@@ -42,11 +42,13 @@ static void
 swap_fences_unref(struct dri_drawable *draw);
 
 static boolean
-dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
+dri_st_framebuffer_validate(struct st_context_iface *stctx,
+                            struct st_framebuffer_iface *stfbi,
                             const enum st_attachment_type *statts,
                             unsigned count,
                             struct pipe_resource **out)
 {
+   struct dri_context *ctx = (struct dri_context *)stctx->st_manager_private;
    struct dri_drawable *drawable =
       (struct dri_drawable *) stfbi->st_manager_private;
    struct dri_screen *screen = dri_screen(drawable->sPriv);
@@ -78,7 +80,7 @@ dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
          if (new_stamp && drawable->update_drawable_info)
             drawable->update_drawable_info(drawable);
 
-         drawable->allocate_textures(drawable, statts, count);
+         drawable->allocate_textures(ctx, drawable, statts, count);
 
          /* add existing textures */
          for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
@@ -183,7 +185,8 @@ dri_destroy_buffer(__DRIdrawable * dPriv)
  * exist.  Used by the TFP extension.
  */
 static void
-dri_drawable_validate_att(struct dri_drawable *drawable,
+dri_drawable_validate_att(struct dri_context *ctx,
+                          struct dri_drawable *drawable,
                           enum st_attachment_type statt)
 {
    enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
@@ -203,7 +206,7 @@ dri_drawable_validate_att(struct dri_drawable *drawable,
 
    drawable->texture_stamp = drawable->dPriv->lastStamp - 1;
 
-   drawable->base.validate(&drawable->base, statts, count, NULL);
+   drawable->base.validate(ctx->st, &drawable->base, statts, count, NULL);
 }
 
 /**
@@ -217,7 +220,7 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
    struct dri_drawable *drawable = dri_drawable(dPriv);
    struct pipe_resource *pt;
 
-   dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
+   dri_drawable_validate_att(ctx, drawable, ST_ATTACHMENT_FRONT_LEFT);
 
    /* Use the pipe resource associated with the X drawable */
    pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
index 50e5cc4cd670b3408493d44e5c63135011fb8799..c5142181e896808d81f4652c7ec413b88d4feeec 100644 (file)
@@ -71,7 +71,8 @@ struct dri_drawable
    struct pipe_surface *drisw_surface;
 
    /* hooks filled in by dri2 & drisw */
-   void (*allocate_textures)(struct dri_drawable *drawable,
+   void (*allocate_textures)(struct dri_context *ctx,
+                             struct dri_drawable *drawable,
                              const enum st_attachment_type *statts,
                              unsigned count);
 
index e4477d6de77bbe77a54242836606221d9d45a9bb..fea1c8dfe52ef553d1ef35852167209727c4a328 100644 (file)
@@ -169,7 +169,8 @@ dri2_drawable_get_buffers(struct dri_drawable *drawable,
  * Process __DRIbuffer and convert them into pipe_resources.
  */
 static void
-dri2_drawable_process_buffers(struct dri_drawable *drawable,
+dri2_drawable_process_buffers(struct dri_context *ctx,
+                              struct dri_drawable *drawable,
                               __DRIbuffer *buffers, unsigned buffer_count,
                               const enum st_attachment_type *atts,
                               unsigned att_count)
@@ -180,8 +181,6 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
    struct winsys_handle whandle;
    boolean alloc_depthstencil = FALSE;
    unsigned i, j, bind;
-   struct pipe_screen *pscreen = screen->base.screen;
-   struct pipe_context *pipe = NULL;
 
    if (drawable->old_num == buffer_count &&
        drawable->old_w == dri_drawable->w &&
@@ -308,14 +307,8 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
                 * The single-sample resources are not exposed
                 * to the state tracker.
                 *
-                * We don't have a context here, so create one temporarily.
-                * We may need to create a persistent context if creation and
-                * destruction of the context becomes a bottleneck.
                 */
-               if (!pipe)
-                  pipe = pscreen->context_create(pscreen, NULL);
-
-               dri_pipe_blit(pipe,
+               dri_pipe_blit(ctx->st->pipe,
                              drawable->msaa_textures[att],
                              drawable->textures[att]);
             }
@@ -371,11 +364,6 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
    drawable->old_w = dri_drawable->w;
    drawable->old_h = dri_drawable->h;
    memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * buffer_count);
-
-   if (pipe) {
-      pipe->flush(pipe, NULL, 0);
-      pipe->destroy(pipe);
-   }
 }
 
 static __DRIbuffer *
@@ -470,7 +458,8 @@ dri2_release_buffer(__DRIscreen *sPriv, __DRIbuffer *bPriv)
  */
 
 static void
-dri2_allocate_textures(struct dri_drawable *drawable,
+dri2_allocate_textures(struct dri_context *ctx,
+                       struct dri_drawable *drawable,
                        const enum st_attachment_type *statts,
                        unsigned statts_count)
 {
@@ -479,7 +468,7 @@ dri2_allocate_textures(struct dri_drawable *drawable,
 
    buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
    if (buffers)
-      dri2_drawable_process_buffers(drawable, buffers, num_buffers,
+      dri2_drawable_process_buffers(ctx, drawable, buffers, num_buffers,
                                     statts, statts_count);
 }
 
index 41f66d5e4d47dc4b35628efeeda408b92aaa557e..121a2057a32b6aaecb7d43187a023104a802d455 100644 (file)
@@ -182,7 +182,8 @@ drisw_flush_frontbuffer(struct dri_context *ctx,
  * framebuffer is resized or destroyed.
  */
 static void
-drisw_allocate_textures(struct dri_drawable *drawable,
+drisw_allocate_textures(struct dri_context *stctx,
+                        struct dri_drawable *drawable,
                         const enum st_attachment_type *statts,
                         unsigned count)
 {
index 3ee0d677017c57bc1053aabb28a18ca4e0f6f8f2..46a3245246fb373c3ef67825865f59e4a6b0e5af 100644 (file)
@@ -443,7 +443,7 @@ egl_g3d_create_pbuffer_from_client_buffer(_EGLDriver *drv, _EGLDisplay *dpy,
    gsurf->client_buffer = buffer;
 
    /* validate now so that it fails if the client buffer is invalid */
-   if (!gsurf->stfbi->validate(gsurf->stfbi,
+   if (!gsurf->stfbi->validate(NULL, gsurf->stfbi,
             &gsurf->stvis.render_buffer, 1, &ptex)) {
       egl_g3d_destroy_st_framebuffer(gsurf->stfbi);
       FREE(gsurf);
index f2ee11c8e01c28198e1c5a5054db2b6a1f52d586..cf1846c74b79fbe44aa00239c93f6c5d5df84fd2 100644 (file)
@@ -149,7 +149,8 @@ pbuffer_allocate_pbuffer_texture(struct egl_g3d_surface *gsurf)
 }
 
 static boolean
-egl_g3d_st_framebuffer_validate_pbuffer(struct st_framebuffer_iface *stfbi,
+egl_g3d_st_framebuffer_validate_pbuffer(struct st_context_iface *stctx,
+                                        struct st_framebuffer_iface *stfbi,
                                         const enum st_attachment_type *statts,
                                         unsigned count,
                                         struct pipe_resource **out)
@@ -202,7 +203,8 @@ egl_g3d_st_framebuffer_flush_front(struct st_context_iface *stctx,
 }
 
 static boolean 
-egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
+egl_g3d_st_framebuffer_validate(struct st_context_iface *stctx,
+                                struct st_framebuffer_iface *stfbi,
                                 const enum st_attachment_type *statts,
                                 unsigned count,
                                 struct pipe_resource **out)
index 30e69eafc178174625fac432def4022e92d17187..fb6999826a9c235af208f10de4de25625f456450 100644 (file)
@@ -194,7 +194,8 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
  * \param out  returns resources for each of the attachments
  */
 static boolean
-xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
+xmesa_st_framebuffer_validate(struct st_context_iface *stctx,
+                              struct st_framebuffer_iface *stfbi,
                               const enum st_attachment_type *statts,
                               unsigned count,
                               struct pipe_resource **out)
index bb85e5c2f0c11135ca9da0fd1962a19a8cdc2c47..3546183a81b7c4b6ca24ae43d3cceb1a1cff170c 100644 (file)
@@ -342,7 +342,8 @@ osmesa_st_framebuffer_flush_front(struct st_context_iface *stctx,
  * its resources).
  */
 static boolean
-osmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
+osmesa_st_framebuffer_validate(struct st_context_iface *stctx,
+                               struct st_framebuffer_iface *stfbi,
                                const enum st_attachment_type *statts,
                                unsigned count,
                                struct pipe_resource **out)
index c079d90359c0d39f9683a1de65ca02dcde99d02b..2c43d763dea47cf67f49f906b18c5c9ad5ce56f7 100644 (file)
@@ -113,7 +113,8 @@ vg_manager_validate_framebuffer(struct vg_context *ctx)
    if (stfb->iface_stamp != new_stamp) {
       do {
         /* validate the fb */
-        if (!stfb->iface->validate(stfb->iface, &stfb->strb_att,
+        if (!stfb->iface->validate((struct st_context_iface *)ctx,
+                                   stfb->iface, &stfb->strb_att,
                                    1, &pt) || !pt)
            return;
 
index 9427398d89d072a0dcf320e3c066bf23dae8f744..e95c37fcecd15e1f5c2f2f83053cc163861782ec 100644 (file)
@@ -121,7 +121,8 @@ stw_st_framebuffer_validate_locked(struct st_framebuffer_iface *stfb,
 }
 
 static boolean 
-stw_st_framebuffer_validate(struct st_framebuffer_iface *stfb,
+stw_st_framebuffer_validate(struct st_context_iface *stctx,
+                            struct st_framebuffer_iface *stfb,
                             const enum st_attachment_type *statts,
                             unsigned count,
                             struct pipe_resource **out)
index 098e6c02c76bbd59968339613131fd93f9087f03..b1fd91a0ebf0ac0f02fa4f915615f796fda4b377 100644 (file)
@@ -189,7 +189,7 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
 
    /* validate the fb */
    do {
-      if (!stfb->iface->validate(stfb->iface, stfb->statts,
+      if (!stfb->iface->validate(&st->iface, stfb->iface, stfb->statts,
                                 stfb->num_statts, textures))
         return;