Squashed commit of the following:
[mesa.git] / src / gallium / drivers / llvmpipe / lp_flush.c
index bf832433be12085a6823974d3e2154d339f90d19..f1533f8f70cb5cf66473ae3e8e4b3c75bd3d0722 100644 (file)
@@ -79,12 +79,12 @@ llvmpipe_flush( struct pipe_context *pipe,
 
       for (i = 0; i < llvmpipe->framebuffer.nr_cbufs; i++) {
         util_snprintf(filename, sizeof(filename), "cbuf%u_%u", i, frame_no);
-         debug_dump_surface(filename, llvmpipe->framebuffer.cbufs[i]);
+         debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.cbufs[0]);
       }
 
       if (0) {
          util_snprintf(filename, sizeof(filename), "zsbuf_%u", frame_no);
-         debug_dump_surface(filename, llvmpipe->framebuffer.zsbuf);
+         debug_dump_surface_bmp(&llvmpipe->pipe, filename, llvmpipe->framebuffer.zsbuf);
       }
 
       ++frame_no;
@@ -92,3 +92,67 @@ llvmpipe_flush( struct pipe_context *pipe,
 #endif
 }
 
+
+/**
+ * Flush context if necessary.
+ *
+ * TODO: move this logic to an auxiliary library?
+ *
+ * FIXME: We must implement DISCARD/DONTBLOCK/UNSYNCHRONIZED/etc for
+ * textures to avoid blocking.
+ */
+boolean
+llvmpipe_flush_texture(struct pipe_context *pipe,
+                       struct pipe_resource *texture,
+                       unsigned face,
+                       unsigned level,
+                       unsigned flush_flags,
+                       boolean read_only,
+                       boolean cpu_access,
+                       boolean do_not_flush)
+{
+   unsigned referenced;
+
+   referenced = pipe->is_resource_referenced(pipe, texture, face, level);
+
+   if ((referenced & PIPE_REFERENCED_FOR_WRITE) ||
+       ((referenced & PIPE_REFERENCED_FOR_READ) && !read_only)) {
+
+      if (do_not_flush)
+         return FALSE;
+
+      /*
+       * TODO: The semantics of these flush flags are too obtuse. They should
+       * disappear and the pipe driver should just ensure that all visible
+       * side-effects happen when they need to happen.
+       */
+      if (referenced & PIPE_REFERENCED_FOR_WRITE)
+         flush_flags |= PIPE_FLUSH_RENDER_CACHE;
+
+      if (referenced & PIPE_REFERENCED_FOR_READ)
+         flush_flags |= PIPE_FLUSH_TEXTURE_CACHE;
+
+      if (cpu_access) {
+         /*
+          * Flush and wait.
+          */
+
+         struct pipe_fence_handle *fence = NULL;
+
+         pipe->flush(pipe, flush_flags, &fence);
+
+         if (fence) {
+            pipe->screen->fence_finish(pipe->screen, fence, 0);
+            pipe->screen->fence_reference(pipe->screen, &fence, NULL);
+         }
+      } else {
+         /*
+          * Just flush.
+          */
+
+         pipe->flush(pipe, flush_flags, NULL);
+      }
+   }
+
+   return TRUE;
+}