gallium: Make sure we flush before some texture / buffer operations.
[mesa.git] / src / mesa / state_tracker / st_cb_accum.c
index 15cc4cd95dc36f228d37e74808cd4d110d4bc6eb..1510a1e23619f26fd71a00b7068c311965a660c0 100644 (file)
@@ -40,6 +40,7 @@
 #include "st_draw.h"
 #include "st_public.h"
 #include "st_format.h"
+#include "st_texture.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_inlines.h"
@@ -118,6 +119,9 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
    const GLint height = ctx->DrawBuffer->_Ymax - ypos;
    GLubyte *map;
 
+   st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+                               PIPE_TRANSFER_WRITE);
+
    acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                      PIPE_TRANSFER_WRITE, xpos, ypos,
                                      width, height);
@@ -149,7 +153,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
    }
 
    screen->transfer_unmap(screen, acc_pt);
-   screen->tex_transfer_release(screen, &acc_pt);
+   screen->tex_transfer_destroy(acc_pt);
 }
 
 
@@ -163,6 +167,9 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
    struct pipe_transfer *acc_pt;
    GLubyte *map;
 
+   st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ_WRITE);
+
    acc_pt = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                      PIPE_TRANSFER_READ_WRITE, xpos, ypos,
                                      width, height);
@@ -187,25 +194,32 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias,
    }
 
    screen->transfer_unmap(screen, acc_pt);
-   screen->tex_transfer_release(screen, &acc_pt);
+   screen->tex_transfer_destroy(acc_pt);
 }
 
 
 static void
-accum_accum(struct pipe_context *pipe, GLfloat value,
+accum_accum(struct st_context *st, GLfloat value,
             GLint xpos, GLint ypos, GLint width, GLint height,
             struct st_renderbuffer *acc_strb,
             struct st_renderbuffer *color_strb)
 {
+   struct pipe_context *pipe = st->pipe;
    struct pipe_screen *screen = pipe->screen;
    struct pipe_transfer *acc_trans, *color_trans;
    GLfloat *colorBuf, *accBuf;
    GLint i;
 
+   st_teximage_flush_before_map(st, acc_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ);
+
    acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                         PIPE_TRANSFER_READ, xpos, ypos,
                                         width, height);
 
+   st_teximage_flush_before_map(st, color_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ);
+
    color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
                                           PIPE_TRANSFER_READ, xpos, ypos,
                                           width, height);
@@ -220,7 +234,7 @@ accum_accum(struct pipe_context *pipe, GLfloat value,
       accBuf[i] = accBuf[i] + colorBuf[i] * value;
    }
 
-   screen->tex_transfer_release(screen, &acc_trans);
+   screen->tex_transfer_destroy(acc_trans);
    acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                         PIPE_TRANSFER_WRITE, xpos, ypos,
                                         width, height);
@@ -229,26 +243,33 @@ accum_accum(struct pipe_context *pipe, GLfloat value,
 
    _mesa_free(colorBuf);
    _mesa_free(accBuf);
-   screen->tex_transfer_release(screen, &acc_trans);
-   screen->tex_transfer_release(screen, &color_trans);
+   screen->tex_transfer_destroy(acc_trans);
+   screen->tex_transfer_destroy(color_trans);
 }
 
 
 static void
-accum_load(struct pipe_context *pipe, GLfloat value,
+accum_load(struct st_context *st, GLfloat value,
            GLint xpos, GLint ypos, GLint width, GLint height,
            struct st_renderbuffer *acc_strb,
            struct st_renderbuffer *color_strb)
 {
+   struct pipe_context *pipe = st->pipe;
    struct pipe_screen *screen = pipe->screen;
    struct pipe_transfer *acc_trans, *color_trans;
    GLfloat *buf;
    GLint i;
 
+   st_teximage_flush_before_map(st, acc_strb->texture, 0, 0,
+                               PIPE_TRANSFER_WRITE);
+
    acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                         PIPE_TRANSFER_WRITE, xpos, ypos,
                                         width, height);
 
+   st_teximage_flush_before_map(st, color_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ);
+
    color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
                                         PIPE_TRANSFER_READ, xpos, ypos,
                                         width, height);
@@ -264,8 +285,8 @@ accum_load(struct pipe_context *pipe, GLfloat value,
    acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, buf);
 
    _mesa_free(buf);
-   screen->tex_transfer_release(screen, &acc_trans);
-   screen->tex_transfer_release(screen, &color_trans);
+   screen->tex_transfer_destroy(acc_trans);
+   screen->tex_transfer_destroy(color_trans);
 }
 
 
@@ -284,10 +305,16 @@ accum_return(GLcontext *ctx, GLfloat value,
 
    abuf = (GLfloat *) _mesa_malloc(width * height * 4 * sizeof(GLfloat));
 
+   st_teximage_flush_before_map(ctx->st, acc_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ);
+
    acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0,
                                         PIPE_TRANSFER_READ, xpos, ypos,
                                         width, height);
 
+   st_teximage_flush_before_map(ctx->st, color_strb->texture, 0, 0,
+                               PIPE_TRANSFER_READ_WRITE);
+
    color_trans = screen->get_tex_transfer(screen, color_strb->texture, 0, 0, 0,
                                           PIPE_TRANSFER_READ_WRITE, xpos, ypos,
                                           width, height);
@@ -316,8 +343,8 @@ accum_return(GLcontext *ctx, GLfloat value,
    _mesa_free(abuf);
    if (cbuf)
       _mesa_free(cbuf);
-   screen->tex_transfer_release(screen, &acc_trans);
-   screen->tex_transfer_release(screen, &color_trans);
+   screen->tex_transfer_destroy(acc_trans);
+   screen->tex_transfer_destroy(color_trans);
 }
 
 
@@ -325,7 +352,6 @@ static void
 st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
 {
    struct st_context *st = ctx->st;
-   struct pipe_context *pipe = st->pipe;
    struct st_renderbuffer *acc_strb
      = st_renderbuffer(ctx->DrawBuffer->Attachment[BUFFER_ACCUM].Renderbuffer);
    struct st_renderbuffer *color_strb
@@ -352,11 +378,11 @@ st_Accum(GLcontext *ctx, GLenum op, GLfloat value)
       break;
    case GL_ACCUM:
       if (value != 0.0F) {
-         accum_accum(pipe, value, xpos, ypos, width, height, acc_strb, color_strb);
+         accum_accum(st, value, xpos, ypos, width, height, acc_strb, color_strb);
       }
       break;
    case GL_LOAD:
-      accum_load(pipe, value, xpos, ypos, width, height, acc_strb, color_strb);
+      accum_load(st, value, xpos, ypos, width, height, acc_strb, color_strb);
       break;
    case GL_RETURN:
       accum_return(ctx, value, xpos, ypos, width, height, acc_strb, color_strb);