vc4: Refactor flushing before mapping a BO.
authorEric Anholt <eric@anholt.net>
Fri, 24 Oct 2014 15:45:04 +0000 (16:45 +0100)
committerEric Anholt <eric@anholt.net>
Fri, 24 Oct 2014 17:04:26 +0000 (18:04 +0100)
I'm going to want to make some other decisions here before flushing.

src/gallium/drivers/vc4/vc4_context.c
src/gallium/drivers/vc4/vc4_context.h
src/gallium/drivers/vc4/vc4_resource.c

index 87f025142ce9ab53d693e58025b67c458ffa4360..b1f0f353fcce61423f4deac3a2305171ae72ccf4 100644 (file)
@@ -350,13 +350,13 @@ vc4_pipe_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
  *
  * This helps avoid flushing the command buffers when unnecessary.
  */
-void
-vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo)
+bool
+vc4_cl_references_bo(struct pipe_context *pctx, struct vc4_bo *bo)
 {
         struct vc4_context *vc4 = vc4_context(pctx);
 
         if (!vc4->needs_flush)
-                return;
+                return false;
 
         /* Walk all the referenced BOs in the drawing command list to see if
          * they match.
@@ -365,8 +365,7 @@ vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo)
         for (int i = 0; i < (vc4->bo_handles.next -
                              vc4->bo_handles.base) / 4; i++) {
                 if (referenced_bos[i] == bo) {
-                        vc4_flush(pctx);
-                        return;
+                        return true;
                 }
         }
 
@@ -377,8 +376,7 @@ vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo)
         if (csurf) {
                 struct vc4_resource *ctex = vc4_resource(csurf->base.texture);
                 if (ctex->bo == bo) {
-                        vc4_flush(pctx);
-                        return;
+                        return true;
                 }
         }
 
@@ -387,10 +385,11 @@ vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo)
                 struct vc4_resource *ztex =
                         vc4_resource(zsurf->base.texture);
                 if (ztex->bo == bo) {
-                        vc4_flush(pctx);
-                        return;
+                        return true;
                 }
         }
+
+        return false;
 }
 
 static void
index d0b280a3b6d47972606c4a061645a60e556d4414..9eaff8f7178249a2a3c4cb97d6da26e5a2ebdf90 100644 (file)
@@ -278,7 +278,7 @@ void vc4_write_uniforms(struct vc4_context *vc4,
                         struct vc4_texture_stateobj *texstate);
 
 void vc4_flush(struct pipe_context *pctx);
-void vc4_flush_for_bo(struct pipe_context *pctx, struct vc4_bo *bo);
+bool vc4_cl_references_bo(struct pipe_context *pctx, struct vc4_bo *bo);
 void vc4_emit_state(struct pipe_context *pctx);
 void vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c);
 struct qpu_reg *vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c);
index c198ab94f43d605b0c59f63cb65309a861a4f4cb..62667bf2586b8dc3cc6df27331d2cf6b8d1d7077 100644 (file)
@@ -80,8 +80,10 @@ vc4_resource_transfer_map(struct pipe_context *pctx,
                 rsc->bo = vc4_bo_alloc(vc4->screen, size, "resource");
         }
 
-        if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED))
-                vc4_flush_for_bo(pctx, rsc->bo);
+        if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
+                if (vc4_cl_references_bo(pctx, rsc->bo))
+                        vc4_flush(pctx);
+        }
 
         if (usage & PIPE_TRANSFER_WRITE)
                 rsc->writes++;