gallium: Preparations for adding more PIPE_TRANSFER_* usage flags.
authorMichel Dänzer <daenzer@vmware.com>
Fri, 2 Oct 2009 16:13:26 +0000 (18:13 +0200)
committerMichel Dänzer <daenzer@vmware.com>
Fri, 2 Oct 2009 16:13:26 +0000 (18:13 +0200)
Always test for PIPE_TRANSFER_READ/WRITE using the bit-wise and operator, and
add a pipe_transfer_buffer_flags() helper for getting the buffer usage flags
corresponding to them.

18 files changed:
src/gallium/auxiliary/util/u_tile.c
src/gallium/drivers/cell/ppu/cell_texture.c
src/gallium/drivers/i915simple/i915_texture.c
src/gallium/drivers/llvmpipe/lp_texture.c
src/gallium/drivers/nv04/nv04_transfer.c
src/gallium/drivers/nv10/nv10_transfer.c
src/gallium/drivers/nv20/nv20_transfer.c
src/gallium/drivers/nv30/nv30_transfer.c
src/gallium/drivers/nv40/nv40_transfer.c
src/gallium/drivers/nv50/nv50_transfer.c
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/softpipe/sp_texture.c
src/gallium/drivers/trace/tr_screen.c
src/gallium/include/pipe/p_inlines.h
src/gallium/state_trackers/python/retrace/interpreter.py
src/gallium/state_trackers/vega/st_inlines.h
src/mesa/state_tracker/st_cb_accum.c
src/mesa/state_tracker/st_texture.c

index 0d6489c26e4521fd190e8c33a54f5db18c4c371c..8a22f584bee766962c09a1d01fd642670d3a8337 100644 (file)
@@ -1452,7 +1452,7 @@ pipe_put_tile_z(struct pipe_transfer *pt,
    case PIPE_FORMAT_S8Z24_UNORM:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
-         assert(pt->usage == PIPE_TRANSFER_READ_WRITE);
+         assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z, preserve stencil */
@@ -1479,7 +1479,7 @@ pipe_put_tile_z(struct pipe_transfer *pt,
    case PIPE_FORMAT_Z24S8_UNORM:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
-         assert(pt->usage == PIPE_TRANSFER_READ_WRITE);
+         assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z, preserve stencil */
index 6a63a0e6ced2db2e8e9ab7442f626e81288a089b..ae4c61efb3bee91e072a545578a6de91ae13c442 100644 (file)
@@ -389,22 +389,14 @@ cell_transfer_map(struct pipe_screen *screen, struct pipe_transfer *transfer)
    const uint texWidth = pt->width[level];
    const uint texHeight = pt->height[level];
    const uint stride = ct->stride[level];
-   unsigned flags = 0x0;
    unsigned size;
 
    assert(transfer->texture);
 
-   if (transfer->usage != PIPE_TRANSFER_READ) {
-      flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
-   }
-
-   if (transfer->usage != PIPE_TRANSFER_WRITE) {
-      flags |= PIPE_BUFFER_USAGE_CPU_READ;
-   }
-
    if (!ct->mapped) {
       /* map now */
-      ct->mapped = pipe_buffer_map(screen, ct->buffer, flags);
+      ct->mapped = pipe_buffer_map(screen, ct->buffer,
+                                   pipe_transfer_buffer_flags(transfer));
    }
 
    /*
@@ -417,8 +409,7 @@ cell_transfer_map(struct pipe_screen *screen, struct pipe_transfer *transfer)
    if (!ctrans->map)
       return NULL; /* out of memory */
 
-   if (transfer->usage == PIPE_TRANSFER_READ ||
-       transfer->usage == PIPE_TRANSFER_READ_WRITE) {
+   if (transfer->usage & PIPE_TRANSFER_READ) {
       /* need to untwiddle the texture to make a linear version */
       const uint bpp = pf_get_size(ct->base.format);
       if (bpp == 4) {
@@ -459,8 +450,7 @@ cell_transfer_unmap(struct pipe_screen *screen,
                                    PIPE_BUFFER_USAGE_CPU_READ);
    }
 
-   if (transfer->usage == PIPE_TRANSFER_WRITE ||
-       transfer->usage == PIPE_TRANSFER_READ_WRITE) {
+   if (transfer->usage & PIPE_TRANSFER_WRITE) {
       /* The user wrote new texture data into the mapped buffer.
        * We need to convert the new linear data into the twiddled/tiled format.
        */
index 15ccc1fc73bfa80ea65704ecac488aa465a168f5..286c9ace8e5736a2ab161eca5dbb2a7be936b913 100644 (file)
@@ -859,7 +859,7 @@ i915_transfer_map(struct pipe_screen *screen,
    char *map;
    boolean write = FALSE;
 
-   if (transfer->usage != PIPE_TRANSFER_READ)
+   if (transfer->usage & PIPE_TRANSFER_WRITE)
       write = TRUE;
 
    map = iws->buffer_map(iws, tex->buffer, write);
index 724d43783360e3a037f6c34cac3688f4ca75cb40..08f0950d47548d4d9997dfb2e6c61296b8abbd61 100644 (file)
@@ -353,17 +353,9 @@ llvmpipe_transfer_map( struct pipe_screen *_screen,
 
    if(lpt->dt) {
       struct llvmpipe_winsys *winsys = screen->winsys;
-      unsigned flags = 0;
 
-      if (transfer->usage != PIPE_TRANSFER_READ) {
-         flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
-      }
-
-      if (transfer->usage != PIPE_TRANSFER_WRITE) {
-         flags |= PIPE_BUFFER_USAGE_CPU_READ;
-      }
-
-      map = winsys->displaytarget_map(winsys, lpt->dt, flags);
+      map = winsys->displaytarget_map(winsys, lpt->dt,
+                                      pipe_transfer_buffer_flags(transfer));
       if (map == NULL)
          return NULL;
    }
@@ -373,7 +365,7 @@ llvmpipe_transfer_map( struct pipe_screen *_screen,
    /* May want to different things here depending on read/write nature
     * of the map:
     */
-   if (transfer->texture && transfer->usage != PIPE_TRANSFER_READ) 
+   if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE))
    {
       /* Do something to notify sharing contexts of a texture change.
        * In llvmpipe, that would mean flushing the texture cache.
index 854b855d64a12aad0ba954d03a638df3fcadc4d2..6618660743d48388048912c1bb45d4014f37ced6 100644 (file)
@@ -13,22 +13,6 @@ struct nv04_transfer {
        bool direct;
 };
 
-static unsigned nv04_usage_tx_to_buf(unsigned tx_usage)
-{
-       switch (tx_usage) {
-               case PIPE_TRANSFER_READ:
-                       return PIPE_BUFFER_USAGE_CPU_READ;
-               case PIPE_TRANSFER_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_WRITE;
-               case PIPE_TRANSFER_READ_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-               default:
-                       assert(0);
-       }
-
-       return -1;
-}
-
 static void
 nv04_compatible_transfer_tex(struct pipe_texture *pt, unsigned level,
                              struct pipe_texture *template)
@@ -86,7 +70,7 @@ nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                tx->direct = true;
                tx->surface = pscreen->get_tex_surface(pscreen, pt,
                                                       0, 0, 0,
-                                                      nv04_usage_tx_to_buf(usage));
+                                                      pipe_transfer_buffer_flags(&tx->base));
                return &tx->base;
        }
 
@@ -103,7 +87,7 @@ nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 
        tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
                                               face, level, zslice,
-                                              nv04_usage_tx_to_buf(usage));
+                                              pipe_transfer_buffer_flags(&tx->base));
 
        pipe_texture_reference(&tx_tex, NULL);
 
@@ -114,7 +98,7 @@ nv04_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                struct nv04_screen *nvscreen = nv04_screen(pscreen);
                struct pipe_surface *src;
 
@@ -140,7 +124,7 @@ nv04_transfer_del(struct pipe_transfer *ptx)
 {
        struct nv04_transfer *tx = (struct nv04_transfer *)ptx;
 
-       if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) {
+       if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                struct nv04_screen *nvscreen = nv04_screen(pscreen);
                struct pipe_surface *dst;
@@ -170,7 +154,7 @@ nv04_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
        struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
        struct nv04_miptree *mt = (struct nv04_miptree *)tx->surface->texture;
        void *map = pipe_buffer_map(pscreen, mt->buffer,
-                                   nv04_usage_tx_to_buf(ptx->usage));
+                                   pipe_transfer_buffer_flags(ptx));
 
        return map + ns->base.offset +
               ptx->y * ns->pitch + ptx->x * ptx->block.size;
index c06b8d34c72c814efbf5177cf1072692928f633b..8feb85e4bda22eb33837d7002fd0777cf9edd0ca 100644 (file)
@@ -13,22 +13,6 @@ struct nv10_transfer {
        bool direct;
 };
 
-static unsigned nv10_usage_tx_to_buf(unsigned tx_usage)
-{
-       switch (tx_usage) {
-               case PIPE_TRANSFER_READ:
-                       return PIPE_BUFFER_USAGE_CPU_READ;
-               case PIPE_TRANSFER_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_WRITE;
-               case PIPE_TRANSFER_READ_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-               default:
-                       assert(0);
-       }
-
-       return -1;
-}
-
 static void
 nv10_compatible_transfer_tex(struct pipe_texture *pt, unsigned level,
                              struct pipe_texture *template)
@@ -86,7 +70,7 @@ nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                tx->direct = true;
                tx->surface = pscreen->get_tex_surface(pscreen, pt,
                                                       0, 0, 0,
-                                                      nv10_usage_tx_to_buf(usage));
+                                                      pipe_transfer_buffer_flags(&tx->base));
                return &tx->base;
        }
 
@@ -103,7 +87,7 @@ nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 
        tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
                                               face, level, zslice,
-                                              nv10_usage_tx_to_buf(usage));
+                                              pipe_transfer_buffer_flags(&tx->base));
 
        pipe_texture_reference(&tx_tex, NULL);
 
@@ -114,7 +98,7 @@ nv10_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                struct nv10_screen *nvscreen = nv10_screen(pscreen);
                struct pipe_surface *src;
 
@@ -140,7 +124,7 @@ nv10_transfer_del(struct pipe_transfer *ptx)
 {
        struct nv10_transfer *tx = (struct nv10_transfer *)ptx;
 
-       if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) {
+       if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                struct nv10_screen *nvscreen = nv10_screen(pscreen);
                struct pipe_surface *dst;
@@ -170,7 +154,7 @@ nv10_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
        struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
        struct nv10_miptree *mt = (struct nv10_miptree *)tx->surface->texture;
        void *map = pipe_buffer_map(pscreen, mt->buffer,
-                                   nv10_usage_tx_to_buf(ptx->usage));
+                                   pipe_transfer_buffer_flags(ptx));
 
        return map + ns->base.offset +
               ptx->y * ns->pitch + ptx->x * ptx->block.size;
index 5018995596c37af300825e7c57ec996002509cdc..81b4f1a9177f47beb75e7c138abb17ca3b975a7e 100644 (file)
@@ -13,22 +13,6 @@ struct nv20_transfer {
        bool direct;
 };
 
-static unsigned nv20_usage_tx_to_buf(unsigned tx_usage)
-{
-       switch (tx_usage) {
-               case PIPE_TRANSFER_READ:
-                       return PIPE_BUFFER_USAGE_CPU_READ;
-               case PIPE_TRANSFER_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_WRITE;
-               case PIPE_TRANSFER_READ_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-               default:
-                       assert(0);
-       }
-
-       return -1;
-}
-
 static void
 nv20_compatible_transfer_tex(struct pipe_texture *pt, unsigned level,
                              struct pipe_texture *template)
@@ -86,7 +70,7 @@ nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                tx->direct = true;
                tx->surface = pscreen->get_tex_surface(pscreen, pt,
                                                       0, 0, 0,
-                                                      nv20_usage_tx_to_buf(usage));
+                                                      pipe_transfer_buffer_flags(&tx->base));
                return &tx->base;
        }
 
@@ -103,7 +87,7 @@ nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 
        tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
                                               face, level, zslice,
-                                              nv20_usage_tx_to_buf(usage));
+                                              pipe_transfer_buffer_flags(&tx->base));
 
        pipe_texture_reference(&tx_tex, NULL);
 
@@ -114,7 +98,7 @@ nv20_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                struct nv20_screen *nvscreen = nv20_screen(pscreen);
                struct pipe_surface *src;
 
@@ -140,7 +124,7 @@ nv20_transfer_del(struct pipe_transfer *ptx)
 {
        struct nv20_transfer *tx = (struct nv20_transfer *)ptx;
 
-       if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) {
+       if (!tx->direct && (ptx->usage = PIPE_TRANSFER_WRITE)) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                struct nv20_screen *nvscreen = nv20_screen(pscreen);
                struct pipe_surface *dst;
@@ -170,7 +154,7 @@ nv20_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
        struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
        struct nv20_miptree *mt = (struct nv20_miptree *)tx->surface->texture;
        void *map = pipe_buffer_map(pscreen, mt->buffer,
-                                   nv20_usage_tx_to_buf(ptx->usage));
+                                   pipe_transfer_buffer_flags(ptx));
 
        return map + ns->base.offset +
               ptx->y * ns->pitch + ptx->x * ptx->block.size;
index 23675718781310c0cc1ee28cc183dd7d1f703154..98011decf7cac2c3f1e2a4cab30fe2be12f0f5d9 100644 (file)
@@ -13,22 +13,6 @@ struct nv30_transfer {
        bool direct;
 };
 
-static unsigned nv30_usage_tx_to_buf(unsigned tx_usage)
-{
-       switch (tx_usage) {
-               case PIPE_TRANSFER_READ:
-                       return PIPE_BUFFER_USAGE_CPU_READ;
-               case PIPE_TRANSFER_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_WRITE;
-               case PIPE_TRANSFER_READ_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-               default:
-                       assert(0);
-       }
-
-       return -1;
-}
-
 static void
 nv30_compatible_transfer_tex(struct pipe_texture *pt, unsigned level,
                              struct pipe_texture *template)
@@ -86,7 +70,7 @@ nv30_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                tx->direct = true;
                tx->surface = pscreen->get_tex_surface(pscreen, pt,
                                                       face, level, zslice,
-                                                      nv30_usage_tx_to_buf(usage));
+                                                      pipe_transfer_buffer_flags(&tx->base));
                return &tx->base;
        }
 
@@ -103,7 +87,7 @@ nv30_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 
        tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
                                               0, 0, 0,
-                                              nv30_usage_tx_to_buf(usage));
+                                              pipe_transfer_buffer_flags(&tx->base));
 
        pipe_texture_reference(&tx_tex, NULL);
 
@@ -114,7 +98,7 @@ nv30_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                struct nv30_screen *nvscreen = nv30_screen(pscreen);
                struct pipe_surface *src;
 
@@ -140,7 +124,7 @@ nv30_transfer_del(struct pipe_transfer *ptx)
 {
        struct nv30_transfer *tx = (struct nv30_transfer *)ptx;
 
-       if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) {
+       if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                struct nv30_screen *nvscreen = nv30_screen(pscreen);
                struct pipe_surface *dst;
@@ -170,7 +154,7 @@ nv30_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
        struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
        struct nv30_miptree *mt = (struct nv30_miptree *)tx->surface->texture;
        void *map = pipe_buffer_map(pscreen, mt->buffer,
-                                   nv30_usage_tx_to_buf(ptx->usage));
+                                   pipe_transfer_buffer_flags(ptx));
 
        return map + ns->base.offset +
               ptx->y * ns->pitch + ptx->x * ptx->block.size;
index 6d92ac3db9caaa8fe26afd9f10f981e33f35c94a..92caee6f3825dda7324b3326501e37cee9d11504 100644 (file)
@@ -13,22 +13,6 @@ struct nv40_transfer {
        bool direct;
 };
 
-static unsigned nv40_usage_tx_to_buf(unsigned tx_usage)
-{
-       switch (tx_usage) {
-               case PIPE_TRANSFER_READ:
-                       return PIPE_BUFFER_USAGE_CPU_READ;
-               case PIPE_TRANSFER_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_WRITE;
-               case PIPE_TRANSFER_READ_WRITE:
-                       return PIPE_BUFFER_USAGE_CPU_READ_WRITE;
-               default:
-                       assert(0);
-       }
-
-       return -1;
-}
-
 static void
 nv40_compatible_transfer_tex(struct pipe_texture *pt, unsigned level,
                              struct pipe_texture *template)
@@ -86,7 +70,7 @@ nv40_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                tx->direct = true;
                tx->surface = pscreen->get_tex_surface(pscreen, pt,
                                                       face, level, zslice,
-                                                      nv40_usage_tx_to_buf(usage));
+                                                      pipe_transfer_buffer_flags(&tx->base));
                return &tx->base;
        }
 
@@ -103,7 +87,7 @@ nv40_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 
        tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
                                               0, 0, 0,
-                                              nv40_usage_tx_to_buf(usage));
+                                              pipe_transfer_buffer_flags(&tx->base));
 
        pipe_texture_reference(&tx_tex, NULL);
 
@@ -114,7 +98,7 @@ nv40_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                struct nv40_screen *nvscreen = nv40_screen(pscreen);
                struct pipe_surface *src;
 
@@ -140,7 +124,7 @@ nv40_transfer_del(struct pipe_transfer *ptx)
 {
        struct nv40_transfer *tx = (struct nv40_transfer *)ptx;
 
-       if (!tx->direct && ptx->usage != PIPE_TRANSFER_READ) {
+       if (!tx->direct && (ptx->usage & PIPE_TRANSFER_WRITE)) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                struct nv40_screen *nvscreen = nv40_screen(pscreen);
                struct pipe_surface *dst;
@@ -170,7 +154,7 @@ nv40_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
        struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
        struct nv40_miptree *mt = (struct nv40_miptree *)tx->surface->texture;
        void *map = pipe_buffer_map(pscreen, mt->buffer,
-                                   nv40_usage_tx_to_buf(ptx->usage));
+                                   pipe_transfer_buffer_flags(ptx));
 
        return map + ns->base.offset +
               ptx->y * ns->pitch + ptx->x * ptx->block.size;
index bb7731855cd4b4af0732f9419dbcf2d19e75bd6d..9c289026bbb14498adccdfa5f1ee602794c71416 100644 (file)
@@ -161,7 +161,7 @@ nv50_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
                return NULL;
        }
 
-       if (usage != PIPE_TRANSFER_WRITE) {
+       if (usage & PIPE_TRANSFER_READ) {
                nv50_transfer_rect_m2mf(pscreen, mt->base.bo, tx->level_offset,
                                        tx->level_pitch, tx->level_tiling,
                                        x, y,
@@ -183,7 +183,7 @@ nv50_transfer_del(struct pipe_transfer *ptx)
        struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
        struct nv50_miptree *mt = nv50_miptree(ptx->texture);
 
-       if (ptx->usage != PIPE_TRANSFER_READ) {
+       if (ptx->usage & PIPE_TRANSFER_WRITE) {
                struct pipe_screen *pscreen = ptx->texture->screen;
                nv50_transfer_rect_m2mf(pscreen, tx->bo, 0, tx->base.stride,
                                        tx->bo->tile_mode, 0, 0,
index 8296d56840f6f012339c577d7bda5816ebc2b967..f2659ca61f718e1a1d959c767d0eb430d7875af8 100644 (file)
@@ -345,16 +345,9 @@ static void* r300_transfer_map(struct pipe_screen* screen,
 {
     struct r300_texture* tex = (struct r300_texture*)transfer->texture;
     char* map;
-    unsigned flags = 0;
 
-    if (transfer->usage != PIPE_TRANSFER_WRITE) {
-        flags |= PIPE_BUFFER_USAGE_CPU_READ;
-    }
-    if (transfer->usage != PIPE_TRANSFER_READ) {
-        flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
-    }
-
-    map = pipe_buffer_map(screen, tex->buffer, flags);
+    map = pipe_buffer_map(screen, tex->buffer,
+                          pipe_transfer_buffer_flags(transfer));
 
     if (!map) {
         return NULL;
index 1c64d58372d2c127ed98f89bae181d688f74b0a0..2e6c43c7ef26fdd93af7a5f372e34cd53803f81f 100644 (file)
@@ -329,27 +329,18 @@ softpipe_transfer_map( struct pipe_screen *screen,
 {
    ubyte *map, *xfer_map;
    struct softpipe_texture *spt;
-   unsigned flags = 0;
 
    assert(transfer->texture);
    spt = softpipe_texture(transfer->texture);
 
-   if (transfer->usage != PIPE_TRANSFER_READ) {
-      flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
-   }
-
-   if (transfer->usage != PIPE_TRANSFER_WRITE) {
-      flags |= PIPE_BUFFER_USAGE_CPU_READ;
-   }
-
-   map = pipe_buffer_map(screen, spt->buffer, flags);
+   map = pipe_buffer_map(screen, spt->buffer, pipe_transfer_buffer_flags(transfer));
    if (map == NULL)
       return NULL;
 
    /* May want to different things here depending on read/write nature
     * of the map:
     */
-   if (transfer->texture && transfer->usage != PIPE_TRANSFER_READ) {
+   if (transfer->texture && (transfer->usage & PIPE_TRANSFER_WRITE)) {
       /* Do something to notify sharing contexts of a texture change.
        * In softpipe, that would mean flushing the texture cache.
        */
@@ -375,7 +366,7 @@ softpipe_transfer_unmap(struct pipe_screen *screen,
 
    pipe_buffer_unmap( screen, spt->buffer );
 
-   if (transfer->usage != PIPE_TRANSFER_READ) {
+   if (transfer->usage & PIPE_TRANSFER_WRITE) {
       /* Mark the texture as dirty to expire the tile caches. */
       spt->timestamp++;
    }
index 26f1c04594f305316452cb11694144f88fe08303..ab605c7fc8761bcf155636c004139cdffec31bc6 100644 (file)
@@ -403,7 +403,7 @@ trace_screen_transfer_map(struct pipe_screen *_screen,
 
    map = screen->transfer_map(screen, transfer);
    if(map) {
-      if(transfer->usage != PIPE_TRANSFER_READ) {
+      if(transfer->usage & PIPE_TRANSFER_WRITE) {
          assert(!tr_trans->map);
          tr_trans->map = map;
       }
index 30a4aaf4093921c2f694712118d9fba492012dde..5fbd62a03d2bba16e3f9bda3d8cbb6ede5edb222 100644 (file)
@@ -176,6 +176,22 @@ pipe_transfer_destroy( struct pipe_transfer *transf )
    screen->tex_transfer_destroy(transf);
 }
 
+static INLINE unsigned
+pipe_transfer_buffer_flags( struct pipe_transfer *transf )
+{
+   switch (transf->usage & PIPE_TRANSFER_READ_WRITE) {
+   case PIPE_TRANSFER_READ_WRITE:
+      return PIPE_BUFFER_USAGE_CPU_READ | PIPE_BUFFER_USAGE_CPU_WRITE;
+   case PIPE_TRANSFER_READ:
+      return PIPE_BUFFER_USAGE_CPU_READ;
+   case PIPE_TRANSFER_WRITE:
+      return PIPE_BUFFER_USAGE_CPU_WRITE;
+   default:
+      debug_assert(0);
+      return 0;
+   }
+}
+
 #ifdef __cplusplus
 }
 #endif
index 6f0bd6ae52a8da44e23646b0b13bce9da2de37c0..f4ed2fde4dc161ebf53185323442b6ca3cc214e5 100755 (executable)
@@ -314,7 +314,7 @@ class Screen(Object):
         if texture is None:
             return None
         transfer = Transfer(texture.get_surface(face, level, zslice), x, y, w, h)
-        if transfer and usage != gallium.PIPE_TRANSFER_WRITE:
+        if transfer and usage & gallium.PIPE_TRANSFER_READ
             if self.interpreter.options.all:
                 self.interpreter.present(transfer.surface, 'transf_read', x, y, w, h)
         return transfer
index 1f331dfcdb722676b3c72f81d66fced779633c98..610755e0636441e1a62de7707e6e9aa8a730085a 100644 (file)
@@ -57,8 +57,7 @@ st_cond_flush_get_tex_transfer(struct vg_context *st,
       pipe->is_texture_referenced(pipe, pt, face, level);
 
    if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
-                     usage == PIPE_TRANSFER_WRITE ||
-                     usage == PIPE_TRANSFER_READ_WRITE))
+                     (usage & PIPE_TRANSFER_WRITE)))
       vgFlush();
 
    return screen->get_tex_transfer(screen, pt, face, level, zslice, usage,
index 95181578f633cb51107e4931e385bbc5e6b4e72c..3d1d0f71d531b7d211e9c44ac0d5ba4747aa06dd 100644 (file)
@@ -241,7 +241,7 @@ accum_return(GLcontext *ctx, GLfloat value,
                                                xpos, ypos,
                                                width, height);
 
-   if (usage != PIPE_TRANSFER_WRITE)
+   if (usage & PIPE_TRANSFER_READ)
       pipe_get_tile_rgba(color_trans, 0, 0, width, height, buf);
 
    switch (acc_strb->format) {
index bbc2830e69413069b19244f11c0d3b20afc96fd0..ba8d1e8cc160c4b6543a8aec946e738ceaf17fed 100644 (file)
@@ -577,7 +577,6 @@ st_teximage_flush_before_map(struct st_context *st,
       pipe->is_texture_referenced(pipe, pt, face, level);
 
    if (referenced && ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
-                     usage == PIPE_TRANSFER_WRITE ||
-                     usage == PIPE_TRANSFER_READ_WRITE))
+                     (usage & PIPE_TRANSFER_WRITE)))
       st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
 }