svga: Remove the screen private context.
authorJosé Fonseca <jfonseca@vmware.com>
Sun, 2 May 2010 22:54:42 +0000 (23:54 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sun, 2 May 2010 23:13:36 +0000 (00:13 +0100)
All affected operations have already been moved to context.

More cleanup work can be done, in particular with the buffer transfers.

src/gallium/drivers/svga/svga_context.c
src/gallium/drivers/svga/svga_pipe_query.c
src/gallium/drivers/svga/svga_resource_buffer.c
src/gallium/drivers/svga/svga_resource_buffer.h
src/gallium/drivers/svga/svga_resource_buffer_upload.c
src/gallium/drivers/svga/svga_resource_texture.c
src/gallium/drivers/svga/svga_sampler_view.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/svga/svga_screen.h
src/gallium/drivers/svga/svga_surface.c
src/gallium/drivers/svga/svga_surface.h

index 3228a6d3d7fe7d8c265c2af5c437eb47d767d1aa..75d8afb2ea8a9beca2d475fca0444b27b60d698f 100644 (file)
@@ -194,6 +194,7 @@ void svga_context_flush( struct svga_context *svga,
                          struct pipe_fence_handle **pfence )
 {
    struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
+   struct pipe_fence_handle *fence = NULL;
 
    svga->curr.nr_fbs = 0;
 
@@ -202,21 +203,26 @@ void svga_context_flush( struct svga_context *svga,
    u_upload_flush(svga->upload_vb);
    u_upload_flush(svga->upload_ib);
 
-   /* Flush screen, to ensure that texture dma uploads are processed
+   /* Ensure that texture dma uploads are processed
     * before submitting commands.
     */
-   svga_screen_flush(svgascreen, NULL);
-   
    svga_context_flush_buffers(svga);
 
    /* Flush pending commands to hardware:
     */
-   svga->swc->flush(svga->swc, pfence);
+   svga->swc->flush(svga->swc, &fence);
+
+   svga_screen_cache_flush(svgascreen, fence);
 
    if (SVGA_DEBUG & DEBUG_SYNC) {
-      if (pfence && *pfence)
-         svga->pipe.screen->fence_finish( svga->pipe.screen, *pfence, 0);
+      if (fence)
+         svga->pipe.screen->fence_finish( svga->pipe.screen, fence, 0);
    }
+
+   if(pfence)
+      *pfence = fence;
+   else
+      svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL);
 }
 
 
index 9c6f5858ba42a6940c3b621d8e1b6172dafc285b..96fb4b8e5368a07e425c41af72c00bf94e32e5be 100644 (file)
@@ -68,6 +68,7 @@ static boolean svga_get_query_result(struct pipe_context *pipe,
 static struct pipe_query *svga_create_query( struct pipe_context *pipe,
                                              unsigned query_type )
 {
+   struct svga_context *svga = svga_context( pipe );
    struct svga_screen *svgascreen = svga_screen(pipe->screen);
    struct svga_winsys_screen *sws = svgascreen->sws;
    struct svga_query *sq;
@@ -80,7 +81,7 @@ static struct pipe_query *svga_create_query( struct pipe_context *pipe,
 
    sq->type = SVGA3D_QUERYTYPE_OCCLUSION;
 
-   sq->hwbuf = svga_winsys_buffer_create(svgascreen, 
+   sq->hwbuf = svga_winsys_buffer_create(svga,
                                          1,
                                          SVGA_BUFFER_USAGE_PINNED,
                                          sizeof *sq->queryResult);
index 18eeff9c67e71192235041d20d86998178e5aa0b..198d40133284158c18465621467e45e1bbdc16ec 100644 (file)
@@ -125,8 +125,6 @@ svga_buffer_map_range( struct pipe_screen *screen,
    }
 
    if(map) {
-      pipe_mutex_lock(ss->swc_mutex);
-
       ++sbuf->map.count;
 
       if (usage & PIPE_TRANSFER_WRITE) {
@@ -135,8 +133,6 @@ svga_buffer_map_range( struct pipe_screen *screen,
          if (usage & PIPE_TRANSFER_FLUSH_EXPLICIT)
             sbuf->map.flush_explicit = TRUE;
       }
-      
-      pipe_mutex_unlock(ss->swc_mutex);
    }
    
    return map;
index 55e7321184faf4972891c35dfe2f861b98818c2c..d3ec11bfd527af0bef7cc6678c8533b414b88ee3 100644 (file)
@@ -238,7 +238,7 @@ void
 svga_context_flush_buffers(struct svga_context *svga);
 
 struct svga_winsys_buffer *
-svga_winsys_buffer_create(struct svga_screen *ss,
+svga_winsys_buffer_create(struct svga_context *svga,
                           unsigned alignment, 
                           unsigned usage,
                           unsigned size);
index acef60f46472d12197955f2848e9c439f728e371..3de5216a949324d1d4fc5b7fc66730643bc415b6 100644 (file)
 #include "svga_debug.h"
 
 
-/* Allocate a winsys_buffer (ie. DMA, aka GMR memory).
+/**
+ * Allocate a winsys_buffer (ie. DMA, aka GMR memory).
+ *
+ * It will flush and retry in case the first attempt to create a DMA buffer
+ * fails, so it should not be called from any function involved in flushing
+ * to avoid recursion.
  */
 struct svga_winsys_buffer *
-svga_winsys_buffer_create( struct svga_screen *ss,
+svga_winsys_buffer_create( struct svga_context *svga,
                            unsigned alignment, 
                            unsigned usage,
                            unsigned size )
 {
-   struct svga_winsys_screen *sws = ss->sws;
+   struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
+   struct svga_winsys_screen *sws = svgascreen->sws;
    struct svga_winsys_buffer *buf;
    
    /* Just try */
@@ -59,9 +65,8 @@ svga_winsys_buffer_create( struct svga_screen *ss,
                size); 
       
       /* Try flushing all pending DMAs */
-      svga_screen_flush(ss, NULL);
+      svga_context_flush(svga, NULL);
       buf = sws->buffer_create(sws, alignment, usage, size);
-
    }
    
    return buf;
@@ -95,11 +100,12 @@ svga_buffer_create_hw_storage(struct svga_screen *ss,
    assert(!sbuf->user);
 
    if(!sbuf->hwbuf) {
+      struct svga_winsys_screen *sws = ss->sws;
       unsigned alignment = 16;
       unsigned usage = 0;
       unsigned size = sbuf->b.b.width0;
       
-      sbuf->hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+      sbuf->hwbuf = sws->buffer_create(sws, alignment, usage, size);
       if(!sbuf->hwbuf)
          return PIPE_ERROR_OUT_OF_MEMORY;
       
@@ -476,12 +482,12 @@ svga_buffer_upload_piecewise(struct svga_screen *ss,
          if (offset + size > range->end)
             size = range->end - offset;
 
-         hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+         hwbuf = sws->buffer_create(sws, alignment, usage, size);
          while (!hwbuf) {
             size /= 2;
             if (!size)
                return PIPE_ERROR_OUT_OF_MEMORY;
-            hwbuf = svga_winsys_buffer_create(ss, alignment, usage, size);
+            hwbuf = sws->buffer_create(sws, alignment, usage, size);
          }
 
          SVGA_DBG(DEBUG_DMA, "  bytes %u - %u\n",
index f06b0323d8c39269a1b34f8dfaec9eb0ce3e0302..ff83c750aafa57085ecc7e2557301e4c9fd71335 100644 (file)
@@ -163,12 +163,12 @@ svga_translate_format_render(enum pipe_format format)
 
 
 static INLINE void
-svga_transfer_dma_band(struct svga_transfer *st,
+svga_transfer_dma_band(struct svga_context *svga,
+                       struct svga_transfer *st,
                        SVGA3dTransferType transfer,
                        unsigned y, unsigned h, unsigned srcy)
 {
    struct svga_texture *texture = svga_texture(st->base.resource); 
-   struct svga_screen *screen = svga_screen(texture->b.b.screen);
    SVGA3dCopyBox box;
    enum pipe_error ret;
    
@@ -195,20 +195,19 @@ svga_transfer_dma_band(struct svga_transfer *st,
    box.srcy = srcy;
    box.srcz = 0;
 
-   pipe_mutex_lock(screen->swc_mutex);
-   ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
+   ret = SVGA3D_SurfaceDMA(svga->swc, st, transfer, &box, 1);
    if(ret != PIPE_OK) {
-      screen->swc->flush(screen->swc, NULL);
-      ret = SVGA3D_SurfaceDMA(screen->swc, st, transfer, &box, 1);
+      svga->swc->flush(svga->swc, NULL);
+      ret = SVGA3D_SurfaceDMA(svga->swc, st, transfer, &box, 1);
       assert(ret == PIPE_OK);
    }
-   pipe_mutex_unlock(screen->swc_mutex);
 }
 
 
 static INLINE void
-svga_transfer_dma(struct svga_transfer *st,
-                 SVGA3dTransferType transfer)
+svga_transfer_dma(struct svga_context *svga,
+                  struct svga_transfer *st,
+                  SVGA3dTransferType transfer)
 {
    struct svga_texture *texture = svga_texture(st->base.resource); 
    struct svga_screen *screen = svga_screen(texture->b.b.screen);
@@ -223,10 +222,10 @@ svga_transfer_dma(struct svga_transfer *st,
    if(!st->swbuf) {
       /* Do the DMA transfer in a single go */
       
-      svga_transfer_dma_band(st, transfer, st->base.box.y, st->base.box.height, 0);
+      svga_transfer_dma_band(svga, st, transfer, st->base.box.y, st->base.box.height, 0);
 
       if(transfer == SVGA3D_READ_HOST_VRAM) {
-         svga_screen_flush(screen, &fence);
+         svga_context_flush(svga, &fence);
          sws->fence_finish(sws, fence, 0);
          sws->fence_reference(sws, &fence, NULL);
       }
@@ -256,7 +255,7 @@ svga_transfer_dma(struct svga_transfer *st,
             /* Wait for the previous DMAs to complete */
             /* TODO: keep one DMA (at half the size) in the background */
             if(y) {
-               svga_screen_flush(screen, &fence);
+               svga_context_flush(svga, &fence);
                sws->fence_finish(sws, fence, 0);
                sws->fence_reference(sws, &fence, NULL);
             }
@@ -269,10 +268,10 @@ svga_transfer_dma(struct svga_transfer *st,
             }
          }
          
-         svga_transfer_dma_band(st, transfer, y, h, srcy);
+         svga_transfer_dma_band(svga, st, transfer, y, h, srcy);
          
          if(transfer == SVGA3D_READ_HOST_VRAM) {
-            svga_screen_flush(screen, &fence);
+            svga_context_flush(svga, &fence);
             sws->fence_finish(sws, fence, 0);
 
             hw = sws->buffer_map(sws, st->hwbuf, PIPE_TRANSFER_READ);
@@ -342,6 +341,7 @@ svga_texture_get_transfer(struct pipe_context *pipe,
                          unsigned usage,
                          const struct pipe_box *box)
 {
+   struct svga_context *svga = svga_context(pipe);
    struct svga_screen *ss = svga_screen(pipe->screen);
    struct svga_winsys_screen *sws = ss->sws;
    struct svga_transfer *st;
@@ -365,12 +365,12 @@ svga_texture_get_transfer(struct pipe_context *pipe,
 
    st->hw_nblocksy = nblocksy;
    
-   st->hwbuf = svga_winsys_buffer_create(ss, 
+   st->hwbuf = svga_winsys_buffer_create(svga,
                                          1, 
                                          0,
                                          st->hw_nblocksy*st->base.stride);
    while(!st->hwbuf && (st->hw_nblocksy /= 2)) {
-      st->hwbuf = svga_winsys_buffer_create(ss, 
+      st->hwbuf = svga_winsys_buffer_create(svga,
                                             1, 
                                             0,
                                             st->hw_nblocksy*st->base.stride);
@@ -393,7 +393,7 @@ svga_texture_get_transfer(struct pipe_context *pipe,
    }
    
    if (usage & PIPE_TRANSFER_READ)
-      svga_transfer_dma(st, SVGA3D_READ_HOST_VRAM);
+      svga_transfer_dma(svga, st, SVGA3D_READ_HOST_VRAM);
 
    return &st->base;
 
@@ -445,13 +445,14 @@ static void
 svga_texture_transfer_destroy(struct pipe_context *pipe,
                              struct pipe_transfer *transfer)
 {
+   struct svga_context *svga = svga_context(pipe);
    struct svga_texture *tex = svga_texture(transfer->resource);
    struct svga_screen *ss = svga_screen(pipe->screen);
    struct svga_winsys_screen *sws = ss->sws;
    struct svga_transfer *st = svga_transfer(transfer);
 
    if (st->base.usage & PIPE_TRANSFER_WRITE) {
-      svga_transfer_dma(st, SVGA3D_WRITE_HOST_VRAM);
+      svga_transfer_dma(svga, st, SVGA3D_WRITE_HOST_VRAM);
       ss->texture_timestamp++;
       tex->view_age[transfer->sr.level] = ++(tex->age);
       tex->defined[transfer->sr.face][transfer->sr.level] = TRUE;
index fbae552f78f46639bf688c1a119ec3f420d613d0..6911f13f778b0e1095cc32fc427c91739a7e7f62 100644 (file)
@@ -169,7 +169,7 @@ svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *
    for (i = v->min_lod; i <= v->max_lod; i++) {
       for (k = 0; k < numFaces; k++) {
          if (v->age < tex->view_age[i])
-            svga_texture_copy_handle(svga, NULL,
+            svga_texture_copy_handle(svga,
                                      tex->handle, 0, 0, 0, i, k,
                                      v->handle, 0, 0, 0, i - v->min_lod, k,
                                      u_minify(tex->b.b.width0, i),
index ac310b6aedde61bd5435dd2824b54794b550daab..45e477e65bffdb21c6977793623a0b7e247e463d 100644 (file)
@@ -347,8 +347,6 @@ svga_destroy_screen( struct pipe_screen *screen )
    pipe_mutex_destroy(svgascreen->swc_mutex);
    pipe_mutex_destroy(svgascreen->tex_mutex);
 
-   svgascreen->swc->destroy(svgascreen->swc);
-   
    svgascreen->sws->destroy(svgascreen->sws);
    
    FREE(svgascreen);
@@ -418,10 +416,6 @@ svga_screen_create(struct svga_winsys_screen *sws)
       svgascreen->use_vs30 = svgascreen->use_ps30 = FALSE;
 #endif
 
-   svgascreen->swc = sws->context_create(sws);
-   if(!svgascreen->swc)
-      goto error2;
-
    pipe_mutex_init(svgascreen->tex_mutex);
    pipe_mutex_init(svgascreen->swc_mutex);
 
@@ -434,25 +428,6 @@ error1:
    return NULL;
 }
 
-void svga_screen_flush( struct svga_screen *svgascreen, 
-                        struct pipe_fence_handle **pfence )
-{
-   struct pipe_fence_handle *fence = NULL;
-
-   SVGA_DBG(DEBUG_PERF, "%s\n", __FUNCTION__);
-   
-   pipe_mutex_lock(svgascreen->swc_mutex);
-   svgascreen->swc->flush(svgascreen->swc, &fence);
-   pipe_mutex_unlock(svgascreen->swc_mutex);
-   
-   svga_screen_cache_flush(svgascreen, fence);
-   
-   if(pfence)
-      *pfence = fence;
-   else
-      svgascreen->sws->fence_reference(svgascreen->sws, &fence, NULL);
-}
-
 struct svga_winsys_screen *
 svga_winsys_screen(struct pipe_screen *screen)
 {
index 9dc229b0a8789bbe35610d5c8cee5ecdb717f3dc..86ec89d88c1fc2ce0c00962463b2b2ab54070bfb 100644 (file)
@@ -60,14 +60,11 @@ struct svga_screen
       boolean no_sampler_view;
    } debug;
 
-   /* The screen needs its own context */
-   struct svga_winsys_context *swc;
-   struct SVGACmdMemory *fifo;
-
    unsigned texture_timestamp;
    pipe_mutex tex_mutex; 
-   pipe_mutex swc_mutex; /* Protects the use of swc and dirty_buffers */
-   
+
+   pipe_mutex swc_mutex; /* Used for buffer uploads */
+
    struct svga_host_surface_cache cache;
 };
 
@@ -83,7 +80,4 @@ struct svga_screen *
 svga_screen(struct pipe_screen *screen);
 #endif
 
-void svga_screen_flush( struct svga_screen *svga_screen, 
-                        struct pipe_fence_handle **pfence );
-
 #endif /* SVGA_SCREEN_H */
index dc1d9a850df81399792f07e38ca1b13f8408358e..bd2cc380048a2feb45b9e47260d513aa85f75b22 100644 (file)
@@ -43,7 +43,6 @@
 
 void
 svga_texture_copy_handle(struct svga_context *svga,
-                         struct svga_screen *ss,
                          struct svga_winsys_surface *src_handle,
                          unsigned src_x, unsigned src_y, unsigned src_z,
                          unsigned src_level, unsigned src_face,
@@ -56,7 +55,7 @@ svga_texture_copy_handle(struct svga_context *svga,
    enum pipe_error ret;
    SVGA3dCopyBox box, *boxes;
 
-   assert(svga || ss);
+   assert(svga);
 
    src.handle = src_handle;
    src.real_level = src_level;
@@ -84,39 +83,20 @@ svga_texture_copy_handle(struct svga_context *svga,
             dst_handle, dst_level, dst_x, dst_y, dst_z);
 */
 
-   if (svga) {
+   ret = SVGA3D_BeginSurfaceCopy(svga->swc,
+                                 &src.base,
+                                 &dst.base,
+                                 &boxes, 1);
+   if(ret != PIPE_OK) {
+      svga_context_flush(svga, NULL);
       ret = SVGA3D_BeginSurfaceCopy(svga->swc,
                                     &src.base,
                                     &dst.base,
                                     &boxes, 1);
-      if(ret != PIPE_OK) {
-         svga_context_flush(svga, NULL);
-         ret = SVGA3D_BeginSurfaceCopy(svga->swc,
-                                       &src.base,
-                                       &dst.base,
-                                       &boxes, 1);
-         assert(ret == PIPE_OK);
-      }
-      *boxes = box;
-      SVGA_FIFOCommitAll(svga->swc);
-   } else {
-      pipe_mutex_lock(ss->swc_mutex);
-      ret = SVGA3D_BeginSurfaceCopy(ss->swc,
-                                    &src.base,
-                                    &dst.base,
-                                    &boxes, 1);
-      if(ret != PIPE_OK) {
-         ss->swc->flush(ss->swc, NULL);
-         ret = SVGA3D_BeginSurfaceCopy(ss->swc,
-                                       &src.base,
-                                       &dst.base,
-                                       &boxes, 1);
-         assert(ret == PIPE_OK);
-      }
-      *boxes = box;
-      SVGA_FIFOCommitAll(ss->swc);
-      pipe_mutex_unlock(ss->swc_mutex);
+      assert(ret == PIPE_OK);
    }
+   *boxes = box;
+   SVGA_FIFOCommitAll(svga->swc);
 }
 
 
@@ -183,7 +163,6 @@ svga_texture_view_surface(struct pipe_context *pipe,
                               1);
 
             svga_texture_copy_handle(svga_context(pipe),
-                                     ss,
                                      tex->handle, 
                                      0, 0, z_offset, 
                                      i + start_mip, 
@@ -346,7 +325,7 @@ svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf)
 
    if (s->handle != tex->handle) {
       SVGA_DBG(DEBUG_VIEWS, "svga: Surface propagate: tex %p, level %u, from %p\n", tex, surf->level, surf);
-      svga_texture_copy_handle(svga_context(pipe), ss,
+      svga_texture_copy_handle(svga_context(pipe),
                                s->handle, 0, 0, 0, s->real_level, s->real_face,
                                tex->handle, 0, 0, surf->zslice, surf->level, surf->face,
                                u_minify(tex->b.b.width0, surf->level),
index b50ecdc99422c56855754ff28da17cd6d09c2c99..13bd5b19b61f248aebb16a2983d237f80fa8cc23 100644 (file)
@@ -74,7 +74,6 @@ svga_texture_view_surface(struct pipe_context *pipe,
 
 void
 svga_texture_copy_handle(struct svga_context *svga,
-                         struct svga_screen *ss,
                          struct svga_winsys_surface *src_handle,
                          unsigned src_x, unsigned src_y, unsigned src_z,
                          unsigned src_level, unsigned src_face,