gallium: unify transfer functions
[mesa.git] / src / gallium / drivers / softpipe / sp_tile_cache.c
index 659ac58e5b0f5997b37ead181061ed77e3eb8dd1..8d581112fcd7cd40f566fa4e26c2db8906104f92 100644 (file)
@@ -141,7 +141,7 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc)
       FREE( tc->tile );
 
       if (tc->transfer) {
-         tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
+         tc->pipe->transfer_unmap(tc->pipe, tc->transfer);
       }
 
       FREE( tc );
@@ -158,27 +158,24 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
 {
    struct pipe_context *pipe = tc->pipe;
 
-   if (tc->transfer) {
+   if (tc->transfer_map) {
       if (ps == tc->surface)
          return;
 
-      if (tc->transfer_map) {
-         pipe->transfer_unmap(pipe, tc->transfer);
-         tc->transfer_map = NULL;
-      }
-
-      pipe->transfer_destroy(pipe, tc->transfer);
+      pipe->transfer_unmap(pipe, tc->transfer);
       tc->transfer = NULL;
+      tc->transfer_map = NULL;
    }
 
    tc->surface = ps;
 
    if (ps) {
-      tc->transfer = pipe_get_transfer(pipe, ps->texture,
-                                       ps->u.tex.level, ps->u.tex.first_layer,
-                                       PIPE_TRANSFER_READ_WRITE |
-                                       PIPE_TRANSFER_UNSYNCHRONIZED,
-                                       0, 0, ps->width, ps->height);
+      tc->transfer_map = pipe_transfer_map(pipe, ps->texture,
+                                           ps->u.tex.level, ps->u.tex.first_layer,
+                                           PIPE_TRANSFER_READ_WRITE |
+                                           PIPE_TRANSFER_UNSYNCHRONIZED,
+                                           0, 0, ps->width, ps->height,
+                                           &tc->transfer);
 
       tc->depth_stencil = util_format_is_depth_or_stencil(ps->format);
    }
@@ -195,24 +192,6 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc)
 }
 
 
-void
-sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc)
-{
-   if (tc->transfer && !tc->transfer_map)
-      tc->transfer_map = tc->pipe->transfer_map(tc->pipe, tc->transfer);
-}
-
-
-void
-sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc)
-{
-   if (tc->transfer_map) {
-      tc->pipe->transfer_unmap(tc->pipe, tc->transfer);
-      tc->transfer_map = NULL;
-   }
-}
-
-
 /**
  * Set pixels in a tile to the given clear color/value, float.
  */
@@ -349,24 +328,23 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc)
          if (is_clear_flag_set(tc->clear_flags, addr)) {
             /* write the scratch tile to the surface */
             if (tc->depth_stencil) {
-               pipe_put_tile_raw(tc->pipe,
-                                 pt,
+               pipe_put_tile_raw(pt, tc->transfer_map,
                                  x, y, TILE_SIZE, TILE_SIZE,
                                  tc->tile->data.any, 0/*STRIDE*/);
             }
             else {
                if (util_format_is_pure_uint(tc->surface->format)) {
-                  pipe_put_tile_ui_format(tc->pipe, pt,
+                  pipe_put_tile_ui_format(pt, tc->transfer_map,
                                           x, y, TILE_SIZE, TILE_SIZE,
                                           pt->resource->format,
                                           (unsigned *) tc->tile->data.colorui128);
                } else if (util_format_is_pure_sint(tc->surface->format)) {
-                  pipe_put_tile_i_format(tc->pipe, pt,
+                  pipe_put_tile_i_format(pt, tc->transfer_map,
                                          x, y, TILE_SIZE, TILE_SIZE,
                                          pt->resource->format,
                                          (int *) tc->tile->data.colori128);
                } else {
-                  pipe_put_tile_rgba(tc->pipe, pt,
+                  pipe_put_tile_rgba(pt, tc->transfer_map,
                                      x, y, TILE_SIZE, TILE_SIZE,
                                      (float *) tc->tile->data.color);
                }
@@ -389,7 +367,7 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos)
 {
    if (!tc->tile_addrs[pos].bits.invalid) {
       if (tc->depth_stencil) {
-         pipe_put_tile_raw(tc->pipe, tc->transfer,
+         pipe_put_tile_raw(tc->transfer, tc->transfer_map,
                            tc->tile_addrs[pos].bits.x * TILE_SIZE,
                            tc->tile_addrs[pos].bits.y * TILE_SIZE,
                            TILE_SIZE, TILE_SIZE,
@@ -397,21 +375,21 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos)
       }
       else {
          if (util_format_is_pure_uint(tc->surface->format)) {
-            pipe_put_tile_ui_format(tc->pipe, tc->transfer,
+            pipe_put_tile_ui_format(tc->transfer, tc->transfer_map,
                                     tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                     tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                     TILE_SIZE, TILE_SIZE,
                                     tc->surface->format,
                                     (unsigned *) tc->entries[pos]->data.colorui128);
          } else if (util_format_is_pure_sint(tc->surface->format)) {
-            pipe_put_tile_i_format(tc->pipe, tc->transfer,
+            pipe_put_tile_i_format(tc->transfer, tc->transfer_map,
                                    tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                    tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                    TILE_SIZE, TILE_SIZE,
                                    tc->surface->format,
                                    (int *) tc->entries[pos]->data.colori128);
          } else {
-            pipe_put_tile_rgba_format(tc->pipe, tc->transfer,
+            pipe_put_tile_rgba_format(tc->transfer, tc->transfer_map,
                                       tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                       tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                       TILE_SIZE, TILE_SIZE,
@@ -516,7 +494,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
       if (tc->tile_addrs[pos].bits.invalid == 0) {
          /* put dirty tile back in framebuffer */
          if (tc->depth_stencil) {
-            pipe_put_tile_raw(tc->pipe, pt,
+            pipe_put_tile_raw(pt, tc->transfer_map,
                               tc->tile_addrs[pos].bits.x * TILE_SIZE,
                               tc->tile_addrs[pos].bits.y * TILE_SIZE,
                               TILE_SIZE, TILE_SIZE,
@@ -524,21 +502,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
          }
          else {
             if (util_format_is_pure_uint(tc->surface->format)) {
-               pipe_put_tile_ui_format(tc->pipe, pt,
+               pipe_put_tile_ui_format(pt, tc->transfer_map,
                                       tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                       tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                       TILE_SIZE, TILE_SIZE,
                                       tc->surface->format,
                                       (unsigned *) tile->data.colorui128);
             } else if (util_format_is_pure_sint(tc->surface->format)) {
-               pipe_put_tile_i_format(tc->pipe, pt,
+               pipe_put_tile_i_format(pt, tc->transfer_map,
                                       tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                       tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                       TILE_SIZE, TILE_SIZE,
                                       tc->surface->format,
                                       (int *) tile->data.colori128);
             } else {
-               pipe_put_tile_rgba_format(tc->pipe, pt,
+               pipe_put_tile_rgba_format(pt, tc->transfer_map,
                                          tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                          tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                          TILE_SIZE, TILE_SIZE,
@@ -563,7 +541,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
       else {
          /* get new tile data from transfer */
          if (tc->depth_stencil) {
-            pipe_get_tile_raw(tc->pipe, pt,
+            pipe_get_tile_raw(pt, tc->transfer_map,
                               tc->tile_addrs[pos].bits.x * TILE_SIZE,
                               tc->tile_addrs[pos].bits.y * TILE_SIZE,
                               TILE_SIZE, TILE_SIZE,
@@ -571,21 +549,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc,
          }
          else {
             if (util_format_is_pure_uint(tc->surface->format)) {
-               pipe_get_tile_ui_format(tc->pipe, pt,
+               pipe_get_tile_ui_format(pt, tc->transfer_map,
                                          tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                          tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                          TILE_SIZE, TILE_SIZE,
                                          tc->surface->format,
                                          (unsigned *) tile->data.colorui128);
             } else if (util_format_is_pure_sint(tc->surface->format)) {
-               pipe_get_tile_i_format(tc->pipe, pt,
+               pipe_get_tile_i_format(pt, tc->transfer_map,
                                          tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                          tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                          TILE_SIZE, TILE_SIZE,
                                          tc->surface->format,
                                          (int *) tile->data.colori128);
             } else {
-               pipe_get_tile_rgba_format(tc->pipe, pt,
+               pipe_get_tile_rgba_format(pt, tc->transfer_map,
                                          tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                          tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                          TILE_SIZE, TILE_SIZE,