r300/compiler: Implement the texture semaphore
[mesa.git] / src / gallium / drivers / r300 / r300_transfer.c
index 30de9ec1e32515fe52ed79e3040b2629c10b5d9f..57d60a0e0feaa7328d3fb2f1f270803f71e9bf3d 100644 (file)
@@ -72,7 +72,8 @@ static void r300_copy_into_tiled_texture(struct pipe_context *ctx,
                               transfer->box.x, transfer->box.y, transfer->box.z,
                               &r300transfer->linear_texture->b.b.b, 0, &src_box);
 
-    ctx->flush(ctx, 0, NULL);
+    /* XXX remove this. */
+    r300_flush(ctx, 0, NULL);
 }
 
 struct pipe_transfer*
@@ -96,11 +97,12 @@ r300_texture_get_transfer(struct pipe_context *ctx,
         referenced_hw = TRUE;
     } else {
         referenced_hw =
-            r300->rws->buffer_is_busy(tex->buf);
+            r300->rws->buffer_is_busy(tex->buf, RADEON_USAGE_READWRITE);
     }
 
     blittable = desc->layout == UTIL_FORMAT_LAYOUT_PLAIN ||
-                desc->layout == UTIL_FORMAT_LAYOUT_S3TC;
+                desc->layout == UTIL_FORMAT_LAYOUT_S3TC ||
+                desc->layout == UTIL_FORMAT_LAYOUT_RGTC;
 
     trans = CALLOC_STRUCT(r300_transfer);
     if (trans) {
@@ -128,8 +130,14 @@ r300_texture_get_transfer(struct pipe_context *ctx,
             base.array_size = 1;
             base.last_level = 0;
             base.nr_samples = 0;
-            base.usage = PIPE_USAGE_DYNAMIC;
+            base.usage = PIPE_USAGE_STAGING;
             base.bind = 0;
+            if (usage & PIPE_TRANSFER_READ) {
+                base.bind |= PIPE_BIND_SAMPLER_VIEW;
+            }
+            if (usage & PIPE_TRANSFER_WRITE) {
+                base.bind |= PIPE_BIND_RENDER_TARGET;
+            }
             base.flags = R300_RESOURCE_FLAG_TRANSFER;
 
             /* For texture reading, the temporary (detiled) texture is used as
@@ -151,7 +159,7 @@ r300_texture_get_transfer(struct pipe_context *ctx,
             if (!trans->linear_texture) {
                 /* Oh crap, the thing can't create the texture.
                  * Let's flush and try again. */
-                ctx->flush(ctx, 0, NULL);
+                r300_flush(ctx, 0, NULL);
 
                 trans->linear_texture = r300_resource(
                    ctx->screen->resource_create(ctx->screen,
@@ -175,13 +183,7 @@ r300_texture_get_transfer(struct pipe_context *ctx,
             assert(!trans->linear_texture->tex.microtile &&
                    !trans->linear_texture->tex.macrotile[0]);
 
-            /* Set the stride.
-            *
-            * Even though we are using an internal texture for this,
-            * the transfer level, box and usage parameters still reflect
-            * the arguments received to get_transfer.  We just do the
-            * right thing internally.
-            */
+            /* Set the stride. */
             trans->transfer.stride =
                     trans->linear_texture->tex.stride_in_bytes[0];
 
@@ -191,7 +193,7 @@ r300_texture_get_transfer(struct pipe_context *ctx,
                 r300_copy_from_tiled_texture(ctx, trans);
 
                 /* Always referenced in the blit. */
-                ctx->flush(ctx, 0, NULL);
+                r300_flush(ctx, 0, NULL);
             }
             return &trans->transfer;
         }
@@ -201,8 +203,9 @@ r300_texture_get_transfer(struct pipe_context *ctx,
         trans->transfer.stride = tex->tex.stride_in_bytes[level];
         trans->offset = r300_texture_get_offset(tex, level, box->z);
 
-        if (referenced_cs)
-            ctx->flush(ctx, PIPE_FLUSH_RENDER_CACHE, NULL);
+        if (referenced_cs &&
+            !(usage & PIPE_TRANSFER_UNSYNCHRONIZED))
+            r300_flush(ctx, 0, NULL);
         return &trans->transfer;
     }
     return NULL;
@@ -229,7 +232,7 @@ void* r300_texture_transfer_map(struct pipe_context *ctx,
                                struct pipe_transfer *transfer)
 {
     struct r300_context *r300 = r300_context(ctx);
-    struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys;
+    struct radeon_winsys *rws = (struct radeon_winsys *)ctx->winsys;
     struct r300_transfer *r300transfer = r300_transfer(transfer);
     struct r300_resource *tex = r300_resource(transfer->resource);
     char *map;
@@ -259,7 +262,7 @@ void* r300_texture_transfer_map(struct pipe_context *ctx,
 void r300_texture_transfer_unmap(struct pipe_context *ctx,
                                 struct pipe_transfer *transfer)
 {
-    struct r300_winsys_screen *rws = (struct r300_winsys_screen *)ctx->winsys;
+    struct radeon_winsys *rws = (struct radeon_winsys *)ctx->winsys;
     struct r300_transfer *r300transfer = r300_transfer(transfer);
     struct r300_resource *tex = r300_resource(transfer->resource);